(function(Te,ue){typeof exports=="object"&&typeof module<"u"?module.exports=ue():typeof define=="function"&&define.amd?define(ue):(Te=typeof globalThis<"u"?globalThis:Te||self,Te.Sigma=ue())})(this,function(){"use strict";function Te(r,e){if(typeof r!="object"||!r)return r;var t=r[Symbol.toPrimitive];if(t!==void 0){var n=t.call(r,e);if(typeof n!="object")return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return(e==="string"?String:Number)(r)}function ue(r){var e=Te(r,"string");return typeof e=="symbol"?e:e+""}function ne(r,e){if(!(r instanceof e))throw new TypeError("Cannot call a class as a function")}function ai(r,e){for(var t=0;t>8&255,o=t>>16&255,a=t>>24&255;return[n,i,o,a]}var it={};function gr(r){if(typeof it[r]<"u")return it[r];var e=(r&16711680)>>>16,t=(r&65280)>>>8,n=r&255,i=255,o=fr(e,t,n,i);return it[r]=o,o}function I(r,e,t){return(e=ue(e))in r?Object.defineProperty(r,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):r[e]=t,r}function mr(r,e){var t=Object.keys(r);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(r);e&&(n=n.filter(function(i){return Object.getOwnPropertyDescriptor(r,i).enumerable})),t.push.apply(t,n)}return t}function fe(r){for(var e=1;e border) gl_FragColor = transparent; else gl_FragColor = v_color; #else float t = 0.0; if (dist > border) t = 1.0; else if (dist > 0.0) t = dist / border; gl_FragColor = mix(v_color, transparent, t); #endif } `,yi=bi,Ei=` attribute vec4 a_id; attribute vec4 a_color; attribute vec2 a_position; attribute float a_size; attribute float a_angle; uniform mat3 u_matrix; uniform float u_sizeRatio; uniform float u_correctionRatio; varying vec4 v_color; varying vec2 v_diffVector; varying float v_radius; varying float v_border; const float bias = 255.0 / 254.0; void main() { float size = a_size * u_correctionRatio / u_sizeRatio * 4.0; vec2 diffVector = size * vec2(cos(a_angle), sin(a_angle)); vec2 position = a_position + diffVector; gl_Position = vec4( (u_matrix * vec3(position, 1)).xy, 0, 1 ); v_diffVector = diffVector; v_radius = size / 2.0; #ifdef PICKING_MODE // For picking mode, we use the ID as the color: v_color = a_id; #else // For normal mode, we use the color: v_color = a_color; #endif v_color.a *= bias; } `,Ti=Ei,Er=WebGLRenderingContext,Tr=Er.UNSIGNED_BYTE,lt=Er.FLOAT,Ri=["u_sizeRatio","u_correctionRatio","u_matrix"],ut=function(r){function e(){return ne(this,e),Re(this,e,arguments)}return Ce(e,r),ie(e,[{key:"getDefinition",value:function(){return{VERTICES:3,VERTEX_SHADER_SOURCE:Ti,FRAGMENT_SHADER_SOURCE:yi,METHOD:WebGLRenderingContext.TRIANGLES,UNIFORMS:Ri,ATTRIBUTES:[{name:"a_position",size:2,type:lt},{name:"a_size",size:1,type:lt},{name:"a_color",size:4,type:Tr,normalized:!0},{name:"a_id",size:4,type:Tr,normalized:!0}],CONSTANT_ATTRIBUTES:[{name:"a_angle",size:1,type:lt}],CONSTANT_DATA:[[e.ANGLE_1],[e.ANGLE_2],[e.ANGLE_3]]}}},{key:"processVisibleItem",value:function(n,i,o){var a=this.array,s=X(o.color);a[i++]=o.x,a[i++]=o.y,a[i++]=o.size,a[i++]=s,a[i++]=n}},{key:"setUniforms",value:function(n,i){var o=i.gl,a=i.uniformLocations,s=a.u_sizeRatio,l=a.u_correctionRatio,c=a.u_matrix;o.uniform1f(l,n.correctionRatio),o.uniform1f(s,n.sizeRatio),o.uniformMatrix3fv(c,!1,n.matrix)}}])}(Ie);I(ut,"ANGLE_1",0),I(ut,"ANGLE_2",2*Math.PI/3),I(ut,"ANGLE_3",4*Math.PI/3);var Ci=` precision mediump float; varying vec4 v_color; void main(void) { gl_FragColor = v_color; } `,wi=Ci,Ai=` attribute vec2 a_position; attribute vec2 a_normal; attribute float a_radius; attribute vec3 a_barycentric; #ifdef PICKING_MODE attribute vec4 a_id; #else attribute vec4 a_color; #endif uniform mat3 u_matrix; uniform float u_sizeRatio; uniform float u_correctionRatio; uniform float u_minEdgeThickness; uniform float u_lengthToThicknessRatio; uniform float u_widenessToThicknessRatio; varying vec4 v_color; const float bias = 255.0 / 254.0; void main() { float minThickness = u_minEdgeThickness; float normalLength = length(a_normal); vec2 unitNormal = a_normal / normalLength; // These first computations are taken from edge.vert.glsl and // edge.clamped.vert.glsl. Please read it to get better comments on what's // happening: float pixelsThickness = max(normalLength / u_sizeRatio, minThickness); float webGLThickness = pixelsThickness * u_correctionRatio; float webGLNodeRadius = a_radius * 2.0 * u_correctionRatio / u_sizeRatio; float webGLArrowHeadLength = webGLThickness * u_lengthToThicknessRatio * 2.0; float webGLArrowHeadThickness = webGLThickness * u_widenessToThicknessRatio; float da = a_barycentric.x; float db = a_barycentric.y; float dc = a_barycentric.z; vec2 delta = vec2( da * (webGLNodeRadius * unitNormal.y) + db * ((webGLNodeRadius + webGLArrowHeadLength) * unitNormal.y + webGLArrowHeadThickness * unitNormal.x) + dc * ((webGLNodeRadius + webGLArrowHeadLength) * unitNormal.y - webGLArrowHeadThickness * unitNormal.x), da * (-webGLNodeRadius * unitNormal.x) + db * (-(webGLNodeRadius + webGLArrowHeadLength) * unitNormal.x + webGLArrowHeadThickness * unitNormal.y) + dc * (-(webGLNodeRadius + webGLArrowHeadLength) * unitNormal.x - webGLArrowHeadThickness * unitNormal.y) ); vec2 position = (u_matrix * vec3(a_position + delta, 1)).xy; gl_Position = vec4(position, 0, 1); #ifdef PICKING_MODE // For picking mode, we use the ID as the color: v_color = a_id; #else // For normal mode, we use the color: v_color = a_color; #endif v_color.a *= bias; } `,Si=Ai,Rr=WebGLRenderingContext,Cr=Rr.UNSIGNED_BYTE,ze=Rr.FLOAT,xi=["u_matrix","u_sizeRatio","u_correctionRatio","u_minEdgeThickness","u_lengthToThicknessRatio","u_widenessToThicknessRatio"],Ge={extremity:"target",lengthToThicknessRatio:2.5,widenessToThicknessRatio:2};function wr(r){var e=fe(fe({},Ge),{});return function(t){function n(){return ne(this,n),Re(this,n,arguments)}return Ce(n,t),ie(n,[{key:"getDefinition",value:function(){return{VERTICES:3,VERTEX_SHADER_SOURCE:Si,FRAGMENT_SHADER_SOURCE:wi,METHOD:WebGLRenderingContext.TRIANGLES,UNIFORMS:xi,ATTRIBUTES:[{name:"a_position",size:2,type:ze},{name:"a_normal",size:2,type:ze},{name:"a_radius",size:1,type:ze},{name:"a_color",size:4,type:Cr,normalized:!0},{name:"a_id",size:4,type:Cr,normalized:!0}],CONSTANT_ATTRIBUTES:[{name:"a_barycentric",size:3,type:ze}],CONSTANT_DATA:[[1,0,0],[0,1,0],[0,0,1]]}}},{key:"processVisibleItem",value:function(o,a,s,l,c){if(e.extremity==="source"){var u=[l,s];s=u[0],l=u[1]}var d=c.size||1,h=l.size||1,m=s.x,g=s.y,b=l.x,E=l.y,v=X(c.color),T=b-m,_=E-g,f=T*T+_*_,p=0,y=0;f&&(f=1/Math.sqrt(f),p=-_*f*d,y=T*f*d);var R=this.array;R[a++]=b,R[a++]=E,R[a++]=-p,R[a++]=-y,R[a++]=h,R[a++]=v,R[a++]=o}},{key:"setUniforms",value:function(o,a){var s=a.gl,l=a.uniformLocations,c=l.u_matrix,u=l.u_sizeRatio,d=l.u_correctionRatio,h=l.u_minEdgeThickness,m=l.u_lengthToThicknessRatio,g=l.u_widenessToThicknessRatio;s.uniformMatrix3fv(c,!1,o.matrix),s.uniform1f(u,o.sizeRatio),s.uniform1f(d,o.correctionRatio),s.uniform1f(h,o.minEdgeThickness),s.uniform1f(m,e.lengthToThicknessRatio),s.uniform1f(g,e.widenessToThicknessRatio)}}])}(ct)}wr();var Li=` precision mediump float; varying vec4 v_color; varying vec2 v_normal; varying float v_thickness; varying float v_feather; const vec4 transparent = vec4(0.0, 0.0, 0.0, 0.0); void main(void) { // We only handle antialiasing for normal mode: #ifdef PICKING_MODE gl_FragColor = v_color; #else float dist = length(v_normal) * v_thickness; float t = smoothstep( v_thickness - v_feather, v_thickness, dist ); gl_FragColor = mix(v_color, transparent, t); #endif } `,Fi=Li,Ni=` attribute vec4 a_id; attribute vec4 a_color; attribute vec2 a_normal; attribute float a_normalCoef; attribute vec2 a_positionStart; attribute vec2 a_positionEnd; attribute float a_positionCoef; attribute float a_radius; attribute float a_radiusCoef; uniform mat3 u_matrix; uniform float u_zoomRatio; uniform float u_sizeRatio; uniform float u_pixelRatio; uniform float u_correctionRatio; uniform float u_minEdgeThickness; uniform float u_lengthToThicknessRatio; uniform float u_feather; varying vec4 v_color; varying vec2 v_normal; varying float v_thickness; varying float v_feather; const float bias = 255.0 / 254.0; void main() { float minThickness = u_minEdgeThickness; float radius = a_radius * a_radiusCoef; vec2 normal = a_normal * a_normalCoef; vec2 position = a_positionStart * (1.0 - a_positionCoef) + a_positionEnd * a_positionCoef; float normalLength = length(normal); vec2 unitNormal = normal / normalLength; // These first computations are taken from edge.vert.glsl. Please read it to // get better comments on what's happening: float pixelsThickness = max(normalLength, minThickness * u_sizeRatio); float webGLThickness = pixelsThickness * u_correctionRatio / u_sizeRatio; // Here, we move the point to leave space for the arrow head: float direction = sign(radius); float webGLNodeRadius = direction * radius * 2.0 * u_correctionRatio / u_sizeRatio; float webGLArrowHeadLength = webGLThickness * u_lengthToThicknessRatio * 2.0; vec2 compensationVector = vec2(-direction * unitNormal.y, direction * unitNormal.x) * (webGLNodeRadius + webGLArrowHeadLength); // Here is the proper position of the vertex gl_Position = vec4((u_matrix * vec3(position + unitNormal * webGLThickness + compensationVector, 1)).xy, 0, 1); v_thickness = webGLThickness / u_zoomRatio; v_normal = unitNormal; v_feather = u_feather * u_correctionRatio / u_zoomRatio / u_pixelRatio * 2.0; #ifdef PICKING_MODE // For picking mode, we use the ID as the color: v_color = a_id; #else // For normal mode, we use the color: v_color = a_color; #endif v_color.a *= bias; } `,Pi=Ni,Ar=WebGLRenderingContext,Sr=Ar.UNSIGNED_BYTE,oe=Ar.FLOAT,Oi=["u_matrix","u_zoomRatio","u_sizeRatio","u_correctionRatio","u_pixelRatio","u_feather","u_minEdgeThickness","u_lengthToThicknessRatio"],Di={lengthToThicknessRatio:Ge.lengthToThicknessRatio};function xr(r){var e=fe(fe({},Di),{});return function(t){function n(){return ne(this,n),Re(this,n,arguments)}return Ce(n,t),ie(n,[{key:"getDefinition",value:function(){return{VERTICES:6,VERTEX_SHADER_SOURCE:Pi,FRAGMENT_SHADER_SOURCE:Fi,METHOD:WebGLRenderingContext.TRIANGLES,UNIFORMS:Oi,ATTRIBUTES:[{name:"a_positionStart",size:2,type:oe},{name:"a_positionEnd",size:2,type:oe},{name:"a_normal",size:2,type:oe},{name:"a_color",size:4,type:Sr,normalized:!0},{name:"a_id",size:4,type:Sr,normalized:!0},{name:"a_radius",size:1,type:oe}],CONSTANT_ATTRIBUTES:[{name:"a_positionCoef",size:1,type:oe},{name:"a_normalCoef",size:1,type:oe},{name:"a_radiusCoef",size:1,type:oe}],CONSTANT_DATA:[[0,1,0],[0,-1,0],[1,1,1],[1,1,1],[0,-1,0],[1,-1,-1]]}}},{key:"processVisibleItem",value:function(o,a,s,l,c){var u=c.size||1,d=s.x,h=s.y,m=l.x,g=l.y,b=X(c.color),E=m-d,v=g-h,T=l.size||1,_=E*E+v*v,f=0,p=0;_&&(_=1/Math.sqrt(_),f=-v*_*u,p=E*_*u);var y=this.array;y[a++]=d,y[a++]=h,y[a++]=m,y[a++]=g,y[a++]=f,y[a++]=p,y[a++]=b,y[a++]=o,y[a++]=T}},{key:"setUniforms",value:function(o,a){var s=a.gl,l=a.uniformLocations,c=l.u_matrix,u=l.u_zoomRatio,d=l.u_feather,h=l.u_pixelRatio,m=l.u_correctionRatio,g=l.u_sizeRatio,b=l.u_minEdgeThickness,E=l.u_lengthToThicknessRatio;s.uniformMatrix3fv(c,!1,o.matrix),s.uniform1f(u,o.zoomRatio),s.uniform1f(g,o.sizeRatio),s.uniform1f(m,o.correctionRatio),s.uniform1f(h,o.pixelRatio),s.uniform1f(d,o.antiAliasingFeather),s.uniform1f(b,o.minEdgeThickness),s.uniform1f(E,e.lengthToThicknessRatio)}}])}(ct)}xr();function ki(r){return _i([xr(),wr()])}ki();function Ii(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}var ht,Lr;function zi(){return Lr||(Lr=1,ht=function(e){return e!==null&&typeof e=="object"&&typeof e.addUndirectedEdgeWithKey=="function"&&typeof e.dropNode=="function"&&typeof e.multi=="boolean"}),ht}var Gi=zi();const Mi=Ii(Gi);function Ui(r,e){if(typeof r!="object"||!r)return r;var t=r[Symbol.toPrimitive];if(t!==void 0){var n=t.call(r,e);if(typeof n!="object")return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return(e==="string"?String:Number)(r)}function Fr(r){var e=Ui(r,"string");return typeof e=="symbol"?e:e+""}function Nr(r,e,t){return(e=Fr(e))in r?Object.defineProperty(r,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):r[e]=t,r}function Pr(r,e){var t=Object.keys(r);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(r);e&&(n=n.filter(function(i){return Object.getOwnPropertyDescriptor(r,i).enumerable})),t.push.apply(t,n)}return t}function Me(r){for(var e=1;er.length)&&(e=r.length);for(var t=0,n=Array(e);tU){var B="…";for(b=b+B,D=o.measureText(b).width;D>U&&b.length>1;)b=b.slice(0,-2)+B,D=o.measureText(b).width;if(b.length<4)return}for(var Y={},J=0,ee=b.length;Jr.length)&&(e=r.length);for(var t=0,n=Array(e);t v_radius) gl_FragColor = transparent; else { gl_FragColor = v_color; gl_FragColor.a *= bias; } #else // Sizes: `).concat(e.flatMap(function(i,o){var a=i.size;if("fill"in a)return[];a=a;var s="attribute"in a?"v_borderSize_".concat(o+1):st(a.value),l=(a.mode||yo)==="pixels"?"u_correctionRatio":"v_radius";return[" float borderSize_".concat(o+1," = ").concat(l," * ").concat(s,";")]}).join(` `),` // Now, let's split the remaining space between "fill" borders: float fillBorderSize = (v_radius - (`).concat(e.flatMap(function(i,o){var a=i.size;return"fill"in a?[]:["borderSize_".concat(o+1)]}).join(" + "),") ) / ").concat(t,`; `).concat(e.flatMap(function(i,o){var a=i.size;return"fill"in a?[" float borderSize_".concat(o+1," = fillBorderSize;")]:[]}).join(` `),` // Finally, normalize all border sizes, to start from the full size and to end with the smallest: float adjustedBorderSize_0 = v_radius; `).concat(e.map(function(i,o){return" float adjustedBorderSize_".concat(o+1," = adjustedBorderSize_").concat(o," - borderSize_").concat(o+1,";")}).join(` `),` // Colors: vec4 borderColor_0 = transparent; `).concat(e.map(function(i,o){var a=i.color,s=[];return"attribute"in a?s.push(" vec4 borderColor_".concat(o+1," = v_borderColor_").concat(o+1,";")):"transparent"in a?s.push(" vec4 borderColor_".concat(o+1," = vec4(0.0, 0.0, 0.0, 0.0);")):s.push(" vec4 borderColor_".concat(o+1," = u_borderColor_").concat(o+1,";")),s.push(" borderColor_".concat(o+1,".a *= bias;")),s.push(" if (borderSize_".concat(o+1," <= 1.0 * u_correctionRatio) { borderColor_").concat(o+1," = borderColor_").concat(o,"; }")),s.join(` `)}).join(` `),` if (dist > adjustedBorderSize_0) { gl_FragColor = borderColor_0; } else `).concat(e.map(function(i,o){return"if (dist > adjustedBorderSize_".concat(o,` - aaBorder) { gl_FragColor = mix(borderColor_`).concat(o+1,", borderColor_").concat(o,", (dist - adjustedBorderSize_").concat(o,` + aaBorder) / aaBorder); } else if (dist > adjustedBorderSize_`).concat(o+1,`) { gl_FragColor = borderColor_`).concat(o+1,`; } else `)}).join(""),` { /* Nothing to add here */ } #endif } `);return n}function Co(r){var e=r.borders,t=` attribute vec2 a_position; attribute float a_size; attribute float a_angle; uniform mat3 u_matrix; uniform float u_sizeRatio; uniform float u_correctionRatio; varying vec2 v_diffVector; varying float v_radius; #ifdef PICKING_MODE attribute vec4 a_id; varying vec4 v_color; #else `.concat(e.flatMap(function(n,i){var o=n.size;return"attribute"in o?["attribute float a_borderSize_".concat(i+1,";"),"varying float v_borderSize_".concat(i+1,";")]:[]}).join(` `),` `).concat(e.flatMap(function(n,i){var o=n.color;return"attribute"in o?["attribute vec4 a_borderColor_".concat(i+1,";"),"varying vec4 v_borderColor_".concat(i+1,";")]:[]}).join(` `),` #endif const float bias = 255.0 / 254.0; const vec4 transparent = vec4(0.0, 0.0, 0.0, 0.0); void main() { float size = a_size * u_correctionRatio / u_sizeRatio * 4.0; vec2 diffVector = size * vec2(cos(a_angle), sin(a_angle)); vec2 position = a_position + diffVector; gl_Position = vec4( (u_matrix * vec3(position, 1)).xy, 0, 1 ); v_radius = size / 2.0; v_diffVector = diffVector; #ifdef PICKING_MODE v_color = a_id; #else `).concat(e.flatMap(function(n,i){var o=n.size;return"attribute"in o?[" v_borderSize_".concat(i+1," = a_borderSize_").concat(i+1,";")]:[]}).join(` `),` `).concat(e.flatMap(function(n,i){var o=n.color;return"attribute"in o?[" v_borderColor_".concat(i+1," = a_borderColor_").concat(i+1,";")]:[]}).join(` `),` #endif } `);return t}var $r=WebGLRenderingContext,jr=$r.UNSIGNED_BYTE,He=$r.FLOAT;function Vr(r){var e,t=Hr(Hr({},Eo),r||{}),n=t.borders,i=t.drawLabel,o=t.drawHover,a=["u_sizeRatio","u_correctionRatio","u_matrix"].concat(_t(n.flatMap(function(s,l){var c=s.color;return"value"in c?["u_borderColor_".concat(l+1)]:[]})));return e=function(s){function l(){var c;co(this,l);for(var u=arguments.length,d=new Array(u),h=0;h0&&(x=y[0]),x instanceof Error)throw x;var O=new Error("Unhandled error."+(x?" ("+x.message+")":""));throw O.context=x,O}var k=F[p];if(k===void 0)return!1;if(typeof k=="function")e(k,this,y);else for(var z=k.length,M=g(k,z),R=0;R0&&x.length>S&&!x.warned){x.warned=!0;var O=new Error("Possible EventEmitter memory leak detected. "+x.length+" "+String(p)+" listeners added. Use emitter.setMaxListeners() to increase limit");O.name="MaxListenersExceededWarning",O.emitter=f,O.type=p,O.count=x.length,n(O)}return f}o.prototype.addListener=function(p,y){return c(this,p,y,!1)},o.prototype.on=o.prototype.addListener,o.prototype.prependListener=function(p,y){return c(this,p,y,!0)};function u(){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 d(f,p,y){var R={fired:!1,wrapFn:void 0,target:f,type:p,listener:y},S=u.bind(R);return S.listener=y,R.wrapFn=S,S}o.prototype.once=function(p,y){return s(y),this.on(p,d(this,p,y)),this},o.prototype.prependOnceListener=function(p,y){return s(y),this.prependListener(p,d(this,p,y)),this},o.prototype.removeListener=function(p,y){var R,S,F,x,O;if(s(y),S=this._events,S===void 0)return this;if(R=S[p],R===void 0)return this;if(R===y||R.listener===y)--this._eventsCount===0?this._events=Object.create(null):(delete S[p],S.removeListener&&this.emit("removeListener",p,R.listener||y));else if(typeof R!="function"){for(F=-1,x=R.length-1;x>=0;x--)if(R[x]===y||R[x].listener===y){O=R[x].listener,F=x;break}if(F<0)return this;F===0?R.shift():b(R,F),R.length===1&&(S[p]=R[0]),S.removeListener!==void 0&&this.emit("removeListener",p,O||y)}return this},o.prototype.off=o.prototype.removeListener,o.prototype.removeAllListeners=function(p){var y,R,S;if(R=this._events,R===void 0)return this;if(R.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):R[p]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete R[p]),this;if(arguments.length===0){var F=Object.keys(R),x;for(S=0;S=0;S--)this.removeListener(p,y[S]);return this};function h(f,p,y){var R=f._events;if(R===void 0)return[];var S=R[p];return S===void 0?[]:typeof S=="function"?y?[S.listener||S]:[S]:y?E(S):g(S,S.length)}o.prototype.listeners=function(p){return h(this,p,!0)},o.prototype.rawListeners=function(p){return h(this,p,!1)},o.listenerCount=function(f,p){return typeof f.listenerCount=="function"?f.listenerCount(p):m.call(f,p)},o.prototype.listenerCount=m;function m(f){var p=this._events;if(p!==void 0){var y=p[f];if(typeof y=="function")return 1;if(y!==void 0)return y.length}return 0}o.prototype.eventNames=function(){return this._eventsCount>0?t(this._events):[]};function g(f,p){for(var y=new Array(p),R=0;Rr.length)&&(e=r.length);for(var t=0,n=Array(e);t v_radius / paddingRatio || abs(diffVector.y) > v_radius / paddingRatio) { color = u_colorizeImages ? gl_FragColor : v_color; } } } #endif // Crop in a circle when u_keepWithinCircle is truthy: if (u_keepWithinCircle) { if (dist < v_radius - border) { gl_FragColor = color; } else if (dist < v_radius) { gl_FragColor = mix(transparent, color, (v_radius - dist) / border); } } // Crop in a square else: else { float squareHalfSize = v_radius * `).concat(Math.SQRT1_2*Math.cos(Math.PI/12),`; if (abs(diffVector.x) > squareHalfSize || abs(diffVector.y) > squareHalfSize) { gl_FragColor = transparent; } else { gl_FragColor = color; } } } `);return t}var Go=` attribute vec4 a_id; attribute vec4 a_color; attribute vec2 a_position; attribute float a_size; attribute float a_angle; attribute vec4 a_texture; attribute float a_textureIndex; uniform mat3 u_matrix; uniform float u_sizeRatio; uniform float u_correctionRatio; varying vec4 v_color; varying vec2 v_diffVector; varying float v_radius; varying vec4 v_texture; varying float v_textureIndex; const float bias = 255.0 / 254.0; const float marginRatio = 1.05; void main() { float size = a_size * u_correctionRatio / u_sizeRatio * 4.0; vec2 diffVector = size * vec2(cos(a_angle), sin(a_angle)); vec2 position = a_position + diffVector * marginRatio; gl_Position = vec4( (u_matrix * vec3(position, 1)).xy, 0, 1 ); v_diffVector = diffVector; v_radius = size / 2.0 / marginRatio; #ifdef PICKING_MODE // For picking mode, we use the ID as the color: v_color = a_id; #else // For normal mode, we use the color: v_color = a_color; // Pass the texture coordinates: v_textureIndex = a_textureIndex; v_texture = a_texture; #endif v_color.a *= bias; } `,Mo=Go;function ae(){ae=function(){return e};var r,e={},t=Object.prototype,n=t.hasOwnProperty,i=Object.defineProperty||function(w,C,A){w[C]=A.value},o=typeof Symbol=="function"?Symbol:{},a=o.iterator||"@@iterator",s=o.asyncIterator||"@@asyncIterator",l=o.toStringTag||"@@toStringTag";function c(w,C,A){return Object.defineProperty(w,C,{value:A,enumerable:!0,configurable:!0,writable:!0}),w[C]}try{c({},"")}catch{c=function(C,A,N){return C[A]=N}}function u(w,C,A,N){var L=C&&C.prototype instanceof v?C:v,P=Object.create(L.prototype),D=new M(N||[]);return i(P,"_invoke",{value:x(w,A,D)}),P}function d(w,C,A){try{return{type:"normal",arg:w.call(C,A)}}catch(N){return{type:"throw",arg:N}}}e.wrap=u;var h="suspendedStart",m="suspendedYield",g="executing",b="completed",E={};function v(){}function T(){}function _(){}var f={};c(f,a,function(){return this});var p=Object.getPrototypeOf,y=p&&p(p(H([])));y&&y!==t&&n.call(y,a)&&(f=y);var R=_.prototype=v.prototype=Object.create(f);function S(w){["next","throw","return"].forEach(function(C){c(w,C,function(A){return this._invoke(C,A)})})}function F(w,C){function A(L,P,D,U){var B=d(w[L],w,P);if(B.type!=="throw"){var Y=B.arg,J=Y.value;return J&&typeof J=="object"&&n.call(J,"__await")?C.resolve(J.__await).then(function(ee){A("next",ee,D,U)},function(ee){A("throw",ee,D,U)}):C.resolve(J).then(function(ee){Y.value=ee,D(Y)},function(ee){return A("throw",ee,D,U)})}U(B.arg)}var N;i(this,"_invoke",{value:function(L,P){function D(){return new C(function(U,B){A(L,P,U,B)})}return N=N?N.then(D,D):D()}})}function x(w,C,A){var N=h;return function(L,P){if(N===g)throw Error("Generator is already running");if(N===b){if(L==="throw")throw P;return{value:r,done:!0}}for(A.method=L,A.arg=P;;){var D=A.delegate;if(D){var U=O(D,A);if(U){if(U===E)continue;return U}}if(A.method==="next")A.sent=A._sent=A.arg;else if(A.method==="throw"){if(N===h)throw N=b,A.arg;A.dispatchException(A.arg)}else A.method==="return"&&A.abrupt("return",A.arg);N=g;var B=d(w,C,A);if(B.type==="normal"){if(N=A.done?b:m,B.arg===E)continue;return{value:B.arg,done:A.done}}B.type==="throw"&&(N=b,A.method="throw",A.arg=B.arg)}}}function O(w,C){var A=C.method,N=w.iterator[A];if(N===r)return C.delegate=null,A==="throw"&&w.iterator.return&&(C.method="return",C.arg=r,O(w,C),C.method==="throw")||A!=="return"&&(C.method="throw",C.arg=new TypeError("The iterator does not provide a '"+A+"' method")),E;var L=d(N,w.iterator,C.arg);if(L.type==="throw")return C.method="throw",C.arg=L.arg,C.delegate=null,E;var P=L.arg;return P?P.done?(C[w.resultName]=P.value,C.next=w.nextLoc,C.method!=="return"&&(C.method="next",C.arg=r),C.delegate=null,E):P:(C.method="throw",C.arg=new TypeError("iterator result is not an object"),C.delegate=null,E)}function k(w){var C={tryLoc:w[0]};1 in w&&(C.catchLoc=w[1]),2 in w&&(C.finallyLoc=w[2],C.afterLoc=w[3]),this.tryEntries.push(C)}function z(w){var C=w.completion||{};C.type="normal",delete C.arg,w.completion=C}function M(w){this.tryEntries=[{tryLoc:"root"}],w.forEach(k,this),this.reset(!0)}function H(w){if(w||w===""){var C=w[a];if(C)return C.call(w);if(typeof w.next=="function")return w;if(!isNaN(w.length)){var A=-1,N=function L(){for(;++A=0;--N){var L=this.tryEntries[N],P=L.completion;if(L.tryLoc==="root")return A("end");if(L.tryLoc<=this.prev){var D=n.call(L,"catchLoc"),U=n.call(L,"finallyLoc");if(D&&U){if(this.prev=0;--A){var N=this.tryEntries[A];if(N.tryLoc<=this.prev&&n.call(N,"finallyLoc")&&this.prev=0;--C){var A=this.tryEntries[C];if(A.finallyLoc===w)return this.complete(A.completion,A.afterLoc),z(A),E}},catch:function(w){for(var C=this.tryEntries.length-1;C>=0;--C){var A=this.tryEntries[C];if(A.tryLoc===w){var N=A.completion;if(N.type==="throw"){var L=N.arg;z(A)}return L}}throw Error("illegal catch attempt")},delegateYield:function(w,C,A){return this.delegate={iterator:H(w),resultName:C,nextLoc:A},this.method==="next"&&(this.arg=r),E}},e}function en(r,e,t,n,i,o,a){try{var s=r[o](a),l=s.value}catch(c){return void t(c)}s.done?e(l):Promise.resolve(l).then(n,i)}function wt(r){return function(){var e=this,t=arguments;return new Promise(function(n,i){var o=r.apply(e,t);function a(l){en(o,n,i,a,s,"next",l)}function s(l){en(o,n,i,a,s,"throw",l)}a(void 0)})}}var At={size:{mode:"max",value:512},objectFit:"cover",correctCentering:!1,maxTextureSize:4096,debounceTimeout:500,crossOrigin:"anonymous"},Uo=1;function St(r){var e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},t=e.crossOrigin;return new Promise(function(n,i){var o=new Image;o.addEventListener("load",function(){n(o)},{once:!0}),o.addEventListener("error",function(a){i(a.error)},{once:!0}),t&&o.setAttribute("crossOrigin",t),o.src=r})}function Bo(r){return xt.apply(this,arguments)}function xt(){return xt=wt(ae().mark(function r(e){var t,n,i,o,a,s,l,c,u,d,h,m,g,b=arguments;return ae().wrap(function(v){for(;;)switch(v.prev=v.next){case 0:if(t=b.length>1&&b[1]!==void 0?b[1]:{},n=t.size,i=t.crossOrigin,i!=="use-credentials"){v.next=7;break}return v.next=4,fetch(e,{credentials:"include"});case 4:o=v.sent,v.next=10;break;case 7:return v.next=9,fetch(e);case 9:o=v.sent;case 10:return v.next=12,o.text();case 12:if(a=v.sent,s=new DOMParser().parseFromString(a,"image/svg+xml"),l=s.documentElement,c=l.getAttribute("width"),u=l.getAttribute("height"),!(!c||!u)){v.next=19;break}throw new Error("loadSVGImage: cannot use `size` if target SVG has no definite dimensions.");case 19:return typeof n=="number"&&(l.setAttribute("width",""+n),l.setAttribute("height",""+n)),d=new XMLSerializer().serializeToString(s),h=new Blob([d],{type:"image/svg+xml"}),m=URL.createObjectURL(h),g=St(m),g.finally(function(){return URL.revokeObjectURL(m)}),v.abrupt("return",g);case 26:case"end":return v.stop()}},r)})),xt.apply(this,arguments)}function Ho(r){return Lt.apply(this,arguments)}function Lt(){return Lt=wt(ae().mark(function r(e){var t,n,i,o,a,s,l=arguments;return ae().wrap(function(u){for(;;)switch(u.prev=u.next){case 0:if(n=l.length>1&&l[1]!==void 0?l[1]:{},i=n.size,o=n.crossOrigin,a=((t=e.split(/[#?]/)[0].split(".").pop())===null||t===void 0?void 0:t.trim().toLowerCase())==="svg",!(a&&i)){u.next=16;break}return u.prev=3,u.next=6,Bo(e,{size:i,crossOrigin:o});case 6:s=u.sent,u.next=14;break;case 9:return u.prev=9,u.t0=u.catch(3),u.next=13,St(e,{crossOrigin:o});case 13:s=u.sent;case 14:u.next=19;break;case 16:return u.next=18,St(e,{crossOrigin:o});case 18:s=u.sent;case 19:return u.abrupt("return",s);case 20:case"end":return u.stop()}},r,null,[[3,9]])})),Lt.apply(this,arguments)}function $o(r,e,t){var n=t.objectFit,i=t.size,o=t.correctCentering,a=n==="contain"?Math.max(r.width,r.height):Math.min(r.width,r.height),s=i.mode==="auto"?a:i.mode==="force"?i.value:Math.min(i.value,a),l=(r.width-a)/2,c=(r.height-a)/2;if(o){var u=e.getCorrectionOffset(r,a);l=u.x,c=u.y}return{sourceX:l,sourceY:c,sourceSize:a,destinationSize:s}}function jo(r,e,t){for(var n=e.canvas,i=n.width,o=n.height,a=[],s=t.x,l=t.y,c=t.rowHeight,u=t.maxRowWidth,d={},h=0,m=r.length;ho||s+p>i&&l+p+c>o||(s+p>i&&(u=Math.max(u,s),s=0,l+=c,c=p),a.push({key:b,image:E,sourceX:T,sourceY:_,sourceSize:v,destinationX:s,destinationY:l,destinationSize:f}),d[b]={x:s,y:l,size:f},s+=p,c=Math.max(c,p))}u=Math.max(u,s);for(var y=u,R=l+c,S=0,F=a.length;S0&&arguments[0]!==void 0?arguments[0]:{};return Et(this,e),t=Kr(this,e),G(t,"canvas",document.createElement("canvas")),G(t,"ctx",t.canvas.getContext("2d",{willReadFrequently:!0})),G(t,"corrector",new Wo),G(t,"imageStates",{}),G(t,"textures",[t.ctx.getImageData(0,0,1,1)]),G(t,"lastTextureCursor",{x:0,y:0,rowHeight:0,maxRowWidth:0}),G(t,"atlas",{}),t.options=$($({},At),n),t.canvas.width=t.options.maxTextureSize,t.canvas.height=t.options.maxTextureSize,t}return Qr(e,r),Tt(e,[{key:"scheduleGenerateTexture",value:function(){var n=this;typeof this.frameId!="number"&&(typeof this.options.debounceTimeout=="number"?this.frameId=window.setTimeout(function(){n.generateTextures(),n.frameId=void 0},this.options.debounceTimeout):this.generateTextures())}},{key:"generateTextures",value:function(){var n=Vo({atlas:this.atlas,textures:this.textures,cursor:this.lastTextureCursor},this.imageStates,this.ctx),i=n.atlas,o=n.textures,a=n.cursor;this.atlas=i,this.textures=o,this.lastTextureCursor=a,this.emit(e.NEW_TEXTURE_EVENT,{atlas:i,textures:o})}},{key:"registerImage",value:function(){var t=wt(ae().mark(function i(o){var a,s;return ae().wrap(function(c){for(;;)switch(c.prev=c.next){case 0:if(!this.imageStates[o]){c.next=2;break}return c.abrupt("return");case 2:return this.imageStates[o]={status:"loading"},c.prev=3,a=this.options.size,c.next=7,Ho(o,{size:a.mode==="force"?a.value:void 0,crossOrigin:this.options.crossOrigin||void 0});case 7:s=c.sent,this.imageStates[o]=$({status:"ready",image:s},$o(s,this.corrector,this.options)),this.scheduleGenerateTexture(),c.next=15;break;case 12:c.prev=12,c.t0=c.catch(3),this.imageStates[o]={status:"error"};case 15:case"end":return c.stop()}},i,this,[[3,12]])}));function n(i){return t.apply(this,arguments)}return n}()},{key:"getAtlas",value:function(){return this.atlas}},{key:"getTextures",value:function(){return this.textures}}])}(Yr.EventEmitter);G(je,"NEW_TEXTURE_EVENT","newTexture");var Yo=["drawHover","drawLabel","drawingMode","keepWithinCircle","padding","colorAttribute","imageAttribute"],tn=WebGLRenderingContext,rn=tn.UNSIGNED_BYTE,we=tn.FLOAT,Xo=$($({},At),{},{drawingMode:"background",keepWithinCircle:!0,drawLabel:void 0,drawHover:void 0,padding:0,colorAttribute:"color",imageAttribute:"image"}),qo=["u_sizeRatio","u_correctionRatio","u_cameraAngle","u_percentagePadding","u_matrix","u_colorizeImages","u_keepWithinCircle","u_atlas"];function Ft(r){var e,t=document.createElement("canvas").getContext("webgl"),n=Math.min(t.getParameter(t.MAX_TEXTURE_SIZE),At.maxTextureSize);t.canvas.remove();var i=$($($({},Xo),{maxTextureSize:n}),r||{}),o=i.drawHover,a=i.drawLabel,s=i.drawingMode,l=i.keepWithinCircle,c=i.padding,u=i.colorAttribute,d=i.imageAttribute,h=Io(i,Yo),m=new je(h);return e=function(g){function b(E,v,T){var _;return Et(this,b),_=Kr(this,b,[E,v,T]),G(_,"drawLabel",a),G(_,"drawHover",o),G(_,"textureManagerCallback",null),_.textureManagerCallback=function(f){var p=f.atlas,y=f.textures,R=y.length!==_.textures.length;_.atlas=p,_.textureImages=y,R&&_.upgradeShaders(),_.bindTextures(),_.latestRenderParams&&_.render(_.latestRenderParams),_.renderer&&_.renderer.refresh&&_.renderer.refresh()},m.on(je.NEW_TEXTURE_EVENT,_.textureManagerCallback),_.atlas=m.getAtlas(),_.textureImages=m.getTextures(),_.textures=_.textureImages.map(function(){return E.createTexture()}),_.bindTextures(),_}return Qr(b,g),Tt(b,[{key:"getDefinition",value:function(){return{VERTICES:3,VERTEX_SHADER_SOURCE:Mo,FRAGMENT_SHADER_SOURCE:zo({texturesCount:m.getTextures().length}),METHOD:WebGLRenderingContext.TRIANGLES,UNIFORMS:qo,ATTRIBUTES:[{name:"a_position",size:2,type:we},{name:"a_size",size:1,type:we},{name:"a_color",size:4,type:rn,normalized:!0},{name:"a_id",size:4,type:rn,normalized:!0},{name:"a_texture",size:4,type:we},{name:"a_textureIndex",size:1,type:we}],CONSTANT_ATTRIBUTES:[{name:"a_angle",size:1,type:we}],CONSTANT_DATA:[[b.ANGLE_1],[b.ANGLE_2],[b.ANGLE_3]]}}},{key:"upgradeShaders",value:function(){var v=this.getDefinition(),T=this.normalProgram,_=T.program,f=T.buffer,p=T.vertexShader,y=T.fragmentShader,R=T.gl;R.deleteProgram(_),R.deleteBuffer(f),R.deleteShader(p),R.deleteShader(y),this.normalProgram=this.getProgramInfo("normal",R,v.VERTEX_SHADER_SOURCE,v.FRAGMENT_SHADER_SOURCE,null)}},{key:"kill",value:function(){var v,T=(v=this.normalProgram)===null||v===void 0?void 0:v.gl;if(T)for(var _=0;_=this.textures.length){var _=v.createTexture();_&&this.textures.push(_)}v.activeTexture(v.TEXTURE0+T),v.bindTexture(v.TEXTURE_2D,this.textures[T]),v.texImage2D(v.TEXTURE_2D,0,v.RGBA,v.RGBA,v.UNSIGNED_BYTE,this.textureImages[T]),v.generateMipmap(v.TEXTURE_2D)}}},{key:"renderProgram",value:function(v,T){if(!T.isPicking)for(var _=T.gl,f=0;fr.length)&&(e=r.length);for(var t=0,n=Array(e);t v_radius) gl_FragColor = transparent; else { gl_FragColor = v_color; gl_FragColor.a *= bias; } #else // Colors: `).concat(e.map(function(i,o){var a=i.color,s=[];return"attribute"in a?s.push(" vec4 sliceColor_".concat(o+1," = v_sliceColor_").concat(o+1,";")):"transparent"in a?s.push(" vec4 sliceColor_".concat(o+1," = vec4(0.0, 0.0, 0.0, 0.0);")):s.push(" vec4 sliceColor_".concat(o+1," = u_sliceColor_").concat(o+1,";")),s.push(" sliceColor_".concat(o+1,".a *= bias;")),s.join(` `)}).join(` `),` vec4 color = u_defaultColor; color.a *= bias; // Sizes: `).concat(e.map(function(i,o){var a=i.value;return" float sliceValue_".concat(o+1," = ").concat("attribute"in a?"v_sliceValue_".concat(o+1):st(a.value),";")}).join(` `),` // Angles and final color: float total = `).concat(e.map(function(i,o){return"sliceValue_".concat(o+1)}).join(" + "),`; float angle_0 = 0.0; if (total > 0.0) { `).concat(e.map(function(i,o){return" float angle_".concat(o+1," = angle_").concat(o," + sliceValue_").concat(o+1," * ").concat(2*Math.PI," / total;")}).join(` `),` `).concat(e.map(function(i,o){return"if (angle < angle_".concat(o+1,") color = sliceColor_").concat(o+1,";")}).join(` else `),` } if (dist < v_radius - aaBorder) { gl_FragColor = color; } else if (dist < v_radius) { gl_FragColor = mix(transparent, color, (v_radius - dist) / aaBorder); } #endif } `);return n}function fa(r){var e=r.slices,t=r.offset,n=` attribute vec4 a_id; attribute vec2 a_position; attribute float a_size; attribute float a_angle; uniform mat3 u_matrix; uniform float u_sizeRatio; uniform float u_correctionRatio; varying vec2 v_diffVector; varying float v_radius; `.concat("attribute"in t?`attribute float a_offset; `:"",` `).concat("attribute"in t?`varying float v_offset; `:"",` #ifdef PICKING_MODE varying vec4 v_color; #else `).concat(e.flatMap(function(i,o){var a=i.value;return"attribute"in a?["attribute float a_sliceValue_".concat(o+1,";"),"varying float v_sliceValue_".concat(o+1,";")]:[]}).join(` `),` `).concat(e.flatMap(function(i,o){var a=i.color;return"attribute"in a?["attribute vec4 a_sliceColor_".concat(o+1,";"),"varying vec4 v_sliceColor_".concat(o+1,";")]:[]}).join(` `),` #endif const vec4 transparent = vec4(0.0, 0.0, 0.0, 0.0); void main() { float size = a_size * u_correctionRatio / u_sizeRatio * 4.0; vec2 diffVector = size * vec2(cos(a_angle), sin(a_angle)); vec2 position = a_position + diffVector; gl_Position = vec4( (u_matrix * vec3(position, 1)).xy, 0, 1 ); v_radius = size / 2.0; v_diffVector = diffVector; `).concat("attribute"in t?`v_offset = a_offset; `:"",` #ifdef PICKING_MODE v_color = a_id; #else `).concat(e.flatMap(function(i,o){var a=i.value;return"attribute"in a?[" v_sliceValue_".concat(o+1," = a_sliceValue_").concat(o+1,";")]:[]}).join(` `),` `).concat(e.flatMap(function(i,o){var a=i.color;return"attribute"in a?[" v_sliceColor_".concat(o+1," = a_sliceColor_").concat(o+1,";")]:[]}).join(` `),` #endif } `);return n}var Dt="#000000",ga={drawLabel:void 0,drawHover:void 0,defaultColor:Dt,offset:{value:0}},un=WebGLRenderingContext,hn=un.UNSIGNED_BYTE,Se=un.FLOAT;function ma(r){var e,t=ln(ln({},ga),r),n=t.slices,i=t.offset,o=t.drawHover,a=t.drawLabel,s=["u_sizeRatio","u_correctionRatio","u_cameraAngle","u_matrix","u_defaultColor"].concat(Ae("value"in i?["u_offset"]:[]),Ae(n.flatMap(function(l,c){var u=l.color;return"value"in u?["u_sliceColor_".concat(c+1)]:[]})));return e=function(l){function c(){var u;Jo(this,c);for(var d=arguments.length,h=new Array(d),m=0;mv)throw new Error("createNodePiechartProgram: Too many slices. The node program requires ".concat(E," vertex attributes, but the current WebGL context only supports ").concat(v,". Please reduce the number of slices."));return sa(c,"getProgramInfo",this,3)([d,h,m,g,b])}},{key:"processVisibleItem",value:function(d,h,m){var g=this.array;g[h++]=m.x,g[h++]=m.y,g[h++]=d,g[h++]=m.size,"attribute"in i&&(g[h++]=m[i.attribute]||0),n.forEach(function(b){var E=b.color;"attribute"in E&&(g[h++]=X(m[E.attribute]||E.defaultValue||Dt))}),n.forEach(function(b){var E=b.value;"attribute"in E&&(g[h++]=m[E.attribute]||0)})}},{key:"setUniforms",value:function(d,h){var m=h.gl,g=h.uniformLocations,b=g.u_sizeRatio,E=g.u_correctionRatio,v=g.u_cameraAngle,T=g.u_matrix,_=g.u_defaultColor;m.uniform1f(E,d.correctionRatio),m.uniform1f(b,d.sizeRatio),m.uniform1f(v,d.cameraAngle),m.uniformMatrix3fv(T,!1,d.matrix),"value"in i&&m.uniform1f(g.u_offset,i.value);var f=nt(t.defaultColor||Dt),p=on(f,4),y=p[0],R=p[1],S=p[2],F=p[3];m.uniform4f(_,y/255,R/255,S/255,F/255),n.forEach(function(x,O){var k=x.color;if("value"in k){var z=g["u_sliceColor_".concat(O+1)],M=nt(k.value),H=on(M,4),w=H[0],C=H[1],A=H[2],N=H[3];m.uniform4f(z,w/255,C/255,A/255,N/255)}})}}])}(Ie),pe(e,"ANGLE_1",0),pe(e,"ANGLE_2",2*Math.PI/3),pe(e,"ANGLE_3",4*Math.PI/3),e}const dn=r=>r,fn=r=>r*r,gn=r=>r*(2-r),mn=r=>(r*=2)<1?.5*r*r:-.5*(--r*(r-2)-1),vn=r=>r*r*r,pn=r=>--r*r*r+1,_n=r=>(r*=2)<1?.5*r*r*r:.5*((r-=2)*r*r+2),kt={linear:dn,quadraticIn:fn,quadraticOut:gn,quadraticInOut:mn,cubicIn:vn,cubicOut:pn,cubicInOut:_n},It={easing:"quadraticInOut",duration:150};function va(r,e,t,n){const i=Object.assign({},It,t),o=typeof i.easing=="function"?i.easing:kt[i.easing],a=Date.now(),s={};for(const u in e){const d=e[u];s[u]={};for(const h in d)s[u][h]=r.getNodeAttribute(u,h)}let l=null;const c=()=>{l=null;let u=(Date.now()-a)/i.duration;if(u>=1){for(const d in e){const h=e[d];for(const m in h)r.setNodeAttribute(d,m,h[m])}typeof n=="function"&&n();return}u=o(u);for(const d in e){const h=e[d],m=s[d];for(const g in h)r.setNodeAttribute(d,g,h[g]*u+m[g]*(1-u))}l=requestAnimationFrame(c)};return c(),()=>{l&&cancelAnimationFrame(l)}}const Ve={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"};function pa(r,e,t,n){const i=n||new Uint8Array(4);return r.readPixels(e,t,1,1,r.RGBA,r.UNSIGNED_BYTE,i),i}const bn=new Int8Array(4),We=new Int32Array(bn.buffer,0,1),yn=new Float32Array(bn.buffer,0,1),_a=/^\s*rgba?\s*\(/,ba=/^\s*rgba?\s*\(\s*([0-9]*)\s*,\s*([0-9]*)\s*,\s*([0-9]*)(?:\s*,\s*(.*)?)?\)\s*$/;function En(r){let e=0,t=0,n=0,i=1;if(r[0]==="#")r.length===4?(e=parseInt(r.charAt(1)+r.charAt(1),16),t=parseInt(r.charAt(2)+r.charAt(2),16),n=parseInt(r.charAt(3)+r.charAt(3),16)):(e=parseInt(r.charAt(1)+r.charAt(2),16),t=parseInt(r.charAt(3)+r.charAt(4),16),n=parseInt(r.charAt(5)+r.charAt(6),16)),r.length===9&&(i=parseInt(r.charAt(7)+r.charAt(8),16)/255);else if(_a.test(r)){const o=r.match(ba);o&&(e=+o[1],t=+o[2],n=+o[3],o[4]&&(i=+o[4]))}return{r:e,g:t,b:n,a:i}}const _e={};for(const r in Ve)_e[r]=V(Ve[r]),_e[Ve[r]]=_e[r];function zt(r,e,t,n,i){return We[0]=n<<24|t<<16|e<<8|r,i&&(We[0]=We[0]&4278190079),yn[0]}function V(r){if(r=r.toLowerCase(),typeof _e[r]<"u")return _e[r];const e=En(r),{r:t,g:n,b:i}=e;let{a:o}=e;o=o*255|0;const a=zt(t,n,i,o,!0);return _e[r]=a,a}function ya(r,e){yn[0]=V(r);let t=We[0];e&&(t=t|16777216);const n=t&255,i=t>>8&255,o=t>>16&255,a=t>>24&255;return[n,i,o,a]}const Gt={};function Mt(r){if(typeof Gt[r]<"u")return Gt[r];const e=(r&16711680)>>>16,t=(r&65280)>>>8,n=r&255,o=zt(e,t,n,255,!0);return Gt[r]=o,o}function Ut(r,e,t,n){return t+(e<<8)+(r<<16)}function Bt(r,e,t,n,i,o){const a=Math.floor(t/o*i),s=Math.floor(r.drawingBufferHeight/o-n/o*i),l=new Uint8Array(4);r.bindFramebuffer(r.FRAMEBUFFER,e),r.readPixels(a,s,1,1,r.RGBA,r.UNSIGNED_BYTE,l);const[c,u,d,h]=l;return[c,u,d,h]}function j(){return Float32Array.of(1,0,0,0,1,0,0,0,1)}function xe(r,e,t){return r[0]=e,r[4]=typeof t=="number"?t:e,r}function Ht(r,e){const t=Math.sin(e),n=Math.cos(e);return r[0]=n,r[1]=t,r[3]=-t,r[4]=n,r}function $t(r,e,t){return r[6]=e,r[7]=t,r}function q(r,e){const t=r[0],n=r[1],i=r[2],o=r[3],a=r[4],s=r[5],l=r[6],c=r[7],u=r[8],d=e[0],h=e[1],m=e[2],g=e[3],b=e[4],E=e[5],v=e[6],T=e[7],_=e[8];return r[0]=d*t+h*o+m*l,r[1]=d*n+h*a+m*c,r[2]=d*i+h*s+m*u,r[3]=g*t+b*o+E*l,r[4]=g*n+b*a+E*c,r[5]=g*i+b*s+E*u,r[6]=v*t+T*o+_*l,r[7]=v*n+T*a+_*c,r[8]=v*i+T*s+_*u,r}function Ye(r,e,t=1){const n=r[0],i=r[1],o=r[3],a=r[4],s=r[6],l=r[7],c=e.x,u=e.y;return{x:c*n+u*o+s*t,y:c*i+u*a+l*t}}function Tn(r,e){const t=r.height/r.width,n=e.height/e.width;return t<1&&n>1||t>1&&n<1?1:Math.min(Math.max(n,1/n),Math.max(1/t,t))}function be(r,e,t,n,i){const{angle:o,ratio:a,x:s,y:l}=r,{width:c,height:u}=e,d=j(),h=Math.min(c,u)-2*n,m=Tn(e,t);return i?(q(d,$t(j(),s,l)),q(d,xe(j(),a)),q(d,Ht(j(),o)),q(d,xe(j(),c/h/2/m,u/h/2/m))):(q(d,xe(j(),2*(h/c)*m,2*(h/u)*m)),q(d,Ht(j(),-o)),q(d,xe(j(),1/a)),q(d,$t(j(),-s,-l))),d}function Rn(r,e,t){const{x:n,y:i}=Ye(r,{x:Math.cos(e.angle),y:Math.sin(e.angle)},0);return 1/Math.sqrt(Math.pow(n,2)+Math.pow(i,2))/t.width}function jt(r,e){const t=e.size;if(t===0)return;const n=r.length;r.length+=t;let i=0;e.forEach(o=>{r[n+i]=o,i++})}function Cn(r){return typeof r=="object"&&r!==null&&r.constructor===Object}function Xe(r,...e){r=r||{};for(let t=0,n=e.length;t{const{x:s,y:l}=a;st&&(t=s),li&&(i=l)}),{x:[e,t],y:[n,i]}}function Sn(r){if(!Mi(r))throw new Error("Sigma: invalid graph instance.");r.forEachNode((e,t)=>{if(!Number.isFinite(t.x)||!Number.isFinite(t.y))throw new Error(`Sigma: Coordinates of node ${e} are invalid. A node must have a numeric 'x' and 'y' attribute.`)})}function xn(r,e,t){const n=document.createElement(r);if(e)for(const i in e)n.style[i]=e[i];if(t)for(const i in t)n.setAttribute(i,t[i]);return n}function Vt(){return typeof window.devicePixelRatio<"u"?window.devicePixelRatio:1}function Wt(r,e,t){return t.sort(function(n,i){const o=e(n)||0,a=e(i)||0;return oa?1:0})}function Yt(r){const{x:[e,t],y:[n,i]}=r;let o=Math.max(t-e,i-n),a=(t+e)/2,s=(i+n)/2;(o===0||Math.abs(o)===1/0||isNaN(o))&&(o=1),isNaN(a)&&(a=0),isNaN(s)&&(s=0);const l=c=>({x:.5+(c.x-a)/o,y:.5+(c.y-s)/o});return l.applyTo=c=>{c.x=.5+(c.x-a)/o,c.y=.5+(c.y-s)/o},l.inverse=c=>({x:a+o*(c.x-.5),y:s+o*(c.y-.5)}),l.ratio=o,l}const Ea=Object.freeze(Object.defineProperty({__proto__:null,ANIMATE_DEFAULTS:It,HTML_COLORS:Ve,animateNodes:va,assign:Xe,assignDeep:wn,colorToArray:ya,colorToIndex:Ut,createElement:xn,createNormalizationFunction:Yt,cubicIn:vn,cubicInOut:_n,cubicOut:pn,easings:kt,extend:jt,extractPixel:pa,floatColor:V,getCorrectionRatio:Tn,getMatrixImpact:Rn,getPixelColor:Bt,getPixelRatio:Vt,graphExtent:An,identity:j,indexToColor:Mt,isPlainObject:Cn,linear:dn,matrixFromCamera:be,multiply:q,multiplyVec2:Ye,parseColor:En,quadraticIn:fn,quadraticInOut:mn,quadraticOut:gn,rgbaToFloat:zt,rotate:Ht,scale:xe,translate:$t,validateGraph:Sn,zIndexOrdering:Wt},Symbol.toStringTag,{value:"Module"}));function Ln(r){return r.normalized?1:r.size}function qe(r){let e=0;return r.forEach(t=>e+=Ln(t)),e}function Fn(r,e,t){const n=r==="VERTEX"?e.VERTEX_SHADER:e.FRAGMENT_SHADER,i=e.createShader(n);if(i===null)throw new Error("loadShader: error while creating the shader");if(e.shaderSource(i,t),e.compileShader(i),!e.getShaderParameter(i,e.COMPILE_STATUS)){const a=e.getShaderInfoLog(i);throw e.deleteShader(i),new Error(`loadShader: error while compiling the shader: ${a} ${t}`)}return i}function Nn(r,e){return Fn("VERTEX",r,e)}function Pn(r,e){return Fn("FRAGMENT",r,e)}function On(r,e){const t=r.createProgram();if(t===null)throw new Error("loadProgram: error while creating the program.");let n,i;for(n=0,i=e.length;n{const b=t.getUniformLocation(u,g);b&&(d[g]=b)});const h={};a.ATTRIBUTES.forEach(g=>{h[g.name]=t.getAttribLocation(u,g.name)});let m;if("CONSTANT_ATTRIBUTES"in a&&(a.CONSTANT_ATTRIBUTES.forEach(g=>{h[g.name]=t.getAttribLocation(u,g.name)}),m=t.createBuffer(),m===null))throw new Error("Program: error while creating the WebGL constant buffer.");return{name:e,program:u,gl:t,frameBuffer:o,buffer:s,constantBuffer:m||{},uniformLocations:d,attributeLocations:h,isPicking:e==="pick",vertexShader:l,fragmentShader:c}}bindProgram(e){let t=0;const{gl:n,buffer:i}=e;this.isInstanced?(n.bindBuffer(n.ARRAY_BUFFER,e.constantBuffer),t=0,this.CONSTANT_ATTRIBUTES.forEach(o=>t+=this.bindAttribute(o,e,t,!1)),n.bufferData(n.ARRAY_BUFFER,this.constantArray,n.STATIC_DRAW),n.bindBuffer(n.ARRAY_BUFFER,e.buffer),t=0,this.ATTRIBUTES.forEach(o=>t+=this.bindAttribute(o,e,t,!0)),n.bufferData(n.ARRAY_BUFFER,this.array,n.DYNAMIC_DRAW)):(n.bindBuffer(n.ARRAY_BUFFER,i),t=0,this.ATTRIBUTES.forEach(o=>t+=this.bindAttribute(o,e,t)),n.bufferData(n.ARRAY_BUFFER,this.array,n.DYNAMIC_DRAW)),n.bindBuffer(n.ARRAY_BUFFER,null)}unbindProgram(e){this.isInstanced?(this.CONSTANT_ATTRIBUTES.forEach(t=>this.unbindAttribute(t,e,!1)),this.ATTRIBUTES.forEach(t=>this.unbindAttribute(t,e,!0))):this.ATTRIBUTES.forEach(t=>this.unbindAttribute(t,e))}bindAttribute(e,t,n,i){const o=Ra[e.type];if(typeof o!="number")throw new Error(`Program.bind: yet unsupported attribute type "${e.type}"`);const a=t.attributeLocations[e.name],s=t.gl;if(a!==-1){s.enableVertexAttribArray(a);const l=this.isInstanced?(i?this.ATTRIBUTES_ITEMS_COUNT:qe(this.CONSTANT_ATTRIBUTES))*Float32Array.BYTES_PER_ELEMENT:this.ATTRIBUTES_ITEMS_COUNT*Float32Array.BYTES_PER_ELEMENT;if(s.vertexAttribPointer(a,e.size,e.type,e.normalized||!1,l,n),this.isInstanced&&i)if(s instanceof WebGL2RenderingContext)s.vertexAttribDivisor(a,1);else{const c=s.getExtension("ANGLE_instanced_arrays");c&&c.vertexAttribDivisorANGLE(a,1)}}return e.size*o}unbindAttribute(e,t,n){const i=t.attributeLocations[e.name],o=t.gl;if(i!==-1&&(o.disableVertexAttribArray(i),this.isInstanced&&n))if(o instanceof WebGL2RenderingContext)o.vertexAttribDivisor(i,0);else{const a=o.getExtension("ANGLE_instanced_arrays");a&&a.vertexAttribDivisorANGLE(i,0)}}reallocate(e){e!==this.capacity&&(this.capacity=e,this.verticesCount=this.VERTICES*e,this.array=new Float32Array(this.isInstanced?this.capacity*this.ATTRIBUTES_ITEMS_COUNT:this.verticesCount*this.ATTRIBUTES_ITEMS_COUNT))}hasNothingToRender(){return this.verticesCount===0}renderProgram(e,t){const{gl:n,program:i}=t;n.enable(n.BLEND),n.useProgram(i),this.setUniforms(e,t),this.drawWebGL(this.METHOD,t)}render(e){this.hasNothingToRender()||(this.pickProgram&&(this.pickProgram.gl.viewport(0,0,e.width*e.pixelRatio/e.downSizingRatio,e.height*e.pixelRatio/e.downSizingRatio),this.bindProgram(this.pickProgram),this.renderProgram({...e,pixelRatio:e.pixelRatio/e.downSizingRatio},this.pickProgram),this.unbindProgram(this.pickProgram)),this.normalProgram.gl.viewport(0,0,e.width*e.pixelRatio,e.height*e.pixelRatio),this.bindProgram(this.normalProgram),this.renderProgram(e,this.normalProgram),this.unbindProgram(this.normalProgram))}drawWebGL(e,{gl:t,frameBuffer:n}){if(t.bindFramebuffer(t.FRAMEBUFFER,n),!this.isInstanced)t.drawArrays(e,0,this.verticesCount);else if(t instanceof WebGL2RenderingContext)t.drawArraysInstanced(e,0,this.VERTICES,this.capacity);else{const i=t.getExtension("ANGLE_instanced_arrays");i&&i.drawArraysInstancedANGLE(e,0,this.VERTICES,this.capacity)}}}class Ca extends qt{}class Zt extends Kt{kill(){super.kill()}process(e,t,n){let i=t*this.STRIDE;if(n.hidden){for(let o=i+this.STRIDE;inew s(i,o,a))}reallocate(i){this.programs.forEach(o=>o.reallocate(i))}process(i,o,a){this.programs.forEach(s=>s.process(i,o,a))}render(i){this.programs.forEach(o=>o.render(i))}kill(){this.programs.forEach(i=>i.kill())}}}class Aa extends qt{}class se extends Kt{constructor(){super(...arguments),this.drawLabel=void 0}kill(){super.kill()}process(e,t,n,i,o){let a=t*this.STRIDE;if(o.hidden||n.hidden||i.hidden){for(let s=a+this.STRIDE;anew a(n,i,o))}reallocate(n){this.programs.forEach(i=>i.reallocate(n))}process(n,i,o,a,s){this.programs.forEach(l=>l.process(n,i,o,a,s))}render(n){this.programs.forEach(i=>i.render(n))}kill(){this.programs.forEach(n=>n.kill())}}}function kn(r,e,t,n,i){const o=i.edgeLabelSize,a=i.edgeLabelFont,s=i.edgeLabelWeight,l=i.edgeLabelColor.attribute?e[i.edgeLabelColor.attribute]||i.edgeLabelColor.color||"#000":i.edgeLabelColor.color;let c=e.label;if(!c)return;r.fillStyle=l,r.font=`${s} ${o}px ${a}`;const u=t.size,d=n.size;let h=t.x,m=t.y,g=n.x,b=n.y,E=(h+g)/2,v=(m+b)/2,T=g-h,_=b-m,f=Math.sqrt(T*T+_*_);if(ff){const R="…";for(c=c+R,p=r.measureText(c).width;p>f&&c.length>1;)c=c.slice(0,-2)+R,p=r.measureText(c).width;if(c.length<4)return}let y;T>0?_>0?y=Math.acos(T/f):y=Math.asin(_/f):_>0?y=Math.acos(T/f)+Math.PI:y=Math.asin(T/f)+Math.PI/2,r.save(),r.translate(E,v),r.rotate(y),r.fillText(c,-p/2,e.size/2+o),r.restore()}function Jt(r,e,t){if(!e.label)return;const n=t.labelSize,i=t.labelFont,o=t.labelWeight,a=t.labelColor.attribute?e[t.labelColor.attribute]||t.labelColor.color||"#000":t.labelColor.color;r.fillStyle=a,r.font=`${o} ${n}px ${i}`,r.fillText(e.label,e.x+e.size+3,e.y+n/3)}function In(r,e,t){const n=t.labelSize,i=t.labelFont,o=t.labelWeight;r.font=`${o} ${n}px ${i}`,r.fillStyle="#FFF",r.shadowOffsetX=0,r.shadowOffsetY=0,r.shadowBlur=8,r.shadowColor="#000";const a=2;if(typeof e.label=="string"){const s=r.measureText(e.label).width,l=Math.round(s+5),c=Math.round(n+2*a),u=Math.max(e.size,n/2)+a,d=Math.asin(c/2/u),h=Math.sqrt(Math.abs(Math.pow(u,2)-Math.pow(c/2,2)));r.beginPath(),r.moveTo(e.x+h,e.y+c/2),r.lineTo(e.x+u+l,e.y+c/2),r.lineTo(e.x+u+l,e.y-c/2),r.lineTo(e.x+h,e.y-c/2),r.arc(e.x,e.y,u,d,-d),r.closePath(),r.fill()}else r.beginPath(),r.arc(e.x,e.y,e.size+a,0,Math.PI*2),r.closePath(),r.fill();r.shadowOffsetX=0,r.shadowOffsetY=0,r.shadowBlur=0,Jt(r,e,t)}const Sa=` precision highp float; varying vec4 v_color; varying vec2 v_diffVector; varying float v_radius; uniform float u_correctionRatio; const vec4 transparent = vec4(0.0, 0.0, 0.0, 0.0); void main(void) { float border = u_correctionRatio * 2.0; float dist = length(v_diffVector) - v_radius + border; // No antialiasing for picking mode: #ifdef PICKING_MODE if (dist > border) gl_FragColor = transparent; else gl_FragColor = v_color; #else float t = 0.0; if (dist > border) t = 1.0; else if (dist > 0.0) t = dist / border; gl_FragColor = mix(v_color, transparent, t); #endif } `,xa=` attribute vec4 a_id; attribute vec4 a_color; attribute vec2 a_position; attribute float a_size; attribute float a_angle; uniform mat3 u_matrix; uniform float u_sizeRatio; uniform float u_correctionRatio; varying vec4 v_color; varying vec2 v_diffVector; varying float v_radius; varying float v_border; const float bias = 255.0 / 254.0; void main() { float size = a_size * u_correctionRatio / u_sizeRatio * 4.0; vec2 diffVector = size * vec2(cos(a_angle), sin(a_angle)); vec2 position = a_position + diffVector; gl_Position = vec4( (u_matrix * vec3(position, 1)).xy, 0, 1 ); v_diffVector = diffVector; v_radius = size / 2.0; #ifdef PICKING_MODE // For picking mode, we use the ID as the color: v_color = a_id; #else // For normal mode, we use the color: v_color = a_color; #endif v_color.a *= bias; } `,{UNSIGNED_BYTE:zn,FLOAT:er}=WebGLRenderingContext,La=["u_sizeRatio","u_correctionRatio","u_matrix"],re=class re extends Zt{getDefinition(){return{VERTICES:3,VERTEX_SHADER_SOURCE:xa,FRAGMENT_SHADER_SOURCE:Sa,METHOD:WebGLRenderingContext.TRIANGLES,UNIFORMS:La,ATTRIBUTES:[{name:"a_position",size:2,type:er},{name:"a_size",size:1,type:er},{name:"a_color",size:4,type:zn,normalized:!0},{name:"a_id",size:4,type:zn,normalized:!0}],CONSTANT_ATTRIBUTES:[{name:"a_angle",size:1,type:er}],CONSTANT_DATA:[[re.ANGLE_1],[re.ANGLE_2],[re.ANGLE_3]]}}processVisibleItem(e,t,n){const i=this.array,o=V(n.color);i[t++]=n.x,i[t++]=n.y,i[t++]=n.size,i[t++]=o,i[t++]=e}setUniforms(e,{gl:t,uniformLocations:n}){const{u_sizeRatio:i,u_correctionRatio:o,u_matrix:a}=n;t.uniform1f(o,e.correctionRatio),t.uniform1f(i,e.sizeRatio),t.uniformMatrix3fv(a,!1,e.matrix)}};re.ANGLE_1=0,re.ANGLE_2=2*Math.PI/3,re.ANGLE_3=4*Math.PI/3;let Ke=re;const Fa=` precision mediump float; varying vec4 v_color; varying float v_border; const float radius = 0.5; const vec4 transparent = vec4(0.0, 0.0, 0.0, 0.0); void main(void) { vec2 m = gl_PointCoord - vec2(0.5, 0.5); float dist = radius - length(m); // No antialiasing for picking mode: #ifdef PICKING_MODE if (dist > v_border) gl_FragColor = v_color; else gl_FragColor = transparent; #else float t = 0.0; if (dist > v_border) t = 1.0; else if (dist > 0.0) t = dist / v_border; gl_FragColor = mix(transparent, v_color, t); #endif } `,Na=` attribute vec4 a_id; attribute vec4 a_color; attribute vec2 a_position; attribute float a_size; uniform float u_sizeRatio; uniform float u_pixelRatio; uniform mat3 u_matrix; varying vec4 v_color; varying float v_border; const float bias = 255.0 / 254.0; void main() { gl_Position = vec4( (u_matrix * vec3(a_position, 1)).xy, 0, 1 ); // Multiply the point size twice: // - x SCALING_RATIO to correct the canvas scaling // - x 2 to correct the formulae gl_PointSize = a_size / u_sizeRatio * u_pixelRatio * 2.0; v_border = (0.5 / a_size) * u_sizeRatio; #ifdef PICKING_MODE // For picking mode, we use the ID as the color: v_color = a_id; #else // For normal mode, we use the color: v_color = a_color; #endif v_color.a *= bias; } `,{UNSIGNED_BYTE:Gn,FLOAT:Mn}=WebGLRenderingContext,Pa=["u_sizeRatio","u_pixelRatio","u_matrix"];class Oa extends Zt{getDefinition(){return{VERTICES:1,VERTEX_SHADER_SOURCE:Na,FRAGMENT_SHADER_SOURCE:Fa,METHOD:WebGLRenderingContext.POINTS,UNIFORMS:Pa,ATTRIBUTES:[{name:"a_position",size:2,type:Mn},{name:"a_size",size:1,type:Mn},{name:"a_color",size:4,type:Gn,normalized:!0},{name:"a_id",size:4,type:Gn,normalized:!0}]}}processVisibleItem(e,t,n){const i=this.array;i[t++]=n.x,i[t++]=n.y,i[t++]=n.size,i[t++]=V(n.color),i[t++]=e}setUniforms({sizeRatio:e,pixelRatio:t,matrix:n},{gl:i,uniformLocations:o}){const{u_sizeRatio:a,u_pixelRatio:s,u_matrix:l}=o;i.uniform1f(s,t),i.uniform1f(a,e),i.uniformMatrix3fv(l,!1,n)}}const Da=` precision mediump float; varying vec4 v_color; void main(void) { gl_FragColor = v_color; } `,ka=` attribute vec2 a_position; attribute vec2 a_normal; attribute float a_radius; attribute vec3 a_barycentric; #ifdef PICKING_MODE attribute vec4 a_id; #else attribute vec4 a_color; #endif uniform mat3 u_matrix; uniform float u_sizeRatio; uniform float u_correctionRatio; uniform float u_minEdgeThickness; uniform float u_lengthToThicknessRatio; uniform float u_widenessToThicknessRatio; varying vec4 v_color; const float bias = 255.0 / 254.0; void main() { float minThickness = u_minEdgeThickness; float normalLength = length(a_normal); vec2 unitNormal = a_normal / normalLength; // These first computations are taken from edge.vert.glsl and // edge.clamped.vert.glsl. Please read it to get better comments on what's // happening: float pixelsThickness = max(normalLength / u_sizeRatio, minThickness); float webGLThickness = pixelsThickness * u_correctionRatio; float webGLNodeRadius = a_radius * 2.0 * u_correctionRatio / u_sizeRatio; float webGLArrowHeadLength = webGLThickness * u_lengthToThicknessRatio * 2.0; float webGLArrowHeadThickness = webGLThickness * u_widenessToThicknessRatio; float da = a_barycentric.x; float db = a_barycentric.y; float dc = a_barycentric.z; vec2 delta = vec2( da * (webGLNodeRadius * unitNormal.y) + db * ((webGLNodeRadius + webGLArrowHeadLength) * unitNormal.y + webGLArrowHeadThickness * unitNormal.x) + dc * ((webGLNodeRadius + webGLArrowHeadLength) * unitNormal.y - webGLArrowHeadThickness * unitNormal.x), da * (-webGLNodeRadius * unitNormal.x) + db * (-(webGLNodeRadius + webGLArrowHeadLength) * unitNormal.x + webGLArrowHeadThickness * unitNormal.y) + dc * (-(webGLNodeRadius + webGLArrowHeadLength) * unitNormal.x - webGLArrowHeadThickness * unitNormal.y) ); vec2 position = (u_matrix * vec3(a_position + delta, 1)).xy; gl_Position = vec4(position, 0, 1); #ifdef PICKING_MODE // For picking mode, we use the ID as the color: v_color = a_id; #else // For normal mode, we use the color: v_color = a_color; #endif v_color.a *= bias; } `,{UNSIGNED_BYTE:Un,FLOAT:Ze}=WebGLRenderingContext,Ia=["u_matrix","u_sizeRatio","u_correctionRatio","u_minEdgeThickness","u_lengthToThicknessRatio","u_widenessToThicknessRatio"],Qe={extremity:"target",lengthToThicknessRatio:2.5,widenessToThicknessRatio:2};function Le(r){const e={...Qe,...r||{}};return class extends se{getDefinition(){return{VERTICES:3,VERTEX_SHADER_SOURCE:ka,FRAGMENT_SHADER_SOURCE:Da,METHOD:WebGLRenderingContext.TRIANGLES,UNIFORMS:Ia,ATTRIBUTES:[{name:"a_position",size:2,type:Ze},{name:"a_normal",size:2,type:Ze},{name:"a_radius",size:1,type:Ze},{name:"a_color",size:4,type:Un,normalized:!0},{name:"a_id",size:4,type:Un,normalized:!0}],CONSTANT_ATTRIBUTES:[{name:"a_barycentric",size:3,type:Ze}],CONSTANT_DATA:[[1,0,0],[0,1,0],[0,0,1]]}}processVisibleItem(n,i,o,a,s){e.extremity==="source"&&([o,a]=[a,o]);const l=s.size||1,c=a.size||1,u=o.x,d=o.y,h=a.x,m=a.y,g=V(s.color),b=h-u,E=m-d;let v=b*b+E*E,T=0,_=0;v&&(v=1/Math.sqrt(v),T=-E*v*l,_=b*v*l);const f=this.array;f[i++]=h,f[i++]=m,f[i++]=-T,f[i++]=-_,f[i++]=c,f[i++]=g,f[i++]=n}setUniforms(n,{gl:i,uniformLocations:o}){const{u_matrix:a,u_sizeRatio:s,u_correctionRatio:l,u_minEdgeThickness:c,u_lengthToThicknessRatio:u,u_widenessToThicknessRatio:d}=o;i.uniformMatrix3fv(a,!1,n.matrix),i.uniform1f(s,n.sizeRatio),i.uniform1f(l,n.correctionRatio),i.uniform1f(c,n.minEdgeThickness),i.uniform1f(u,e.lengthToThicknessRatio),i.uniform1f(d,e.widenessToThicknessRatio)}}}const za=Le(),tr=` precision mediump float; varying vec4 v_color; varying vec2 v_normal; varying float v_thickness; varying float v_feather; const vec4 transparent = vec4(0.0, 0.0, 0.0, 0.0); void main(void) { // We only handle antialiasing for normal mode: #ifdef PICKING_MODE gl_FragColor = v_color; #else float dist = length(v_normal) * v_thickness; float t = smoothstep( v_thickness - v_feather, v_thickness, dist ); gl_FragColor = mix(v_color, transparent, t); #endif } `,Ga=` attribute vec4 a_id; attribute vec4 a_color; attribute vec2 a_normal; attribute float a_normalCoef; attribute vec2 a_positionStart; attribute vec2 a_positionEnd; attribute float a_positionCoef; attribute float a_radius; attribute float a_radiusCoef; uniform mat3 u_matrix; uniform float u_zoomRatio; uniform float u_sizeRatio; uniform float u_pixelRatio; uniform float u_correctionRatio; uniform float u_minEdgeThickness; uniform float u_lengthToThicknessRatio; uniform float u_feather; varying vec4 v_color; varying vec2 v_normal; varying float v_thickness; varying float v_feather; const float bias = 255.0 / 254.0; void main() { float minThickness = u_minEdgeThickness; float radius = a_radius * a_radiusCoef; vec2 normal = a_normal * a_normalCoef; vec2 position = a_positionStart * (1.0 - a_positionCoef) + a_positionEnd * a_positionCoef; float normalLength = length(normal); vec2 unitNormal = normal / normalLength; // These first computations are taken from edge.vert.glsl. Please read it to // get better comments on what's happening: float pixelsThickness = max(normalLength, minThickness * u_sizeRatio); float webGLThickness = pixelsThickness * u_correctionRatio / u_sizeRatio; // Here, we move the point to leave space for the arrow head: float direction = sign(radius); float webGLNodeRadius = direction * radius * 2.0 * u_correctionRatio / u_sizeRatio; float webGLArrowHeadLength = webGLThickness * u_lengthToThicknessRatio * 2.0; vec2 compensationVector = vec2(-direction * unitNormal.y, direction * unitNormal.x) * (webGLNodeRadius + webGLArrowHeadLength); // Here is the proper position of the vertex gl_Position = vec4((u_matrix * vec3(position + unitNormal * webGLThickness + compensationVector, 1)).xy, 0, 1); v_thickness = webGLThickness / u_zoomRatio; v_normal = unitNormal; v_feather = u_feather * u_correctionRatio / u_zoomRatio / u_pixelRatio * 2.0; #ifdef PICKING_MODE // For picking mode, we use the ID as the color: v_color = a_id; #else // For normal mode, we use the color: v_color = a_color; #endif v_color.a *= bias; } `,{UNSIGNED_BYTE:Bn,FLOAT:ce}=WebGLRenderingContext,Ma=["u_matrix","u_zoomRatio","u_sizeRatio","u_correctionRatio","u_pixelRatio","u_feather","u_minEdgeThickness","u_lengthToThicknessRatio"],Hn={lengthToThicknessRatio:Qe.lengthToThicknessRatio};function rr(r){const e={...Hn,...r||{}};return class extends se{getDefinition(){return{VERTICES:6,VERTEX_SHADER_SOURCE:Ga,FRAGMENT_SHADER_SOURCE:tr,METHOD:WebGLRenderingContext.TRIANGLES,UNIFORMS:Ma,ATTRIBUTES:[{name:"a_positionStart",size:2,type:ce},{name:"a_positionEnd",size:2,type:ce},{name:"a_normal",size:2,type:ce},{name:"a_color",size:4,type:Bn,normalized:!0},{name:"a_id",size:4,type:Bn,normalized:!0},{name:"a_radius",size:1,type:ce}],CONSTANT_ATTRIBUTES:[{name:"a_positionCoef",size:1,type:ce},{name:"a_normalCoef",size:1,type:ce},{name:"a_radiusCoef",size:1,type:ce}],CONSTANT_DATA:[[0,1,0],[0,-1,0],[1,1,1],[1,1,1],[0,-1,0],[1,-1,-1]]}}processVisibleItem(n,i,o,a,s){const l=s.size||1,c=o.x,u=o.y,d=a.x,h=a.y,m=V(s.color),g=d-c,b=h-u,E=a.size||1;let v=g*g+b*b,T=0,_=0;v&&(v=1/Math.sqrt(v),T=-b*v*l,_=g*v*l);const f=this.array;f[i++]=c,f[i++]=u,f[i++]=d,f[i++]=h,f[i++]=T,f[i++]=_,f[i++]=m,f[i++]=n,f[i++]=E}setUniforms(n,{gl:i,uniformLocations:o}){const{u_matrix:a,u_zoomRatio:s,u_feather:l,u_pixelRatio:c,u_correctionRatio:u,u_sizeRatio:d,u_minEdgeThickness:h,u_lengthToThicknessRatio:m}=o;i.uniformMatrix3fv(a,!1,n.matrix),i.uniform1f(s,n.zoomRatio),i.uniform1f(d,n.sizeRatio),i.uniform1f(u,n.correctionRatio),i.uniform1f(c,n.pixelRatio),i.uniform1f(l,n.antiAliasingFeather),i.uniform1f(h,n.minEdgeThickness),i.uniform1f(m,e.lengthToThicknessRatio)}}}const Ua=rr(),Ba=` attribute vec4 a_id; attribute vec4 a_color; attribute vec2 a_normal; attribute float a_normalCoef; attribute vec2 a_positionStart; attribute vec2 a_positionEnd; attribute float a_positionCoef; attribute float a_sourceRadius; attribute float a_targetRadius; attribute float a_sourceRadiusCoef; attribute float a_targetRadiusCoef; uniform mat3 u_matrix; uniform float u_zoomRatio; uniform float u_sizeRatio; uniform float u_pixelRatio; uniform float u_correctionRatio; uniform float u_minEdgeThickness; uniform float u_lengthToThicknessRatio; uniform float u_feather; varying vec4 v_color; varying vec2 v_normal; varying float v_thickness; varying float v_feather; const float bias = 255.0 / 254.0; void main() { float minThickness = u_minEdgeThickness; vec2 normal = a_normal * a_normalCoef; vec2 position = a_positionStart * (1.0 - a_positionCoef) + a_positionEnd * a_positionCoef; float normalLength = length(normal); vec2 unitNormal = normal / normalLength; // These first computations are taken from edge.vert.glsl. Please read it to // get better comments on what's happening: float pixelsThickness = max(normalLength, minThickness * u_sizeRatio); float webGLThickness = pixelsThickness * u_correctionRatio / u_sizeRatio; // Here, we move the point to leave space for the arrow heads: // Source arrow head float sourceRadius = a_sourceRadius * a_sourceRadiusCoef; float sourceDirection = sign(sourceRadius); float webGLSourceRadius = sourceDirection * sourceRadius * 2.0 * u_correctionRatio / u_sizeRatio; float webGLSourceArrowHeadLength = webGLThickness * u_lengthToThicknessRatio * 2.0; vec2 sourceCompensationVector = vec2(-sourceDirection * unitNormal.y, sourceDirection * unitNormal.x) * (webGLSourceRadius + webGLSourceArrowHeadLength); // Target arrow head float targetRadius = a_targetRadius * a_targetRadiusCoef; float targetDirection = sign(targetRadius); float webGLTargetRadius = targetDirection * targetRadius * 2.0 * u_correctionRatio / u_sizeRatio; float webGLTargetArrowHeadLength = webGLThickness * u_lengthToThicknessRatio * 2.0; vec2 targetCompensationVector = vec2(-targetDirection * unitNormal.y, targetDirection * unitNormal.x) * (webGLTargetRadius + webGLTargetArrowHeadLength); // Here is the proper position of the vertex gl_Position = vec4((u_matrix * vec3(position + unitNormal * webGLThickness + sourceCompensationVector + targetCompensationVector, 1)).xy, 0, 1); v_thickness = webGLThickness / u_zoomRatio; v_normal = unitNormal; v_feather = u_feather * u_correctionRatio / u_zoomRatio / u_pixelRatio * 2.0; #ifdef PICKING_MODE // For picking mode, we use the ID as the color: v_color = a_id; #else // For normal mode, we use the color: v_color = a_color; #endif v_color.a *= bias; } `,{UNSIGNED_BYTE:$n,FLOAT:K}=WebGLRenderingContext,Ha=["u_matrix","u_zoomRatio","u_sizeRatio","u_correctionRatio","u_pixelRatio","u_feather","u_minEdgeThickness","u_lengthToThicknessRatio"],jn={lengthToThicknessRatio:Qe.lengthToThicknessRatio};function nr(r){const e={...jn,...r||{}};return class extends se{getDefinition(){return{VERTICES:6,VERTEX_SHADER_SOURCE:Ba,FRAGMENT_SHADER_SOURCE:tr,METHOD:WebGLRenderingContext.TRIANGLES,UNIFORMS:Ha,ATTRIBUTES:[{name:"a_positionStart",size:2,type:K},{name:"a_positionEnd",size:2,type:K},{name:"a_normal",size:2,type:K},{name:"a_color",size:4,type:$n,normalized:!0},{name:"a_id",size:4,type:$n,normalized:!0},{name:"a_sourceRadius",size:1,type:K},{name:"a_targetRadius",size:1,type:K}],CONSTANT_ATTRIBUTES:[{name:"a_positionCoef",size:1,type:K},{name:"a_normalCoef",size:1,type:K},{name:"a_sourceRadiusCoef",size:1,type:K},{name:"a_targetRadiusCoef",size:1,type:K}],CONSTANT_DATA:[[0,1,-1,0],[0,-1,1,0],[1,1,0,1],[1,1,0,1],[0,-1,1,0],[1,-1,0,-1]]}}processVisibleItem(n,i,o,a,s){const l=s.size||1,c=o.x,u=o.y,d=a.x,h=a.y,m=V(s.color),g=d-c,b=h-u,E=o.size||1,v=a.size||1;let T=g*g+b*b,_=0,f=0;T&&(T=1/Math.sqrt(T),_=-b*T*l,f=g*T*l);const p=this.array;p[i++]=c,p[i++]=u,p[i++]=d,p[i++]=h,p[i++]=_,p[i++]=f,p[i++]=m,p[i++]=n,p[i++]=E,p[i++]=v}setUniforms(n,{gl:i,uniformLocations:o}){const{u_matrix:a,u_zoomRatio:s,u_feather:l,u_pixelRatio:c,u_correctionRatio:u,u_sizeRatio:d,u_minEdgeThickness:h,u_lengthToThicknessRatio:m}=o;i.uniformMatrix3fv(a,!1,n.matrix),i.uniform1f(s,n.zoomRatio),i.uniform1f(d,n.sizeRatio),i.uniform1f(u,n.correctionRatio),i.uniform1f(c,n.pixelRatio),i.uniform1f(l,n.antiAliasingFeather),i.uniform1f(h,n.minEdgeThickness),i.uniform1f(m,e.lengthToThicknessRatio)}}}const $a=nr();function Vn(r){return Qt([rr(r),Le(r)])}const Wn=Vn();function Yn(r){return Qt([nr(r),Le(r),Le({...r,extremity:"source"})])}const ja=Yn(),Va=` precision mediump float; varying vec4 v_color; void main(void) { gl_FragColor = v_color; } `,Wa=` attribute vec4 a_id; attribute vec4 a_color; attribute vec2 a_position; uniform mat3 u_matrix; varying vec4 v_color; const float bias = 255.0 / 254.0; void main() { // Scale from [[-1 1] [-1 1]] to the container: gl_Position = vec4( (u_matrix * vec3(a_position, 1)).xy, 0, 1 ); #ifdef PICKING_MODE // For picking mode, we use the ID as the color: v_color = a_id; #else // For normal mode, we use the color: v_color = a_color; #endif v_color.a *= bias; } `,{UNSIGNED_BYTE:Xn,FLOAT:Ya}=WebGLRenderingContext,Xa=["u_matrix"];class qa extends se{getDefinition(){return{VERTICES:2,VERTEX_SHADER_SOURCE:Wa,FRAGMENT_SHADER_SOURCE:Va,METHOD:WebGLRenderingContext.LINES,UNIFORMS:Xa,ATTRIBUTES:[{name:"a_position",size:2,type:Ya},{name:"a_color",size:4,type:Xn,normalized:!0},{name:"a_id",size:4,type:Xn,normalized:!0}]}}processVisibleItem(e,t,n,i,o){const a=this.array,s=n.x,l=n.y,c=i.x,u=i.y,d=V(o.color);a[t++]=s,a[t++]=l,a[t++]=d,a[t++]=e,a[t++]=c,a[t++]=u,a[t++]=d,a[t++]=e}setUniforms(e,{gl:t,uniformLocations:n}){const{u_matrix:i}=n;t.uniformMatrix3fv(i,!1,e.matrix)}}const Ka=` attribute vec4 a_id; attribute vec4 a_color; attribute vec2 a_normal; attribute float a_normalCoef; attribute vec2 a_positionStart; attribute vec2 a_positionEnd; attribute float a_positionCoef; uniform mat3 u_matrix; uniform float u_sizeRatio; uniform float u_zoomRatio; uniform float u_pixelRatio; uniform float u_correctionRatio; uniform float u_minEdgeThickness; uniform float u_feather; varying vec4 v_color; varying vec2 v_normal; varying float v_thickness; varying float v_feather; const float bias = 255.0 / 254.0; void main() { float minThickness = u_minEdgeThickness; vec2 normal = a_normal * a_normalCoef; vec2 position = a_positionStart * (1.0 - a_positionCoef) + a_positionEnd * a_positionCoef; float normalLength = length(normal); vec2 unitNormal = normal / normalLength; // We require edges to be at least "minThickness" pixels thick *on screen* // (so we need to compensate the size ratio): float pixelsThickness = max(normalLength, minThickness * u_sizeRatio); // Then, we need to retrieve the normalized thickness of the edge in the WebGL // referential (in a ([0, 1], [0, 1]) space), using our "magic" correction // ratio: float webGLThickness = pixelsThickness * u_correctionRatio / u_sizeRatio; // Here is the proper position of the vertex gl_Position = vec4((u_matrix * vec3(position + unitNormal * webGLThickness, 1)).xy, 0, 1); // For the fragment shader though, we need a thickness that takes the "magic" // correction ratio into account (as in webGLThickness), but so that the // antialiasing effect does not depend on the zoom level. So here's yet // another thickness version: v_thickness = webGLThickness / u_zoomRatio; v_normal = unitNormal; v_feather = u_feather * u_correctionRatio / u_zoomRatio / u_pixelRatio * 2.0; #ifdef PICKING_MODE // For picking mode, we use the ID as the color: v_color = a_id; #else // For normal mode, we use the color: v_color = a_color; #endif v_color.a *= bias; } `,{UNSIGNED_BYTE:qn,FLOAT:Fe}=WebGLRenderingContext,Za=["u_matrix","u_zoomRatio","u_sizeRatio","u_correctionRatio","u_pixelRatio","u_feather","u_minEdgeThickness"];class Kn extends se{getDefinition(){return{VERTICES:6,VERTEX_SHADER_SOURCE:Ka,FRAGMENT_SHADER_SOURCE:tr,METHOD:WebGLRenderingContext.TRIANGLES,UNIFORMS:Za,ATTRIBUTES:[{name:"a_positionStart",size:2,type:Fe},{name:"a_positionEnd",size:2,type:Fe},{name:"a_normal",size:2,type:Fe},{name:"a_color",size:4,type:qn,normalized:!0},{name:"a_id",size:4,type:qn,normalized:!0}],CONSTANT_ATTRIBUTES:[{name:"a_positionCoef",size:1,type:Fe},{name:"a_normalCoef",size:1,type:Fe}],CONSTANT_DATA:[[0,1],[0,-1],[1,1],[1,1],[0,-1],[1,-1]]}}processVisibleItem(e,t,n,i,o){const a=o.size||1,s=n.x,l=n.y,c=i.x,u=i.y,d=V(o.color),h=c-s,m=u-l;let g=h*h+m*m,b=0,E=0;g&&(g=1/Math.sqrt(g),b=-m*g*a,E=h*g*a);const v=this.array;v[t++]=s,v[t++]=l,v[t++]=c,v[t++]=u,v[t++]=b,v[t++]=E,v[t++]=d,v[t++]=e}setUniforms(e,{gl:t,uniformLocations:n}){const{u_matrix:i,u_zoomRatio:o,u_feather:a,u_pixelRatio:s,u_correctionRatio:l,u_sizeRatio:c,u_minEdgeThickness:u}=n;t.uniformMatrix3fv(i,!1,e.matrix),t.uniform1f(o,e.zoomRatio),t.uniform1f(c,e.sizeRatio),t.uniform1f(l,e.correctionRatio),t.uniform1f(s,e.pixelRatio),t.uniform1f(a,e.antiAliasingFeather),t.uniform1f(u,e.minEdgeThickness)}}const Qa=` precision mediump float; varying vec4 v_color; void main(void) { gl_FragColor = v_color; } `,Ja=` attribute vec4 a_id; attribute vec4 a_color; attribute vec2 a_normal; attribute float a_normalCoef; attribute vec2 a_positionStart; attribute vec2 a_positionEnd; attribute float a_positionCoef; uniform mat3 u_matrix; uniform float u_sizeRatio; uniform float u_correctionRatio; varying vec4 v_color; const float minThickness = 1.7; const float bias = 255.0 / 254.0; void main() { vec2 normal = a_normal * a_normalCoef; vec2 position = a_positionStart * (1.0 - a_positionCoef) + a_positionEnd * a_positionCoef; // The only different here with edge.vert.glsl is that we need to handle null // input normal vector. Apart from that, you can read edge.vert.glsl more info // on how it works: float normalLength = length(normal); vec2 unitNormal = normal / normalLength; if (normalLength <= 0.0) unitNormal = normal; float pixelsThickness = max(normalLength, minThickness * u_sizeRatio); float webGLThickness = pixelsThickness * u_correctionRatio / u_sizeRatio; gl_Position = vec4((u_matrix * vec3(position + unitNormal * webGLThickness, 1)).xy, 0, 1); #ifdef PICKING_MODE // For picking mode, we use the ID as the color: v_color = a_id; #else // For normal mode, we use the color: v_color = a_color; #endif v_color.a *= bias; } `,{UNSIGNED_BYTE:Zn,FLOAT:Ne}=WebGLRenderingContext,es=["u_matrix","u_sizeRatio","u_correctionRatio","u_minEdgeThickness"];class ts extends se{getDefinition(){return{VERTICES:3,VERTEX_SHADER_SOURCE:Ja,FRAGMENT_SHADER_SOURCE:Qa,METHOD:WebGLRenderingContext.TRIANGLES,UNIFORMS:es,ATTRIBUTES:[{name:"a_positionStart",size:2,type:Ne},{name:"a_positionEnd",size:2,type:Ne},{name:"a_normal",size:2,type:Ne},{name:"a_color",size:4,type:Zn,normalized:!0},{name:"a_id",size:4,type:Zn,normalized:!0}],CONSTANT_ATTRIBUTES:[{name:"a_positionCoef",size:1,type:Ne},{name:"a_normalCoef",size:1,type:Ne}],CONSTANT_DATA:[[0,1],[0,-1],[1,0]]}}processVisibleItem(e,t,n,i,o){const a=o.size||1,s=n.x,l=n.y,c=i.x,u=i.y,d=V(o.color),h=c-s,m=u-l;let g=h*h+m*m,b=0,E=0;g&&(g=1/Math.sqrt(g),b=-m*g*a,E=h*g*a);const v=this.array;v[t++]=s,v[t++]=l,v[t++]=c,v[t++]=u,v[t++]=b,v[t++]=E,v[t++]=d,v[t++]=e}setUniforms(e,{gl:t,uniformLocations:n}){const{u_matrix:i,u_sizeRatio:o,u_correctionRatio:a,u_minEdgeThickness:s}=n;t.uniformMatrix3fv(i,!1,e.matrix),t.uniform1f(o,e.sizeRatio),t.uniform1f(a,e.correctionRatio),t.uniform1f(s,e.minEdgeThickness)}}const rs=Object.freeze(Object.defineProperty({__proto__:null,AbstractEdgeProgram:Aa,AbstractNodeProgram:Ca,AbstractProgram:qt,DEFAULT_EDGE_ARROW_HEAD_PROGRAM_OPTIONS:Qe,DEFAULT_EDGE_CLAMPED_PROGRAM_OPTIONS:Hn,DEFAULT_EDGE_DOUBLE_CLAMPED_PROGRAM_OPTIONS:jn,EdgeArrowHeadProgram:za,EdgeArrowProgram:Wn,EdgeClampedProgram:Ua,EdgeDoubleArrowProgram:ja,EdgeDoubleClampedProgram:$a,EdgeLineProgram:qa,EdgeProgram:se,EdgeRectangleProgram:Kn,EdgeTriangleProgram:ts,NodeCircleProgram:Ke,NodePointProgram:Oa,NodeProgram:Zt,Program:Kt,createEdgeArrowHeadProgram:Le,createEdgeArrowProgram:Vn,createEdgeClampedProgram:rr,createEdgeCompoundProgram:Qt,createEdgeDoubleArrowProgram:Yn,createEdgeDoubleClampedProgram:nr,createNodeCompoundProgram:wa,drawDiscNodeHover:In,drawDiscNodeLabel:Jt,drawStraightEdgeLabel:kn,getAttributeItemsCount:Ln,getAttributesItemsCount:qe,killProgram:Xt,loadFragmentShader:Pn,loadProgram:On,loadVertexShader:Nn,numberToGLSLFloat:Ta},Symbol.toStringTag,{value:"Module"}));class ir extends Yr.EventEmitter{constructor(){super(),this.rawEmitter=this}}const Je=1.5;class ye extends ir{constructor(){super(),this.x=.5,this.y=.5,this.angle=0,this.ratio=1,this.minRatio=null,this.maxRatio=null,this.enabledZooming=!0,this.enabledPanning=!0,this.enabledRotation=!0,this.clean=null,this.nextFrame=null,this.previousState=null,this.enabled=!0,this.previousState=this.getState()}static from(e){return new ye().setState(e)}enable(){return this.enabled=!0,this}disable(){return this.enabled=!1,this}getState(){return{x:this.x,y:this.y,angle:this.angle,ratio:this.ratio}}hasState(e){return this.x===e.x&&this.y===e.y&&this.ratio===e.ratio&&this.angle===e.angle}getPreviousState(){const e=this.previousState;return e?{x:e.x,y:e.y,angle:e.angle,ratio:e.ratio}:null}getBoundedRatio(e){let t=e;return typeof this.minRatio=="number"&&(t=Math.max(t,this.minRatio)),typeof this.maxRatio=="number"&&(t=Math.min(t,this.maxRatio)),t}validateState(e){const t={};return this.enabledPanning&&typeof e.x=="number"&&(t.x=e.x),this.enabledPanning&&typeof e.y=="number"&&(t.y=e.y),this.enabledZooming&&typeof e.ratio=="number"&&(t.ratio=this.getBoundedRatio(e.ratio)),this.enabledRotation&&typeof e.angle=="number"&&(t.angle=e.angle),this.clean?this.clean({...this.getState(),...t}):t}isAnimated(){return!!this.nextFrame}setState(e){if(!this.enabled)return this;this.previousState=this.getState();const t=this.validateState(e);return typeof t.x=="number"&&(this.x=t.x),typeof t.y=="number"&&(this.y=t.y),typeof t.ratio=="number"&&(this.ratio=t.ratio),typeof t.angle=="number"&&(this.angle=t.angle),this.hasState(this.previousState)||this.emit("updated",this.getState()),this}updateState(e){return this.setState(e(this.getState())),this}animate(e,t={},n){if(!n)return new Promise(u=>this.animate(e,t,u));if(!this.enabled)return;const i={...It,...t},o=this.validateState(e),a=typeof i.easing=="function"?i.easing:kt[i.easing],s=Date.now(),l=this.getState(),c=()=>{const u=(Date.now()-s)/i.duration;if(u>=1){this.nextFrame=null,this.setState(o),this.animationCallback&&(this.animationCallback.call(null),this.animationCallback=void 0);return}const d=a(u),h={};typeof o.x=="number"&&(h.x=l.x+(o.x-l.x)*d),typeof o.y=="number"&&(h.y=l.y+(o.y-l.y)*d),this.enabledRotation&&typeof o.angle=="number"&&(h.angle=l.angle+(o.angle-l.angle)*d),typeof o.ratio=="number"&&(h.ratio=l.ratio+(o.ratio-l.ratio)*d),this.setState(h),this.nextFrame=requestAnimationFrame(c)};this.nextFrame?(cancelAnimationFrame(this.nextFrame),this.animationCallback&&this.animationCallback.call(null),this.nextFrame=requestAnimationFrame(c)):c(),this.animationCallback=n}animatedZoom(e){return e?typeof e=="number"?this.animate({ratio:this.ratio/e}):this.animate({ratio:this.ratio/(e.factor||Je)},e):this.animate({ratio:this.ratio/Je})}animatedUnzoom(e){return e?typeof e=="number"?this.animate({ratio:this.ratio*e}):this.animate({ratio:this.ratio*(e.factor||Je)},e):this.animate({ratio:this.ratio*Je})}animatedReset(e){return this.animate({x:.5,y:.5,ratio:1,angle:0},e)}copy(){return ye.from(this.getState())}}const or={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:kn,defaultDrawNodeLabel:Jt,defaultDrawNodeHover:In,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:{}},ns={circle:Ke},is={arrow:Wn,line:Kn};function ar(r){if(typeof r.labelDensity!="number"||r.labelDensity<0)throw new Error("Settings: invalid `labelDensity`. Expecting a positive number.");const{minCameraRatio:e,maxCameraRatio:t}=r;if(typeof e=="number"&&typeof t=="number"&&t{r.sigmaDefaultPrevented=!0,e.sigmaDefaultPrevented=!0}};return e}function as(r,e){return{...Z(r,e),delta:Qn(r)}}const ss=2;function et(r){const e=[];for(let t=0,n=Math.min(r.length,ss);tW(i,t)),previousTouches:e.map(i=>W(i,t)),sigmaDefaultPrevented:!1,preventSigmaDefault(){n.sigmaDefaultPrevented=!0},original:r};return n}function Qn(r){if(typeof r.deltaY<"u")return r.deltaY*-3/360;if(typeof r.detail<"u")return r.detail/-9;throw new Error("Captor: could not extract delta from event.")}class Jn extends ir{constructor(e,t){super(),this.container=e,this.renderer=t}}const cs=["doubleClickTimeout","doubleClickZoomingDuration","doubleClickZoomingRatio","dragTimeout","draggedEventsTolerance","inertiaDuration","inertiaRatio","zoomDuration","zoomingRatio"].reduce((r,e)=>({...r,[e]:or[e]}),{});class ei extends Jn{constructor(e,t){super(e,t),this.enabled=!0,this.draggedEvents=0,this.downStartTime=null,this.lastMouseX=null,this.lastMouseY=null,this.isMouseDown=!1,this.isMoving=!1,this.movingTimeout=null,this.startCameraState=null,this.clicks=0,this.doubleClickTimeout=null,this.currentWheelDirection=0,this.settings=cs,this.handleClick=this.handleClick.bind(this),this.handleRightClick=this.handleRightClick.bind(this),this.handleDown=this.handleDown.bind(this),this.handleUp=this.handleUp.bind(this),this.handleMove=this.handleMove.bind(this),this.handleWheel=this.handleWheel.bind(this),this.handleLeave=this.handleLeave.bind(this),this.handleEnter=this.handleEnter.bind(this),e.addEventListener("click",this.handleClick,{capture:!1}),e.addEventListener("contextmenu",this.handleRightClick,{capture:!1}),e.addEventListener("mousedown",this.handleDown,{capture:!1}),e.addEventListener("wheel",this.handleWheel,{capture:!1}),e.addEventListener("mouseleave",this.handleLeave,{capture:!1}),e.addEventListener("mouseenter",this.handleEnter,{capture:!1}),document.addEventListener("mousemove",this.handleMove,{capture:!1}),document.addEventListener("mouseup",this.handleUp,{capture:!1})}kill(){const 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)}handleClick(e){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(()=>{this.clicks=0,this.doubleClickTimeout=null},this.settings.doubleClickTimeout),this.draggedEvents{const s=this.draggedEvents>0;this.draggedEvents=0,s&&this.renderer.getSetting("hideEdgesOnMove")&&this.renderer.refresh()},0),this.emit("mouseup",Z(e,this.container))}handleMove(e){if(!this.enabled)return;const t=Z(e,this.container);if(this.emit("mousemovebody",t),(e.target===this.container||e.composedPath()[0]===this.container)&&this.emit("mousemove",t),!t.sigmaDefaultPrevented&&this.isMouseDown){this.isMoving=!0,this.draggedEvents++,typeof this.movingTimeout=="number"&&clearTimeout(this.movingTimeout),this.movingTimeout=window.setTimeout(()=>{this.movingTimeout=null,this.isMoving=!1},this.settings.dragTimeout);const n=this.renderer.getCamera(),{x:i,y:o}=W(e,this.container),a=this.renderer.viewportToFramedGraph({x:this.lastMouseX,y:this.lastMouseY}),s=this.renderer.viewportToFramedGraph({x:i,y:o}),l=a.x-s.x,c=a.y-s.y,u=n.getState(),d=u.x+l,h=u.y+c;n.setState({x:d,y:h}),this.lastMouseX=i,this.lastMouseY=o,e.preventDefault(),e.stopPropagation()}}handleLeave(e){this.emit("mouseleave",Z(e,this.container))}handleEnter(e){this.emit("mouseenter",Z(e,this.container))}handleWheel(e){const t=this.renderer.getCamera();if(!this.enabled||!t.enabledZooming)return;const n=Qn(e);if(!n)return;const i=as(e,this.container);if(this.emit("wheel",i),i.sigmaDefaultPrevented){e.preventDefault(),e.stopPropagation();return}const o=t.getState().ratio,a=n>0?1/this.settings.zoomingRatio:this.settings.zoomingRatio,s=t.getBoundedRatio(o*a),l=n>0?1:-1,c=Date.now();o!==s&&(e.preventDefault(),e.stopPropagation(),!(this.currentWheelDirection===l&&this.lastWheelTriggerTime&&c-this.lastWheelTriggerTime{this.currentWheelDirection=0}),this.currentWheelDirection=l,this.lastWheelTriggerTime=c))}setSettings(e){this.settings=e}}const ls=["dragTimeout","inertiaDuration","inertiaRatio","doubleClickTimeout","doubleClickZoomingRatio","doubleClickZoomingDuration","tapMoveTolerance"].reduce((r,e)=>({...r,[e]:or[e]}),{});class us extends Jn{constructor(e,t){super(e,t),this.enabled=!0,this.isMoving=!1,this.hasMoved=!1,this.touchMode=0,this.startTouchesPositions=[],this.lastTouches=[],this.lastTap=null,this.settings=ls,this.handleStart=this.handleStart.bind(this),this.handleLeave=this.handleLeave.bind(this),this.handleMove=this.handleMove.bind(this),e.addEventListener("touchstart",this.handleStart,{capture:!1}),e.addEventListener("touchcancel",this.handleLeave,{capture:!1}),document.addEventListener("touchend",this.handleLeave,{capture:!1,passive:!1}),document.addEventListener("touchmove",this.handleMove,{capture:!1,passive:!1})}kill(){const e=this.container;e.removeEventListener("touchstart",this.handleStart),e.removeEventListener("touchcancel",this.handleLeave),document.removeEventListener("touchend",this.handleLeave),document.removeEventListener("touchmove",this.handleMove)}getDimensions(){return{width:this.container.offsetWidth,height:this.container.offsetHeight}}handleStart(e){if(!this.enabled)return;e.preventDefault();const t=et(e.touches);if(this.touchMode=t.length,this.startCameraState=this.renderer.getCamera().getState(),this.startTouchesPositions=t.map(n=>W(n,this.container)),this.touchMode===2){const[{x:n,y:i},{x:o,y:a}]=this.startTouchesPositions;this.startTouchesAngle=Math.atan2(a-i,o-n),this.startTouchesDistance=Math.sqrt(Math.pow(o-n,2)+Math.pow(a-i,2))}this.emit("touchdown",Oe(e,this.lastTouches,this.container)),this.lastTouches=t,this.lastTouchesPositions=this.startTouchesPositions}handleLeave(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){const t=this.renderer.getCamera(),n=t.getState(),i=t.getPreviousState()||{x:0,y:0};t.animate({x:n.x+this.settings.inertiaRatio*(n.x-i.x),y:n.y+this.settings.inertiaRatio*(n.y-i.y)},{duration:this.settings.inertiaDuration,easing:"quadraticOut"})}this.hasMoved=!1,this.isMoving=!1,this.touchMode=0;break}if(this.emit("touchup",Oe(e,this.lastTouches,this.container)),!e.touches.length){const t=W(this.lastTouches[0],this.container),n=this.startTouchesPositions[0],i=(t.x-n.x)**2+(t.y-n.y)**2;if(!e.touches.length&&iW(c,this.container)),i=this.lastTouches;this.lastTouches=t,this.lastTouchesPositions=n;const o=Oe(e,i,this.container);if(this.emit("touchmove",o),o.sigmaDefaultPrevented||(this.hasMoved||(this.hasMoved=n.some((c,u)=>{const d=this.startTouchesPositions[u];return d&&(c.x!==d.x||c.y!==d.y)})),!this.hasMoved))return;this.isMoving=!0,this.movingTimeout&&clearTimeout(this.movingTimeout),this.movingTimeout=window.setTimeout(()=>{this.isMoving=!1},this.settings.dragTimeout);const a=this.renderer.getCamera(),s=this.startCameraState,l=this.renderer.getSetting("stagePadding");switch(this.touchMode){case 1:{const{x:c,y:u}=this.renderer.viewportToFramedGraph((this.startTouchesPositions||[])[0]),{x:d,y:h}=this.renderer.viewportToFramedGraph(n[0]);a.setState({x:s.x+c-d,y:s.y+u-h});break}case 2:{const c={x:.5,y:.5,angle:0,ratio:1},{x:u,y:d}=n[0],{x:h,y:m}=n[1],g=Math.atan2(m-d,h-u)-this.startTouchesAngle,b=Math.hypot(m-d,h-u)/this.startTouchesDistance,E=a.getBoundedRatio(s.ratio/b);c.ratio=E,c.angle=s.angle+g;const v=this.getDimensions(),T=this.renderer.viewportToFramedGraph((this.startTouchesPositions||[])[0],{cameraState:s}),_=Math.min(v.width,v.height)-2*l,f=_/v.width,p=_/v.height,y=E/_;let R=u-_/2/f,S=d-_/2/p;[R,S]=[R*Math.cos(-c.angle)-S*Math.sin(-c.angle),S*Math.cos(-c.angle)+R*Math.sin(-c.angle)],c.x=T.x-R*y,c.y=T.y+S*y,a.setState(c);break}}}setSettings(e){this.settings=e}}class ti{constructor(e,t){this.key=e,this.size=t}static compare(e,t){return e.size>t.size?-1:e.sizet.key?1:-1}}class ri{constructor(){this.width=0,this.height=0,this.cellSize=0,this.columns=0,this.rows=0,this.cells={}}resizeAndClear(e,t){this.width=e.width,this.height=e.height,this.cellSize=t,this.columns=Math.ceil(e.width/t),this.rows=Math.ceil(e.height/t),this.cells={}}getIndex(e){const t=Math.floor(e.x/this.cellSize);return Math.floor(e.y/this.cellSize)*this.columns+t}add(e,t,n){const i=new ti(e,t),o=this.getIndex(n);let a=this.cells[o];a||(a=[],this.cells[o]=a),a.push(i)}organize(){for(const e in this.cells)this.cells[e].sort(ti.compare)}getLabelsToDisplay(e,t){const n=this.cellSize*this.cellSize,o=n/e/e*t/n,a=Math.ceil(o),s=[];for(const l in this.cells){const c=this.cells[l];for(let u=0;u{(l===t||c===t||n.has(l)||n.has(c)||i.has(l)&&i.has(c))&&o.push(a)}),o}const ds=150,fs=50,Q=Object.prototype.hasOwnProperty;function gs(r,e,t){if(!Q.call(t,"x")||!Q.call(t,"y"))throw new Error(`Sigma: could not find a valid position (x, y) for node "${e}". 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=r.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),Q.call(t,"hidden")||(t.hidden=!1),Q.call(t,"highlighted")||(t.highlighted=!1),Q.call(t,"forceLabel")||(t.forceLabel=!1),(!t.type||t.type==="")&&(t.type=r.defaultNodeType),t.zIndex||(t.zIndex=0),t}function ms(r,e,t){return t.color||(t.color=r.defaultEdgeColor),t.label||(t.label=""),t.size||(t.size=.5),Q.call(t,"hidden")||(t.hidden=!1),Q.call(t,"forceLabel")||(t.forceLabel=!1),(!t.type||t.type==="")&&(t.type=r.defaultEdgeType),t.zIndex||(t.zIndex=0),t}let ni=class extends ir{constructor(e,t,n={}){if(super(),this.elements={},this.canvasContexts={},this.webGLContexts={},this.pickingLayers=new Set,this.textures={},this.frameBuffers={},this.activeListeners={},this.labelGrid=new ri,this.nodeDataCache={},this.edgeDataCache={},this.nodeProgramIndex={},this.edgeProgramIndex={},this.nodesWithForcedLabels=new Set,this.edgesWithForcedLabels=new Set,this.nodeExtent={x:[0,1],y:[0,1]},this.nodeZExtent=[1/0,-1/0],this.edgeZExtent=[1/0,-1/0],this.matrix=j(),this.invMatrix=j(),this.correctionRatio=1,this.customBBox=null,this.normalizationFunction=Yt({x:[0,1],y:[0,1]}),this.graphToViewportRatio=1,this.itemIDsIndex={},this.nodeIndices={},this.edgeIndices={},this.width=0,this.height=0,this.pixelRatio=Vt(),this.pickingDownSizingRatio=2*this.pixelRatio,this.displayedNodeLabels=new Set,this.displayedEdgeLabels=new Set,this.highlightedNodes=new Set,this.hoveredNode=null,this.hoveredEdge=null,this.renderFrame=null,this.renderHighlightedNodesFrame=null,this.needToProcess=!1,this.checkEdgesEventsFrame=null,this.nodePrograms={},this.nodeHoverPrograms={},this.edgePrograms={},this.settings=os(n),ar(this.settings),Sn(e),!(t instanceof HTMLElement))throw new Error("Sigma: container should be an html element.");this.graph=e,this.container=t,this.createWebGLContext("edges",{picking:n.enableEdgeEvents}),this.createCanvasContext("edgeLabels"),this.createWebGLContext("nodes",{picking:!0}),this.createCanvasContext("labels"),this.createCanvasContext("hovers"),this.createWebGLContext("hoverNodes"),this.createCanvasContext("mouse",{style:{touchAction:"none",userSelect:"none"}}),this.resize();for(const i in this.settings.nodeProgramClasses)this.registerNodeProgram(i,this.settings.nodeProgramClasses[i],this.settings.nodeHoverProgramClasses[i]);for(const i in this.settings.edgeProgramClasses)this.registerEdgeProgram(i,this.settings.edgeProgramClasses[i]);this.camera=new ye,this.bindCameraHandlers(),this.mouseCaptor=new ei(this.elements.mouse,this),this.mouseCaptor.setSettings(this.settings),this.touchCaptor=new us(this.elements.mouse,this),this.touchCaptor.setSettings(this.settings),this.bindEventHandlers(),this.bindGraphHandlers(),this.handleSettingsUpdate(),this.refresh()}registerNodeProgram(e,t,n){return this.nodePrograms[e]&&this.nodePrograms[e].kill(),this.nodeHoverPrograms[e]&&this.nodeHoverPrograms[e].kill(),this.nodePrograms[e]=new t(this.webGLContexts.nodes,this.frameBuffers.nodes,this),this.nodeHoverPrograms[e]=new(n||t)(this.webGLContexts.hoverNodes,null,this),this}registerEdgeProgram(e,t){return this.edgePrograms[e]&&this.edgePrograms[e].kill(),this.edgePrograms[e]=new t(this.webGLContexts.edges,this.frameBuffers.edges,this),this}unregisterNodeProgram(e){if(this.nodePrograms[e]){const{[e]:t,...n}=this.nodePrograms;t.kill(),this.nodePrograms=n}if(this.nodeHoverPrograms[e]){const{[e]:t,...n}=this.nodeHoverPrograms;t.kill(),this.nodePrograms=n}return this}unregisterEdgeProgram(e){if(this.edgePrograms[e]){const{[e]:t,...n}=this.edgePrograms;t.kill(),this.edgePrograms=n}return this}resetWebGLTexture(e){const t=this.webGLContexts[e],n=this.frameBuffers[e],i=this.textures[e];i&&t.deleteTexture(i);const o=t.createTexture();return t.bindFramebuffer(t.FRAMEBUFFER,n),t.bindTexture(t.TEXTURE_2D,o),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,this.width,this.height,0,t.RGBA,t.UNSIGNED_BYTE,null),t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,o,0),this.textures[e]=o,this}bindCameraHandlers(){return this.activeListeners.camera=()=>{this.scheduleRender()},this.camera.on("updated",this.activeListeners.camera),this}unbindCameraHandlers(){return this.camera.removeListener("updated",this.activeListeners.camera),this}getNodeAtPosition(e){const{x:t,y:n}=e,i=Bt(this.webGLContexts.nodes,this.frameBuffers.nodes,t,n,this.pixelRatio,this.pickingDownSizingRatio),o=Ut(...i),a=this.itemIDsIndex[o];return a&&a.type==="node"?a.id:null}bindEventHandlers(){this.activeListeners.handleResize=()=>{this.scheduleRefresh()},window.addEventListener("resize",this.activeListeners.handleResize),this.activeListeners.handleMove=t=>{const n=Pe(t),i={event:n,preventSigmaDefault(){n.preventSigmaDefault()}},o=this.getNodeAtPosition(n);if(o&&this.hoveredNode!==o&&!this.nodeDataCache[o].hidden){this.hoveredNode&&this.emit("leaveNode",{...i,node:this.hoveredNode}),this.hoveredNode=o,this.emit("enterNode",{...i,node:o}),this.scheduleHighlightedNodesRender();return}if(this.hoveredNode&&this.getNodeAtPosition(n)!==this.hoveredNode){const a=this.hoveredNode;this.hoveredNode=null,this.emit("leaveNode",{...i,node:a}),this.scheduleHighlightedNodesRender();return}if(this.settings.enableEdgeEvents){const a=this.hoveredNode?null:this.getEdgeAtPoint(i.event.x,i.event.y);a!==this.hoveredEdge&&(this.hoveredEdge&&this.emit("leaveEdge",{...i,edge:this.hoveredEdge}),a&&this.emit("enterEdge",{...i,edge:a}),this.hoveredEdge=a)}},this.activeListeners.handleMoveBody=t=>{const n=Pe(t);this.emit("moveBody",{event:n,preventSigmaDefault(){n.preventSigmaDefault()}})},this.activeListeners.handleLeave=t=>{const n=Pe(t),i={event:n,preventSigmaDefault(){n.preventSigmaDefault()}};this.hoveredNode&&(this.emit("leaveNode",{...i,node:this.hoveredNode}),this.scheduleHighlightedNodesRender()),this.settings.enableEdgeEvents&&this.hoveredEdge&&(this.emit("leaveEdge",{...i,edge:this.hoveredEdge}),this.scheduleHighlightedNodesRender()),this.emit("leaveStage",{...i})},this.activeListeners.handleEnter=t=>{const n=Pe(t),i={event:n,preventSigmaDefault(){n.preventSigmaDefault()}};this.emit("enterStage",{...i})};const e=t=>n=>{const i=Pe(n),o={event:i,preventSigmaDefault:()=>{i.preventSigmaDefault()}},a=this.getNodeAtPosition(i);if(a)return this.emit(`${t}Node`,{...o,node:a});if(this.settings.enableEdgeEvents){const s=this.getEdgeAtPoint(i.x,i.y);if(s)return this.emit(`${t}Edge`,{...o,edge:s})}return this.emit(`${t}Stage`,o)};return this.activeListeners.handleClick=e("click"),this.activeListeners.handleRightClick=e("rightClick"),this.activeListeners.handleDoubleClick=e("doubleClick"),this.activeListeners.handleWheel=e("wheel"),this.activeListeners.handleDown=e("down"),this.activeListeners.handleUp=e("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}bindGraphHandlers(){const e=this.graph,t=new Set(["x","y","zIndex","type"]);return this.activeListeners.eachNodeAttributesUpdatedGraphUpdate=n=>{var a;const i=(a=n.hints)==null?void 0:a.attributes;this.graph.forEachNode(s=>this.updateNode(s));const o=!i||i.some(s=>t.has(s));this.refresh({partialGraph:{nodes:e.nodes()},skipIndexation:!o,schedule:!0})},this.activeListeners.eachEdgeAttributesUpdatedGraphUpdate=n=>{var a;const i=(a=n.hints)==null?void 0:a.attributes;this.graph.forEachEdge(s=>this.updateEdge(s));const o=i&&["zIndex","type"].some(s=>i==null?void 0:i.includes(s));this.refresh({partialGraph:{edges:e.edges()},skipIndexation:!o,schedule:!0})},this.activeListeners.addNodeGraphUpdate=n=>{const i=n.key;this.addNode(i),this.refresh({partialGraph:{nodes:[i]},skipIndexation:!1,schedule:!0})},this.activeListeners.updateNodeGraphUpdate=n=>{const i=n.key;this.refresh({partialGraph:{nodes:[i]},skipIndexation:!1,schedule:!0})},this.activeListeners.dropNodeGraphUpdate=n=>{const i=n.key;this.removeNode(i),this.refresh({schedule:!0})},this.activeListeners.addEdgeGraphUpdate=n=>{const i=n.key;this.addEdge(i),this.refresh({partialGraph:{edges:[i]},schedule:!0})},this.activeListeners.updateEdgeGraphUpdate=n=>{const i=n.key;this.refresh({partialGraph:{edges:[i]},skipIndexation:!1,schedule:!0})},this.activeListeners.dropEdgeGraphUpdate=n=>{const i=n.key;this.removeEdge(i),this.refresh({schedule:!0})},this.activeListeners.clearEdgesGraphUpdate=()=>{this.clearEdgeState(),this.clearEdgeIndices(),this.refresh({schedule:!0})},this.activeListeners.clearGraphUpdate=()=>{this.clearEdgeState(),this.clearNodeState(),this.clearEdgeIndices(),this.clearNodeIndices(),this.refresh({schedule:!0})},e.on("nodeAdded",this.activeListeners.addNodeGraphUpdate),e.on("nodeDropped",this.activeListeners.dropNodeGraphUpdate),e.on("nodeAttributesUpdated",this.activeListeners.updateNodeGraphUpdate),e.on("eachNodeAttributesUpdated",this.activeListeners.eachNodeAttributesUpdatedGraphUpdate),e.on("edgeAdded",this.activeListeners.addEdgeGraphUpdate),e.on("edgeDropped",this.activeListeners.dropEdgeGraphUpdate),e.on("edgeAttributesUpdated",this.activeListeners.updateEdgeGraphUpdate),e.on("eachEdgeAttributesUpdated",this.activeListeners.eachEdgeAttributesUpdatedGraphUpdate),e.on("edgesCleared",this.activeListeners.clearEdgesGraphUpdate),e.on("cleared",this.activeListeners.clearGraphUpdate),this}unbindGraphHandlers(){const 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)}getEdgeAtPoint(e,t){const n=Bt(this.webGLContexts.edges,this.frameBuffers.edges,e,t,this.pixelRatio,this.pickingDownSizingRatio),i=Ut(...n),o=this.itemIDsIndex[i];return o&&o.type==="edge"?o.id:null}process(){this.emit("beforeProcess");const e=this.graph,t=this.settings,n=this.getDimensions();if(this.nodeExtent=An(this.graph),!this.settings.autoRescale){const{width:g,height:b}=n,{x:E,y:v}=this.nodeExtent;this.nodeExtent={x:[(E[0]+E[1])/2-g/2,(E[0]+E[1])/2+g/2],y:[(v[0]+v[1])/2-b/2,(v[0]+v[1])/2+b/2]}}this.normalizationFunction=Yt(this.customBBox||this.nodeExtent);const i=new ye,o=be(i.getState(),n,this.getGraphDimensions(),this.getStagePadding());this.labelGrid.resizeAndClear(n,t.labelGridCellSize);const a={},s={},l={},c={};let u=1,d=e.nodes();for(let g=0,b=d.length;gthis.nodeDataCache[g].zIndex,d));for(let g=0,b=d.length;gthis.edgeDataCache[g].zIndex,m));for(const g in this.edgePrograms){if(!Q.call(this.edgePrograms,g))throw new Error(`Sigma: could not find a suitable program for edge type "${g}"!`);this.edgePrograms[g].reallocate(h[g]||0),h[g]=0}for(let g=0,b=m.length;gthis.cleanCameraState(n,t.cameraPanBoundaries&&typeof t.cameraPanBoundaries=="object"?t.cameraPanBoundaries:{}):this.camera.clean=null,this.camera.setState(this.camera.validateState(this.camera.getState())),e){if(e.edgeProgramClasses!==t.edgeProgramClasses){for(const n in t.edgeProgramClasses)t.edgeProgramClasses[n]!==e.edgeProgramClasses[n]&&this.registerEdgeProgram(n,t.edgeProgramClasses[n]);for(const n in e.edgeProgramClasses)t.edgeProgramClasses[n]||this.unregisterEdgeProgram(n)}if(e.nodeProgramClasses!==t.nodeProgramClasses||e.nodeHoverProgramClasses!==t.nodeHoverProgramClasses){for(const n in t.nodeProgramClasses)(t.nodeProgramClasses[n]!==e.nodeProgramClasses[n]||t.nodeHoverProgramClasses[n]!==e.nodeHoverProgramClasses[n])&&this.registerNodeProgram(n,t.nodeProgramClasses[n],t.nodeHoverProgramClasses[n]);for(const n in e.nodeProgramClasses)t.nodeProgramClasses[n]||this.unregisterNodeProgram(n)}}return this.mouseCaptor.setSettings(this.settings),this.touchCaptor.setSettings(this.settings),this}cleanCameraState(e,{tolerance:t=0,boundaries:n}={}){const i={...e},{x:[o,a],y:[s,l]}=n||this.nodeExtent,c=[this.graphToViewport({x:o,y:s},{cameraState:e}),this.graphToViewport({x:a,y:s},{cameraState:e}),this.graphToViewport({x:o,y:l},{cameraState:e}),this.graphToViewport({x:a,y:l},{cameraState:e})];let u=1/0,d=-1/0,h=1/0,m=-1/0;c.forEach(({x:f,y:p})=>{u=Math.min(u,f),d=Math.max(d,f),h=Math.min(h,p),m=Math.max(m,p)});const g=d-u,b=m-h,{width:E,height:v}=this.getDimensions();let T=0,_=0;if(g>=E?dt&&(T=u-t):d>E+t?T=d-(E+t):u<-t&&(T=u+t),b>=v?mt&&(_=h-t):m>v+t?_=m-(v+t):h<-t&&(_=h+t),T||_){const f=this.viewportToFramedGraph({x:0,y:0},{cameraState:e}),p=this.viewportToFramedGraph({x:T,y:_},{cameraState:e});T=p.x-f.x,_=p.y-f.y,i.x+=T,i.y+=_}return i}renderLabels(){if(!this.settings.renderLabels)return this;const e=this.camera.getState(),t=this.labelGrid.getLabelsToDisplay(e.ratio,this.settings.labelDensity);jt(t,this.nodesWithForcedLabels),this.displayedNodeLabels=new Set;const n=this.canvasContexts.labels;for(let i=0,o=t.length;ithis.width+ds||c<-50||c>this.height+fs)continue;this.displayedNodeLabels.add(a);const{defaultDrawNodeLabel:d}=this.settings,h=this.nodePrograms[s.type];((h==null?void 0:h.drawLabel)||d)(n,{key:a,...s,size:u,x:l,y:c},this.settings)}return this}renderEdgeLabels(){if(!this.settings.renderEdgeLabels)return this;const e=this.canvasContexts.edgeLabels;e.clearRect(0,0,this.width,this.height);const t=hs({graph:this.graph,hoveredNode:this.hoveredNode,displayedNodeLabels:this.displayedNodeLabels,highlightedNodes:this.highlightedNodes});jt(t,this.edgesWithForcedLabels);const n=new Set;for(let i=0,o=t.length;i{const s=this.nodeDataCache[a],{x:l,y:c}=this.framedGraphToViewport(s),u=this.scaleSize(s.size),{defaultDrawNodeHover:d}=this.settings,h=this.nodePrograms[s.type];((h==null?void 0:h.drawHover)||d)(e,{key:a,...s,size:u,x:l,y:c},this.settings)},n=[];this.hoveredNode&&!this.nodeDataCache[this.hoveredNode].hidden&&n.push(this.hoveredNode),this.highlightedNodes.forEach(a=>{a!==this.hoveredNode&&n.push(a)}),n.forEach(a=>t(a));const i={};n.forEach(a=>{const s=this.nodeDataCache[a].type;i[s]=(i[s]||0)+1});for(const a in this.nodeHoverPrograms)this.nodeHoverPrograms[a].reallocate(i[a]||0),i[a]=0;n.forEach(a=>{const s=this.nodeDataCache[a];this.nodeHoverPrograms[s.type].process(0,i[s.type]++,s)}),this.webGLContexts.hoverNodes.clear(this.webGLContexts.hoverNodes.COLOR_BUFFER_BIT);const o=this.getRenderParams();for(const a in this.nodeHoverPrograms)this.nodeHoverPrograms[a].render(o)}scheduleHighlightedNodesRender(){this.renderHighlightedNodesFrame||this.renderFrame||(this.renderHighlightedNodesFrame=requestAnimationFrame(()=>{this.renderHighlightedNodesFrame=null,this.renderHighlightedNodes(),this.renderEdgeLabels()}))}render(){this.emit("beforeRender");const e=()=>(this.emit("afterRender"),this);if(this.renderFrame&&(cancelAnimationFrame(this.renderFrame),this.renderFrame=null),this.resize(),this.needToProcess&&this.process(),this.needToProcess=!1,this.clear(),this.pickingLayers.forEach(c=>this.resetWebGLTexture(c)),!this.graph.order)return e();const t=this.mouseCaptor,n=this.camera.isAnimated()||t.isMoving||t.draggedEvents||t.currentWheelDirection,i=this.camera.getState(),o=this.getDimensions(),a=this.getGraphDimensions(),s=this.getStagePadding();this.matrix=be(i,o,a,s),this.invMatrix=be(i,o,a,s,!0),this.correctionRatio=Rn(this.matrix,i,o),this.graphToViewportRatio=this.getGraphToViewportRatio();const l=this.getRenderParams();for(const c in this.nodePrograms)this.nodePrograms[c].render(l);if(!this.settings.hideEdgesOnMove||!n)for(const c in this.edgePrograms)this.edgePrograms[c].render(l);return this.settings.hideLabelsOnMove&&n||(this.renderLabels(),this.renderEdgeLabels(),this.renderHighlightedNodes()),e()}addNode(e){let t=Object.assign({},this.graph.getNodeAttributes(e));this.settings.nodeReducer&&(t=this.settings.nodeReducer(e,t));const n=gs(this.settings,e,t);this.nodeDataCache[e]=n,this.nodesWithForcedLabels.delete(e),n.forceLabel&&!n.hidden&&this.nodesWithForcedLabels.add(e),this.highlightedNodes.delete(e),n.highlighted&&!n.hidden&&this.highlightedNodes.add(e),this.settings.zIndex&&(n.zIndexthis.nodeZExtent[1]&&(this.nodeZExtent[1]=n.zIndex))}updateNode(e){this.addNode(e);const t=this.nodeDataCache[e];this.normalizationFunction.applyTo(t)}removeNode(e){delete this.nodeDataCache[e],delete this.nodeProgramIndex[e],this.highlightedNodes.delete(e),this.hoveredNode===e&&(this.hoveredNode=null),this.nodesWithForcedLabels.delete(e)}addEdge(e){let t=Object.assign({},this.graph.getEdgeAttributes(e));this.settings.edgeReducer&&(t=this.settings.edgeReducer(e,t));const n=ms(this.settings,e,t);this.edgeDataCache[e]=n,this.edgesWithForcedLabels.delete(e),n.forceLabel&&!n.hidden&&this.edgesWithForcedLabels.add(e),this.settings.zIndex&&(n.zIndexthis.edgeZExtent[1]&&(this.edgeZExtent[1]=n.zIndex))}updateEdge(e){this.addEdge(e)}removeEdge(e){delete this.edgeDataCache[e],delete this.edgeProgramIndex[e],this.hoveredEdge===e&&(this.hoveredEdge=null),this.edgesWithForcedLabels.delete(e)}clearNodeIndices(){this.labelGrid=new ri,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}clearEdgeIndices(){this.edgeDataCache={},this.edgeProgramIndex={},this.edgesWithForcedLabels=new Set,this.edgeZExtent=[1/0,-1/0]}clearIndices(){this.clearEdgeIndices(),this.clearNodeIndices()}clearNodeState(){this.displayedNodeLabels=new Set,this.highlightedNodes=new Set,this.hoveredNode=null}clearEdgeState(){this.displayedEdgeLabels=new Set,this.highlightedNodes=new Set,this.hoveredEdge=null}clearState(){this.clearEdgeState(),this.clearNodeState()}addNodeToProgram(e,t,n){const i=this.nodeDataCache[e],o=this.nodePrograms[i.type];if(!o)throw new Error(`Sigma: could not find a suitable program for node type "${i.type}"!`);o.process(t,n,i),this.nodeProgramIndex[e]=n}addEdgeToProgram(e,t,n){const i=this.edgeDataCache[e],o=this.edgePrograms[i.type];if(!o)throw new Error(`Sigma: could not find a suitable program for edge type "${i.type}"!`);const a=this.graph.extremities(e),s=this.nodeDataCache[a[0]],l=this.nodeDataCache[a[1]];o.process(t,n,s,l,i),this.edgeProgramIndex[e]=n}getRenderParams(){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}}getStagePadding(){const{stagePadding:e,autoRescale:t}=this.settings;return t&&e||0}createLayer(e,t,n={}){if(this.elements[e])throw new Error(`Sigma: a layer named "${e}" already exists`);const i=xn(t,{position:"absolute"},{class:`sigma-${e}`});return n.style&&Object.assign(i.style,n.style),this.elements[e]=i,"beforeLayer"in n&&n.beforeLayer?this.elements[n.beforeLayer].before(i):"afterLayer"in n&&n.afterLayer?this.elements[n.afterLayer].after(i):this.container.appendChild(i),i}createCanvas(e,t={}){return this.createLayer(e,"canvas",t)}createCanvasContext(e,t={}){const n=this.createCanvas(e,t),i={preserveDrawingBuffer:!1,antialias:!1};return this.canvasContexts[e]=n.getContext("2d",i),this}createWebGLContext(e,t={}){const n=(t==null?void 0:t.canvas)||this.createCanvas(e,t);t.hidden&&n.remove();const i={preserveDrawingBuffer:!1,antialias:!1,...t};let o;o=n.getContext("webgl2",i),o||(o=n.getContext("webgl",i)),o||(o=n.getContext("experimental-webgl",i));const a=o;if(this.webGLContexts[e]=a,a.blendFunc(a.ONE,a.ONE_MINUS_SRC_ALPHA),t.picking){this.pickingLayers.add(e);const s=a.createFramebuffer();if(!s)throw new Error(`Sigma: cannot create a new frame buffer for layer ${e}`);this.frameBuffers[e]=s}return a}killLayer(e){var n;const t=this.elements[e];if(!t)throw new Error(`Sigma: cannot kill layer ${e}, which does not exist`);return this.webGLContexts[e]?((n=this.webGLContexts[e].getExtension("WEBGL_lose_context"))==null||n.loseContext(),delete this.webGLContexts[e]):this.canvasContexts[e]&&delete this.canvasContexts[e],t.remove(),delete this.elements[e],this}getCamera(){return this.camera}setCamera(e){this.unbindCameraHandlers(),this.camera=e,this.bindCameraHandlers()}getContainer(){return this.container}getGraph(){return this.graph}setGraph(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())}getMouseCaptor(){return this.mouseCaptor}getTouchCaptor(){return this.touchCaptor}getDimensions(){return{width:this.width,height:this.height}}getGraphDimensions(){const e=this.customBBox||this.nodeExtent;return{width:e.x[1]-e.x[0]||1,height:e.y[1]-e.y[0]||1}}getNodeDisplayData(e){const t=this.nodeDataCache[e];return t?Object.assign({},t):void 0}getEdgeDisplayData(e){const t=this.edgeDataCache[e];return t?Object.assign({},t):void 0}getNodeDisplayedLabels(){return new Set(this.displayedNodeLabels)}getEdgeDisplayedLabels(){return new Set(this.displayedEdgeLabels)}getSettings(){return{...this.settings}}getSetting(e){return this.settings[e]}setSetting(e,t){const n={...this.settings};return this.settings[e]=t,ar(this.settings),this.handleSettingsUpdate(n),this.scheduleRefresh(),this}updateSetting(e,t){return this.setSetting(e,t(this.settings[e])),this}setSettings(e){const t={...this.settings};return this.settings={...this.settings,...e},ar(this.settings),this.handleSettingsUpdate(t),this.scheduleRefresh(),this}resize(e){const t=this.width,n=this.height;if(this.width=this.container.offsetWidth,this.height=this.container.offsetHeight,this.pixelRatio=Vt(),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&&t===this.width&&n===this.height)return this;for(const i in this.elements){const o=this.elements[i];o.style.width=this.width+"px",o.style.height=this.height+"px"}for(const i in this.canvasContexts)this.elements[i].setAttribute("width",this.width*this.pixelRatio+"px"),this.elements[i].setAttribute("height",this.height*this.pixelRatio+"px"),this.pixelRatio!==1&&this.canvasContexts[i].scale(this.pixelRatio,this.pixelRatio);for(const i in this.webGLContexts){this.elements[i].setAttribute("width",this.width*this.pixelRatio+"px"),this.elements[i].setAttribute("height",this.height*this.pixelRatio+"px");const o=this.webGLContexts[i];if(o.viewport(0,0,this.width*this.pixelRatio,this.height*this.pixelRatio),this.pickingLayers.has(i)){const a=this.textures[i];a&&o.deleteTexture(a)}}return this.emit("resize"),this}clear(){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}refresh(e){var o,a;const t=(e==null?void 0:e.skipIndexation)!==void 0?e==null?void 0:e.skipIndexation:!1,n=(e==null?void 0:e.schedule)!==void 0?e.schedule:!1,i=!e||!e.partialGraph;if(i)this.clearEdgeIndices(),this.clearNodeIndices(),this.graph.forEachNode(s=>this.addNode(s)),this.graph.forEachEdge(s=>this.addEdge(s));else{const s=((o=e.partialGraph)==null?void 0:o.nodes)||[];for(let c=0,u=(s==null?void 0:s.length)||0;c{this.render()})),this}scheduleRefresh(e){return this.refresh({...e,schedule:!0})}getViewportZoomedState(e,t){const{ratio:n,angle:i,x:o,y:a}=this.camera.getState(),{minCameraRatio:s,maxCameraRatio:l}=this.settings;typeof l=="number"&&(t=Math.min(t,l)),typeof s=="number"&&(t=Math.max(t,s));const c=t/n,u={x:this.width/2,y:this.height/2},d=this.viewportToFramedGraph(e),h=this.viewportToFramedGraph(u);return{angle:i,x:(d.x-h.x)*(1-c)+o,y:(d.y-h.y)*(1-c)+a,ratio:t}}viewRectangle(){const e=this.viewportToFramedGraph({x:0,y:0}),t=this.viewportToFramedGraph({x:this.width,y:0}),n=this.viewportToFramedGraph({x:0,y:this.height});return{x1:e.x,y1:e.y,x2:t.x,y2:t.y,height:t.y-n.y}}framedGraphToViewport(e,t={}){const n=!!t.cameraState||!!t.viewportDimensions||!!t.graphDimensions,i=t.matrix?t.matrix:n?be(t.cameraState||this.camera.getState(),t.viewportDimensions||this.getDimensions(),t.graphDimensions||this.getGraphDimensions(),t.padding||this.getStagePadding()):this.matrix,o=Ye(i,e);return{x:(1+o.x)*this.width/2,y:(1-o.y)*this.height/2}}viewportToFramedGraph(e,t={}){const n=!!t.cameraState||!!t.viewportDimensions||!t.graphDimensions,i=t.matrix?t.matrix:n?be(t.cameraState||this.camera.getState(),t.viewportDimensions||this.getDimensions(),t.graphDimensions||this.getGraphDimensions(),t.padding||this.getStagePadding(),!0):this.invMatrix,o=Ye(i,{x:e.x/this.width*2-1,y:1-e.y/this.height*2});return isNaN(o.x)&&(o.x=0),isNaN(o.y)&&(o.y=0),o}viewportToGraph(e,t={}){return this.normalizationFunction.inverse(this.viewportToFramedGraph(e,t))}graphToViewport(e,t={}){return this.framedGraphToViewport(this.normalizationFunction(e),t)}getGraphToViewportRatio(){const e={x:0,y:0},t={x:1,y:1},n=Math.sqrt(Math.pow(e.x-t.x,2)+Math.pow(e.y-t.y,2)),i=this.graphToViewport(e),o=this.graphToViewport(t);return Math.sqrt(Math.pow(i.x-o.x,2)+Math.pow(i.y-o.y,2))/n}getBBox(){return this.nodeExtent}getCustomBBox(){return this.customBBox}setCustomBBox(e){return this.customBBox=e,this.scheduleRender(),this}kill(){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);const e=this.container;for(;e.firstChild;)e.removeChild(e.firstChild);for(const t in this.nodePrograms)this.nodePrograms[t].kill();for(const t in this.nodeHoverPrograms)this.nodeHoverPrograms[t].kill();for(const t in this.edgePrograms)this.edgePrograms[t].kill();this.nodePrograms={},this.nodeHoverPrograms={},this.edgePrograms={};for(const t in this.elements)this.killLayer(t);this.canvasContexts={},this.webGLContexts={},this.elements={}}scaleSize(e=1,t=this.camera.ratio){return e/this.settings.zoomToSizeRatioFunction(t)*(this.getSetting("itemSizesReference")==="positions"?t*this.graphToViewportRatio:1)}getCanvases(){const e={};for(const t in this.elements)this.elements[t]instanceof HTMLCanvasElement&&(e[t]=this.elements[t]);return e}};const le=class le extends ni{};le.Camera=ye,le.MouseCaptor=ei,le.Sigma=ni,le.rendering={...rs,createNodeBorderProgram:Vr,createNodeImageProgram:Ft,createNodePiechartProgram:ma,EdgeCurveProgram:no},le.utils=Ea;let sr=le;return sr});