@antv/layout 1.0.0-alpha.11 → 1.0.0-alpha.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/1f8aa319de677a5a27b9.worker.js +2 -0
- package/dist/1f8aa319de677a5a27b9.worker.js.map +1 -0
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/esm/1f8aa319de677a5a27b9.worker.js +2 -0
- package/esm/1f8aa319de677a5a27b9.worker.js.map +1 -0
- package/esm/index.esm.js +1 -1
- package/esm/index.esm.js.map +1 -1
- package/lib/force/index.d.ts +22 -7
- package/lib/fruchterman.d.ts +3 -5
- package/lib/types.d.ts +0 -1
- package/package.json +1 -1
- package/dist/2a6b6d9f27a9b35490fa.worker.js +0 -2
- package/dist/2a6b6d9f27a9b35490fa.worker.js.map +0 -1
- package/esm/2a6b6d9f27a9b35490fa.worker.js +0 -2
- package/esm/2a6b6d9f27a9b35490fa.worker.js.map +0 -1
package/esm/index.esm.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var t={161:t=>{var e=Object.prototype.hasOwnProperty,r="~";function n(){}function o(t,e,r){this.fn=t,this.context=e,this.once=r||!1}function i(t,e,n,i,s){if("function"!=typeof n)throw new TypeError("The listener must be a function");var a=new o(n,i||t,s),u=r?r+e:e;return t._events[u]?t._events[u].fn?t._events[u]=[t._events[u],a]:t._events[u].push(a):(t._events[u]=a,t._eventsCount++),t}function s(t,e){0==--t._eventsCount?t._events=new n:delete t._events[e]}function a(){this._events=new n,this._eventsCount=0}Object.create&&(n.prototype=Object.create(null),(new n).__proto__||(r=!1)),a.prototype.eventNames=function(){var t,n,o=[];if(0===this._eventsCount)return o;for(n in t=this._events)e.call(t,n)&&o.push(r?n.slice(1):n);return Object.getOwnPropertySymbols?o.concat(Object.getOwnPropertySymbols(t)):o},a.prototype.listeners=function(t){var e=r?r+t:t,n=this._events[e];if(!n)return[];if(n.fn)return[n.fn];for(var o=0,i=n.length,s=new Array(i);o<i;o++)s[o]=n[o].fn;return s},a.prototype.listenerCount=function(t){var e=r?r+t:t,n=this._events[e];return n?n.fn?1:n.length:0},a.prototype.emit=function(t,e,n,o,i,s){var a=r?r+t:t;if(!this._events[a])return!1;var u,h,l=this._events[a],c=arguments.length;if(l.fn){switch(l.once&&this.removeListener(t,l.fn,void 0,!0),c){case 1:return l.fn.call(l.context),!0;case 2:return l.fn.call(l.context,e),!0;case 3:return l.fn.call(l.context,e,n),!0;case 4:return l.fn.call(l.context,e,n,o),!0;case 5:return l.fn.call(l.context,e,n,o,i),!0;case 6:return l.fn.call(l.context,e,n,o,i,s),!0}for(h=1,u=new Array(c-1);h<c;h++)u[h-1]=arguments[h];l.fn.apply(l.context,u)}else{var f,d=l.length;for(h=0;h<d;h++)switch(l[h].once&&this.removeListener(t,l[h].fn,void 0,!0),c){case 1:l[h].fn.call(l[h].context);break;case 2:l[h].fn.call(l[h].context,e);break;case 3:l[h].fn.call(l[h].context,e,n);break;case 4:l[h].fn.call(l[h].context,e,n,o);break;default:if(!u)for(f=1,u=new Array(c-1);f<c;f++)u[f-1]=arguments[f];l[h].fn.apply(l[h].context,u)}}return!0},a.prototype.on=function(t,e,r){return i(this,t,e,r,!1)},a.prototype.once=function(t,e,r){return i(this,t,e,r,!0)},a.prototype.removeListener=function(t,e,n,o){var i=r?r+t:t;if(!this._events[i])return this;if(!e)return s(this,i),this;var a=this._events[i];if(a.fn)a.fn!==e||o&&!a.once||n&&a.context!==n||s(this,i);else{for(var u=0,h=[],l=a.length;u<l;u++)(a[u].fn!==e||o&&!a[u].once||n&&a[u].context!==n)&&h.push(a[u]);h.length?this._events[i]=1===h.length?h[0]:h:s(this,i)}return this},a.prototype.removeAllListeners=function(t){var e;return t?(e=r?r+t:t,this._events[e]&&s(this,e)):(this._events=new n,this._eventsCount=0),this},a.prototype.off=a.prototype.removeListener,a.prototype.addListener=a.prototype.on,a.prefixed=r,a.EventEmitter=a,t.exports=a},825:(t,e,r)=>{var n=r(475),o=["stopLayout","calculateLayout"];t.exports=function(){var t=new Worker(URL.createObjectURL(new Blob(['var t={d:(e,r)=>{for(var n in r)t.o(r,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:r[n]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)},e={};t.d(e,{calculateLayout:()=>ze,stopLayout:()=>_e});var r=function(){return r=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var o in e=arguments[r])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},r.apply(this,arguments)};function n(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(t);o<n.length;o++)e.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(t,n[o])&&(r[n[o]]=t[n[o]])}return r}function o(t,e){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var n,o,i=r.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(n=i.next()).done;)s.push(n.value)}catch(t){o={error:t}}finally{try{n&&!n.done&&(r=i.return)&&r.call(i)}finally{if(o)throw o.error}}return s}function i(t,e,r){if(r||2===arguments.length)for(var n,o=0,i=e.length;o<i;o++)!n&&o in e||(n||(n=Array.prototype.slice.call(e,0,o)),n[o]=e[o]);return t.concat(n||Array.prototype.slice.call(e))}Object.create,Object.create;class s{nodeMap=new Map;edgeMap=new Map;inEdgesMap=new Map;outEdgesMap=new Map;treeIndices=new Map;changes=[];batchCount=0;onChanged=()=>{};constructor(t){t&&(t.nodes&&this.addNodes(t.nodes),t.edges&&this.addEdges(t.edges),t.tree&&this.addTree(t.tree),t.onChanged&&(this.onChanged=t.onChanged))}batch=t=>{this.batchCount+=1,t(),this.batchCount-=1,this.batchCount||this.commit()};commit(){const t=this.changes;this.changes=[],this.onChanged({graph:this,changes:t})}reduceChanges(t){let e=[];return t.forEach((t=>{switch(t.type){case"NodeRemoved":{let r=!1;e=e.filter((e=>{if("NodeAdded"===e.type){const n=e.value.id===t.value.id;return n&&(r=!0),!n}return"NodeDataUpdated"===e.type?e.id!==t.value.id:"TreeStructureChanged"!==e.type||e.nodeId!==t.value.id})),r||e.push(t);break}case"EdgeRemoved":{let r=!1;e=e.filter((e=>{if("EdgeAdded"===e.type){const n=e.value.id===t.value.id;return n&&(r=!0),!n}return"EdgeDataUpdated"!==e.type&&"EdgeUpdated"!==e.type||e.id!==t.value.id})),r||e.push(t);break}case"NodeDataUpdated":case"EdgeDataUpdated":case"EdgeUpdated":{const r=e.find((e=>e.type===t.type&&e.id===t.id&&e.propertyName===t.propertyName));r?r.newValue=t.newValue:e.push(t);break}case"TreeStructureDetached":e=e.filter((e=>"TreeStructureAttached"===e.type?e.treeKey!==t.treeKey:"TreeStructureChanged"!==e.type||e.treeKey!==t.treeKey)),e.push(t);break;case"TreeStructureChanged":{const r=e.find((e=>"TreeStructureChanged"===e.type&&e.treeKey===t.treeKey&&e.nodeId===t.nodeId));r?r.newParentId=t.newParentId:e.push(t);break}default:e.push(t)}})),e}checkNodeExistence(t){if(!this.hasNode(t))throw new Error("Node not found for id: "+t)}hasNode(t){return this.nodeMap.has(t)}areNeighbors(t,e){return this.checkNodeExistence(t),this.getNeighbors(e).some((e=>e.id===t))}getNode(t){return this.checkNodeExistence(t),this.nodeMap.get(t)}getRelatedEdges(t,e){this.checkNodeExistence(t);const r=this.inEdgesMap.get(t),n=this.outEdgesMap.get(t);if("in"===e)return Array.from(r);if("out"===e)return Array.from(n);const o=new Set([...r,...n]);return Array.from(o)}getDegree(t,e){return this.getRelatedEdges(t,e).length}getSuccessors(t){const e=this.getRelatedEdges(t,"out").map((t=>t.target));return Array.from(new Set(e)).map((t=>this.getNode(t)))}getPredecessors(t){const e=this.getRelatedEdges(t,"in").map((t=>t.source));return Array.from(new Set(e)).map((t=>this.getNode(t)))}getNeighbors(t){const e=this.getPredecessors(t),r=this.getSuccessors(t);return Array.from(new Set([...e,...r]))}doAddNode(t){if(this.hasNode(t.id))throw new Error("Node already exists: "+t.id);this.nodeMap.set(t.id,t),this.inEdgesMap.set(t.id,new Set),this.outEdgesMap.set(t.id,new Set),this.treeIndices.forEach((e=>{e.childrenMap.set(t.id,new Set)})),this.changes.push({type:"NodeAdded",value:t})}addNodes(t){this.batch((()=>{for(const e of t)this.doAddNode(e)}))}addNode(t){this.addNodes([t])}doRemoveNode(t){const e=this.getNode(t),r=this.inEdgesMap.get(t),n=this.outEdgesMap.get(t);r?.forEach((t=>this.doRemoveEdge(t.id))),n?.forEach((t=>this.doRemoveEdge(t.id))),this.nodeMap.delete(t),this.treeIndices.forEach((e=>{e.childrenMap.get(t)?.forEach((t=>{e.parentMap.delete(t.id)})),e.parentMap.delete(t),e.childrenMap.delete(t)})),this.changes.push({type:"NodeRemoved",value:e})}removeNodes(t){this.batch((()=>{t.forEach((t=>this.doRemoveNode(t)))}))}removeNode(t){this.removeNodes([t])}updateNodeDataProperty(t,e,r){const n=this.getNode(t);this.batch((()=>{const o=n.data[e],i=r;n.data[e]=i,this.changes.push({type:"NodeDataUpdated",id:t,propertyName:e,oldValue:o,newValue:i})}))}mergeNodeData(t,e){this.batch((()=>{Object.entries(e).forEach((([e,r])=>{this.updateNodeDataProperty(t,e,r)}))}))}updateNodeData(...t){const e=t[0],r=this.getNode(e);if("string"==typeof t[1])return void this.updateNodeDataProperty(e,t[1],t[2]);let n;if("function"==typeof t[1]){const e=t[1];n=e(r.data)}else"object"==typeof t[1]&&(n=t[1]);this.batch((()=>{const t=r.data,o=n;r.data=n,this.changes.push({type:"NodeDataUpdated",id:e,oldValue:t,newValue:o})}))}checkEdgeExistence(t){if(!this.hasEdge(t))throw new Error("Edge not found for id: "+t)}hasEdge(t){return this.edgeMap.has(t)}getEdge(t){return this.checkEdgeExistence(t),this.edgeMap.get(t)}getEdgeDetail(t){const e=this.getEdge(t);return{edge:e,source:this.getNode(e.source),target:this.getNode(e.target)}}doAddEdge(t){if(this.hasEdge(t.id))throw new Error("Edge already exists: "+t.id);this.checkNodeExistence(t.source),this.checkNodeExistence(t.target),this.edgeMap.set(t.id,t);const e=this.inEdgesMap.get(t.target),r=this.outEdgesMap.get(t.source);e.add(t),r.add(t),this.changes.push({type:"EdgeAdded",value:t})}addEdges(t){this.batch((()=>{for(const e of t)this.doAddEdge(e)}))}addEdge(t){this.addEdges([t])}doRemoveEdge(t){const e=this.getEdge(t),r=this.outEdgesMap.get(e.source),n=this.inEdgesMap.get(e.target);r.delete(e),n.delete(e),this.edgeMap.delete(t),this.changes.push({type:"EdgeRemoved",value:e})}removeEdges(t){this.batch((()=>{t.forEach((t=>this.doRemoveEdge(t)))}))}removeEdge(t){this.removeEdges([t])}updateEdgeSource(t,e){const r=this.getEdge(t);this.checkNodeExistence(e);const n=r.source,o=e;this.outEdgesMap.get(n).delete(r),this.outEdgesMap.get(o).add(r),r.source=e,this.batch((()=>{this.changes.push({type:"EdgeUpdated",id:t,propertyName:"source",oldValue:n,newValue:o})}))}updateEdgeTarget(t,e){const r=this.getEdge(t);this.checkNodeExistence(e);const n=r.target,o=e;this.inEdgesMap.get(n).delete(r),this.inEdgesMap.get(o).add(r),r.target=e,this.batch((()=>{this.changes.push({type:"EdgeUpdated",id:t,propertyName:"target",oldValue:n,newValue:o})}))}updateEdgeDataProperty(t,e,r){const n=this.getEdge(t);this.batch((()=>{const o=n.data[e],i=r;n.data[e]=i,this.changes.push({type:"EdgeDataUpdated",id:t,propertyName:e,oldValue:o,newValue:i})}))}updateEdgeData(...t){const e=t[0],r=this.getEdge(e);if("string"==typeof t[1])return void this.updateEdgeDataProperty(e,t[1],t[2]);let n;if("function"==typeof t[1]){const e=t[1];n=e(r.data)}else"object"==typeof t[1]&&(n=t[1]);this.batch((()=>{const t=r.data,o=n;r.data=n,this.changes.push({type:"EdgeDataUpdated",id:e,oldValue:t,newValue:o})}))}mergeEdgeData(t,e){this.batch((()=>{Object.entries(e).forEach((([e,r])=>{this.updateEdgeDataProperty(t,e,r)}))}))}checkTreeExistence(t){if(!this.treeIndices.has(t))throw new Error("Tree structure not found for treeKey: "+t)}attachTreeStructure(t){this.treeIndices.has(t)||(this.treeIndices.set(t,{parentMap:new Map,childrenMap:new Map}),this.batch((()=>{this.changes.push({type:"TreeStructureAttached",treeKey:t})})))}detachTreeStructure(t){this.checkTreeExistence(t),this.treeIndices.delete(t),this.batch((()=>{this.changes.push({type:"TreeStructureDetached",treeKey:t})}))}addTree(t,e){this.batch((()=>{this.attachTreeStructure(e);const r=[],n=Array.isArray(t)?t:[t];for(;n.length;){const t=n.shift();r.push(t),t.children&&n.push(...t.children)}this.addNodes(r),r.forEach((t=>{t.children?.forEach((r=>{this.setParent(r.id,t.id,e)}))}))}))}getRoots(t){return this.checkTreeExistence(t),this.getAllNodes().filter((e=>!this.getParent(e.id,t)))}getChildren(t,e){this.checkNodeExistence(t),this.checkTreeExistence(e);const r=this.treeIndices.get(e).childrenMap.get(t);return Array.from(r||[])}getParent(t,e){return this.checkNodeExistence(t),this.checkTreeExistence(e),this.treeIndices.get(e).parentMap.get(t)||null}setParent(t,e,r){this.checkTreeExistence(r);const n=this.treeIndices.get(r),o=this.getNode(t),i=n.parentMap.get(t),s=this.getNode(e);n.parentMap.set(t,s),i&&n.childrenMap.get(i.id)?.delete(o);let a=n.childrenMap.get(s.id);a||(a=new Set,n.childrenMap.set(s.id,a)),a.add(o),this.batch((()=>{this.changes.push({type:"TreeStructureChanged",treeKey:r,nodeId:t,oldParentId:i?.id,newParentId:s.id})}))}getAllNodes(){return Array.from(this.nodeMap.values())}getAllEdges(){return Array.from(this.edgeMap.values())}doBFS(t,e,r){for(;t.length;){const n=t.shift();r(n),e.add(n.id),this.getSuccessors(n.id).forEach((r=>{e.has(r.id)||(e.add(r.id),t.push(r))}))}}bfs(t,e){this.doBFS([this.getNode(t)],new Set,e)}doDFS(t,e,r){r(t),e.add(t.id),this.getSuccessors(t.id).forEach((t=>{e.has(t.id)||this.doDFS(t,e,r)}))}dfs(t,e){this.doDFS(this.getNode(t),new Set,e)}clone(){const t=this.getAllNodes().map((t=>({...t,data:{...t.data}}))),e=this.getAllEdges().map((t=>({...t,data:{...t.data}}))),r=new s({nodes:t,edges:e});return this.treeIndices.forEach((({parentMap:t,childrenMap:e},n)=>{const o=new Map;t.forEach(((t,e)=>{o.set(e,r.getNode(t.id))}));const i=new Map;e.forEach(((t,e)=>{i.set(e,new Set(Array.from(t).map((t=>r.getNode(t.id)))))})),r.treeIndices.set(n,{parentMap:o,childrenMap:i})})),r}toJSON(){return JSON.stringify({nodes:this.getAllNodes(),edges:this.getAllEdges()})}}var a=function(t){return"string"==typeof t},u=/-(\\w)/g,h=(function(t){return t.replace(u,(function(t,e){return e?e.toUpperCase():""}))},Object.create(null),Array.isArray),l=function(t){return"number"==typeof t},c=function(t){for(var e=[],r=t.length,n=0;n<r;n+=1){e[n]=[];for(var o=0;o<r;o+=1)n===o?e[n][o]=0:0!==t[n][o]&&t[n][o]?e[n][o]=t[n][o]:e[n][o]=1/0}for(var i=0;i<r;i+=1)for(n=0;n<r;n+=1)for(o=0;o<r;o+=1)e[n][o]>e[n][i]+e[i][o]&&(e[n][o]=e[n][i]+e[i][o]);return e},f=function(t,e){var r=t.nodes,n=t.edges,o=[],i={};if(!r)throw new Error("invalid nodes data!");return r&&r.forEach((function(t,e){i[t.id]=e,o.push([])})),null==n||n.forEach((function(t){var r=t.source,n=t.target,s=i[r],a=i[n];void 0!==s&&void 0!==a&&(o[s][a]=1,e||(o[a][s]=1))})),o},d=function(t,e){return Math.sqrt((t.x-e.x)*(t.x-e.x)+(t.y-e.y)*(t.y-e.y))},g=function(t){return null!==t&&"object"==typeof t},p=function(t){if(null===t)return t;if(t instanceof Date)return new Date(t.getTime());if(t instanceof Array){var e=[];return t.forEach((function(t){e.push(t)})),e.map((function(t){return p(t)}))}if("object"==typeof t&&Object.keys(t).length){var n=r({},t);return Object.keys(n).forEach((function(t){n[t]=p(n[t])})),n}return t},m=function(t,e){var r=p(t);return r.data=r.data||{},e&&(l(r.data.x)||(r.data.x=Math.random()*e[0]),l(r.data.y)||(r.data.y=Math.random()*e[1])),r},y=function(t){return"function"==typeof t};function w(t,e){return y(e)?e:l(e)?function(){return e}:function(){return t}}function v(t,e,r){return void 0===r&&(r=!0),e||0===e?y(e)?e:l(e)?function(){return e}:h(e)?function(){if(r){var n=Math.max.apply(Math,i([],o(e),!1));return isNaN(n)?t:n}return e}:g(e)?function(){if(r){var n=Math.max(e.width,e.height);return isNaN(n)?t:n}return[e.width,e.height]}:function(){return t}:function(e){var r=(e.data||{}).size;return r?h(r)?r[0]>r[1]?r[0]:r[1]:g(r)?r.width>r.height?r.width:r.height:r:t}}var x={radius:null,startRadius:null,endRadius:null,startAngle:0,endAngle:2*Math.PI,clockwise:!0,divisions:1,ordering:null,angleRatio:1},M=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="circular",this.options=r(r({},x),t)}return t.prototype.execute=function(t,e){return this.genericCircularLayout(!1,t,e)},t.prototype.assign=function(t,e){var r=this;t.batch((function(){r.genericCircularLayout(!0,t,e)}))},t.prototype.genericCircularLayout=function(t,e,n){var i=r(r({},this.options),n),s=i.width,a=i.height,u=i.center,h=i.divisions,l=i.startAngle,c=void 0===l?0:l,f=i.endAngle,d=void 0===f?2*Math.PI:f,g=i.angleRatio,p=i.ordering,y=i.clockwise,x=i.nodeSpacing,M=i.nodeSize,N=i.layoutInvisibles,S=i.onLayoutEnd,A=e.getAllNodes(),k=e.getAllEdges();N||(A=A.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e})),k=k.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e})));var I=A.length;if(0===I)return null==S||S({nodes:[],edges:[]}),{nodes:[],edges:[]};var D=o(E(s,a,u),3),R=D[0],_=D[1],z=D[2];if(1===I){t&&e.mergeNodeData(A[0].id,{x:z[0],y:z[1]});var T={nodes:[r(r({},A[0]),{data:r(r({},A[0].data),{x:z[0],y:z[1]})})],edges:k};return null==S||S(T),T}var C=(d-c)/I,O=i.radius,P=i.startRadius,L=i.endRadius;if(x){var q=w(10,x),j=v(10,M),V=-1/0;A.forEach((function(t){var e=j(t);V<e&&(V=e)}));var F=0;A.forEach((function(t,e){F+=0===e?V||10:(q(t)||0)+(V||10)})),O=F/(2*Math.PI)}else O||P||L?!P&&L?P=L:P&&!L&&(L=P):O=Math.min(_,R)/2;var $=C*g,U=[];U="topology"===p?b(e,A):"topology-directed"===p?b(e,A,!0):"degree"===p?function(t,e){var r=[];return e.forEach((function(t,e){r.push(m(t))})),r.sort((function(e,r){return t.getDegree(e.id,"both")-t.getDegree(r.id,"both")})),r}(e,A):A.map((function(t){return m(t)}));for(var B=Math.ceil(I/h),G=0;G<I;++G){var K=O;K||null===P||null===L||(K=P+G*(L-P)/(I-1)),K||(K=10+100*G/(I-1));var W=c+G%B*$+2*Math.PI/h*Math.floor(G/B);y||(W=d-G%B*$-2*Math.PI/h*Math.floor(G/B)),U[G].data.x=z[0]+Math.cos(W)*K,U[G].data.y=z[1]+Math.sin(W)*K}t&&U.forEach((function(t){e.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}));var H={nodes:U,edges:k};return null==S||S(H),H},t}(),b=function(t,e,r){void 0===r&&(r=!1);var n=[m(e[0])],o={},i=e.length;o[e[0].id]=!0;var s=0;return e.forEach((function(a,u){if(0!==u)if(u!==i-1&&t.getDegree(a.id,"both")===t.getDegree(e[u+1].id,"both")&&!t.areNeighbors(n[s].id,a.id)||o[a.id]){for(var h=r?t.getSuccessors(n[s].id):t.getNeighbors(n[s].id),l=!1,c=0;c<h.length;c++){var f=h[c];if(t.getDegree(f.id)===t.getDegree(a.id)&&!o[f.id]){n.push(m(f)),o[f.id]=!0,l=!0;break}}for(var d=0;!l&&(o[e[d].id]||(n.push(m(e[d])),o[e[d].id]=!0,l=!0),++d!==i););}else n.push(m(a)),o[a.id]=!0,s++})),n},E=function(t,e,r){var n=t,o=e,i=r;return n||"undefined"==typeof window||(n=window.innerWidth),o||"undefined"==typeof window||(o=window.innerHeight),i||(i=[n/2,o/2]),[n,o,i]},N={nodeSize:30,minNodeSpacing:10,nodeSpacing:10,preventOverlap:!1,sweep:void 0,equidistant:!1,startAngle:1.5*Math.PI,clockwise:!0,maxLevelDiff:void 0,sortBy:"degree"},S=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="concentric",this.options=r(r({},N),t)}return t.prototype.execute=function(t,e){return this.genericConcentricLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericConcentricLayout(!0,t,e)},t.prototype.genericConcentricLayout=function(t,e,n){var o=r(r({},this.options),n),i=o.center,s=o.width,u=o.height,c=o.sortBy,f=o.maxLevelDiff,d=o.sweep,p=o.clockwise,w=o.equidistant,v=o.minNodeSpacing,x=void 0===v?10:v,M=o.preventOverlap,b=o.startAngle,E=void 0===b?1.5*Math.PI:b,N=o.nodeSize,S=o.nodeSpacing,A=o.layoutInvisibles,k=o.onLayoutEnd,I=e.getAllNodes(),D=e.getAllEdges();A||(I=I.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e})),D=D.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e})));var R=I.length;if(0===R){var _={nodes:[],edges:D};return null==k||k(_),_}var z=s||"undefined"==typeof window?s:window.innerWidth,T=u||"undefined"==typeof window?u:window.innerHeight,C=i||[z/2,T/2];if(1===R){t&&e.mergeNodeData(I[0].id,{x:C[0],y:C[1]});var O={nodes:[r(r({},I[0]),{data:r(r({},I[0].data),{x:C[0],y:C[1]})})],edges:D};return null==k||k(O),O}var P,L=[],q=0;P=h(N)?Math.max(N[0],N[1]):N,h(S)?q=Math.max(S[0],S[1]):l(S)&&(q=S),I.forEach((function(t){var e=m(t);L.push(e);var r=P,n=e.data;h(n.size)?r=Math.max(n.size[0],n.size[1]):l(n.size)?r=n.size:g(n.size)&&(r=Math.max(n.size.width,n.size.height)),P=Math.max(P,r),y(S)&&(q=Math.max(S(t),q))}));var j={};L.forEach((function(t,e){j[t.id]=e}));var V=c;a(V)&&void 0!==L[0].data[V]||(V="degree"),"degree"===V?L.sort((function(t,r){return e.getDegree(r.id,"both")-e.getDegree(t.id,"both")})):L.sort((function(t,e){return e.data[V]-t.data[V]}));var F=L[0],$=(f||("degree"===V?e.getDegree(F.id,"both"):F.data[V]))/4,U=[{nodes:[]}],B=U[0];L.forEach((function(t){if(B.nodes.length>0){var r="degree"===V?Math.abs(e.getDegree(B.nodes[0].id,"both")-e.getDegree(t.id,"both")):Math.abs(B.nodes[0].data[V]-t.data[V]);$&&r>=$&&(B={nodes:[]},U.push(B))}B.nodes.push(t)}));var G=P+(q||x);if(!M){var K=U.length>0&&U[0].nodes.length>1,W=(Math.min(z,T)/2-G)/(U.length+(K?1:0));G=Math.min(G,W)}var H=0;if(U.forEach((function(t){var e=void 0===d?2*Math.PI-2*Math.PI/t.nodes.length:d;if(t.dTheta=e/Math.max(1,t.nodes.length-1),t.nodes.length>1&&M){var r=Math.cos(t.dTheta)-Math.cos(0),n=Math.sin(t.dTheta)-Math.sin(0),o=Math.sqrt(G*G/(r*r+n*n));H=Math.max(o,H)}t.r=H,H+=G})),w){for(var J=0,Y=0,X=0;X<U.length;X++){var Q=(U[X].r||0)-Y;J=Math.max(J,Q)}Y=0,U.forEach((function(t,e){0===e&&(Y=t.r||0),t.r=Y,Y+=J}))}U.forEach((function(t){var e=t.dTheta||0,r=t.r||0;t.nodes.forEach((function(t,n){var o=E+(p?1:-1)*e*n;t.data.x=C[0]+r*Math.cos(o),t.data.y=C[1]+r*Math.sin(o)}))})),t&&L.forEach((function(t){return e.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}));var Z={nodes:L,edges:D};return null==k||k(Z),Z},t}();function A(t,e,r,n){if(isNaN(e)||isNaN(r))return t;var o,i,s,a,u,h,l,c,f,d=t._root,g={data:n},p=t._x0,m=t._y0,y=t._x1,w=t._y1;if(!d)return t._root=g,t;for(;d.length;)if((h=e>=(i=(p+y)/2))?p=i:y=i,(l=r>=(s=(m+w)/2))?m=s:w=s,o=d,!(d=d[c=l<<1|h]))return o[c]=g,t;if(a=+t._x.call(null,d.data),u=+t._y.call(null,d.data),e===a&&r===u)return g.next=d,o?o[c]=g:t._root=g,t;do{o=o?o[c]=new Array(4):t._root=new Array(4),(h=e>=(i=(p+y)/2))?p=i:y=i,(l=r>=(s=(m+w)/2))?m=s:w=s}while((c=l<<1|h)==(f=(u>=s)<<1|a>=i));return o[f]=d,o[c]=g,t}function k(t,e,r,n,o){this.node=t,this.x0=e,this.y0=r,this.x1=n,this.y1=o}function I(t){return t[0]}function D(t){return t[1]}function R(t,e,r){var n=new _(null==e?I:e,null==r?D:r,NaN,NaN,NaN,NaN);return null==t?n:n.addAll(t)}function _(t,e,r,n,o,i){this._x=t,this._y=e,this._x0=r,this._y0=n,this._x1=o,this._y1=i,this._root=void 0}function z(t){for(var e={data:t.data},r=e;t=t.next;)r=r.next={data:t.data};return e}var T=R.prototype=_.prototype;function C(t){return function(){return t}}function O(t){return 1e-6*(t()-.5)}T.copy=function(){var t,e,r=new _(this._x,this._y,this._x0,this._y0,this._x1,this._y1),n=this._root;if(!n)return r;if(!n.length)return r._root=z(n),r;for(t=[{source:n,target:r._root=new Array(4)}];n=t.pop();)for(var o=0;o<4;++o)(e=n.source[o])&&(e.length?t.push({source:e,target:n.target[o]=new Array(4)}):n.target[o]=z(e));return r},T.add=function(t){const e=+this._x.call(null,t),r=+this._y.call(null,t);return A(this.cover(e,r),e,r,t)},T.addAll=function(t){var e,r,n,o,i=t.length,s=new Array(i),a=new Array(i),u=1/0,h=1/0,l=-1/0,c=-1/0;for(r=0;r<i;++r)isNaN(n=+this._x.call(null,e=t[r]))||isNaN(o=+this._y.call(null,e))||(s[r]=n,a[r]=o,n<u&&(u=n),n>l&&(l=n),o<h&&(h=o),o>c&&(c=o));if(u>l||h>c)return this;for(this.cover(u,h).cover(l,c),r=0;r<i;++r)A(this,s[r],a[r],t[r]);return this},T.cover=function(t,e){if(isNaN(t=+t)||isNaN(e=+e))return this;var r=this._x0,n=this._y0,o=this._x1,i=this._y1;if(isNaN(r))o=(r=Math.floor(t))+1,i=(n=Math.floor(e))+1;else{for(var s,a,u=o-r||1,h=this._root;r>t||t>=o||n>e||e>=i;)switch(a=(e<n)<<1|t<r,(s=new Array(4))[a]=h,h=s,u*=2,a){case 0:o=r+u,i=n+u;break;case 1:r=o-u,i=n+u;break;case 2:o=r+u,n=i-u;break;case 3:r=o-u,n=i-u}this._root&&this._root.length&&(this._root=h)}return this._x0=r,this._y0=n,this._x1=o,this._y1=i,this},T.data=function(){var t=[];return this.visit((function(e){if(!e.length)do{t.push(e.data)}while(e=e.next)})),t},T.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]]},T.find=function(t,e,r){var n,o,i,s,a,u,h,l=this._x0,c=this._y0,f=this._x1,d=this._y1,g=[],p=this._root;for(p&&g.push(new k(p,l,c,f,d)),null==r?r=1/0:(l=t-r,c=e-r,f=t+r,d=e+r,r*=r);u=g.pop();)if(!(!(p=u.node)||(o=u.x0)>f||(i=u.y0)>d||(s=u.x1)<l||(a=u.y1)<c))if(p.length){var m=(o+s)/2,y=(i+a)/2;g.push(new k(p[3],m,y,s,a),new k(p[2],o,y,m,a),new k(p[1],m,i,s,y),new k(p[0],o,i,m,y)),(h=(e>=y)<<1|t>=m)&&(u=g[g.length-1],g[g.length-1]=g[g.length-1-h],g[g.length-1-h]=u)}else{var w=t-+this._x.call(null,p.data),v=e-+this._y.call(null,p.data),x=w*w+v*v;if(x<r){var M=Math.sqrt(r=x);l=t-M,c=e-M,f=t+M,d=e+M,n=p.data}}return n},T.remove=function(t){if(isNaN(i=+this._x.call(null,t))||isNaN(s=+this._y.call(null,t)))return this;var e,r,n,o,i,s,a,u,h,l,c,f,d=this._root,g=this._x0,p=this._y0,m=this._x1,y=this._y1;if(!d)return this;if(d.length)for(;;){if((h=i>=(a=(g+m)/2))?g=a:m=a,(l=s>=(u=(p+y)/2))?p=u:y=u,e=d,!(d=d[c=l<<1|h]))return this;if(!d.length)break;(e[c+1&3]||e[c+2&3]||e[c+3&3])&&(r=e,f=c)}for(;d.data!==t;)if(n=d,!(d=d.next))return this;return(o=d.next)&&delete d.next,n?(o?n.next=o:delete n.next,this):e?(o?e[c]=o:delete e[c],(d=e[0]||e[1]||e[2]||e[3])&&d===(e[3]||e[2]||e[1]||e[0])&&!d.length&&(r?r[f]=d:this._root=d),this):(this._root=o,this)},T.removeAll=function(t){for(var e=0,r=t.length;e<r;++e)this.remove(t[e]);return this},T.root=function(){return this._root},T.size=function(){var t=0;return this.visit((function(e){if(!e.length)do{++t}while(e=e.next)})),t},T.visit=function(t){var e,r,n,o,i,s,a=[],u=this._root;for(u&&a.push(new k(u,this._x0,this._y0,this._x1,this._y1));e=a.pop();)if(!t(u=e.node,n=e.x0,o=e.y0,i=e.x1,s=e.y1)&&u.length){var h=(n+i)/2,l=(o+s)/2;(r=u[3])&&a.push(new k(r,h,l,i,s)),(r=u[2])&&a.push(new k(r,n,l,h,s)),(r=u[1])&&a.push(new k(r,h,o,i,l)),(r=u[0])&&a.push(new k(r,n,o,h,l))}return this},T.visitAfter=function(t){var e,r=[],n=[];for(this._root&&r.push(new k(this._root,this._x0,this._y0,this._x1,this._y1));e=r.pop();){var o=e.node;if(o.length){var i,s=e.x0,a=e.y0,u=e.x1,h=e.y1,l=(s+u)/2,c=(a+h)/2;(i=o[0])&&r.push(new k(i,s,a,l,c)),(i=o[1])&&r.push(new k(i,l,a,u,c)),(i=o[2])&&r.push(new k(i,s,c,l,h)),(i=o[3])&&r.push(new k(i,l,c,u,h))}n.push(e)}for(;e=n.pop();)t(e.node,e.x0,e.y0,e.x1,e.y1);return this},T.x=function(t){return arguments.length?(this._x=t,this):this._x},T.y=function(t){return arguments.length?(this._y=t,this):this._y};var P={value:()=>{}};function L(){for(var t,e=0,r=arguments.length,n={};e<r;++e){if(!(t=arguments[e]+"")||t in n||/[\\s.]/.test(t))throw new Error("illegal type: "+t);n[t]=[]}return new q(n)}function q(t){this._=t}function j(t,e){return t.trim().split(/^|\\s+/).map((function(t){var r="",n=t.indexOf(".");if(n>=0&&(r=t.slice(n+1),t=t.slice(0,n)),t&&!e.hasOwnProperty(t))throw new Error("unknown type: "+t);return{type:t,name:r}}))}function V(t,e){for(var r,n=0,o=t.length;n<o;++n)if((r=t[n]).name===e)return r.value}function F(t,e,r){for(var n=0,o=t.length;n<o;++n)if(t[n].name===e){t[n]=P,t=t.slice(0,n).concat(t.slice(n+1));break}return null!=r&&t.push({name:e,value:r}),t}q.prototype=L.prototype={constructor:q,on:function(t,e){var r,n=this._,o=j(t+"",n),i=-1,s=o.length;if(!(arguments.length<2)){if(null!=e&&"function"!=typeof e)throw new Error("invalid callback: "+e);for(;++i<s;)if(r=(t=o[i]).type)n[r]=F(n[r],t.name,e);else if(null==e)for(r in n)n[r]=F(n[r],t.name,null);return this}for(;++i<s;)if((r=(t=o[i]).type)&&(r=V(n[r],t.name)))return r},copy:function(){var t={},e=this._;for(var r in e)t[r]=e[r].slice();return new q(t)},call:function(t,e){if((r=arguments.length-2)>0)for(var r,n,o=new Array(r),i=0;i<r;++i)o[i]=arguments[i+2];if(!this._.hasOwnProperty(t))throw new Error("unknown type: "+t);for(i=0,r=(n=this._[t]).length;i<r;++i)n[i].value.apply(e,o)},apply:function(t,e,r){if(!this._.hasOwnProperty(t))throw new Error("unknown type: "+t);for(var n=this._[t],o=0,i=n.length;o<i;++o)n[o].value.apply(e,r)}};const $=L;var U,B,G=0,K=0,W=0,H=0,J=0,Y=0,X="object"==typeof performance&&performance.now?performance:Date,Q="object"==typeof window&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(t){setTimeout(t,17)};function Z(){return J||(Q(tt),J=X.now()+Y)}function tt(){J=0}function et(){this._call=this._time=this._next=null}function rt(t,e,r){var n=new et;return n.restart(t,e,r),n}function nt(){J=(H=X.now())+Y,G=K=0;try{!function(){Z(),++G;for(var t,e=U;e;)(t=J-e._time)>=0&&e._call.call(void 0,t),e=e._next;--G}()}finally{G=0,function(){for(var t,e,r=U,n=1/0;r;)r._call?(n>r._time&&(n=r._time),t=r,r=r._next):(e=r._next,r._next=null,r=t?t._next=e:U=e);B=t,it(n)}(),J=0}}function ot(){var t=X.now(),e=t-H;e>1e3&&(Y-=e,H=t)}function it(t){G||(K&&(K=clearTimeout(K)),t-J>24?(t<1/0&&(K=setTimeout(nt,t-X.now()-Y)),W&&(W=clearInterval(W))):(W||(H=X.now(),W=setInterval(ot,1e3)),G=1,Q(nt)))}et.prototype=rt.prototype={constructor:et,restart:function(t,e,r){if("function"!=typeof t)throw new TypeError("callback is not a function");r=(null==r?Z():+r)+(null==e?0:+e),this._next||B===this||(B?B._next=this:U=this,B=this),this._call=t,this._time=r,it()},stop:function(){this._call&&(this._call=null,this._time=1/0,it())}};const st=4294967296;function at(t){return t.x}function ut(t){return t.y}var ht=Math.PI*(3-Math.sqrt(5));function lt(t){var e,r=1,n=.001,o=1-Math.pow(n,1/300),i=0,s=.6,a=new Map,u=rt(c),h=$("tick","end"),l=function(){let t=1;return()=>(t=(1664525*t+1013904223)%st)/st}();function c(){f(),h.call("tick",e),r<n&&(u.stop(),h.call("end",e))}function f(n){var u,h,l=t.length;void 0===n&&(n=1);for(var c=0;c<n;++c)for(r+=(i-r)*o,a.forEach((function(t){t(r)})),u=0;u<l;++u)null==(h=t[u]).fx?h.x+=h.vx*=s:(h.x=h.fx,h.vx=0),null==h.fy?h.y+=h.vy*=s:(h.y=h.fy,h.vy=0);return e}function d(){for(var e,r=0,n=t.length;r<n;++r){if((e=t[r]).index=r,null!=e.fx&&(e.x=e.fx),null!=e.fy&&(e.y=e.fy),isNaN(e.x)||isNaN(e.y)){var o=10*Math.sqrt(.5+r),i=r*ht;e.x=o*Math.cos(i),e.y=o*Math.sin(i)}(isNaN(e.vx)||isNaN(e.vy))&&(e.vx=e.vy=0)}}function g(e){return e.initialize&&e.initialize(t,l),e}return null==t&&(t=[]),d(),e={tick:f,restart:function(){return u.restart(c),e},stop:function(){return u.stop(),e},nodes:function(r){return arguments.length?(t=r,d(),a.forEach(g),e):t},alpha:function(t){return arguments.length?(r=+t,e):r},alphaMin:function(t){return arguments.length?(n=+t,e):n},alphaDecay:function(t){return arguments.length?(o=+t,e):+o},alphaTarget:function(t){return arguments.length?(i=+t,e):i},velocityDecay:function(t){return arguments.length?(s=1-t,e):1-s},randomSource:function(t){return arguments.length?(l=t,a.forEach(g),e):l},force:function(t,r){return arguments.length>1?(null==r?a.delete(t):a.set(t,g(r)),e):a.get(t)},find:function(e,r,n){var o,i,s,a,u,h=0,l=t.length;for(null==n?n=1/0:n*=n,h=0;h<l;++h)(s=(o=e-(a=t[h]).x)*o+(i=r-a.y)*i)<n&&(u=a,n=s);return u},on:function(t,r){return arguments.length>1?(h.on(t,r),e):h.on(t)}}}function ct(){var t,e,r,n,o,i=C(-30),s=1,a=1/0,u=.81;function h(r){var o,i=t.length,s=R(t,at,ut).visitAfter(c);for(n=r,o=0;o<i;++o)e=t[o],s.visit(f)}function l(){if(t){var e,r,n=t.length;for(o=new Array(n),e=0;e<n;++e)r=t[e],o[r.index]=+i(r,e,t)}}function c(t){var e,r,n,i,s,a=0,u=0;if(t.length){for(n=i=s=0;s<4;++s)(e=t[s])&&(r=Math.abs(e.value))&&(a+=e.value,u+=r,n+=r*e.x,i+=r*e.y);t.x=n/u,t.y=i/u}else{(e=t).x=e.data.x,e.y=e.data.y;do{a+=o[e.data.index]}while(e=e.next)}t.value=a}function f(t,i,h,l){if(!t.value)return!0;var c=t.x-e.x,f=t.y-e.y,d=l-i,g=c*c+f*f;if(d*d/u<g)return g<a&&(0===c&&(g+=(c=O(r))*c),0===f&&(g+=(f=O(r))*f),g<s&&(g=Math.sqrt(s*g)),e.vx+=c*t.value*n/g,e.vy+=f*t.value*n/g),!0;if(!(t.length||g>=a)){(t.data!==e||t.next)&&(0===c&&(g+=(c=O(r))*c),0===f&&(g+=(f=O(r))*f),g<s&&(g=Math.sqrt(s*g)));do{t.data!==e&&(d=o[t.data.index]*n/g,e.vx+=c*d,e.vy+=f*d)}while(t=t.next)}}return h.initialize=function(e,n){t=e,r=n,l()},h.strength=function(t){return arguments.length?(i="function"==typeof t?t:C(+t),l(),h):i},h.distanceMin=function(t){return arguments.length?(s=t*t,h):Math.sqrt(s)},h.distanceMax=function(t){return arguments.length?(a=t*t,h):Math.sqrt(a)},h.theta=function(t){return arguments.length?(u=t*t,h):Math.sqrt(u)},h}function ft(t){return t.index}function dt(t,e){var r=t.get(e);if(!r)throw new Error("node not found: "+e);return r}function gt(t){var e,r,n,o,i,s,a=ft,u=function(t){return 1/Math.min(o[t.source.index],o[t.target.index])},h=C(30),l=1;function c(n){for(var o=0,a=t.length;o<l;++o)for(var u,h,c,f,d,g,p,m=0;m<a;++m)h=(u=t[m]).source,f=(c=u.target).x+c.vx-h.x-h.vx||O(s),d=c.y+c.vy-h.y-h.vy||O(s),f*=g=((g=Math.sqrt(f*f+d*d))-r[m])/g*n*e[m],d*=g,c.vx-=f*(p=i[m]),c.vy-=d*p,h.vx+=f*(p=1-p),h.vy+=d*p}function f(){if(n){var s,u,h=n.length,l=t.length,c=new Map(n.map(((t,e)=>[a(t,e,n),t])));for(s=0,o=new Array(h);s<l;++s)(u=t[s]).index=s,"object"!=typeof u.source&&(u.source=dt(c,u.source)),"object"!=typeof u.target&&(u.target=dt(c,u.target)),o[u.source.index]=(o[u.source.index]||0)+1,o[u.target.index]=(o[u.target.index]||0)+1;for(s=0,i=new Array(l);s<l;++s)u=t[s],i[s]=o[u.source.index]/(o[u.source.index]+o[u.target.index]);e=new Array(l),d(),r=new Array(l),g()}}function d(){if(n)for(var r=0,o=t.length;r<o;++r)e[r]=+u(t[r],r,t)}function g(){if(n)for(var e=0,o=t.length;e<o;++e)r[e]=+h(t[e],e,t)}return null==t&&(t=[]),c.initialize=function(t,e){n=t,s=e,f()},c.links=function(e){return arguments.length?(t=e,f(),c):t},c.id=function(t){return arguments.length?(a=t,c):a},c.iterations=function(t){return arguments.length?(l=+t,c):l},c.strength=function(t){return arguments.length?(u="function"==typeof t?t:C(+t),d(),c):u},c.distance=function(t){return arguments.length?(h="function"==typeof t?t:C(+t),g(),c):h},c}function pt(t){return t.x+t.vx}function mt(t){return t.y+t.vy}function yt(t){var e,r,n,o=1,i=1;function s(){for(var t,s,u,h,l,c,f,d=e.length,g=0;g<i;++g)for(s=R(e,pt,mt).visitAfter(a),t=0;t<d;++t)u=e[t],c=r[u.index],f=c*c,h=u.x+u.vx,l=u.y+u.vy,s.visit(p);function p(t,e,r,i,s){var a=t.data,d=t.r,g=c+d;if(!a)return e>h+g||i<h-g||r>l+g||s<l-g;if(a.index>u.index){var p=h-a.x-a.vx,m=l-a.y-a.vy,y=p*p+m*m;y<g*g&&(0===p&&(y+=(p=O(n))*p),0===m&&(y+=(m=O(n))*m),y=(g-(y=Math.sqrt(y)))/y*o,u.vx+=(p*=y)*(g=(d*=d)/(f+d)),u.vy+=(m*=y)*g,a.vx-=p*(g=1-g),a.vy-=m*g)}}}function a(t){if(t.data)return t.r=r[t.data.index];for(var e=t.r=0;e<4;++e)t[e]&&t[e].r>t.r&&(t.r=t[e].r)}function u(){if(e){var n,o,i=e.length;for(r=new Array(i),n=0;n<i;++n)o=e[n],r[o.index]=+t(o,n,e)}}return"function"!=typeof t&&(t=C(null==t?1:+t)),s.initialize=function(t,r){e=t,n=r,u()},s.iterations=function(t){return arguments.length?(i=+t,s):i},s.strength=function(t){return arguments.length?(o=+t,s):o},s.radius=function(e){return arguments.length?(t="function"==typeof e?e:C(+e),u(),s):t},s}function wt(t){var e,r,n,o=C(.1);function i(t){for(var o,i=0,s=e.length;i<s;++i)(o=e[i]).vx+=(n[i]-o.x)*r[i]*t}function s(){if(e){var i,s=e.length;for(r=new Array(s),n=new Array(s),i=0;i<s;++i)r[i]=isNaN(n[i]=+t(e[i],i,e))?0:+o(e[i],i,e)}}return"function"!=typeof t&&(t=C(null==t?0:+t)),i.initialize=function(t){e=t,s()},i.strength=function(t){return arguments.length?(o="function"==typeof t?t:C(+t),s(),i):o},i.x=function(e){return arguments.length?(t="function"==typeof e?e:C(+e),s(),i):t},i}function vt(t){var e,r,n,o=C(.1);function i(t){for(var o,i=0,s=e.length;i<s;++i)(o=e[i]).vy+=(n[i]-o.y)*r[i]*t}function s(){if(e){var i,s=e.length;for(r=new Array(s),n=new Array(s),i=0;i<s;++i)r[i]=isNaN(n[i]=+t(e[i],i,e))?0:+o(e[i],i,e)}}return"function"!=typeof t&&(t=C(null==t?0:+t)),i.initialize=function(t){e=t,s()},i.strength=function(t){return arguments.length?(o="function"==typeof t?t:C(+t),s(),i):o},i.y=function(e){return arguments.length?(t="function"==typeof e?e:C(+e),s(),i):t},i}function xt(){function t(t){return function(){return t}}var e,r=function(t){return t.cluster},n=t(1),i=t(-1),s=t(100),a=t(.1),u=[0,0],h=[],l={},c=[],f=100,d=100,g={none:{x:0,y:0}},p=[],m="force",y=!0,w=.1;function v(t){if(!y)return v;e.tick(),M();for(var n=0,o=h.length,i=void 0,s=t*w;n<o;++n)(i=h[n]).vx+=(g[r(i)].x-i.x)*s,i.vy+=(g[r(i)].y-i.y)*s}function x(){h&&function(){if(h&&h.length){if(void 0===r(h[0]))throw Error("Couldnt find the grouping attribute for the nodes. Make sure to set it up with forceInBox.groupBy(\'clusterAttr\') before calling .links()");var t,u,g,m,y,w=(t=[],u=[],g={},{},y=[],m=function(t){var e={};return t.forEach((function(t){var n=r(t);e[n]||(e[n]={count:0,sumforceNodeSize:0})})),t.forEach((function(t){var o=r(t),i=n(t),s=e[o];s.count=s.count+1,s.sumforceNodeSize=s.sumforceNodeSize+Math.PI*(i*i)*1.3,e[o]=s})),e}(h),y=function(t){var e={},n=[];return t.forEach((function(t){var n,o,i,s,a,u=(o=(n=t).source,i=n.target,(s=r(l[o]))<=(a=r(l[i]))?"".concat(s,"~").concat(a):"".concat(a,"~").concat(s)),h=0;void 0!==e[u]&&(h=e[u]),h+=1,e[u]=h})),Object.entries(e).forEach((function(t){var e=o(t,2),r=e[0],i=e[1],s=r.split("~")[0],a=r.split("~")[1];void 0!==s&&void 0!==a&&n.push({source:s,target:a,count:i})})),n}(c),Object.keys(m).forEach((function(e,r){var n=m[e];t.push({id:e,size:n.count,r:Math.sqrt(n.sumforceNodeSize/Math.PI)}),g[e]=r})),y.forEach((function(t){var e=t.source,r=t.target,n=g[e],o=g[r];void 0!==n&&void 0!==o&&u.push({source:n,target:o,count:t.count})})),{nodes:t,links:u});e=lt(w.nodes).force("x",wt(f).strength(.1)).force("y",vt(d).strength(.1)).force("collide",yt((function(t){return t.r})).iterations(4)).force("charge",ct().strength(i)).force("links",gt(w.nodes.length?w.links:[]).distance(s).strength(a)),p=e.nodes(),M()}}()}function M(){return g={none:{x:0,y:0}},p.forEach((function(t){g[t.id]={x:t.x-u[0],y:t.y-u[1]}})),g}function b(t){l={},t.forEach((function(t){l[t.id]=t}))}return v.initialize=function(t){h=t,x()},v.template=function(t){return arguments.length?(m=t,x(),v):m},v.groupBy=function(t){return arguments.length?"string"==typeof t?(r=function(e){return e[t]},v):(r=t,v):r},v.enableGrouping=function(t){return arguments.length?(y=t,v):y},v.strength=function(t){return arguments.length?(w=t,v):w},v.centerX=function(t){return arguments.length?(f=t,v):f},v.centerY=function(t){return arguments.length?(d=t,v):d},v.nodes=function(t){return arguments.length?(b(t||[]),h=t||[],v):h},v.links=function(t){return arguments.length?(c=t||[],x(),v):c},v.forceNodeSize=function(e){return arguments.length?(n="function"==typeof e?e:t(+e),x(),v):n},v.nodeSize=v.forceNodeSize,v.forceCharge=function(e){return arguments.length?(i="function"==typeof e?e:t(+e),x(),v):i},v.forceLinkDistance=function(e){return arguments.length?(s="function"==typeof e?e:t(+e),x(),v):s},v.forceLinkStrength=function(e){return arguments.length?(a="function"==typeof e?e:t(+e),x(),v):a},v.offset=function(t){return arguments.length?(u=t,v):u},v.getFocis=M,v}var Mt={center:[0,0],preventOverlap:!1,nodeSize:void 0,nodeSpacing:void 0,linkDistance:50,forceSimulation:null,alphaDecay:.028,alphaMin:.001,alpha:.3,collideStrength:1,clustering:!1,clusterNodeStrength:-1,clusterEdgeStrength:.1,clusterEdgeDistance:100,clusterFociStrength:.8,clusterNodeSize:10},bt=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="d3force",this.running=!1,this.options=r(r({},Mt),t)}return t.prototype.execute=function(t,e){return this.genericForceLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericForceLayout(!0,t,e)},t.prototype.stop=function(){var t;null===(t=this.forceSimulation)||void 0===t||t.stop(),this.running=!1},t.prototype.restart=function(){var t;null===(t=this.forceSimulation)||void 0===t||t.restart(),this.running=!0},t.prototype.tick=function(t){var e=this;void 0===t&&(t=1),this.forceSimulation.tick(t);var r={nodes:Et(this.lastLayoutNodes),edges:Nt(this.lastLayoutEdges)};return this.lastAssign&&r.nodes.forEach((function(t){return e.lastGraph.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})})),this.lastOptions.onLayoutEnd&&this.lastOptions.onLayoutEnd(r),r},t.prototype.genericForceLayout=function(t,e,n){var o=this,i=r(r({},this.options),n),s=i.layoutInvisibles,a=e.getAllNodes(),u=e.getAllEdges();s||(a=a.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e})),u=u.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e})));var h=a.map((function(t){var e,n;return r(r({},m(t)),{x:null===(e=t.data)||void 0===e?void 0:e.x,y:null===(n=t.data)||void 0===n?void 0:n.y})})),l=u.map((function(t){return m(t)}));if(this.lastLayoutNodes=h,this.lastLayoutEdges=l,this.lastAssign=t,this.lastGraph=e,this.lastOptions=i,!this.running){var c=i.alphaMin,f=i.alphaDecay,d=i.alpha,g=i.nodeStrength,p=i.edgeStrength,y=i.linkDistance,w=i.clustering,v=i.clusterFociStrength,x=i.clusterEdgeDistance,M=i.clusterEdgeStrength,b=i.clusterNodeStrength,E=i.clusterNodeSize,N=i.collideStrength,S=void 0===N?1:N,A=i.center,k=void 0===A?[0,0]:A,I=i.preventOverlap,D=i.nodeSize,R=i.nodeSpacing,_=i.onTick,z=i.onLayoutEnd,T=i.forceSimulation;if(T)w&&((C=xt()).nodes(h),C.links(l)),T.nodes(h),l&&(P=gt().id((function(t){return t.id})).links(l),p&&P.strength(p),y&&P.distance(y),T.force("link",P)),I&&this.overlapProcess(T,{nodeSize:D,nodeSpacing:R,collideStrength:S}),T.alpha(d).restart(),this.running=!0;else try{var C,O=ct();if(g&&O.strength(g),T=lt().nodes(h),w&&((C=xt()).centerX(k[0]).centerY(k[1]).template("force").strength(v),l&&C.links(l),h&&C.nodes(h),C.forceLinkDistance(x).forceLinkStrength(M).forceCharge(b).forceNodeSize(E),T.force("group",C)),T.force("center",function(t,e){var r,n=1;function o(){var o,i,s=r.length,a=0,u=0;for(o=0;o<s;++o)a+=(i=r[o]).x,u+=i.y;for(a=(a/s-t)*n,u=(u/s-e)*n,o=0;o<s;++o)(i=r[o]).x-=a,i.y-=u}return null==t&&(t=0),null==e&&(e=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.strength=function(t){return arguments.length?(n=+t,o):n},o}(k[0],k[1])).force("charge",O).alpha(d).alphaDecay(f).alphaMin(c),I&&this.overlapProcess(T,{nodeSize:D,nodeSpacing:R,collideStrength:S}),l){var P=gt().id((function(t){return t.id})).links(l);p&&P.strength(p),y&&P.distance(y),T.force("link",P)}T.on("tick",(function(){var r=Et(h);null==_||_({nodes:r,edges:Nt(l)}),t&&r.forEach((function(t){return e.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}))})).on("end",(function(){o.running=!1;var r=Et(h);null==z||z({nodes:r,edges:Nt(l)}),t&&r.forEach((function(t){return e.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}))})),this.running=!0}catch(t){this.running=!1,console.warn(t)}this.forceSimulation=T;var L=Et(h),q=Nt(l);return t&&L.forEach((function(t){return e.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})})),{nodes:L,edges:q}}},t.prototype.overlapProcess=function(t,e){var r,n,o=e.nodeSize,i=e.nodeSpacing,s=e.collideStrength;if(n=l(i)?function(){return i}:y(i)?i:function(){return 0},o)if(y(o))r=function(t){return o(t)+n(t)};else if(h(o)){var a=(o[0]>o[1]?o[0]:o[1])/2;r=function(t){return a+n(t)}}else if(l(o)){var u=o/2;r=function(t){return u+n(t)}}else r=function(){return 10};else r=function(t){return t.size?h(t.size)?(t.size[0]>t.size[1]?t.size[0]:t.size[1])/2+n(t):g(t.size)?(t.size.width>t.size.height?t.size.width:t.size.height)/2+n(t):t.size/2+n(t):10+n(t)};t.force("collisionForce",yt(r).strength(s))},t}(),Et=function(t){return t.map((function(t){var e=t.x,o=t.y,i=n(t,["x","y"]);return r(r({},i),{data:r(r({},i.data),{x:e,y:o})})}))},Nt=function(t){return t.map((function(t){var e=t.source,o=t.target,i=n(t,["source","target"]);return r(r({},i),{source:e.id,target:o.id})}))};function St(t){var e=0,r=0,n=0;if(t.length){for(var o=0;o<4;o++)(i=t[o])&&i.weight&&(e+=i.weight,r+=i.x*i.weight,n+=i.y*i.weight);t.x=r/e,t.y=n/e,t.weight=e}else{var i=t;t.x=i.data.x,t.y=i.data.y,t.weight=i.data.weight}}var At={maxIteration:500,gravity:10,animate:!0,factor:1,edgeStrength:200,nodeStrength:1e3,coulombDisScale:.005,damping:.9,maxSpeed:500,minMovement:.4,interval:.02,linkDistance:200,clusterNodeStrength:20,preventOverlap:!0,distanceThresholdMode:"mean"},kt=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="force",this.timeInterval=0,this.judgingDistance=0,this.options=r(r({},At),t)}return t.prototype.execute=function(t,e){return this.genericForceLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericForceLayout(!0,t,e)},t.prototype.genericForceLayout=function(t,e,n){var o=this,i=r(r({},this.options),n),a=e.getAllNodes(),u=e.getAllEdges();i.layoutInvisibles||(a=a.filter((function(t){return t.data.visible||void 0===t.data.visible})),u=u.filter((function(t){return t.data.visible||void 0===t.data.visible})));var h=this.formatOptions(i,e),c=h.width,f=h.height,d=h.nodeSize,g=h.getMass,p=h.nodeStrength,m=h.edgeStrength,y=h.linkDistance,w=a.map((function(t){return r(r({},t),{data:r(r({},t.data),{x:l(t.data.x)?t.data.x:Math.random()*c,y:l(t.data.y)?t.data.y:Math.random()*f,size:d(t)||30,mass:g(t),nodeStrength:p(t)})})})),v=u.map((function(t){return r(r({},t),{data:r(r({},t.data),{edgeStrength:m(t),linkDistance:y(t,e.getNode(t.source),e.getNode(t.target))})})}));if(!(null==a?void 0:a.length))return{nodes:[],edges:u};var x={};a.forEach((function(t,e){x[t.id]={x:0,y:0}}));var M=new s({nodes:w,edges:v});this.formatCentripetal(h,M);var b=h.maxIteration,E=h.animate,N=h.minMovement,S=h.onLayoutEnd,A=h.onTick;if(!E){for(var k=0;(this.judgingDistance>N||k<1)&&k<b;k++)this.runOneStep(M,e,k,x,h),this.updatePosition(e,M,x,h),t&&w.forEach((function(t){return e.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})})),null==A||A({nodes:zt(e,w),edges:u});t&&w.forEach((function(t){return e.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}));var I={nodes:zt(e,w),edges:u};return null==S||S(I),I}if("undefined"!=typeof window){var D=0;return this.timeInterval=window.setInterval((function(){a&&(o.runOneStep(M,e,D,x,h),o.updatePosition(e,M,x,h),t&&w.forEach((function(t){return e.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})})),null==A||A({nodes:zt(e,w),edges:u}),(++D>=b||o.judgingDistance<N)&&(null==S||S({nodes:zt(e,w),edges:u}),window.clearInterval(o.timeInterval)))}),0),{nodes:zt(e,w),edges:u}}},t.prototype.formatOptions=function(t,e){var r=t,n=t.width,o=t.height,i=t.getMass;if(r.width=n||"undefined"==typeof window?n:window.innerWidth,r.height=o||"undefined"==typeof window?o:window.innerHeight,t.center||(r.center=[r.width/2,r.height/2]),i||(r.getMass=function(t){var r=1;l(null==t?void 0:t.data.mass)&&(r=null==t?void 0:t.data.mass);var n=e.getDegree(t.id,"both");return!n||n<5?r:5*n*r}),t.preventOverlap){var s=w(0,t.nodeSpacing);t.nodeSize?h(t.nodeSize)?r.nodeSize=function(e){var r=t.nodeSize;return Math.max(r[0],r[1])+s(e)}:r.nodeSize=function(e){return t.nodeSize+s(e)}:r.nodeSize=function(t){var e=((null==t?void 0:t.data)||{}).size;return e?h(e)?Math.max(e[0],e[1])+s(t):g(e)?Math.max(e.width,e.height)+s(t):e+s(t):10+s(t)}}return r.linkDistance=t.linkDistance?w(1,t.linkDistance):function(t){return 1+r.nodeSize(e.getNode(t.source))+r.nodeSize(e.getNode(t.target))},r.nodeStrength=w(1,t.nodeStrength),r.edgeStrength=w(1,t.edgeStrength),t},t.prototype.formatCentripetal=function(t,e){var r,n=t.centripetalOptions,o=t.center,i=t.clusterNodeStrength,s=t.leafCluster,a=t.clustering,u=t.nodeClusterBy,h=e.getAllNodes(),l=n||{leaf:2,single:2,others:1,center:function(t){return{x:o[0],y:o[1]}}};"function"!=typeof i&&(t.clusterNodeStrength=function(t){return i});var c=[];if(s&&u&&(r=It(e,u),c=Array.from(new Set(null==h?void 0:h.map((function(t){return t.data[u]}))))||[],t.centripetalOptions=Object.assign(l,{single:100,leaf:function(e){var n=r[e.id]||{},o=n.siblingLeaves,i=n.sameTypeLeaves;return(null==i?void 0:i.length)===(null==o?void 0:o.length)||1===(null==c?void 0:c.length)?1:t.clusterNodeStrength(e)},others:1,center:function(t){var n,o=e.getDegree(t.id,"both");if(!o)return{x:100,y:100};if(1===o){var i=(r[t.id]||{}).sameTypeLeaves,s=void 0===i?[]:i;1===s.length?n=void 0:s.length>1&&(n=_t(s))}else n=void 0;return{x:null==n?void 0:n.x,y:null==n?void 0:n.y}}})),a&&u){r||(r=It(e,u)),c||(c=Array.from(new Set(h.map((function(t){return t.data[u]}))))),c=c.filter((function(t){return void 0!==t}));var f={};c.forEach((function(t){var r=h.filter((function(e){return e.data[u]===t})).map((function(t){return e.getNode(t.id)}));f[t]=_t(r)})),t.centripetalOptions=Object.assign(l,{single:function(e){return t.clusterNodeStrength(e)},leaf:function(e){return t.clusterNodeStrength(e)},others:function(e){return t.clusterNodeStrength(e)},center:function(t){var e=f[t.data[u]];return{x:null==e?void 0:e.x,y:null==e?void 0:e.y}}})}var d=t.centripetalOptions,g=d.leaf,p=d.single,m=d.others;g&&"function"!=typeof g&&(t.centripetalOptions.leaf=function(){return g}),p&&"function"!=typeof p&&(t.centripetalOptions.single=function(){return p}),m&&"function"!=typeof m&&(t.centripetalOptions.others=function(){return m})},t.prototype.runOneStep=function(t,e,r,n,o){var i={},s=t.getAllNodes(),a=t.getAllEdges();if(null==s?void 0:s.length){var u=o.monitor;this.calRepulsive(t,i,o),a&&this.calAttractive(t,i),this.calGravity(t,e,i,o),this.updateVelocity(t,i,n,o),u&&u({energy:this.calTotalEnergy(i,s),nodes:e.getAllNodes(),edges:e.getAllEdges(),iterations:r})}},t.prototype.calTotalEnergy=function(t,e){if(!(null==e?void 0:e.length))return 0;var r=0;return e.forEach((function(e,n){var o=t[e.id].x,i=t[e.id].y,s=o*o+i*i,a=e.data.mass;r+=(void 0===a?1:a)*s*.5})),r},t.prototype.calRepulsive=function(t,e,r){var n=r.factor,o=r.coulombDisScale;!function(t,e,r,n){var o=e/r,i=t.getAllNodes(),s=i.map((function(t,e){var r=t.data,n=r.nodeStrength;return{x:r.x,y:r.y,size:r.size,index:e,vx:0,vy:0,weight:o*n}})),a=R(s,(function(t){return t.x}),(function(t){return t.y})).visitAfter(St);s.forEach((function(t){!function(t,e){e.visit((function(e,r,n,o,i){return function(t,e,r,n,o,i){var s=i.x-t.x||.1,a=i.y-t.y||.1,u=n-e,h=s*s+a*a,l=Math.sqrt(h)*h;if(u*u*.81<h){var c=t.weight/l;return i.vx+=s*c,i.vy+=a*c,!0}if(t.length)return!1;t.data!==i&&(c=t.data.weight/l,i.vx+=s*c,i.vy+=a*c)}(e,r,0,o,0,t)}))}(t,a)})),s.map((function(t,e){var r=i[e],o=r.id,s=r.data.mass,a=void 0===s?1:s;n[o]={x:t.vx/a,y:t.vy/a}}))}(t,n,o*o,e)},t.prototype.calAttractive=function(t,e){t.getAllEdges().forEach((function(r,n){var o=r.source,i=r.target,s=t.getNode(o),a=t.getNode(i);if(s&&a){var u=a.data.x-s.data.x,h=a.data.y-s.data.y;u||h||(u=.01*Math.random(),h=.01*Math.random());var l=Math.sqrt(u*u+h*h),c=u/l,f=h/l,d=edgeInfos[n]||{},g=d.linkDistance,p=void 0===g?200:g,m=d.edgeStrength,y=(p-l)*(void 0===m?200:m),w=1/(s.data.mass||1),v=1/(a.data.mass||1),x=c*y,M=f*y;e[o].x-=x*w,e[o].y-=M*w,e[i].x+=x*v,e[i].y+=M*v}}))},t.prototype.calGravity=function(t,e,r,n){var i=n.getCenter,s=t.getAllNodes(),a=e.getAllNodes(),u=e.getAllEdges(),h=n.width,c=n.height,f=n.center,d=n.gravity,g=n.centripetalOptions;s&&s.forEach((function(n){var s=n.id,p=n.data,m=p.mass,y=p.x,w=p.y,v=e.getNode(s),x=0,M=0,b=d,E=t.getDegree(s,"in"),N=t.getDegree(s,"out"),S=t.getDegree(s,"both"),A=null==i?void 0:i(v,S);if(A){var k=o(A,3);x=y-k[0],M=w-k[1],b=k[2]}else x=y-f[0],M=w-f[1];if(b&&(r[s].x-=b*x/m,r[s].y-=b*M/m),g){var I=g.leaf,D=g.single,R=g.others,_=g.center,z=(null==_?void 0:_(v,a,u,h,c))||{x:0,y:0,centerStrength:0},T=z.x,C=z.y,O=z.centerStrength;if(!l(T)||!l(C))return;var P=(y-T)/m,L=(w-C)/m;if(O&&(r[s].x-=O*P,r[s].y-=O*L),0===S){var q=D(v);if(!q)return;return r[s].x-=q*P,void(r[s].y-=q*L)}if(0===E||0===N){var j=I(v,a,u);if(!j)return;return r[s].x-=j*P,void(r[s].y-=j*L)}var V=R(v);if(!V)return;r[s].x-=V*P,r[s].y-=V*L}}))},t.prototype.updateVelocity=function(t,e,r,n){var o=n.damping,i=n.maxSpeed,s=n.interval,a=t.getAllNodes();(null==a?void 0:a.length)&&a.forEach((function(t){var n=t.id,a=(r[n].x+e[n].x*s)*o||.01,u=(r[n].y+e[n].y*s)*o||.01,h=Math.sqrt(a*a+u*u);if(h>i){var l=i/h;a*=l,u*=l}r[n]={x:a,y:u}}))},t.prototype.updatePosition=function(t,e,r,n){var o=this,i=n.distanceThresholdMode,s=n.interval,a=e.getAllNodes();if(null==a?void 0:a.length){var u=0;"max"===i?this.judgingDistance=-1/0:"min"===i&&(this.judgingDistance=1/0),a.forEach((function(n){var a=n.id,h=t.getNode(a);if(l(h.data.fx)&&l(h.data.fy))e.mergeNodeData(a,{x:h.data.fx,y:h.data.fy});else{var c=r[a].x*s,f=r[a].y*s;e.mergeNodeData(a,{x:n.data.x+c,y:n.data.y+f});var d=Math.sqrt(c*c+f*f);switch(i){case"max":o.judgingDistance<d&&(o.judgingDistance=d);break;case"min":o.judgingDistance>d&&(o.judgingDistance=d);break;default:u+=d}}})),i&&"mean"!==i||(this.judgingDistance=u/a.length)}else this.judgingDistance=0},t.prototype.stop=function(){this.timeInterval&&"undefined"!=typeof window&&window.clearInterval(this.timeInterval)},t}(),It=function(t,e){var r=t.getAllNodes();if(!(null==r?void 0:r.length))return{};var n={};return r.forEach((function(r,o){1===t.getDegree(r.id,"both")&&(n[r.id]=Dt(t,"leaf",r,e))})),n},Dt=function(t,e,r,n){var o=t.getDegree(r.id,"in"),i=t.getDegree(r.id,"out"),s=r,a=[];return 0===o?(s=t.getSuccessors(r.id)[0],a=t.getNeighbors(s.id)):0===i&&(s=t.getPredecessors(r.id)[0],a=t.getNeighbors(s.id)),a=a.filter((function(e){return 0===t.getDegree(e.id,"in")||0===t.getDegree(e.id,"out")})),{coreNode:s,siblingLeaves:a,sameTypeLeaves:Rt(t,e,n,r,a)}},Rt=function(t,e,r,n,o){var i=n.data[r]||"",s=(null==o?void 0:o.filter((function(t){return t.data[r]===i})))||[];return"leaf"===e&&(s=s.filter((function(e){return 0===t.getDegree(e.id,"in")||0===t.getDegree(e.id,"out")}))),s},_t=function(t){var e={x:0,y:0};t.forEach((function(t){var r=t.data,n=r.x,o=r.y;e.x+=n||0,e.y+=o||0}));var r=t.length||1;return{x:e.x/r,y:e.y/r}},zt=function(t,e){return e.map((function(e){var n=e.id,o=e.data,i=t.getNode(n);return r(r({},i),{data:r(r({},i.data),{x:o.x,y:o.y})})}))},Tt={maxIteration:1e3,gravity:10,speed:5,clustering:!1,clusterGravity:10,width:300,height:300,nodeClusterBy:"cluster"},Ct=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="fruchterman",this.timeInterval=0,this.running=!1,this.options=r(r({},Tt),t)}return t.prototype.execute=function(t,e){return this.genericFruchtermanLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericFruchtermanLayout(!0,t,e)},t.prototype.stop=function(){this.timeInterval&&"undefined"!=typeof window&&window.clearInterval(this.timeInterval),this.running=!1},t.prototype.restart=function(){this.running=!0},t.prototype.tick=function(t){var e=this;void 0===t&&(t=1);for(var r=0;r<t;r++)this.runOneStep(this.lastGraph,this.lastClusterMap,this.lastOptions);var n={nodes:this.lastLayoutNodes,edges:this.lastLayoutEdges};return this.lastAssign&&n.nodes.forEach((function(t){return e.lastGraph.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})})),this.lastOptions.onLayoutEnd&&this.lastOptions.onLayoutEnd(n),n},t.prototype.genericFruchtermanLayout=function(t,e,n){var o=this;if(!this.running){var i=this.formatOptions(n),a=i.layoutInvisibles,u=i.width,h=i.height,l=i.center,c=i.clustering,f=i.nodeClusterBy,d=i.maxIteration,g=i.onTick,p=i.onLayoutEnd,y=e.getAllNodes(),w=e.getAllEdges();if(a||(y=y.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e})),w=w.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e}))),!(null==y?void 0:y.length)){var v={nodes:[],edges:w};return null==p||p(v),v}if(1===y.length)return t&&e.mergeNodeData(y[0].id,{x:l[0],y:l[1]}),v={nodes:[r(r({},y[0]),{data:r(r({},y[0].data),{x:l[0],y:l[1]})})],edges:w},null==p||p(v),v;var x=y.map((function(t){return m(t,[u,h])})),M=new s({nodes:x,edges:w}),b={};if(c&&x.forEach((function(t){var e=t.data[f];b[e]||(b[e]={name:e,cx:0,cy:0,count:0})})),this.lastLayoutNodes=x,this.lastLayoutEdges=w,this.lastAssign=t,this.lastGraph=M,this.lastOptions=i,this.lastClusterMap=b,"undefined"!=typeof window){var E=0;return this.timeInterval=window.setInterval((function(){if(o.runOneStep(M,b,i),t&&x.forEach((function(t){var r=t.id,n=t.data;return e.mergeNodeData(r,{x:n.x,y:n.y})})),null==g||g({nodes:x,edges:w}),++E>=d){try{null==p||p({nodes:x,edges:w})}catch(t){console.warn("onLayoutEnd failed",t)}window.clearInterval(o.timeInterval)}}),0),{nodes:x,edges:w}}}},t.prototype.formatOptions=function(t){void 0===t&&(t={});var e=r(r({},this.options),t),n=e.clustering,o=e.nodeClusterBy,i=e.center,s=e.width,a=e.height;return e.width=s||"undefined"==typeof window?s:window.innerWidth,e.height=a||"undefined"==typeof window?a:window.innerHeight,e.center=i||[e.width/2,e.height/2],e.clustering=n&&!!o,e},t.prototype.runOneStep=function(t,e,r){var n=r.height,o=r.width,i=r.gravity,s=r.center,a=r.speed,u=r.clustering,h=r.nodeClusterBy,c=r.clusterGravity,f=n*o,d=Math.sqrt(f)/10,g=t.getAllNodes(),p=f/(g.length+1),m=Math.sqrt(p),y={};if(this.applyCalculate(t,y,m,p),u){for(var w in e)e[w].cx=0,e[w].cy=0,e[w].count=0;for(var w in g.forEach((function(t){var r=t.data,n=e[r[h]];l(r.x)&&(n.cx+=r.x),l(r.y)&&(n.cy+=r.y),n.count++})),e)e[w].cx/=e[w].count,e[w].cy/=e[w].count;var v=c||i;g.forEach((function(t,r){var n=t.id,o=t.data;if(l(o.x)&&l(o.y)){var i=e[o[h]],s=Math.sqrt((o.x-i.cx)*(o.x-i.cx)+(o.y-i.cy)*(o.y-i.cy)),a=m*v;y[n].x-=a*(o.x-i.cx)/s,y[n].y-=a*(o.y-i.cy)/s}}))}g.forEach((function(t,e){var r=t.id,n=t.data;if(l(n.x)&&l(n.y)){var o=.01*m*i;y[r].x-=o*(n.x-s[0]),y[r].y-=o*(n.y-s[1])}})),g.forEach((function(e,r){var n=e.id,o=e.data;if(l(o.fx)&&l(o.fy))return o.x=o.fx,void(o.y=o.fy);if(l(o.x)&&l(o.y)){var i=Math.sqrt(y[n].x*y[n].x+y[n].y*y[n].y);if(i>0){var s=Math.min(d*(a/800),i);t.mergeNodeData(n,{x:o.x+y[n].x/i*s,y:o.y+y[n].y/i*s})}}}))},t.prototype.applyCalculate=function(t,e,r,n){this.calRepulsive(t,e,n),this.calAttractive(t,e,r)},t.prototype.calRepulsive=function(t,e,r){var n=t.getAllNodes();n.forEach((function(t,o){var i=t.data,s=t.id;e[s]={x:0,y:0},n.forEach((function(t,n){var a=t.data,u=t.id;if(!(o<=n)&&l(i.x)&&l(a.x)&&l(i.y)&&l(a.y)){var h=i.x-a.x,c=i.y-a.y,f=h*h+c*c;0===f&&(f=1,h=.01,c=.01);var d=r/f,g=h*d,p=c*d;e[s].x+=g,e[s].y+=p,e[u].x-=g,e[u].y-=p}}))}))},t.prototype.calAttractive=function(t,e,r){t.getAllEdges().forEach((function(n){var o=n.source,i=n.target;if(o&&i&&o!==i){var s=t.getNode(o).data,a=t.getNode(i).data;if(l(a.x)&&l(s.x)&&l(a.y)&&l(s.y)){var u=a.x-s.x,h=a.y-s.y,c=Math.sqrt(u*u+h*h)/r,f=u*c,d=h*c;e[o].x+=f,e[o].y+=d,e[i].x-=f,e[i].y-=d}}}))},t}(),Ot={begin:[0,0],preventOverlap:!0,preventOverlapPadding:10,condense:!1,rows:void 0,cols:void 0,position:void 0,sortBy:"degree",nodeSize:30,width:300,height:300},Pt=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="grid",this.options=r(r({},Ot),t)}return t.prototype.execute=function(t,e){return this.genericGridLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericGridLayout(!0,t,e)},t.prototype.genericGridLayout=function(t,e,n){var o=r(r({},this.options),n),i=o.begin,s=void 0===i?[0,0]:i,u=o.condense,c=o.preventOverlapPadding,f=o.preventOverlap,d=o.rows,g=o.cols,p=o.nodeSpacing,y=o.nodeSize,x=o.width,M=o.height,b=o.layoutInvisibles,E=o.onLayoutEnd,N=o.position,S=o.sortBy,A=e.getAllNodes(),k=e.getAllEdges();b||(A=A.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e})),k=k.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e})));var I=A.length;if(0===I){var D={nodes:[],edges:k};return null==E||E(D),D}if(1===I){t&&e.mergeNodeData(A[0].id,{x:s[0],y:s[1]});var R={nodes:[r(r({},A[0]),{data:r(r({},A[0].data),{x:s[0],y:s[1]})})],edges:k};return null==E||E(R),R}var _=A.map((function(t){return m(t)}));"id"===S||a(S)&&void 0!==_[0].data[S]||(S="degree"),"degree"===S?_.sort((function(t,r){return e.getDegree(r.id,"both")-e.getDegree(t.id,"both")})):"id"===S?_.sort((function(t,e){return l(e.id)&&l(t.id)?e.id-t.id:"".concat(t.id).localeCompare("".concat(e.id))})):_.sort((function(t,e){return e.data[S]-t.data[S]}));var z=x||"undefined"==typeof window?x:window.innerWidth,T=M||"undefined"==typeof window?M:window.innerHeight,C=I,O={rows:d,cols:g};if(null!=d&&null!=g)O.rows=d,O.cols=g;else if(null!=d&&null==g)O.rows=d,O.cols=Math.ceil(C/O.rows);else if(null==d&&null!=g)O.cols=g,O.rows=Math.ceil(C/O.cols);else{var P=Math.sqrt(C*T/z);O.rows=Math.round(P),O.cols=Math.round(z/T*P)}if(O.rows=Math.max(O.rows,1),O.cols=Math.max(O.cols,1),O.cols*O.rows>C)((q=Lt(O))-1)*(L=qt(O))>=C?Lt(O,q-1):(L-1)*q>=C&&qt(O,L-1);else for(;O.cols*O.rows<C;){var L,q=Lt(O);((L=qt(O))+1)*q>=C?qt(O,L+1):Lt(O,q+1)}var j=u?0:z/O.cols,V=u?0:T/O.rows;if(f||p){var F=w(10,p),$=v(30,y,!1);_.forEach((function(t){t.data.x&&t.data.y||(t.data.x=0,t.data.y=0);var r,n,o=e.getNode(t.id),i=$(o)||30;h(i)?(r=i[0],n=i[1]):(r=i,n=i);var s=void 0!==F?F(t):c,a=r+s,u=n+s;j=Math.max(j,a),V=Math.max(V,u)}))}for(var U={},B={row:0,col:0},G={},K=0;K<_.length;K++){var W=_[K],H=void 0;if(N&&(H=N(e.getNode(W.id))),H&&(void 0!==H.row||void 0!==H.col)){var J={row:H.row,col:H.col};if(void 0===J.col)for(J.col=0;jt(U,J);)J.col++;else if(void 0===J.row)for(J.row=0;jt(U,J);)J.row++;G[W.id]=J,Vt(U,J)}$t(W,s,j,V,G,O,B,U)}var Y={nodes:_,edges:k};return null==E||E(Y),t&&_.forEach((function(t){e.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})})),Y},t}(),Lt=function(t,e){var r,n=t.rows||5,o=t.cols||5;return null==e?r=Math.min(n,o):Math.min(n,o)===t.rows?t.rows=e:t.cols=e,r},qt=function(t,e){var r,n=t.rows||5,o=t.cols||5;return null==e?r=Math.max(n,o):Math.max(n,o)===t.rows?t.rows=e:t.cols=e,r},jt=function(t,e){return t["c-".concat(e.row,"-").concat(e.col)]||!1},Vt=function(t,e){return t["c-".concat(e.row,"-").concat(e.col)]=!0},Ft=function(t,e){var r=t.cols||5;e.col++,e.col>=r&&(e.col=0,e.row++)},$t=function(t,e,r,n,o,i,s,a){var u,h,l=o[t.id];if(l)u=l.col*r+r/2+e[0],h=l.row*n+n/2+e[1];else{for(;jt(a,s);)Ft(i,s);u=s.col*r+r/2+e[0],h=s.row*n+n/2+e[1],Vt(a,s),Ft(i,s)}t.data.x=u,t.data.y=h};const Ut=Object.prototype.toString;function Bt(t){return Ut.call(t).endsWith("Array]")}function Gt(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!Bt(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");var r=e.fromIndex,n=void 0===r?0:r,o=e.toIndex,i=void 0===o?t.length:o;if(n<0||n>=t.length||!Number.isInteger(n))throw new Error("fromIndex must be a positive integer smaller than length");if(i<=n||i>t.length||!Number.isInteger(i))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var s=t[n],a=n+1;a<i;a++)t[a]>s&&(s=t[a]);return s}function Kt(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!Bt(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");var r=e.fromIndex,n=void 0===r?0:r,o=e.toIndex,i=void 0===o?t.length:o;if(n<0||n>=t.length||!Number.isInteger(n))throw new Error("fromIndex must be a positive integer smaller than length");if(i<=n||i>t.length||!Number.isInteger(i))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var s=t[n],a=n+1;a<i;a++)t[a]<s&&(s=t[a]);return s}function Wt(t){var e,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!Bt(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");if(void 0!==r.output){if(!Bt(r.output))throw new TypeError("output option must be an array if specified");e=r.output}else e=new Array(t.length);var n=Kt(t),o=Gt(t);if(n===o)throw new RangeError("minimum and maximum input values are equal. Cannot rescale a constant array");var i=r.min,s=void 0===i?r.autoMinMax?n:0:i,a=r.max,u=void 0===a?r.autoMinMax?o:1:a;if(s>=u)throw new RangeError("min option must be smaller than max option");for(var h=(u-s)/(o-n),l=0;l<t.length;l++)e[l]=(t[l]-n)*h+s;return e}const Ht=" ".repeat(2),Jt=" ".repeat(4);function Yt(t,e={}){const{maxRows:r=15,maxColumns:n=10,maxNumSize:o=8,padMinus:i="auto"}=e;return`${t.constructor.name} {\\n${Ht}[\\n${Jt}${function(t,e,r,n,o){const{rows:i,columns:s}=t,a=Math.min(i,e),u=Math.min(s,r),h=[];if("auto"===o){o=!1;t:for(let e=0;e<a;e++)for(let r=0;r<u;r++)if(t.get(e,r)<0){o=!0;break t}}for(let e=0;e<a;e++){let r=[];for(let i=0;i<u;i++)r.push(Xt(t.get(e,i),n,o));h.push(`${r.join(" ")}`)}return u!==s&&(h[h.length-1]+=` ... ${s-r} more columns`),a!==i&&h.push(`... ${i-e} more rows`),h.join(`\\n${Jt}`)}(t,r,n,o,i)}\\n${Ht}]\\n${Ht}rows: ${t.rows}\\n${Ht}columns: ${t.columns}\\n}`}function Xt(t,e,r){return(t>=0&&r?` ${Qt(t,e-1)}`:Qt(t,e)).padEnd(e)}function Qt(t,e){let r=t.toString();if(r.length<=e)return r;let n=t.toFixed(e);if(n.length>e&&(n=t.toFixed(Math.max(0,e-(n.length-e)))),n.length<=e&&!n.startsWith("0.000")&&!n.startsWith("-0.000"))return n;let o=t.toExponential(e);return o.length>e&&(o=t.toExponential(Math.max(0,e-(o.length-e)))),o.slice(0)}function Zt(t,e,r){let n=r?t.rows:t.rows-1;if(e<0||e>n)throw new RangeError("Row index out of range")}function te(t,e,r){let n=r?t.columns:t.columns-1;if(e<0||e>n)throw new RangeError("Column index out of range")}function ee(t,e){if(e.to1DArray&&(e=e.to1DArray()),e.length!==t.columns)throw new RangeError("vector size must be the same as the number of columns");return e}function re(t,e){if(e.to1DArray&&(e=e.to1DArray()),e.length!==t.rows)throw new RangeError("vector size must be the same as the number of rows");return e}function ne(t,e,r,n,o){if(5!==arguments.length)throw new RangeError("expected 4 arguments");if(ie("startRow",e),ie("endRow",r),ie("startColumn",n),ie("endColumn",o),e>r||n>o||e<0||e>=t.rows||r<0||r>=t.rows||n<0||n>=t.columns||o<0||o>=t.columns)throw new RangeError("Submatrix indices are out of range")}function oe(t,e=0){let r=[];for(let n=0;n<t;n++)r.push(e);return r}function ie(t,e){if("number"!=typeof e)throw new TypeError(`${t} must be a number`)}function se(t){if(t.isEmpty())throw new Error("Empty matrix has no elements to index")}class ae{static from1DArray(t,e,r){if(t*e!==r.length)throw new RangeError("data length does not match given dimensions");let n=new he(t,e);for(let o=0;o<t;o++)for(let t=0;t<e;t++)n.set(o,t,r[o*e+t]);return n}static rowVector(t){let e=new he(1,t.length);for(let r=0;r<t.length;r++)e.set(0,r,t[r]);return e}static columnVector(t){let e=new he(t.length,1);for(let r=0;r<t.length;r++)e.set(r,0,t[r]);return e}static zeros(t,e){return new he(t,e)}static ones(t,e){return new he(t,e).fill(1)}static rand(t,e,r={}){if("object"!=typeof r)throw new TypeError("options must be an object");const{random:n=Math.random}=r;let o=new he(t,e);for(let r=0;r<t;r++)for(let t=0;t<e;t++)o.set(r,t,n());return o}static randInt(t,e,r={}){if("object"!=typeof r)throw new TypeError("options must be an object");const{min:n=0,max:o=1e3,random:i=Math.random}=r;if(!Number.isInteger(n))throw new TypeError("min must be an integer");if(!Number.isInteger(o))throw new TypeError("max must be an integer");if(n>=o)throw new RangeError("min must be smaller than max");let s=o-n,a=new he(t,e);for(let r=0;r<t;r++)for(let t=0;t<e;t++){let e=n+Math.round(i()*s);a.set(r,t,e)}return a}static eye(t,e,r){void 0===e&&(e=t),void 0===r&&(r=1);let n=Math.min(t,e),o=this.zeros(t,e);for(let t=0;t<n;t++)o.set(t,t,r);return o}static diag(t,e,r){let n=t.length;void 0===e&&(e=n),void 0===r&&(r=e);let o=Math.min(n,e,r),i=this.zeros(e,r);for(let e=0;e<o;e++)i.set(e,e,t[e]);return i}static min(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);let r=t.rows,n=t.columns,o=new he(r,n);for(let i=0;i<r;i++)for(let r=0;r<n;r++)o.set(i,r,Math.min(t.get(i,r),e.get(i,r)));return o}static max(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);let r=t.rows,n=t.columns,o=new this(r,n);for(let i=0;i<r;i++)for(let r=0;r<n;r++)o.set(i,r,Math.max(t.get(i,r),e.get(i,r)));return o}static checkMatrix(t){return ae.isMatrix(t)?t:new he(t)}static isMatrix(t){return null!=t&&"Matrix"===t.klass}get size(){return this.rows*this.columns}apply(t){if("function"!=typeof t)throw new TypeError("callback must be a function");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.call(this,e,r);return this}to1DArray(){let t=[];for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.push(this.get(e,r));return t}to2DArray(){let t=[];for(let e=0;e<this.rows;e++){t.push([]);for(let r=0;r<this.columns;r++)t[e].push(this.get(e,r))}return t}toJSON(){return this.to2DArray()}isRowVector(){return 1===this.rows}isColumnVector(){return 1===this.columns}isVector(){return 1===this.rows||1===this.columns}isSquare(){return this.rows===this.columns}isEmpty(){return 0===this.rows||0===this.columns}isSymmetric(){if(this.isSquare()){for(let t=0;t<this.rows;t++)for(let e=0;e<=t;e++)if(this.get(t,e)!==this.get(e,t))return!1;return!0}return!1}isEchelonForm(){let t=0,e=0,r=-1,n=!0,o=!1;for(;t<this.rows&&n;){for(e=0,o=!1;e<this.columns&&!1===o;)0===this.get(t,e)?e++:1===this.get(t,e)&&e>r?(o=!0,r=e):(n=!1,o=!0);t++}return n}isReducedEchelonForm(){let t=0,e=0,r=-1,n=!0,o=!1;for(;t<this.rows&&n;){for(e=0,o=!1;e<this.columns&&!1===o;)0===this.get(t,e)?e++:1===this.get(t,e)&&e>r?(o=!0,r=e):(n=!1,o=!0);for(let r=e+1;r<this.rows;r++)0!==this.get(t,r)&&(n=!1);t++}return n}echelonForm(){let t=this.clone(),e=0,r=0;for(;e<t.rows&&r<t.columns;){let n=e;for(let o=e;o<t.rows;o++)t.get(o,r)>t.get(n,r)&&(n=o);if(0===t.get(n,r))r++;else{t.swapRows(e,n);let o=t.get(e,r);for(let n=r;n<t.columns;n++)t.set(e,n,t.get(e,n)/o);for(let n=e+1;n<t.rows;n++){let o=t.get(n,r)/t.get(e,r);t.set(n,r,0);for(let i=r+1;i<t.columns;i++)t.set(n,i,t.get(n,i)-t.get(e,i)*o)}e++,r++}}return t}reducedEchelonForm(){let t=this.echelonForm(),e=t.columns,r=t.rows,n=r-1;for(;n>=0;)if(0===t.maxRow(n))n--;else{let o=0,i=!1;for(;o<r&&!1===i;)1===t.get(n,o)?i=!0:o++;for(let r=0;r<n;r++){let i=t.get(r,o);for(let s=o;s<e;s++){let e=t.get(r,s)-i*t.get(n,s);t.set(r,s,e)}}n--}return t}set(){throw new Error("set method is unimplemented")}get(){throw new Error("get method is unimplemented")}repeat(t={}){if("object"!=typeof t)throw new TypeError("options must be an object");const{rows:e=1,columns:r=1}=t;if(!Number.isInteger(e)||e<=0)throw new TypeError("rows must be a positive integer");if(!Number.isInteger(r)||r<=0)throw new TypeError("columns must be a positive integer");let n=new he(this.rows*e,this.columns*r);for(let t=0;t<e;t++)for(let e=0;e<r;e++)n.setSubMatrix(this,this.rows*t,this.columns*e);return n}fill(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,t);return this}neg(){return this.mulS(-1)}getRow(t){Zt(this,t);let e=[];for(let r=0;r<this.columns;r++)e.push(this.get(t,r));return e}getRowVector(t){return he.rowVector(this.getRow(t))}setRow(t,e){Zt(this,t),e=ee(this,e);for(let r=0;r<this.columns;r++)this.set(t,r,e[r]);return this}swapRows(t,e){Zt(this,t),Zt(this,e);for(let r=0;r<this.columns;r++){let n=this.get(t,r);this.set(t,r,this.get(e,r)),this.set(e,r,n)}return this}getColumn(t){te(this,t);let e=[];for(let r=0;r<this.rows;r++)e.push(this.get(r,t));return e}getColumnVector(t){return he.columnVector(this.getColumn(t))}setColumn(t,e){te(this,t),e=re(this,e);for(let r=0;r<this.rows;r++)this.set(r,t,e[r]);return this}swapColumns(t,e){te(this,t),te(this,e);for(let r=0;r<this.rows;r++){let n=this.get(r,t);this.set(r,t,this.get(r,e)),this.set(r,e,n)}return this}addRowVector(t){t=ee(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t[r]);return this}subRowVector(t){t=ee(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t[r]);return this}mulRowVector(t){t=ee(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t[r]);return this}divRowVector(t){t=ee(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t[r]);return this}addColumnVector(t){t=re(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t[e]);return this}subColumnVector(t){t=re(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t[e]);return this}mulColumnVector(t){t=re(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t[e]);return this}divColumnVector(t){t=re(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t[e]);return this}mulRow(t,e){Zt(this,t);for(let r=0;r<this.columns;r++)this.set(t,r,this.get(t,r)*e);return this}mulColumn(t,e){te(this,t);for(let r=0;r<this.rows;r++)this.set(r,t,this.get(r,t)*e);return this}max(t){if(this.isEmpty())return NaN;switch(t){case"row":{const t=new Array(this.rows).fill(Number.NEGATIVE_INFINITY);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)>t[e]&&(t[e]=this.get(e,r));return t}case"column":{const t=new Array(this.columns).fill(Number.NEGATIVE_INFINITY);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)>t[r]&&(t[r]=this.get(e,r));return t}case void 0:{let t=this.get(0,0);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)>t&&(t=this.get(e,r));return t}default:throw new Error(`invalid option: ${t}`)}}maxIndex(){se(this);let t=this.get(0,0),e=[0,0];for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.get(r,n)>t&&(t=this.get(r,n),e[0]=r,e[1]=n);return e}min(t){if(this.isEmpty())return NaN;switch(t){case"row":{const t=new Array(this.rows).fill(Number.POSITIVE_INFINITY);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)<t[e]&&(t[e]=this.get(e,r));return t}case"column":{const t=new Array(this.columns).fill(Number.POSITIVE_INFINITY);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)<t[r]&&(t[r]=this.get(e,r));return t}case void 0:{let t=this.get(0,0);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)<t&&(t=this.get(e,r));return t}default:throw new Error(`invalid option: ${t}`)}}minIndex(){se(this);let t=this.get(0,0),e=[0,0];for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.get(r,n)<t&&(t=this.get(r,n),e[0]=r,e[1]=n);return e}maxRow(t){if(Zt(this,t),this.isEmpty())return NaN;let e=this.get(t,0);for(let r=1;r<this.columns;r++)this.get(t,r)>e&&(e=this.get(t,r));return e}maxRowIndex(t){Zt(this,t),se(this);let e=this.get(t,0),r=[t,0];for(let n=1;n<this.columns;n++)this.get(t,n)>e&&(e=this.get(t,n),r[1]=n);return r}minRow(t){if(Zt(this,t),this.isEmpty())return NaN;let e=this.get(t,0);for(let r=1;r<this.columns;r++)this.get(t,r)<e&&(e=this.get(t,r));return e}minRowIndex(t){Zt(this,t),se(this);let e=this.get(t,0),r=[t,0];for(let n=1;n<this.columns;n++)this.get(t,n)<e&&(e=this.get(t,n),r[1]=n);return r}maxColumn(t){if(te(this,t),this.isEmpty())return NaN;let e=this.get(0,t);for(let r=1;r<this.rows;r++)this.get(r,t)>e&&(e=this.get(r,t));return e}maxColumnIndex(t){te(this,t),se(this);let e=this.get(0,t),r=[0,t];for(let n=1;n<this.rows;n++)this.get(n,t)>e&&(e=this.get(n,t),r[0]=n);return r}minColumn(t){if(te(this,t),this.isEmpty())return NaN;let e=this.get(0,t);for(let r=1;r<this.rows;r++)this.get(r,t)<e&&(e=this.get(r,t));return e}minColumnIndex(t){te(this,t),se(this);let e=this.get(0,t),r=[0,t];for(let n=1;n<this.rows;n++)this.get(n,t)<e&&(e=this.get(n,t),r[0]=n);return r}diag(){let t=Math.min(this.rows,this.columns),e=[];for(let r=0;r<t;r++)e.push(this.get(r,r));return e}norm(t="frobenius"){let e=0;if("max"===t)return this.max();if("frobenius"===t){for(let t=0;t<this.rows;t++)for(let r=0;r<this.columns;r++)e+=this.get(t,r)*this.get(t,r);return Math.sqrt(e)}throw new RangeError(`unknown norm type: ${t}`)}cumulativeSum(){let t=0;for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t+=this.get(e,r),this.set(e,r,t);return this}dot(t){ae.isMatrix(t)&&(t=t.to1DArray());let e=this.to1DArray();if(e.length!==t.length)throw new RangeError("vectors do not have the same size");let r=0;for(let n=0;n<e.length;n++)r+=e[n]*t[n];return r}mmul(t){t=he.checkMatrix(t);let e=this.rows,r=this.columns,n=t.columns,o=new he(e,n),i=new Float64Array(r);for(let s=0;s<n;s++){for(let e=0;e<r;e++)i[e]=t.get(e,s);for(let t=0;t<e;t++){let e=0;for(let n=0;n<r;n++)e+=this.get(t,n)*i[n];o.set(t,s,e)}}return o}strassen2x2(t){t=he.checkMatrix(t);let e=new he(2,2);const r=this.get(0,0),n=t.get(0,0),o=this.get(0,1),i=t.get(0,1),s=this.get(1,0),a=t.get(1,0),u=this.get(1,1),h=t.get(1,1),l=(r+u)*(n+h),c=(s+u)*n,f=r*(i-h),d=u*(a-n),g=(r+o)*h,p=l+d-g+(o-u)*(a+h),m=f+g,y=c+d,w=l-c+f+(s-r)*(n+i);return e.set(0,0,p),e.set(0,1,m),e.set(1,0,y),e.set(1,1,w),e}strassen3x3(t){t=he.checkMatrix(t);let e=new he(3,3);const r=this.get(0,0),n=this.get(0,1),o=this.get(0,2),i=this.get(1,0),s=this.get(1,1),a=this.get(1,2),u=this.get(2,0),h=this.get(2,1),l=this.get(2,2),c=t.get(0,0),f=t.get(0,1),d=t.get(0,2),g=t.get(1,0),p=t.get(1,1),m=t.get(1,2),y=t.get(2,0),w=t.get(2,1),v=t.get(2,2),x=(r-i)*(-f+p),M=(-r+i+s)*(c-f+p),b=(i+s)*(-c+f),E=r*c,N=(-r+u+h)*(c-d+m),S=(-r+u)*(d-m),A=(u+h)*(-c+d),k=(-o+h+l)*(p+y-w),I=(o-l)*(p-w),D=o*y,R=(h+l)*(-y+w),_=(-o+s+a)*(m+y-v),z=(o-a)*(m-v),T=(s+a)*(-y+v),C=E+D+n*g,O=(r+n+o-i-s-h-l)*p+M+b+E+k+D+R,P=E+N+A+(r+n+o-s-a-u-h)*m+D+_+T,L=x+s*(-c+f+g-p-m-y+v)+M+E+D+_+z,q=x+M+b+E+a*w,j=D+_+z+T+i*d,V=E+N+S+h*(-c+d+g-p-m-y+w)+k+I+D,F=k+I+D+R+u*f,$=E+N+S+A+l*v;return e.set(0,0,C),e.set(0,1,O),e.set(0,2,P),e.set(1,0,L),e.set(1,1,q),e.set(1,2,j),e.set(2,0,V),e.set(2,1,F),e.set(2,2,$),e}mmulStrassen(t){t=he.checkMatrix(t);let e=this.clone(),r=e.rows,n=e.columns,o=t.rows,i=t.columns;function s(t,e,r){let n=t.rows,o=t.columns;if(n===e&&o===r)return t;{let n=ae.zeros(e,r);return n=n.setSubMatrix(t,0,0),n}}n!==o&&console.warn(`Multiplying ${r} x ${n} and ${o} x ${i} matrix: dimensions do not match.`);let a=Math.max(r,o),u=Math.max(n,i);return e=s(e,a,u),function t(e,r,n,o){if(n<=512||o<=512)return e.mmul(r);n%2==1&&o%2==1?(e=s(e,n+1,o+1),r=s(r,n+1,o+1)):n%2==1?(e=s(e,n+1,o),r=s(r,n+1,o)):o%2==1&&(e=s(e,n,o+1),r=s(r,n,o+1));let i=parseInt(e.rows/2,10),a=parseInt(e.columns/2,10),u=e.subMatrix(0,i-1,0,a-1),h=r.subMatrix(0,i-1,0,a-1),l=e.subMatrix(0,i-1,a,e.columns-1),c=r.subMatrix(0,i-1,a,r.columns-1),f=e.subMatrix(i,e.rows-1,0,a-1),d=r.subMatrix(i,r.rows-1,0,a-1),g=e.subMatrix(i,e.rows-1,a,e.columns-1),p=r.subMatrix(i,r.rows-1,a,r.columns-1),m=t(ae.add(u,g),ae.add(h,p),i,a),y=t(ae.add(f,g),h,i,a),w=t(u,ae.sub(c,p),i,a),v=t(g,ae.sub(d,h),i,a),x=t(ae.add(u,l),p,i,a),M=t(ae.sub(f,u),ae.add(h,c),i,a),b=t(ae.sub(l,g),ae.add(d,p),i,a),E=ae.add(m,v);E.sub(x),E.add(b);let N=ae.add(w,x),S=ae.add(y,v),A=ae.sub(m,y);A.add(w),A.add(M);let k=ae.zeros(2*E.rows,2*E.columns);return k=k.setSubMatrix(E,0,0),k=k.setSubMatrix(N,E.rows,0),k=k.setSubMatrix(S,0,E.columns),k=k.setSubMatrix(A,E.rows,E.columns),k.subMatrix(0,n-1,0,o-1)}(e,t=s(t,a,u),a,u)}scaleRows(t={}){if("object"!=typeof t)throw new TypeError("options must be an object");const{min:e=0,max:r=1}=t;if(!Number.isFinite(e))throw new TypeError("min must be a number");if(!Number.isFinite(r))throw new TypeError("max must be a number");if(e>=r)throw new RangeError("min must be smaller than max");let n=new he(this.rows,this.columns);for(let t=0;t<this.rows;t++){const o=this.getRow(t);o.length>0&&Wt(o,{min:e,max:r,output:o}),n.setRow(t,o)}return n}scaleColumns(t={}){if("object"!=typeof t)throw new TypeError("options must be an object");const{min:e=0,max:r=1}=t;if(!Number.isFinite(e))throw new TypeError("min must be a number");if(!Number.isFinite(r))throw new TypeError("max must be a number");if(e>=r)throw new RangeError("min must be smaller than max");let n=new he(this.rows,this.columns);for(let t=0;t<this.columns;t++){const o=this.getColumn(t);o.length&&Wt(o,{min:e,max:r,output:o}),n.setColumn(t,o)}return n}flipRows(){const t=Math.ceil(this.columns/2);for(let e=0;e<this.rows;e++)for(let r=0;r<t;r++){let t=this.get(e,r),n=this.get(e,this.columns-1-r);this.set(e,r,n),this.set(e,this.columns-1-r,t)}return this}flipColumns(){const t=Math.ceil(this.rows/2);for(let e=0;e<this.columns;e++)for(let r=0;r<t;r++){let t=this.get(r,e),n=this.get(this.rows-1-r,e);this.set(r,e,n),this.set(this.rows-1-r,e,t)}return this}kroneckerProduct(t){t=he.checkMatrix(t);let e=this.rows,r=this.columns,n=t.rows,o=t.columns,i=new he(e*n,r*o);for(let s=0;s<e;s++)for(let e=0;e<r;e++)for(let r=0;r<n;r++)for(let a=0;a<o;a++)i.set(n*s+r,o*e+a,this.get(s,e)*t.get(r,a));return i}kroneckerSum(t){if(t=he.checkMatrix(t),!this.isSquare()||!t.isSquare())throw new Error("Kronecker Sum needs two Square Matrices");let e=this.rows,r=t.rows,n=this.kroneckerProduct(he.eye(r,r)),o=he.eye(e,e).kroneckerProduct(t);return n.add(o)}transpose(){let t=new he(this.columns,this.rows);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.set(r,e,this.get(e,r));return t}sortRows(t=ue){for(let e=0;e<this.rows;e++)this.setRow(e,this.getRow(e).sort(t));return this}sortColumns(t=ue){for(let e=0;e<this.columns;e++)this.setColumn(e,this.getColumn(e).sort(t));return this}subMatrix(t,e,r,n){ne(this,t,e,r,n);let o=new he(e-t+1,n-r+1);for(let i=t;i<=e;i++)for(let e=r;e<=n;e++)o.set(i-t,e-r,this.get(i,e));return o}subMatrixRow(t,e,r){if(void 0===e&&(e=0),void 0===r&&(r=this.columns-1),e>r||e<0||e>=this.columns||r<0||r>=this.columns)throw new RangeError("Argument out of range");let n=new he(t.length,r-e+1);for(let o=0;o<t.length;o++)for(let i=e;i<=r;i++){if(t[o]<0||t[o]>=this.rows)throw new RangeError(`Row index out of range: ${t[o]}`);n.set(o,i-e,this.get(t[o],i))}return n}subMatrixColumn(t,e,r){if(void 0===e&&(e=0),void 0===r&&(r=this.rows-1),e>r||e<0||e>=this.rows||r<0||r>=this.rows)throw new RangeError("Argument out of range");let n=new he(r-e+1,t.length);for(let o=0;o<t.length;o++)for(let i=e;i<=r;i++){if(t[o]<0||t[o]>=this.columns)throw new RangeError(`Column index out of range: ${t[o]}`);n.set(i-e,o,this.get(i,t[o]))}return n}setSubMatrix(t,e,r){if((t=he.checkMatrix(t)).isEmpty())return this;ne(this,e,e+t.rows-1,r,r+t.columns-1);for(let n=0;n<t.rows;n++)for(let o=0;o<t.columns;o++)this.set(e+n,r+o,t.get(n,o));return this}selection(t,e){!function(t,e){if(!Bt(e))throw new TypeError("row indices must be an array");for(let r=0;r<e.length;r++)if(e[r]<0||e[r]>=t.rows)throw new RangeError("row indices are out of range")}(this,t),function(t,e){if(!Bt(e))throw new TypeError("column indices must be an array");for(let r=0;r<e.length;r++)if(e[r]<0||e[r]>=t.columns)throw new RangeError("column indices are out of range")}(this,e);let r=new he(t.length,e.length);for(let n=0;n<t.length;n++){let o=t[n];for(let t=0;t<e.length;t++){let i=e[t];r.set(n,t,this.get(o,i))}}return r}trace(){let t=Math.min(this.rows,this.columns),e=0;for(let r=0;r<t;r++)e+=this.get(r,r);return e}clone(){let t=new he(this.rows,this.columns);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.set(e,r,this.get(e,r));return t}sum(t){switch(t){case"row":return function(t){let e=oe(t.rows);for(let r=0;r<t.rows;++r)for(let n=0;n<t.columns;++n)e[r]+=t.get(r,n);return e}(this);case"column":return function(t){let e=oe(t.columns);for(let r=0;r<t.rows;++r)for(let n=0;n<t.columns;++n)e[n]+=t.get(r,n);return e}(this);case void 0:return function(t){let e=0;for(let r=0;r<t.rows;r++)for(let n=0;n<t.columns;n++)e+=t.get(r,n);return e}(this);default:throw new Error(`invalid option: ${t}`)}}product(t){switch(t){case"row":return function(t){let e=oe(t.rows,1);for(let r=0;r<t.rows;++r)for(let n=0;n<t.columns;++n)e[r]*=t.get(r,n);return e}(this);case"column":return function(t){let e=oe(t.columns,1);for(let r=0;r<t.rows;++r)for(let n=0;n<t.columns;++n)e[n]*=t.get(r,n);return e}(this);case void 0:return function(t){let e=1;for(let r=0;r<t.rows;r++)for(let n=0;n<t.columns;n++)e*=t.get(r,n);return e}(this);default:throw new Error(`invalid option: ${t}`)}}mean(t){const e=this.sum(t);switch(t){case"row":for(let t=0;t<this.rows;t++)e[t]/=this.columns;return e;case"column":for(let t=0;t<this.columns;t++)e[t]/=this.rows;return e;case void 0:return e/this.size;default:throw new Error(`invalid option: ${t}`)}}variance(t,e={}){if("object"==typeof t&&(e=t,t=void 0),"object"!=typeof e)throw new TypeError("options must be an object");const{unbiased:r=!0,mean:n=this.mean(t)}=e;if("boolean"!=typeof r)throw new TypeError("unbiased must be a boolean");switch(t){case"row":if(!Bt(n))throw new TypeError("mean must be an array");return function(t,e,r){const n=t.rows,o=t.columns,i=[];for(let s=0;s<n;s++){let n=0,a=0,u=0;for(let e=0;e<o;e++)u=t.get(s,e)-r[s],n+=u,a+=u*u;e?i.push((a-n*n/o)/(o-1)):i.push((a-n*n/o)/o)}return i}(this,r,n);case"column":if(!Bt(n))throw new TypeError("mean must be an array");return function(t,e,r){const n=t.rows,o=t.columns,i=[];for(let s=0;s<o;s++){let o=0,a=0,u=0;for(let e=0;e<n;e++)u=t.get(e,s)-r[s],o+=u,a+=u*u;e?i.push((a-o*o/n)/(n-1)):i.push((a-o*o/n)/n)}return i}(this,r,n);case void 0:if("number"!=typeof n)throw new TypeError("mean must be a number");return function(t,e,r){const n=t.rows,o=t.columns,i=n*o;let s=0,a=0,u=0;for(let e=0;e<n;e++)for(let n=0;n<o;n++)u=t.get(e,n)-r,s+=u,a+=u*u;return e?(a-s*s/i)/(i-1):(a-s*s/i)/i}(this,r,n);default:throw new Error(`invalid option: ${t}`)}}standardDeviation(t,e){"object"==typeof t&&(e=t,t=void 0);const r=this.variance(t,e);if(void 0===t)return Math.sqrt(r);for(let t=0;t<r.length;t++)r[t]=Math.sqrt(r[t]);return r}center(t,e={}){if("object"==typeof t&&(e=t,t=void 0),"object"!=typeof e)throw new TypeError("options must be an object");const{center:r=this.mean(t)}=e;switch(t){case"row":if(!Bt(r))throw new TypeError("center must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let n=0;n<t.columns;n++)t.set(r,n,t.get(r,n)-e[r])}(this,r),this;case"column":if(!Bt(r))throw new TypeError("center must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let n=0;n<t.columns;n++)t.set(r,n,t.get(r,n)-e[n])}(this,r),this;case void 0:if("number"!=typeof r)throw new TypeError("center must be a number");return function(t,e){for(let r=0;r<t.rows;r++)for(let n=0;n<t.columns;n++)t.set(r,n,t.get(r,n)-e)}(this,r),this;default:throw new Error(`invalid option: ${t}`)}}scale(t,e={}){if("object"==typeof t&&(e=t,t=void 0),"object"!=typeof e)throw new TypeError("options must be an object");let r=e.scale;switch(t){case"row":if(void 0===r)r=function(t){const e=[];for(let r=0;r<t.rows;r++){let n=0;for(let e=0;e<t.columns;e++)n+=Math.pow(t.get(r,e),2)/(t.columns-1);e.push(Math.sqrt(n))}return e}(this);else if(!Bt(r))throw new TypeError("scale must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let n=0;n<t.columns;n++)t.set(r,n,t.get(r,n)/e[r])}(this,r),this;case"column":if(void 0===r)r=function(t){const e=[];for(let r=0;r<t.columns;r++){let n=0;for(let e=0;e<t.rows;e++)n+=Math.pow(t.get(e,r),2)/(t.rows-1);e.push(Math.sqrt(n))}return e}(this);else if(!Bt(r))throw new TypeError("scale must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let n=0;n<t.columns;n++)t.set(r,n,t.get(r,n)/e[n])}(this,r),this;case void 0:if(void 0===r)r=function(t){const e=t.size-1;let r=0;for(let n=0;n<t.columns;n++)for(let o=0;o<t.rows;o++)r+=Math.pow(t.get(o,n),2)/e;return Math.sqrt(r)}(this);else if("number"!=typeof r)throw new TypeError("scale must be a number");return function(t,e){for(let r=0;r<t.rows;r++)for(let n=0;n<t.columns;n++)t.set(r,n,t.get(r,n)/e)}(this,r),this;default:throw new Error(`invalid option: ${t}`)}}toString(t){return Yt(this,t)}}function ue(t,e){return t-e}ae.prototype.klass="Matrix","undefined"!=typeof Symbol&&(ae.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return Yt(this)}),ae.random=ae.rand,ae.randomInt=ae.randInt,ae.diagonal=ae.diag,ae.prototype.diagonal=ae.prototype.diag,ae.identity=ae.eye,ae.prototype.negate=ae.prototype.neg,ae.prototype.tensorProduct=ae.prototype.kroneckerProduct;class he extends ae{constructor(t,e){if(super(),he.isMatrix(t))return t.clone();if(Number.isInteger(t)&&t>=0){if(this.data=[],!(Number.isInteger(e)&&e>=0))throw new TypeError("nColumns must be a positive integer");for(let r=0;r<t;r++)this.data.push(new Float64Array(e))}else{if(!Bt(t))throw new TypeError("First argument must be a positive number or an array");{const r=t;if("number"!=typeof(e=(t=r.length)?r[0].length:0))throw new TypeError("Data must be a 2D array with at least one element");this.data=[];for(let n=0;n<t;n++){if(r[n].length!==e)throw new RangeError("Inconsistent array dimensions");if(!r[n].every((t=>"number"==typeof t)))throw new TypeError("Input data contains non-numeric values");this.data.push(Float64Array.from(r[n]))}}}this.rows=t,this.columns=e}set(t,e,r){return this.data[t][e]=r,this}get(t,e){return this.data[t][e]}removeRow(t){return Zt(this,t),this.data.splice(t,1),this.rows-=1,this}addRow(t,e){return void 0===e&&(e=t,t=this.rows),Zt(this,t,!0),e=Float64Array.from(ee(this,e)),this.data.splice(t,0,e),this.rows+=1,this}removeColumn(t){te(this,t);for(let e=0;e<this.rows;e++){const r=new Float64Array(this.columns-1);for(let n=0;n<t;n++)r[n]=this.data[e][n];for(let n=t+1;n<this.columns;n++)r[n-1]=this.data[e][n];this.data[e]=r}return this.columns-=1,this}addColumn(t,e){void 0===e&&(e=t,t=this.columns),te(this,t,!0),e=re(this,e);for(let r=0;r<this.rows;r++){const n=new Float64Array(this.columns+1);let o=0;for(;o<t;o++)n[o]=this.data[r][o];for(n[o++]=e[r];o<this.columns+1;o++)n[o]=this.data[r][o-1];this.data[r]=n}return this.columns+=1,this}}!function(t,e){t.prototype.add=function(t){return"number"==typeof t?this.addS(t):this.addM(t)},t.prototype.addS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t);return this},t.prototype.addM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t.get(e,r));return this},t.add=function(t,r){return new e(t).add(r)},t.prototype.sub=function(t){return"number"==typeof t?this.subS(t):this.subM(t)},t.prototype.subS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t);return this},t.prototype.subM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t.get(e,r));return this},t.sub=function(t,r){return new e(t).sub(r)},t.prototype.subtract=t.prototype.sub,t.prototype.subtractS=t.prototype.subS,t.prototype.subtractM=t.prototype.subM,t.subtract=t.sub,t.prototype.mul=function(t){return"number"==typeof t?this.mulS(t):this.mulM(t)},t.prototype.mulS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t);return this},t.prototype.mulM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t.get(e,r));return this},t.mul=function(t,r){return new e(t).mul(r)},t.prototype.multiply=t.prototype.mul,t.prototype.multiplyS=t.prototype.mulS,t.prototype.multiplyM=t.prototype.mulM,t.multiply=t.mul,t.prototype.div=function(t){return"number"==typeof t?this.divS(t):this.divM(t)},t.prototype.divS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t);return this},t.prototype.divM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t.get(e,r));return this},t.div=function(t,r){return new e(t).div(r)},t.prototype.divide=t.prototype.div,t.prototype.divideS=t.prototype.divS,t.prototype.divideM=t.prototype.divM,t.divide=t.div,t.prototype.mod=function(t){return"number"==typeof t?this.modS(t):this.modM(t)},t.prototype.modS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)%t);return this},t.prototype.modM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)%t.get(e,r));return this},t.mod=function(t,r){return new e(t).mod(r)},t.prototype.modulus=t.prototype.mod,t.prototype.modulusS=t.prototype.modS,t.prototype.modulusM=t.prototype.modM,t.modulus=t.mod,t.prototype.and=function(t){return"number"==typeof t?this.andS(t):this.andM(t)},t.prototype.andS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)&t);return this},t.prototype.andM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)&t.get(e,r));return this},t.and=function(t,r){return new e(t).and(r)},t.prototype.or=function(t){return"number"==typeof t?this.orS(t):this.orM(t)},t.prototype.orS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)|t);return this},t.prototype.orM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)|t.get(e,r));return this},t.or=function(t,r){return new e(t).or(r)},t.prototype.xor=function(t){return"number"==typeof t?this.xorS(t):this.xorM(t)},t.prototype.xorS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)^t);return this},t.prototype.xorM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)^t.get(e,r));return this},t.xor=function(t,r){return new e(t).xor(r)},t.prototype.leftShift=function(t){return"number"==typeof t?this.leftShiftS(t):this.leftShiftM(t)},t.prototype.leftShiftS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)<<t);return this},t.prototype.leftShiftM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)<<t.get(e,r));return this},t.leftShift=function(t,r){return new e(t).leftShift(r)},t.prototype.signPropagatingRightShift=function(t){return"number"==typeof t?this.signPropagatingRightShiftS(t):this.signPropagatingRightShiftM(t)},t.prototype.signPropagatingRightShiftS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>t);return this},t.prototype.signPropagatingRightShiftM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>t.get(e,r));return this},t.signPropagatingRightShift=function(t,r){return new e(t).signPropagatingRightShift(r)},t.prototype.rightShift=function(t){return"number"==typeof t?this.rightShiftS(t):this.rightShiftM(t)},t.prototype.rightShiftS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>>t);return this},t.prototype.rightShiftM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>>t.get(e,r));return this},t.rightShift=function(t,r){return new e(t).rightShift(r)},t.prototype.zeroFillRightShift=t.prototype.rightShift,t.prototype.zeroFillRightShiftS=t.prototype.rightShiftS,t.prototype.zeroFillRightShiftM=t.prototype.rightShiftM,t.zeroFillRightShift=t.rightShift,t.prototype.not=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,~this.get(t,e));return this},t.not=function(t){return new e(t).not()},t.prototype.abs=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.abs(this.get(t,e)));return this},t.abs=function(t){return new e(t).abs()},t.prototype.acos=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.acos(this.get(t,e)));return this},t.acos=function(t){return new e(t).acos()},t.prototype.acosh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.acosh(this.get(t,e)));return this},t.acosh=function(t){return new e(t).acosh()},t.prototype.asin=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.asin(this.get(t,e)));return this},t.asin=function(t){return new e(t).asin()},t.prototype.asinh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.asinh(this.get(t,e)));return this},t.asinh=function(t){return new e(t).asinh()},t.prototype.atan=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.atan(this.get(t,e)));return this},t.atan=function(t){return new e(t).atan()},t.prototype.atanh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.atanh(this.get(t,e)));return this},t.atanh=function(t){return new e(t).atanh()},t.prototype.cbrt=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.cbrt(this.get(t,e)));return this},t.cbrt=function(t){return new e(t).cbrt()},t.prototype.ceil=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.ceil(this.get(t,e)));return this},t.ceil=function(t){return new e(t).ceil()},t.prototype.clz32=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.clz32(this.get(t,e)));return this},t.clz32=function(t){return new e(t).clz32()},t.prototype.cos=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.cos(this.get(t,e)));return this},t.cos=function(t){return new e(t).cos()},t.prototype.cosh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.cosh(this.get(t,e)));return this},t.cosh=function(t){return new e(t).cosh()},t.prototype.exp=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.exp(this.get(t,e)));return this},t.exp=function(t){return new e(t).exp()},t.prototype.expm1=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.expm1(this.get(t,e)));return this},t.expm1=function(t){return new e(t).expm1()},t.prototype.floor=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.floor(this.get(t,e)));return this},t.floor=function(t){return new e(t).floor()},t.prototype.fround=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.fround(this.get(t,e)));return this},t.fround=function(t){return new e(t).fround()},t.prototype.log=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log(this.get(t,e)));return this},t.log=function(t){return new e(t).log()},t.prototype.log1p=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log1p(this.get(t,e)));return this},t.log1p=function(t){return new e(t).log1p()},t.prototype.log10=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log10(this.get(t,e)));return this},t.log10=function(t){return new e(t).log10()},t.prototype.log2=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log2(this.get(t,e)));return this},t.log2=function(t){return new e(t).log2()},t.prototype.round=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.round(this.get(t,e)));return this},t.round=function(t){return new e(t).round()},t.prototype.sign=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sign(this.get(t,e)));return this},t.sign=function(t){return new e(t).sign()},t.prototype.sin=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sin(this.get(t,e)));return this},t.sin=function(t){return new e(t).sin()},t.prototype.sinh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sinh(this.get(t,e)));return this},t.sinh=function(t){return new e(t).sinh()},t.prototype.sqrt=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sqrt(this.get(t,e)));return this},t.sqrt=function(t){return new e(t).sqrt()},t.prototype.tan=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.tan(this.get(t,e)));return this},t.tan=function(t){return new e(t).tan()},t.prototype.tanh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.tanh(this.get(t,e)));return this},t.tanh=function(t){return new e(t).tanh()},t.prototype.trunc=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.trunc(this.get(t,e)));return this},t.trunc=function(t){return new e(t).trunc()},t.pow=function(t,r){return new e(t).pow(r)},t.prototype.pow=function(t){return"number"==typeof t?this.powS(t):this.powM(t)},t.prototype.powS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,Math.pow(this.get(e,r),t));return this},t.prototype.powM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,Math.pow(this.get(e,r),t.get(e,r)));return this}}(ae,he);class le extends ae{constructor(t){super(),this.data=t,this.rows=t.length,this.columns=t[0].length}set(t,e,r){return this.data[t][e]=r,this}get(t,e){return this.data[t][e]}}function ce(t,e){let r=0;return Math.abs(t)>Math.abs(e)?(r=e/t,Math.abs(t)*Math.sqrt(1+r*r)):0!==e?(r=t/e,Math.abs(e)*Math.sqrt(1+r*r)):0}class fe{constructor(t,e={}){if((t=le.checkMatrix(t)).isEmpty())throw new Error("Matrix must be non-empty");let r=t.rows,n=t.columns;const{computeLeftSingularVectors:o=!0,computeRightSingularVectors:i=!0,autoTranspose:s=!1}=e;let a,u=Boolean(o),h=Boolean(i),l=!1;if(r<n)if(s){a=t.transpose(),r=a.rows,n=a.columns,l=!0;let e=u;u=h,h=e}else a=t.clone(),console.warn("Computing SVD on a matrix with more columns than rows. Consider enabling autoTranspose");else a=t.clone();let c=Math.min(r,n),f=Math.min(r+1,n),d=new Float64Array(f),g=new he(r,c),p=new he(n,n),m=new Float64Array(n),y=new Float64Array(r),w=new Float64Array(f);for(let t=0;t<f;t++)w[t]=t;let v=Math.min(r-1,n),x=Math.max(0,Math.min(n-2,r)),M=Math.max(v,x);for(let t=0;t<M;t++){if(t<v){d[t]=0;for(let e=t;e<r;e++)d[t]=ce(d[t],a.get(e,t));if(0!==d[t]){a.get(t,t)<0&&(d[t]=-d[t]);for(let e=t;e<r;e++)a.set(e,t,a.get(e,t)/d[t]);a.set(t,t,a.get(t,t)+1)}d[t]=-d[t]}for(let e=t+1;e<n;e++){if(t<v&&0!==d[t]){let n=0;for(let o=t;o<r;o++)n+=a.get(o,t)*a.get(o,e);n=-n/a.get(t,t);for(let o=t;o<r;o++)a.set(o,e,a.get(o,e)+n*a.get(o,t))}m[e]=a.get(t,e)}if(u&&t<v)for(let e=t;e<r;e++)g.set(e,t,a.get(e,t));if(t<x){m[t]=0;for(let e=t+1;e<n;e++)m[t]=ce(m[t],m[e]);if(0!==m[t]){m[t+1]<0&&(m[t]=0-m[t]);for(let e=t+1;e<n;e++)m[e]/=m[t];m[t+1]+=1}if(m[t]=-m[t],t+1<r&&0!==m[t]){for(let e=t+1;e<r;e++)y[e]=0;for(let e=t+1;e<r;e++)for(let r=t+1;r<n;r++)y[e]+=m[r]*a.get(e,r);for(let e=t+1;e<n;e++){let n=-m[e]/m[t+1];for(let o=t+1;o<r;o++)a.set(o,e,a.get(o,e)+n*y[o])}}if(h)for(let e=t+1;e<n;e++)p.set(e,t,m[e])}}let b=Math.min(n,r+1);if(v<n&&(d[v]=a.get(v,v)),r<b&&(d[b-1]=0),x+1<b&&(m[x]=a.get(x,b-1)),m[b-1]=0,u){for(let t=v;t<c;t++){for(let e=0;e<r;e++)g.set(e,t,0);g.set(t,t,1)}for(let t=v-1;t>=0;t--)if(0!==d[t]){for(let e=t+1;e<c;e++){let n=0;for(let o=t;o<r;o++)n+=g.get(o,t)*g.get(o,e);n=-n/g.get(t,t);for(let o=t;o<r;o++)g.set(o,e,g.get(o,e)+n*g.get(o,t))}for(let e=t;e<r;e++)g.set(e,t,-g.get(e,t));g.set(t,t,1+g.get(t,t));for(let e=0;e<t-1;e++)g.set(e,t,0)}else{for(let e=0;e<r;e++)g.set(e,t,0);g.set(t,t,1)}}if(h)for(let t=n-1;t>=0;t--){if(t<x&&0!==m[t])for(let e=t+1;e<n;e++){let r=0;for(let o=t+1;o<n;o++)r+=p.get(o,t)*p.get(o,e);r=-r/p.get(t+1,t);for(let o=t+1;o<n;o++)p.set(o,e,p.get(o,e)+r*p.get(o,t))}for(let e=0;e<n;e++)p.set(e,t,0);p.set(t,t,1)}let E=b-1,N=0,S=Number.EPSILON;for(;b>0;){let t,e;for(t=b-2;t>=-1&&-1!==t;t--){const e=Number.MIN_VALUE+S*Math.abs(d[t]+Math.abs(d[t+1]));if(Math.abs(m[t])<=e||Number.isNaN(m[t])){m[t]=0;break}}if(t===b-2)e=4;else{let r;for(r=b-1;r>=t&&r!==t;r--){let e=(r!==b?Math.abs(m[r]):0)+(r!==t+1?Math.abs(m[r-1]):0);if(Math.abs(d[r])<=S*e){d[r]=0;break}}r===t?e=3:r===b-1?e=1:(e=2,t=r)}switch(t++,e){case 1:{let e=m[b-2];m[b-2]=0;for(let r=b-2;r>=t;r--){let o=ce(d[r],e),i=d[r]/o,s=e/o;if(d[r]=o,r!==t&&(e=-s*m[r-1],m[r-1]=i*m[r-1]),h)for(let t=0;t<n;t++)o=i*p.get(t,r)+s*p.get(t,b-1),p.set(t,b-1,-s*p.get(t,r)+i*p.get(t,b-1)),p.set(t,r,o)}break}case 2:{let e=m[t-1];m[t-1]=0;for(let n=t;n<b;n++){let o=ce(d[n],e),i=d[n]/o,s=e/o;if(d[n]=o,e=-s*m[n],m[n]=i*m[n],u)for(let e=0;e<r;e++)o=i*g.get(e,n)+s*g.get(e,t-1),g.set(e,t-1,-s*g.get(e,n)+i*g.get(e,t-1)),g.set(e,n,o)}break}case 3:{const e=Math.max(Math.abs(d[b-1]),Math.abs(d[b-2]),Math.abs(m[b-2]),Math.abs(d[t]),Math.abs(m[t])),o=d[b-1]/e,i=d[b-2]/e,s=m[b-2]/e,a=d[t]/e,l=m[t]/e,c=((i+o)*(i-o)+s*s)/2,f=o*s*(o*s);let y=0;0===c&&0===f||(y=c<0?0-Math.sqrt(c*c+f):Math.sqrt(c*c+f),y=f/(c+y));let w=(a+o)*(a-o)+y,v=a*l;for(let e=t;e<b-1;e++){let o=ce(w,v);0===o&&(o=Number.MIN_VALUE);let i=w/o,s=v/o;if(e!==t&&(m[e-1]=o),w=i*d[e]+s*m[e],m[e]=i*m[e]-s*d[e],v=s*d[e+1],d[e+1]=i*d[e+1],h)for(let t=0;t<n;t++)o=i*p.get(t,e)+s*p.get(t,e+1),p.set(t,e+1,-s*p.get(t,e)+i*p.get(t,e+1)),p.set(t,e,o);if(o=ce(w,v),0===o&&(o=Number.MIN_VALUE),i=w/o,s=v/o,d[e]=o,w=i*m[e]+s*d[e+1],d[e+1]=-s*m[e]+i*d[e+1],v=s*m[e+1],m[e+1]=i*m[e+1],u&&e<r-1)for(let t=0;t<r;t++)o=i*g.get(t,e)+s*g.get(t,e+1),g.set(t,e+1,-s*g.get(t,e)+i*g.get(t,e+1)),g.set(t,e,o)}m[b-2]=w,N+=1;break}case 4:if(d[t]<=0&&(d[t]=d[t]<0?-d[t]:0,h))for(let e=0;e<=E;e++)p.set(e,t,-p.get(e,t));for(;t<E&&!(d[t]>=d[t+1]);){let e=d[t];if(d[t]=d[t+1],d[t+1]=e,h&&t<n-1)for(let r=0;r<n;r++)e=p.get(r,t+1),p.set(r,t+1,p.get(r,t)),p.set(r,t,e);if(u&&t<r-1)for(let n=0;n<r;n++)e=g.get(n,t+1),g.set(n,t+1,g.get(n,t)),g.set(n,t,e);t++}N=0,b--}}if(l){let t=p;p=g,g=t}this.m=r,this.n=n,this.s=d,this.U=g,this.V=p}solve(t){let e=t,r=this.threshold,n=this.s.length,o=he.zeros(n,n);for(let t=0;t<n;t++)Math.abs(this.s[t])<=r?o.set(t,t,0):o.set(t,t,1/this.s[t]);let i=this.U,s=this.rightSingularVectors,a=s.mmul(o),u=s.rows,h=i.rows,l=he.zeros(u,h);for(let t=0;t<u;t++)for(let e=0;e<h;e++){let r=0;for(let o=0;o<n;o++)r+=a.get(t,o)*i.get(e,o);l.set(t,e,r)}return l.mmul(e)}solveForDiagonal(t){return this.solve(he.diag(t))}inverse(){let t=this.V,e=this.threshold,r=t.rows,n=t.columns,o=new he(r,this.s.length);for(let i=0;i<r;i++)for(let r=0;r<n;r++)Math.abs(this.s[r])>e&&o.set(i,r,t.get(i,r)/this.s[r]);let i=this.U,s=i.rows,a=i.columns,u=new he(r,s);for(let t=0;t<r;t++)for(let e=0;e<s;e++){let r=0;for(let n=0;n<a;n++)r+=o.get(t,n)*i.get(e,n);u.set(t,e,r)}return u}get condition(){return this.s[0]/this.s[Math.min(this.m,this.n)-1]}get norm2(){return this.s[0]}get rank(){let t=Math.max(this.m,this.n)*this.s[0]*Number.EPSILON,e=0,r=this.s;for(let n=0,o=r.length;n<o;n++)r[n]>t&&e++;return e}get diagonal(){return Array.from(this.s)}get threshold(){return Number.EPSILON/2*Math.max(this.m,this.n)*this.s[0]}get leftSingularVectors(){return this.U}get rightSingularVectors(){return this.V}get diagonalMatrix(){return he.diag(this.s)}}var de,ge={center:[0,0],linkDistance:50},pe=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="mds",this.options=r(r({},ge),t)}return t.prototype.execute=function(t,e){return this.genericMDSLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericMDSLayout(!0,t,e)},t.prototype.genericMDSLayout=function(t,e,n){var o=r(r({},this.options),n),i=o.center,s=void 0===i?[0,0]:i,a=o.linkDistance,u=void 0===a?50:a,h=o.layoutInvisibles,l=o.onLayoutEnd,d=e.getAllNodes(),g=e.getAllEdges();if(h||(d=d.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e})),g=g.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e}))),!d||0===d.length){var p={nodes:[],edges:g};return null==l||l(p),p}if(1===d.length){t&&e.mergeNodeData(d[0].id,{x:s[0],y:s[1]});var y={nodes:[r(r({},d[0]),{data:r(r({},d[0].data),{x:s[0],y:s[1]})})],edges:g};return null==l||l(y),y}var w=f({nodes:d,edges:g},!1),v=c(w);me(v);var x=function(t,e){var r=[];return t.forEach((function(t){var n=[];t.forEach((function(t){n.push(t*e)})),r.push(n)})),r}(v,u),M=ye(x),b=[];M.forEach((function(t,e){var r=m(d[e]);r.data.x=t[0]+s[0],r.data.y=t[1]+s[1],b.push(r)})),t&&b.forEach((function(t){return e.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}));var E={nodes:b,edges:g};return null==l||l(E),E},t}(),me=function(t){var e=-999999;t.forEach((function(t){t.forEach((function(t){t!==1/0&&e<t&&(e=t)}))})),t.forEach((function(r,n){r.forEach((function(r,o){r===1/0&&(t[n][o]=e)}))}))},ye=function(t){var e=he.mul(he.pow(t,2),-.5),r=e.mean("row"),n=e.mean("column"),o=e.mean();e.add(o).subRowVector(r).subColumnVector(n);var i=new fe(e),s=he.sqrt(i.diagonalMatrix).diagonal();return i.leftSingularVectors.toJSON().map((function(t){return he.mul([t],[s]).toJSON()[0].splice(0,2)}))},we={iterations:10,height:10,width:10,speed:100,gravity:10,k:5},ve=function(t,e,r,n,o,i){e.forEach((function(s,a){r[a]={x:0,y:0},e.forEach((function(e,u){if(a!==u&&o[a]===o[u]){var h=s.x-e.x,l=s.y-e.y,c=Math.sqrt(h*h+l*l);if(0===c){c=1;var f=a>u?1:-1;h=.01*f,l=.01*f}if(c<i(t[a])/2+i(t[u])/2){var d=n*n/c;r[a].x+=h/c*d,r[a].y+=l/c*d}}}))}))},xe=function(t,e,r,n,o,i,s,a){var u=i||s/10;return n&&e.forEach((function(e,r){var n=t[r].x-t[o].x,i=t[r].y-t[o].y,s=Math.sqrt(n*n+i*i),a=i/s,u=-n/s,h=Math.sqrt(e.x*e.x+e.y*e.y),l=Math.acos((a*e.x+u*e.y)/h);l>Math.PI/2&&(l-=Math.PI/2,a*=-1,u*=-1);var c=Math.cos(l)*h;e.x=a*c,e.y=u*c})),t.forEach((function(i,s){if(s!==o){var h=Math.sqrt(e[s].x*e[s].x+e[s].y*e[s].y);if(h>0&&s!==o){var l=Math.min(u*(r/800),h);if(i.x+=e[s].x/h*l,i.y+=e[s].y/h*l,n){var c=i.x-t[o].x,f=i.y-t[o].y,d=Math.sqrt(c*c+f*f);c=c/d*a[s],f=f/d*a[s],i.x=t[o].x+c,i.y=t[o].y+f}}}})),t},Me={maxIteration:1e3,focusNode:null,unitRadius:null,linkDistance:50,preventOverlap:!1,strictRadial:!0,maxPreventOverlapIteration:200,sortStrength:10},be=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="radial",this.options=r(r({},Me),t)}return t.prototype.execute=function(t,e){return this.genericRadialLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericRadialLayout(!0,t,e)},t.prototype.genericRadialLayout=function(t,e,n){var s=r(r({},this.options),n),u=s.width,h=s.height,l=s.center,d=s.focusNode,g=s.unitRadius,p=s.nodeSize,y=s.nodeSpacing,w=s.strictRadial,v=s.preventOverlap,x=s.maxPreventOverlapIteration,M=s.sortBy,b=s.linkDistance,E=void 0===b?50:b,N=s.sortStrength,S=void 0===N?10:N,A=s.maxIteration,k=void 0===A?1e3:A,I=s.layoutInvisibles,D=s.onLayoutEnd,R=e.getAllNodes(),_=e.getAllEdges();if(I||(R=R.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e})),_=_.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e}))),!R||0===R.length){var z={nodes:[],edges:_};return null==D||D(z),z}var T=u||"undefined"==typeof window?u:window.innerWidth,C=h||"undefined"==typeof window?h:window.innerHeight,O=l||[T/2,C/2];if(1===R.length){t&&e.mergeNodeData(R[0].id,{x:O[0],y:O[1]});var P={nodes:[r(r({},R[0]),{data:r(r({},R[0].data),{x:O[0],y:O[1]})})],edges:_};return null==D||D(P),P}var L=R[0];if(a(d)){for(var q=0;q<R.length;q++)if(R[q].id===d){L=R[q];break}}else L=d||R[0];var j=Se(R,L.id),V=f({nodes:R,edges:_},!1),F=c(V),$=ke(F,j);Ae(F,j,$+1);var U=F[j],B=T-O[0]>O[0]?O[0]:T-O[0],G=C-O[1]>O[1]?O[1]:C-O[1];0===B&&(B=T/2),0===G&&(G=C/2);var K=Math.min(B,G),W=Math.max.apply(Math,i([],o(U),!1)),H=[],J=g||K/W;U.forEach((function(t,e){H[e]=t*J}));var Y,X=Ee(R,F,E,H,J,M,S),Q=Ne(X),Z=function(t,e,r){try{var n=he.mul(he.pow(e,2),-.5),o=n.mean("row"),i=n.mean("column"),s=n.mean();n.add(s).subRowVector(o).subColumnVector(i);var a=new fe(n),u=he.sqrt(a.diagonalMatrix).diagonal();return a.leftSingularVectors.toJSON().map((function(e){return he.mul([e],[u]).toJSON()[0].splice(0,t)}))}catch(t){for(var h=[],l=0;l<e.length;l++){var c=Math.random()*r,f=Math.random()*r;h.push([c,f])}return h}}(E,X,E),tt=Z.map((function(t){var e=o(t,2),r=e[0],n=e[1];return{x:(isNaN(r)?Math.random()*E:r)-Z[j][0],y:(isNaN(n)?Math.random()*E:n)-Z[j][1]}}));if(this.run(k,tt,Q,X,H,j),v){Y=Ie(p,y);var et={nodes:R,nodeSizeFunc:Y,positions:tt,radii:H,height:C,width:T,strictRadial:Boolean(w),focusIdx:j,iterations:x||200,k:tt.length/4.5};tt=function(t,e){for(var n=r(r({},we),e),o=n.positions,i=n.iterations,s=n.width,a=n.k,u=n.speed,h=void 0===u?100:u,l=n.strictRadial,c=n.focusIdx,f=n.radii,d=void 0===f?[]:f,g=n.nodeSizeFunc,p=t.getAllNodes(),m=[],y=s/10,w=0;w<i;w++)o.forEach((function(t,e){m[e]={x:0,y:0}})),ve(p,o,m,a,d,g),xe(o,m,h,l,c,y,s,d);return o}(e,et)}var rt=[];tt.forEach((function(t,e){var r=m(R[e]);r.data.x=t.x+O[0],r.data.y=t.y+O[1],rt.push(r)})),t&&rt.forEach((function(t){return e.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}));var nt={nodes:rt,edges:_};return null==D||D(nt),nt},t.prototype.run=function(t,e,r,n,o,i){for(var s=0;s<=t;s++){var a=s/t;this.oneIteration(a,e,o,n,r,i)}},t.prototype.oneIteration=function(t,e,r,n,o,i){var s=1-t;e.forEach((function(a,u){var h=d(a,{x:0,y:0}),l=0===h?0:1/h;if(u!==i){var c=0,f=0,g=0;e.forEach((function(t,e){if(u!==e){var r=d(a,t),i=0===r?0:1/r,s=n[e][u];g+=o[u][e],c+=o[u][e]*(t.x+s*(a.x-t.x)*i),f+=o[u][e]*(t.y+s*(a.y-t.y)*i)}}));var p=0===r[u]?0:1/r[u];g*=s,g+=t*p*p,c*=s,c+=t*p*a.x*l,a.x=c/g,f*=s,f+=t*p*a.y*l,a.y=f/g}}))},t}(),Ee=function(t,e,r,n,o,i,s){if(!t)return[];var u=[];if(e){var h={};e.forEach((function(e,l){var c=[];e.forEach((function(e,u){var f,d;if(l===u)c.push(0);else if(n[l]===n[u])if("data"===i)c.push(e*(Math.abs(l-u)*s)/(n[l]/o));else if(i){var g=void 0,p=void 0;if(h[t[l].id])g=h[t[l].id];else{var m=("id"===i?t[l].id:null===(f=t[l].data)||void 0===f?void 0:f[i])||0;g=a(m)?m.charCodeAt(0):m,h[t[l].id]=g}h[t[u].id]?p=h[t[u].id]:(m=("id"===i?t[u].id:null===(d=t[u].data)||void 0===d?void 0:d[i])||0,p=a(m)?m.charCodeAt(0):m,h[t[u].id]=p),c.push(e*(Math.abs(g-p)*s)/(n[l]/o))}else c.push(e*r/(n[l]/o));else{var y=(r+o)/2;c.push(e*y)}})),u.push(c)}))}return u},Ne=function(t){for(var e=t.length,r=t[0].length,n=[],o=0;o<e;o++){for(var i=[],s=0;s<r;s++)0!==t[o][s]?i.push(1/(t[o][s]*t[o][s])):i.push(0);n.push(i)}return n},Se=function(t,e){var r=-1;return t.forEach((function(t,n){t.id===e&&(r=n)})),Math.max(r,0)},Ae=function(t,e,r){for(var n=t.length,o=0;o<n;o++)if(t[e][o]===1/0){t[e][o]=r,t[o][e]=r;for(var i=0;i<n;i++)t[o][i]!==1/0&&t[e][i]===1/0&&(t[e][i]=r+t[o][i],t[i][e]=r+t[o][i])}for(o=0;o<n;o++)if(o!==e)for(i=0;i<n;i++)if(t[o][i]===1/0){var s=Math.abs(t[e][o]-t[e][i]);s=0===s?1:s,t[o][i]=s}},ke=function(t,e){for(var r=0,n=0;n<t[e].length;n++)t[e][n]!==1/0&&(r=t[e][n]>r?t[e][n]:r);return r},Ie=function(t,e){var r;return r=l(e)?function(){return e}:y(e)?e:function(){return 0},t?h(t)?function(e){return(t[0]>t[1]?t[0]:t[1])+r(e)}:function(e){return t+r(e)}:function(t){var e,n;return(null===(e=t.data)||void 0===e?void 0:e.bboxSize)?Math.max(t.data.bboxSize[0],t.data.bboxSize[1])+r(t):(null===(n=t.data)||void 0===n?void 0:n.size)?h(t.data.size)?Math.max(t.data.size[0],t.data.size[1])+r(t):g(t.data.size)?(t.data.size.width>t.data.size.height?t.data.size.width:t.data.size.height)+r(t):t.data.size+r(t):10+r(t)}},De={center:[0,0],width:300,height:300},Re={circular:M,concentric:S,mds:pe,random:function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="random",this.options=r(r({},De),t)}return t.prototype.execute=function(t,e){return this.genericRandomLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericRandomLayout(!0,t,e)},t.prototype.genericRandomLayout=function(t,e,n){var o=r(r({},this.options),n),i=o.center,s=o.width,a=o.height,u=o.layoutInvisibles,h=o.onLayoutEnd,l=e.getAllNodes();u||(l=l.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e})));var c=s||"undefined"==typeof window?s:window.innerWidth,f=a||"undefined"==typeof window?a:window.innerHeight,d=i||[c/2,f/2],g=[];l&&l.forEach((function(t){g.push({id:t.id,data:{x:.9*(Math.random()-.5)*c+d[0],y:.9*(Math.random()-.5)*f+d[1]}})})),t&&g.forEach((function(t){return e.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}));var p={nodes:g,edges:e.getAllEdges()};return null==h||h(p),p},t}(),grid:Pt,radial:be,force:kt,d3force:bt,fruchterman:Ct};function _e(){(null==de?void 0:de.stop)&&de.stop()}function ze(t,e){return r=this,n=void 0,i=function(){var r,n,o,i,a,u,h,l;return function(t,e){var r,n,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(u){return function(a){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(r=1,n&&(o=2&a[0]?n.return:a[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,a[1])).done)return o;switch(n=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,n=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],n=0}finally{r=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}}(this,(function(c){if(r=t.layout,n=r.id,o=r.options,i=r.iterations,a=t.nodes,u=t.edges,h=new s({nodes:a,edges:u}),!(l=Re[n]))throw new Error("Unknown layout id: ".concat(n));return de=new l(o),[2,new Promise((function(t){var r;de.assign(h,{onLayoutEnd:function(r){t([r,e])}}),(r=de).tick&&r.stop&&r.restart&&(de.stop(),de.tick(i))}))]}))},new((o=void 0)||(o=Promise))((function(t,e){function s(t){try{u(i.next(t))}catch(t){e(t)}}function a(t){try{u(i.throw(t))}catch(t){e(t)}}function u(e){var r;e.done?t(e.value):(r=e.value,r instanceof o?r:new o((function(t){t(r)}))).then(s,a)}u((i=i.apply(r,n||[])).next())}));var r,n,o,i}addEventListener("message",(function(t){var r,n=t.data,o=n.type,i=n.method,s=n.id,a=n.params;"RPC"===o&&i&&((r=e[i])?Promise.resolve().then((function(){return r.apply(e,a)})):Promise.reject("No such method")).then((function(t){postMessage({type:"RPC",id:s,result:t})})).catch((function(t){var e={message:t};t.stack&&(e.message=t.message,e.stack=t.stack,e.name=t.name),postMessage({type:"RPC",id:s,error:e})}))})),postMessage({type:"RPC",method:"ready"});\n//# sourceMappingURL=2a6b6d9f27a9b35490fa.worker.js.map'])),{name:"[fullhash].worker.js"});return URL.revokeObjectURL(URL.createObjectURL(new Blob(['var t={d:(e,r)=>{for(var n in r)t.o(r,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:r[n]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)},e={};t.d(e,{calculateLayout:()=>ze,stopLayout:()=>_e});var r=function(){return r=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var o in e=arguments[r])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},r.apply(this,arguments)};function n(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(t);o<n.length;o++)e.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(t,n[o])&&(r[n[o]]=t[n[o]])}return r}function o(t,e){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var n,o,i=r.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(n=i.next()).done;)s.push(n.value)}catch(t){o={error:t}}finally{try{n&&!n.done&&(r=i.return)&&r.call(i)}finally{if(o)throw o.error}}return s}function i(t,e,r){if(r||2===arguments.length)for(var n,o=0,i=e.length;o<i;o++)!n&&o in e||(n||(n=Array.prototype.slice.call(e,0,o)),n[o]=e[o]);return t.concat(n||Array.prototype.slice.call(e))}Object.create,Object.create;class s{nodeMap=new Map;edgeMap=new Map;inEdgesMap=new Map;outEdgesMap=new Map;treeIndices=new Map;changes=[];batchCount=0;onChanged=()=>{};constructor(t){t&&(t.nodes&&this.addNodes(t.nodes),t.edges&&this.addEdges(t.edges),t.tree&&this.addTree(t.tree),t.onChanged&&(this.onChanged=t.onChanged))}batch=t=>{this.batchCount+=1,t(),this.batchCount-=1,this.batchCount||this.commit()};commit(){const t=this.changes;this.changes=[],this.onChanged({graph:this,changes:t})}reduceChanges(t){let e=[];return t.forEach((t=>{switch(t.type){case"NodeRemoved":{let r=!1;e=e.filter((e=>{if("NodeAdded"===e.type){const n=e.value.id===t.value.id;return n&&(r=!0),!n}return"NodeDataUpdated"===e.type?e.id!==t.value.id:"TreeStructureChanged"!==e.type||e.nodeId!==t.value.id})),r||e.push(t);break}case"EdgeRemoved":{let r=!1;e=e.filter((e=>{if("EdgeAdded"===e.type){const n=e.value.id===t.value.id;return n&&(r=!0),!n}return"EdgeDataUpdated"!==e.type&&"EdgeUpdated"!==e.type||e.id!==t.value.id})),r||e.push(t);break}case"NodeDataUpdated":case"EdgeDataUpdated":case"EdgeUpdated":{const r=e.find((e=>e.type===t.type&&e.id===t.id&&e.propertyName===t.propertyName));r?r.newValue=t.newValue:e.push(t);break}case"TreeStructureDetached":e=e.filter((e=>"TreeStructureAttached"===e.type?e.treeKey!==t.treeKey:"TreeStructureChanged"!==e.type||e.treeKey!==t.treeKey)),e.push(t);break;case"TreeStructureChanged":{const r=e.find((e=>"TreeStructureChanged"===e.type&&e.treeKey===t.treeKey&&e.nodeId===t.nodeId));r?r.newParentId=t.newParentId:e.push(t);break}default:e.push(t)}})),e}checkNodeExistence(t){if(!this.hasNode(t))throw new Error("Node not found for id: "+t)}hasNode(t){return this.nodeMap.has(t)}areNeighbors(t,e){return this.checkNodeExistence(t),this.getNeighbors(e).some((e=>e.id===t))}getNode(t){return this.checkNodeExistence(t),this.nodeMap.get(t)}getRelatedEdges(t,e){this.checkNodeExistence(t);const r=this.inEdgesMap.get(t),n=this.outEdgesMap.get(t);if("in"===e)return Array.from(r);if("out"===e)return Array.from(n);const o=new Set([...r,...n]);return Array.from(o)}getDegree(t,e){return this.getRelatedEdges(t,e).length}getSuccessors(t){const e=this.getRelatedEdges(t,"out").map((t=>t.target));return Array.from(new Set(e)).map((t=>this.getNode(t)))}getPredecessors(t){const e=this.getRelatedEdges(t,"in").map((t=>t.source));return Array.from(new Set(e)).map((t=>this.getNode(t)))}getNeighbors(t){const e=this.getPredecessors(t),r=this.getSuccessors(t);return Array.from(new Set([...e,...r]))}doAddNode(t){if(this.hasNode(t.id))throw new Error("Node already exists: "+t.id);this.nodeMap.set(t.id,t),this.inEdgesMap.set(t.id,new Set),this.outEdgesMap.set(t.id,new Set),this.treeIndices.forEach((e=>{e.childrenMap.set(t.id,new Set)})),this.changes.push({type:"NodeAdded",value:t})}addNodes(t){this.batch((()=>{for(const e of t)this.doAddNode(e)}))}addNode(t){this.addNodes([t])}doRemoveNode(t){const e=this.getNode(t),r=this.inEdgesMap.get(t),n=this.outEdgesMap.get(t);r?.forEach((t=>this.doRemoveEdge(t.id))),n?.forEach((t=>this.doRemoveEdge(t.id))),this.nodeMap.delete(t),this.treeIndices.forEach((e=>{e.childrenMap.get(t)?.forEach((t=>{e.parentMap.delete(t.id)})),e.parentMap.delete(t),e.childrenMap.delete(t)})),this.changes.push({type:"NodeRemoved",value:e})}removeNodes(t){this.batch((()=>{t.forEach((t=>this.doRemoveNode(t)))}))}removeNode(t){this.removeNodes([t])}updateNodeDataProperty(t,e,r){const n=this.getNode(t);this.batch((()=>{const o=n.data[e],i=r;n.data[e]=i,this.changes.push({type:"NodeDataUpdated",id:t,propertyName:e,oldValue:o,newValue:i})}))}mergeNodeData(t,e){this.batch((()=>{Object.entries(e).forEach((([e,r])=>{this.updateNodeDataProperty(t,e,r)}))}))}updateNodeData(...t){const e=t[0],r=this.getNode(e);if("string"==typeof t[1])return void this.updateNodeDataProperty(e,t[1],t[2]);let n;if("function"==typeof t[1]){const e=t[1];n=e(r.data)}else"object"==typeof t[1]&&(n=t[1]);this.batch((()=>{const t=r.data,o=n;r.data=n,this.changes.push({type:"NodeDataUpdated",id:e,oldValue:t,newValue:o})}))}checkEdgeExistence(t){if(!this.hasEdge(t))throw new Error("Edge not found for id: "+t)}hasEdge(t){return this.edgeMap.has(t)}getEdge(t){return this.checkEdgeExistence(t),this.edgeMap.get(t)}getEdgeDetail(t){const e=this.getEdge(t);return{edge:e,source:this.getNode(e.source),target:this.getNode(e.target)}}doAddEdge(t){if(this.hasEdge(t.id))throw new Error("Edge already exists: "+t.id);this.checkNodeExistence(t.source),this.checkNodeExistence(t.target),this.edgeMap.set(t.id,t);const e=this.inEdgesMap.get(t.target),r=this.outEdgesMap.get(t.source);e.add(t),r.add(t),this.changes.push({type:"EdgeAdded",value:t})}addEdges(t){this.batch((()=>{for(const e of t)this.doAddEdge(e)}))}addEdge(t){this.addEdges([t])}doRemoveEdge(t){const e=this.getEdge(t),r=this.outEdgesMap.get(e.source),n=this.inEdgesMap.get(e.target);r.delete(e),n.delete(e),this.edgeMap.delete(t),this.changes.push({type:"EdgeRemoved",value:e})}removeEdges(t){this.batch((()=>{t.forEach((t=>this.doRemoveEdge(t)))}))}removeEdge(t){this.removeEdges([t])}updateEdgeSource(t,e){const r=this.getEdge(t);this.checkNodeExistence(e);const n=r.source,o=e;this.outEdgesMap.get(n).delete(r),this.outEdgesMap.get(o).add(r),r.source=e,this.batch((()=>{this.changes.push({type:"EdgeUpdated",id:t,propertyName:"source",oldValue:n,newValue:o})}))}updateEdgeTarget(t,e){const r=this.getEdge(t);this.checkNodeExistence(e);const n=r.target,o=e;this.inEdgesMap.get(n).delete(r),this.inEdgesMap.get(o).add(r),r.target=e,this.batch((()=>{this.changes.push({type:"EdgeUpdated",id:t,propertyName:"target",oldValue:n,newValue:o})}))}updateEdgeDataProperty(t,e,r){const n=this.getEdge(t);this.batch((()=>{const o=n.data[e],i=r;n.data[e]=i,this.changes.push({type:"EdgeDataUpdated",id:t,propertyName:e,oldValue:o,newValue:i})}))}updateEdgeData(...t){const e=t[0],r=this.getEdge(e);if("string"==typeof t[1])return void this.updateEdgeDataProperty(e,t[1],t[2]);let n;if("function"==typeof t[1]){const e=t[1];n=e(r.data)}else"object"==typeof t[1]&&(n=t[1]);this.batch((()=>{const t=r.data,o=n;r.data=n,this.changes.push({type:"EdgeDataUpdated",id:e,oldValue:t,newValue:o})}))}mergeEdgeData(t,e){this.batch((()=>{Object.entries(e).forEach((([e,r])=>{this.updateEdgeDataProperty(t,e,r)}))}))}checkTreeExistence(t){if(!this.treeIndices.has(t))throw new Error("Tree structure not found for treeKey: "+t)}attachTreeStructure(t){this.treeIndices.has(t)||(this.treeIndices.set(t,{parentMap:new Map,childrenMap:new Map}),this.batch((()=>{this.changes.push({type:"TreeStructureAttached",treeKey:t})})))}detachTreeStructure(t){this.checkTreeExistence(t),this.treeIndices.delete(t),this.batch((()=>{this.changes.push({type:"TreeStructureDetached",treeKey:t})}))}addTree(t,e){this.batch((()=>{this.attachTreeStructure(e);const r=[],n=Array.isArray(t)?t:[t];for(;n.length;){const t=n.shift();r.push(t),t.children&&n.push(...t.children)}this.addNodes(r),r.forEach((t=>{t.children?.forEach((r=>{this.setParent(r.id,t.id,e)}))}))}))}getRoots(t){return this.checkTreeExistence(t),this.getAllNodes().filter((e=>!this.getParent(e.id,t)))}getChildren(t,e){this.checkNodeExistence(t),this.checkTreeExistence(e);const r=this.treeIndices.get(e).childrenMap.get(t);return Array.from(r||[])}getParent(t,e){return this.checkNodeExistence(t),this.checkTreeExistence(e),this.treeIndices.get(e).parentMap.get(t)||null}setParent(t,e,r){this.checkTreeExistence(r);const n=this.treeIndices.get(r),o=this.getNode(t),i=n.parentMap.get(t),s=this.getNode(e);n.parentMap.set(t,s),i&&n.childrenMap.get(i.id)?.delete(o);let a=n.childrenMap.get(s.id);a||(a=new Set,n.childrenMap.set(s.id,a)),a.add(o),this.batch((()=>{this.changes.push({type:"TreeStructureChanged",treeKey:r,nodeId:t,oldParentId:i?.id,newParentId:s.id})}))}getAllNodes(){return Array.from(this.nodeMap.values())}getAllEdges(){return Array.from(this.edgeMap.values())}doBFS(t,e,r){for(;t.length;){const n=t.shift();r(n),e.add(n.id),this.getSuccessors(n.id).forEach((r=>{e.has(r.id)||(e.add(r.id),t.push(r))}))}}bfs(t,e){this.doBFS([this.getNode(t)],new Set,e)}doDFS(t,e,r){r(t),e.add(t.id),this.getSuccessors(t.id).forEach((t=>{e.has(t.id)||this.doDFS(t,e,r)}))}dfs(t,e){this.doDFS(this.getNode(t),new Set,e)}clone(){const t=this.getAllNodes().map((t=>({...t,data:{...t.data}}))),e=this.getAllEdges().map((t=>({...t,data:{...t.data}}))),r=new s({nodes:t,edges:e});return this.treeIndices.forEach((({parentMap:t,childrenMap:e},n)=>{const o=new Map;t.forEach(((t,e)=>{o.set(e,r.getNode(t.id))}));const i=new Map;e.forEach(((t,e)=>{i.set(e,new Set(Array.from(t).map((t=>r.getNode(t.id)))))})),r.treeIndices.set(n,{parentMap:o,childrenMap:i})})),r}toJSON(){return JSON.stringify({nodes:this.getAllNodes(),edges:this.getAllEdges()})}}var a=function(t){return"string"==typeof t},u=/-(\\w)/g,h=(function(t){return t.replace(u,(function(t,e){return e?e.toUpperCase():""}))},Object.create(null),Array.isArray),l=function(t){return"number"==typeof t},c=function(t){for(var e=[],r=t.length,n=0;n<r;n+=1){e[n]=[];for(var o=0;o<r;o+=1)n===o?e[n][o]=0:0!==t[n][o]&&t[n][o]?e[n][o]=t[n][o]:e[n][o]=1/0}for(var i=0;i<r;i+=1)for(n=0;n<r;n+=1)for(o=0;o<r;o+=1)e[n][o]>e[n][i]+e[i][o]&&(e[n][o]=e[n][i]+e[i][o]);return e},f=function(t,e){var r=t.nodes,n=t.edges,o=[],i={};if(!r)throw new Error("invalid nodes data!");return r&&r.forEach((function(t,e){i[t.id]=e,o.push([])})),null==n||n.forEach((function(t){var r=t.source,n=t.target,s=i[r],a=i[n];void 0!==s&&void 0!==a&&(o[s][a]=1,e||(o[a][s]=1))})),o},d=function(t,e){return Math.sqrt((t.x-e.x)*(t.x-e.x)+(t.y-e.y)*(t.y-e.y))},g=function(t){return null!==t&&"object"==typeof t},p=function(t){if(null===t)return t;if(t instanceof Date)return new Date(t.getTime());if(t instanceof Array){var e=[];return t.forEach((function(t){e.push(t)})),e.map((function(t){return p(t)}))}if("object"==typeof t&&Object.keys(t).length){var n=r({},t);return Object.keys(n).forEach((function(t){n[t]=p(n[t])})),n}return t},m=function(t,e){var r=p(t);return r.data=r.data||{},e&&(l(r.data.x)||(r.data.x=Math.random()*e[0]),l(r.data.y)||(r.data.y=Math.random()*e[1])),r},y=function(t){return"function"==typeof t};function w(t,e){return y(e)?e:l(e)?function(){return e}:function(){return t}}function v(t,e,r){return void 0===r&&(r=!0),e||0===e?y(e)?e:l(e)?function(){return e}:h(e)?function(){if(r){var n=Math.max.apply(Math,i([],o(e),!1));return isNaN(n)?t:n}return e}:g(e)?function(){if(r){var n=Math.max(e.width,e.height);return isNaN(n)?t:n}return[e.width,e.height]}:function(){return t}:function(e){var r=(e.data||{}).size;return r?h(r)?r[0]>r[1]?r[0]:r[1]:g(r)?r.width>r.height?r.width:r.height:r:t}}var x={radius:null,startRadius:null,endRadius:null,startAngle:0,endAngle:2*Math.PI,clockwise:!0,divisions:1,ordering:null,angleRatio:1},M=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="circular",this.options=r(r({},x),t)}return t.prototype.execute=function(t,e){return this.genericCircularLayout(!1,t,e)},t.prototype.assign=function(t,e){var r=this;t.batch((function(){r.genericCircularLayout(!0,t,e)}))},t.prototype.genericCircularLayout=function(t,e,n){var i=r(r({},this.options),n),s=i.width,a=i.height,u=i.center,h=i.divisions,l=i.startAngle,c=void 0===l?0:l,f=i.endAngle,d=void 0===f?2*Math.PI:f,g=i.angleRatio,p=i.ordering,y=i.clockwise,x=i.nodeSpacing,M=i.nodeSize,N=i.layoutInvisibles,S=i.onLayoutEnd,A=e.getAllNodes(),k=e.getAllEdges();N||(A=A.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e})),k=k.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e})));var I=A.length;if(0===I)return null==S||S({nodes:[],edges:[]}),{nodes:[],edges:[]};var D=o(E(s,a,u),3),R=D[0],_=D[1],z=D[2];if(1===I){t&&e.mergeNodeData(A[0].id,{x:z[0],y:z[1]});var T={nodes:[r(r({},A[0]),{data:r(r({},A[0].data),{x:z[0],y:z[1]})})],edges:k};return null==S||S(T),T}var C=(d-c)/I,O=i.radius,P=i.startRadius,L=i.endRadius;if(x){var q=w(10,x),j=v(10,M),V=-1/0;A.forEach((function(t){var e=j(t);V<e&&(V=e)}));var F=0;A.forEach((function(t,e){F+=0===e?V||10:(q(t)||0)+(V||10)})),O=F/(2*Math.PI)}else O||P||L?!P&&L?P=L:P&&!L&&(L=P):O=Math.min(_,R)/2;var $=C*g,U=[];U="topology"===p?b(e,A):"topology-directed"===p?b(e,A,!0):"degree"===p?function(t,e){var r=[];return e.forEach((function(t,e){r.push(m(t))})),r.sort((function(e,r){return t.getDegree(e.id,"both")-t.getDegree(r.id,"both")})),r}(e,A):A.map((function(t){return m(t)}));for(var B=Math.ceil(I/h),G=0;G<I;++G){var K=O;K||null===P||null===L||(K=P+G*(L-P)/(I-1)),K||(K=10+100*G/(I-1));var W=c+G%B*$+2*Math.PI/h*Math.floor(G/B);y||(W=d-G%B*$-2*Math.PI/h*Math.floor(G/B)),U[G].data.x=z[0]+Math.cos(W)*K,U[G].data.y=z[1]+Math.sin(W)*K}t&&U.forEach((function(t){e.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}));var H={nodes:U,edges:k};return null==S||S(H),H},t}(),b=function(t,e,r){void 0===r&&(r=!1);var n=[m(e[0])],o={},i=e.length;o[e[0].id]=!0;var s=0;return e.forEach((function(a,u){if(0!==u)if(u!==i-1&&t.getDegree(a.id,"both")===t.getDegree(e[u+1].id,"both")&&!t.areNeighbors(n[s].id,a.id)||o[a.id]){for(var h=r?t.getSuccessors(n[s].id):t.getNeighbors(n[s].id),l=!1,c=0;c<h.length;c++){var f=h[c];if(t.getDegree(f.id)===t.getDegree(a.id)&&!o[f.id]){n.push(m(f)),o[f.id]=!0,l=!0;break}}for(var d=0;!l&&(o[e[d].id]||(n.push(m(e[d])),o[e[d].id]=!0,l=!0),++d!==i););}else n.push(m(a)),o[a.id]=!0,s++})),n},E=function(t,e,r){var n=t,o=e,i=r;return n||"undefined"==typeof window||(n=window.innerWidth),o||"undefined"==typeof window||(o=window.innerHeight),i||(i=[n/2,o/2]),[n,o,i]},N={nodeSize:30,minNodeSpacing:10,nodeSpacing:10,preventOverlap:!1,sweep:void 0,equidistant:!1,startAngle:1.5*Math.PI,clockwise:!0,maxLevelDiff:void 0,sortBy:"degree"},S=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="concentric",this.options=r(r({},N),t)}return t.prototype.execute=function(t,e){return this.genericConcentricLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericConcentricLayout(!0,t,e)},t.prototype.genericConcentricLayout=function(t,e,n){var o=r(r({},this.options),n),i=o.center,s=o.width,u=o.height,c=o.sortBy,f=o.maxLevelDiff,d=o.sweep,p=o.clockwise,w=o.equidistant,v=o.minNodeSpacing,x=void 0===v?10:v,M=o.preventOverlap,b=o.startAngle,E=void 0===b?1.5*Math.PI:b,N=o.nodeSize,S=o.nodeSpacing,A=o.layoutInvisibles,k=o.onLayoutEnd,I=e.getAllNodes(),D=e.getAllEdges();A||(I=I.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e})),D=D.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e})));var R=I.length;if(0===R){var _={nodes:[],edges:D};return null==k||k(_),_}var z=s||"undefined"==typeof window?s:window.innerWidth,T=u||"undefined"==typeof window?u:window.innerHeight,C=i||[z/2,T/2];if(1===R){t&&e.mergeNodeData(I[0].id,{x:C[0],y:C[1]});var O={nodes:[r(r({},I[0]),{data:r(r({},I[0].data),{x:C[0],y:C[1]})})],edges:D};return null==k||k(O),O}var P,L=[],q=0;P=h(N)?Math.max(N[0],N[1]):N,h(S)?q=Math.max(S[0],S[1]):l(S)&&(q=S),I.forEach((function(t){var e=m(t);L.push(e);var r=P,n=e.data;h(n.size)?r=Math.max(n.size[0],n.size[1]):l(n.size)?r=n.size:g(n.size)&&(r=Math.max(n.size.width,n.size.height)),P=Math.max(P,r),y(S)&&(q=Math.max(S(t),q))}));var j={};L.forEach((function(t,e){j[t.id]=e}));var V=c;a(V)&&void 0!==L[0].data[V]||(V="degree"),"degree"===V?L.sort((function(t,r){return e.getDegree(r.id,"both")-e.getDegree(t.id,"both")})):L.sort((function(t,e){return e.data[V]-t.data[V]}));var F=L[0],$=(f||("degree"===V?e.getDegree(F.id,"both"):F.data[V]))/4,U=[{nodes:[]}],B=U[0];L.forEach((function(t){if(B.nodes.length>0){var r="degree"===V?Math.abs(e.getDegree(B.nodes[0].id,"both")-e.getDegree(t.id,"both")):Math.abs(B.nodes[0].data[V]-t.data[V]);$&&r>=$&&(B={nodes:[]},U.push(B))}B.nodes.push(t)}));var G=P+(q||x);if(!M){var K=U.length>0&&U[0].nodes.length>1,W=(Math.min(z,T)/2-G)/(U.length+(K?1:0));G=Math.min(G,W)}var H=0;if(U.forEach((function(t){var e=void 0===d?2*Math.PI-2*Math.PI/t.nodes.length:d;if(t.dTheta=e/Math.max(1,t.nodes.length-1),t.nodes.length>1&&M){var r=Math.cos(t.dTheta)-Math.cos(0),n=Math.sin(t.dTheta)-Math.sin(0),o=Math.sqrt(G*G/(r*r+n*n));H=Math.max(o,H)}t.r=H,H+=G})),w){for(var J=0,Y=0,X=0;X<U.length;X++){var Q=(U[X].r||0)-Y;J=Math.max(J,Q)}Y=0,U.forEach((function(t,e){0===e&&(Y=t.r||0),t.r=Y,Y+=J}))}U.forEach((function(t){var e=t.dTheta||0,r=t.r||0;t.nodes.forEach((function(t,n){var o=E+(p?1:-1)*e*n;t.data.x=C[0]+r*Math.cos(o),t.data.y=C[1]+r*Math.sin(o)}))})),t&&L.forEach((function(t){return e.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}));var Z={nodes:L,edges:D};return null==k||k(Z),Z},t}();function A(t,e,r,n){if(isNaN(e)||isNaN(r))return t;var o,i,s,a,u,h,l,c,f,d=t._root,g={data:n},p=t._x0,m=t._y0,y=t._x1,w=t._y1;if(!d)return t._root=g,t;for(;d.length;)if((h=e>=(i=(p+y)/2))?p=i:y=i,(l=r>=(s=(m+w)/2))?m=s:w=s,o=d,!(d=d[c=l<<1|h]))return o[c]=g,t;if(a=+t._x.call(null,d.data),u=+t._y.call(null,d.data),e===a&&r===u)return g.next=d,o?o[c]=g:t._root=g,t;do{o=o?o[c]=new Array(4):t._root=new Array(4),(h=e>=(i=(p+y)/2))?p=i:y=i,(l=r>=(s=(m+w)/2))?m=s:w=s}while((c=l<<1|h)==(f=(u>=s)<<1|a>=i));return o[f]=d,o[c]=g,t}function k(t,e,r,n,o){this.node=t,this.x0=e,this.y0=r,this.x1=n,this.y1=o}function I(t){return t[0]}function D(t){return t[1]}function R(t,e,r){var n=new _(null==e?I:e,null==r?D:r,NaN,NaN,NaN,NaN);return null==t?n:n.addAll(t)}function _(t,e,r,n,o,i){this._x=t,this._y=e,this._x0=r,this._y0=n,this._x1=o,this._y1=i,this._root=void 0}function z(t){for(var e={data:t.data},r=e;t=t.next;)r=r.next={data:t.data};return e}var T=R.prototype=_.prototype;function C(t){return function(){return t}}function O(t){return 1e-6*(t()-.5)}T.copy=function(){var t,e,r=new _(this._x,this._y,this._x0,this._y0,this._x1,this._y1),n=this._root;if(!n)return r;if(!n.length)return r._root=z(n),r;for(t=[{source:n,target:r._root=new Array(4)}];n=t.pop();)for(var o=0;o<4;++o)(e=n.source[o])&&(e.length?t.push({source:e,target:n.target[o]=new Array(4)}):n.target[o]=z(e));return r},T.add=function(t){const e=+this._x.call(null,t),r=+this._y.call(null,t);return A(this.cover(e,r),e,r,t)},T.addAll=function(t){var e,r,n,o,i=t.length,s=new Array(i),a=new Array(i),u=1/0,h=1/0,l=-1/0,c=-1/0;for(r=0;r<i;++r)isNaN(n=+this._x.call(null,e=t[r]))||isNaN(o=+this._y.call(null,e))||(s[r]=n,a[r]=o,n<u&&(u=n),n>l&&(l=n),o<h&&(h=o),o>c&&(c=o));if(u>l||h>c)return this;for(this.cover(u,h).cover(l,c),r=0;r<i;++r)A(this,s[r],a[r],t[r]);return this},T.cover=function(t,e){if(isNaN(t=+t)||isNaN(e=+e))return this;var r=this._x0,n=this._y0,o=this._x1,i=this._y1;if(isNaN(r))o=(r=Math.floor(t))+1,i=(n=Math.floor(e))+1;else{for(var s,a,u=o-r||1,h=this._root;r>t||t>=o||n>e||e>=i;)switch(a=(e<n)<<1|t<r,(s=new Array(4))[a]=h,h=s,u*=2,a){case 0:o=r+u,i=n+u;break;case 1:r=o-u,i=n+u;break;case 2:o=r+u,n=i-u;break;case 3:r=o-u,n=i-u}this._root&&this._root.length&&(this._root=h)}return this._x0=r,this._y0=n,this._x1=o,this._y1=i,this},T.data=function(){var t=[];return this.visit((function(e){if(!e.length)do{t.push(e.data)}while(e=e.next)})),t},T.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]]},T.find=function(t,e,r){var n,o,i,s,a,u,h,l=this._x0,c=this._y0,f=this._x1,d=this._y1,g=[],p=this._root;for(p&&g.push(new k(p,l,c,f,d)),null==r?r=1/0:(l=t-r,c=e-r,f=t+r,d=e+r,r*=r);u=g.pop();)if(!(!(p=u.node)||(o=u.x0)>f||(i=u.y0)>d||(s=u.x1)<l||(a=u.y1)<c))if(p.length){var m=(o+s)/2,y=(i+a)/2;g.push(new k(p[3],m,y,s,a),new k(p[2],o,y,m,a),new k(p[1],m,i,s,y),new k(p[0],o,i,m,y)),(h=(e>=y)<<1|t>=m)&&(u=g[g.length-1],g[g.length-1]=g[g.length-1-h],g[g.length-1-h]=u)}else{var w=t-+this._x.call(null,p.data),v=e-+this._y.call(null,p.data),x=w*w+v*v;if(x<r){var M=Math.sqrt(r=x);l=t-M,c=e-M,f=t+M,d=e+M,n=p.data}}return n},T.remove=function(t){if(isNaN(i=+this._x.call(null,t))||isNaN(s=+this._y.call(null,t)))return this;var e,r,n,o,i,s,a,u,h,l,c,f,d=this._root,g=this._x0,p=this._y0,m=this._x1,y=this._y1;if(!d)return this;if(d.length)for(;;){if((h=i>=(a=(g+m)/2))?g=a:m=a,(l=s>=(u=(p+y)/2))?p=u:y=u,e=d,!(d=d[c=l<<1|h]))return this;if(!d.length)break;(e[c+1&3]||e[c+2&3]||e[c+3&3])&&(r=e,f=c)}for(;d.data!==t;)if(n=d,!(d=d.next))return this;return(o=d.next)&&delete d.next,n?(o?n.next=o:delete n.next,this):e?(o?e[c]=o:delete e[c],(d=e[0]||e[1]||e[2]||e[3])&&d===(e[3]||e[2]||e[1]||e[0])&&!d.length&&(r?r[f]=d:this._root=d),this):(this._root=o,this)},T.removeAll=function(t){for(var e=0,r=t.length;e<r;++e)this.remove(t[e]);return this},T.root=function(){return this._root},T.size=function(){var t=0;return this.visit((function(e){if(!e.length)do{++t}while(e=e.next)})),t},T.visit=function(t){var e,r,n,o,i,s,a=[],u=this._root;for(u&&a.push(new k(u,this._x0,this._y0,this._x1,this._y1));e=a.pop();)if(!t(u=e.node,n=e.x0,o=e.y0,i=e.x1,s=e.y1)&&u.length){var h=(n+i)/2,l=(o+s)/2;(r=u[3])&&a.push(new k(r,h,l,i,s)),(r=u[2])&&a.push(new k(r,n,l,h,s)),(r=u[1])&&a.push(new k(r,h,o,i,l)),(r=u[0])&&a.push(new k(r,n,o,h,l))}return this},T.visitAfter=function(t){var e,r=[],n=[];for(this._root&&r.push(new k(this._root,this._x0,this._y0,this._x1,this._y1));e=r.pop();){var o=e.node;if(o.length){var i,s=e.x0,a=e.y0,u=e.x1,h=e.y1,l=(s+u)/2,c=(a+h)/2;(i=o[0])&&r.push(new k(i,s,a,l,c)),(i=o[1])&&r.push(new k(i,l,a,u,c)),(i=o[2])&&r.push(new k(i,s,c,l,h)),(i=o[3])&&r.push(new k(i,l,c,u,h))}n.push(e)}for(;e=n.pop();)t(e.node,e.x0,e.y0,e.x1,e.y1);return this},T.x=function(t){return arguments.length?(this._x=t,this):this._x},T.y=function(t){return arguments.length?(this._y=t,this):this._y};var P={value:()=>{}};function L(){for(var t,e=0,r=arguments.length,n={};e<r;++e){if(!(t=arguments[e]+"")||t in n||/[\\s.]/.test(t))throw new Error("illegal type: "+t);n[t]=[]}return new q(n)}function q(t){this._=t}function j(t,e){return t.trim().split(/^|\\s+/).map((function(t){var r="",n=t.indexOf(".");if(n>=0&&(r=t.slice(n+1),t=t.slice(0,n)),t&&!e.hasOwnProperty(t))throw new Error("unknown type: "+t);return{type:t,name:r}}))}function V(t,e){for(var r,n=0,o=t.length;n<o;++n)if((r=t[n]).name===e)return r.value}function F(t,e,r){for(var n=0,o=t.length;n<o;++n)if(t[n].name===e){t[n]=P,t=t.slice(0,n).concat(t.slice(n+1));break}return null!=r&&t.push({name:e,value:r}),t}q.prototype=L.prototype={constructor:q,on:function(t,e){var r,n=this._,o=j(t+"",n),i=-1,s=o.length;if(!(arguments.length<2)){if(null!=e&&"function"!=typeof e)throw new Error("invalid callback: "+e);for(;++i<s;)if(r=(t=o[i]).type)n[r]=F(n[r],t.name,e);else if(null==e)for(r in n)n[r]=F(n[r],t.name,null);return this}for(;++i<s;)if((r=(t=o[i]).type)&&(r=V(n[r],t.name)))return r},copy:function(){var t={},e=this._;for(var r in e)t[r]=e[r].slice();return new q(t)},call:function(t,e){if((r=arguments.length-2)>0)for(var r,n,o=new Array(r),i=0;i<r;++i)o[i]=arguments[i+2];if(!this._.hasOwnProperty(t))throw new Error("unknown type: "+t);for(i=0,r=(n=this._[t]).length;i<r;++i)n[i].value.apply(e,o)},apply:function(t,e,r){if(!this._.hasOwnProperty(t))throw new Error("unknown type: "+t);for(var n=this._[t],o=0,i=n.length;o<i;++o)n[o].value.apply(e,r)}};const $=L;var U,B,G=0,K=0,W=0,H=0,J=0,Y=0,X="object"==typeof performance&&performance.now?performance:Date,Q="object"==typeof window&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(t){setTimeout(t,17)};function Z(){return J||(Q(tt),J=X.now()+Y)}function tt(){J=0}function et(){this._call=this._time=this._next=null}function rt(t,e,r){var n=new et;return n.restart(t,e,r),n}function nt(){J=(H=X.now())+Y,G=K=0;try{!function(){Z(),++G;for(var t,e=U;e;)(t=J-e._time)>=0&&e._call.call(void 0,t),e=e._next;--G}()}finally{G=0,function(){for(var t,e,r=U,n=1/0;r;)r._call?(n>r._time&&(n=r._time),t=r,r=r._next):(e=r._next,r._next=null,r=t?t._next=e:U=e);B=t,it(n)}(),J=0}}function ot(){var t=X.now(),e=t-H;e>1e3&&(Y-=e,H=t)}function it(t){G||(K&&(K=clearTimeout(K)),t-J>24?(t<1/0&&(K=setTimeout(nt,t-X.now()-Y)),W&&(W=clearInterval(W))):(W||(H=X.now(),W=setInterval(ot,1e3)),G=1,Q(nt)))}et.prototype=rt.prototype={constructor:et,restart:function(t,e,r){if("function"!=typeof t)throw new TypeError("callback is not a function");r=(null==r?Z():+r)+(null==e?0:+e),this._next||B===this||(B?B._next=this:U=this,B=this),this._call=t,this._time=r,it()},stop:function(){this._call&&(this._call=null,this._time=1/0,it())}};const st=4294967296;function at(t){return t.x}function ut(t){return t.y}var ht=Math.PI*(3-Math.sqrt(5));function lt(t){var e,r=1,n=.001,o=1-Math.pow(n,1/300),i=0,s=.6,a=new Map,u=rt(c),h=$("tick","end"),l=function(){let t=1;return()=>(t=(1664525*t+1013904223)%st)/st}();function c(){f(),h.call("tick",e),r<n&&(u.stop(),h.call("end",e))}function f(n){var u,h,l=t.length;void 0===n&&(n=1);for(var c=0;c<n;++c)for(r+=(i-r)*o,a.forEach((function(t){t(r)})),u=0;u<l;++u)null==(h=t[u]).fx?h.x+=h.vx*=s:(h.x=h.fx,h.vx=0),null==h.fy?h.y+=h.vy*=s:(h.y=h.fy,h.vy=0);return e}function d(){for(var e,r=0,n=t.length;r<n;++r){if((e=t[r]).index=r,null!=e.fx&&(e.x=e.fx),null!=e.fy&&(e.y=e.fy),isNaN(e.x)||isNaN(e.y)){var o=10*Math.sqrt(.5+r),i=r*ht;e.x=o*Math.cos(i),e.y=o*Math.sin(i)}(isNaN(e.vx)||isNaN(e.vy))&&(e.vx=e.vy=0)}}function g(e){return e.initialize&&e.initialize(t,l),e}return null==t&&(t=[]),d(),e={tick:f,restart:function(){return u.restart(c),e},stop:function(){return u.stop(),e},nodes:function(r){return arguments.length?(t=r,d(),a.forEach(g),e):t},alpha:function(t){return arguments.length?(r=+t,e):r},alphaMin:function(t){return arguments.length?(n=+t,e):n},alphaDecay:function(t){return arguments.length?(o=+t,e):+o},alphaTarget:function(t){return arguments.length?(i=+t,e):i},velocityDecay:function(t){return arguments.length?(s=1-t,e):1-s},randomSource:function(t){return arguments.length?(l=t,a.forEach(g),e):l},force:function(t,r){return arguments.length>1?(null==r?a.delete(t):a.set(t,g(r)),e):a.get(t)},find:function(e,r,n){var o,i,s,a,u,h=0,l=t.length;for(null==n?n=1/0:n*=n,h=0;h<l;++h)(s=(o=e-(a=t[h]).x)*o+(i=r-a.y)*i)<n&&(u=a,n=s);return u},on:function(t,r){return arguments.length>1?(h.on(t,r),e):h.on(t)}}}function ct(){var t,e,r,n,o,i=C(-30),s=1,a=1/0,u=.81;function h(r){var o,i=t.length,s=R(t,at,ut).visitAfter(c);for(n=r,o=0;o<i;++o)e=t[o],s.visit(f)}function l(){if(t){var e,r,n=t.length;for(o=new Array(n),e=0;e<n;++e)r=t[e],o[r.index]=+i(r,e,t)}}function c(t){var e,r,n,i,s,a=0,u=0;if(t.length){for(n=i=s=0;s<4;++s)(e=t[s])&&(r=Math.abs(e.value))&&(a+=e.value,u+=r,n+=r*e.x,i+=r*e.y);t.x=n/u,t.y=i/u}else{(e=t).x=e.data.x,e.y=e.data.y;do{a+=o[e.data.index]}while(e=e.next)}t.value=a}function f(t,i,h,l){if(!t.value)return!0;var c=t.x-e.x,f=t.y-e.y,d=l-i,g=c*c+f*f;if(d*d/u<g)return g<a&&(0===c&&(g+=(c=O(r))*c),0===f&&(g+=(f=O(r))*f),g<s&&(g=Math.sqrt(s*g)),e.vx+=c*t.value*n/g,e.vy+=f*t.value*n/g),!0;if(!(t.length||g>=a)){(t.data!==e||t.next)&&(0===c&&(g+=(c=O(r))*c),0===f&&(g+=(f=O(r))*f),g<s&&(g=Math.sqrt(s*g)));do{t.data!==e&&(d=o[t.data.index]*n/g,e.vx+=c*d,e.vy+=f*d)}while(t=t.next)}}return h.initialize=function(e,n){t=e,r=n,l()},h.strength=function(t){return arguments.length?(i="function"==typeof t?t:C(+t),l(),h):i},h.distanceMin=function(t){return arguments.length?(s=t*t,h):Math.sqrt(s)},h.distanceMax=function(t){return arguments.length?(a=t*t,h):Math.sqrt(a)},h.theta=function(t){return arguments.length?(u=t*t,h):Math.sqrt(u)},h}function ft(t){return t.index}function dt(t,e){var r=t.get(e);if(!r)throw new Error("node not found: "+e);return r}function gt(t){var e,r,n,o,i,s,a=ft,u=function(t){return 1/Math.min(o[t.source.index],o[t.target.index])},h=C(30),l=1;function c(n){for(var o=0,a=t.length;o<l;++o)for(var u,h,c,f,d,g,p,m=0;m<a;++m)h=(u=t[m]).source,f=(c=u.target).x+c.vx-h.x-h.vx||O(s),d=c.y+c.vy-h.y-h.vy||O(s),f*=g=((g=Math.sqrt(f*f+d*d))-r[m])/g*n*e[m],d*=g,c.vx-=f*(p=i[m]),c.vy-=d*p,h.vx+=f*(p=1-p),h.vy+=d*p}function f(){if(n){var s,u,h=n.length,l=t.length,c=new Map(n.map(((t,e)=>[a(t,e,n),t])));for(s=0,o=new Array(h);s<l;++s)(u=t[s]).index=s,"object"!=typeof u.source&&(u.source=dt(c,u.source)),"object"!=typeof u.target&&(u.target=dt(c,u.target)),o[u.source.index]=(o[u.source.index]||0)+1,o[u.target.index]=(o[u.target.index]||0)+1;for(s=0,i=new Array(l);s<l;++s)u=t[s],i[s]=o[u.source.index]/(o[u.source.index]+o[u.target.index]);e=new Array(l),d(),r=new Array(l),g()}}function d(){if(n)for(var r=0,o=t.length;r<o;++r)e[r]=+u(t[r],r,t)}function g(){if(n)for(var e=0,o=t.length;e<o;++e)r[e]=+h(t[e],e,t)}return null==t&&(t=[]),c.initialize=function(t,e){n=t,s=e,f()},c.links=function(e){return arguments.length?(t=e,f(),c):t},c.id=function(t){return arguments.length?(a=t,c):a},c.iterations=function(t){return arguments.length?(l=+t,c):l},c.strength=function(t){return arguments.length?(u="function"==typeof t?t:C(+t),d(),c):u},c.distance=function(t){return arguments.length?(h="function"==typeof t?t:C(+t),g(),c):h},c}function pt(t){return t.x+t.vx}function mt(t){return t.y+t.vy}function yt(t){var e,r,n,o=1,i=1;function s(){for(var t,s,u,h,l,c,f,d=e.length,g=0;g<i;++g)for(s=R(e,pt,mt).visitAfter(a),t=0;t<d;++t)u=e[t],c=r[u.index],f=c*c,h=u.x+u.vx,l=u.y+u.vy,s.visit(p);function p(t,e,r,i,s){var a=t.data,d=t.r,g=c+d;if(!a)return e>h+g||i<h-g||r>l+g||s<l-g;if(a.index>u.index){var p=h-a.x-a.vx,m=l-a.y-a.vy,y=p*p+m*m;y<g*g&&(0===p&&(y+=(p=O(n))*p),0===m&&(y+=(m=O(n))*m),y=(g-(y=Math.sqrt(y)))/y*o,u.vx+=(p*=y)*(g=(d*=d)/(f+d)),u.vy+=(m*=y)*g,a.vx-=p*(g=1-g),a.vy-=m*g)}}}function a(t){if(t.data)return t.r=r[t.data.index];for(var e=t.r=0;e<4;++e)t[e]&&t[e].r>t.r&&(t.r=t[e].r)}function u(){if(e){var n,o,i=e.length;for(r=new Array(i),n=0;n<i;++n)o=e[n],r[o.index]=+t(o,n,e)}}return"function"!=typeof t&&(t=C(null==t?1:+t)),s.initialize=function(t,r){e=t,n=r,u()},s.iterations=function(t){return arguments.length?(i=+t,s):i},s.strength=function(t){return arguments.length?(o=+t,s):o},s.radius=function(e){return arguments.length?(t="function"==typeof e?e:C(+e),u(),s):t},s}function wt(t){var e,r,n,o=C(.1);function i(t){for(var o,i=0,s=e.length;i<s;++i)(o=e[i]).vx+=(n[i]-o.x)*r[i]*t}function s(){if(e){var i,s=e.length;for(r=new Array(s),n=new Array(s),i=0;i<s;++i)r[i]=isNaN(n[i]=+t(e[i],i,e))?0:+o(e[i],i,e)}}return"function"!=typeof t&&(t=C(null==t?0:+t)),i.initialize=function(t){e=t,s()},i.strength=function(t){return arguments.length?(o="function"==typeof t?t:C(+t),s(),i):o},i.x=function(e){return arguments.length?(t="function"==typeof e?e:C(+e),s(),i):t},i}function vt(t){var e,r,n,o=C(.1);function i(t){for(var o,i=0,s=e.length;i<s;++i)(o=e[i]).vy+=(n[i]-o.y)*r[i]*t}function s(){if(e){var i,s=e.length;for(r=new Array(s),n=new Array(s),i=0;i<s;++i)r[i]=isNaN(n[i]=+t(e[i],i,e))?0:+o(e[i],i,e)}}return"function"!=typeof t&&(t=C(null==t?0:+t)),i.initialize=function(t){e=t,s()},i.strength=function(t){return arguments.length?(o="function"==typeof t?t:C(+t),s(),i):o},i.y=function(e){return arguments.length?(t="function"==typeof e?e:C(+e),s(),i):t},i}function xt(){function t(t){return function(){return t}}var e,r=function(t){return t.cluster},n=t(1),i=t(-1),s=t(100),a=t(.1),u=[0,0],h=[],l={},c=[],f=100,d=100,g={none:{x:0,y:0}},p=[],m="force",y=!0,w=.1;function v(t){if(!y)return v;e.tick(),M();for(var n=0,o=h.length,i=void 0,s=t*w;n<o;++n)(i=h[n]).vx+=(g[r(i)].x-i.x)*s,i.vy+=(g[r(i)].y-i.y)*s}function x(){h&&function(){if(h&&h.length){if(void 0===r(h[0]))throw Error("Couldnt find the grouping attribute for the nodes. Make sure to set it up with forceInBox.groupBy(\'clusterAttr\') before calling .links()");var t,u,g,m,y,w=(t=[],u=[],g={},{},y=[],m=function(t){var e={};return t.forEach((function(t){var n=r(t);e[n]||(e[n]={count:0,sumforceNodeSize:0})})),t.forEach((function(t){var o=r(t),i=n(t),s=e[o];s.count=s.count+1,s.sumforceNodeSize=s.sumforceNodeSize+Math.PI*(i*i)*1.3,e[o]=s})),e}(h),y=function(t){var e={},n=[];return t.forEach((function(t){var n,o,i,s,a,u=(o=(n=t).source,i=n.target,(s=r(l[o]))<=(a=r(l[i]))?"".concat(s,"~").concat(a):"".concat(a,"~").concat(s)),h=0;void 0!==e[u]&&(h=e[u]),h+=1,e[u]=h})),Object.entries(e).forEach((function(t){var e=o(t,2),r=e[0],i=e[1],s=r.split("~")[0],a=r.split("~")[1];void 0!==s&&void 0!==a&&n.push({source:s,target:a,count:i})})),n}(c),Object.keys(m).forEach((function(e,r){var n=m[e];t.push({id:e,size:n.count,r:Math.sqrt(n.sumforceNodeSize/Math.PI)}),g[e]=r})),y.forEach((function(t){var e=t.source,r=t.target,n=g[e],o=g[r];void 0!==n&&void 0!==o&&u.push({source:n,target:o,count:t.count})})),{nodes:t,links:u});e=lt(w.nodes).force("x",wt(f).strength(.1)).force("y",vt(d).strength(.1)).force("collide",yt((function(t){return t.r})).iterations(4)).force("charge",ct().strength(i)).force("links",gt(w.nodes.length?w.links:[]).distance(s).strength(a)),p=e.nodes(),M()}}()}function M(){return g={none:{x:0,y:0}},p.forEach((function(t){g[t.id]={x:t.x-u[0],y:t.y-u[1]}})),g}function b(t){l={},t.forEach((function(t){l[t.id]=t}))}return v.initialize=function(t){h=t,x()},v.template=function(t){return arguments.length?(m=t,x(),v):m},v.groupBy=function(t){return arguments.length?"string"==typeof t?(r=function(e){return e[t]},v):(r=t,v):r},v.enableGrouping=function(t){return arguments.length?(y=t,v):y},v.strength=function(t){return arguments.length?(w=t,v):w},v.centerX=function(t){return arguments.length?(f=t,v):f},v.centerY=function(t){return arguments.length?(d=t,v):d},v.nodes=function(t){return arguments.length?(b(t||[]),h=t||[],v):h},v.links=function(t){return arguments.length?(c=t||[],x(),v):c},v.forceNodeSize=function(e){return arguments.length?(n="function"==typeof e?e:t(+e),x(),v):n},v.nodeSize=v.forceNodeSize,v.forceCharge=function(e){return arguments.length?(i="function"==typeof e?e:t(+e),x(),v):i},v.forceLinkDistance=function(e){return arguments.length?(s="function"==typeof e?e:t(+e),x(),v):s},v.forceLinkStrength=function(e){return arguments.length?(a="function"==typeof e?e:t(+e),x(),v):a},v.offset=function(t){return arguments.length?(u=t,v):u},v.getFocis=M,v}var Mt={center:[0,0],preventOverlap:!1,nodeSize:void 0,nodeSpacing:void 0,linkDistance:50,forceSimulation:null,alphaDecay:.028,alphaMin:.001,alpha:.3,collideStrength:1,clustering:!1,clusterNodeStrength:-1,clusterEdgeStrength:.1,clusterEdgeDistance:100,clusterFociStrength:.8,clusterNodeSize:10},bt=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="d3force",this.running=!1,this.options=r(r({},Mt),t)}return t.prototype.execute=function(t,e){return this.genericForceLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericForceLayout(!0,t,e)},t.prototype.stop=function(){var t;null===(t=this.forceSimulation)||void 0===t||t.stop(),this.running=!1},t.prototype.restart=function(){var t;null===(t=this.forceSimulation)||void 0===t||t.restart(),this.running=!0},t.prototype.tick=function(t){var e=this;void 0===t&&(t=1),this.forceSimulation.tick(t);var r={nodes:Et(this.lastLayoutNodes),edges:Nt(this.lastLayoutEdges)};return this.lastAssign&&r.nodes.forEach((function(t){return e.lastGraph.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})})),this.lastOptions.onLayoutEnd&&this.lastOptions.onLayoutEnd(r),r},t.prototype.genericForceLayout=function(t,e,n){var o=this,i=r(r({},this.options),n),s=i.layoutInvisibles,a=e.getAllNodes(),u=e.getAllEdges();s||(a=a.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e})),u=u.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e})));var h=a.map((function(t){var e,n;return r(r({},m(t)),{x:null===(e=t.data)||void 0===e?void 0:e.x,y:null===(n=t.data)||void 0===n?void 0:n.y})})),l=u.map((function(t){return m(t)}));if(this.lastLayoutNodes=h,this.lastLayoutEdges=l,this.lastAssign=t,this.lastGraph=e,this.lastOptions=i,!this.running){var c=i.alphaMin,f=i.alphaDecay,d=i.alpha,g=i.nodeStrength,p=i.edgeStrength,y=i.linkDistance,w=i.clustering,v=i.clusterFociStrength,x=i.clusterEdgeDistance,M=i.clusterEdgeStrength,b=i.clusterNodeStrength,E=i.clusterNodeSize,N=i.collideStrength,S=void 0===N?1:N,A=i.center,k=void 0===A?[0,0]:A,I=i.preventOverlap,D=i.nodeSize,R=i.nodeSpacing,_=i.onTick,z=i.onLayoutEnd,T=i.forceSimulation;if(T)w&&((C=xt()).nodes(h),C.links(l)),T.nodes(h),l&&(P=gt().id((function(t){return t.id})).links(l),p&&P.strength(p),y&&P.distance(y),T.force("link",P)),I&&this.overlapProcess(T,{nodeSize:D,nodeSpacing:R,collideStrength:S}),T.alpha(d).restart(),this.running=!0;else try{var C,O=ct();if(g&&O.strength(g),T=lt().nodes(h),w&&((C=xt()).centerX(k[0]).centerY(k[1]).template("force").strength(v),l&&C.links(l),h&&C.nodes(h),C.forceLinkDistance(x).forceLinkStrength(M).forceCharge(b).forceNodeSize(E),T.force("group",C)),T.force("center",function(t,e){var r,n=1;function o(){var o,i,s=r.length,a=0,u=0;for(o=0;o<s;++o)a+=(i=r[o]).x,u+=i.y;for(a=(a/s-t)*n,u=(u/s-e)*n,o=0;o<s;++o)(i=r[o]).x-=a,i.y-=u}return null==t&&(t=0),null==e&&(e=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.strength=function(t){return arguments.length?(n=+t,o):n},o}(k[0],k[1])).force("charge",O).alpha(d).alphaDecay(f).alphaMin(c),I&&this.overlapProcess(T,{nodeSize:D,nodeSpacing:R,collideStrength:S}),l){var P=gt().id((function(t){return t.id})).links(l);p&&P.strength(p),y&&P.distance(y),T.force("link",P)}T.on("tick",(function(){var r=Et(h);null==_||_({nodes:r,edges:Nt(l)}),t&&r.forEach((function(t){return e.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}))})).on("end",(function(){o.running=!1;var r=Et(h);null==z||z({nodes:r,edges:Nt(l)}),t&&r.forEach((function(t){return e.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}))})),this.running=!0}catch(t){this.running=!1,console.warn(t)}this.forceSimulation=T;var L=Et(h),q=Nt(l);return t&&L.forEach((function(t){return e.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})})),{nodes:L,edges:q}}},t.prototype.overlapProcess=function(t,e){var r,n,o=e.nodeSize,i=e.nodeSpacing,s=e.collideStrength;if(n=l(i)?function(){return i}:y(i)?i:function(){return 0},o)if(y(o))r=function(t){return o(t)+n(t)};else if(h(o)){var a=(o[0]>o[1]?o[0]:o[1])/2;r=function(t){return a+n(t)}}else if(l(o)){var u=o/2;r=function(t){return u+n(t)}}else r=function(){return 10};else r=function(t){return t.size?h(t.size)?(t.size[0]>t.size[1]?t.size[0]:t.size[1])/2+n(t):g(t.size)?(t.size.width>t.size.height?t.size.width:t.size.height)/2+n(t):t.size/2+n(t):10+n(t)};t.force("collisionForce",yt(r).strength(s))},t}(),Et=function(t){return t.map((function(t){var e=t.x,o=t.y,i=n(t,["x","y"]);return r(r({},i),{data:r(r({},i.data),{x:e,y:o})})}))},Nt=function(t){return t.map((function(t){var e=t.source,o=t.target,i=n(t,["source","target"]);return r(r({},i),{source:e.id,target:o.id})}))};function St(t){var e=0,r=0,n=0;if(t.length){for(var o=0;o<4;o++)(i=t[o])&&i.weight&&(e+=i.weight,r+=i.x*i.weight,n+=i.y*i.weight);t.x=r/e,t.y=n/e,t.weight=e}else{var i=t;t.x=i.data.x,t.y=i.data.y,t.weight=i.data.weight}}var At={maxIteration:500,gravity:10,animate:!0,factor:1,edgeStrength:200,nodeStrength:1e3,coulombDisScale:.005,damping:.9,maxSpeed:500,minMovement:.4,interval:.02,linkDistance:200,clusterNodeStrength:20,preventOverlap:!0,distanceThresholdMode:"mean"},kt=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="force",this.timeInterval=0,this.judgingDistance=0,this.options=r(r({},At),t)}return t.prototype.execute=function(t,e){return this.genericForceLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericForceLayout(!0,t,e)},t.prototype.genericForceLayout=function(t,e,n){var o=this,i=r(r({},this.options),n),a=e.getAllNodes(),u=e.getAllEdges();i.layoutInvisibles||(a=a.filter((function(t){return t.data.visible||void 0===t.data.visible})),u=u.filter((function(t){return t.data.visible||void 0===t.data.visible})));var h=this.formatOptions(i,e),c=h.width,f=h.height,d=h.nodeSize,g=h.getMass,p=h.nodeStrength,m=h.edgeStrength,y=h.linkDistance,w=a.map((function(t){return r(r({},t),{data:r(r({},t.data),{x:l(t.data.x)?t.data.x:Math.random()*c,y:l(t.data.y)?t.data.y:Math.random()*f,size:d(t)||30,mass:g(t),nodeStrength:p(t)})})})),v=u.map((function(t){return r(r({},t),{data:r(r({},t.data),{edgeStrength:m(t),linkDistance:y(t,e.getNode(t.source),e.getNode(t.target))})})}));if(!(null==a?void 0:a.length))return{nodes:[],edges:u};var x={};a.forEach((function(t,e){x[t.id]={x:0,y:0}}));var M=new s({nodes:w,edges:v});this.formatCentripetal(h,M);var b=h.maxIteration,E=h.animate,N=h.minMovement,S=h.onLayoutEnd,A=h.onTick;if(!E){for(var k=0;(this.judgingDistance>N||k<1)&&k<b;k++)this.runOneStep(M,e,k,x,h),this.updatePosition(e,M,x,h),t&&w.forEach((function(t){return e.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})})),null==A||A({nodes:zt(e,w),edges:u});t&&w.forEach((function(t){return e.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}));var I={nodes:zt(e,w),edges:u};return null==S||S(I),I}if("undefined"!=typeof window){var D=0;return this.timeInterval=window.setInterval((function(){a&&(o.runOneStep(M,e,D,x,h),o.updatePosition(e,M,x,h),t&&w.forEach((function(t){return e.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})})),null==A||A({nodes:zt(e,w),edges:u}),(++D>=b||o.judgingDistance<N)&&(null==S||S({nodes:zt(e,w),edges:u}),window.clearInterval(o.timeInterval)))}),0),{nodes:zt(e,w),edges:u}}},t.prototype.formatOptions=function(t,e){var r=t,n=t.width,o=t.height,i=t.getMass;if(r.width=n||"undefined"==typeof window?n:window.innerWidth,r.height=o||"undefined"==typeof window?o:window.innerHeight,t.center||(r.center=[r.width/2,r.height/2]),i||(r.getMass=function(t){var r=1;l(null==t?void 0:t.data.mass)&&(r=null==t?void 0:t.data.mass);var n=e.getDegree(t.id,"both");return!n||n<5?r:5*n*r}),t.preventOverlap){var s=w(0,t.nodeSpacing);t.nodeSize?h(t.nodeSize)?r.nodeSize=function(e){var r=t.nodeSize;return Math.max(r[0],r[1])+s(e)}:r.nodeSize=function(e){return t.nodeSize+s(e)}:r.nodeSize=function(t){var e=((null==t?void 0:t.data)||{}).size;return e?h(e)?Math.max(e[0],e[1])+s(t):g(e)?Math.max(e.width,e.height)+s(t):e+s(t):10+s(t)}}return r.linkDistance=t.linkDistance?w(1,t.linkDistance):function(t){return 1+r.nodeSize(e.getNode(t.source))+r.nodeSize(e.getNode(t.target))},r.nodeStrength=w(1,t.nodeStrength),r.edgeStrength=w(1,t.edgeStrength),t},t.prototype.formatCentripetal=function(t,e){var r,n=t.centripetalOptions,o=t.center,i=t.clusterNodeStrength,s=t.leafCluster,a=t.clustering,u=t.nodeClusterBy,h=e.getAllNodes(),l=n||{leaf:2,single:2,others:1,center:function(t){return{x:o[0],y:o[1]}}};"function"!=typeof i&&(t.clusterNodeStrength=function(t){return i});var c=[];if(s&&u&&(r=It(e,u),c=Array.from(new Set(null==h?void 0:h.map((function(t){return t.data[u]}))))||[],t.centripetalOptions=Object.assign(l,{single:100,leaf:function(e){var n=r[e.id]||{},o=n.siblingLeaves,i=n.sameTypeLeaves;return(null==i?void 0:i.length)===(null==o?void 0:o.length)||1===(null==c?void 0:c.length)?1:t.clusterNodeStrength(e)},others:1,center:function(t){var n,o=e.getDegree(t.id,"both");if(!o)return{x:100,y:100};if(1===o){var i=(r[t.id]||{}).sameTypeLeaves,s=void 0===i?[]:i;1===s.length?n=void 0:s.length>1&&(n=_t(s))}else n=void 0;return{x:null==n?void 0:n.x,y:null==n?void 0:n.y}}})),a&&u){r||(r=It(e,u)),c||(c=Array.from(new Set(h.map((function(t){return t.data[u]}))))),c=c.filter((function(t){return void 0!==t}));var f={};c.forEach((function(t){var r=h.filter((function(e){return e.data[u]===t})).map((function(t){return e.getNode(t.id)}));f[t]=_t(r)})),t.centripetalOptions=Object.assign(l,{single:function(e){return t.clusterNodeStrength(e)},leaf:function(e){return t.clusterNodeStrength(e)},others:function(e){return t.clusterNodeStrength(e)},center:function(t){var e=f[t.data[u]];return{x:null==e?void 0:e.x,y:null==e?void 0:e.y}}})}var d=t.centripetalOptions,g=d.leaf,p=d.single,m=d.others;g&&"function"!=typeof g&&(t.centripetalOptions.leaf=function(){return g}),p&&"function"!=typeof p&&(t.centripetalOptions.single=function(){return p}),m&&"function"!=typeof m&&(t.centripetalOptions.others=function(){return m})},t.prototype.runOneStep=function(t,e,r,n,o){var i={},s=t.getAllNodes(),a=t.getAllEdges();if(null==s?void 0:s.length){var u=o.monitor;this.calRepulsive(t,i,o),a&&this.calAttractive(t,i),this.calGravity(t,e,i,o),this.updateVelocity(t,i,n,o),u&&u({energy:this.calTotalEnergy(i,s),nodes:e.getAllNodes(),edges:e.getAllEdges(),iterations:r})}},t.prototype.calTotalEnergy=function(t,e){if(!(null==e?void 0:e.length))return 0;var r=0;return e.forEach((function(e,n){var o=t[e.id].x,i=t[e.id].y,s=o*o+i*i,a=e.data.mass;r+=(void 0===a?1:a)*s*.5})),r},t.prototype.calRepulsive=function(t,e,r){var n=r.factor,o=r.coulombDisScale;!function(t,e,r,n){var o=e/r,i=t.getAllNodes(),s=i.map((function(t,e){var r=t.data,n=r.nodeStrength;return{x:r.x,y:r.y,size:r.size,index:e,vx:0,vy:0,weight:o*n}})),a=R(s,(function(t){return t.x}),(function(t){return t.y})).visitAfter(St);s.forEach((function(t){!function(t,e){e.visit((function(e,r,n,o,i){return function(t,e,r,n,o,i){var s=i.x-t.x||.1,a=i.y-t.y||.1,u=n-e,h=s*s+a*a,l=Math.sqrt(h)*h;if(u*u*.81<h){var c=t.weight/l;return i.vx+=s*c,i.vy+=a*c,!0}if(t.length)return!1;t.data!==i&&(c=t.data.weight/l,i.vx+=s*c,i.vy+=a*c)}(e,r,0,o,0,t)}))}(t,a)})),s.map((function(t,e){var r=i[e],o=r.id,s=r.data.mass,a=void 0===s?1:s;n[o]={x:t.vx/a,y:t.vy/a}}))}(t,n,o*o,e)},t.prototype.calAttractive=function(t,e){t.getAllEdges().forEach((function(r,n){var o=r.source,i=r.target,s=t.getNode(o),a=t.getNode(i);if(s&&a){var u=a.data.x-s.data.x,h=a.data.y-s.data.y;u||h||(u=.01*Math.random(),h=.01*Math.random());var l=Math.sqrt(u*u+h*h),c=u/l,f=h/l,d=edgeInfos[n]||{},g=d.linkDistance,p=void 0===g?200:g,m=d.edgeStrength,y=(p-l)*(void 0===m?200:m),w=1/(s.data.mass||1),v=1/(a.data.mass||1),x=c*y,M=f*y;e[o].x-=x*w,e[o].y-=M*w,e[i].x+=x*v,e[i].y+=M*v}}))},t.prototype.calGravity=function(t,e,r,n){var i=n.getCenter,s=t.getAllNodes(),a=e.getAllNodes(),u=e.getAllEdges(),h=n.width,c=n.height,f=n.center,d=n.gravity,g=n.centripetalOptions;s&&s.forEach((function(n){var s=n.id,p=n.data,m=p.mass,y=p.x,w=p.y,v=e.getNode(s),x=0,M=0,b=d,E=t.getDegree(s,"in"),N=t.getDegree(s,"out"),S=t.getDegree(s,"both"),A=null==i?void 0:i(v,S);if(A){var k=o(A,3);x=y-k[0],M=w-k[1],b=k[2]}else x=y-f[0],M=w-f[1];if(b&&(r[s].x-=b*x/m,r[s].y-=b*M/m),g){var I=g.leaf,D=g.single,R=g.others,_=g.center,z=(null==_?void 0:_(v,a,u,h,c))||{x:0,y:0,centerStrength:0},T=z.x,C=z.y,O=z.centerStrength;if(!l(T)||!l(C))return;var P=(y-T)/m,L=(w-C)/m;if(O&&(r[s].x-=O*P,r[s].y-=O*L),0===S){var q=D(v);if(!q)return;return r[s].x-=q*P,void(r[s].y-=q*L)}if(0===E||0===N){var j=I(v,a,u);if(!j)return;return r[s].x-=j*P,void(r[s].y-=j*L)}var V=R(v);if(!V)return;r[s].x-=V*P,r[s].y-=V*L}}))},t.prototype.updateVelocity=function(t,e,r,n){var o=n.damping,i=n.maxSpeed,s=n.interval,a=t.getAllNodes();(null==a?void 0:a.length)&&a.forEach((function(t){var n=t.id,a=(r[n].x+e[n].x*s)*o||.01,u=(r[n].y+e[n].y*s)*o||.01,h=Math.sqrt(a*a+u*u);if(h>i){var l=i/h;a*=l,u*=l}r[n]={x:a,y:u}}))},t.prototype.updatePosition=function(t,e,r,n){var o=this,i=n.distanceThresholdMode,s=n.interval,a=e.getAllNodes();if(null==a?void 0:a.length){var u=0;"max"===i?this.judgingDistance=-1/0:"min"===i&&(this.judgingDistance=1/0),a.forEach((function(n){var a=n.id,h=t.getNode(a);if(l(h.data.fx)&&l(h.data.fy))e.mergeNodeData(a,{x:h.data.fx,y:h.data.fy});else{var c=r[a].x*s,f=r[a].y*s;e.mergeNodeData(a,{x:n.data.x+c,y:n.data.y+f});var d=Math.sqrt(c*c+f*f);switch(i){case"max":o.judgingDistance<d&&(o.judgingDistance=d);break;case"min":o.judgingDistance>d&&(o.judgingDistance=d);break;default:u+=d}}})),i&&"mean"!==i||(this.judgingDistance=u/a.length)}else this.judgingDistance=0},t.prototype.stop=function(){this.timeInterval&&"undefined"!=typeof window&&window.clearInterval(this.timeInterval)},t}(),It=function(t,e){var r=t.getAllNodes();if(!(null==r?void 0:r.length))return{};var n={};return r.forEach((function(r,o){1===t.getDegree(r.id,"both")&&(n[r.id]=Dt(t,"leaf",r,e))})),n},Dt=function(t,e,r,n){var o=t.getDegree(r.id,"in"),i=t.getDegree(r.id,"out"),s=r,a=[];return 0===o?(s=t.getSuccessors(r.id)[0],a=t.getNeighbors(s.id)):0===i&&(s=t.getPredecessors(r.id)[0],a=t.getNeighbors(s.id)),a=a.filter((function(e){return 0===t.getDegree(e.id,"in")||0===t.getDegree(e.id,"out")})),{coreNode:s,siblingLeaves:a,sameTypeLeaves:Rt(t,e,n,r,a)}},Rt=function(t,e,r,n,o){var i=n.data[r]||"",s=(null==o?void 0:o.filter((function(t){return t.data[r]===i})))||[];return"leaf"===e&&(s=s.filter((function(e){return 0===t.getDegree(e.id,"in")||0===t.getDegree(e.id,"out")}))),s},_t=function(t){var e={x:0,y:0};t.forEach((function(t){var r=t.data,n=r.x,o=r.y;e.x+=n||0,e.y+=o||0}));var r=t.length||1;return{x:e.x/r,y:e.y/r}},zt=function(t,e){return e.map((function(e){var n=e.id,o=e.data,i=t.getNode(n);return r(r({},i),{data:r(r({},i.data),{x:o.x,y:o.y})})}))},Tt={maxIteration:1e3,gravity:10,speed:5,clustering:!1,clusterGravity:10,width:300,height:300,nodeClusterBy:"cluster"},Ct=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="fruchterman",this.timeInterval=0,this.running=!1,this.options=r(r({},Tt),t)}return t.prototype.execute=function(t,e){return this.genericFruchtermanLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericFruchtermanLayout(!0,t,e)},t.prototype.stop=function(){this.timeInterval&&"undefined"!=typeof window&&window.clearInterval(this.timeInterval),this.running=!1},t.prototype.restart=function(){this.running=!0},t.prototype.tick=function(t){var e=this;void 0===t&&(t=1);for(var r=0;r<t;r++)this.runOneStep(this.lastGraph,this.lastClusterMap,this.lastOptions);var n={nodes:this.lastLayoutNodes,edges:this.lastLayoutEdges};return this.lastAssign&&n.nodes.forEach((function(t){return e.lastGraph.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})})),this.lastOptions.onLayoutEnd&&this.lastOptions.onLayoutEnd(n),n},t.prototype.genericFruchtermanLayout=function(t,e,n){var o=this;if(!this.running){var i=this.formatOptions(n),a=i.layoutInvisibles,u=i.width,h=i.height,l=i.center,c=i.clustering,f=i.nodeClusterBy,d=i.maxIteration,g=i.onTick,p=i.onLayoutEnd,y=e.getAllNodes(),w=e.getAllEdges();if(a||(y=y.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e})),w=w.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e}))),!(null==y?void 0:y.length)){var v={nodes:[],edges:w};return null==p||p(v),v}if(1===y.length)return t&&e.mergeNodeData(y[0].id,{x:l[0],y:l[1]}),v={nodes:[r(r({},y[0]),{data:r(r({},y[0].data),{x:l[0],y:l[1]})})],edges:w},null==p||p(v),v;var x=y.map((function(t){return m(t,[u,h])})),M=new s({nodes:x,edges:w}),b={};if(c&&x.forEach((function(t){var e=t.data[f];b[e]||(b[e]={name:e,cx:0,cy:0,count:0})})),this.lastLayoutNodes=x,this.lastLayoutEdges=w,this.lastAssign=t,this.lastGraph=M,this.lastOptions=i,this.lastClusterMap=b,"undefined"!=typeof window){var E=0;return this.timeInterval=window.setInterval((function(){if(o.runOneStep(M,b,i),t&&x.forEach((function(t){var r=t.id,n=t.data;return e.mergeNodeData(r,{x:n.x,y:n.y})})),null==g||g({nodes:x,edges:w}),++E>=d){try{null==p||p({nodes:x,edges:w})}catch(t){console.warn("onLayoutEnd failed",t)}window.clearInterval(o.timeInterval)}}),0),{nodes:x,edges:w}}}},t.prototype.formatOptions=function(t){void 0===t&&(t={});var e=r(r({},this.options),t),n=e.clustering,o=e.nodeClusterBy,i=e.center,s=e.width,a=e.height;return e.width=s||"undefined"==typeof window?s:window.innerWidth,e.height=a||"undefined"==typeof window?a:window.innerHeight,e.center=i||[e.width/2,e.height/2],e.clustering=n&&!!o,e},t.prototype.runOneStep=function(t,e,r){var n=r.height,o=r.width,i=r.gravity,s=r.center,a=r.speed,u=r.clustering,h=r.nodeClusterBy,c=r.clusterGravity,f=n*o,d=Math.sqrt(f)/10,g=t.getAllNodes(),p=f/(g.length+1),m=Math.sqrt(p),y={};if(this.applyCalculate(t,y,m,p),u){for(var w in e)e[w].cx=0,e[w].cy=0,e[w].count=0;for(var w in g.forEach((function(t){var r=t.data,n=e[r[h]];l(r.x)&&(n.cx+=r.x),l(r.y)&&(n.cy+=r.y),n.count++})),e)e[w].cx/=e[w].count,e[w].cy/=e[w].count;var v=c||i;g.forEach((function(t,r){var n=t.id,o=t.data;if(l(o.x)&&l(o.y)){var i=e[o[h]],s=Math.sqrt((o.x-i.cx)*(o.x-i.cx)+(o.y-i.cy)*(o.y-i.cy)),a=m*v;y[n].x-=a*(o.x-i.cx)/s,y[n].y-=a*(o.y-i.cy)/s}}))}g.forEach((function(t,e){var r=t.id,n=t.data;if(l(n.x)&&l(n.y)){var o=.01*m*i;y[r].x-=o*(n.x-s[0]),y[r].y-=o*(n.y-s[1])}})),g.forEach((function(e,r){var n=e.id,o=e.data;if(l(o.fx)&&l(o.fy))return o.x=o.fx,void(o.y=o.fy);if(l(o.x)&&l(o.y)){var i=Math.sqrt(y[n].x*y[n].x+y[n].y*y[n].y);if(i>0){var s=Math.min(d*(a/800),i);t.mergeNodeData(n,{x:o.x+y[n].x/i*s,y:o.y+y[n].y/i*s})}}}))},t.prototype.applyCalculate=function(t,e,r,n){this.calRepulsive(t,e,n),this.calAttractive(t,e,r)},t.prototype.calRepulsive=function(t,e,r){var n=t.getAllNodes();n.forEach((function(t,o){var i=t.data,s=t.id;e[s]={x:0,y:0},n.forEach((function(t,n){var a=t.data,u=t.id;if(!(o<=n)&&l(i.x)&&l(a.x)&&l(i.y)&&l(a.y)){var h=i.x-a.x,c=i.y-a.y,f=h*h+c*c;0===f&&(f=1,h=.01,c=.01);var d=r/f,g=h*d,p=c*d;e[s].x+=g,e[s].y+=p,e[u].x-=g,e[u].y-=p}}))}))},t.prototype.calAttractive=function(t,e,r){t.getAllEdges().forEach((function(n){var o=n.source,i=n.target;if(o&&i&&o!==i){var s=t.getNode(o).data,a=t.getNode(i).data;if(l(a.x)&&l(s.x)&&l(a.y)&&l(s.y)){var u=a.x-s.x,h=a.y-s.y,c=Math.sqrt(u*u+h*h)/r,f=u*c,d=h*c;e[o].x+=f,e[o].y+=d,e[i].x-=f,e[i].y-=d}}}))},t}(),Ot={begin:[0,0],preventOverlap:!0,preventOverlapPadding:10,condense:!1,rows:void 0,cols:void 0,position:void 0,sortBy:"degree",nodeSize:30,width:300,height:300},Pt=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="grid",this.options=r(r({},Ot),t)}return t.prototype.execute=function(t,e){return this.genericGridLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericGridLayout(!0,t,e)},t.prototype.genericGridLayout=function(t,e,n){var o=r(r({},this.options),n),i=o.begin,s=void 0===i?[0,0]:i,u=o.condense,c=o.preventOverlapPadding,f=o.preventOverlap,d=o.rows,g=o.cols,p=o.nodeSpacing,y=o.nodeSize,x=o.width,M=o.height,b=o.layoutInvisibles,E=o.onLayoutEnd,N=o.position,S=o.sortBy,A=e.getAllNodes(),k=e.getAllEdges();b||(A=A.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e})),k=k.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e})));var I=A.length;if(0===I){var D={nodes:[],edges:k};return null==E||E(D),D}if(1===I){t&&e.mergeNodeData(A[0].id,{x:s[0],y:s[1]});var R={nodes:[r(r({},A[0]),{data:r(r({},A[0].data),{x:s[0],y:s[1]})})],edges:k};return null==E||E(R),R}var _=A.map((function(t){return m(t)}));"id"===S||a(S)&&void 0!==_[0].data[S]||(S="degree"),"degree"===S?_.sort((function(t,r){return e.getDegree(r.id,"both")-e.getDegree(t.id,"both")})):"id"===S?_.sort((function(t,e){return l(e.id)&&l(t.id)?e.id-t.id:"".concat(t.id).localeCompare("".concat(e.id))})):_.sort((function(t,e){return e.data[S]-t.data[S]}));var z=x||"undefined"==typeof window?x:window.innerWidth,T=M||"undefined"==typeof window?M:window.innerHeight,C=I,O={rows:d,cols:g};if(null!=d&&null!=g)O.rows=d,O.cols=g;else if(null!=d&&null==g)O.rows=d,O.cols=Math.ceil(C/O.rows);else if(null==d&&null!=g)O.cols=g,O.rows=Math.ceil(C/O.cols);else{var P=Math.sqrt(C*T/z);O.rows=Math.round(P),O.cols=Math.round(z/T*P)}if(O.rows=Math.max(O.rows,1),O.cols=Math.max(O.cols,1),O.cols*O.rows>C)((q=Lt(O))-1)*(L=qt(O))>=C?Lt(O,q-1):(L-1)*q>=C&&qt(O,L-1);else for(;O.cols*O.rows<C;){var L,q=Lt(O);((L=qt(O))+1)*q>=C?qt(O,L+1):Lt(O,q+1)}var j=u?0:z/O.cols,V=u?0:T/O.rows;if(f||p){var F=w(10,p),$=v(30,y,!1);_.forEach((function(t){t.data.x&&t.data.y||(t.data.x=0,t.data.y=0);var r,n,o=e.getNode(t.id),i=$(o)||30;h(i)?(r=i[0],n=i[1]):(r=i,n=i);var s=void 0!==F?F(t):c,a=r+s,u=n+s;j=Math.max(j,a),V=Math.max(V,u)}))}for(var U={},B={row:0,col:0},G={},K=0;K<_.length;K++){var W=_[K],H=void 0;if(N&&(H=N(e.getNode(W.id))),H&&(void 0!==H.row||void 0!==H.col)){var J={row:H.row,col:H.col};if(void 0===J.col)for(J.col=0;jt(U,J);)J.col++;else if(void 0===J.row)for(J.row=0;jt(U,J);)J.row++;G[W.id]=J,Vt(U,J)}$t(W,s,j,V,G,O,B,U)}var Y={nodes:_,edges:k};return null==E||E(Y),t&&_.forEach((function(t){e.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})})),Y},t}(),Lt=function(t,e){var r,n=t.rows||5,o=t.cols||5;return null==e?r=Math.min(n,o):Math.min(n,o)===t.rows?t.rows=e:t.cols=e,r},qt=function(t,e){var r,n=t.rows||5,o=t.cols||5;return null==e?r=Math.max(n,o):Math.max(n,o)===t.rows?t.rows=e:t.cols=e,r},jt=function(t,e){return t["c-".concat(e.row,"-").concat(e.col)]||!1},Vt=function(t,e){return t["c-".concat(e.row,"-").concat(e.col)]=!0},Ft=function(t,e){var r=t.cols||5;e.col++,e.col>=r&&(e.col=0,e.row++)},$t=function(t,e,r,n,o,i,s,a){var u,h,l=o[t.id];if(l)u=l.col*r+r/2+e[0],h=l.row*n+n/2+e[1];else{for(;jt(a,s);)Ft(i,s);u=s.col*r+r/2+e[0],h=s.row*n+n/2+e[1],Vt(a,s),Ft(i,s)}t.data.x=u,t.data.y=h};const Ut=Object.prototype.toString;function Bt(t){return Ut.call(t).endsWith("Array]")}function Gt(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!Bt(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");var r=e.fromIndex,n=void 0===r?0:r,o=e.toIndex,i=void 0===o?t.length:o;if(n<0||n>=t.length||!Number.isInteger(n))throw new Error("fromIndex must be a positive integer smaller than length");if(i<=n||i>t.length||!Number.isInteger(i))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var s=t[n],a=n+1;a<i;a++)t[a]>s&&(s=t[a]);return s}function Kt(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!Bt(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");var r=e.fromIndex,n=void 0===r?0:r,o=e.toIndex,i=void 0===o?t.length:o;if(n<0||n>=t.length||!Number.isInteger(n))throw new Error("fromIndex must be a positive integer smaller than length");if(i<=n||i>t.length||!Number.isInteger(i))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var s=t[n],a=n+1;a<i;a++)t[a]<s&&(s=t[a]);return s}function Wt(t){var e,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!Bt(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");if(void 0!==r.output){if(!Bt(r.output))throw new TypeError("output option must be an array if specified");e=r.output}else e=new Array(t.length);var n=Kt(t),o=Gt(t);if(n===o)throw new RangeError("minimum and maximum input values are equal. Cannot rescale a constant array");var i=r.min,s=void 0===i?r.autoMinMax?n:0:i,a=r.max,u=void 0===a?r.autoMinMax?o:1:a;if(s>=u)throw new RangeError("min option must be smaller than max option");for(var h=(u-s)/(o-n),l=0;l<t.length;l++)e[l]=(t[l]-n)*h+s;return e}const Ht=" ".repeat(2),Jt=" ".repeat(4);function Yt(t,e={}){const{maxRows:r=15,maxColumns:n=10,maxNumSize:o=8,padMinus:i="auto"}=e;return`${t.constructor.name} {\\n${Ht}[\\n${Jt}${function(t,e,r,n,o){const{rows:i,columns:s}=t,a=Math.min(i,e),u=Math.min(s,r),h=[];if("auto"===o){o=!1;t:for(let e=0;e<a;e++)for(let r=0;r<u;r++)if(t.get(e,r)<0){o=!0;break t}}for(let e=0;e<a;e++){let r=[];for(let i=0;i<u;i++)r.push(Xt(t.get(e,i),n,o));h.push(`${r.join(" ")}`)}return u!==s&&(h[h.length-1]+=` ... ${s-r} more columns`),a!==i&&h.push(`... ${i-e} more rows`),h.join(`\\n${Jt}`)}(t,r,n,o,i)}\\n${Ht}]\\n${Ht}rows: ${t.rows}\\n${Ht}columns: ${t.columns}\\n}`}function Xt(t,e,r){return(t>=0&&r?` ${Qt(t,e-1)}`:Qt(t,e)).padEnd(e)}function Qt(t,e){let r=t.toString();if(r.length<=e)return r;let n=t.toFixed(e);if(n.length>e&&(n=t.toFixed(Math.max(0,e-(n.length-e)))),n.length<=e&&!n.startsWith("0.000")&&!n.startsWith("-0.000"))return n;let o=t.toExponential(e);return o.length>e&&(o=t.toExponential(Math.max(0,e-(o.length-e)))),o.slice(0)}function Zt(t,e,r){let n=r?t.rows:t.rows-1;if(e<0||e>n)throw new RangeError("Row index out of range")}function te(t,e,r){let n=r?t.columns:t.columns-1;if(e<0||e>n)throw new RangeError("Column index out of range")}function ee(t,e){if(e.to1DArray&&(e=e.to1DArray()),e.length!==t.columns)throw new RangeError("vector size must be the same as the number of columns");return e}function re(t,e){if(e.to1DArray&&(e=e.to1DArray()),e.length!==t.rows)throw new RangeError("vector size must be the same as the number of rows");return e}function ne(t,e,r,n,o){if(5!==arguments.length)throw new RangeError("expected 4 arguments");if(ie("startRow",e),ie("endRow",r),ie("startColumn",n),ie("endColumn",o),e>r||n>o||e<0||e>=t.rows||r<0||r>=t.rows||n<0||n>=t.columns||o<0||o>=t.columns)throw new RangeError("Submatrix indices are out of range")}function oe(t,e=0){let r=[];for(let n=0;n<t;n++)r.push(e);return r}function ie(t,e){if("number"!=typeof e)throw new TypeError(`${t} must be a number`)}function se(t){if(t.isEmpty())throw new Error("Empty matrix has no elements to index")}class ae{static from1DArray(t,e,r){if(t*e!==r.length)throw new RangeError("data length does not match given dimensions");let n=new he(t,e);for(let o=0;o<t;o++)for(let t=0;t<e;t++)n.set(o,t,r[o*e+t]);return n}static rowVector(t){let e=new he(1,t.length);for(let r=0;r<t.length;r++)e.set(0,r,t[r]);return e}static columnVector(t){let e=new he(t.length,1);for(let r=0;r<t.length;r++)e.set(r,0,t[r]);return e}static zeros(t,e){return new he(t,e)}static ones(t,e){return new he(t,e).fill(1)}static rand(t,e,r={}){if("object"!=typeof r)throw new TypeError("options must be an object");const{random:n=Math.random}=r;let o=new he(t,e);for(let r=0;r<t;r++)for(let t=0;t<e;t++)o.set(r,t,n());return o}static randInt(t,e,r={}){if("object"!=typeof r)throw new TypeError("options must be an object");const{min:n=0,max:o=1e3,random:i=Math.random}=r;if(!Number.isInteger(n))throw new TypeError("min must be an integer");if(!Number.isInteger(o))throw new TypeError("max must be an integer");if(n>=o)throw new RangeError("min must be smaller than max");let s=o-n,a=new he(t,e);for(let r=0;r<t;r++)for(let t=0;t<e;t++){let e=n+Math.round(i()*s);a.set(r,t,e)}return a}static eye(t,e,r){void 0===e&&(e=t),void 0===r&&(r=1);let n=Math.min(t,e),o=this.zeros(t,e);for(let t=0;t<n;t++)o.set(t,t,r);return o}static diag(t,e,r){let n=t.length;void 0===e&&(e=n),void 0===r&&(r=e);let o=Math.min(n,e,r),i=this.zeros(e,r);for(let e=0;e<o;e++)i.set(e,e,t[e]);return i}static min(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);let r=t.rows,n=t.columns,o=new he(r,n);for(let i=0;i<r;i++)for(let r=0;r<n;r++)o.set(i,r,Math.min(t.get(i,r),e.get(i,r)));return o}static max(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);let r=t.rows,n=t.columns,o=new this(r,n);for(let i=0;i<r;i++)for(let r=0;r<n;r++)o.set(i,r,Math.max(t.get(i,r),e.get(i,r)));return o}static checkMatrix(t){return ae.isMatrix(t)?t:new he(t)}static isMatrix(t){return null!=t&&"Matrix"===t.klass}get size(){return this.rows*this.columns}apply(t){if("function"!=typeof t)throw new TypeError("callback must be a function");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.call(this,e,r);return this}to1DArray(){let t=[];for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.push(this.get(e,r));return t}to2DArray(){let t=[];for(let e=0;e<this.rows;e++){t.push([]);for(let r=0;r<this.columns;r++)t[e].push(this.get(e,r))}return t}toJSON(){return this.to2DArray()}isRowVector(){return 1===this.rows}isColumnVector(){return 1===this.columns}isVector(){return 1===this.rows||1===this.columns}isSquare(){return this.rows===this.columns}isEmpty(){return 0===this.rows||0===this.columns}isSymmetric(){if(this.isSquare()){for(let t=0;t<this.rows;t++)for(let e=0;e<=t;e++)if(this.get(t,e)!==this.get(e,t))return!1;return!0}return!1}isEchelonForm(){let t=0,e=0,r=-1,n=!0,o=!1;for(;t<this.rows&&n;){for(e=0,o=!1;e<this.columns&&!1===o;)0===this.get(t,e)?e++:1===this.get(t,e)&&e>r?(o=!0,r=e):(n=!1,o=!0);t++}return n}isReducedEchelonForm(){let t=0,e=0,r=-1,n=!0,o=!1;for(;t<this.rows&&n;){for(e=0,o=!1;e<this.columns&&!1===o;)0===this.get(t,e)?e++:1===this.get(t,e)&&e>r?(o=!0,r=e):(n=!1,o=!0);for(let r=e+1;r<this.rows;r++)0!==this.get(t,r)&&(n=!1);t++}return n}echelonForm(){let t=this.clone(),e=0,r=0;for(;e<t.rows&&r<t.columns;){let n=e;for(let o=e;o<t.rows;o++)t.get(o,r)>t.get(n,r)&&(n=o);if(0===t.get(n,r))r++;else{t.swapRows(e,n);let o=t.get(e,r);for(let n=r;n<t.columns;n++)t.set(e,n,t.get(e,n)/o);for(let n=e+1;n<t.rows;n++){let o=t.get(n,r)/t.get(e,r);t.set(n,r,0);for(let i=r+1;i<t.columns;i++)t.set(n,i,t.get(n,i)-t.get(e,i)*o)}e++,r++}}return t}reducedEchelonForm(){let t=this.echelonForm(),e=t.columns,r=t.rows,n=r-1;for(;n>=0;)if(0===t.maxRow(n))n--;else{let o=0,i=!1;for(;o<r&&!1===i;)1===t.get(n,o)?i=!0:o++;for(let r=0;r<n;r++){let i=t.get(r,o);for(let s=o;s<e;s++){let e=t.get(r,s)-i*t.get(n,s);t.set(r,s,e)}}n--}return t}set(){throw new Error("set method is unimplemented")}get(){throw new Error("get method is unimplemented")}repeat(t={}){if("object"!=typeof t)throw new TypeError("options must be an object");const{rows:e=1,columns:r=1}=t;if(!Number.isInteger(e)||e<=0)throw new TypeError("rows must be a positive integer");if(!Number.isInteger(r)||r<=0)throw new TypeError("columns must be a positive integer");let n=new he(this.rows*e,this.columns*r);for(let t=0;t<e;t++)for(let e=0;e<r;e++)n.setSubMatrix(this,this.rows*t,this.columns*e);return n}fill(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,t);return this}neg(){return this.mulS(-1)}getRow(t){Zt(this,t);let e=[];for(let r=0;r<this.columns;r++)e.push(this.get(t,r));return e}getRowVector(t){return he.rowVector(this.getRow(t))}setRow(t,e){Zt(this,t),e=ee(this,e);for(let r=0;r<this.columns;r++)this.set(t,r,e[r]);return this}swapRows(t,e){Zt(this,t),Zt(this,e);for(let r=0;r<this.columns;r++){let n=this.get(t,r);this.set(t,r,this.get(e,r)),this.set(e,r,n)}return this}getColumn(t){te(this,t);let e=[];for(let r=0;r<this.rows;r++)e.push(this.get(r,t));return e}getColumnVector(t){return he.columnVector(this.getColumn(t))}setColumn(t,e){te(this,t),e=re(this,e);for(let r=0;r<this.rows;r++)this.set(r,t,e[r]);return this}swapColumns(t,e){te(this,t),te(this,e);for(let r=0;r<this.rows;r++){let n=this.get(r,t);this.set(r,t,this.get(r,e)),this.set(r,e,n)}return this}addRowVector(t){t=ee(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t[r]);return this}subRowVector(t){t=ee(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t[r]);return this}mulRowVector(t){t=ee(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t[r]);return this}divRowVector(t){t=ee(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t[r]);return this}addColumnVector(t){t=re(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t[e]);return this}subColumnVector(t){t=re(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t[e]);return this}mulColumnVector(t){t=re(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t[e]);return this}divColumnVector(t){t=re(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t[e]);return this}mulRow(t,e){Zt(this,t);for(let r=0;r<this.columns;r++)this.set(t,r,this.get(t,r)*e);return this}mulColumn(t,e){te(this,t);for(let r=0;r<this.rows;r++)this.set(r,t,this.get(r,t)*e);return this}max(t){if(this.isEmpty())return NaN;switch(t){case"row":{const t=new Array(this.rows).fill(Number.NEGATIVE_INFINITY);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)>t[e]&&(t[e]=this.get(e,r));return t}case"column":{const t=new Array(this.columns).fill(Number.NEGATIVE_INFINITY);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)>t[r]&&(t[r]=this.get(e,r));return t}case void 0:{let t=this.get(0,0);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)>t&&(t=this.get(e,r));return t}default:throw new Error(`invalid option: ${t}`)}}maxIndex(){se(this);let t=this.get(0,0),e=[0,0];for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.get(r,n)>t&&(t=this.get(r,n),e[0]=r,e[1]=n);return e}min(t){if(this.isEmpty())return NaN;switch(t){case"row":{const t=new Array(this.rows).fill(Number.POSITIVE_INFINITY);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)<t[e]&&(t[e]=this.get(e,r));return t}case"column":{const t=new Array(this.columns).fill(Number.POSITIVE_INFINITY);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)<t[r]&&(t[r]=this.get(e,r));return t}case void 0:{let t=this.get(0,0);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)<t&&(t=this.get(e,r));return t}default:throw new Error(`invalid option: ${t}`)}}minIndex(){se(this);let t=this.get(0,0),e=[0,0];for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.get(r,n)<t&&(t=this.get(r,n),e[0]=r,e[1]=n);return e}maxRow(t){if(Zt(this,t),this.isEmpty())return NaN;let e=this.get(t,0);for(let r=1;r<this.columns;r++)this.get(t,r)>e&&(e=this.get(t,r));return e}maxRowIndex(t){Zt(this,t),se(this);let e=this.get(t,0),r=[t,0];for(let n=1;n<this.columns;n++)this.get(t,n)>e&&(e=this.get(t,n),r[1]=n);return r}minRow(t){if(Zt(this,t),this.isEmpty())return NaN;let e=this.get(t,0);for(let r=1;r<this.columns;r++)this.get(t,r)<e&&(e=this.get(t,r));return e}minRowIndex(t){Zt(this,t),se(this);let e=this.get(t,0),r=[t,0];for(let n=1;n<this.columns;n++)this.get(t,n)<e&&(e=this.get(t,n),r[1]=n);return r}maxColumn(t){if(te(this,t),this.isEmpty())return NaN;let e=this.get(0,t);for(let r=1;r<this.rows;r++)this.get(r,t)>e&&(e=this.get(r,t));return e}maxColumnIndex(t){te(this,t),se(this);let e=this.get(0,t),r=[0,t];for(let n=1;n<this.rows;n++)this.get(n,t)>e&&(e=this.get(n,t),r[0]=n);return r}minColumn(t){if(te(this,t),this.isEmpty())return NaN;let e=this.get(0,t);for(let r=1;r<this.rows;r++)this.get(r,t)<e&&(e=this.get(r,t));return e}minColumnIndex(t){te(this,t),se(this);let e=this.get(0,t),r=[0,t];for(let n=1;n<this.rows;n++)this.get(n,t)<e&&(e=this.get(n,t),r[0]=n);return r}diag(){let t=Math.min(this.rows,this.columns),e=[];for(let r=0;r<t;r++)e.push(this.get(r,r));return e}norm(t="frobenius"){let e=0;if("max"===t)return this.max();if("frobenius"===t){for(let t=0;t<this.rows;t++)for(let r=0;r<this.columns;r++)e+=this.get(t,r)*this.get(t,r);return Math.sqrt(e)}throw new RangeError(`unknown norm type: ${t}`)}cumulativeSum(){let t=0;for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t+=this.get(e,r),this.set(e,r,t);return this}dot(t){ae.isMatrix(t)&&(t=t.to1DArray());let e=this.to1DArray();if(e.length!==t.length)throw new RangeError("vectors do not have the same size");let r=0;for(let n=0;n<e.length;n++)r+=e[n]*t[n];return r}mmul(t){t=he.checkMatrix(t);let e=this.rows,r=this.columns,n=t.columns,o=new he(e,n),i=new Float64Array(r);for(let s=0;s<n;s++){for(let e=0;e<r;e++)i[e]=t.get(e,s);for(let t=0;t<e;t++){let e=0;for(let n=0;n<r;n++)e+=this.get(t,n)*i[n];o.set(t,s,e)}}return o}strassen2x2(t){t=he.checkMatrix(t);let e=new he(2,2);const r=this.get(0,0),n=t.get(0,0),o=this.get(0,1),i=t.get(0,1),s=this.get(1,0),a=t.get(1,0),u=this.get(1,1),h=t.get(1,1),l=(r+u)*(n+h),c=(s+u)*n,f=r*(i-h),d=u*(a-n),g=(r+o)*h,p=l+d-g+(o-u)*(a+h),m=f+g,y=c+d,w=l-c+f+(s-r)*(n+i);return e.set(0,0,p),e.set(0,1,m),e.set(1,0,y),e.set(1,1,w),e}strassen3x3(t){t=he.checkMatrix(t);let e=new he(3,3);const r=this.get(0,0),n=this.get(0,1),o=this.get(0,2),i=this.get(1,0),s=this.get(1,1),a=this.get(1,2),u=this.get(2,0),h=this.get(2,1),l=this.get(2,2),c=t.get(0,0),f=t.get(0,1),d=t.get(0,2),g=t.get(1,0),p=t.get(1,1),m=t.get(1,2),y=t.get(2,0),w=t.get(2,1),v=t.get(2,2),x=(r-i)*(-f+p),M=(-r+i+s)*(c-f+p),b=(i+s)*(-c+f),E=r*c,N=(-r+u+h)*(c-d+m),S=(-r+u)*(d-m),A=(u+h)*(-c+d),k=(-o+h+l)*(p+y-w),I=(o-l)*(p-w),D=o*y,R=(h+l)*(-y+w),_=(-o+s+a)*(m+y-v),z=(o-a)*(m-v),T=(s+a)*(-y+v),C=E+D+n*g,O=(r+n+o-i-s-h-l)*p+M+b+E+k+D+R,P=E+N+A+(r+n+o-s-a-u-h)*m+D+_+T,L=x+s*(-c+f+g-p-m-y+v)+M+E+D+_+z,q=x+M+b+E+a*w,j=D+_+z+T+i*d,V=E+N+S+h*(-c+d+g-p-m-y+w)+k+I+D,F=k+I+D+R+u*f,$=E+N+S+A+l*v;return e.set(0,0,C),e.set(0,1,O),e.set(0,2,P),e.set(1,0,L),e.set(1,1,q),e.set(1,2,j),e.set(2,0,V),e.set(2,1,F),e.set(2,2,$),e}mmulStrassen(t){t=he.checkMatrix(t);let e=this.clone(),r=e.rows,n=e.columns,o=t.rows,i=t.columns;function s(t,e,r){let n=t.rows,o=t.columns;if(n===e&&o===r)return t;{let n=ae.zeros(e,r);return n=n.setSubMatrix(t,0,0),n}}n!==o&&console.warn(`Multiplying ${r} x ${n} and ${o} x ${i} matrix: dimensions do not match.`);let a=Math.max(r,o),u=Math.max(n,i);return e=s(e,a,u),function t(e,r,n,o){if(n<=512||o<=512)return e.mmul(r);n%2==1&&o%2==1?(e=s(e,n+1,o+1),r=s(r,n+1,o+1)):n%2==1?(e=s(e,n+1,o),r=s(r,n+1,o)):o%2==1&&(e=s(e,n,o+1),r=s(r,n,o+1));let i=parseInt(e.rows/2,10),a=parseInt(e.columns/2,10),u=e.subMatrix(0,i-1,0,a-1),h=r.subMatrix(0,i-1,0,a-1),l=e.subMatrix(0,i-1,a,e.columns-1),c=r.subMatrix(0,i-1,a,r.columns-1),f=e.subMatrix(i,e.rows-1,0,a-1),d=r.subMatrix(i,r.rows-1,0,a-1),g=e.subMatrix(i,e.rows-1,a,e.columns-1),p=r.subMatrix(i,r.rows-1,a,r.columns-1),m=t(ae.add(u,g),ae.add(h,p),i,a),y=t(ae.add(f,g),h,i,a),w=t(u,ae.sub(c,p),i,a),v=t(g,ae.sub(d,h),i,a),x=t(ae.add(u,l),p,i,a),M=t(ae.sub(f,u),ae.add(h,c),i,a),b=t(ae.sub(l,g),ae.add(d,p),i,a),E=ae.add(m,v);E.sub(x),E.add(b);let N=ae.add(w,x),S=ae.add(y,v),A=ae.sub(m,y);A.add(w),A.add(M);let k=ae.zeros(2*E.rows,2*E.columns);return k=k.setSubMatrix(E,0,0),k=k.setSubMatrix(N,E.rows,0),k=k.setSubMatrix(S,0,E.columns),k=k.setSubMatrix(A,E.rows,E.columns),k.subMatrix(0,n-1,0,o-1)}(e,t=s(t,a,u),a,u)}scaleRows(t={}){if("object"!=typeof t)throw new TypeError("options must be an object");const{min:e=0,max:r=1}=t;if(!Number.isFinite(e))throw new TypeError("min must be a number");if(!Number.isFinite(r))throw new TypeError("max must be a number");if(e>=r)throw new RangeError("min must be smaller than max");let n=new he(this.rows,this.columns);for(let t=0;t<this.rows;t++){const o=this.getRow(t);o.length>0&&Wt(o,{min:e,max:r,output:o}),n.setRow(t,o)}return n}scaleColumns(t={}){if("object"!=typeof t)throw new TypeError("options must be an object");const{min:e=0,max:r=1}=t;if(!Number.isFinite(e))throw new TypeError("min must be a number");if(!Number.isFinite(r))throw new TypeError("max must be a number");if(e>=r)throw new RangeError("min must be smaller than max");let n=new he(this.rows,this.columns);for(let t=0;t<this.columns;t++){const o=this.getColumn(t);o.length&&Wt(o,{min:e,max:r,output:o}),n.setColumn(t,o)}return n}flipRows(){const t=Math.ceil(this.columns/2);for(let e=0;e<this.rows;e++)for(let r=0;r<t;r++){let t=this.get(e,r),n=this.get(e,this.columns-1-r);this.set(e,r,n),this.set(e,this.columns-1-r,t)}return this}flipColumns(){const t=Math.ceil(this.rows/2);for(let e=0;e<this.columns;e++)for(let r=0;r<t;r++){let t=this.get(r,e),n=this.get(this.rows-1-r,e);this.set(r,e,n),this.set(this.rows-1-r,e,t)}return this}kroneckerProduct(t){t=he.checkMatrix(t);let e=this.rows,r=this.columns,n=t.rows,o=t.columns,i=new he(e*n,r*o);for(let s=0;s<e;s++)for(let e=0;e<r;e++)for(let r=0;r<n;r++)for(let a=0;a<o;a++)i.set(n*s+r,o*e+a,this.get(s,e)*t.get(r,a));return i}kroneckerSum(t){if(t=he.checkMatrix(t),!this.isSquare()||!t.isSquare())throw new Error("Kronecker Sum needs two Square Matrices");let e=this.rows,r=t.rows,n=this.kroneckerProduct(he.eye(r,r)),o=he.eye(e,e).kroneckerProduct(t);return n.add(o)}transpose(){let t=new he(this.columns,this.rows);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.set(r,e,this.get(e,r));return t}sortRows(t=ue){for(let e=0;e<this.rows;e++)this.setRow(e,this.getRow(e).sort(t));return this}sortColumns(t=ue){for(let e=0;e<this.columns;e++)this.setColumn(e,this.getColumn(e).sort(t));return this}subMatrix(t,e,r,n){ne(this,t,e,r,n);let o=new he(e-t+1,n-r+1);for(let i=t;i<=e;i++)for(let e=r;e<=n;e++)o.set(i-t,e-r,this.get(i,e));return o}subMatrixRow(t,e,r){if(void 0===e&&(e=0),void 0===r&&(r=this.columns-1),e>r||e<0||e>=this.columns||r<0||r>=this.columns)throw new RangeError("Argument out of range");let n=new he(t.length,r-e+1);for(let o=0;o<t.length;o++)for(let i=e;i<=r;i++){if(t[o]<0||t[o]>=this.rows)throw new RangeError(`Row index out of range: ${t[o]}`);n.set(o,i-e,this.get(t[o],i))}return n}subMatrixColumn(t,e,r){if(void 0===e&&(e=0),void 0===r&&(r=this.rows-1),e>r||e<0||e>=this.rows||r<0||r>=this.rows)throw new RangeError("Argument out of range");let n=new he(r-e+1,t.length);for(let o=0;o<t.length;o++)for(let i=e;i<=r;i++){if(t[o]<0||t[o]>=this.columns)throw new RangeError(`Column index out of range: ${t[o]}`);n.set(i-e,o,this.get(i,t[o]))}return n}setSubMatrix(t,e,r){if((t=he.checkMatrix(t)).isEmpty())return this;ne(this,e,e+t.rows-1,r,r+t.columns-1);for(let n=0;n<t.rows;n++)for(let o=0;o<t.columns;o++)this.set(e+n,r+o,t.get(n,o));return this}selection(t,e){!function(t,e){if(!Bt(e))throw new TypeError("row indices must be an array");for(let r=0;r<e.length;r++)if(e[r]<0||e[r]>=t.rows)throw new RangeError("row indices are out of range")}(this,t),function(t,e){if(!Bt(e))throw new TypeError("column indices must be an array");for(let r=0;r<e.length;r++)if(e[r]<0||e[r]>=t.columns)throw new RangeError("column indices are out of range")}(this,e);let r=new he(t.length,e.length);for(let n=0;n<t.length;n++){let o=t[n];for(let t=0;t<e.length;t++){let i=e[t];r.set(n,t,this.get(o,i))}}return r}trace(){let t=Math.min(this.rows,this.columns),e=0;for(let r=0;r<t;r++)e+=this.get(r,r);return e}clone(){let t=new he(this.rows,this.columns);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.set(e,r,this.get(e,r));return t}sum(t){switch(t){case"row":return function(t){let e=oe(t.rows);for(let r=0;r<t.rows;++r)for(let n=0;n<t.columns;++n)e[r]+=t.get(r,n);return e}(this);case"column":return function(t){let e=oe(t.columns);for(let r=0;r<t.rows;++r)for(let n=0;n<t.columns;++n)e[n]+=t.get(r,n);return e}(this);case void 0:return function(t){let e=0;for(let r=0;r<t.rows;r++)for(let n=0;n<t.columns;n++)e+=t.get(r,n);return e}(this);default:throw new Error(`invalid option: ${t}`)}}product(t){switch(t){case"row":return function(t){let e=oe(t.rows,1);for(let r=0;r<t.rows;++r)for(let n=0;n<t.columns;++n)e[r]*=t.get(r,n);return e}(this);case"column":return function(t){let e=oe(t.columns,1);for(let r=0;r<t.rows;++r)for(let n=0;n<t.columns;++n)e[n]*=t.get(r,n);return e}(this);case void 0:return function(t){let e=1;for(let r=0;r<t.rows;r++)for(let n=0;n<t.columns;n++)e*=t.get(r,n);return e}(this);default:throw new Error(`invalid option: ${t}`)}}mean(t){const e=this.sum(t);switch(t){case"row":for(let t=0;t<this.rows;t++)e[t]/=this.columns;return e;case"column":for(let t=0;t<this.columns;t++)e[t]/=this.rows;return e;case void 0:return e/this.size;default:throw new Error(`invalid option: ${t}`)}}variance(t,e={}){if("object"==typeof t&&(e=t,t=void 0),"object"!=typeof e)throw new TypeError("options must be an object");const{unbiased:r=!0,mean:n=this.mean(t)}=e;if("boolean"!=typeof r)throw new TypeError("unbiased must be a boolean");switch(t){case"row":if(!Bt(n))throw new TypeError("mean must be an array");return function(t,e,r){const n=t.rows,o=t.columns,i=[];for(let s=0;s<n;s++){let n=0,a=0,u=0;for(let e=0;e<o;e++)u=t.get(s,e)-r[s],n+=u,a+=u*u;e?i.push((a-n*n/o)/(o-1)):i.push((a-n*n/o)/o)}return i}(this,r,n);case"column":if(!Bt(n))throw new TypeError("mean must be an array");return function(t,e,r){const n=t.rows,o=t.columns,i=[];for(let s=0;s<o;s++){let o=0,a=0,u=0;for(let e=0;e<n;e++)u=t.get(e,s)-r[s],o+=u,a+=u*u;e?i.push((a-o*o/n)/(n-1)):i.push((a-o*o/n)/n)}return i}(this,r,n);case void 0:if("number"!=typeof n)throw new TypeError("mean must be a number");return function(t,e,r){const n=t.rows,o=t.columns,i=n*o;let s=0,a=0,u=0;for(let e=0;e<n;e++)for(let n=0;n<o;n++)u=t.get(e,n)-r,s+=u,a+=u*u;return e?(a-s*s/i)/(i-1):(a-s*s/i)/i}(this,r,n);default:throw new Error(`invalid option: ${t}`)}}standardDeviation(t,e){"object"==typeof t&&(e=t,t=void 0);const r=this.variance(t,e);if(void 0===t)return Math.sqrt(r);for(let t=0;t<r.length;t++)r[t]=Math.sqrt(r[t]);return r}center(t,e={}){if("object"==typeof t&&(e=t,t=void 0),"object"!=typeof e)throw new TypeError("options must be an object");const{center:r=this.mean(t)}=e;switch(t){case"row":if(!Bt(r))throw new TypeError("center must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let n=0;n<t.columns;n++)t.set(r,n,t.get(r,n)-e[r])}(this,r),this;case"column":if(!Bt(r))throw new TypeError("center must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let n=0;n<t.columns;n++)t.set(r,n,t.get(r,n)-e[n])}(this,r),this;case void 0:if("number"!=typeof r)throw new TypeError("center must be a number");return function(t,e){for(let r=0;r<t.rows;r++)for(let n=0;n<t.columns;n++)t.set(r,n,t.get(r,n)-e)}(this,r),this;default:throw new Error(`invalid option: ${t}`)}}scale(t,e={}){if("object"==typeof t&&(e=t,t=void 0),"object"!=typeof e)throw new TypeError("options must be an object");let r=e.scale;switch(t){case"row":if(void 0===r)r=function(t){const e=[];for(let r=0;r<t.rows;r++){let n=0;for(let e=0;e<t.columns;e++)n+=Math.pow(t.get(r,e),2)/(t.columns-1);e.push(Math.sqrt(n))}return e}(this);else if(!Bt(r))throw new TypeError("scale must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let n=0;n<t.columns;n++)t.set(r,n,t.get(r,n)/e[r])}(this,r),this;case"column":if(void 0===r)r=function(t){const e=[];for(let r=0;r<t.columns;r++){let n=0;for(let e=0;e<t.rows;e++)n+=Math.pow(t.get(e,r),2)/(t.rows-1);e.push(Math.sqrt(n))}return e}(this);else if(!Bt(r))throw new TypeError("scale must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let n=0;n<t.columns;n++)t.set(r,n,t.get(r,n)/e[n])}(this,r),this;case void 0:if(void 0===r)r=function(t){const e=t.size-1;let r=0;for(let n=0;n<t.columns;n++)for(let o=0;o<t.rows;o++)r+=Math.pow(t.get(o,n),2)/e;return Math.sqrt(r)}(this);else if("number"!=typeof r)throw new TypeError("scale must be a number");return function(t,e){for(let r=0;r<t.rows;r++)for(let n=0;n<t.columns;n++)t.set(r,n,t.get(r,n)/e)}(this,r),this;default:throw new Error(`invalid option: ${t}`)}}toString(t){return Yt(this,t)}}function ue(t,e){return t-e}ae.prototype.klass="Matrix","undefined"!=typeof Symbol&&(ae.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return Yt(this)}),ae.random=ae.rand,ae.randomInt=ae.randInt,ae.diagonal=ae.diag,ae.prototype.diagonal=ae.prototype.diag,ae.identity=ae.eye,ae.prototype.negate=ae.prototype.neg,ae.prototype.tensorProduct=ae.prototype.kroneckerProduct;class he extends ae{constructor(t,e){if(super(),he.isMatrix(t))return t.clone();if(Number.isInteger(t)&&t>=0){if(this.data=[],!(Number.isInteger(e)&&e>=0))throw new TypeError("nColumns must be a positive integer");for(let r=0;r<t;r++)this.data.push(new Float64Array(e))}else{if(!Bt(t))throw new TypeError("First argument must be a positive number or an array");{const r=t;if("number"!=typeof(e=(t=r.length)?r[0].length:0))throw new TypeError("Data must be a 2D array with at least one element");this.data=[];for(let n=0;n<t;n++){if(r[n].length!==e)throw new RangeError("Inconsistent array dimensions");if(!r[n].every((t=>"number"==typeof t)))throw new TypeError("Input data contains non-numeric values");this.data.push(Float64Array.from(r[n]))}}}this.rows=t,this.columns=e}set(t,e,r){return this.data[t][e]=r,this}get(t,e){return this.data[t][e]}removeRow(t){return Zt(this,t),this.data.splice(t,1),this.rows-=1,this}addRow(t,e){return void 0===e&&(e=t,t=this.rows),Zt(this,t,!0),e=Float64Array.from(ee(this,e)),this.data.splice(t,0,e),this.rows+=1,this}removeColumn(t){te(this,t);for(let e=0;e<this.rows;e++){const r=new Float64Array(this.columns-1);for(let n=0;n<t;n++)r[n]=this.data[e][n];for(let n=t+1;n<this.columns;n++)r[n-1]=this.data[e][n];this.data[e]=r}return this.columns-=1,this}addColumn(t,e){void 0===e&&(e=t,t=this.columns),te(this,t,!0),e=re(this,e);for(let r=0;r<this.rows;r++){const n=new Float64Array(this.columns+1);let o=0;for(;o<t;o++)n[o]=this.data[r][o];for(n[o++]=e[r];o<this.columns+1;o++)n[o]=this.data[r][o-1];this.data[r]=n}return this.columns+=1,this}}!function(t,e){t.prototype.add=function(t){return"number"==typeof t?this.addS(t):this.addM(t)},t.prototype.addS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t);return this},t.prototype.addM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t.get(e,r));return this},t.add=function(t,r){return new e(t).add(r)},t.prototype.sub=function(t){return"number"==typeof t?this.subS(t):this.subM(t)},t.prototype.subS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t);return this},t.prototype.subM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t.get(e,r));return this},t.sub=function(t,r){return new e(t).sub(r)},t.prototype.subtract=t.prototype.sub,t.prototype.subtractS=t.prototype.subS,t.prototype.subtractM=t.prototype.subM,t.subtract=t.sub,t.prototype.mul=function(t){return"number"==typeof t?this.mulS(t):this.mulM(t)},t.prototype.mulS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t);return this},t.prototype.mulM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t.get(e,r));return this},t.mul=function(t,r){return new e(t).mul(r)},t.prototype.multiply=t.prototype.mul,t.prototype.multiplyS=t.prototype.mulS,t.prototype.multiplyM=t.prototype.mulM,t.multiply=t.mul,t.prototype.div=function(t){return"number"==typeof t?this.divS(t):this.divM(t)},t.prototype.divS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t);return this},t.prototype.divM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t.get(e,r));return this},t.div=function(t,r){return new e(t).div(r)},t.prototype.divide=t.prototype.div,t.prototype.divideS=t.prototype.divS,t.prototype.divideM=t.prototype.divM,t.divide=t.div,t.prototype.mod=function(t){return"number"==typeof t?this.modS(t):this.modM(t)},t.prototype.modS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)%t);return this},t.prototype.modM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)%t.get(e,r));return this},t.mod=function(t,r){return new e(t).mod(r)},t.prototype.modulus=t.prototype.mod,t.prototype.modulusS=t.prototype.modS,t.prototype.modulusM=t.prototype.modM,t.modulus=t.mod,t.prototype.and=function(t){return"number"==typeof t?this.andS(t):this.andM(t)},t.prototype.andS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)&t);return this},t.prototype.andM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)&t.get(e,r));return this},t.and=function(t,r){return new e(t).and(r)},t.prototype.or=function(t){return"number"==typeof t?this.orS(t):this.orM(t)},t.prototype.orS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)|t);return this},t.prototype.orM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)|t.get(e,r));return this},t.or=function(t,r){return new e(t).or(r)},t.prototype.xor=function(t){return"number"==typeof t?this.xorS(t):this.xorM(t)},t.prototype.xorS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)^t);return this},t.prototype.xorM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)^t.get(e,r));return this},t.xor=function(t,r){return new e(t).xor(r)},t.prototype.leftShift=function(t){return"number"==typeof t?this.leftShiftS(t):this.leftShiftM(t)},t.prototype.leftShiftS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)<<t);return this},t.prototype.leftShiftM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)<<t.get(e,r));return this},t.leftShift=function(t,r){return new e(t).leftShift(r)},t.prototype.signPropagatingRightShift=function(t){return"number"==typeof t?this.signPropagatingRightShiftS(t):this.signPropagatingRightShiftM(t)},t.prototype.signPropagatingRightShiftS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>t);return this},t.prototype.signPropagatingRightShiftM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>t.get(e,r));return this},t.signPropagatingRightShift=function(t,r){return new e(t).signPropagatingRightShift(r)},t.prototype.rightShift=function(t){return"number"==typeof t?this.rightShiftS(t):this.rightShiftM(t)},t.prototype.rightShiftS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>>t);return this},t.prototype.rightShiftM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>>t.get(e,r));return this},t.rightShift=function(t,r){return new e(t).rightShift(r)},t.prototype.zeroFillRightShift=t.prototype.rightShift,t.prototype.zeroFillRightShiftS=t.prototype.rightShiftS,t.prototype.zeroFillRightShiftM=t.prototype.rightShiftM,t.zeroFillRightShift=t.rightShift,t.prototype.not=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,~this.get(t,e));return this},t.not=function(t){return new e(t).not()},t.prototype.abs=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.abs(this.get(t,e)));return this},t.abs=function(t){return new e(t).abs()},t.prototype.acos=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.acos(this.get(t,e)));return this},t.acos=function(t){return new e(t).acos()},t.prototype.acosh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.acosh(this.get(t,e)));return this},t.acosh=function(t){return new e(t).acosh()},t.prototype.asin=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.asin(this.get(t,e)));return this},t.asin=function(t){return new e(t).asin()},t.prototype.asinh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.asinh(this.get(t,e)));return this},t.asinh=function(t){return new e(t).asinh()},t.prototype.atan=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.atan(this.get(t,e)));return this},t.atan=function(t){return new e(t).atan()},t.prototype.atanh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.atanh(this.get(t,e)));return this},t.atanh=function(t){return new e(t).atanh()},t.prototype.cbrt=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.cbrt(this.get(t,e)));return this},t.cbrt=function(t){return new e(t).cbrt()},t.prototype.ceil=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.ceil(this.get(t,e)));return this},t.ceil=function(t){return new e(t).ceil()},t.prototype.clz32=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.clz32(this.get(t,e)));return this},t.clz32=function(t){return new e(t).clz32()},t.prototype.cos=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.cos(this.get(t,e)));return this},t.cos=function(t){return new e(t).cos()},t.prototype.cosh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.cosh(this.get(t,e)));return this},t.cosh=function(t){return new e(t).cosh()},t.prototype.exp=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.exp(this.get(t,e)));return this},t.exp=function(t){return new e(t).exp()},t.prototype.expm1=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.expm1(this.get(t,e)));return this},t.expm1=function(t){return new e(t).expm1()},t.prototype.floor=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.floor(this.get(t,e)));return this},t.floor=function(t){return new e(t).floor()},t.prototype.fround=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.fround(this.get(t,e)));return this},t.fround=function(t){return new e(t).fround()},t.prototype.log=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log(this.get(t,e)));return this},t.log=function(t){return new e(t).log()},t.prototype.log1p=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log1p(this.get(t,e)));return this},t.log1p=function(t){return new e(t).log1p()},t.prototype.log10=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log10(this.get(t,e)));return this},t.log10=function(t){return new e(t).log10()},t.prototype.log2=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log2(this.get(t,e)));return this},t.log2=function(t){return new e(t).log2()},t.prototype.round=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.round(this.get(t,e)));return this},t.round=function(t){return new e(t).round()},t.prototype.sign=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sign(this.get(t,e)));return this},t.sign=function(t){return new e(t).sign()},t.prototype.sin=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sin(this.get(t,e)));return this},t.sin=function(t){return new e(t).sin()},t.prototype.sinh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sinh(this.get(t,e)));return this},t.sinh=function(t){return new e(t).sinh()},t.prototype.sqrt=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sqrt(this.get(t,e)));return this},t.sqrt=function(t){return new e(t).sqrt()},t.prototype.tan=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.tan(this.get(t,e)));return this},t.tan=function(t){return new e(t).tan()},t.prototype.tanh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.tanh(this.get(t,e)));return this},t.tanh=function(t){return new e(t).tanh()},t.prototype.trunc=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.trunc(this.get(t,e)));return this},t.trunc=function(t){return new e(t).trunc()},t.pow=function(t,r){return new e(t).pow(r)},t.prototype.pow=function(t){return"number"==typeof t?this.powS(t):this.powM(t)},t.prototype.powS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,Math.pow(this.get(e,r),t));return this},t.prototype.powM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,Math.pow(this.get(e,r),t.get(e,r)));return this}}(ae,he);class le extends ae{constructor(t){super(),this.data=t,this.rows=t.length,this.columns=t[0].length}set(t,e,r){return this.data[t][e]=r,this}get(t,e){return this.data[t][e]}}function ce(t,e){let r=0;return Math.abs(t)>Math.abs(e)?(r=e/t,Math.abs(t)*Math.sqrt(1+r*r)):0!==e?(r=t/e,Math.abs(e)*Math.sqrt(1+r*r)):0}class fe{constructor(t,e={}){if((t=le.checkMatrix(t)).isEmpty())throw new Error("Matrix must be non-empty");let r=t.rows,n=t.columns;const{computeLeftSingularVectors:o=!0,computeRightSingularVectors:i=!0,autoTranspose:s=!1}=e;let a,u=Boolean(o),h=Boolean(i),l=!1;if(r<n)if(s){a=t.transpose(),r=a.rows,n=a.columns,l=!0;let e=u;u=h,h=e}else a=t.clone(),console.warn("Computing SVD on a matrix with more columns than rows. Consider enabling autoTranspose");else a=t.clone();let c=Math.min(r,n),f=Math.min(r+1,n),d=new Float64Array(f),g=new he(r,c),p=new he(n,n),m=new Float64Array(n),y=new Float64Array(r),w=new Float64Array(f);for(let t=0;t<f;t++)w[t]=t;let v=Math.min(r-1,n),x=Math.max(0,Math.min(n-2,r)),M=Math.max(v,x);for(let t=0;t<M;t++){if(t<v){d[t]=0;for(let e=t;e<r;e++)d[t]=ce(d[t],a.get(e,t));if(0!==d[t]){a.get(t,t)<0&&(d[t]=-d[t]);for(let e=t;e<r;e++)a.set(e,t,a.get(e,t)/d[t]);a.set(t,t,a.get(t,t)+1)}d[t]=-d[t]}for(let e=t+1;e<n;e++){if(t<v&&0!==d[t]){let n=0;for(let o=t;o<r;o++)n+=a.get(o,t)*a.get(o,e);n=-n/a.get(t,t);for(let o=t;o<r;o++)a.set(o,e,a.get(o,e)+n*a.get(o,t))}m[e]=a.get(t,e)}if(u&&t<v)for(let e=t;e<r;e++)g.set(e,t,a.get(e,t));if(t<x){m[t]=0;for(let e=t+1;e<n;e++)m[t]=ce(m[t],m[e]);if(0!==m[t]){m[t+1]<0&&(m[t]=0-m[t]);for(let e=t+1;e<n;e++)m[e]/=m[t];m[t+1]+=1}if(m[t]=-m[t],t+1<r&&0!==m[t]){for(let e=t+1;e<r;e++)y[e]=0;for(let e=t+1;e<r;e++)for(let r=t+1;r<n;r++)y[e]+=m[r]*a.get(e,r);for(let e=t+1;e<n;e++){let n=-m[e]/m[t+1];for(let o=t+1;o<r;o++)a.set(o,e,a.get(o,e)+n*y[o])}}if(h)for(let e=t+1;e<n;e++)p.set(e,t,m[e])}}let b=Math.min(n,r+1);if(v<n&&(d[v]=a.get(v,v)),r<b&&(d[b-1]=0),x+1<b&&(m[x]=a.get(x,b-1)),m[b-1]=0,u){for(let t=v;t<c;t++){for(let e=0;e<r;e++)g.set(e,t,0);g.set(t,t,1)}for(let t=v-1;t>=0;t--)if(0!==d[t]){for(let e=t+1;e<c;e++){let n=0;for(let o=t;o<r;o++)n+=g.get(o,t)*g.get(o,e);n=-n/g.get(t,t);for(let o=t;o<r;o++)g.set(o,e,g.get(o,e)+n*g.get(o,t))}for(let e=t;e<r;e++)g.set(e,t,-g.get(e,t));g.set(t,t,1+g.get(t,t));for(let e=0;e<t-1;e++)g.set(e,t,0)}else{for(let e=0;e<r;e++)g.set(e,t,0);g.set(t,t,1)}}if(h)for(let t=n-1;t>=0;t--){if(t<x&&0!==m[t])for(let e=t+1;e<n;e++){let r=0;for(let o=t+1;o<n;o++)r+=p.get(o,t)*p.get(o,e);r=-r/p.get(t+1,t);for(let o=t+1;o<n;o++)p.set(o,e,p.get(o,e)+r*p.get(o,t))}for(let e=0;e<n;e++)p.set(e,t,0);p.set(t,t,1)}let E=b-1,N=0,S=Number.EPSILON;for(;b>0;){let t,e;for(t=b-2;t>=-1&&-1!==t;t--){const e=Number.MIN_VALUE+S*Math.abs(d[t]+Math.abs(d[t+1]));if(Math.abs(m[t])<=e||Number.isNaN(m[t])){m[t]=0;break}}if(t===b-2)e=4;else{let r;for(r=b-1;r>=t&&r!==t;r--){let e=(r!==b?Math.abs(m[r]):0)+(r!==t+1?Math.abs(m[r-1]):0);if(Math.abs(d[r])<=S*e){d[r]=0;break}}r===t?e=3:r===b-1?e=1:(e=2,t=r)}switch(t++,e){case 1:{let e=m[b-2];m[b-2]=0;for(let r=b-2;r>=t;r--){let o=ce(d[r],e),i=d[r]/o,s=e/o;if(d[r]=o,r!==t&&(e=-s*m[r-1],m[r-1]=i*m[r-1]),h)for(let t=0;t<n;t++)o=i*p.get(t,r)+s*p.get(t,b-1),p.set(t,b-1,-s*p.get(t,r)+i*p.get(t,b-1)),p.set(t,r,o)}break}case 2:{let e=m[t-1];m[t-1]=0;for(let n=t;n<b;n++){let o=ce(d[n],e),i=d[n]/o,s=e/o;if(d[n]=o,e=-s*m[n],m[n]=i*m[n],u)for(let e=0;e<r;e++)o=i*g.get(e,n)+s*g.get(e,t-1),g.set(e,t-1,-s*g.get(e,n)+i*g.get(e,t-1)),g.set(e,n,o)}break}case 3:{const e=Math.max(Math.abs(d[b-1]),Math.abs(d[b-2]),Math.abs(m[b-2]),Math.abs(d[t]),Math.abs(m[t])),o=d[b-1]/e,i=d[b-2]/e,s=m[b-2]/e,a=d[t]/e,l=m[t]/e,c=((i+o)*(i-o)+s*s)/2,f=o*s*(o*s);let y=0;0===c&&0===f||(y=c<0?0-Math.sqrt(c*c+f):Math.sqrt(c*c+f),y=f/(c+y));let w=(a+o)*(a-o)+y,v=a*l;for(let e=t;e<b-1;e++){let o=ce(w,v);0===o&&(o=Number.MIN_VALUE);let i=w/o,s=v/o;if(e!==t&&(m[e-1]=o),w=i*d[e]+s*m[e],m[e]=i*m[e]-s*d[e],v=s*d[e+1],d[e+1]=i*d[e+1],h)for(let t=0;t<n;t++)o=i*p.get(t,e)+s*p.get(t,e+1),p.set(t,e+1,-s*p.get(t,e)+i*p.get(t,e+1)),p.set(t,e,o);if(o=ce(w,v),0===o&&(o=Number.MIN_VALUE),i=w/o,s=v/o,d[e]=o,w=i*m[e]+s*d[e+1],d[e+1]=-s*m[e]+i*d[e+1],v=s*m[e+1],m[e+1]=i*m[e+1],u&&e<r-1)for(let t=0;t<r;t++)o=i*g.get(t,e)+s*g.get(t,e+1),g.set(t,e+1,-s*g.get(t,e)+i*g.get(t,e+1)),g.set(t,e,o)}m[b-2]=w,N+=1;break}case 4:if(d[t]<=0&&(d[t]=d[t]<0?-d[t]:0,h))for(let e=0;e<=E;e++)p.set(e,t,-p.get(e,t));for(;t<E&&!(d[t]>=d[t+1]);){let e=d[t];if(d[t]=d[t+1],d[t+1]=e,h&&t<n-1)for(let r=0;r<n;r++)e=p.get(r,t+1),p.set(r,t+1,p.get(r,t)),p.set(r,t,e);if(u&&t<r-1)for(let n=0;n<r;n++)e=g.get(n,t+1),g.set(n,t+1,g.get(n,t)),g.set(n,t,e);t++}N=0,b--}}if(l){let t=p;p=g,g=t}this.m=r,this.n=n,this.s=d,this.U=g,this.V=p}solve(t){let e=t,r=this.threshold,n=this.s.length,o=he.zeros(n,n);for(let t=0;t<n;t++)Math.abs(this.s[t])<=r?o.set(t,t,0):o.set(t,t,1/this.s[t]);let i=this.U,s=this.rightSingularVectors,a=s.mmul(o),u=s.rows,h=i.rows,l=he.zeros(u,h);for(let t=0;t<u;t++)for(let e=0;e<h;e++){let r=0;for(let o=0;o<n;o++)r+=a.get(t,o)*i.get(e,o);l.set(t,e,r)}return l.mmul(e)}solveForDiagonal(t){return this.solve(he.diag(t))}inverse(){let t=this.V,e=this.threshold,r=t.rows,n=t.columns,o=new he(r,this.s.length);for(let i=0;i<r;i++)for(let r=0;r<n;r++)Math.abs(this.s[r])>e&&o.set(i,r,t.get(i,r)/this.s[r]);let i=this.U,s=i.rows,a=i.columns,u=new he(r,s);for(let t=0;t<r;t++)for(let e=0;e<s;e++){let r=0;for(let n=0;n<a;n++)r+=o.get(t,n)*i.get(e,n);u.set(t,e,r)}return u}get condition(){return this.s[0]/this.s[Math.min(this.m,this.n)-1]}get norm2(){return this.s[0]}get rank(){let t=Math.max(this.m,this.n)*this.s[0]*Number.EPSILON,e=0,r=this.s;for(let n=0,o=r.length;n<o;n++)r[n]>t&&e++;return e}get diagonal(){return Array.from(this.s)}get threshold(){return Number.EPSILON/2*Math.max(this.m,this.n)*this.s[0]}get leftSingularVectors(){return this.U}get rightSingularVectors(){return this.V}get diagonalMatrix(){return he.diag(this.s)}}var de,ge={center:[0,0],linkDistance:50},pe=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="mds",this.options=r(r({},ge),t)}return t.prototype.execute=function(t,e){return this.genericMDSLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericMDSLayout(!0,t,e)},t.prototype.genericMDSLayout=function(t,e,n){var o=r(r({},this.options),n),i=o.center,s=void 0===i?[0,0]:i,a=o.linkDistance,u=void 0===a?50:a,h=o.layoutInvisibles,l=o.onLayoutEnd,d=e.getAllNodes(),g=e.getAllEdges();if(h||(d=d.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e})),g=g.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e}))),!d||0===d.length){var p={nodes:[],edges:g};return null==l||l(p),p}if(1===d.length){t&&e.mergeNodeData(d[0].id,{x:s[0],y:s[1]});var y={nodes:[r(r({},d[0]),{data:r(r({},d[0].data),{x:s[0],y:s[1]})})],edges:g};return null==l||l(y),y}var w=f({nodes:d,edges:g},!1),v=c(w);me(v);var x=function(t,e){var r=[];return t.forEach((function(t){var n=[];t.forEach((function(t){n.push(t*e)})),r.push(n)})),r}(v,u),M=ye(x),b=[];M.forEach((function(t,e){var r=m(d[e]);r.data.x=t[0]+s[0],r.data.y=t[1]+s[1],b.push(r)})),t&&b.forEach((function(t){return e.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}));var E={nodes:b,edges:g};return null==l||l(E),E},t}(),me=function(t){var e=-999999;t.forEach((function(t){t.forEach((function(t){t!==1/0&&e<t&&(e=t)}))})),t.forEach((function(r,n){r.forEach((function(r,o){r===1/0&&(t[n][o]=e)}))}))},ye=function(t){var e=he.mul(he.pow(t,2),-.5),r=e.mean("row"),n=e.mean("column"),o=e.mean();e.add(o).subRowVector(r).subColumnVector(n);var i=new fe(e),s=he.sqrt(i.diagonalMatrix).diagonal();return i.leftSingularVectors.toJSON().map((function(t){return he.mul([t],[s]).toJSON()[0].splice(0,2)}))},we={iterations:10,height:10,width:10,speed:100,gravity:10,k:5},ve=function(t,e,r,n,o,i){e.forEach((function(s,a){r[a]={x:0,y:0},e.forEach((function(e,u){if(a!==u&&o[a]===o[u]){var h=s.x-e.x,l=s.y-e.y,c=Math.sqrt(h*h+l*l);if(0===c){c=1;var f=a>u?1:-1;h=.01*f,l=.01*f}if(c<i(t[a])/2+i(t[u])/2){var d=n*n/c;r[a].x+=h/c*d,r[a].y+=l/c*d}}}))}))},xe=function(t,e,r,n,o,i,s,a){var u=i||s/10;return n&&e.forEach((function(e,r){var n=t[r].x-t[o].x,i=t[r].y-t[o].y,s=Math.sqrt(n*n+i*i),a=i/s,u=-n/s,h=Math.sqrt(e.x*e.x+e.y*e.y),l=Math.acos((a*e.x+u*e.y)/h);l>Math.PI/2&&(l-=Math.PI/2,a*=-1,u*=-1);var c=Math.cos(l)*h;e.x=a*c,e.y=u*c})),t.forEach((function(i,s){if(s!==o){var h=Math.sqrt(e[s].x*e[s].x+e[s].y*e[s].y);if(h>0&&s!==o){var l=Math.min(u*(r/800),h);if(i.x+=e[s].x/h*l,i.y+=e[s].y/h*l,n){var c=i.x-t[o].x,f=i.y-t[o].y,d=Math.sqrt(c*c+f*f);c=c/d*a[s],f=f/d*a[s],i.x=t[o].x+c,i.y=t[o].y+f}}}})),t},Me={maxIteration:1e3,focusNode:null,unitRadius:null,linkDistance:50,preventOverlap:!1,strictRadial:!0,maxPreventOverlapIteration:200,sortStrength:10},be=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="radial",this.options=r(r({},Me),t)}return t.prototype.execute=function(t,e){return this.genericRadialLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericRadialLayout(!0,t,e)},t.prototype.genericRadialLayout=function(t,e,n){var s=r(r({},this.options),n),u=s.width,h=s.height,l=s.center,d=s.focusNode,g=s.unitRadius,p=s.nodeSize,y=s.nodeSpacing,w=s.strictRadial,v=s.preventOverlap,x=s.maxPreventOverlapIteration,M=s.sortBy,b=s.linkDistance,E=void 0===b?50:b,N=s.sortStrength,S=void 0===N?10:N,A=s.maxIteration,k=void 0===A?1e3:A,I=s.layoutInvisibles,D=s.onLayoutEnd,R=e.getAllNodes(),_=e.getAllEdges();if(I||(R=R.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e})),_=_.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e}))),!R||0===R.length){var z={nodes:[],edges:_};return null==D||D(z),z}var T=u||"undefined"==typeof window?u:window.innerWidth,C=h||"undefined"==typeof window?h:window.innerHeight,O=l||[T/2,C/2];if(1===R.length){t&&e.mergeNodeData(R[0].id,{x:O[0],y:O[1]});var P={nodes:[r(r({},R[0]),{data:r(r({},R[0].data),{x:O[0],y:O[1]})})],edges:_};return null==D||D(P),P}var L=R[0];if(a(d)){for(var q=0;q<R.length;q++)if(R[q].id===d){L=R[q];break}}else L=d||R[0];var j=Se(R,L.id),V=f({nodes:R,edges:_},!1),F=c(V),$=ke(F,j);Ae(F,j,$+1);var U=F[j],B=T-O[0]>O[0]?O[0]:T-O[0],G=C-O[1]>O[1]?O[1]:C-O[1];0===B&&(B=T/2),0===G&&(G=C/2);var K=Math.min(B,G),W=Math.max.apply(Math,i([],o(U),!1)),H=[],J=g||K/W;U.forEach((function(t,e){H[e]=t*J}));var Y,X=Ee(R,F,E,H,J,M,S),Q=Ne(X),Z=function(t,e,r){try{var n=he.mul(he.pow(e,2),-.5),o=n.mean("row"),i=n.mean("column"),s=n.mean();n.add(s).subRowVector(o).subColumnVector(i);var a=new fe(n),u=he.sqrt(a.diagonalMatrix).diagonal();return a.leftSingularVectors.toJSON().map((function(e){return he.mul([e],[u]).toJSON()[0].splice(0,t)}))}catch(t){for(var h=[],l=0;l<e.length;l++){var c=Math.random()*r,f=Math.random()*r;h.push([c,f])}return h}}(E,X,E),tt=Z.map((function(t){var e=o(t,2),r=e[0],n=e[1];return{x:(isNaN(r)?Math.random()*E:r)-Z[j][0],y:(isNaN(n)?Math.random()*E:n)-Z[j][1]}}));if(this.run(k,tt,Q,X,H,j),v){Y=Ie(p,y);var et={nodes:R,nodeSizeFunc:Y,positions:tt,radii:H,height:C,width:T,strictRadial:Boolean(w),focusIdx:j,iterations:x||200,k:tt.length/4.5};tt=function(t,e){for(var n=r(r({},we),e),o=n.positions,i=n.iterations,s=n.width,a=n.k,u=n.speed,h=void 0===u?100:u,l=n.strictRadial,c=n.focusIdx,f=n.radii,d=void 0===f?[]:f,g=n.nodeSizeFunc,p=t.getAllNodes(),m=[],y=s/10,w=0;w<i;w++)o.forEach((function(t,e){m[e]={x:0,y:0}})),ve(p,o,m,a,d,g),xe(o,m,h,l,c,y,s,d);return o}(e,et)}var rt=[];tt.forEach((function(t,e){var r=m(R[e]);r.data.x=t.x+O[0],r.data.y=t.y+O[1],rt.push(r)})),t&&rt.forEach((function(t){return e.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}));var nt={nodes:rt,edges:_};return null==D||D(nt),nt},t.prototype.run=function(t,e,r,n,o,i){for(var s=0;s<=t;s++){var a=s/t;this.oneIteration(a,e,o,n,r,i)}},t.prototype.oneIteration=function(t,e,r,n,o,i){var s=1-t;e.forEach((function(a,u){var h=d(a,{x:0,y:0}),l=0===h?0:1/h;if(u!==i){var c=0,f=0,g=0;e.forEach((function(t,e){if(u!==e){var r=d(a,t),i=0===r?0:1/r,s=n[e][u];g+=o[u][e],c+=o[u][e]*(t.x+s*(a.x-t.x)*i),f+=o[u][e]*(t.y+s*(a.y-t.y)*i)}}));var p=0===r[u]?0:1/r[u];g*=s,g+=t*p*p,c*=s,c+=t*p*a.x*l,a.x=c/g,f*=s,f+=t*p*a.y*l,a.y=f/g}}))},t}(),Ee=function(t,e,r,n,o,i,s){if(!t)return[];var u=[];if(e){var h={};e.forEach((function(e,l){var c=[];e.forEach((function(e,u){var f,d;if(l===u)c.push(0);else if(n[l]===n[u])if("data"===i)c.push(e*(Math.abs(l-u)*s)/(n[l]/o));else if(i){var g=void 0,p=void 0;if(h[t[l].id])g=h[t[l].id];else{var m=("id"===i?t[l].id:null===(f=t[l].data)||void 0===f?void 0:f[i])||0;g=a(m)?m.charCodeAt(0):m,h[t[l].id]=g}h[t[u].id]?p=h[t[u].id]:(m=("id"===i?t[u].id:null===(d=t[u].data)||void 0===d?void 0:d[i])||0,p=a(m)?m.charCodeAt(0):m,h[t[u].id]=p),c.push(e*(Math.abs(g-p)*s)/(n[l]/o))}else c.push(e*r/(n[l]/o));else{var y=(r+o)/2;c.push(e*y)}})),u.push(c)}))}return u},Ne=function(t){for(var e=t.length,r=t[0].length,n=[],o=0;o<e;o++){for(var i=[],s=0;s<r;s++)0!==t[o][s]?i.push(1/(t[o][s]*t[o][s])):i.push(0);n.push(i)}return n},Se=function(t,e){var r=-1;return t.forEach((function(t,n){t.id===e&&(r=n)})),Math.max(r,0)},Ae=function(t,e,r){for(var n=t.length,o=0;o<n;o++)if(t[e][o]===1/0){t[e][o]=r,t[o][e]=r;for(var i=0;i<n;i++)t[o][i]!==1/0&&t[e][i]===1/0&&(t[e][i]=r+t[o][i],t[i][e]=r+t[o][i])}for(o=0;o<n;o++)if(o!==e)for(i=0;i<n;i++)if(t[o][i]===1/0){var s=Math.abs(t[e][o]-t[e][i]);s=0===s?1:s,t[o][i]=s}},ke=function(t,e){for(var r=0,n=0;n<t[e].length;n++)t[e][n]!==1/0&&(r=t[e][n]>r?t[e][n]:r);return r},Ie=function(t,e){var r;return r=l(e)?function(){return e}:y(e)?e:function(){return 0},t?h(t)?function(e){return(t[0]>t[1]?t[0]:t[1])+r(e)}:function(e){return t+r(e)}:function(t){var e,n;return(null===(e=t.data)||void 0===e?void 0:e.bboxSize)?Math.max(t.data.bboxSize[0],t.data.bboxSize[1])+r(t):(null===(n=t.data)||void 0===n?void 0:n.size)?h(t.data.size)?Math.max(t.data.size[0],t.data.size[1])+r(t):g(t.data.size)?(t.data.size.width>t.data.size.height?t.data.size.width:t.data.size.height)+r(t):t.data.size+r(t):10+r(t)}},De={center:[0,0],width:300,height:300},Re={circular:M,concentric:S,mds:pe,random:function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="random",this.options=r(r({},De),t)}return t.prototype.execute=function(t,e){return this.genericRandomLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericRandomLayout(!0,t,e)},t.prototype.genericRandomLayout=function(t,e,n){var o=r(r({},this.options),n),i=o.center,s=o.width,a=o.height,u=o.layoutInvisibles,h=o.onLayoutEnd,l=e.getAllNodes();u||(l=l.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e})));var c=s||"undefined"==typeof window?s:window.innerWidth,f=a||"undefined"==typeof window?a:window.innerHeight,d=i||[c/2,f/2],g=[];l&&l.forEach((function(t){g.push({id:t.id,data:{x:.9*(Math.random()-.5)*c+d[0],y:.9*(Math.random()-.5)*f+d[1]}})})),t&&g.forEach((function(t){return e.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}));var p={nodes:g,edges:e.getAllEdges()};return null==h||h(p),p},t}(),grid:Pt,radial:be,force:kt,d3force:bt,fruchterman:Ct};function _e(){(null==de?void 0:de.stop)&&de.stop()}function ze(t,e){return r=this,n=void 0,i=function(){var r,n,o,i,a,u,h,l;return function(t,e){var r,n,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(u){return function(a){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(r=1,n&&(o=2&a[0]?n.return:a[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,a[1])).done)return o;switch(n=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,n=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],n=0}finally{r=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}}(this,(function(c){if(r=t.layout,n=r.id,o=r.options,i=r.iterations,a=t.nodes,u=t.edges,h=new s({nodes:a,edges:u}),!(l=Re[n]))throw new Error("Unknown layout id: ".concat(n));return de=new l(o),[2,new Promise((function(t){var r;de.assign(h,{onLayoutEnd:function(r){t([r,e])}}),(r=de).tick&&r.stop&&r.restart&&(de.stop(),de.tick(i))}))]}))},new((o=void 0)||(o=Promise))((function(t,e){function s(t){try{u(i.next(t))}catch(t){e(t)}}function a(t){try{u(i.throw(t))}catch(t){e(t)}}function u(e){var r;e.done?t(e.value):(r=e.value,r instanceof o?r:new o((function(t){t(r)}))).then(s,a)}u((i=i.apply(r,n||[])).next())}));var r,n,o,i}addEventListener("message",(function(t){var r,n=t.data,o=n.type,i=n.method,s=n.id,a=n.params;"RPC"===o&&i&&((r=e[i])?Promise.resolve().then((function(){return r.apply(e,a)})):Promise.reject("No such method")).then((function(t){postMessage({type:"RPC",id:s,result:t})})).catch((function(t){var e={message:t};t.stack&&(e.message=t.message,e.stack=t.stack,e.name=t.name),postMessage({type:"RPC",id:s,error:e})}))})),postMessage({type:"RPC",method:"ready"});\n//# sourceMappingURL=2a6b6d9f27a9b35490fa.worker.js.map']))),n(t,o),t}},475:t=>{t.exports=function(t,e){var r=0,n={};t.addEventListener("message",(function(e){var r=e.data;if("RPC"===r.type)if(r.id){var o=n[r.id];o&&(delete n[r.id],r.error?o[1](Object.assign(Error(r.error.message),r.error)):o[0](r.result))}else{var i=document.createEvent("Event");i.initEvent(r.method,!1,!1),i.data=r.params,t.dispatchEvent(i)}})),e.forEach((function(e){t[e]=function(){var o=arguments;return new Promise((function(i,s){var a=++r;n[a]=[i,s],t.postMessage({type:"RPC",id:a,method:e,params:[].slice.call(o)})}))}}))}}},e={};function r(n){var o=e[n];if(void 0!==o)return o.exports;var i=e[n]={exports:{}};return t[n](i,i.exports,r),i.exports}r.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return r.d(e,{a:e}),e},r.d=(t,e)=>{for(var n in e)r.o(e,n)&&!r.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},r.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);var n={};(()=>{r.d(n,{SB:()=>b,W1:()=>R,jA:()=>Dt,y7:()=>zt,O2:()=>Ft,Me:()=>Bt,AI:()=>be,D4:()=>De,_5:()=>Le,y9:()=>I,Xp:()=>D,qR:()=>qe,i_:()=>Pe});var t=function(e,r){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])},t(e,r)},e=function(){return e=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var o in e=arguments[r])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},e.apply(this,arguments)};function o(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(t);o<n.length;o++)e.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(t,n[o])&&(r[n[o]]=t[n[o]])}return r}function i(t,e){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var n,o,i=r.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(n=i.next()).done;)s.push(n.value)}catch(t){o={error:t}}finally{try{n&&!n.done&&(r=i.return)&&r.call(i)}finally{if(o)throw o.error}}return s}function s(t,e,r){if(r||2===arguments.length)for(var n,o=0,i=e.length;o<i;o++)!n&&o in e||(n||(n=Array.prototype.slice.call(e,0,o)),n[o]=e[o]);return t.concat(n||Array.prototype.slice.call(e))}Object.create,Object.create;var a=function(t){return"string"==typeof t},u=/-(\w)/g,h=(function(t){return t.replace(u,(function(t,e){return e?e.toUpperCase():""}))},Object.create(null),Array.isArray),l=function(t){return"number"==typeof t},c=function(t){for(var e=[],r=t.length,n=0;n<r;n+=1){e[n]=[];for(var o=0;o<r;o+=1)n===o?e[n][o]=0:0!==t[n][o]&&t[n][o]?e[n][o]=t[n][o]:e[n][o]=1/0}for(var i=0;i<r;i+=1)for(n=0;n<r;n+=1)for(o=0;o<r;o+=1)e[n][o]>e[n][i]+e[i][o]&&(e[n][o]=e[n][i]+e[i][o]);return e},f=function(t,e){var r=t.nodes,n=t.edges,o=[],i={};if(!r)throw new Error("invalid nodes data!");return r&&r.forEach((function(t,e){i[t.id]=e,o.push([])})),null==n||n.forEach((function(t){var r=t.source,n=t.target,s=i[r],a=i[n];void 0!==s&&void 0!==a&&(o[s][a]=1,e||(o[a][s]=1))})),o},d=function(t,e){return Math.sqrt((t.x-e.x)*(t.x-e.x)+(t.y-e.y)*(t.y-e.y))},g=function(t){return null!==t&&"object"==typeof t},p=function(t){if(null===t)return t;if(t instanceof Date)return new Date(t.getTime());if(t instanceof Array){var r=[];return t.forEach((function(t){r.push(t)})),r.map((function(t){return p(t)}))}if("object"==typeof t&&Object.keys(t).length){var n=e({},t);return Object.keys(n).forEach((function(t){n[t]=p(n[t])})),n}return t},m=function(t,e){var r=p(t);return r.data=r.data||{},e&&(l(r.data.x)||(r.data.x=Math.random()*e[0]),l(r.data.y)||(r.data.y=Math.random()*e[1])),r},y=function(t){return"function"==typeof t};function w(t,e){return y(e)?e:l(e)?function(){return e}:function(){return t}}function v(t,e,r){return void 0===r&&(r=!0),e||0===e?y(e)?e:l(e)?function(){return e}:h(e)?function(){if(r){var n=Math.max.apply(Math,s([],i(e),!1));return isNaN(n)?t:n}return e}:g(e)?function(){if(r){var n=Math.max(e.width,e.height);return isNaN(n)?t:n}return[e.width,e.height]}:function(){return t}:function(e){var r=(e.data||{}).size;return r?h(r)?r[0]>r[1]?r[0]:r[1]:g(r)?r.width>r.height?r.width:r.height:r:t}}var x={radius:null,startRadius:null,endRadius:null,startAngle:0,endAngle:2*Math.PI,clockwise:!0,divisions:1,ordering:null,angleRatio:1},b=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="circular",this.options=e(e({},x),t)}return t.prototype.execute=function(t,e){return this.genericCircularLayout(!1,t,e)},t.prototype.assign=function(t,e){var r=this;t.batch((function(){r.genericCircularLayout(!0,t,e)}))},t.prototype.genericCircularLayout=function(t,r,n){var o=e(e({},this.options),n),s=o.width,a=o.height,u=o.center,h=o.divisions,l=o.startAngle,c=void 0===l?0:l,f=o.endAngle,d=void 0===f?2*Math.PI:f,g=o.angleRatio,p=o.ordering,y=o.clockwise,x=o.nodeSpacing,b=o.nodeSize,N=o.layoutInvisibles,S=o.onLayoutEnd,k=r.getAllNodes(),A=r.getAllEdges();N||(k=k.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e})),A=A.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e})));var D=k.length;if(0===D)return null==S||S({nodes:[],edges:[]}),{nodes:[],edges:[]};var I=i(E(s,a,u),3),_=I[0],R=I[1],O=I[2];if(1===D){t&&r.mergeNodeData(k[0].id,{x:O[0],y:O[1]});var T={nodes:[e(e({},k[0]),{data:e(e({},k[0].data),{x:O[0],y:O[1]})})],edges:A};return null==S||S(T),T}var z=(d-c)/D,C=o.radius,L=o.startRadius,P=o.endRadius;if(x){var q=w(10,x),j=v(10,b),V=-1/0;k.forEach((function(t){var e=j(t);V<e&&(V=e)}));var F=0;k.forEach((function(t,e){F+=0===e?V||10:(q(t)||0)+(V||10)})),C=F/(2*Math.PI)}else C||L||P?!L&&P?L=P:L&&!P&&(P=L):C=Math.min(R,_)/2;var U=z*g,B=[];B="topology"===p?M(r,k):"topology-directed"===p?M(r,k,!0):"degree"===p?function(t,e){var r=[];return e.forEach((function(t,e){r.push(m(t))})),r.sort((function(e,r){return t.getDegree(e.id,"both")-t.getDegree(r.id,"both")})),r}(r,k):k.map((function(t){return m(t)}));for(var $=Math.ceil(D/h),G=0;G<D;++G){var H=C;H||null===L||null===P||(H=L+G*(P-L)/(D-1)),H||(H=10+100*G/(D-1));var J=c+G%$*U+2*Math.PI/h*Math.floor(G/$);y||(J=d-G%$*U-2*Math.PI/h*Math.floor(G/$)),B[G].data.x=O[0]+Math.cos(J)*H,B[G].data.y=O[1]+Math.sin(J)*H}t&&B.forEach((function(t){r.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}));var K={nodes:B,edges:A};return null==S||S(K),K},t}(),M=function(t,e,r){void 0===r&&(r=!1);var n=[m(e[0])],o={},i=e.length;o[e[0].id]=!0;var s=0;return e.forEach((function(a,u){if(0!==u)if(u!==i-1&&t.getDegree(a.id,"both")===t.getDegree(e[u+1].id,"both")&&!t.areNeighbors(n[s].id,a.id)||o[a.id]){for(var h=r?t.getSuccessors(n[s].id):t.getNeighbors(n[s].id),l=!1,c=0;c<h.length;c++){var f=h[c];if(t.getDegree(f.id)===t.getDegree(a.id)&&!o[f.id]){n.push(m(f)),o[f.id]=!0,l=!0;break}}for(var d=0;!l&&(o[e[d].id]||(n.push(m(e[d])),o[e[d].id]=!0,l=!0),++d!==i););}else n.push(m(a)),o[a.id]=!0,s++})),n},E=function(t,e,r){var n=t,o=e,i=r;return n||"undefined"==typeof window||(n=window.innerWidth),o||"undefined"==typeof window||(o=window.innerHeight),i||(i=[n/2,o/2]),[n,o,i]},N=r(161),S=r.n(N),k=r(825),A=r.n(k),D={LAYOUT_ITERATION:"tick",LAYOUT_END:"layoutend"},I=function(e){function r(t,r,n){var o=e.call(this)||this;return o.graph=t,o.layout=r,o.options=n,o.spawnWorker(),o}return function(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}(r,e),r.prototype.spawnWorker=function(){this.worker&&this.worker.terminate(),this.worker=A()(),this.running&&(this.running=!1,this.start())},r.prototype.start=function(){var t,e=this;if(this.running)return this;this.running=!0;var r=this.layout.options,n=(r.onLayoutEnd,r.onTick,o(r,["onLayoutEnd","onTick"])),s={layout:{id:this.layout.id,options:n,iterations:null===(t=this.options)||void 0===t?void 0:t.iterations},nodes:this.graph.getAllNodes(),edges:this.graph.getAllEdges()},a=new Float32Array([0]);return this.worker.calculateLayout(s,[a]).then((function(t){var r=i(t,2),n=r[0];r[1],e.emit(D.LAYOUT_END,n),e.layout.options.onLayoutEnd&&e.layout.options.onLayoutEnd(n)})),this},r.prototype.stop=function(){return this.running=!1,this.worker.stopLayout(),this},r.prototype.kill=function(){this.worker&&this.worker.terminate()},r.prototype.isRunning=function(){return this.running},r}(S()),_={nodeSize:30,minNodeSpacing:10,nodeSpacing:10,preventOverlap:!1,sweep:void 0,equidistant:!1,startAngle:1.5*Math.PI,clockwise:!0,maxLevelDiff:void 0,sortBy:"degree"},R=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="concentric",this.options=e(e({},_),t)}return t.prototype.execute=function(t,e){return this.genericConcentricLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericConcentricLayout(!0,t,e)},t.prototype.genericConcentricLayout=function(t,r,n){var o=e(e({},this.options),n),i=o.center,s=o.width,u=o.height,c=o.sortBy,f=o.maxLevelDiff,d=o.sweep,p=o.clockwise,w=o.equidistant,v=o.minNodeSpacing,x=void 0===v?10:v,b=o.preventOverlap,M=o.startAngle,E=void 0===M?1.5*Math.PI:M,N=o.nodeSize,S=o.nodeSpacing,k=o.layoutInvisibles,A=o.onLayoutEnd,D=r.getAllNodes(),I=r.getAllEdges();k||(D=D.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e})),I=I.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e})));var _=D.length;if(0===_){var R={nodes:[],edges:I};return null==A||A(R),R}var O=s||"undefined"==typeof window?s:window.innerWidth,T=u||"undefined"==typeof window?u:window.innerHeight,z=i||[O/2,T/2];if(1===_){t&&r.mergeNodeData(D[0].id,{x:z[0],y:z[1]});var C={nodes:[e(e({},D[0]),{data:e(e({},D[0].data),{x:z[0],y:z[1]})})],edges:I};return null==A||A(C),C}var L,P=[],q=0;L=h(N)?Math.max(N[0],N[1]):N,h(S)?q=Math.max(S[0],S[1]):l(S)&&(q=S),D.forEach((function(t){var e=m(t);P.push(e);var r=L,n=e.data;h(n.size)?r=Math.max(n.size[0],n.size[1]):l(n.size)?r=n.size:g(n.size)&&(r=Math.max(n.size.width,n.size.height)),L=Math.max(L,r),y(S)&&(q=Math.max(S(t),q))}));var j={};P.forEach((function(t,e){j[t.id]=e}));var V=c;a(V)&&void 0!==P[0].data[V]||(V="degree"),"degree"===V?P.sort((function(t,e){return r.getDegree(e.id,"both")-r.getDegree(t.id,"both")})):P.sort((function(t,e){return e.data[V]-t.data[V]}));var F=P[0],U=(f||("degree"===V?r.getDegree(F.id,"both"):F.data[V]))/4,B=[{nodes:[]}],$=B[0];P.forEach((function(t){if($.nodes.length>0){var e="degree"===V?Math.abs(r.getDegree($.nodes[0].id,"both")-r.getDegree(t.id,"both")):Math.abs($.nodes[0].data[V]-t.data[V]);U&&e>=U&&($={nodes:[]},B.push($))}$.nodes.push(t)}));var G=L+(q||x);if(!b){var H=B.length>0&&B[0].nodes.length>1,J=(Math.min(O,T)/2-G)/(B.length+(H?1:0));G=Math.min(G,J)}var K=0;if(B.forEach((function(t){var e=void 0===d?2*Math.PI-2*Math.PI/t.nodes.length:d;if(t.dTheta=e/Math.max(1,t.nodes.length-1),t.nodes.length>1&&b){var r=Math.cos(t.dTheta)-Math.cos(0),n=Math.sin(t.dTheta)-Math.sin(0),o=Math.sqrt(G*G/(r*r+n*n));K=Math.max(o,K)}t.r=K,K+=G})),w){for(var W=0,Y=0,Z=0;Z<B.length;Z++){var X=(B[Z].r||0)-Y;W=Math.max(W,X)}Y=0,B.forEach((function(t,e){0===e&&(Y=t.r||0),t.r=Y,Y+=W}))}B.forEach((function(t){var e=t.dTheta||0,r=t.r||0;t.nodes.forEach((function(t,n){var o=E+(p?1:-1)*e*n;t.data.x=z[0]+r*Math.cos(o),t.data.y=z[1]+r*Math.sin(o)}))})),t&&P.forEach((function(t){return r.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}));var Q={nodes:P,edges:I};return null==A||A(Q),Q},t}();function O(t,e,r,n){if(isNaN(e)||isNaN(r))return t;var o,i,s,a,u,h,l,c,f,d=t._root,g={data:n},p=t._x0,m=t._y0,y=t._x1,w=t._y1;if(!d)return t._root=g,t;for(;d.length;)if((h=e>=(i=(p+y)/2))?p=i:y=i,(l=r>=(s=(m+w)/2))?m=s:w=s,o=d,!(d=d[c=l<<1|h]))return o[c]=g,t;if(a=+t._x.call(null,d.data),u=+t._y.call(null,d.data),e===a&&r===u)return g.next=d,o?o[c]=g:t._root=g,t;do{o=o?o[c]=new Array(4):t._root=new Array(4),(h=e>=(i=(p+y)/2))?p=i:y=i,(l=r>=(s=(m+w)/2))?m=s:w=s}while((c=l<<1|h)==(f=(u>=s)<<1|a>=i));return o[f]=d,o[c]=g,t}function T(t,e,r,n,o){this.node=t,this.x0=e,this.y0=r,this.x1=n,this.y1=o}function z(t){return t[0]}function C(t){return t[1]}function L(t,e,r){var n=new P(null==e?z:e,null==r?C:r,NaN,NaN,NaN,NaN);return null==t?n:n.addAll(t)}function P(t,e,r,n,o,i){this._x=t,this._y=e,this._x0=r,this._y0=n,this._x1=o,this._y1=i,this._root=void 0}function q(t){for(var e={data:t.data},r=e;t=t.next;)r=r.next={data:t.data};return e}var j=L.prototype=P.prototype;function V(t){return function(){return t}}function F(t){return 1e-6*(t()-.5)}j.copy=function(){var t,e,r=new P(this._x,this._y,this._x0,this._y0,this._x1,this._y1),n=this._root;if(!n)return r;if(!n.length)return r._root=q(n),r;for(t=[{source:n,target:r._root=new Array(4)}];n=t.pop();)for(var o=0;o<4;++o)(e=n.source[o])&&(e.length?t.push({source:e,target:n.target[o]=new Array(4)}):n.target[o]=q(e));return r},j.add=function(t){const e=+this._x.call(null,t),r=+this._y.call(null,t);return O(this.cover(e,r),e,r,t)},j.addAll=function(t){var e,r,n,o,i=t.length,s=new Array(i),a=new Array(i),u=1/0,h=1/0,l=-1/0,c=-1/0;for(r=0;r<i;++r)isNaN(n=+this._x.call(null,e=t[r]))||isNaN(o=+this._y.call(null,e))||(s[r]=n,a[r]=o,n<u&&(u=n),n>l&&(l=n),o<h&&(h=o),o>c&&(c=o));if(u>l||h>c)return this;for(this.cover(u,h).cover(l,c),r=0;r<i;++r)O(this,s[r],a[r],t[r]);return this},j.cover=function(t,e){if(isNaN(t=+t)||isNaN(e=+e))return this;var r=this._x0,n=this._y0,o=this._x1,i=this._y1;if(isNaN(r))o=(r=Math.floor(t))+1,i=(n=Math.floor(e))+1;else{for(var s,a,u=o-r||1,h=this._root;r>t||t>=o||n>e||e>=i;)switch(a=(e<n)<<1|t<r,(s=new Array(4))[a]=h,h=s,u*=2,a){case 0:o=r+u,i=n+u;break;case 1:r=o-u,i=n+u;break;case 2:o=r+u,n=i-u;break;case 3:r=o-u,n=i-u}this._root&&this._root.length&&(this._root=h)}return this._x0=r,this._y0=n,this._x1=o,this._y1=i,this},j.data=function(){var t=[];return this.visit((function(e){if(!e.length)do{t.push(e.data)}while(e=e.next)})),t},j.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]]},j.find=function(t,e,r){var n,o,i,s,a,u,h,l=this._x0,c=this._y0,f=this._x1,d=this._y1,g=[],p=this._root;for(p&&g.push(new T(p,l,c,f,d)),null==r?r=1/0:(l=t-r,c=e-r,f=t+r,d=e+r,r*=r);u=g.pop();)if(!(!(p=u.node)||(o=u.x0)>f||(i=u.y0)>d||(s=u.x1)<l||(a=u.y1)<c))if(p.length){var m=(o+s)/2,y=(i+a)/2;g.push(new T(p[3],m,y,s,a),new T(p[2],o,y,m,a),new T(p[1],m,i,s,y),new T(p[0],o,i,m,y)),(h=(e>=y)<<1|t>=m)&&(u=g[g.length-1],g[g.length-1]=g[g.length-1-h],g[g.length-1-h]=u)}else{var w=t-+this._x.call(null,p.data),v=e-+this._y.call(null,p.data),x=w*w+v*v;if(x<r){var b=Math.sqrt(r=x);l=t-b,c=e-b,f=t+b,d=e+b,n=p.data}}return n},j.remove=function(t){if(isNaN(i=+this._x.call(null,t))||isNaN(s=+this._y.call(null,t)))return this;var e,r,n,o,i,s,a,u,h,l,c,f,d=this._root,g=this._x0,p=this._y0,m=this._x1,y=this._y1;if(!d)return this;if(d.length)for(;;){if((h=i>=(a=(g+m)/2))?g=a:m=a,(l=s>=(u=(p+y)/2))?p=u:y=u,e=d,!(d=d[c=l<<1|h]))return this;if(!d.length)break;(e[c+1&3]||e[c+2&3]||e[c+3&3])&&(r=e,f=c)}for(;d.data!==t;)if(n=d,!(d=d.next))return this;return(o=d.next)&&delete d.next,n?(o?n.next=o:delete n.next,this):e?(o?e[c]=o:delete e[c],(d=e[0]||e[1]||e[2]||e[3])&&d===(e[3]||e[2]||e[1]||e[0])&&!d.length&&(r?r[f]=d:this._root=d),this):(this._root=o,this)},j.removeAll=function(t){for(var e=0,r=t.length;e<r;++e)this.remove(t[e]);return this},j.root=function(){return this._root},j.size=function(){var t=0;return this.visit((function(e){if(!e.length)do{++t}while(e=e.next)})),t},j.visit=function(t){var e,r,n,o,i,s,a=[],u=this._root;for(u&&a.push(new T(u,this._x0,this._y0,this._x1,this._y1));e=a.pop();)if(!t(u=e.node,n=e.x0,o=e.y0,i=e.x1,s=e.y1)&&u.length){var h=(n+i)/2,l=(o+s)/2;(r=u[3])&&a.push(new T(r,h,l,i,s)),(r=u[2])&&a.push(new T(r,n,l,h,s)),(r=u[1])&&a.push(new T(r,h,o,i,l)),(r=u[0])&&a.push(new T(r,n,o,h,l))}return this},j.visitAfter=function(t){var e,r=[],n=[];for(this._root&&r.push(new T(this._root,this._x0,this._y0,this._x1,this._y1));e=r.pop();){var o=e.node;if(o.length){var i,s=e.x0,a=e.y0,u=e.x1,h=e.y1,l=(s+u)/2,c=(a+h)/2;(i=o[0])&&r.push(new T(i,s,a,l,c)),(i=o[1])&&r.push(new T(i,l,a,u,c)),(i=o[2])&&r.push(new T(i,s,c,l,h)),(i=o[3])&&r.push(new T(i,l,c,u,h))}n.push(e)}for(;e=n.pop();)t(e.node,e.x0,e.y0,e.x1,e.y1);return this},j.x=function(t){return arguments.length?(this._x=t,this):this._x},j.y=function(t){return arguments.length?(this._y=t,this):this._y};var U={value:()=>{}};function B(){for(var t,e=0,r=arguments.length,n={};e<r;++e){if(!(t=arguments[e]+"")||t in n||/[\s.]/.test(t))throw new Error("illegal type: "+t);n[t]=[]}return new $(n)}function $(t){this._=t}function G(t,e){return t.trim().split(/^|\s+/).map((function(t){var r="",n=t.indexOf(".");if(n>=0&&(r=t.slice(n+1),t=t.slice(0,n)),t&&!e.hasOwnProperty(t))throw new Error("unknown type: "+t);return{type:t,name:r}}))}function H(t,e){for(var r,n=0,o=t.length;n<o;++n)if((r=t[n]).name===e)return r.value}function J(t,e,r){for(var n=0,o=t.length;n<o;++n)if(t[n].name===e){t[n]=U,t=t.slice(0,n).concat(t.slice(n+1));break}return null!=r&&t.push({name:e,value:r}),t}$.prototype=B.prototype={constructor:$,on:function(t,e){var r,n=this._,o=G(t+"",n),i=-1,s=o.length;if(!(arguments.length<2)){if(null!=e&&"function"!=typeof e)throw new Error("invalid callback: "+e);for(;++i<s;)if(r=(t=o[i]).type)n[r]=J(n[r],t.name,e);else if(null==e)for(r in n)n[r]=J(n[r],t.name,null);return this}for(;++i<s;)if((r=(t=o[i]).type)&&(r=H(n[r],t.name)))return r},copy:function(){var t={},e=this._;for(var r in e)t[r]=e[r].slice();return new $(t)},call:function(t,e){if((r=arguments.length-2)>0)for(var r,n,o=new Array(r),i=0;i<r;++i)o[i]=arguments[i+2];if(!this._.hasOwnProperty(t))throw new Error("unknown type: "+t);for(i=0,r=(n=this._[t]).length;i<r;++i)n[i].value.apply(e,o)},apply:function(t,e,r){if(!this._.hasOwnProperty(t))throw new Error("unknown type: "+t);for(var n=this._[t],o=0,i=n.length;o<i;++o)n[o].value.apply(e,r)}};const K=B;var W,Y,Z=0,X=0,Q=0,tt=0,et=0,rt=0,nt="object"==typeof performance&&performance.now?performance:Date,ot="object"==typeof window&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(t){setTimeout(t,17)};function it(){return et||(ot(st),et=nt.now()+rt)}function st(){et=0}function at(){this._call=this._time=this._next=null}function ut(t,e,r){var n=new at;return n.restart(t,e,r),n}function ht(){et=(tt=nt.now())+rt,Z=X=0;try{!function(){it(),++Z;for(var t,e=W;e;)(t=et-e._time)>=0&&e._call.call(void 0,t),e=e._next;--Z}()}finally{Z=0,function(){for(var t,e,r=W,n=1/0;r;)r._call?(n>r._time&&(n=r._time),t=r,r=r._next):(e=r._next,r._next=null,r=t?t._next=e:W=e);Y=t,ct(n)}(),et=0}}function lt(){var t=nt.now(),e=t-tt;e>1e3&&(rt-=e,tt=t)}function ct(t){Z||(X&&(X=clearTimeout(X)),t-et>24?(t<1/0&&(X=setTimeout(ht,t-nt.now()-rt)),Q&&(Q=clearInterval(Q))):(Q||(tt=nt.now(),Q=setInterval(lt,1e3)),Z=1,ot(ht)))}at.prototype=ut.prototype={constructor:at,restart:function(t,e,r){if("function"!=typeof t)throw new TypeError("callback is not a function");r=(null==r?it():+r)+(null==e?0:+e),this._next||Y===this||(Y?Y._next=this:W=this,Y=this),this._call=t,this._time=r,ct()},stop:function(){this._call&&(this._call=null,this._time=1/0,ct())}};const ft=4294967296;function dt(t){return t.x}function gt(t){return t.y}var pt=Math.PI*(3-Math.sqrt(5));function mt(t){var e,r=1,n=.001,o=1-Math.pow(n,1/300),i=0,s=.6,a=new Map,u=ut(c),h=K("tick","end"),l=function(){let t=1;return()=>(t=(1664525*t+1013904223)%ft)/ft}();function c(){f(),h.call("tick",e),r<n&&(u.stop(),h.call("end",e))}function f(n){var u,h,l=t.length;void 0===n&&(n=1);for(var c=0;c<n;++c)for(r+=(i-r)*o,a.forEach((function(t){t(r)})),u=0;u<l;++u)null==(h=t[u]).fx?h.x+=h.vx*=s:(h.x=h.fx,h.vx=0),null==h.fy?h.y+=h.vy*=s:(h.y=h.fy,h.vy=0);return e}function d(){for(var e,r=0,n=t.length;r<n;++r){if((e=t[r]).index=r,null!=e.fx&&(e.x=e.fx),null!=e.fy&&(e.y=e.fy),isNaN(e.x)||isNaN(e.y)){var o=10*Math.sqrt(.5+r),i=r*pt;e.x=o*Math.cos(i),e.y=o*Math.sin(i)}(isNaN(e.vx)||isNaN(e.vy))&&(e.vx=e.vy=0)}}function g(e){return e.initialize&&e.initialize(t,l),e}return null==t&&(t=[]),d(),e={tick:f,restart:function(){return u.restart(c),e},stop:function(){return u.stop(),e},nodes:function(r){return arguments.length?(t=r,d(),a.forEach(g),e):t},alpha:function(t){return arguments.length?(r=+t,e):r},alphaMin:function(t){return arguments.length?(n=+t,e):n},alphaDecay:function(t){return arguments.length?(o=+t,e):+o},alphaTarget:function(t){return arguments.length?(i=+t,e):i},velocityDecay:function(t){return arguments.length?(s=1-t,e):1-s},randomSource:function(t){return arguments.length?(l=t,a.forEach(g),e):l},force:function(t,r){return arguments.length>1?(null==r?a.delete(t):a.set(t,g(r)),e):a.get(t)},find:function(e,r,n){var o,i,s,a,u,h=0,l=t.length;for(null==n?n=1/0:n*=n,h=0;h<l;++h)(s=(o=e-(a=t[h]).x)*o+(i=r-a.y)*i)<n&&(u=a,n=s);return u},on:function(t,r){return arguments.length>1?(h.on(t,r),e):h.on(t)}}}function yt(){var t,e,r,n,o,i=V(-30),s=1,a=1/0,u=.81;function h(r){var o,i=t.length,s=L(t,dt,gt).visitAfter(c);for(n=r,o=0;o<i;++o)e=t[o],s.visit(f)}function l(){if(t){var e,r,n=t.length;for(o=new Array(n),e=0;e<n;++e)r=t[e],o[r.index]=+i(r,e,t)}}function c(t){var e,r,n,i,s,a=0,u=0;if(t.length){for(n=i=s=0;s<4;++s)(e=t[s])&&(r=Math.abs(e.value))&&(a+=e.value,u+=r,n+=r*e.x,i+=r*e.y);t.x=n/u,t.y=i/u}else{(e=t).x=e.data.x,e.y=e.data.y;do{a+=o[e.data.index]}while(e=e.next)}t.value=a}function f(t,i,h,l){if(!t.value)return!0;var c=t.x-e.x,f=t.y-e.y,d=l-i,g=c*c+f*f;if(d*d/u<g)return g<a&&(0===c&&(g+=(c=F(r))*c),0===f&&(g+=(f=F(r))*f),g<s&&(g=Math.sqrt(s*g)),e.vx+=c*t.value*n/g,e.vy+=f*t.value*n/g),!0;if(!(t.length||g>=a)){(t.data!==e||t.next)&&(0===c&&(g+=(c=F(r))*c),0===f&&(g+=(f=F(r))*f),g<s&&(g=Math.sqrt(s*g)));do{t.data!==e&&(d=o[t.data.index]*n/g,e.vx+=c*d,e.vy+=f*d)}while(t=t.next)}}return h.initialize=function(e,n){t=e,r=n,l()},h.strength=function(t){return arguments.length?(i="function"==typeof t?t:V(+t),l(),h):i},h.distanceMin=function(t){return arguments.length?(s=t*t,h):Math.sqrt(s)},h.distanceMax=function(t){return arguments.length?(a=t*t,h):Math.sqrt(a)},h.theta=function(t){return arguments.length?(u=t*t,h):Math.sqrt(u)},h}function wt(t){return t.index}function vt(t,e){var r=t.get(e);if(!r)throw new Error("node not found: "+e);return r}function xt(t){var e,r,n,o,i,s,a=wt,u=function(t){return 1/Math.min(o[t.source.index],o[t.target.index])},h=V(30),l=1;function c(n){for(var o=0,a=t.length;o<l;++o)for(var u,h,c,f,d,g,p,m=0;m<a;++m)h=(u=t[m]).source,f=(c=u.target).x+c.vx-h.x-h.vx||F(s),d=c.y+c.vy-h.y-h.vy||F(s),f*=g=((g=Math.sqrt(f*f+d*d))-r[m])/g*n*e[m],d*=g,c.vx-=f*(p=i[m]),c.vy-=d*p,h.vx+=f*(p=1-p),h.vy+=d*p}function f(){if(n){var s,u,h=n.length,l=t.length,c=new Map(n.map(((t,e)=>[a(t,e,n),t])));for(s=0,o=new Array(h);s<l;++s)(u=t[s]).index=s,"object"!=typeof u.source&&(u.source=vt(c,u.source)),"object"!=typeof u.target&&(u.target=vt(c,u.target)),o[u.source.index]=(o[u.source.index]||0)+1,o[u.target.index]=(o[u.target.index]||0)+1;for(s=0,i=new Array(l);s<l;++s)u=t[s],i[s]=o[u.source.index]/(o[u.source.index]+o[u.target.index]);e=new Array(l),d(),r=new Array(l),g()}}function d(){if(n)for(var r=0,o=t.length;r<o;++r)e[r]=+u(t[r],r,t)}function g(){if(n)for(var e=0,o=t.length;e<o;++e)r[e]=+h(t[e],e,t)}return null==t&&(t=[]),c.initialize=function(t,e){n=t,s=e,f()},c.links=function(e){return arguments.length?(t=e,f(),c):t},c.id=function(t){return arguments.length?(a=t,c):a},c.iterations=function(t){return arguments.length?(l=+t,c):l},c.strength=function(t){return arguments.length?(u="function"==typeof t?t:V(+t),d(),c):u},c.distance=function(t){return arguments.length?(h="function"==typeof t?t:V(+t),g(),c):h},c}function bt(t){return t.x+t.vx}function Mt(t){return t.y+t.vy}function Et(t){var e,r,n,o=1,i=1;function s(){for(var t,s,u,h,l,c,f,d=e.length,g=0;g<i;++g)for(s=L(e,bt,Mt).visitAfter(a),t=0;t<d;++t)u=e[t],c=r[u.index],f=c*c,h=u.x+u.vx,l=u.y+u.vy,s.visit(p);function p(t,e,r,i,s){var a=t.data,d=t.r,g=c+d;if(!a)return e>h+g||i<h-g||r>l+g||s<l-g;if(a.index>u.index){var p=h-a.x-a.vx,m=l-a.y-a.vy,y=p*p+m*m;y<g*g&&(0===p&&(y+=(p=F(n))*p),0===m&&(y+=(m=F(n))*m),y=(g-(y=Math.sqrt(y)))/y*o,u.vx+=(p*=y)*(g=(d*=d)/(f+d)),u.vy+=(m*=y)*g,a.vx-=p*(g=1-g),a.vy-=m*g)}}}function a(t){if(t.data)return t.r=r[t.data.index];for(var e=t.r=0;e<4;++e)t[e]&&t[e].r>t.r&&(t.r=t[e].r)}function u(){if(e){var n,o,i=e.length;for(r=new Array(i),n=0;n<i;++n)o=e[n],r[o.index]=+t(o,n,e)}}return"function"!=typeof t&&(t=V(null==t?1:+t)),s.initialize=function(t,r){e=t,n=r,u()},s.iterations=function(t){return arguments.length?(i=+t,s):i},s.strength=function(t){return arguments.length?(o=+t,s):o},s.radius=function(e){return arguments.length?(t="function"==typeof e?e:V(+e),u(),s):t},s}function Nt(t){var e,r,n,o=V(.1);function i(t){for(var o,i=0,s=e.length;i<s;++i)(o=e[i]).vx+=(n[i]-o.x)*r[i]*t}function s(){if(e){var i,s=e.length;for(r=new Array(s),n=new Array(s),i=0;i<s;++i)r[i]=isNaN(n[i]=+t(e[i],i,e))?0:+o(e[i],i,e)}}return"function"!=typeof t&&(t=V(null==t?0:+t)),i.initialize=function(t){e=t,s()},i.strength=function(t){return arguments.length?(o="function"==typeof t?t:V(+t),s(),i):o},i.x=function(e){return arguments.length?(t="function"==typeof e?e:V(+e),s(),i):t},i}function St(t){var e,r,n,o=V(.1);function i(t){for(var o,i=0,s=e.length;i<s;++i)(o=e[i]).vy+=(n[i]-o.y)*r[i]*t}function s(){if(e){var i,s=e.length;for(r=new Array(s),n=new Array(s),i=0;i<s;++i)r[i]=isNaN(n[i]=+t(e[i],i,e))?0:+o(e[i],i,e)}}return"function"!=typeof t&&(t=V(null==t?0:+t)),i.initialize=function(t){e=t,s()},i.strength=function(t){return arguments.length?(o="function"==typeof t?t:V(+t),s(),i):o},i.y=function(e){return arguments.length?(t="function"==typeof e?e:V(+e),s(),i):t},i}function kt(){function t(t){return function(){return t}}var e,r=function(t){return t.cluster},n=t(1),o=t(-1),s=t(100),a=t(.1),u=[0,0],h=[],l={},c=[],f=100,d=100,g={none:{x:0,y:0}},p=[],m="force",y=!0,w=.1;function v(t){if(!y)return v;e.tick(),b();for(var n=0,o=h.length,i=void 0,s=t*w;n<o;++n)(i=h[n]).vx+=(g[r(i)].x-i.x)*s,i.vy+=(g[r(i)].y-i.y)*s}function x(){h&&function(){if(h&&h.length){if(void 0===r(h[0]))throw Error("Couldnt find the grouping attribute for the nodes. Make sure to set it up with forceInBox.groupBy('clusterAttr') before calling .links()");var t,u,g,m,y,w=(t=[],u=[],g={},{},y=[],m=function(t){var e={};return t.forEach((function(t){var n=r(t);e[n]||(e[n]={count:0,sumforceNodeSize:0})})),t.forEach((function(t){var o=r(t),i=n(t),s=e[o];s.count=s.count+1,s.sumforceNodeSize=s.sumforceNodeSize+Math.PI*(i*i)*1.3,e[o]=s})),e}(h),y=function(t){var e={},n=[];return t.forEach((function(t){var n,o,i,s,a,u=(o=(n=t).source,i=n.target,(s=r(l[o]))<=(a=r(l[i]))?"".concat(s,"~").concat(a):"".concat(a,"~").concat(s)),h=0;void 0!==e[u]&&(h=e[u]),h+=1,e[u]=h})),Object.entries(e).forEach((function(t){var e=i(t,2),r=e[0],o=e[1],s=r.split("~")[0],a=r.split("~")[1];void 0!==s&&void 0!==a&&n.push({source:s,target:a,count:o})})),n}(c),Object.keys(m).forEach((function(e,r){var n=m[e];t.push({id:e,size:n.count,r:Math.sqrt(n.sumforceNodeSize/Math.PI)}),g[e]=r})),y.forEach((function(t){var e=t.source,r=t.target,n=g[e],o=g[r];void 0!==n&&void 0!==o&&u.push({source:n,target:o,count:t.count})})),{nodes:t,links:u});e=mt(w.nodes).force("x",Nt(f).strength(.1)).force("y",St(d).strength(.1)).force("collide",Et((function(t){return t.r})).iterations(4)).force("charge",yt().strength(o)).force("links",xt(w.nodes.length?w.links:[]).distance(s).strength(a)),p=e.nodes(),b()}}()}function b(){return g={none:{x:0,y:0}},p.forEach((function(t){g[t.id]={x:t.x-u[0],y:t.y-u[1]}})),g}function M(t){l={},t.forEach((function(t){l[t.id]=t}))}return v.initialize=function(t){h=t,x()},v.template=function(t){return arguments.length?(m=t,x(),v):m},v.groupBy=function(t){return arguments.length?"string"==typeof t?(r=function(e){return e[t]},v):(r=t,v):r},v.enableGrouping=function(t){return arguments.length?(y=t,v):y},v.strength=function(t){return arguments.length?(w=t,v):w},v.centerX=function(t){return arguments.length?(f=t,v):f},v.centerY=function(t){return arguments.length?(d=t,v):d},v.nodes=function(t){return arguments.length?(M(t||[]),h=t||[],v):h},v.links=function(t){return arguments.length?(c=t||[],x(),v):c},v.forceNodeSize=function(e){return arguments.length?(n="function"==typeof e?e:t(+e),x(),v):n},v.nodeSize=v.forceNodeSize,v.forceCharge=function(e){return arguments.length?(o="function"==typeof e?e:t(+e),x(),v):o},v.forceLinkDistance=function(e){return arguments.length?(s="function"==typeof e?e:t(+e),x(),v):s},v.forceLinkStrength=function(e){return arguments.length?(a="function"==typeof e?e:t(+e),x(),v):a},v.offset=function(t){return arguments.length?(u=t,v):u},v.getFocis=b,v}var At={center:[0,0],preventOverlap:!1,nodeSize:void 0,nodeSpacing:void 0,linkDistance:50,forceSimulation:null,alphaDecay:.028,alphaMin:.001,alpha:.3,collideStrength:1,clustering:!1,clusterNodeStrength:-1,clusterEdgeStrength:.1,clusterEdgeDistance:100,clusterFociStrength:.8,clusterNodeSize:10},Dt=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="d3force",this.running=!1,this.options=e(e({},At),t)}return t.prototype.execute=function(t,e){return this.genericForceLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericForceLayout(!0,t,e)},t.prototype.stop=function(){var t;null===(t=this.forceSimulation)||void 0===t||t.stop(),this.running=!1},t.prototype.restart=function(){var t;null===(t=this.forceSimulation)||void 0===t||t.restart(),this.running=!0},t.prototype.tick=function(t){var e=this;void 0===t&&(t=1),this.forceSimulation.tick(t);var r={nodes:It(this.lastLayoutNodes),edges:_t(this.lastLayoutEdges)};return this.lastAssign&&r.nodes.forEach((function(t){return e.lastGraph.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})})),this.lastOptions.onLayoutEnd&&this.lastOptions.onLayoutEnd(r),r},t.prototype.genericForceLayout=function(t,r,n){var o=this,i=e(e({},this.options),n),s=i.layoutInvisibles,a=r.getAllNodes(),u=r.getAllEdges();s||(a=a.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e})),u=u.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e})));var h=a.map((function(t){var r,n;return e(e({},m(t)),{x:null===(r=t.data)||void 0===r?void 0:r.x,y:null===(n=t.data)||void 0===n?void 0:n.y})})),l=u.map((function(t){return m(t)}));if(this.lastLayoutNodes=h,this.lastLayoutEdges=l,this.lastAssign=t,this.lastGraph=r,this.lastOptions=i,!this.running){var c=i.alphaMin,f=i.alphaDecay,d=i.alpha,g=i.nodeStrength,p=i.edgeStrength,y=i.linkDistance,w=i.clustering,v=i.clusterFociStrength,x=i.clusterEdgeDistance,b=i.clusterEdgeStrength,M=i.clusterNodeStrength,E=i.clusterNodeSize,N=i.collideStrength,S=void 0===N?1:N,k=i.center,A=void 0===k?[0,0]:k,D=i.preventOverlap,I=i.nodeSize,_=i.nodeSpacing,R=i.onTick,O=i.onLayoutEnd,T=i.forceSimulation;if(T)w&&((z=kt()).nodes(h),z.links(l)),T.nodes(h),l&&(L=xt().id((function(t){return t.id})).links(l),p&&L.strength(p),y&&L.distance(y),T.force("link",L)),D&&this.overlapProcess(T,{nodeSize:I,nodeSpacing:_,collideStrength:S}),T.alpha(d).restart(),this.running=!0;else try{var z,C=yt();if(g&&C.strength(g),T=mt().nodes(h),w&&((z=kt()).centerX(A[0]).centerY(A[1]).template("force").strength(v),l&&z.links(l),h&&z.nodes(h),z.forceLinkDistance(x).forceLinkStrength(b).forceCharge(M).forceNodeSize(E),T.force("group",z)),T.force("center",function(t,e){var r,n=1;function o(){var o,i,s=r.length,a=0,u=0;for(o=0;o<s;++o)a+=(i=r[o]).x,u+=i.y;for(a=(a/s-t)*n,u=(u/s-e)*n,o=0;o<s;++o)(i=r[o]).x-=a,i.y-=u}return null==t&&(t=0),null==e&&(e=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.strength=function(t){return arguments.length?(n=+t,o):n},o}(A[0],A[1])).force("charge",C).alpha(d).alphaDecay(f).alphaMin(c),D&&this.overlapProcess(T,{nodeSize:I,nodeSpacing:_,collideStrength:S}),l){var L=xt().id((function(t){return t.id})).links(l);p&&L.strength(p),y&&L.distance(y),T.force("link",L)}T.on("tick",(function(){var e=It(h);null==R||R({nodes:e,edges:_t(l)}),t&&e.forEach((function(t){return r.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}))})).on("end",(function(){o.running=!1;var e=It(h);null==O||O({nodes:e,edges:_t(l)}),t&&e.forEach((function(t){return r.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}))})),this.running=!0}catch(t){this.running=!1,console.warn(t)}this.forceSimulation=T;var P=It(h),q=_t(l);return t&&P.forEach((function(t){return r.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})})),{nodes:P,edges:q}}},t.prototype.overlapProcess=function(t,e){var r,n,o=e.nodeSize,i=e.nodeSpacing,s=e.collideStrength;if(n=l(i)?function(){return i}:y(i)?i:function(){return 0},o)if(y(o))r=function(t){return o(t)+n(t)};else if(h(o)){var a=(o[0]>o[1]?o[0]:o[1])/2;r=function(t){return a+n(t)}}else if(l(o)){var u=o/2;r=function(t){return u+n(t)}}else r=function(){return 10};else r=function(t){return t.size?h(t.size)?(t.size[0]>t.size[1]?t.size[0]:t.size[1])/2+n(t):g(t.size)?(t.size.width>t.size.height?t.size.width:t.size.height)/2+n(t):t.size/2+n(t):10+n(t)};t.force("collisionForce",Et(r).strength(s))},t}(),It=function(t){return t.map((function(t){var r=t.x,n=t.y,i=o(t,["x","y"]);return e(e({},i),{data:e(e({},i.data),{x:r,y:n})})}))},_t=function(t){return t.map((function(t){var r=t.source,n=t.target,i=o(t,["source","target"]);return e(e({},i),{source:r.id,target:n.id})}))};class Rt{nodeMap=new Map;edgeMap=new Map;inEdgesMap=new Map;outEdgesMap=new Map;treeIndices=new Map;changes=[];batchCount=0;onChanged=()=>{};constructor(t){t&&(t.nodes&&this.addNodes(t.nodes),t.edges&&this.addEdges(t.edges),t.tree&&this.addTree(t.tree),t.onChanged&&(this.onChanged=t.onChanged))}batch=t=>{this.batchCount+=1,t(),this.batchCount-=1,this.batchCount||this.commit()};commit(){const t=this.changes;this.changes=[],this.onChanged({graph:this,changes:t})}reduceChanges(t){let e=[];return t.forEach((t=>{switch(t.type){case"NodeRemoved":{let r=!1;e=e.filter((e=>{if("NodeAdded"===e.type){const n=e.value.id===t.value.id;return n&&(r=!0),!n}return"NodeDataUpdated"===e.type?e.id!==t.value.id:"TreeStructureChanged"!==e.type||e.nodeId!==t.value.id})),r||e.push(t);break}case"EdgeRemoved":{let r=!1;e=e.filter((e=>{if("EdgeAdded"===e.type){const n=e.value.id===t.value.id;return n&&(r=!0),!n}return"EdgeDataUpdated"!==e.type&&"EdgeUpdated"!==e.type||e.id!==t.value.id})),r||e.push(t);break}case"NodeDataUpdated":case"EdgeDataUpdated":case"EdgeUpdated":{const r=e.find((e=>e.type===t.type&&e.id===t.id&&e.propertyName===t.propertyName));r?r.newValue=t.newValue:e.push(t);break}case"TreeStructureDetached":e=e.filter((e=>"TreeStructureAttached"===e.type?e.treeKey!==t.treeKey:"TreeStructureChanged"!==e.type||e.treeKey!==t.treeKey)),e.push(t);break;case"TreeStructureChanged":{const r=e.find((e=>"TreeStructureChanged"===e.type&&e.treeKey===t.treeKey&&e.nodeId===t.nodeId));r?r.newParentId=t.newParentId:e.push(t);break}default:e.push(t)}})),e}checkNodeExistence(t){if(!this.hasNode(t))throw new Error("Node not found for id: "+t)}hasNode(t){return this.nodeMap.has(t)}areNeighbors(t,e){return this.checkNodeExistence(t),this.getNeighbors(e).some((e=>e.id===t))}getNode(t){return this.checkNodeExistence(t),this.nodeMap.get(t)}getRelatedEdges(t,e){this.checkNodeExistence(t);const r=this.inEdgesMap.get(t),n=this.outEdgesMap.get(t);if("in"===e)return Array.from(r);if("out"===e)return Array.from(n);const o=new Set([...r,...n]);return Array.from(o)}getDegree(t,e){return this.getRelatedEdges(t,e).length}getSuccessors(t){const e=this.getRelatedEdges(t,"out").map((t=>t.target));return Array.from(new Set(e)).map((t=>this.getNode(t)))}getPredecessors(t){const e=this.getRelatedEdges(t,"in").map((t=>t.source));return Array.from(new Set(e)).map((t=>this.getNode(t)))}getNeighbors(t){const e=this.getPredecessors(t),r=this.getSuccessors(t);return Array.from(new Set([...e,...r]))}doAddNode(t){if(this.hasNode(t.id))throw new Error("Node already exists: "+t.id);this.nodeMap.set(t.id,t),this.inEdgesMap.set(t.id,new Set),this.outEdgesMap.set(t.id,new Set),this.treeIndices.forEach((e=>{e.childrenMap.set(t.id,new Set)})),this.changes.push({type:"NodeAdded",value:t})}addNodes(t){this.batch((()=>{for(const e of t)this.doAddNode(e)}))}addNode(t){this.addNodes([t])}doRemoveNode(t){const e=this.getNode(t),r=this.inEdgesMap.get(t),n=this.outEdgesMap.get(t);r?.forEach((t=>this.doRemoveEdge(t.id))),n?.forEach((t=>this.doRemoveEdge(t.id))),this.nodeMap.delete(t),this.treeIndices.forEach((e=>{e.childrenMap.get(t)?.forEach((t=>{e.parentMap.delete(t.id)})),e.parentMap.delete(t),e.childrenMap.delete(t)})),this.changes.push({type:"NodeRemoved",value:e})}removeNodes(t){this.batch((()=>{t.forEach((t=>this.doRemoveNode(t)))}))}removeNode(t){this.removeNodes([t])}updateNodeDataProperty(t,e,r){const n=this.getNode(t);this.batch((()=>{const o=n.data[e],i=r;n.data[e]=i,this.changes.push({type:"NodeDataUpdated",id:t,propertyName:e,oldValue:o,newValue:i})}))}mergeNodeData(t,e){this.batch((()=>{Object.entries(e).forEach((([e,r])=>{this.updateNodeDataProperty(t,e,r)}))}))}updateNodeData(...t){const e=t[0],r=this.getNode(e);if("string"==typeof t[1])return void this.updateNodeDataProperty(e,t[1],t[2]);let n;if("function"==typeof t[1]){const e=t[1];n=e(r.data)}else"object"==typeof t[1]&&(n=t[1]);this.batch((()=>{const t=r.data,o=n;r.data=n,this.changes.push({type:"NodeDataUpdated",id:e,oldValue:t,newValue:o})}))}checkEdgeExistence(t){if(!this.hasEdge(t))throw new Error("Edge not found for id: "+t)}hasEdge(t){return this.edgeMap.has(t)}getEdge(t){return this.checkEdgeExistence(t),this.edgeMap.get(t)}getEdgeDetail(t){const e=this.getEdge(t);return{edge:e,source:this.getNode(e.source),target:this.getNode(e.target)}}doAddEdge(t){if(this.hasEdge(t.id))throw new Error("Edge already exists: "+t.id);this.checkNodeExistence(t.source),this.checkNodeExistence(t.target),this.edgeMap.set(t.id,t);const e=this.inEdgesMap.get(t.target),r=this.outEdgesMap.get(t.source);e.add(t),r.add(t),this.changes.push({type:"EdgeAdded",value:t})}addEdges(t){this.batch((()=>{for(const e of t)this.doAddEdge(e)}))}addEdge(t){this.addEdges([t])}doRemoveEdge(t){const e=this.getEdge(t),r=this.outEdgesMap.get(e.source),n=this.inEdgesMap.get(e.target);r.delete(e),n.delete(e),this.edgeMap.delete(t),this.changes.push({type:"EdgeRemoved",value:e})}removeEdges(t){this.batch((()=>{t.forEach((t=>this.doRemoveEdge(t)))}))}removeEdge(t){this.removeEdges([t])}updateEdgeSource(t,e){const r=this.getEdge(t);this.checkNodeExistence(e);const n=r.source,o=e;this.outEdgesMap.get(n).delete(r),this.outEdgesMap.get(o).add(r),r.source=e,this.batch((()=>{this.changes.push({type:"EdgeUpdated",id:t,propertyName:"source",oldValue:n,newValue:o})}))}updateEdgeTarget(t,e){const r=this.getEdge(t);this.checkNodeExistence(e);const n=r.target,o=e;this.inEdgesMap.get(n).delete(r),this.inEdgesMap.get(o).add(r),r.target=e,this.batch((()=>{this.changes.push({type:"EdgeUpdated",id:t,propertyName:"target",oldValue:n,newValue:o})}))}updateEdgeDataProperty(t,e,r){const n=this.getEdge(t);this.batch((()=>{const o=n.data[e],i=r;n.data[e]=i,this.changes.push({type:"EdgeDataUpdated",id:t,propertyName:e,oldValue:o,newValue:i})}))}updateEdgeData(...t){const e=t[0],r=this.getEdge(e);if("string"==typeof t[1])return void this.updateEdgeDataProperty(e,t[1],t[2]);let n;if("function"==typeof t[1]){const e=t[1];n=e(r.data)}else"object"==typeof t[1]&&(n=t[1]);this.batch((()=>{const t=r.data,o=n;r.data=n,this.changes.push({type:"EdgeDataUpdated",id:e,oldValue:t,newValue:o})}))}mergeEdgeData(t,e){this.batch((()=>{Object.entries(e).forEach((([e,r])=>{this.updateEdgeDataProperty(t,e,r)}))}))}checkTreeExistence(t){if(!this.treeIndices.has(t))throw new Error("Tree structure not found for treeKey: "+t)}attachTreeStructure(t){this.treeIndices.has(t)||(this.treeIndices.set(t,{parentMap:new Map,childrenMap:new Map}),this.batch((()=>{this.changes.push({type:"TreeStructureAttached",treeKey:t})})))}detachTreeStructure(t){this.checkTreeExistence(t),this.treeIndices.delete(t),this.batch((()=>{this.changes.push({type:"TreeStructureDetached",treeKey:t})}))}addTree(t,e){this.batch((()=>{this.attachTreeStructure(e);const r=[],n=Array.isArray(t)?t:[t];for(;n.length;){const t=n.shift();r.push(t),t.children&&n.push(...t.children)}this.addNodes(r),r.forEach((t=>{t.children?.forEach((r=>{this.setParent(r.id,t.id,e)}))}))}))}getRoots(t){return this.checkTreeExistence(t),this.getAllNodes().filter((e=>!this.getParent(e.id,t)))}getChildren(t,e){this.checkNodeExistence(t),this.checkTreeExistence(e);const r=this.treeIndices.get(e).childrenMap.get(t);return Array.from(r||[])}getParent(t,e){return this.checkNodeExistence(t),this.checkTreeExistence(e),this.treeIndices.get(e).parentMap.get(t)||null}setParent(t,e,r){this.checkTreeExistence(r);const n=this.treeIndices.get(r),o=this.getNode(t),i=n.parentMap.get(t),s=this.getNode(e);n.parentMap.set(t,s),i&&n.childrenMap.get(i.id)?.delete(o);let a=n.childrenMap.get(s.id);a||(a=new Set,n.childrenMap.set(s.id,a)),a.add(o),this.batch((()=>{this.changes.push({type:"TreeStructureChanged",treeKey:r,nodeId:t,oldParentId:i?.id,newParentId:s.id})}))}getAllNodes(){return Array.from(this.nodeMap.values())}getAllEdges(){return Array.from(this.edgeMap.values())}doBFS(t,e,r){for(;t.length;){const n=t.shift();r(n),e.add(n.id),this.getSuccessors(n.id).forEach((r=>{e.has(r.id)||(e.add(r.id),t.push(r))}))}}bfs(t,e){this.doBFS([this.getNode(t)],new Set,e)}doDFS(t,e,r){r(t),e.add(t.id),this.getSuccessors(t.id).forEach((t=>{e.has(t.id)||this.doDFS(t,e,r)}))}dfs(t,e){this.doDFS(this.getNode(t),new Set,e)}clone(){const t=this.getAllNodes().map((t=>({...t,data:{...t.data}}))),e=this.getAllEdges().map((t=>({...t,data:{...t.data}}))),r=new Rt({nodes:t,edges:e});return this.treeIndices.forEach((({parentMap:t,childrenMap:e},n)=>{const o=new Map;t.forEach(((t,e)=>{o.set(e,r.getNode(t.id))}));const i=new Map;e.forEach(((t,e)=>{i.set(e,new Set(Array.from(t).map((t=>r.getNode(t.id)))))})),r.treeIndices.set(n,{parentMap:o,childrenMap:i})})),r}toJSON(){return JSON.stringify({nodes:this.getAllNodes(),edges:this.getAllEdges()})}}function Ot(t){var e=0,r=0,n=0;if(t.length){for(var o=0;o<4;o++)(i=t[o])&&i.weight&&(e+=i.weight,r+=i.x*i.weight,n+=i.y*i.weight);t.x=r/e,t.y=n/e,t.weight=e}else{var i=t;t.x=i.data.x,t.y=i.data.y,t.weight=i.data.weight}}var Tt={maxIteration:500,gravity:10,animate:!0,factor:1,edgeStrength:200,nodeStrength:1e3,coulombDisScale:.005,damping:.9,maxSpeed:500,minMovement:.4,interval:.02,linkDistance:200,clusterNodeStrength:20,preventOverlap:!0,distanceThresholdMode:"mean"},zt=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="force",this.timeInterval=0,this.judgingDistance=0,this.options=e(e({},Tt),t)}return t.prototype.execute=function(t,e){return this.genericForceLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericForceLayout(!0,t,e)},t.prototype.genericForceLayout=function(t,r,n){var o=this,i=e(e({},this.options),n),s=r.getAllNodes(),a=r.getAllEdges();i.layoutInvisibles||(s=s.filter((function(t){return t.data.visible||void 0===t.data.visible})),a=a.filter((function(t){return t.data.visible||void 0===t.data.visible})));var u=this.formatOptions(i,r),h=u.width,c=u.height,f=u.nodeSize,d=u.getMass,g=u.nodeStrength,p=u.edgeStrength,m=u.linkDistance,y=s.map((function(t){return e(e({},t),{data:e(e({},t.data),{x:l(t.data.x)?t.data.x:Math.random()*h,y:l(t.data.y)?t.data.y:Math.random()*c,size:f(t)||30,mass:d(t),nodeStrength:g(t)})})})),w=a.map((function(t){return e(e({},t),{data:e(e({},t.data),{edgeStrength:p(t),linkDistance:m(t,r.getNode(t.source),r.getNode(t.target))})})}));if(!(null==s?void 0:s.length))return{nodes:[],edges:a};var v={};s.forEach((function(t,e){v[t.id]={x:0,y:0}}));var x=new Rt({nodes:y,edges:w});this.formatCentripetal(u,x);var b=u.maxIteration,M=u.animate,E=u.minMovement,N=u.onLayoutEnd,S=u.onTick;if(!M){for(var k=0;(this.judgingDistance>E||k<1)&&k<b;k++)this.runOneStep(x,r,k,v,u),this.updatePosition(r,x,v,u),t&&y.forEach((function(t){return r.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})})),null==S||S({nodes:jt(r,y),edges:a});t&&y.forEach((function(t){return r.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}));var A={nodes:jt(r,y),edges:a};return null==N||N(A),A}if("undefined"!=typeof window){var D=0;return this.timeInterval=window.setInterval((function(){s&&(o.runOneStep(x,r,D,v,u),o.updatePosition(r,x,v,u),t&&y.forEach((function(t){return r.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})})),null==S||S({nodes:jt(r,y),edges:a}),(++D>=b||o.judgingDistance<E)&&(null==N||N({nodes:jt(r,y),edges:a}),window.clearInterval(o.timeInterval)))}),0),{nodes:jt(r,y),edges:a}}},t.prototype.formatOptions=function(t,e){var r=t,n=t.width,o=t.height,i=t.getMass;if(r.width=n||"undefined"==typeof window?n:window.innerWidth,r.height=o||"undefined"==typeof window?o:window.innerHeight,t.center||(r.center=[r.width/2,r.height/2]),i||(r.getMass=function(t){var r=1;l(null==t?void 0:t.data.mass)&&(r=null==t?void 0:t.data.mass);var n=e.getDegree(t.id,"both");return!n||n<5?r:5*n*r}),t.preventOverlap){var s=w(0,t.nodeSpacing);t.nodeSize?h(t.nodeSize)?r.nodeSize=function(e){var r=t.nodeSize;return Math.max(r[0],r[1])+s(e)}:r.nodeSize=function(e){return t.nodeSize+s(e)}:r.nodeSize=function(t){var e=((null==t?void 0:t.data)||{}).size;return e?h(e)?Math.max(e[0],e[1])+s(t):g(e)?Math.max(e.width,e.height)+s(t):e+s(t):10+s(t)}}return r.linkDistance=t.linkDistance?w(1,t.linkDistance):function(t){return 1+r.nodeSize(e.getNode(t.source))+r.nodeSize(e.getNode(t.target))},r.nodeStrength=w(1,t.nodeStrength),r.edgeStrength=w(1,t.edgeStrength),t},t.prototype.formatCentripetal=function(t,e){var r,n=t.centripetalOptions,o=t.center,i=t.clusterNodeStrength,s=t.leafCluster,a=t.clustering,u=t.nodeClusterBy,h=e.getAllNodes(),l=n||{leaf:2,single:2,others:1,center:function(t){return{x:o[0],y:o[1]}}};"function"!=typeof i&&(t.clusterNodeStrength=function(t){return i});var c=[];if(s&&u&&(r=Ct(e,u),c=Array.from(new Set(null==h?void 0:h.map((function(t){return t.data[u]}))))||[],t.centripetalOptions=Object.assign(l,{single:100,leaf:function(e){var n=r[e.id]||{},o=n.siblingLeaves,i=n.sameTypeLeaves;return(null==i?void 0:i.length)===(null==o?void 0:o.length)||1===(null==c?void 0:c.length)?1:t.clusterNodeStrength(e)},others:1,center:function(t){var n,o=e.getDegree(t.id,"both");if(!o)return{x:100,y:100};if(1===o){var i=(r[t.id]||{}).sameTypeLeaves,s=void 0===i?[]:i;1===s.length?n=void 0:s.length>1&&(n=qt(s))}else n=void 0;return{x:null==n?void 0:n.x,y:null==n?void 0:n.y}}})),a&&u){r||(r=Ct(e,u)),c||(c=Array.from(new Set(h.map((function(t){return t.data[u]}))))),c=c.filter((function(t){return void 0!==t}));var f={};c.forEach((function(t){var r=h.filter((function(e){return e.data[u]===t})).map((function(t){return e.getNode(t.id)}));f[t]=qt(r)})),t.centripetalOptions=Object.assign(l,{single:function(e){return t.clusterNodeStrength(e)},leaf:function(e){return t.clusterNodeStrength(e)},others:function(e){return t.clusterNodeStrength(e)},center:function(t){var e=f[t.data[u]];return{x:null==e?void 0:e.x,y:null==e?void 0:e.y}}})}var d=t.centripetalOptions,g=d.leaf,p=d.single,m=d.others;g&&"function"!=typeof g&&(t.centripetalOptions.leaf=function(){return g}),p&&"function"!=typeof p&&(t.centripetalOptions.single=function(){return p}),m&&"function"!=typeof m&&(t.centripetalOptions.others=function(){return m})},t.prototype.runOneStep=function(t,e,r,n,o){var i={},s=t.getAllNodes(),a=t.getAllEdges();if(null==s?void 0:s.length){var u=o.monitor;this.calRepulsive(t,i,o),a&&this.calAttractive(t,i),this.calGravity(t,e,i,o),this.updateVelocity(t,i,n,o),u&&u({energy:this.calTotalEnergy(i,s),nodes:e.getAllNodes(),edges:e.getAllEdges(),iterations:r})}},t.prototype.calTotalEnergy=function(t,e){if(!(null==e?void 0:e.length))return 0;var r=0;return e.forEach((function(e,n){var o=t[e.id].x,i=t[e.id].y,s=o*o+i*i,a=e.data.mass;r+=(void 0===a?1:a)*s*.5})),r},t.prototype.calRepulsive=function(t,e,r){var n=r.factor,o=r.coulombDisScale;!function(t,e,r,n){var o=e/r,i=t.getAllNodes(),s=i.map((function(t,e){var r=t.data,n=r.nodeStrength;return{x:r.x,y:r.y,size:r.size,index:e,vx:0,vy:0,weight:o*n}})),a=L(s,(function(t){return t.x}),(function(t){return t.y})).visitAfter(Ot);s.forEach((function(t){!function(t,e){e.visit((function(e,r,n,o,i){return function(t,e,r,n,o,i){var s=i.x-t.x||.1,a=i.y-t.y||.1,u=n-e,h=s*s+a*a,l=Math.sqrt(h)*h;if(u*u*.81<h){var c=t.weight/l;return i.vx+=s*c,i.vy+=a*c,!0}if(t.length)return!1;t.data!==i&&(c=t.data.weight/l,i.vx+=s*c,i.vy+=a*c)}(e,r,0,o,0,t)}))}(t,a)})),s.map((function(t,e){var r=i[e],o=r.id,s=r.data.mass,a=void 0===s?1:s;n[o]={x:t.vx/a,y:t.vy/a}}))}(t,n,o*o,e)},t.prototype.calAttractive=function(t,e){t.getAllEdges().forEach((function(r,n){var o=r.source,i=r.target,s=t.getNode(o),a=t.getNode(i);if(s&&a){var u=a.data.x-s.data.x,h=a.data.y-s.data.y;u||h||(u=.01*Math.random(),h=.01*Math.random());var l=Math.sqrt(u*u+h*h),c=u/l,f=h/l,d=edgeInfos[n]||{},g=d.linkDistance,p=void 0===g?200:g,m=d.edgeStrength,y=(p-l)*(void 0===m?200:m),w=1/(s.data.mass||1),v=1/(a.data.mass||1),x=c*y,b=f*y;e[o].x-=x*w,e[o].y-=b*w,e[i].x+=x*v,e[i].y+=b*v}}))},t.prototype.calGravity=function(t,e,r,n){var o=n.getCenter,s=t.getAllNodes(),a=e.getAllNodes(),u=e.getAllEdges(),h=n.width,c=n.height,f=n.center,d=n.gravity,g=n.centripetalOptions;s&&s.forEach((function(n){var s=n.id,p=n.data,m=p.mass,y=p.x,w=p.y,v=e.getNode(s),x=0,b=0,M=d,E=t.getDegree(s,"in"),N=t.getDegree(s,"out"),S=t.getDegree(s,"both"),k=null==o?void 0:o(v,S);if(k){var A=i(k,3);x=y-A[0],b=w-A[1],M=A[2]}else x=y-f[0],b=w-f[1];if(M&&(r[s].x-=M*x/m,r[s].y-=M*b/m),g){var D=g.leaf,I=g.single,_=g.others,R=g.center,O=(null==R?void 0:R(v,a,u,h,c))||{x:0,y:0,centerStrength:0},T=O.x,z=O.y,C=O.centerStrength;if(!l(T)||!l(z))return;var L=(y-T)/m,P=(w-z)/m;if(C&&(r[s].x-=C*L,r[s].y-=C*P),0===S){var q=I(v);if(!q)return;return r[s].x-=q*L,void(r[s].y-=q*P)}if(0===E||0===N){var j=D(v,a,u);if(!j)return;return r[s].x-=j*L,void(r[s].y-=j*P)}var V=_(v);if(!V)return;r[s].x-=V*L,r[s].y-=V*P}}))},t.prototype.updateVelocity=function(t,e,r,n){var o=n.damping,i=n.maxSpeed,s=n.interval,a=t.getAllNodes();(null==a?void 0:a.length)&&a.forEach((function(t){var n=t.id,a=(r[n].x+e[n].x*s)*o||.01,u=(r[n].y+e[n].y*s)*o||.01,h=Math.sqrt(a*a+u*u);if(h>i){var l=i/h;a*=l,u*=l}r[n]={x:a,y:u}}))},t.prototype.updatePosition=function(t,e,r,n){var o=this,i=n.distanceThresholdMode,s=n.interval,a=e.getAllNodes();if(null==a?void 0:a.length){var u=0;"max"===i?this.judgingDistance=-1/0:"min"===i&&(this.judgingDistance=1/0),a.forEach((function(n){var a=n.id,h=t.getNode(a);if(l(h.data.fx)&&l(h.data.fy))e.mergeNodeData(a,{x:h.data.fx,y:h.data.fy});else{var c=r[a].x*s,f=r[a].y*s;e.mergeNodeData(a,{x:n.data.x+c,y:n.data.y+f});var d=Math.sqrt(c*c+f*f);switch(i){case"max":o.judgingDistance<d&&(o.judgingDistance=d);break;case"min":o.judgingDistance>d&&(o.judgingDistance=d);break;default:u+=d}}})),i&&"mean"!==i||(this.judgingDistance=u/a.length)}else this.judgingDistance=0},t.prototype.stop=function(){this.timeInterval&&"undefined"!=typeof window&&window.clearInterval(this.timeInterval)},t}(),Ct=function(t,e){var r=t.getAllNodes();if(!(null==r?void 0:r.length))return{};var n={};return r.forEach((function(r,o){1===t.getDegree(r.id,"both")&&(n[r.id]=Lt(t,"leaf",r,e))})),n},Lt=function(t,e,r,n){var o=t.getDegree(r.id,"in"),i=t.getDegree(r.id,"out"),s=r,a=[];return 0===o?(s=t.getSuccessors(r.id)[0],a=t.getNeighbors(s.id)):0===i&&(s=t.getPredecessors(r.id)[0],a=t.getNeighbors(s.id)),a=a.filter((function(e){return 0===t.getDegree(e.id,"in")||0===t.getDegree(e.id,"out")})),{coreNode:s,siblingLeaves:a,sameTypeLeaves:Pt(t,e,n,r,a)}},Pt=function(t,e,r,n,o){var i=n.data[r]||"",s=(null==o?void 0:o.filter((function(t){return t.data[r]===i})))||[];return"leaf"===e&&(s=s.filter((function(e){return 0===t.getDegree(e.id,"in")||0===t.getDegree(e.id,"out")}))),s},qt=function(t){var e={x:0,y:0};t.forEach((function(t){var r=t.data,n=r.x,o=r.y;e.x+=n||0,e.y+=o||0}));var r=t.length||1;return{x:e.x/r,y:e.y/r}},jt=function(t,r){return r.map((function(r){var n=r.id,o=r.data,i=t.getNode(n);return e(e({},i),{data:e(e({},i.data),{x:o.x,y:o.y})})}))},Vt={maxIteration:1e3,gravity:10,speed:5,clustering:!1,clusterGravity:10,width:300,height:300,nodeClusterBy:"cluster"},Ft=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="fruchterman",this.timeInterval=0,this.running=!1,this.options=e(e({},Vt),t)}return t.prototype.execute=function(t,e){return this.genericFruchtermanLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericFruchtermanLayout(!0,t,e)},t.prototype.stop=function(){this.timeInterval&&"undefined"!=typeof window&&window.clearInterval(this.timeInterval),this.running=!1},t.prototype.restart=function(){this.running=!0},t.prototype.tick=function(t){var e=this;void 0===t&&(t=1);for(var r=0;r<t;r++)this.runOneStep(this.lastGraph,this.lastClusterMap,this.lastOptions);var n={nodes:this.lastLayoutNodes,edges:this.lastLayoutEdges};return this.lastAssign&&n.nodes.forEach((function(t){return e.lastGraph.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})})),this.lastOptions.onLayoutEnd&&this.lastOptions.onLayoutEnd(n),n},t.prototype.genericFruchtermanLayout=function(t,r,n){var o=this;if(!this.running){var i=this.formatOptions(n),s=i.layoutInvisibles,a=i.width,u=i.height,h=i.center,l=i.clustering,c=i.nodeClusterBy,f=i.maxIteration,d=i.onTick,g=i.onLayoutEnd,p=r.getAllNodes(),y=r.getAllEdges();if(s||(p=p.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e})),y=y.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e}))),!(null==p?void 0:p.length)){var w={nodes:[],edges:y};return null==g||g(w),w}if(1===p.length)return t&&r.mergeNodeData(p[0].id,{x:h[0],y:h[1]}),w={nodes:[e(e({},p[0]),{data:e(e({},p[0].data),{x:h[0],y:h[1]})})],edges:y},null==g||g(w),w;var v=p.map((function(t){return m(t,[a,u])})),x=new Rt({nodes:v,edges:y}),b={};if(l&&v.forEach((function(t){var e=t.data[c];b[e]||(b[e]={name:e,cx:0,cy:0,count:0})})),this.lastLayoutNodes=v,this.lastLayoutEdges=y,this.lastAssign=t,this.lastGraph=x,this.lastOptions=i,this.lastClusterMap=b,"undefined"!=typeof window){var M=0;return this.timeInterval=window.setInterval((function(){if(o.runOneStep(x,b,i),t&&v.forEach((function(t){var e=t.id,n=t.data;return r.mergeNodeData(e,{x:n.x,y:n.y})})),null==d||d({nodes:v,edges:y}),++M>=f){try{null==g||g({nodes:v,edges:y})}catch(t){console.warn("onLayoutEnd failed",t)}window.clearInterval(o.timeInterval)}}),0),{nodes:v,edges:y}}}},t.prototype.formatOptions=function(t){void 0===t&&(t={});var r=e(e({},this.options),t),n=r.clustering,o=r.nodeClusterBy,i=r.center,s=r.width,a=r.height;return r.width=s||"undefined"==typeof window?s:window.innerWidth,r.height=a||"undefined"==typeof window?a:window.innerHeight,r.center=i||[r.width/2,r.height/2],r.clustering=n&&!!o,r},t.prototype.runOneStep=function(t,e,r){var n=r.height,o=r.width,i=r.gravity,s=r.center,a=r.speed,u=r.clustering,h=r.nodeClusterBy,c=r.clusterGravity,f=n*o,d=Math.sqrt(f)/10,g=t.getAllNodes(),p=f/(g.length+1),m=Math.sqrt(p),y={};if(this.applyCalculate(t,y,m,p),u){for(var w in e)e[w].cx=0,e[w].cy=0,e[w].count=0;for(var w in g.forEach((function(t){var r=t.data,n=e[r[h]];l(r.x)&&(n.cx+=r.x),l(r.y)&&(n.cy+=r.y),n.count++})),e)e[w].cx/=e[w].count,e[w].cy/=e[w].count;var v=c||i;g.forEach((function(t,r){var n=t.id,o=t.data;if(l(o.x)&&l(o.y)){var i=e[o[h]],s=Math.sqrt((o.x-i.cx)*(o.x-i.cx)+(o.y-i.cy)*(o.y-i.cy)),a=m*v;y[n].x-=a*(o.x-i.cx)/s,y[n].y-=a*(o.y-i.cy)/s}}))}g.forEach((function(t,e){var r=t.id,n=t.data;if(l(n.x)&&l(n.y)){var o=.01*m*i;y[r].x-=o*(n.x-s[0]),y[r].y-=o*(n.y-s[1])}})),g.forEach((function(e,r){var n=e.id,o=e.data;if(l(o.fx)&&l(o.fy))return o.x=o.fx,void(o.y=o.fy);if(l(o.x)&&l(o.y)){var i=Math.sqrt(y[n].x*y[n].x+y[n].y*y[n].y);if(i>0){var s=Math.min(d*(a/800),i);t.mergeNodeData(n,{x:o.x+y[n].x/i*s,y:o.y+y[n].y/i*s})}}}))},t.prototype.applyCalculate=function(t,e,r,n){this.calRepulsive(t,e,n),this.calAttractive(t,e,r)},t.prototype.calRepulsive=function(t,e,r){var n=t.getAllNodes();n.forEach((function(t,o){var i=t.data,s=t.id;e[s]={x:0,y:0},n.forEach((function(t,n){var a=t.data,u=t.id;if(!(o<=n)&&l(i.x)&&l(a.x)&&l(i.y)&&l(a.y)){var h=i.x-a.x,c=i.y-a.y,f=h*h+c*c;0===f&&(f=1,h=.01,c=.01);var d=r/f,g=h*d,p=c*d;e[s].x+=g,e[s].y+=p,e[u].x-=g,e[u].y-=p}}))}))},t.prototype.calAttractive=function(t,e,r){t.getAllEdges().forEach((function(n){var o=n.source,i=n.target;if(o&&i&&o!==i){var s=t.getNode(o).data,a=t.getNode(i).data;if(l(a.x)&&l(s.x)&&l(a.y)&&l(s.y)){var u=a.x-s.x,h=a.y-s.y,c=Math.sqrt(u*u+h*h)/r,f=u*c,d=h*c;e[o].x+=f,e[o].y+=d,e[i].x-=f,e[i].y-=d}}}))},t}(),Ut={begin:[0,0],preventOverlap:!0,preventOverlapPadding:10,condense:!1,rows:void 0,cols:void 0,position:void 0,sortBy:"degree",nodeSize:30,width:300,height:300},Bt=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="grid",this.options=e(e({},Ut),t)}return t.prototype.execute=function(t,e){return this.genericGridLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericGridLayout(!0,t,e)},t.prototype.genericGridLayout=function(t,r,n){var o=e(e({},this.options),n),i=o.begin,s=void 0===i?[0,0]:i,u=o.condense,c=o.preventOverlapPadding,f=o.preventOverlap,d=o.rows,g=o.cols,p=o.nodeSpacing,y=o.nodeSize,x=o.width,b=o.height,M=o.layoutInvisibles,E=o.onLayoutEnd,N=o.position,S=o.sortBy,k=r.getAllNodes(),A=r.getAllEdges();M||(k=k.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e})),A=A.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e})));var D=k.length;if(0===D){var I={nodes:[],edges:A};return null==E||E(I),I}if(1===D){t&&r.mergeNodeData(k[0].id,{x:s[0],y:s[1]});var _={nodes:[e(e({},k[0]),{data:e(e({},k[0].data),{x:s[0],y:s[1]})})],edges:A};return null==E||E(_),_}var R=k.map((function(t){return m(t)}));"id"===S||a(S)&&void 0!==R[0].data[S]||(S="degree"),"degree"===S?R.sort((function(t,e){return r.getDegree(e.id,"both")-r.getDegree(t.id,"both")})):"id"===S?R.sort((function(t,e){return l(e.id)&&l(t.id)?e.id-t.id:"".concat(t.id).localeCompare("".concat(e.id))})):R.sort((function(t,e){return e.data[S]-t.data[S]}));var O=x||"undefined"==typeof window?x:window.innerWidth,T=b||"undefined"==typeof window?b:window.innerHeight,z=D,C={rows:d,cols:g};if(null!=d&&null!=g)C.rows=d,C.cols=g;else if(null!=d&&null==g)C.rows=d,C.cols=Math.ceil(z/C.rows);else if(null==d&&null!=g)C.cols=g,C.rows=Math.ceil(z/C.cols);else{var L=Math.sqrt(z*T/O);C.rows=Math.round(L),C.cols=Math.round(O/T*L)}if(C.rows=Math.max(C.rows,1),C.cols=Math.max(C.cols,1),C.cols*C.rows>z)((q=$t(C))-1)*(P=Gt(C))>=z?$t(C,q-1):(P-1)*q>=z&&Gt(C,P-1);else for(;C.cols*C.rows<z;){var P,q=$t(C);((P=Gt(C))+1)*q>=z?Gt(C,P+1):$t(C,q+1)}var j=u?0:O/C.cols,V=u?0:T/C.rows;if(f||p){var F=w(10,p),U=v(30,y,!1);R.forEach((function(t){t.data.x&&t.data.y||(t.data.x=0,t.data.y=0);var e,n,o=r.getNode(t.id),i=U(o)||30;h(i)?(e=i[0],n=i[1]):(e=i,n=i);var s=void 0!==F?F(t):c,a=e+s,u=n+s;j=Math.max(j,a),V=Math.max(V,u)}))}for(var B={},$={row:0,col:0},G={},H=0;H<R.length;H++){var J=R[H],K=void 0;if(N&&(K=N(r.getNode(J.id))),K&&(void 0!==K.row||void 0!==K.col)){var W={row:K.row,col:K.col};if(void 0===W.col)for(W.col=0;Ht(B,W);)W.col++;else if(void 0===W.row)for(W.row=0;Ht(B,W);)W.row++;G[J.id]=W,Jt(B,W)}Wt(J,s,j,V,G,C,$,B)}var Y={nodes:R,edges:A};return null==E||E(Y),t&&R.forEach((function(t){r.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})})),Y},t}(),$t=function(t,e){var r,n=t.rows||5,o=t.cols||5;return null==e?r=Math.min(n,o):Math.min(n,o)===t.rows?t.rows=e:t.cols=e,r},Gt=function(t,e){var r,n=t.rows||5,o=t.cols||5;return null==e?r=Math.max(n,o):Math.max(n,o)===t.rows?t.rows=e:t.cols=e,r},Ht=function(t,e){return t["c-".concat(e.row,"-").concat(e.col)]||!1},Jt=function(t,e){return t["c-".concat(e.row,"-").concat(e.col)]=!0},Kt=function(t,e){var r=t.cols||5;e.col++,e.col>=r&&(e.col=0,e.row++)},Wt=function(t,e,r,n,o,i,s,a){var u,h,l=o[t.id];if(l)u=l.col*r+r/2+e[0],h=l.row*n+n/2+e[1];else{for(;Ht(a,s);)Kt(i,s);u=s.col*r+r/2+e[0],h=s.row*n+n/2+e[1],Jt(a,s),Kt(i,s)}t.data.x=u,t.data.y=h};const Yt=Object.prototype.toString;function Zt(t){return Yt.call(t).endsWith("Array]")}function Xt(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!Zt(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");var r=e.fromIndex,n=void 0===r?0:r,o=e.toIndex,i=void 0===o?t.length:o;if(n<0||n>=t.length||!Number.isInteger(n))throw new Error("fromIndex must be a positive integer smaller than length");if(i<=n||i>t.length||!Number.isInteger(i))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var s=t[n],a=n+1;a<i;a++)t[a]>s&&(s=t[a]);return s}function Qt(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!Zt(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");var r=e.fromIndex,n=void 0===r?0:r,o=e.toIndex,i=void 0===o?t.length:o;if(n<0||n>=t.length||!Number.isInteger(n))throw new Error("fromIndex must be a positive integer smaller than length");if(i<=n||i>t.length||!Number.isInteger(i))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var s=t[n],a=n+1;a<i;a++)t[a]<s&&(s=t[a]);return s}function te(t){var e,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!Zt(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");if(void 0!==r.output){if(!Zt(r.output))throw new TypeError("output option must be an array if specified");e=r.output}else e=new Array(t.length);var n=Qt(t),o=Xt(t);if(n===o)throw new RangeError("minimum and maximum input values are equal. Cannot rescale a constant array");var i=r.min,s=void 0===i?r.autoMinMax?n:0:i,a=r.max,u=void 0===a?r.autoMinMax?o:1:a;if(s>=u)throw new RangeError("min option must be smaller than max option");for(var h=(u-s)/(o-n),l=0;l<t.length;l++)e[l]=(t[l]-n)*h+s;return e}const ee=" ".repeat(2),re=" ".repeat(4);function ne(t,e={}){const{maxRows:r=15,maxColumns:n=10,maxNumSize:o=8,padMinus:i="auto"}=e;return`${t.constructor.name} {\n${ee}[\n${re}${function(t,e,r,n,o){const{rows:i,columns:s}=t,a=Math.min(i,e),u=Math.min(s,r),h=[];if("auto"===o){o=!1;t:for(let e=0;e<a;e++)for(let r=0;r<u;r++)if(t.get(e,r)<0){o=!0;break t}}for(let e=0;e<a;e++){let r=[];for(let i=0;i<u;i++)r.push(oe(t.get(e,i),n,o));h.push(`${r.join(" ")}`)}return u!==s&&(h[h.length-1]+=` ... ${s-r} more columns`),a!==i&&h.push(`... ${i-e} more rows`),h.join(`\n${re}`)}(t,r,n,o,i)}\n${ee}]\n${ee}rows: ${t.rows}\n${ee}columns: ${t.columns}\n}`}function oe(t,e,r){return(t>=0&&r?` ${ie(t,e-1)}`:ie(t,e)).padEnd(e)}function ie(t,e){let r=t.toString();if(r.length<=e)return r;let n=t.toFixed(e);if(n.length>e&&(n=t.toFixed(Math.max(0,e-(n.length-e)))),n.length<=e&&!n.startsWith("0.000")&&!n.startsWith("-0.000"))return n;let o=t.toExponential(e);return o.length>e&&(o=t.toExponential(Math.max(0,e-(o.length-e)))),o.slice(0)}function se(t,e,r){let n=r?t.rows:t.rows-1;if(e<0||e>n)throw new RangeError("Row index out of range")}function ae(t,e,r){let n=r?t.columns:t.columns-1;if(e<0||e>n)throw new RangeError("Column index out of range")}function ue(t,e){if(e.to1DArray&&(e=e.to1DArray()),e.length!==t.columns)throw new RangeError("vector size must be the same as the number of columns");return e}function he(t,e){if(e.to1DArray&&(e=e.to1DArray()),e.length!==t.rows)throw new RangeError("vector size must be the same as the number of rows");return e}function le(t,e,r,n,o){if(5!==arguments.length)throw new RangeError("expected 4 arguments");if(fe("startRow",e),fe("endRow",r),fe("startColumn",n),fe("endColumn",o),e>r||n>o||e<0||e>=t.rows||r<0||r>=t.rows||n<0||n>=t.columns||o<0||o>=t.columns)throw new RangeError("Submatrix indices are out of range")}function ce(t,e=0){let r=[];for(let n=0;n<t;n++)r.push(e);return r}function fe(t,e){if("number"!=typeof e)throw new TypeError(`${t} must be a number`)}function de(t){if(t.isEmpty())throw new Error("Empty matrix has no elements to index")}class ge{static from1DArray(t,e,r){if(t*e!==r.length)throw new RangeError("data length does not match given dimensions");let n=new me(t,e);for(let o=0;o<t;o++)for(let t=0;t<e;t++)n.set(o,t,r[o*e+t]);return n}static rowVector(t){let e=new me(1,t.length);for(let r=0;r<t.length;r++)e.set(0,r,t[r]);return e}static columnVector(t){let e=new me(t.length,1);for(let r=0;r<t.length;r++)e.set(r,0,t[r]);return e}static zeros(t,e){return new me(t,e)}static ones(t,e){return new me(t,e).fill(1)}static rand(t,e,r={}){if("object"!=typeof r)throw new TypeError("options must be an object");const{random:n=Math.random}=r;let o=new me(t,e);for(let r=0;r<t;r++)for(let t=0;t<e;t++)o.set(r,t,n());return o}static randInt(t,e,r={}){if("object"!=typeof r)throw new TypeError("options must be an object");const{min:n=0,max:o=1e3,random:i=Math.random}=r;if(!Number.isInteger(n))throw new TypeError("min must be an integer");if(!Number.isInteger(o))throw new TypeError("max must be an integer");if(n>=o)throw new RangeError("min must be smaller than max");let s=o-n,a=new me(t,e);for(let r=0;r<t;r++)for(let t=0;t<e;t++){let e=n+Math.round(i()*s);a.set(r,t,e)}return a}static eye(t,e,r){void 0===e&&(e=t),void 0===r&&(r=1);let n=Math.min(t,e),o=this.zeros(t,e);for(let t=0;t<n;t++)o.set(t,t,r);return o}static diag(t,e,r){let n=t.length;void 0===e&&(e=n),void 0===r&&(r=e);let o=Math.min(n,e,r),i=this.zeros(e,r);for(let e=0;e<o;e++)i.set(e,e,t[e]);return i}static min(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);let r=t.rows,n=t.columns,o=new me(r,n);for(let i=0;i<r;i++)for(let r=0;r<n;r++)o.set(i,r,Math.min(t.get(i,r),e.get(i,r)));return o}static max(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);let r=t.rows,n=t.columns,o=new this(r,n);for(let i=0;i<r;i++)for(let r=0;r<n;r++)o.set(i,r,Math.max(t.get(i,r),e.get(i,r)));return o}static checkMatrix(t){return ge.isMatrix(t)?t:new me(t)}static isMatrix(t){return null!=t&&"Matrix"===t.klass}get size(){return this.rows*this.columns}apply(t){if("function"!=typeof t)throw new TypeError("callback must be a function");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.call(this,e,r);return this}to1DArray(){let t=[];for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.push(this.get(e,r));return t}to2DArray(){let t=[];for(let e=0;e<this.rows;e++){t.push([]);for(let r=0;r<this.columns;r++)t[e].push(this.get(e,r))}return t}toJSON(){return this.to2DArray()}isRowVector(){return 1===this.rows}isColumnVector(){return 1===this.columns}isVector(){return 1===this.rows||1===this.columns}isSquare(){return this.rows===this.columns}isEmpty(){return 0===this.rows||0===this.columns}isSymmetric(){if(this.isSquare()){for(let t=0;t<this.rows;t++)for(let e=0;e<=t;e++)if(this.get(t,e)!==this.get(e,t))return!1;return!0}return!1}isEchelonForm(){let t=0,e=0,r=-1,n=!0,o=!1;for(;t<this.rows&&n;){for(e=0,o=!1;e<this.columns&&!1===o;)0===this.get(t,e)?e++:1===this.get(t,e)&&e>r?(o=!0,r=e):(n=!1,o=!0);t++}return n}isReducedEchelonForm(){let t=0,e=0,r=-1,n=!0,o=!1;for(;t<this.rows&&n;){for(e=0,o=!1;e<this.columns&&!1===o;)0===this.get(t,e)?e++:1===this.get(t,e)&&e>r?(o=!0,r=e):(n=!1,o=!0);for(let r=e+1;r<this.rows;r++)0!==this.get(t,r)&&(n=!1);t++}return n}echelonForm(){let t=this.clone(),e=0,r=0;for(;e<t.rows&&r<t.columns;){let n=e;for(let o=e;o<t.rows;o++)t.get(o,r)>t.get(n,r)&&(n=o);if(0===t.get(n,r))r++;else{t.swapRows(e,n);let o=t.get(e,r);for(let n=r;n<t.columns;n++)t.set(e,n,t.get(e,n)/o);for(let n=e+1;n<t.rows;n++){let o=t.get(n,r)/t.get(e,r);t.set(n,r,0);for(let i=r+1;i<t.columns;i++)t.set(n,i,t.get(n,i)-t.get(e,i)*o)}e++,r++}}return t}reducedEchelonForm(){let t=this.echelonForm(),e=t.columns,r=t.rows,n=r-1;for(;n>=0;)if(0===t.maxRow(n))n--;else{let o=0,i=!1;for(;o<r&&!1===i;)1===t.get(n,o)?i=!0:o++;for(let r=0;r<n;r++){let i=t.get(r,o);for(let s=o;s<e;s++){let e=t.get(r,s)-i*t.get(n,s);t.set(r,s,e)}}n--}return t}set(){throw new Error("set method is unimplemented")}get(){throw new Error("get method is unimplemented")}repeat(t={}){if("object"!=typeof t)throw new TypeError("options must be an object");const{rows:e=1,columns:r=1}=t;if(!Number.isInteger(e)||e<=0)throw new TypeError("rows must be a positive integer");if(!Number.isInteger(r)||r<=0)throw new TypeError("columns must be a positive integer");let n=new me(this.rows*e,this.columns*r);for(let t=0;t<e;t++)for(let e=0;e<r;e++)n.setSubMatrix(this,this.rows*t,this.columns*e);return n}fill(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,t);return this}neg(){return this.mulS(-1)}getRow(t){se(this,t);let e=[];for(let r=0;r<this.columns;r++)e.push(this.get(t,r));return e}getRowVector(t){return me.rowVector(this.getRow(t))}setRow(t,e){se(this,t),e=ue(this,e);for(let r=0;r<this.columns;r++)this.set(t,r,e[r]);return this}swapRows(t,e){se(this,t),se(this,e);for(let r=0;r<this.columns;r++){let n=this.get(t,r);this.set(t,r,this.get(e,r)),this.set(e,r,n)}return this}getColumn(t){ae(this,t);let e=[];for(let r=0;r<this.rows;r++)e.push(this.get(r,t));return e}getColumnVector(t){return me.columnVector(this.getColumn(t))}setColumn(t,e){ae(this,t),e=he(this,e);for(let r=0;r<this.rows;r++)this.set(r,t,e[r]);return this}swapColumns(t,e){ae(this,t),ae(this,e);for(let r=0;r<this.rows;r++){let n=this.get(r,t);this.set(r,t,this.get(r,e)),this.set(r,e,n)}return this}addRowVector(t){t=ue(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t[r]);return this}subRowVector(t){t=ue(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t[r]);return this}mulRowVector(t){t=ue(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t[r]);return this}divRowVector(t){t=ue(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t[r]);return this}addColumnVector(t){t=he(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t[e]);return this}subColumnVector(t){t=he(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t[e]);return this}mulColumnVector(t){t=he(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t[e]);return this}divColumnVector(t){t=he(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t[e]);return this}mulRow(t,e){se(this,t);for(let r=0;r<this.columns;r++)this.set(t,r,this.get(t,r)*e);return this}mulColumn(t,e){ae(this,t);for(let r=0;r<this.rows;r++)this.set(r,t,this.get(r,t)*e);return this}max(t){if(this.isEmpty())return NaN;switch(t){case"row":{const t=new Array(this.rows).fill(Number.NEGATIVE_INFINITY);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)>t[e]&&(t[e]=this.get(e,r));return t}case"column":{const t=new Array(this.columns).fill(Number.NEGATIVE_INFINITY);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)>t[r]&&(t[r]=this.get(e,r));return t}case void 0:{let t=this.get(0,0);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)>t&&(t=this.get(e,r));return t}default:throw new Error(`invalid option: ${t}`)}}maxIndex(){de(this);let t=this.get(0,0),e=[0,0];for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.get(r,n)>t&&(t=this.get(r,n),e[0]=r,e[1]=n);return e}min(t){if(this.isEmpty())return NaN;switch(t){case"row":{const t=new Array(this.rows).fill(Number.POSITIVE_INFINITY);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)<t[e]&&(t[e]=this.get(e,r));return t}case"column":{const t=new Array(this.columns).fill(Number.POSITIVE_INFINITY);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)<t[r]&&(t[r]=this.get(e,r));return t}case void 0:{let t=this.get(0,0);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)<t&&(t=this.get(e,r));return t}default:throw new Error(`invalid option: ${t}`)}}minIndex(){de(this);let t=this.get(0,0),e=[0,0];for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.get(r,n)<t&&(t=this.get(r,n),e[0]=r,e[1]=n);return e}maxRow(t){if(se(this,t),this.isEmpty())return NaN;let e=this.get(t,0);for(let r=1;r<this.columns;r++)this.get(t,r)>e&&(e=this.get(t,r));return e}maxRowIndex(t){se(this,t),de(this);let e=this.get(t,0),r=[t,0];for(let n=1;n<this.columns;n++)this.get(t,n)>e&&(e=this.get(t,n),r[1]=n);return r}minRow(t){if(se(this,t),this.isEmpty())return NaN;let e=this.get(t,0);for(let r=1;r<this.columns;r++)this.get(t,r)<e&&(e=this.get(t,r));return e}minRowIndex(t){se(this,t),de(this);let e=this.get(t,0),r=[t,0];for(let n=1;n<this.columns;n++)this.get(t,n)<e&&(e=this.get(t,n),r[1]=n);return r}maxColumn(t){if(ae(this,t),this.isEmpty())return NaN;let e=this.get(0,t);for(let r=1;r<this.rows;r++)this.get(r,t)>e&&(e=this.get(r,t));return e}maxColumnIndex(t){ae(this,t),de(this);let e=this.get(0,t),r=[0,t];for(let n=1;n<this.rows;n++)this.get(n,t)>e&&(e=this.get(n,t),r[0]=n);return r}minColumn(t){if(ae(this,t),this.isEmpty())return NaN;let e=this.get(0,t);for(let r=1;r<this.rows;r++)this.get(r,t)<e&&(e=this.get(r,t));return e}minColumnIndex(t){ae(this,t),de(this);let e=this.get(0,t),r=[0,t];for(let n=1;n<this.rows;n++)this.get(n,t)<e&&(e=this.get(n,t),r[0]=n);return r}diag(){let t=Math.min(this.rows,this.columns),e=[];for(let r=0;r<t;r++)e.push(this.get(r,r));return e}norm(t="frobenius"){let e=0;if("max"===t)return this.max();if("frobenius"===t){for(let t=0;t<this.rows;t++)for(let r=0;r<this.columns;r++)e+=this.get(t,r)*this.get(t,r);return Math.sqrt(e)}throw new RangeError(`unknown norm type: ${t}`)}cumulativeSum(){let t=0;for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t+=this.get(e,r),this.set(e,r,t);return this}dot(t){ge.isMatrix(t)&&(t=t.to1DArray());let e=this.to1DArray();if(e.length!==t.length)throw new RangeError("vectors do not have the same size");let r=0;for(let n=0;n<e.length;n++)r+=e[n]*t[n];return r}mmul(t){t=me.checkMatrix(t);let e=this.rows,r=this.columns,n=t.columns,o=new me(e,n),i=new Float64Array(r);for(let s=0;s<n;s++){for(let e=0;e<r;e++)i[e]=t.get(e,s);for(let t=0;t<e;t++){let e=0;for(let n=0;n<r;n++)e+=this.get(t,n)*i[n];o.set(t,s,e)}}return o}strassen2x2(t){t=me.checkMatrix(t);let e=new me(2,2);const r=this.get(0,0),n=t.get(0,0),o=this.get(0,1),i=t.get(0,1),s=this.get(1,0),a=t.get(1,0),u=this.get(1,1),h=t.get(1,1),l=(r+u)*(n+h),c=(s+u)*n,f=r*(i-h),d=u*(a-n),g=(r+o)*h,p=l+d-g+(o-u)*(a+h),m=f+g,y=c+d,w=l-c+f+(s-r)*(n+i);return e.set(0,0,p),e.set(0,1,m),e.set(1,0,y),e.set(1,1,w),e}strassen3x3(t){t=me.checkMatrix(t);let e=new me(3,3);const r=this.get(0,0),n=this.get(0,1),o=this.get(0,2),i=this.get(1,0),s=this.get(1,1),a=this.get(1,2),u=this.get(2,0),h=this.get(2,1),l=this.get(2,2),c=t.get(0,0),f=t.get(0,1),d=t.get(0,2),g=t.get(1,0),p=t.get(1,1),m=t.get(1,2),y=t.get(2,0),w=t.get(2,1),v=t.get(2,2),x=(r-i)*(-f+p),b=(-r+i+s)*(c-f+p),M=(i+s)*(-c+f),E=r*c,N=(-r+u+h)*(c-d+m),S=(-r+u)*(d-m),k=(u+h)*(-c+d),A=(-o+h+l)*(p+y-w),D=(o-l)*(p-w),I=o*y,_=(h+l)*(-y+w),R=(-o+s+a)*(m+y-v),O=(o-a)*(m-v),T=(s+a)*(-y+v),z=E+I+n*g,C=(r+n+o-i-s-h-l)*p+b+M+E+A+I+_,L=E+N+k+(r+n+o-s-a-u-h)*m+I+R+T,P=x+s*(-c+f+g-p-m-y+v)+b+E+I+R+O,q=x+b+M+E+a*w,j=I+R+O+T+i*d,V=E+N+S+h*(-c+d+g-p-m-y+w)+A+D+I,F=A+D+I+_+u*f,U=E+N+S+k+l*v;return e.set(0,0,z),e.set(0,1,C),e.set(0,2,L),e.set(1,0,P),e.set(1,1,q),e.set(1,2,j),e.set(2,0,V),e.set(2,1,F),e.set(2,2,U),e}mmulStrassen(t){t=me.checkMatrix(t);let e=this.clone(),r=e.rows,n=e.columns,o=t.rows,i=t.columns;function s(t,e,r){let n=t.rows,o=t.columns;if(n===e&&o===r)return t;{let n=ge.zeros(e,r);return n=n.setSubMatrix(t,0,0),n}}n!==o&&console.warn(`Multiplying ${r} x ${n} and ${o} x ${i} matrix: dimensions do not match.`);let a=Math.max(r,o),u=Math.max(n,i);return e=s(e,a,u),function t(e,r,n,o){if(n<=512||o<=512)return e.mmul(r);n%2==1&&o%2==1?(e=s(e,n+1,o+1),r=s(r,n+1,o+1)):n%2==1?(e=s(e,n+1,o),r=s(r,n+1,o)):o%2==1&&(e=s(e,n,o+1),r=s(r,n,o+1));let i=parseInt(e.rows/2,10),a=parseInt(e.columns/2,10),u=e.subMatrix(0,i-1,0,a-1),h=r.subMatrix(0,i-1,0,a-1),l=e.subMatrix(0,i-1,a,e.columns-1),c=r.subMatrix(0,i-1,a,r.columns-1),f=e.subMatrix(i,e.rows-1,0,a-1),d=r.subMatrix(i,r.rows-1,0,a-1),g=e.subMatrix(i,e.rows-1,a,e.columns-1),p=r.subMatrix(i,r.rows-1,a,r.columns-1),m=t(ge.add(u,g),ge.add(h,p),i,a),y=t(ge.add(f,g),h,i,a),w=t(u,ge.sub(c,p),i,a),v=t(g,ge.sub(d,h),i,a),x=t(ge.add(u,l),p,i,a),b=t(ge.sub(f,u),ge.add(h,c),i,a),M=t(ge.sub(l,g),ge.add(d,p),i,a),E=ge.add(m,v);E.sub(x),E.add(M);let N=ge.add(w,x),S=ge.add(y,v),k=ge.sub(m,y);k.add(w),k.add(b);let A=ge.zeros(2*E.rows,2*E.columns);return A=A.setSubMatrix(E,0,0),A=A.setSubMatrix(N,E.rows,0),A=A.setSubMatrix(S,0,E.columns),A=A.setSubMatrix(k,E.rows,E.columns),A.subMatrix(0,n-1,0,o-1)}(e,t=s(t,a,u),a,u)}scaleRows(t={}){if("object"!=typeof t)throw new TypeError("options must be an object");const{min:e=0,max:r=1}=t;if(!Number.isFinite(e))throw new TypeError("min must be a number");if(!Number.isFinite(r))throw new TypeError("max must be a number");if(e>=r)throw new RangeError("min must be smaller than max");let n=new me(this.rows,this.columns);for(let t=0;t<this.rows;t++){const o=this.getRow(t);o.length>0&&te(o,{min:e,max:r,output:o}),n.setRow(t,o)}return n}scaleColumns(t={}){if("object"!=typeof t)throw new TypeError("options must be an object");const{min:e=0,max:r=1}=t;if(!Number.isFinite(e))throw new TypeError("min must be a number");if(!Number.isFinite(r))throw new TypeError("max must be a number");if(e>=r)throw new RangeError("min must be smaller than max");let n=new me(this.rows,this.columns);for(let t=0;t<this.columns;t++){const o=this.getColumn(t);o.length&&te(o,{min:e,max:r,output:o}),n.setColumn(t,o)}return n}flipRows(){const t=Math.ceil(this.columns/2);for(let e=0;e<this.rows;e++)for(let r=0;r<t;r++){let t=this.get(e,r),n=this.get(e,this.columns-1-r);this.set(e,r,n),this.set(e,this.columns-1-r,t)}return this}flipColumns(){const t=Math.ceil(this.rows/2);for(let e=0;e<this.columns;e++)for(let r=0;r<t;r++){let t=this.get(r,e),n=this.get(this.rows-1-r,e);this.set(r,e,n),this.set(this.rows-1-r,e,t)}return this}kroneckerProduct(t){t=me.checkMatrix(t);let e=this.rows,r=this.columns,n=t.rows,o=t.columns,i=new me(e*n,r*o);for(let s=0;s<e;s++)for(let e=0;e<r;e++)for(let r=0;r<n;r++)for(let a=0;a<o;a++)i.set(n*s+r,o*e+a,this.get(s,e)*t.get(r,a));return i}kroneckerSum(t){if(t=me.checkMatrix(t),!this.isSquare()||!t.isSquare())throw new Error("Kronecker Sum needs two Square Matrices");let e=this.rows,r=t.rows,n=this.kroneckerProduct(me.eye(r,r)),o=me.eye(e,e).kroneckerProduct(t);return n.add(o)}transpose(){let t=new me(this.columns,this.rows);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.set(r,e,this.get(e,r));return t}sortRows(t=pe){for(let e=0;e<this.rows;e++)this.setRow(e,this.getRow(e).sort(t));return this}sortColumns(t=pe){for(let e=0;e<this.columns;e++)this.setColumn(e,this.getColumn(e).sort(t));return this}subMatrix(t,e,r,n){le(this,t,e,r,n);let o=new me(e-t+1,n-r+1);for(let i=t;i<=e;i++)for(let e=r;e<=n;e++)o.set(i-t,e-r,this.get(i,e));return o}subMatrixRow(t,e,r){if(void 0===e&&(e=0),void 0===r&&(r=this.columns-1),e>r||e<0||e>=this.columns||r<0||r>=this.columns)throw new RangeError("Argument out of range");let n=new me(t.length,r-e+1);for(let o=0;o<t.length;o++)for(let i=e;i<=r;i++){if(t[o]<0||t[o]>=this.rows)throw new RangeError(`Row index out of range: ${t[o]}`);n.set(o,i-e,this.get(t[o],i))}return n}subMatrixColumn(t,e,r){if(void 0===e&&(e=0),void 0===r&&(r=this.rows-1),e>r||e<0||e>=this.rows||r<0||r>=this.rows)throw new RangeError("Argument out of range");let n=new me(r-e+1,t.length);for(let o=0;o<t.length;o++)for(let i=e;i<=r;i++){if(t[o]<0||t[o]>=this.columns)throw new RangeError(`Column index out of range: ${t[o]}`);n.set(i-e,o,this.get(i,t[o]))}return n}setSubMatrix(t,e,r){if((t=me.checkMatrix(t)).isEmpty())return this;le(this,e,e+t.rows-1,r,r+t.columns-1);for(let n=0;n<t.rows;n++)for(let o=0;o<t.columns;o++)this.set(e+n,r+o,t.get(n,o));return this}selection(t,e){!function(t,e){if(!Zt(e))throw new TypeError("row indices must be an array");for(let r=0;r<e.length;r++)if(e[r]<0||e[r]>=t.rows)throw new RangeError("row indices are out of range")}(this,t),function(t,e){if(!Zt(e))throw new TypeError("column indices must be an array");for(let r=0;r<e.length;r++)if(e[r]<0||e[r]>=t.columns)throw new RangeError("column indices are out of range")}(this,e);let r=new me(t.length,e.length);for(let n=0;n<t.length;n++){let o=t[n];for(let t=0;t<e.length;t++){let i=e[t];r.set(n,t,this.get(o,i))}}return r}trace(){let t=Math.min(this.rows,this.columns),e=0;for(let r=0;r<t;r++)e+=this.get(r,r);return e}clone(){let t=new me(this.rows,this.columns);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.set(e,r,this.get(e,r));return t}sum(t){switch(t){case"row":return function(t){let e=ce(t.rows);for(let r=0;r<t.rows;++r)for(let n=0;n<t.columns;++n)e[r]+=t.get(r,n);return e}(this);case"column":return function(t){let e=ce(t.columns);for(let r=0;r<t.rows;++r)for(let n=0;n<t.columns;++n)e[n]+=t.get(r,n);return e}(this);case void 0:return function(t){let e=0;for(let r=0;r<t.rows;r++)for(let n=0;n<t.columns;n++)e+=t.get(r,n);return e}(this);default:throw new Error(`invalid option: ${t}`)}}product(t){switch(t){case"row":return function(t){let e=ce(t.rows,1);for(let r=0;r<t.rows;++r)for(let n=0;n<t.columns;++n)e[r]*=t.get(r,n);return e}(this);case"column":return function(t){let e=ce(t.columns,1);for(let r=0;r<t.rows;++r)for(let n=0;n<t.columns;++n)e[n]*=t.get(r,n);return e}(this);case void 0:return function(t){let e=1;for(let r=0;r<t.rows;r++)for(let n=0;n<t.columns;n++)e*=t.get(r,n);return e}(this);default:throw new Error(`invalid option: ${t}`)}}mean(t){const e=this.sum(t);switch(t){case"row":for(let t=0;t<this.rows;t++)e[t]/=this.columns;return e;case"column":for(let t=0;t<this.columns;t++)e[t]/=this.rows;return e;case void 0:return e/this.size;default:throw new Error(`invalid option: ${t}`)}}variance(t,e={}){if("object"==typeof t&&(e=t,t=void 0),"object"!=typeof e)throw new TypeError("options must be an object");const{unbiased:r=!0,mean:n=this.mean(t)}=e;if("boolean"!=typeof r)throw new TypeError("unbiased must be a boolean");switch(t){case"row":if(!Zt(n))throw new TypeError("mean must be an array");return function(t,e,r){const n=t.rows,o=t.columns,i=[];for(let s=0;s<n;s++){let n=0,a=0,u=0;for(let e=0;e<o;e++)u=t.get(s,e)-r[s],n+=u,a+=u*u;e?i.push((a-n*n/o)/(o-1)):i.push((a-n*n/o)/o)}return i}(this,r,n);case"column":if(!Zt(n))throw new TypeError("mean must be an array");return function(t,e,r){const n=t.rows,o=t.columns,i=[];for(let s=0;s<o;s++){let o=0,a=0,u=0;for(let e=0;e<n;e++)u=t.get(e,s)-r[s],o+=u,a+=u*u;e?i.push((a-o*o/n)/(n-1)):i.push((a-o*o/n)/n)}return i}(this,r,n);case void 0:if("number"!=typeof n)throw new TypeError("mean must be a number");return function(t,e,r){const n=t.rows,o=t.columns,i=n*o;let s=0,a=0,u=0;for(let e=0;e<n;e++)for(let n=0;n<o;n++)u=t.get(e,n)-r,s+=u,a+=u*u;return e?(a-s*s/i)/(i-1):(a-s*s/i)/i}(this,r,n);default:throw new Error(`invalid option: ${t}`)}}standardDeviation(t,e){"object"==typeof t&&(e=t,t=void 0);const r=this.variance(t,e);if(void 0===t)return Math.sqrt(r);for(let t=0;t<r.length;t++)r[t]=Math.sqrt(r[t]);return r}center(t,e={}){if("object"==typeof t&&(e=t,t=void 0),"object"!=typeof e)throw new TypeError("options must be an object");const{center:r=this.mean(t)}=e;switch(t){case"row":if(!Zt(r))throw new TypeError("center must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let n=0;n<t.columns;n++)t.set(r,n,t.get(r,n)-e[r])}(this,r),this;case"column":if(!Zt(r))throw new TypeError("center must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let n=0;n<t.columns;n++)t.set(r,n,t.get(r,n)-e[n])}(this,r),this;case void 0:if("number"!=typeof r)throw new TypeError("center must be a number");return function(t,e){for(let r=0;r<t.rows;r++)for(let n=0;n<t.columns;n++)t.set(r,n,t.get(r,n)-e)}(this,r),this;default:throw new Error(`invalid option: ${t}`)}}scale(t,e={}){if("object"==typeof t&&(e=t,t=void 0),"object"!=typeof e)throw new TypeError("options must be an object");let r=e.scale;switch(t){case"row":if(void 0===r)r=function(t){const e=[];for(let r=0;r<t.rows;r++){let n=0;for(let e=0;e<t.columns;e++)n+=Math.pow(t.get(r,e),2)/(t.columns-1);e.push(Math.sqrt(n))}return e}(this);else if(!Zt(r))throw new TypeError("scale must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let n=0;n<t.columns;n++)t.set(r,n,t.get(r,n)/e[r])}(this,r),this;case"column":if(void 0===r)r=function(t){const e=[];for(let r=0;r<t.columns;r++){let n=0;for(let e=0;e<t.rows;e++)n+=Math.pow(t.get(e,r),2)/(t.rows-1);e.push(Math.sqrt(n))}return e}(this);else if(!Zt(r))throw new TypeError("scale must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let n=0;n<t.columns;n++)t.set(r,n,t.get(r,n)/e[n])}(this,r),this;case void 0:if(void 0===r)r=function(t){const e=t.size-1;let r=0;for(let n=0;n<t.columns;n++)for(let o=0;o<t.rows;o++)r+=Math.pow(t.get(o,n),2)/e;return Math.sqrt(r)}(this);else if("number"!=typeof r)throw new TypeError("scale must be a number");return function(t,e){for(let r=0;r<t.rows;r++)for(let n=0;n<t.columns;n++)t.set(r,n,t.get(r,n)/e)}(this,r),this;default:throw new Error(`invalid option: ${t}`)}}toString(t){return ne(this,t)}}function pe(t,e){return t-e}ge.prototype.klass="Matrix","undefined"!=typeof Symbol&&(ge.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return ne(this)}),ge.random=ge.rand,ge.randomInt=ge.randInt,ge.diagonal=ge.diag,ge.prototype.diagonal=ge.prototype.diag,ge.identity=ge.eye,ge.prototype.negate=ge.prototype.neg,ge.prototype.tensorProduct=ge.prototype.kroneckerProduct;class me extends ge{constructor(t,e){if(super(),me.isMatrix(t))return t.clone();if(Number.isInteger(t)&&t>=0){if(this.data=[],!(Number.isInteger(e)&&e>=0))throw new TypeError("nColumns must be a positive integer");for(let r=0;r<t;r++)this.data.push(new Float64Array(e))}else{if(!Zt(t))throw new TypeError("First argument must be a positive number or an array");{const r=t;if("number"!=typeof(e=(t=r.length)?r[0].length:0))throw new TypeError("Data must be a 2D array with at least one element");this.data=[];for(let n=0;n<t;n++){if(r[n].length!==e)throw new RangeError("Inconsistent array dimensions");if(!r[n].every((t=>"number"==typeof t)))throw new TypeError("Input data contains non-numeric values");this.data.push(Float64Array.from(r[n]))}}}this.rows=t,this.columns=e}set(t,e,r){return this.data[t][e]=r,this}get(t,e){return this.data[t][e]}removeRow(t){return se(this,t),this.data.splice(t,1),this.rows-=1,this}addRow(t,e){return void 0===e&&(e=t,t=this.rows),se(this,t,!0),e=Float64Array.from(ue(this,e)),this.data.splice(t,0,e),this.rows+=1,this}removeColumn(t){ae(this,t);for(let e=0;e<this.rows;e++){const r=new Float64Array(this.columns-1);for(let n=0;n<t;n++)r[n]=this.data[e][n];for(let n=t+1;n<this.columns;n++)r[n-1]=this.data[e][n];this.data[e]=r}return this.columns-=1,this}addColumn(t,e){void 0===e&&(e=t,t=this.columns),ae(this,t,!0),e=he(this,e);for(let r=0;r<this.rows;r++){const n=new Float64Array(this.columns+1);let o=0;for(;o<t;o++)n[o]=this.data[r][o];for(n[o++]=e[r];o<this.columns+1;o++)n[o]=this.data[r][o-1];this.data[r]=n}return this.columns+=1,this}}!function(t,e){t.prototype.add=function(t){return"number"==typeof t?this.addS(t):this.addM(t)},t.prototype.addS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t);return this},t.prototype.addM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t.get(e,r));return this},t.add=function(t,r){return new e(t).add(r)},t.prototype.sub=function(t){return"number"==typeof t?this.subS(t):this.subM(t)},t.prototype.subS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t);return this},t.prototype.subM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t.get(e,r));return this},t.sub=function(t,r){return new e(t).sub(r)},t.prototype.subtract=t.prototype.sub,t.prototype.subtractS=t.prototype.subS,t.prototype.subtractM=t.prototype.subM,t.subtract=t.sub,t.prototype.mul=function(t){return"number"==typeof t?this.mulS(t):this.mulM(t)},t.prototype.mulS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t);return this},t.prototype.mulM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t.get(e,r));return this},t.mul=function(t,r){return new e(t).mul(r)},t.prototype.multiply=t.prototype.mul,t.prototype.multiplyS=t.prototype.mulS,t.prototype.multiplyM=t.prototype.mulM,t.multiply=t.mul,t.prototype.div=function(t){return"number"==typeof t?this.divS(t):this.divM(t)},t.prototype.divS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t);return this},t.prototype.divM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t.get(e,r));return this},t.div=function(t,r){return new e(t).div(r)},t.prototype.divide=t.prototype.div,t.prototype.divideS=t.prototype.divS,t.prototype.divideM=t.prototype.divM,t.divide=t.div,t.prototype.mod=function(t){return"number"==typeof t?this.modS(t):this.modM(t)},t.prototype.modS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)%t);return this},t.prototype.modM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)%t.get(e,r));return this},t.mod=function(t,r){return new e(t).mod(r)},t.prototype.modulus=t.prototype.mod,t.prototype.modulusS=t.prototype.modS,t.prototype.modulusM=t.prototype.modM,t.modulus=t.mod,t.prototype.and=function(t){return"number"==typeof t?this.andS(t):this.andM(t)},t.prototype.andS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)&t);return this},t.prototype.andM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)&t.get(e,r));return this},t.and=function(t,r){return new e(t).and(r)},t.prototype.or=function(t){return"number"==typeof t?this.orS(t):this.orM(t)},t.prototype.orS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)|t);return this},t.prototype.orM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)|t.get(e,r));return this},t.or=function(t,r){return new e(t).or(r)},t.prototype.xor=function(t){return"number"==typeof t?this.xorS(t):this.xorM(t)},t.prototype.xorS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)^t);return this},t.prototype.xorM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)^t.get(e,r));return this},t.xor=function(t,r){return new e(t).xor(r)},t.prototype.leftShift=function(t){return"number"==typeof t?this.leftShiftS(t):this.leftShiftM(t)},t.prototype.leftShiftS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)<<t);return this},t.prototype.leftShiftM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)<<t.get(e,r));return this},t.leftShift=function(t,r){return new e(t).leftShift(r)},t.prototype.signPropagatingRightShift=function(t){return"number"==typeof t?this.signPropagatingRightShiftS(t):this.signPropagatingRightShiftM(t)},t.prototype.signPropagatingRightShiftS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>t);return this},t.prototype.signPropagatingRightShiftM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>t.get(e,r));return this},t.signPropagatingRightShift=function(t,r){return new e(t).signPropagatingRightShift(r)},t.prototype.rightShift=function(t){return"number"==typeof t?this.rightShiftS(t):this.rightShiftM(t)},t.prototype.rightShiftS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>>t);return this},t.prototype.rightShiftM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>>t.get(e,r));return this},t.rightShift=function(t,r){return new e(t).rightShift(r)},t.prototype.zeroFillRightShift=t.prototype.rightShift,t.prototype.zeroFillRightShiftS=t.prototype.rightShiftS,t.prototype.zeroFillRightShiftM=t.prototype.rightShiftM,t.zeroFillRightShift=t.rightShift,t.prototype.not=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,~this.get(t,e));return this},t.not=function(t){return new e(t).not()},t.prototype.abs=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.abs(this.get(t,e)));return this},t.abs=function(t){return new e(t).abs()},t.prototype.acos=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.acos(this.get(t,e)));return this},t.acos=function(t){return new e(t).acos()},t.prototype.acosh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.acosh(this.get(t,e)));return this},t.acosh=function(t){return new e(t).acosh()},t.prototype.asin=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.asin(this.get(t,e)));return this},t.asin=function(t){return new e(t).asin()},t.prototype.asinh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.asinh(this.get(t,e)));return this},t.asinh=function(t){return new e(t).asinh()},t.prototype.atan=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.atan(this.get(t,e)));return this},t.atan=function(t){return new e(t).atan()},t.prototype.atanh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.atanh(this.get(t,e)));return this},t.atanh=function(t){return new e(t).atanh()},t.prototype.cbrt=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.cbrt(this.get(t,e)));return this},t.cbrt=function(t){return new e(t).cbrt()},t.prototype.ceil=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.ceil(this.get(t,e)));return this},t.ceil=function(t){return new e(t).ceil()},t.prototype.clz32=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.clz32(this.get(t,e)));return this},t.clz32=function(t){return new e(t).clz32()},t.prototype.cos=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.cos(this.get(t,e)));return this},t.cos=function(t){return new e(t).cos()},t.prototype.cosh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.cosh(this.get(t,e)));return this},t.cosh=function(t){return new e(t).cosh()},t.prototype.exp=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.exp(this.get(t,e)));return this},t.exp=function(t){return new e(t).exp()},t.prototype.expm1=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.expm1(this.get(t,e)));return this},t.expm1=function(t){return new e(t).expm1()},t.prototype.floor=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.floor(this.get(t,e)));return this},t.floor=function(t){return new e(t).floor()},t.prototype.fround=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.fround(this.get(t,e)));return this},t.fround=function(t){return new e(t).fround()},t.prototype.log=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log(this.get(t,e)));return this},t.log=function(t){return new e(t).log()},t.prototype.log1p=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log1p(this.get(t,e)));return this},t.log1p=function(t){return new e(t).log1p()},t.prototype.log10=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log10(this.get(t,e)));return this},t.log10=function(t){return new e(t).log10()},t.prototype.log2=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log2(this.get(t,e)));return this},t.log2=function(t){return new e(t).log2()},t.prototype.round=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.round(this.get(t,e)));return this},t.round=function(t){return new e(t).round()},t.prototype.sign=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sign(this.get(t,e)));return this},t.sign=function(t){return new e(t).sign()},t.prototype.sin=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sin(this.get(t,e)));return this},t.sin=function(t){return new e(t).sin()},t.prototype.sinh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sinh(this.get(t,e)));return this},t.sinh=function(t){return new e(t).sinh()},t.prototype.sqrt=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sqrt(this.get(t,e)));return this},t.sqrt=function(t){return new e(t).sqrt()},t.prototype.tan=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.tan(this.get(t,e)));return this},t.tan=function(t){return new e(t).tan()},t.prototype.tanh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.tanh(this.get(t,e)));return this},t.tanh=function(t){return new e(t).tanh()},t.prototype.trunc=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.trunc(this.get(t,e)));return this},t.trunc=function(t){return new e(t).trunc()},t.pow=function(t,r){return new e(t).pow(r)},t.prototype.pow=function(t){return"number"==typeof t?this.powS(t):this.powM(t)},t.prototype.powS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,Math.pow(this.get(e,r),t));return this},t.prototype.powM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,Math.pow(this.get(e,r),t.get(e,r)));return this}}(ge,me);class ye extends ge{constructor(t){super(),this.data=t,this.rows=t.length,this.columns=t[0].length}set(t,e,r){return this.data[t][e]=r,this}get(t,e){return this.data[t][e]}}function we(t,e){let r=0;return Math.abs(t)>Math.abs(e)?(r=e/t,Math.abs(t)*Math.sqrt(1+r*r)):0!==e?(r=t/e,Math.abs(e)*Math.sqrt(1+r*r)):0}class ve{constructor(t,e={}){if((t=ye.checkMatrix(t)).isEmpty())throw new Error("Matrix must be non-empty");let r=t.rows,n=t.columns;const{computeLeftSingularVectors:o=!0,computeRightSingularVectors:i=!0,autoTranspose:s=!1}=e;let a,u=Boolean(o),h=Boolean(i),l=!1;if(r<n)if(s){a=t.transpose(),r=a.rows,n=a.columns,l=!0;let e=u;u=h,h=e}else a=t.clone(),console.warn("Computing SVD on a matrix with more columns than rows. Consider enabling autoTranspose");else a=t.clone();let c=Math.min(r,n),f=Math.min(r+1,n),d=new Float64Array(f),g=new me(r,c),p=new me(n,n),m=new Float64Array(n),y=new Float64Array(r),w=new Float64Array(f);for(let t=0;t<f;t++)w[t]=t;let v=Math.min(r-1,n),x=Math.max(0,Math.min(n-2,r)),b=Math.max(v,x);for(let t=0;t<b;t++){if(t<v){d[t]=0;for(let e=t;e<r;e++)d[t]=we(d[t],a.get(e,t));if(0!==d[t]){a.get(t,t)<0&&(d[t]=-d[t]);for(let e=t;e<r;e++)a.set(e,t,a.get(e,t)/d[t]);a.set(t,t,a.get(t,t)+1)}d[t]=-d[t]}for(let e=t+1;e<n;e++){if(t<v&&0!==d[t]){let n=0;for(let o=t;o<r;o++)n+=a.get(o,t)*a.get(o,e);n=-n/a.get(t,t);for(let o=t;o<r;o++)a.set(o,e,a.get(o,e)+n*a.get(o,t))}m[e]=a.get(t,e)}if(u&&t<v)for(let e=t;e<r;e++)g.set(e,t,a.get(e,t));if(t<x){m[t]=0;for(let e=t+1;e<n;e++)m[t]=we(m[t],m[e]);if(0!==m[t]){m[t+1]<0&&(m[t]=0-m[t]);for(let e=t+1;e<n;e++)m[e]/=m[t];m[t+1]+=1}if(m[t]=-m[t],t+1<r&&0!==m[t]){for(let e=t+1;e<r;e++)y[e]=0;for(let e=t+1;e<r;e++)for(let r=t+1;r<n;r++)y[e]+=m[r]*a.get(e,r);for(let e=t+1;e<n;e++){let n=-m[e]/m[t+1];for(let o=t+1;o<r;o++)a.set(o,e,a.get(o,e)+n*y[o])}}if(h)for(let e=t+1;e<n;e++)p.set(e,t,m[e])}}let M=Math.min(n,r+1);if(v<n&&(d[v]=a.get(v,v)),r<M&&(d[M-1]=0),x+1<M&&(m[x]=a.get(x,M-1)),m[M-1]=0,u){for(let t=v;t<c;t++){for(let e=0;e<r;e++)g.set(e,t,0);g.set(t,t,1)}for(let t=v-1;t>=0;t--)if(0!==d[t]){for(let e=t+1;e<c;e++){let n=0;for(let o=t;o<r;o++)n+=g.get(o,t)*g.get(o,e);n=-n/g.get(t,t);for(let o=t;o<r;o++)g.set(o,e,g.get(o,e)+n*g.get(o,t))}for(let e=t;e<r;e++)g.set(e,t,-g.get(e,t));g.set(t,t,1+g.get(t,t));for(let e=0;e<t-1;e++)g.set(e,t,0)}else{for(let e=0;e<r;e++)g.set(e,t,0);g.set(t,t,1)}}if(h)for(let t=n-1;t>=0;t--){if(t<x&&0!==m[t])for(let e=t+1;e<n;e++){let r=0;for(let o=t+1;o<n;o++)r+=p.get(o,t)*p.get(o,e);r=-r/p.get(t+1,t);for(let o=t+1;o<n;o++)p.set(o,e,p.get(o,e)+r*p.get(o,t))}for(let e=0;e<n;e++)p.set(e,t,0);p.set(t,t,1)}let E=M-1,N=0,S=Number.EPSILON;for(;M>0;){let t,e;for(t=M-2;t>=-1&&-1!==t;t--){const e=Number.MIN_VALUE+S*Math.abs(d[t]+Math.abs(d[t+1]));if(Math.abs(m[t])<=e||Number.isNaN(m[t])){m[t]=0;break}}if(t===M-2)e=4;else{let r;for(r=M-1;r>=t&&r!==t;r--){let e=(r!==M?Math.abs(m[r]):0)+(r!==t+1?Math.abs(m[r-1]):0);if(Math.abs(d[r])<=S*e){d[r]=0;break}}r===t?e=3:r===M-1?e=1:(e=2,t=r)}switch(t++,e){case 1:{let e=m[M-2];m[M-2]=0;for(let r=M-2;r>=t;r--){let o=we(d[r],e),i=d[r]/o,s=e/o;if(d[r]=o,r!==t&&(e=-s*m[r-1],m[r-1]=i*m[r-1]),h)for(let t=0;t<n;t++)o=i*p.get(t,r)+s*p.get(t,M-1),p.set(t,M-1,-s*p.get(t,r)+i*p.get(t,M-1)),p.set(t,r,o)}break}case 2:{let e=m[t-1];m[t-1]=0;for(let n=t;n<M;n++){let o=we(d[n],e),i=d[n]/o,s=e/o;if(d[n]=o,e=-s*m[n],m[n]=i*m[n],u)for(let e=0;e<r;e++)o=i*g.get(e,n)+s*g.get(e,t-1),g.set(e,t-1,-s*g.get(e,n)+i*g.get(e,t-1)),g.set(e,n,o)}break}case 3:{const e=Math.max(Math.abs(d[M-1]),Math.abs(d[M-2]),Math.abs(m[M-2]),Math.abs(d[t]),Math.abs(m[t])),o=d[M-1]/e,i=d[M-2]/e,s=m[M-2]/e,a=d[t]/e,l=m[t]/e,c=((i+o)*(i-o)+s*s)/2,f=o*s*(o*s);let y=0;0===c&&0===f||(y=c<0?0-Math.sqrt(c*c+f):Math.sqrt(c*c+f),y=f/(c+y));let w=(a+o)*(a-o)+y,v=a*l;for(let e=t;e<M-1;e++){let o=we(w,v);0===o&&(o=Number.MIN_VALUE);let i=w/o,s=v/o;if(e!==t&&(m[e-1]=o),w=i*d[e]+s*m[e],m[e]=i*m[e]-s*d[e],v=s*d[e+1],d[e+1]=i*d[e+1],h)for(let t=0;t<n;t++)o=i*p.get(t,e)+s*p.get(t,e+1),p.set(t,e+1,-s*p.get(t,e)+i*p.get(t,e+1)),p.set(t,e,o);if(o=we(w,v),0===o&&(o=Number.MIN_VALUE),i=w/o,s=v/o,d[e]=o,w=i*m[e]+s*d[e+1],d[e+1]=-s*m[e]+i*d[e+1],v=s*m[e+1],m[e+1]=i*m[e+1],u&&e<r-1)for(let t=0;t<r;t++)o=i*g.get(t,e)+s*g.get(t,e+1),g.set(t,e+1,-s*g.get(t,e)+i*g.get(t,e+1)),g.set(t,e,o)}m[M-2]=w,N+=1;break}case 4:if(d[t]<=0&&(d[t]=d[t]<0?-d[t]:0,h))for(let e=0;e<=E;e++)p.set(e,t,-p.get(e,t));for(;t<E&&!(d[t]>=d[t+1]);){let e=d[t];if(d[t]=d[t+1],d[t+1]=e,h&&t<n-1)for(let r=0;r<n;r++)e=p.get(r,t+1),p.set(r,t+1,p.get(r,t)),p.set(r,t,e);if(u&&t<r-1)for(let n=0;n<r;n++)e=g.get(n,t+1),g.set(n,t+1,g.get(n,t)),g.set(n,t,e);t++}N=0,M--}}if(l){let t=p;p=g,g=t}this.m=r,this.n=n,this.s=d,this.U=g,this.V=p}solve(t){let e=t,r=this.threshold,n=this.s.length,o=me.zeros(n,n);for(let t=0;t<n;t++)Math.abs(this.s[t])<=r?o.set(t,t,0):o.set(t,t,1/this.s[t]);let i=this.U,s=this.rightSingularVectors,a=s.mmul(o),u=s.rows,h=i.rows,l=me.zeros(u,h);for(let t=0;t<u;t++)for(let e=0;e<h;e++){let r=0;for(let o=0;o<n;o++)r+=a.get(t,o)*i.get(e,o);l.set(t,e,r)}return l.mmul(e)}solveForDiagonal(t){return this.solve(me.diag(t))}inverse(){let t=this.V,e=this.threshold,r=t.rows,n=t.columns,o=new me(r,this.s.length);for(let i=0;i<r;i++)for(let r=0;r<n;r++)Math.abs(this.s[r])>e&&o.set(i,r,t.get(i,r)/this.s[r]);let i=this.U,s=i.rows,a=i.columns,u=new me(r,s);for(let t=0;t<r;t++)for(let e=0;e<s;e++){let r=0;for(let n=0;n<a;n++)r+=o.get(t,n)*i.get(e,n);u.set(t,e,r)}return u}get condition(){return this.s[0]/this.s[Math.min(this.m,this.n)-1]}get norm2(){return this.s[0]}get rank(){let t=Math.max(this.m,this.n)*this.s[0]*Number.EPSILON,e=0,r=this.s;for(let n=0,o=r.length;n<o;n++)r[n]>t&&e++;return e}get diagonal(){return Array.from(this.s)}get threshold(){return Number.EPSILON/2*Math.max(this.m,this.n)*this.s[0]}get leftSingularVectors(){return this.U}get rightSingularVectors(){return this.V}get diagonalMatrix(){return me.diag(this.s)}}var xe={center:[0,0],linkDistance:50},be=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="mds",this.options=e(e({},xe),t)}return t.prototype.execute=function(t,e){return this.genericMDSLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericMDSLayout(!0,t,e)},t.prototype.genericMDSLayout=function(t,r,n){var o=e(e({},this.options),n),i=o.center,s=void 0===i?[0,0]:i,a=o.linkDistance,u=void 0===a?50:a,h=o.layoutInvisibles,l=o.onLayoutEnd,d=r.getAllNodes(),g=r.getAllEdges();if(h||(d=d.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e})),g=g.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e}))),!d||0===d.length){var p={nodes:[],edges:g};return null==l||l(p),p}if(1===d.length){t&&r.mergeNodeData(d[0].id,{x:s[0],y:s[1]});var y={nodes:[e(e({},d[0]),{data:e(e({},d[0].data),{x:s[0],y:s[1]})})],edges:g};return null==l||l(y),y}var w=f({nodes:d,edges:g},!1),v=c(w);Me(v);var x=function(t,e){var r=[];return t.forEach((function(t){var n=[];t.forEach((function(t){n.push(t*e)})),r.push(n)})),r}(v,u),b=Ee(x),M=[];b.forEach((function(t,e){var r=m(d[e]);r.data.x=t[0]+s[0],r.data.y=t[1]+s[1],M.push(r)})),t&&M.forEach((function(t){return r.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}));var E={nodes:M,edges:g};return null==l||l(E),E},t}(),Me=function(t){var e=-999999;t.forEach((function(t){t.forEach((function(t){t!==1/0&&e<t&&(e=t)}))})),t.forEach((function(r,n){r.forEach((function(r,o){r===1/0&&(t[n][o]=e)}))}))},Ee=function(t){var e=me.mul(me.pow(t,2),-.5),r=e.mean("row"),n=e.mean("column"),o=e.mean();e.add(o).subRowVector(r).subColumnVector(n);var i=new ve(e),s=me.sqrt(i.diagonalMatrix).diagonal();return i.leftSingularVectors.toJSON().map((function(t){return me.mul([t],[s]).toJSON()[0].splice(0,2)}))},Ne={iterations:10,height:10,width:10,speed:100,gravity:10,k:5},Se=function(t,e,r,n,o,i){e.forEach((function(s,a){r[a]={x:0,y:0},e.forEach((function(e,u){if(a!==u&&o[a]===o[u]){var h=s.x-e.x,l=s.y-e.y,c=Math.sqrt(h*h+l*l);if(0===c){c=1;var f=a>u?1:-1;h=.01*f,l=.01*f}if(c<i(t[a])/2+i(t[u])/2){var d=n*n/c;r[a].x+=h/c*d,r[a].y+=l/c*d}}}))}))},ke=function(t,e,r,n,o,i,s,a){var u=i||s/10;return n&&e.forEach((function(e,r){var n=t[r].x-t[o].x,i=t[r].y-t[o].y,s=Math.sqrt(n*n+i*i),a=i/s,u=-n/s,h=Math.sqrt(e.x*e.x+e.y*e.y),l=Math.acos((a*e.x+u*e.y)/h);l>Math.PI/2&&(l-=Math.PI/2,a*=-1,u*=-1);var c=Math.cos(l)*h;e.x=a*c,e.y=u*c})),t.forEach((function(i,s){if(s!==o){var h=Math.sqrt(e[s].x*e[s].x+e[s].y*e[s].y);if(h>0&&s!==o){var l=Math.min(u*(r/800),h);if(i.x+=e[s].x/h*l,i.y+=e[s].y/h*l,n){var c=i.x-t[o].x,f=i.y-t[o].y,d=Math.sqrt(c*c+f*f);c=c/d*a[s],f=f/d*a[s],i.x=t[o].x+c,i.y=t[o].y+f}}}})),t},Ae={maxIteration:1e3,focusNode:null,unitRadius:null,linkDistance:50,preventOverlap:!1,strictRadial:!0,maxPreventOverlapIteration:200,sortStrength:10},De=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="radial",this.options=e(e({},Ae),t)}return t.prototype.execute=function(t,e){return this.genericRadialLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericRadialLayout(!0,t,e)},t.prototype.genericRadialLayout=function(t,r,n){var o=e(e({},this.options),n),u=o.width,h=o.height,l=o.center,d=o.focusNode,g=o.unitRadius,p=o.nodeSize,y=o.nodeSpacing,w=o.strictRadial,v=o.preventOverlap,x=o.maxPreventOverlapIteration,b=o.sortBy,M=o.linkDistance,E=void 0===M?50:M,N=o.sortStrength,S=void 0===N?10:N,k=o.maxIteration,A=void 0===k?1e3:k,D=o.layoutInvisibles,I=o.onLayoutEnd,_=r.getAllNodes(),R=r.getAllEdges();if(D||(_=_.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e})),R=R.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e}))),!_||0===_.length){var O={nodes:[],edges:R};return null==I||I(O),O}var T=u||"undefined"==typeof window?u:window.innerWidth,z=h||"undefined"==typeof window?h:window.innerHeight,C=l||[T/2,z/2];if(1===_.length){t&&r.mergeNodeData(_[0].id,{x:C[0],y:C[1]});var L={nodes:[e(e({},_[0]),{data:e(e({},_[0].data),{x:C[0],y:C[1]})})],edges:R};return null==I||I(L),L}var P=_[0];if(a(d)){for(var q=0;q<_.length;q++)if(_[q].id===d){P=_[q];break}}else P=d||_[0];var j=Re(_,P.id),V=f({nodes:_,edges:R},!1),F=c(V),U=Te(F,j);Oe(F,j,U+1);var B=F[j],$=T-C[0]>C[0]?C[0]:T-C[0],G=z-C[1]>C[1]?C[1]:z-C[1];0===$&&($=T/2),0===G&&(G=z/2);var H=Math.min($,G),J=Math.max.apply(Math,s([],i(B),!1)),K=[],W=g||H/J;B.forEach((function(t,e){K[e]=t*W}));var Y,Z=Ie(_,F,E,K,W,b,S),X=_e(Z),Q=function(t,e,r){try{var n=me.mul(me.pow(e,2),-.5),o=n.mean("row"),i=n.mean("column"),s=n.mean();n.add(s).subRowVector(o).subColumnVector(i);var a=new ve(n),u=me.sqrt(a.diagonalMatrix).diagonal();return a.leftSingularVectors.toJSON().map((function(e){return me.mul([e],[u]).toJSON()[0].splice(0,t)}))}catch(t){for(var h=[],l=0;l<e.length;l++){var c=Math.random()*r,f=Math.random()*r;h.push([c,f])}return h}}(E,Z,E),tt=Q.map((function(t){var e=i(t,2),r=e[0],n=e[1];return{x:(isNaN(r)?Math.random()*E:r)-Q[j][0],y:(isNaN(n)?Math.random()*E:n)-Q[j][1]}}));if(this.run(A,tt,X,Z,K,j),v){Y=ze(p,y);var et={nodes:_,nodeSizeFunc:Y,positions:tt,radii:K,height:z,width:T,strictRadial:Boolean(w),focusIdx:j,iterations:x||200,k:tt.length/4.5};tt=function(t,r){for(var n=e(e({},Ne),r),o=n.positions,i=n.iterations,s=n.width,a=n.k,u=n.speed,h=void 0===u?100:u,l=n.strictRadial,c=n.focusIdx,f=n.radii,d=void 0===f?[]:f,g=n.nodeSizeFunc,p=t.getAllNodes(),m=[],y=s/10,w=0;w<i;w++)o.forEach((function(t,e){m[e]={x:0,y:0}})),Se(p,o,m,a,d,g),ke(o,m,h,l,c,y,s,d);return o}(r,et)}var rt=[];tt.forEach((function(t,e){var r=m(_[e]);r.data.x=t.x+C[0],r.data.y=t.y+C[1],rt.push(r)})),t&&rt.forEach((function(t){return r.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}));var nt={nodes:rt,edges:R};return null==I||I(nt),nt},t.prototype.run=function(t,e,r,n,o,i){for(var s=0;s<=t;s++){var a=s/t;this.oneIteration(a,e,o,n,r,i)}},t.prototype.oneIteration=function(t,e,r,n,o,i){var s=1-t;e.forEach((function(a,u){var h=d(a,{x:0,y:0}),l=0===h?0:1/h;if(u!==i){var c=0,f=0,g=0;e.forEach((function(t,e){if(u!==e){var r=d(a,t),i=0===r?0:1/r,s=n[e][u];g+=o[u][e],c+=o[u][e]*(t.x+s*(a.x-t.x)*i),f+=o[u][e]*(t.y+s*(a.y-t.y)*i)}}));var p=0===r[u]?0:1/r[u];g*=s,g+=t*p*p,c*=s,c+=t*p*a.x*l,a.x=c/g,f*=s,f+=t*p*a.y*l,a.y=f/g}}))},t}(),Ie=function(t,e,r,n,o,i,s){if(!t)return[];var u=[];if(e){var h={};e.forEach((function(e,l){var c=[];e.forEach((function(e,u){var f,d;if(l===u)c.push(0);else if(n[l]===n[u])if("data"===i)c.push(e*(Math.abs(l-u)*s)/(n[l]/o));else if(i){var g=void 0,p=void 0;if(h[t[l].id])g=h[t[l].id];else{var m=("id"===i?t[l].id:null===(f=t[l].data)||void 0===f?void 0:f[i])||0;g=a(m)?m.charCodeAt(0):m,h[t[l].id]=g}h[t[u].id]?p=h[t[u].id]:(m=("id"===i?t[u].id:null===(d=t[u].data)||void 0===d?void 0:d[i])||0,p=a(m)?m.charCodeAt(0):m,h[t[u].id]=p),c.push(e*(Math.abs(g-p)*s)/(n[l]/o))}else c.push(e*r/(n[l]/o));else{var y=(r+o)/2;c.push(e*y)}})),u.push(c)}))}return u},_e=function(t){for(var e=t.length,r=t[0].length,n=[],o=0;o<e;o++){for(var i=[],s=0;s<r;s++)0!==t[o][s]?i.push(1/(t[o][s]*t[o][s])):i.push(0);n.push(i)}return n},Re=function(t,e){var r=-1;return t.forEach((function(t,n){t.id===e&&(r=n)})),Math.max(r,0)},Oe=function(t,e,r){for(var n=t.length,o=0;o<n;o++)if(t[e][o]===1/0){t[e][o]=r,t[o][e]=r;for(var i=0;i<n;i++)t[o][i]!==1/0&&t[e][i]===1/0&&(t[e][i]=r+t[o][i],t[i][e]=r+t[o][i])}for(o=0;o<n;o++)if(o!==e)for(i=0;i<n;i++)if(t[o][i]===1/0){var s=Math.abs(t[e][o]-t[e][i]);s=0===s?1:s,t[o][i]=s}},Te=function(t,e){for(var r=0,n=0;n<t[e].length;n++)t[e][n]!==1/0&&(r=t[e][n]>r?t[e][n]:r);return r},ze=function(t,e){var r;return r=l(e)?function(){return e}:y(e)?e:function(){return 0},t?h(t)?function(e){return(t[0]>t[1]?t[0]:t[1])+r(e)}:function(e){return t+r(e)}:function(t){var e,n;return(null===(e=t.data)||void 0===e?void 0:e.bboxSize)?Math.max(t.data.bboxSize[0],t.data.bboxSize[1])+r(t):(null===(n=t.data)||void 0===n?void 0:n.size)?h(t.data.size)?Math.max(t.data.size[0],t.data.size[1])+r(t):g(t.data.size)?(t.data.size.width>t.data.size.height?t.data.size.width:t.data.size.height)+r(t):t.data.size+r(t):10+r(t)}},Ce={center:[0,0],width:300,height:300},Le=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="random",this.options=e(e({},Ce),t)}return t.prototype.execute=function(t,e){return this.genericRandomLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericRandomLayout(!0,t,e)},t.prototype.genericRandomLayout=function(t,r,n){var o=e(e({},this.options),n),i=o.center,s=o.width,a=o.height,u=o.layoutInvisibles,h=o.onLayoutEnd,l=r.getAllNodes();u||(l=l.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e})));var c=s||"undefined"==typeof window?s:window.innerWidth,f=a||"undefined"==typeof window?a:window.innerHeight,d=i||[c/2,f/2],g=[];l&&l.forEach((function(t){g.push({id:t.id,data:{x:.9*(Math.random()-.5)*c+d[0],y:.9*(Math.random()-.5)*f+d[1]}})})),t&&g.forEach((function(t){return r.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}));var p={nodes:g,edges:r.getAllEdges()};return null==h||h(p),p},t}(),Pe={circular:b,concentric:R,mds:be,random:Le,grid:Bt,radial:De,force:zt,d3force:Dt,fruchterman:Ft};function qe(t,e){Pe[t]=e}})();var o=n.SB,i=n.W1,s=n.jA,a=n.y7,u=n.O2,h=n.Me,l=n.AI,c=n.D4,f=n._5,d=n.y9,g=n.Xp,p=n.qR,m=n.i_;export{o as CircularLayout,i as ConcentricLayout,s as D3ForceLayout,a as ForceLayout,u as FruchtermanLayout,h as GridLayout,l as MDSLayout,c as RadialLayout,f as RandomLayout,d as Supervisor,g as SupervisorEvent,p as registerLayout,m as registry};
|
|
1
|
+
var t={161:t=>{var e=Object.prototype.hasOwnProperty,r="~";function n(){}function o(t,e,r){this.fn=t,this.context=e,this.once=r||!1}function i(t,e,n,i,s){if("function"!=typeof n)throw new TypeError("The listener must be a function");var a=new o(n,i||t,s),u=r?r+e:e;return t._events[u]?t._events[u].fn?t._events[u]=[t._events[u],a]:t._events[u].push(a):(t._events[u]=a,t._eventsCount++),t}function s(t,e){0==--t._eventsCount?t._events=new n:delete t._events[e]}function a(){this._events=new n,this._eventsCount=0}Object.create&&(n.prototype=Object.create(null),(new n).__proto__||(r=!1)),a.prototype.eventNames=function(){var t,n,o=[];if(0===this._eventsCount)return o;for(n in t=this._events)e.call(t,n)&&o.push(r?n.slice(1):n);return Object.getOwnPropertySymbols?o.concat(Object.getOwnPropertySymbols(t)):o},a.prototype.listeners=function(t){var e=r?r+t:t,n=this._events[e];if(!n)return[];if(n.fn)return[n.fn];for(var o=0,i=n.length,s=new Array(i);o<i;o++)s[o]=n[o].fn;return s},a.prototype.listenerCount=function(t){var e=r?r+t:t,n=this._events[e];return n?n.fn?1:n.length:0},a.prototype.emit=function(t,e,n,o,i,s){var a=r?r+t:t;if(!this._events[a])return!1;var u,h,l=this._events[a],c=arguments.length;if(l.fn){switch(l.once&&this.removeListener(t,l.fn,void 0,!0),c){case 1:return l.fn.call(l.context),!0;case 2:return l.fn.call(l.context,e),!0;case 3:return l.fn.call(l.context,e,n),!0;case 4:return l.fn.call(l.context,e,n,o),!0;case 5:return l.fn.call(l.context,e,n,o,i),!0;case 6:return l.fn.call(l.context,e,n,o,i,s),!0}for(h=1,u=new Array(c-1);h<c;h++)u[h-1]=arguments[h];l.fn.apply(l.context,u)}else{var f,d=l.length;for(h=0;h<d;h++)switch(l[h].once&&this.removeListener(t,l[h].fn,void 0,!0),c){case 1:l[h].fn.call(l[h].context);break;case 2:l[h].fn.call(l[h].context,e);break;case 3:l[h].fn.call(l[h].context,e,n);break;case 4:l[h].fn.call(l[h].context,e,n,o);break;default:if(!u)for(f=1,u=new Array(c-1);f<c;f++)u[f-1]=arguments[f];l[h].fn.apply(l[h].context,u)}}return!0},a.prototype.on=function(t,e,r){return i(this,t,e,r,!1)},a.prototype.once=function(t,e,r){return i(this,t,e,r,!0)},a.prototype.removeListener=function(t,e,n,o){var i=r?r+t:t;if(!this._events[i])return this;if(!e)return s(this,i),this;var a=this._events[i];if(a.fn)a.fn!==e||o&&!a.once||n&&a.context!==n||s(this,i);else{for(var u=0,h=[],l=a.length;u<l;u++)(a[u].fn!==e||o&&!a[u].once||n&&a[u].context!==n)&&h.push(a[u]);h.length?this._events[i]=1===h.length?h[0]:h:s(this,i)}return this},a.prototype.removeAllListeners=function(t){var e;return t?(e=r?r+t:t,this._events[e]&&s(this,e)):(this._events=new n,this._eventsCount=0),this},a.prototype.off=a.prototype.removeListener,a.prototype.addListener=a.prototype.on,a.prefixed=r,a.EventEmitter=a,t.exports=a},825:(t,e,r)=>{var n=r(475),o=["stopLayout","calculateLayout"];t.exports=function(){var t=new Worker(URL.createObjectURL(new Blob(['var t={d:(e,r)=>{for(var n in r)t.o(r,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:r[n]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)},e={};t.d(e,{calculateLayout:()=>ze,stopLayout:()=>_e});var r=function(){return r=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var o in e=arguments[r])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},r.apply(this,arguments)};function n(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(t);o<n.length;o++)e.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(t,n[o])&&(r[n[o]]=t[n[o]])}return r}function o(t,e){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var n,o,i=r.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(n=i.next()).done;)s.push(n.value)}catch(t){o={error:t}}finally{try{n&&!n.done&&(r=i.return)&&r.call(i)}finally{if(o)throw o.error}}return s}function i(t,e,r){if(r||2===arguments.length)for(var n,o=0,i=e.length;o<i;o++)!n&&o in e||(n||(n=Array.prototype.slice.call(e,0,o)),n[o]=e[o]);return t.concat(n||Array.prototype.slice.call(e))}Object.create,Object.create;class s{nodeMap=new Map;edgeMap=new Map;inEdgesMap=new Map;outEdgesMap=new Map;treeIndices=new Map;changes=[];batchCount=0;onChanged=()=>{};constructor(t){t&&(t.nodes&&this.addNodes(t.nodes),t.edges&&this.addEdges(t.edges),t.tree&&this.addTree(t.tree),t.onChanged&&(this.onChanged=t.onChanged))}batch=t=>{this.batchCount+=1,t(),this.batchCount-=1,this.batchCount||this.commit()};commit(){const t=this.changes;this.changes=[],this.onChanged({graph:this,changes:t})}reduceChanges(t){let e=[];return t.forEach((t=>{switch(t.type){case"NodeRemoved":{let r=!1;e=e.filter((e=>{if("NodeAdded"===e.type){const n=e.value.id===t.value.id;return n&&(r=!0),!n}return"NodeDataUpdated"===e.type?e.id!==t.value.id:"TreeStructureChanged"!==e.type||e.nodeId!==t.value.id})),r||e.push(t);break}case"EdgeRemoved":{let r=!1;e=e.filter((e=>{if("EdgeAdded"===e.type){const n=e.value.id===t.value.id;return n&&(r=!0),!n}return"EdgeDataUpdated"!==e.type&&"EdgeUpdated"!==e.type||e.id!==t.value.id})),r||e.push(t);break}case"NodeDataUpdated":case"EdgeDataUpdated":case"EdgeUpdated":{const r=e.find((e=>e.type===t.type&&e.id===t.id&&e.propertyName===t.propertyName));r?r.newValue=t.newValue:e.push(t);break}case"TreeStructureDetached":e=e.filter((e=>"TreeStructureAttached"===e.type?e.treeKey!==t.treeKey:"TreeStructureChanged"!==e.type||e.treeKey!==t.treeKey)),e.push(t);break;case"TreeStructureChanged":{const r=e.find((e=>"TreeStructureChanged"===e.type&&e.treeKey===t.treeKey&&e.nodeId===t.nodeId));r?r.newParentId=t.newParentId:e.push(t);break}default:e.push(t)}})),e}checkNodeExistence(t){if(!this.hasNode(t))throw new Error("Node not found for id: "+t)}hasNode(t){return this.nodeMap.has(t)}areNeighbors(t,e){return this.checkNodeExistence(t),this.getNeighbors(e).some((e=>e.id===t))}getNode(t){return this.checkNodeExistence(t),this.nodeMap.get(t)}getRelatedEdges(t,e){this.checkNodeExistence(t);const r=this.inEdgesMap.get(t),n=this.outEdgesMap.get(t);if("in"===e)return Array.from(r);if("out"===e)return Array.from(n);const o=new Set([...r,...n]);return Array.from(o)}getDegree(t,e){return this.getRelatedEdges(t,e).length}getSuccessors(t){const e=this.getRelatedEdges(t,"out").map((t=>t.target));return Array.from(new Set(e)).map((t=>this.getNode(t)))}getPredecessors(t){const e=this.getRelatedEdges(t,"in").map((t=>t.source));return Array.from(new Set(e)).map((t=>this.getNode(t)))}getNeighbors(t){const e=this.getPredecessors(t),r=this.getSuccessors(t);return Array.from(new Set([...e,...r]))}doAddNode(t){if(this.hasNode(t.id))throw new Error("Node already exists: "+t.id);this.nodeMap.set(t.id,t),this.inEdgesMap.set(t.id,new Set),this.outEdgesMap.set(t.id,new Set),this.treeIndices.forEach((e=>{e.childrenMap.set(t.id,new Set)})),this.changes.push({type:"NodeAdded",value:t})}addNodes(t){this.batch((()=>{for(const e of t)this.doAddNode(e)}))}addNode(t){this.addNodes([t])}doRemoveNode(t){const e=this.getNode(t),r=this.inEdgesMap.get(t),n=this.outEdgesMap.get(t);r?.forEach((t=>this.doRemoveEdge(t.id))),n?.forEach((t=>this.doRemoveEdge(t.id))),this.nodeMap.delete(t),this.treeIndices.forEach((e=>{e.childrenMap.get(t)?.forEach((t=>{e.parentMap.delete(t.id)})),e.parentMap.delete(t),e.childrenMap.delete(t)})),this.changes.push({type:"NodeRemoved",value:e})}removeNodes(t){this.batch((()=>{t.forEach((t=>this.doRemoveNode(t)))}))}removeNode(t){this.removeNodes([t])}updateNodeDataProperty(t,e,r){const n=this.getNode(t);this.batch((()=>{const o=n.data[e],i=r;n.data[e]=i,this.changes.push({type:"NodeDataUpdated",id:t,propertyName:e,oldValue:o,newValue:i})}))}mergeNodeData(t,e){this.batch((()=>{Object.entries(e).forEach((([e,r])=>{this.updateNodeDataProperty(t,e,r)}))}))}updateNodeData(...t){const e=t[0],r=this.getNode(e);if("string"==typeof t[1])return void this.updateNodeDataProperty(e,t[1],t[2]);let n;if("function"==typeof t[1]){const e=t[1];n=e(r.data)}else"object"==typeof t[1]&&(n=t[1]);this.batch((()=>{const t=r.data,o=n;r.data=n,this.changes.push({type:"NodeDataUpdated",id:e,oldValue:t,newValue:o})}))}checkEdgeExistence(t){if(!this.hasEdge(t))throw new Error("Edge not found for id: "+t)}hasEdge(t){return this.edgeMap.has(t)}getEdge(t){return this.checkEdgeExistence(t),this.edgeMap.get(t)}getEdgeDetail(t){const e=this.getEdge(t);return{edge:e,source:this.getNode(e.source),target:this.getNode(e.target)}}doAddEdge(t){if(this.hasEdge(t.id))throw new Error("Edge already exists: "+t.id);this.checkNodeExistence(t.source),this.checkNodeExistence(t.target),this.edgeMap.set(t.id,t);const e=this.inEdgesMap.get(t.target),r=this.outEdgesMap.get(t.source);e.add(t),r.add(t),this.changes.push({type:"EdgeAdded",value:t})}addEdges(t){this.batch((()=>{for(const e of t)this.doAddEdge(e)}))}addEdge(t){this.addEdges([t])}doRemoveEdge(t){const e=this.getEdge(t),r=this.outEdgesMap.get(e.source),n=this.inEdgesMap.get(e.target);r.delete(e),n.delete(e),this.edgeMap.delete(t),this.changes.push({type:"EdgeRemoved",value:e})}removeEdges(t){this.batch((()=>{t.forEach((t=>this.doRemoveEdge(t)))}))}removeEdge(t){this.removeEdges([t])}updateEdgeSource(t,e){const r=this.getEdge(t);this.checkNodeExistence(e);const n=r.source,o=e;this.outEdgesMap.get(n).delete(r),this.outEdgesMap.get(o).add(r),r.source=e,this.batch((()=>{this.changes.push({type:"EdgeUpdated",id:t,propertyName:"source",oldValue:n,newValue:o})}))}updateEdgeTarget(t,e){const r=this.getEdge(t);this.checkNodeExistence(e);const n=r.target,o=e;this.inEdgesMap.get(n).delete(r),this.inEdgesMap.get(o).add(r),r.target=e,this.batch((()=>{this.changes.push({type:"EdgeUpdated",id:t,propertyName:"target",oldValue:n,newValue:o})}))}updateEdgeDataProperty(t,e,r){const n=this.getEdge(t);this.batch((()=>{const o=n.data[e],i=r;n.data[e]=i,this.changes.push({type:"EdgeDataUpdated",id:t,propertyName:e,oldValue:o,newValue:i})}))}updateEdgeData(...t){const e=t[0],r=this.getEdge(e);if("string"==typeof t[1])return void this.updateEdgeDataProperty(e,t[1],t[2]);let n;if("function"==typeof t[1]){const e=t[1];n=e(r.data)}else"object"==typeof t[1]&&(n=t[1]);this.batch((()=>{const t=r.data,o=n;r.data=n,this.changes.push({type:"EdgeDataUpdated",id:e,oldValue:t,newValue:o})}))}mergeEdgeData(t,e){this.batch((()=>{Object.entries(e).forEach((([e,r])=>{this.updateEdgeDataProperty(t,e,r)}))}))}checkTreeExistence(t){if(!this.treeIndices.has(t))throw new Error("Tree structure not found for treeKey: "+t)}attachTreeStructure(t){this.treeIndices.has(t)||(this.treeIndices.set(t,{parentMap:new Map,childrenMap:new Map}),this.batch((()=>{this.changes.push({type:"TreeStructureAttached",treeKey:t})})))}detachTreeStructure(t){this.checkTreeExistence(t),this.treeIndices.delete(t),this.batch((()=>{this.changes.push({type:"TreeStructureDetached",treeKey:t})}))}addTree(t,e){this.batch((()=>{this.attachTreeStructure(e);const r=[],n=Array.isArray(t)?t:[t];for(;n.length;){const t=n.shift();r.push(t),t.children&&n.push(...t.children)}this.addNodes(r),r.forEach((t=>{t.children?.forEach((r=>{this.setParent(r.id,t.id,e)}))}))}))}getRoots(t){return this.checkTreeExistence(t),this.getAllNodes().filter((e=>!this.getParent(e.id,t)))}getChildren(t,e){this.checkNodeExistence(t),this.checkTreeExistence(e);const r=this.treeIndices.get(e).childrenMap.get(t);return Array.from(r||[])}getParent(t,e){return this.checkNodeExistence(t),this.checkTreeExistence(e),this.treeIndices.get(e).parentMap.get(t)||null}setParent(t,e,r){this.checkTreeExistence(r);const n=this.treeIndices.get(r),o=this.getNode(t),i=n.parentMap.get(t),s=this.getNode(e);n.parentMap.set(t,s),i&&n.childrenMap.get(i.id)?.delete(o);let a=n.childrenMap.get(s.id);a||(a=new Set,n.childrenMap.set(s.id,a)),a.add(o),this.batch((()=>{this.changes.push({type:"TreeStructureChanged",treeKey:r,nodeId:t,oldParentId:i?.id,newParentId:s.id})}))}getAllNodes(){return Array.from(this.nodeMap.values())}getAllEdges(){return Array.from(this.edgeMap.values())}doBFS(t,e,r){for(;t.length;){const n=t.shift();r(n),e.add(n.id),this.getSuccessors(n.id).forEach((r=>{e.has(r.id)||(e.add(r.id),t.push(r))}))}}bfs(t,e){this.doBFS([this.getNode(t)],new Set,e)}doDFS(t,e,r){r(t),e.add(t.id),this.getSuccessors(t.id).forEach((t=>{e.has(t.id)||this.doDFS(t,e,r)}))}dfs(t,e){this.doDFS(this.getNode(t),new Set,e)}clone(){const t=this.getAllNodes().map((t=>({...t,data:{...t.data}}))),e=this.getAllEdges().map((t=>({...t,data:{...t.data}}))),r=new s({nodes:t,edges:e});return this.treeIndices.forEach((({parentMap:t,childrenMap:e},n)=>{const o=new Map;t.forEach(((t,e)=>{o.set(e,r.getNode(t.id))}));const i=new Map;e.forEach(((t,e)=>{i.set(e,new Set(Array.from(t).map((t=>r.getNode(t.id)))))})),r.treeIndices.set(n,{parentMap:o,childrenMap:i})})),r}toJSON(){return JSON.stringify({nodes:this.getAllNodes(),edges:this.getAllEdges()})}}var a=function(t){return"string"==typeof t},u=/-(\\w)/g,h=(function(t){return t.replace(u,(function(t,e){return e?e.toUpperCase():""}))},Object.create(null),Array.isArray),l=function(t){return"number"==typeof t},c=function(t){for(var e=[],r=t.length,n=0;n<r;n+=1){e[n]=[];for(var o=0;o<r;o+=1)n===o?e[n][o]=0:0!==t[n][o]&&t[n][o]?e[n][o]=t[n][o]:e[n][o]=1/0}for(var i=0;i<r;i+=1)for(n=0;n<r;n+=1)for(o=0;o<r;o+=1)e[n][o]>e[n][i]+e[i][o]&&(e[n][o]=e[n][i]+e[i][o]);return e},f=function(t,e){var r=t.nodes,n=t.edges,o=[],i={};if(!r)throw new Error("invalid nodes data!");return r&&r.forEach((function(t,e){i[t.id]=e,o.push([])})),null==n||n.forEach((function(t){var r=t.source,n=t.target,s=i[r],a=i[n];void 0!==s&&void 0!==a&&(o[s][a]=1,e||(o[a][s]=1))})),o},d=function(t,e){return Math.sqrt((t.x-e.x)*(t.x-e.x)+(t.y-e.y)*(t.y-e.y))},g=function(t){return null!==t&&"object"==typeof t},p=function(t){if(null===t)return t;if(t instanceof Date)return new Date(t.getTime());if(t instanceof Array){var e=[];return t.forEach((function(t){e.push(t)})),e.map((function(t){return p(t)}))}if("object"==typeof t&&Object.keys(t).length){var n=r({},t);return Object.keys(n).forEach((function(t){n[t]=p(n[t])})),n}return t},y=function(t,e){var r=p(t);return r.data=r.data||{},e&&(l(r.data.x)||(r.data.x=Math.random()*e[0]),l(r.data.y)||(r.data.y=Math.random()*e[1])),r},m=function(t){return"function"==typeof t};function w(t,e){return m(e)?e:l(e)?function(){return e}:function(){return t}}function v(t,e,r){return void 0===r&&(r=!0),e||0===e?m(e)?e:l(e)?function(){return e}:h(e)?function(){if(r){var n=Math.max.apply(Math,i([],o(e),!1));return isNaN(n)?t:n}return e}:g(e)?function(){if(r){var n=Math.max(e.width,e.height);return isNaN(n)?t:n}return[e.width,e.height]}:function(){return t}:function(e){var r=(e.data||{}).size;return r?h(r)?r[0]>r[1]?r[0]:r[1]:g(r)?r.width>r.height?r.width:r.height:r:t}}var x={radius:null,startRadius:null,endRadius:null,startAngle:0,endAngle:2*Math.PI,clockwise:!0,divisions:1,ordering:null,angleRatio:1},M=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="circular",this.options=r(r({},x),t)}return t.prototype.execute=function(t,e){return this.genericCircularLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericCircularLayout(!0,t,e)},t.prototype.genericCircularLayout=function(t,e,n){var i=r(r({},this.options),n),s=i.width,a=i.height,u=i.center,h=i.divisions,l=i.startAngle,c=void 0===l?0:l,f=i.endAngle,d=void 0===f?2*Math.PI:f,g=i.angleRatio,p=i.ordering,m=i.clockwise,x=i.nodeSpacing,M=i.nodeSize,N=i.layoutInvisibles,S=i.onLayoutEnd,A=e.getAllNodes(),k=e.getAllEdges();N||(A=A.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e})),k=k.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e})));var I=A.length;if(0===I)return null==S||S({nodes:[],edges:[]}),{nodes:[],edges:[]};var D=o(E(s,a,u),3),R=D[0],_=D[1],z=D[2];if(1===I){t&&e.mergeNodeData(A[0].id,{x:z[0],y:z[1]});var T={nodes:[r(r({},A[0]),{data:r(r({},A[0].data),{x:z[0],y:z[1]})})],edges:k};return null==S||S(T),T}var O=(d-c)/I,C=i.radius,L=i.startRadius,P=i.endRadius;if(x){var q=w(10,x),j=v(10,M),V=-1/0;A.forEach((function(t){var e=j(t);V<e&&(V=e)}));var F=0;A.forEach((function(t,e){F+=0===e?V||10:(q(t)||0)+(V||10)})),C=F/(2*Math.PI)}else C||L||P?!L&&P?L=P:L&&!P&&(P=L):C=Math.min(_,R)/2;var $=O*g,G=[];G="topology"===p?b(e,A):"topology-directed"===p?b(e,A,!0):"degree"===p?function(t,e){var r=[];return e.forEach((function(t,e){r.push(y(t))})),r.sort((function(e,r){return t.getDegree(e.id,"both")-t.getDegree(r.id,"both")})),r}(e,A):A.map((function(t){return y(t)}));for(var U=Math.ceil(I/h),B=0;B<I;++B){var K=C;K||null===L||null===P||(K=L+B*(P-L)/(I-1)),K||(K=10+100*B/(I-1));var W=c+B%U*$+2*Math.PI/h*Math.floor(B/U);m||(W=d-B%U*$-2*Math.PI/h*Math.floor(B/U)),G[B].data.x=z[0]+Math.cos(W)*K,G[B].data.y=z[1]+Math.sin(W)*K}t&&G.forEach((function(t){e.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}));var H={nodes:G,edges:k};return null==S||S(H),H},t}(),b=function(t,e,r){void 0===r&&(r=!1);var n=[y(e[0])],o={},i=e.length;o[e[0].id]=!0;var s=0;return e.forEach((function(a,u){if(0!==u)if(u!==i-1&&t.getDegree(a.id,"both")===t.getDegree(e[u+1].id,"both")&&!t.areNeighbors(n[s].id,a.id)||o[a.id]){for(var h=r?t.getSuccessors(n[s].id):t.getNeighbors(n[s].id),l=!1,c=0;c<h.length;c++){var f=h[c];if(t.getDegree(f.id)===t.getDegree(a.id)&&!o[f.id]){n.push(y(f)),o[f.id]=!0,l=!0;break}}for(var d=0;!l&&(o[e[d].id]||(n.push(y(e[d])),o[e[d].id]=!0,l=!0),++d!==i););}else n.push(y(a)),o[a.id]=!0,s++})),n},E=function(t,e,r){var n=t,o=e,i=r;return n||"undefined"==typeof window||(n=window.innerWidth),o||"undefined"==typeof window||(o=window.innerHeight),i||(i=[n/2,o/2]),[n,o,i]},N={nodeSize:30,minNodeSpacing:10,nodeSpacing:10,preventOverlap:!1,sweep:void 0,equidistant:!1,startAngle:1.5*Math.PI,clockwise:!0,maxLevelDiff:void 0,sortBy:"degree"},S=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="concentric",this.options=r(r({},N),t)}return t.prototype.execute=function(t,e){return this.genericConcentricLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericConcentricLayout(!0,t,e)},t.prototype.genericConcentricLayout=function(t,e,n){var o=r(r({},this.options),n),i=o.center,s=o.width,u=o.height,c=o.sortBy,f=o.maxLevelDiff,d=o.sweep,p=o.clockwise,w=o.equidistant,v=o.minNodeSpacing,x=void 0===v?10:v,M=o.preventOverlap,b=o.startAngle,E=void 0===b?1.5*Math.PI:b,N=o.nodeSize,S=o.nodeSpacing,A=o.layoutInvisibles,k=o.onLayoutEnd,I=e.getAllNodes(),D=e.getAllEdges();A||(I=I.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e})),D=D.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e})));var R=I.length;if(0===R){var _={nodes:[],edges:D};return null==k||k(_),_}var z=s||"undefined"==typeof window?s:window.innerWidth,T=u||"undefined"==typeof window?u:window.innerHeight,O=i||[z/2,T/2];if(1===R){t&&e.mergeNodeData(I[0].id,{x:O[0],y:O[1]});var C={nodes:[r(r({},I[0]),{data:r(r({},I[0].data),{x:O[0],y:O[1]})})],edges:D};return null==k||k(C),C}var L,P=[],q=0;L=h(N)?Math.max(N[0],N[1]):N,h(S)?q=Math.max(S[0],S[1]):l(S)&&(q=S),I.forEach((function(t){var e=y(t);P.push(e);var r=L,n=e.data;h(n.size)?r=Math.max(n.size[0],n.size[1]):l(n.size)?r=n.size:g(n.size)&&(r=Math.max(n.size.width,n.size.height)),L=Math.max(L,r),m(S)&&(q=Math.max(S(t),q))}));var j={};P.forEach((function(t,e){j[t.id]=e}));var V=c;a(V)&&void 0!==P[0].data[V]||(V="degree"),"degree"===V?P.sort((function(t,r){return e.getDegree(r.id,"both")-e.getDegree(t.id,"both")})):P.sort((function(t,e){return e.data[V]-t.data[V]}));var F=P[0],$=(f||("degree"===V?e.getDegree(F.id,"both"):F.data[V]))/4,G=[{nodes:[]}],U=G[0];P.forEach((function(t){if(U.nodes.length>0){var r="degree"===V?Math.abs(e.getDegree(U.nodes[0].id,"both")-e.getDegree(t.id,"both")):Math.abs(U.nodes[0].data[V]-t.data[V]);$&&r>=$&&(U={nodes:[]},G.push(U))}U.nodes.push(t)}));var B=L+(q||x);if(!M){var K=G.length>0&&G[0].nodes.length>1,W=(Math.min(z,T)/2-B)/(G.length+(K?1:0));B=Math.min(B,W)}var H=0;if(G.forEach((function(t){var e=void 0===d?2*Math.PI-2*Math.PI/t.nodes.length:d;if(t.dTheta=e/Math.max(1,t.nodes.length-1),t.nodes.length>1&&M){var r=Math.cos(t.dTheta)-Math.cos(0),n=Math.sin(t.dTheta)-Math.sin(0),o=Math.sqrt(B*B/(r*r+n*n));H=Math.max(o,H)}t.r=H,H+=B})),w){for(var J=0,Y=0,X=0;X<G.length;X++){var Q=(G[X].r||0)-Y;J=Math.max(J,Q)}Y=0,G.forEach((function(t,e){0===e&&(Y=t.r||0),t.r=Y,Y+=J}))}G.forEach((function(t){var e=t.dTheta||0,r=t.r||0;t.nodes.forEach((function(t,n){var o=E+(p?1:-1)*e*n;t.data.x=O[0]+r*Math.cos(o),t.data.y=O[1]+r*Math.sin(o)}))})),t&&P.forEach((function(t){return e.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}));var Z={nodes:P,edges:D};return null==k||k(Z),Z},t}();function A(t,e,r,n){if(isNaN(e)||isNaN(r))return t;var o,i,s,a,u,h,l,c,f,d=t._root,g={data:n},p=t._x0,y=t._y0,m=t._x1,w=t._y1;if(!d)return t._root=g,t;for(;d.length;)if((h=e>=(i=(p+m)/2))?p=i:m=i,(l=r>=(s=(y+w)/2))?y=s:w=s,o=d,!(d=d[c=l<<1|h]))return o[c]=g,t;if(a=+t._x.call(null,d.data),u=+t._y.call(null,d.data),e===a&&r===u)return g.next=d,o?o[c]=g:t._root=g,t;do{o=o?o[c]=new Array(4):t._root=new Array(4),(h=e>=(i=(p+m)/2))?p=i:m=i,(l=r>=(s=(y+w)/2))?y=s:w=s}while((c=l<<1|h)==(f=(u>=s)<<1|a>=i));return o[f]=d,o[c]=g,t}function k(t,e,r,n,o){this.node=t,this.x0=e,this.y0=r,this.x1=n,this.y1=o}function I(t){return t[0]}function D(t){return t[1]}function R(t,e,r){var n=new _(null==e?I:e,null==r?D:r,NaN,NaN,NaN,NaN);return null==t?n:n.addAll(t)}function _(t,e,r,n,o,i){this._x=t,this._y=e,this._x0=r,this._y0=n,this._x1=o,this._y1=i,this._root=void 0}function z(t){for(var e={data:t.data},r=e;t=t.next;)r=r.next={data:t.data};return e}var T=R.prototype=_.prototype;function O(t){return function(){return t}}function C(t){return 1e-6*(t()-.5)}T.copy=function(){var t,e,r=new _(this._x,this._y,this._x0,this._y0,this._x1,this._y1),n=this._root;if(!n)return r;if(!n.length)return r._root=z(n),r;for(t=[{source:n,target:r._root=new Array(4)}];n=t.pop();)for(var o=0;o<4;++o)(e=n.source[o])&&(e.length?t.push({source:e,target:n.target[o]=new Array(4)}):n.target[o]=z(e));return r},T.add=function(t){const e=+this._x.call(null,t),r=+this._y.call(null,t);return A(this.cover(e,r),e,r,t)},T.addAll=function(t){var e,r,n,o,i=t.length,s=new Array(i),a=new Array(i),u=1/0,h=1/0,l=-1/0,c=-1/0;for(r=0;r<i;++r)isNaN(n=+this._x.call(null,e=t[r]))||isNaN(o=+this._y.call(null,e))||(s[r]=n,a[r]=o,n<u&&(u=n),n>l&&(l=n),o<h&&(h=o),o>c&&(c=o));if(u>l||h>c)return this;for(this.cover(u,h).cover(l,c),r=0;r<i;++r)A(this,s[r],a[r],t[r]);return this},T.cover=function(t,e){if(isNaN(t=+t)||isNaN(e=+e))return this;var r=this._x0,n=this._y0,o=this._x1,i=this._y1;if(isNaN(r))o=(r=Math.floor(t))+1,i=(n=Math.floor(e))+1;else{for(var s,a,u=o-r||1,h=this._root;r>t||t>=o||n>e||e>=i;)switch(a=(e<n)<<1|t<r,(s=new Array(4))[a]=h,h=s,u*=2,a){case 0:o=r+u,i=n+u;break;case 1:r=o-u,i=n+u;break;case 2:o=r+u,n=i-u;break;case 3:r=o-u,n=i-u}this._root&&this._root.length&&(this._root=h)}return this._x0=r,this._y0=n,this._x1=o,this._y1=i,this},T.data=function(){var t=[];return this.visit((function(e){if(!e.length)do{t.push(e.data)}while(e=e.next)})),t},T.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]]},T.find=function(t,e,r){var n,o,i,s,a,u,h,l=this._x0,c=this._y0,f=this._x1,d=this._y1,g=[],p=this._root;for(p&&g.push(new k(p,l,c,f,d)),null==r?r=1/0:(l=t-r,c=e-r,f=t+r,d=e+r,r*=r);u=g.pop();)if(!(!(p=u.node)||(o=u.x0)>f||(i=u.y0)>d||(s=u.x1)<l||(a=u.y1)<c))if(p.length){var y=(o+s)/2,m=(i+a)/2;g.push(new k(p[3],y,m,s,a),new k(p[2],o,m,y,a),new k(p[1],y,i,s,m),new k(p[0],o,i,y,m)),(h=(e>=m)<<1|t>=y)&&(u=g[g.length-1],g[g.length-1]=g[g.length-1-h],g[g.length-1-h]=u)}else{var w=t-+this._x.call(null,p.data),v=e-+this._y.call(null,p.data),x=w*w+v*v;if(x<r){var M=Math.sqrt(r=x);l=t-M,c=e-M,f=t+M,d=e+M,n=p.data}}return n},T.remove=function(t){if(isNaN(i=+this._x.call(null,t))||isNaN(s=+this._y.call(null,t)))return this;var e,r,n,o,i,s,a,u,h,l,c,f,d=this._root,g=this._x0,p=this._y0,y=this._x1,m=this._y1;if(!d)return this;if(d.length)for(;;){if((h=i>=(a=(g+y)/2))?g=a:y=a,(l=s>=(u=(p+m)/2))?p=u:m=u,e=d,!(d=d[c=l<<1|h]))return this;if(!d.length)break;(e[c+1&3]||e[c+2&3]||e[c+3&3])&&(r=e,f=c)}for(;d.data!==t;)if(n=d,!(d=d.next))return this;return(o=d.next)&&delete d.next,n?(o?n.next=o:delete n.next,this):e?(o?e[c]=o:delete e[c],(d=e[0]||e[1]||e[2]||e[3])&&d===(e[3]||e[2]||e[1]||e[0])&&!d.length&&(r?r[f]=d:this._root=d),this):(this._root=o,this)},T.removeAll=function(t){for(var e=0,r=t.length;e<r;++e)this.remove(t[e]);return this},T.root=function(){return this._root},T.size=function(){var t=0;return this.visit((function(e){if(!e.length)do{++t}while(e=e.next)})),t},T.visit=function(t){var e,r,n,o,i,s,a=[],u=this._root;for(u&&a.push(new k(u,this._x0,this._y0,this._x1,this._y1));e=a.pop();)if(!t(u=e.node,n=e.x0,o=e.y0,i=e.x1,s=e.y1)&&u.length){var h=(n+i)/2,l=(o+s)/2;(r=u[3])&&a.push(new k(r,h,l,i,s)),(r=u[2])&&a.push(new k(r,n,l,h,s)),(r=u[1])&&a.push(new k(r,h,o,i,l)),(r=u[0])&&a.push(new k(r,n,o,h,l))}return this},T.visitAfter=function(t){var e,r=[],n=[];for(this._root&&r.push(new k(this._root,this._x0,this._y0,this._x1,this._y1));e=r.pop();){var o=e.node;if(o.length){var i,s=e.x0,a=e.y0,u=e.x1,h=e.y1,l=(s+u)/2,c=(a+h)/2;(i=o[0])&&r.push(new k(i,s,a,l,c)),(i=o[1])&&r.push(new k(i,l,a,u,c)),(i=o[2])&&r.push(new k(i,s,c,l,h)),(i=o[3])&&r.push(new k(i,l,c,u,h))}n.push(e)}for(;e=n.pop();)t(e.node,e.x0,e.y0,e.x1,e.y1);return this},T.x=function(t){return arguments.length?(this._x=t,this):this._x},T.y=function(t){return arguments.length?(this._y=t,this):this._y};var L={value:()=>{}};function P(){for(var t,e=0,r=arguments.length,n={};e<r;++e){if(!(t=arguments[e]+"")||t in n||/[\\s.]/.test(t))throw new Error("illegal type: "+t);n[t]=[]}return new q(n)}function q(t){this._=t}function j(t,e){return t.trim().split(/^|\\s+/).map((function(t){var r="",n=t.indexOf(".");if(n>=0&&(r=t.slice(n+1),t=t.slice(0,n)),t&&!e.hasOwnProperty(t))throw new Error("unknown type: "+t);return{type:t,name:r}}))}function V(t,e){for(var r,n=0,o=t.length;n<o;++n)if((r=t[n]).name===e)return r.value}function F(t,e,r){for(var n=0,o=t.length;n<o;++n)if(t[n].name===e){t[n]=L,t=t.slice(0,n).concat(t.slice(n+1));break}return null!=r&&t.push({name:e,value:r}),t}q.prototype=P.prototype={constructor:q,on:function(t,e){var r,n=this._,o=j(t+"",n),i=-1,s=o.length;if(!(arguments.length<2)){if(null!=e&&"function"!=typeof e)throw new Error("invalid callback: "+e);for(;++i<s;)if(r=(t=o[i]).type)n[r]=F(n[r],t.name,e);else if(null==e)for(r in n)n[r]=F(n[r],t.name,null);return this}for(;++i<s;)if((r=(t=o[i]).type)&&(r=V(n[r],t.name)))return r},copy:function(){var t={},e=this._;for(var r in e)t[r]=e[r].slice();return new q(t)},call:function(t,e){if((r=arguments.length-2)>0)for(var r,n,o=new Array(r),i=0;i<r;++i)o[i]=arguments[i+2];if(!this._.hasOwnProperty(t))throw new Error("unknown type: "+t);for(i=0,r=(n=this._[t]).length;i<r;++i)n[i].value.apply(e,o)},apply:function(t,e,r){if(!this._.hasOwnProperty(t))throw new Error("unknown type: "+t);for(var n=this._[t],o=0,i=n.length;o<i;++o)n[o].value.apply(e,r)}};const $=P;var G,U,B=0,K=0,W=0,H=0,J=0,Y=0,X="object"==typeof performance&&performance.now?performance:Date,Q="object"==typeof window&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(t){setTimeout(t,17)};function Z(){return J||(Q(tt),J=X.now()+Y)}function tt(){J=0}function et(){this._call=this._time=this._next=null}function rt(t,e,r){var n=new et;return n.restart(t,e,r),n}function nt(){J=(H=X.now())+Y,B=K=0;try{!function(){Z(),++B;for(var t,e=G;e;)(t=J-e._time)>=0&&e._call.call(void 0,t),e=e._next;--B}()}finally{B=0,function(){for(var t,e,r=G,n=1/0;r;)r._call?(n>r._time&&(n=r._time),t=r,r=r._next):(e=r._next,r._next=null,r=t?t._next=e:G=e);U=t,it(n)}(),J=0}}function ot(){var t=X.now(),e=t-H;e>1e3&&(Y-=e,H=t)}function it(t){B||(K&&(K=clearTimeout(K)),t-J>24?(t<1/0&&(K=setTimeout(nt,t-X.now()-Y)),W&&(W=clearInterval(W))):(W||(H=X.now(),W=setInterval(ot,1e3)),B=1,Q(nt)))}et.prototype=rt.prototype={constructor:et,restart:function(t,e,r){if("function"!=typeof t)throw new TypeError("callback is not a function");r=(null==r?Z():+r)+(null==e?0:+e),this._next||U===this||(U?U._next=this:G=this,U=this),this._call=t,this._time=r,it()},stop:function(){this._call&&(this._call=null,this._time=1/0,it())}};const st=4294967296;function at(t){return t.x}function ut(t){return t.y}var ht=Math.PI*(3-Math.sqrt(5));function lt(t){var e,r=1,n=.001,o=1-Math.pow(n,1/300),i=0,s=.6,a=new Map,u=rt(c),h=$("tick","end"),l=function(){let t=1;return()=>(t=(1664525*t+1013904223)%st)/st}();function c(){f(),h.call("tick",e),r<n&&(u.stop(),h.call("end",e))}function f(n){var u,h,l=t.length;void 0===n&&(n=1);for(var c=0;c<n;++c)for(r+=(i-r)*o,a.forEach((function(t){t(r)})),u=0;u<l;++u)null==(h=t[u]).fx?h.x+=h.vx*=s:(h.x=h.fx,h.vx=0),null==h.fy?h.y+=h.vy*=s:(h.y=h.fy,h.vy=0);return e}function d(){for(var e,r=0,n=t.length;r<n;++r){if((e=t[r]).index=r,null!=e.fx&&(e.x=e.fx),null!=e.fy&&(e.y=e.fy),isNaN(e.x)||isNaN(e.y)){var o=10*Math.sqrt(.5+r),i=r*ht;e.x=o*Math.cos(i),e.y=o*Math.sin(i)}(isNaN(e.vx)||isNaN(e.vy))&&(e.vx=e.vy=0)}}function g(e){return e.initialize&&e.initialize(t,l),e}return null==t&&(t=[]),d(),e={tick:f,restart:function(){return u.restart(c),e},stop:function(){return u.stop(),e},nodes:function(r){return arguments.length?(t=r,d(),a.forEach(g),e):t},alpha:function(t){return arguments.length?(r=+t,e):r},alphaMin:function(t){return arguments.length?(n=+t,e):n},alphaDecay:function(t){return arguments.length?(o=+t,e):+o},alphaTarget:function(t){return arguments.length?(i=+t,e):i},velocityDecay:function(t){return arguments.length?(s=1-t,e):1-s},randomSource:function(t){return arguments.length?(l=t,a.forEach(g),e):l},force:function(t,r){return arguments.length>1?(null==r?a.delete(t):a.set(t,g(r)),e):a.get(t)},find:function(e,r,n){var o,i,s,a,u,h=0,l=t.length;for(null==n?n=1/0:n*=n,h=0;h<l;++h)(s=(o=e-(a=t[h]).x)*o+(i=r-a.y)*i)<n&&(u=a,n=s);return u},on:function(t,r){return arguments.length>1?(h.on(t,r),e):h.on(t)}}}function ct(){var t,e,r,n,o,i=O(-30),s=1,a=1/0,u=.81;function h(r){var o,i=t.length,s=R(t,at,ut).visitAfter(c);for(n=r,o=0;o<i;++o)e=t[o],s.visit(f)}function l(){if(t){var e,r,n=t.length;for(o=new Array(n),e=0;e<n;++e)r=t[e],o[r.index]=+i(r,e,t)}}function c(t){var e,r,n,i,s,a=0,u=0;if(t.length){for(n=i=s=0;s<4;++s)(e=t[s])&&(r=Math.abs(e.value))&&(a+=e.value,u+=r,n+=r*e.x,i+=r*e.y);t.x=n/u,t.y=i/u}else{(e=t).x=e.data.x,e.y=e.data.y;do{a+=o[e.data.index]}while(e=e.next)}t.value=a}function f(t,i,h,l){if(!t.value)return!0;var c=t.x-e.x,f=t.y-e.y,d=l-i,g=c*c+f*f;if(d*d/u<g)return g<a&&(0===c&&(g+=(c=C(r))*c),0===f&&(g+=(f=C(r))*f),g<s&&(g=Math.sqrt(s*g)),e.vx+=c*t.value*n/g,e.vy+=f*t.value*n/g),!0;if(!(t.length||g>=a)){(t.data!==e||t.next)&&(0===c&&(g+=(c=C(r))*c),0===f&&(g+=(f=C(r))*f),g<s&&(g=Math.sqrt(s*g)));do{t.data!==e&&(d=o[t.data.index]*n/g,e.vx+=c*d,e.vy+=f*d)}while(t=t.next)}}return h.initialize=function(e,n){t=e,r=n,l()},h.strength=function(t){return arguments.length?(i="function"==typeof t?t:O(+t),l(),h):i},h.distanceMin=function(t){return arguments.length?(s=t*t,h):Math.sqrt(s)},h.distanceMax=function(t){return arguments.length?(a=t*t,h):Math.sqrt(a)},h.theta=function(t){return arguments.length?(u=t*t,h):Math.sqrt(u)},h}function ft(t){return t.index}function dt(t,e){var r=t.get(e);if(!r)throw new Error("node not found: "+e);return r}function gt(t){var e,r,n,o,i,s,a=ft,u=function(t){return 1/Math.min(o[t.source.index],o[t.target.index])},h=O(30),l=1;function c(n){for(var o=0,a=t.length;o<l;++o)for(var u,h,c,f,d,g,p,y=0;y<a;++y)h=(u=t[y]).source,f=(c=u.target).x+c.vx-h.x-h.vx||C(s),d=c.y+c.vy-h.y-h.vy||C(s),f*=g=((g=Math.sqrt(f*f+d*d))-r[y])/g*n*e[y],d*=g,c.vx-=f*(p=i[y]),c.vy-=d*p,h.vx+=f*(p=1-p),h.vy+=d*p}function f(){if(n){var s,u,h=n.length,l=t.length,c=new Map(n.map(((t,e)=>[a(t,e,n),t])));for(s=0,o=new Array(h);s<l;++s)(u=t[s]).index=s,"object"!=typeof u.source&&(u.source=dt(c,u.source)),"object"!=typeof u.target&&(u.target=dt(c,u.target)),o[u.source.index]=(o[u.source.index]||0)+1,o[u.target.index]=(o[u.target.index]||0)+1;for(s=0,i=new Array(l);s<l;++s)u=t[s],i[s]=o[u.source.index]/(o[u.source.index]+o[u.target.index]);e=new Array(l),d(),r=new Array(l),g()}}function d(){if(n)for(var r=0,o=t.length;r<o;++r)e[r]=+u(t[r],r,t)}function g(){if(n)for(var e=0,o=t.length;e<o;++e)r[e]=+h(t[e],e,t)}return null==t&&(t=[]),c.initialize=function(t,e){n=t,s=e,f()},c.links=function(e){return arguments.length?(t=e,f(),c):t},c.id=function(t){return arguments.length?(a=t,c):a},c.iterations=function(t){return arguments.length?(l=+t,c):l},c.strength=function(t){return arguments.length?(u="function"==typeof t?t:O(+t),d(),c):u},c.distance=function(t){return arguments.length?(h="function"==typeof t?t:O(+t),g(),c):h},c}function pt(t){return t.x+t.vx}function yt(t){return t.y+t.vy}function mt(t){var e,r,n,o=1,i=1;function s(){for(var t,s,u,h,l,c,f,d=e.length,g=0;g<i;++g)for(s=R(e,pt,yt).visitAfter(a),t=0;t<d;++t)u=e[t],c=r[u.index],f=c*c,h=u.x+u.vx,l=u.y+u.vy,s.visit(p);function p(t,e,r,i,s){var a=t.data,d=t.r,g=c+d;if(!a)return e>h+g||i<h-g||r>l+g||s<l-g;if(a.index>u.index){var p=h-a.x-a.vx,y=l-a.y-a.vy,m=p*p+y*y;m<g*g&&(0===p&&(m+=(p=C(n))*p),0===y&&(m+=(y=C(n))*y),m=(g-(m=Math.sqrt(m)))/m*o,u.vx+=(p*=m)*(g=(d*=d)/(f+d)),u.vy+=(y*=m)*g,a.vx-=p*(g=1-g),a.vy-=y*g)}}}function a(t){if(t.data)return t.r=r[t.data.index];for(var e=t.r=0;e<4;++e)t[e]&&t[e].r>t.r&&(t.r=t[e].r)}function u(){if(e){var n,o,i=e.length;for(r=new Array(i),n=0;n<i;++n)o=e[n],r[o.index]=+t(o,n,e)}}return"function"!=typeof t&&(t=O(null==t?1:+t)),s.initialize=function(t,r){e=t,n=r,u()},s.iterations=function(t){return arguments.length?(i=+t,s):i},s.strength=function(t){return arguments.length?(o=+t,s):o},s.radius=function(e){return arguments.length?(t="function"==typeof e?e:O(+e),u(),s):t},s}function wt(t){var e,r,n,o=O(.1);function i(t){for(var o,i=0,s=e.length;i<s;++i)(o=e[i]).vx+=(n[i]-o.x)*r[i]*t}function s(){if(e){var i,s=e.length;for(r=new Array(s),n=new Array(s),i=0;i<s;++i)r[i]=isNaN(n[i]=+t(e[i],i,e))?0:+o(e[i],i,e)}}return"function"!=typeof t&&(t=O(null==t?0:+t)),i.initialize=function(t){e=t,s()},i.strength=function(t){return arguments.length?(o="function"==typeof t?t:O(+t),s(),i):o},i.x=function(e){return arguments.length?(t="function"==typeof e?e:O(+e),s(),i):t},i}function vt(t){var e,r,n,o=O(.1);function i(t){for(var o,i=0,s=e.length;i<s;++i)(o=e[i]).vy+=(n[i]-o.y)*r[i]*t}function s(){if(e){var i,s=e.length;for(r=new Array(s),n=new Array(s),i=0;i<s;++i)r[i]=isNaN(n[i]=+t(e[i],i,e))?0:+o(e[i],i,e)}}return"function"!=typeof t&&(t=O(null==t?0:+t)),i.initialize=function(t){e=t,s()},i.strength=function(t){return arguments.length?(o="function"==typeof t?t:O(+t),s(),i):o},i.y=function(e){return arguments.length?(t="function"==typeof e?e:O(+e),s(),i):t},i}function xt(){function t(t){return function(){return t}}var e,r=function(t){return t.cluster},n=t(1),i=t(-1),s=t(100),a=t(.1),u=[0,0],h=[],l={},c=[],f=100,d=100,g={none:{x:0,y:0}},p=[],y="force",m=!0,w=.1;function v(t){if(!m)return v;e.tick(),M();for(var n=0,o=h.length,i=void 0,s=t*w;n<o;++n)(i=h[n]).vx+=(g[r(i)].x-i.x)*s,i.vy+=(g[r(i)].y-i.y)*s}function x(){h&&function(){if(h&&h.length){if(void 0===r(h[0]))throw Error("Couldnt find the grouping attribute for the nodes. Make sure to set it up with forceInBox.groupBy(\'clusterAttr\') before calling .links()");var t,u,g,y,m,w=(t=[],u=[],g={},{},m=[],y=function(t){var e={};return t.forEach((function(t){var n=r(t);e[n]||(e[n]={count:0,sumforceNodeSize:0})})),t.forEach((function(t){var o=r(t),i=n(t),s=e[o];s.count=s.count+1,s.sumforceNodeSize=s.sumforceNodeSize+Math.PI*(i*i)*1.3,e[o]=s})),e}(h),m=function(t){var e={},n=[];return t.forEach((function(t){var n,o,i,s,a,u=(o=(n=t).source,i=n.target,(s=r(l[o]))<=(a=r(l[i]))?"".concat(s,"~").concat(a):"".concat(a,"~").concat(s)),h=0;void 0!==e[u]&&(h=e[u]),h+=1,e[u]=h})),Object.entries(e).forEach((function(t){var e=o(t,2),r=e[0],i=e[1],s=r.split("~")[0],a=r.split("~")[1];void 0!==s&&void 0!==a&&n.push({source:s,target:a,count:i})})),n}(c),Object.keys(y).forEach((function(e,r){var n=y[e];t.push({id:e,size:n.count,r:Math.sqrt(n.sumforceNodeSize/Math.PI)}),g[e]=r})),m.forEach((function(t){var e=t.source,r=t.target,n=g[e],o=g[r];void 0!==n&&void 0!==o&&u.push({source:n,target:o,count:t.count})})),{nodes:t,links:u});e=lt(w.nodes).force("x",wt(f).strength(.1)).force("y",vt(d).strength(.1)).force("collide",mt((function(t){return t.r})).iterations(4)).force("charge",ct().strength(i)).force("links",gt(w.nodes.length?w.links:[]).distance(s).strength(a)),p=e.nodes(),M()}}()}function M(){return g={none:{x:0,y:0}},p.forEach((function(t){g[t.id]={x:t.x-u[0],y:t.y-u[1]}})),g}function b(t){l={},t.forEach((function(t){l[t.id]=t}))}return v.initialize=function(t){h=t,x()},v.template=function(t){return arguments.length?(y=t,x(),v):y},v.groupBy=function(t){return arguments.length?"string"==typeof t?(r=function(e){return e[t]},v):(r=t,v):r},v.enableGrouping=function(t){return arguments.length?(m=t,v):m},v.strength=function(t){return arguments.length?(w=t,v):w},v.centerX=function(t){return arguments.length?(f=t,v):f},v.centerY=function(t){return arguments.length?(d=t,v):d},v.nodes=function(t){return arguments.length?(b(t||[]),h=t||[],v):h},v.links=function(t){return arguments.length?(c=t||[],x(),v):c},v.forceNodeSize=function(e){return arguments.length?(n="function"==typeof e?e:t(+e),x(),v):n},v.nodeSize=v.forceNodeSize,v.forceCharge=function(e){return arguments.length?(i="function"==typeof e?e:t(+e),x(),v):i},v.forceLinkDistance=function(e){return arguments.length?(s="function"==typeof e?e:t(+e),x(),v):s},v.forceLinkStrength=function(e){return arguments.length?(a="function"==typeof e?e:t(+e),x(),v):a},v.offset=function(t){return arguments.length?(u=t,v):u},v.getFocis=M,v}var Mt={center:[0,0],preventOverlap:!1,nodeSize:void 0,nodeSpacing:void 0,linkDistance:50,forceSimulation:null,alphaDecay:.028,alphaMin:.001,alpha:.3,collideStrength:1,clustering:!1,clusterNodeStrength:-1,clusterEdgeStrength:.1,clusterEdgeDistance:100,clusterFociStrength:.8,clusterNodeSize:10},bt=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="d3force",this.running=!1,this.options=r(r({},Mt),t)}return t.prototype.execute=function(t,e){return this.genericForceLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericForceLayout(!0,t,e)},t.prototype.stop=function(){var t;null===(t=this.forceSimulation)||void 0===t||t.stop(),this.running=!1},t.prototype.restart=function(){var t;null===(t=this.forceSimulation)||void 0===t||t.restart(),this.running=!0},t.prototype.tick=function(t){var e=this;void 0===t&&(t=1),this.forceSimulation.tick(t);var r={nodes:Et(this.lastLayoutNodes),edges:Nt(this.lastLayoutEdges)};return this.lastAssign&&r.nodes.forEach((function(t){return e.lastGraph.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})})),this.lastOptions.onLayoutEnd&&this.lastOptions.onLayoutEnd(r),r},t.prototype.genericForceLayout=function(t,e,n){var o=this,i=r(r({},this.options),n),s=i.layoutInvisibles,a=e.getAllNodes(),u=e.getAllEdges();s||(a=a.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e})),u=u.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e})));var h=a.map((function(t){var e,n;return r(r({},y(t)),{x:null===(e=t.data)||void 0===e?void 0:e.x,y:null===(n=t.data)||void 0===n?void 0:n.y})})),l=u.map((function(t){return y(t)}));if(this.lastLayoutNodes=h,this.lastLayoutEdges=l,this.lastAssign=t,this.lastGraph=e,this.lastOptions=i,!this.running){var c=i.alphaMin,f=i.alphaDecay,d=i.alpha,g=i.nodeStrength,p=i.edgeStrength,m=i.linkDistance,w=i.clustering,v=i.clusterFociStrength,x=i.clusterEdgeDistance,M=i.clusterEdgeStrength,b=i.clusterNodeStrength,E=i.clusterNodeSize,N=i.collideStrength,S=void 0===N?1:N,A=i.center,k=void 0===A?[0,0]:A,I=i.preventOverlap,D=i.nodeSize,R=i.nodeSpacing,_=i.onTick,z=i.onLayoutEnd,T=i.forceSimulation;if(T)w&&((O=xt()).nodes(h),O.links(l)),T.nodes(h),l&&(L=gt().id((function(t){return t.id})).links(l),p&&L.strength(p),m&&L.distance(m),T.force("link",L)),I&&this.overlapProcess(T,{nodeSize:D,nodeSpacing:R,collideStrength:S}),T.alpha(d).restart(),this.running=!0;else try{var O,C=ct();if(g&&C.strength(g),T=lt().nodes(h),w&&((O=xt()).centerX(k[0]).centerY(k[1]).template("force").strength(v),l&&O.links(l),h&&O.nodes(h),O.forceLinkDistance(x).forceLinkStrength(M).forceCharge(b).forceNodeSize(E),T.force("group",O)),T.force("center",function(t,e){var r,n=1;function o(){var o,i,s=r.length,a=0,u=0;for(o=0;o<s;++o)a+=(i=r[o]).x,u+=i.y;for(a=(a/s-t)*n,u=(u/s-e)*n,o=0;o<s;++o)(i=r[o]).x-=a,i.y-=u}return null==t&&(t=0),null==e&&(e=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.strength=function(t){return arguments.length?(n=+t,o):n},o}(k[0],k[1])).force("charge",C).alpha(d).alphaDecay(f).alphaMin(c),I&&this.overlapProcess(T,{nodeSize:D,nodeSpacing:R,collideStrength:S}),l){var L=gt().id((function(t){return t.id})).links(l);p&&L.strength(p),m&&L.distance(m),T.force("link",L)}T.on("tick",(function(){var r=Et(h);null==_||_({nodes:r,edges:Nt(l)}),t&&r.forEach((function(t){return e.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}))})).on("end",(function(){o.running=!1;var r=Et(h);null==z||z({nodes:r,edges:Nt(l)}),t&&r.forEach((function(t){return e.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}))})),this.running=!0}catch(t){this.running=!1,console.warn(t)}this.forceSimulation=T;var P=Et(h),q=Nt(l);return t&&P.forEach((function(t){return e.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})})),{nodes:P,edges:q}}},t.prototype.overlapProcess=function(t,e){var r,n,o=e.nodeSize,i=e.nodeSpacing,s=e.collideStrength;if(n=l(i)?function(){return i}:m(i)?i:function(){return 0},o)if(m(o))r=function(t){return o(t)+n(t)};else if(h(o)){var a=(o[0]>o[1]?o[0]:o[1])/2;r=function(t){return a+n(t)}}else if(l(o)){var u=o/2;r=function(t){return u+n(t)}}else r=function(){return 10};else r=function(t){return t.size?h(t.size)?(t.size[0]>t.size[1]?t.size[0]:t.size[1])/2+n(t):g(t.size)?(t.size.width>t.size.height?t.size.width:t.size.height)/2+n(t):t.size/2+n(t):10+n(t)};t.force("collisionForce",mt(r).strength(s))},t}(),Et=function(t){return t.map((function(t){var e=t.x,o=t.y,i=n(t,["x","y"]);return r(r({},i),{data:r(r({},i.data),{x:e,y:o})})}))},Nt=function(t){return t.map((function(t){var e=t.source,o=t.target,i=n(t,["source","target"]);return r(r({},i),{source:e.id,target:o.id})}))};function St(t){var e=0,r=0,n=0;if(t.length){for(var o=0;o<4;o++)(i=t[o])&&i.weight&&(e+=i.weight,r+=i.x*i.weight,n+=i.y*i.weight);t.x=r/e,t.y=n/e,t.weight=e}else{var i=t;t.x=i.data.x,t.y=i.data.y,t.weight=i.data.weight}}var At={maxIteration:500,gravity:10,factor:1,edgeStrength:200,nodeStrength:1e3,coulombDisScale:.005,damping:.9,maxSpeed:500,minMovement:.4,interval:.02,linkDistance:200,clusterNodeStrength:20,preventOverlap:!0,distanceThresholdMode:"mean"},kt=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="force",this.timeInterval=0,this.judgingDistance=0,this.running=!1,this.options=r(r({},At),t)}return t.prototype.execute=function(t,e){return this.genericForceLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericForceLayout(!0,t,e)},t.prototype.stop=function(){this.timeInterval&&"undefined"!=typeof window&&window.clearInterval(this.timeInterval),this.running=!1},t.prototype.restart=function(){this.running=!0},t.prototype.tick=function(t){var e=this;if(void 0===t&&(t=this.options.maxIteration||1),this.lastResult)return this.lastResult;for(var r=0;(this.judgingDistance>this.lastOptions.minMovement||r<1)&&r<t;r++)this.runOneStep(this.lastCalcGraph,this.lastGraph,r,this.lastVelMap,this.lastOptions),this.updatePosition(this.lastGraph,this.lastCalcGraph,this.lastVelMap,this.lastOptions);var n={nodes:this.lastLayoutNodes,edges:this.lastLayoutEdges};return this.lastAssign&&n.nodes.forEach((function(t){return e.lastGraph.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})})),this.lastOptions.onLayoutEnd&&this.lastOptions.onLayoutEnd(n),n},t.prototype.genericForceLayout=function(t,e,n){var o=this,i=r(r({},this.options),n),a=e.getAllNodes(),u=e.getAllEdges();i.layoutInvisibles||(a=a.filter((function(t){return t.data.visible||void 0===t.data.visible})),u=u.filter((function(t){return t.data.visible||void 0===t.data.visible})));var h=this.formatOptions(i,e),c=h.width,f=h.height,d=h.nodeSize,g=h.getMass,p=h.nodeStrength,y=h.edgeStrength,m=h.linkDistance,w=a.map((function(t){return r(r({},t),{data:r(r({},t.data),{x:l(t.data.x)?t.data.x:Math.random()*c,y:l(t.data.y)?t.data.y:Math.random()*f,size:d(t)||30,mass:g(t),nodeStrength:p(t)})})})),v=u.map((function(t){return r(r({},t),{data:r(r({},t.data),{edgeStrength:y(t),linkDistance:m(t,e.getNode(t.source),e.getNode(t.target))})})}));if(!(null==a?void 0:a.length))return this.lastResult={nodes:[],edges:u},{nodes:[],edges:u};var x={};a.forEach((function(t,e){x[t.id]={x:0,y:0}}));var M=new s({nodes:w,edges:v});this.formatCentripetal(h,M);var b=h.maxIteration,E=h.minMovement,N=h.onLayoutEnd,S=h.onTick;if(this.lastLayoutNodes=w,this.lastLayoutEdges=v,this.lastAssign=t,this.lastGraph=e,this.lastCalcGraph=M,this.lastOptions=h,this.lastVelMap=x,"undefined"!=typeof window){var A=0;return this.timeInterval=window.setInterval((function(){a&&o.running&&(o.runOneStep(M,e,A,x,h),o.updatePosition(e,M,x,h),t&&w.forEach((function(t){return e.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})})),null==S||S({nodes:zt(e,w),edges:u}),(++A>=b||o.judgingDistance<E)&&(null==N||N({nodes:zt(e,w),edges:u}),window.clearInterval(o.timeInterval)))}),0),this.running=!0,{nodes:zt(e,w),edges:u}}},t.prototype.formatOptions=function(t,e){var r=t,n=t.width,o=t.height,i=t.getMass;if(r.width=n||"undefined"==typeof window?n:window.innerWidth,r.height=o||"undefined"==typeof window?o:window.innerHeight,t.center||(r.center=[r.width/2,r.height/2]),i||(r.getMass=function(t){var r=1;l(null==t?void 0:t.data.mass)&&(r=null==t?void 0:t.data.mass);var n=e.getDegree(t.id,"both");return!n||n<5?r:5*n*r}),t.preventOverlap){var s=w(0,t.nodeSpacing);t.nodeSize?h(t.nodeSize)?r.nodeSize=function(e){var r=t.nodeSize;return Math.max(r[0],r[1])+s(e)}:r.nodeSize=function(e){return t.nodeSize+s(e)}:r.nodeSize=function(t){var e=((null==t?void 0:t.data)||{}).size;return e?h(e)?Math.max(e[0],e[1])+s(t):g(e)?Math.max(e.width,e.height)+s(t):e+s(t):10+s(t)}}return r.linkDistance=t.linkDistance?w(1,t.linkDistance):function(t){return 1+r.nodeSize(e.getNode(t.source))+r.nodeSize(e.getNode(t.target))},r.nodeStrength=w(1,t.nodeStrength),r.edgeStrength=w(1,t.edgeStrength),t},t.prototype.formatCentripetal=function(t,e){var r,n=t.centripetalOptions,o=t.center,i=t.clusterNodeStrength,s=t.leafCluster,a=t.clustering,u=t.nodeClusterBy,h=e.getAllNodes(),l=n||{leaf:2,single:2,others:1,center:function(t){return{x:o[0],y:o[1]}}};"function"!=typeof i&&(t.clusterNodeStrength=function(t){return i});var c=[];if(s&&u&&(r=It(e,u),c=Array.from(new Set(null==h?void 0:h.map((function(t){return t.data[u]}))))||[],t.centripetalOptions=Object.assign(l,{single:100,leaf:function(e){var n=r[e.id]||{},o=n.siblingLeaves,i=n.sameTypeLeaves;return(null==i?void 0:i.length)===(null==o?void 0:o.length)||1===(null==c?void 0:c.length)?1:t.clusterNodeStrength(e)},others:1,center:function(t){var n,o=e.getDegree(t.id,"both");if(!o)return{x:100,y:100};if(1===o){var i=(r[t.id]||{}).sameTypeLeaves,s=void 0===i?[]:i;1===s.length?n=void 0:s.length>1&&(n=_t(s))}else n=void 0;return{x:null==n?void 0:n.x,y:null==n?void 0:n.y}}})),a&&u){r||(r=It(e,u)),c||(c=Array.from(new Set(h.map((function(t){return t.data[u]}))))),c=c.filter((function(t){return void 0!==t}));var f={};c.forEach((function(t){var r=h.filter((function(e){return e.data[u]===t})).map((function(t){return e.getNode(t.id)}));f[t]=_t(r)})),t.centripetalOptions=Object.assign(l,{single:function(e){return t.clusterNodeStrength(e)},leaf:function(e){return t.clusterNodeStrength(e)},others:function(e){return t.clusterNodeStrength(e)},center:function(t){var e=f[t.data[u]];return{x:null==e?void 0:e.x,y:null==e?void 0:e.y}}})}var d=t.centripetalOptions||{},g=d.leaf,p=d.single,y=d.others;g&&"function"!=typeof g&&(t.centripetalOptions.leaf=function(){return g}),p&&"function"!=typeof p&&(t.centripetalOptions.single=function(){return p}),y&&"function"!=typeof y&&(t.centripetalOptions.others=function(){return y})},t.prototype.runOneStep=function(t,e,r,n,o){var i={},s=t.getAllNodes(),a=t.getAllEdges();if(null==s?void 0:s.length){var u=o.monitor;this.calRepulsive(t,i,o),a&&this.calAttractive(t,i),this.calGravity(t,e,i,o),this.updateVelocity(t,i,n,o),u&&u({energy:this.calTotalEnergy(i,s),nodes:e.getAllNodes(),edges:e.getAllEdges(),iterations:r})}},t.prototype.calTotalEnergy=function(t,e){if(!(null==e?void 0:e.length))return 0;var r=0;return e.forEach((function(e,n){var o=t[e.id].x,i=t[e.id].y,s=o*o+i*i,a=e.data.mass;r+=(void 0===a?1:a)*s*.5})),r},t.prototype.calRepulsive=function(t,e,r){var n=r.factor,o=r.coulombDisScale;!function(t,e,r,n){var o=e/r,i=t.getAllNodes(),s=i.map((function(t,e){var r=t.data,n=r.nodeStrength;return{x:r.x,y:r.y,size:r.size,index:e,vx:0,vy:0,weight:o*n}})),a=R(s,(function(t){return t.x}),(function(t){return t.y})).visitAfter(St);s.forEach((function(t){!function(t,e){e.visit((function(e,r,n,o,i){return function(t,e,r,n,o,i){var s=i.x-t.x||.1,a=i.y-t.y||.1,u=n-e,h=s*s+a*a,l=Math.sqrt(h)*h;if(u*u*.81<h){var c=t.weight/l;return i.vx+=s*c,i.vy+=a*c,!0}if(t.length)return!1;t.data!==i&&(c=t.data.weight/l,i.vx+=s*c,i.vy+=a*c)}(e,r,0,o,0,t)}))}(t,a)})),s.map((function(t,e){var r=i[e],o=r.id,s=r.data.mass,a=void 0===s?1:s;n[o]={x:t.vx/a,y:t.vy/a}}))}(t,n,o*o,e)},t.prototype.calAttractive=function(t,e){t.getAllEdges().forEach((function(r,n){var o=r.source,i=r.target,s=t.getNode(o),a=t.getNode(i);if(s&&a){var u=a.data.x-s.data.x,h=a.data.y-s.data.y;u||h||(u=.01*Math.random(),h=.01*Math.random());var l=Math.sqrt(u*u+h*h),c=u/l,f=h/l,d=r.data||{},g=d.linkDistance,p=void 0===g?200:g,y=d.edgeStrength,m=(p-l)*(void 0===y?200:y),w=1/(s.data.mass||1),v=1/(a.data.mass||1),x=c*m,M=f*m;e[o].x-=x*w,e[o].y-=M*w,e[i].x+=x*v,e[i].y+=M*v}}))},t.prototype.calGravity=function(t,e,r,n){var i=n.getCenter,s=t.getAllNodes(),a=e.getAllNodes(),u=e.getAllEdges(),h=n.width,c=n.height,f=n.center,d=n.gravity,g=n.centripetalOptions;s&&s.forEach((function(n){var s=n.id,p=n.data,y=p.mass,m=p.x,w=p.y,v=e.getNode(s),x=0,M=0,b=d,E=t.getDegree(s,"in"),N=t.getDegree(s,"out"),S=t.getDegree(s,"both"),A=null==i?void 0:i(v,S);if(A){var k=o(A,3);x=m-k[0],M=w-k[1],b=k[2]}else x=m-f[0],M=w-f[1];if(b&&(r[s].x-=b*x/y,r[s].y-=b*M/y),g){var I=g.leaf,D=g.single,R=g.others,_=g.center,z=(null==_?void 0:_(v,a,u,h,c))||{x:0,y:0,centerStrength:0},T=z.x,O=z.y,C=z.centerStrength;if(!l(T)||!l(O))return;var L=(m-T)/y,P=(w-O)/y;if(C&&(r[s].x-=C*L,r[s].y-=C*P),0===S){var q=D(v);if(!q)return;return r[s].x-=q*L,void(r[s].y-=q*P)}if(0===E||0===N){var j=I(v,a,u);if(!j)return;return r[s].x-=j*L,void(r[s].y-=j*P)}var V=R(v);if(!V)return;r[s].x-=V*L,r[s].y-=V*P}}))},t.prototype.updateVelocity=function(t,e,r,n){var o=n.damping,i=n.maxSpeed,s=n.interval,a=t.getAllNodes();(null==a?void 0:a.length)&&a.forEach((function(t){var n=t.id,a=(r[n].x+e[n].x*s)*o||.01,u=(r[n].y+e[n].y*s)*o||.01,h=Math.sqrt(a*a+u*u);if(h>i){var l=i/h;a*=l,u*=l}r[n]={x:a,y:u}}))},t.prototype.updatePosition=function(t,e,r,n){var o=this,i=n.distanceThresholdMode,s=n.interval,a=e.getAllNodes();if(null==a?void 0:a.length){var u=0;"max"===i?this.judgingDistance=-1/0:"min"===i&&(this.judgingDistance=1/0),a.forEach((function(n){var a=n.id,h=t.getNode(a);if(l(h.data.fx)&&l(h.data.fy))e.mergeNodeData(a,{x:h.data.fx,y:h.data.fy});else{var c=r[a].x*s,f=r[a].y*s;e.mergeNodeData(a,{x:n.data.x+c,y:n.data.y+f});var d=Math.sqrt(c*c+f*f);switch(i){case"max":o.judgingDistance<d&&(o.judgingDistance=d);break;case"min":o.judgingDistance>d&&(o.judgingDistance=d);break;default:u+=d}}})),i&&"mean"!==i||(this.judgingDistance=u/a.length)}else this.judgingDistance=0},t}(),It=function(t,e){var r=t.getAllNodes();if(!(null==r?void 0:r.length))return{};var n={};return r.forEach((function(r,o){1===t.getDegree(r.id,"both")&&(n[r.id]=Dt(t,"leaf",r,e))})),n},Dt=function(t,e,r,n){var o=t.getDegree(r.id,"in"),i=t.getDegree(r.id,"out"),s=r,a=[];return 0===o?(s=t.getSuccessors(r.id)[0],a=t.getNeighbors(s.id)):0===i&&(s=t.getPredecessors(r.id)[0],a=t.getNeighbors(s.id)),a=a.filter((function(e){return 0===t.getDegree(e.id,"in")||0===t.getDegree(e.id,"out")})),{coreNode:s,siblingLeaves:a,sameTypeLeaves:Rt(t,e,n,r,a)}},Rt=function(t,e,r,n,o){var i=n.data[r]||"",s=(null==o?void 0:o.filter((function(t){return t.data[r]===i})))||[];return"leaf"===e&&(s=s.filter((function(e){return 0===t.getDegree(e.id,"in")||0===t.getDegree(e.id,"out")}))),s},_t=function(t){var e={x:0,y:0};t.forEach((function(t){var r=t.data,n=r.x,o=r.y;e.x+=n||0,e.y+=o||0}));var r=t.length||1;return{x:e.x/r,y:e.y/r}},zt=function(t,e){return e.map((function(e){var n=e.id,o=e.data,i=t.getNode(n);return r(r({},i),{data:r(r({},i.data),{x:o.x,y:o.y})})}))},Tt={maxIteration:1e3,gravity:10,speed:5,clustering:!1,clusterGravity:10,width:300,height:300,nodeClusterBy:"cluster"},Ot=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="fruchterman",this.timeInterval=0,this.running=!1,this.options=r(r({},Tt),t)}return t.prototype.execute=function(t,e){return this.genericFruchtermanLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericFruchtermanLayout(!0,t,e)},t.prototype.stop=function(){this.timeInterval&&"undefined"!=typeof window&&window.clearInterval(this.timeInterval),this.running=!1},t.prototype.restart=function(){this.running=!0},t.prototype.tick=function(t){var e=this;if(void 0===t&&(t=this.options.maxIteration||1),this.lastResult)return this.lastResult;for(var r=0;r<t;r++)this.runOneStep(this.lastGraph,this.lastClusterMap,this.lastOptions);var n={nodes:this.lastLayoutNodes,edges:this.lastLayoutEdges};return this.lastAssign&&n.nodes.forEach((function(t){return e.lastGraph.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})})),this.lastOptions.onLayoutEnd&&this.lastOptions.onLayoutEnd(n),n},t.prototype.genericFruchtermanLayout=function(t,e,n){var o=this;if(!this.running){var i=this.formatOptions(n),a=i.layoutInvisibles,u=i.width,h=i.height,l=i.center,c=i.clustering,f=i.nodeClusterBy,d=i.maxIteration,g=i.onTick,p=i.onLayoutEnd,m=e.getAllNodes(),w=e.getAllEdges();if(a||(m=m.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e})),w=w.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e}))),!(null==m?void 0:m.length)){var v={nodes:[],edges:w};return this.lastResult=v,null==p||p(v),v}if(1===m.length)return t&&e.mergeNodeData(m[0].id,{x:l[0],y:l[1]}),v={nodes:[r(r({},m[0]),{data:r(r({},m[0].data),{x:l[0],y:l[1]})})],edges:w},this.lastResult=v,null==p||p(v),v;var x=m.map((function(t){return y(t,[u,h])})),M=new s({nodes:x,edges:w}),b={};if(c&&x.forEach((function(t){var e=t.data[f];b[e]||(b[e]={name:e,cx:0,cy:0,count:0})})),this.lastLayoutNodes=x,this.lastLayoutEdges=w,this.lastAssign=t,this.lastGraph=M,this.lastOptions=i,this.lastClusterMap=b,"undefined"!=typeof window){var E=0;return this.timeInterval=window.setInterval((function(){if(o.running&&(o.runOneStep(M,b,i),t&&x.forEach((function(t){var r=t.id,n=t.data;return e.mergeNodeData(r,{x:n.x,y:n.y})})),null==g||g({nodes:x,edges:w}),++E>=d)){try{null==p||p({nodes:x,edges:w})}catch(t){console.warn("onLayoutEnd failed",t)}window.clearInterval(o.timeInterval)}}),0),this.running=!0,{nodes:x,edges:w}}}},t.prototype.formatOptions=function(t){void 0===t&&(t={});var e=r(r({},this.options),t),n=e.clustering,o=e.nodeClusterBy,i=e.center,s=e.width,a=e.height;return e.width=s||"undefined"==typeof window?s:window.innerWidth,e.height=a||"undefined"==typeof window?a:window.innerHeight,e.center=i||[e.width/2,e.height/2],e.clustering=n&&!!o,e},t.prototype.runOneStep=function(t,e,r){var n=r.height,o=r.width,i=r.gravity,s=r.center,a=r.speed,u=r.clustering,h=r.nodeClusterBy,c=r.clusterGravity,f=n*o,d=Math.sqrt(f)/10,g=t.getAllNodes(),p=f/(g.length+1),y=Math.sqrt(p),m={};if(this.applyCalculate(t,m,y,p),u){for(var w in e)e[w].cx=0,e[w].cy=0,e[w].count=0;for(var w in g.forEach((function(t){var r=t.data,n=e[r[h]];l(r.x)&&(n.cx+=r.x),l(r.y)&&(n.cy+=r.y),n.count++})),e)e[w].cx/=e[w].count,e[w].cy/=e[w].count;var v=c||i;g.forEach((function(t,r){var n=t.id,o=t.data;if(l(o.x)&&l(o.y)){var i=e[o[h]],s=Math.sqrt((o.x-i.cx)*(o.x-i.cx)+(o.y-i.cy)*(o.y-i.cy)),a=y*v;m[n].x-=a*(o.x-i.cx)/s,m[n].y-=a*(o.y-i.cy)/s}}))}g.forEach((function(t,e){var r=t.id,n=t.data;if(l(n.x)&&l(n.y)){var o=.01*y*i;m[r].x-=o*(n.x-s[0]),m[r].y-=o*(n.y-s[1])}})),g.forEach((function(e,r){var n=e.id,o=e.data;if(l(o.fx)&&l(o.fy))return o.x=o.fx,void(o.y=o.fy);if(l(o.x)&&l(o.y)){var i=Math.sqrt(m[n].x*m[n].x+m[n].y*m[n].y);if(i>0){var s=Math.min(d*(a/800),i);t.mergeNodeData(n,{x:o.x+m[n].x/i*s,y:o.y+m[n].y/i*s})}}}))},t.prototype.applyCalculate=function(t,e,r,n){this.calRepulsive(t,e,n),this.calAttractive(t,e,r)},t.prototype.calRepulsive=function(t,e,r){var n=t.getAllNodes();n.forEach((function(t,o){var i=t.data,s=t.id;e[s]={x:0,y:0},n.forEach((function(t,n){var a=t.data,u=t.id;if(!(o<=n)&&l(i.x)&&l(a.x)&&l(i.y)&&l(a.y)){var h=i.x-a.x,c=i.y-a.y,f=h*h+c*c;0===f&&(f=1,h=.01,c=.01);var d=r/f,g=h*d,p=c*d;e[s].x+=g,e[s].y+=p,e[u].x-=g,e[u].y-=p}}))}))},t.prototype.calAttractive=function(t,e,r){t.getAllEdges().forEach((function(n){var o=n.source,i=n.target;if(o&&i&&o!==i){var s=t.getNode(o).data,a=t.getNode(i).data;if(l(a.x)&&l(s.x)&&l(a.y)&&l(s.y)){var u=a.x-s.x,h=a.y-s.y,c=Math.sqrt(u*u+h*h)/r,f=u*c,d=h*c;e[o].x+=f,e[o].y+=d,e[i].x-=f,e[i].y-=d}}}))},t}(),Ct={begin:[0,0],preventOverlap:!0,preventOverlapPadding:10,condense:!1,rows:void 0,cols:void 0,position:void 0,sortBy:"degree",nodeSize:30,width:300,height:300},Lt=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="grid",this.options=r(r({},Ct),t)}return t.prototype.execute=function(t,e){return this.genericGridLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericGridLayout(!0,t,e)},t.prototype.genericGridLayout=function(t,e,n){var o=r(r({},this.options),n),i=o.begin,s=void 0===i?[0,0]:i,u=o.condense,c=o.preventOverlapPadding,f=o.preventOverlap,d=o.rows,g=o.cols,p=o.nodeSpacing,m=o.nodeSize,x=o.width,M=o.height,b=o.layoutInvisibles,E=o.onLayoutEnd,N=o.position,S=o.sortBy,A=e.getAllNodes(),k=e.getAllEdges();b||(A=A.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e})),k=k.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e})));var I=A.length;if(0===I){var D={nodes:[],edges:k};return null==E||E(D),D}if(1===I){t&&e.mergeNodeData(A[0].id,{x:s[0],y:s[1]});var R={nodes:[r(r({},A[0]),{data:r(r({},A[0].data),{x:s[0],y:s[1]})})],edges:k};return null==E||E(R),R}var _=A.map((function(t){return y(t)}));"id"===S||a(S)&&void 0!==_[0].data[S]||(S="degree"),"degree"===S?_.sort((function(t,r){return e.getDegree(r.id,"both")-e.getDegree(t.id,"both")})):"id"===S?_.sort((function(t,e){return l(e.id)&&l(t.id)?e.id-t.id:"".concat(t.id).localeCompare("".concat(e.id))})):_.sort((function(t,e){return e.data[S]-t.data[S]}));var z=x||"undefined"==typeof window?x:window.innerWidth,T=M||"undefined"==typeof window?M:window.innerHeight,O=I,C={rows:d,cols:g};if(null!=d&&null!=g)C.rows=d,C.cols=g;else if(null!=d&&null==g)C.rows=d,C.cols=Math.ceil(O/C.rows);else if(null==d&&null!=g)C.cols=g,C.rows=Math.ceil(O/C.cols);else{var L=Math.sqrt(O*T/z);C.rows=Math.round(L),C.cols=Math.round(z/T*L)}if(C.rows=Math.max(C.rows,1),C.cols=Math.max(C.cols,1),C.cols*C.rows>O)((q=Pt(C))-1)*(P=qt(C))>=O?Pt(C,q-1):(P-1)*q>=O&&qt(C,P-1);else for(;C.cols*C.rows<O;){var P,q=Pt(C);((P=qt(C))+1)*q>=O?qt(C,P+1):Pt(C,q+1)}var j=u?0:z/C.cols,V=u?0:T/C.rows;if(f||p){var F=w(10,p),$=v(30,m,!1);_.forEach((function(t){t.data.x&&t.data.y||(t.data.x=0,t.data.y=0);var r,n,o=e.getNode(t.id),i=$(o)||30;h(i)?(r=i[0],n=i[1]):(r=i,n=i);var s=void 0!==F?F(t):c,a=r+s,u=n+s;j=Math.max(j,a),V=Math.max(V,u)}))}for(var G={},U={row:0,col:0},B={},K=0;K<_.length;K++){var W=_[K],H=void 0;if(N&&(H=N(e.getNode(W.id))),H&&(void 0!==H.row||void 0!==H.col)){var J={row:H.row,col:H.col};if(void 0===J.col)for(J.col=0;jt(G,J);)J.col++;else if(void 0===J.row)for(J.row=0;jt(G,J);)J.row++;B[W.id]=J,Vt(G,J)}$t(W,s,j,V,B,C,U,G)}var Y={nodes:_,edges:k};return null==E||E(Y),t&&_.forEach((function(t){e.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})})),Y},t}(),Pt=function(t,e){var r,n=t.rows||5,o=t.cols||5;return null==e?r=Math.min(n,o):Math.min(n,o)===t.rows?t.rows=e:t.cols=e,r},qt=function(t,e){var r,n=t.rows||5,o=t.cols||5;return null==e?r=Math.max(n,o):Math.max(n,o)===t.rows?t.rows=e:t.cols=e,r},jt=function(t,e){return t["c-".concat(e.row,"-").concat(e.col)]||!1},Vt=function(t,e){return t["c-".concat(e.row,"-").concat(e.col)]=!0},Ft=function(t,e){var r=t.cols||5;e.col++,e.col>=r&&(e.col=0,e.row++)},$t=function(t,e,r,n,o,i,s,a){var u,h,l=o[t.id];if(l)u=l.col*r+r/2+e[0],h=l.row*n+n/2+e[1];else{for(;jt(a,s);)Ft(i,s);u=s.col*r+r/2+e[0],h=s.row*n+n/2+e[1],Vt(a,s),Ft(i,s)}t.data.x=u,t.data.y=h};const Gt=Object.prototype.toString;function Ut(t){return Gt.call(t).endsWith("Array]")}function Bt(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!Ut(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");var r=e.fromIndex,n=void 0===r?0:r,o=e.toIndex,i=void 0===o?t.length:o;if(n<0||n>=t.length||!Number.isInteger(n))throw new Error("fromIndex must be a positive integer smaller than length");if(i<=n||i>t.length||!Number.isInteger(i))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var s=t[n],a=n+1;a<i;a++)t[a]>s&&(s=t[a]);return s}function Kt(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!Ut(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");var r=e.fromIndex,n=void 0===r?0:r,o=e.toIndex,i=void 0===o?t.length:o;if(n<0||n>=t.length||!Number.isInteger(n))throw new Error("fromIndex must be a positive integer smaller than length");if(i<=n||i>t.length||!Number.isInteger(i))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var s=t[n],a=n+1;a<i;a++)t[a]<s&&(s=t[a]);return s}function Wt(t){var e,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!Ut(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");if(void 0!==r.output){if(!Ut(r.output))throw new TypeError("output option must be an array if specified");e=r.output}else e=new Array(t.length);var n=Kt(t),o=Bt(t);if(n===o)throw new RangeError("minimum and maximum input values are equal. Cannot rescale a constant array");var i=r.min,s=void 0===i?r.autoMinMax?n:0:i,a=r.max,u=void 0===a?r.autoMinMax?o:1:a;if(s>=u)throw new RangeError("min option must be smaller than max option");for(var h=(u-s)/(o-n),l=0;l<t.length;l++)e[l]=(t[l]-n)*h+s;return e}const Ht=" ".repeat(2),Jt=" ".repeat(4);function Yt(t,e={}){const{maxRows:r=15,maxColumns:n=10,maxNumSize:o=8,padMinus:i="auto"}=e;return`${t.constructor.name} {\\n${Ht}[\\n${Jt}${function(t,e,r,n,o){const{rows:i,columns:s}=t,a=Math.min(i,e),u=Math.min(s,r),h=[];if("auto"===o){o=!1;t:for(let e=0;e<a;e++)for(let r=0;r<u;r++)if(t.get(e,r)<0){o=!0;break t}}for(let e=0;e<a;e++){let r=[];for(let i=0;i<u;i++)r.push(Xt(t.get(e,i),n,o));h.push(`${r.join(" ")}`)}return u!==s&&(h[h.length-1]+=` ... ${s-r} more columns`),a!==i&&h.push(`... ${i-e} more rows`),h.join(`\\n${Jt}`)}(t,r,n,o,i)}\\n${Ht}]\\n${Ht}rows: ${t.rows}\\n${Ht}columns: ${t.columns}\\n}`}function Xt(t,e,r){return(t>=0&&r?` ${Qt(t,e-1)}`:Qt(t,e)).padEnd(e)}function Qt(t,e){let r=t.toString();if(r.length<=e)return r;let n=t.toFixed(e);if(n.length>e&&(n=t.toFixed(Math.max(0,e-(n.length-e)))),n.length<=e&&!n.startsWith("0.000")&&!n.startsWith("-0.000"))return n;let o=t.toExponential(e);return o.length>e&&(o=t.toExponential(Math.max(0,e-(o.length-e)))),o.slice(0)}function Zt(t,e,r){let n=r?t.rows:t.rows-1;if(e<0||e>n)throw new RangeError("Row index out of range")}function te(t,e,r){let n=r?t.columns:t.columns-1;if(e<0||e>n)throw new RangeError("Column index out of range")}function ee(t,e){if(e.to1DArray&&(e=e.to1DArray()),e.length!==t.columns)throw new RangeError("vector size must be the same as the number of columns");return e}function re(t,e){if(e.to1DArray&&(e=e.to1DArray()),e.length!==t.rows)throw new RangeError("vector size must be the same as the number of rows");return e}function ne(t,e,r,n,o){if(5!==arguments.length)throw new RangeError("expected 4 arguments");if(ie("startRow",e),ie("endRow",r),ie("startColumn",n),ie("endColumn",o),e>r||n>o||e<0||e>=t.rows||r<0||r>=t.rows||n<0||n>=t.columns||o<0||o>=t.columns)throw new RangeError("Submatrix indices are out of range")}function oe(t,e=0){let r=[];for(let n=0;n<t;n++)r.push(e);return r}function ie(t,e){if("number"!=typeof e)throw new TypeError(`${t} must be a number`)}function se(t){if(t.isEmpty())throw new Error("Empty matrix has no elements to index")}class ae{static from1DArray(t,e,r){if(t*e!==r.length)throw new RangeError("data length does not match given dimensions");let n=new he(t,e);for(let o=0;o<t;o++)for(let t=0;t<e;t++)n.set(o,t,r[o*e+t]);return n}static rowVector(t){let e=new he(1,t.length);for(let r=0;r<t.length;r++)e.set(0,r,t[r]);return e}static columnVector(t){let e=new he(t.length,1);for(let r=0;r<t.length;r++)e.set(r,0,t[r]);return e}static zeros(t,e){return new he(t,e)}static ones(t,e){return new he(t,e).fill(1)}static rand(t,e,r={}){if("object"!=typeof r)throw new TypeError("options must be an object");const{random:n=Math.random}=r;let o=new he(t,e);for(let r=0;r<t;r++)for(let t=0;t<e;t++)o.set(r,t,n());return o}static randInt(t,e,r={}){if("object"!=typeof r)throw new TypeError("options must be an object");const{min:n=0,max:o=1e3,random:i=Math.random}=r;if(!Number.isInteger(n))throw new TypeError("min must be an integer");if(!Number.isInteger(o))throw new TypeError("max must be an integer");if(n>=o)throw new RangeError("min must be smaller than max");let s=o-n,a=new he(t,e);for(let r=0;r<t;r++)for(let t=0;t<e;t++){let e=n+Math.round(i()*s);a.set(r,t,e)}return a}static eye(t,e,r){void 0===e&&(e=t),void 0===r&&(r=1);let n=Math.min(t,e),o=this.zeros(t,e);for(let t=0;t<n;t++)o.set(t,t,r);return o}static diag(t,e,r){let n=t.length;void 0===e&&(e=n),void 0===r&&(r=e);let o=Math.min(n,e,r),i=this.zeros(e,r);for(let e=0;e<o;e++)i.set(e,e,t[e]);return i}static min(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);let r=t.rows,n=t.columns,o=new he(r,n);for(let i=0;i<r;i++)for(let r=0;r<n;r++)o.set(i,r,Math.min(t.get(i,r),e.get(i,r)));return o}static max(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);let r=t.rows,n=t.columns,o=new this(r,n);for(let i=0;i<r;i++)for(let r=0;r<n;r++)o.set(i,r,Math.max(t.get(i,r),e.get(i,r)));return o}static checkMatrix(t){return ae.isMatrix(t)?t:new he(t)}static isMatrix(t){return null!=t&&"Matrix"===t.klass}get size(){return this.rows*this.columns}apply(t){if("function"!=typeof t)throw new TypeError("callback must be a function");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.call(this,e,r);return this}to1DArray(){let t=[];for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.push(this.get(e,r));return t}to2DArray(){let t=[];for(let e=0;e<this.rows;e++){t.push([]);for(let r=0;r<this.columns;r++)t[e].push(this.get(e,r))}return t}toJSON(){return this.to2DArray()}isRowVector(){return 1===this.rows}isColumnVector(){return 1===this.columns}isVector(){return 1===this.rows||1===this.columns}isSquare(){return this.rows===this.columns}isEmpty(){return 0===this.rows||0===this.columns}isSymmetric(){if(this.isSquare()){for(let t=0;t<this.rows;t++)for(let e=0;e<=t;e++)if(this.get(t,e)!==this.get(e,t))return!1;return!0}return!1}isEchelonForm(){let t=0,e=0,r=-1,n=!0,o=!1;for(;t<this.rows&&n;){for(e=0,o=!1;e<this.columns&&!1===o;)0===this.get(t,e)?e++:1===this.get(t,e)&&e>r?(o=!0,r=e):(n=!1,o=!0);t++}return n}isReducedEchelonForm(){let t=0,e=0,r=-1,n=!0,o=!1;for(;t<this.rows&&n;){for(e=0,o=!1;e<this.columns&&!1===o;)0===this.get(t,e)?e++:1===this.get(t,e)&&e>r?(o=!0,r=e):(n=!1,o=!0);for(let r=e+1;r<this.rows;r++)0!==this.get(t,r)&&(n=!1);t++}return n}echelonForm(){let t=this.clone(),e=0,r=0;for(;e<t.rows&&r<t.columns;){let n=e;for(let o=e;o<t.rows;o++)t.get(o,r)>t.get(n,r)&&(n=o);if(0===t.get(n,r))r++;else{t.swapRows(e,n);let o=t.get(e,r);for(let n=r;n<t.columns;n++)t.set(e,n,t.get(e,n)/o);for(let n=e+1;n<t.rows;n++){let o=t.get(n,r)/t.get(e,r);t.set(n,r,0);for(let i=r+1;i<t.columns;i++)t.set(n,i,t.get(n,i)-t.get(e,i)*o)}e++,r++}}return t}reducedEchelonForm(){let t=this.echelonForm(),e=t.columns,r=t.rows,n=r-1;for(;n>=0;)if(0===t.maxRow(n))n--;else{let o=0,i=!1;for(;o<r&&!1===i;)1===t.get(n,o)?i=!0:o++;for(let r=0;r<n;r++){let i=t.get(r,o);for(let s=o;s<e;s++){let e=t.get(r,s)-i*t.get(n,s);t.set(r,s,e)}}n--}return t}set(){throw new Error("set method is unimplemented")}get(){throw new Error("get method is unimplemented")}repeat(t={}){if("object"!=typeof t)throw new TypeError("options must be an object");const{rows:e=1,columns:r=1}=t;if(!Number.isInteger(e)||e<=0)throw new TypeError("rows must be a positive integer");if(!Number.isInteger(r)||r<=0)throw new TypeError("columns must be a positive integer");let n=new he(this.rows*e,this.columns*r);for(let t=0;t<e;t++)for(let e=0;e<r;e++)n.setSubMatrix(this,this.rows*t,this.columns*e);return n}fill(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,t);return this}neg(){return this.mulS(-1)}getRow(t){Zt(this,t);let e=[];for(let r=0;r<this.columns;r++)e.push(this.get(t,r));return e}getRowVector(t){return he.rowVector(this.getRow(t))}setRow(t,e){Zt(this,t),e=ee(this,e);for(let r=0;r<this.columns;r++)this.set(t,r,e[r]);return this}swapRows(t,e){Zt(this,t),Zt(this,e);for(let r=0;r<this.columns;r++){let n=this.get(t,r);this.set(t,r,this.get(e,r)),this.set(e,r,n)}return this}getColumn(t){te(this,t);let e=[];for(let r=0;r<this.rows;r++)e.push(this.get(r,t));return e}getColumnVector(t){return he.columnVector(this.getColumn(t))}setColumn(t,e){te(this,t),e=re(this,e);for(let r=0;r<this.rows;r++)this.set(r,t,e[r]);return this}swapColumns(t,e){te(this,t),te(this,e);for(let r=0;r<this.rows;r++){let n=this.get(r,t);this.set(r,t,this.get(r,e)),this.set(r,e,n)}return this}addRowVector(t){t=ee(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t[r]);return this}subRowVector(t){t=ee(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t[r]);return this}mulRowVector(t){t=ee(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t[r]);return this}divRowVector(t){t=ee(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t[r]);return this}addColumnVector(t){t=re(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t[e]);return this}subColumnVector(t){t=re(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t[e]);return this}mulColumnVector(t){t=re(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t[e]);return this}divColumnVector(t){t=re(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t[e]);return this}mulRow(t,e){Zt(this,t);for(let r=0;r<this.columns;r++)this.set(t,r,this.get(t,r)*e);return this}mulColumn(t,e){te(this,t);for(let r=0;r<this.rows;r++)this.set(r,t,this.get(r,t)*e);return this}max(t){if(this.isEmpty())return NaN;switch(t){case"row":{const t=new Array(this.rows).fill(Number.NEGATIVE_INFINITY);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)>t[e]&&(t[e]=this.get(e,r));return t}case"column":{const t=new Array(this.columns).fill(Number.NEGATIVE_INFINITY);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)>t[r]&&(t[r]=this.get(e,r));return t}case void 0:{let t=this.get(0,0);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)>t&&(t=this.get(e,r));return t}default:throw new Error(`invalid option: ${t}`)}}maxIndex(){se(this);let t=this.get(0,0),e=[0,0];for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.get(r,n)>t&&(t=this.get(r,n),e[0]=r,e[1]=n);return e}min(t){if(this.isEmpty())return NaN;switch(t){case"row":{const t=new Array(this.rows).fill(Number.POSITIVE_INFINITY);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)<t[e]&&(t[e]=this.get(e,r));return t}case"column":{const t=new Array(this.columns).fill(Number.POSITIVE_INFINITY);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)<t[r]&&(t[r]=this.get(e,r));return t}case void 0:{let t=this.get(0,0);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)<t&&(t=this.get(e,r));return t}default:throw new Error(`invalid option: ${t}`)}}minIndex(){se(this);let t=this.get(0,0),e=[0,0];for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.get(r,n)<t&&(t=this.get(r,n),e[0]=r,e[1]=n);return e}maxRow(t){if(Zt(this,t),this.isEmpty())return NaN;let e=this.get(t,0);for(let r=1;r<this.columns;r++)this.get(t,r)>e&&(e=this.get(t,r));return e}maxRowIndex(t){Zt(this,t),se(this);let e=this.get(t,0),r=[t,0];for(let n=1;n<this.columns;n++)this.get(t,n)>e&&(e=this.get(t,n),r[1]=n);return r}minRow(t){if(Zt(this,t),this.isEmpty())return NaN;let e=this.get(t,0);for(let r=1;r<this.columns;r++)this.get(t,r)<e&&(e=this.get(t,r));return e}minRowIndex(t){Zt(this,t),se(this);let e=this.get(t,0),r=[t,0];for(let n=1;n<this.columns;n++)this.get(t,n)<e&&(e=this.get(t,n),r[1]=n);return r}maxColumn(t){if(te(this,t),this.isEmpty())return NaN;let e=this.get(0,t);for(let r=1;r<this.rows;r++)this.get(r,t)>e&&(e=this.get(r,t));return e}maxColumnIndex(t){te(this,t),se(this);let e=this.get(0,t),r=[0,t];for(let n=1;n<this.rows;n++)this.get(n,t)>e&&(e=this.get(n,t),r[0]=n);return r}minColumn(t){if(te(this,t),this.isEmpty())return NaN;let e=this.get(0,t);for(let r=1;r<this.rows;r++)this.get(r,t)<e&&(e=this.get(r,t));return e}minColumnIndex(t){te(this,t),se(this);let e=this.get(0,t),r=[0,t];for(let n=1;n<this.rows;n++)this.get(n,t)<e&&(e=this.get(n,t),r[0]=n);return r}diag(){let t=Math.min(this.rows,this.columns),e=[];for(let r=0;r<t;r++)e.push(this.get(r,r));return e}norm(t="frobenius"){let e=0;if("max"===t)return this.max();if("frobenius"===t){for(let t=0;t<this.rows;t++)for(let r=0;r<this.columns;r++)e+=this.get(t,r)*this.get(t,r);return Math.sqrt(e)}throw new RangeError(`unknown norm type: ${t}`)}cumulativeSum(){let t=0;for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t+=this.get(e,r),this.set(e,r,t);return this}dot(t){ae.isMatrix(t)&&(t=t.to1DArray());let e=this.to1DArray();if(e.length!==t.length)throw new RangeError("vectors do not have the same size");let r=0;for(let n=0;n<e.length;n++)r+=e[n]*t[n];return r}mmul(t){t=he.checkMatrix(t);let e=this.rows,r=this.columns,n=t.columns,o=new he(e,n),i=new Float64Array(r);for(let s=0;s<n;s++){for(let e=0;e<r;e++)i[e]=t.get(e,s);for(let t=0;t<e;t++){let e=0;for(let n=0;n<r;n++)e+=this.get(t,n)*i[n];o.set(t,s,e)}}return o}strassen2x2(t){t=he.checkMatrix(t);let e=new he(2,2);const r=this.get(0,0),n=t.get(0,0),o=this.get(0,1),i=t.get(0,1),s=this.get(1,0),a=t.get(1,0),u=this.get(1,1),h=t.get(1,1),l=(r+u)*(n+h),c=(s+u)*n,f=r*(i-h),d=u*(a-n),g=(r+o)*h,p=l+d-g+(o-u)*(a+h),y=f+g,m=c+d,w=l-c+f+(s-r)*(n+i);return e.set(0,0,p),e.set(0,1,y),e.set(1,0,m),e.set(1,1,w),e}strassen3x3(t){t=he.checkMatrix(t);let e=new he(3,3);const r=this.get(0,0),n=this.get(0,1),o=this.get(0,2),i=this.get(1,0),s=this.get(1,1),a=this.get(1,2),u=this.get(2,0),h=this.get(2,1),l=this.get(2,2),c=t.get(0,0),f=t.get(0,1),d=t.get(0,2),g=t.get(1,0),p=t.get(1,1),y=t.get(1,2),m=t.get(2,0),w=t.get(2,1),v=t.get(2,2),x=(r-i)*(-f+p),M=(-r+i+s)*(c-f+p),b=(i+s)*(-c+f),E=r*c,N=(-r+u+h)*(c-d+y),S=(-r+u)*(d-y),A=(u+h)*(-c+d),k=(-o+h+l)*(p+m-w),I=(o-l)*(p-w),D=o*m,R=(h+l)*(-m+w),_=(-o+s+a)*(y+m-v),z=(o-a)*(y-v),T=(s+a)*(-m+v),O=E+D+n*g,C=(r+n+o-i-s-h-l)*p+M+b+E+k+D+R,L=E+N+A+(r+n+o-s-a-u-h)*y+D+_+T,P=x+s*(-c+f+g-p-y-m+v)+M+E+D+_+z,q=x+M+b+E+a*w,j=D+_+z+T+i*d,V=E+N+S+h*(-c+d+g-p-y-m+w)+k+I+D,F=k+I+D+R+u*f,$=E+N+S+A+l*v;return e.set(0,0,O),e.set(0,1,C),e.set(0,2,L),e.set(1,0,P),e.set(1,1,q),e.set(1,2,j),e.set(2,0,V),e.set(2,1,F),e.set(2,2,$),e}mmulStrassen(t){t=he.checkMatrix(t);let e=this.clone(),r=e.rows,n=e.columns,o=t.rows,i=t.columns;function s(t,e,r){let n=t.rows,o=t.columns;if(n===e&&o===r)return t;{let n=ae.zeros(e,r);return n=n.setSubMatrix(t,0,0),n}}n!==o&&console.warn(`Multiplying ${r} x ${n} and ${o} x ${i} matrix: dimensions do not match.`);let a=Math.max(r,o),u=Math.max(n,i);return e=s(e,a,u),function t(e,r,n,o){if(n<=512||o<=512)return e.mmul(r);n%2==1&&o%2==1?(e=s(e,n+1,o+1),r=s(r,n+1,o+1)):n%2==1?(e=s(e,n+1,o),r=s(r,n+1,o)):o%2==1&&(e=s(e,n,o+1),r=s(r,n,o+1));let i=parseInt(e.rows/2,10),a=parseInt(e.columns/2,10),u=e.subMatrix(0,i-1,0,a-1),h=r.subMatrix(0,i-1,0,a-1),l=e.subMatrix(0,i-1,a,e.columns-1),c=r.subMatrix(0,i-1,a,r.columns-1),f=e.subMatrix(i,e.rows-1,0,a-1),d=r.subMatrix(i,r.rows-1,0,a-1),g=e.subMatrix(i,e.rows-1,a,e.columns-1),p=r.subMatrix(i,r.rows-1,a,r.columns-1),y=t(ae.add(u,g),ae.add(h,p),i,a),m=t(ae.add(f,g),h,i,a),w=t(u,ae.sub(c,p),i,a),v=t(g,ae.sub(d,h),i,a),x=t(ae.add(u,l),p,i,a),M=t(ae.sub(f,u),ae.add(h,c),i,a),b=t(ae.sub(l,g),ae.add(d,p),i,a),E=ae.add(y,v);E.sub(x),E.add(b);let N=ae.add(w,x),S=ae.add(m,v),A=ae.sub(y,m);A.add(w),A.add(M);let k=ae.zeros(2*E.rows,2*E.columns);return k=k.setSubMatrix(E,0,0),k=k.setSubMatrix(N,E.rows,0),k=k.setSubMatrix(S,0,E.columns),k=k.setSubMatrix(A,E.rows,E.columns),k.subMatrix(0,n-1,0,o-1)}(e,t=s(t,a,u),a,u)}scaleRows(t={}){if("object"!=typeof t)throw new TypeError("options must be an object");const{min:e=0,max:r=1}=t;if(!Number.isFinite(e))throw new TypeError("min must be a number");if(!Number.isFinite(r))throw new TypeError("max must be a number");if(e>=r)throw new RangeError("min must be smaller than max");let n=new he(this.rows,this.columns);for(let t=0;t<this.rows;t++){const o=this.getRow(t);o.length>0&&Wt(o,{min:e,max:r,output:o}),n.setRow(t,o)}return n}scaleColumns(t={}){if("object"!=typeof t)throw new TypeError("options must be an object");const{min:e=0,max:r=1}=t;if(!Number.isFinite(e))throw new TypeError("min must be a number");if(!Number.isFinite(r))throw new TypeError("max must be a number");if(e>=r)throw new RangeError("min must be smaller than max");let n=new he(this.rows,this.columns);for(let t=0;t<this.columns;t++){const o=this.getColumn(t);o.length&&Wt(o,{min:e,max:r,output:o}),n.setColumn(t,o)}return n}flipRows(){const t=Math.ceil(this.columns/2);for(let e=0;e<this.rows;e++)for(let r=0;r<t;r++){let t=this.get(e,r),n=this.get(e,this.columns-1-r);this.set(e,r,n),this.set(e,this.columns-1-r,t)}return this}flipColumns(){const t=Math.ceil(this.rows/2);for(let e=0;e<this.columns;e++)for(let r=0;r<t;r++){let t=this.get(r,e),n=this.get(this.rows-1-r,e);this.set(r,e,n),this.set(this.rows-1-r,e,t)}return this}kroneckerProduct(t){t=he.checkMatrix(t);let e=this.rows,r=this.columns,n=t.rows,o=t.columns,i=new he(e*n,r*o);for(let s=0;s<e;s++)for(let e=0;e<r;e++)for(let r=0;r<n;r++)for(let a=0;a<o;a++)i.set(n*s+r,o*e+a,this.get(s,e)*t.get(r,a));return i}kroneckerSum(t){if(t=he.checkMatrix(t),!this.isSquare()||!t.isSquare())throw new Error("Kronecker Sum needs two Square Matrices");let e=this.rows,r=t.rows,n=this.kroneckerProduct(he.eye(r,r)),o=he.eye(e,e).kroneckerProduct(t);return n.add(o)}transpose(){let t=new he(this.columns,this.rows);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.set(r,e,this.get(e,r));return t}sortRows(t=ue){for(let e=0;e<this.rows;e++)this.setRow(e,this.getRow(e).sort(t));return this}sortColumns(t=ue){for(let e=0;e<this.columns;e++)this.setColumn(e,this.getColumn(e).sort(t));return this}subMatrix(t,e,r,n){ne(this,t,e,r,n);let o=new he(e-t+1,n-r+1);for(let i=t;i<=e;i++)for(let e=r;e<=n;e++)o.set(i-t,e-r,this.get(i,e));return o}subMatrixRow(t,e,r){if(void 0===e&&(e=0),void 0===r&&(r=this.columns-1),e>r||e<0||e>=this.columns||r<0||r>=this.columns)throw new RangeError("Argument out of range");let n=new he(t.length,r-e+1);for(let o=0;o<t.length;o++)for(let i=e;i<=r;i++){if(t[o]<0||t[o]>=this.rows)throw new RangeError(`Row index out of range: ${t[o]}`);n.set(o,i-e,this.get(t[o],i))}return n}subMatrixColumn(t,e,r){if(void 0===e&&(e=0),void 0===r&&(r=this.rows-1),e>r||e<0||e>=this.rows||r<0||r>=this.rows)throw new RangeError("Argument out of range");let n=new he(r-e+1,t.length);for(let o=0;o<t.length;o++)for(let i=e;i<=r;i++){if(t[o]<0||t[o]>=this.columns)throw new RangeError(`Column index out of range: ${t[o]}`);n.set(i-e,o,this.get(i,t[o]))}return n}setSubMatrix(t,e,r){if((t=he.checkMatrix(t)).isEmpty())return this;ne(this,e,e+t.rows-1,r,r+t.columns-1);for(let n=0;n<t.rows;n++)for(let o=0;o<t.columns;o++)this.set(e+n,r+o,t.get(n,o));return this}selection(t,e){!function(t,e){if(!Ut(e))throw new TypeError("row indices must be an array");for(let r=0;r<e.length;r++)if(e[r]<0||e[r]>=t.rows)throw new RangeError("row indices are out of range")}(this,t),function(t,e){if(!Ut(e))throw new TypeError("column indices must be an array");for(let r=0;r<e.length;r++)if(e[r]<0||e[r]>=t.columns)throw new RangeError("column indices are out of range")}(this,e);let r=new he(t.length,e.length);for(let n=0;n<t.length;n++){let o=t[n];for(let t=0;t<e.length;t++){let i=e[t];r.set(n,t,this.get(o,i))}}return r}trace(){let t=Math.min(this.rows,this.columns),e=0;for(let r=0;r<t;r++)e+=this.get(r,r);return e}clone(){let t=new he(this.rows,this.columns);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.set(e,r,this.get(e,r));return t}sum(t){switch(t){case"row":return function(t){let e=oe(t.rows);for(let r=0;r<t.rows;++r)for(let n=0;n<t.columns;++n)e[r]+=t.get(r,n);return e}(this);case"column":return function(t){let e=oe(t.columns);for(let r=0;r<t.rows;++r)for(let n=0;n<t.columns;++n)e[n]+=t.get(r,n);return e}(this);case void 0:return function(t){let e=0;for(let r=0;r<t.rows;r++)for(let n=0;n<t.columns;n++)e+=t.get(r,n);return e}(this);default:throw new Error(`invalid option: ${t}`)}}product(t){switch(t){case"row":return function(t){let e=oe(t.rows,1);for(let r=0;r<t.rows;++r)for(let n=0;n<t.columns;++n)e[r]*=t.get(r,n);return e}(this);case"column":return function(t){let e=oe(t.columns,1);for(let r=0;r<t.rows;++r)for(let n=0;n<t.columns;++n)e[n]*=t.get(r,n);return e}(this);case void 0:return function(t){let e=1;for(let r=0;r<t.rows;r++)for(let n=0;n<t.columns;n++)e*=t.get(r,n);return e}(this);default:throw new Error(`invalid option: ${t}`)}}mean(t){const e=this.sum(t);switch(t){case"row":for(let t=0;t<this.rows;t++)e[t]/=this.columns;return e;case"column":for(let t=0;t<this.columns;t++)e[t]/=this.rows;return e;case void 0:return e/this.size;default:throw new Error(`invalid option: ${t}`)}}variance(t,e={}){if("object"==typeof t&&(e=t,t=void 0),"object"!=typeof e)throw new TypeError("options must be an object");const{unbiased:r=!0,mean:n=this.mean(t)}=e;if("boolean"!=typeof r)throw new TypeError("unbiased must be a boolean");switch(t){case"row":if(!Ut(n))throw new TypeError("mean must be an array");return function(t,e,r){const n=t.rows,o=t.columns,i=[];for(let s=0;s<n;s++){let n=0,a=0,u=0;for(let e=0;e<o;e++)u=t.get(s,e)-r[s],n+=u,a+=u*u;e?i.push((a-n*n/o)/(o-1)):i.push((a-n*n/o)/o)}return i}(this,r,n);case"column":if(!Ut(n))throw new TypeError("mean must be an array");return function(t,e,r){const n=t.rows,o=t.columns,i=[];for(let s=0;s<o;s++){let o=0,a=0,u=0;for(let e=0;e<n;e++)u=t.get(e,s)-r[s],o+=u,a+=u*u;e?i.push((a-o*o/n)/(n-1)):i.push((a-o*o/n)/n)}return i}(this,r,n);case void 0:if("number"!=typeof n)throw new TypeError("mean must be a number");return function(t,e,r){const n=t.rows,o=t.columns,i=n*o;let s=0,a=0,u=0;for(let e=0;e<n;e++)for(let n=0;n<o;n++)u=t.get(e,n)-r,s+=u,a+=u*u;return e?(a-s*s/i)/(i-1):(a-s*s/i)/i}(this,r,n);default:throw new Error(`invalid option: ${t}`)}}standardDeviation(t,e){"object"==typeof t&&(e=t,t=void 0);const r=this.variance(t,e);if(void 0===t)return Math.sqrt(r);for(let t=0;t<r.length;t++)r[t]=Math.sqrt(r[t]);return r}center(t,e={}){if("object"==typeof t&&(e=t,t=void 0),"object"!=typeof e)throw new TypeError("options must be an object");const{center:r=this.mean(t)}=e;switch(t){case"row":if(!Ut(r))throw new TypeError("center must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let n=0;n<t.columns;n++)t.set(r,n,t.get(r,n)-e[r])}(this,r),this;case"column":if(!Ut(r))throw new TypeError("center must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let n=0;n<t.columns;n++)t.set(r,n,t.get(r,n)-e[n])}(this,r),this;case void 0:if("number"!=typeof r)throw new TypeError("center must be a number");return function(t,e){for(let r=0;r<t.rows;r++)for(let n=0;n<t.columns;n++)t.set(r,n,t.get(r,n)-e)}(this,r),this;default:throw new Error(`invalid option: ${t}`)}}scale(t,e={}){if("object"==typeof t&&(e=t,t=void 0),"object"!=typeof e)throw new TypeError("options must be an object");let r=e.scale;switch(t){case"row":if(void 0===r)r=function(t){const e=[];for(let r=0;r<t.rows;r++){let n=0;for(let e=0;e<t.columns;e++)n+=Math.pow(t.get(r,e),2)/(t.columns-1);e.push(Math.sqrt(n))}return e}(this);else if(!Ut(r))throw new TypeError("scale must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let n=0;n<t.columns;n++)t.set(r,n,t.get(r,n)/e[r])}(this,r),this;case"column":if(void 0===r)r=function(t){const e=[];for(let r=0;r<t.columns;r++){let n=0;for(let e=0;e<t.rows;e++)n+=Math.pow(t.get(e,r),2)/(t.rows-1);e.push(Math.sqrt(n))}return e}(this);else if(!Ut(r))throw new TypeError("scale must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let n=0;n<t.columns;n++)t.set(r,n,t.get(r,n)/e[n])}(this,r),this;case void 0:if(void 0===r)r=function(t){const e=t.size-1;let r=0;for(let n=0;n<t.columns;n++)for(let o=0;o<t.rows;o++)r+=Math.pow(t.get(o,n),2)/e;return Math.sqrt(r)}(this);else if("number"!=typeof r)throw new TypeError("scale must be a number");return function(t,e){for(let r=0;r<t.rows;r++)for(let n=0;n<t.columns;n++)t.set(r,n,t.get(r,n)/e)}(this,r),this;default:throw new Error(`invalid option: ${t}`)}}toString(t){return Yt(this,t)}}function ue(t,e){return t-e}ae.prototype.klass="Matrix","undefined"!=typeof Symbol&&(ae.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return Yt(this)}),ae.random=ae.rand,ae.randomInt=ae.randInt,ae.diagonal=ae.diag,ae.prototype.diagonal=ae.prototype.diag,ae.identity=ae.eye,ae.prototype.negate=ae.prototype.neg,ae.prototype.tensorProduct=ae.prototype.kroneckerProduct;class he extends ae{constructor(t,e){if(super(),he.isMatrix(t))return t.clone();if(Number.isInteger(t)&&t>=0){if(this.data=[],!(Number.isInteger(e)&&e>=0))throw new TypeError("nColumns must be a positive integer");for(let r=0;r<t;r++)this.data.push(new Float64Array(e))}else{if(!Ut(t))throw new TypeError("First argument must be a positive number or an array");{const r=t;if("number"!=typeof(e=(t=r.length)?r[0].length:0))throw new TypeError("Data must be a 2D array with at least one element");this.data=[];for(let n=0;n<t;n++){if(r[n].length!==e)throw new RangeError("Inconsistent array dimensions");if(!r[n].every((t=>"number"==typeof t)))throw new TypeError("Input data contains non-numeric values");this.data.push(Float64Array.from(r[n]))}}}this.rows=t,this.columns=e}set(t,e,r){return this.data[t][e]=r,this}get(t,e){return this.data[t][e]}removeRow(t){return Zt(this,t),this.data.splice(t,1),this.rows-=1,this}addRow(t,e){return void 0===e&&(e=t,t=this.rows),Zt(this,t,!0),e=Float64Array.from(ee(this,e)),this.data.splice(t,0,e),this.rows+=1,this}removeColumn(t){te(this,t);for(let e=0;e<this.rows;e++){const r=new Float64Array(this.columns-1);for(let n=0;n<t;n++)r[n]=this.data[e][n];for(let n=t+1;n<this.columns;n++)r[n-1]=this.data[e][n];this.data[e]=r}return this.columns-=1,this}addColumn(t,e){void 0===e&&(e=t,t=this.columns),te(this,t,!0),e=re(this,e);for(let r=0;r<this.rows;r++){const n=new Float64Array(this.columns+1);let o=0;for(;o<t;o++)n[o]=this.data[r][o];for(n[o++]=e[r];o<this.columns+1;o++)n[o]=this.data[r][o-1];this.data[r]=n}return this.columns+=1,this}}!function(t,e){t.prototype.add=function(t){return"number"==typeof t?this.addS(t):this.addM(t)},t.prototype.addS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t);return this},t.prototype.addM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t.get(e,r));return this},t.add=function(t,r){return new e(t).add(r)},t.prototype.sub=function(t){return"number"==typeof t?this.subS(t):this.subM(t)},t.prototype.subS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t);return this},t.prototype.subM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t.get(e,r));return this},t.sub=function(t,r){return new e(t).sub(r)},t.prototype.subtract=t.prototype.sub,t.prototype.subtractS=t.prototype.subS,t.prototype.subtractM=t.prototype.subM,t.subtract=t.sub,t.prototype.mul=function(t){return"number"==typeof t?this.mulS(t):this.mulM(t)},t.prototype.mulS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t);return this},t.prototype.mulM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t.get(e,r));return this},t.mul=function(t,r){return new e(t).mul(r)},t.prototype.multiply=t.prototype.mul,t.prototype.multiplyS=t.prototype.mulS,t.prototype.multiplyM=t.prototype.mulM,t.multiply=t.mul,t.prototype.div=function(t){return"number"==typeof t?this.divS(t):this.divM(t)},t.prototype.divS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t);return this},t.prototype.divM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t.get(e,r));return this},t.div=function(t,r){return new e(t).div(r)},t.prototype.divide=t.prototype.div,t.prototype.divideS=t.prototype.divS,t.prototype.divideM=t.prototype.divM,t.divide=t.div,t.prototype.mod=function(t){return"number"==typeof t?this.modS(t):this.modM(t)},t.prototype.modS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)%t);return this},t.prototype.modM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)%t.get(e,r));return this},t.mod=function(t,r){return new e(t).mod(r)},t.prototype.modulus=t.prototype.mod,t.prototype.modulusS=t.prototype.modS,t.prototype.modulusM=t.prototype.modM,t.modulus=t.mod,t.prototype.and=function(t){return"number"==typeof t?this.andS(t):this.andM(t)},t.prototype.andS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)&t);return this},t.prototype.andM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)&t.get(e,r));return this},t.and=function(t,r){return new e(t).and(r)},t.prototype.or=function(t){return"number"==typeof t?this.orS(t):this.orM(t)},t.prototype.orS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)|t);return this},t.prototype.orM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)|t.get(e,r));return this},t.or=function(t,r){return new e(t).or(r)},t.prototype.xor=function(t){return"number"==typeof t?this.xorS(t):this.xorM(t)},t.prototype.xorS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)^t);return this},t.prototype.xorM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)^t.get(e,r));return this},t.xor=function(t,r){return new e(t).xor(r)},t.prototype.leftShift=function(t){return"number"==typeof t?this.leftShiftS(t):this.leftShiftM(t)},t.prototype.leftShiftS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)<<t);return this},t.prototype.leftShiftM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)<<t.get(e,r));return this},t.leftShift=function(t,r){return new e(t).leftShift(r)},t.prototype.signPropagatingRightShift=function(t){return"number"==typeof t?this.signPropagatingRightShiftS(t):this.signPropagatingRightShiftM(t)},t.prototype.signPropagatingRightShiftS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>t);return this},t.prototype.signPropagatingRightShiftM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>t.get(e,r));return this},t.signPropagatingRightShift=function(t,r){return new e(t).signPropagatingRightShift(r)},t.prototype.rightShift=function(t){return"number"==typeof t?this.rightShiftS(t):this.rightShiftM(t)},t.prototype.rightShiftS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>>t);return this},t.prototype.rightShiftM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>>t.get(e,r));return this},t.rightShift=function(t,r){return new e(t).rightShift(r)},t.prototype.zeroFillRightShift=t.prototype.rightShift,t.prototype.zeroFillRightShiftS=t.prototype.rightShiftS,t.prototype.zeroFillRightShiftM=t.prototype.rightShiftM,t.zeroFillRightShift=t.rightShift,t.prototype.not=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,~this.get(t,e));return this},t.not=function(t){return new e(t).not()},t.prototype.abs=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.abs(this.get(t,e)));return this},t.abs=function(t){return new e(t).abs()},t.prototype.acos=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.acos(this.get(t,e)));return this},t.acos=function(t){return new e(t).acos()},t.prototype.acosh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.acosh(this.get(t,e)));return this},t.acosh=function(t){return new e(t).acosh()},t.prototype.asin=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.asin(this.get(t,e)));return this},t.asin=function(t){return new e(t).asin()},t.prototype.asinh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.asinh(this.get(t,e)));return this},t.asinh=function(t){return new e(t).asinh()},t.prototype.atan=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.atan(this.get(t,e)));return this},t.atan=function(t){return new e(t).atan()},t.prototype.atanh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.atanh(this.get(t,e)));return this},t.atanh=function(t){return new e(t).atanh()},t.prototype.cbrt=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.cbrt(this.get(t,e)));return this},t.cbrt=function(t){return new e(t).cbrt()},t.prototype.ceil=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.ceil(this.get(t,e)));return this},t.ceil=function(t){return new e(t).ceil()},t.prototype.clz32=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.clz32(this.get(t,e)));return this},t.clz32=function(t){return new e(t).clz32()},t.prototype.cos=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.cos(this.get(t,e)));return this},t.cos=function(t){return new e(t).cos()},t.prototype.cosh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.cosh(this.get(t,e)));return this},t.cosh=function(t){return new e(t).cosh()},t.prototype.exp=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.exp(this.get(t,e)));return this},t.exp=function(t){return new e(t).exp()},t.prototype.expm1=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.expm1(this.get(t,e)));return this},t.expm1=function(t){return new e(t).expm1()},t.prototype.floor=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.floor(this.get(t,e)));return this},t.floor=function(t){return new e(t).floor()},t.prototype.fround=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.fround(this.get(t,e)));return this},t.fround=function(t){return new e(t).fround()},t.prototype.log=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log(this.get(t,e)));return this},t.log=function(t){return new e(t).log()},t.prototype.log1p=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log1p(this.get(t,e)));return this},t.log1p=function(t){return new e(t).log1p()},t.prototype.log10=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log10(this.get(t,e)));return this},t.log10=function(t){return new e(t).log10()},t.prototype.log2=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log2(this.get(t,e)));return this},t.log2=function(t){return new e(t).log2()},t.prototype.round=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.round(this.get(t,e)));return this},t.round=function(t){return new e(t).round()},t.prototype.sign=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sign(this.get(t,e)));return this},t.sign=function(t){return new e(t).sign()},t.prototype.sin=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sin(this.get(t,e)));return this},t.sin=function(t){return new e(t).sin()},t.prototype.sinh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sinh(this.get(t,e)));return this},t.sinh=function(t){return new e(t).sinh()},t.prototype.sqrt=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sqrt(this.get(t,e)));return this},t.sqrt=function(t){return new e(t).sqrt()},t.prototype.tan=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.tan(this.get(t,e)));return this},t.tan=function(t){return new e(t).tan()},t.prototype.tanh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.tanh(this.get(t,e)));return this},t.tanh=function(t){return new e(t).tanh()},t.prototype.trunc=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.trunc(this.get(t,e)));return this},t.trunc=function(t){return new e(t).trunc()},t.pow=function(t,r){return new e(t).pow(r)},t.prototype.pow=function(t){return"number"==typeof t?this.powS(t):this.powM(t)},t.prototype.powS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,Math.pow(this.get(e,r),t));return this},t.prototype.powM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,Math.pow(this.get(e,r),t.get(e,r)));return this}}(ae,he);class le extends ae{constructor(t){super(),this.data=t,this.rows=t.length,this.columns=t[0].length}set(t,e,r){return this.data[t][e]=r,this}get(t,e){return this.data[t][e]}}function ce(t,e){let r=0;return Math.abs(t)>Math.abs(e)?(r=e/t,Math.abs(t)*Math.sqrt(1+r*r)):0!==e?(r=t/e,Math.abs(e)*Math.sqrt(1+r*r)):0}class fe{constructor(t,e={}){if((t=le.checkMatrix(t)).isEmpty())throw new Error("Matrix must be non-empty");let r=t.rows,n=t.columns;const{computeLeftSingularVectors:o=!0,computeRightSingularVectors:i=!0,autoTranspose:s=!1}=e;let a,u=Boolean(o),h=Boolean(i),l=!1;if(r<n)if(s){a=t.transpose(),r=a.rows,n=a.columns,l=!0;let e=u;u=h,h=e}else a=t.clone(),console.warn("Computing SVD on a matrix with more columns than rows. Consider enabling autoTranspose");else a=t.clone();let c=Math.min(r,n),f=Math.min(r+1,n),d=new Float64Array(f),g=new he(r,c),p=new he(n,n),y=new Float64Array(n),m=new Float64Array(r),w=new Float64Array(f);for(let t=0;t<f;t++)w[t]=t;let v=Math.min(r-1,n),x=Math.max(0,Math.min(n-2,r)),M=Math.max(v,x);for(let t=0;t<M;t++){if(t<v){d[t]=0;for(let e=t;e<r;e++)d[t]=ce(d[t],a.get(e,t));if(0!==d[t]){a.get(t,t)<0&&(d[t]=-d[t]);for(let e=t;e<r;e++)a.set(e,t,a.get(e,t)/d[t]);a.set(t,t,a.get(t,t)+1)}d[t]=-d[t]}for(let e=t+1;e<n;e++){if(t<v&&0!==d[t]){let n=0;for(let o=t;o<r;o++)n+=a.get(o,t)*a.get(o,e);n=-n/a.get(t,t);for(let o=t;o<r;o++)a.set(o,e,a.get(o,e)+n*a.get(o,t))}y[e]=a.get(t,e)}if(u&&t<v)for(let e=t;e<r;e++)g.set(e,t,a.get(e,t));if(t<x){y[t]=0;for(let e=t+1;e<n;e++)y[t]=ce(y[t],y[e]);if(0!==y[t]){y[t+1]<0&&(y[t]=0-y[t]);for(let e=t+1;e<n;e++)y[e]/=y[t];y[t+1]+=1}if(y[t]=-y[t],t+1<r&&0!==y[t]){for(let e=t+1;e<r;e++)m[e]=0;for(let e=t+1;e<r;e++)for(let r=t+1;r<n;r++)m[e]+=y[r]*a.get(e,r);for(let e=t+1;e<n;e++){let n=-y[e]/y[t+1];for(let o=t+1;o<r;o++)a.set(o,e,a.get(o,e)+n*m[o])}}if(h)for(let e=t+1;e<n;e++)p.set(e,t,y[e])}}let b=Math.min(n,r+1);if(v<n&&(d[v]=a.get(v,v)),r<b&&(d[b-1]=0),x+1<b&&(y[x]=a.get(x,b-1)),y[b-1]=0,u){for(let t=v;t<c;t++){for(let e=0;e<r;e++)g.set(e,t,0);g.set(t,t,1)}for(let t=v-1;t>=0;t--)if(0!==d[t]){for(let e=t+1;e<c;e++){let n=0;for(let o=t;o<r;o++)n+=g.get(o,t)*g.get(o,e);n=-n/g.get(t,t);for(let o=t;o<r;o++)g.set(o,e,g.get(o,e)+n*g.get(o,t))}for(let e=t;e<r;e++)g.set(e,t,-g.get(e,t));g.set(t,t,1+g.get(t,t));for(let e=0;e<t-1;e++)g.set(e,t,0)}else{for(let e=0;e<r;e++)g.set(e,t,0);g.set(t,t,1)}}if(h)for(let t=n-1;t>=0;t--){if(t<x&&0!==y[t])for(let e=t+1;e<n;e++){let r=0;for(let o=t+1;o<n;o++)r+=p.get(o,t)*p.get(o,e);r=-r/p.get(t+1,t);for(let o=t+1;o<n;o++)p.set(o,e,p.get(o,e)+r*p.get(o,t))}for(let e=0;e<n;e++)p.set(e,t,0);p.set(t,t,1)}let E=b-1,N=0,S=Number.EPSILON;for(;b>0;){let t,e;for(t=b-2;t>=-1&&-1!==t;t--){const e=Number.MIN_VALUE+S*Math.abs(d[t]+Math.abs(d[t+1]));if(Math.abs(y[t])<=e||Number.isNaN(y[t])){y[t]=0;break}}if(t===b-2)e=4;else{let r;for(r=b-1;r>=t&&r!==t;r--){let e=(r!==b?Math.abs(y[r]):0)+(r!==t+1?Math.abs(y[r-1]):0);if(Math.abs(d[r])<=S*e){d[r]=0;break}}r===t?e=3:r===b-1?e=1:(e=2,t=r)}switch(t++,e){case 1:{let e=y[b-2];y[b-2]=0;for(let r=b-2;r>=t;r--){let o=ce(d[r],e),i=d[r]/o,s=e/o;if(d[r]=o,r!==t&&(e=-s*y[r-1],y[r-1]=i*y[r-1]),h)for(let t=0;t<n;t++)o=i*p.get(t,r)+s*p.get(t,b-1),p.set(t,b-1,-s*p.get(t,r)+i*p.get(t,b-1)),p.set(t,r,o)}break}case 2:{let e=y[t-1];y[t-1]=0;for(let n=t;n<b;n++){let o=ce(d[n],e),i=d[n]/o,s=e/o;if(d[n]=o,e=-s*y[n],y[n]=i*y[n],u)for(let e=0;e<r;e++)o=i*g.get(e,n)+s*g.get(e,t-1),g.set(e,t-1,-s*g.get(e,n)+i*g.get(e,t-1)),g.set(e,n,o)}break}case 3:{const e=Math.max(Math.abs(d[b-1]),Math.abs(d[b-2]),Math.abs(y[b-2]),Math.abs(d[t]),Math.abs(y[t])),o=d[b-1]/e,i=d[b-2]/e,s=y[b-2]/e,a=d[t]/e,l=y[t]/e,c=((i+o)*(i-o)+s*s)/2,f=o*s*(o*s);let m=0;0===c&&0===f||(m=c<0?0-Math.sqrt(c*c+f):Math.sqrt(c*c+f),m=f/(c+m));let w=(a+o)*(a-o)+m,v=a*l;for(let e=t;e<b-1;e++){let o=ce(w,v);0===o&&(o=Number.MIN_VALUE);let i=w/o,s=v/o;if(e!==t&&(y[e-1]=o),w=i*d[e]+s*y[e],y[e]=i*y[e]-s*d[e],v=s*d[e+1],d[e+1]=i*d[e+1],h)for(let t=0;t<n;t++)o=i*p.get(t,e)+s*p.get(t,e+1),p.set(t,e+1,-s*p.get(t,e)+i*p.get(t,e+1)),p.set(t,e,o);if(o=ce(w,v),0===o&&(o=Number.MIN_VALUE),i=w/o,s=v/o,d[e]=o,w=i*y[e]+s*d[e+1],d[e+1]=-s*y[e]+i*d[e+1],v=s*y[e+1],y[e+1]=i*y[e+1],u&&e<r-1)for(let t=0;t<r;t++)o=i*g.get(t,e)+s*g.get(t,e+1),g.set(t,e+1,-s*g.get(t,e)+i*g.get(t,e+1)),g.set(t,e,o)}y[b-2]=w,N+=1;break}case 4:if(d[t]<=0&&(d[t]=d[t]<0?-d[t]:0,h))for(let e=0;e<=E;e++)p.set(e,t,-p.get(e,t));for(;t<E&&!(d[t]>=d[t+1]);){let e=d[t];if(d[t]=d[t+1],d[t+1]=e,h&&t<n-1)for(let r=0;r<n;r++)e=p.get(r,t+1),p.set(r,t+1,p.get(r,t)),p.set(r,t,e);if(u&&t<r-1)for(let n=0;n<r;n++)e=g.get(n,t+1),g.set(n,t+1,g.get(n,t)),g.set(n,t,e);t++}N=0,b--}}if(l){let t=p;p=g,g=t}this.m=r,this.n=n,this.s=d,this.U=g,this.V=p}solve(t){let e=t,r=this.threshold,n=this.s.length,o=he.zeros(n,n);for(let t=0;t<n;t++)Math.abs(this.s[t])<=r?o.set(t,t,0):o.set(t,t,1/this.s[t]);let i=this.U,s=this.rightSingularVectors,a=s.mmul(o),u=s.rows,h=i.rows,l=he.zeros(u,h);for(let t=0;t<u;t++)for(let e=0;e<h;e++){let r=0;for(let o=0;o<n;o++)r+=a.get(t,o)*i.get(e,o);l.set(t,e,r)}return l.mmul(e)}solveForDiagonal(t){return this.solve(he.diag(t))}inverse(){let t=this.V,e=this.threshold,r=t.rows,n=t.columns,o=new he(r,this.s.length);for(let i=0;i<r;i++)for(let r=0;r<n;r++)Math.abs(this.s[r])>e&&o.set(i,r,t.get(i,r)/this.s[r]);let i=this.U,s=i.rows,a=i.columns,u=new he(r,s);for(let t=0;t<r;t++)for(let e=0;e<s;e++){let r=0;for(let n=0;n<a;n++)r+=o.get(t,n)*i.get(e,n);u.set(t,e,r)}return u}get condition(){return this.s[0]/this.s[Math.min(this.m,this.n)-1]}get norm2(){return this.s[0]}get rank(){let t=Math.max(this.m,this.n)*this.s[0]*Number.EPSILON,e=0,r=this.s;for(let n=0,o=r.length;n<o;n++)r[n]>t&&e++;return e}get diagonal(){return Array.from(this.s)}get threshold(){return Number.EPSILON/2*Math.max(this.m,this.n)*this.s[0]}get leftSingularVectors(){return this.U}get rightSingularVectors(){return this.V}get diagonalMatrix(){return he.diag(this.s)}}var de,ge={center:[0,0],linkDistance:50},pe=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="mds",this.options=r(r({},ge),t)}return t.prototype.execute=function(t,e){return this.genericMDSLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericMDSLayout(!0,t,e)},t.prototype.genericMDSLayout=function(t,e,n){var o=r(r({},this.options),n),i=o.center,s=void 0===i?[0,0]:i,a=o.linkDistance,u=void 0===a?50:a,h=o.layoutInvisibles,l=o.onLayoutEnd,d=e.getAllNodes(),g=e.getAllEdges();if(h||(d=d.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e})),g=g.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e}))),!d||0===d.length){var p={nodes:[],edges:g};return null==l||l(p),p}if(1===d.length){t&&e.mergeNodeData(d[0].id,{x:s[0],y:s[1]});var m={nodes:[r(r({},d[0]),{data:r(r({},d[0].data),{x:s[0],y:s[1]})})],edges:g};return null==l||l(m),m}var w=f({nodes:d,edges:g},!1),v=c(w);ye(v);var x=function(t,e){var r=[];return t.forEach((function(t){var n=[];t.forEach((function(t){n.push(t*e)})),r.push(n)})),r}(v,u),M=me(x),b=[];M.forEach((function(t,e){var r=y(d[e]);r.data.x=t[0]+s[0],r.data.y=t[1]+s[1],b.push(r)})),t&&b.forEach((function(t){return e.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}));var E={nodes:b,edges:g};return null==l||l(E),E},t}(),ye=function(t){var e=-999999;t.forEach((function(t){t.forEach((function(t){t!==1/0&&e<t&&(e=t)}))})),t.forEach((function(r,n){r.forEach((function(r,o){r===1/0&&(t[n][o]=e)}))}))},me=function(t){var e=he.mul(he.pow(t,2),-.5),r=e.mean("row"),n=e.mean("column"),o=e.mean();e.add(o).subRowVector(r).subColumnVector(n);var i=new fe(e),s=he.sqrt(i.diagonalMatrix).diagonal();return i.leftSingularVectors.toJSON().map((function(t){return he.mul([t],[s]).toJSON()[0].splice(0,2)}))},we={iterations:10,height:10,width:10,speed:100,gravity:10,k:5},ve=function(t,e,r,n,o,i){e.forEach((function(s,a){r[a]={x:0,y:0},e.forEach((function(e,u){if(a!==u&&o[a]===o[u]){var h=s.x-e.x,l=s.y-e.y,c=Math.sqrt(h*h+l*l);if(0===c){c=1;var f=a>u?1:-1;h=.01*f,l=.01*f}if(c<i(t[a])/2+i(t[u])/2){var d=n*n/c;r[a].x+=h/c*d,r[a].y+=l/c*d}}}))}))},xe=function(t,e,r,n,o,i,s,a){var u=i||s/10;return n&&e.forEach((function(e,r){var n=t[r].x-t[o].x,i=t[r].y-t[o].y,s=Math.sqrt(n*n+i*i),a=i/s,u=-n/s,h=Math.sqrt(e.x*e.x+e.y*e.y),l=Math.acos((a*e.x+u*e.y)/h);l>Math.PI/2&&(l-=Math.PI/2,a*=-1,u*=-1);var c=Math.cos(l)*h;e.x=a*c,e.y=u*c})),t.forEach((function(i,s){if(s!==o){var h=Math.sqrt(e[s].x*e[s].x+e[s].y*e[s].y);if(h>0&&s!==o){var l=Math.min(u*(r/800),h);if(i.x+=e[s].x/h*l,i.y+=e[s].y/h*l,n){var c=i.x-t[o].x,f=i.y-t[o].y,d=Math.sqrt(c*c+f*f);c=c/d*a[s],f=f/d*a[s],i.x=t[o].x+c,i.y=t[o].y+f}}}})),t},Me={maxIteration:1e3,focusNode:null,unitRadius:null,linkDistance:50,preventOverlap:!1,strictRadial:!0,maxPreventOverlapIteration:200,sortStrength:10},be=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="radial",this.options=r(r({},Me),t)}return t.prototype.execute=function(t,e){return this.genericRadialLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericRadialLayout(!0,t,e)},t.prototype.genericRadialLayout=function(t,e,n){var s=r(r({},this.options),n),u=s.width,h=s.height,l=s.center,d=s.focusNode,g=s.unitRadius,p=s.nodeSize,m=s.nodeSpacing,w=s.strictRadial,v=s.preventOverlap,x=s.maxPreventOverlapIteration,M=s.sortBy,b=s.linkDistance,E=void 0===b?50:b,N=s.sortStrength,S=void 0===N?10:N,A=s.maxIteration,k=void 0===A?1e3:A,I=s.layoutInvisibles,D=s.onLayoutEnd,R=e.getAllNodes(),_=e.getAllEdges();if(I||(R=R.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e})),_=_.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e}))),!R||0===R.length){var z={nodes:[],edges:_};return null==D||D(z),z}var T=u||"undefined"==typeof window?u:window.innerWidth,O=h||"undefined"==typeof window?h:window.innerHeight,C=l||[T/2,O/2];if(1===R.length){t&&e.mergeNodeData(R[0].id,{x:C[0],y:C[1]});var L={nodes:[r(r({},R[0]),{data:r(r({},R[0].data),{x:C[0],y:C[1]})})],edges:_};return null==D||D(L),L}var P=R[0];if(a(d)){for(var q=0;q<R.length;q++)if(R[q].id===d){P=R[q];break}}else P=d||R[0];var j=Se(R,P.id),V=f({nodes:R,edges:_},!1),F=c(V),$=ke(F,j);Ae(F,j,$+1);var G=F[j],U=T-C[0]>C[0]?C[0]:T-C[0],B=O-C[1]>C[1]?C[1]:O-C[1];0===U&&(U=T/2),0===B&&(B=O/2);var K=Math.min(U,B),W=Math.max.apply(Math,i([],o(G),!1)),H=[],J=g||K/W;G.forEach((function(t,e){H[e]=t*J}));var Y,X=Ee(R,F,E,H,J,M,S),Q=Ne(X),Z=function(t,e,r){try{var n=he.mul(he.pow(e,2),-.5),o=n.mean("row"),i=n.mean("column"),s=n.mean();n.add(s).subRowVector(o).subColumnVector(i);var a=new fe(n),u=he.sqrt(a.diagonalMatrix).diagonal();return a.leftSingularVectors.toJSON().map((function(e){return he.mul([e],[u]).toJSON()[0].splice(0,t)}))}catch(t){for(var h=[],l=0;l<e.length;l++){var c=Math.random()*r,f=Math.random()*r;h.push([c,f])}return h}}(E,X,E),tt=Z.map((function(t){var e=o(t,2),r=e[0],n=e[1];return{x:(isNaN(r)?Math.random()*E:r)-Z[j][0],y:(isNaN(n)?Math.random()*E:n)-Z[j][1]}}));if(this.run(k,tt,Q,X,H,j),v){Y=Ie(p,m);var et={nodes:R,nodeSizeFunc:Y,positions:tt,radii:H,height:O,width:T,strictRadial:Boolean(w),focusIdx:j,iterations:x||200,k:tt.length/4.5};tt=function(t,e){for(var n=r(r({},we),e),o=n.positions,i=n.iterations,s=n.width,a=n.k,u=n.speed,h=void 0===u?100:u,l=n.strictRadial,c=n.focusIdx,f=n.radii,d=void 0===f?[]:f,g=n.nodeSizeFunc,p=t.getAllNodes(),y=[],m=s/10,w=0;w<i;w++)o.forEach((function(t,e){y[e]={x:0,y:0}})),ve(p,o,y,a,d,g),xe(o,y,h,l,c,m,s,d);return o}(e,et)}var rt=[];tt.forEach((function(t,e){var r=y(R[e]);r.data.x=t.x+C[0],r.data.y=t.y+C[1],rt.push(r)})),t&&rt.forEach((function(t){return e.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}));var nt={nodes:rt,edges:_};return null==D||D(nt),nt},t.prototype.run=function(t,e,r,n,o,i){for(var s=0;s<=t;s++){var a=s/t;this.oneIteration(a,e,o,n,r,i)}},t.prototype.oneIteration=function(t,e,r,n,o,i){var s=1-t;e.forEach((function(a,u){var h=d(a,{x:0,y:0}),l=0===h?0:1/h;if(u!==i){var c=0,f=0,g=0;e.forEach((function(t,e){if(u!==e){var r=d(a,t),i=0===r?0:1/r,s=n[e][u];g+=o[u][e],c+=o[u][e]*(t.x+s*(a.x-t.x)*i),f+=o[u][e]*(t.y+s*(a.y-t.y)*i)}}));var p=0===r[u]?0:1/r[u];g*=s,g+=t*p*p,c*=s,c+=t*p*a.x*l,a.x=c/g,f*=s,f+=t*p*a.y*l,a.y=f/g}}))},t}(),Ee=function(t,e,r,n,o,i,s){if(!t)return[];var u=[];if(e){var h={};e.forEach((function(e,l){var c=[];e.forEach((function(e,u){var f,d;if(l===u)c.push(0);else if(n[l]===n[u])if("data"===i)c.push(e*(Math.abs(l-u)*s)/(n[l]/o));else if(i){var g=void 0,p=void 0;if(h[t[l].id])g=h[t[l].id];else{var y=("id"===i?t[l].id:null===(f=t[l].data)||void 0===f?void 0:f[i])||0;g=a(y)?y.charCodeAt(0):y,h[t[l].id]=g}h[t[u].id]?p=h[t[u].id]:(y=("id"===i?t[u].id:null===(d=t[u].data)||void 0===d?void 0:d[i])||0,p=a(y)?y.charCodeAt(0):y,h[t[u].id]=p),c.push(e*(Math.abs(g-p)*s)/(n[l]/o))}else c.push(e*r/(n[l]/o));else{var m=(r+o)/2;c.push(e*m)}})),u.push(c)}))}return u},Ne=function(t){for(var e=t.length,r=t[0].length,n=[],o=0;o<e;o++){for(var i=[],s=0;s<r;s++)0!==t[o][s]?i.push(1/(t[o][s]*t[o][s])):i.push(0);n.push(i)}return n},Se=function(t,e){var r=-1;return t.forEach((function(t,n){t.id===e&&(r=n)})),Math.max(r,0)},Ae=function(t,e,r){for(var n=t.length,o=0;o<n;o++)if(t[e][o]===1/0){t[e][o]=r,t[o][e]=r;for(var i=0;i<n;i++)t[o][i]!==1/0&&t[e][i]===1/0&&(t[e][i]=r+t[o][i],t[i][e]=r+t[o][i])}for(o=0;o<n;o++)if(o!==e)for(i=0;i<n;i++)if(t[o][i]===1/0){var s=Math.abs(t[e][o]-t[e][i]);s=0===s?1:s,t[o][i]=s}},ke=function(t,e){for(var r=0,n=0;n<t[e].length;n++)t[e][n]!==1/0&&(r=t[e][n]>r?t[e][n]:r);return r},Ie=function(t,e){var r;return r=l(e)?function(){return e}:m(e)?e:function(){return 0},t?h(t)?function(e){return(t[0]>t[1]?t[0]:t[1])+r(e)}:function(e){return t+r(e)}:function(t){var e,n;return(null===(e=t.data)||void 0===e?void 0:e.bboxSize)?Math.max(t.data.bboxSize[0],t.data.bboxSize[1])+r(t):(null===(n=t.data)||void 0===n?void 0:n.size)?h(t.data.size)?Math.max(t.data.size[0],t.data.size[1])+r(t):g(t.data.size)?(t.data.size.width>t.data.size.height?t.data.size.width:t.data.size.height)+r(t):t.data.size+r(t):10+r(t)}},De={center:[0,0],width:300,height:300},Re={circular:M,concentric:S,mds:pe,random:function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="random",this.options=r(r({},De),t)}return t.prototype.execute=function(t,e){return this.genericRandomLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericRandomLayout(!0,t,e)},t.prototype.genericRandomLayout=function(t,e,n){var o=r(r({},this.options),n),i=o.center,s=o.width,a=o.height,u=o.layoutInvisibles,h=o.onLayoutEnd,l=e.getAllNodes();u||(l=l.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e})));var c=s||"undefined"==typeof window?s:window.innerWidth,f=a||"undefined"==typeof window?a:window.innerHeight,d=i||[c/2,f/2],g=[];l&&l.forEach((function(t){g.push({id:t.id,data:{x:.9*(Math.random()-.5)*c+d[0],y:.9*(Math.random()-.5)*f+d[1]}})})),t&&g.forEach((function(t){return e.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}));var p={nodes:g,edges:e.getAllEdges()};return null==h||h(p),p},t}(),grid:Lt,radial:be,force:kt,d3force:bt,fruchterman:Ot};function _e(){(null==de?void 0:de.stop)&&de.stop()}function ze(t,e){return r=this,n=void 0,i=function(){var r,n,o,i,a,u,h,l;return function(t,e){var r,n,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(u){return function(a){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(r=1,n&&(o=2&a[0]?n.return:a[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,a[1])).done)return o;switch(n=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,n=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],n=0}finally{r=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}}(this,(function(c){if(r=t.layout,n=r.id,o=r.options,i=r.iterations,a=t.nodes,u=t.edges,h=new s({nodes:a,edges:u}),!(l=Re[n]))throw new Error("Unknown layout id: ".concat(n));return de=new l(o),[2,new Promise((function(t){var r;de.assign(h,{onLayoutEnd:function(r){t([r,e])}}),(r=de).tick&&r.stop&&r.restart&&(de.stop(),de.tick(i))}))]}))},new((o=void 0)||(o=Promise))((function(t,e){function s(t){try{u(i.next(t))}catch(t){e(t)}}function a(t){try{u(i.throw(t))}catch(t){e(t)}}function u(e){var r;e.done?t(e.value):(r=e.value,r instanceof o?r:new o((function(t){t(r)}))).then(s,a)}u((i=i.apply(r,n||[])).next())}));var r,n,o,i}addEventListener("message",(function(t){var r,n=t.data,o=n.type,i=n.method,s=n.id,a=n.params;"RPC"===o&&i&&((r=e[i])?Promise.resolve().then((function(){return r.apply(e,a)})):Promise.reject("No such method")).then((function(t){postMessage({type:"RPC",id:s,result:t})})).catch((function(t){var e={message:t};t.stack&&(e.message=t.message,e.stack=t.stack,e.name=t.name),postMessage({type:"RPC",id:s,error:e})}))})),postMessage({type:"RPC",method:"ready"});\n//# sourceMappingURL=1f8aa319de677a5a27b9.worker.js.map'])),{name:"[fullhash].worker.js"});return URL.revokeObjectURL(URL.createObjectURL(new Blob(['var t={d:(e,r)=>{for(var n in r)t.o(r,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:r[n]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)},e={};t.d(e,{calculateLayout:()=>ze,stopLayout:()=>_e});var r=function(){return r=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var o in e=arguments[r])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},r.apply(this,arguments)};function n(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(t);o<n.length;o++)e.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(t,n[o])&&(r[n[o]]=t[n[o]])}return r}function o(t,e){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var n,o,i=r.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(n=i.next()).done;)s.push(n.value)}catch(t){o={error:t}}finally{try{n&&!n.done&&(r=i.return)&&r.call(i)}finally{if(o)throw o.error}}return s}function i(t,e,r){if(r||2===arguments.length)for(var n,o=0,i=e.length;o<i;o++)!n&&o in e||(n||(n=Array.prototype.slice.call(e,0,o)),n[o]=e[o]);return t.concat(n||Array.prototype.slice.call(e))}Object.create,Object.create;class s{nodeMap=new Map;edgeMap=new Map;inEdgesMap=new Map;outEdgesMap=new Map;treeIndices=new Map;changes=[];batchCount=0;onChanged=()=>{};constructor(t){t&&(t.nodes&&this.addNodes(t.nodes),t.edges&&this.addEdges(t.edges),t.tree&&this.addTree(t.tree),t.onChanged&&(this.onChanged=t.onChanged))}batch=t=>{this.batchCount+=1,t(),this.batchCount-=1,this.batchCount||this.commit()};commit(){const t=this.changes;this.changes=[],this.onChanged({graph:this,changes:t})}reduceChanges(t){let e=[];return t.forEach((t=>{switch(t.type){case"NodeRemoved":{let r=!1;e=e.filter((e=>{if("NodeAdded"===e.type){const n=e.value.id===t.value.id;return n&&(r=!0),!n}return"NodeDataUpdated"===e.type?e.id!==t.value.id:"TreeStructureChanged"!==e.type||e.nodeId!==t.value.id})),r||e.push(t);break}case"EdgeRemoved":{let r=!1;e=e.filter((e=>{if("EdgeAdded"===e.type){const n=e.value.id===t.value.id;return n&&(r=!0),!n}return"EdgeDataUpdated"!==e.type&&"EdgeUpdated"!==e.type||e.id!==t.value.id})),r||e.push(t);break}case"NodeDataUpdated":case"EdgeDataUpdated":case"EdgeUpdated":{const r=e.find((e=>e.type===t.type&&e.id===t.id&&e.propertyName===t.propertyName));r?r.newValue=t.newValue:e.push(t);break}case"TreeStructureDetached":e=e.filter((e=>"TreeStructureAttached"===e.type?e.treeKey!==t.treeKey:"TreeStructureChanged"!==e.type||e.treeKey!==t.treeKey)),e.push(t);break;case"TreeStructureChanged":{const r=e.find((e=>"TreeStructureChanged"===e.type&&e.treeKey===t.treeKey&&e.nodeId===t.nodeId));r?r.newParentId=t.newParentId:e.push(t);break}default:e.push(t)}})),e}checkNodeExistence(t){if(!this.hasNode(t))throw new Error("Node not found for id: "+t)}hasNode(t){return this.nodeMap.has(t)}areNeighbors(t,e){return this.checkNodeExistence(t),this.getNeighbors(e).some((e=>e.id===t))}getNode(t){return this.checkNodeExistence(t),this.nodeMap.get(t)}getRelatedEdges(t,e){this.checkNodeExistence(t);const r=this.inEdgesMap.get(t),n=this.outEdgesMap.get(t);if("in"===e)return Array.from(r);if("out"===e)return Array.from(n);const o=new Set([...r,...n]);return Array.from(o)}getDegree(t,e){return this.getRelatedEdges(t,e).length}getSuccessors(t){const e=this.getRelatedEdges(t,"out").map((t=>t.target));return Array.from(new Set(e)).map((t=>this.getNode(t)))}getPredecessors(t){const e=this.getRelatedEdges(t,"in").map((t=>t.source));return Array.from(new Set(e)).map((t=>this.getNode(t)))}getNeighbors(t){const e=this.getPredecessors(t),r=this.getSuccessors(t);return Array.from(new Set([...e,...r]))}doAddNode(t){if(this.hasNode(t.id))throw new Error("Node already exists: "+t.id);this.nodeMap.set(t.id,t),this.inEdgesMap.set(t.id,new Set),this.outEdgesMap.set(t.id,new Set),this.treeIndices.forEach((e=>{e.childrenMap.set(t.id,new Set)})),this.changes.push({type:"NodeAdded",value:t})}addNodes(t){this.batch((()=>{for(const e of t)this.doAddNode(e)}))}addNode(t){this.addNodes([t])}doRemoveNode(t){const e=this.getNode(t),r=this.inEdgesMap.get(t),n=this.outEdgesMap.get(t);r?.forEach((t=>this.doRemoveEdge(t.id))),n?.forEach((t=>this.doRemoveEdge(t.id))),this.nodeMap.delete(t),this.treeIndices.forEach((e=>{e.childrenMap.get(t)?.forEach((t=>{e.parentMap.delete(t.id)})),e.parentMap.delete(t),e.childrenMap.delete(t)})),this.changes.push({type:"NodeRemoved",value:e})}removeNodes(t){this.batch((()=>{t.forEach((t=>this.doRemoveNode(t)))}))}removeNode(t){this.removeNodes([t])}updateNodeDataProperty(t,e,r){const n=this.getNode(t);this.batch((()=>{const o=n.data[e],i=r;n.data[e]=i,this.changes.push({type:"NodeDataUpdated",id:t,propertyName:e,oldValue:o,newValue:i})}))}mergeNodeData(t,e){this.batch((()=>{Object.entries(e).forEach((([e,r])=>{this.updateNodeDataProperty(t,e,r)}))}))}updateNodeData(...t){const e=t[0],r=this.getNode(e);if("string"==typeof t[1])return void this.updateNodeDataProperty(e,t[1],t[2]);let n;if("function"==typeof t[1]){const e=t[1];n=e(r.data)}else"object"==typeof t[1]&&(n=t[1]);this.batch((()=>{const t=r.data,o=n;r.data=n,this.changes.push({type:"NodeDataUpdated",id:e,oldValue:t,newValue:o})}))}checkEdgeExistence(t){if(!this.hasEdge(t))throw new Error("Edge not found for id: "+t)}hasEdge(t){return this.edgeMap.has(t)}getEdge(t){return this.checkEdgeExistence(t),this.edgeMap.get(t)}getEdgeDetail(t){const e=this.getEdge(t);return{edge:e,source:this.getNode(e.source),target:this.getNode(e.target)}}doAddEdge(t){if(this.hasEdge(t.id))throw new Error("Edge already exists: "+t.id);this.checkNodeExistence(t.source),this.checkNodeExistence(t.target),this.edgeMap.set(t.id,t);const e=this.inEdgesMap.get(t.target),r=this.outEdgesMap.get(t.source);e.add(t),r.add(t),this.changes.push({type:"EdgeAdded",value:t})}addEdges(t){this.batch((()=>{for(const e of t)this.doAddEdge(e)}))}addEdge(t){this.addEdges([t])}doRemoveEdge(t){const e=this.getEdge(t),r=this.outEdgesMap.get(e.source),n=this.inEdgesMap.get(e.target);r.delete(e),n.delete(e),this.edgeMap.delete(t),this.changes.push({type:"EdgeRemoved",value:e})}removeEdges(t){this.batch((()=>{t.forEach((t=>this.doRemoveEdge(t)))}))}removeEdge(t){this.removeEdges([t])}updateEdgeSource(t,e){const r=this.getEdge(t);this.checkNodeExistence(e);const n=r.source,o=e;this.outEdgesMap.get(n).delete(r),this.outEdgesMap.get(o).add(r),r.source=e,this.batch((()=>{this.changes.push({type:"EdgeUpdated",id:t,propertyName:"source",oldValue:n,newValue:o})}))}updateEdgeTarget(t,e){const r=this.getEdge(t);this.checkNodeExistence(e);const n=r.target,o=e;this.inEdgesMap.get(n).delete(r),this.inEdgesMap.get(o).add(r),r.target=e,this.batch((()=>{this.changes.push({type:"EdgeUpdated",id:t,propertyName:"target",oldValue:n,newValue:o})}))}updateEdgeDataProperty(t,e,r){const n=this.getEdge(t);this.batch((()=>{const o=n.data[e],i=r;n.data[e]=i,this.changes.push({type:"EdgeDataUpdated",id:t,propertyName:e,oldValue:o,newValue:i})}))}updateEdgeData(...t){const e=t[0],r=this.getEdge(e);if("string"==typeof t[1])return void this.updateEdgeDataProperty(e,t[1],t[2]);let n;if("function"==typeof t[1]){const e=t[1];n=e(r.data)}else"object"==typeof t[1]&&(n=t[1]);this.batch((()=>{const t=r.data,o=n;r.data=n,this.changes.push({type:"EdgeDataUpdated",id:e,oldValue:t,newValue:o})}))}mergeEdgeData(t,e){this.batch((()=>{Object.entries(e).forEach((([e,r])=>{this.updateEdgeDataProperty(t,e,r)}))}))}checkTreeExistence(t){if(!this.treeIndices.has(t))throw new Error("Tree structure not found for treeKey: "+t)}attachTreeStructure(t){this.treeIndices.has(t)||(this.treeIndices.set(t,{parentMap:new Map,childrenMap:new Map}),this.batch((()=>{this.changes.push({type:"TreeStructureAttached",treeKey:t})})))}detachTreeStructure(t){this.checkTreeExistence(t),this.treeIndices.delete(t),this.batch((()=>{this.changes.push({type:"TreeStructureDetached",treeKey:t})}))}addTree(t,e){this.batch((()=>{this.attachTreeStructure(e);const r=[],n=Array.isArray(t)?t:[t];for(;n.length;){const t=n.shift();r.push(t),t.children&&n.push(...t.children)}this.addNodes(r),r.forEach((t=>{t.children?.forEach((r=>{this.setParent(r.id,t.id,e)}))}))}))}getRoots(t){return this.checkTreeExistence(t),this.getAllNodes().filter((e=>!this.getParent(e.id,t)))}getChildren(t,e){this.checkNodeExistence(t),this.checkTreeExistence(e);const r=this.treeIndices.get(e).childrenMap.get(t);return Array.from(r||[])}getParent(t,e){return this.checkNodeExistence(t),this.checkTreeExistence(e),this.treeIndices.get(e).parentMap.get(t)||null}setParent(t,e,r){this.checkTreeExistence(r);const n=this.treeIndices.get(r),o=this.getNode(t),i=n.parentMap.get(t),s=this.getNode(e);n.parentMap.set(t,s),i&&n.childrenMap.get(i.id)?.delete(o);let a=n.childrenMap.get(s.id);a||(a=new Set,n.childrenMap.set(s.id,a)),a.add(o),this.batch((()=>{this.changes.push({type:"TreeStructureChanged",treeKey:r,nodeId:t,oldParentId:i?.id,newParentId:s.id})}))}getAllNodes(){return Array.from(this.nodeMap.values())}getAllEdges(){return Array.from(this.edgeMap.values())}doBFS(t,e,r){for(;t.length;){const n=t.shift();r(n),e.add(n.id),this.getSuccessors(n.id).forEach((r=>{e.has(r.id)||(e.add(r.id),t.push(r))}))}}bfs(t,e){this.doBFS([this.getNode(t)],new Set,e)}doDFS(t,e,r){r(t),e.add(t.id),this.getSuccessors(t.id).forEach((t=>{e.has(t.id)||this.doDFS(t,e,r)}))}dfs(t,e){this.doDFS(this.getNode(t),new Set,e)}clone(){const t=this.getAllNodes().map((t=>({...t,data:{...t.data}}))),e=this.getAllEdges().map((t=>({...t,data:{...t.data}}))),r=new s({nodes:t,edges:e});return this.treeIndices.forEach((({parentMap:t,childrenMap:e},n)=>{const o=new Map;t.forEach(((t,e)=>{o.set(e,r.getNode(t.id))}));const i=new Map;e.forEach(((t,e)=>{i.set(e,new Set(Array.from(t).map((t=>r.getNode(t.id)))))})),r.treeIndices.set(n,{parentMap:o,childrenMap:i})})),r}toJSON(){return JSON.stringify({nodes:this.getAllNodes(),edges:this.getAllEdges()})}}var a=function(t){return"string"==typeof t},u=/-(\\w)/g,h=(function(t){return t.replace(u,(function(t,e){return e?e.toUpperCase():""}))},Object.create(null),Array.isArray),l=function(t){return"number"==typeof t},c=function(t){for(var e=[],r=t.length,n=0;n<r;n+=1){e[n]=[];for(var o=0;o<r;o+=1)n===o?e[n][o]=0:0!==t[n][o]&&t[n][o]?e[n][o]=t[n][o]:e[n][o]=1/0}for(var i=0;i<r;i+=1)for(n=0;n<r;n+=1)for(o=0;o<r;o+=1)e[n][o]>e[n][i]+e[i][o]&&(e[n][o]=e[n][i]+e[i][o]);return e},f=function(t,e){var r=t.nodes,n=t.edges,o=[],i={};if(!r)throw new Error("invalid nodes data!");return r&&r.forEach((function(t,e){i[t.id]=e,o.push([])})),null==n||n.forEach((function(t){var r=t.source,n=t.target,s=i[r],a=i[n];void 0!==s&&void 0!==a&&(o[s][a]=1,e||(o[a][s]=1))})),o},d=function(t,e){return Math.sqrt((t.x-e.x)*(t.x-e.x)+(t.y-e.y)*(t.y-e.y))},g=function(t){return null!==t&&"object"==typeof t},p=function(t){if(null===t)return t;if(t instanceof Date)return new Date(t.getTime());if(t instanceof Array){var e=[];return t.forEach((function(t){e.push(t)})),e.map((function(t){return p(t)}))}if("object"==typeof t&&Object.keys(t).length){var n=r({},t);return Object.keys(n).forEach((function(t){n[t]=p(n[t])})),n}return t},y=function(t,e){var r=p(t);return r.data=r.data||{},e&&(l(r.data.x)||(r.data.x=Math.random()*e[0]),l(r.data.y)||(r.data.y=Math.random()*e[1])),r},m=function(t){return"function"==typeof t};function w(t,e){return m(e)?e:l(e)?function(){return e}:function(){return t}}function v(t,e,r){return void 0===r&&(r=!0),e||0===e?m(e)?e:l(e)?function(){return e}:h(e)?function(){if(r){var n=Math.max.apply(Math,i([],o(e),!1));return isNaN(n)?t:n}return e}:g(e)?function(){if(r){var n=Math.max(e.width,e.height);return isNaN(n)?t:n}return[e.width,e.height]}:function(){return t}:function(e){var r=(e.data||{}).size;return r?h(r)?r[0]>r[1]?r[0]:r[1]:g(r)?r.width>r.height?r.width:r.height:r:t}}var x={radius:null,startRadius:null,endRadius:null,startAngle:0,endAngle:2*Math.PI,clockwise:!0,divisions:1,ordering:null,angleRatio:1},M=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="circular",this.options=r(r({},x),t)}return t.prototype.execute=function(t,e){return this.genericCircularLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericCircularLayout(!0,t,e)},t.prototype.genericCircularLayout=function(t,e,n){var i=r(r({},this.options),n),s=i.width,a=i.height,u=i.center,h=i.divisions,l=i.startAngle,c=void 0===l?0:l,f=i.endAngle,d=void 0===f?2*Math.PI:f,g=i.angleRatio,p=i.ordering,m=i.clockwise,x=i.nodeSpacing,M=i.nodeSize,N=i.layoutInvisibles,S=i.onLayoutEnd,A=e.getAllNodes(),k=e.getAllEdges();N||(A=A.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e})),k=k.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e})));var I=A.length;if(0===I)return null==S||S({nodes:[],edges:[]}),{nodes:[],edges:[]};var D=o(E(s,a,u),3),R=D[0],_=D[1],z=D[2];if(1===I){t&&e.mergeNodeData(A[0].id,{x:z[0],y:z[1]});var T={nodes:[r(r({},A[0]),{data:r(r({},A[0].data),{x:z[0],y:z[1]})})],edges:k};return null==S||S(T),T}var O=(d-c)/I,C=i.radius,L=i.startRadius,P=i.endRadius;if(x){var q=w(10,x),j=v(10,M),V=-1/0;A.forEach((function(t){var e=j(t);V<e&&(V=e)}));var F=0;A.forEach((function(t,e){F+=0===e?V||10:(q(t)||0)+(V||10)})),C=F/(2*Math.PI)}else C||L||P?!L&&P?L=P:L&&!P&&(P=L):C=Math.min(_,R)/2;var $=O*g,G=[];G="topology"===p?b(e,A):"topology-directed"===p?b(e,A,!0):"degree"===p?function(t,e){var r=[];return e.forEach((function(t,e){r.push(y(t))})),r.sort((function(e,r){return t.getDegree(e.id,"both")-t.getDegree(r.id,"both")})),r}(e,A):A.map((function(t){return y(t)}));for(var U=Math.ceil(I/h),B=0;B<I;++B){var K=C;K||null===L||null===P||(K=L+B*(P-L)/(I-1)),K||(K=10+100*B/(I-1));var W=c+B%U*$+2*Math.PI/h*Math.floor(B/U);m||(W=d-B%U*$-2*Math.PI/h*Math.floor(B/U)),G[B].data.x=z[0]+Math.cos(W)*K,G[B].data.y=z[1]+Math.sin(W)*K}t&&G.forEach((function(t){e.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}));var H={nodes:G,edges:k};return null==S||S(H),H},t}(),b=function(t,e,r){void 0===r&&(r=!1);var n=[y(e[0])],o={},i=e.length;o[e[0].id]=!0;var s=0;return e.forEach((function(a,u){if(0!==u)if(u!==i-1&&t.getDegree(a.id,"both")===t.getDegree(e[u+1].id,"both")&&!t.areNeighbors(n[s].id,a.id)||o[a.id]){for(var h=r?t.getSuccessors(n[s].id):t.getNeighbors(n[s].id),l=!1,c=0;c<h.length;c++){var f=h[c];if(t.getDegree(f.id)===t.getDegree(a.id)&&!o[f.id]){n.push(y(f)),o[f.id]=!0,l=!0;break}}for(var d=0;!l&&(o[e[d].id]||(n.push(y(e[d])),o[e[d].id]=!0,l=!0),++d!==i););}else n.push(y(a)),o[a.id]=!0,s++})),n},E=function(t,e,r){var n=t,o=e,i=r;return n||"undefined"==typeof window||(n=window.innerWidth),o||"undefined"==typeof window||(o=window.innerHeight),i||(i=[n/2,o/2]),[n,o,i]},N={nodeSize:30,minNodeSpacing:10,nodeSpacing:10,preventOverlap:!1,sweep:void 0,equidistant:!1,startAngle:1.5*Math.PI,clockwise:!0,maxLevelDiff:void 0,sortBy:"degree"},S=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="concentric",this.options=r(r({},N),t)}return t.prototype.execute=function(t,e){return this.genericConcentricLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericConcentricLayout(!0,t,e)},t.prototype.genericConcentricLayout=function(t,e,n){var o=r(r({},this.options),n),i=o.center,s=o.width,u=o.height,c=o.sortBy,f=o.maxLevelDiff,d=o.sweep,p=o.clockwise,w=o.equidistant,v=o.minNodeSpacing,x=void 0===v?10:v,M=o.preventOverlap,b=o.startAngle,E=void 0===b?1.5*Math.PI:b,N=o.nodeSize,S=o.nodeSpacing,A=o.layoutInvisibles,k=o.onLayoutEnd,I=e.getAllNodes(),D=e.getAllEdges();A||(I=I.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e})),D=D.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e})));var R=I.length;if(0===R){var _={nodes:[],edges:D};return null==k||k(_),_}var z=s||"undefined"==typeof window?s:window.innerWidth,T=u||"undefined"==typeof window?u:window.innerHeight,O=i||[z/2,T/2];if(1===R){t&&e.mergeNodeData(I[0].id,{x:O[0],y:O[1]});var C={nodes:[r(r({},I[0]),{data:r(r({},I[0].data),{x:O[0],y:O[1]})})],edges:D};return null==k||k(C),C}var L,P=[],q=0;L=h(N)?Math.max(N[0],N[1]):N,h(S)?q=Math.max(S[0],S[1]):l(S)&&(q=S),I.forEach((function(t){var e=y(t);P.push(e);var r=L,n=e.data;h(n.size)?r=Math.max(n.size[0],n.size[1]):l(n.size)?r=n.size:g(n.size)&&(r=Math.max(n.size.width,n.size.height)),L=Math.max(L,r),m(S)&&(q=Math.max(S(t),q))}));var j={};P.forEach((function(t,e){j[t.id]=e}));var V=c;a(V)&&void 0!==P[0].data[V]||(V="degree"),"degree"===V?P.sort((function(t,r){return e.getDegree(r.id,"both")-e.getDegree(t.id,"both")})):P.sort((function(t,e){return e.data[V]-t.data[V]}));var F=P[0],$=(f||("degree"===V?e.getDegree(F.id,"both"):F.data[V]))/4,G=[{nodes:[]}],U=G[0];P.forEach((function(t){if(U.nodes.length>0){var r="degree"===V?Math.abs(e.getDegree(U.nodes[0].id,"both")-e.getDegree(t.id,"both")):Math.abs(U.nodes[0].data[V]-t.data[V]);$&&r>=$&&(U={nodes:[]},G.push(U))}U.nodes.push(t)}));var B=L+(q||x);if(!M){var K=G.length>0&&G[0].nodes.length>1,W=(Math.min(z,T)/2-B)/(G.length+(K?1:0));B=Math.min(B,W)}var H=0;if(G.forEach((function(t){var e=void 0===d?2*Math.PI-2*Math.PI/t.nodes.length:d;if(t.dTheta=e/Math.max(1,t.nodes.length-1),t.nodes.length>1&&M){var r=Math.cos(t.dTheta)-Math.cos(0),n=Math.sin(t.dTheta)-Math.sin(0),o=Math.sqrt(B*B/(r*r+n*n));H=Math.max(o,H)}t.r=H,H+=B})),w){for(var J=0,Y=0,X=0;X<G.length;X++){var Q=(G[X].r||0)-Y;J=Math.max(J,Q)}Y=0,G.forEach((function(t,e){0===e&&(Y=t.r||0),t.r=Y,Y+=J}))}G.forEach((function(t){var e=t.dTheta||0,r=t.r||0;t.nodes.forEach((function(t,n){var o=E+(p?1:-1)*e*n;t.data.x=O[0]+r*Math.cos(o),t.data.y=O[1]+r*Math.sin(o)}))})),t&&P.forEach((function(t){return e.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}));var Z={nodes:P,edges:D};return null==k||k(Z),Z},t}();function A(t,e,r,n){if(isNaN(e)||isNaN(r))return t;var o,i,s,a,u,h,l,c,f,d=t._root,g={data:n},p=t._x0,y=t._y0,m=t._x1,w=t._y1;if(!d)return t._root=g,t;for(;d.length;)if((h=e>=(i=(p+m)/2))?p=i:m=i,(l=r>=(s=(y+w)/2))?y=s:w=s,o=d,!(d=d[c=l<<1|h]))return o[c]=g,t;if(a=+t._x.call(null,d.data),u=+t._y.call(null,d.data),e===a&&r===u)return g.next=d,o?o[c]=g:t._root=g,t;do{o=o?o[c]=new Array(4):t._root=new Array(4),(h=e>=(i=(p+m)/2))?p=i:m=i,(l=r>=(s=(y+w)/2))?y=s:w=s}while((c=l<<1|h)==(f=(u>=s)<<1|a>=i));return o[f]=d,o[c]=g,t}function k(t,e,r,n,o){this.node=t,this.x0=e,this.y0=r,this.x1=n,this.y1=o}function I(t){return t[0]}function D(t){return t[1]}function R(t,e,r){var n=new _(null==e?I:e,null==r?D:r,NaN,NaN,NaN,NaN);return null==t?n:n.addAll(t)}function _(t,e,r,n,o,i){this._x=t,this._y=e,this._x0=r,this._y0=n,this._x1=o,this._y1=i,this._root=void 0}function z(t){for(var e={data:t.data},r=e;t=t.next;)r=r.next={data:t.data};return e}var T=R.prototype=_.prototype;function O(t){return function(){return t}}function C(t){return 1e-6*(t()-.5)}T.copy=function(){var t,e,r=new _(this._x,this._y,this._x0,this._y0,this._x1,this._y1),n=this._root;if(!n)return r;if(!n.length)return r._root=z(n),r;for(t=[{source:n,target:r._root=new Array(4)}];n=t.pop();)for(var o=0;o<4;++o)(e=n.source[o])&&(e.length?t.push({source:e,target:n.target[o]=new Array(4)}):n.target[o]=z(e));return r},T.add=function(t){const e=+this._x.call(null,t),r=+this._y.call(null,t);return A(this.cover(e,r),e,r,t)},T.addAll=function(t){var e,r,n,o,i=t.length,s=new Array(i),a=new Array(i),u=1/0,h=1/0,l=-1/0,c=-1/0;for(r=0;r<i;++r)isNaN(n=+this._x.call(null,e=t[r]))||isNaN(o=+this._y.call(null,e))||(s[r]=n,a[r]=o,n<u&&(u=n),n>l&&(l=n),o<h&&(h=o),o>c&&(c=o));if(u>l||h>c)return this;for(this.cover(u,h).cover(l,c),r=0;r<i;++r)A(this,s[r],a[r],t[r]);return this},T.cover=function(t,e){if(isNaN(t=+t)||isNaN(e=+e))return this;var r=this._x0,n=this._y0,o=this._x1,i=this._y1;if(isNaN(r))o=(r=Math.floor(t))+1,i=(n=Math.floor(e))+1;else{for(var s,a,u=o-r||1,h=this._root;r>t||t>=o||n>e||e>=i;)switch(a=(e<n)<<1|t<r,(s=new Array(4))[a]=h,h=s,u*=2,a){case 0:o=r+u,i=n+u;break;case 1:r=o-u,i=n+u;break;case 2:o=r+u,n=i-u;break;case 3:r=o-u,n=i-u}this._root&&this._root.length&&(this._root=h)}return this._x0=r,this._y0=n,this._x1=o,this._y1=i,this},T.data=function(){var t=[];return this.visit((function(e){if(!e.length)do{t.push(e.data)}while(e=e.next)})),t},T.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]]},T.find=function(t,e,r){var n,o,i,s,a,u,h,l=this._x0,c=this._y0,f=this._x1,d=this._y1,g=[],p=this._root;for(p&&g.push(new k(p,l,c,f,d)),null==r?r=1/0:(l=t-r,c=e-r,f=t+r,d=e+r,r*=r);u=g.pop();)if(!(!(p=u.node)||(o=u.x0)>f||(i=u.y0)>d||(s=u.x1)<l||(a=u.y1)<c))if(p.length){var y=(o+s)/2,m=(i+a)/2;g.push(new k(p[3],y,m,s,a),new k(p[2],o,m,y,a),new k(p[1],y,i,s,m),new k(p[0],o,i,y,m)),(h=(e>=m)<<1|t>=y)&&(u=g[g.length-1],g[g.length-1]=g[g.length-1-h],g[g.length-1-h]=u)}else{var w=t-+this._x.call(null,p.data),v=e-+this._y.call(null,p.data),x=w*w+v*v;if(x<r){var M=Math.sqrt(r=x);l=t-M,c=e-M,f=t+M,d=e+M,n=p.data}}return n},T.remove=function(t){if(isNaN(i=+this._x.call(null,t))||isNaN(s=+this._y.call(null,t)))return this;var e,r,n,o,i,s,a,u,h,l,c,f,d=this._root,g=this._x0,p=this._y0,y=this._x1,m=this._y1;if(!d)return this;if(d.length)for(;;){if((h=i>=(a=(g+y)/2))?g=a:y=a,(l=s>=(u=(p+m)/2))?p=u:m=u,e=d,!(d=d[c=l<<1|h]))return this;if(!d.length)break;(e[c+1&3]||e[c+2&3]||e[c+3&3])&&(r=e,f=c)}for(;d.data!==t;)if(n=d,!(d=d.next))return this;return(o=d.next)&&delete d.next,n?(o?n.next=o:delete n.next,this):e?(o?e[c]=o:delete e[c],(d=e[0]||e[1]||e[2]||e[3])&&d===(e[3]||e[2]||e[1]||e[0])&&!d.length&&(r?r[f]=d:this._root=d),this):(this._root=o,this)},T.removeAll=function(t){for(var e=0,r=t.length;e<r;++e)this.remove(t[e]);return this},T.root=function(){return this._root},T.size=function(){var t=0;return this.visit((function(e){if(!e.length)do{++t}while(e=e.next)})),t},T.visit=function(t){var e,r,n,o,i,s,a=[],u=this._root;for(u&&a.push(new k(u,this._x0,this._y0,this._x1,this._y1));e=a.pop();)if(!t(u=e.node,n=e.x0,o=e.y0,i=e.x1,s=e.y1)&&u.length){var h=(n+i)/2,l=(o+s)/2;(r=u[3])&&a.push(new k(r,h,l,i,s)),(r=u[2])&&a.push(new k(r,n,l,h,s)),(r=u[1])&&a.push(new k(r,h,o,i,l)),(r=u[0])&&a.push(new k(r,n,o,h,l))}return this},T.visitAfter=function(t){var e,r=[],n=[];for(this._root&&r.push(new k(this._root,this._x0,this._y0,this._x1,this._y1));e=r.pop();){var o=e.node;if(o.length){var i,s=e.x0,a=e.y0,u=e.x1,h=e.y1,l=(s+u)/2,c=(a+h)/2;(i=o[0])&&r.push(new k(i,s,a,l,c)),(i=o[1])&&r.push(new k(i,l,a,u,c)),(i=o[2])&&r.push(new k(i,s,c,l,h)),(i=o[3])&&r.push(new k(i,l,c,u,h))}n.push(e)}for(;e=n.pop();)t(e.node,e.x0,e.y0,e.x1,e.y1);return this},T.x=function(t){return arguments.length?(this._x=t,this):this._x},T.y=function(t){return arguments.length?(this._y=t,this):this._y};var L={value:()=>{}};function P(){for(var t,e=0,r=arguments.length,n={};e<r;++e){if(!(t=arguments[e]+"")||t in n||/[\\s.]/.test(t))throw new Error("illegal type: "+t);n[t]=[]}return new q(n)}function q(t){this._=t}function j(t,e){return t.trim().split(/^|\\s+/).map((function(t){var r="",n=t.indexOf(".");if(n>=0&&(r=t.slice(n+1),t=t.slice(0,n)),t&&!e.hasOwnProperty(t))throw new Error("unknown type: "+t);return{type:t,name:r}}))}function V(t,e){for(var r,n=0,o=t.length;n<o;++n)if((r=t[n]).name===e)return r.value}function F(t,e,r){for(var n=0,o=t.length;n<o;++n)if(t[n].name===e){t[n]=L,t=t.slice(0,n).concat(t.slice(n+1));break}return null!=r&&t.push({name:e,value:r}),t}q.prototype=P.prototype={constructor:q,on:function(t,e){var r,n=this._,o=j(t+"",n),i=-1,s=o.length;if(!(arguments.length<2)){if(null!=e&&"function"!=typeof e)throw new Error("invalid callback: "+e);for(;++i<s;)if(r=(t=o[i]).type)n[r]=F(n[r],t.name,e);else if(null==e)for(r in n)n[r]=F(n[r],t.name,null);return this}for(;++i<s;)if((r=(t=o[i]).type)&&(r=V(n[r],t.name)))return r},copy:function(){var t={},e=this._;for(var r in e)t[r]=e[r].slice();return new q(t)},call:function(t,e){if((r=arguments.length-2)>0)for(var r,n,o=new Array(r),i=0;i<r;++i)o[i]=arguments[i+2];if(!this._.hasOwnProperty(t))throw new Error("unknown type: "+t);for(i=0,r=(n=this._[t]).length;i<r;++i)n[i].value.apply(e,o)},apply:function(t,e,r){if(!this._.hasOwnProperty(t))throw new Error("unknown type: "+t);for(var n=this._[t],o=0,i=n.length;o<i;++o)n[o].value.apply(e,r)}};const $=P;var G,U,B=0,K=0,W=0,H=0,J=0,Y=0,X="object"==typeof performance&&performance.now?performance:Date,Q="object"==typeof window&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(t){setTimeout(t,17)};function Z(){return J||(Q(tt),J=X.now()+Y)}function tt(){J=0}function et(){this._call=this._time=this._next=null}function rt(t,e,r){var n=new et;return n.restart(t,e,r),n}function nt(){J=(H=X.now())+Y,B=K=0;try{!function(){Z(),++B;for(var t,e=G;e;)(t=J-e._time)>=0&&e._call.call(void 0,t),e=e._next;--B}()}finally{B=0,function(){for(var t,e,r=G,n=1/0;r;)r._call?(n>r._time&&(n=r._time),t=r,r=r._next):(e=r._next,r._next=null,r=t?t._next=e:G=e);U=t,it(n)}(),J=0}}function ot(){var t=X.now(),e=t-H;e>1e3&&(Y-=e,H=t)}function it(t){B||(K&&(K=clearTimeout(K)),t-J>24?(t<1/0&&(K=setTimeout(nt,t-X.now()-Y)),W&&(W=clearInterval(W))):(W||(H=X.now(),W=setInterval(ot,1e3)),B=1,Q(nt)))}et.prototype=rt.prototype={constructor:et,restart:function(t,e,r){if("function"!=typeof t)throw new TypeError("callback is not a function");r=(null==r?Z():+r)+(null==e?0:+e),this._next||U===this||(U?U._next=this:G=this,U=this),this._call=t,this._time=r,it()},stop:function(){this._call&&(this._call=null,this._time=1/0,it())}};const st=4294967296;function at(t){return t.x}function ut(t){return t.y}var ht=Math.PI*(3-Math.sqrt(5));function lt(t){var e,r=1,n=.001,o=1-Math.pow(n,1/300),i=0,s=.6,a=new Map,u=rt(c),h=$("tick","end"),l=function(){let t=1;return()=>(t=(1664525*t+1013904223)%st)/st}();function c(){f(),h.call("tick",e),r<n&&(u.stop(),h.call("end",e))}function f(n){var u,h,l=t.length;void 0===n&&(n=1);for(var c=0;c<n;++c)for(r+=(i-r)*o,a.forEach((function(t){t(r)})),u=0;u<l;++u)null==(h=t[u]).fx?h.x+=h.vx*=s:(h.x=h.fx,h.vx=0),null==h.fy?h.y+=h.vy*=s:(h.y=h.fy,h.vy=0);return e}function d(){for(var e,r=0,n=t.length;r<n;++r){if((e=t[r]).index=r,null!=e.fx&&(e.x=e.fx),null!=e.fy&&(e.y=e.fy),isNaN(e.x)||isNaN(e.y)){var o=10*Math.sqrt(.5+r),i=r*ht;e.x=o*Math.cos(i),e.y=o*Math.sin(i)}(isNaN(e.vx)||isNaN(e.vy))&&(e.vx=e.vy=0)}}function g(e){return e.initialize&&e.initialize(t,l),e}return null==t&&(t=[]),d(),e={tick:f,restart:function(){return u.restart(c),e},stop:function(){return u.stop(),e},nodes:function(r){return arguments.length?(t=r,d(),a.forEach(g),e):t},alpha:function(t){return arguments.length?(r=+t,e):r},alphaMin:function(t){return arguments.length?(n=+t,e):n},alphaDecay:function(t){return arguments.length?(o=+t,e):+o},alphaTarget:function(t){return arguments.length?(i=+t,e):i},velocityDecay:function(t){return arguments.length?(s=1-t,e):1-s},randomSource:function(t){return arguments.length?(l=t,a.forEach(g),e):l},force:function(t,r){return arguments.length>1?(null==r?a.delete(t):a.set(t,g(r)),e):a.get(t)},find:function(e,r,n){var o,i,s,a,u,h=0,l=t.length;for(null==n?n=1/0:n*=n,h=0;h<l;++h)(s=(o=e-(a=t[h]).x)*o+(i=r-a.y)*i)<n&&(u=a,n=s);return u},on:function(t,r){return arguments.length>1?(h.on(t,r),e):h.on(t)}}}function ct(){var t,e,r,n,o,i=O(-30),s=1,a=1/0,u=.81;function h(r){var o,i=t.length,s=R(t,at,ut).visitAfter(c);for(n=r,o=0;o<i;++o)e=t[o],s.visit(f)}function l(){if(t){var e,r,n=t.length;for(o=new Array(n),e=0;e<n;++e)r=t[e],o[r.index]=+i(r,e,t)}}function c(t){var e,r,n,i,s,a=0,u=0;if(t.length){for(n=i=s=0;s<4;++s)(e=t[s])&&(r=Math.abs(e.value))&&(a+=e.value,u+=r,n+=r*e.x,i+=r*e.y);t.x=n/u,t.y=i/u}else{(e=t).x=e.data.x,e.y=e.data.y;do{a+=o[e.data.index]}while(e=e.next)}t.value=a}function f(t,i,h,l){if(!t.value)return!0;var c=t.x-e.x,f=t.y-e.y,d=l-i,g=c*c+f*f;if(d*d/u<g)return g<a&&(0===c&&(g+=(c=C(r))*c),0===f&&(g+=(f=C(r))*f),g<s&&(g=Math.sqrt(s*g)),e.vx+=c*t.value*n/g,e.vy+=f*t.value*n/g),!0;if(!(t.length||g>=a)){(t.data!==e||t.next)&&(0===c&&(g+=(c=C(r))*c),0===f&&(g+=(f=C(r))*f),g<s&&(g=Math.sqrt(s*g)));do{t.data!==e&&(d=o[t.data.index]*n/g,e.vx+=c*d,e.vy+=f*d)}while(t=t.next)}}return h.initialize=function(e,n){t=e,r=n,l()},h.strength=function(t){return arguments.length?(i="function"==typeof t?t:O(+t),l(),h):i},h.distanceMin=function(t){return arguments.length?(s=t*t,h):Math.sqrt(s)},h.distanceMax=function(t){return arguments.length?(a=t*t,h):Math.sqrt(a)},h.theta=function(t){return arguments.length?(u=t*t,h):Math.sqrt(u)},h}function ft(t){return t.index}function dt(t,e){var r=t.get(e);if(!r)throw new Error("node not found: "+e);return r}function gt(t){var e,r,n,o,i,s,a=ft,u=function(t){return 1/Math.min(o[t.source.index],o[t.target.index])},h=O(30),l=1;function c(n){for(var o=0,a=t.length;o<l;++o)for(var u,h,c,f,d,g,p,y=0;y<a;++y)h=(u=t[y]).source,f=(c=u.target).x+c.vx-h.x-h.vx||C(s),d=c.y+c.vy-h.y-h.vy||C(s),f*=g=((g=Math.sqrt(f*f+d*d))-r[y])/g*n*e[y],d*=g,c.vx-=f*(p=i[y]),c.vy-=d*p,h.vx+=f*(p=1-p),h.vy+=d*p}function f(){if(n){var s,u,h=n.length,l=t.length,c=new Map(n.map(((t,e)=>[a(t,e,n),t])));for(s=0,o=new Array(h);s<l;++s)(u=t[s]).index=s,"object"!=typeof u.source&&(u.source=dt(c,u.source)),"object"!=typeof u.target&&(u.target=dt(c,u.target)),o[u.source.index]=(o[u.source.index]||0)+1,o[u.target.index]=(o[u.target.index]||0)+1;for(s=0,i=new Array(l);s<l;++s)u=t[s],i[s]=o[u.source.index]/(o[u.source.index]+o[u.target.index]);e=new Array(l),d(),r=new Array(l),g()}}function d(){if(n)for(var r=0,o=t.length;r<o;++r)e[r]=+u(t[r],r,t)}function g(){if(n)for(var e=0,o=t.length;e<o;++e)r[e]=+h(t[e],e,t)}return null==t&&(t=[]),c.initialize=function(t,e){n=t,s=e,f()},c.links=function(e){return arguments.length?(t=e,f(),c):t},c.id=function(t){return arguments.length?(a=t,c):a},c.iterations=function(t){return arguments.length?(l=+t,c):l},c.strength=function(t){return arguments.length?(u="function"==typeof t?t:O(+t),d(),c):u},c.distance=function(t){return arguments.length?(h="function"==typeof t?t:O(+t),g(),c):h},c}function pt(t){return t.x+t.vx}function yt(t){return t.y+t.vy}function mt(t){var e,r,n,o=1,i=1;function s(){for(var t,s,u,h,l,c,f,d=e.length,g=0;g<i;++g)for(s=R(e,pt,yt).visitAfter(a),t=0;t<d;++t)u=e[t],c=r[u.index],f=c*c,h=u.x+u.vx,l=u.y+u.vy,s.visit(p);function p(t,e,r,i,s){var a=t.data,d=t.r,g=c+d;if(!a)return e>h+g||i<h-g||r>l+g||s<l-g;if(a.index>u.index){var p=h-a.x-a.vx,y=l-a.y-a.vy,m=p*p+y*y;m<g*g&&(0===p&&(m+=(p=C(n))*p),0===y&&(m+=(y=C(n))*y),m=(g-(m=Math.sqrt(m)))/m*o,u.vx+=(p*=m)*(g=(d*=d)/(f+d)),u.vy+=(y*=m)*g,a.vx-=p*(g=1-g),a.vy-=y*g)}}}function a(t){if(t.data)return t.r=r[t.data.index];for(var e=t.r=0;e<4;++e)t[e]&&t[e].r>t.r&&(t.r=t[e].r)}function u(){if(e){var n,o,i=e.length;for(r=new Array(i),n=0;n<i;++n)o=e[n],r[o.index]=+t(o,n,e)}}return"function"!=typeof t&&(t=O(null==t?1:+t)),s.initialize=function(t,r){e=t,n=r,u()},s.iterations=function(t){return arguments.length?(i=+t,s):i},s.strength=function(t){return arguments.length?(o=+t,s):o},s.radius=function(e){return arguments.length?(t="function"==typeof e?e:O(+e),u(),s):t},s}function wt(t){var e,r,n,o=O(.1);function i(t){for(var o,i=0,s=e.length;i<s;++i)(o=e[i]).vx+=(n[i]-o.x)*r[i]*t}function s(){if(e){var i,s=e.length;for(r=new Array(s),n=new Array(s),i=0;i<s;++i)r[i]=isNaN(n[i]=+t(e[i],i,e))?0:+o(e[i],i,e)}}return"function"!=typeof t&&(t=O(null==t?0:+t)),i.initialize=function(t){e=t,s()},i.strength=function(t){return arguments.length?(o="function"==typeof t?t:O(+t),s(),i):o},i.x=function(e){return arguments.length?(t="function"==typeof e?e:O(+e),s(),i):t},i}function vt(t){var e,r,n,o=O(.1);function i(t){for(var o,i=0,s=e.length;i<s;++i)(o=e[i]).vy+=(n[i]-o.y)*r[i]*t}function s(){if(e){var i,s=e.length;for(r=new Array(s),n=new Array(s),i=0;i<s;++i)r[i]=isNaN(n[i]=+t(e[i],i,e))?0:+o(e[i],i,e)}}return"function"!=typeof t&&(t=O(null==t?0:+t)),i.initialize=function(t){e=t,s()},i.strength=function(t){return arguments.length?(o="function"==typeof t?t:O(+t),s(),i):o},i.y=function(e){return arguments.length?(t="function"==typeof e?e:O(+e),s(),i):t},i}function xt(){function t(t){return function(){return t}}var e,r=function(t){return t.cluster},n=t(1),i=t(-1),s=t(100),a=t(.1),u=[0,0],h=[],l={},c=[],f=100,d=100,g={none:{x:0,y:0}},p=[],y="force",m=!0,w=.1;function v(t){if(!m)return v;e.tick(),M();for(var n=0,o=h.length,i=void 0,s=t*w;n<o;++n)(i=h[n]).vx+=(g[r(i)].x-i.x)*s,i.vy+=(g[r(i)].y-i.y)*s}function x(){h&&function(){if(h&&h.length){if(void 0===r(h[0]))throw Error("Couldnt find the grouping attribute for the nodes. Make sure to set it up with forceInBox.groupBy(\'clusterAttr\') before calling .links()");var t,u,g,y,m,w=(t=[],u=[],g={},{},m=[],y=function(t){var e={};return t.forEach((function(t){var n=r(t);e[n]||(e[n]={count:0,sumforceNodeSize:0})})),t.forEach((function(t){var o=r(t),i=n(t),s=e[o];s.count=s.count+1,s.sumforceNodeSize=s.sumforceNodeSize+Math.PI*(i*i)*1.3,e[o]=s})),e}(h),m=function(t){var e={},n=[];return t.forEach((function(t){var n,o,i,s,a,u=(o=(n=t).source,i=n.target,(s=r(l[o]))<=(a=r(l[i]))?"".concat(s,"~").concat(a):"".concat(a,"~").concat(s)),h=0;void 0!==e[u]&&(h=e[u]),h+=1,e[u]=h})),Object.entries(e).forEach((function(t){var e=o(t,2),r=e[0],i=e[1],s=r.split("~")[0],a=r.split("~")[1];void 0!==s&&void 0!==a&&n.push({source:s,target:a,count:i})})),n}(c),Object.keys(y).forEach((function(e,r){var n=y[e];t.push({id:e,size:n.count,r:Math.sqrt(n.sumforceNodeSize/Math.PI)}),g[e]=r})),m.forEach((function(t){var e=t.source,r=t.target,n=g[e],o=g[r];void 0!==n&&void 0!==o&&u.push({source:n,target:o,count:t.count})})),{nodes:t,links:u});e=lt(w.nodes).force("x",wt(f).strength(.1)).force("y",vt(d).strength(.1)).force("collide",mt((function(t){return t.r})).iterations(4)).force("charge",ct().strength(i)).force("links",gt(w.nodes.length?w.links:[]).distance(s).strength(a)),p=e.nodes(),M()}}()}function M(){return g={none:{x:0,y:0}},p.forEach((function(t){g[t.id]={x:t.x-u[0],y:t.y-u[1]}})),g}function b(t){l={},t.forEach((function(t){l[t.id]=t}))}return v.initialize=function(t){h=t,x()},v.template=function(t){return arguments.length?(y=t,x(),v):y},v.groupBy=function(t){return arguments.length?"string"==typeof t?(r=function(e){return e[t]},v):(r=t,v):r},v.enableGrouping=function(t){return arguments.length?(m=t,v):m},v.strength=function(t){return arguments.length?(w=t,v):w},v.centerX=function(t){return arguments.length?(f=t,v):f},v.centerY=function(t){return arguments.length?(d=t,v):d},v.nodes=function(t){return arguments.length?(b(t||[]),h=t||[],v):h},v.links=function(t){return arguments.length?(c=t||[],x(),v):c},v.forceNodeSize=function(e){return arguments.length?(n="function"==typeof e?e:t(+e),x(),v):n},v.nodeSize=v.forceNodeSize,v.forceCharge=function(e){return arguments.length?(i="function"==typeof e?e:t(+e),x(),v):i},v.forceLinkDistance=function(e){return arguments.length?(s="function"==typeof e?e:t(+e),x(),v):s},v.forceLinkStrength=function(e){return arguments.length?(a="function"==typeof e?e:t(+e),x(),v):a},v.offset=function(t){return arguments.length?(u=t,v):u},v.getFocis=M,v}var Mt={center:[0,0],preventOverlap:!1,nodeSize:void 0,nodeSpacing:void 0,linkDistance:50,forceSimulation:null,alphaDecay:.028,alphaMin:.001,alpha:.3,collideStrength:1,clustering:!1,clusterNodeStrength:-1,clusterEdgeStrength:.1,clusterEdgeDistance:100,clusterFociStrength:.8,clusterNodeSize:10},bt=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="d3force",this.running=!1,this.options=r(r({},Mt),t)}return t.prototype.execute=function(t,e){return this.genericForceLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericForceLayout(!0,t,e)},t.prototype.stop=function(){var t;null===(t=this.forceSimulation)||void 0===t||t.stop(),this.running=!1},t.prototype.restart=function(){var t;null===(t=this.forceSimulation)||void 0===t||t.restart(),this.running=!0},t.prototype.tick=function(t){var e=this;void 0===t&&(t=1),this.forceSimulation.tick(t);var r={nodes:Et(this.lastLayoutNodes),edges:Nt(this.lastLayoutEdges)};return this.lastAssign&&r.nodes.forEach((function(t){return e.lastGraph.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})})),this.lastOptions.onLayoutEnd&&this.lastOptions.onLayoutEnd(r),r},t.prototype.genericForceLayout=function(t,e,n){var o=this,i=r(r({},this.options),n),s=i.layoutInvisibles,a=e.getAllNodes(),u=e.getAllEdges();s||(a=a.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e})),u=u.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e})));var h=a.map((function(t){var e,n;return r(r({},y(t)),{x:null===(e=t.data)||void 0===e?void 0:e.x,y:null===(n=t.data)||void 0===n?void 0:n.y})})),l=u.map((function(t){return y(t)}));if(this.lastLayoutNodes=h,this.lastLayoutEdges=l,this.lastAssign=t,this.lastGraph=e,this.lastOptions=i,!this.running){var c=i.alphaMin,f=i.alphaDecay,d=i.alpha,g=i.nodeStrength,p=i.edgeStrength,m=i.linkDistance,w=i.clustering,v=i.clusterFociStrength,x=i.clusterEdgeDistance,M=i.clusterEdgeStrength,b=i.clusterNodeStrength,E=i.clusterNodeSize,N=i.collideStrength,S=void 0===N?1:N,A=i.center,k=void 0===A?[0,0]:A,I=i.preventOverlap,D=i.nodeSize,R=i.nodeSpacing,_=i.onTick,z=i.onLayoutEnd,T=i.forceSimulation;if(T)w&&((O=xt()).nodes(h),O.links(l)),T.nodes(h),l&&(L=gt().id((function(t){return t.id})).links(l),p&&L.strength(p),m&&L.distance(m),T.force("link",L)),I&&this.overlapProcess(T,{nodeSize:D,nodeSpacing:R,collideStrength:S}),T.alpha(d).restart(),this.running=!0;else try{var O,C=ct();if(g&&C.strength(g),T=lt().nodes(h),w&&((O=xt()).centerX(k[0]).centerY(k[1]).template("force").strength(v),l&&O.links(l),h&&O.nodes(h),O.forceLinkDistance(x).forceLinkStrength(M).forceCharge(b).forceNodeSize(E),T.force("group",O)),T.force("center",function(t,e){var r,n=1;function o(){var o,i,s=r.length,a=0,u=0;for(o=0;o<s;++o)a+=(i=r[o]).x,u+=i.y;for(a=(a/s-t)*n,u=(u/s-e)*n,o=0;o<s;++o)(i=r[o]).x-=a,i.y-=u}return null==t&&(t=0),null==e&&(e=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.strength=function(t){return arguments.length?(n=+t,o):n},o}(k[0],k[1])).force("charge",C).alpha(d).alphaDecay(f).alphaMin(c),I&&this.overlapProcess(T,{nodeSize:D,nodeSpacing:R,collideStrength:S}),l){var L=gt().id((function(t){return t.id})).links(l);p&&L.strength(p),m&&L.distance(m),T.force("link",L)}T.on("tick",(function(){var r=Et(h);null==_||_({nodes:r,edges:Nt(l)}),t&&r.forEach((function(t){return e.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}))})).on("end",(function(){o.running=!1;var r=Et(h);null==z||z({nodes:r,edges:Nt(l)}),t&&r.forEach((function(t){return e.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}))})),this.running=!0}catch(t){this.running=!1,console.warn(t)}this.forceSimulation=T;var P=Et(h),q=Nt(l);return t&&P.forEach((function(t){return e.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})})),{nodes:P,edges:q}}},t.prototype.overlapProcess=function(t,e){var r,n,o=e.nodeSize,i=e.nodeSpacing,s=e.collideStrength;if(n=l(i)?function(){return i}:m(i)?i:function(){return 0},o)if(m(o))r=function(t){return o(t)+n(t)};else if(h(o)){var a=(o[0]>o[1]?o[0]:o[1])/2;r=function(t){return a+n(t)}}else if(l(o)){var u=o/2;r=function(t){return u+n(t)}}else r=function(){return 10};else r=function(t){return t.size?h(t.size)?(t.size[0]>t.size[1]?t.size[0]:t.size[1])/2+n(t):g(t.size)?(t.size.width>t.size.height?t.size.width:t.size.height)/2+n(t):t.size/2+n(t):10+n(t)};t.force("collisionForce",mt(r).strength(s))},t}(),Et=function(t){return t.map((function(t){var e=t.x,o=t.y,i=n(t,["x","y"]);return r(r({},i),{data:r(r({},i.data),{x:e,y:o})})}))},Nt=function(t){return t.map((function(t){var e=t.source,o=t.target,i=n(t,["source","target"]);return r(r({},i),{source:e.id,target:o.id})}))};function St(t){var e=0,r=0,n=0;if(t.length){for(var o=0;o<4;o++)(i=t[o])&&i.weight&&(e+=i.weight,r+=i.x*i.weight,n+=i.y*i.weight);t.x=r/e,t.y=n/e,t.weight=e}else{var i=t;t.x=i.data.x,t.y=i.data.y,t.weight=i.data.weight}}var At={maxIteration:500,gravity:10,factor:1,edgeStrength:200,nodeStrength:1e3,coulombDisScale:.005,damping:.9,maxSpeed:500,minMovement:.4,interval:.02,linkDistance:200,clusterNodeStrength:20,preventOverlap:!0,distanceThresholdMode:"mean"},kt=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="force",this.timeInterval=0,this.judgingDistance=0,this.running=!1,this.options=r(r({},At),t)}return t.prototype.execute=function(t,e){return this.genericForceLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericForceLayout(!0,t,e)},t.prototype.stop=function(){this.timeInterval&&"undefined"!=typeof window&&window.clearInterval(this.timeInterval),this.running=!1},t.prototype.restart=function(){this.running=!0},t.prototype.tick=function(t){var e=this;if(void 0===t&&(t=this.options.maxIteration||1),this.lastResult)return this.lastResult;for(var r=0;(this.judgingDistance>this.lastOptions.minMovement||r<1)&&r<t;r++)this.runOneStep(this.lastCalcGraph,this.lastGraph,r,this.lastVelMap,this.lastOptions),this.updatePosition(this.lastGraph,this.lastCalcGraph,this.lastVelMap,this.lastOptions);var n={nodes:this.lastLayoutNodes,edges:this.lastLayoutEdges};return this.lastAssign&&n.nodes.forEach((function(t){return e.lastGraph.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})})),this.lastOptions.onLayoutEnd&&this.lastOptions.onLayoutEnd(n),n},t.prototype.genericForceLayout=function(t,e,n){var o=this,i=r(r({},this.options),n),a=e.getAllNodes(),u=e.getAllEdges();i.layoutInvisibles||(a=a.filter((function(t){return t.data.visible||void 0===t.data.visible})),u=u.filter((function(t){return t.data.visible||void 0===t.data.visible})));var h=this.formatOptions(i,e),c=h.width,f=h.height,d=h.nodeSize,g=h.getMass,p=h.nodeStrength,y=h.edgeStrength,m=h.linkDistance,w=a.map((function(t){return r(r({},t),{data:r(r({},t.data),{x:l(t.data.x)?t.data.x:Math.random()*c,y:l(t.data.y)?t.data.y:Math.random()*f,size:d(t)||30,mass:g(t),nodeStrength:p(t)})})})),v=u.map((function(t){return r(r({},t),{data:r(r({},t.data),{edgeStrength:y(t),linkDistance:m(t,e.getNode(t.source),e.getNode(t.target))})})}));if(!(null==a?void 0:a.length))return this.lastResult={nodes:[],edges:u},{nodes:[],edges:u};var x={};a.forEach((function(t,e){x[t.id]={x:0,y:0}}));var M=new s({nodes:w,edges:v});this.formatCentripetal(h,M);var b=h.maxIteration,E=h.minMovement,N=h.onLayoutEnd,S=h.onTick;if(this.lastLayoutNodes=w,this.lastLayoutEdges=v,this.lastAssign=t,this.lastGraph=e,this.lastCalcGraph=M,this.lastOptions=h,this.lastVelMap=x,"undefined"!=typeof window){var A=0;return this.timeInterval=window.setInterval((function(){a&&o.running&&(o.runOneStep(M,e,A,x,h),o.updatePosition(e,M,x,h),t&&w.forEach((function(t){return e.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})})),null==S||S({nodes:zt(e,w),edges:u}),(++A>=b||o.judgingDistance<E)&&(null==N||N({nodes:zt(e,w),edges:u}),window.clearInterval(o.timeInterval)))}),0),this.running=!0,{nodes:zt(e,w),edges:u}}},t.prototype.formatOptions=function(t,e){var r=t,n=t.width,o=t.height,i=t.getMass;if(r.width=n||"undefined"==typeof window?n:window.innerWidth,r.height=o||"undefined"==typeof window?o:window.innerHeight,t.center||(r.center=[r.width/2,r.height/2]),i||(r.getMass=function(t){var r=1;l(null==t?void 0:t.data.mass)&&(r=null==t?void 0:t.data.mass);var n=e.getDegree(t.id,"both");return!n||n<5?r:5*n*r}),t.preventOverlap){var s=w(0,t.nodeSpacing);t.nodeSize?h(t.nodeSize)?r.nodeSize=function(e){var r=t.nodeSize;return Math.max(r[0],r[1])+s(e)}:r.nodeSize=function(e){return t.nodeSize+s(e)}:r.nodeSize=function(t){var e=((null==t?void 0:t.data)||{}).size;return e?h(e)?Math.max(e[0],e[1])+s(t):g(e)?Math.max(e.width,e.height)+s(t):e+s(t):10+s(t)}}return r.linkDistance=t.linkDistance?w(1,t.linkDistance):function(t){return 1+r.nodeSize(e.getNode(t.source))+r.nodeSize(e.getNode(t.target))},r.nodeStrength=w(1,t.nodeStrength),r.edgeStrength=w(1,t.edgeStrength),t},t.prototype.formatCentripetal=function(t,e){var r,n=t.centripetalOptions,o=t.center,i=t.clusterNodeStrength,s=t.leafCluster,a=t.clustering,u=t.nodeClusterBy,h=e.getAllNodes(),l=n||{leaf:2,single:2,others:1,center:function(t){return{x:o[0],y:o[1]}}};"function"!=typeof i&&(t.clusterNodeStrength=function(t){return i});var c=[];if(s&&u&&(r=It(e,u),c=Array.from(new Set(null==h?void 0:h.map((function(t){return t.data[u]}))))||[],t.centripetalOptions=Object.assign(l,{single:100,leaf:function(e){var n=r[e.id]||{},o=n.siblingLeaves,i=n.sameTypeLeaves;return(null==i?void 0:i.length)===(null==o?void 0:o.length)||1===(null==c?void 0:c.length)?1:t.clusterNodeStrength(e)},others:1,center:function(t){var n,o=e.getDegree(t.id,"both");if(!o)return{x:100,y:100};if(1===o){var i=(r[t.id]||{}).sameTypeLeaves,s=void 0===i?[]:i;1===s.length?n=void 0:s.length>1&&(n=_t(s))}else n=void 0;return{x:null==n?void 0:n.x,y:null==n?void 0:n.y}}})),a&&u){r||(r=It(e,u)),c||(c=Array.from(new Set(h.map((function(t){return t.data[u]}))))),c=c.filter((function(t){return void 0!==t}));var f={};c.forEach((function(t){var r=h.filter((function(e){return e.data[u]===t})).map((function(t){return e.getNode(t.id)}));f[t]=_t(r)})),t.centripetalOptions=Object.assign(l,{single:function(e){return t.clusterNodeStrength(e)},leaf:function(e){return t.clusterNodeStrength(e)},others:function(e){return t.clusterNodeStrength(e)},center:function(t){var e=f[t.data[u]];return{x:null==e?void 0:e.x,y:null==e?void 0:e.y}}})}var d=t.centripetalOptions||{},g=d.leaf,p=d.single,y=d.others;g&&"function"!=typeof g&&(t.centripetalOptions.leaf=function(){return g}),p&&"function"!=typeof p&&(t.centripetalOptions.single=function(){return p}),y&&"function"!=typeof y&&(t.centripetalOptions.others=function(){return y})},t.prototype.runOneStep=function(t,e,r,n,o){var i={},s=t.getAllNodes(),a=t.getAllEdges();if(null==s?void 0:s.length){var u=o.monitor;this.calRepulsive(t,i,o),a&&this.calAttractive(t,i),this.calGravity(t,e,i,o),this.updateVelocity(t,i,n,o),u&&u({energy:this.calTotalEnergy(i,s),nodes:e.getAllNodes(),edges:e.getAllEdges(),iterations:r})}},t.prototype.calTotalEnergy=function(t,e){if(!(null==e?void 0:e.length))return 0;var r=0;return e.forEach((function(e,n){var o=t[e.id].x,i=t[e.id].y,s=o*o+i*i,a=e.data.mass;r+=(void 0===a?1:a)*s*.5})),r},t.prototype.calRepulsive=function(t,e,r){var n=r.factor,o=r.coulombDisScale;!function(t,e,r,n){var o=e/r,i=t.getAllNodes(),s=i.map((function(t,e){var r=t.data,n=r.nodeStrength;return{x:r.x,y:r.y,size:r.size,index:e,vx:0,vy:0,weight:o*n}})),a=R(s,(function(t){return t.x}),(function(t){return t.y})).visitAfter(St);s.forEach((function(t){!function(t,e){e.visit((function(e,r,n,o,i){return function(t,e,r,n,o,i){var s=i.x-t.x||.1,a=i.y-t.y||.1,u=n-e,h=s*s+a*a,l=Math.sqrt(h)*h;if(u*u*.81<h){var c=t.weight/l;return i.vx+=s*c,i.vy+=a*c,!0}if(t.length)return!1;t.data!==i&&(c=t.data.weight/l,i.vx+=s*c,i.vy+=a*c)}(e,r,0,o,0,t)}))}(t,a)})),s.map((function(t,e){var r=i[e],o=r.id,s=r.data.mass,a=void 0===s?1:s;n[o]={x:t.vx/a,y:t.vy/a}}))}(t,n,o*o,e)},t.prototype.calAttractive=function(t,e){t.getAllEdges().forEach((function(r,n){var o=r.source,i=r.target,s=t.getNode(o),a=t.getNode(i);if(s&&a){var u=a.data.x-s.data.x,h=a.data.y-s.data.y;u||h||(u=.01*Math.random(),h=.01*Math.random());var l=Math.sqrt(u*u+h*h),c=u/l,f=h/l,d=r.data||{},g=d.linkDistance,p=void 0===g?200:g,y=d.edgeStrength,m=(p-l)*(void 0===y?200:y),w=1/(s.data.mass||1),v=1/(a.data.mass||1),x=c*m,M=f*m;e[o].x-=x*w,e[o].y-=M*w,e[i].x+=x*v,e[i].y+=M*v}}))},t.prototype.calGravity=function(t,e,r,n){var i=n.getCenter,s=t.getAllNodes(),a=e.getAllNodes(),u=e.getAllEdges(),h=n.width,c=n.height,f=n.center,d=n.gravity,g=n.centripetalOptions;s&&s.forEach((function(n){var s=n.id,p=n.data,y=p.mass,m=p.x,w=p.y,v=e.getNode(s),x=0,M=0,b=d,E=t.getDegree(s,"in"),N=t.getDegree(s,"out"),S=t.getDegree(s,"both"),A=null==i?void 0:i(v,S);if(A){var k=o(A,3);x=m-k[0],M=w-k[1],b=k[2]}else x=m-f[0],M=w-f[1];if(b&&(r[s].x-=b*x/y,r[s].y-=b*M/y),g){var I=g.leaf,D=g.single,R=g.others,_=g.center,z=(null==_?void 0:_(v,a,u,h,c))||{x:0,y:0,centerStrength:0},T=z.x,O=z.y,C=z.centerStrength;if(!l(T)||!l(O))return;var L=(m-T)/y,P=(w-O)/y;if(C&&(r[s].x-=C*L,r[s].y-=C*P),0===S){var q=D(v);if(!q)return;return r[s].x-=q*L,void(r[s].y-=q*P)}if(0===E||0===N){var j=I(v,a,u);if(!j)return;return r[s].x-=j*L,void(r[s].y-=j*P)}var V=R(v);if(!V)return;r[s].x-=V*L,r[s].y-=V*P}}))},t.prototype.updateVelocity=function(t,e,r,n){var o=n.damping,i=n.maxSpeed,s=n.interval,a=t.getAllNodes();(null==a?void 0:a.length)&&a.forEach((function(t){var n=t.id,a=(r[n].x+e[n].x*s)*o||.01,u=(r[n].y+e[n].y*s)*o||.01,h=Math.sqrt(a*a+u*u);if(h>i){var l=i/h;a*=l,u*=l}r[n]={x:a,y:u}}))},t.prototype.updatePosition=function(t,e,r,n){var o=this,i=n.distanceThresholdMode,s=n.interval,a=e.getAllNodes();if(null==a?void 0:a.length){var u=0;"max"===i?this.judgingDistance=-1/0:"min"===i&&(this.judgingDistance=1/0),a.forEach((function(n){var a=n.id,h=t.getNode(a);if(l(h.data.fx)&&l(h.data.fy))e.mergeNodeData(a,{x:h.data.fx,y:h.data.fy});else{var c=r[a].x*s,f=r[a].y*s;e.mergeNodeData(a,{x:n.data.x+c,y:n.data.y+f});var d=Math.sqrt(c*c+f*f);switch(i){case"max":o.judgingDistance<d&&(o.judgingDistance=d);break;case"min":o.judgingDistance>d&&(o.judgingDistance=d);break;default:u+=d}}})),i&&"mean"!==i||(this.judgingDistance=u/a.length)}else this.judgingDistance=0},t}(),It=function(t,e){var r=t.getAllNodes();if(!(null==r?void 0:r.length))return{};var n={};return r.forEach((function(r,o){1===t.getDegree(r.id,"both")&&(n[r.id]=Dt(t,"leaf",r,e))})),n},Dt=function(t,e,r,n){var o=t.getDegree(r.id,"in"),i=t.getDegree(r.id,"out"),s=r,a=[];return 0===o?(s=t.getSuccessors(r.id)[0],a=t.getNeighbors(s.id)):0===i&&(s=t.getPredecessors(r.id)[0],a=t.getNeighbors(s.id)),a=a.filter((function(e){return 0===t.getDegree(e.id,"in")||0===t.getDegree(e.id,"out")})),{coreNode:s,siblingLeaves:a,sameTypeLeaves:Rt(t,e,n,r,a)}},Rt=function(t,e,r,n,o){var i=n.data[r]||"",s=(null==o?void 0:o.filter((function(t){return t.data[r]===i})))||[];return"leaf"===e&&(s=s.filter((function(e){return 0===t.getDegree(e.id,"in")||0===t.getDegree(e.id,"out")}))),s},_t=function(t){var e={x:0,y:0};t.forEach((function(t){var r=t.data,n=r.x,o=r.y;e.x+=n||0,e.y+=o||0}));var r=t.length||1;return{x:e.x/r,y:e.y/r}},zt=function(t,e){return e.map((function(e){var n=e.id,o=e.data,i=t.getNode(n);return r(r({},i),{data:r(r({},i.data),{x:o.x,y:o.y})})}))},Tt={maxIteration:1e3,gravity:10,speed:5,clustering:!1,clusterGravity:10,width:300,height:300,nodeClusterBy:"cluster"},Ot=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="fruchterman",this.timeInterval=0,this.running=!1,this.options=r(r({},Tt),t)}return t.prototype.execute=function(t,e){return this.genericFruchtermanLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericFruchtermanLayout(!0,t,e)},t.prototype.stop=function(){this.timeInterval&&"undefined"!=typeof window&&window.clearInterval(this.timeInterval),this.running=!1},t.prototype.restart=function(){this.running=!0},t.prototype.tick=function(t){var e=this;if(void 0===t&&(t=this.options.maxIteration||1),this.lastResult)return this.lastResult;for(var r=0;r<t;r++)this.runOneStep(this.lastGraph,this.lastClusterMap,this.lastOptions);var n={nodes:this.lastLayoutNodes,edges:this.lastLayoutEdges};return this.lastAssign&&n.nodes.forEach((function(t){return e.lastGraph.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})})),this.lastOptions.onLayoutEnd&&this.lastOptions.onLayoutEnd(n),n},t.prototype.genericFruchtermanLayout=function(t,e,n){var o=this;if(!this.running){var i=this.formatOptions(n),a=i.layoutInvisibles,u=i.width,h=i.height,l=i.center,c=i.clustering,f=i.nodeClusterBy,d=i.maxIteration,g=i.onTick,p=i.onLayoutEnd,m=e.getAllNodes(),w=e.getAllEdges();if(a||(m=m.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e})),w=w.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e}))),!(null==m?void 0:m.length)){var v={nodes:[],edges:w};return this.lastResult=v,null==p||p(v),v}if(1===m.length)return t&&e.mergeNodeData(m[0].id,{x:l[0],y:l[1]}),v={nodes:[r(r({},m[0]),{data:r(r({},m[0].data),{x:l[0],y:l[1]})})],edges:w},this.lastResult=v,null==p||p(v),v;var x=m.map((function(t){return y(t,[u,h])})),M=new s({nodes:x,edges:w}),b={};if(c&&x.forEach((function(t){var e=t.data[f];b[e]||(b[e]={name:e,cx:0,cy:0,count:0})})),this.lastLayoutNodes=x,this.lastLayoutEdges=w,this.lastAssign=t,this.lastGraph=M,this.lastOptions=i,this.lastClusterMap=b,"undefined"!=typeof window){var E=0;return this.timeInterval=window.setInterval((function(){if(o.running&&(o.runOneStep(M,b,i),t&&x.forEach((function(t){var r=t.id,n=t.data;return e.mergeNodeData(r,{x:n.x,y:n.y})})),null==g||g({nodes:x,edges:w}),++E>=d)){try{null==p||p({nodes:x,edges:w})}catch(t){console.warn("onLayoutEnd failed",t)}window.clearInterval(o.timeInterval)}}),0),this.running=!0,{nodes:x,edges:w}}}},t.prototype.formatOptions=function(t){void 0===t&&(t={});var e=r(r({},this.options),t),n=e.clustering,o=e.nodeClusterBy,i=e.center,s=e.width,a=e.height;return e.width=s||"undefined"==typeof window?s:window.innerWidth,e.height=a||"undefined"==typeof window?a:window.innerHeight,e.center=i||[e.width/2,e.height/2],e.clustering=n&&!!o,e},t.prototype.runOneStep=function(t,e,r){var n=r.height,o=r.width,i=r.gravity,s=r.center,a=r.speed,u=r.clustering,h=r.nodeClusterBy,c=r.clusterGravity,f=n*o,d=Math.sqrt(f)/10,g=t.getAllNodes(),p=f/(g.length+1),y=Math.sqrt(p),m={};if(this.applyCalculate(t,m,y,p),u){for(var w in e)e[w].cx=0,e[w].cy=0,e[w].count=0;for(var w in g.forEach((function(t){var r=t.data,n=e[r[h]];l(r.x)&&(n.cx+=r.x),l(r.y)&&(n.cy+=r.y),n.count++})),e)e[w].cx/=e[w].count,e[w].cy/=e[w].count;var v=c||i;g.forEach((function(t,r){var n=t.id,o=t.data;if(l(o.x)&&l(o.y)){var i=e[o[h]],s=Math.sqrt((o.x-i.cx)*(o.x-i.cx)+(o.y-i.cy)*(o.y-i.cy)),a=y*v;m[n].x-=a*(o.x-i.cx)/s,m[n].y-=a*(o.y-i.cy)/s}}))}g.forEach((function(t,e){var r=t.id,n=t.data;if(l(n.x)&&l(n.y)){var o=.01*y*i;m[r].x-=o*(n.x-s[0]),m[r].y-=o*(n.y-s[1])}})),g.forEach((function(e,r){var n=e.id,o=e.data;if(l(o.fx)&&l(o.fy))return o.x=o.fx,void(o.y=o.fy);if(l(o.x)&&l(o.y)){var i=Math.sqrt(m[n].x*m[n].x+m[n].y*m[n].y);if(i>0){var s=Math.min(d*(a/800),i);t.mergeNodeData(n,{x:o.x+m[n].x/i*s,y:o.y+m[n].y/i*s})}}}))},t.prototype.applyCalculate=function(t,e,r,n){this.calRepulsive(t,e,n),this.calAttractive(t,e,r)},t.prototype.calRepulsive=function(t,e,r){var n=t.getAllNodes();n.forEach((function(t,o){var i=t.data,s=t.id;e[s]={x:0,y:0},n.forEach((function(t,n){var a=t.data,u=t.id;if(!(o<=n)&&l(i.x)&&l(a.x)&&l(i.y)&&l(a.y)){var h=i.x-a.x,c=i.y-a.y,f=h*h+c*c;0===f&&(f=1,h=.01,c=.01);var d=r/f,g=h*d,p=c*d;e[s].x+=g,e[s].y+=p,e[u].x-=g,e[u].y-=p}}))}))},t.prototype.calAttractive=function(t,e,r){t.getAllEdges().forEach((function(n){var o=n.source,i=n.target;if(o&&i&&o!==i){var s=t.getNode(o).data,a=t.getNode(i).data;if(l(a.x)&&l(s.x)&&l(a.y)&&l(s.y)){var u=a.x-s.x,h=a.y-s.y,c=Math.sqrt(u*u+h*h)/r,f=u*c,d=h*c;e[o].x+=f,e[o].y+=d,e[i].x-=f,e[i].y-=d}}}))},t}(),Ct={begin:[0,0],preventOverlap:!0,preventOverlapPadding:10,condense:!1,rows:void 0,cols:void 0,position:void 0,sortBy:"degree",nodeSize:30,width:300,height:300},Lt=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="grid",this.options=r(r({},Ct),t)}return t.prototype.execute=function(t,e){return this.genericGridLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericGridLayout(!0,t,e)},t.prototype.genericGridLayout=function(t,e,n){var o=r(r({},this.options),n),i=o.begin,s=void 0===i?[0,0]:i,u=o.condense,c=o.preventOverlapPadding,f=o.preventOverlap,d=o.rows,g=o.cols,p=o.nodeSpacing,m=o.nodeSize,x=o.width,M=o.height,b=o.layoutInvisibles,E=o.onLayoutEnd,N=o.position,S=o.sortBy,A=e.getAllNodes(),k=e.getAllEdges();b||(A=A.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e})),k=k.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e})));var I=A.length;if(0===I){var D={nodes:[],edges:k};return null==E||E(D),D}if(1===I){t&&e.mergeNodeData(A[0].id,{x:s[0],y:s[1]});var R={nodes:[r(r({},A[0]),{data:r(r({},A[0].data),{x:s[0],y:s[1]})})],edges:k};return null==E||E(R),R}var _=A.map((function(t){return y(t)}));"id"===S||a(S)&&void 0!==_[0].data[S]||(S="degree"),"degree"===S?_.sort((function(t,r){return e.getDegree(r.id,"both")-e.getDegree(t.id,"both")})):"id"===S?_.sort((function(t,e){return l(e.id)&&l(t.id)?e.id-t.id:"".concat(t.id).localeCompare("".concat(e.id))})):_.sort((function(t,e){return e.data[S]-t.data[S]}));var z=x||"undefined"==typeof window?x:window.innerWidth,T=M||"undefined"==typeof window?M:window.innerHeight,O=I,C={rows:d,cols:g};if(null!=d&&null!=g)C.rows=d,C.cols=g;else if(null!=d&&null==g)C.rows=d,C.cols=Math.ceil(O/C.rows);else if(null==d&&null!=g)C.cols=g,C.rows=Math.ceil(O/C.cols);else{var L=Math.sqrt(O*T/z);C.rows=Math.round(L),C.cols=Math.round(z/T*L)}if(C.rows=Math.max(C.rows,1),C.cols=Math.max(C.cols,1),C.cols*C.rows>O)((q=Pt(C))-1)*(P=qt(C))>=O?Pt(C,q-1):(P-1)*q>=O&&qt(C,P-1);else for(;C.cols*C.rows<O;){var P,q=Pt(C);((P=qt(C))+1)*q>=O?qt(C,P+1):Pt(C,q+1)}var j=u?0:z/C.cols,V=u?0:T/C.rows;if(f||p){var F=w(10,p),$=v(30,m,!1);_.forEach((function(t){t.data.x&&t.data.y||(t.data.x=0,t.data.y=0);var r,n,o=e.getNode(t.id),i=$(o)||30;h(i)?(r=i[0],n=i[1]):(r=i,n=i);var s=void 0!==F?F(t):c,a=r+s,u=n+s;j=Math.max(j,a),V=Math.max(V,u)}))}for(var G={},U={row:0,col:0},B={},K=0;K<_.length;K++){var W=_[K],H=void 0;if(N&&(H=N(e.getNode(W.id))),H&&(void 0!==H.row||void 0!==H.col)){var J={row:H.row,col:H.col};if(void 0===J.col)for(J.col=0;jt(G,J);)J.col++;else if(void 0===J.row)for(J.row=0;jt(G,J);)J.row++;B[W.id]=J,Vt(G,J)}$t(W,s,j,V,B,C,U,G)}var Y={nodes:_,edges:k};return null==E||E(Y),t&&_.forEach((function(t){e.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})})),Y},t}(),Pt=function(t,e){var r,n=t.rows||5,o=t.cols||5;return null==e?r=Math.min(n,o):Math.min(n,o)===t.rows?t.rows=e:t.cols=e,r},qt=function(t,e){var r,n=t.rows||5,o=t.cols||5;return null==e?r=Math.max(n,o):Math.max(n,o)===t.rows?t.rows=e:t.cols=e,r},jt=function(t,e){return t["c-".concat(e.row,"-").concat(e.col)]||!1},Vt=function(t,e){return t["c-".concat(e.row,"-").concat(e.col)]=!0},Ft=function(t,e){var r=t.cols||5;e.col++,e.col>=r&&(e.col=0,e.row++)},$t=function(t,e,r,n,o,i,s,a){var u,h,l=o[t.id];if(l)u=l.col*r+r/2+e[0],h=l.row*n+n/2+e[1];else{for(;jt(a,s);)Ft(i,s);u=s.col*r+r/2+e[0],h=s.row*n+n/2+e[1],Vt(a,s),Ft(i,s)}t.data.x=u,t.data.y=h};const Gt=Object.prototype.toString;function Ut(t){return Gt.call(t).endsWith("Array]")}function Bt(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!Ut(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");var r=e.fromIndex,n=void 0===r?0:r,o=e.toIndex,i=void 0===o?t.length:o;if(n<0||n>=t.length||!Number.isInteger(n))throw new Error("fromIndex must be a positive integer smaller than length");if(i<=n||i>t.length||!Number.isInteger(i))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var s=t[n],a=n+1;a<i;a++)t[a]>s&&(s=t[a]);return s}function Kt(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!Ut(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");var r=e.fromIndex,n=void 0===r?0:r,o=e.toIndex,i=void 0===o?t.length:o;if(n<0||n>=t.length||!Number.isInteger(n))throw new Error("fromIndex must be a positive integer smaller than length");if(i<=n||i>t.length||!Number.isInteger(i))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var s=t[n],a=n+1;a<i;a++)t[a]<s&&(s=t[a]);return s}function Wt(t){var e,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!Ut(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");if(void 0!==r.output){if(!Ut(r.output))throw new TypeError("output option must be an array if specified");e=r.output}else e=new Array(t.length);var n=Kt(t),o=Bt(t);if(n===o)throw new RangeError("minimum and maximum input values are equal. Cannot rescale a constant array");var i=r.min,s=void 0===i?r.autoMinMax?n:0:i,a=r.max,u=void 0===a?r.autoMinMax?o:1:a;if(s>=u)throw new RangeError("min option must be smaller than max option");for(var h=(u-s)/(o-n),l=0;l<t.length;l++)e[l]=(t[l]-n)*h+s;return e}const Ht=" ".repeat(2),Jt=" ".repeat(4);function Yt(t,e={}){const{maxRows:r=15,maxColumns:n=10,maxNumSize:o=8,padMinus:i="auto"}=e;return`${t.constructor.name} {\\n${Ht}[\\n${Jt}${function(t,e,r,n,o){const{rows:i,columns:s}=t,a=Math.min(i,e),u=Math.min(s,r),h=[];if("auto"===o){o=!1;t:for(let e=0;e<a;e++)for(let r=0;r<u;r++)if(t.get(e,r)<0){o=!0;break t}}for(let e=0;e<a;e++){let r=[];for(let i=0;i<u;i++)r.push(Xt(t.get(e,i),n,o));h.push(`${r.join(" ")}`)}return u!==s&&(h[h.length-1]+=` ... ${s-r} more columns`),a!==i&&h.push(`... ${i-e} more rows`),h.join(`\\n${Jt}`)}(t,r,n,o,i)}\\n${Ht}]\\n${Ht}rows: ${t.rows}\\n${Ht}columns: ${t.columns}\\n}`}function Xt(t,e,r){return(t>=0&&r?` ${Qt(t,e-1)}`:Qt(t,e)).padEnd(e)}function Qt(t,e){let r=t.toString();if(r.length<=e)return r;let n=t.toFixed(e);if(n.length>e&&(n=t.toFixed(Math.max(0,e-(n.length-e)))),n.length<=e&&!n.startsWith("0.000")&&!n.startsWith("-0.000"))return n;let o=t.toExponential(e);return o.length>e&&(o=t.toExponential(Math.max(0,e-(o.length-e)))),o.slice(0)}function Zt(t,e,r){let n=r?t.rows:t.rows-1;if(e<0||e>n)throw new RangeError("Row index out of range")}function te(t,e,r){let n=r?t.columns:t.columns-1;if(e<0||e>n)throw new RangeError("Column index out of range")}function ee(t,e){if(e.to1DArray&&(e=e.to1DArray()),e.length!==t.columns)throw new RangeError("vector size must be the same as the number of columns");return e}function re(t,e){if(e.to1DArray&&(e=e.to1DArray()),e.length!==t.rows)throw new RangeError("vector size must be the same as the number of rows");return e}function ne(t,e,r,n,o){if(5!==arguments.length)throw new RangeError("expected 4 arguments");if(ie("startRow",e),ie("endRow",r),ie("startColumn",n),ie("endColumn",o),e>r||n>o||e<0||e>=t.rows||r<0||r>=t.rows||n<0||n>=t.columns||o<0||o>=t.columns)throw new RangeError("Submatrix indices are out of range")}function oe(t,e=0){let r=[];for(let n=0;n<t;n++)r.push(e);return r}function ie(t,e){if("number"!=typeof e)throw new TypeError(`${t} must be a number`)}function se(t){if(t.isEmpty())throw new Error("Empty matrix has no elements to index")}class ae{static from1DArray(t,e,r){if(t*e!==r.length)throw new RangeError("data length does not match given dimensions");let n=new he(t,e);for(let o=0;o<t;o++)for(let t=0;t<e;t++)n.set(o,t,r[o*e+t]);return n}static rowVector(t){let e=new he(1,t.length);for(let r=0;r<t.length;r++)e.set(0,r,t[r]);return e}static columnVector(t){let e=new he(t.length,1);for(let r=0;r<t.length;r++)e.set(r,0,t[r]);return e}static zeros(t,e){return new he(t,e)}static ones(t,e){return new he(t,e).fill(1)}static rand(t,e,r={}){if("object"!=typeof r)throw new TypeError("options must be an object");const{random:n=Math.random}=r;let o=new he(t,e);for(let r=0;r<t;r++)for(let t=0;t<e;t++)o.set(r,t,n());return o}static randInt(t,e,r={}){if("object"!=typeof r)throw new TypeError("options must be an object");const{min:n=0,max:o=1e3,random:i=Math.random}=r;if(!Number.isInteger(n))throw new TypeError("min must be an integer");if(!Number.isInteger(o))throw new TypeError("max must be an integer");if(n>=o)throw new RangeError("min must be smaller than max");let s=o-n,a=new he(t,e);for(let r=0;r<t;r++)for(let t=0;t<e;t++){let e=n+Math.round(i()*s);a.set(r,t,e)}return a}static eye(t,e,r){void 0===e&&(e=t),void 0===r&&(r=1);let n=Math.min(t,e),o=this.zeros(t,e);for(let t=0;t<n;t++)o.set(t,t,r);return o}static diag(t,e,r){let n=t.length;void 0===e&&(e=n),void 0===r&&(r=e);let o=Math.min(n,e,r),i=this.zeros(e,r);for(let e=0;e<o;e++)i.set(e,e,t[e]);return i}static min(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);let r=t.rows,n=t.columns,o=new he(r,n);for(let i=0;i<r;i++)for(let r=0;r<n;r++)o.set(i,r,Math.min(t.get(i,r),e.get(i,r)));return o}static max(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);let r=t.rows,n=t.columns,o=new this(r,n);for(let i=0;i<r;i++)for(let r=0;r<n;r++)o.set(i,r,Math.max(t.get(i,r),e.get(i,r)));return o}static checkMatrix(t){return ae.isMatrix(t)?t:new he(t)}static isMatrix(t){return null!=t&&"Matrix"===t.klass}get size(){return this.rows*this.columns}apply(t){if("function"!=typeof t)throw new TypeError("callback must be a function");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.call(this,e,r);return this}to1DArray(){let t=[];for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.push(this.get(e,r));return t}to2DArray(){let t=[];for(let e=0;e<this.rows;e++){t.push([]);for(let r=0;r<this.columns;r++)t[e].push(this.get(e,r))}return t}toJSON(){return this.to2DArray()}isRowVector(){return 1===this.rows}isColumnVector(){return 1===this.columns}isVector(){return 1===this.rows||1===this.columns}isSquare(){return this.rows===this.columns}isEmpty(){return 0===this.rows||0===this.columns}isSymmetric(){if(this.isSquare()){for(let t=0;t<this.rows;t++)for(let e=0;e<=t;e++)if(this.get(t,e)!==this.get(e,t))return!1;return!0}return!1}isEchelonForm(){let t=0,e=0,r=-1,n=!0,o=!1;for(;t<this.rows&&n;){for(e=0,o=!1;e<this.columns&&!1===o;)0===this.get(t,e)?e++:1===this.get(t,e)&&e>r?(o=!0,r=e):(n=!1,o=!0);t++}return n}isReducedEchelonForm(){let t=0,e=0,r=-1,n=!0,o=!1;for(;t<this.rows&&n;){for(e=0,o=!1;e<this.columns&&!1===o;)0===this.get(t,e)?e++:1===this.get(t,e)&&e>r?(o=!0,r=e):(n=!1,o=!0);for(let r=e+1;r<this.rows;r++)0!==this.get(t,r)&&(n=!1);t++}return n}echelonForm(){let t=this.clone(),e=0,r=0;for(;e<t.rows&&r<t.columns;){let n=e;for(let o=e;o<t.rows;o++)t.get(o,r)>t.get(n,r)&&(n=o);if(0===t.get(n,r))r++;else{t.swapRows(e,n);let o=t.get(e,r);for(let n=r;n<t.columns;n++)t.set(e,n,t.get(e,n)/o);for(let n=e+1;n<t.rows;n++){let o=t.get(n,r)/t.get(e,r);t.set(n,r,0);for(let i=r+1;i<t.columns;i++)t.set(n,i,t.get(n,i)-t.get(e,i)*o)}e++,r++}}return t}reducedEchelonForm(){let t=this.echelonForm(),e=t.columns,r=t.rows,n=r-1;for(;n>=0;)if(0===t.maxRow(n))n--;else{let o=0,i=!1;for(;o<r&&!1===i;)1===t.get(n,o)?i=!0:o++;for(let r=0;r<n;r++){let i=t.get(r,o);for(let s=o;s<e;s++){let e=t.get(r,s)-i*t.get(n,s);t.set(r,s,e)}}n--}return t}set(){throw new Error("set method is unimplemented")}get(){throw new Error("get method is unimplemented")}repeat(t={}){if("object"!=typeof t)throw new TypeError("options must be an object");const{rows:e=1,columns:r=1}=t;if(!Number.isInteger(e)||e<=0)throw new TypeError("rows must be a positive integer");if(!Number.isInteger(r)||r<=0)throw new TypeError("columns must be a positive integer");let n=new he(this.rows*e,this.columns*r);for(let t=0;t<e;t++)for(let e=0;e<r;e++)n.setSubMatrix(this,this.rows*t,this.columns*e);return n}fill(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,t);return this}neg(){return this.mulS(-1)}getRow(t){Zt(this,t);let e=[];for(let r=0;r<this.columns;r++)e.push(this.get(t,r));return e}getRowVector(t){return he.rowVector(this.getRow(t))}setRow(t,e){Zt(this,t),e=ee(this,e);for(let r=0;r<this.columns;r++)this.set(t,r,e[r]);return this}swapRows(t,e){Zt(this,t),Zt(this,e);for(let r=0;r<this.columns;r++){let n=this.get(t,r);this.set(t,r,this.get(e,r)),this.set(e,r,n)}return this}getColumn(t){te(this,t);let e=[];for(let r=0;r<this.rows;r++)e.push(this.get(r,t));return e}getColumnVector(t){return he.columnVector(this.getColumn(t))}setColumn(t,e){te(this,t),e=re(this,e);for(let r=0;r<this.rows;r++)this.set(r,t,e[r]);return this}swapColumns(t,e){te(this,t),te(this,e);for(let r=0;r<this.rows;r++){let n=this.get(r,t);this.set(r,t,this.get(r,e)),this.set(r,e,n)}return this}addRowVector(t){t=ee(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t[r]);return this}subRowVector(t){t=ee(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t[r]);return this}mulRowVector(t){t=ee(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t[r]);return this}divRowVector(t){t=ee(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t[r]);return this}addColumnVector(t){t=re(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t[e]);return this}subColumnVector(t){t=re(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t[e]);return this}mulColumnVector(t){t=re(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t[e]);return this}divColumnVector(t){t=re(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t[e]);return this}mulRow(t,e){Zt(this,t);for(let r=0;r<this.columns;r++)this.set(t,r,this.get(t,r)*e);return this}mulColumn(t,e){te(this,t);for(let r=0;r<this.rows;r++)this.set(r,t,this.get(r,t)*e);return this}max(t){if(this.isEmpty())return NaN;switch(t){case"row":{const t=new Array(this.rows).fill(Number.NEGATIVE_INFINITY);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)>t[e]&&(t[e]=this.get(e,r));return t}case"column":{const t=new Array(this.columns).fill(Number.NEGATIVE_INFINITY);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)>t[r]&&(t[r]=this.get(e,r));return t}case void 0:{let t=this.get(0,0);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)>t&&(t=this.get(e,r));return t}default:throw new Error(`invalid option: ${t}`)}}maxIndex(){se(this);let t=this.get(0,0),e=[0,0];for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.get(r,n)>t&&(t=this.get(r,n),e[0]=r,e[1]=n);return e}min(t){if(this.isEmpty())return NaN;switch(t){case"row":{const t=new Array(this.rows).fill(Number.POSITIVE_INFINITY);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)<t[e]&&(t[e]=this.get(e,r));return t}case"column":{const t=new Array(this.columns).fill(Number.POSITIVE_INFINITY);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)<t[r]&&(t[r]=this.get(e,r));return t}case void 0:{let t=this.get(0,0);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)<t&&(t=this.get(e,r));return t}default:throw new Error(`invalid option: ${t}`)}}minIndex(){se(this);let t=this.get(0,0),e=[0,0];for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.get(r,n)<t&&(t=this.get(r,n),e[0]=r,e[1]=n);return e}maxRow(t){if(Zt(this,t),this.isEmpty())return NaN;let e=this.get(t,0);for(let r=1;r<this.columns;r++)this.get(t,r)>e&&(e=this.get(t,r));return e}maxRowIndex(t){Zt(this,t),se(this);let e=this.get(t,0),r=[t,0];for(let n=1;n<this.columns;n++)this.get(t,n)>e&&(e=this.get(t,n),r[1]=n);return r}minRow(t){if(Zt(this,t),this.isEmpty())return NaN;let e=this.get(t,0);for(let r=1;r<this.columns;r++)this.get(t,r)<e&&(e=this.get(t,r));return e}minRowIndex(t){Zt(this,t),se(this);let e=this.get(t,0),r=[t,0];for(let n=1;n<this.columns;n++)this.get(t,n)<e&&(e=this.get(t,n),r[1]=n);return r}maxColumn(t){if(te(this,t),this.isEmpty())return NaN;let e=this.get(0,t);for(let r=1;r<this.rows;r++)this.get(r,t)>e&&(e=this.get(r,t));return e}maxColumnIndex(t){te(this,t),se(this);let e=this.get(0,t),r=[0,t];for(let n=1;n<this.rows;n++)this.get(n,t)>e&&(e=this.get(n,t),r[0]=n);return r}minColumn(t){if(te(this,t),this.isEmpty())return NaN;let e=this.get(0,t);for(let r=1;r<this.rows;r++)this.get(r,t)<e&&(e=this.get(r,t));return e}minColumnIndex(t){te(this,t),se(this);let e=this.get(0,t),r=[0,t];for(let n=1;n<this.rows;n++)this.get(n,t)<e&&(e=this.get(n,t),r[0]=n);return r}diag(){let t=Math.min(this.rows,this.columns),e=[];for(let r=0;r<t;r++)e.push(this.get(r,r));return e}norm(t="frobenius"){let e=0;if("max"===t)return this.max();if("frobenius"===t){for(let t=0;t<this.rows;t++)for(let r=0;r<this.columns;r++)e+=this.get(t,r)*this.get(t,r);return Math.sqrt(e)}throw new RangeError(`unknown norm type: ${t}`)}cumulativeSum(){let t=0;for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t+=this.get(e,r),this.set(e,r,t);return this}dot(t){ae.isMatrix(t)&&(t=t.to1DArray());let e=this.to1DArray();if(e.length!==t.length)throw new RangeError("vectors do not have the same size");let r=0;for(let n=0;n<e.length;n++)r+=e[n]*t[n];return r}mmul(t){t=he.checkMatrix(t);let e=this.rows,r=this.columns,n=t.columns,o=new he(e,n),i=new Float64Array(r);for(let s=0;s<n;s++){for(let e=0;e<r;e++)i[e]=t.get(e,s);for(let t=0;t<e;t++){let e=0;for(let n=0;n<r;n++)e+=this.get(t,n)*i[n];o.set(t,s,e)}}return o}strassen2x2(t){t=he.checkMatrix(t);let e=new he(2,2);const r=this.get(0,0),n=t.get(0,0),o=this.get(0,1),i=t.get(0,1),s=this.get(1,0),a=t.get(1,0),u=this.get(1,1),h=t.get(1,1),l=(r+u)*(n+h),c=(s+u)*n,f=r*(i-h),d=u*(a-n),g=(r+o)*h,p=l+d-g+(o-u)*(a+h),y=f+g,m=c+d,w=l-c+f+(s-r)*(n+i);return e.set(0,0,p),e.set(0,1,y),e.set(1,0,m),e.set(1,1,w),e}strassen3x3(t){t=he.checkMatrix(t);let e=new he(3,3);const r=this.get(0,0),n=this.get(0,1),o=this.get(0,2),i=this.get(1,0),s=this.get(1,1),a=this.get(1,2),u=this.get(2,0),h=this.get(2,1),l=this.get(2,2),c=t.get(0,0),f=t.get(0,1),d=t.get(0,2),g=t.get(1,0),p=t.get(1,1),y=t.get(1,2),m=t.get(2,0),w=t.get(2,1),v=t.get(2,2),x=(r-i)*(-f+p),M=(-r+i+s)*(c-f+p),b=(i+s)*(-c+f),E=r*c,N=(-r+u+h)*(c-d+y),S=(-r+u)*(d-y),A=(u+h)*(-c+d),k=(-o+h+l)*(p+m-w),I=(o-l)*(p-w),D=o*m,R=(h+l)*(-m+w),_=(-o+s+a)*(y+m-v),z=(o-a)*(y-v),T=(s+a)*(-m+v),O=E+D+n*g,C=(r+n+o-i-s-h-l)*p+M+b+E+k+D+R,L=E+N+A+(r+n+o-s-a-u-h)*y+D+_+T,P=x+s*(-c+f+g-p-y-m+v)+M+E+D+_+z,q=x+M+b+E+a*w,j=D+_+z+T+i*d,V=E+N+S+h*(-c+d+g-p-y-m+w)+k+I+D,F=k+I+D+R+u*f,$=E+N+S+A+l*v;return e.set(0,0,O),e.set(0,1,C),e.set(0,2,L),e.set(1,0,P),e.set(1,1,q),e.set(1,2,j),e.set(2,0,V),e.set(2,1,F),e.set(2,2,$),e}mmulStrassen(t){t=he.checkMatrix(t);let e=this.clone(),r=e.rows,n=e.columns,o=t.rows,i=t.columns;function s(t,e,r){let n=t.rows,o=t.columns;if(n===e&&o===r)return t;{let n=ae.zeros(e,r);return n=n.setSubMatrix(t,0,0),n}}n!==o&&console.warn(`Multiplying ${r} x ${n} and ${o} x ${i} matrix: dimensions do not match.`);let a=Math.max(r,o),u=Math.max(n,i);return e=s(e,a,u),function t(e,r,n,o){if(n<=512||o<=512)return e.mmul(r);n%2==1&&o%2==1?(e=s(e,n+1,o+1),r=s(r,n+1,o+1)):n%2==1?(e=s(e,n+1,o),r=s(r,n+1,o)):o%2==1&&(e=s(e,n,o+1),r=s(r,n,o+1));let i=parseInt(e.rows/2,10),a=parseInt(e.columns/2,10),u=e.subMatrix(0,i-1,0,a-1),h=r.subMatrix(0,i-1,0,a-1),l=e.subMatrix(0,i-1,a,e.columns-1),c=r.subMatrix(0,i-1,a,r.columns-1),f=e.subMatrix(i,e.rows-1,0,a-1),d=r.subMatrix(i,r.rows-1,0,a-1),g=e.subMatrix(i,e.rows-1,a,e.columns-1),p=r.subMatrix(i,r.rows-1,a,r.columns-1),y=t(ae.add(u,g),ae.add(h,p),i,a),m=t(ae.add(f,g),h,i,a),w=t(u,ae.sub(c,p),i,a),v=t(g,ae.sub(d,h),i,a),x=t(ae.add(u,l),p,i,a),M=t(ae.sub(f,u),ae.add(h,c),i,a),b=t(ae.sub(l,g),ae.add(d,p),i,a),E=ae.add(y,v);E.sub(x),E.add(b);let N=ae.add(w,x),S=ae.add(m,v),A=ae.sub(y,m);A.add(w),A.add(M);let k=ae.zeros(2*E.rows,2*E.columns);return k=k.setSubMatrix(E,0,0),k=k.setSubMatrix(N,E.rows,0),k=k.setSubMatrix(S,0,E.columns),k=k.setSubMatrix(A,E.rows,E.columns),k.subMatrix(0,n-1,0,o-1)}(e,t=s(t,a,u),a,u)}scaleRows(t={}){if("object"!=typeof t)throw new TypeError("options must be an object");const{min:e=0,max:r=1}=t;if(!Number.isFinite(e))throw new TypeError("min must be a number");if(!Number.isFinite(r))throw new TypeError("max must be a number");if(e>=r)throw new RangeError("min must be smaller than max");let n=new he(this.rows,this.columns);for(let t=0;t<this.rows;t++){const o=this.getRow(t);o.length>0&&Wt(o,{min:e,max:r,output:o}),n.setRow(t,o)}return n}scaleColumns(t={}){if("object"!=typeof t)throw new TypeError("options must be an object");const{min:e=0,max:r=1}=t;if(!Number.isFinite(e))throw new TypeError("min must be a number");if(!Number.isFinite(r))throw new TypeError("max must be a number");if(e>=r)throw new RangeError("min must be smaller than max");let n=new he(this.rows,this.columns);for(let t=0;t<this.columns;t++){const o=this.getColumn(t);o.length&&Wt(o,{min:e,max:r,output:o}),n.setColumn(t,o)}return n}flipRows(){const t=Math.ceil(this.columns/2);for(let e=0;e<this.rows;e++)for(let r=0;r<t;r++){let t=this.get(e,r),n=this.get(e,this.columns-1-r);this.set(e,r,n),this.set(e,this.columns-1-r,t)}return this}flipColumns(){const t=Math.ceil(this.rows/2);for(let e=0;e<this.columns;e++)for(let r=0;r<t;r++){let t=this.get(r,e),n=this.get(this.rows-1-r,e);this.set(r,e,n),this.set(this.rows-1-r,e,t)}return this}kroneckerProduct(t){t=he.checkMatrix(t);let e=this.rows,r=this.columns,n=t.rows,o=t.columns,i=new he(e*n,r*o);for(let s=0;s<e;s++)for(let e=0;e<r;e++)for(let r=0;r<n;r++)for(let a=0;a<o;a++)i.set(n*s+r,o*e+a,this.get(s,e)*t.get(r,a));return i}kroneckerSum(t){if(t=he.checkMatrix(t),!this.isSquare()||!t.isSquare())throw new Error("Kronecker Sum needs two Square Matrices");let e=this.rows,r=t.rows,n=this.kroneckerProduct(he.eye(r,r)),o=he.eye(e,e).kroneckerProduct(t);return n.add(o)}transpose(){let t=new he(this.columns,this.rows);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.set(r,e,this.get(e,r));return t}sortRows(t=ue){for(let e=0;e<this.rows;e++)this.setRow(e,this.getRow(e).sort(t));return this}sortColumns(t=ue){for(let e=0;e<this.columns;e++)this.setColumn(e,this.getColumn(e).sort(t));return this}subMatrix(t,e,r,n){ne(this,t,e,r,n);let o=new he(e-t+1,n-r+1);for(let i=t;i<=e;i++)for(let e=r;e<=n;e++)o.set(i-t,e-r,this.get(i,e));return o}subMatrixRow(t,e,r){if(void 0===e&&(e=0),void 0===r&&(r=this.columns-1),e>r||e<0||e>=this.columns||r<0||r>=this.columns)throw new RangeError("Argument out of range");let n=new he(t.length,r-e+1);for(let o=0;o<t.length;o++)for(let i=e;i<=r;i++){if(t[o]<0||t[o]>=this.rows)throw new RangeError(`Row index out of range: ${t[o]}`);n.set(o,i-e,this.get(t[o],i))}return n}subMatrixColumn(t,e,r){if(void 0===e&&(e=0),void 0===r&&(r=this.rows-1),e>r||e<0||e>=this.rows||r<0||r>=this.rows)throw new RangeError("Argument out of range");let n=new he(r-e+1,t.length);for(let o=0;o<t.length;o++)for(let i=e;i<=r;i++){if(t[o]<0||t[o]>=this.columns)throw new RangeError(`Column index out of range: ${t[o]}`);n.set(i-e,o,this.get(i,t[o]))}return n}setSubMatrix(t,e,r){if((t=he.checkMatrix(t)).isEmpty())return this;ne(this,e,e+t.rows-1,r,r+t.columns-1);for(let n=0;n<t.rows;n++)for(let o=0;o<t.columns;o++)this.set(e+n,r+o,t.get(n,o));return this}selection(t,e){!function(t,e){if(!Ut(e))throw new TypeError("row indices must be an array");for(let r=0;r<e.length;r++)if(e[r]<0||e[r]>=t.rows)throw new RangeError("row indices are out of range")}(this,t),function(t,e){if(!Ut(e))throw new TypeError("column indices must be an array");for(let r=0;r<e.length;r++)if(e[r]<0||e[r]>=t.columns)throw new RangeError("column indices are out of range")}(this,e);let r=new he(t.length,e.length);for(let n=0;n<t.length;n++){let o=t[n];for(let t=0;t<e.length;t++){let i=e[t];r.set(n,t,this.get(o,i))}}return r}trace(){let t=Math.min(this.rows,this.columns),e=0;for(let r=0;r<t;r++)e+=this.get(r,r);return e}clone(){let t=new he(this.rows,this.columns);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.set(e,r,this.get(e,r));return t}sum(t){switch(t){case"row":return function(t){let e=oe(t.rows);for(let r=0;r<t.rows;++r)for(let n=0;n<t.columns;++n)e[r]+=t.get(r,n);return e}(this);case"column":return function(t){let e=oe(t.columns);for(let r=0;r<t.rows;++r)for(let n=0;n<t.columns;++n)e[n]+=t.get(r,n);return e}(this);case void 0:return function(t){let e=0;for(let r=0;r<t.rows;r++)for(let n=0;n<t.columns;n++)e+=t.get(r,n);return e}(this);default:throw new Error(`invalid option: ${t}`)}}product(t){switch(t){case"row":return function(t){let e=oe(t.rows,1);for(let r=0;r<t.rows;++r)for(let n=0;n<t.columns;++n)e[r]*=t.get(r,n);return e}(this);case"column":return function(t){let e=oe(t.columns,1);for(let r=0;r<t.rows;++r)for(let n=0;n<t.columns;++n)e[n]*=t.get(r,n);return e}(this);case void 0:return function(t){let e=1;for(let r=0;r<t.rows;r++)for(let n=0;n<t.columns;n++)e*=t.get(r,n);return e}(this);default:throw new Error(`invalid option: ${t}`)}}mean(t){const e=this.sum(t);switch(t){case"row":for(let t=0;t<this.rows;t++)e[t]/=this.columns;return e;case"column":for(let t=0;t<this.columns;t++)e[t]/=this.rows;return e;case void 0:return e/this.size;default:throw new Error(`invalid option: ${t}`)}}variance(t,e={}){if("object"==typeof t&&(e=t,t=void 0),"object"!=typeof e)throw new TypeError("options must be an object");const{unbiased:r=!0,mean:n=this.mean(t)}=e;if("boolean"!=typeof r)throw new TypeError("unbiased must be a boolean");switch(t){case"row":if(!Ut(n))throw new TypeError("mean must be an array");return function(t,e,r){const n=t.rows,o=t.columns,i=[];for(let s=0;s<n;s++){let n=0,a=0,u=0;for(let e=0;e<o;e++)u=t.get(s,e)-r[s],n+=u,a+=u*u;e?i.push((a-n*n/o)/(o-1)):i.push((a-n*n/o)/o)}return i}(this,r,n);case"column":if(!Ut(n))throw new TypeError("mean must be an array");return function(t,e,r){const n=t.rows,o=t.columns,i=[];for(let s=0;s<o;s++){let o=0,a=0,u=0;for(let e=0;e<n;e++)u=t.get(e,s)-r[s],o+=u,a+=u*u;e?i.push((a-o*o/n)/(n-1)):i.push((a-o*o/n)/n)}return i}(this,r,n);case void 0:if("number"!=typeof n)throw new TypeError("mean must be a number");return function(t,e,r){const n=t.rows,o=t.columns,i=n*o;let s=0,a=0,u=0;for(let e=0;e<n;e++)for(let n=0;n<o;n++)u=t.get(e,n)-r,s+=u,a+=u*u;return e?(a-s*s/i)/(i-1):(a-s*s/i)/i}(this,r,n);default:throw new Error(`invalid option: ${t}`)}}standardDeviation(t,e){"object"==typeof t&&(e=t,t=void 0);const r=this.variance(t,e);if(void 0===t)return Math.sqrt(r);for(let t=0;t<r.length;t++)r[t]=Math.sqrt(r[t]);return r}center(t,e={}){if("object"==typeof t&&(e=t,t=void 0),"object"!=typeof e)throw new TypeError("options must be an object");const{center:r=this.mean(t)}=e;switch(t){case"row":if(!Ut(r))throw new TypeError("center must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let n=0;n<t.columns;n++)t.set(r,n,t.get(r,n)-e[r])}(this,r),this;case"column":if(!Ut(r))throw new TypeError("center must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let n=0;n<t.columns;n++)t.set(r,n,t.get(r,n)-e[n])}(this,r),this;case void 0:if("number"!=typeof r)throw new TypeError("center must be a number");return function(t,e){for(let r=0;r<t.rows;r++)for(let n=0;n<t.columns;n++)t.set(r,n,t.get(r,n)-e)}(this,r),this;default:throw new Error(`invalid option: ${t}`)}}scale(t,e={}){if("object"==typeof t&&(e=t,t=void 0),"object"!=typeof e)throw new TypeError("options must be an object");let r=e.scale;switch(t){case"row":if(void 0===r)r=function(t){const e=[];for(let r=0;r<t.rows;r++){let n=0;for(let e=0;e<t.columns;e++)n+=Math.pow(t.get(r,e),2)/(t.columns-1);e.push(Math.sqrt(n))}return e}(this);else if(!Ut(r))throw new TypeError("scale must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let n=0;n<t.columns;n++)t.set(r,n,t.get(r,n)/e[r])}(this,r),this;case"column":if(void 0===r)r=function(t){const e=[];for(let r=0;r<t.columns;r++){let n=0;for(let e=0;e<t.rows;e++)n+=Math.pow(t.get(e,r),2)/(t.rows-1);e.push(Math.sqrt(n))}return e}(this);else if(!Ut(r))throw new TypeError("scale must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let n=0;n<t.columns;n++)t.set(r,n,t.get(r,n)/e[n])}(this,r),this;case void 0:if(void 0===r)r=function(t){const e=t.size-1;let r=0;for(let n=0;n<t.columns;n++)for(let o=0;o<t.rows;o++)r+=Math.pow(t.get(o,n),2)/e;return Math.sqrt(r)}(this);else if("number"!=typeof r)throw new TypeError("scale must be a number");return function(t,e){for(let r=0;r<t.rows;r++)for(let n=0;n<t.columns;n++)t.set(r,n,t.get(r,n)/e)}(this,r),this;default:throw new Error(`invalid option: ${t}`)}}toString(t){return Yt(this,t)}}function ue(t,e){return t-e}ae.prototype.klass="Matrix","undefined"!=typeof Symbol&&(ae.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return Yt(this)}),ae.random=ae.rand,ae.randomInt=ae.randInt,ae.diagonal=ae.diag,ae.prototype.diagonal=ae.prototype.diag,ae.identity=ae.eye,ae.prototype.negate=ae.prototype.neg,ae.prototype.tensorProduct=ae.prototype.kroneckerProduct;class he extends ae{constructor(t,e){if(super(),he.isMatrix(t))return t.clone();if(Number.isInteger(t)&&t>=0){if(this.data=[],!(Number.isInteger(e)&&e>=0))throw new TypeError("nColumns must be a positive integer");for(let r=0;r<t;r++)this.data.push(new Float64Array(e))}else{if(!Ut(t))throw new TypeError("First argument must be a positive number or an array");{const r=t;if("number"!=typeof(e=(t=r.length)?r[0].length:0))throw new TypeError("Data must be a 2D array with at least one element");this.data=[];for(let n=0;n<t;n++){if(r[n].length!==e)throw new RangeError("Inconsistent array dimensions");if(!r[n].every((t=>"number"==typeof t)))throw new TypeError("Input data contains non-numeric values");this.data.push(Float64Array.from(r[n]))}}}this.rows=t,this.columns=e}set(t,e,r){return this.data[t][e]=r,this}get(t,e){return this.data[t][e]}removeRow(t){return Zt(this,t),this.data.splice(t,1),this.rows-=1,this}addRow(t,e){return void 0===e&&(e=t,t=this.rows),Zt(this,t,!0),e=Float64Array.from(ee(this,e)),this.data.splice(t,0,e),this.rows+=1,this}removeColumn(t){te(this,t);for(let e=0;e<this.rows;e++){const r=new Float64Array(this.columns-1);for(let n=0;n<t;n++)r[n]=this.data[e][n];for(let n=t+1;n<this.columns;n++)r[n-1]=this.data[e][n];this.data[e]=r}return this.columns-=1,this}addColumn(t,e){void 0===e&&(e=t,t=this.columns),te(this,t,!0),e=re(this,e);for(let r=0;r<this.rows;r++){const n=new Float64Array(this.columns+1);let o=0;for(;o<t;o++)n[o]=this.data[r][o];for(n[o++]=e[r];o<this.columns+1;o++)n[o]=this.data[r][o-1];this.data[r]=n}return this.columns+=1,this}}!function(t,e){t.prototype.add=function(t){return"number"==typeof t?this.addS(t):this.addM(t)},t.prototype.addS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t);return this},t.prototype.addM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t.get(e,r));return this},t.add=function(t,r){return new e(t).add(r)},t.prototype.sub=function(t){return"number"==typeof t?this.subS(t):this.subM(t)},t.prototype.subS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t);return this},t.prototype.subM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t.get(e,r));return this},t.sub=function(t,r){return new e(t).sub(r)},t.prototype.subtract=t.prototype.sub,t.prototype.subtractS=t.prototype.subS,t.prototype.subtractM=t.prototype.subM,t.subtract=t.sub,t.prototype.mul=function(t){return"number"==typeof t?this.mulS(t):this.mulM(t)},t.prototype.mulS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t);return this},t.prototype.mulM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t.get(e,r));return this},t.mul=function(t,r){return new e(t).mul(r)},t.prototype.multiply=t.prototype.mul,t.prototype.multiplyS=t.prototype.mulS,t.prototype.multiplyM=t.prototype.mulM,t.multiply=t.mul,t.prototype.div=function(t){return"number"==typeof t?this.divS(t):this.divM(t)},t.prototype.divS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t);return this},t.prototype.divM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t.get(e,r));return this},t.div=function(t,r){return new e(t).div(r)},t.prototype.divide=t.prototype.div,t.prototype.divideS=t.prototype.divS,t.prototype.divideM=t.prototype.divM,t.divide=t.div,t.prototype.mod=function(t){return"number"==typeof t?this.modS(t):this.modM(t)},t.prototype.modS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)%t);return this},t.prototype.modM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)%t.get(e,r));return this},t.mod=function(t,r){return new e(t).mod(r)},t.prototype.modulus=t.prototype.mod,t.prototype.modulusS=t.prototype.modS,t.prototype.modulusM=t.prototype.modM,t.modulus=t.mod,t.prototype.and=function(t){return"number"==typeof t?this.andS(t):this.andM(t)},t.prototype.andS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)&t);return this},t.prototype.andM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)&t.get(e,r));return this},t.and=function(t,r){return new e(t).and(r)},t.prototype.or=function(t){return"number"==typeof t?this.orS(t):this.orM(t)},t.prototype.orS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)|t);return this},t.prototype.orM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)|t.get(e,r));return this},t.or=function(t,r){return new e(t).or(r)},t.prototype.xor=function(t){return"number"==typeof t?this.xorS(t):this.xorM(t)},t.prototype.xorS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)^t);return this},t.prototype.xorM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)^t.get(e,r));return this},t.xor=function(t,r){return new e(t).xor(r)},t.prototype.leftShift=function(t){return"number"==typeof t?this.leftShiftS(t):this.leftShiftM(t)},t.prototype.leftShiftS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)<<t);return this},t.prototype.leftShiftM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)<<t.get(e,r));return this},t.leftShift=function(t,r){return new e(t).leftShift(r)},t.prototype.signPropagatingRightShift=function(t){return"number"==typeof t?this.signPropagatingRightShiftS(t):this.signPropagatingRightShiftM(t)},t.prototype.signPropagatingRightShiftS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>t);return this},t.prototype.signPropagatingRightShiftM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>t.get(e,r));return this},t.signPropagatingRightShift=function(t,r){return new e(t).signPropagatingRightShift(r)},t.prototype.rightShift=function(t){return"number"==typeof t?this.rightShiftS(t):this.rightShiftM(t)},t.prototype.rightShiftS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>>t);return this},t.prototype.rightShiftM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>>t.get(e,r));return this},t.rightShift=function(t,r){return new e(t).rightShift(r)},t.prototype.zeroFillRightShift=t.prototype.rightShift,t.prototype.zeroFillRightShiftS=t.prototype.rightShiftS,t.prototype.zeroFillRightShiftM=t.prototype.rightShiftM,t.zeroFillRightShift=t.rightShift,t.prototype.not=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,~this.get(t,e));return this},t.not=function(t){return new e(t).not()},t.prototype.abs=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.abs(this.get(t,e)));return this},t.abs=function(t){return new e(t).abs()},t.prototype.acos=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.acos(this.get(t,e)));return this},t.acos=function(t){return new e(t).acos()},t.prototype.acosh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.acosh(this.get(t,e)));return this},t.acosh=function(t){return new e(t).acosh()},t.prototype.asin=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.asin(this.get(t,e)));return this},t.asin=function(t){return new e(t).asin()},t.prototype.asinh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.asinh(this.get(t,e)));return this},t.asinh=function(t){return new e(t).asinh()},t.prototype.atan=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.atan(this.get(t,e)));return this},t.atan=function(t){return new e(t).atan()},t.prototype.atanh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.atanh(this.get(t,e)));return this},t.atanh=function(t){return new e(t).atanh()},t.prototype.cbrt=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.cbrt(this.get(t,e)));return this},t.cbrt=function(t){return new e(t).cbrt()},t.prototype.ceil=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.ceil(this.get(t,e)));return this},t.ceil=function(t){return new e(t).ceil()},t.prototype.clz32=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.clz32(this.get(t,e)));return this},t.clz32=function(t){return new e(t).clz32()},t.prototype.cos=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.cos(this.get(t,e)));return this},t.cos=function(t){return new e(t).cos()},t.prototype.cosh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.cosh(this.get(t,e)));return this},t.cosh=function(t){return new e(t).cosh()},t.prototype.exp=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.exp(this.get(t,e)));return this},t.exp=function(t){return new e(t).exp()},t.prototype.expm1=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.expm1(this.get(t,e)));return this},t.expm1=function(t){return new e(t).expm1()},t.prototype.floor=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.floor(this.get(t,e)));return this},t.floor=function(t){return new e(t).floor()},t.prototype.fround=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.fround(this.get(t,e)));return this},t.fround=function(t){return new e(t).fround()},t.prototype.log=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log(this.get(t,e)));return this},t.log=function(t){return new e(t).log()},t.prototype.log1p=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log1p(this.get(t,e)));return this},t.log1p=function(t){return new e(t).log1p()},t.prototype.log10=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log10(this.get(t,e)));return this},t.log10=function(t){return new e(t).log10()},t.prototype.log2=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log2(this.get(t,e)));return this},t.log2=function(t){return new e(t).log2()},t.prototype.round=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.round(this.get(t,e)));return this},t.round=function(t){return new e(t).round()},t.prototype.sign=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sign(this.get(t,e)));return this},t.sign=function(t){return new e(t).sign()},t.prototype.sin=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sin(this.get(t,e)));return this},t.sin=function(t){return new e(t).sin()},t.prototype.sinh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sinh(this.get(t,e)));return this},t.sinh=function(t){return new e(t).sinh()},t.prototype.sqrt=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sqrt(this.get(t,e)));return this},t.sqrt=function(t){return new e(t).sqrt()},t.prototype.tan=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.tan(this.get(t,e)));return this},t.tan=function(t){return new e(t).tan()},t.prototype.tanh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.tanh(this.get(t,e)));return this},t.tanh=function(t){return new e(t).tanh()},t.prototype.trunc=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.trunc(this.get(t,e)));return this},t.trunc=function(t){return new e(t).trunc()},t.pow=function(t,r){return new e(t).pow(r)},t.prototype.pow=function(t){return"number"==typeof t?this.powS(t):this.powM(t)},t.prototype.powS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,Math.pow(this.get(e,r),t));return this},t.prototype.powM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,Math.pow(this.get(e,r),t.get(e,r)));return this}}(ae,he);class le extends ae{constructor(t){super(),this.data=t,this.rows=t.length,this.columns=t[0].length}set(t,e,r){return this.data[t][e]=r,this}get(t,e){return this.data[t][e]}}function ce(t,e){let r=0;return Math.abs(t)>Math.abs(e)?(r=e/t,Math.abs(t)*Math.sqrt(1+r*r)):0!==e?(r=t/e,Math.abs(e)*Math.sqrt(1+r*r)):0}class fe{constructor(t,e={}){if((t=le.checkMatrix(t)).isEmpty())throw new Error("Matrix must be non-empty");let r=t.rows,n=t.columns;const{computeLeftSingularVectors:o=!0,computeRightSingularVectors:i=!0,autoTranspose:s=!1}=e;let a,u=Boolean(o),h=Boolean(i),l=!1;if(r<n)if(s){a=t.transpose(),r=a.rows,n=a.columns,l=!0;let e=u;u=h,h=e}else a=t.clone(),console.warn("Computing SVD on a matrix with more columns than rows. Consider enabling autoTranspose");else a=t.clone();let c=Math.min(r,n),f=Math.min(r+1,n),d=new Float64Array(f),g=new he(r,c),p=new he(n,n),y=new Float64Array(n),m=new Float64Array(r),w=new Float64Array(f);for(let t=0;t<f;t++)w[t]=t;let v=Math.min(r-1,n),x=Math.max(0,Math.min(n-2,r)),M=Math.max(v,x);for(let t=0;t<M;t++){if(t<v){d[t]=0;for(let e=t;e<r;e++)d[t]=ce(d[t],a.get(e,t));if(0!==d[t]){a.get(t,t)<0&&(d[t]=-d[t]);for(let e=t;e<r;e++)a.set(e,t,a.get(e,t)/d[t]);a.set(t,t,a.get(t,t)+1)}d[t]=-d[t]}for(let e=t+1;e<n;e++){if(t<v&&0!==d[t]){let n=0;for(let o=t;o<r;o++)n+=a.get(o,t)*a.get(o,e);n=-n/a.get(t,t);for(let o=t;o<r;o++)a.set(o,e,a.get(o,e)+n*a.get(o,t))}y[e]=a.get(t,e)}if(u&&t<v)for(let e=t;e<r;e++)g.set(e,t,a.get(e,t));if(t<x){y[t]=0;for(let e=t+1;e<n;e++)y[t]=ce(y[t],y[e]);if(0!==y[t]){y[t+1]<0&&(y[t]=0-y[t]);for(let e=t+1;e<n;e++)y[e]/=y[t];y[t+1]+=1}if(y[t]=-y[t],t+1<r&&0!==y[t]){for(let e=t+1;e<r;e++)m[e]=0;for(let e=t+1;e<r;e++)for(let r=t+1;r<n;r++)m[e]+=y[r]*a.get(e,r);for(let e=t+1;e<n;e++){let n=-y[e]/y[t+1];for(let o=t+1;o<r;o++)a.set(o,e,a.get(o,e)+n*m[o])}}if(h)for(let e=t+1;e<n;e++)p.set(e,t,y[e])}}let b=Math.min(n,r+1);if(v<n&&(d[v]=a.get(v,v)),r<b&&(d[b-1]=0),x+1<b&&(y[x]=a.get(x,b-1)),y[b-1]=0,u){for(let t=v;t<c;t++){for(let e=0;e<r;e++)g.set(e,t,0);g.set(t,t,1)}for(let t=v-1;t>=0;t--)if(0!==d[t]){for(let e=t+1;e<c;e++){let n=0;for(let o=t;o<r;o++)n+=g.get(o,t)*g.get(o,e);n=-n/g.get(t,t);for(let o=t;o<r;o++)g.set(o,e,g.get(o,e)+n*g.get(o,t))}for(let e=t;e<r;e++)g.set(e,t,-g.get(e,t));g.set(t,t,1+g.get(t,t));for(let e=0;e<t-1;e++)g.set(e,t,0)}else{for(let e=0;e<r;e++)g.set(e,t,0);g.set(t,t,1)}}if(h)for(let t=n-1;t>=0;t--){if(t<x&&0!==y[t])for(let e=t+1;e<n;e++){let r=0;for(let o=t+1;o<n;o++)r+=p.get(o,t)*p.get(o,e);r=-r/p.get(t+1,t);for(let o=t+1;o<n;o++)p.set(o,e,p.get(o,e)+r*p.get(o,t))}for(let e=0;e<n;e++)p.set(e,t,0);p.set(t,t,1)}let E=b-1,N=0,S=Number.EPSILON;for(;b>0;){let t,e;for(t=b-2;t>=-1&&-1!==t;t--){const e=Number.MIN_VALUE+S*Math.abs(d[t]+Math.abs(d[t+1]));if(Math.abs(y[t])<=e||Number.isNaN(y[t])){y[t]=0;break}}if(t===b-2)e=4;else{let r;for(r=b-1;r>=t&&r!==t;r--){let e=(r!==b?Math.abs(y[r]):0)+(r!==t+1?Math.abs(y[r-1]):0);if(Math.abs(d[r])<=S*e){d[r]=0;break}}r===t?e=3:r===b-1?e=1:(e=2,t=r)}switch(t++,e){case 1:{let e=y[b-2];y[b-2]=0;for(let r=b-2;r>=t;r--){let o=ce(d[r],e),i=d[r]/o,s=e/o;if(d[r]=o,r!==t&&(e=-s*y[r-1],y[r-1]=i*y[r-1]),h)for(let t=0;t<n;t++)o=i*p.get(t,r)+s*p.get(t,b-1),p.set(t,b-1,-s*p.get(t,r)+i*p.get(t,b-1)),p.set(t,r,o)}break}case 2:{let e=y[t-1];y[t-1]=0;for(let n=t;n<b;n++){let o=ce(d[n],e),i=d[n]/o,s=e/o;if(d[n]=o,e=-s*y[n],y[n]=i*y[n],u)for(let e=0;e<r;e++)o=i*g.get(e,n)+s*g.get(e,t-1),g.set(e,t-1,-s*g.get(e,n)+i*g.get(e,t-1)),g.set(e,n,o)}break}case 3:{const e=Math.max(Math.abs(d[b-1]),Math.abs(d[b-2]),Math.abs(y[b-2]),Math.abs(d[t]),Math.abs(y[t])),o=d[b-1]/e,i=d[b-2]/e,s=y[b-2]/e,a=d[t]/e,l=y[t]/e,c=((i+o)*(i-o)+s*s)/2,f=o*s*(o*s);let m=0;0===c&&0===f||(m=c<0?0-Math.sqrt(c*c+f):Math.sqrt(c*c+f),m=f/(c+m));let w=(a+o)*(a-o)+m,v=a*l;for(let e=t;e<b-1;e++){let o=ce(w,v);0===o&&(o=Number.MIN_VALUE);let i=w/o,s=v/o;if(e!==t&&(y[e-1]=o),w=i*d[e]+s*y[e],y[e]=i*y[e]-s*d[e],v=s*d[e+1],d[e+1]=i*d[e+1],h)for(let t=0;t<n;t++)o=i*p.get(t,e)+s*p.get(t,e+1),p.set(t,e+1,-s*p.get(t,e)+i*p.get(t,e+1)),p.set(t,e,o);if(o=ce(w,v),0===o&&(o=Number.MIN_VALUE),i=w/o,s=v/o,d[e]=o,w=i*y[e]+s*d[e+1],d[e+1]=-s*y[e]+i*d[e+1],v=s*y[e+1],y[e+1]=i*y[e+1],u&&e<r-1)for(let t=0;t<r;t++)o=i*g.get(t,e)+s*g.get(t,e+1),g.set(t,e+1,-s*g.get(t,e)+i*g.get(t,e+1)),g.set(t,e,o)}y[b-2]=w,N+=1;break}case 4:if(d[t]<=0&&(d[t]=d[t]<0?-d[t]:0,h))for(let e=0;e<=E;e++)p.set(e,t,-p.get(e,t));for(;t<E&&!(d[t]>=d[t+1]);){let e=d[t];if(d[t]=d[t+1],d[t+1]=e,h&&t<n-1)for(let r=0;r<n;r++)e=p.get(r,t+1),p.set(r,t+1,p.get(r,t)),p.set(r,t,e);if(u&&t<r-1)for(let n=0;n<r;n++)e=g.get(n,t+1),g.set(n,t+1,g.get(n,t)),g.set(n,t,e);t++}N=0,b--}}if(l){let t=p;p=g,g=t}this.m=r,this.n=n,this.s=d,this.U=g,this.V=p}solve(t){let e=t,r=this.threshold,n=this.s.length,o=he.zeros(n,n);for(let t=0;t<n;t++)Math.abs(this.s[t])<=r?o.set(t,t,0):o.set(t,t,1/this.s[t]);let i=this.U,s=this.rightSingularVectors,a=s.mmul(o),u=s.rows,h=i.rows,l=he.zeros(u,h);for(let t=0;t<u;t++)for(let e=0;e<h;e++){let r=0;for(let o=0;o<n;o++)r+=a.get(t,o)*i.get(e,o);l.set(t,e,r)}return l.mmul(e)}solveForDiagonal(t){return this.solve(he.diag(t))}inverse(){let t=this.V,e=this.threshold,r=t.rows,n=t.columns,o=new he(r,this.s.length);for(let i=0;i<r;i++)for(let r=0;r<n;r++)Math.abs(this.s[r])>e&&o.set(i,r,t.get(i,r)/this.s[r]);let i=this.U,s=i.rows,a=i.columns,u=new he(r,s);for(let t=0;t<r;t++)for(let e=0;e<s;e++){let r=0;for(let n=0;n<a;n++)r+=o.get(t,n)*i.get(e,n);u.set(t,e,r)}return u}get condition(){return this.s[0]/this.s[Math.min(this.m,this.n)-1]}get norm2(){return this.s[0]}get rank(){let t=Math.max(this.m,this.n)*this.s[0]*Number.EPSILON,e=0,r=this.s;for(let n=0,o=r.length;n<o;n++)r[n]>t&&e++;return e}get diagonal(){return Array.from(this.s)}get threshold(){return Number.EPSILON/2*Math.max(this.m,this.n)*this.s[0]}get leftSingularVectors(){return this.U}get rightSingularVectors(){return this.V}get diagonalMatrix(){return he.diag(this.s)}}var de,ge={center:[0,0],linkDistance:50},pe=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="mds",this.options=r(r({},ge),t)}return t.prototype.execute=function(t,e){return this.genericMDSLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericMDSLayout(!0,t,e)},t.prototype.genericMDSLayout=function(t,e,n){var o=r(r({},this.options),n),i=o.center,s=void 0===i?[0,0]:i,a=o.linkDistance,u=void 0===a?50:a,h=o.layoutInvisibles,l=o.onLayoutEnd,d=e.getAllNodes(),g=e.getAllEdges();if(h||(d=d.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e})),g=g.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e}))),!d||0===d.length){var p={nodes:[],edges:g};return null==l||l(p),p}if(1===d.length){t&&e.mergeNodeData(d[0].id,{x:s[0],y:s[1]});var m={nodes:[r(r({},d[0]),{data:r(r({},d[0].data),{x:s[0],y:s[1]})})],edges:g};return null==l||l(m),m}var w=f({nodes:d,edges:g},!1),v=c(w);ye(v);var x=function(t,e){var r=[];return t.forEach((function(t){var n=[];t.forEach((function(t){n.push(t*e)})),r.push(n)})),r}(v,u),M=me(x),b=[];M.forEach((function(t,e){var r=y(d[e]);r.data.x=t[0]+s[0],r.data.y=t[1]+s[1],b.push(r)})),t&&b.forEach((function(t){return e.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}));var E={nodes:b,edges:g};return null==l||l(E),E},t}(),ye=function(t){var e=-999999;t.forEach((function(t){t.forEach((function(t){t!==1/0&&e<t&&(e=t)}))})),t.forEach((function(r,n){r.forEach((function(r,o){r===1/0&&(t[n][o]=e)}))}))},me=function(t){var e=he.mul(he.pow(t,2),-.5),r=e.mean("row"),n=e.mean("column"),o=e.mean();e.add(o).subRowVector(r).subColumnVector(n);var i=new fe(e),s=he.sqrt(i.diagonalMatrix).diagonal();return i.leftSingularVectors.toJSON().map((function(t){return he.mul([t],[s]).toJSON()[0].splice(0,2)}))},we={iterations:10,height:10,width:10,speed:100,gravity:10,k:5},ve=function(t,e,r,n,o,i){e.forEach((function(s,a){r[a]={x:0,y:0},e.forEach((function(e,u){if(a!==u&&o[a]===o[u]){var h=s.x-e.x,l=s.y-e.y,c=Math.sqrt(h*h+l*l);if(0===c){c=1;var f=a>u?1:-1;h=.01*f,l=.01*f}if(c<i(t[a])/2+i(t[u])/2){var d=n*n/c;r[a].x+=h/c*d,r[a].y+=l/c*d}}}))}))},xe=function(t,e,r,n,o,i,s,a){var u=i||s/10;return n&&e.forEach((function(e,r){var n=t[r].x-t[o].x,i=t[r].y-t[o].y,s=Math.sqrt(n*n+i*i),a=i/s,u=-n/s,h=Math.sqrt(e.x*e.x+e.y*e.y),l=Math.acos((a*e.x+u*e.y)/h);l>Math.PI/2&&(l-=Math.PI/2,a*=-1,u*=-1);var c=Math.cos(l)*h;e.x=a*c,e.y=u*c})),t.forEach((function(i,s){if(s!==o){var h=Math.sqrt(e[s].x*e[s].x+e[s].y*e[s].y);if(h>0&&s!==o){var l=Math.min(u*(r/800),h);if(i.x+=e[s].x/h*l,i.y+=e[s].y/h*l,n){var c=i.x-t[o].x,f=i.y-t[o].y,d=Math.sqrt(c*c+f*f);c=c/d*a[s],f=f/d*a[s],i.x=t[o].x+c,i.y=t[o].y+f}}}})),t},Me={maxIteration:1e3,focusNode:null,unitRadius:null,linkDistance:50,preventOverlap:!1,strictRadial:!0,maxPreventOverlapIteration:200,sortStrength:10},be=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="radial",this.options=r(r({},Me),t)}return t.prototype.execute=function(t,e){return this.genericRadialLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericRadialLayout(!0,t,e)},t.prototype.genericRadialLayout=function(t,e,n){var s=r(r({},this.options),n),u=s.width,h=s.height,l=s.center,d=s.focusNode,g=s.unitRadius,p=s.nodeSize,m=s.nodeSpacing,w=s.strictRadial,v=s.preventOverlap,x=s.maxPreventOverlapIteration,M=s.sortBy,b=s.linkDistance,E=void 0===b?50:b,N=s.sortStrength,S=void 0===N?10:N,A=s.maxIteration,k=void 0===A?1e3:A,I=s.layoutInvisibles,D=s.onLayoutEnd,R=e.getAllNodes(),_=e.getAllEdges();if(I||(R=R.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e})),_=_.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e}))),!R||0===R.length){var z={nodes:[],edges:_};return null==D||D(z),z}var T=u||"undefined"==typeof window?u:window.innerWidth,O=h||"undefined"==typeof window?h:window.innerHeight,C=l||[T/2,O/2];if(1===R.length){t&&e.mergeNodeData(R[0].id,{x:C[0],y:C[1]});var L={nodes:[r(r({},R[0]),{data:r(r({},R[0].data),{x:C[0],y:C[1]})})],edges:_};return null==D||D(L),L}var P=R[0];if(a(d)){for(var q=0;q<R.length;q++)if(R[q].id===d){P=R[q];break}}else P=d||R[0];var j=Se(R,P.id),V=f({nodes:R,edges:_},!1),F=c(V),$=ke(F,j);Ae(F,j,$+1);var G=F[j],U=T-C[0]>C[0]?C[0]:T-C[0],B=O-C[1]>C[1]?C[1]:O-C[1];0===U&&(U=T/2),0===B&&(B=O/2);var K=Math.min(U,B),W=Math.max.apply(Math,i([],o(G),!1)),H=[],J=g||K/W;G.forEach((function(t,e){H[e]=t*J}));var Y,X=Ee(R,F,E,H,J,M,S),Q=Ne(X),Z=function(t,e,r){try{var n=he.mul(he.pow(e,2),-.5),o=n.mean("row"),i=n.mean("column"),s=n.mean();n.add(s).subRowVector(o).subColumnVector(i);var a=new fe(n),u=he.sqrt(a.diagonalMatrix).diagonal();return a.leftSingularVectors.toJSON().map((function(e){return he.mul([e],[u]).toJSON()[0].splice(0,t)}))}catch(t){for(var h=[],l=0;l<e.length;l++){var c=Math.random()*r,f=Math.random()*r;h.push([c,f])}return h}}(E,X,E),tt=Z.map((function(t){var e=o(t,2),r=e[0],n=e[1];return{x:(isNaN(r)?Math.random()*E:r)-Z[j][0],y:(isNaN(n)?Math.random()*E:n)-Z[j][1]}}));if(this.run(k,tt,Q,X,H,j),v){Y=Ie(p,m);var et={nodes:R,nodeSizeFunc:Y,positions:tt,radii:H,height:O,width:T,strictRadial:Boolean(w),focusIdx:j,iterations:x||200,k:tt.length/4.5};tt=function(t,e){for(var n=r(r({},we),e),o=n.positions,i=n.iterations,s=n.width,a=n.k,u=n.speed,h=void 0===u?100:u,l=n.strictRadial,c=n.focusIdx,f=n.radii,d=void 0===f?[]:f,g=n.nodeSizeFunc,p=t.getAllNodes(),y=[],m=s/10,w=0;w<i;w++)o.forEach((function(t,e){y[e]={x:0,y:0}})),ve(p,o,y,a,d,g),xe(o,y,h,l,c,m,s,d);return o}(e,et)}var rt=[];tt.forEach((function(t,e){var r=y(R[e]);r.data.x=t.x+C[0],r.data.y=t.y+C[1],rt.push(r)})),t&&rt.forEach((function(t){return e.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}));var nt={nodes:rt,edges:_};return null==D||D(nt),nt},t.prototype.run=function(t,e,r,n,o,i){for(var s=0;s<=t;s++){var a=s/t;this.oneIteration(a,e,o,n,r,i)}},t.prototype.oneIteration=function(t,e,r,n,o,i){var s=1-t;e.forEach((function(a,u){var h=d(a,{x:0,y:0}),l=0===h?0:1/h;if(u!==i){var c=0,f=0,g=0;e.forEach((function(t,e){if(u!==e){var r=d(a,t),i=0===r?0:1/r,s=n[e][u];g+=o[u][e],c+=o[u][e]*(t.x+s*(a.x-t.x)*i),f+=o[u][e]*(t.y+s*(a.y-t.y)*i)}}));var p=0===r[u]?0:1/r[u];g*=s,g+=t*p*p,c*=s,c+=t*p*a.x*l,a.x=c/g,f*=s,f+=t*p*a.y*l,a.y=f/g}}))},t}(),Ee=function(t,e,r,n,o,i,s){if(!t)return[];var u=[];if(e){var h={};e.forEach((function(e,l){var c=[];e.forEach((function(e,u){var f,d;if(l===u)c.push(0);else if(n[l]===n[u])if("data"===i)c.push(e*(Math.abs(l-u)*s)/(n[l]/o));else if(i){var g=void 0,p=void 0;if(h[t[l].id])g=h[t[l].id];else{var y=("id"===i?t[l].id:null===(f=t[l].data)||void 0===f?void 0:f[i])||0;g=a(y)?y.charCodeAt(0):y,h[t[l].id]=g}h[t[u].id]?p=h[t[u].id]:(y=("id"===i?t[u].id:null===(d=t[u].data)||void 0===d?void 0:d[i])||0,p=a(y)?y.charCodeAt(0):y,h[t[u].id]=p),c.push(e*(Math.abs(g-p)*s)/(n[l]/o))}else c.push(e*r/(n[l]/o));else{var m=(r+o)/2;c.push(e*m)}})),u.push(c)}))}return u},Ne=function(t){for(var e=t.length,r=t[0].length,n=[],o=0;o<e;o++){for(var i=[],s=0;s<r;s++)0!==t[o][s]?i.push(1/(t[o][s]*t[o][s])):i.push(0);n.push(i)}return n},Se=function(t,e){var r=-1;return t.forEach((function(t,n){t.id===e&&(r=n)})),Math.max(r,0)},Ae=function(t,e,r){for(var n=t.length,o=0;o<n;o++)if(t[e][o]===1/0){t[e][o]=r,t[o][e]=r;for(var i=0;i<n;i++)t[o][i]!==1/0&&t[e][i]===1/0&&(t[e][i]=r+t[o][i],t[i][e]=r+t[o][i])}for(o=0;o<n;o++)if(o!==e)for(i=0;i<n;i++)if(t[o][i]===1/0){var s=Math.abs(t[e][o]-t[e][i]);s=0===s?1:s,t[o][i]=s}},ke=function(t,e){for(var r=0,n=0;n<t[e].length;n++)t[e][n]!==1/0&&(r=t[e][n]>r?t[e][n]:r);return r},Ie=function(t,e){var r;return r=l(e)?function(){return e}:m(e)?e:function(){return 0},t?h(t)?function(e){return(t[0]>t[1]?t[0]:t[1])+r(e)}:function(e){return t+r(e)}:function(t){var e,n;return(null===(e=t.data)||void 0===e?void 0:e.bboxSize)?Math.max(t.data.bboxSize[0],t.data.bboxSize[1])+r(t):(null===(n=t.data)||void 0===n?void 0:n.size)?h(t.data.size)?Math.max(t.data.size[0],t.data.size[1])+r(t):g(t.data.size)?(t.data.size.width>t.data.size.height?t.data.size.width:t.data.size.height)+r(t):t.data.size+r(t):10+r(t)}},De={center:[0,0],width:300,height:300},Re={circular:M,concentric:S,mds:pe,random:function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="random",this.options=r(r({},De),t)}return t.prototype.execute=function(t,e){return this.genericRandomLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericRandomLayout(!0,t,e)},t.prototype.genericRandomLayout=function(t,e,n){var o=r(r({},this.options),n),i=o.center,s=o.width,a=o.height,u=o.layoutInvisibles,h=o.onLayoutEnd,l=e.getAllNodes();u||(l=l.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e})));var c=s||"undefined"==typeof window?s:window.innerWidth,f=a||"undefined"==typeof window?a:window.innerHeight,d=i||[c/2,f/2],g=[];l&&l.forEach((function(t){g.push({id:t.id,data:{x:.9*(Math.random()-.5)*c+d[0],y:.9*(Math.random()-.5)*f+d[1]}})})),t&&g.forEach((function(t){return e.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}));var p={nodes:g,edges:e.getAllEdges()};return null==h||h(p),p},t}(),grid:Lt,radial:be,force:kt,d3force:bt,fruchterman:Ot};function _e(){(null==de?void 0:de.stop)&&de.stop()}function ze(t,e){return r=this,n=void 0,i=function(){var r,n,o,i,a,u,h,l;return function(t,e){var r,n,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(u){return function(a){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(r=1,n&&(o=2&a[0]?n.return:a[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,a[1])).done)return o;switch(n=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,n=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],n=0}finally{r=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}}(this,(function(c){if(r=t.layout,n=r.id,o=r.options,i=r.iterations,a=t.nodes,u=t.edges,h=new s({nodes:a,edges:u}),!(l=Re[n]))throw new Error("Unknown layout id: ".concat(n));return de=new l(o),[2,new Promise((function(t){var r;de.assign(h,{onLayoutEnd:function(r){t([r,e])}}),(r=de).tick&&r.stop&&r.restart&&(de.stop(),de.tick(i))}))]}))},new((o=void 0)||(o=Promise))((function(t,e){function s(t){try{u(i.next(t))}catch(t){e(t)}}function a(t){try{u(i.throw(t))}catch(t){e(t)}}function u(e){var r;e.done?t(e.value):(r=e.value,r instanceof o?r:new o((function(t){t(r)}))).then(s,a)}u((i=i.apply(r,n||[])).next())}));var r,n,o,i}addEventListener("message",(function(t){var r,n=t.data,o=n.type,i=n.method,s=n.id,a=n.params;"RPC"===o&&i&&((r=e[i])?Promise.resolve().then((function(){return r.apply(e,a)})):Promise.reject("No such method")).then((function(t){postMessage({type:"RPC",id:s,result:t})})).catch((function(t){var e={message:t};t.stack&&(e.message=t.message,e.stack=t.stack,e.name=t.name),postMessage({type:"RPC",id:s,error:e})}))})),postMessage({type:"RPC",method:"ready"});\n//# sourceMappingURL=1f8aa319de677a5a27b9.worker.js.map']))),n(t,o),t}},475:t=>{t.exports=function(t,e){var r=0,n={};t.addEventListener("message",(function(e){var r=e.data;if("RPC"===r.type)if(r.id){var o=n[r.id];o&&(delete n[r.id],r.error?o[1](Object.assign(Error(r.error.message),r.error)):o[0](r.result))}else{var i=document.createEvent("Event");i.initEvent(r.method,!1,!1),i.data=r.params,t.dispatchEvent(i)}})),e.forEach((function(e){t[e]=function(){var o=arguments;return new Promise((function(i,s){var a=++r;n[a]=[i,s],t.postMessage({type:"RPC",id:a,method:e,params:[].slice.call(o)})}))}}))}}},e={};function r(n){var o=e[n];if(void 0!==o)return o.exports;var i=e[n]={exports:{}};return t[n](i,i.exports,r),i.exports}r.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return r.d(e,{a:e}),e},r.d=(t,e)=>{for(var n in e)r.o(e,n)&&!r.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},r.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);var n={};(()=>{r.d(n,{SB:()=>M,W1:()=>_,jA:()=>Rt,y7:()=>Tt,O2:()=>Ft,Me:()=>Gt,AI:()=>Me,D4:()=>Re,_5:()=>Le,y9:()=>I,Xp:()=>R,qR:()=>qe,i_:()=>Pe});var t=function(e,r){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])},t(e,r)},e=function(){return e=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var o in e=arguments[r])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},e.apply(this,arguments)};function o(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(t);o<n.length;o++)e.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(t,n[o])&&(r[n[o]]=t[n[o]])}return r}function i(t,e){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var n,o,i=r.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(n=i.next()).done;)s.push(n.value)}catch(t){o={error:t}}finally{try{n&&!n.done&&(r=i.return)&&r.call(i)}finally{if(o)throw o.error}}return s}function s(t,e,r){if(r||2===arguments.length)for(var n,o=0,i=e.length;o<i;o++)!n&&o in e||(n||(n=Array.prototype.slice.call(e,0,o)),n[o]=e[o]);return t.concat(n||Array.prototype.slice.call(e))}Object.create,Object.create;var a=function(t){return"string"==typeof t},u=/-(\w)/g,h=(function(t){return t.replace(u,(function(t,e){return e?e.toUpperCase():""}))},Object.create(null),Array.isArray),l=function(t){return"number"==typeof t},c=function(t){for(var e=[],r=t.length,n=0;n<r;n+=1){e[n]=[];for(var o=0;o<r;o+=1)n===o?e[n][o]=0:0!==t[n][o]&&t[n][o]?e[n][o]=t[n][o]:e[n][o]=1/0}for(var i=0;i<r;i+=1)for(n=0;n<r;n+=1)for(o=0;o<r;o+=1)e[n][o]>e[n][i]+e[i][o]&&(e[n][o]=e[n][i]+e[i][o]);return e},f=function(t,e){var r=t.nodes,n=t.edges,o=[],i={};if(!r)throw new Error("invalid nodes data!");return r&&r.forEach((function(t,e){i[t.id]=e,o.push([])})),null==n||n.forEach((function(t){var r=t.source,n=t.target,s=i[r],a=i[n];void 0!==s&&void 0!==a&&(o[s][a]=1,e||(o[a][s]=1))})),o},d=function(t,e){return Math.sqrt((t.x-e.x)*(t.x-e.x)+(t.y-e.y)*(t.y-e.y))},g=function(t){return null!==t&&"object"==typeof t},p=function(t){if(null===t)return t;if(t instanceof Date)return new Date(t.getTime());if(t instanceof Array){var r=[];return t.forEach((function(t){r.push(t)})),r.map((function(t){return p(t)}))}if("object"==typeof t&&Object.keys(t).length){var n=e({},t);return Object.keys(n).forEach((function(t){n[t]=p(n[t])})),n}return t},m=function(t,e){var r=p(t);return r.data=r.data||{},e&&(l(r.data.x)||(r.data.x=Math.random()*e[0]),l(r.data.y)||(r.data.y=Math.random()*e[1])),r},y=function(t){return"function"==typeof t};function w(t,e){return y(e)?e:l(e)?function(){return e}:function(){return t}}function v(t,e,r){return void 0===r&&(r=!0),e||0===e?y(e)?e:l(e)?function(){return e}:h(e)?function(){if(r){var n=Math.max.apply(Math,s([],i(e),!1));return isNaN(n)?t:n}return e}:g(e)?function(){if(r){var n=Math.max(e.width,e.height);return isNaN(n)?t:n}return[e.width,e.height]}:function(){return t}:function(e){var r=(e.data||{}).size;return r?h(r)?r[0]>r[1]?r[0]:r[1]:g(r)?r.width>r.height?r.width:r.height:r:t}}var x={radius:null,startRadius:null,endRadius:null,startAngle:0,endAngle:2*Math.PI,clockwise:!0,divisions:1,ordering:null,angleRatio:1},M=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="circular",this.options=e(e({},x),t)}return t.prototype.execute=function(t,e){return this.genericCircularLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericCircularLayout(!0,t,e)},t.prototype.genericCircularLayout=function(t,r,n){var o=e(e({},this.options),n),s=o.width,a=o.height,u=o.center,h=o.divisions,l=o.startAngle,c=void 0===l?0:l,f=o.endAngle,d=void 0===f?2*Math.PI:f,g=o.angleRatio,p=o.ordering,y=o.clockwise,x=o.nodeSpacing,M=o.nodeSize,N=o.layoutInvisibles,S=o.onLayoutEnd,k=r.getAllNodes(),A=r.getAllEdges();N||(k=k.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e})),A=A.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e})));var R=k.length;if(0===R)return null==S||S({nodes:[],edges:[]}),{nodes:[],edges:[]};var I=i(E(s,a,u),3),D=I[0],_=I[1],C=I[2];if(1===R){t&&r.mergeNodeData(k[0].id,{x:C[0],y:C[1]});var O={nodes:[e(e({},k[0]),{data:e(e({},k[0].data),{x:C[0],y:C[1]})})],edges:A};return null==S||S(O),O}var T=(d-c)/R,z=o.radius,L=o.startRadius,P=o.endRadius;if(x){var q=w(10,x),j=v(10,M),V=-1/0;k.forEach((function(t){var e=j(t);V<e&&(V=e)}));var F=0;k.forEach((function(t,e){F+=0===e?V||10:(q(t)||0)+(V||10)})),z=F/(2*Math.PI)}else z||L||P?!L&&P?L=P:L&&!P&&(P=L):z=Math.min(_,D)/2;var U=T*g,G=[];G="topology"===p?b(r,k):"topology-directed"===p?b(r,k,!0):"degree"===p?function(t,e){var r=[];return e.forEach((function(t,e){r.push(m(t))})),r.sort((function(e,r){return t.getDegree(e.id,"both")-t.getDegree(r.id,"both")})),r}(r,k):k.map((function(t){return m(t)}));for(var B=Math.ceil(R/h),$=0;$<R;++$){var H=z;H||null===L||null===P||(H=L+$*(P-L)/(R-1)),H||(H=10+100*$/(R-1));var J=c+$%B*U+2*Math.PI/h*Math.floor($/B);y||(J=d-$%B*U-2*Math.PI/h*Math.floor($/B)),G[$].data.x=C[0]+Math.cos(J)*H,G[$].data.y=C[1]+Math.sin(J)*H}t&&G.forEach((function(t){r.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}));var K={nodes:G,edges:A};return null==S||S(K),K},t}(),b=function(t,e,r){void 0===r&&(r=!1);var n=[m(e[0])],o={},i=e.length;o[e[0].id]=!0;var s=0;return e.forEach((function(a,u){if(0!==u)if(u!==i-1&&t.getDegree(a.id,"both")===t.getDegree(e[u+1].id,"both")&&!t.areNeighbors(n[s].id,a.id)||o[a.id]){for(var h=r?t.getSuccessors(n[s].id):t.getNeighbors(n[s].id),l=!1,c=0;c<h.length;c++){var f=h[c];if(t.getDegree(f.id)===t.getDegree(a.id)&&!o[f.id]){n.push(m(f)),o[f.id]=!0,l=!0;break}}for(var d=0;!l&&(o[e[d].id]||(n.push(m(e[d])),o[e[d].id]=!0,l=!0),++d!==i););}else n.push(m(a)),o[a.id]=!0,s++})),n},E=function(t,e,r){var n=t,o=e,i=r;return n||"undefined"==typeof window||(n=window.innerWidth),o||"undefined"==typeof window||(o=window.innerHeight),i||(i=[n/2,o/2]),[n,o,i]},N=r(161),S=r.n(N),k=r(825),A=r.n(k),R={LAYOUT_ITERATION:"tick",LAYOUT_END:"layoutend"},I=function(e){function r(t,r,n){var o=e.call(this)||this;return o.graph=t,o.layout=r,o.options=n,o.spawnWorker(),o}return function(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}(r,e),r.prototype.spawnWorker=function(){this.worker&&this.worker.terminate(),this.worker=A()(),this.running&&(this.running=!1,this.start())},r.prototype.start=function(){var t,e=this;if(this.running)return this;this.running=!0;var r=this.layout.options,n=(r.onLayoutEnd,r.onTick,o(r,["onLayoutEnd","onTick"])),s={layout:{id:this.layout.id,options:n,iterations:null===(t=this.options)||void 0===t?void 0:t.iterations},nodes:this.graph.getAllNodes(),edges:this.graph.getAllEdges()},a=new Float32Array([0]);return this.worker.calculateLayout(s,[a]).then((function(t){var r=i(t,2),n=r[0];r[1],e.emit(R.LAYOUT_END,n),e.layout.options.onLayoutEnd&&e.layout.options.onLayoutEnd(n)})),this},r.prototype.stop=function(){return this.running=!1,this.worker.stopLayout(),this},r.prototype.kill=function(){this.worker&&this.worker.terminate()},r.prototype.isRunning=function(){return this.running},r}(S()),D={nodeSize:30,minNodeSpacing:10,nodeSpacing:10,preventOverlap:!1,sweep:void 0,equidistant:!1,startAngle:1.5*Math.PI,clockwise:!0,maxLevelDiff:void 0,sortBy:"degree"},_=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="concentric",this.options=e(e({},D),t)}return t.prototype.execute=function(t,e){return this.genericConcentricLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericConcentricLayout(!0,t,e)},t.prototype.genericConcentricLayout=function(t,r,n){var o=e(e({},this.options),n),i=o.center,s=o.width,u=o.height,c=o.sortBy,f=o.maxLevelDiff,d=o.sweep,p=o.clockwise,w=o.equidistant,v=o.minNodeSpacing,x=void 0===v?10:v,M=o.preventOverlap,b=o.startAngle,E=void 0===b?1.5*Math.PI:b,N=o.nodeSize,S=o.nodeSpacing,k=o.layoutInvisibles,A=o.onLayoutEnd,R=r.getAllNodes(),I=r.getAllEdges();k||(R=R.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e})),I=I.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e})));var D=R.length;if(0===D){var _={nodes:[],edges:I};return null==A||A(_),_}var C=s||"undefined"==typeof window?s:window.innerWidth,O=u||"undefined"==typeof window?u:window.innerHeight,T=i||[C/2,O/2];if(1===D){t&&r.mergeNodeData(R[0].id,{x:T[0],y:T[1]});var z={nodes:[e(e({},R[0]),{data:e(e({},R[0].data),{x:T[0],y:T[1]})})],edges:I};return null==A||A(z),z}var L,P=[],q=0;L=h(N)?Math.max(N[0],N[1]):N,h(S)?q=Math.max(S[0],S[1]):l(S)&&(q=S),R.forEach((function(t){var e=m(t);P.push(e);var r=L,n=e.data;h(n.size)?r=Math.max(n.size[0],n.size[1]):l(n.size)?r=n.size:g(n.size)&&(r=Math.max(n.size.width,n.size.height)),L=Math.max(L,r),y(S)&&(q=Math.max(S(t),q))}));var j={};P.forEach((function(t,e){j[t.id]=e}));var V=c;a(V)&&void 0!==P[0].data[V]||(V="degree"),"degree"===V?P.sort((function(t,e){return r.getDegree(e.id,"both")-r.getDegree(t.id,"both")})):P.sort((function(t,e){return e.data[V]-t.data[V]}));var F=P[0],U=(f||("degree"===V?r.getDegree(F.id,"both"):F.data[V]))/4,G=[{nodes:[]}],B=G[0];P.forEach((function(t){if(B.nodes.length>0){var e="degree"===V?Math.abs(r.getDegree(B.nodes[0].id,"both")-r.getDegree(t.id,"both")):Math.abs(B.nodes[0].data[V]-t.data[V]);U&&e>=U&&(B={nodes:[]},G.push(B))}B.nodes.push(t)}));var $=L+(q||x);if(!M){var H=G.length>0&&G[0].nodes.length>1,J=(Math.min(C,O)/2-$)/(G.length+(H?1:0));$=Math.min($,J)}var K=0;if(G.forEach((function(t){var e=void 0===d?2*Math.PI-2*Math.PI/t.nodes.length:d;if(t.dTheta=e/Math.max(1,t.nodes.length-1),t.nodes.length>1&&M){var r=Math.cos(t.dTheta)-Math.cos(0),n=Math.sin(t.dTheta)-Math.sin(0),o=Math.sqrt($*$/(r*r+n*n));K=Math.max(o,K)}t.r=K,K+=$})),w){for(var W=0,Y=0,Z=0;Z<G.length;Z++){var X=(G[Z].r||0)-Y;W=Math.max(W,X)}Y=0,G.forEach((function(t,e){0===e&&(Y=t.r||0),t.r=Y,Y+=W}))}G.forEach((function(t){var e=t.dTheta||0,r=t.r||0;t.nodes.forEach((function(t,n){var o=E+(p?1:-1)*e*n;t.data.x=T[0]+r*Math.cos(o),t.data.y=T[1]+r*Math.sin(o)}))})),t&&P.forEach((function(t){return r.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}));var Q={nodes:P,edges:I};return null==A||A(Q),Q},t}();function C(t,e,r,n){if(isNaN(e)||isNaN(r))return t;var o,i,s,a,u,h,l,c,f,d=t._root,g={data:n},p=t._x0,m=t._y0,y=t._x1,w=t._y1;if(!d)return t._root=g,t;for(;d.length;)if((h=e>=(i=(p+y)/2))?p=i:y=i,(l=r>=(s=(m+w)/2))?m=s:w=s,o=d,!(d=d[c=l<<1|h]))return o[c]=g,t;if(a=+t._x.call(null,d.data),u=+t._y.call(null,d.data),e===a&&r===u)return g.next=d,o?o[c]=g:t._root=g,t;do{o=o?o[c]=new Array(4):t._root=new Array(4),(h=e>=(i=(p+y)/2))?p=i:y=i,(l=r>=(s=(m+w)/2))?m=s:w=s}while((c=l<<1|h)==(f=(u>=s)<<1|a>=i));return o[f]=d,o[c]=g,t}function O(t,e,r,n,o){this.node=t,this.x0=e,this.y0=r,this.x1=n,this.y1=o}function T(t){return t[0]}function z(t){return t[1]}function L(t,e,r){var n=new P(null==e?T:e,null==r?z:r,NaN,NaN,NaN,NaN);return null==t?n:n.addAll(t)}function P(t,e,r,n,o,i){this._x=t,this._y=e,this._x0=r,this._y0=n,this._x1=o,this._y1=i,this._root=void 0}function q(t){for(var e={data:t.data},r=e;t=t.next;)r=r.next={data:t.data};return e}var j=L.prototype=P.prototype;function V(t){return function(){return t}}function F(t){return 1e-6*(t()-.5)}j.copy=function(){var t,e,r=new P(this._x,this._y,this._x0,this._y0,this._x1,this._y1),n=this._root;if(!n)return r;if(!n.length)return r._root=q(n),r;for(t=[{source:n,target:r._root=new Array(4)}];n=t.pop();)for(var o=0;o<4;++o)(e=n.source[o])&&(e.length?t.push({source:e,target:n.target[o]=new Array(4)}):n.target[o]=q(e));return r},j.add=function(t){const e=+this._x.call(null,t),r=+this._y.call(null,t);return C(this.cover(e,r),e,r,t)},j.addAll=function(t){var e,r,n,o,i=t.length,s=new Array(i),a=new Array(i),u=1/0,h=1/0,l=-1/0,c=-1/0;for(r=0;r<i;++r)isNaN(n=+this._x.call(null,e=t[r]))||isNaN(o=+this._y.call(null,e))||(s[r]=n,a[r]=o,n<u&&(u=n),n>l&&(l=n),o<h&&(h=o),o>c&&(c=o));if(u>l||h>c)return this;for(this.cover(u,h).cover(l,c),r=0;r<i;++r)C(this,s[r],a[r],t[r]);return this},j.cover=function(t,e){if(isNaN(t=+t)||isNaN(e=+e))return this;var r=this._x0,n=this._y0,o=this._x1,i=this._y1;if(isNaN(r))o=(r=Math.floor(t))+1,i=(n=Math.floor(e))+1;else{for(var s,a,u=o-r||1,h=this._root;r>t||t>=o||n>e||e>=i;)switch(a=(e<n)<<1|t<r,(s=new Array(4))[a]=h,h=s,u*=2,a){case 0:o=r+u,i=n+u;break;case 1:r=o-u,i=n+u;break;case 2:o=r+u,n=i-u;break;case 3:r=o-u,n=i-u}this._root&&this._root.length&&(this._root=h)}return this._x0=r,this._y0=n,this._x1=o,this._y1=i,this},j.data=function(){var t=[];return this.visit((function(e){if(!e.length)do{t.push(e.data)}while(e=e.next)})),t},j.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]]},j.find=function(t,e,r){var n,o,i,s,a,u,h,l=this._x0,c=this._y0,f=this._x1,d=this._y1,g=[],p=this._root;for(p&&g.push(new O(p,l,c,f,d)),null==r?r=1/0:(l=t-r,c=e-r,f=t+r,d=e+r,r*=r);u=g.pop();)if(!(!(p=u.node)||(o=u.x0)>f||(i=u.y0)>d||(s=u.x1)<l||(a=u.y1)<c))if(p.length){var m=(o+s)/2,y=(i+a)/2;g.push(new O(p[3],m,y,s,a),new O(p[2],o,y,m,a),new O(p[1],m,i,s,y),new O(p[0],o,i,m,y)),(h=(e>=y)<<1|t>=m)&&(u=g[g.length-1],g[g.length-1]=g[g.length-1-h],g[g.length-1-h]=u)}else{var w=t-+this._x.call(null,p.data),v=e-+this._y.call(null,p.data),x=w*w+v*v;if(x<r){var M=Math.sqrt(r=x);l=t-M,c=e-M,f=t+M,d=e+M,n=p.data}}return n},j.remove=function(t){if(isNaN(i=+this._x.call(null,t))||isNaN(s=+this._y.call(null,t)))return this;var e,r,n,o,i,s,a,u,h,l,c,f,d=this._root,g=this._x0,p=this._y0,m=this._x1,y=this._y1;if(!d)return this;if(d.length)for(;;){if((h=i>=(a=(g+m)/2))?g=a:m=a,(l=s>=(u=(p+y)/2))?p=u:y=u,e=d,!(d=d[c=l<<1|h]))return this;if(!d.length)break;(e[c+1&3]||e[c+2&3]||e[c+3&3])&&(r=e,f=c)}for(;d.data!==t;)if(n=d,!(d=d.next))return this;return(o=d.next)&&delete d.next,n?(o?n.next=o:delete n.next,this):e?(o?e[c]=o:delete e[c],(d=e[0]||e[1]||e[2]||e[3])&&d===(e[3]||e[2]||e[1]||e[0])&&!d.length&&(r?r[f]=d:this._root=d),this):(this._root=o,this)},j.removeAll=function(t){for(var e=0,r=t.length;e<r;++e)this.remove(t[e]);return this},j.root=function(){return this._root},j.size=function(){var t=0;return this.visit((function(e){if(!e.length)do{++t}while(e=e.next)})),t},j.visit=function(t){var e,r,n,o,i,s,a=[],u=this._root;for(u&&a.push(new O(u,this._x0,this._y0,this._x1,this._y1));e=a.pop();)if(!t(u=e.node,n=e.x0,o=e.y0,i=e.x1,s=e.y1)&&u.length){var h=(n+i)/2,l=(o+s)/2;(r=u[3])&&a.push(new O(r,h,l,i,s)),(r=u[2])&&a.push(new O(r,n,l,h,s)),(r=u[1])&&a.push(new O(r,h,o,i,l)),(r=u[0])&&a.push(new O(r,n,o,h,l))}return this},j.visitAfter=function(t){var e,r=[],n=[];for(this._root&&r.push(new O(this._root,this._x0,this._y0,this._x1,this._y1));e=r.pop();){var o=e.node;if(o.length){var i,s=e.x0,a=e.y0,u=e.x1,h=e.y1,l=(s+u)/2,c=(a+h)/2;(i=o[0])&&r.push(new O(i,s,a,l,c)),(i=o[1])&&r.push(new O(i,l,a,u,c)),(i=o[2])&&r.push(new O(i,s,c,l,h)),(i=o[3])&&r.push(new O(i,l,c,u,h))}n.push(e)}for(;e=n.pop();)t(e.node,e.x0,e.y0,e.x1,e.y1);return this},j.x=function(t){return arguments.length?(this._x=t,this):this._x},j.y=function(t){return arguments.length?(this._y=t,this):this._y};var U={value:()=>{}};function G(){for(var t,e=0,r=arguments.length,n={};e<r;++e){if(!(t=arguments[e]+"")||t in n||/[\s.]/.test(t))throw new Error("illegal type: "+t);n[t]=[]}return new B(n)}function B(t){this._=t}function $(t,e){return t.trim().split(/^|\s+/).map((function(t){var r="",n=t.indexOf(".");if(n>=0&&(r=t.slice(n+1),t=t.slice(0,n)),t&&!e.hasOwnProperty(t))throw new Error("unknown type: "+t);return{type:t,name:r}}))}function H(t,e){for(var r,n=0,o=t.length;n<o;++n)if((r=t[n]).name===e)return r.value}function J(t,e,r){for(var n=0,o=t.length;n<o;++n)if(t[n].name===e){t[n]=U,t=t.slice(0,n).concat(t.slice(n+1));break}return null!=r&&t.push({name:e,value:r}),t}B.prototype=G.prototype={constructor:B,on:function(t,e){var r,n=this._,o=$(t+"",n),i=-1,s=o.length;if(!(arguments.length<2)){if(null!=e&&"function"!=typeof e)throw new Error("invalid callback: "+e);for(;++i<s;)if(r=(t=o[i]).type)n[r]=J(n[r],t.name,e);else if(null==e)for(r in n)n[r]=J(n[r],t.name,null);return this}for(;++i<s;)if((r=(t=o[i]).type)&&(r=H(n[r],t.name)))return r},copy:function(){var t={},e=this._;for(var r in e)t[r]=e[r].slice();return new B(t)},call:function(t,e){if((r=arguments.length-2)>0)for(var r,n,o=new Array(r),i=0;i<r;++i)o[i]=arguments[i+2];if(!this._.hasOwnProperty(t))throw new Error("unknown type: "+t);for(i=0,r=(n=this._[t]).length;i<r;++i)n[i].value.apply(e,o)},apply:function(t,e,r){if(!this._.hasOwnProperty(t))throw new Error("unknown type: "+t);for(var n=this._[t],o=0,i=n.length;o<i;++o)n[o].value.apply(e,r)}};const K=G;var W,Y,Z=0,X=0,Q=0,tt=0,et=0,rt=0,nt="object"==typeof performance&&performance.now?performance:Date,ot="object"==typeof window&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(t){setTimeout(t,17)};function it(){return et||(ot(st),et=nt.now()+rt)}function st(){et=0}function at(){this._call=this._time=this._next=null}function ut(t,e,r){var n=new at;return n.restart(t,e,r),n}function ht(){et=(tt=nt.now())+rt,Z=X=0;try{!function(){it(),++Z;for(var t,e=W;e;)(t=et-e._time)>=0&&e._call.call(void 0,t),e=e._next;--Z}()}finally{Z=0,function(){for(var t,e,r=W,n=1/0;r;)r._call?(n>r._time&&(n=r._time),t=r,r=r._next):(e=r._next,r._next=null,r=t?t._next=e:W=e);Y=t,ct(n)}(),et=0}}function lt(){var t=nt.now(),e=t-tt;e>1e3&&(rt-=e,tt=t)}function ct(t){Z||(X&&(X=clearTimeout(X)),t-et>24?(t<1/0&&(X=setTimeout(ht,t-nt.now()-rt)),Q&&(Q=clearInterval(Q))):(Q||(tt=nt.now(),Q=setInterval(lt,1e3)),Z=1,ot(ht)))}at.prototype=ut.prototype={constructor:at,restart:function(t,e,r){if("function"!=typeof t)throw new TypeError("callback is not a function");r=(null==r?it():+r)+(null==e?0:+e),this._next||Y===this||(Y?Y._next=this:W=this,Y=this),this._call=t,this._time=r,ct()},stop:function(){this._call&&(this._call=null,this._time=1/0,ct())}};const ft=4294967296;function dt(t){return t.x}function gt(t){return t.y}var pt=Math.PI*(3-Math.sqrt(5));function mt(t){var e,r=1,n=.001,o=1-Math.pow(n,1/300),i=0,s=.6,a=new Map,u=ut(c),h=K("tick","end"),l=function(){let t=1;return()=>(t=(1664525*t+1013904223)%ft)/ft}();function c(){f(),h.call("tick",e),r<n&&(u.stop(),h.call("end",e))}function f(n){var u,h,l=t.length;void 0===n&&(n=1);for(var c=0;c<n;++c)for(r+=(i-r)*o,a.forEach((function(t){t(r)})),u=0;u<l;++u)null==(h=t[u]).fx?h.x+=h.vx*=s:(h.x=h.fx,h.vx=0),null==h.fy?h.y+=h.vy*=s:(h.y=h.fy,h.vy=0);return e}function d(){for(var e,r=0,n=t.length;r<n;++r){if((e=t[r]).index=r,null!=e.fx&&(e.x=e.fx),null!=e.fy&&(e.y=e.fy),isNaN(e.x)||isNaN(e.y)){var o=10*Math.sqrt(.5+r),i=r*pt;e.x=o*Math.cos(i),e.y=o*Math.sin(i)}(isNaN(e.vx)||isNaN(e.vy))&&(e.vx=e.vy=0)}}function g(e){return e.initialize&&e.initialize(t,l),e}return null==t&&(t=[]),d(),e={tick:f,restart:function(){return u.restart(c),e},stop:function(){return u.stop(),e},nodes:function(r){return arguments.length?(t=r,d(),a.forEach(g),e):t},alpha:function(t){return arguments.length?(r=+t,e):r},alphaMin:function(t){return arguments.length?(n=+t,e):n},alphaDecay:function(t){return arguments.length?(o=+t,e):+o},alphaTarget:function(t){return arguments.length?(i=+t,e):i},velocityDecay:function(t){return arguments.length?(s=1-t,e):1-s},randomSource:function(t){return arguments.length?(l=t,a.forEach(g),e):l},force:function(t,r){return arguments.length>1?(null==r?a.delete(t):a.set(t,g(r)),e):a.get(t)},find:function(e,r,n){var o,i,s,a,u,h=0,l=t.length;for(null==n?n=1/0:n*=n,h=0;h<l;++h)(s=(o=e-(a=t[h]).x)*o+(i=r-a.y)*i)<n&&(u=a,n=s);return u},on:function(t,r){return arguments.length>1?(h.on(t,r),e):h.on(t)}}}function yt(){var t,e,r,n,o,i=V(-30),s=1,a=1/0,u=.81;function h(r){var o,i=t.length,s=L(t,dt,gt).visitAfter(c);for(n=r,o=0;o<i;++o)e=t[o],s.visit(f)}function l(){if(t){var e,r,n=t.length;for(o=new Array(n),e=0;e<n;++e)r=t[e],o[r.index]=+i(r,e,t)}}function c(t){var e,r,n,i,s,a=0,u=0;if(t.length){for(n=i=s=0;s<4;++s)(e=t[s])&&(r=Math.abs(e.value))&&(a+=e.value,u+=r,n+=r*e.x,i+=r*e.y);t.x=n/u,t.y=i/u}else{(e=t).x=e.data.x,e.y=e.data.y;do{a+=o[e.data.index]}while(e=e.next)}t.value=a}function f(t,i,h,l){if(!t.value)return!0;var c=t.x-e.x,f=t.y-e.y,d=l-i,g=c*c+f*f;if(d*d/u<g)return g<a&&(0===c&&(g+=(c=F(r))*c),0===f&&(g+=(f=F(r))*f),g<s&&(g=Math.sqrt(s*g)),e.vx+=c*t.value*n/g,e.vy+=f*t.value*n/g),!0;if(!(t.length||g>=a)){(t.data!==e||t.next)&&(0===c&&(g+=(c=F(r))*c),0===f&&(g+=(f=F(r))*f),g<s&&(g=Math.sqrt(s*g)));do{t.data!==e&&(d=o[t.data.index]*n/g,e.vx+=c*d,e.vy+=f*d)}while(t=t.next)}}return h.initialize=function(e,n){t=e,r=n,l()},h.strength=function(t){return arguments.length?(i="function"==typeof t?t:V(+t),l(),h):i},h.distanceMin=function(t){return arguments.length?(s=t*t,h):Math.sqrt(s)},h.distanceMax=function(t){return arguments.length?(a=t*t,h):Math.sqrt(a)},h.theta=function(t){return arguments.length?(u=t*t,h):Math.sqrt(u)},h}function wt(t){return t.index}function vt(t,e){var r=t.get(e);if(!r)throw new Error("node not found: "+e);return r}function xt(t){var e,r,n,o,i,s,a=wt,u=function(t){return 1/Math.min(o[t.source.index],o[t.target.index])},h=V(30),l=1;function c(n){for(var o=0,a=t.length;o<l;++o)for(var u,h,c,f,d,g,p,m=0;m<a;++m)h=(u=t[m]).source,f=(c=u.target).x+c.vx-h.x-h.vx||F(s),d=c.y+c.vy-h.y-h.vy||F(s),f*=g=((g=Math.sqrt(f*f+d*d))-r[m])/g*n*e[m],d*=g,c.vx-=f*(p=i[m]),c.vy-=d*p,h.vx+=f*(p=1-p),h.vy+=d*p}function f(){if(n){var s,u,h=n.length,l=t.length,c=new Map(n.map(((t,e)=>[a(t,e,n),t])));for(s=0,o=new Array(h);s<l;++s)(u=t[s]).index=s,"object"!=typeof u.source&&(u.source=vt(c,u.source)),"object"!=typeof u.target&&(u.target=vt(c,u.target)),o[u.source.index]=(o[u.source.index]||0)+1,o[u.target.index]=(o[u.target.index]||0)+1;for(s=0,i=new Array(l);s<l;++s)u=t[s],i[s]=o[u.source.index]/(o[u.source.index]+o[u.target.index]);e=new Array(l),d(),r=new Array(l),g()}}function d(){if(n)for(var r=0,o=t.length;r<o;++r)e[r]=+u(t[r],r,t)}function g(){if(n)for(var e=0,o=t.length;e<o;++e)r[e]=+h(t[e],e,t)}return null==t&&(t=[]),c.initialize=function(t,e){n=t,s=e,f()},c.links=function(e){return arguments.length?(t=e,f(),c):t},c.id=function(t){return arguments.length?(a=t,c):a},c.iterations=function(t){return arguments.length?(l=+t,c):l},c.strength=function(t){return arguments.length?(u="function"==typeof t?t:V(+t),d(),c):u},c.distance=function(t){return arguments.length?(h="function"==typeof t?t:V(+t),g(),c):h},c}function Mt(t){return t.x+t.vx}function bt(t){return t.y+t.vy}function Et(t){var e,r,n,o=1,i=1;function s(){for(var t,s,u,h,l,c,f,d=e.length,g=0;g<i;++g)for(s=L(e,Mt,bt).visitAfter(a),t=0;t<d;++t)u=e[t],c=r[u.index],f=c*c,h=u.x+u.vx,l=u.y+u.vy,s.visit(p);function p(t,e,r,i,s){var a=t.data,d=t.r,g=c+d;if(!a)return e>h+g||i<h-g||r>l+g||s<l-g;if(a.index>u.index){var p=h-a.x-a.vx,m=l-a.y-a.vy,y=p*p+m*m;y<g*g&&(0===p&&(y+=(p=F(n))*p),0===m&&(y+=(m=F(n))*m),y=(g-(y=Math.sqrt(y)))/y*o,u.vx+=(p*=y)*(g=(d*=d)/(f+d)),u.vy+=(m*=y)*g,a.vx-=p*(g=1-g),a.vy-=m*g)}}}function a(t){if(t.data)return t.r=r[t.data.index];for(var e=t.r=0;e<4;++e)t[e]&&t[e].r>t.r&&(t.r=t[e].r)}function u(){if(e){var n,o,i=e.length;for(r=new Array(i),n=0;n<i;++n)o=e[n],r[o.index]=+t(o,n,e)}}return"function"!=typeof t&&(t=V(null==t?1:+t)),s.initialize=function(t,r){e=t,n=r,u()},s.iterations=function(t){return arguments.length?(i=+t,s):i},s.strength=function(t){return arguments.length?(o=+t,s):o},s.radius=function(e){return arguments.length?(t="function"==typeof e?e:V(+e),u(),s):t},s}function Nt(t){var e,r,n,o=V(.1);function i(t){for(var o,i=0,s=e.length;i<s;++i)(o=e[i]).vx+=(n[i]-o.x)*r[i]*t}function s(){if(e){var i,s=e.length;for(r=new Array(s),n=new Array(s),i=0;i<s;++i)r[i]=isNaN(n[i]=+t(e[i],i,e))?0:+o(e[i],i,e)}}return"function"!=typeof t&&(t=V(null==t?0:+t)),i.initialize=function(t){e=t,s()},i.strength=function(t){return arguments.length?(o="function"==typeof t?t:V(+t),s(),i):o},i.x=function(e){return arguments.length?(t="function"==typeof e?e:V(+e),s(),i):t},i}function St(t){var e,r,n,o=V(.1);function i(t){for(var o,i=0,s=e.length;i<s;++i)(o=e[i]).vy+=(n[i]-o.y)*r[i]*t}function s(){if(e){var i,s=e.length;for(r=new Array(s),n=new Array(s),i=0;i<s;++i)r[i]=isNaN(n[i]=+t(e[i],i,e))?0:+o(e[i],i,e)}}return"function"!=typeof t&&(t=V(null==t?0:+t)),i.initialize=function(t){e=t,s()},i.strength=function(t){return arguments.length?(o="function"==typeof t?t:V(+t),s(),i):o},i.y=function(e){return arguments.length?(t="function"==typeof e?e:V(+e),s(),i):t},i}function kt(){function t(t){return function(){return t}}var e,r=function(t){return t.cluster},n=t(1),o=t(-1),s=t(100),a=t(.1),u=[0,0],h=[],l={},c=[],f=100,d=100,g={none:{x:0,y:0}},p=[],m="force",y=!0,w=.1;function v(t){if(!y)return v;e.tick(),M();for(var n=0,o=h.length,i=void 0,s=t*w;n<o;++n)(i=h[n]).vx+=(g[r(i)].x-i.x)*s,i.vy+=(g[r(i)].y-i.y)*s}function x(){h&&function(){if(h&&h.length){if(void 0===r(h[0]))throw Error("Couldnt find the grouping attribute for the nodes. Make sure to set it up with forceInBox.groupBy('clusterAttr') before calling .links()");var t,u,g,m,y,w=(t=[],u=[],g={},{},y=[],m=function(t){var e={};return t.forEach((function(t){var n=r(t);e[n]||(e[n]={count:0,sumforceNodeSize:0})})),t.forEach((function(t){var o=r(t),i=n(t),s=e[o];s.count=s.count+1,s.sumforceNodeSize=s.sumforceNodeSize+Math.PI*(i*i)*1.3,e[o]=s})),e}(h),y=function(t){var e={},n=[];return t.forEach((function(t){var n,o,i,s,a,u=(o=(n=t).source,i=n.target,(s=r(l[o]))<=(a=r(l[i]))?"".concat(s,"~").concat(a):"".concat(a,"~").concat(s)),h=0;void 0!==e[u]&&(h=e[u]),h+=1,e[u]=h})),Object.entries(e).forEach((function(t){var e=i(t,2),r=e[0],o=e[1],s=r.split("~")[0],a=r.split("~")[1];void 0!==s&&void 0!==a&&n.push({source:s,target:a,count:o})})),n}(c),Object.keys(m).forEach((function(e,r){var n=m[e];t.push({id:e,size:n.count,r:Math.sqrt(n.sumforceNodeSize/Math.PI)}),g[e]=r})),y.forEach((function(t){var e=t.source,r=t.target,n=g[e],o=g[r];void 0!==n&&void 0!==o&&u.push({source:n,target:o,count:t.count})})),{nodes:t,links:u});e=mt(w.nodes).force("x",Nt(f).strength(.1)).force("y",St(d).strength(.1)).force("collide",Et((function(t){return t.r})).iterations(4)).force("charge",yt().strength(o)).force("links",xt(w.nodes.length?w.links:[]).distance(s).strength(a)),p=e.nodes(),M()}}()}function M(){return g={none:{x:0,y:0}},p.forEach((function(t){g[t.id]={x:t.x-u[0],y:t.y-u[1]}})),g}function b(t){l={},t.forEach((function(t){l[t.id]=t}))}return v.initialize=function(t){h=t,x()},v.template=function(t){return arguments.length?(m=t,x(),v):m},v.groupBy=function(t){return arguments.length?"string"==typeof t?(r=function(e){return e[t]},v):(r=t,v):r},v.enableGrouping=function(t){return arguments.length?(y=t,v):y},v.strength=function(t){return arguments.length?(w=t,v):w},v.centerX=function(t){return arguments.length?(f=t,v):f},v.centerY=function(t){return arguments.length?(d=t,v):d},v.nodes=function(t){return arguments.length?(b(t||[]),h=t||[],v):h},v.links=function(t){return arguments.length?(c=t||[],x(),v):c},v.forceNodeSize=function(e){return arguments.length?(n="function"==typeof e?e:t(+e),x(),v):n},v.nodeSize=v.forceNodeSize,v.forceCharge=function(e){return arguments.length?(o="function"==typeof e?e:t(+e),x(),v):o},v.forceLinkDistance=function(e){return arguments.length?(s="function"==typeof e?e:t(+e),x(),v):s},v.forceLinkStrength=function(e){return arguments.length?(a="function"==typeof e?e:t(+e),x(),v):a},v.offset=function(t){return arguments.length?(u=t,v):u},v.getFocis=M,v}var At={center:[0,0],preventOverlap:!1,nodeSize:void 0,nodeSpacing:void 0,linkDistance:50,forceSimulation:null,alphaDecay:.028,alphaMin:.001,alpha:.3,collideStrength:1,clustering:!1,clusterNodeStrength:-1,clusterEdgeStrength:.1,clusterEdgeDistance:100,clusterFociStrength:.8,clusterNodeSize:10},Rt=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="d3force",this.running=!1,this.options=e(e({},At),t)}return t.prototype.execute=function(t,e){return this.genericForceLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericForceLayout(!0,t,e)},t.prototype.stop=function(){var t;null===(t=this.forceSimulation)||void 0===t||t.stop(),this.running=!1},t.prototype.restart=function(){var t;null===(t=this.forceSimulation)||void 0===t||t.restart(),this.running=!0},t.prototype.tick=function(t){var e=this;void 0===t&&(t=1),this.forceSimulation.tick(t);var r={nodes:It(this.lastLayoutNodes),edges:Dt(this.lastLayoutEdges)};return this.lastAssign&&r.nodes.forEach((function(t){return e.lastGraph.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})})),this.lastOptions.onLayoutEnd&&this.lastOptions.onLayoutEnd(r),r},t.prototype.genericForceLayout=function(t,r,n){var o=this,i=e(e({},this.options),n),s=i.layoutInvisibles,a=r.getAllNodes(),u=r.getAllEdges();s||(a=a.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e})),u=u.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e})));var h=a.map((function(t){var r,n;return e(e({},m(t)),{x:null===(r=t.data)||void 0===r?void 0:r.x,y:null===(n=t.data)||void 0===n?void 0:n.y})})),l=u.map((function(t){return m(t)}));if(this.lastLayoutNodes=h,this.lastLayoutEdges=l,this.lastAssign=t,this.lastGraph=r,this.lastOptions=i,!this.running){var c=i.alphaMin,f=i.alphaDecay,d=i.alpha,g=i.nodeStrength,p=i.edgeStrength,y=i.linkDistance,w=i.clustering,v=i.clusterFociStrength,x=i.clusterEdgeDistance,M=i.clusterEdgeStrength,b=i.clusterNodeStrength,E=i.clusterNodeSize,N=i.collideStrength,S=void 0===N?1:N,k=i.center,A=void 0===k?[0,0]:k,R=i.preventOverlap,I=i.nodeSize,D=i.nodeSpacing,_=i.onTick,C=i.onLayoutEnd,O=i.forceSimulation;if(O)w&&((T=kt()).nodes(h),T.links(l)),O.nodes(h),l&&(L=xt().id((function(t){return t.id})).links(l),p&&L.strength(p),y&&L.distance(y),O.force("link",L)),R&&this.overlapProcess(O,{nodeSize:I,nodeSpacing:D,collideStrength:S}),O.alpha(d).restart(),this.running=!0;else try{var T,z=yt();if(g&&z.strength(g),O=mt().nodes(h),w&&((T=kt()).centerX(A[0]).centerY(A[1]).template("force").strength(v),l&&T.links(l),h&&T.nodes(h),T.forceLinkDistance(x).forceLinkStrength(M).forceCharge(b).forceNodeSize(E),O.force("group",T)),O.force("center",function(t,e){var r,n=1;function o(){var o,i,s=r.length,a=0,u=0;for(o=0;o<s;++o)a+=(i=r[o]).x,u+=i.y;for(a=(a/s-t)*n,u=(u/s-e)*n,o=0;o<s;++o)(i=r[o]).x-=a,i.y-=u}return null==t&&(t=0),null==e&&(e=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.strength=function(t){return arguments.length?(n=+t,o):n},o}(A[0],A[1])).force("charge",z).alpha(d).alphaDecay(f).alphaMin(c),R&&this.overlapProcess(O,{nodeSize:I,nodeSpacing:D,collideStrength:S}),l){var L=xt().id((function(t){return t.id})).links(l);p&&L.strength(p),y&&L.distance(y),O.force("link",L)}O.on("tick",(function(){var e=It(h);null==_||_({nodes:e,edges:Dt(l)}),t&&e.forEach((function(t){return r.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}))})).on("end",(function(){o.running=!1;var e=It(h);null==C||C({nodes:e,edges:Dt(l)}),t&&e.forEach((function(t){return r.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}))})),this.running=!0}catch(t){this.running=!1,console.warn(t)}this.forceSimulation=O;var P=It(h),q=Dt(l);return t&&P.forEach((function(t){return r.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})})),{nodes:P,edges:q}}},t.prototype.overlapProcess=function(t,e){var r,n,o=e.nodeSize,i=e.nodeSpacing,s=e.collideStrength;if(n=l(i)?function(){return i}:y(i)?i:function(){return 0},o)if(y(o))r=function(t){return o(t)+n(t)};else if(h(o)){var a=(o[0]>o[1]?o[0]:o[1])/2;r=function(t){return a+n(t)}}else if(l(o)){var u=o/2;r=function(t){return u+n(t)}}else r=function(){return 10};else r=function(t){return t.size?h(t.size)?(t.size[0]>t.size[1]?t.size[0]:t.size[1])/2+n(t):g(t.size)?(t.size.width>t.size.height?t.size.width:t.size.height)/2+n(t):t.size/2+n(t):10+n(t)};t.force("collisionForce",Et(r).strength(s))},t}(),It=function(t){return t.map((function(t){var r=t.x,n=t.y,i=o(t,["x","y"]);return e(e({},i),{data:e(e({},i.data),{x:r,y:n})})}))},Dt=function(t){return t.map((function(t){var r=t.source,n=t.target,i=o(t,["source","target"]);return e(e({},i),{source:r.id,target:n.id})}))};class _t{nodeMap=new Map;edgeMap=new Map;inEdgesMap=new Map;outEdgesMap=new Map;treeIndices=new Map;changes=[];batchCount=0;onChanged=()=>{};constructor(t){t&&(t.nodes&&this.addNodes(t.nodes),t.edges&&this.addEdges(t.edges),t.tree&&this.addTree(t.tree),t.onChanged&&(this.onChanged=t.onChanged))}batch=t=>{this.batchCount+=1,t(),this.batchCount-=1,this.batchCount||this.commit()};commit(){const t=this.changes;this.changes=[],this.onChanged({graph:this,changes:t})}reduceChanges(t){let e=[];return t.forEach((t=>{switch(t.type){case"NodeRemoved":{let r=!1;e=e.filter((e=>{if("NodeAdded"===e.type){const n=e.value.id===t.value.id;return n&&(r=!0),!n}return"NodeDataUpdated"===e.type?e.id!==t.value.id:"TreeStructureChanged"!==e.type||e.nodeId!==t.value.id})),r||e.push(t);break}case"EdgeRemoved":{let r=!1;e=e.filter((e=>{if("EdgeAdded"===e.type){const n=e.value.id===t.value.id;return n&&(r=!0),!n}return"EdgeDataUpdated"!==e.type&&"EdgeUpdated"!==e.type||e.id!==t.value.id})),r||e.push(t);break}case"NodeDataUpdated":case"EdgeDataUpdated":case"EdgeUpdated":{const r=e.find((e=>e.type===t.type&&e.id===t.id&&e.propertyName===t.propertyName));r?r.newValue=t.newValue:e.push(t);break}case"TreeStructureDetached":e=e.filter((e=>"TreeStructureAttached"===e.type?e.treeKey!==t.treeKey:"TreeStructureChanged"!==e.type||e.treeKey!==t.treeKey)),e.push(t);break;case"TreeStructureChanged":{const r=e.find((e=>"TreeStructureChanged"===e.type&&e.treeKey===t.treeKey&&e.nodeId===t.nodeId));r?r.newParentId=t.newParentId:e.push(t);break}default:e.push(t)}})),e}checkNodeExistence(t){if(!this.hasNode(t))throw new Error("Node not found for id: "+t)}hasNode(t){return this.nodeMap.has(t)}areNeighbors(t,e){return this.checkNodeExistence(t),this.getNeighbors(e).some((e=>e.id===t))}getNode(t){return this.checkNodeExistence(t),this.nodeMap.get(t)}getRelatedEdges(t,e){this.checkNodeExistence(t);const r=this.inEdgesMap.get(t),n=this.outEdgesMap.get(t);if("in"===e)return Array.from(r);if("out"===e)return Array.from(n);const o=new Set([...r,...n]);return Array.from(o)}getDegree(t,e){return this.getRelatedEdges(t,e).length}getSuccessors(t){const e=this.getRelatedEdges(t,"out").map((t=>t.target));return Array.from(new Set(e)).map((t=>this.getNode(t)))}getPredecessors(t){const e=this.getRelatedEdges(t,"in").map((t=>t.source));return Array.from(new Set(e)).map((t=>this.getNode(t)))}getNeighbors(t){const e=this.getPredecessors(t),r=this.getSuccessors(t);return Array.from(new Set([...e,...r]))}doAddNode(t){if(this.hasNode(t.id))throw new Error("Node already exists: "+t.id);this.nodeMap.set(t.id,t),this.inEdgesMap.set(t.id,new Set),this.outEdgesMap.set(t.id,new Set),this.treeIndices.forEach((e=>{e.childrenMap.set(t.id,new Set)})),this.changes.push({type:"NodeAdded",value:t})}addNodes(t){this.batch((()=>{for(const e of t)this.doAddNode(e)}))}addNode(t){this.addNodes([t])}doRemoveNode(t){const e=this.getNode(t),r=this.inEdgesMap.get(t),n=this.outEdgesMap.get(t);r?.forEach((t=>this.doRemoveEdge(t.id))),n?.forEach((t=>this.doRemoveEdge(t.id))),this.nodeMap.delete(t),this.treeIndices.forEach((e=>{e.childrenMap.get(t)?.forEach((t=>{e.parentMap.delete(t.id)})),e.parentMap.delete(t),e.childrenMap.delete(t)})),this.changes.push({type:"NodeRemoved",value:e})}removeNodes(t){this.batch((()=>{t.forEach((t=>this.doRemoveNode(t)))}))}removeNode(t){this.removeNodes([t])}updateNodeDataProperty(t,e,r){const n=this.getNode(t);this.batch((()=>{const o=n.data[e],i=r;n.data[e]=i,this.changes.push({type:"NodeDataUpdated",id:t,propertyName:e,oldValue:o,newValue:i})}))}mergeNodeData(t,e){this.batch((()=>{Object.entries(e).forEach((([e,r])=>{this.updateNodeDataProperty(t,e,r)}))}))}updateNodeData(...t){const e=t[0],r=this.getNode(e);if("string"==typeof t[1])return void this.updateNodeDataProperty(e,t[1],t[2]);let n;if("function"==typeof t[1]){const e=t[1];n=e(r.data)}else"object"==typeof t[1]&&(n=t[1]);this.batch((()=>{const t=r.data,o=n;r.data=n,this.changes.push({type:"NodeDataUpdated",id:e,oldValue:t,newValue:o})}))}checkEdgeExistence(t){if(!this.hasEdge(t))throw new Error("Edge not found for id: "+t)}hasEdge(t){return this.edgeMap.has(t)}getEdge(t){return this.checkEdgeExistence(t),this.edgeMap.get(t)}getEdgeDetail(t){const e=this.getEdge(t);return{edge:e,source:this.getNode(e.source),target:this.getNode(e.target)}}doAddEdge(t){if(this.hasEdge(t.id))throw new Error("Edge already exists: "+t.id);this.checkNodeExistence(t.source),this.checkNodeExistence(t.target),this.edgeMap.set(t.id,t);const e=this.inEdgesMap.get(t.target),r=this.outEdgesMap.get(t.source);e.add(t),r.add(t),this.changes.push({type:"EdgeAdded",value:t})}addEdges(t){this.batch((()=>{for(const e of t)this.doAddEdge(e)}))}addEdge(t){this.addEdges([t])}doRemoveEdge(t){const e=this.getEdge(t),r=this.outEdgesMap.get(e.source),n=this.inEdgesMap.get(e.target);r.delete(e),n.delete(e),this.edgeMap.delete(t),this.changes.push({type:"EdgeRemoved",value:e})}removeEdges(t){this.batch((()=>{t.forEach((t=>this.doRemoveEdge(t)))}))}removeEdge(t){this.removeEdges([t])}updateEdgeSource(t,e){const r=this.getEdge(t);this.checkNodeExistence(e);const n=r.source,o=e;this.outEdgesMap.get(n).delete(r),this.outEdgesMap.get(o).add(r),r.source=e,this.batch((()=>{this.changes.push({type:"EdgeUpdated",id:t,propertyName:"source",oldValue:n,newValue:o})}))}updateEdgeTarget(t,e){const r=this.getEdge(t);this.checkNodeExistence(e);const n=r.target,o=e;this.inEdgesMap.get(n).delete(r),this.inEdgesMap.get(o).add(r),r.target=e,this.batch((()=>{this.changes.push({type:"EdgeUpdated",id:t,propertyName:"target",oldValue:n,newValue:o})}))}updateEdgeDataProperty(t,e,r){const n=this.getEdge(t);this.batch((()=>{const o=n.data[e],i=r;n.data[e]=i,this.changes.push({type:"EdgeDataUpdated",id:t,propertyName:e,oldValue:o,newValue:i})}))}updateEdgeData(...t){const e=t[0],r=this.getEdge(e);if("string"==typeof t[1])return void this.updateEdgeDataProperty(e,t[1],t[2]);let n;if("function"==typeof t[1]){const e=t[1];n=e(r.data)}else"object"==typeof t[1]&&(n=t[1]);this.batch((()=>{const t=r.data,o=n;r.data=n,this.changes.push({type:"EdgeDataUpdated",id:e,oldValue:t,newValue:o})}))}mergeEdgeData(t,e){this.batch((()=>{Object.entries(e).forEach((([e,r])=>{this.updateEdgeDataProperty(t,e,r)}))}))}checkTreeExistence(t){if(!this.treeIndices.has(t))throw new Error("Tree structure not found for treeKey: "+t)}attachTreeStructure(t){this.treeIndices.has(t)||(this.treeIndices.set(t,{parentMap:new Map,childrenMap:new Map}),this.batch((()=>{this.changes.push({type:"TreeStructureAttached",treeKey:t})})))}detachTreeStructure(t){this.checkTreeExistence(t),this.treeIndices.delete(t),this.batch((()=>{this.changes.push({type:"TreeStructureDetached",treeKey:t})}))}addTree(t,e){this.batch((()=>{this.attachTreeStructure(e);const r=[],n=Array.isArray(t)?t:[t];for(;n.length;){const t=n.shift();r.push(t),t.children&&n.push(...t.children)}this.addNodes(r),r.forEach((t=>{t.children?.forEach((r=>{this.setParent(r.id,t.id,e)}))}))}))}getRoots(t){return this.checkTreeExistence(t),this.getAllNodes().filter((e=>!this.getParent(e.id,t)))}getChildren(t,e){this.checkNodeExistence(t),this.checkTreeExistence(e);const r=this.treeIndices.get(e).childrenMap.get(t);return Array.from(r||[])}getParent(t,e){return this.checkNodeExistence(t),this.checkTreeExistence(e),this.treeIndices.get(e).parentMap.get(t)||null}setParent(t,e,r){this.checkTreeExistence(r);const n=this.treeIndices.get(r),o=this.getNode(t),i=n.parentMap.get(t),s=this.getNode(e);n.parentMap.set(t,s),i&&n.childrenMap.get(i.id)?.delete(o);let a=n.childrenMap.get(s.id);a||(a=new Set,n.childrenMap.set(s.id,a)),a.add(o),this.batch((()=>{this.changes.push({type:"TreeStructureChanged",treeKey:r,nodeId:t,oldParentId:i?.id,newParentId:s.id})}))}getAllNodes(){return Array.from(this.nodeMap.values())}getAllEdges(){return Array.from(this.edgeMap.values())}doBFS(t,e,r){for(;t.length;){const n=t.shift();r(n),e.add(n.id),this.getSuccessors(n.id).forEach((r=>{e.has(r.id)||(e.add(r.id),t.push(r))}))}}bfs(t,e){this.doBFS([this.getNode(t)],new Set,e)}doDFS(t,e,r){r(t),e.add(t.id),this.getSuccessors(t.id).forEach((t=>{e.has(t.id)||this.doDFS(t,e,r)}))}dfs(t,e){this.doDFS(this.getNode(t),new Set,e)}clone(){const t=this.getAllNodes().map((t=>({...t,data:{...t.data}}))),e=this.getAllEdges().map((t=>({...t,data:{...t.data}}))),r=new _t({nodes:t,edges:e});return this.treeIndices.forEach((({parentMap:t,childrenMap:e},n)=>{const o=new Map;t.forEach(((t,e)=>{o.set(e,r.getNode(t.id))}));const i=new Map;e.forEach(((t,e)=>{i.set(e,new Set(Array.from(t).map((t=>r.getNode(t.id)))))})),r.treeIndices.set(n,{parentMap:o,childrenMap:i})})),r}toJSON(){return JSON.stringify({nodes:this.getAllNodes(),edges:this.getAllEdges()})}}function Ct(t){var e=0,r=0,n=0;if(t.length){for(var o=0;o<4;o++)(i=t[o])&&i.weight&&(e+=i.weight,r+=i.x*i.weight,n+=i.y*i.weight);t.x=r/e,t.y=n/e,t.weight=e}else{var i=t;t.x=i.data.x,t.y=i.data.y,t.weight=i.data.weight}}var Ot={maxIteration:500,gravity:10,factor:1,edgeStrength:200,nodeStrength:1e3,coulombDisScale:.005,damping:.9,maxSpeed:500,minMovement:.4,interval:.02,linkDistance:200,clusterNodeStrength:20,preventOverlap:!0,distanceThresholdMode:"mean"},Tt=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="force",this.timeInterval=0,this.judgingDistance=0,this.running=!1,this.options=e(e({},Ot),t)}return t.prototype.execute=function(t,e){return this.genericForceLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericForceLayout(!0,t,e)},t.prototype.stop=function(){this.timeInterval&&"undefined"!=typeof window&&window.clearInterval(this.timeInterval),this.running=!1},t.prototype.restart=function(){this.running=!0},t.prototype.tick=function(t){var e=this;if(void 0===t&&(t=this.options.maxIteration||1),this.lastResult)return this.lastResult;for(var r=0;(this.judgingDistance>this.lastOptions.minMovement||r<1)&&r<t;r++)this.runOneStep(this.lastCalcGraph,this.lastGraph,r,this.lastVelMap,this.lastOptions),this.updatePosition(this.lastGraph,this.lastCalcGraph,this.lastVelMap,this.lastOptions);var n={nodes:this.lastLayoutNodes,edges:this.lastLayoutEdges};return this.lastAssign&&n.nodes.forEach((function(t){return e.lastGraph.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})})),this.lastOptions.onLayoutEnd&&this.lastOptions.onLayoutEnd(n),n},t.prototype.genericForceLayout=function(t,r,n){var o=this,i=e(e({},this.options),n),s=r.getAllNodes(),a=r.getAllEdges();i.layoutInvisibles||(s=s.filter((function(t){return t.data.visible||void 0===t.data.visible})),a=a.filter((function(t){return t.data.visible||void 0===t.data.visible})));var u=this.formatOptions(i,r),h=u.width,c=u.height,f=u.nodeSize,d=u.getMass,g=u.nodeStrength,p=u.edgeStrength,m=u.linkDistance,y=s.map((function(t){return e(e({},t),{data:e(e({},t.data),{x:l(t.data.x)?t.data.x:Math.random()*h,y:l(t.data.y)?t.data.y:Math.random()*c,size:f(t)||30,mass:d(t),nodeStrength:g(t)})})})),w=a.map((function(t){return e(e({},t),{data:e(e({},t.data),{edgeStrength:p(t),linkDistance:m(t,r.getNode(t.source),r.getNode(t.target))})})}));if(!(null==s?void 0:s.length))return this.lastResult={nodes:[],edges:a},{nodes:[],edges:a};var v={};s.forEach((function(t,e){v[t.id]={x:0,y:0}}));var x=new _t({nodes:y,edges:w});this.formatCentripetal(u,x);var M=u.maxIteration,b=u.minMovement,E=u.onLayoutEnd,N=u.onTick;if(this.lastLayoutNodes=y,this.lastLayoutEdges=w,this.lastAssign=t,this.lastGraph=r,this.lastCalcGraph=x,this.lastOptions=u,this.lastVelMap=v,"undefined"!=typeof window){var S=0;return this.timeInterval=window.setInterval((function(){s&&o.running&&(o.runOneStep(x,r,S,v,u),o.updatePosition(r,x,v,u),t&&y.forEach((function(t){return r.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})})),null==N||N({nodes:jt(r,y),edges:a}),(++S>=M||o.judgingDistance<b)&&(null==E||E({nodes:jt(r,y),edges:a}),window.clearInterval(o.timeInterval)))}),0),this.running=!0,{nodes:jt(r,y),edges:a}}},t.prototype.formatOptions=function(t,e){var r=t,n=t.width,o=t.height,i=t.getMass;if(r.width=n||"undefined"==typeof window?n:window.innerWidth,r.height=o||"undefined"==typeof window?o:window.innerHeight,t.center||(r.center=[r.width/2,r.height/2]),i||(r.getMass=function(t){var r=1;l(null==t?void 0:t.data.mass)&&(r=null==t?void 0:t.data.mass);var n=e.getDegree(t.id,"both");return!n||n<5?r:5*n*r}),t.preventOverlap){var s=w(0,t.nodeSpacing);t.nodeSize?h(t.nodeSize)?r.nodeSize=function(e){var r=t.nodeSize;return Math.max(r[0],r[1])+s(e)}:r.nodeSize=function(e){return t.nodeSize+s(e)}:r.nodeSize=function(t){var e=((null==t?void 0:t.data)||{}).size;return e?h(e)?Math.max(e[0],e[1])+s(t):g(e)?Math.max(e.width,e.height)+s(t):e+s(t):10+s(t)}}return r.linkDistance=t.linkDistance?w(1,t.linkDistance):function(t){return 1+r.nodeSize(e.getNode(t.source))+r.nodeSize(e.getNode(t.target))},r.nodeStrength=w(1,t.nodeStrength),r.edgeStrength=w(1,t.edgeStrength),t},t.prototype.formatCentripetal=function(t,e){var r,n=t.centripetalOptions,o=t.center,i=t.clusterNodeStrength,s=t.leafCluster,a=t.clustering,u=t.nodeClusterBy,h=e.getAllNodes(),l=n||{leaf:2,single:2,others:1,center:function(t){return{x:o[0],y:o[1]}}};"function"!=typeof i&&(t.clusterNodeStrength=function(t){return i});var c=[];if(s&&u&&(r=zt(e,u),c=Array.from(new Set(null==h?void 0:h.map((function(t){return t.data[u]}))))||[],t.centripetalOptions=Object.assign(l,{single:100,leaf:function(e){var n=r[e.id]||{},o=n.siblingLeaves,i=n.sameTypeLeaves;return(null==i?void 0:i.length)===(null==o?void 0:o.length)||1===(null==c?void 0:c.length)?1:t.clusterNodeStrength(e)},others:1,center:function(t){var n,o=e.getDegree(t.id,"both");if(!o)return{x:100,y:100};if(1===o){var i=(r[t.id]||{}).sameTypeLeaves,s=void 0===i?[]:i;1===s.length?n=void 0:s.length>1&&(n=qt(s))}else n=void 0;return{x:null==n?void 0:n.x,y:null==n?void 0:n.y}}})),a&&u){r||(r=zt(e,u)),c||(c=Array.from(new Set(h.map((function(t){return t.data[u]}))))),c=c.filter((function(t){return void 0!==t}));var f={};c.forEach((function(t){var r=h.filter((function(e){return e.data[u]===t})).map((function(t){return e.getNode(t.id)}));f[t]=qt(r)})),t.centripetalOptions=Object.assign(l,{single:function(e){return t.clusterNodeStrength(e)},leaf:function(e){return t.clusterNodeStrength(e)},others:function(e){return t.clusterNodeStrength(e)},center:function(t){var e=f[t.data[u]];return{x:null==e?void 0:e.x,y:null==e?void 0:e.y}}})}var d=t.centripetalOptions||{},g=d.leaf,p=d.single,m=d.others;g&&"function"!=typeof g&&(t.centripetalOptions.leaf=function(){return g}),p&&"function"!=typeof p&&(t.centripetalOptions.single=function(){return p}),m&&"function"!=typeof m&&(t.centripetalOptions.others=function(){return m})},t.prototype.runOneStep=function(t,e,r,n,o){var i={},s=t.getAllNodes(),a=t.getAllEdges();if(null==s?void 0:s.length){var u=o.monitor;this.calRepulsive(t,i,o),a&&this.calAttractive(t,i),this.calGravity(t,e,i,o),this.updateVelocity(t,i,n,o),u&&u({energy:this.calTotalEnergy(i,s),nodes:e.getAllNodes(),edges:e.getAllEdges(),iterations:r})}},t.prototype.calTotalEnergy=function(t,e){if(!(null==e?void 0:e.length))return 0;var r=0;return e.forEach((function(e,n){var o=t[e.id].x,i=t[e.id].y,s=o*o+i*i,a=e.data.mass;r+=(void 0===a?1:a)*s*.5})),r},t.prototype.calRepulsive=function(t,e,r){var n=r.factor,o=r.coulombDisScale;!function(t,e,r,n){var o=e/r,i=t.getAllNodes(),s=i.map((function(t,e){var r=t.data,n=r.nodeStrength;return{x:r.x,y:r.y,size:r.size,index:e,vx:0,vy:0,weight:o*n}})),a=L(s,(function(t){return t.x}),(function(t){return t.y})).visitAfter(Ct);s.forEach((function(t){!function(t,e){e.visit((function(e,r,n,o,i){return function(t,e,r,n,o,i){var s=i.x-t.x||.1,a=i.y-t.y||.1,u=n-e,h=s*s+a*a,l=Math.sqrt(h)*h;if(u*u*.81<h){var c=t.weight/l;return i.vx+=s*c,i.vy+=a*c,!0}if(t.length)return!1;t.data!==i&&(c=t.data.weight/l,i.vx+=s*c,i.vy+=a*c)}(e,r,0,o,0,t)}))}(t,a)})),s.map((function(t,e){var r=i[e],o=r.id,s=r.data.mass,a=void 0===s?1:s;n[o]={x:t.vx/a,y:t.vy/a}}))}(t,n,o*o,e)},t.prototype.calAttractive=function(t,e){t.getAllEdges().forEach((function(r,n){var o=r.source,i=r.target,s=t.getNode(o),a=t.getNode(i);if(s&&a){var u=a.data.x-s.data.x,h=a.data.y-s.data.y;u||h||(u=.01*Math.random(),h=.01*Math.random());var l=Math.sqrt(u*u+h*h),c=u/l,f=h/l,d=r.data||{},g=d.linkDistance,p=void 0===g?200:g,m=d.edgeStrength,y=(p-l)*(void 0===m?200:m),w=1/(s.data.mass||1),v=1/(a.data.mass||1),x=c*y,M=f*y;e[o].x-=x*w,e[o].y-=M*w,e[i].x+=x*v,e[i].y+=M*v}}))},t.prototype.calGravity=function(t,e,r,n){var o=n.getCenter,s=t.getAllNodes(),a=e.getAllNodes(),u=e.getAllEdges(),h=n.width,c=n.height,f=n.center,d=n.gravity,g=n.centripetalOptions;s&&s.forEach((function(n){var s=n.id,p=n.data,m=p.mass,y=p.x,w=p.y,v=e.getNode(s),x=0,M=0,b=d,E=t.getDegree(s,"in"),N=t.getDegree(s,"out"),S=t.getDegree(s,"both"),k=null==o?void 0:o(v,S);if(k){var A=i(k,3);x=y-A[0],M=w-A[1],b=A[2]}else x=y-f[0],M=w-f[1];if(b&&(r[s].x-=b*x/m,r[s].y-=b*M/m),g){var R=g.leaf,I=g.single,D=g.others,_=g.center,C=(null==_?void 0:_(v,a,u,h,c))||{x:0,y:0,centerStrength:0},O=C.x,T=C.y,z=C.centerStrength;if(!l(O)||!l(T))return;var L=(y-O)/m,P=(w-T)/m;if(z&&(r[s].x-=z*L,r[s].y-=z*P),0===S){var q=I(v);if(!q)return;return r[s].x-=q*L,void(r[s].y-=q*P)}if(0===E||0===N){var j=R(v,a,u);if(!j)return;return r[s].x-=j*L,void(r[s].y-=j*P)}var V=D(v);if(!V)return;r[s].x-=V*L,r[s].y-=V*P}}))},t.prototype.updateVelocity=function(t,e,r,n){var o=n.damping,i=n.maxSpeed,s=n.interval,a=t.getAllNodes();(null==a?void 0:a.length)&&a.forEach((function(t){var n=t.id,a=(r[n].x+e[n].x*s)*o||.01,u=(r[n].y+e[n].y*s)*o||.01,h=Math.sqrt(a*a+u*u);if(h>i){var l=i/h;a*=l,u*=l}r[n]={x:a,y:u}}))},t.prototype.updatePosition=function(t,e,r,n){var o=this,i=n.distanceThresholdMode,s=n.interval,a=e.getAllNodes();if(null==a?void 0:a.length){var u=0;"max"===i?this.judgingDistance=-1/0:"min"===i&&(this.judgingDistance=1/0),a.forEach((function(n){var a=n.id,h=t.getNode(a);if(l(h.data.fx)&&l(h.data.fy))e.mergeNodeData(a,{x:h.data.fx,y:h.data.fy});else{var c=r[a].x*s,f=r[a].y*s;e.mergeNodeData(a,{x:n.data.x+c,y:n.data.y+f});var d=Math.sqrt(c*c+f*f);switch(i){case"max":o.judgingDistance<d&&(o.judgingDistance=d);break;case"min":o.judgingDistance>d&&(o.judgingDistance=d);break;default:u+=d}}})),i&&"mean"!==i||(this.judgingDistance=u/a.length)}else this.judgingDistance=0},t}(),zt=function(t,e){var r=t.getAllNodes();if(!(null==r?void 0:r.length))return{};var n={};return r.forEach((function(r,o){1===t.getDegree(r.id,"both")&&(n[r.id]=Lt(t,"leaf",r,e))})),n},Lt=function(t,e,r,n){var o=t.getDegree(r.id,"in"),i=t.getDegree(r.id,"out"),s=r,a=[];return 0===o?(s=t.getSuccessors(r.id)[0],a=t.getNeighbors(s.id)):0===i&&(s=t.getPredecessors(r.id)[0],a=t.getNeighbors(s.id)),a=a.filter((function(e){return 0===t.getDegree(e.id,"in")||0===t.getDegree(e.id,"out")})),{coreNode:s,siblingLeaves:a,sameTypeLeaves:Pt(t,e,n,r,a)}},Pt=function(t,e,r,n,o){var i=n.data[r]||"",s=(null==o?void 0:o.filter((function(t){return t.data[r]===i})))||[];return"leaf"===e&&(s=s.filter((function(e){return 0===t.getDegree(e.id,"in")||0===t.getDegree(e.id,"out")}))),s},qt=function(t){var e={x:0,y:0};t.forEach((function(t){var r=t.data,n=r.x,o=r.y;e.x+=n||0,e.y+=o||0}));var r=t.length||1;return{x:e.x/r,y:e.y/r}},jt=function(t,r){return r.map((function(r){var n=r.id,o=r.data,i=t.getNode(n);return e(e({},i),{data:e(e({},i.data),{x:o.x,y:o.y})})}))},Vt={maxIteration:1e3,gravity:10,speed:5,clustering:!1,clusterGravity:10,width:300,height:300,nodeClusterBy:"cluster"},Ft=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="fruchterman",this.timeInterval=0,this.running=!1,this.options=e(e({},Vt),t)}return t.prototype.execute=function(t,e){return this.genericFruchtermanLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericFruchtermanLayout(!0,t,e)},t.prototype.stop=function(){this.timeInterval&&"undefined"!=typeof window&&window.clearInterval(this.timeInterval),this.running=!1},t.prototype.restart=function(){this.running=!0},t.prototype.tick=function(t){var e=this;if(void 0===t&&(t=this.options.maxIteration||1),this.lastResult)return this.lastResult;for(var r=0;r<t;r++)this.runOneStep(this.lastGraph,this.lastClusterMap,this.lastOptions);var n={nodes:this.lastLayoutNodes,edges:this.lastLayoutEdges};return this.lastAssign&&n.nodes.forEach((function(t){return e.lastGraph.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})})),this.lastOptions.onLayoutEnd&&this.lastOptions.onLayoutEnd(n),n},t.prototype.genericFruchtermanLayout=function(t,r,n){var o=this;if(!this.running){var i=this.formatOptions(n),s=i.layoutInvisibles,a=i.width,u=i.height,h=i.center,l=i.clustering,c=i.nodeClusterBy,f=i.maxIteration,d=i.onTick,g=i.onLayoutEnd,p=r.getAllNodes(),y=r.getAllEdges();if(s||(p=p.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e})),y=y.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e}))),!(null==p?void 0:p.length)){var w={nodes:[],edges:y};return this.lastResult=w,null==g||g(w),w}if(1===p.length)return t&&r.mergeNodeData(p[0].id,{x:h[0],y:h[1]}),w={nodes:[e(e({},p[0]),{data:e(e({},p[0].data),{x:h[0],y:h[1]})})],edges:y},this.lastResult=w,null==g||g(w),w;var v=p.map((function(t){return m(t,[a,u])})),x=new _t({nodes:v,edges:y}),M={};if(l&&v.forEach((function(t){var e=t.data[c];M[e]||(M[e]={name:e,cx:0,cy:0,count:0})})),this.lastLayoutNodes=v,this.lastLayoutEdges=y,this.lastAssign=t,this.lastGraph=x,this.lastOptions=i,this.lastClusterMap=M,"undefined"!=typeof window){var b=0;return this.timeInterval=window.setInterval((function(){if(o.running&&(o.runOneStep(x,M,i),t&&v.forEach((function(t){var e=t.id,n=t.data;return r.mergeNodeData(e,{x:n.x,y:n.y})})),null==d||d({nodes:v,edges:y}),++b>=f)){try{null==g||g({nodes:v,edges:y})}catch(t){console.warn("onLayoutEnd failed",t)}window.clearInterval(o.timeInterval)}}),0),this.running=!0,{nodes:v,edges:y}}}},t.prototype.formatOptions=function(t){void 0===t&&(t={});var r=e(e({},this.options),t),n=r.clustering,o=r.nodeClusterBy,i=r.center,s=r.width,a=r.height;return r.width=s||"undefined"==typeof window?s:window.innerWidth,r.height=a||"undefined"==typeof window?a:window.innerHeight,r.center=i||[r.width/2,r.height/2],r.clustering=n&&!!o,r},t.prototype.runOneStep=function(t,e,r){var n=r.height,o=r.width,i=r.gravity,s=r.center,a=r.speed,u=r.clustering,h=r.nodeClusterBy,c=r.clusterGravity,f=n*o,d=Math.sqrt(f)/10,g=t.getAllNodes(),p=f/(g.length+1),m=Math.sqrt(p),y={};if(this.applyCalculate(t,y,m,p),u){for(var w in e)e[w].cx=0,e[w].cy=0,e[w].count=0;for(var w in g.forEach((function(t){var r=t.data,n=e[r[h]];l(r.x)&&(n.cx+=r.x),l(r.y)&&(n.cy+=r.y),n.count++})),e)e[w].cx/=e[w].count,e[w].cy/=e[w].count;var v=c||i;g.forEach((function(t,r){var n=t.id,o=t.data;if(l(o.x)&&l(o.y)){var i=e[o[h]],s=Math.sqrt((o.x-i.cx)*(o.x-i.cx)+(o.y-i.cy)*(o.y-i.cy)),a=m*v;y[n].x-=a*(o.x-i.cx)/s,y[n].y-=a*(o.y-i.cy)/s}}))}g.forEach((function(t,e){var r=t.id,n=t.data;if(l(n.x)&&l(n.y)){var o=.01*m*i;y[r].x-=o*(n.x-s[0]),y[r].y-=o*(n.y-s[1])}})),g.forEach((function(e,r){var n=e.id,o=e.data;if(l(o.fx)&&l(o.fy))return o.x=o.fx,void(o.y=o.fy);if(l(o.x)&&l(o.y)){var i=Math.sqrt(y[n].x*y[n].x+y[n].y*y[n].y);if(i>0){var s=Math.min(d*(a/800),i);t.mergeNodeData(n,{x:o.x+y[n].x/i*s,y:o.y+y[n].y/i*s})}}}))},t.prototype.applyCalculate=function(t,e,r,n){this.calRepulsive(t,e,n),this.calAttractive(t,e,r)},t.prototype.calRepulsive=function(t,e,r){var n=t.getAllNodes();n.forEach((function(t,o){var i=t.data,s=t.id;e[s]={x:0,y:0},n.forEach((function(t,n){var a=t.data,u=t.id;if(!(o<=n)&&l(i.x)&&l(a.x)&&l(i.y)&&l(a.y)){var h=i.x-a.x,c=i.y-a.y,f=h*h+c*c;0===f&&(f=1,h=.01,c=.01);var d=r/f,g=h*d,p=c*d;e[s].x+=g,e[s].y+=p,e[u].x-=g,e[u].y-=p}}))}))},t.prototype.calAttractive=function(t,e,r){t.getAllEdges().forEach((function(n){var o=n.source,i=n.target;if(o&&i&&o!==i){var s=t.getNode(o).data,a=t.getNode(i).data;if(l(a.x)&&l(s.x)&&l(a.y)&&l(s.y)){var u=a.x-s.x,h=a.y-s.y,c=Math.sqrt(u*u+h*h)/r,f=u*c,d=h*c;e[o].x+=f,e[o].y+=d,e[i].x-=f,e[i].y-=d}}}))},t}(),Ut={begin:[0,0],preventOverlap:!0,preventOverlapPadding:10,condense:!1,rows:void 0,cols:void 0,position:void 0,sortBy:"degree",nodeSize:30,width:300,height:300},Gt=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="grid",this.options=e(e({},Ut),t)}return t.prototype.execute=function(t,e){return this.genericGridLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericGridLayout(!0,t,e)},t.prototype.genericGridLayout=function(t,r,n){var o=e(e({},this.options),n),i=o.begin,s=void 0===i?[0,0]:i,u=o.condense,c=o.preventOverlapPadding,f=o.preventOverlap,d=o.rows,g=o.cols,p=o.nodeSpacing,y=o.nodeSize,x=o.width,M=o.height,b=o.layoutInvisibles,E=o.onLayoutEnd,N=o.position,S=o.sortBy,k=r.getAllNodes(),A=r.getAllEdges();b||(k=k.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e})),A=A.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e})));var R=k.length;if(0===R){var I={nodes:[],edges:A};return null==E||E(I),I}if(1===R){t&&r.mergeNodeData(k[0].id,{x:s[0],y:s[1]});var D={nodes:[e(e({},k[0]),{data:e(e({},k[0].data),{x:s[0],y:s[1]})})],edges:A};return null==E||E(D),D}var _=k.map((function(t){return m(t)}));"id"===S||a(S)&&void 0!==_[0].data[S]||(S="degree"),"degree"===S?_.sort((function(t,e){return r.getDegree(e.id,"both")-r.getDegree(t.id,"both")})):"id"===S?_.sort((function(t,e){return l(e.id)&&l(t.id)?e.id-t.id:"".concat(t.id).localeCompare("".concat(e.id))})):_.sort((function(t,e){return e.data[S]-t.data[S]}));var C=x||"undefined"==typeof window?x:window.innerWidth,O=M||"undefined"==typeof window?M:window.innerHeight,T=R,z={rows:d,cols:g};if(null!=d&&null!=g)z.rows=d,z.cols=g;else if(null!=d&&null==g)z.rows=d,z.cols=Math.ceil(T/z.rows);else if(null==d&&null!=g)z.cols=g,z.rows=Math.ceil(T/z.cols);else{var L=Math.sqrt(T*O/C);z.rows=Math.round(L),z.cols=Math.round(C/O*L)}if(z.rows=Math.max(z.rows,1),z.cols=Math.max(z.cols,1),z.cols*z.rows>T)((q=Bt(z))-1)*(P=$t(z))>=T?Bt(z,q-1):(P-1)*q>=T&&$t(z,P-1);else for(;z.cols*z.rows<T;){var P,q=Bt(z);((P=$t(z))+1)*q>=T?$t(z,P+1):Bt(z,q+1)}var j=u?0:C/z.cols,V=u?0:O/z.rows;if(f||p){var F=w(10,p),U=v(30,y,!1);_.forEach((function(t){t.data.x&&t.data.y||(t.data.x=0,t.data.y=0);var e,n,o=r.getNode(t.id),i=U(o)||30;h(i)?(e=i[0],n=i[1]):(e=i,n=i);var s=void 0!==F?F(t):c,a=e+s,u=n+s;j=Math.max(j,a),V=Math.max(V,u)}))}for(var G={},B={row:0,col:0},$={},H=0;H<_.length;H++){var J=_[H],K=void 0;if(N&&(K=N(r.getNode(J.id))),K&&(void 0!==K.row||void 0!==K.col)){var W={row:K.row,col:K.col};if(void 0===W.col)for(W.col=0;Ht(G,W);)W.col++;else if(void 0===W.row)for(W.row=0;Ht(G,W);)W.row++;$[J.id]=W,Jt(G,W)}Wt(J,s,j,V,$,z,B,G)}var Y={nodes:_,edges:A};return null==E||E(Y),t&&_.forEach((function(t){r.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})})),Y},t}(),Bt=function(t,e){var r,n=t.rows||5,o=t.cols||5;return null==e?r=Math.min(n,o):Math.min(n,o)===t.rows?t.rows=e:t.cols=e,r},$t=function(t,e){var r,n=t.rows||5,o=t.cols||5;return null==e?r=Math.max(n,o):Math.max(n,o)===t.rows?t.rows=e:t.cols=e,r},Ht=function(t,e){return t["c-".concat(e.row,"-").concat(e.col)]||!1},Jt=function(t,e){return t["c-".concat(e.row,"-").concat(e.col)]=!0},Kt=function(t,e){var r=t.cols||5;e.col++,e.col>=r&&(e.col=0,e.row++)},Wt=function(t,e,r,n,o,i,s,a){var u,h,l=o[t.id];if(l)u=l.col*r+r/2+e[0],h=l.row*n+n/2+e[1];else{for(;Ht(a,s);)Kt(i,s);u=s.col*r+r/2+e[0],h=s.row*n+n/2+e[1],Jt(a,s),Kt(i,s)}t.data.x=u,t.data.y=h};const Yt=Object.prototype.toString;function Zt(t){return Yt.call(t).endsWith("Array]")}function Xt(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!Zt(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");var r=e.fromIndex,n=void 0===r?0:r,o=e.toIndex,i=void 0===o?t.length:o;if(n<0||n>=t.length||!Number.isInteger(n))throw new Error("fromIndex must be a positive integer smaller than length");if(i<=n||i>t.length||!Number.isInteger(i))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var s=t[n],a=n+1;a<i;a++)t[a]>s&&(s=t[a]);return s}function Qt(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!Zt(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");var r=e.fromIndex,n=void 0===r?0:r,o=e.toIndex,i=void 0===o?t.length:o;if(n<0||n>=t.length||!Number.isInteger(n))throw new Error("fromIndex must be a positive integer smaller than length");if(i<=n||i>t.length||!Number.isInteger(i))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var s=t[n],a=n+1;a<i;a++)t[a]<s&&(s=t[a]);return s}function te(t){var e,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!Zt(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");if(void 0!==r.output){if(!Zt(r.output))throw new TypeError("output option must be an array if specified");e=r.output}else e=new Array(t.length);var n=Qt(t),o=Xt(t);if(n===o)throw new RangeError("minimum and maximum input values are equal. Cannot rescale a constant array");var i=r.min,s=void 0===i?r.autoMinMax?n:0:i,a=r.max,u=void 0===a?r.autoMinMax?o:1:a;if(s>=u)throw new RangeError("min option must be smaller than max option");for(var h=(u-s)/(o-n),l=0;l<t.length;l++)e[l]=(t[l]-n)*h+s;return e}const ee=" ".repeat(2),re=" ".repeat(4);function ne(t,e={}){const{maxRows:r=15,maxColumns:n=10,maxNumSize:o=8,padMinus:i="auto"}=e;return`${t.constructor.name} {\n${ee}[\n${re}${function(t,e,r,n,o){const{rows:i,columns:s}=t,a=Math.min(i,e),u=Math.min(s,r),h=[];if("auto"===o){o=!1;t:for(let e=0;e<a;e++)for(let r=0;r<u;r++)if(t.get(e,r)<0){o=!0;break t}}for(let e=0;e<a;e++){let r=[];for(let i=0;i<u;i++)r.push(oe(t.get(e,i),n,o));h.push(`${r.join(" ")}`)}return u!==s&&(h[h.length-1]+=` ... ${s-r} more columns`),a!==i&&h.push(`... ${i-e} more rows`),h.join(`\n${re}`)}(t,r,n,o,i)}\n${ee}]\n${ee}rows: ${t.rows}\n${ee}columns: ${t.columns}\n}`}function oe(t,e,r){return(t>=0&&r?` ${ie(t,e-1)}`:ie(t,e)).padEnd(e)}function ie(t,e){let r=t.toString();if(r.length<=e)return r;let n=t.toFixed(e);if(n.length>e&&(n=t.toFixed(Math.max(0,e-(n.length-e)))),n.length<=e&&!n.startsWith("0.000")&&!n.startsWith("-0.000"))return n;let o=t.toExponential(e);return o.length>e&&(o=t.toExponential(Math.max(0,e-(o.length-e)))),o.slice(0)}function se(t,e,r){let n=r?t.rows:t.rows-1;if(e<0||e>n)throw new RangeError("Row index out of range")}function ae(t,e,r){let n=r?t.columns:t.columns-1;if(e<0||e>n)throw new RangeError("Column index out of range")}function ue(t,e){if(e.to1DArray&&(e=e.to1DArray()),e.length!==t.columns)throw new RangeError("vector size must be the same as the number of columns");return e}function he(t,e){if(e.to1DArray&&(e=e.to1DArray()),e.length!==t.rows)throw new RangeError("vector size must be the same as the number of rows");return e}function le(t,e,r,n,o){if(5!==arguments.length)throw new RangeError("expected 4 arguments");if(fe("startRow",e),fe("endRow",r),fe("startColumn",n),fe("endColumn",o),e>r||n>o||e<0||e>=t.rows||r<0||r>=t.rows||n<0||n>=t.columns||o<0||o>=t.columns)throw new RangeError("Submatrix indices are out of range")}function ce(t,e=0){let r=[];for(let n=0;n<t;n++)r.push(e);return r}function fe(t,e){if("number"!=typeof e)throw new TypeError(`${t} must be a number`)}function de(t){if(t.isEmpty())throw new Error("Empty matrix has no elements to index")}class ge{static from1DArray(t,e,r){if(t*e!==r.length)throw new RangeError("data length does not match given dimensions");let n=new me(t,e);for(let o=0;o<t;o++)for(let t=0;t<e;t++)n.set(o,t,r[o*e+t]);return n}static rowVector(t){let e=new me(1,t.length);for(let r=0;r<t.length;r++)e.set(0,r,t[r]);return e}static columnVector(t){let e=new me(t.length,1);for(let r=0;r<t.length;r++)e.set(r,0,t[r]);return e}static zeros(t,e){return new me(t,e)}static ones(t,e){return new me(t,e).fill(1)}static rand(t,e,r={}){if("object"!=typeof r)throw new TypeError("options must be an object");const{random:n=Math.random}=r;let o=new me(t,e);for(let r=0;r<t;r++)for(let t=0;t<e;t++)o.set(r,t,n());return o}static randInt(t,e,r={}){if("object"!=typeof r)throw new TypeError("options must be an object");const{min:n=0,max:o=1e3,random:i=Math.random}=r;if(!Number.isInteger(n))throw new TypeError("min must be an integer");if(!Number.isInteger(o))throw new TypeError("max must be an integer");if(n>=o)throw new RangeError("min must be smaller than max");let s=o-n,a=new me(t,e);for(let r=0;r<t;r++)for(let t=0;t<e;t++){let e=n+Math.round(i()*s);a.set(r,t,e)}return a}static eye(t,e,r){void 0===e&&(e=t),void 0===r&&(r=1);let n=Math.min(t,e),o=this.zeros(t,e);for(let t=0;t<n;t++)o.set(t,t,r);return o}static diag(t,e,r){let n=t.length;void 0===e&&(e=n),void 0===r&&(r=e);let o=Math.min(n,e,r),i=this.zeros(e,r);for(let e=0;e<o;e++)i.set(e,e,t[e]);return i}static min(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);let r=t.rows,n=t.columns,o=new me(r,n);for(let i=0;i<r;i++)for(let r=0;r<n;r++)o.set(i,r,Math.min(t.get(i,r),e.get(i,r)));return o}static max(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);let r=t.rows,n=t.columns,o=new this(r,n);for(let i=0;i<r;i++)for(let r=0;r<n;r++)o.set(i,r,Math.max(t.get(i,r),e.get(i,r)));return o}static checkMatrix(t){return ge.isMatrix(t)?t:new me(t)}static isMatrix(t){return null!=t&&"Matrix"===t.klass}get size(){return this.rows*this.columns}apply(t){if("function"!=typeof t)throw new TypeError("callback must be a function");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.call(this,e,r);return this}to1DArray(){let t=[];for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.push(this.get(e,r));return t}to2DArray(){let t=[];for(let e=0;e<this.rows;e++){t.push([]);for(let r=0;r<this.columns;r++)t[e].push(this.get(e,r))}return t}toJSON(){return this.to2DArray()}isRowVector(){return 1===this.rows}isColumnVector(){return 1===this.columns}isVector(){return 1===this.rows||1===this.columns}isSquare(){return this.rows===this.columns}isEmpty(){return 0===this.rows||0===this.columns}isSymmetric(){if(this.isSquare()){for(let t=0;t<this.rows;t++)for(let e=0;e<=t;e++)if(this.get(t,e)!==this.get(e,t))return!1;return!0}return!1}isEchelonForm(){let t=0,e=0,r=-1,n=!0,o=!1;for(;t<this.rows&&n;){for(e=0,o=!1;e<this.columns&&!1===o;)0===this.get(t,e)?e++:1===this.get(t,e)&&e>r?(o=!0,r=e):(n=!1,o=!0);t++}return n}isReducedEchelonForm(){let t=0,e=0,r=-1,n=!0,o=!1;for(;t<this.rows&&n;){for(e=0,o=!1;e<this.columns&&!1===o;)0===this.get(t,e)?e++:1===this.get(t,e)&&e>r?(o=!0,r=e):(n=!1,o=!0);for(let r=e+1;r<this.rows;r++)0!==this.get(t,r)&&(n=!1);t++}return n}echelonForm(){let t=this.clone(),e=0,r=0;for(;e<t.rows&&r<t.columns;){let n=e;for(let o=e;o<t.rows;o++)t.get(o,r)>t.get(n,r)&&(n=o);if(0===t.get(n,r))r++;else{t.swapRows(e,n);let o=t.get(e,r);for(let n=r;n<t.columns;n++)t.set(e,n,t.get(e,n)/o);for(let n=e+1;n<t.rows;n++){let o=t.get(n,r)/t.get(e,r);t.set(n,r,0);for(let i=r+1;i<t.columns;i++)t.set(n,i,t.get(n,i)-t.get(e,i)*o)}e++,r++}}return t}reducedEchelonForm(){let t=this.echelonForm(),e=t.columns,r=t.rows,n=r-1;for(;n>=0;)if(0===t.maxRow(n))n--;else{let o=0,i=!1;for(;o<r&&!1===i;)1===t.get(n,o)?i=!0:o++;for(let r=0;r<n;r++){let i=t.get(r,o);for(let s=o;s<e;s++){let e=t.get(r,s)-i*t.get(n,s);t.set(r,s,e)}}n--}return t}set(){throw new Error("set method is unimplemented")}get(){throw new Error("get method is unimplemented")}repeat(t={}){if("object"!=typeof t)throw new TypeError("options must be an object");const{rows:e=1,columns:r=1}=t;if(!Number.isInteger(e)||e<=0)throw new TypeError("rows must be a positive integer");if(!Number.isInteger(r)||r<=0)throw new TypeError("columns must be a positive integer");let n=new me(this.rows*e,this.columns*r);for(let t=0;t<e;t++)for(let e=0;e<r;e++)n.setSubMatrix(this,this.rows*t,this.columns*e);return n}fill(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,t);return this}neg(){return this.mulS(-1)}getRow(t){se(this,t);let e=[];for(let r=0;r<this.columns;r++)e.push(this.get(t,r));return e}getRowVector(t){return me.rowVector(this.getRow(t))}setRow(t,e){se(this,t),e=ue(this,e);for(let r=0;r<this.columns;r++)this.set(t,r,e[r]);return this}swapRows(t,e){se(this,t),se(this,e);for(let r=0;r<this.columns;r++){let n=this.get(t,r);this.set(t,r,this.get(e,r)),this.set(e,r,n)}return this}getColumn(t){ae(this,t);let e=[];for(let r=0;r<this.rows;r++)e.push(this.get(r,t));return e}getColumnVector(t){return me.columnVector(this.getColumn(t))}setColumn(t,e){ae(this,t),e=he(this,e);for(let r=0;r<this.rows;r++)this.set(r,t,e[r]);return this}swapColumns(t,e){ae(this,t),ae(this,e);for(let r=0;r<this.rows;r++){let n=this.get(r,t);this.set(r,t,this.get(r,e)),this.set(r,e,n)}return this}addRowVector(t){t=ue(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t[r]);return this}subRowVector(t){t=ue(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t[r]);return this}mulRowVector(t){t=ue(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t[r]);return this}divRowVector(t){t=ue(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t[r]);return this}addColumnVector(t){t=he(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t[e]);return this}subColumnVector(t){t=he(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t[e]);return this}mulColumnVector(t){t=he(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t[e]);return this}divColumnVector(t){t=he(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t[e]);return this}mulRow(t,e){se(this,t);for(let r=0;r<this.columns;r++)this.set(t,r,this.get(t,r)*e);return this}mulColumn(t,e){ae(this,t);for(let r=0;r<this.rows;r++)this.set(r,t,this.get(r,t)*e);return this}max(t){if(this.isEmpty())return NaN;switch(t){case"row":{const t=new Array(this.rows).fill(Number.NEGATIVE_INFINITY);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)>t[e]&&(t[e]=this.get(e,r));return t}case"column":{const t=new Array(this.columns).fill(Number.NEGATIVE_INFINITY);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)>t[r]&&(t[r]=this.get(e,r));return t}case void 0:{let t=this.get(0,0);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)>t&&(t=this.get(e,r));return t}default:throw new Error(`invalid option: ${t}`)}}maxIndex(){de(this);let t=this.get(0,0),e=[0,0];for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.get(r,n)>t&&(t=this.get(r,n),e[0]=r,e[1]=n);return e}min(t){if(this.isEmpty())return NaN;switch(t){case"row":{const t=new Array(this.rows).fill(Number.POSITIVE_INFINITY);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)<t[e]&&(t[e]=this.get(e,r));return t}case"column":{const t=new Array(this.columns).fill(Number.POSITIVE_INFINITY);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)<t[r]&&(t[r]=this.get(e,r));return t}case void 0:{let t=this.get(0,0);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)<t&&(t=this.get(e,r));return t}default:throw new Error(`invalid option: ${t}`)}}minIndex(){de(this);let t=this.get(0,0),e=[0,0];for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.get(r,n)<t&&(t=this.get(r,n),e[0]=r,e[1]=n);return e}maxRow(t){if(se(this,t),this.isEmpty())return NaN;let e=this.get(t,0);for(let r=1;r<this.columns;r++)this.get(t,r)>e&&(e=this.get(t,r));return e}maxRowIndex(t){se(this,t),de(this);let e=this.get(t,0),r=[t,0];for(let n=1;n<this.columns;n++)this.get(t,n)>e&&(e=this.get(t,n),r[1]=n);return r}minRow(t){if(se(this,t),this.isEmpty())return NaN;let e=this.get(t,0);for(let r=1;r<this.columns;r++)this.get(t,r)<e&&(e=this.get(t,r));return e}minRowIndex(t){se(this,t),de(this);let e=this.get(t,0),r=[t,0];for(let n=1;n<this.columns;n++)this.get(t,n)<e&&(e=this.get(t,n),r[1]=n);return r}maxColumn(t){if(ae(this,t),this.isEmpty())return NaN;let e=this.get(0,t);for(let r=1;r<this.rows;r++)this.get(r,t)>e&&(e=this.get(r,t));return e}maxColumnIndex(t){ae(this,t),de(this);let e=this.get(0,t),r=[0,t];for(let n=1;n<this.rows;n++)this.get(n,t)>e&&(e=this.get(n,t),r[0]=n);return r}minColumn(t){if(ae(this,t),this.isEmpty())return NaN;let e=this.get(0,t);for(let r=1;r<this.rows;r++)this.get(r,t)<e&&(e=this.get(r,t));return e}minColumnIndex(t){ae(this,t),de(this);let e=this.get(0,t),r=[0,t];for(let n=1;n<this.rows;n++)this.get(n,t)<e&&(e=this.get(n,t),r[0]=n);return r}diag(){let t=Math.min(this.rows,this.columns),e=[];for(let r=0;r<t;r++)e.push(this.get(r,r));return e}norm(t="frobenius"){let e=0;if("max"===t)return this.max();if("frobenius"===t){for(let t=0;t<this.rows;t++)for(let r=0;r<this.columns;r++)e+=this.get(t,r)*this.get(t,r);return Math.sqrt(e)}throw new RangeError(`unknown norm type: ${t}`)}cumulativeSum(){let t=0;for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t+=this.get(e,r),this.set(e,r,t);return this}dot(t){ge.isMatrix(t)&&(t=t.to1DArray());let e=this.to1DArray();if(e.length!==t.length)throw new RangeError("vectors do not have the same size");let r=0;for(let n=0;n<e.length;n++)r+=e[n]*t[n];return r}mmul(t){t=me.checkMatrix(t);let e=this.rows,r=this.columns,n=t.columns,o=new me(e,n),i=new Float64Array(r);for(let s=0;s<n;s++){for(let e=0;e<r;e++)i[e]=t.get(e,s);for(let t=0;t<e;t++){let e=0;for(let n=0;n<r;n++)e+=this.get(t,n)*i[n];o.set(t,s,e)}}return o}strassen2x2(t){t=me.checkMatrix(t);let e=new me(2,2);const r=this.get(0,0),n=t.get(0,0),o=this.get(0,1),i=t.get(0,1),s=this.get(1,0),a=t.get(1,0),u=this.get(1,1),h=t.get(1,1),l=(r+u)*(n+h),c=(s+u)*n,f=r*(i-h),d=u*(a-n),g=(r+o)*h,p=l+d-g+(o-u)*(a+h),m=f+g,y=c+d,w=l-c+f+(s-r)*(n+i);return e.set(0,0,p),e.set(0,1,m),e.set(1,0,y),e.set(1,1,w),e}strassen3x3(t){t=me.checkMatrix(t);let e=new me(3,3);const r=this.get(0,0),n=this.get(0,1),o=this.get(0,2),i=this.get(1,0),s=this.get(1,1),a=this.get(1,2),u=this.get(2,0),h=this.get(2,1),l=this.get(2,2),c=t.get(0,0),f=t.get(0,1),d=t.get(0,2),g=t.get(1,0),p=t.get(1,1),m=t.get(1,2),y=t.get(2,0),w=t.get(2,1),v=t.get(2,2),x=(r-i)*(-f+p),M=(-r+i+s)*(c-f+p),b=(i+s)*(-c+f),E=r*c,N=(-r+u+h)*(c-d+m),S=(-r+u)*(d-m),k=(u+h)*(-c+d),A=(-o+h+l)*(p+y-w),R=(o-l)*(p-w),I=o*y,D=(h+l)*(-y+w),_=(-o+s+a)*(m+y-v),C=(o-a)*(m-v),O=(s+a)*(-y+v),T=E+I+n*g,z=(r+n+o-i-s-h-l)*p+M+b+E+A+I+D,L=E+N+k+(r+n+o-s-a-u-h)*m+I+_+O,P=x+s*(-c+f+g-p-m-y+v)+M+E+I+_+C,q=x+M+b+E+a*w,j=I+_+C+O+i*d,V=E+N+S+h*(-c+d+g-p-m-y+w)+A+R+I,F=A+R+I+D+u*f,U=E+N+S+k+l*v;return e.set(0,0,T),e.set(0,1,z),e.set(0,2,L),e.set(1,0,P),e.set(1,1,q),e.set(1,2,j),e.set(2,0,V),e.set(2,1,F),e.set(2,2,U),e}mmulStrassen(t){t=me.checkMatrix(t);let e=this.clone(),r=e.rows,n=e.columns,o=t.rows,i=t.columns;function s(t,e,r){let n=t.rows,o=t.columns;if(n===e&&o===r)return t;{let n=ge.zeros(e,r);return n=n.setSubMatrix(t,0,0),n}}n!==o&&console.warn(`Multiplying ${r} x ${n} and ${o} x ${i} matrix: dimensions do not match.`);let a=Math.max(r,o),u=Math.max(n,i);return e=s(e,a,u),function t(e,r,n,o){if(n<=512||o<=512)return e.mmul(r);n%2==1&&o%2==1?(e=s(e,n+1,o+1),r=s(r,n+1,o+1)):n%2==1?(e=s(e,n+1,o),r=s(r,n+1,o)):o%2==1&&(e=s(e,n,o+1),r=s(r,n,o+1));let i=parseInt(e.rows/2,10),a=parseInt(e.columns/2,10),u=e.subMatrix(0,i-1,0,a-1),h=r.subMatrix(0,i-1,0,a-1),l=e.subMatrix(0,i-1,a,e.columns-1),c=r.subMatrix(0,i-1,a,r.columns-1),f=e.subMatrix(i,e.rows-1,0,a-1),d=r.subMatrix(i,r.rows-1,0,a-1),g=e.subMatrix(i,e.rows-1,a,e.columns-1),p=r.subMatrix(i,r.rows-1,a,r.columns-1),m=t(ge.add(u,g),ge.add(h,p),i,a),y=t(ge.add(f,g),h,i,a),w=t(u,ge.sub(c,p),i,a),v=t(g,ge.sub(d,h),i,a),x=t(ge.add(u,l),p,i,a),M=t(ge.sub(f,u),ge.add(h,c),i,a),b=t(ge.sub(l,g),ge.add(d,p),i,a),E=ge.add(m,v);E.sub(x),E.add(b);let N=ge.add(w,x),S=ge.add(y,v),k=ge.sub(m,y);k.add(w),k.add(M);let A=ge.zeros(2*E.rows,2*E.columns);return A=A.setSubMatrix(E,0,0),A=A.setSubMatrix(N,E.rows,0),A=A.setSubMatrix(S,0,E.columns),A=A.setSubMatrix(k,E.rows,E.columns),A.subMatrix(0,n-1,0,o-1)}(e,t=s(t,a,u),a,u)}scaleRows(t={}){if("object"!=typeof t)throw new TypeError("options must be an object");const{min:e=0,max:r=1}=t;if(!Number.isFinite(e))throw new TypeError("min must be a number");if(!Number.isFinite(r))throw new TypeError("max must be a number");if(e>=r)throw new RangeError("min must be smaller than max");let n=new me(this.rows,this.columns);for(let t=0;t<this.rows;t++){const o=this.getRow(t);o.length>0&&te(o,{min:e,max:r,output:o}),n.setRow(t,o)}return n}scaleColumns(t={}){if("object"!=typeof t)throw new TypeError("options must be an object");const{min:e=0,max:r=1}=t;if(!Number.isFinite(e))throw new TypeError("min must be a number");if(!Number.isFinite(r))throw new TypeError("max must be a number");if(e>=r)throw new RangeError("min must be smaller than max");let n=new me(this.rows,this.columns);for(let t=0;t<this.columns;t++){const o=this.getColumn(t);o.length&&te(o,{min:e,max:r,output:o}),n.setColumn(t,o)}return n}flipRows(){const t=Math.ceil(this.columns/2);for(let e=0;e<this.rows;e++)for(let r=0;r<t;r++){let t=this.get(e,r),n=this.get(e,this.columns-1-r);this.set(e,r,n),this.set(e,this.columns-1-r,t)}return this}flipColumns(){const t=Math.ceil(this.rows/2);for(let e=0;e<this.columns;e++)for(let r=0;r<t;r++){let t=this.get(r,e),n=this.get(this.rows-1-r,e);this.set(r,e,n),this.set(this.rows-1-r,e,t)}return this}kroneckerProduct(t){t=me.checkMatrix(t);let e=this.rows,r=this.columns,n=t.rows,o=t.columns,i=new me(e*n,r*o);for(let s=0;s<e;s++)for(let e=0;e<r;e++)for(let r=0;r<n;r++)for(let a=0;a<o;a++)i.set(n*s+r,o*e+a,this.get(s,e)*t.get(r,a));return i}kroneckerSum(t){if(t=me.checkMatrix(t),!this.isSquare()||!t.isSquare())throw new Error("Kronecker Sum needs two Square Matrices");let e=this.rows,r=t.rows,n=this.kroneckerProduct(me.eye(r,r)),o=me.eye(e,e).kroneckerProduct(t);return n.add(o)}transpose(){let t=new me(this.columns,this.rows);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.set(r,e,this.get(e,r));return t}sortRows(t=pe){for(let e=0;e<this.rows;e++)this.setRow(e,this.getRow(e).sort(t));return this}sortColumns(t=pe){for(let e=0;e<this.columns;e++)this.setColumn(e,this.getColumn(e).sort(t));return this}subMatrix(t,e,r,n){le(this,t,e,r,n);let o=new me(e-t+1,n-r+1);for(let i=t;i<=e;i++)for(let e=r;e<=n;e++)o.set(i-t,e-r,this.get(i,e));return o}subMatrixRow(t,e,r){if(void 0===e&&(e=0),void 0===r&&(r=this.columns-1),e>r||e<0||e>=this.columns||r<0||r>=this.columns)throw new RangeError("Argument out of range");let n=new me(t.length,r-e+1);for(let o=0;o<t.length;o++)for(let i=e;i<=r;i++){if(t[o]<0||t[o]>=this.rows)throw new RangeError(`Row index out of range: ${t[o]}`);n.set(o,i-e,this.get(t[o],i))}return n}subMatrixColumn(t,e,r){if(void 0===e&&(e=0),void 0===r&&(r=this.rows-1),e>r||e<0||e>=this.rows||r<0||r>=this.rows)throw new RangeError("Argument out of range");let n=new me(r-e+1,t.length);for(let o=0;o<t.length;o++)for(let i=e;i<=r;i++){if(t[o]<0||t[o]>=this.columns)throw new RangeError(`Column index out of range: ${t[o]}`);n.set(i-e,o,this.get(i,t[o]))}return n}setSubMatrix(t,e,r){if((t=me.checkMatrix(t)).isEmpty())return this;le(this,e,e+t.rows-1,r,r+t.columns-1);for(let n=0;n<t.rows;n++)for(let o=0;o<t.columns;o++)this.set(e+n,r+o,t.get(n,o));return this}selection(t,e){!function(t,e){if(!Zt(e))throw new TypeError("row indices must be an array");for(let r=0;r<e.length;r++)if(e[r]<0||e[r]>=t.rows)throw new RangeError("row indices are out of range")}(this,t),function(t,e){if(!Zt(e))throw new TypeError("column indices must be an array");for(let r=0;r<e.length;r++)if(e[r]<0||e[r]>=t.columns)throw new RangeError("column indices are out of range")}(this,e);let r=new me(t.length,e.length);for(let n=0;n<t.length;n++){let o=t[n];for(let t=0;t<e.length;t++){let i=e[t];r.set(n,t,this.get(o,i))}}return r}trace(){let t=Math.min(this.rows,this.columns),e=0;for(let r=0;r<t;r++)e+=this.get(r,r);return e}clone(){let t=new me(this.rows,this.columns);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.set(e,r,this.get(e,r));return t}sum(t){switch(t){case"row":return function(t){let e=ce(t.rows);for(let r=0;r<t.rows;++r)for(let n=0;n<t.columns;++n)e[r]+=t.get(r,n);return e}(this);case"column":return function(t){let e=ce(t.columns);for(let r=0;r<t.rows;++r)for(let n=0;n<t.columns;++n)e[n]+=t.get(r,n);return e}(this);case void 0:return function(t){let e=0;for(let r=0;r<t.rows;r++)for(let n=0;n<t.columns;n++)e+=t.get(r,n);return e}(this);default:throw new Error(`invalid option: ${t}`)}}product(t){switch(t){case"row":return function(t){let e=ce(t.rows,1);for(let r=0;r<t.rows;++r)for(let n=0;n<t.columns;++n)e[r]*=t.get(r,n);return e}(this);case"column":return function(t){let e=ce(t.columns,1);for(let r=0;r<t.rows;++r)for(let n=0;n<t.columns;++n)e[n]*=t.get(r,n);return e}(this);case void 0:return function(t){let e=1;for(let r=0;r<t.rows;r++)for(let n=0;n<t.columns;n++)e*=t.get(r,n);return e}(this);default:throw new Error(`invalid option: ${t}`)}}mean(t){const e=this.sum(t);switch(t){case"row":for(let t=0;t<this.rows;t++)e[t]/=this.columns;return e;case"column":for(let t=0;t<this.columns;t++)e[t]/=this.rows;return e;case void 0:return e/this.size;default:throw new Error(`invalid option: ${t}`)}}variance(t,e={}){if("object"==typeof t&&(e=t,t=void 0),"object"!=typeof e)throw new TypeError("options must be an object");const{unbiased:r=!0,mean:n=this.mean(t)}=e;if("boolean"!=typeof r)throw new TypeError("unbiased must be a boolean");switch(t){case"row":if(!Zt(n))throw new TypeError("mean must be an array");return function(t,e,r){const n=t.rows,o=t.columns,i=[];for(let s=0;s<n;s++){let n=0,a=0,u=0;for(let e=0;e<o;e++)u=t.get(s,e)-r[s],n+=u,a+=u*u;e?i.push((a-n*n/o)/(o-1)):i.push((a-n*n/o)/o)}return i}(this,r,n);case"column":if(!Zt(n))throw new TypeError("mean must be an array");return function(t,e,r){const n=t.rows,o=t.columns,i=[];for(let s=0;s<o;s++){let o=0,a=0,u=0;for(let e=0;e<n;e++)u=t.get(e,s)-r[s],o+=u,a+=u*u;e?i.push((a-o*o/n)/(n-1)):i.push((a-o*o/n)/n)}return i}(this,r,n);case void 0:if("number"!=typeof n)throw new TypeError("mean must be a number");return function(t,e,r){const n=t.rows,o=t.columns,i=n*o;let s=0,a=0,u=0;for(let e=0;e<n;e++)for(let n=0;n<o;n++)u=t.get(e,n)-r,s+=u,a+=u*u;return e?(a-s*s/i)/(i-1):(a-s*s/i)/i}(this,r,n);default:throw new Error(`invalid option: ${t}`)}}standardDeviation(t,e){"object"==typeof t&&(e=t,t=void 0);const r=this.variance(t,e);if(void 0===t)return Math.sqrt(r);for(let t=0;t<r.length;t++)r[t]=Math.sqrt(r[t]);return r}center(t,e={}){if("object"==typeof t&&(e=t,t=void 0),"object"!=typeof e)throw new TypeError("options must be an object");const{center:r=this.mean(t)}=e;switch(t){case"row":if(!Zt(r))throw new TypeError("center must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let n=0;n<t.columns;n++)t.set(r,n,t.get(r,n)-e[r])}(this,r),this;case"column":if(!Zt(r))throw new TypeError("center must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let n=0;n<t.columns;n++)t.set(r,n,t.get(r,n)-e[n])}(this,r),this;case void 0:if("number"!=typeof r)throw new TypeError("center must be a number");return function(t,e){for(let r=0;r<t.rows;r++)for(let n=0;n<t.columns;n++)t.set(r,n,t.get(r,n)-e)}(this,r),this;default:throw new Error(`invalid option: ${t}`)}}scale(t,e={}){if("object"==typeof t&&(e=t,t=void 0),"object"!=typeof e)throw new TypeError("options must be an object");let r=e.scale;switch(t){case"row":if(void 0===r)r=function(t){const e=[];for(let r=0;r<t.rows;r++){let n=0;for(let e=0;e<t.columns;e++)n+=Math.pow(t.get(r,e),2)/(t.columns-1);e.push(Math.sqrt(n))}return e}(this);else if(!Zt(r))throw new TypeError("scale must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let n=0;n<t.columns;n++)t.set(r,n,t.get(r,n)/e[r])}(this,r),this;case"column":if(void 0===r)r=function(t){const e=[];for(let r=0;r<t.columns;r++){let n=0;for(let e=0;e<t.rows;e++)n+=Math.pow(t.get(e,r),2)/(t.rows-1);e.push(Math.sqrt(n))}return e}(this);else if(!Zt(r))throw new TypeError("scale must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let n=0;n<t.columns;n++)t.set(r,n,t.get(r,n)/e[n])}(this,r),this;case void 0:if(void 0===r)r=function(t){const e=t.size-1;let r=0;for(let n=0;n<t.columns;n++)for(let o=0;o<t.rows;o++)r+=Math.pow(t.get(o,n),2)/e;return Math.sqrt(r)}(this);else if("number"!=typeof r)throw new TypeError("scale must be a number");return function(t,e){for(let r=0;r<t.rows;r++)for(let n=0;n<t.columns;n++)t.set(r,n,t.get(r,n)/e)}(this,r),this;default:throw new Error(`invalid option: ${t}`)}}toString(t){return ne(this,t)}}function pe(t,e){return t-e}ge.prototype.klass="Matrix","undefined"!=typeof Symbol&&(ge.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return ne(this)}),ge.random=ge.rand,ge.randomInt=ge.randInt,ge.diagonal=ge.diag,ge.prototype.diagonal=ge.prototype.diag,ge.identity=ge.eye,ge.prototype.negate=ge.prototype.neg,ge.prototype.tensorProduct=ge.prototype.kroneckerProduct;class me extends ge{constructor(t,e){if(super(),me.isMatrix(t))return t.clone();if(Number.isInteger(t)&&t>=0){if(this.data=[],!(Number.isInteger(e)&&e>=0))throw new TypeError("nColumns must be a positive integer");for(let r=0;r<t;r++)this.data.push(new Float64Array(e))}else{if(!Zt(t))throw new TypeError("First argument must be a positive number or an array");{const r=t;if("number"!=typeof(e=(t=r.length)?r[0].length:0))throw new TypeError("Data must be a 2D array with at least one element");this.data=[];for(let n=0;n<t;n++){if(r[n].length!==e)throw new RangeError("Inconsistent array dimensions");if(!r[n].every((t=>"number"==typeof t)))throw new TypeError("Input data contains non-numeric values");this.data.push(Float64Array.from(r[n]))}}}this.rows=t,this.columns=e}set(t,e,r){return this.data[t][e]=r,this}get(t,e){return this.data[t][e]}removeRow(t){return se(this,t),this.data.splice(t,1),this.rows-=1,this}addRow(t,e){return void 0===e&&(e=t,t=this.rows),se(this,t,!0),e=Float64Array.from(ue(this,e)),this.data.splice(t,0,e),this.rows+=1,this}removeColumn(t){ae(this,t);for(let e=0;e<this.rows;e++){const r=new Float64Array(this.columns-1);for(let n=0;n<t;n++)r[n]=this.data[e][n];for(let n=t+1;n<this.columns;n++)r[n-1]=this.data[e][n];this.data[e]=r}return this.columns-=1,this}addColumn(t,e){void 0===e&&(e=t,t=this.columns),ae(this,t,!0),e=he(this,e);for(let r=0;r<this.rows;r++){const n=new Float64Array(this.columns+1);let o=0;for(;o<t;o++)n[o]=this.data[r][o];for(n[o++]=e[r];o<this.columns+1;o++)n[o]=this.data[r][o-1];this.data[r]=n}return this.columns+=1,this}}!function(t,e){t.prototype.add=function(t){return"number"==typeof t?this.addS(t):this.addM(t)},t.prototype.addS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t);return this},t.prototype.addM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t.get(e,r));return this},t.add=function(t,r){return new e(t).add(r)},t.prototype.sub=function(t){return"number"==typeof t?this.subS(t):this.subM(t)},t.prototype.subS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t);return this},t.prototype.subM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t.get(e,r));return this},t.sub=function(t,r){return new e(t).sub(r)},t.prototype.subtract=t.prototype.sub,t.prototype.subtractS=t.prototype.subS,t.prototype.subtractM=t.prototype.subM,t.subtract=t.sub,t.prototype.mul=function(t){return"number"==typeof t?this.mulS(t):this.mulM(t)},t.prototype.mulS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t);return this},t.prototype.mulM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t.get(e,r));return this},t.mul=function(t,r){return new e(t).mul(r)},t.prototype.multiply=t.prototype.mul,t.prototype.multiplyS=t.prototype.mulS,t.prototype.multiplyM=t.prototype.mulM,t.multiply=t.mul,t.prototype.div=function(t){return"number"==typeof t?this.divS(t):this.divM(t)},t.prototype.divS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t);return this},t.prototype.divM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t.get(e,r));return this},t.div=function(t,r){return new e(t).div(r)},t.prototype.divide=t.prototype.div,t.prototype.divideS=t.prototype.divS,t.prototype.divideM=t.prototype.divM,t.divide=t.div,t.prototype.mod=function(t){return"number"==typeof t?this.modS(t):this.modM(t)},t.prototype.modS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)%t);return this},t.prototype.modM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)%t.get(e,r));return this},t.mod=function(t,r){return new e(t).mod(r)},t.prototype.modulus=t.prototype.mod,t.prototype.modulusS=t.prototype.modS,t.prototype.modulusM=t.prototype.modM,t.modulus=t.mod,t.prototype.and=function(t){return"number"==typeof t?this.andS(t):this.andM(t)},t.prototype.andS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)&t);return this},t.prototype.andM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)&t.get(e,r));return this},t.and=function(t,r){return new e(t).and(r)},t.prototype.or=function(t){return"number"==typeof t?this.orS(t):this.orM(t)},t.prototype.orS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)|t);return this},t.prototype.orM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)|t.get(e,r));return this},t.or=function(t,r){return new e(t).or(r)},t.prototype.xor=function(t){return"number"==typeof t?this.xorS(t):this.xorM(t)},t.prototype.xorS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)^t);return this},t.prototype.xorM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)^t.get(e,r));return this},t.xor=function(t,r){return new e(t).xor(r)},t.prototype.leftShift=function(t){return"number"==typeof t?this.leftShiftS(t):this.leftShiftM(t)},t.prototype.leftShiftS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)<<t);return this},t.prototype.leftShiftM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)<<t.get(e,r));return this},t.leftShift=function(t,r){return new e(t).leftShift(r)},t.prototype.signPropagatingRightShift=function(t){return"number"==typeof t?this.signPropagatingRightShiftS(t):this.signPropagatingRightShiftM(t)},t.prototype.signPropagatingRightShiftS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>t);return this},t.prototype.signPropagatingRightShiftM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>t.get(e,r));return this},t.signPropagatingRightShift=function(t,r){return new e(t).signPropagatingRightShift(r)},t.prototype.rightShift=function(t){return"number"==typeof t?this.rightShiftS(t):this.rightShiftM(t)},t.prototype.rightShiftS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>>t);return this},t.prototype.rightShiftM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>>t.get(e,r));return this},t.rightShift=function(t,r){return new e(t).rightShift(r)},t.prototype.zeroFillRightShift=t.prototype.rightShift,t.prototype.zeroFillRightShiftS=t.prototype.rightShiftS,t.prototype.zeroFillRightShiftM=t.prototype.rightShiftM,t.zeroFillRightShift=t.rightShift,t.prototype.not=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,~this.get(t,e));return this},t.not=function(t){return new e(t).not()},t.prototype.abs=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.abs(this.get(t,e)));return this},t.abs=function(t){return new e(t).abs()},t.prototype.acos=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.acos(this.get(t,e)));return this},t.acos=function(t){return new e(t).acos()},t.prototype.acosh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.acosh(this.get(t,e)));return this},t.acosh=function(t){return new e(t).acosh()},t.prototype.asin=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.asin(this.get(t,e)));return this},t.asin=function(t){return new e(t).asin()},t.prototype.asinh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.asinh(this.get(t,e)));return this},t.asinh=function(t){return new e(t).asinh()},t.prototype.atan=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.atan(this.get(t,e)));return this},t.atan=function(t){return new e(t).atan()},t.prototype.atanh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.atanh(this.get(t,e)));return this},t.atanh=function(t){return new e(t).atanh()},t.prototype.cbrt=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.cbrt(this.get(t,e)));return this},t.cbrt=function(t){return new e(t).cbrt()},t.prototype.ceil=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.ceil(this.get(t,e)));return this},t.ceil=function(t){return new e(t).ceil()},t.prototype.clz32=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.clz32(this.get(t,e)));return this},t.clz32=function(t){return new e(t).clz32()},t.prototype.cos=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.cos(this.get(t,e)));return this},t.cos=function(t){return new e(t).cos()},t.prototype.cosh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.cosh(this.get(t,e)));return this},t.cosh=function(t){return new e(t).cosh()},t.prototype.exp=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.exp(this.get(t,e)));return this},t.exp=function(t){return new e(t).exp()},t.prototype.expm1=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.expm1(this.get(t,e)));return this},t.expm1=function(t){return new e(t).expm1()},t.prototype.floor=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.floor(this.get(t,e)));return this},t.floor=function(t){return new e(t).floor()},t.prototype.fround=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.fround(this.get(t,e)));return this},t.fround=function(t){return new e(t).fround()},t.prototype.log=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log(this.get(t,e)));return this},t.log=function(t){return new e(t).log()},t.prototype.log1p=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log1p(this.get(t,e)));return this},t.log1p=function(t){return new e(t).log1p()},t.prototype.log10=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log10(this.get(t,e)));return this},t.log10=function(t){return new e(t).log10()},t.prototype.log2=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log2(this.get(t,e)));return this},t.log2=function(t){return new e(t).log2()},t.prototype.round=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.round(this.get(t,e)));return this},t.round=function(t){return new e(t).round()},t.prototype.sign=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sign(this.get(t,e)));return this},t.sign=function(t){return new e(t).sign()},t.prototype.sin=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sin(this.get(t,e)));return this},t.sin=function(t){return new e(t).sin()},t.prototype.sinh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sinh(this.get(t,e)));return this},t.sinh=function(t){return new e(t).sinh()},t.prototype.sqrt=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sqrt(this.get(t,e)));return this},t.sqrt=function(t){return new e(t).sqrt()},t.prototype.tan=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.tan(this.get(t,e)));return this},t.tan=function(t){return new e(t).tan()},t.prototype.tanh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.tanh(this.get(t,e)));return this},t.tanh=function(t){return new e(t).tanh()},t.prototype.trunc=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.trunc(this.get(t,e)));return this},t.trunc=function(t){return new e(t).trunc()},t.pow=function(t,r){return new e(t).pow(r)},t.prototype.pow=function(t){return"number"==typeof t?this.powS(t):this.powM(t)},t.prototype.powS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,Math.pow(this.get(e,r),t));return this},t.prototype.powM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,Math.pow(this.get(e,r),t.get(e,r)));return this}}(ge,me);class ye extends ge{constructor(t){super(),this.data=t,this.rows=t.length,this.columns=t[0].length}set(t,e,r){return this.data[t][e]=r,this}get(t,e){return this.data[t][e]}}function we(t,e){let r=0;return Math.abs(t)>Math.abs(e)?(r=e/t,Math.abs(t)*Math.sqrt(1+r*r)):0!==e?(r=t/e,Math.abs(e)*Math.sqrt(1+r*r)):0}class ve{constructor(t,e={}){if((t=ye.checkMatrix(t)).isEmpty())throw new Error("Matrix must be non-empty");let r=t.rows,n=t.columns;const{computeLeftSingularVectors:o=!0,computeRightSingularVectors:i=!0,autoTranspose:s=!1}=e;let a,u=Boolean(o),h=Boolean(i),l=!1;if(r<n)if(s){a=t.transpose(),r=a.rows,n=a.columns,l=!0;let e=u;u=h,h=e}else a=t.clone(),console.warn("Computing SVD on a matrix with more columns than rows. Consider enabling autoTranspose");else a=t.clone();let c=Math.min(r,n),f=Math.min(r+1,n),d=new Float64Array(f),g=new me(r,c),p=new me(n,n),m=new Float64Array(n),y=new Float64Array(r),w=new Float64Array(f);for(let t=0;t<f;t++)w[t]=t;let v=Math.min(r-1,n),x=Math.max(0,Math.min(n-2,r)),M=Math.max(v,x);for(let t=0;t<M;t++){if(t<v){d[t]=0;for(let e=t;e<r;e++)d[t]=we(d[t],a.get(e,t));if(0!==d[t]){a.get(t,t)<0&&(d[t]=-d[t]);for(let e=t;e<r;e++)a.set(e,t,a.get(e,t)/d[t]);a.set(t,t,a.get(t,t)+1)}d[t]=-d[t]}for(let e=t+1;e<n;e++){if(t<v&&0!==d[t]){let n=0;for(let o=t;o<r;o++)n+=a.get(o,t)*a.get(o,e);n=-n/a.get(t,t);for(let o=t;o<r;o++)a.set(o,e,a.get(o,e)+n*a.get(o,t))}m[e]=a.get(t,e)}if(u&&t<v)for(let e=t;e<r;e++)g.set(e,t,a.get(e,t));if(t<x){m[t]=0;for(let e=t+1;e<n;e++)m[t]=we(m[t],m[e]);if(0!==m[t]){m[t+1]<0&&(m[t]=0-m[t]);for(let e=t+1;e<n;e++)m[e]/=m[t];m[t+1]+=1}if(m[t]=-m[t],t+1<r&&0!==m[t]){for(let e=t+1;e<r;e++)y[e]=0;for(let e=t+1;e<r;e++)for(let r=t+1;r<n;r++)y[e]+=m[r]*a.get(e,r);for(let e=t+1;e<n;e++){let n=-m[e]/m[t+1];for(let o=t+1;o<r;o++)a.set(o,e,a.get(o,e)+n*y[o])}}if(h)for(let e=t+1;e<n;e++)p.set(e,t,m[e])}}let b=Math.min(n,r+1);if(v<n&&(d[v]=a.get(v,v)),r<b&&(d[b-1]=0),x+1<b&&(m[x]=a.get(x,b-1)),m[b-1]=0,u){for(let t=v;t<c;t++){for(let e=0;e<r;e++)g.set(e,t,0);g.set(t,t,1)}for(let t=v-1;t>=0;t--)if(0!==d[t]){for(let e=t+1;e<c;e++){let n=0;for(let o=t;o<r;o++)n+=g.get(o,t)*g.get(o,e);n=-n/g.get(t,t);for(let o=t;o<r;o++)g.set(o,e,g.get(o,e)+n*g.get(o,t))}for(let e=t;e<r;e++)g.set(e,t,-g.get(e,t));g.set(t,t,1+g.get(t,t));for(let e=0;e<t-1;e++)g.set(e,t,0)}else{for(let e=0;e<r;e++)g.set(e,t,0);g.set(t,t,1)}}if(h)for(let t=n-1;t>=0;t--){if(t<x&&0!==m[t])for(let e=t+1;e<n;e++){let r=0;for(let o=t+1;o<n;o++)r+=p.get(o,t)*p.get(o,e);r=-r/p.get(t+1,t);for(let o=t+1;o<n;o++)p.set(o,e,p.get(o,e)+r*p.get(o,t))}for(let e=0;e<n;e++)p.set(e,t,0);p.set(t,t,1)}let E=b-1,N=0,S=Number.EPSILON;for(;b>0;){let t,e;for(t=b-2;t>=-1&&-1!==t;t--){const e=Number.MIN_VALUE+S*Math.abs(d[t]+Math.abs(d[t+1]));if(Math.abs(m[t])<=e||Number.isNaN(m[t])){m[t]=0;break}}if(t===b-2)e=4;else{let r;for(r=b-1;r>=t&&r!==t;r--){let e=(r!==b?Math.abs(m[r]):0)+(r!==t+1?Math.abs(m[r-1]):0);if(Math.abs(d[r])<=S*e){d[r]=0;break}}r===t?e=3:r===b-1?e=1:(e=2,t=r)}switch(t++,e){case 1:{let e=m[b-2];m[b-2]=0;for(let r=b-2;r>=t;r--){let o=we(d[r],e),i=d[r]/o,s=e/o;if(d[r]=o,r!==t&&(e=-s*m[r-1],m[r-1]=i*m[r-1]),h)for(let t=0;t<n;t++)o=i*p.get(t,r)+s*p.get(t,b-1),p.set(t,b-1,-s*p.get(t,r)+i*p.get(t,b-1)),p.set(t,r,o)}break}case 2:{let e=m[t-1];m[t-1]=0;for(let n=t;n<b;n++){let o=we(d[n],e),i=d[n]/o,s=e/o;if(d[n]=o,e=-s*m[n],m[n]=i*m[n],u)for(let e=0;e<r;e++)o=i*g.get(e,n)+s*g.get(e,t-1),g.set(e,t-1,-s*g.get(e,n)+i*g.get(e,t-1)),g.set(e,n,o)}break}case 3:{const e=Math.max(Math.abs(d[b-1]),Math.abs(d[b-2]),Math.abs(m[b-2]),Math.abs(d[t]),Math.abs(m[t])),o=d[b-1]/e,i=d[b-2]/e,s=m[b-2]/e,a=d[t]/e,l=m[t]/e,c=((i+o)*(i-o)+s*s)/2,f=o*s*(o*s);let y=0;0===c&&0===f||(y=c<0?0-Math.sqrt(c*c+f):Math.sqrt(c*c+f),y=f/(c+y));let w=(a+o)*(a-o)+y,v=a*l;for(let e=t;e<b-1;e++){let o=we(w,v);0===o&&(o=Number.MIN_VALUE);let i=w/o,s=v/o;if(e!==t&&(m[e-1]=o),w=i*d[e]+s*m[e],m[e]=i*m[e]-s*d[e],v=s*d[e+1],d[e+1]=i*d[e+1],h)for(let t=0;t<n;t++)o=i*p.get(t,e)+s*p.get(t,e+1),p.set(t,e+1,-s*p.get(t,e)+i*p.get(t,e+1)),p.set(t,e,o);if(o=we(w,v),0===o&&(o=Number.MIN_VALUE),i=w/o,s=v/o,d[e]=o,w=i*m[e]+s*d[e+1],d[e+1]=-s*m[e]+i*d[e+1],v=s*m[e+1],m[e+1]=i*m[e+1],u&&e<r-1)for(let t=0;t<r;t++)o=i*g.get(t,e)+s*g.get(t,e+1),g.set(t,e+1,-s*g.get(t,e)+i*g.get(t,e+1)),g.set(t,e,o)}m[b-2]=w,N+=1;break}case 4:if(d[t]<=0&&(d[t]=d[t]<0?-d[t]:0,h))for(let e=0;e<=E;e++)p.set(e,t,-p.get(e,t));for(;t<E&&!(d[t]>=d[t+1]);){let e=d[t];if(d[t]=d[t+1],d[t+1]=e,h&&t<n-1)for(let r=0;r<n;r++)e=p.get(r,t+1),p.set(r,t+1,p.get(r,t)),p.set(r,t,e);if(u&&t<r-1)for(let n=0;n<r;n++)e=g.get(n,t+1),g.set(n,t+1,g.get(n,t)),g.set(n,t,e);t++}N=0,b--}}if(l){let t=p;p=g,g=t}this.m=r,this.n=n,this.s=d,this.U=g,this.V=p}solve(t){let e=t,r=this.threshold,n=this.s.length,o=me.zeros(n,n);for(let t=0;t<n;t++)Math.abs(this.s[t])<=r?o.set(t,t,0):o.set(t,t,1/this.s[t]);let i=this.U,s=this.rightSingularVectors,a=s.mmul(o),u=s.rows,h=i.rows,l=me.zeros(u,h);for(let t=0;t<u;t++)for(let e=0;e<h;e++){let r=0;for(let o=0;o<n;o++)r+=a.get(t,o)*i.get(e,o);l.set(t,e,r)}return l.mmul(e)}solveForDiagonal(t){return this.solve(me.diag(t))}inverse(){let t=this.V,e=this.threshold,r=t.rows,n=t.columns,o=new me(r,this.s.length);for(let i=0;i<r;i++)for(let r=0;r<n;r++)Math.abs(this.s[r])>e&&o.set(i,r,t.get(i,r)/this.s[r]);let i=this.U,s=i.rows,a=i.columns,u=new me(r,s);for(let t=0;t<r;t++)for(let e=0;e<s;e++){let r=0;for(let n=0;n<a;n++)r+=o.get(t,n)*i.get(e,n);u.set(t,e,r)}return u}get condition(){return this.s[0]/this.s[Math.min(this.m,this.n)-1]}get norm2(){return this.s[0]}get rank(){let t=Math.max(this.m,this.n)*this.s[0]*Number.EPSILON,e=0,r=this.s;for(let n=0,o=r.length;n<o;n++)r[n]>t&&e++;return e}get diagonal(){return Array.from(this.s)}get threshold(){return Number.EPSILON/2*Math.max(this.m,this.n)*this.s[0]}get leftSingularVectors(){return this.U}get rightSingularVectors(){return this.V}get diagonalMatrix(){return me.diag(this.s)}}var xe={center:[0,0],linkDistance:50},Me=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="mds",this.options=e(e({},xe),t)}return t.prototype.execute=function(t,e){return this.genericMDSLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericMDSLayout(!0,t,e)},t.prototype.genericMDSLayout=function(t,r,n){var o=e(e({},this.options),n),i=o.center,s=void 0===i?[0,0]:i,a=o.linkDistance,u=void 0===a?50:a,h=o.layoutInvisibles,l=o.onLayoutEnd,d=r.getAllNodes(),g=r.getAllEdges();if(h||(d=d.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e})),g=g.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e}))),!d||0===d.length){var p={nodes:[],edges:g};return null==l||l(p),p}if(1===d.length){t&&r.mergeNodeData(d[0].id,{x:s[0],y:s[1]});var y={nodes:[e(e({},d[0]),{data:e(e({},d[0].data),{x:s[0],y:s[1]})})],edges:g};return null==l||l(y),y}var w=f({nodes:d,edges:g},!1),v=c(w);be(v);var x=function(t,e){var r=[];return t.forEach((function(t){var n=[];t.forEach((function(t){n.push(t*e)})),r.push(n)})),r}(v,u),M=Ee(x),b=[];M.forEach((function(t,e){var r=m(d[e]);r.data.x=t[0]+s[0],r.data.y=t[1]+s[1],b.push(r)})),t&&b.forEach((function(t){return r.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}));var E={nodes:b,edges:g};return null==l||l(E),E},t}(),be=function(t){var e=-999999;t.forEach((function(t){t.forEach((function(t){t!==1/0&&e<t&&(e=t)}))})),t.forEach((function(r,n){r.forEach((function(r,o){r===1/0&&(t[n][o]=e)}))}))},Ee=function(t){var e=me.mul(me.pow(t,2),-.5),r=e.mean("row"),n=e.mean("column"),o=e.mean();e.add(o).subRowVector(r).subColumnVector(n);var i=new ve(e),s=me.sqrt(i.diagonalMatrix).diagonal();return i.leftSingularVectors.toJSON().map((function(t){return me.mul([t],[s]).toJSON()[0].splice(0,2)}))},Ne={iterations:10,height:10,width:10,speed:100,gravity:10,k:5},Se=function(t,e,r,n,o,i){e.forEach((function(s,a){r[a]={x:0,y:0},e.forEach((function(e,u){if(a!==u&&o[a]===o[u]){var h=s.x-e.x,l=s.y-e.y,c=Math.sqrt(h*h+l*l);if(0===c){c=1;var f=a>u?1:-1;h=.01*f,l=.01*f}if(c<i(t[a])/2+i(t[u])/2){var d=n*n/c;r[a].x+=h/c*d,r[a].y+=l/c*d}}}))}))},ke=function(t,e,r,n,o,i,s,a){var u=i||s/10;return n&&e.forEach((function(e,r){var n=t[r].x-t[o].x,i=t[r].y-t[o].y,s=Math.sqrt(n*n+i*i),a=i/s,u=-n/s,h=Math.sqrt(e.x*e.x+e.y*e.y),l=Math.acos((a*e.x+u*e.y)/h);l>Math.PI/2&&(l-=Math.PI/2,a*=-1,u*=-1);var c=Math.cos(l)*h;e.x=a*c,e.y=u*c})),t.forEach((function(i,s){if(s!==o){var h=Math.sqrt(e[s].x*e[s].x+e[s].y*e[s].y);if(h>0&&s!==o){var l=Math.min(u*(r/800),h);if(i.x+=e[s].x/h*l,i.y+=e[s].y/h*l,n){var c=i.x-t[o].x,f=i.y-t[o].y,d=Math.sqrt(c*c+f*f);c=c/d*a[s],f=f/d*a[s],i.x=t[o].x+c,i.y=t[o].y+f}}}})),t},Ae={maxIteration:1e3,focusNode:null,unitRadius:null,linkDistance:50,preventOverlap:!1,strictRadial:!0,maxPreventOverlapIteration:200,sortStrength:10},Re=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="radial",this.options=e(e({},Ae),t)}return t.prototype.execute=function(t,e){return this.genericRadialLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericRadialLayout(!0,t,e)},t.prototype.genericRadialLayout=function(t,r,n){var o=e(e({},this.options),n),u=o.width,h=o.height,l=o.center,d=o.focusNode,g=o.unitRadius,p=o.nodeSize,y=o.nodeSpacing,w=o.strictRadial,v=o.preventOverlap,x=o.maxPreventOverlapIteration,M=o.sortBy,b=o.linkDistance,E=void 0===b?50:b,N=o.sortStrength,S=void 0===N?10:N,k=o.maxIteration,A=void 0===k?1e3:k,R=o.layoutInvisibles,I=o.onLayoutEnd,D=r.getAllNodes(),_=r.getAllEdges();if(R||(D=D.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e})),_=_.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e}))),!D||0===D.length){var C={nodes:[],edges:_};return null==I||I(C),C}var O=u||"undefined"==typeof window?u:window.innerWidth,T=h||"undefined"==typeof window?h:window.innerHeight,z=l||[O/2,T/2];if(1===D.length){t&&r.mergeNodeData(D[0].id,{x:z[0],y:z[1]});var L={nodes:[e(e({},D[0]),{data:e(e({},D[0].data),{x:z[0],y:z[1]})})],edges:_};return null==I||I(L),L}var P=D[0];if(a(d)){for(var q=0;q<D.length;q++)if(D[q].id===d){P=D[q];break}}else P=d||D[0];var j=_e(D,P.id),V=f({nodes:D,edges:_},!1),F=c(V),U=Oe(F,j);Ce(F,j,U+1);var G=F[j],B=O-z[0]>z[0]?z[0]:O-z[0],$=T-z[1]>z[1]?z[1]:T-z[1];0===B&&(B=O/2),0===$&&($=T/2);var H=Math.min(B,$),J=Math.max.apply(Math,s([],i(G),!1)),K=[],W=g||H/J;G.forEach((function(t,e){K[e]=t*W}));var Y,Z=Ie(D,F,E,K,W,M,S),X=De(Z),Q=function(t,e,r){try{var n=me.mul(me.pow(e,2),-.5),o=n.mean("row"),i=n.mean("column"),s=n.mean();n.add(s).subRowVector(o).subColumnVector(i);var a=new ve(n),u=me.sqrt(a.diagonalMatrix).diagonal();return a.leftSingularVectors.toJSON().map((function(e){return me.mul([e],[u]).toJSON()[0].splice(0,t)}))}catch(t){for(var h=[],l=0;l<e.length;l++){var c=Math.random()*r,f=Math.random()*r;h.push([c,f])}return h}}(E,Z,E),tt=Q.map((function(t){var e=i(t,2),r=e[0],n=e[1];return{x:(isNaN(r)?Math.random()*E:r)-Q[j][0],y:(isNaN(n)?Math.random()*E:n)-Q[j][1]}}));if(this.run(A,tt,X,Z,K,j),v){Y=Te(p,y);var et={nodes:D,nodeSizeFunc:Y,positions:tt,radii:K,height:T,width:O,strictRadial:Boolean(w),focusIdx:j,iterations:x||200,k:tt.length/4.5};tt=function(t,r){for(var n=e(e({},Ne),r),o=n.positions,i=n.iterations,s=n.width,a=n.k,u=n.speed,h=void 0===u?100:u,l=n.strictRadial,c=n.focusIdx,f=n.radii,d=void 0===f?[]:f,g=n.nodeSizeFunc,p=t.getAllNodes(),m=[],y=s/10,w=0;w<i;w++)o.forEach((function(t,e){m[e]={x:0,y:0}})),Se(p,o,m,a,d,g),ke(o,m,h,l,c,y,s,d);return o}(r,et)}var rt=[];tt.forEach((function(t,e){var r=m(D[e]);r.data.x=t.x+z[0],r.data.y=t.y+z[1],rt.push(r)})),t&&rt.forEach((function(t){return r.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}));var nt={nodes:rt,edges:_};return null==I||I(nt),nt},t.prototype.run=function(t,e,r,n,o,i){for(var s=0;s<=t;s++){var a=s/t;this.oneIteration(a,e,o,n,r,i)}},t.prototype.oneIteration=function(t,e,r,n,o,i){var s=1-t;e.forEach((function(a,u){var h=d(a,{x:0,y:0}),l=0===h?0:1/h;if(u!==i){var c=0,f=0,g=0;e.forEach((function(t,e){if(u!==e){var r=d(a,t),i=0===r?0:1/r,s=n[e][u];g+=o[u][e],c+=o[u][e]*(t.x+s*(a.x-t.x)*i),f+=o[u][e]*(t.y+s*(a.y-t.y)*i)}}));var p=0===r[u]?0:1/r[u];g*=s,g+=t*p*p,c*=s,c+=t*p*a.x*l,a.x=c/g,f*=s,f+=t*p*a.y*l,a.y=f/g}}))},t}(),Ie=function(t,e,r,n,o,i,s){if(!t)return[];var u=[];if(e){var h={};e.forEach((function(e,l){var c=[];e.forEach((function(e,u){var f,d;if(l===u)c.push(0);else if(n[l]===n[u])if("data"===i)c.push(e*(Math.abs(l-u)*s)/(n[l]/o));else if(i){var g=void 0,p=void 0;if(h[t[l].id])g=h[t[l].id];else{var m=("id"===i?t[l].id:null===(f=t[l].data)||void 0===f?void 0:f[i])||0;g=a(m)?m.charCodeAt(0):m,h[t[l].id]=g}h[t[u].id]?p=h[t[u].id]:(m=("id"===i?t[u].id:null===(d=t[u].data)||void 0===d?void 0:d[i])||0,p=a(m)?m.charCodeAt(0):m,h[t[u].id]=p),c.push(e*(Math.abs(g-p)*s)/(n[l]/o))}else c.push(e*r/(n[l]/o));else{var y=(r+o)/2;c.push(e*y)}})),u.push(c)}))}return u},De=function(t){for(var e=t.length,r=t[0].length,n=[],o=0;o<e;o++){for(var i=[],s=0;s<r;s++)0!==t[o][s]?i.push(1/(t[o][s]*t[o][s])):i.push(0);n.push(i)}return n},_e=function(t,e){var r=-1;return t.forEach((function(t,n){t.id===e&&(r=n)})),Math.max(r,0)},Ce=function(t,e,r){for(var n=t.length,o=0;o<n;o++)if(t[e][o]===1/0){t[e][o]=r,t[o][e]=r;for(var i=0;i<n;i++)t[o][i]!==1/0&&t[e][i]===1/0&&(t[e][i]=r+t[o][i],t[i][e]=r+t[o][i])}for(o=0;o<n;o++)if(o!==e)for(i=0;i<n;i++)if(t[o][i]===1/0){var s=Math.abs(t[e][o]-t[e][i]);s=0===s?1:s,t[o][i]=s}},Oe=function(t,e){for(var r=0,n=0;n<t[e].length;n++)t[e][n]!==1/0&&(r=t[e][n]>r?t[e][n]:r);return r},Te=function(t,e){var r;return r=l(e)?function(){return e}:y(e)?e:function(){return 0},t?h(t)?function(e){return(t[0]>t[1]?t[0]:t[1])+r(e)}:function(e){return t+r(e)}:function(t){var e,n;return(null===(e=t.data)||void 0===e?void 0:e.bboxSize)?Math.max(t.data.bboxSize[0],t.data.bboxSize[1])+r(t):(null===(n=t.data)||void 0===n?void 0:n.size)?h(t.data.size)?Math.max(t.data.size[0],t.data.size[1])+r(t):g(t.data.size)?(t.data.size.width>t.data.size.height?t.data.size.width:t.data.size.height)+r(t):t.data.size+r(t):10+r(t)}},ze={center:[0,0],width:300,height:300},Le=function(){function t(t){void 0===t&&(t={}),this.options=t,this.id="random",this.options=e(e({},ze),t)}return t.prototype.execute=function(t,e){return this.genericRandomLayout(!1,t,e)},t.prototype.assign=function(t,e){this.genericRandomLayout(!0,t,e)},t.prototype.genericRandomLayout=function(t,r,n){var o=e(e({},this.options),n),i=o.center,s=o.width,a=o.height,u=o.layoutInvisibles,h=o.onLayoutEnd,l=r.getAllNodes();u||(l=l.filter((function(t){var e=(t.data||{}).visible;return e||void 0===e})));var c=s||"undefined"==typeof window?s:window.innerWidth,f=a||"undefined"==typeof window?a:window.innerHeight,d=i||[c/2,f/2],g=[];l&&l.forEach((function(t){g.push({id:t.id,data:{x:.9*(Math.random()-.5)*c+d[0],y:.9*(Math.random()-.5)*f+d[1]}})})),t&&g.forEach((function(t){return r.mergeNodeData(t.id,{x:t.data.x,y:t.data.y})}));var p={nodes:g,edges:r.getAllEdges()};return null==h||h(p),p},t}(),Pe={circular:M,concentric:_,mds:Me,random:Le,grid:Gt,radial:Re,force:Tt,d3force:Rt,fruchterman:Ft};function qe(t,e){Pe[t]=e}})();var o=n.SB,i=n.W1,s=n.jA,a=n.y7,u=n.O2,h=n.Me,l=n.AI,c=n.D4,f=n._5,d=n.y9,g=n.Xp,p=n.qR,m=n.i_;export{o as CircularLayout,i as ConcentricLayout,s as D3ForceLayout,a as ForceLayout,u as FruchtermanLayout,h as GridLayout,l as MDSLayout,c as RadialLayout,f as RandomLayout,d as Supervisor,g as SupervisorEvent,p as registerLayout,m as registry};
|
|
2
2
|
//# sourceMappingURL=index.esm.js.map
|