@unson/brainbase-mcp 0.9.0 → 0.10.1
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/local-web-host.js +6 -0
- package/package.json +12 -4
- package/ui/graph-projects-view.css +66 -0
- package/ui/graph-projects-view.js +126 -10
- package/ui/project-graph-entry.js +293 -0
- package/ui/project-graph-vendor.LICENSE.txt +109 -0
- package/ui/project-graph-vendor.js +312 -0
- package/ui/project-graph.js +358 -0
- package/ui/project-workspace.css +491 -0
- package/ui/project-workspace.js +727 -0
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
var zi=Object.create;var xt=Object.defineProperty;var Bi=Object.getOwnPropertyDescriptor;var Hi=Object.getOwnPropertyNames;var Wi=Object.getPrototypeOf,ji=Object.prototype.hasOwnProperty;var Tt=(n,i)=>()=>{try{return i||n((i={exports:{}}).exports,i),i.exports}catch(t){throw i=0,t}};var Vi=(n,i,t,e)=>{if(i&&typeof i=="object"||typeof i=="function")for(let r of Hi(i))!ji.call(n,r)&&r!==t&&xt(n,r,{get:()=>i[r],enumerable:!(e=Bi(i,r))||e.enumerable});return n};var be=(n,i,t)=>(t=n!=null?zi(Wi(n)):{},Vi(i||!n||!n.__esModule?xt(t,"default",{value:n,enumerable:!0}):t,n));var Fe=Tt((Ta,ct)=>{"use strict";var fe=typeof Reflect=="object"?Reflect:null,Xt=fe&&typeof fe.apply=="function"?fe.apply:function(i,t,e){return Function.prototype.apply.call(i,t,e)},Ne;fe&&typeof fe.ownKeys=="function"?Ne=fe.ownKeys:Object.getOwnPropertySymbols?Ne=function(i){return Object.getOwnPropertyNames(i).concat(Object.getOwnPropertySymbols(i))}:Ne=function(i){return Object.getOwnPropertyNames(i)};function Dr(n){console&&console.warn&&console.warn(n)}var Qt=Number.isNaN||function(i){return i!==i};function C(){C.init.call(this)}ct.exports=C;ct.exports.once=Pr;C.EventEmitter=C;C.prototype._events=void 0;C.prototype._eventsCount=0;C.prototype._maxListeners=void 0;var Jt=10;function Ge(n){if(typeof n!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof n)}Object.defineProperty(C,"defaultMaxListeners",{enumerable:!0,get:function(){return Jt},set:function(n){if(typeof n!="number"||n<0||Qt(n))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+n+".");Jt=n}});C.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0};C.prototype.setMaxListeners=function(i){if(typeof i!="number"||i<0||Qt(i))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+i+".");return this._maxListeners=i,this};function ei(n){return n._maxListeners===void 0?C.defaultMaxListeners:n._maxListeners}C.prototype.getMaxListeners=function(){return ei(this)};C.prototype.emit=function(i){for(var t=[],e=1;e<arguments.length;e++)t.push(arguments[e]);var r=i==="error",a=this._events;if(a!==void 0)r=r&&a.error===void 0;else if(!r)return!1;if(r){var o;if(t.length>0&&(o=t[0]),o instanceof Error)throw o;var s=new Error("Unhandled error."+(o?" ("+o.message+")":""));throw s.context=o,s}var u=a[i];if(u===void 0)return!1;if(typeof u=="function")Xt(u,this,t);else for(var h=u.length,d=ai(u,h),e=0;e<h;++e)Xt(d[e],this,t);return!0};function ti(n,i,t,e){var r,a,o;if(Ge(t),a=n._events,a===void 0?(a=n._events=Object.create(null),n._eventsCount=0):(a.newListener!==void 0&&(n.emit("newListener",i,t.listener?t.listener:t),a=n._events),o=a[i]),o===void 0)o=a[i]=t,++n._eventsCount;else if(typeof o=="function"?o=a[i]=e?[t,o]:[o,t]:e?o.unshift(t):o.push(t),r=ei(n),r>0&&o.length>r&&!o.warned){o.warned=!0;var s=new Error("Possible EventEmitter memory leak detected. "+o.length+" "+String(i)+" listeners added. Use emitter.setMaxListeners() to increase limit");s.name="MaxListenersExceededWarning",s.emitter=n,s.type=i,s.count=o.length,Dr(s)}return n}C.prototype.addListener=function(i,t){return ti(this,i,t,!1)};C.prototype.on=C.prototype.addListener;C.prototype.prependListener=function(i,t){return ti(this,i,t,!0)};function Nr(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function ii(n,i,t){var e={fired:!1,wrapFn:void 0,target:n,type:i,listener:t},r=Nr.bind(e);return r.listener=t,e.wrapFn=r,r}C.prototype.once=function(i,t){return Ge(t),this.on(i,ii(this,i,t)),this};C.prototype.prependOnceListener=function(i,t){return Ge(t),this.prependListener(i,ii(this,i,t)),this};C.prototype.removeListener=function(i,t){var e,r,a,o,s;if(Ge(t),r=this._events,r===void 0)return this;if(e=r[i],e===void 0)return this;if(e===t||e.listener===t)--this._eventsCount===0?this._events=Object.create(null):(delete r[i],r.removeListener&&this.emit("removeListener",i,e.listener||t));else if(typeof e!="function"){for(a=-1,o=e.length-1;o>=0;o--)if(e[o]===t||e[o].listener===t){s=e[o].listener,a=o;break}if(a<0)return this;a===0?e.shift():Gr(e,a),e.length===1&&(r[i]=e[0]),r.removeListener!==void 0&&this.emit("removeListener",i,s||t)}return this};C.prototype.off=C.prototype.removeListener;C.prototype.removeAllListeners=function(i){var t,e,r;if(e=this._events,e===void 0)return this;if(e.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):e[i]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete e[i]),this;if(arguments.length===0){var a=Object.keys(e),o;for(r=0;r<a.length;++r)o=a[r],o!=="removeListener"&&this.removeAllListeners(o);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if(t=e[i],typeof t=="function")this.removeListener(i,t);else if(t!==void 0)for(r=t.length-1;r>=0;r--)this.removeListener(i,t[r]);return this};function ri(n,i,t){var e=n._events;if(e===void 0)return[];var r=e[i];return r===void 0?[]:typeof r=="function"?t?[r.listener||r]:[r]:t?Fr(r):ai(r,r.length)}C.prototype.listeners=function(i){return ri(this,i,!0)};C.prototype.rawListeners=function(i){return ri(this,i,!1)};C.listenerCount=function(n,i){return typeof n.listenerCount=="function"?n.listenerCount(i):ni.call(n,i)};C.prototype.listenerCount=ni;function ni(n){var i=this._events;if(i!==void 0){var t=i[n];if(typeof t=="function")return 1;if(t!==void 0)return t.length}return 0}C.prototype.eventNames=function(){return this._eventsCount>0?Ne(this._events):[]};function ai(n,i){for(var t=new Array(i),e=0;e<i;++e)t[e]=n[e];return t}function Gr(n,i){for(;i+1<n.length;i++)n[i]=n[i+1];n.pop()}function Fr(n){for(var i=new Array(n.length),t=0;t<i.length;++t)i[t]=n[t].listener||n[t];return i}function Pr(n,i){return new Promise(function(t,e){function r(o){n.removeListener(i,a),e(o)}function a(){typeof n.removeListener=="function"&&n.removeListener("error",r),t([].slice.call(arguments))}oi(n,i,a,{once:!0}),i!=="error"&&Ir(n,r,{once:!0})})}function Ir(n,i,t){typeof n.on=="function"&&oi(n,"error",i,t)}function oi(n,i,t,e){if(typeof n.on=="function")e.once?n.once(i,t):n.on(i,t);else if(typeof n.addEventListener=="function")n.addEventListener(i,function r(a){e.once&&n.removeEventListener(i,r),t(a)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof n)}});var lt=Tt((Ca,ui)=>{ui.exports=function(i){return i!==null&&typeof i=="object"&&typeof i.addUndirectedEdgeWithKey=="function"&&typeof i.dropNode=="function"&&typeof i.multi=="boolean"}});function Ki(n,i){if(typeof n!="object"||!n)return n;var t=n[Symbol.toPrimitive];if(t!==void 0){var e=t.call(n,i||"default");if(typeof e!="object")return e;throw new TypeError("@@toPrimitive must return a primitive value.")}return(i==="string"?String:Number)(n)}function ue(n){var i=Ki(n,"string");return typeof i=="symbol"?i:i+""}function D(n,i){if(!(n instanceof i))throw new TypeError("Cannot call a class as a function")}function At(n,i){for(var t=0;t<i.length;t++){var e=i[t];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(n,ue(e.key),e)}}function N(n,i,t){return i&&At(n.prototype,i),t&&At(n,t),Object.defineProperty(n,"prototype",{writable:!1}),n}function se(n){return se=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(i){return i.__proto__||Object.getPrototypeOf(i)},se(n)}function St(){try{var n=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch{}return(St=function(){return!!n})()}function Yi(n){if(n===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return n}function qi(n,i){if(i&&(typeof i=="object"||typeof i=="function"))return i;if(i!==void 0)throw new TypeError("Derived constructors may only return object or undefined");return Yi(n)}function P(n,i,t){return i=se(i),qi(n,St()?Reflect.construct(i,t||[],se(n).constructor):i.apply(n,t))}function Je(n,i){return Je=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},Je(n,i)}function I(n,i){if(typeof i!="function"&&i!==null)throw new TypeError("Super expression must either be null or a function");n.prototype=Object.create(i&&i.prototype,{constructor:{value:n,writable:!0,configurable:!0}}),Object.defineProperty(n,"prototype",{writable:!1}),i&&Je(n,i)}function Zi(n){if(Array.isArray(n))return n}function Xi(n,i){var t=n==null?null:typeof Symbol<"u"&&n[Symbol.iterator]||n["@@iterator"];if(t!=null){var e,r,a,o,s=[],u=!0,h=!1;try{if(a=(t=t.call(n)).next,i===0){if(Object(t)!==t)return;u=!1}else for(;!(u=(e=a.call(t)).done)&&(s.push(e.value),s.length!==i);u=!0);}catch(d){h=!0,r=d}finally{try{if(!u&&t.return!=null&&(o=t.return(),Object(o)!==o))return}finally{if(h)throw r}}return s}}function Le(n,i){(i==null||i>n.length)&&(i=n.length);for(var t=0,e=Array(i);t<i;t++)e[t]=n[t];return e}function it(n,i){if(n){if(typeof n=="string")return Le(n,i);var t={}.toString.call(n).slice(8,-1);return t==="Object"&&n.constructor&&(t=n.constructor.name),t==="Map"||t==="Set"?Array.from(n):t==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?Le(n,i):void 0}}function Ji(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
|
|
2
|
+
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function re(n,i){return Zi(n)||Xi(n,i)||it(n,i)||Ji()}var Qe={black:"#000000",silver:"#C0C0C0",gray:"#808080",grey:"#808080",white:"#FFFFFF",maroon:"#800000",red:"#FF0000",purple:"#800080",fuchsia:"#FF00FF",green:"#008000",lime:"#00FF00",olive:"#808000",yellow:"#FFFF00",navy:"#000080",blue:"#0000FF",teal:"#008080",aqua:"#00FFFF",darkblue:"#00008B",mediumblue:"#0000CD",darkgreen:"#006400",darkcyan:"#008B8B",deepskyblue:"#00BFFF",darkturquoise:"#00CED1",mediumspringgreen:"#00FA9A",springgreen:"#00FF7F",cyan:"#00FFFF",midnightblue:"#191970",dodgerblue:"#1E90FF",lightseagreen:"#20B2AA",forestgreen:"#228B22",seagreen:"#2E8B57",darkslategray:"#2F4F4F",darkslategrey:"#2F4F4F",limegreen:"#32CD32",mediumseagreen:"#3CB371",turquoise:"#40E0D0",royalblue:"#4169E1",steelblue:"#4682B4",darkslateblue:"#483D8B",mediumturquoise:"#48D1CC",indigo:"#4B0082",darkolivegreen:"#556B2F",cadetblue:"#5F9EA0",cornflowerblue:"#6495ED",rebeccapurple:"#663399",mediumaquamarine:"#66CDAA",dimgray:"#696969",dimgrey:"#696969",slateblue:"#6A5ACD",olivedrab:"#6B8E23",slategray:"#708090",slategrey:"#708090",lightslategray:"#778899",lightslategrey:"#778899",mediumslateblue:"#7B68EE",lawngreen:"#7CFC00",chartreuse:"#7FFF00",aquamarine:"#7FFFD4",skyblue:"#87CEEB",lightskyblue:"#87CEFA",blueviolet:"#8A2BE2",darkred:"#8B0000",darkmagenta:"#8B008B",saddlebrown:"#8B4513",darkseagreen:"#8FBC8F",lightgreen:"#90EE90",mediumpurple:"#9370DB",darkviolet:"#9400D3",palegreen:"#98FB98",darkorchid:"#9932CC",yellowgreen:"#9ACD32",sienna:"#A0522D",brown:"#A52A2A",darkgray:"#A9A9A9",darkgrey:"#A9A9A9",lightblue:"#ADD8E6",greenyellow:"#ADFF2F",paleturquoise:"#AFEEEE",lightsteelblue:"#B0C4DE",powderblue:"#B0E0E6",firebrick:"#B22222",darkgoldenrod:"#B8860B",mediumorchid:"#BA55D3",rosybrown:"#BC8F8F",darkkhaki:"#BDB76B",mediumvioletred:"#C71585",indianred:"#CD5C5C",peru:"#CD853F",chocolate:"#D2691E",tan:"#D2B48C",lightgray:"#D3D3D3",lightgrey:"#D3D3D3",thistle:"#D8BFD8",orchid:"#DA70D6",goldenrod:"#DAA520",palevioletred:"#DB7093",crimson:"#DC143C",gainsboro:"#DCDCDC",plum:"#DDA0DD",burlywood:"#DEB887",lightcyan:"#E0FFFF",lavender:"#E6E6FA",darksalmon:"#E9967A",violet:"#EE82EE",palegoldenrod:"#EEE8AA",lightcoral:"#F08080",khaki:"#F0E68C",aliceblue:"#F0F8FF",honeydew:"#F0FFF0",azure:"#F0FFFF",sandybrown:"#F4A460",wheat:"#F5DEB3",beige:"#F5F5DC",whitesmoke:"#F5F5F5",mintcream:"#F5FFFA",ghostwhite:"#F8F8FF",salmon:"#FA8072",antiquewhite:"#FAEBD7",linen:"#FAF0E6",lightgoldenrodyellow:"#FAFAD2",oldlace:"#FDF5E6",magenta:"#FF00FF",deeppink:"#FF1493",orangered:"#FF4500",tomato:"#FF6347",hotpink:"#FF69B4",coral:"#FF7F50",darkorange:"#FF8C00",lightsalmon:"#FFA07A",orange:"#FFA500",lightpink:"#FFB6C1",pink:"#FFC0CB",gold:"#FFD700",peachpuff:"#FFDAB9",navajowhite:"#FFDEAD",moccasin:"#FFE4B5",bisque:"#FFE4C4",mistyrose:"#FFE4E1",blanchedalmond:"#FFEBCD",papayawhip:"#FFEFD5",lavenderblush:"#FFF0F5",seashell:"#FFF5EE",cornsilk:"#FFF8DC",lemonchiffon:"#FFFACD",floralwhite:"#FFFAF0",snow:"#FFFAFA",lightyellow:"#FFFFE0",ivory:"#FFFFF0"};var Ct=new Int8Array(4),et=new Int32Array(Ct.buffer,0,1),Qi=new Float32Array(Ct.buffer,0,1),er=/^\s*rgba?\s*\(/,tr=/^\s*rgba?\s*\(\s*([0-9]*)\s*,\s*([0-9]*)\s*,\s*([0-9]*)(?:\s*,\s*(.*)?)?\)\s*$/;function ir(n){var i=0,t=0,e=0,r=1;if(n[0]==="#")n.length===4?(i=parseInt(n.charAt(1)+n.charAt(1),16),t=parseInt(n.charAt(2)+n.charAt(2),16),e=parseInt(n.charAt(3)+n.charAt(3),16)):(i=parseInt(n.charAt(1)+n.charAt(2),16),t=parseInt(n.charAt(3)+n.charAt(4),16),e=parseInt(n.charAt(5)+n.charAt(6),16)),n.length===9&&(r=parseInt(n.charAt(7)+n.charAt(8),16)/255);else if(er.test(n)){var a=n.match(tr);a&&(i=+a[1],t=+a[2],e=+a[3],a[4]&&(r=+a[4]))}return{r:i,g:t,b:e,a:r}}var ce={};for(we in Qe)ce[we]=le(Qe[we]),ce[Qe[we]]=ce[we];var we;function kt(n,i,t,e,r){return et[0]=e<<24|t<<16|i<<8|n,r&&(et[0]=et[0]&4278190079),Qi[0]}function le(n){if(n=n.toLowerCase(),typeof ce[n]<"u")return ce[n];var i=ir(n),t=i.r,e=i.g,r=i.b,a=i.a;a=a*255|0;var o=kt(t,e,r,a,!0);return ce[n]=o,o}var tt={};function rt(n){if(typeof tt[n]<"u")return tt[n];var i=(n&16711680)>>>16,t=(n&65280)>>>8,e=n&255,r=255,a=kt(i,t,e,r,!0);return tt[n]=a,a}function nt(n,i,t,e){return t+(i<<8)+(n<<16)}function at(n,i,t,e,r,a){var o=Math.floor(t/a*r),s=Math.floor(n.drawingBufferHeight/a-e/a*r),u=new Uint8Array(4);n.bindFramebuffer(n.FRAMEBUFFER,i),n.readPixels(o,s,1,1,n.RGBA,n.UNSIGNED_BYTE,u);var h=re(u,4),d=h[0],c=h[1],l=h[2],f=h[3];return[d,c,l,f]}function g(n,i,t){return(i=ue(i))in n?Object.defineProperty(n,i,{value:t,enumerable:!0,configurable:!0,writable:!0}):n[i]=t,n}function Rt(n,i){var t=Object.keys(n);if(Object.getOwnPropertySymbols){var e=Object.getOwnPropertySymbols(n);i&&(e=e.filter(function(r){return Object.getOwnPropertyDescriptor(n,r).enumerable})),t.push.apply(t,e)}return t}function _(n){for(var i=1;i<arguments.length;i++){var t=arguments[i]!=null?arguments[i]:{};i%2?Rt(Object(t),!0).forEach(function(e){g(n,e,t[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(t)):Rt(Object(t)).forEach(function(e){Object.defineProperty(n,e,Object.getOwnPropertyDescriptor(t,e))})}return n}function rr(n,i){for(;!{}.hasOwnProperty.call(n,i)&&(n=se(n))!==null;);return n}function ut(){return ut=typeof Reflect<"u"&&Reflect.get?Reflect.get.bind():function(n,i,t){var e=rr(n,i);if(e){var r=Object.getOwnPropertyDescriptor(e,i);return r.get?r.get.call(arguments.length<3?n:t):r.value}},ut.apply(null,arguments)}function It(n,i,t,e){var r=ut(se(1&e?n.prototype:n),i,t);return 2&e&&typeof r=="function"?function(a){return r.apply(t,a)}:r}function nr(n){return n.normalized?1:n.size}function ot(n){var i=0;return n.forEach(function(t){return i+=nr(t)}),i}function Mt(n,i,t){var e=n==="VERTEX"?i.VERTEX_SHADER:i.FRAGMENT_SHADER,r=i.createShader(e);if(r===null)throw new Error("loadShader: error while creating the shader");i.shaderSource(r,t),i.compileShader(r);var a=i.getShaderParameter(r,i.COMPILE_STATUS);if(!a){var o=i.getShaderInfoLog(r);throw i.deleteShader(r),new Error(`loadShader: error while compiling the shader:
|
|
3
|
+
`.concat(o,`
|
|
4
|
+
`).concat(t))}return r}function ar(n,i){return Mt("VERTEX",n,i)}function or(n,i){return Mt("FRAGMENT",n,i)}function sr(n,i){var t=n.createProgram();if(t===null)throw new Error("loadProgram: error while creating the program.");var e,r;for(e=0,r=i.length;e<r;e++)n.attachShader(t,i[e]);n.linkProgram(t);var a=n.getProgramParameter(t,n.LINK_STATUS);if(!a){var o=n.getProgramInfoLog(t);throw n.deleteProgram(t),new Error("loadProgram: error while linking the program: ".concat(o))}return t}function Lt(n){var i=n.gl,t=n.buffer,e=n.program,r=n.vertexShader,a=n.fragmentShader;i.deleteShader(r),i.deleteShader(a),i.deleteProgram(e),i.deleteBuffer(t)}var Dt=`#define PICKING_MODE
|
|
5
|
+
`,ur=g(g(g(g(g(g(g(g({},WebGL2RenderingContext.BOOL,1),WebGL2RenderingContext.BYTE,1),WebGL2RenderingContext.UNSIGNED_BYTE,1),WebGL2RenderingContext.SHORT,2),WebGL2RenderingContext.UNSIGNED_SHORT,2),WebGL2RenderingContext.INT,4),WebGL2RenderingContext.UNSIGNED_INT,4),WebGL2RenderingContext.FLOAT,4);var Ut=(function(){function n(i,t,e){D(this,n),g(this,"array",new Float32Array),g(this,"constantArray",new Float32Array),g(this,"capacity",0),g(this,"verticesCount",0);var r=this.getDefinition();if(this.VERTICES=r.VERTICES,this.VERTEX_SHADER_SOURCE=r.VERTEX_SHADER_SOURCE,this.FRAGMENT_SHADER_SOURCE=r.FRAGMENT_SHADER_SOURCE,this.UNIFORMS=r.UNIFORMS,this.ATTRIBUTES=r.ATTRIBUTES,this.METHOD=r.METHOD,this.CONSTANT_ATTRIBUTES="CONSTANT_ATTRIBUTES"in r?r.CONSTANT_ATTRIBUTES:[],this.CONSTANT_DATA="CONSTANT_DATA"in r?r.CONSTANT_DATA:[],this.isInstanced="CONSTANT_ATTRIBUTES"in r,this.ATTRIBUTES_ITEMS_COUNT=ot(this.ATTRIBUTES),this.STRIDE=this.VERTICES*this.ATTRIBUTES_ITEMS_COUNT,this.renderer=e,this.normalProgram=this.getProgramInfo("normal",i,r.VERTEX_SHADER_SOURCE,r.FRAGMENT_SHADER_SOURCE,null),this.pickProgram=t?this.getProgramInfo("pick",i,Dt+r.VERTEX_SHADER_SOURCE,Dt+r.FRAGMENT_SHADER_SOURCE,t):null,this.isInstanced){var a=ot(this.CONSTANT_ATTRIBUTES);if(this.CONSTANT_DATA.length!==this.VERTICES)throw new Error("Program: error while getting constant data (expected ".concat(this.VERTICES," items, received ").concat(this.CONSTANT_DATA.length," instead)"));this.constantArray=new Float32Array(this.CONSTANT_DATA.length*a);for(var o=0;o<this.CONSTANT_DATA.length;o++){var s=this.CONSTANT_DATA[o];if(s.length!==a)throw new Error("Program: error while getting constant data (one vector has ".concat(s.length," items instead of ").concat(a,")"));for(var u=0;u<s.length;u++)this.constantArray[o*a+u]=s[u]}this.STRIDE=this.ATTRIBUTES_ITEMS_COUNT}}return N(n,[{key:"kill",value:function(){Lt(this.normalProgram),this.pickProgram&&(Lt(this.pickProgram),this.pickProgram=null)}},{key:"getProgramInfo",value:function(t,e,r,a,o){var s=this.getDefinition(),u=e.createBuffer();if(u===null)throw new Error("Program: error while creating the WebGL buffer.");var h=ar(e,r),d=or(e,a),c=sr(e,[h,d]),l={};s.UNIFORMS.forEach(function(v){var y=e.getUniformLocation(c,v);y&&(l[v]=y)});var f={};s.ATTRIBUTES.forEach(function(v){f[v.name]=e.getAttribLocation(c,v.name)});var p;if("CONSTANT_ATTRIBUTES"in s&&(s.CONSTANT_ATTRIBUTES.forEach(function(v){f[v.name]=e.getAttribLocation(c,v.name)}),p=e.createBuffer(),p===null))throw new Error("Program: error while creating the WebGL constant buffer.");return{name:t,program:c,gl:e,frameBuffer:o,buffer:u,constantBuffer:p||{},uniformLocations:l,attributeLocations:f,isPicking:t==="pick",vertexShader:h,fragmentShader:d}}},{key:"bindProgram",value:function(t){var e=this,r=0,a=t.gl,o=t.buffer;this.isInstanced?(a.bindBuffer(a.ARRAY_BUFFER,t.constantBuffer),r=0,this.CONSTANT_ATTRIBUTES.forEach(function(s){return r+=e.bindAttribute(s,t,r,!1)}),a.bufferData(a.ARRAY_BUFFER,this.constantArray,a.STATIC_DRAW),a.bindBuffer(a.ARRAY_BUFFER,t.buffer),r=0,this.ATTRIBUTES.forEach(function(s){return r+=e.bindAttribute(s,t,r,!0)}),a.bufferData(a.ARRAY_BUFFER,this.array,a.DYNAMIC_DRAW)):(a.bindBuffer(a.ARRAY_BUFFER,o),r=0,this.ATTRIBUTES.forEach(function(s){return r+=e.bindAttribute(s,t,r)}),a.bufferData(a.ARRAY_BUFFER,this.array,a.DYNAMIC_DRAW)),a.bindBuffer(a.ARRAY_BUFFER,null)}},{key:"unbindProgram",value:function(t){var e=this;this.isInstanced?(this.CONSTANT_ATTRIBUTES.forEach(function(r){return e.unbindAttribute(r,t,!1)}),this.ATTRIBUTES.forEach(function(r){return e.unbindAttribute(r,t,!0)})):this.ATTRIBUTES.forEach(function(r){return e.unbindAttribute(r,t)})}},{key:"bindAttribute",value:function(t,e,r,a){var o=ur[t.type];if(typeof o!="number")throw new Error('Program.bind: yet unsupported attribute type "'.concat(t.type,'"'));var s=e.attributeLocations[t.name],u=e.gl;if(s!==-1){u.enableVertexAttribArray(s);var h=this.isInstanced?(a?this.ATTRIBUTES_ITEMS_COUNT:ot(this.CONSTANT_ATTRIBUTES))*Float32Array.BYTES_PER_ELEMENT:this.ATTRIBUTES_ITEMS_COUNT*Float32Array.BYTES_PER_ELEMENT;if(u.vertexAttribPointer(s,t.size,t.type,t.normalized||!1,h,r),this.isInstanced&&a)if(u instanceof WebGL2RenderingContext)u.vertexAttribDivisor(s,1);else{var d=u.getExtension("ANGLE_instanced_arrays");d&&d.vertexAttribDivisorANGLE(s,1)}}return t.size*o}},{key:"unbindAttribute",value:function(t,e,r){var a=e.attributeLocations[t.name],o=e.gl;if(a!==-1&&(o.disableVertexAttribArray(a),this.isInstanced&&r))if(o instanceof WebGL2RenderingContext)o.vertexAttribDivisor(a,0);else{var s=o.getExtension("ANGLE_instanced_arrays");s&&s.vertexAttribDivisorANGLE(a,0)}}},{key:"reallocate",value:function(t){t!==this.capacity&&(this.capacity=t,this.verticesCount=this.VERTICES*t,this.array=new Float32Array(this.isInstanced?this.capacity*this.ATTRIBUTES_ITEMS_COUNT:this.verticesCount*this.ATTRIBUTES_ITEMS_COUNT))}},{key:"hasNothingToRender",value:function(){return this.verticesCount===0}},{key:"renderProgram",value:function(t,e){var r=e.gl,a=e.program;r.enable(r.BLEND),r.useProgram(a),this.setUniforms(t,e),this.drawWebGL(this.METHOD,e)}},{key:"render",value:function(t){this.hasNothingToRender()||(this.pickProgram&&(this.pickProgram.gl.viewport(0,0,t.width*t.pixelRatio/t.downSizingRatio,t.height*t.pixelRatio/t.downSizingRatio),this.bindProgram(this.pickProgram),this.renderProgram(_(_({},t),{},{pixelRatio:t.pixelRatio/t.downSizingRatio}),this.pickProgram),this.unbindProgram(this.pickProgram)),this.normalProgram.gl.viewport(0,0,t.width*t.pixelRatio,t.height*t.pixelRatio),this.bindProgram(this.normalProgram),this.renderProgram(t,this.normalProgram),this.unbindProgram(this.normalProgram))}},{key:"drawWebGL",value:function(t,e){var r=e.gl,a=e.frameBuffer;if(r.bindFramebuffer(r.FRAMEBUFFER,a),!this.isInstanced)r.drawArrays(t,0,this.verticesCount);else if(r instanceof WebGL2RenderingContext)r.drawArraysInstanced(t,0,this.VERTICES,this.capacity);else{var o=r.getExtension("ANGLE_instanced_arrays");o&&o.drawArraysInstancedANGLE(t,0,this.VERTICES,this.capacity)}}}])})();var hr=(function(n){function i(){return D(this,i),P(this,i,arguments)}return I(i,n),N(i,[{key:"kill",value:function(){It(i,"kill",this,3)([])}},{key:"process",value:function(e,r,a){var o=r*this.STRIDE;if(a.hidden){for(var s=o+this.STRIDE;o<s;o++)this.array[o]=0;return}return this.processVisibleItem(rt(e),o,a)}}])})(Ut);var ht=(function(n){function i(){var t;D(this,i);for(var e=arguments.length,r=new Array(e),a=0;a<e;a++)r[a]=arguments[a];return t=P(this,i,[].concat(r)),g(t,"drawLabel",void 0),t}return I(i,n),N(i,[{key:"kill",value:function(){It(i,"kill",this,3)([])}},{key:"process",value:function(e,r,a,o,s){var u=r*this.STRIDE;if(s.hidden||a.hidden||o.hidden){for(var h=u+this.STRIDE;u<h;u++)this.array[u]=0;return}return this.processVisibleItem(rt(e),u,a,o,s)}}])})(Ut);function dr(n,i){return(function(){function t(e,r,a){D(this,t),g(this,"drawLabel",i),this.programs=n.map(function(o){return new o(e,r,a)})}return N(t,[{key:"reallocate",value:function(r){this.programs.forEach(function(a){return a.reallocate(r)})}},{key:"process",value:function(r,a,o,s,u){this.programs.forEach(function(h){return h.process(r,a,o,s,u)})}},{key:"render",value:function(r){this.programs.forEach(function(a){return a.render(r)})}},{key:"kill",value:function(){this.programs.forEach(function(r){return r.kill()})}}])})()}function $t(n,i,t,e,r){var a=r.edgeLabelSize,o=r.edgeLabelFont,s=r.edgeLabelWeight,u=r.edgeLabelColor.attribute?i[r.edgeLabelColor.attribute]||r.edgeLabelColor.color||"#000":r.edgeLabelColor.color,h=i.label;if(h){n.fillStyle=u,n.font="".concat(s," ").concat(a,"px ").concat(o);var d=t.size,c=e.size,l=t.x,f=t.y,p=e.x,v=e.y,y=(l+p)/2,T=(f+v)/2,w=p-l,E=v-f,A=Math.sqrt(w*w+E*E);if(!(A<d+c)){l+=w*d/A,f+=E*d/A,p-=w*c/A,v-=E*c/A,y=(l+p)/2,T=(f+v)/2,w=p-l,E=v-f,A=Math.sqrt(w*w+E*E);var L=n.measureText(h).width;if(L>A){var R="\u2026";for(h=h+R,L=n.measureText(h).width;L>A&&h.length>1;)h=h.slice(0,-2)+R,L=n.measureText(h).width;if(h.length<4)return}var S;w>0?E>0?S=Math.acos(w/A):S=Math.asin(E/A):E>0?S=Math.acos(w/A)+Math.PI:S=Math.asin(w/A)+Math.PI/2,n.save(),n.translate(y,T),n.rotate(S),n.fillText(h,-L/2,i.size/2+a),n.restore()}}}function dt(n,i,t){if(i.label){var e=t.labelSize,r=t.labelFont,a=t.labelWeight,o=t.labelColor.attribute?i[t.labelColor.attribute]||t.labelColor.color||"#000":t.labelColor.color;n.fillStyle=o,n.font="".concat(a," ").concat(e,"px ").concat(r),n.fillText(i.label,i.x+i.size+3,i.y+e/3)}}function Ot(n,i,t){var e=t.labelSize,r=t.labelFont,a=t.labelWeight;n.font="".concat(a," ").concat(e,"px ").concat(r),n.fillStyle="#FFF",n.shadowOffsetX=0,n.shadowOffsetY=0,n.shadowBlur=8,n.shadowColor="#000";var o=2;if(typeof i.label=="string"){var s=n.measureText(i.label).width,u=Math.round(s+5),h=Math.round(e+2*o),d=Math.max(i.size,e/2)+o,c=Math.asin(h/2/d),l=Math.sqrt(Math.abs(Math.pow(d,2)-Math.pow(h/2,2)));n.beginPath(),n.moveTo(i.x+l,i.y+h/2),n.lineTo(i.x+d+u,i.y+h/2),n.lineTo(i.x+d+u,i.y-h/2),n.lineTo(i.x+l,i.y-h/2),n.arc(i.x,i.y,d,c,-c),n.closePath(),n.fill()}else n.beginPath(),n.arc(i.x,i.y,i.size+o,0,Math.PI*2),n.closePath(),n.fill();n.shadowOffsetX=0,n.shadowOffsetY=0,n.shadowBlur=0,dt(n,i,t)}var cr=`
|
|
6
|
+
precision highp float;
|
|
7
|
+
|
|
8
|
+
varying vec4 v_color;
|
|
9
|
+
varying vec2 v_diffVector;
|
|
10
|
+
varying float v_radius;
|
|
11
|
+
|
|
12
|
+
uniform float u_correctionRatio;
|
|
13
|
+
|
|
14
|
+
const vec4 transparent = vec4(0.0, 0.0, 0.0, 0.0);
|
|
15
|
+
|
|
16
|
+
void main(void) {
|
|
17
|
+
float border = u_correctionRatio * 2.0;
|
|
18
|
+
float dist = length(v_diffVector) - v_radius + border;
|
|
19
|
+
|
|
20
|
+
// No antialiasing for picking mode:
|
|
21
|
+
#ifdef PICKING_MODE
|
|
22
|
+
if (dist > border)
|
|
23
|
+
gl_FragColor = transparent;
|
|
24
|
+
else
|
|
25
|
+
gl_FragColor = v_color;
|
|
26
|
+
|
|
27
|
+
#else
|
|
28
|
+
float t = 0.0;
|
|
29
|
+
if (dist > border)
|
|
30
|
+
t = 1.0;
|
|
31
|
+
else if (dist > 0.0)
|
|
32
|
+
t = dist / border;
|
|
33
|
+
|
|
34
|
+
gl_FragColor = mix(v_color, transparent, t);
|
|
35
|
+
#endif
|
|
36
|
+
}
|
|
37
|
+
`,lr=cr,fr=`
|
|
38
|
+
attribute vec4 a_id;
|
|
39
|
+
attribute vec4 a_color;
|
|
40
|
+
attribute vec2 a_position;
|
|
41
|
+
attribute float a_size;
|
|
42
|
+
attribute float a_angle;
|
|
43
|
+
|
|
44
|
+
uniform mat3 u_matrix;
|
|
45
|
+
uniform float u_sizeRatio;
|
|
46
|
+
uniform float u_correctionRatio;
|
|
47
|
+
|
|
48
|
+
varying vec4 v_color;
|
|
49
|
+
varying vec2 v_diffVector;
|
|
50
|
+
varying float v_radius;
|
|
51
|
+
varying float v_border;
|
|
52
|
+
|
|
53
|
+
const float bias = 255.0 / 254.0;
|
|
54
|
+
|
|
55
|
+
void main() {
|
|
56
|
+
float size = a_size * u_correctionRatio / u_sizeRatio * 4.0;
|
|
57
|
+
vec2 diffVector = size * vec2(cos(a_angle), sin(a_angle));
|
|
58
|
+
vec2 position = a_position + diffVector;
|
|
59
|
+
gl_Position = vec4(
|
|
60
|
+
(u_matrix * vec3(position, 1)).xy,
|
|
61
|
+
0,
|
|
62
|
+
1
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
v_diffVector = diffVector;
|
|
66
|
+
v_radius = size / 2.0;
|
|
67
|
+
|
|
68
|
+
#ifdef PICKING_MODE
|
|
69
|
+
// For picking mode, we use the ID as the color:
|
|
70
|
+
v_color = a_id;
|
|
71
|
+
#else
|
|
72
|
+
// For normal mode, we use the color:
|
|
73
|
+
v_color = a_color;
|
|
74
|
+
#endif
|
|
75
|
+
|
|
76
|
+
v_color.a *= bias;
|
|
77
|
+
}
|
|
78
|
+
`,gr=fr,zt=WebGLRenderingContext,Nt=zt.UNSIGNED_BYTE,st=zt.FLOAT,pr=["u_sizeRatio","u_correctionRatio","u_matrix"],_e=(function(n){function i(){return D(this,i),P(this,i,arguments)}return I(i,n),N(i,[{key:"getDefinition",value:function(){return{VERTICES:3,VERTEX_SHADER_SOURCE:gr,FRAGMENT_SHADER_SOURCE:lr,METHOD:WebGLRenderingContext.TRIANGLES,UNIFORMS:pr,ATTRIBUTES:[{name:"a_position",size:2,type:st},{name:"a_size",size:1,type:st},{name:"a_color",size:4,type:Nt,normalized:!0},{name:"a_id",size:4,type:Nt,normalized:!0}],CONSTANT_ATTRIBUTES:[{name:"a_angle",size:1,type:st}],CONSTANT_DATA:[[i.ANGLE_1],[i.ANGLE_2],[i.ANGLE_3]]}}},{key:"processVisibleItem",value:function(e,r,a){var o=this.array,s=le(a.color);o[r++]=a.x,o[r++]=a.y,o[r++]=a.size,o[r++]=s,o[r++]=e}},{key:"setUniforms",value:function(e,r){var a=r.gl,o=r.uniformLocations,s=o.u_sizeRatio,u=o.u_correctionRatio,h=o.u_matrix;a.uniform1f(u,e.correctionRatio),a.uniform1f(s,e.sizeRatio),a.uniformMatrix3fv(h,!1,e.matrix)}}])})(hr);g(_e,"ANGLE_1",0);g(_e,"ANGLE_2",2*Math.PI/3);g(_e,"ANGLE_3",4*Math.PI/3);var mr=`
|
|
79
|
+
precision mediump float;
|
|
80
|
+
|
|
81
|
+
varying vec4 v_color;
|
|
82
|
+
|
|
83
|
+
void main(void) {
|
|
84
|
+
gl_FragColor = v_color;
|
|
85
|
+
}
|
|
86
|
+
`,vr=mr,yr=`
|
|
87
|
+
attribute vec2 a_position;
|
|
88
|
+
attribute vec2 a_normal;
|
|
89
|
+
attribute float a_radius;
|
|
90
|
+
attribute vec3 a_barycentric;
|
|
91
|
+
|
|
92
|
+
#ifdef PICKING_MODE
|
|
93
|
+
attribute vec4 a_id;
|
|
94
|
+
#else
|
|
95
|
+
attribute vec4 a_color;
|
|
96
|
+
#endif
|
|
97
|
+
|
|
98
|
+
uniform mat3 u_matrix;
|
|
99
|
+
uniform float u_sizeRatio;
|
|
100
|
+
uniform float u_correctionRatio;
|
|
101
|
+
uniform float u_minEdgeThickness;
|
|
102
|
+
uniform float u_lengthToThicknessRatio;
|
|
103
|
+
uniform float u_widenessToThicknessRatio;
|
|
104
|
+
|
|
105
|
+
varying vec4 v_color;
|
|
106
|
+
|
|
107
|
+
const float bias = 255.0 / 254.0;
|
|
108
|
+
|
|
109
|
+
void main() {
|
|
110
|
+
float minThickness = u_minEdgeThickness;
|
|
111
|
+
|
|
112
|
+
float normalLength = length(a_normal);
|
|
113
|
+
vec2 unitNormal = a_normal / normalLength;
|
|
114
|
+
|
|
115
|
+
// These first computations are taken from edge.vert.glsl and
|
|
116
|
+
// edge.clamped.vert.glsl. Please read it to get better comments on what's
|
|
117
|
+
// happening:
|
|
118
|
+
float pixelsThickness = max(normalLength / u_sizeRatio, minThickness);
|
|
119
|
+
float webGLThickness = pixelsThickness * u_correctionRatio;
|
|
120
|
+
float webGLNodeRadius = a_radius * 2.0 * u_correctionRatio / u_sizeRatio;
|
|
121
|
+
float webGLArrowHeadLength = webGLThickness * u_lengthToThicknessRatio * 2.0;
|
|
122
|
+
float webGLArrowHeadThickness = webGLThickness * u_widenessToThicknessRatio;
|
|
123
|
+
|
|
124
|
+
float da = a_barycentric.x;
|
|
125
|
+
float db = a_barycentric.y;
|
|
126
|
+
float dc = a_barycentric.z;
|
|
127
|
+
|
|
128
|
+
vec2 delta = vec2(
|
|
129
|
+
da * (webGLNodeRadius * unitNormal.y)
|
|
130
|
+
+ db * ((webGLNodeRadius + webGLArrowHeadLength) * unitNormal.y + webGLArrowHeadThickness * unitNormal.x)
|
|
131
|
+
+ dc * ((webGLNodeRadius + webGLArrowHeadLength) * unitNormal.y - webGLArrowHeadThickness * unitNormal.x),
|
|
132
|
+
|
|
133
|
+
da * (-webGLNodeRadius * unitNormal.x)
|
|
134
|
+
+ db * (-(webGLNodeRadius + webGLArrowHeadLength) * unitNormal.x + webGLArrowHeadThickness * unitNormal.y)
|
|
135
|
+
+ dc * (-(webGLNodeRadius + webGLArrowHeadLength) * unitNormal.x - webGLArrowHeadThickness * unitNormal.y)
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
vec2 position = (u_matrix * vec3(a_position + delta, 1)).xy;
|
|
139
|
+
|
|
140
|
+
gl_Position = vec4(position, 0, 1);
|
|
141
|
+
|
|
142
|
+
#ifdef PICKING_MODE
|
|
143
|
+
// For picking mode, we use the ID as the color:
|
|
144
|
+
v_color = a_id;
|
|
145
|
+
#else
|
|
146
|
+
// For normal mode, we use the color:
|
|
147
|
+
v_color = a_color;
|
|
148
|
+
#endif
|
|
149
|
+
|
|
150
|
+
v_color.a *= bias;
|
|
151
|
+
}
|
|
152
|
+
`,br=yr,Bt=WebGLRenderingContext,Gt=Bt.UNSIGNED_BYTE,De=Bt.FLOAT,wr=["u_matrix","u_sizeRatio","u_correctionRatio","u_minEdgeThickness","u_lengthToThicknessRatio","u_widenessToThicknessRatio"],Ht={extremity:"target",lengthToThicknessRatio:2.5,widenessToThicknessRatio:2};function Wt(n){var i=_(_({},Ht),n||{});return(function(t){function e(){return D(this,e),P(this,e,arguments)}return I(e,t),N(e,[{key:"getDefinition",value:function(){return{VERTICES:3,VERTEX_SHADER_SOURCE:br,FRAGMENT_SHADER_SOURCE:vr,METHOD:WebGLRenderingContext.TRIANGLES,UNIFORMS:wr,ATTRIBUTES:[{name:"a_position",size:2,type:De},{name:"a_normal",size:2,type:De},{name:"a_radius",size:1,type:De},{name:"a_color",size:4,type:Gt,normalized:!0},{name:"a_id",size:4,type:Gt,normalized:!0}],CONSTANT_ATTRIBUTES:[{name:"a_barycentric",size:3,type:De}],CONSTANT_DATA:[[1,0,0],[0,1,0],[0,0,1]]}}},{key:"processVisibleItem",value:function(a,o,s,u,h){if(i.extremity==="source"){var d=[u,s];s=d[0],u=d[1]}var c=h.size||1,l=u.size||1,f=s.x,p=s.y,v=u.x,y=u.y,T=le(h.color),w=v-f,E=y-p,A=w*w+E*E,L=0,R=0;A&&(A=1/Math.sqrt(A),L=-E*A*c,R=w*A*c);var S=this.array;S[o++]=v,S[o++]=y,S[o++]=-L,S[o++]=-R,S[o++]=l,S[o++]=T,S[o++]=a}},{key:"setUniforms",value:function(a,o){var s=o.gl,u=o.uniformLocations,h=u.u_matrix,d=u.u_sizeRatio,c=u.u_correctionRatio,l=u.u_minEdgeThickness,f=u.u_lengthToThicknessRatio,p=u.u_widenessToThicknessRatio;s.uniformMatrix3fv(h,!1,a.matrix),s.uniform1f(d,a.sizeRatio),s.uniform1f(c,a.correctionRatio),s.uniform1f(l,a.minEdgeThickness),s.uniform1f(f,i.lengthToThicknessRatio),s.uniform1f(p,i.widenessToThicknessRatio)}}])})(ht)}var Ea=Wt();var Er=`
|
|
153
|
+
precision mediump float;
|
|
154
|
+
|
|
155
|
+
varying vec4 v_color;
|
|
156
|
+
varying vec2 v_normal;
|
|
157
|
+
varying float v_thickness;
|
|
158
|
+
varying float v_feather;
|
|
159
|
+
|
|
160
|
+
const vec4 transparent = vec4(0.0, 0.0, 0.0, 0.0);
|
|
161
|
+
|
|
162
|
+
void main(void) {
|
|
163
|
+
// We only handle antialiasing for normal mode:
|
|
164
|
+
#ifdef PICKING_MODE
|
|
165
|
+
gl_FragColor = v_color;
|
|
166
|
+
#else
|
|
167
|
+
float dist = length(v_normal) * v_thickness;
|
|
168
|
+
|
|
169
|
+
float t = smoothstep(
|
|
170
|
+
v_thickness - v_feather,
|
|
171
|
+
v_thickness,
|
|
172
|
+
dist
|
|
173
|
+
);
|
|
174
|
+
|
|
175
|
+
gl_FragColor = mix(v_color, transparent, t);
|
|
176
|
+
#endif
|
|
177
|
+
}
|
|
178
|
+
`,jt=Er,_r=`
|
|
179
|
+
attribute vec4 a_id;
|
|
180
|
+
attribute vec4 a_color;
|
|
181
|
+
attribute vec2 a_normal;
|
|
182
|
+
attribute float a_normalCoef;
|
|
183
|
+
attribute vec2 a_positionStart;
|
|
184
|
+
attribute vec2 a_positionEnd;
|
|
185
|
+
attribute float a_positionCoef;
|
|
186
|
+
attribute float a_radius;
|
|
187
|
+
attribute float a_radiusCoef;
|
|
188
|
+
|
|
189
|
+
uniform mat3 u_matrix;
|
|
190
|
+
uniform float u_zoomRatio;
|
|
191
|
+
uniform float u_sizeRatio;
|
|
192
|
+
uniform float u_pixelRatio;
|
|
193
|
+
uniform float u_correctionRatio;
|
|
194
|
+
uniform float u_minEdgeThickness;
|
|
195
|
+
uniform float u_lengthToThicknessRatio;
|
|
196
|
+
uniform float u_feather;
|
|
197
|
+
|
|
198
|
+
varying vec4 v_color;
|
|
199
|
+
varying vec2 v_normal;
|
|
200
|
+
varying float v_thickness;
|
|
201
|
+
varying float v_feather;
|
|
202
|
+
|
|
203
|
+
const float bias = 255.0 / 254.0;
|
|
204
|
+
|
|
205
|
+
void main() {
|
|
206
|
+
float minThickness = u_minEdgeThickness;
|
|
207
|
+
|
|
208
|
+
float radius = a_radius * a_radiusCoef;
|
|
209
|
+
vec2 normal = a_normal * a_normalCoef;
|
|
210
|
+
vec2 position = a_positionStart * (1.0 - a_positionCoef) + a_positionEnd * a_positionCoef;
|
|
211
|
+
|
|
212
|
+
float normalLength = length(normal);
|
|
213
|
+
vec2 unitNormal = normal / normalLength;
|
|
214
|
+
|
|
215
|
+
// These first computations are taken from edge.vert.glsl. Please read it to
|
|
216
|
+
// get better comments on what's happening:
|
|
217
|
+
float pixelsThickness = max(normalLength, minThickness * u_sizeRatio);
|
|
218
|
+
float webGLThickness = pixelsThickness * u_correctionRatio / u_sizeRatio;
|
|
219
|
+
|
|
220
|
+
// Here, we move the point to leave space for the arrow head:
|
|
221
|
+
float direction = sign(radius);
|
|
222
|
+
float webGLNodeRadius = direction * radius * 2.0 * u_correctionRatio / u_sizeRatio;
|
|
223
|
+
float webGLArrowHeadLength = webGLThickness * u_lengthToThicknessRatio * 2.0;
|
|
224
|
+
|
|
225
|
+
vec2 compensationVector = vec2(-direction * unitNormal.y, direction * unitNormal.x) * (webGLNodeRadius + webGLArrowHeadLength);
|
|
226
|
+
|
|
227
|
+
// Here is the proper position of the vertex
|
|
228
|
+
gl_Position = vec4((u_matrix * vec3(position + unitNormal * webGLThickness + compensationVector, 1)).xy, 0, 1);
|
|
229
|
+
|
|
230
|
+
v_thickness = webGLThickness / u_zoomRatio;
|
|
231
|
+
|
|
232
|
+
v_normal = unitNormal;
|
|
233
|
+
|
|
234
|
+
v_feather = u_feather * u_correctionRatio / u_zoomRatio / u_pixelRatio * 2.0;
|
|
235
|
+
|
|
236
|
+
#ifdef PICKING_MODE
|
|
237
|
+
// For picking mode, we use the ID as the color:
|
|
238
|
+
v_color = a_id;
|
|
239
|
+
#else
|
|
240
|
+
// For normal mode, we use the color:
|
|
241
|
+
v_color = a_color;
|
|
242
|
+
#endif
|
|
243
|
+
|
|
244
|
+
v_color.a *= bias;
|
|
245
|
+
}
|
|
246
|
+
`,xr=_r,Vt=WebGLRenderingContext,Ft=Vt.UNSIGNED_BYTE,he=Vt.FLOAT,Tr=["u_matrix","u_zoomRatio","u_sizeRatio","u_correctionRatio","u_pixelRatio","u_feather","u_minEdgeThickness","u_lengthToThicknessRatio"],Ar={lengthToThicknessRatio:Ht.lengthToThicknessRatio};function Kt(n){var i=_(_({},Ar),n||{});return(function(t){function e(){return D(this,e),P(this,e,arguments)}return I(e,t),N(e,[{key:"getDefinition",value:function(){return{VERTICES:6,VERTEX_SHADER_SOURCE:xr,FRAGMENT_SHADER_SOURCE:jt,METHOD:WebGLRenderingContext.TRIANGLES,UNIFORMS:Tr,ATTRIBUTES:[{name:"a_positionStart",size:2,type:he},{name:"a_positionEnd",size:2,type:he},{name:"a_normal",size:2,type:he},{name:"a_color",size:4,type:Ft,normalized:!0},{name:"a_id",size:4,type:Ft,normalized:!0},{name:"a_radius",size:1,type:he}],CONSTANT_ATTRIBUTES:[{name:"a_positionCoef",size:1,type:he},{name:"a_normalCoef",size:1,type:he},{name:"a_radiusCoef",size:1,type:he}],CONSTANT_DATA:[[0,1,0],[0,-1,0],[1,1,1],[1,1,1],[0,-1,0],[1,-1,-1]]}}},{key:"processVisibleItem",value:function(a,o,s,u,h){var d=h.size||1,c=s.x,l=s.y,f=u.x,p=u.y,v=le(h.color),y=f-c,T=p-l,w=u.size||1,E=y*y+T*T,A=0,L=0;E&&(E=1/Math.sqrt(E),A=-T*E*d,L=y*E*d);var R=this.array;R[o++]=c,R[o++]=l,R[o++]=f,R[o++]=p,R[o++]=A,R[o++]=L,R[o++]=v,R[o++]=a,R[o++]=w}},{key:"setUniforms",value:function(a,o){var s=o.gl,u=o.uniformLocations,h=u.u_matrix,d=u.u_zoomRatio,c=u.u_feather,l=u.u_pixelRatio,f=u.u_correctionRatio,p=u.u_sizeRatio,v=u.u_minEdgeThickness,y=u.u_lengthToThicknessRatio;s.uniformMatrix3fv(h,!1,a.matrix),s.uniform1f(d,a.zoomRatio),s.uniform1f(p,a.sizeRatio),s.uniform1f(f,a.correctionRatio),s.uniform1f(l,a.pixelRatio),s.uniform1f(c,a.antiAliasingFeather),s.uniform1f(v,a.minEdgeThickness),s.uniform1f(y,i.lengthToThicknessRatio)}}])})(ht)}var _a=Kt();function Sr(n){return dr([Kt(n),Wt(n)])}var Cr=Sr(),Yt=Cr,kr=`
|
|
247
|
+
attribute vec4 a_id;
|
|
248
|
+
attribute vec4 a_color;
|
|
249
|
+
attribute vec2 a_normal;
|
|
250
|
+
attribute float a_normalCoef;
|
|
251
|
+
attribute vec2 a_positionStart;
|
|
252
|
+
attribute vec2 a_positionEnd;
|
|
253
|
+
attribute float a_positionCoef;
|
|
254
|
+
|
|
255
|
+
uniform mat3 u_matrix;
|
|
256
|
+
uniform float u_sizeRatio;
|
|
257
|
+
uniform float u_zoomRatio;
|
|
258
|
+
uniform float u_pixelRatio;
|
|
259
|
+
uniform float u_correctionRatio;
|
|
260
|
+
uniform float u_minEdgeThickness;
|
|
261
|
+
uniform float u_feather;
|
|
262
|
+
|
|
263
|
+
varying vec4 v_color;
|
|
264
|
+
varying vec2 v_normal;
|
|
265
|
+
varying float v_thickness;
|
|
266
|
+
varying float v_feather;
|
|
267
|
+
|
|
268
|
+
const float bias = 255.0 / 254.0;
|
|
269
|
+
|
|
270
|
+
void main() {
|
|
271
|
+
float minThickness = u_minEdgeThickness;
|
|
272
|
+
|
|
273
|
+
vec2 normal = a_normal * a_normalCoef;
|
|
274
|
+
vec2 position = a_positionStart * (1.0 - a_positionCoef) + a_positionEnd * a_positionCoef;
|
|
275
|
+
|
|
276
|
+
float normalLength = length(normal);
|
|
277
|
+
vec2 unitNormal = normal / normalLength;
|
|
278
|
+
|
|
279
|
+
// We require edges to be at least "minThickness" pixels thick *on screen*
|
|
280
|
+
// (so we need to compensate the size ratio):
|
|
281
|
+
float pixelsThickness = max(normalLength, minThickness * u_sizeRatio);
|
|
282
|
+
|
|
283
|
+
// Then, we need to retrieve the normalized thickness of the edge in the WebGL
|
|
284
|
+
// referential (in a ([0, 1], [0, 1]) space), using our "magic" correction
|
|
285
|
+
// ratio:
|
|
286
|
+
float webGLThickness = pixelsThickness * u_correctionRatio / u_sizeRatio;
|
|
287
|
+
|
|
288
|
+
// Here is the proper position of the vertex
|
|
289
|
+
gl_Position = vec4((u_matrix * vec3(position + unitNormal * webGLThickness, 1)).xy, 0, 1);
|
|
290
|
+
|
|
291
|
+
// For the fragment shader though, we need a thickness that takes the "magic"
|
|
292
|
+
// correction ratio into account (as in webGLThickness), but so that the
|
|
293
|
+
// antialiasing effect does not depend on the zoom level. So here's yet
|
|
294
|
+
// another thickness version:
|
|
295
|
+
v_thickness = webGLThickness / u_zoomRatio;
|
|
296
|
+
|
|
297
|
+
v_normal = unitNormal;
|
|
298
|
+
|
|
299
|
+
v_feather = u_feather * u_correctionRatio / u_zoomRatio / u_pixelRatio * 2.0;
|
|
300
|
+
|
|
301
|
+
#ifdef PICKING_MODE
|
|
302
|
+
// For picking mode, we use the ID as the color:
|
|
303
|
+
v_color = a_id;
|
|
304
|
+
#else
|
|
305
|
+
// For normal mode, we use the color:
|
|
306
|
+
v_color = a_color;
|
|
307
|
+
#endif
|
|
308
|
+
|
|
309
|
+
v_color.a *= bias;
|
|
310
|
+
}
|
|
311
|
+
`,Rr=kr,qt=WebGLRenderingContext,Pt=qt.UNSIGNED_BYTE,Ee=qt.FLOAT,Lr=["u_matrix","u_zoomRatio","u_sizeRatio","u_correctionRatio","u_pixelRatio","u_feather","u_minEdgeThickness"],Zt=(function(n){function i(){return D(this,i),P(this,i,arguments)}return I(i,n),N(i,[{key:"getDefinition",value:function(){return{VERTICES:6,VERTEX_SHADER_SOURCE:Rr,FRAGMENT_SHADER_SOURCE:jt,METHOD:WebGLRenderingContext.TRIANGLES,UNIFORMS:Lr,ATTRIBUTES:[{name:"a_positionStart",size:2,type:Ee},{name:"a_positionEnd",size:2,type:Ee},{name:"a_normal",size:2,type:Ee},{name:"a_color",size:4,type:Pt,normalized:!0},{name:"a_id",size:4,type:Pt,normalized:!0}],CONSTANT_ATTRIBUTES:[{name:"a_positionCoef",size:1,type:Ee},{name:"a_normalCoef",size:1,type:Ee}],CONSTANT_DATA:[[0,1],[0,-1],[1,1],[1,1],[0,-1],[1,-1]]}}},{key:"processVisibleItem",value:function(e,r,a,o,s){var u=s.size||1,h=a.x,d=a.y,c=o.x,l=o.y,f=le(s.color),p=c-h,v=l-d,y=p*p+v*v,T=0,w=0;y&&(y=1/Math.sqrt(y),T=-v*y*u,w=p*y*u);var E=this.array;E[r++]=h,E[r++]=d,E[r++]=c,E[r++]=l,E[r++]=T,E[r++]=w,E[r++]=f,E[r++]=e}},{key:"setUniforms",value:function(e,r){var a=r.gl,o=r.uniformLocations,s=o.u_matrix,u=o.u_zoomRatio,h=o.u_feather,d=o.u_pixelRatio,c=o.u_correctionRatio,l=o.u_sizeRatio,f=o.u_minEdgeThickness;a.uniformMatrix3fv(s,!1,e.matrix),a.uniform1f(u,e.zoomRatio),a.uniform1f(l,e.sizeRatio),a.uniform1f(c,e.correctionRatio),a.uniform1f(d,e.pixelRatio),a.uniform1f(h,e.antiAliasingFeather),a.uniform1f(f,e.minEdgeThickness)}}])})(ht);var si=be(Fe()),Pe=(function(n){function i(){var t;return D(this,i),t=P(this,i),t.rawEmitter=t,t}return I(i,n),N(i)})(si.EventEmitter);var ci=be(lt());var Mr=function(i){return i},Ur=function(i){return i*i},$r=function(i){return i*(2-i)},Or=function(i){return(i*=2)<1?.5*i*i:-.5*(--i*(i-2)-1)},zr=function(i){return i*i*i},Br=function(i){return--i*i*i+1},Hr=function(i){return(i*=2)<1?.5*i*i*i:.5*((i-=2)*i*i+2)},li={linear:Mr,quadraticIn:Ur,quadraticOut:$r,quadraticInOut:Or,cubicIn:zr,cubicOut:Br,cubicInOut:Hr},fi={easing:"quadraticInOut",duration:150};function B(){return Float32Array.of(1,0,0,0,1,0,0,0,1)}function Ie(n,i,t){return n[0]=i,n[4]=typeof t=="number"?t:i,n}function hi(n,i){var t=Math.sin(i),e=Math.cos(i);return n[0]=e,n[1]=t,n[3]=-t,n[4]=e,n}function di(n,i,t){return n[6]=i,n[7]=t,n}function ne(n,i){var t=n[0],e=n[1],r=n[2],a=n[3],o=n[4],s=n[5],u=n[6],h=n[7],d=n[8],c=i[0],l=i[1],f=i[2],p=i[3],v=i[4],y=i[5],T=i[6],w=i[7],E=i[8];return n[0]=c*t+l*a+f*u,n[1]=c*e+l*o+f*h,n[2]=c*r+l*s+f*d,n[3]=p*t+v*a+y*u,n[4]=p*e+v*o+y*h,n[5]=p*r+v*s+y*d,n[6]=T*t+w*a+E*u,n[7]=T*e+w*o+E*h,n[8]=T*r+w*s+E*d,n}function Me(n,i){var t=arguments.length>2&&arguments[2]!==void 0?arguments[2]:1,e=n[0],r=n[1],a=n[3],o=n[4],s=n[6],u=n[7],h=i.x,d=i.y;return{x:h*e+d*a+s*t,y:h*r+d*o+u*t}}function Wr(n,i){var t=n.height/n.width,e=i.height/i.width;return t<1&&e>1||t>1&&e<1?1:Math.min(Math.max(e,1/e),Math.max(1/t,t))}function ge(n,i,t,e,r){var a=n.angle,o=n.ratio,s=n.x,u=n.y,h=i.width,d=i.height,c=B(),l=Math.min(h,d)-2*e,f=Wr(i,t);return r?(ne(c,di(B(),s,u)),ne(c,Ie(B(),o)),ne(c,hi(B(),a)),ne(c,Ie(B(),h/l/2/f,d/l/2/f))):(ne(c,Ie(B(),2*(l/h)*f,2*(l/d)*f)),ne(c,hi(B(),-a)),ne(c,Ie(B(),1/o)),ne(c,di(B(),-s,-u))),c}function gi(n,i,t){var e=Me(n,{x:Math.cos(i.angle),y:Math.sin(i.angle)},0),r=e.x,a=e.y;return 1/Math.sqrt(Math.pow(r,2)+Math.pow(a,2))/t.width}function pi(n){if(!n.order)return{x:[0,1],y:[0,1]};var i=1/0,t=-1/0,e=1/0,r=-1/0;return n.forEachNode(function(a,o){var s=o.x,u=o.y;s<i&&(i=s),s>t&&(t=s),u<e&&(e=u),u>r&&(r=u)}),{x:[i,t],y:[e,r]}}function mi(n){if(!(0,ci.default)(n))throw new Error("Sigma: invalid graph instance.");n.forEachNode(function(i,t){if(!Number.isFinite(t.x)||!Number.isFinite(t.y))throw new Error("Sigma: Coordinates of node ".concat(i," are invalid. A node must have a numeric 'x' and 'y' attribute."))})}function vi(n,i,t){var e=document.createElement(n);if(i)for(var r in i)e.style[r]=i[r];if(t)for(var a in t)e.setAttribute(a,t[a]);return e}function ft(){return typeof window.devicePixelRatio<"u"?window.devicePixelRatio:1}function gt(n,i,t){return t.sort(function(e,r){var a=i(e)||0,o=i(r)||0;return a<o?-1:a>o?1:0})}function pt(n){var i=re(n.x,2),t=i[0],e=i[1],r=re(n.y,2),a=r[0],o=r[1],s=Math.max(e-t,o-a),u=(e+t)/2,h=(o+a)/2;(s===0||Math.abs(s)===1/0||isNaN(s))&&(s=1),isNaN(u)&&(u=0),isNaN(h)&&(h=0);var d=function(l){return{x:.5+(l.x-u)/s,y:.5+(l.y-h)/s}};return d.applyTo=function(c){c.x=.5+(c.x-u)/s,c.y=.5+(c.y-h)/s},d.inverse=function(c){return{x:u+s*(c.x-.5),y:h+s*(c.y-.5)}},d.ratio=s,d}function Ue(n){"@babel/helpers - typeof";return Ue=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(i){return typeof i}:function(i){return i&&typeof Symbol=="function"&&i.constructor===Symbol&&i!==Symbol.prototype?"symbol":typeof i},Ue(n)}function mt(n,i){var t=i.size;if(t!==0){var e=n.length;n.length+=t;var r=0;i.forEach(function(a){n[e+r]=a,r++})}}function $e(n){n=n||{};for(var i=0,t=arguments.length<=1?0:arguments.length-1;i<t;i++){var e=i+1<1||arguments.length<=i+1?void 0:arguments[i+1];e&&Object.assign(n,e)}return n}var Oe={hideEdgesOnMove:!1,hideLabelsOnMove:!1,renderLabels:!0,renderEdgeLabels:!1,enableEdgeEvents:!1,defaultNodeColor:"#999",defaultNodeType:"circle",defaultEdgeColor:"#ccc",defaultEdgeType:"line",labelFont:"Arial",labelSize:14,labelWeight:"normal",labelColor:{color:"#000"},edgeLabelFont:"Arial",edgeLabelSize:14,edgeLabelWeight:"normal",edgeLabelColor:{attribute:"color"},stagePadding:30,defaultDrawEdgeLabel:$t,defaultDrawNodeLabel:dt,defaultDrawNodeHover:Ot,minEdgeThickness:1.7,antiAliasingFeather:1,dragTimeout:100,draggedEventsTolerance:3,inertiaDuration:200,inertiaRatio:3,zoomDuration:250,zoomingRatio:1.7,doubleClickTimeout:300,doubleClickZoomingRatio:2.2,doubleClickZoomingDuration:200,tapMoveTolerance:10,zoomToSizeRatioFunction:Math.sqrt,itemSizesReference:"screen",autoRescale:!0,autoCenter:!0,labelDensity:1,labelGridCellSize:100,labelRenderedSizeThreshold:6,nodeReducer:null,edgeReducer:null,zIndex:!1,minCameraRatio:null,maxCameraRatio:null,enableCameraZooming:!0,enableCameraPanning:!0,enableCameraRotation:!0,cameraPanBoundaries:null,allowInvalidContainer:!1,nodeProgramClasses:{},nodeHoverProgramClasses:{},edgeProgramClasses:{}},jr={circle:_e},Vr={arrow:Yt,line:Zt};function ze(n){if(typeof n.labelDensity!="number"||n.labelDensity<0)throw new Error("Settings: invalid `labelDensity`. Expecting a positive number.");var i=n.minCameraRatio,t=n.maxCameraRatio;if(typeof i=="number"&&typeof t=="number"&&t<i)throw new Error("Settings: invalid camera ratio boundaries. Expecting `maxCameraRatio` to be greater than `minCameraRatio`.")}function yi(n){var i=$e({},Oe,n);return i.nodeProgramClasses=$e({},jr,i.nodeProgramClasses),i.edgeProgramClasses=$e({},Vr,i.edgeProgramClasses),i}var za=be(Fe()),Ba=be(lt()),Be=1.5,bi=(function(n){function i(){var t;return D(this,i),t=P(this,i),g(t,"x",.5),g(t,"y",.5),g(t,"angle",0),g(t,"ratio",1),g(t,"minRatio",null),g(t,"maxRatio",null),g(t,"enabledZooming",!0),g(t,"enabledPanning",!0),g(t,"enabledRotation",!0),g(t,"clean",null),g(t,"nextFrame",null),g(t,"previousState",null),g(t,"enabled",!0),t.previousState=t.getState(),t}return I(i,n),N(i,[{key:"enable",value:function(){return this.enabled=!0,this}},{key:"disable",value:function(){return this.enabled=!1,this}},{key:"getState",value:function(){return{x:this.x,y:this.y,angle:this.angle,ratio:this.ratio}}},{key:"hasState",value:function(e){return this.x===e.x&&this.y===e.y&&this.ratio===e.ratio&&this.angle===e.angle}},{key:"getPreviousState",value:function(){var e=this.previousState;return e?{x:e.x,y:e.y,angle:e.angle,ratio:e.ratio}:null}},{key:"getBoundedRatio",value:function(e){var r=e;return typeof this.minRatio=="number"&&(r=Math.max(r,this.minRatio)),typeof this.maxRatio=="number"&&(r=Math.min(r,this.maxRatio)),r}},{key:"validateState",value:function(e){var r={};return this.enabledPanning&&typeof e.x=="number"&&(r.x=e.x),this.enabledPanning&&typeof e.y=="number"&&(r.y=e.y),this.enabledZooming&&typeof e.ratio=="number"&&(r.ratio=this.getBoundedRatio(e.ratio)),this.enabledRotation&&typeof e.angle=="number"&&(r.angle=e.angle),this.clean?this.clean(_(_({},this.getState()),r)):r}},{key:"isAnimated",value:function(){return!!this.nextFrame}},{key:"setState",value:function(e){if(!this.enabled)return this;this.previousState=this.getState();var r=this.validateState(e);return typeof r.x=="number"&&(this.x=r.x),typeof r.y=="number"&&(this.y=r.y),typeof r.ratio=="number"&&(this.ratio=r.ratio),typeof r.angle=="number"&&(this.angle=r.angle),this.hasState(this.previousState)||this.emit("updated",this.getState()),this}},{key:"updateState",value:function(e){return this.setState(e(this.getState())),this}},{key:"animate",value:function(e){var r=this,a=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},o=arguments.length>2?arguments[2]:void 0;if(!o)return new Promise(function(f){return r.animate(e,a,f)});if(this.enabled){var s=_(_({},fi),a),u=this.validateState(e),h=typeof s.easing=="function"?s.easing:li[s.easing],d=Date.now(),c=this.getState(),l=function(){var p=(Date.now()-d)/s.duration;if(p>=1){r.nextFrame=null,r.setState(u),r.animationCallback&&(r.animationCallback.call(null),r.animationCallback=void 0);return}var v=h(p),y={};typeof u.x=="number"&&(y.x=c.x+(u.x-c.x)*v),typeof u.y=="number"&&(y.y=c.y+(u.y-c.y)*v),r.enabledRotation&&typeof u.angle=="number"&&(y.angle=c.angle+(u.angle-c.angle)*v),typeof u.ratio=="number"&&(y.ratio=c.ratio+(u.ratio-c.ratio)*v),r.setState(y),r.nextFrame=requestAnimationFrame(l)};this.nextFrame?(cancelAnimationFrame(this.nextFrame),this.animationCallback&&this.animationCallback.call(null),this.nextFrame=requestAnimationFrame(l)):l(),this.animationCallback=o}}},{key:"animatedZoom",value:function(e){return e?typeof e=="number"?this.animate({ratio:this.ratio/e}):this.animate({ratio:this.ratio/(e.factor||Be)},e):this.animate({ratio:this.ratio/Be})}},{key:"animatedUnzoom",value:function(e){return e?typeof e=="number"?this.animate({ratio:this.ratio*e}):this.animate({ratio:this.ratio*(e.factor||Be)},e):this.animate({ratio:this.ratio*Be})}},{key:"animatedReset",value:function(e){return this.animate({x:.5,y:.5,ratio:1,angle:0},e)}},{key:"copy",value:function(){return i.from(this.getState())}}],[{key:"from",value:function(e){var r=new i;return r.setState(e)}}])})(Pe);function K(n,i){var t=i.getBoundingClientRect();return{x:n.clientX-t.left,y:n.clientY-t.top}}function Z(n,i){var t=_(_({},K(n,i)),{},{sigmaDefaultPrevented:!1,preventSigmaDefault:function(){t.sigmaDefaultPrevented=!0},original:n});return t}function xe(n){var i="x"in n?n:_(_({},n.touches[0]||n.previousTouches[0]),{},{original:n.original,sigmaDefaultPrevented:n.sigmaDefaultPrevented,preventSigmaDefault:function(){n.sigmaDefaultPrevented=!0,i.sigmaDefaultPrevented=!0}});return i}function Kr(n,i){return _(_({},Z(n,i)),{},{delta:Ai(n)})}var Yr=2;function He(n){for(var i=[],t=0,e=Math.min(n.length,Yr);t<e;t++)i.push(n[t]);return i}function Te(n,i,t){var e={touches:He(n.touches).map(function(r){return K(r,t)}),previousTouches:i.map(function(r){return K(r,t)}),sigmaDefaultPrevented:!1,preventSigmaDefault:function(){e.sigmaDefaultPrevented=!0},original:n};return e}function Ai(n){if(typeof n.deltaY<"u")return n.deltaY*-3/360;if(typeof n.detail<"u")return n.detail/-9;throw new Error("Captor: could not extract delta from event.")}var Si=(function(n){function i(t,e){var r;return D(this,i),r=P(this,i),r.container=t,r.renderer=e,r}return I(i,n),N(i)})(Pe),qr=["doubleClickTimeout","doubleClickZoomingDuration","doubleClickZoomingRatio","dragTimeout","draggedEventsTolerance","inertiaDuration","inertiaRatio","zoomDuration","zoomingRatio"],Zr=qr.reduce(function(n,i){return _(_({},n),{},g({},i,Oe[i]))},{}),Xr=(function(n){function i(t,e){var r;return D(this,i),r=P(this,i,[t,e]),g(r,"enabled",!0),g(r,"draggedEvents",0),g(r,"downStartTime",null),g(r,"lastMouseX",null),g(r,"lastMouseY",null),g(r,"isMouseDown",!1),g(r,"isMoving",!1),g(r,"movingTimeout",null),g(r,"startCameraState",null),g(r,"clicks",0),g(r,"doubleClickTimeout",null),g(r,"currentWheelDirection",0),g(r,"settings",Zr),r.handleClick=r.handleClick.bind(r),r.handleRightClick=r.handleRightClick.bind(r),r.handleDown=r.handleDown.bind(r),r.handleUp=r.handleUp.bind(r),r.handleMove=r.handleMove.bind(r),r.handleWheel=r.handleWheel.bind(r),r.handleLeave=r.handleLeave.bind(r),r.handleEnter=r.handleEnter.bind(r),t.addEventListener("click",r.handleClick,{capture:!1}),t.addEventListener("contextmenu",r.handleRightClick,{capture:!1}),t.addEventListener("mousedown",r.handleDown,{capture:!1}),t.addEventListener("wheel",r.handleWheel,{capture:!1}),t.addEventListener("mouseleave",r.handleLeave,{capture:!1}),t.addEventListener("mouseenter",r.handleEnter,{capture:!1}),document.addEventListener("mousemove",r.handleMove,{capture:!1}),document.addEventListener("mouseup",r.handleUp,{capture:!1}),r}return I(i,n),N(i,[{key:"kill",value:function(){var e=this.container;e.removeEventListener("click",this.handleClick),e.removeEventListener("contextmenu",this.handleRightClick),e.removeEventListener("mousedown",this.handleDown),e.removeEventListener("wheel",this.handleWheel),e.removeEventListener("mouseleave",this.handleLeave),e.removeEventListener("mouseenter",this.handleEnter),document.removeEventListener("mousemove",this.handleMove),document.removeEventListener("mouseup",this.handleUp)}},{key:"handleClick",value:function(e){var r=this;if(this.enabled){if(this.clicks++,this.clicks===2)return this.clicks=0,typeof this.doubleClickTimeout=="number"&&(clearTimeout(this.doubleClickTimeout),this.doubleClickTimeout=null),this.handleDoubleClick(e);setTimeout(function(){r.clicks=0,r.doubleClickTimeout=null},this.settings.doubleClickTimeout),this.draggedEvents<this.settings.draggedEventsTolerance&&this.emit("click",Z(e,this.container))}}},{key:"handleRightClick",value:function(e){this.enabled&&this.emit("rightClick",Z(e,this.container))}},{key:"handleDoubleClick",value:function(e){if(this.enabled){e.preventDefault(),e.stopPropagation();var r=Z(e,this.container);if(this.emit("doubleClick",r),!r.sigmaDefaultPrevented){var a=this.renderer.getCamera(),o=a.getBoundedRatio(a.getState().ratio/this.settings.doubleClickZoomingRatio);a.animate(this.renderer.getViewportZoomedState(K(e,this.container),o),{easing:"quadraticInOut",duration:this.settings.doubleClickZoomingDuration})}}}},{key:"handleDown",value:function(e){if(this.enabled){if(e.button===0){this.startCameraState=this.renderer.getCamera().getState();var r=K(e,this.container),a=r.x,o=r.y;this.lastMouseX=a,this.lastMouseY=o,this.draggedEvents=0,this.downStartTime=Date.now(),this.isMouseDown=!0}this.emit("mousedown",Z(e,this.container))}}},{key:"handleUp",value:function(e){var r=this;if(!(!this.enabled||!this.isMouseDown)){var a=this.renderer.getCamera();this.isMouseDown=!1,typeof this.movingTimeout=="number"&&(clearTimeout(this.movingTimeout),this.movingTimeout=null);var o=K(e,this.container),s=o.x,u=o.y,h=a.getState(),d=a.getPreviousState()||{x:0,y:0};this.isMoving?a.animate({x:h.x+this.settings.inertiaRatio*(h.x-d.x),y:h.y+this.settings.inertiaRatio*(h.y-d.y)},{duration:this.settings.inertiaDuration,easing:"quadraticOut"}):(this.lastMouseX!==s||this.lastMouseY!==u)&&a.setState({x:h.x,y:h.y}),this.isMoving=!1,setTimeout(function(){var c=r.draggedEvents>0;r.draggedEvents=0,c&&r.renderer.getSetting("hideEdgesOnMove")&&r.renderer.refresh()},0),this.emit("mouseup",Z(e,this.container))}}},{key:"handleMove",value:function(e){var r=this;if(this.enabled){var a=Z(e,this.container);if(this.emit("mousemovebody",a),(e.target===this.container||e.composedPath()[0]===this.container)&&this.emit("mousemove",a),!a.sigmaDefaultPrevented&&this.isMouseDown){this.isMoving=!0,this.draggedEvents++,typeof this.movingTimeout=="number"&&clearTimeout(this.movingTimeout),this.movingTimeout=window.setTimeout(function(){r.movingTimeout=null,r.isMoving=!1},this.settings.dragTimeout);var o=this.renderer.getCamera(),s=K(e,this.container),u=s.x,h=s.y,d=this.renderer.viewportToFramedGraph({x:this.lastMouseX,y:this.lastMouseY}),c=this.renderer.viewportToFramedGraph({x:u,y:h}),l=d.x-c.x,f=d.y-c.y,p=o.getState(),v=p.x+l,y=p.y+f;o.setState({x:v,y}),this.lastMouseX=u,this.lastMouseY=h,e.preventDefault(),e.stopPropagation()}}}},{key:"handleLeave",value:function(e){this.emit("mouseleave",Z(e,this.container))}},{key:"handleEnter",value:function(e){this.emit("mouseenter",Z(e,this.container))}},{key:"handleWheel",value:function(e){var r=this,a=this.renderer.getCamera();if(!(!this.enabled||!a.enabledZooming)){var o=Ai(e);if(o){var s=Kr(e,this.container);if(this.emit("wheel",s),s.sigmaDefaultPrevented){e.preventDefault(),e.stopPropagation();return}var u=a.getState().ratio,h=o>0?1/this.settings.zoomingRatio:this.settings.zoomingRatio,d=a.getBoundedRatio(u*h),c=o>0?1:-1,l=Date.now();u!==d&&(e.preventDefault(),e.stopPropagation(),!(this.currentWheelDirection===c&&this.lastWheelTriggerTime&&l-this.lastWheelTriggerTime<this.settings.zoomDuration/5)&&(a.animate(this.renderer.getViewportZoomedState(K(e,this.container),d),{easing:"quadraticOut",duration:this.settings.zoomDuration},function(){r.currentWheelDirection=0}),this.currentWheelDirection=c,this.lastWheelTriggerTime=l))}}}},{key:"setSettings",value:function(e){this.settings=e}}])})(Si),Jr=["dragTimeout","inertiaDuration","inertiaRatio","doubleClickTimeout","doubleClickZoomingRatio","doubleClickZoomingDuration","tapMoveTolerance"],Qr=Jr.reduce(function(n,i){return _(_({},n),{},g({},i,Oe[i]))},{}),en=(function(n){function i(t,e){var r;return D(this,i),r=P(this,i,[t,e]),g(r,"enabled",!0),g(r,"isMoving",!1),g(r,"hasMoved",!1),g(r,"touchMode",0),g(r,"startTouchesPositions",[]),g(r,"lastTouches",[]),g(r,"lastTap",null),g(r,"settings",Qr),r.handleStart=r.handleStart.bind(r),r.handleLeave=r.handleLeave.bind(r),r.handleMove=r.handleMove.bind(r),t.addEventListener("touchstart",r.handleStart,{capture:!1}),t.addEventListener("touchcancel",r.handleLeave,{capture:!1}),document.addEventListener("touchend",r.handleLeave,{capture:!1,passive:!1}),document.addEventListener("touchmove",r.handleMove,{capture:!1,passive:!1}),r}return I(i,n),N(i,[{key:"kill",value:function(){var e=this.container;e.removeEventListener("touchstart",this.handleStart),e.removeEventListener("touchcancel",this.handleLeave),document.removeEventListener("touchend",this.handleLeave),document.removeEventListener("touchmove",this.handleMove)}},{key:"getDimensions",value:function(){return{width:this.container.offsetWidth,height:this.container.offsetHeight}}},{key:"handleStart",value:function(e){var r=this;if(this.enabled){e.preventDefault();var a=He(e.touches);if(this.touchMode=a.length,this.startCameraState=this.renderer.getCamera().getState(),this.startTouchesPositions=a.map(function(f){return K(f,r.container)}),this.touchMode===2){var o=re(this.startTouchesPositions,2),s=o[0],u=s.x,h=s.y,d=o[1],c=d.x,l=d.y;this.startTouchesAngle=Math.atan2(l-h,c-u),this.startTouchesDistance=Math.sqrt(Math.pow(c-u,2)+Math.pow(l-h,2))}this.emit("touchdown",Te(e,this.lastTouches,this.container)),this.lastTouches=a,this.lastTouchesPositions=this.startTouchesPositions}}},{key:"handleLeave",value:function(e){if(!(!this.enabled||!this.startTouchesPositions.length)){switch(e.cancelable&&e.preventDefault(),this.movingTimeout&&(this.isMoving=!1,clearTimeout(this.movingTimeout)),this.touchMode){case 2:if(e.touches.length===1){this.handleStart(e),e.preventDefault();break}case 1:if(this.isMoving){var r=this.renderer.getCamera(),a=r.getState(),o=r.getPreviousState()||{x:0,y:0};r.animate({x:a.x+this.settings.inertiaRatio*(a.x-o.x),y:a.y+this.settings.inertiaRatio*(a.y-o.y)},{duration:this.settings.inertiaDuration,easing:"quadraticOut"})}this.hasMoved=!1,this.isMoving=!1,this.touchMode=0;break}if(this.emit("touchup",Te(e,this.lastTouches,this.container)),!e.touches.length){var s=K(this.lastTouches[0],this.container),u=this.startTouchesPositions[0],h=Math.pow(s.x-u.x,2)+Math.pow(s.y-u.y,2);if(!e.touches.length&&h<Math.pow(this.settings.tapMoveTolerance,2))if(this.lastTap&&Date.now()-this.lastTap.time<this.settings.doubleClickTimeout){var d=Te(e,this.lastTouches,this.container);if(this.emit("doubletap",d),this.lastTap=null,!d.sigmaDefaultPrevented){var c=this.renderer.getCamera(),l=c.getBoundedRatio(c.getState().ratio/this.settings.doubleClickZoomingRatio);c.animate(this.renderer.getViewportZoomedState(s,l),{easing:"quadraticInOut",duration:this.settings.doubleClickZoomingDuration})}}else{var f=Te(e,this.lastTouches,this.container);this.emit("tap",f),this.lastTap={time:Date.now(),position:f.touches[0]||f.previousTouches[0]}}}this.lastTouches=He(e.touches),this.startTouchesPositions=[]}}},{key:"handleMove",value:function(e){var r=this;if(!(!this.enabled||!this.startTouchesPositions.length)){e.preventDefault();var a=He(e.touches),o=a.map(function(ie){return K(ie,r.container)}),s=this.lastTouches;this.lastTouches=a,this.lastTouchesPositions=o;var u=Te(e,s,this.container);if(this.emit("touchmove",u),!u.sigmaDefaultPrevented&&(this.hasMoved||(this.hasMoved=o.some(function(ie,Ze){var q=r.startTouchesPositions[Ze];return q&&(ie.x!==q.x||ie.y!==q.y)})),!!this.hasMoved)){this.isMoving=!0,this.movingTimeout&&clearTimeout(this.movingTimeout),this.movingTimeout=window.setTimeout(function(){r.isMoving=!1},this.settings.dragTimeout);var h=this.renderer.getCamera(),d=this.startCameraState,c=this.renderer.getSetting("stagePadding");switch(this.touchMode){case 1:{var l=this.renderer.viewportToFramedGraph((this.startTouchesPositions||[])[0]),f=l.x,p=l.y,v=this.renderer.viewportToFramedGraph(o[0]),y=v.x,T=v.y;h.setState({x:d.x+f-y,y:d.y+p-T});break}case 2:{var w={x:.5,y:.5,angle:0,ratio:1},E=o[0],A=E.x,L=E.y,R=o[1],S=R.x,j=R.y,O=Math.atan2(j-L,S-A)-this.startTouchesAngle,M=Math.hypot(j-L,S-A)/this.startTouchesDistance,z=h.getBoundedRatio(d.ratio/M);w.ratio=z,w.angle=d.angle+O;var U=this.getDimensions(),ae=this.renderer.viewportToFramedGraph((this.startTouchesPositions||[])[0],{cameraState:d}),$=Math.min(U.width,U.height)-2*c,V=$/U.width,ee=$/U.height,Re=z/$,de=A-$/2/V,oe=L-$/2/ee,te=[de*Math.cos(-w.angle)-oe*Math.sin(-w.angle),oe*Math.cos(-w.angle)+de*Math.sin(-w.angle)];de=te[0],oe=te[1],w.x=ae.x-de*Re,w.y=ae.y+oe*Re,h.setState(w);break}}}}}},{key:"setSettings",value:function(e){this.settings=e}}])})(Si);function tn(n){if(Array.isArray(n))return Le(n)}function rn(n){if(typeof Symbol<"u"&&n[Symbol.iterator]!=null||n["@@iterator"]!=null)return Array.from(n)}function nn(){throw new TypeError(`Invalid attempt to spread non-iterable instance.
|
|
312
|
+
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function wi(n){return tn(n)||rn(n)||it(n)||nn()}function an(n,i){if(n==null)return{};var t={};for(var e in n)if({}.hasOwnProperty.call(n,e)){if(i.indexOf(e)!==-1)continue;t[e]=n[e]}return t}function vt(n,i){if(n==null)return{};var t,e,r=an(n,i);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(n);for(e=0;e<a.length;e++)t=a[e],i.indexOf(t)===-1&&{}.propertyIsEnumerable.call(n,t)&&(r[t]=n[t])}return r}var Ei=(function(){function n(i,t){D(this,n),this.key=i,this.size=t}return N(n,null,[{key:"compare",value:function(t,e){return t.size>e.size?-1:t.size<e.size||t.key>e.key?1:-1}}])})(),_i=(function(){function n(){D(this,n),g(this,"width",0),g(this,"height",0),g(this,"cellSize",0),g(this,"columns",0),g(this,"rows",0),g(this,"cells",{})}return N(n,[{key:"resizeAndClear",value:function(t,e){this.width=t.width,this.height=t.height,this.cellSize=e,this.columns=Math.ceil(t.width/e),this.rows=Math.ceil(t.height/e),this.cells={}}},{key:"getIndex",value:function(t){var e=Math.floor(t.x/this.cellSize),r=Math.floor(t.y/this.cellSize);return r*this.columns+e}},{key:"add",value:function(t,e,r){var a=new Ei(t,e),o=this.getIndex(r),s=this.cells[o];s||(s=[],this.cells[o]=s),s.push(a)}},{key:"organize",value:function(){for(var t in this.cells){var e=this.cells[t];e.sort(Ei.compare)}}},{key:"getLabelsToDisplay",value:function(t,e){var r=this.cellSize*this.cellSize,a=r/t/t,o=a*e/r,s=Math.ceil(o),u=[];for(var h in this.cells)for(var d=this.cells[h],c=0;c<Math.min(s,d.length);c++)u.push(d[c].key);return u}}])})();function on(n){var i=n.graph,t=n.hoveredNode,e=n.highlightedNodes,r=n.displayedNodeLabels,a=[];return i.forEachEdge(function(o,s,u,h){(u===t||h===t||e.has(u)||e.has(h)||r.has(u)&&r.has(h))&&a.push(o)}),a}var xi=150,Ti=50,X=Object.prototype.hasOwnProperty;function sn(n,i,t){if(!X.call(t,"x")||!X.call(t,"y"))throw new Error('Sigma: could not find a valid position (x, y) for node "'.concat(i,'". All your nodes must have a number "x" and "y". Maybe your forgot to apply a layout or your "nodeReducer" is not returning the correct data?'));return t.color||(t.color=n.defaultNodeColor),!t.label&&t.label!==""&&(t.label=null),t.label!==void 0&&t.label!==null?t.label=""+t.label:t.label=null,t.size||(t.size=2),X.call(t,"hidden")||(t.hidden=!1),X.call(t,"highlighted")||(t.highlighted=!1),X.call(t,"forceLabel")||(t.forceLabel=!1),(!t.type||t.type==="")&&(t.type=n.defaultNodeType),t.zIndex||(t.zIndex=0),t}function un(n,i,t){return t.color||(t.color=n.defaultEdgeColor),t.label||(t.label=""),t.size||(t.size=.5),X.call(t,"hidden")||(t.hidden=!1),X.call(t,"forceLabel")||(t.forceLabel=!1),(!t.type||t.type==="")&&(t.type=n.defaultEdgeType),t.zIndex||(t.zIndex=0),t}var hn=(function(n){function i(t,e){var r,a=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};if(D(this,i),r=P(this,i),g(r,"elements",{}),g(r,"canvasContexts",{}),g(r,"webGLContexts",{}),g(r,"pickingLayers",new Set),g(r,"textures",{}),g(r,"frameBuffers",{}),g(r,"activeListeners",{}),g(r,"labelGrid",new _i),g(r,"nodeDataCache",{}),g(r,"edgeDataCache",{}),g(r,"nodeProgramIndex",{}),g(r,"edgeProgramIndex",{}),g(r,"nodesWithForcedLabels",new Set),g(r,"edgesWithForcedLabels",new Set),g(r,"nodeExtent",{x:[0,1],y:[0,1]}),g(r,"nodeZExtent",[1/0,-1/0]),g(r,"edgeZExtent",[1/0,-1/0]),g(r,"matrix",B()),g(r,"invMatrix",B()),g(r,"correctionRatio",1),g(r,"customBBox",null),g(r,"normalizationFunction",pt({x:[0,1],y:[0,1]})),g(r,"graphToViewportRatio",1),g(r,"itemIDsIndex",{}),g(r,"nodeIndices",{}),g(r,"edgeIndices",{}),g(r,"width",0),g(r,"height",0),g(r,"pixelRatio",ft()),g(r,"pickingDownSizingRatio",2*r.pixelRatio),g(r,"displayedNodeLabels",new Set),g(r,"displayedEdgeLabels",new Set),g(r,"highlightedNodes",new Set),g(r,"hoveredNode",null),g(r,"hoveredEdge",null),g(r,"renderFrame",null),g(r,"renderHighlightedNodesFrame",null),g(r,"needToProcess",!1),g(r,"checkEdgesEventsFrame",null),g(r,"nodePrograms",{}),g(r,"nodeHoverPrograms",{}),g(r,"edgePrograms",{}),r.settings=yi(a),ze(r.settings),mi(t),!(e instanceof HTMLElement))throw new Error("Sigma: container should be an html element.");r.graph=t,r.container=e,r.createWebGLContext("edges",{picking:a.enableEdgeEvents}),r.createCanvasContext("edgeLabels"),r.createWebGLContext("nodes",{picking:!0}),r.createCanvasContext("labels"),r.createCanvasContext("hovers"),r.createWebGLContext("hoverNodes"),r.createCanvasContext("mouse",{style:{touchAction:"none",userSelect:"none"}}),r.resize();for(var o in r.settings.nodeProgramClasses)r.registerNodeProgram(o,r.settings.nodeProgramClasses[o],r.settings.nodeHoverProgramClasses[o]);for(var s in r.settings.edgeProgramClasses)r.registerEdgeProgram(s,r.settings.edgeProgramClasses[s]);return r.camera=new bi,r.bindCameraHandlers(),r.mouseCaptor=new Xr(r.elements.mouse,r),r.mouseCaptor.setSettings(r.settings),r.touchCaptor=new en(r.elements.mouse,r),r.touchCaptor.setSettings(r.settings),r.bindEventHandlers(),r.bindGraphHandlers(),r.handleSettingsUpdate(),r.refresh(),r}return I(i,n),N(i,[{key:"registerNodeProgram",value:function(e,r,a){return this.nodePrograms[e]&&this.nodePrograms[e].kill(),this.nodeHoverPrograms[e]&&this.nodeHoverPrograms[e].kill(),this.nodePrograms[e]=new r(this.webGLContexts.nodes,this.frameBuffers.nodes,this),this.nodeHoverPrograms[e]=new(a||r)(this.webGLContexts.hoverNodes,null,this),this}},{key:"registerEdgeProgram",value:function(e,r){return this.edgePrograms[e]&&this.edgePrograms[e].kill(),this.edgePrograms[e]=new r(this.webGLContexts.edges,this.frameBuffers.edges,this),this}},{key:"unregisterNodeProgram",value:function(e){if(this.nodePrograms[e]){var r=this.nodePrograms,a=r[e],o=vt(r,[e].map(ue));a.kill(),this.nodePrograms=o}if(this.nodeHoverPrograms[e]){var s=this.nodeHoverPrograms,u=s[e],h=vt(s,[e].map(ue));u.kill(),this.nodePrograms=h}return this}},{key:"unregisterEdgeProgram",value:function(e){if(this.edgePrograms[e]){var r=this.edgePrograms,a=r[e],o=vt(r,[e].map(ue));a.kill(),this.edgePrograms=o}return this}},{key:"resetWebGLTexture",value:function(e){var r=this.webGLContexts[e],a=this.frameBuffers[e],o=this.textures[e];o&&r.deleteTexture(o);var s=r.createTexture();return r.bindFramebuffer(r.FRAMEBUFFER,a),r.bindTexture(r.TEXTURE_2D,s),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,this.width,this.height,0,r.RGBA,r.UNSIGNED_BYTE,null),r.framebufferTexture2D(r.FRAMEBUFFER,r.COLOR_ATTACHMENT0,r.TEXTURE_2D,s,0),this.textures[e]=s,this}},{key:"bindCameraHandlers",value:function(){var e=this;return this.activeListeners.camera=function(){e.scheduleRender()},this.camera.on("updated",this.activeListeners.camera),this}},{key:"unbindCameraHandlers",value:function(){return this.camera.removeListener("updated",this.activeListeners.camera),this}},{key:"getNodeAtPosition",value:function(e){var r=e.x,a=e.y,o=at(this.webGLContexts.nodes,this.frameBuffers.nodes,r,a,this.pixelRatio,this.pickingDownSizingRatio),s=nt.apply(void 0,wi(o)),u=this.itemIDsIndex[s];return u&&u.type==="node"?u.id:null}},{key:"bindEventHandlers",value:function(){var e=this;this.activeListeners.handleResize=function(){e.scheduleRefresh()},window.addEventListener("resize",this.activeListeners.handleResize),this.activeListeners.handleMove=function(a){var o=xe(a),s={event:o,preventSigmaDefault:function(){o.preventSigmaDefault()}},u=e.getNodeAtPosition(o);if(u&&e.hoveredNode!==u&&!e.nodeDataCache[u].hidden){e.hoveredNode&&e.emit("leaveNode",_(_({},s),{},{node:e.hoveredNode})),e.hoveredNode=u,e.emit("enterNode",_(_({},s),{},{node:u})),e.scheduleHighlightedNodesRender();return}if(e.hoveredNode&&e.getNodeAtPosition(o)!==e.hoveredNode){var h=e.hoveredNode;e.hoveredNode=null,e.emit("leaveNode",_(_({},s),{},{node:h})),e.scheduleHighlightedNodesRender();return}if(e.settings.enableEdgeEvents){var d=e.hoveredNode?null:e.getEdgeAtPoint(s.event.x,s.event.y);d!==e.hoveredEdge&&(e.hoveredEdge&&e.emit("leaveEdge",_(_({},s),{},{edge:e.hoveredEdge})),d&&e.emit("enterEdge",_(_({},s),{},{edge:d})),e.hoveredEdge=d)}},this.activeListeners.handleMoveBody=function(a){var o=xe(a);e.emit("moveBody",{event:o,preventSigmaDefault:function(){o.preventSigmaDefault()}})},this.activeListeners.handleLeave=function(a){var o=xe(a),s={event:o,preventSigmaDefault:function(){o.preventSigmaDefault()}};e.hoveredNode&&(e.emit("leaveNode",_(_({},s),{},{node:e.hoveredNode})),e.scheduleHighlightedNodesRender()),e.settings.enableEdgeEvents&&e.hoveredEdge&&(e.emit("leaveEdge",_(_({},s),{},{edge:e.hoveredEdge})),e.scheduleHighlightedNodesRender()),e.emit("leaveStage",_({},s))},this.activeListeners.handleEnter=function(a){var o=xe(a),s={event:o,preventSigmaDefault:function(){o.preventSigmaDefault()}};e.emit("enterStage",_({},s))};var r=function(o){return function(s){var u=xe(s),h={event:u,preventSigmaDefault:function(){u.preventSigmaDefault()}},d=e.getNodeAtPosition(u);if(d)return e.emit("".concat(o,"Node"),_(_({},h),{},{node:d}));if(e.settings.enableEdgeEvents){var c=e.getEdgeAtPoint(u.x,u.y);if(c)return e.emit("".concat(o,"Edge"),_(_({},h),{},{edge:c}))}return e.emit("".concat(o,"Stage"),h)}};return this.activeListeners.handleClick=r("click"),this.activeListeners.handleRightClick=r("rightClick"),this.activeListeners.handleDoubleClick=r("doubleClick"),this.activeListeners.handleWheel=r("wheel"),this.activeListeners.handleDown=r("down"),this.activeListeners.handleUp=r("up"),this.mouseCaptor.on("mousemove",this.activeListeners.handleMove),this.mouseCaptor.on("mousemovebody",this.activeListeners.handleMoveBody),this.mouseCaptor.on("click",this.activeListeners.handleClick),this.mouseCaptor.on("rightClick",this.activeListeners.handleRightClick),this.mouseCaptor.on("doubleClick",this.activeListeners.handleDoubleClick),this.mouseCaptor.on("wheel",this.activeListeners.handleWheel),this.mouseCaptor.on("mousedown",this.activeListeners.handleDown),this.mouseCaptor.on("mouseup",this.activeListeners.handleUp),this.mouseCaptor.on("mouseleave",this.activeListeners.handleLeave),this.mouseCaptor.on("mouseenter",this.activeListeners.handleEnter),this.touchCaptor.on("touchdown",this.activeListeners.handleDown),this.touchCaptor.on("touchdown",this.activeListeners.handleMove),this.touchCaptor.on("touchup",this.activeListeners.handleUp),this.touchCaptor.on("touchmove",this.activeListeners.handleMove),this.touchCaptor.on("tap",this.activeListeners.handleClick),this.touchCaptor.on("doubletap",this.activeListeners.handleDoubleClick),this.touchCaptor.on("touchmove",this.activeListeners.handleMoveBody),this}},{key:"bindGraphHandlers",value:function(){var e=this,r=this.graph,a=new Set(["x","y","zIndex","type"]);return this.activeListeners.eachNodeAttributesUpdatedGraphUpdate=function(o){var s,u=(s=o.hints)===null||s===void 0?void 0:s.attributes;e.graph.forEachNode(function(d){return e.updateNode(d)});var h=!u||u.some(function(d){return a.has(d)});e.refresh({partialGraph:{nodes:r.nodes()},skipIndexation:!h,schedule:!0})},this.activeListeners.eachEdgeAttributesUpdatedGraphUpdate=function(o){var s,u=(s=o.hints)===null||s===void 0?void 0:s.attributes;e.graph.forEachEdge(function(d){return e.updateEdge(d)});var h=u&&["zIndex","type"].some(function(d){return u?.includes(d)});e.refresh({partialGraph:{edges:r.edges()},skipIndexation:!h,schedule:!0})},this.activeListeners.addNodeGraphUpdate=function(o){var s=o.key;e.addNode(s),e.refresh({partialGraph:{nodes:[s]},skipIndexation:!1,schedule:!0})},this.activeListeners.updateNodeGraphUpdate=function(o){var s=o.key;e.refresh({partialGraph:{nodes:[s]},skipIndexation:!1,schedule:!0})},this.activeListeners.dropNodeGraphUpdate=function(o){var s=o.key;e.removeNode(s),e.refresh({schedule:!0})},this.activeListeners.addEdgeGraphUpdate=function(o){var s=o.key;e.addEdge(s),e.refresh({partialGraph:{edges:[s]},schedule:!0})},this.activeListeners.updateEdgeGraphUpdate=function(o){var s=o.key;e.refresh({partialGraph:{edges:[s]},skipIndexation:!1,schedule:!0})},this.activeListeners.dropEdgeGraphUpdate=function(o){var s=o.key;e.removeEdge(s),e.refresh({schedule:!0})},this.activeListeners.clearEdgesGraphUpdate=function(){e.clearEdgeState(),e.clearEdgeIndices(),e.refresh({schedule:!0})},this.activeListeners.clearGraphUpdate=function(){e.clearEdgeState(),e.clearNodeState(),e.clearEdgeIndices(),e.clearNodeIndices(),e.refresh({schedule:!0})},r.on("nodeAdded",this.activeListeners.addNodeGraphUpdate),r.on("nodeDropped",this.activeListeners.dropNodeGraphUpdate),r.on("nodeAttributesUpdated",this.activeListeners.updateNodeGraphUpdate),r.on("eachNodeAttributesUpdated",this.activeListeners.eachNodeAttributesUpdatedGraphUpdate),r.on("edgeAdded",this.activeListeners.addEdgeGraphUpdate),r.on("edgeDropped",this.activeListeners.dropEdgeGraphUpdate),r.on("edgeAttributesUpdated",this.activeListeners.updateEdgeGraphUpdate),r.on("eachEdgeAttributesUpdated",this.activeListeners.eachEdgeAttributesUpdatedGraphUpdate),r.on("edgesCleared",this.activeListeners.clearEdgesGraphUpdate),r.on("cleared",this.activeListeners.clearGraphUpdate),this}},{key:"unbindGraphHandlers",value:function(){var e=this.graph;e.removeListener("nodeAdded",this.activeListeners.addNodeGraphUpdate),e.removeListener("nodeDropped",this.activeListeners.dropNodeGraphUpdate),e.removeListener("nodeAttributesUpdated",this.activeListeners.updateNodeGraphUpdate),e.removeListener("eachNodeAttributesUpdated",this.activeListeners.eachNodeAttributesUpdatedGraphUpdate),e.removeListener("edgeAdded",this.activeListeners.addEdgeGraphUpdate),e.removeListener("edgeDropped",this.activeListeners.dropEdgeGraphUpdate),e.removeListener("edgeAttributesUpdated",this.activeListeners.updateEdgeGraphUpdate),e.removeListener("eachEdgeAttributesUpdated",this.activeListeners.eachEdgeAttributesUpdatedGraphUpdate),e.removeListener("edgesCleared",this.activeListeners.clearEdgesGraphUpdate),e.removeListener("cleared",this.activeListeners.clearGraphUpdate)}},{key:"getEdgeAtPoint",value:function(e,r){var a=at(this.webGLContexts.edges,this.frameBuffers.edges,e,r,this.pixelRatio,this.pickingDownSizingRatio),o=nt.apply(void 0,wi(a)),s=this.itemIDsIndex[o];return s&&s.type==="edge"?s.id:null}},{key:"process",value:function(){var e=this;this.emit("beforeProcess");var r=this.graph,a=this.settings,o=this.getDimensions();if(this.nodeExtent=pi(this.graph),!this.settings.autoRescale){var s=o.width,u=o.height,h=this.nodeExtent,d=h.x,c=h.y;this.nodeExtent={x:[(d[0]+d[1])/2-s/2,(d[0]+d[1])/2+s/2],y:[(c[0]+c[1])/2-u/2,(c[0]+c[1])/2+u/2]}}this.normalizationFunction=pt(this.customBBox||this.nodeExtent);var l=new bi,f=ge(l.getState(),o,this.getGraphDimensions(),this.getStagePadding());this.labelGrid.resizeAndClear(o,a.labelGridCellSize);for(var p={},v={},y={},T={},w=1,E=r.nodes(),A=0,L=E.length;A<L;A++){var R=E[A],S=this.nodeDataCache[R],j=r.getNodeAttributes(R);S.x=j.x,S.y=j.y,this.normalizationFunction.applyTo(S),typeof S.label=="string"&&!S.hidden&&this.labelGrid.add(R,S.size,this.framedGraphToViewport(S,{matrix:f})),p[S.type]=(p[S.type]||0)+1}this.labelGrid.organize();for(var O in this.nodePrograms){if(!X.call(this.nodePrograms,O))throw new Error('Sigma: could not find a suitable program for node type "'.concat(O,'"!'));this.nodePrograms[O].reallocate(p[O]||0),p[O]=0}this.settings.zIndex&&this.nodeZExtent[0]!==this.nodeZExtent[1]&&(E=gt(this.nodeZExtent,function(Xe){return e.nodeDataCache[Xe].zIndex},E));for(var M=0,z=E.length;M<z;M++){var U=E[M];v[U]=w,T[v[U]]={type:"node",id:U},w++;var ae=this.nodeDataCache[U];this.addNodeToProgram(U,v[U],p[ae.type]++)}for(var $={},V=r.edges(),ee=0,Re=V.length;ee<Re;ee++){var de=V[ee],oe=this.edgeDataCache[de];$[oe.type]=($[oe.type]||0)+1}this.settings.zIndex&&this.edgeZExtent[0]!==this.edgeZExtent[1]&&(V=gt(this.edgeZExtent,function(Xe){return e.edgeDataCache[Xe].zIndex},V));for(var te in this.edgePrograms){if(!X.call(this.edgePrograms,te))throw new Error('Sigma: could not find a suitable program for edge type "'.concat(te,'"!'));this.edgePrograms[te].reallocate($[te]||0),$[te]=0}for(var ie=0,Ze=V.length;ie<Ze;ie++){var q=V[ie];y[q]=w,T[y[q]]={type:"edge",id:q},w++;var Oi=this.edgeDataCache[q];this.addEdgeToProgram(q,y[q],$[Oi.type]++)}return this.itemIDsIndex=T,this.nodeIndices=v,this.edgeIndices=y,this.emit("afterProcess"),this}},{key:"handleSettingsUpdate",value:function(e){var r=this,a=this.settings;if(this.camera.minRatio=a.minCameraRatio,this.camera.maxRatio=a.maxCameraRatio,this.camera.enabledZooming=a.enableCameraZooming,this.camera.enabledPanning=a.enableCameraPanning,this.camera.enabledRotation=a.enableCameraRotation,a.cameraPanBoundaries?this.camera.clean=function(d){return r.cleanCameraState(d,a.cameraPanBoundaries&&Ue(a.cameraPanBoundaries)==="object"?a.cameraPanBoundaries:{})}:this.camera.clean=null,this.camera.setState(this.camera.validateState(this.camera.getState())),e){if(e.edgeProgramClasses!==a.edgeProgramClasses){for(var o in a.edgeProgramClasses)a.edgeProgramClasses[o]!==e.edgeProgramClasses[o]&&this.registerEdgeProgram(o,a.edgeProgramClasses[o]);for(var s in e.edgeProgramClasses)a.edgeProgramClasses[s]||this.unregisterEdgeProgram(s)}if(e.nodeProgramClasses!==a.nodeProgramClasses||e.nodeHoverProgramClasses!==a.nodeHoverProgramClasses){for(var u in a.nodeProgramClasses)(a.nodeProgramClasses[u]!==e.nodeProgramClasses[u]||a.nodeHoverProgramClasses[u]!==e.nodeHoverProgramClasses[u])&&this.registerNodeProgram(u,a.nodeProgramClasses[u],a.nodeHoverProgramClasses[u]);for(var h in e.nodeProgramClasses)a.nodeProgramClasses[h]||this.unregisterNodeProgram(h)}}return this.mouseCaptor.setSettings(this.settings),this.touchCaptor.setSettings(this.settings),this}},{key:"cleanCameraState",value:function(e){var r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},a=r.tolerance,o=a===void 0?0:a,s=r.boundaries,u=_({},e),h=s||this.nodeExtent,d=re(h.x,2),c=d[0],l=d[1],f=re(h.y,2),p=f[0],v=f[1],y=[this.graphToViewport({x:c,y:p},{cameraState:e}),this.graphToViewport({x:l,y:p},{cameraState:e}),this.graphToViewport({x:c,y:v},{cameraState:e}),this.graphToViewport({x:l,y:v},{cameraState:e})],T=1/0,w=-1/0,E=1/0,A=-1/0;y.forEach(function($){var V=$.x,ee=$.y;T=Math.min(T,V),w=Math.max(w,V),E=Math.min(E,ee),A=Math.max(A,ee)});var L=w-T,R=A-E,S=this.getDimensions(),j=S.width,O=S.height,M=0,z=0;if(L>=j?w<j-o?M=w-(j-o):T>o&&(M=T-o):w>j+o?M=w-(j+o):T<-o&&(M=T+o),R>=O?A<O-o?z=A-(O-o):E>o&&(z=E-o):A>O+o?z=A-(O+o):E<-o&&(z=E+o),M||z){var U=this.viewportToFramedGraph({x:0,y:0},{cameraState:e}),ae=this.viewportToFramedGraph({x:M,y:z},{cameraState:e});M=ae.x-U.x,z=ae.y-U.y,u.x+=M,u.y+=z}return u}},{key:"renderLabels",value:function(){if(!this.settings.renderLabels)return this;var e=this.camera.getState(),r=this.labelGrid.getLabelsToDisplay(e.ratio,this.settings.labelDensity);mt(r,this.nodesWithForcedLabels),this.displayedNodeLabels=new Set;for(var a=this.canvasContexts.labels,o=0,s=r.length;o<s;o++){var u=r[o],h=this.nodeDataCache[u];if(!this.displayedNodeLabels.has(u)&&!h.hidden){var d=this.framedGraphToViewport(h),c=d.x,l=d.y,f=this.scaleSize(h.size);if(!(!h.forceLabel&&f<this.settings.labelRenderedSizeThreshold)&&!(c<-xi||c>this.width+xi||l<-Ti||l>this.height+Ti)){this.displayedNodeLabels.add(u);var p=this.settings.defaultDrawNodeLabel,v=this.nodePrograms[h.type],y=v?.drawLabel||p;y(a,_(_({key:u},h),{},{size:f,x:c,y:l}),this.settings)}}}return this}},{key:"renderEdgeLabels",value:function(){if(!this.settings.renderEdgeLabels)return this;var e=this.canvasContexts.edgeLabels;e.clearRect(0,0,this.width,this.height);var r=on({graph:this.graph,hoveredNode:this.hoveredNode,displayedNodeLabels:this.displayedNodeLabels,highlightedNodes:this.highlightedNodes});mt(r,this.edgesWithForcedLabels);for(var a=new Set,o=0,s=r.length;o<s;o++){var u=r[o],h=this.graph.extremities(u),d=this.nodeDataCache[h[0]],c=this.nodeDataCache[h[1]],l=this.edgeDataCache[u];if(!a.has(u)&&!(l.hidden||d.hidden||c.hidden)){var f=this.settings.defaultDrawEdgeLabel,p=this.edgePrograms[l.type],v=p?.drawLabel||f;v(e,_(_({key:u},l),{},{size:this.scaleSize(l.size)}),_(_(_({key:h[0]},d),this.framedGraphToViewport(d)),{},{size:this.scaleSize(d.size)}),_(_(_({key:h[1]},c),this.framedGraphToViewport(c)),{},{size:this.scaleSize(c.size)}),this.settings),a.add(u)}}return this.displayedEdgeLabels=a,this}},{key:"renderHighlightedNodes",value:function(){var e=this,r=this.canvasContexts.hovers;r.clearRect(0,0,this.width,this.height);var a=function(f){var p=e.nodeDataCache[f],v=e.framedGraphToViewport(p),y=v.x,T=v.y,w=e.scaleSize(p.size),E=e.settings.defaultDrawNodeHover,A=e.nodePrograms[p.type],L=A?.drawHover||E;L(r,_(_({key:f},p),{},{size:w,x:y,y:T}),e.settings)},o=[];this.hoveredNode&&!this.nodeDataCache[this.hoveredNode].hidden&&o.push(this.hoveredNode),this.highlightedNodes.forEach(function(l){l!==e.hoveredNode&&o.push(l)}),o.forEach(function(l){return a(l)});var s={};o.forEach(function(l){var f=e.nodeDataCache[l].type;s[f]=(s[f]||0)+1});for(var u in this.nodeHoverPrograms)this.nodeHoverPrograms[u].reallocate(s[u]||0),s[u]=0;o.forEach(function(l){var f=e.nodeDataCache[l];e.nodeHoverPrograms[f.type].process(0,s[f.type]++,f)}),this.webGLContexts.hoverNodes.clear(this.webGLContexts.hoverNodes.COLOR_BUFFER_BIT);var h=this.getRenderParams();for(var d in this.nodeHoverPrograms){var c=this.nodeHoverPrograms[d];c.render(h)}}},{key:"scheduleHighlightedNodesRender",value:function(){var e=this;this.renderHighlightedNodesFrame||this.renderFrame||(this.renderHighlightedNodesFrame=requestAnimationFrame(function(){e.renderHighlightedNodesFrame=null,e.renderHighlightedNodes(),e.renderEdgeLabels()}))}},{key:"render",value:function(){var e=this;this.emit("beforeRender");var r=function(){return e.emit("afterRender"),e};if(this.renderFrame&&(cancelAnimationFrame(this.renderFrame),this.renderFrame=null),this.resize(),this.needToProcess&&this.process(),this.needToProcess=!1,this.clear(),this.pickingLayers.forEach(function(y){return e.resetWebGLTexture(y)}),!this.graph.order)return r();var a=this.mouseCaptor,o=this.camera.isAnimated()||a.isMoving||a.draggedEvents||a.currentWheelDirection,s=this.camera.getState(),u=this.getDimensions(),h=this.getGraphDimensions(),d=this.getStagePadding();this.matrix=ge(s,u,h,d),this.invMatrix=ge(s,u,h,d,!0),this.correctionRatio=gi(this.matrix,s,u),this.graphToViewportRatio=this.getGraphToViewportRatio();var c=this.getRenderParams();for(var l in this.nodePrograms){var f=this.nodePrograms[l];f.render(c)}if(!this.settings.hideEdgesOnMove||!o)for(var p in this.edgePrograms){var v=this.edgePrograms[p];v.render(c)}return this.settings.hideLabelsOnMove&&o||(this.renderLabels(),this.renderEdgeLabels(),this.renderHighlightedNodes()),r()}},{key:"addNode",value:function(e){var r=Object.assign({},this.graph.getNodeAttributes(e));this.settings.nodeReducer&&(r=this.settings.nodeReducer(e,r));var a=sn(this.settings,e,r);this.nodeDataCache[e]=a,this.nodesWithForcedLabels.delete(e),a.forceLabel&&!a.hidden&&this.nodesWithForcedLabels.add(e),this.highlightedNodes.delete(e),a.highlighted&&!a.hidden&&this.highlightedNodes.add(e),this.settings.zIndex&&(a.zIndex<this.nodeZExtent[0]&&(this.nodeZExtent[0]=a.zIndex),a.zIndex>this.nodeZExtent[1]&&(this.nodeZExtent[1]=a.zIndex))}},{key:"updateNode",value:function(e){this.addNode(e);var r=this.nodeDataCache[e];this.normalizationFunction.applyTo(r)}},{key:"removeNode",value:function(e){delete this.nodeDataCache[e],delete this.nodeProgramIndex[e],this.highlightedNodes.delete(e),this.hoveredNode===e&&(this.hoveredNode=null),this.nodesWithForcedLabels.delete(e)}},{key:"addEdge",value:function(e){var r=Object.assign({},this.graph.getEdgeAttributes(e));this.settings.edgeReducer&&(r=this.settings.edgeReducer(e,r));var a=un(this.settings,e,r);this.edgeDataCache[e]=a,this.edgesWithForcedLabels.delete(e),a.forceLabel&&!a.hidden&&this.edgesWithForcedLabels.add(e),this.settings.zIndex&&(a.zIndex<this.edgeZExtent[0]&&(this.edgeZExtent[0]=a.zIndex),a.zIndex>this.edgeZExtent[1]&&(this.edgeZExtent[1]=a.zIndex))}},{key:"updateEdge",value:function(e){this.addEdge(e)}},{key:"removeEdge",value:function(e){delete this.edgeDataCache[e],delete this.edgeProgramIndex[e],this.hoveredEdge===e&&(this.hoveredEdge=null),this.edgesWithForcedLabels.delete(e)}},{key:"clearNodeIndices",value:function(){this.labelGrid=new _i,this.nodeExtent={x:[0,1],y:[0,1]},this.nodeDataCache={},this.edgeProgramIndex={},this.nodesWithForcedLabels=new Set,this.nodeZExtent=[1/0,-1/0],this.highlightedNodes=new Set}},{key:"clearEdgeIndices",value:function(){this.edgeDataCache={},this.edgeProgramIndex={},this.edgesWithForcedLabels=new Set,this.edgeZExtent=[1/0,-1/0]}},{key:"clearIndices",value:function(){this.clearEdgeIndices(),this.clearNodeIndices()}},{key:"clearNodeState",value:function(){this.displayedNodeLabels=new Set,this.highlightedNodes=new Set,this.hoveredNode=null}},{key:"clearEdgeState",value:function(){this.displayedEdgeLabels=new Set,this.highlightedNodes=new Set,this.hoveredEdge=null}},{key:"clearState",value:function(){this.clearEdgeState(),this.clearNodeState()}},{key:"addNodeToProgram",value:function(e,r,a){var o=this.nodeDataCache[e],s=this.nodePrograms[o.type];if(!s)throw new Error('Sigma: could not find a suitable program for node type "'.concat(o.type,'"!'));s.process(r,a,o),this.nodeProgramIndex[e]=a}},{key:"addEdgeToProgram",value:function(e,r,a){var o=this.edgeDataCache[e],s=this.edgePrograms[o.type];if(!s)throw new Error('Sigma: could not find a suitable program for edge type "'.concat(o.type,'"!'));var u=this.graph.extremities(e),h=this.nodeDataCache[u[0]],d=this.nodeDataCache[u[1]];s.process(r,a,h,d,o),this.edgeProgramIndex[e]=a}},{key:"getRenderParams",value:function(){return{matrix:this.matrix,invMatrix:this.invMatrix,width:this.width,height:this.height,pixelRatio:this.pixelRatio,zoomRatio:this.camera.ratio,cameraAngle:this.camera.angle,sizeRatio:1/this.scaleSize(),correctionRatio:this.correctionRatio,downSizingRatio:this.pickingDownSizingRatio,minEdgeThickness:this.settings.minEdgeThickness,antiAliasingFeather:this.settings.antiAliasingFeather}}},{key:"getStagePadding",value:function(){var e=this.settings,r=e.stagePadding,a=e.autoRescale;return a&&r||0}},{key:"createLayer",value:function(e,r){var a=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};if(this.elements[e])throw new Error('Sigma: a layer named "'.concat(e,'" already exists'));var o=vi(r,{position:"absolute"},{class:"sigma-".concat(e)});return a.style&&Object.assign(o.style,a.style),this.elements[e]=o,"beforeLayer"in a&&a.beforeLayer?this.elements[a.beforeLayer].before(o):"afterLayer"in a&&a.afterLayer?this.elements[a.afterLayer].after(o):this.container.appendChild(o),o}},{key:"createCanvas",value:function(e){var r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return this.createLayer(e,"canvas",r)}},{key:"createCanvasContext",value:function(e){var r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},a=this.createCanvas(e,r),o={preserveDrawingBuffer:!1,antialias:!1};return this.canvasContexts[e]=a.getContext("2d",o),this}},{key:"createWebGLContext",value:function(e){var r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},a=r?.canvas||this.createCanvas(e,r);r.hidden&&a.remove();var o=_({preserveDrawingBuffer:!1,antialias:!1},r),s;s=a.getContext("webgl2",o),s||(s=a.getContext("webgl",o)),s||(s=a.getContext("experimental-webgl",o));var u=s;if(this.webGLContexts[e]=u,u.blendFunc(u.ONE,u.ONE_MINUS_SRC_ALPHA),r.picking){this.pickingLayers.add(e);var h=u.createFramebuffer();if(!h)throw new Error("Sigma: cannot create a new frame buffer for layer ".concat(e));this.frameBuffers[e]=h}return u}},{key:"killLayer",value:function(e){var r=this.elements[e];if(!r)throw new Error("Sigma: cannot kill layer ".concat(e,", which does not exist"));if(this.webGLContexts[e]){var a,o=this.webGLContexts[e];(a=o.getExtension("WEBGL_lose_context"))===null||a===void 0||a.loseContext(),delete this.webGLContexts[e]}else this.canvasContexts[e]&&delete this.canvasContexts[e];return r.remove(),delete this.elements[e],this}},{key:"getCamera",value:function(){return this.camera}},{key:"setCamera",value:function(e){this.unbindCameraHandlers(),this.camera=e,this.bindCameraHandlers()}},{key:"getContainer",value:function(){return this.container}},{key:"getGraph",value:function(){return this.graph}},{key:"setGraph",value:function(e){e!==this.graph&&(this.hoveredNode&&!e.hasNode(this.hoveredNode)&&(this.hoveredNode=null),this.hoveredEdge&&!e.hasEdge(this.hoveredEdge)&&(this.hoveredEdge=null),this.unbindGraphHandlers(),this.checkEdgesEventsFrame!==null&&(cancelAnimationFrame(this.checkEdgesEventsFrame),this.checkEdgesEventsFrame=null),this.graph=e,this.bindGraphHandlers(),this.refresh())}},{key:"getMouseCaptor",value:function(){return this.mouseCaptor}},{key:"getTouchCaptor",value:function(){return this.touchCaptor}},{key:"getDimensions",value:function(){return{width:this.width,height:this.height}}},{key:"getGraphDimensions",value:function(){var e=this.customBBox||this.nodeExtent;return{width:e.x[1]-e.x[0]||1,height:e.y[1]-e.y[0]||1}}},{key:"getNodeDisplayData",value:function(e){var r=this.nodeDataCache[e];return r?Object.assign({},r):void 0}},{key:"getEdgeDisplayData",value:function(e){var r=this.edgeDataCache[e];return r?Object.assign({},r):void 0}},{key:"getNodeDisplayedLabels",value:function(){return new Set(this.displayedNodeLabels)}},{key:"getEdgeDisplayedLabels",value:function(){return new Set(this.displayedEdgeLabels)}},{key:"getSettings",value:function(){return _({},this.settings)}},{key:"getSetting",value:function(e){return this.settings[e]}},{key:"setSetting",value:function(e,r){var a=_({},this.settings);return this.settings[e]=r,ze(this.settings),this.handleSettingsUpdate(a),this.scheduleRefresh(),this}},{key:"updateSetting",value:function(e,r){return this.setSetting(e,r(this.settings[e])),this}},{key:"setSettings",value:function(e){var r=_({},this.settings);return this.settings=_(_({},this.settings),e),ze(this.settings),this.handleSettingsUpdate(r),this.scheduleRefresh(),this}},{key:"resize",value:function(e){var r=this.width,a=this.height;if(this.width=this.container.offsetWidth,this.height=this.container.offsetHeight,this.pixelRatio=ft(),this.width===0)if(this.settings.allowInvalidContainer)this.width=1;else throw new Error("Sigma: Container has no width. You can set the allowInvalidContainer setting to true to stop seeing this error.");if(this.height===0)if(this.settings.allowInvalidContainer)this.height=1;else throw new Error("Sigma: Container has no height. You can set the allowInvalidContainer setting to true to stop seeing this error.");if(!e&&r===this.width&&a===this.height)return this;for(var o in this.elements){var s=this.elements[o];s.style.width=this.width+"px",s.style.height=this.height+"px"}for(var u in this.canvasContexts)this.elements[u].setAttribute("width",this.width*this.pixelRatio+"px"),this.elements[u].setAttribute("height",this.height*this.pixelRatio+"px"),this.pixelRatio!==1&&this.canvasContexts[u].scale(this.pixelRatio,this.pixelRatio);for(var h in this.webGLContexts){this.elements[h].setAttribute("width",this.width*this.pixelRatio+"px"),this.elements[h].setAttribute("height",this.height*this.pixelRatio+"px");var d=this.webGLContexts[h];if(d.viewport(0,0,this.width*this.pixelRatio,this.height*this.pixelRatio),this.pickingLayers.has(h)){var c=this.textures[h];c&&d.deleteTexture(c)}}return this.emit("resize"),this}},{key:"clear",value:function(){return this.emit("beforeClear"),this.webGLContexts.nodes.bindFramebuffer(WebGLRenderingContext.FRAMEBUFFER,null),this.webGLContexts.nodes.clear(WebGLRenderingContext.COLOR_BUFFER_BIT),this.webGLContexts.edges.bindFramebuffer(WebGLRenderingContext.FRAMEBUFFER,null),this.webGLContexts.edges.clear(WebGLRenderingContext.COLOR_BUFFER_BIT),this.webGLContexts.hoverNodes.clear(WebGLRenderingContext.COLOR_BUFFER_BIT),this.canvasContexts.labels.clearRect(0,0,this.width,this.height),this.canvasContexts.hovers.clearRect(0,0,this.width,this.height),this.canvasContexts.edgeLabels.clearRect(0,0,this.width,this.height),this.emit("afterClear"),this}},{key:"refresh",value:function(e){var r=this,a=e?.skipIndexation!==void 0?e?.skipIndexation:!1,o=e?.schedule!==void 0?e.schedule:!1,s=!e||!e.partialGraph;if(s)this.clearEdgeIndices(),this.clearNodeIndices(),this.graph.forEachNode(function(A){return r.addNode(A)}),this.graph.forEachEdge(function(A){return r.addEdge(A)});else{for(var u,h,d=((u=e.partialGraph)===null||u===void 0?void 0:u.nodes)||[],c=0,l=d?.length||0;c<l;c++){var f=d[c];if(this.updateNode(f),a){var p=this.nodeProgramIndex[f];if(p===void 0)throw new Error('Sigma: node "'.concat(f,`" can't be repaint`));this.addNodeToProgram(f,this.nodeIndices[f],p)}}for(var v=(e==null||(h=e.partialGraph)===null||h===void 0?void 0:h.edges)||[],y=0,T=v.length;y<T;y++){var w=v[y];if(this.updateEdge(w),a){var E=this.edgeProgramIndex[w];if(E===void 0)throw new Error('Sigma: edge "'.concat(w,`" can't be repaint`));this.addEdgeToProgram(w,this.edgeIndices[w],E)}}}return(s||!a)&&(this.needToProcess=!0),o?this.scheduleRender():this.render(),this}},{key:"scheduleRender",value:function(){var e=this;return this.renderFrame||(this.renderFrame=requestAnimationFrame(function(){e.render()})),this}},{key:"scheduleRefresh",value:function(e){return this.refresh(_(_({},e),{},{schedule:!0}))}},{key:"getViewportZoomedState",value:function(e,r){var a=this.camera.getState(),o=a.ratio,s=a.angle,u=a.x,h=a.y,d=this.settings,c=d.minCameraRatio,l=d.maxCameraRatio;typeof l=="number"&&(r=Math.min(r,l)),typeof c=="number"&&(r=Math.max(r,c));var f=r/o,p={x:this.width/2,y:this.height/2},v=this.viewportToFramedGraph(e),y=this.viewportToFramedGraph(p);return{angle:s,x:(v.x-y.x)*(1-f)+u,y:(v.y-y.y)*(1-f)+h,ratio:r}}},{key:"viewRectangle",value:function(){var e=this.viewportToFramedGraph({x:0,y:0}),r=this.viewportToFramedGraph({x:this.width,y:0}),a=this.viewportToFramedGraph({x:0,y:this.height});return{x1:e.x,y1:e.y,x2:r.x,y2:r.y,height:r.y-a.y}}},{key:"framedGraphToViewport",value:function(e){var r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},a=!!r.cameraState||!!r.viewportDimensions||!!r.graphDimensions,o=r.matrix?r.matrix:a?ge(r.cameraState||this.camera.getState(),r.viewportDimensions||this.getDimensions(),r.graphDimensions||this.getGraphDimensions(),r.padding||this.getStagePadding()):this.matrix,s=Me(o,e);return{x:(1+s.x)*this.width/2,y:(1-s.y)*this.height/2}}},{key:"viewportToFramedGraph",value:function(e){var r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},a=!!r.cameraState||!!r.viewportDimensions||!r.graphDimensions,o=r.matrix?r.matrix:a?ge(r.cameraState||this.camera.getState(),r.viewportDimensions||this.getDimensions(),r.graphDimensions||this.getGraphDimensions(),r.padding||this.getStagePadding(),!0):this.invMatrix,s=Me(o,{x:e.x/this.width*2-1,y:1-e.y/this.height*2});return isNaN(s.x)&&(s.x=0),isNaN(s.y)&&(s.y=0),s}},{key:"viewportToGraph",value:function(e){var r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return this.normalizationFunction.inverse(this.viewportToFramedGraph(e,r))}},{key:"graphToViewport",value:function(e){var r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return this.framedGraphToViewport(this.normalizationFunction(e),r)}},{key:"getGraphToViewportRatio",value:function(){var e={x:0,y:0},r={x:1,y:1},a=Math.sqrt(Math.pow(e.x-r.x,2)+Math.pow(e.y-r.y,2)),o=this.graphToViewport(e),s=this.graphToViewport(r),u=Math.sqrt(Math.pow(o.x-s.x,2)+Math.pow(o.y-s.y,2));return u/a}},{key:"getBBox",value:function(){return this.nodeExtent}},{key:"getCustomBBox",value:function(){return this.customBBox}},{key:"setCustomBBox",value:function(e){return this.customBBox=e,this.scheduleRender(),this}},{key:"kill",value:function(){this.emit("kill"),this.removeAllListeners(),this.unbindCameraHandlers(),window.removeEventListener("resize",this.activeListeners.handleResize),this.mouseCaptor.kill(),this.touchCaptor.kill(),this.unbindGraphHandlers(),this.clearIndices(),this.clearState(),this.nodeDataCache={},this.edgeDataCache={},this.highlightedNodes.clear(),this.renderFrame&&(cancelAnimationFrame(this.renderFrame),this.renderFrame=null),this.renderHighlightedNodesFrame&&(cancelAnimationFrame(this.renderHighlightedNodesFrame),this.renderHighlightedNodesFrame=null);for(var e=this.container;e.firstChild;)e.removeChild(e.firstChild);for(var r in this.nodePrograms)this.nodePrograms[r].kill();for(var a in this.nodeHoverPrograms)this.nodeHoverPrograms[a].kill();for(var o in this.edgePrograms)this.edgePrograms[o].kill();this.nodePrograms={},this.nodeHoverPrograms={},this.edgePrograms={};for(var s in this.elements)this.killLayer(s);this.canvasContexts={},this.webGLContexts={},this.elements={}}},{key:"scaleSize",value:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:1,r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this.camera.ratio;return e/this.settings.zoomToSizeRatioFunction(r)*(this.getSetting("itemSizesReference")==="positions"?r*this.graphToViewportRatio:1)}},{key:"getCanvases",value:function(){var e={};for(var r in this.elements)this.elements[r]instanceof HTMLCanvasElement&&(e[r]=this.elements[r]);return e}}])})(Pe),dn=hn;var Li=be(Fe(),1);function cn(){let n=arguments[0];for(let i=1,t=arguments.length;i<t;i++)if(arguments[i])for(let e in arguments[i])n[e]=arguments[i][e];return n}var G=cn;typeof Object.assign=="function"&&(G=Object.assign);function W(n,i,t,e){let r=n._nodes.get(i),a=null;return r&&(e==="mixed"?a=r.out&&r.out[t]||r.undirected&&r.undirected[t]:e==="directed"?a=r.out&&r.out[t]:a=r.undirected&&r.undirected[t]),a}function F(n){return typeof n=="object"&&n!==null}function Di(n){let i;for(i in n)return!1;return!0}function H(n,i,t){Object.defineProperty(n,i,{enumerable:!1,configurable:!1,writable:!0,value:t})}function Y(n,i,t){let e={enumerable:!0,configurable:!0};typeof t=="function"?e.get=t:(e.value=t,e.writable=!1),Object.defineProperty(n,i,e)}function Ci(n){return!(!F(n)||n.attributes&&!Array.isArray(n.attributes))}function ln(){let n=Math.floor(Math.random()*256)&255;return()=>n++}function J(){let n=arguments,i=null,t=-1;return{[Symbol.iterator](){return this},next(){let e=null;do{if(i===null){if(t++,t>=n.length)return{done:!0};i=n[t][Symbol.iterator]()}if(e=i.next(),e.done){i=null;continue}break}while(!0);return e}}}function me(){return{[Symbol.iterator](){return this},next(){return{done:!0}}}}var Ce=class extends Error{constructor(i){super(),this.name="GraphError",this.message=i}},b=class n extends Ce{constructor(i){super(i),this.name="InvalidArgumentsGraphError",typeof Error.captureStackTrace=="function"&&Error.captureStackTrace(this,n.prototype.constructor)}},m=class n extends Ce{constructor(i){super(i),this.name="NotFoundGraphError",typeof Error.captureStackTrace=="function"&&Error.captureStackTrace(this,n.prototype.constructor)}},x=class n extends Ce{constructor(i){super(i),this.name="UsageGraphError",typeof Error.captureStackTrace=="function"&&Error.captureStackTrace(this,n.prototype.constructor)}};function Ni(n,i){this.key=n,this.attributes=i,this.clear()}Ni.prototype.clear=function(){this.inDegree=0,this.outDegree=0,this.undirectedDegree=0,this.undirectedLoops=0,this.directedLoops=0,this.in={},this.out={},this.undirected={}};function Gi(n,i){this.key=n,this.attributes=i,this.clear()}Gi.prototype.clear=function(){this.inDegree=0,this.outDegree=0,this.directedLoops=0,this.in={},this.out={}};function Fi(n,i){this.key=n,this.attributes=i,this.clear()}Fi.prototype.clear=function(){this.undirectedDegree=0,this.undirectedLoops=0,this.undirected={}};function ve(n,i,t,e,r){this.key=i,this.attributes=r,this.undirected=n,this.source=t,this.target=e}ve.prototype.attach=function(){let n="out",i="in";this.undirected&&(n=i="undirected");let t=this.source.key,e=this.target.key;this.source[n][e]=this,!(this.undirected&&t===e)&&(this.target[i][t]=this)};ve.prototype.attachMulti=function(){let n="out",i="in",t=this.source.key,e=this.target.key;this.undirected&&(n=i="undirected");let r=this.source[n],a=r[e];if(typeof a>"u"){r[e]=this,this.undirected&&t===e||(this.target[i][t]=this);return}a.previous=this,this.next=a,r[e]=this,this.target[i][t]=this};ve.prototype.detach=function(){let n=this.source.key,i=this.target.key,t="out",e="in";this.undirected&&(t=e="undirected"),delete this.source[t][i],delete this.target[e][n]};ve.prototype.detachMulti=function(){let n=this.source.key,i=this.target.key,t="out",e="in";this.undirected&&(t=e="undirected"),this.previous===void 0?this.next===void 0?(delete this.source[t][i],delete this.target[e][n]):(this.next.previous=void 0,this.source[t][i]=this.next,this.target[e][n]=this.next):(this.previous.next=this.next,this.next!==void 0&&(this.next.previous=this.previous))};var Pi=0,Ii=1,fn=2,Mi=3;function Q(n,i,t,e,r,a,o){let s,u,h,d;if(e=""+e,t===Pi){if(s=n._nodes.get(e),!s)throw new m(`Graph.${i}: could not find the "${e}" node in the graph.`);h=r,d=a}else if(t===Mi){if(r=""+r,u=n._edges.get(r),!u)throw new m(`Graph.${i}: could not find the "${r}" edge in the graph.`);let c=u.source.key,l=u.target.key;if(e===c)s=u.target;else if(e===l)s=u.source;else throw new m(`Graph.${i}: the "${e}" node is not attached to the "${r}" edge (${c}, ${l}).`);h=a,d=o}else{if(u=n._edges.get(e),!u)throw new m(`Graph.${i}: could not find the "${e}" edge in the graph.`);t===Ii?s=u.source:s=u.target,h=r,d=a}return[s,h,d]}function gn(n,i,t){n.prototype[i]=function(e,r,a){let[o,s]=Q(this,i,t,e,r,a);return o.attributes[s]}}function pn(n,i,t){n.prototype[i]=function(e,r){let[a]=Q(this,i,t,e,r);return a.attributes}}function mn(n,i,t){n.prototype[i]=function(e,r,a){let[o,s]=Q(this,i,t,e,r,a);return o.attributes.hasOwnProperty(s)}}function vn(n,i,t){n.prototype[i]=function(e,r,a,o){let[s,u,h]=Q(this,i,t,e,r,a,o);return s.attributes[u]=h,this.emit("nodeAttributesUpdated",{key:s.key,type:"set",attributes:s.attributes,name:u}),this}}function yn(n,i,t){n.prototype[i]=function(e,r,a,o){let[s,u,h]=Q(this,i,t,e,r,a,o);if(typeof h!="function")throw new b(`Graph.${i}: updater should be a function.`);let d=s.attributes,c=h(d[u]);return d[u]=c,this.emit("nodeAttributesUpdated",{key:s.key,type:"set",attributes:s.attributes,name:u}),this}}function bn(n,i,t){n.prototype[i]=function(e,r,a){let[o,s]=Q(this,i,t,e,r,a);return delete o.attributes[s],this.emit("nodeAttributesUpdated",{key:o.key,type:"remove",attributes:o.attributes,name:s}),this}}function wn(n,i,t){n.prototype[i]=function(e,r,a){let[o,s]=Q(this,i,t,e,r,a);if(!F(s))throw new b(`Graph.${i}: provided attributes are not a plain object.`);return o.attributes=s,this.emit("nodeAttributesUpdated",{key:o.key,type:"replace",attributes:o.attributes}),this}}function En(n,i,t){n.prototype[i]=function(e,r,a){let[o,s]=Q(this,i,t,e,r,a);if(!F(s))throw new b(`Graph.${i}: provided attributes are not a plain object.`);return G(o.attributes,s),this.emit("nodeAttributesUpdated",{key:o.key,type:"merge",attributes:o.attributes,data:s}),this}}function _n(n,i,t){n.prototype[i]=function(e,r,a){let[o,s]=Q(this,i,t,e,r,a);if(typeof s!="function")throw new b(`Graph.${i}: provided updater is not a function.`);return o.attributes=s(o.attributes),this.emit("nodeAttributesUpdated",{key:o.key,type:"update",attributes:o.attributes}),this}}var xn=[{name:n=>`get${n}Attribute`,attacher:gn},{name:n=>`get${n}Attributes`,attacher:pn},{name:n=>`has${n}Attribute`,attacher:mn},{name:n=>`set${n}Attribute`,attacher:vn},{name:n=>`update${n}Attribute`,attacher:yn},{name:n=>`remove${n}Attribute`,attacher:bn},{name:n=>`replace${n}Attributes`,attacher:wn},{name:n=>`merge${n}Attributes`,attacher:En},{name:n=>`update${n}Attributes`,attacher:_n}];function Tn(n){xn.forEach(function({name:i,attacher:t}){t(n,i("Node"),Pi),t(n,i("Source"),Ii),t(n,i("Target"),fn),t(n,i("Opposite"),Mi)})}function An(n,i,t){n.prototype[i]=function(e,r){let a;if(this.type!=="mixed"&&t!=="mixed"&&t!==this.type)throw new x(`Graph.${i}: cannot find this type of edges in your ${this.type} graph.`);if(arguments.length>2){if(this.multi)throw new x(`Graph.${i}: cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about.`);let o=""+e,s=""+r;if(r=arguments[2],a=W(this,o,s,t),!a)throw new m(`Graph.${i}: could not find an edge for the given path ("${o}" - "${s}").`)}else{if(t!=="mixed")throw new x(`Graph.${i}: calling this method with only a key (vs. a source and target) does not make sense since an edge with this key could have the other type.`);if(e=""+e,a=this._edges.get(e),!a)throw new m(`Graph.${i}: could not find the "${e}" edge in the graph.`)}return a.attributes[r]}}function Sn(n,i,t){n.prototype[i]=function(e){let r;if(this.type!=="mixed"&&t!=="mixed"&&t!==this.type)throw new x(`Graph.${i}: cannot find this type of edges in your ${this.type} graph.`);if(arguments.length>1){if(this.multi)throw new x(`Graph.${i}: cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about.`);let a=""+e,o=""+arguments[1];if(r=W(this,a,o,t),!r)throw new m(`Graph.${i}: could not find an edge for the given path ("${a}" - "${o}").`)}else{if(t!=="mixed")throw new x(`Graph.${i}: calling this method with only a key (vs. a source and target) does not make sense since an edge with this key could have the other type.`);if(e=""+e,r=this._edges.get(e),!r)throw new m(`Graph.${i}: could not find the "${e}" edge in the graph.`)}return r.attributes}}function Cn(n,i,t){n.prototype[i]=function(e,r){let a;if(this.type!=="mixed"&&t!=="mixed"&&t!==this.type)throw new x(`Graph.${i}: cannot find this type of edges in your ${this.type} graph.`);if(arguments.length>2){if(this.multi)throw new x(`Graph.${i}: cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about.`);let o=""+e,s=""+r;if(r=arguments[2],a=W(this,o,s,t),!a)throw new m(`Graph.${i}: could not find an edge for the given path ("${o}" - "${s}").`)}else{if(t!=="mixed")throw new x(`Graph.${i}: calling this method with only a key (vs. a source and target) does not make sense since an edge with this key could have the other type.`);if(e=""+e,a=this._edges.get(e),!a)throw new m(`Graph.${i}: could not find the "${e}" edge in the graph.`)}return a.attributes.hasOwnProperty(r)}}function kn(n,i,t){n.prototype[i]=function(e,r,a){let o;if(this.type!=="mixed"&&t!=="mixed"&&t!==this.type)throw new x(`Graph.${i}: cannot find this type of edges in your ${this.type} graph.`);if(arguments.length>3){if(this.multi)throw new x(`Graph.${i}: cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about.`);let s=""+e,u=""+r;if(r=arguments[2],a=arguments[3],o=W(this,s,u,t),!o)throw new m(`Graph.${i}: could not find an edge for the given path ("${s}" - "${u}").`)}else{if(t!=="mixed")throw new x(`Graph.${i}: calling this method with only a key (vs. a source and target) does not make sense since an edge with this key could have the other type.`);if(e=""+e,o=this._edges.get(e),!o)throw new m(`Graph.${i}: could not find the "${e}" edge in the graph.`)}return o.attributes[r]=a,this.emit("edgeAttributesUpdated",{key:o.key,type:"set",attributes:o.attributes,name:r}),this}}function Rn(n,i,t){n.prototype[i]=function(e,r,a){let o;if(this.type!=="mixed"&&t!=="mixed"&&t!==this.type)throw new x(`Graph.${i}: cannot find this type of edges in your ${this.type} graph.`);if(arguments.length>3){if(this.multi)throw new x(`Graph.${i}: cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about.`);let s=""+e,u=""+r;if(r=arguments[2],a=arguments[3],o=W(this,s,u,t),!o)throw new m(`Graph.${i}: could not find an edge for the given path ("${s}" - "${u}").`)}else{if(t!=="mixed")throw new x(`Graph.${i}: calling this method with only a key (vs. a source and target) does not make sense since an edge with this key could have the other type.`);if(e=""+e,o=this._edges.get(e),!o)throw new m(`Graph.${i}: could not find the "${e}" edge in the graph.`)}if(typeof a!="function")throw new b(`Graph.${i}: updater should be a function.`);return o.attributes[r]=a(o.attributes[r]),this.emit("edgeAttributesUpdated",{key:o.key,type:"set",attributes:o.attributes,name:r}),this}}function Ln(n,i,t){n.prototype[i]=function(e,r){let a;if(this.type!=="mixed"&&t!=="mixed"&&t!==this.type)throw new x(`Graph.${i}: cannot find this type of edges in your ${this.type} graph.`);if(arguments.length>2){if(this.multi)throw new x(`Graph.${i}: cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about.`);let o=""+e,s=""+r;if(r=arguments[2],a=W(this,o,s,t),!a)throw new m(`Graph.${i}: could not find an edge for the given path ("${o}" - "${s}").`)}else{if(t!=="mixed")throw new x(`Graph.${i}: calling this method with only a key (vs. a source and target) does not make sense since an edge with this key could have the other type.`);if(e=""+e,a=this._edges.get(e),!a)throw new m(`Graph.${i}: could not find the "${e}" edge in the graph.`)}return delete a.attributes[r],this.emit("edgeAttributesUpdated",{key:a.key,type:"remove",attributes:a.attributes,name:r}),this}}function Dn(n,i,t){n.prototype[i]=function(e,r){let a;if(this.type!=="mixed"&&t!=="mixed"&&t!==this.type)throw new x(`Graph.${i}: cannot find this type of edges in your ${this.type} graph.`);if(arguments.length>2){if(this.multi)throw new x(`Graph.${i}: cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about.`);let o=""+e,s=""+r;if(r=arguments[2],a=W(this,o,s,t),!a)throw new m(`Graph.${i}: could not find an edge for the given path ("${o}" - "${s}").`)}else{if(t!=="mixed")throw new x(`Graph.${i}: calling this method with only a key (vs. a source and target) does not make sense since an edge with this key could have the other type.`);if(e=""+e,a=this._edges.get(e),!a)throw new m(`Graph.${i}: could not find the "${e}" edge in the graph.`)}if(!F(r))throw new b(`Graph.${i}: provided attributes are not a plain object.`);return a.attributes=r,this.emit("edgeAttributesUpdated",{key:a.key,type:"replace",attributes:a.attributes}),this}}function Nn(n,i,t){n.prototype[i]=function(e,r){let a;if(this.type!=="mixed"&&t!=="mixed"&&t!==this.type)throw new x(`Graph.${i}: cannot find this type of edges in your ${this.type} graph.`);if(arguments.length>2){if(this.multi)throw new x(`Graph.${i}: cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about.`);let o=""+e,s=""+r;if(r=arguments[2],a=W(this,o,s,t),!a)throw new m(`Graph.${i}: could not find an edge for the given path ("${o}" - "${s}").`)}else{if(t!=="mixed")throw new x(`Graph.${i}: calling this method with only a key (vs. a source and target) does not make sense since an edge with this key could have the other type.`);if(e=""+e,a=this._edges.get(e),!a)throw new m(`Graph.${i}: could not find the "${e}" edge in the graph.`)}if(!F(r))throw new b(`Graph.${i}: provided attributes are not a plain object.`);return G(a.attributes,r),this.emit("edgeAttributesUpdated",{key:a.key,type:"merge",attributes:a.attributes,data:r}),this}}function Gn(n,i,t){n.prototype[i]=function(e,r){let a;if(this.type!=="mixed"&&t!=="mixed"&&t!==this.type)throw new x(`Graph.${i}: cannot find this type of edges in your ${this.type} graph.`);if(arguments.length>2){if(this.multi)throw new x(`Graph.${i}: cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about.`);let o=""+e,s=""+r;if(r=arguments[2],a=W(this,o,s,t),!a)throw new m(`Graph.${i}: could not find an edge for the given path ("${o}" - "${s}").`)}else{if(t!=="mixed")throw new x(`Graph.${i}: calling this method with only a key (vs. a source and target) does not make sense since an edge with this key could have the other type.`);if(e=""+e,a=this._edges.get(e),!a)throw new m(`Graph.${i}: could not find the "${e}" edge in the graph.`)}if(typeof r!="function")throw new b(`Graph.${i}: provided updater is not a function.`);return a.attributes=r(a.attributes),this.emit("edgeAttributesUpdated",{key:a.key,type:"update",attributes:a.attributes}),this}}var Fn=[{name:n=>`get${n}Attribute`,attacher:An},{name:n=>`get${n}Attributes`,attacher:Sn},{name:n=>`has${n}Attribute`,attacher:Cn},{name:n=>`set${n}Attribute`,attacher:kn},{name:n=>`update${n}Attribute`,attacher:Rn},{name:n=>`remove${n}Attribute`,attacher:Ln},{name:n=>`replace${n}Attributes`,attacher:Dn},{name:n=>`merge${n}Attributes`,attacher:Nn},{name:n=>`update${n}Attributes`,attacher:Gn}];function Pn(n){Fn.forEach(function({name:i,attacher:t}){t(n,i("Edge"),"mixed"),t(n,i("DirectedEdge"),"directed"),t(n,i("UndirectedEdge"),"undirected")})}var In=[{name:"edges",type:"mixed"},{name:"inEdges",type:"directed",direction:"in"},{name:"outEdges",type:"directed",direction:"out"},{name:"inboundEdges",type:"mixed",direction:"in"},{name:"outboundEdges",type:"mixed",direction:"out"},{name:"directedEdges",type:"directed"},{name:"undirectedEdges",type:"undirected"}];function Mn(n,i,t,e){let r=!1;for(let a in i){if(a===e)continue;let o=i[a];if(r=t(o.key,o.attributes,o.source.key,o.target.key,o.source.attributes,o.target.attributes,o.undirected),n&&r)return o.key}}function Un(n,i,t,e){let r,a,o,s=!1;for(let u in i)if(u!==e){r=i[u];do{if(a=r.source,o=r.target,s=t(r.key,r.attributes,a.key,o.key,a.attributes,o.attributes,r.undirected),n&&s)return r.key;r=r.next}while(r!==void 0)}}function yt(n,i){let t=Object.keys(n),e=t.length,r,a=0;return{[Symbol.iterator](){return this},next(){do if(r)r=r.next;else{if(a>=e)return{done:!0};let o=t[a++];if(o===i){r=void 0;continue}r=n[o]}while(!r);return{done:!1,value:{edge:r.key,attributes:r.attributes,source:r.source.key,target:r.target.key,sourceAttributes:r.source.attributes,targetAttributes:r.target.attributes,undirected:r.undirected}}}}}function $n(n,i,t,e){let r=i[t];if(!r)return;let a=r.source,o=r.target;if(e(r.key,r.attributes,a.key,o.key,a.attributes,o.attributes,r.undirected)&&n)return r.key}function On(n,i,t,e){let r=i[t];if(!r)return;let a=!1;do{if(a=e(r.key,r.attributes,r.source.key,r.target.key,r.source.attributes,r.target.attributes,r.undirected),n&&a)return r.key;r=r.next}while(r!==void 0)}function bt(n,i){let t=n[i];if(t.next!==void 0)return{[Symbol.iterator](){return this},next(){if(!t)return{done:!0};let r={edge:t.key,attributes:t.attributes,source:t.source.key,target:t.target.key,sourceAttributes:t.source.attributes,targetAttributes:t.target.attributes,undirected:t.undirected};return t=t.next,{done:!1,value:r}}};let e=!1;return{[Symbol.iterator](){return this},next(){return e===!0?{done:!0}:(e=!0,{done:!1,value:{edge:t.key,attributes:t.attributes,source:t.source.key,target:t.target.key,sourceAttributes:t.source.attributes,targetAttributes:t.target.attributes,undirected:t.undirected}})}}}function zn(n,i){if(n.size===0)return[];if(i==="mixed"||i===n.type)return Array.from(n._edges.keys());let t=i==="undirected"?n.undirectedSize:n.directedSize,e=new Array(t),r=i==="undirected",a=n._edges.values(),o=0,s,u;for(;s=a.next(),s.done!==!0;)u=s.value,u.undirected===r&&(e[o++]=u.key);return e}function Ui(n,i,t,e){if(i.size===0)return;let r=t!=="mixed"&&t!==i.type,a=t==="undirected",o,s,u=!1,h=i._edges.values();for(;o=h.next(),o.done!==!0;){if(s=o.value,r&&s.undirected!==a)continue;let{key:d,attributes:c,source:l,target:f}=s;if(u=e(d,c,l.key,f.key,l.attributes,f.attributes,s.undirected),n&&u)return d}}function Bn(n,i){if(n.size===0)return me();let t=i!=="mixed"&&i!==n.type,e=i==="undirected",r=n._edges.values();return{[Symbol.iterator](){return this},next(){let a,o;for(;;){if(a=r.next(),a.done)return a;if(o=a.value,!(t&&o.undirected!==e))break}return{value:{edge:o.key,attributes:o.attributes,source:o.source.key,target:o.target.key,sourceAttributes:o.source.attributes,targetAttributes:o.target.attributes,undirected:o.undirected},done:!1}}}}function wt(n,i,t,e,r,a){let o=i?Un:Mn,s;if(t!=="undirected"&&(e!=="out"&&(s=o(n,r.in,a),n&&s)||e!=="in"&&(s=o(n,r.out,a,e?void 0:r.key),n&&s))||t!=="directed"&&(s=o(n,r.undirected,a),n&&s))return s}function Hn(n,i,t,e){let r=[];return wt(!1,n,i,t,e,function(a){r.push(a)}),r}function Wn(n,i,t){let e=me();return n!=="undirected"&&(i!=="out"&&typeof t.in<"u"&&(e=J(e,yt(t.in))),i!=="in"&&typeof t.out<"u"&&(e=J(e,yt(t.out,i?void 0:t.key)))),n!=="directed"&&typeof t.undirected<"u"&&(e=J(e,yt(t.undirected))),e}function Et(n,i,t,e,r,a,o){let s=t?On:$n,u;if(i!=="undirected"&&(typeof r.in<"u"&&e!=="out"&&(u=s(n,r.in,a,o),n&&u)||typeof r.out<"u"&&e!=="in"&&(e||r.key!==a)&&(u=s(n,r.out,a,o),n&&u))||i!=="directed"&&typeof r.undirected<"u"&&(u=s(n,r.undirected,a,o),n&&u))return u}function jn(n,i,t,e,r){let a=[];return Et(!1,n,i,t,e,r,function(o){a.push(o)}),a}function Vn(n,i,t,e){let r=me();return n!=="undirected"&&(typeof t.in<"u"&&i!=="out"&&e in t.in&&(r=J(r,bt(t.in,e))),typeof t.out<"u"&&i!=="in"&&e in t.out&&(i||t.key!==e)&&(r=J(r,bt(t.out,e)))),n!=="directed"&&typeof t.undirected<"u"&&e in t.undirected&&(r=J(r,bt(t.undirected,e))),r}function Kn(n,i){let{name:t,type:e,direction:r}=i;n.prototype[t]=function(a,o){if(e!=="mixed"&&this.type!=="mixed"&&e!==this.type)return[];if(!arguments.length)return zn(this,e);if(arguments.length===1){a=""+a;let s=this._nodes.get(a);if(typeof s>"u")throw new m(`Graph.${t}: could not find the "${a}" node in the graph.`);return Hn(this.multi,e==="mixed"?this.type:e,r,s)}if(arguments.length===2){a=""+a,o=""+o;let s=this._nodes.get(a);if(!s)throw new m(`Graph.${t}: could not find the "${a}" source node in the graph.`);if(!this._nodes.has(o))throw new m(`Graph.${t}: could not find the "${o}" target node in the graph.`);return jn(e,this.multi,r,s,o)}throw new b(`Graph.${t}: too many arguments (expecting 0, 1 or 2 and got ${arguments.length}).`)}}function Yn(n,i){let{name:t,type:e,direction:r}=i,a="forEach"+t[0].toUpperCase()+t.slice(1,-1);n.prototype[a]=function(h,d,c){if(!(e!=="mixed"&&this.type!=="mixed"&&e!==this.type)){if(arguments.length===1)return c=h,Ui(!1,this,e,c);if(arguments.length===2){h=""+h,c=d;let l=this._nodes.get(h);if(typeof l>"u")throw new m(`Graph.${a}: could not find the "${h}" node in the graph.`);return wt(!1,this.multi,e==="mixed"?this.type:e,r,l,c)}if(arguments.length===3){h=""+h,d=""+d;let l=this._nodes.get(h);if(!l)throw new m(`Graph.${a}: could not find the "${h}" source node in the graph.`);if(!this._nodes.has(d))throw new m(`Graph.${a}: could not find the "${d}" target node in the graph.`);return Et(!1,e,this.multi,r,l,d,c)}throw new b(`Graph.${a}: too many arguments (expecting 1, 2 or 3 and got ${arguments.length}).`)}};let o="map"+t[0].toUpperCase()+t.slice(1);n.prototype[o]=function(){let h=Array.prototype.slice.call(arguments),d=h.pop(),c;if(h.length===0){let l=0;e!=="directed"&&(l+=this.undirectedSize),e!=="undirected"&&(l+=this.directedSize),c=new Array(l);let f=0;h.push((p,v,y,T,w,E,A)=>{c[f++]=d(p,v,y,T,w,E,A)})}else c=[],h.push((l,f,p,v,y,T,w)=>{c.push(d(l,f,p,v,y,T,w))});return this[a].apply(this,h),c};let s="filter"+t[0].toUpperCase()+t.slice(1);n.prototype[s]=function(){let h=Array.prototype.slice.call(arguments),d=h.pop(),c=[];return h.push((l,f,p,v,y,T,w)=>{d(l,f,p,v,y,T,w)&&c.push(l)}),this[a].apply(this,h),c};let u="reduce"+t[0].toUpperCase()+t.slice(1);n.prototype[u]=function(){let h=Array.prototype.slice.call(arguments);if(h.length<2||h.length>4)throw new b(`Graph.${u}: invalid number of arguments (expecting 2, 3 or 4 and got ${h.length}).`);if(typeof h[h.length-1]=="function"&&typeof h[h.length-2]!="function")throw new b(`Graph.${u}: missing initial value. You must provide it because the callback takes more than one argument and we cannot infer the initial value from the first iteration, as you could with a simple array.`);let d,c;h.length===2?(d=h[0],c=h[1],h=[]):h.length===3?(d=h[1],c=h[2],h=[h[0]]):h.length===4&&(d=h[2],c=h[3],h=[h[0],h[1]]);let l=c;return h.push((f,p,v,y,T,w,E)=>{l=d(l,f,p,v,y,T,w,E)}),this[a].apply(this,h),l}}function qn(n,i){let{name:t,type:e,direction:r}=i,a="find"+t[0].toUpperCase()+t.slice(1,-1);n.prototype[a]=function(u,h,d){if(e!=="mixed"&&this.type!=="mixed"&&e!==this.type)return!1;if(arguments.length===1)return d=u,Ui(!0,this,e,d);if(arguments.length===2){u=""+u,d=h;let c=this._nodes.get(u);if(typeof c>"u")throw new m(`Graph.${a}: could not find the "${u}" node in the graph.`);return wt(!0,this.multi,e==="mixed"?this.type:e,r,c,d)}if(arguments.length===3){u=""+u,h=""+h;let c=this._nodes.get(u);if(!c)throw new m(`Graph.${a}: could not find the "${u}" source node in the graph.`);if(!this._nodes.has(h))throw new m(`Graph.${a}: could not find the "${h}" target node in the graph.`);return Et(!0,e,this.multi,r,c,h,d)}throw new b(`Graph.${a}: too many arguments (expecting 1, 2 or 3 and got ${arguments.length}).`)};let o="some"+t[0].toUpperCase()+t.slice(1,-1);n.prototype[o]=function(){let u=Array.prototype.slice.call(arguments),h=u.pop();return u.push((c,l,f,p,v,y,T)=>h(c,l,f,p,v,y,T)),!!this[a].apply(this,u)};let s="every"+t[0].toUpperCase()+t.slice(1,-1);n.prototype[s]=function(){let u=Array.prototype.slice.call(arguments),h=u.pop();return u.push((c,l,f,p,v,y,T)=>!h(c,l,f,p,v,y,T)),!this[a].apply(this,u)}}function Zn(n,i){let{name:t,type:e,direction:r}=i,a=t.slice(0,-1)+"Entries";n.prototype[a]=function(o,s){if(e!=="mixed"&&this.type!=="mixed"&&e!==this.type)return me();if(!arguments.length)return Bn(this,e);if(arguments.length===1){o=""+o;let u=this._nodes.get(o);if(!u)throw new m(`Graph.${a}: could not find the "${o}" node in the graph.`);return Wn(e,r,u)}if(arguments.length===2){o=""+o,s=""+s;let u=this._nodes.get(o);if(!u)throw new m(`Graph.${a}: could not find the "${o}" source node in the graph.`);if(!this._nodes.has(s))throw new m(`Graph.${a}: could not find the "${s}" target node in the graph.`);return Vn(e,r,u,s)}throw new b(`Graph.${a}: too many arguments (expecting 0, 1 or 2 and got ${arguments.length}).`)}}function Xn(n){In.forEach(i=>{Kn(n,i),Yn(n,i),qn(n,i),Zn(n,i)})}var Jn=[{name:"neighbors",type:"mixed"},{name:"inNeighbors",type:"directed",direction:"in"},{name:"outNeighbors",type:"directed",direction:"out"},{name:"inboundNeighbors",type:"mixed",direction:"in"},{name:"outboundNeighbors",type:"mixed",direction:"out"},{name:"directedNeighbors",type:"directed"},{name:"undirectedNeighbors",type:"undirected"}];function qe(){this.A=null,this.B=null}qe.prototype.wrap=function(n){this.A===null?this.A=n:this.B===null&&(this.B=n)};qe.prototype.has=function(n){return this.A!==null&&n in this.A||this.B!==null&&n in this.B};function Ae(n,i,t,e,r){for(let a in e){let o=e[a],s=o.source,u=o.target,h=s===t?u:s;if(i&&i.has(h.key))continue;let d=r(h.key,h.attributes);if(n&&d)return h.key}}function _t(n,i,t,e,r){if(i!=="mixed"){if(i==="undirected")return Ae(n,null,e,e.undirected,r);if(typeof t=="string")return Ae(n,null,e,e[t],r)}let a=new qe,o;if(i!=="undirected"){if(t!=="out"){if(o=Ae(n,null,e,e.in,r),n&&o)return o;a.wrap(e.in)}if(t!=="in"){if(o=Ae(n,a,e,e.out,r),n&&o)return o;a.wrap(e.out)}}if(i!=="directed"&&(o=Ae(n,a,e,e.undirected,r),n&&o))return o}function Qn(n,i,t){if(n!=="mixed"){if(n==="undirected")return Object.keys(t.undirected);if(typeof i=="string")return Object.keys(t[i])}let e=[];return _t(!1,n,i,t,function(r){e.push(r)}),e}function Se(n,i,t){let e=Object.keys(t),r=e.length,a=0;return{[Symbol.iterator](){return this},next(){let o=null;do{if(a>=r)return n&&n.wrap(t),{done:!0};let s=t[e[a++]],u=s.source,h=s.target;if(o=u===i?h:u,n&&n.has(o.key)){o=null;continue}}while(o===null);return{done:!1,value:{neighbor:o.key,attributes:o.attributes}}}}}function ea(n,i,t){if(n!=="mixed"){if(n==="undirected")return Se(null,t,t.undirected);if(typeof i=="string")return Se(null,t,t[i])}let e=me(),r=new qe;return n!=="undirected"&&(i!=="out"&&(e=J(e,Se(r,t,t.in))),i!=="in"&&(e=J(e,Se(r,t,t.out)))),n!=="directed"&&(e=J(e,Se(r,t,t.undirected))),e}function ta(n,i){let{name:t,type:e,direction:r}=i;n.prototype[t]=function(a){if(e!=="mixed"&&this.type!=="mixed"&&e!==this.type)return[];a=""+a;let o=this._nodes.get(a);if(typeof o>"u")throw new m(`Graph.${t}: could not find the "${a}" node in the graph.`);return Qn(e==="mixed"?this.type:e,r,o)}}function ia(n,i){let{name:t,type:e,direction:r}=i,a="forEach"+t[0].toUpperCase()+t.slice(1,-1);n.prototype[a]=function(h,d){if(e!=="mixed"&&this.type!=="mixed"&&e!==this.type)return;h=""+h;let c=this._nodes.get(h);if(typeof c>"u")throw new m(`Graph.${a}: could not find the "${h}" node in the graph.`);_t(!1,e==="mixed"?this.type:e,r,c,d)};let o="map"+t[0].toUpperCase()+t.slice(1);n.prototype[o]=function(h,d){let c=[];return this[a](h,(l,f)=>{c.push(d(l,f))}),c};let s="filter"+t[0].toUpperCase()+t.slice(1);n.prototype[s]=function(h,d){let c=[];return this[a](h,(l,f)=>{d(l,f)&&c.push(l)}),c};let u="reduce"+t[0].toUpperCase()+t.slice(1);n.prototype[u]=function(h,d,c){if(arguments.length<3)throw new b(`Graph.${u}: missing initial value. You must provide it because the callback takes more than one argument and we cannot infer the initial value from the first iteration, as you could with a simple array.`);let l=c;return this[a](h,(f,p)=>{l=d(l,f,p)}),l}}function ra(n,i){let{name:t,type:e,direction:r}=i,a=t[0].toUpperCase()+t.slice(1,-1),o="find"+a;n.prototype[o]=function(h,d){if(e!=="mixed"&&this.type!=="mixed"&&e!==this.type)return;h=""+h;let c=this._nodes.get(h);if(typeof c>"u")throw new m(`Graph.${o}: could not find the "${h}" node in the graph.`);return _t(!0,e==="mixed"?this.type:e,r,c,d)};let s="some"+a;n.prototype[s]=function(h,d){return!!this[o](h,d)};let u="every"+a;n.prototype[u]=function(h,d){return!this[o](h,(l,f)=>!d(l,f))}}function na(n,i){let{name:t,type:e,direction:r}=i,a=t.slice(0,-1)+"Entries";n.prototype[a]=function(o){if(e!=="mixed"&&this.type!=="mixed"&&e!==this.type)return me();o=""+o;let s=this._nodes.get(o);if(typeof s>"u")throw new m(`Graph.${a}: could not find the "${o}" node in the graph.`);return ea(e==="mixed"?this.type:e,r,s)}}function aa(n){Jn.forEach(i=>{ta(n,i),ia(n,i),ra(n,i),na(n,i)})}function We(n,i,t,e,r){let a=e._nodes.values(),o=e.type,s,u,h,d,c,l,f;for(;s=a.next(),s.done!==!0;){let p=!1;if(u=s.value,o!=="undirected"){d=u.out;for(h in d){c=d[h];do{if(l=c.target,p=!0,f=r(u.key,l.key,u.attributes,l.attributes,c.key,c.attributes,c.undirected),n&&f)return c;c=c.next}while(c)}}if(o!=="directed"){d=u.undirected;for(h in d)if(!(i&&u.key>h)){c=d[h];do{if(l=c.target,l.key!==h&&(l=c.source),p=!0,f=r(u.key,l.key,u.attributes,l.attributes,c.key,c.attributes,c.undirected),n&&f)return c;c=c.next}while(c)}}if(t&&!p&&(f=r(u.key,null,u.attributes,null,null,null,null),n&&f))return null}}function oa(n,i){let t={key:n};return Di(i.attributes)||(t.attributes=G({},i.attributes)),t}function sa(n,i,t){let e={key:i,source:t.source.key,target:t.target.key};return Di(t.attributes)||(e.attributes=G({},t.attributes)),n==="mixed"&&t.undirected&&(e.undirected=!0),e}function ua(n){if(!F(n))throw new b('Graph.import: invalid serialized node. A serialized node should be a plain object with at least a "key" property.');if(!("key"in n))throw new b("Graph.import: serialized node is missing its key.");if("attributes"in n&&(!F(n.attributes)||n.attributes===null))throw new b("Graph.import: invalid attributes. Attributes should be a plain object, null or omitted.")}function ha(n){if(!F(n))throw new b('Graph.import: invalid serialized edge. A serialized edge should be a plain object with at least a "source" & "target" property.');if(!("source"in n))throw new b("Graph.import: serialized edge is missing its source.");if(!("target"in n))throw new b("Graph.import: serialized edge is missing its target.");if("attributes"in n&&(!F(n.attributes)||n.attributes===null))throw new b("Graph.import: invalid attributes. Attributes should be a plain object, null or omitted.");if("undirected"in n&&typeof n.undirected!="boolean")throw new b("Graph.import: invalid undirectedness information. Undirected should be boolean or omitted.")}var da=ln(),ca=new Set(["directed","undirected","mixed"]),ki=new Set(["domain","_events","_eventsCount","_maxListeners"]),la=[{name:n=>`${n}Edge`,generateKey:!0},{name:n=>`${n}DirectedEdge`,generateKey:!0,type:"directed"},{name:n=>`${n}UndirectedEdge`,generateKey:!0,type:"undirected"},{name:n=>`${n}EdgeWithKey`},{name:n=>`${n}DirectedEdgeWithKey`,type:"directed"},{name:n=>`${n}UndirectedEdgeWithKey`,type:"undirected"}],fa={allowSelfLoops:!0,multi:!1,type:"mixed"};function ga(n,i,t){if(t&&!F(t))throw new b(`Graph.addNode: invalid attributes. Expecting an object but got "${t}"`);if(i=""+i,t=t||{},n._nodes.has(i))throw new x(`Graph.addNode: the "${i}" node already exist in the graph.`);let e=new n.NodeDataClass(i,t);return n._nodes.set(i,e),n.emit("nodeAdded",{key:i,attributes:t}),e}function Ri(n,i,t){let e=new n.NodeDataClass(i,t);return n._nodes.set(i,e),n.emit("nodeAdded",{key:i,attributes:t}),e}function $i(n,i,t,e,r,a,o,s){if(!e&&n.type==="undirected")throw new x(`Graph.${i}: you cannot add a directed edge to an undirected graph. Use the #.addEdge or #.addUndirectedEdge instead.`);if(e&&n.type==="directed")throw new x(`Graph.${i}: you cannot add an undirected edge to a directed graph. Use the #.addEdge or #.addDirectedEdge instead.`);if(s&&!F(s))throw new b(`Graph.${i}: invalid attributes. Expecting an object but got "${s}"`);if(a=""+a,o=""+o,s=s||{},!n.allowSelfLoops&&a===o)throw new x(`Graph.${i}: source & target are the same ("${a}"), thus creating a loop explicitly forbidden by this graph 'allowSelfLoops' option set to false.`);let u=n._nodes.get(a),h=n._nodes.get(o);if(!u)throw new m(`Graph.${i}: source node "${a}" not found.`);if(!h)throw new m(`Graph.${i}: target node "${o}" not found.`);let d={key:null,undirected:e,source:a,target:o,attributes:s};if(t)r=n._edgeKeyGenerator();else if(r=""+r,n._edges.has(r))throw new x(`Graph.${i}: the "${r}" edge already exists in the graph.`);if(!n.multi&&(e?typeof u.undirected[o]<"u":typeof u.out[o]<"u"))throw new x(`Graph.${i}: an edge linking "${a}" to "${o}" already exists. If you really want to add multiple edges linking those nodes, you should create a multi graph by using the 'multi' option.`);let c=new ve(e,r,u,h,s);n._edges.set(r,c);let l=a===o;return e?(u.undirectedDegree++,h.undirectedDegree++,l&&(u.undirectedLoops++,n._undirectedSelfLoopCount++)):(u.outDegree++,h.inDegree++,l&&(u.directedLoops++,n._directedSelfLoopCount++)),n.multi?c.attachMulti():c.attach(),e?n._undirectedSize++:n._directedSize++,d.key=r,n.emit("edgeAdded",d),r}function pa(n,i,t,e,r,a,o,s,u){if(!e&&n.type==="undirected")throw new x(`Graph.${i}: you cannot merge/update a directed edge to an undirected graph. Use the #.mergeEdge/#.updateEdge or #.addUndirectedEdge instead.`);if(e&&n.type==="directed")throw new x(`Graph.${i}: you cannot merge/update an undirected edge to a directed graph. Use the #.mergeEdge/#.updateEdge or #.addDirectedEdge instead.`);if(s){if(u){if(typeof s!="function")throw new b(`Graph.${i}: invalid updater function. Expecting a function but got "${s}"`)}else if(!F(s))throw new b(`Graph.${i}: invalid attributes. Expecting an object but got "${s}"`)}a=""+a,o=""+o;let h;if(u&&(h=s,s=void 0),!n.allowSelfLoops&&a===o)throw new x(`Graph.${i}: source & target are the same ("${a}"), thus creating a loop explicitly forbidden by this graph 'allowSelfLoops' option set to false.`);let d=n._nodes.get(a),c=n._nodes.get(o),l,f;if(!t&&(l=n._edges.get(r),l)){if((l.source.key!==a||l.target.key!==o)&&(!e||l.source.key!==o||l.target.key!==a))throw new x(`Graph.${i}: inconsistency detected when attempting to merge the "${r}" edge with "${a}" source & "${o}" target vs. ("${l.source.key}", "${l.target.key}").`);f=l}if(!f&&!n.multi&&d&&(f=e?d.undirected[o]:d.out[o]),f){let w=[f.key,!1,!1,!1];if(u?!h:!s)return w;if(u){let E=f.attributes;f.attributes=h(E),n.emit("edgeAttributesUpdated",{type:"replace",key:f.key,attributes:f.attributes})}else G(f.attributes,s),n.emit("edgeAttributesUpdated",{type:"merge",key:f.key,attributes:f.attributes,data:s});return w}s=s||{},u&&h&&(s=h(s));let p={key:null,undirected:e,source:a,target:o,attributes:s};if(t)r=n._edgeKeyGenerator();else if(r=""+r,n._edges.has(r))throw new x(`Graph.${i}: the "${r}" edge already exists in the graph.`);let v=!1,y=!1;d||(d=Ri(n,a,{}),v=!0,a===o&&(c=d,y=!0)),c||(c=Ri(n,o,{}),y=!0),l=new ve(e,r,d,c,s),n._edges.set(r,l);let T=a===o;return e?(d.undirectedDegree++,c.undirectedDegree++,T&&(d.undirectedLoops++,n._undirectedSelfLoopCount++)):(d.outDegree++,c.inDegree++,T&&(d.directedLoops++,n._directedSelfLoopCount++)),n.multi?l.attachMulti():l.attach(),e?n._undirectedSize++:n._directedSize++,p.key=r,n.emit("edgeAdded",p),[r,!0,v,y]}function pe(n,i){n._edges.delete(i.key);let{source:t,target:e,attributes:r}=i,a=i.undirected,o=t===e;a?(t.undirectedDegree--,e.undirectedDegree--,o&&(t.undirectedLoops--,n._undirectedSelfLoopCount--)):(t.outDegree--,e.inDegree--,o&&(t.directedLoops--,n._directedSelfLoopCount--)),n.multi?i.detachMulti():i.detach(),a?n._undirectedSize--:n._directedSize--,n.emit("edgeDropped",{key:i.key,attributes:r,source:t.key,target:e.key,undirected:a})}var k=class n extends Li.EventEmitter{constructor(i){if(super(),i=G({},fa,i),typeof i.multi!="boolean")throw new b(`Graph.constructor: invalid 'multi' option. Expecting a boolean but got "${i.multi}".`);if(!ca.has(i.type))throw new b(`Graph.constructor: invalid 'type' option. Should be one of "mixed", "directed" or "undirected" but got "${i.type}".`);if(typeof i.allowSelfLoops!="boolean")throw new b(`Graph.constructor: invalid 'allowSelfLoops' option. Expecting a boolean but got "${i.allowSelfLoops}".`);let t=i.type==="mixed"?Ni:i.type==="directed"?Gi:Fi;H(this,"NodeDataClass",t);let e="geid_"+da()+"_",r=0,a=()=>{let o;do o=e+r++;while(this._edges.has(o));return o};H(this,"_attributes",{}),H(this,"_nodes",new Map),H(this,"_edges",new Map),H(this,"_directedSize",0),H(this,"_undirectedSize",0),H(this,"_directedSelfLoopCount",0),H(this,"_undirectedSelfLoopCount",0),H(this,"_edgeKeyGenerator",a),H(this,"_options",i),ki.forEach(o=>H(this,o,this[o])),Y(this,"order",()=>this._nodes.size),Y(this,"size",()=>this._edges.size),Y(this,"directedSize",()=>this._directedSize),Y(this,"undirectedSize",()=>this._undirectedSize),Y(this,"selfLoopCount",()=>this._directedSelfLoopCount+this._undirectedSelfLoopCount),Y(this,"directedSelfLoopCount",()=>this._directedSelfLoopCount),Y(this,"undirectedSelfLoopCount",()=>this._undirectedSelfLoopCount),Y(this,"multi",this._options.multi),Y(this,"type",this._options.type),Y(this,"allowSelfLoops",this._options.allowSelfLoops),Y(this,"implementation",()=>"graphology")}_resetInstanceCounters(){this._directedSize=0,this._undirectedSize=0,this._directedSelfLoopCount=0,this._undirectedSelfLoopCount=0}hasNode(i){return this._nodes.has(""+i)}hasDirectedEdge(i,t){if(this.type==="undirected")return!1;if(arguments.length===1){let e=""+i,r=this._edges.get(e);return!!r&&!r.undirected}else if(arguments.length===2){i=""+i,t=""+t;let e=this._nodes.get(i);return e?e.out.hasOwnProperty(t):!1}throw new b(`Graph.hasDirectedEdge: invalid arity (${arguments.length}, instead of 1 or 2). You can either ask for an edge id or for the existence of an edge between a source & a target.`)}hasUndirectedEdge(i,t){if(this.type==="directed")return!1;if(arguments.length===1){let e=""+i,r=this._edges.get(e);return!!r&&r.undirected}else if(arguments.length===2){i=""+i,t=""+t;let e=this._nodes.get(i);return e?e.undirected.hasOwnProperty(t):!1}throw new b(`Graph.hasDirectedEdge: invalid arity (${arguments.length}, instead of 1 or 2). You can either ask for an edge id or for the existence of an edge between a source & a target.`)}hasEdge(i,t){if(arguments.length===1){let e=""+i;return this._edges.has(e)}else if(arguments.length===2){i=""+i,t=""+t;let e=this._nodes.get(i);return e?typeof e.out<"u"&&e.out.hasOwnProperty(t)||typeof e.undirected<"u"&&e.undirected.hasOwnProperty(t):!1}throw new b(`Graph.hasEdge: invalid arity (${arguments.length}, instead of 1 or 2). You can either ask for an edge id or for the existence of an edge between a source & a target.`)}directedEdge(i,t){if(this.type==="undirected")return;if(i=""+i,t=""+t,this.multi)throw new x("Graph.directedEdge: this method is irrelevant with multigraphs since there might be multiple edges between source & target. See #.directedEdges instead.");let e=this._nodes.get(i);if(!e)throw new m(`Graph.directedEdge: could not find the "${i}" source node in the graph.`);if(!this._nodes.has(t))throw new m(`Graph.directedEdge: could not find the "${t}" target node in the graph.`);let r=e.out&&e.out[t]||void 0;if(r)return r.key}undirectedEdge(i,t){if(this.type==="directed")return;if(i=""+i,t=""+t,this.multi)throw new x("Graph.undirectedEdge: this method is irrelevant with multigraphs since there might be multiple edges between source & target. See #.undirectedEdges instead.");let e=this._nodes.get(i);if(!e)throw new m(`Graph.undirectedEdge: could not find the "${i}" source node in the graph.`);if(!this._nodes.has(t))throw new m(`Graph.undirectedEdge: could not find the "${t}" target node in the graph.`);let r=e.undirected&&e.undirected[t]||void 0;if(r)return r.key}edge(i,t){if(this.multi)throw new x("Graph.edge: this method is irrelevant with multigraphs since there might be multiple edges between source & target. See #.edges instead.");i=""+i,t=""+t;let e=this._nodes.get(i);if(!e)throw new m(`Graph.edge: could not find the "${i}" source node in the graph.`);if(!this._nodes.has(t))throw new m(`Graph.edge: could not find the "${t}" target node in the graph.`);let r=e.out&&e.out[t]||e.undirected&&e.undirected[t]||void 0;if(r)return r.key}areDirectedNeighbors(i,t){i=""+i,t=""+t;let e=this._nodes.get(i);if(!e)throw new m(`Graph.areDirectedNeighbors: could not find the "${i}" node in the graph.`);return this.type==="undirected"?!1:t in e.in||t in e.out}areOutNeighbors(i,t){i=""+i,t=""+t;let e=this._nodes.get(i);if(!e)throw new m(`Graph.areOutNeighbors: could not find the "${i}" node in the graph.`);return this.type==="undirected"?!1:t in e.out}areInNeighbors(i,t){i=""+i,t=""+t;let e=this._nodes.get(i);if(!e)throw new m(`Graph.areInNeighbors: could not find the "${i}" node in the graph.`);return this.type==="undirected"?!1:t in e.in}areUndirectedNeighbors(i,t){i=""+i,t=""+t;let e=this._nodes.get(i);if(!e)throw new m(`Graph.areUndirectedNeighbors: could not find the "${i}" node in the graph.`);return this.type==="directed"?!1:t in e.undirected}areNeighbors(i,t){i=""+i,t=""+t;let e=this._nodes.get(i);if(!e)throw new m(`Graph.areNeighbors: could not find the "${i}" node in the graph.`);return this.type!=="undirected"&&(t in e.in||t in e.out)||this.type!=="directed"&&t in e.undirected}areInboundNeighbors(i,t){i=""+i,t=""+t;let e=this._nodes.get(i);if(!e)throw new m(`Graph.areInboundNeighbors: could not find the "${i}" node in the graph.`);return this.type!=="undirected"&&t in e.in||this.type!=="directed"&&t in e.undirected}areOutboundNeighbors(i,t){i=""+i,t=""+t;let e=this._nodes.get(i);if(!e)throw new m(`Graph.areOutboundNeighbors: could not find the "${i}" node in the graph.`);return this.type!=="undirected"&&t in e.out||this.type!=="directed"&&t in e.undirected}inDegree(i){i=""+i;let t=this._nodes.get(i);if(!t)throw new m(`Graph.inDegree: could not find the "${i}" node in the graph.`);return this.type==="undirected"?0:t.inDegree}outDegree(i){i=""+i;let t=this._nodes.get(i);if(!t)throw new m(`Graph.outDegree: could not find the "${i}" node in the graph.`);return this.type==="undirected"?0:t.outDegree}directedDegree(i){i=""+i;let t=this._nodes.get(i);if(!t)throw new m(`Graph.directedDegree: could not find the "${i}" node in the graph.`);return this.type==="undirected"?0:t.inDegree+t.outDegree}undirectedDegree(i){i=""+i;let t=this._nodes.get(i);if(!t)throw new m(`Graph.undirectedDegree: could not find the "${i}" node in the graph.`);return this.type==="directed"?0:t.undirectedDegree}inboundDegree(i){i=""+i;let t=this._nodes.get(i);if(!t)throw new m(`Graph.inboundDegree: could not find the "${i}" node in the graph.`);let e=0;return this.type!=="directed"&&(e+=t.undirectedDegree),this.type!=="undirected"&&(e+=t.inDegree),e}outboundDegree(i){i=""+i;let t=this._nodes.get(i);if(!t)throw new m(`Graph.outboundDegree: could not find the "${i}" node in the graph.`);let e=0;return this.type!=="directed"&&(e+=t.undirectedDegree),this.type!=="undirected"&&(e+=t.outDegree),e}degree(i){i=""+i;let t=this._nodes.get(i);if(!t)throw new m(`Graph.degree: could not find the "${i}" node in the graph.`);let e=0;return this.type!=="directed"&&(e+=t.undirectedDegree),this.type!=="undirected"&&(e+=t.inDegree+t.outDegree),e}inDegreeWithoutSelfLoops(i){i=""+i;let t=this._nodes.get(i);if(!t)throw new m(`Graph.inDegreeWithoutSelfLoops: could not find the "${i}" node in the graph.`);return this.type==="undirected"?0:t.inDegree-t.directedLoops}outDegreeWithoutSelfLoops(i){i=""+i;let t=this._nodes.get(i);if(!t)throw new m(`Graph.outDegreeWithoutSelfLoops: could not find the "${i}" node in the graph.`);return this.type==="undirected"?0:t.outDegree-t.directedLoops}directedDegreeWithoutSelfLoops(i){i=""+i;let t=this._nodes.get(i);if(!t)throw new m(`Graph.directedDegreeWithoutSelfLoops: could not find the "${i}" node in the graph.`);return this.type==="undirected"?0:t.inDegree+t.outDegree-t.directedLoops*2}undirectedDegreeWithoutSelfLoops(i){i=""+i;let t=this._nodes.get(i);if(!t)throw new m(`Graph.undirectedDegreeWithoutSelfLoops: could not find the "${i}" node in the graph.`);return this.type==="directed"?0:t.undirectedDegree-t.undirectedLoops*2}inboundDegreeWithoutSelfLoops(i){i=""+i;let t=this._nodes.get(i);if(!t)throw new m(`Graph.inboundDegreeWithoutSelfLoops: could not find the "${i}" node in the graph.`);let e=0,r=0;return this.type!=="directed"&&(e+=t.undirectedDegree,r+=t.undirectedLoops*2),this.type!=="undirected"&&(e+=t.inDegree,r+=t.directedLoops),e-r}outboundDegreeWithoutSelfLoops(i){i=""+i;let t=this._nodes.get(i);if(!t)throw new m(`Graph.outboundDegreeWithoutSelfLoops: could not find the "${i}" node in the graph.`);let e=0,r=0;return this.type!=="directed"&&(e+=t.undirectedDegree,r+=t.undirectedLoops*2),this.type!=="undirected"&&(e+=t.outDegree,r+=t.directedLoops),e-r}degreeWithoutSelfLoops(i){i=""+i;let t=this._nodes.get(i);if(!t)throw new m(`Graph.degreeWithoutSelfLoops: could not find the "${i}" node in the graph.`);let e=0,r=0;return this.type!=="directed"&&(e+=t.undirectedDegree,r+=t.undirectedLoops*2),this.type!=="undirected"&&(e+=t.inDegree+t.outDegree,r+=t.directedLoops*2),e-r}source(i){i=""+i;let t=this._edges.get(i);if(!t)throw new m(`Graph.source: could not find the "${i}" edge in the graph.`);return t.source.key}target(i){i=""+i;let t=this._edges.get(i);if(!t)throw new m(`Graph.target: could not find the "${i}" edge in the graph.`);return t.target.key}extremities(i){i=""+i;let t=this._edges.get(i);if(!t)throw new m(`Graph.extremities: could not find the "${i}" edge in the graph.`);return[t.source.key,t.target.key]}opposite(i,t){i=""+i,t=""+t;let e=this._edges.get(t);if(!e)throw new m(`Graph.opposite: could not find the "${t}" edge in the graph.`);let r=e.source.key,a=e.target.key;if(i===r)return a;if(i===a)return r;throw new m(`Graph.opposite: the "${i}" node is not attached to the "${t}" edge (${r}, ${a}).`)}hasExtremity(i,t){i=""+i,t=""+t;let e=this._edges.get(i);if(!e)throw new m(`Graph.hasExtremity: could not find the "${i}" edge in the graph.`);return e.source.key===t||e.target.key===t}isUndirected(i){i=""+i;let t=this._edges.get(i);if(!t)throw new m(`Graph.isUndirected: could not find the "${i}" edge in the graph.`);return t.undirected}isDirected(i){i=""+i;let t=this._edges.get(i);if(!t)throw new m(`Graph.isDirected: could not find the "${i}" edge in the graph.`);return!t.undirected}isSelfLoop(i){i=""+i;let t=this._edges.get(i);if(!t)throw new m(`Graph.isSelfLoop: could not find the "${i}" edge in the graph.`);return t.source===t.target}addNode(i,t){return ga(this,i,t).key}mergeNode(i,t){if(t&&!F(t))throw new b(`Graph.mergeNode: invalid attributes. Expecting an object but got "${t}"`);i=""+i,t=t||{};let e=this._nodes.get(i);return e?(t&&(G(e.attributes,t),this.emit("nodeAttributesUpdated",{type:"merge",key:i,attributes:e.attributes,data:t})),[i,!1]):(e=new this.NodeDataClass(i,t),this._nodes.set(i,e),this.emit("nodeAdded",{key:i,attributes:t}),[i,!0])}updateNode(i,t){if(t&&typeof t!="function")throw new b(`Graph.updateNode: invalid updater function. Expecting a function but got "${t}"`);i=""+i;let e=this._nodes.get(i);if(e){if(t){let a=e.attributes;e.attributes=t(a),this.emit("nodeAttributesUpdated",{type:"replace",key:i,attributes:e.attributes})}return[i,!1]}let r=t?t({}):{};return e=new this.NodeDataClass(i,r),this._nodes.set(i,e),this.emit("nodeAdded",{key:i,attributes:r}),[i,!0]}dropNode(i){i=""+i;let t=this._nodes.get(i);if(!t)throw new m(`Graph.dropNode: could not find the "${i}" node in the graph.`);let e;if(this.type!=="undirected"){for(let r in t.out){e=t.out[r];do pe(this,e),e=e.next;while(e)}for(let r in t.in){e=t.in[r];do pe(this,e),e=e.next;while(e)}}if(this.type!=="directed")for(let r in t.undirected){e=t.undirected[r];do pe(this,e),e=e.next;while(e)}this._nodes.delete(i),this.emit("nodeDropped",{key:i,attributes:t.attributes})}dropEdge(i){let t;if(arguments.length>1){let e=""+arguments[0],r=""+arguments[1];if(t=W(this,e,r,this.type),!t)throw new m(`Graph.dropEdge: could not find the "${e}" -> "${r}" edge in the graph.`)}else if(i=""+i,t=this._edges.get(i),!t)throw new m(`Graph.dropEdge: could not find the "${i}" edge in the graph.`);return pe(this,t),this}dropDirectedEdge(i,t){if(arguments.length<2)throw new x("Graph.dropDirectedEdge: it does not make sense to try and drop a directed edge by key. What if the edge with this key is undirected? Use #.dropEdge for this purpose instead.");if(this.multi)throw new x("Graph.dropDirectedEdge: cannot use a {source,target} combo when dropping an edge in a MultiGraph since we cannot infer the one you want to delete as there could be multiple ones.");i=""+i,t=""+t;let e=W(this,i,t,"directed");if(!e)throw new m(`Graph.dropDirectedEdge: could not find a "${i}" -> "${t}" edge in the graph.`);return pe(this,e),this}dropUndirectedEdge(i,t){if(arguments.length<2)throw new x("Graph.dropUndirectedEdge: it does not make sense to drop a directed edge by key. What if the edge with this key is undirected? Use #.dropEdge for this purpose instead.");if(this.multi)throw new x("Graph.dropUndirectedEdge: cannot use a {source,target} combo when dropping an edge in a MultiGraph since we cannot infer the one you want to delete as there could be multiple ones.");let e=W(this,i,t,"undirected");if(!e)throw new m(`Graph.dropUndirectedEdge: could not find a "${i}" -> "${t}" edge in the graph.`);return pe(this,e),this}clear(){this._edges.clear(),this._nodes.clear(),this._resetInstanceCounters(),this.emit("cleared")}clearEdges(){let i=this._nodes.values(),t;for(;t=i.next(),t.done!==!0;)t.value.clear();this._edges.clear(),this._resetInstanceCounters(),this.emit("edgesCleared")}getAttribute(i){return this._attributes[i]}getAttributes(){return this._attributes}hasAttribute(i){return this._attributes.hasOwnProperty(i)}setAttribute(i,t){return this._attributes[i]=t,this.emit("attributesUpdated",{type:"set",attributes:this._attributes,name:i}),this}updateAttribute(i,t){if(typeof t!="function")throw new b("Graph.updateAttribute: updater should be a function.");let e=this._attributes[i];return this._attributes[i]=t(e),this.emit("attributesUpdated",{type:"set",attributes:this._attributes,name:i}),this}removeAttribute(i){return delete this._attributes[i],this.emit("attributesUpdated",{type:"remove",attributes:this._attributes,name:i}),this}replaceAttributes(i){if(!F(i))throw new b("Graph.replaceAttributes: provided attributes are not a plain object.");return this._attributes=i,this.emit("attributesUpdated",{type:"replace",attributes:this._attributes}),this}mergeAttributes(i){if(!F(i))throw new b("Graph.mergeAttributes: provided attributes are not a plain object.");return G(this._attributes,i),this.emit("attributesUpdated",{type:"merge",attributes:this._attributes,data:i}),this}updateAttributes(i){if(typeof i!="function")throw new b("Graph.updateAttributes: provided updater is not a function.");return this._attributes=i(this._attributes),this.emit("attributesUpdated",{type:"update",attributes:this._attributes}),this}updateEachNodeAttributes(i,t){if(typeof i!="function")throw new b("Graph.updateEachNodeAttributes: expecting an updater function.");if(t&&!Ci(t))throw new b("Graph.updateEachNodeAttributes: invalid hints. Expecting an object having the following shape: {attributes?: [string]}");let e=this._nodes.values(),r,a;for(;r=e.next(),r.done!==!0;)a=r.value,a.attributes=i(a.key,a.attributes);this.emit("eachNodeAttributesUpdated",{hints:t||null})}updateEachEdgeAttributes(i,t){if(typeof i!="function")throw new b("Graph.updateEachEdgeAttributes: expecting an updater function.");if(t&&!Ci(t))throw new b("Graph.updateEachEdgeAttributes: invalid hints. Expecting an object having the following shape: {attributes?: [string]}");let e=this._edges.values(),r,a,o,s;for(;r=e.next(),r.done!==!0;)a=r.value,o=a.source,s=a.target,a.attributes=i(a.key,a.attributes,o.key,s.key,o.attributes,s.attributes,a.undirected);this.emit("eachEdgeAttributesUpdated",{hints:t||null})}forEachAdjacencyEntry(i){if(typeof i!="function")throw new b("Graph.forEachAdjacencyEntry: expecting a callback.");We(!1,!1,!1,this,i)}forEachAdjacencyEntryWithOrphans(i){if(typeof i!="function")throw new b("Graph.forEachAdjacencyEntryWithOrphans: expecting a callback.");We(!1,!1,!0,this,i)}forEachAssymetricAdjacencyEntry(i){if(typeof i!="function")throw new b("Graph.forEachAssymetricAdjacencyEntry: expecting a callback.");We(!1,!0,!1,this,i)}forEachAssymetricAdjacencyEntryWithOrphans(i){if(typeof i!="function")throw new b("Graph.forEachAssymetricAdjacencyEntryWithOrphans: expecting a callback.");We(!1,!0,!0,this,i)}nodes(){return Array.from(this._nodes.keys())}forEachNode(i){if(typeof i!="function")throw new b("Graph.forEachNode: expecting a callback.");let t=this._nodes.values(),e,r;for(;e=t.next(),e.done!==!0;)r=e.value,i(r.key,r.attributes)}findNode(i){if(typeof i!="function")throw new b("Graph.findNode: expecting a callback.");let t=this._nodes.values(),e,r;for(;e=t.next(),e.done!==!0;)if(r=e.value,i(r.key,r.attributes))return r.key}mapNodes(i){if(typeof i!="function")throw new b("Graph.mapNode: expecting a callback.");let t=this._nodes.values(),e,r,a=new Array(this.order),o=0;for(;e=t.next(),e.done!==!0;)r=e.value,a[o++]=i(r.key,r.attributes);return a}someNode(i){if(typeof i!="function")throw new b("Graph.someNode: expecting a callback.");let t=this._nodes.values(),e,r;for(;e=t.next(),e.done!==!0;)if(r=e.value,i(r.key,r.attributes))return!0;return!1}everyNode(i){if(typeof i!="function")throw new b("Graph.everyNode: expecting a callback.");let t=this._nodes.values(),e,r;for(;e=t.next(),e.done!==!0;)if(r=e.value,!i(r.key,r.attributes))return!1;return!0}filterNodes(i){if(typeof i!="function")throw new b("Graph.filterNodes: expecting a callback.");let t=this._nodes.values(),e,r,a=[];for(;e=t.next(),e.done!==!0;)r=e.value,i(r.key,r.attributes)&&a.push(r.key);return a}reduceNodes(i,t){if(typeof i!="function")throw new b("Graph.reduceNodes: expecting a callback.");if(arguments.length<2)throw new b("Graph.reduceNodes: missing initial value. You must provide it because the callback takes more than one argument and we cannot infer the initial value from the first iteration, as you could with a simple array.");let e=t,r=this._nodes.values(),a,o;for(;a=r.next(),a.done!==!0;)o=a.value,e=i(e,o.key,o.attributes);return e}nodeEntries(){let i=this._nodes.values();return{[Symbol.iterator](){return this},next(){let t=i.next();if(t.done)return t;let e=t.value;return{value:{node:e.key,attributes:e.attributes},done:!1}}}}export(){let i=new Array(this._nodes.size),t=0;this._nodes.forEach((r,a)=>{i[t++]=oa(a,r)});let e=new Array(this._edges.size);return t=0,this._edges.forEach((r,a)=>{e[t++]=sa(this.type,a,r)}),{options:{type:this.type,multi:this.multi,allowSelfLoops:this.allowSelfLoops},attributes:this.getAttributes(),nodes:i,edges:e}}import(i,t=!1){if(i instanceof n)return i.forEachNode((u,h)=>{t?this.mergeNode(u,h):this.addNode(u,h)}),i.forEachEdge((u,h,d,c,l,f,p)=>{t?p?this.mergeUndirectedEdgeWithKey(u,d,c,h):this.mergeDirectedEdgeWithKey(u,d,c,h):p?this.addUndirectedEdgeWithKey(u,d,c,h):this.addDirectedEdgeWithKey(u,d,c,h)}),this;if(!F(i))throw new b("Graph.import: invalid argument. Expecting a serialized graph or, alternatively, a Graph instance.");if(i.attributes){if(!F(i.attributes))throw new b("Graph.import: invalid attributes. Expecting a plain object.");t?this.mergeAttributes(i.attributes):this.replaceAttributes(i.attributes)}let e,r,a,o,s;if(i.nodes){if(a=i.nodes,!Array.isArray(a))throw new b("Graph.import: invalid nodes. Expecting an array.");for(e=0,r=a.length;e<r;e++){o=a[e],ua(o);let{key:u,attributes:h}=o;t?this.mergeNode(u,h):this.addNode(u,h)}}if(i.edges){let u=!1;if(this.type==="undirected"&&(u=!0),a=i.edges,!Array.isArray(a))throw new b("Graph.import: invalid edges. Expecting an array.");for(e=0,r=a.length;e<r;e++){s=a[e],ha(s);let{source:h,target:d,attributes:c,undirected:l=u}=s,f;"key"in s?(f=t?l?this.mergeUndirectedEdgeWithKey:this.mergeDirectedEdgeWithKey:l?this.addUndirectedEdgeWithKey:this.addDirectedEdgeWithKey,f.call(this,s.key,h,d,c)):(f=t?l?this.mergeUndirectedEdge:this.mergeDirectedEdge:l?this.addUndirectedEdge:this.addDirectedEdge,f.call(this,h,d,c))}}return this}nullCopy(i){let t=new n(G({},this._options,i));return t.replaceAttributes(G({},this.getAttributes())),t}emptyCopy(i){let t=this.nullCopy(i);return this._nodes.forEach((e,r)=>{let a=G({},e.attributes);e=new t.NodeDataClass(r,a),t._nodes.set(r,e)}),t}copy(i){if(i=i||{},typeof i.type=="string"&&i.type!==this.type&&i.type!=="mixed")throw new x(`Graph.copy: cannot create an incompatible copy from "${this.type}" type to "${i.type}" because this would mean losing information about the current graph.`);if(typeof i.multi=="boolean"&&i.multi!==this.multi&&i.multi!==!0)throw new x("Graph.copy: cannot create an incompatible copy by downgrading a multi graph to a simple one because this would mean losing information about the current graph.");if(typeof i.allowSelfLoops=="boolean"&&i.allowSelfLoops!==this.allowSelfLoops&&i.allowSelfLoops!==!0)throw new x("Graph.copy: cannot create an incompatible copy from a graph allowing self loops to one that does not because this would mean losing information about the current graph.");let t=this.emptyCopy(i),e=this._edges.values(),r,a;for(;r=e.next(),r.done!==!0;)a=r.value,$i(t,"copy",!1,a.undirected,a.key,a.source.key,a.target.key,G({},a.attributes));return t}toJSON(){return this.export()}toString(){return"[object Graph]"}inspect(){let i={};this._nodes.forEach((a,o)=>{i[o]=a.attributes});let t={},e={};this._edges.forEach((a,o)=>{let s=a.undirected?"--":"->",u="",h=a.source.key,d=a.target.key,c;a.undirected&&h>d&&(c=h,h=d,d=c);let l=`(${h})${s}(${d})`;o.startsWith("geid_")?this.multi&&(typeof e[l]>"u"?e[l]=0:e[l]++,u+=`${e[l]}. `):u+=`[${o}]: `,u+=l,t[u]=a.attributes});let r={};for(let a in this)this.hasOwnProperty(a)&&!ki.has(a)&&typeof this[a]!="function"&&typeof a!="symbol"&&(r[a]=this[a]);return r.attributes=this._attributes,r.nodes=i,r.edges=t,H(r,"constructor",this.constructor),r}};typeof Symbol<"u"&&(k.prototype[Symbol.for("nodejs.util.inspect.custom")]=k.prototype.inspect);la.forEach(n=>{["add","merge","update"].forEach(i=>{let t=n.name(i),e=i==="add"?$i:pa;n.generateKey?k.prototype[t]=function(r,a,o){return e(this,t,!0,(n.type||this.type)==="undirected",null,r,a,o,i==="update")}:k.prototype[t]=function(r,a,o,s){return e(this,t,!1,(n.type||this.type)==="undirected",r,a,o,s,i==="update")}})});Tn(k);Pn(k);Xn(k);aa(k);var je=class extends k{constructor(i){let t=G({type:"directed"},i);if("multi"in t&&t.multi!==!1)throw new b("DirectedGraph.from: inconsistent indication that the graph should be multi in given options!");if(t.type!=="directed")throw new b('DirectedGraph.from: inconsistent "'+t.type+'" type in given options!');super(t)}},Ve=class extends k{constructor(i){let t=G({type:"undirected"},i);if("multi"in t&&t.multi!==!1)throw new b("UndirectedGraph.from: inconsistent indication that the graph should be multi in given options!");if(t.type!=="undirected")throw new b('UndirectedGraph.from: inconsistent "'+t.type+'" type in given options!');super(t)}},Ke=class extends k{constructor(i){let t=G({multi:!0},i);if("multi"in t&&t.multi!==!0)throw new b("MultiGraph.from: inconsistent indication that the graph should be simple in given options!");super(t)}},ke=class extends k{constructor(i){let t=G({type:"directed",multi:!0},i);if("multi"in t&&t.multi!==!0)throw new b("MultiDirectedGraph.from: inconsistent indication that the graph should be simple in given options!");if(t.type!=="directed")throw new b('MultiDirectedGraph.from: inconsistent "'+t.type+'" type in given options!');super(t)}},Ye=class extends k{constructor(i){let t=G({type:"undirected",multi:!0},i);if("multi"in t&&t.multi!==!0)throw new b("MultiUndirectedGraph.from: inconsistent indication that the graph should be simple in given options!");if(t.type!=="undirected")throw new b('MultiUndirectedGraph.from: inconsistent "'+t.type+'" type in given options!');super(t)}};function ye(n){n.from=function(i,t){let e=G({},i.options,t),r=new n(e);return r.import(i),r}}ye(k);ye(je);ye(Ve);ye(Ke);ye(ke);ye(Ye);k.Graph=k;k.DirectedGraph=je;k.UndirectedGraph=Ve;k.MultiGraph=Ke;k.MultiDirectedGraph=ke;k.MultiUndirectedGraph=Ye;k.InvalidArgumentsGraphError=b;k.NotFoundGraphError=m;k.UsageGraphError=x;export{ke as MultiDirectedGraph,dn as Sigma};
|