(function(Ce,de){typeof exports=="object"&&typeof module<"u"?module.exports=de():typeof define=="function"&&define.amd?define(de):(Ce=typeof globalThis<"u"?globalThis:Ce||self,Ce.Sigma=de())})(this,function(){"use strict";function Ce(r,e){if(typeof r!="object"||!r)return r;var t=r[Symbol.toPrimitive];if(t!==void 0){var i=t.call(r,e||"default");if(typeof i!="object")return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return(e==="string"?String:Number)(r)}function de(r){var e=Ce(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 Rn(r,e){for(var t=0;t>8&255,o=t>>16&255,a=t>>24&255;return[i,n,o,a]}var at={};function pr(r){if(typeof at[r]<"u")return at[r];var e=(r&16711680)>>>16,t=(r&65280)>>>8,i=r&255,n=255,o=vr(e,t,i,n);return at[r]=o,o}function O(r,e,t){return(e=de(e))in r?Object.defineProperty(r,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):r[e]=t,r}function _r(r,e){var t=Object.keys(r);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(r);e&&(i=i.filter(function(n){return Object.getOwnPropertyDescriptor(r,n).enumerable})),t.push.apply(t,i)}return t}function me(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 } `,In=kn,zn=` 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; } `,Gn=zn,Cr=WebGLRenderingContext,wr=Cr.UNSIGNED_BYTE,ht=Cr.FLOAT,Mn=["u_sizeRatio","u_correctionRatio","u_matrix"],dt=function(r){Ae(e,r);function e(){return ne(this,e),we(this,e,arguments)}return oe(e,[{key:"getDefinition",value:function(){return{VERTICES:3,VERTEX_SHADER_SOURCE:Gn,FRAGMENT_SHADER_SOURCE:In,METHOD:WebGLRenderingContext.TRIANGLES,UNIFORMS:Mn,ATTRIBUTES:[{name:"a_position",size:2,type:ht},{name:"a_size",size:1,type:ht},{name:"a_color",size:4,type:wr,normalized:!0},{name:"a_id",size:4,type:wr,normalized:!0}],CONSTANT_ATTRIBUTES:[{name:"a_angle",size:1,type:ht}],CONSTANT_DATA:[[e.ANGLE_1],[e.ANGLE_2],[e.ANGLE_3]]}}},{key:"processVisibleItem",value:function(i,n,o){var a=this.array,s=K(o.color);a[n++]=o.x,a[n++]=o.y,a[n++]=o.size,a[n++]=s,a[n++]=i}},{key:"setUniforms",value:function(i,n){var o=n.gl,a=n.uniformLocations,s=a.u_sizeRatio,c=a.u_correctionRatio,l=a.u_matrix;o.uniform1f(c,i.correctionRatio),o.uniform1f(s,i.sizeRatio),o.uniformMatrix3fv(l,!1,i.matrix)}}]),e}(Ge);O(dt,"ANGLE_1",0),O(dt,"ANGLE_2",2*Math.PI/3),O(dt,"ANGLE_3",4*Math.PI/3);var Un=` precision mediump float; varying vec4 v_color; void main(void) { gl_FragColor = v_color; } `,Bn=Un,Hn=` 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; } `,$n=Hn,Ar=WebGLRenderingContext,Sr=Ar.UNSIGNED_BYTE,Me=Ar.FLOAT,jn=["u_matrix","u_sizeRatio","u_correctionRatio","u_minEdgeThickness","u_lengthToThicknessRatio","u_widenessToThicknessRatio"],ft={extremity:"target",lengthToThicknessRatio:2.5,widenessToThicknessRatio:2};function xr(r){var e=me(me({},ft),{});return function(t){Ae(i,t);function i(){return ne(this,i),we(this,i,arguments)}return oe(i,[{key:"getDefinition",value:function(){return{VERTICES:3,VERTEX_SHADER_SOURCE:$n,FRAGMENT_SHADER_SOURCE:Bn,METHOD:WebGLRenderingContext.TRIANGLES,UNIFORMS:jn,ATTRIBUTES:[{name:"a_position",size:2,type:Me},{name:"a_normal",size:2,type:Me},{name:"a_radius",size:1,type:Me},{name:"a_color",size:4,type:Sr,normalized:!0},{name:"a_id",size:4,type:Sr,normalized:!0}],CONSTANT_ATTRIBUTES:[{name:"a_barycentric",size:3,type:Me}],CONSTANT_DATA:[[1,0,0],[0,1,0],[0,0,1]]}}},{key:"processVisibleItem",value:function(o,a,s,c,l){if(e.extremity==="source"){var u=[c,s];s=u[0],c=u[1]}var h=l.size||1,d=c.size||1,m=s.x,f=s.y,p=c.x,b=c.y,g=K(l.color),_=p-m,v=b-f,y=_*_+v*v,C=0,S=0;y&&(y=1/Math.sqrt(y),C=-v*y*h,S=_*y*h);var w=this.array;w[a++]=p,w[a++]=b,w[a++]=-C,w[a++]=-S,w[a++]=d,w[a++]=g,w[a++]=o}},{key:"setUniforms",value:function(o,a){var s=a.gl,c=a.uniformLocations,l=c.u_matrix,u=c.u_sizeRatio,h=c.u_correctionRatio,d=c.u_minEdgeThickness,m=c.u_lengthToThicknessRatio,f=c.u_widenessToThicknessRatio;s.uniformMatrix3fv(l,!1,o.matrix),s.uniform1f(u,o.sizeRatio),s.uniform1f(h,o.correctionRatio),s.uniform1f(d,o.minEdgeThickness),s.uniform1f(m,e.lengthToThicknessRatio),s.uniform1f(f,e.widenessToThicknessRatio)}}]),i}(ut)}xr();var Vn=` 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 } `,Wn=Vn,Yn=` 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; } `,Xn=Yn,Fr=WebGLRenderingContext,Lr=Fr.UNSIGNED_BYTE,ae=Fr.FLOAT,qn=["u_matrix","u_zoomRatio","u_sizeRatio","u_correctionRatio","u_pixelRatio","u_feather","u_minEdgeThickness","u_lengthToThicknessRatio"],Kn={lengthToThicknessRatio:ft.lengthToThicknessRatio};function Nr(r){var e=me(me({},Kn),{});return function(t){Ae(i,t);function i(){return ne(this,i),we(this,i,arguments)}return oe(i,[{key:"getDefinition",value:function(){return{VERTICES:6,VERTEX_SHADER_SOURCE:Xn,FRAGMENT_SHADER_SOURCE:Wn,METHOD:WebGLRenderingContext.TRIANGLES,UNIFORMS:qn,ATTRIBUTES:[{name:"a_positionStart",size:2,type:ae},{name:"a_positionEnd",size:2,type:ae},{name:"a_normal",size:2,type:ae},{name:"a_color",size:4,type:Lr,normalized:!0},{name:"a_id",size:4,type:Lr,normalized:!0},{name:"a_radius",size:1,type:ae}],CONSTANT_ATTRIBUTES:[{name:"a_positionCoef",size:1,type:ae},{name:"a_normalCoef",size:1,type:ae},{name:"a_radiusCoef",size:1,type:ae}],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,c,l){var u=l.size||1,h=s.x,d=s.y,m=c.x,f=c.y,p=K(l.color),b=m-h,g=f-d,_=c.size||1,v=b*b+g*g,y=0,C=0;v&&(v=1/Math.sqrt(v),y=-g*v*u,C=b*v*u);var S=this.array;S[a++]=h,S[a++]=d,S[a++]=m,S[a++]=f,S[a++]=y,S[a++]=C,S[a++]=p,S[a++]=o,S[a++]=_}},{key:"setUniforms",value:function(o,a){var s=a.gl,c=a.uniformLocations,l=c.u_matrix,u=c.u_zoomRatio,h=c.u_feather,d=c.u_pixelRatio,m=c.u_correctionRatio,f=c.u_sizeRatio,p=c.u_minEdgeThickness,b=c.u_lengthToThicknessRatio;s.uniformMatrix3fv(l,!1,o.matrix),s.uniform1f(u,o.zoomRatio),s.uniform1f(f,o.sizeRatio),s.uniform1f(m,o.correctionRatio),s.uniform1f(d,o.pixelRatio),s.uniform1f(h,o.antiAliasingFeather),s.uniform1f(p,o.minEdgeThickness),s.uniform1f(b,e.lengthToThicknessRatio)}}]),i}(ut)}Nr();function Zn(r){return On([Nr(),xr()])}Zn();function Qn(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}var Jn=function(e){return e!==null&&typeof e=="object"&&typeof e.addUndirectedEdgeWithKey=="function"&&typeof e.dropNode=="function"&&typeof e.multi=="boolean"};const eo=Qn(Jn);function to(r,e){if(!(r instanceof e))throw new TypeError("Cannot call a class as a function")}function ro(r,e){if(typeof r!="object"||!r)return r;var t=r[Symbol.toPrimitive];if(t!==void 0){var i=t.call(r,e||"default");if(typeof i!="object")return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return(e==="string"?String:Number)(r)}function Pr(r){var e=ro(r,"string");return typeof e=="symbol"?e:e+""}function io(r,e){for(var t=0;tr.length)&&(e=r.length);for(var t=0,i=Array(e);tG){var M="…";for(p=p+M,N=o.measureText(p).width;N>G&&p.length>1;)p=p.slice(0,-2)+M,N=o.measureText(p).width;if(p.length<4)return}for(var q={},te=0,re=p.length;ter.length)&&(e=r.length);for(var t=0,i=Array(e);t v_radius) gl_FragColor = transparent; else { gl_FragColor = v_color; gl_FragColor.a *= bias; } #else // Sizes: `).concat(e.flatMap(function(n,o){var a=n.size;if("fill"in a)return[];a=a;var s="attribute"in a?"v_borderSize_".concat(o+1):lt(a.value),c=(a.mode||Do)==="pixels"?"u_correctionRatio":"v_radius";return[" float borderSize_".concat(o+1," = ").concat(c," * ").concat(s,";")]}).join(` `),` // Now, let's split the remaining space between "fill" borders: float fillBorderSize = (v_radius - (`).concat(e.flatMap(function(n,o){var a=n.size;return"fill"in a?[]:["borderSize_".concat(o+1)]}).join(" + "),") ) / ").concat(t,`; `).concat(e.flatMap(function(n,o){var a=n.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(n,o){return" float adjustedBorderSize_".concat(o+1," = adjustedBorderSize_").concat(o," - borderSize_").concat(o+1,";")}).join(` `),` // Colors: vec4 borderColor_0 = transparent; `).concat(e.map(function(n,o){var a=n.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(n,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 i}function zo(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(i,n){var o=i.size;return"attribute"in o?["attribute float a_borderSize_".concat(n+1,";"),"varying float v_borderSize_".concat(n+1,";")]:[]}).join(` `),` `).concat(e.flatMap(function(i,n){var o=i.color;return"attribute"in o?["attribute vec4 a_borderColor_".concat(n+1,";"),"varying vec4 v_borderColor_".concat(n+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(i,n){var o=i.size;return"attribute"in o?[" v_borderSize_".concat(n+1," = a_borderSize_").concat(n+1,";")]:[]}).join(` `),` `).concat(e.flatMap(function(i,n){var o=i.color;return"attribute"in o?[" v_borderColor_".concat(n+1," = a_borderColor_").concat(n+1,";")]:[]}).join(` `),` #endif } `);return t}var qr=WebGLRenderingContext,Kr=qr.UNSIGNED_BYTE,He=qr.FLOAT;function Zr(r){var e,t=Xr(Xr({},Oo),r||{}),i=t.borders,n=t.drawLabel,o=t.drawHover,a=["u_sizeRatio","u_correctionRatio","u_matrix"].concat(bt(i.flatMap(function(s,c){var l=s.color;return"value"in l?["u_borderColor_".concat(c+1)]:[]})));return e=function(s){Fo(c,s);function c(){var l;Ro(this,c);for(var u=arguments.length,h=new Array(u),d=0;d0&&(a=t[0]),a instanceof Error)throw a;var s=new Error("Unhandled error."+(a?" ("+a.message+")":""));throw s.context=a,s}var c=o[e];if(c===void 0)return!1;if(typeof c=="function")Qr(c,this,t);else for(var l=c.length,u=ai(c,l),i=0;i0&&a.length>n&&!a.warned){a.warned=!0;var s=new Error("Possible EventEmitter memory leak detected. "+a.length+" "+String(e)+" listeners added. Use emitter.setMaxListeners() to increase limit");s.name="MaxListenersExceededWarning",s.emitter=r,s.type=e,s.count=a.length,Go(s)}return r}L.prototype.addListener=function(e,t){return ri(this,e,t,!1)},L.prototype.on=L.prototype.addListener,L.prototype.prependListener=function(e,t){return ri(this,e,t,!0)};function Mo(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function ii(r,e,t){var i={fired:!1,wrapFn:void 0,target:r,type:e,listener:t},n=Mo.bind(i);return n.listener=t,i.wrapFn=n,n}L.prototype.once=function(e,t){return je(t),this.on(e,ii(this,e,t)),this},L.prototype.prependOnceListener=function(e,t){return je(t),this.prependListener(e,ii(this,e,t)),this},L.prototype.removeListener=function(e,t){var i,n,o,a,s;if(je(t),n=this._events,n===void 0)return this;if(i=n[e],i===void 0)return this;if(i===t||i.listener===t)--this._eventsCount===0?this._events=Object.create(null):(delete n[e],n.removeListener&&this.emit("removeListener",e,i.listener||t));else if(typeof i!="function"){for(o=-1,a=i.length-1;a>=0;a--)if(i[a]===t||i[a].listener===t){s=i[a].listener,o=a;break}if(o<0)return this;o===0?i.shift():Uo(i,o),i.length===1&&(n[e]=i[0]),n.removeListener!==void 0&&this.emit("removeListener",e,s||t)}return this},L.prototype.off=L.prototype.removeListener,L.prototype.removeAllListeners=function(e){var t,i,n;if(i=this._events,i===void 0)return this;if(i.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):i[e]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete i[e]),this;if(arguments.length===0){var o=Object.keys(i),a;for(n=0;n=0;n--)this.removeListener(e,t[n]);return this};function ni(r,e,t){var i=r._events;if(i===void 0)return[];var n=i[e];return n===void 0?[]:typeof n=="function"?t?[n.listener||n]:[n]:t?Bo(n):ai(n,n.length)}L.prototype.listeners=function(e){return ni(this,e,!0)},L.prototype.rawListeners=function(e){return ni(this,e,!1)},L.listenerCount=function(r,e){return typeof r.listenerCount=="function"?r.listenerCount(e):oi.call(r,e)},L.prototype.listenerCount=oi;function oi(r){var e=this._events;if(e!==void 0){var t=e[r];if(typeof t=="function")return 1;if(t!==void 0)return t.length}return 0}L.prototype.eventNames=function(){return this._eventsCount>0?$e(this._events):[]};function ai(r,e){for(var t=new Array(e),i=0;ir.length)&&(e=r.length);for(var t=0,i=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 ta=` 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; } `,ra=ta;function ce(){ce=function(){return e};var r,e={},t=Object.prototype,i=t.hasOwnProperty,n=Object.defineProperty||function(T,E,R){T[E]=R.value},o=typeof Symbol=="function"?Symbol:{},a=o.iterator||"@@iterator",s=o.asyncIterator||"@@asyncIterator",c=o.toStringTag||"@@toStringTag";function l(T,E,R){return Object.defineProperty(T,E,{value:R,enumerable:!0,configurable:!0,writable:!0}),T[E]}try{l({},"")}catch{l=function(E,R,x){return E[R]=x}}function u(T,E,R,x){var A=E&&E.prototype instanceof g?E:g,F=Object.create(A.prototype),N=new H(x||[]);return n(F,"_invoke",{value:D(T,R,N)}),F}function h(T,E,R){try{return{type:"normal",arg:T.call(E,R)}}catch(x){return{type:"throw",arg:x}}}e.wrap=u;var d="suspendedStart",m="suspendedYield",f="executing",p="completed",b={};function g(){}function _(){}function v(){}var y={};l(y,a,function(){return this});var C=Object.getPrototypeOf,S=C&&C(C($([])));S&&S!==t&&i.call(S,a)&&(y=S);var w=v.prototype=g.prototype=Object.create(y);function P(T){["next","throw","return"].forEach(function(E){l(T,E,function(R){return this._invoke(E,R)})})}function k(T,E){function R(A,F,N,G){var M=h(T[A],T,F);if(M.type!=="throw"){var q=M.arg,te=q.value;return te&&typeof te=="object"&&i.call(te,"__await")?E.resolve(te.__await).then(function(re){R("next",re,N,G)},function(re){R("throw",re,N,G)}):E.resolve(te).then(function(re){q.value=re,N(q)},function(re){return R("throw",re,N,G)})}G(M.arg)}var x;n(this,"_invoke",{value:function(A,F){function N(){return new E(function(G,M){R(A,F,G,M)})}return x=x?x.then(N,N):N()}})}function D(T,E,R){var x=d;return function(A,F){if(x===f)throw Error("Generator is already running");if(x===p){if(A==="throw")throw F;return{value:r,done:!0}}for(R.method=A,R.arg=F;;){var N=R.delegate;if(N){var G=U(N,R);if(G){if(G===b)continue;return G}}if(R.method==="next")R.sent=R._sent=R.arg;else if(R.method==="throw"){if(x===d)throw x=p,R.arg;R.dispatchException(R.arg)}else R.method==="return"&&R.abrupt("return",R.arg);x=f;var M=h(T,E,R);if(M.type==="normal"){if(x=R.done?p:m,M.arg===b)continue;return{value:M.arg,done:R.done}}M.type==="throw"&&(x=p,R.method="throw",R.arg=M.arg)}}}function U(T,E){var R=E.method,x=T.iterator[R];if(x===r)return E.delegate=null,R==="throw"&&T.iterator.return&&(E.method="return",E.arg=r,U(T,E),E.method==="throw")||R!=="return"&&(E.method="throw",E.arg=new TypeError("The iterator does not provide a '"+R+"' method")),b;var A=h(x,T.iterator,E.arg);if(A.type==="throw")return E.method="throw",E.arg=A.arg,E.delegate=null,b;var F=A.arg;return F?F.done?(E[T.resultName]=F.value,E.next=T.nextLoc,E.method!=="return"&&(E.method="next",E.arg=r),E.delegate=null,b):F:(E.method="throw",E.arg=new TypeError("iterator result is not an object"),E.delegate=null,b)}function z(T){var E={tryLoc:T[0]};1 in T&&(E.catchLoc=T[1]),2 in T&&(E.finallyLoc=T[2],E.afterLoc=T[3]),this.tryEntries.push(E)}function B(T){var E=T.completion||{};E.type="normal",delete E.arg,T.completion=E}function H(T){this.tryEntries=[{tryLoc:"root"}],T.forEach(z,this),this.reset(!0)}function $(T){if(T||T===""){var E=T[a];if(E)return E.call(T);if(typeof T.next=="function")return T;if(!isNaN(T.length)){var R=-1,x=function A(){for(;++R=0;--x){var A=this.tryEntries[x],F=A.completion;if(A.tryLoc==="root")return R("end");if(A.tryLoc<=this.prev){var N=i.call(A,"catchLoc"),G=i.call(A,"finallyLoc");if(N&&G){if(this.prev=0;--R){var x=this.tryEntries[R];if(x.tryLoc<=this.prev&&i.call(x,"finallyLoc")&&this.prev=0;--E){var R=this.tryEntries[E];if(R.finallyLoc===T)return this.complete(R.completion,R.afterLoc),B(R),b}},catch:function(T){for(var E=this.tryEntries.length-1;E>=0;--E){var R=this.tryEntries[E];if(R.tryLoc===T){var x=R.completion;if(x.type==="throw"){var A=x.arg;B(R)}return A}}throw Error("illegal catch attempt")},delegateYield:function(T,E,R){return this.delegate={iterator:$(T),resultName:E,nextLoc:R},this.method==="next"&&(this.arg=r),b}},e}function mi(r,e,t,i,n,o,a){try{var s=r[o](a),c=s.value}catch(l){return void t(l)}s.done?e(c):Promise.resolve(c).then(i,n)}function St(r){return function(){var e=this,t=arguments;return new Promise(function(i,n){var o=r.apply(e,t);function a(c){mi(o,i,n,a,s,"next",c)}function s(c){mi(o,i,n,a,s,"throw",c)}a(void 0)})}}var xt={size:{mode:"max",value:512},objectFit:"cover",correctCentering:!1,maxTextureSize:4096,debounceTimeout:500,crossOrigin:"anonymous"},ia=1;function Ft(r){var e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},t=e.crossOrigin;return new Promise(function(i,n){var o=new Image;o.addEventListener("load",function(){i(o)},{once:!0}),o.addEventListener("error",function(a){n(a.error)},{once:!0}),t&&o.setAttribute("crossOrigin",t),o.src=r})}function na(r){return Lt.apply(this,arguments)}function Lt(){return Lt=St(ce().mark(function r(e){var t,i,n,o,a,s,c,l,u,h,d,m,f,p=arguments;return ce().wrap(function(g){for(;;)switch(g.prev=g.next){case 0:if(t=p.length>1&&p[1]!==void 0?p[1]:{},i=t.size,n=t.crossOrigin,n!=="use-credentials"){g.next=7;break}return g.next=4,fetch(e,{credentials:"include"});case 4:o=g.sent,g.next=10;break;case 7:return g.next=9,fetch(e);case 9:o=g.sent;case 10:return g.next=12,o.text();case 12:if(a=g.sent,s=new DOMParser().parseFromString(a,"image/svg+xml"),c=s.documentElement,l=c.getAttribute("width"),u=c.getAttribute("height"),!(!l||!u)){g.next=19;break}throw new Error("loadSVGImage: cannot use `size` if target SVG has no definite dimensions.");case 19:return typeof i=="number"&&(c.setAttribute("width",""+i),c.setAttribute("height",""+i)),h=new XMLSerializer().serializeToString(s),d=new Blob([h],{type:"image/svg+xml"}),m=URL.createObjectURL(d),f=Ft(m),f.finally(function(){return URL.revokeObjectURL(m)}),g.abrupt("return",f);case 26:case"end":return g.stop()}},r)})),Lt.apply(this,arguments)}function oa(r){return Nt.apply(this,arguments)}function Nt(){return Nt=St(ce().mark(function r(e){var t,i,n,o,a,s,c=arguments;return ce().wrap(function(u){for(;;)switch(u.prev=u.next){case 0:if(i=c.length>1&&c[1]!==void 0?c[1]:{},n=i.size,o=i.crossOrigin,a=((t=e.split(/[#?]/)[0].split(".").pop())===null||t===void 0?void 0:t.trim().toLowerCase())==="svg",!(a&&n)){u.next=16;break}return u.prev=3,u.next=6,na(e,{size:n,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,Ft(e,{crossOrigin:o});case 13:s=u.sent;case 14:u.next=19;break;case 16:return u.next=18,Ft(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]])})),Nt.apply(this,arguments)}function aa(r,e,t){var i=t.objectFit,n=t.size,o=t.correctCentering,a=i==="contain"?Math.max(r.width,r.height):Math.min(r.width,r.height),s=n.mode==="auto"?a:n.mode==="force"?n.value:Math.min(n.value,a),c=(r.width-a)/2,l=(r.height-a)/2;if(o){var u=e.getCorrectionOffset(r,a);c=u.x,l=u.y}return{sourceX:c,sourceY:l,sourceSize:a,destinationSize:s}}function sa(r,e,t){for(var i=e.canvas,n=i.width,o=i.height,a=[],s=t.x,c=t.y,l=t.rowHeight,u=t.maxRowWidth,h={},d=0,m=r.length;do||s+C>n&&c+C+l>o||(s+C>n&&(u=Math.max(u,s),s=0,c+=l,l=C),a.push({key:p,image:b,sourceX:_,sourceY:v,sourceSize:g,destinationX:s,destinationY:c,destinationSize:y}),h[p]={x:s,y:c,size:y},s+=C,l=Math.max(l,C))}u=Math.max(u,s);for(var S=u,w=c+l,P=0,k=a.length;P0&&arguments[0]!==void 0?arguments[0]:{};return Rt(this,e),t=hi(this,e),I(W(t),"canvas",document.createElement("canvas")),I(W(t),"ctx",t.canvas.getContext("2d",{willReadFrequently:!0})),I(W(t),"corrector",new la),I(W(t),"imageStates",{}),I(W(t),"textures",[t.ctx.getImageData(0,0,1,1)]),I(W(t),"lastTextureCursor",{x:0,y:0,rowHeight:0,maxRowWidth:0}),I(W(t),"atlas",{}),t.options=j(j({},xt),i),t.canvas.width=t.options.maxTextureSize,t.canvas.height=t.options.maxTextureSize,t}return Ct(e,[{key:"scheduleGenerateTexture",value:function(){var i=this;typeof this.frameId!="number"&&(typeof this.options.debounceTimeout=="number"?this.frameId=window.setTimeout(function(){i.generateTextures(),i.frameId=void 0},this.options.debounceTimeout):this.generateTextures())}},{key:"generateTextures",value:function(){var i=ca({atlas:this.atlas,textures:this.textures,cursor:this.lastTextureCursor},this.imageStates,this.ctx),n=i.atlas,o=i.textures,a=i.cursor;this.atlas=n,this.textures=o,this.lastTextureCursor=a,this.emit(e.NEW_TEXTURE_EVENT,{atlas:n,textures:o})}},{key:"registerImage",value:function(){var t=St(ce().mark(function n(o){var a,s;return ce().wrap(function(l){for(;;)switch(l.prev=l.next){case 0:if(!this.imageStates[o]){l.next=2;break}return l.abrupt("return");case 2:return this.imageStates[o]={status:"loading"},l.prev=3,a=this.options.size,l.next=7,oa(o,{size:a.mode==="force"?a.value:void 0,crossOrigin:this.options.crossOrigin||void 0});case 7:s=l.sent,this.imageStates[o]=j({status:"ready",image:s},aa(s,this.corrector,this.options)),this.scheduleGenerateTexture(),l.next=15;break;case 12:l.prev=12,l.t0=l.catch(3),this.imageStates[o]={status:"error"};case 15:case"end":return l.stop()}},n,this,[[3,12]])}));function i(n){return t.apply(this,arguments)}return i}()},{key:"getAtlas",value:function(){return this.atlas}},{key:"getTextures",value:function(){return this.textures}}]),e}(ci.EventEmitter);I(Ve,"NEW_TEXTURE_EVENT","newTexture");var ua=["drawHover","drawLabel","drawingMode","keepWithinCircle","padding","colorAttribute","imageAttribute"],vi=WebGLRenderingContext,pi=vi.UNSIGNED_BYTE,Se=vi.FLOAT,ha=j(j({},xt),{},{drawingMode:"background",keepWithinCircle:!0,drawLabel:void 0,drawHover:void 0,padding:0,colorAttribute:"color",imageAttribute:"image"}),da=["u_sizeRatio","u_correctionRatio","u_cameraAngle","u_percentagePadding","u_matrix","u_colorizeImages","u_keepWithinCircle","u_atlas"];function Pt(r){var e,t=document.createElement("canvas").getContext("webgl"),i=Math.min(t.getParameter(t.MAX_TEXTURE_SIZE),xt.maxTextureSize);t.canvas.remove();var n=j(j(j({},ha),{maxTextureSize:i}),r||{}),o=n.drawHover,a=n.drawLabel,s=n.drawingMode,c=n.keepWithinCircle,l=n.padding,u=n.colorAttribute,h=n.imageAttribute,d=Jo(n,ua),m=new Ve(d);return e=function(f){fi(p,f);function p(b,g,_){var v;return Rt(this,p),v=hi(this,p,[b,g,_]),I(W(v),"drawLabel",a),I(W(v),"drawHover",o),I(W(v),"textureManagerCallback",null),v.textureManagerCallback=function(y){var C=y.atlas,S=y.textures,w=S.length!==v.textures.length;v.atlas=C,v.textureImages=S,w&&v.upgradeShaders(),v.bindTextures(),v.latestRenderParams&&v.render(v.latestRenderParams),v.renderer&&v.renderer.refresh&&v.renderer.refresh()},m.on(Ve.NEW_TEXTURE_EVENT,v.textureManagerCallback),v.atlas=m.getAtlas(),v.textureImages=m.getTextures(),v.textures=v.textureImages.map(function(){return b.createTexture()}),v.bindTextures(),v}return Ct(p,[{key:"getDefinition",value:function(){return{VERTICES:3,VERTEX_SHADER_SOURCE:ra,FRAGMENT_SHADER_SOURCE:ea({texturesCount:m.getTextures().length}),METHOD:WebGLRenderingContext.TRIANGLES,UNIFORMS:da,ATTRIBUTES:[{name:"a_position",size:2,type:Se},{name:"a_size",size:1,type:Se},{name:"a_color",size:4,type:pi,normalized:!0},{name:"a_id",size:4,type:pi,normalized:!0},{name:"a_texture",size:4,type:Se},{name:"a_textureIndex",size:1,type:Se}],CONSTANT_ATTRIBUTES:[{name:"a_angle",size:1,type:Se}],CONSTANT_DATA:[[p.ANGLE_1],[p.ANGLE_2],[p.ANGLE_3]]}}},{key:"upgradeShaders",value:function(){var g=this.getDefinition(),_=this.normalProgram,v=_.program,y=_.buffer,C=_.vertexShader,S=_.fragmentShader,w=_.gl;w.deleteProgram(v),w.deleteBuffer(y),w.deleteShader(C),w.deleteShader(S),this.normalProgram=this.getProgramInfo("normal",w,g.VERTEX_SHADER_SOURCE,g.FRAGMENT_SHADER_SOURCE,null)}},{key:"kill",value:function(){var g,_=(g=this.normalProgram)===null||g===void 0?void 0:g.gl;if(_)for(var v=0;v=this.textures.length){var v=g.createTexture();v&&this.textures.push(v)}g.activeTexture(g.TEXTURE0+_),g.bindTexture(g.TEXTURE_2D,this.textures[_]),g.texImage2D(g.TEXTURE_2D,0,g.RGBA,g.RGBA,g.UNSIGNED_BYTE,this.textureImages[_]),g.generateMipmap(g.TEXTURE_2D)}}},{key:"renderProgram",value:function(g,_){if(!_.isPicking)for(var v=_.gl,y=0;yr.length)&&(e=r.length);for(var t=0,i=Array(e);t v_radius) gl_FragColor = transparent; else { gl_FragColor = v_color; gl_FragColor.a *= bias; } #else // Colors: `).concat(e.map(function(n,o){var a=n.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(n,o){var a=n.value;return" float sliceValue_".concat(o+1," = ").concat("attribute"in a?"v_sliceValue_".concat(o+1):lt(a.value),";")}).join(` `),` // Angles and final color: float total = `).concat(e.map(function(n,o){return"sliceValue_".concat(o+1)}).join(" + "),`; float angle_0 = 0.0; if (total > 0.0) { `).concat(e.map(function(n,o){return" float angle_".concat(o+1," = angle_").concat(o," + sliceValue_").concat(o+1," * ").concat(2*Math.PI," / total;")}).join(` `),` `).concat(e.map(function(n,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 i}function Sa(r){var e=r.slices,t=r.offset,i=` 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(n,o){var a=n.value;return"attribute"in a?["attribute float a_sliceValue_".concat(o+1,";"),"varying float v_sliceValue_".concat(o+1,";")]:[]}).join(` `),` `).concat(e.flatMap(function(n,o){var a=n.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(n,o){var a=n.value;return"attribute"in a?[" v_sliceValue_".concat(o+1," = a_sliceValue_").concat(o+1,";")]:[]}).join(` `),` `).concat(e.flatMap(function(n,o){var a=n.color;return"attribute"in a?[" v_sliceColor_".concat(o+1," = a_sliceColor_").concat(o+1,";")]:[]}).join(` `),` #endif } `);return i}var It="#000000",xa={drawLabel:void 0,drawHover:void 0,defaultColor:It,offset:{value:0}},Ci=WebGLRenderingContext,wi=Ci.UNSIGNED_BYTE,Fe=Ci.FLOAT;function Fa(r){var e,t=Ri(Ri({},xa),r),i=t.slices,n=t.offset,o=t.drawHover,a=t.drawLabel,s=["u_sizeRatio","u_correctionRatio","u_cameraAngle","u_matrix","u_defaultColor"].concat(xe("value"in n?["u_offset"]:[]),xe(i.flatMap(function(c,l){var u=c.color;return"value"in u?["u_sliceColor_".concat(l+1)]:[]})));return e=function(c){Ta(l,c);function l(){var u;va(this,l);for(var h=arguments.length,d=new Array(h),m=0;mr,Si=r=>r*r,xi=r=>r*(2-r),Fi=r=>(r*=2)<1?.5*r*r:-.5*(--r*(r-2)-1),Li=r=>r*r*r,Ni=r=>--r*r*r+1,Pi=r=>(r*=2)<1?.5*r*r*r:.5*((r-=2)*r*r+2),zt={linear:Ai,quadraticIn:Si,quadraticOut:xi,quadraticInOut:Fi,cubicIn:Li,cubicOut:Ni,cubicInOut:Pi},Gt={easing:"quadraticInOut",duration:150};function La(r,e,t,i){const n=Object.assign({},Gt,t),o=typeof n.easing=="function"?n.easing:zt[n.easing],a=Date.now(),s={};for(const u in e){const h=e[u];s[u]={};for(const d in h)s[u][d]=r.getNodeAttribute(u,d)}let c=null;const l=()=>{c=null;let u=(Date.now()-a)/n.duration;if(u>=1){for(const h in e){const d=e[h];for(const m in d)r.setNodeAttribute(h,m,d[m])}typeof i=="function"&&i();return}u=o(u);for(const h in e){const d=e[h],m=s[h];for(const f in d)r.setNodeAttribute(h,f,d[f]*u+m[f]*(1-u))}c=requestAnimationFrame(l)};return l(),()=>{c&&cancelAnimationFrame(c)}}const Ye={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 Na(r,e,t,i){const n=i||new Uint8Array(4);return r.readPixels(e,t,1,1,r.RGBA,r.UNSIGNED_BYTE,n),n}const Di=new Int8Array(4),Xe=new Int32Array(Di.buffer,0,1),Oi=new Float32Array(Di.buffer,0,1),Pa=/^\s*rgba?\s*\(/,Da=/^\s*rgba?\s*\(\s*([0-9]*)\s*,\s*([0-9]*)\s*,\s*([0-9]*)(?:\s*,\s*(.*)?)?\)\s*$/;function ki(r){let e=0,t=0,i=0,n=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),i=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),i=parseInt(r.charAt(5)+r.charAt(6),16)),r.length===9&&(n=parseInt(r.charAt(7)+r.charAt(8),16)/255);else if(Pa.test(r)){const o=r.match(Da);o&&(e=+o[1],t=+o[2],i=+o[3],o[4]&&(n=+o[4]))}return{r:e,g:t,b:i,a:n}}const ye={};for(const r in Ye)ye[r]=Y(Ye[r]),ye[Ye[r]]=ye[r];function Mt(r,e,t,i,n){return Xe[0]=i<<24|t<<16|e<<8|r,n&&(Xe[0]=Xe[0]&4278190079),Oi[0]}function Y(r){if(r=r.toLowerCase(),typeof ye[r]<"u")return ye[r];const e=ki(r),{r:t,g:i,b:n}=e;let{a:o}=e;o=o*255|0;const a=Mt(t,i,n,o,!0);return ye[r]=a,a}function Oa(r,e){Oi[0]=Y(r);let t=Xe[0];e&&(t=t|16777216);const i=t&255,n=t>>8&255,o=t>>16&255,a=t>>24&255;return[i,n,o,a]}const Ut={};function Bt(r){if(typeof Ut[r]<"u")return Ut[r];const e=(r&16711680)>>>16,t=(r&65280)>>>8,i=r&255,o=Mt(e,t,i,255,!0);return Ut[r]=o,o}function Ht(r,e,t,i){return t+(e<<8)+(r<<16)}function $t(r,e,t,i,n,o){const a=Math.floor(t/o*n),s=Math.floor(r.drawingBufferHeight/o-i/o*n),c=new Uint8Array(4);r.bindFramebuffer(r.FRAMEBUFFER,e),r.readPixels(a,s,1,1,r.RGBA,r.UNSIGNED_BYTE,c);const[l,u,h,d]=c;return[l,u,h,d]}function V(){return Float32Array.of(1,0,0,0,1,0,0,0,1)}function Le(r,e,t){return r[0]=e,r[4]=typeof t=="number"?t:e,r}function jt(r,e){const t=Math.sin(e),i=Math.cos(e);return r[0]=i,r[1]=t,r[3]=-t,r[4]=i,r}function Vt(r,e,t){return r[6]=e,r[7]=t,r}function Z(r,e){const t=r[0],i=r[1],n=r[2],o=r[3],a=r[4],s=r[5],c=r[6],l=r[7],u=r[8],h=e[0],d=e[1],m=e[2],f=e[3],p=e[4],b=e[5],g=e[6],_=e[7],v=e[8];return r[0]=h*t+d*o+m*c,r[1]=h*i+d*a+m*l,r[2]=h*n+d*s+m*u,r[3]=f*t+p*o+b*c,r[4]=f*i+p*a+b*l,r[5]=f*n+p*s+b*u,r[6]=g*t+_*o+v*c,r[7]=g*i+_*a+v*l,r[8]=g*n+_*s+v*u,r}function qe(r,e,t=1){const i=r[0],n=r[1],o=r[3],a=r[4],s=r[6],c=r[7],l=e.x,u=e.y;return{x:l*i+u*o+s*t,y:l*n+u*a+c*t}}function Ii(r,e){const t=r.height/r.width,i=e.height/e.width;return t<1&&i>1||t>1&&i<1?1:Math.min(Math.max(i,1/i),Math.max(1/t,t))}function Ee(r,e,t,i,n){const{angle:o,ratio:a,x:s,y:c}=r,{width:l,height:u}=e,h=V(),d=Math.min(l,u)-2*i,m=Ii(e,t);return n?(Z(h,Vt(V(),s,c)),Z(h,Le(V(),a)),Z(h,jt(V(),o)),Z(h,Le(V(),l/d/2/m,u/d/2/m))):(Z(h,Le(V(),2*(d/l)*m,2*(d/u)*m)),Z(h,jt(V(),-o)),Z(h,Le(V(),1/a)),Z(h,Vt(V(),-s,-c))),h}function zi(r,e,t){const{x:i,y:n}=qe(r,{x:Math.cos(e.angle),y:Math.sin(e.angle)},0);return 1/Math.sqrt(Math.pow(i,2)+Math.pow(n,2))/t.width}function Wt(r,e){const t=e.size;if(t===0)return;const i=r.length;r.length+=t;let n=0;e.forEach(o=>{r[i+n]=o,n++})}function Gi(r){return typeof r=="object"&&r!==null&&r.constructor===Object}function Ke(r,...e){r=r||{};for(let t=0,i=e.length;t{const{x:s,y:c}=a;st&&(t=s),cn&&(n=c)}),{x:[e,t],y:[i,n]}}function Bi(r){if(!eo(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 Hi(r,e,t){const i=document.createElement(r);if(e)for(const n in e)i.style[n]=e[n];if(t)for(const n in t)i.setAttribute(n,t[n]);return i}function Yt(){return typeof window.devicePixelRatio<"u"?window.devicePixelRatio:1}function Xt(r,e,t){return t.sort(function(i,n){const o=e(i)||0,a=e(n)||0;return oa?1:0})}function qt(r){const{x:[e,t],y:[i,n]}=r;let o=Math.max(t-e,n-i),a=(t+e)/2,s=(n+i)/2;(o===0||Math.abs(o)===1/0||isNaN(o))&&(o=1),isNaN(a)&&(a=0),isNaN(s)&&(s=0);const c=l=>({x:.5+(l.x-a)/o,y:.5+(l.y-s)/o});return c.applyTo=l=>{l.x=.5+(l.x-a)/o,l.y=.5+(l.y-s)/o},c.inverse=l=>({x:a+o*(l.x-.5),y:s+o*(l.y-.5)}),c.ratio=o,c}const ka=Object.freeze(Object.defineProperty({__proto__:null,ANIMATE_DEFAULTS:Gt,HTML_COLORS:Ye,animateNodes:La,assign:Ke,assignDeep:Mi,colorToArray:Oa,colorToIndex:Ht,createElement:Hi,createNormalizationFunction:qt,cubicIn:Li,cubicInOut:Pi,cubicOut:Ni,easings:zt,extend:Wt,extractPixel:Na,floatColor:Y,getCorrectionRatio:Ii,getMatrixImpact:zi,getPixelColor:$t,getPixelRatio:Yt,graphExtent:Ui,identity:V,indexToColor:Bt,isPlainObject:Gi,linear:Ai,matrixFromCamera:Ee,multiply:Z,multiplyVec2:qe,parseColor:ki,quadraticIn:Si,quadraticInOut:Fi,quadraticOut:xi,rgbaToFloat:Mt,rotate:jt,scale:Le,translate:Vt,validateGraph:Bi,zIndexOrdering:Xt},Symbol.toStringTag,{value:"Module"}));function $i(r){return r.normalized?1:r.size}function Ze(r){let e=0;return r.forEach(t=>e+=$i(t)),e}function ji(r,e,t){const i=r==="VERTEX"?e.VERTEX_SHADER:e.FRAGMENT_SHADER,n=e.createShader(i);if(n===null)throw new Error("loadShader: error while creating the shader");if(e.shaderSource(n,t),e.compileShader(n),!e.getShaderParameter(n,e.COMPILE_STATUS)){const a=e.getShaderInfoLog(n);throw e.deleteShader(n),new Error(`loadShader: error while compiling the shader: ${a} ${t}`)}return n}function Vi(r,e){return ji("VERTEX",r,e)}function Wi(r,e){return ji("FRAGMENT",r,e)}function Yi(r,e){const t=r.createProgram();if(t===null)throw new Error("loadProgram: error while creating the program.");let i,n;for(i=0,n=e.length;i{const p=t.getUniformLocation(u,f);p&&(h[f]=p)});const d={};a.ATTRIBUTES.forEach(f=>{d[f.name]=t.getAttribLocation(u,f.name)});let m;if("CONSTANT_ATTRIBUTES"in a&&(a.CONSTANT_ATTRIBUTES.forEach(f=>{d[f.name]=t.getAttribLocation(u,f.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:h,attributeLocations:d,isPicking:e==="pick",vertexShader:c,fragmentShader:l}}bindProgram(e){let t=0;const{gl:i,buffer:n}=e;this.isInstanced?(i.bindBuffer(i.ARRAY_BUFFER,e.constantBuffer),t=0,this.CONSTANT_ATTRIBUTES.forEach(o=>t+=this.bindAttribute(o,e,t,!1)),i.bufferData(i.ARRAY_BUFFER,this.constantArray,i.STATIC_DRAW),i.bindBuffer(i.ARRAY_BUFFER,e.buffer),t=0,this.ATTRIBUTES.forEach(o=>t+=this.bindAttribute(o,e,t,!0)),i.bufferData(i.ARRAY_BUFFER,this.array,i.DYNAMIC_DRAW)):(i.bindBuffer(i.ARRAY_BUFFER,n),t=0,this.ATTRIBUTES.forEach(o=>t+=this.bindAttribute(o,e,t)),i.bufferData(i.ARRAY_BUFFER,this.array,i.DYNAMIC_DRAW)),i.bindBuffer(i.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,i,n){const o=za[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 c=this.isInstanced?(n?this.ATTRIBUTES_ITEMS_COUNT:Ze(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,c,i),this.isInstanced&&n)if(s instanceof WebGL2RenderingContext)s.vertexAttribDivisor(a,1);else{const l=s.getExtension("ANGLE_instanced_arrays");l&&l.vertexAttribDivisorANGLE(a,1)}}return e.size*o}unbindAttribute(e,t,i){const n=t.attributeLocations[e.name],o=t.gl;if(n!==-1&&(o.disableVertexAttribArray(n),this.isInstanced&&i))if(o instanceof WebGL2RenderingContext)o.vertexAttribDivisor(n,0);else{const a=o.getExtension("ANGLE_instanced_arrays");a&&a.vertexAttribDivisorANGLE(n,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:i,program:n}=t;i.enable(i.BLEND),i.useProgram(n),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:i}){if(t.bindFramebuffer(t.FRAMEBUFFER,i),!this.isInstanced)t.drawArrays(e,0,this.verticesCount);else if(t instanceof WebGL2RenderingContext)t.drawArraysInstanced(e,0,this.VERTICES,this.capacity);else{const n=t.getExtension("ANGLE_instanced_arrays");n&&n.drawArraysInstancedANGLE(e,0,this.VERTICES,this.capacity)}}}class Ga extends Zt{}class Jt extends Qt{kill(){super.kill()}process(e,t,i){let n=t*this.STRIDE;if(i.hidden){for(let o=n+this.STRIDE;nnew s(n,o,a))}reallocate(n){this.programs.forEach(o=>o.reallocate(n))}process(n,o,a){this.programs.forEach(s=>s.process(n,o,a))}render(n){this.programs.forEach(o=>o.render(n))}kill(){this.programs.forEach(n=>n.kill())}}}class Ua extends Zt{}class le extends Qt{constructor(){super(...arguments),this.drawLabel=void 0}kill(){super.kill()}process(e,t,i,n,o){let a=t*this.STRIDE;if(o.hidden||i.hidden||n.hidden){for(let s=a+this.STRIDE;anew a(i,n,o))}reallocate(i){this.programs.forEach(n=>n.reallocate(i))}process(i,n,o,a,s){this.programs.forEach(c=>c.process(i,n,o,a,s))}render(i){this.programs.forEach(n=>n.render(i))}kill(){this.programs.forEach(i=>i.kill())}}}function qi(r,e,t,i,n){const o=n.edgeLabelSize,a=n.edgeLabelFont,s=n.edgeLabelWeight,c=n.edgeLabelColor.attribute?e[n.edgeLabelColor.attribute]||n.edgeLabelColor.color||"#000":n.edgeLabelColor.color;let l=e.label;if(!l)return;r.fillStyle=c,r.font=`${s} ${o}px ${a}`;const u=t.size,h=i.size;let d=t.x,m=t.y,f=i.x,p=i.y,b=(d+f)/2,g=(m+p)/2,_=f-d,v=p-m,y=Math.sqrt(_*_+v*v);if(yy){const w="…";for(l=l+w,C=r.measureText(l).width;C>y&&l.length>1;)l=l.slice(0,-2)+w,C=r.measureText(l).width;if(l.length<4)return}let S;_>0?v>0?S=Math.acos(_/y):S=Math.asin(v/y):v>0?S=Math.acos(_/y)+Math.PI:S=Math.asin(_/y)+Math.PI/2,r.save(),r.translate(b,g),r.rotate(S),r.fillText(l,-C/2,e.size/2+o),r.restore()}function tr(r,e,t){if(!e.label)return;const i=t.labelSize,n=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} ${i}px ${n}`,r.fillText(e.label,e.x+e.size+3,e.y+i/3)}function Ki(r,e,t){const i=t.labelSize,n=t.labelFont,o=t.labelWeight;r.font=`${o} ${i}px ${n}`,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,c=Math.round(s+5),l=Math.round(i+2*a),u=Math.max(e.size,i/2)+a,h=Math.asin(l/2/u),d=Math.sqrt(Math.abs(Math.pow(u,2)-Math.pow(l/2,2)));r.beginPath(),r.moveTo(e.x+d,e.y+l/2),r.lineTo(e.x+u+c,e.y+l/2),r.lineTo(e.x+u+c,e.y-l/2),r.lineTo(e.x+d,e.y-l/2),r.arc(e.x,e.y,u,h,-h),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,tr(r,e,t)}const Ba=` 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 } `,Ha=` 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:Zi,FLOAT:rr}=WebGLRenderingContext,$a=["u_sizeRatio","u_correctionRatio","u_matrix"],ie=class ie extends Jt{getDefinition(){return{VERTICES:3,VERTEX_SHADER_SOURCE:Ha,FRAGMENT_SHADER_SOURCE:Ba,METHOD:WebGLRenderingContext.TRIANGLES,UNIFORMS:$a,ATTRIBUTES:[{name:"a_position",size:2,type:rr},{name:"a_size",size:1,type:rr},{name:"a_color",size:4,type:Zi,normalized:!0},{name:"a_id",size:4,type:Zi,normalized:!0}],CONSTANT_ATTRIBUTES:[{name:"a_angle",size:1,type:rr}],CONSTANT_DATA:[[ie.ANGLE_1],[ie.ANGLE_2],[ie.ANGLE_3]]}}processVisibleItem(e,t,i){const n=this.array,o=Y(i.color);n[t++]=i.x,n[t++]=i.y,n[t++]=i.size,n[t++]=o,n[t++]=e}setUniforms(e,{gl:t,uniformLocations:i}){const{u_sizeRatio:n,u_correctionRatio:o,u_matrix:a}=i;t.uniform1f(o,e.correctionRatio),t.uniform1f(n,e.sizeRatio),t.uniformMatrix3fv(a,!1,e.matrix)}};ie.ANGLE_1=0,ie.ANGLE_2=2*Math.PI/3,ie.ANGLE_3=4*Math.PI/3;let Qe=ie;const ja=` 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 } `,Va=` 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:Qi,FLOAT:Ji}=WebGLRenderingContext,Wa=["u_sizeRatio","u_pixelRatio","u_matrix"];class Ya extends Jt{getDefinition(){return{VERTICES:1,VERTEX_SHADER_SOURCE:Va,FRAGMENT_SHADER_SOURCE:ja,METHOD:WebGLRenderingContext.POINTS,UNIFORMS:Wa,ATTRIBUTES:[{name:"a_position",size:2,type:Ji},{name:"a_size",size:1,type:Ji},{name:"a_color",size:4,type:Qi,normalized:!0},{name:"a_id",size:4,type:Qi,normalized:!0}]}}processVisibleItem(e,t,i){const n=this.array;n[t++]=i.x,n[t++]=i.y,n[t++]=i.size,n[t++]=Y(i.color),n[t++]=e}setUniforms({sizeRatio:e,pixelRatio:t,matrix:i},{gl:n,uniformLocations:o}){const{u_sizeRatio:a,u_pixelRatio:s,u_matrix:c}=o;n.uniform1f(s,t),n.uniform1f(a,e),n.uniformMatrix3fv(c,!1,i)}}const Xa=` precision mediump float; varying vec4 v_color; void main(void) { gl_FragColor = v_color; } `,qa=` 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:en,FLOAT:Je}=WebGLRenderingContext,Ka=["u_matrix","u_sizeRatio","u_correctionRatio","u_minEdgeThickness","u_lengthToThicknessRatio","u_widenessToThicknessRatio"],et={extremity:"target",lengthToThicknessRatio:2.5,widenessToThicknessRatio:2};function Ne(r){const e={...et,...r||{}};return class extends le{getDefinition(){return{VERTICES:3,VERTEX_SHADER_SOURCE:qa,FRAGMENT_SHADER_SOURCE:Xa,METHOD:WebGLRenderingContext.TRIANGLES,UNIFORMS:Ka,ATTRIBUTES:[{name:"a_position",size:2,type:Je},{name:"a_normal",size:2,type:Je},{name:"a_radius",size:1,type:Je},{name:"a_color",size:4,type:en,normalized:!0},{name:"a_id",size:4,type:en,normalized:!0}],CONSTANT_ATTRIBUTES:[{name:"a_barycentric",size:3,type:Je}],CONSTANT_DATA:[[1,0,0],[0,1,0],[0,0,1]]}}processVisibleItem(i,n,o,a,s){e.extremity==="source"&&([o,a]=[a,o]);const c=s.size||1,l=a.size||1,u=o.x,h=o.y,d=a.x,m=a.y,f=Y(s.color),p=d-u,b=m-h;let g=p*p+b*b,_=0,v=0;g&&(g=1/Math.sqrt(g),_=-b*g*c,v=p*g*c);const y=this.array;y[n++]=d,y[n++]=m,y[n++]=-_,y[n++]=-v,y[n++]=l,y[n++]=f,y[n++]=i}setUniforms(i,{gl:n,uniformLocations:o}){const{u_matrix:a,u_sizeRatio:s,u_correctionRatio:c,u_minEdgeThickness:l,u_lengthToThicknessRatio:u,u_widenessToThicknessRatio:h}=o;n.uniformMatrix3fv(a,!1,i.matrix),n.uniform1f(s,i.sizeRatio),n.uniform1f(c,i.correctionRatio),n.uniform1f(l,i.minEdgeThickness),n.uniform1f(u,e.lengthToThicknessRatio),n.uniform1f(h,e.widenessToThicknessRatio)}}}const Za=Ne(),ir=` 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 } `,Qa=` 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:tn,FLOAT:ue}=WebGLRenderingContext,Ja=["u_matrix","u_zoomRatio","u_sizeRatio","u_correctionRatio","u_pixelRatio","u_feather","u_minEdgeThickness","u_lengthToThicknessRatio"],rn={lengthToThicknessRatio:et.lengthToThicknessRatio};function nr(r){const e={...rn,...r||{}};return class extends le{getDefinition(){return{VERTICES:6,VERTEX_SHADER_SOURCE:Qa,FRAGMENT_SHADER_SOURCE:ir,METHOD:WebGLRenderingContext.TRIANGLES,UNIFORMS:Ja,ATTRIBUTES:[{name:"a_positionStart",size:2,type:ue},{name:"a_positionEnd",size:2,type:ue},{name:"a_normal",size:2,type:ue},{name:"a_color",size:4,type:tn,normalized:!0},{name:"a_id",size:4,type:tn,normalized:!0},{name:"a_radius",size:1,type:ue}],CONSTANT_ATTRIBUTES:[{name:"a_positionCoef",size:1,type:ue},{name:"a_normalCoef",size:1,type:ue},{name:"a_radiusCoef",size:1,type:ue}],CONSTANT_DATA:[[0,1,0],[0,-1,0],[1,1,1],[1,1,1],[0,-1,0],[1,-1,-1]]}}processVisibleItem(i,n,o,a,s){const c=s.size||1,l=o.x,u=o.y,h=a.x,d=a.y,m=Y(s.color),f=h-l,p=d-u,b=a.size||1;let g=f*f+p*p,_=0,v=0;g&&(g=1/Math.sqrt(g),_=-p*g*c,v=f*g*c);const y=this.array;y[n++]=l,y[n++]=u,y[n++]=h,y[n++]=d,y[n++]=_,y[n++]=v,y[n++]=m,y[n++]=i,y[n++]=b}setUniforms(i,{gl:n,uniformLocations:o}){const{u_matrix:a,u_zoomRatio:s,u_feather:c,u_pixelRatio:l,u_correctionRatio:u,u_sizeRatio:h,u_minEdgeThickness:d,u_lengthToThicknessRatio:m}=o;n.uniformMatrix3fv(a,!1,i.matrix),n.uniform1f(s,i.zoomRatio),n.uniform1f(h,i.sizeRatio),n.uniform1f(u,i.correctionRatio),n.uniform1f(l,i.pixelRatio),n.uniform1f(c,i.antiAliasingFeather),n.uniform1f(d,i.minEdgeThickness),n.uniform1f(m,e.lengthToThicknessRatio)}}}const es=nr(),ts=` 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:nn,FLOAT:Q}=WebGLRenderingContext,rs=["u_matrix","u_zoomRatio","u_sizeRatio","u_correctionRatio","u_pixelRatio","u_feather","u_minEdgeThickness","u_lengthToThicknessRatio"],on={lengthToThicknessRatio:et.lengthToThicknessRatio};function or(r){const e={...on,...r||{}};return class extends le{getDefinition(){return{VERTICES:6,VERTEX_SHADER_SOURCE:ts,FRAGMENT_SHADER_SOURCE:ir,METHOD:WebGLRenderingContext.TRIANGLES,UNIFORMS:rs,ATTRIBUTES:[{name:"a_positionStart",size:2,type:Q},{name:"a_positionEnd",size:2,type:Q},{name:"a_normal",size:2,type:Q},{name:"a_color",size:4,type:nn,normalized:!0},{name:"a_id",size:4,type:nn,normalized:!0},{name:"a_sourceRadius",size:1,type:Q},{name:"a_targetRadius",size:1,type:Q}],CONSTANT_ATTRIBUTES:[{name:"a_positionCoef",size:1,type:Q},{name:"a_normalCoef",size:1,type:Q},{name:"a_sourceRadiusCoef",size:1,type:Q},{name:"a_targetRadiusCoef",size:1,type:Q}],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(i,n,o,a,s){const c=s.size||1,l=o.x,u=o.y,h=a.x,d=a.y,m=Y(s.color),f=h-l,p=d-u,b=o.size||1,g=a.size||1;let _=f*f+p*p,v=0,y=0;_&&(_=1/Math.sqrt(_),v=-p*_*c,y=f*_*c);const C=this.array;C[n++]=l,C[n++]=u,C[n++]=h,C[n++]=d,C[n++]=v,C[n++]=y,C[n++]=m,C[n++]=i,C[n++]=b,C[n++]=g}setUniforms(i,{gl:n,uniformLocations:o}){const{u_matrix:a,u_zoomRatio:s,u_feather:c,u_pixelRatio:l,u_correctionRatio:u,u_sizeRatio:h,u_minEdgeThickness:d,u_lengthToThicknessRatio:m}=o;n.uniformMatrix3fv(a,!1,i.matrix),n.uniform1f(s,i.zoomRatio),n.uniform1f(h,i.sizeRatio),n.uniform1f(u,i.correctionRatio),n.uniform1f(l,i.pixelRatio),n.uniform1f(c,i.antiAliasingFeather),n.uniform1f(d,i.minEdgeThickness),n.uniform1f(m,e.lengthToThicknessRatio)}}}const is=or();function an(r){return er([nr(r),Ne(r)])}const sn=an();function cn(r){return er([or(r),Ne(r),Ne({...r,extremity:"source"})])}const ns=cn(),os=` precision mediump float; varying vec4 v_color; void main(void) { gl_FragColor = v_color; } `,as=` 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:ln,FLOAT:ss}=WebGLRenderingContext,cs=["u_matrix"];class ls extends le{getDefinition(){return{VERTICES:2,VERTEX_SHADER_SOURCE:as,FRAGMENT_SHADER_SOURCE:os,METHOD:WebGLRenderingContext.LINES,UNIFORMS:cs,ATTRIBUTES:[{name:"a_position",size:2,type:ss},{name:"a_color",size:4,type:ln,normalized:!0},{name:"a_id",size:4,type:ln,normalized:!0}]}}processVisibleItem(e,t,i,n,o){const a=this.array,s=i.x,c=i.y,l=n.x,u=n.y,h=Y(o.color);a[t++]=s,a[t++]=c,a[t++]=h,a[t++]=e,a[t++]=l,a[t++]=u,a[t++]=h,a[t++]=e}setUniforms(e,{gl:t,uniformLocations:i}){const{u_matrix:n}=i;t.uniformMatrix3fv(n,!1,e.matrix)}}const us=` 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:un,FLOAT:Pe}=WebGLRenderingContext,hs=["u_matrix","u_zoomRatio","u_sizeRatio","u_correctionRatio","u_pixelRatio","u_feather","u_minEdgeThickness"];class hn extends le{getDefinition(){return{VERTICES:6,VERTEX_SHADER_SOURCE:us,FRAGMENT_SHADER_SOURCE:ir,METHOD:WebGLRenderingContext.TRIANGLES,UNIFORMS:hs,ATTRIBUTES:[{name:"a_positionStart",size:2,type:Pe},{name:"a_positionEnd",size:2,type:Pe},{name:"a_normal",size:2,type:Pe},{name:"a_color",size:4,type:un,normalized:!0},{name:"a_id",size:4,type:un,normalized:!0}],CONSTANT_ATTRIBUTES:[{name:"a_positionCoef",size:1,type:Pe},{name:"a_normalCoef",size:1,type:Pe}],CONSTANT_DATA:[[0,1],[0,-1],[1,1],[1,1],[0,-1],[1,-1]]}}processVisibleItem(e,t,i,n,o){const a=o.size||1,s=i.x,c=i.y,l=n.x,u=n.y,h=Y(o.color),d=l-s,m=u-c;let f=d*d+m*m,p=0,b=0;f&&(f=1/Math.sqrt(f),p=-m*f*a,b=d*f*a);const g=this.array;g[t++]=s,g[t++]=c,g[t++]=l,g[t++]=u,g[t++]=p,g[t++]=b,g[t++]=h,g[t++]=e}setUniforms(e,{gl:t,uniformLocations:i}){const{u_matrix:n,u_zoomRatio:o,u_feather:a,u_pixelRatio:s,u_correctionRatio:c,u_sizeRatio:l,u_minEdgeThickness:u}=i;t.uniformMatrix3fv(n,!1,e.matrix),t.uniform1f(o,e.zoomRatio),t.uniform1f(l,e.sizeRatio),t.uniform1f(c,e.correctionRatio),t.uniform1f(s,e.pixelRatio),t.uniform1f(a,e.antiAliasingFeather),t.uniform1f(u,e.minEdgeThickness)}}const ds=` precision mediump float; varying vec4 v_color; void main(void) { gl_FragColor = v_color; } `,fs=` 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:dn,FLOAT:De}=WebGLRenderingContext,gs=["u_matrix","u_sizeRatio","u_correctionRatio","u_minEdgeThickness"];class ms extends le{getDefinition(){return{VERTICES:3,VERTEX_SHADER_SOURCE:fs,FRAGMENT_SHADER_SOURCE:ds,METHOD:WebGLRenderingContext.TRIANGLES,UNIFORMS:gs,ATTRIBUTES:[{name:"a_positionStart",size:2,type:De},{name:"a_positionEnd",size:2,type:De},{name:"a_normal",size:2,type:De},{name:"a_color",size:4,type:dn,normalized:!0},{name:"a_id",size:4,type:dn,normalized:!0}],CONSTANT_ATTRIBUTES:[{name:"a_positionCoef",size:1,type:De},{name:"a_normalCoef",size:1,type:De}],CONSTANT_DATA:[[0,1],[0,-1],[1,0]]}}processVisibleItem(e,t,i,n,o){const a=o.size||1,s=i.x,c=i.y,l=n.x,u=n.y,h=Y(o.color),d=l-s,m=u-c;let f=d*d+m*m,p=0,b=0;f&&(f=1/Math.sqrt(f),p=-m*f*a,b=d*f*a);const g=this.array;g[t++]=s,g[t++]=c,g[t++]=l,g[t++]=u,g[t++]=p,g[t++]=b,g[t++]=h,g[t++]=e}setUniforms(e,{gl:t,uniformLocations:i}){const{u_matrix:n,u_sizeRatio:o,u_correctionRatio:a,u_minEdgeThickness:s}=i;t.uniformMatrix3fv(n,!1,e.matrix),t.uniform1f(o,e.sizeRatio),t.uniform1f(a,e.correctionRatio),t.uniform1f(s,e.minEdgeThickness)}}const vs=Object.freeze(Object.defineProperty({__proto__:null,AbstractEdgeProgram:Ua,AbstractNodeProgram:Ga,AbstractProgram:Zt,DEFAULT_EDGE_ARROW_HEAD_PROGRAM_OPTIONS:et,DEFAULT_EDGE_CLAMPED_PROGRAM_OPTIONS:rn,DEFAULT_EDGE_DOUBLE_CLAMPED_PROGRAM_OPTIONS:on,EdgeArrowHeadProgram:Za,EdgeArrowProgram:sn,EdgeClampedProgram:es,EdgeDoubleArrowProgram:ns,EdgeDoubleClampedProgram:is,EdgeLineProgram:ls,EdgeProgram:le,EdgeRectangleProgram:hn,EdgeTriangleProgram:ms,NodeCircleProgram:Qe,NodePointProgram:Ya,NodeProgram:Jt,Program:Qt,createEdgeArrowHeadProgram:Ne,createEdgeArrowProgram:an,createEdgeClampedProgram:nr,createEdgeCompoundProgram:er,createEdgeDoubleArrowProgram:cn,createEdgeDoubleClampedProgram:or,createNodeCompoundProgram:Ma,drawDiscNodeHover:Ki,drawDiscNodeLabel:tr,drawStraightEdgeLabel:qi,getAttributeItemsCount:$i,getAttributesItemsCount:Ze,killProgram:Kt,loadFragmentShader:Wi,loadProgram:Yi,loadVertexShader:Vi,numberToGLSLFloat:Ia},Symbol.toStringTag,{value:"Module"}));class ar extends ci.EventEmitter{constructor(){super(),this.rawEmitter=this}}const tt=1.5;class Te extends ar{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 Te().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={},i){if(!i)return new Promise(u=>this.animate(e,t,u));if(!this.enabled)return;const n={...Gt,...t},o=this.validateState(e),a=typeof n.easing=="function"?n.easing:zt[n.easing],s=Date.now(),c=this.getState(),l=()=>{const u=(Date.now()-s)/n.duration;if(u>=1){this.nextFrame=null,this.setState(o),this.animationCallback&&(this.animationCallback.call(null),this.animationCallback=void 0);return}const h=a(u),d={};typeof o.x=="number"&&(d.x=c.x+(o.x-c.x)*h),typeof o.y=="number"&&(d.y=c.y+(o.y-c.y)*h),this.enabledRotation&&typeof o.angle=="number"&&(d.angle=c.angle+(o.angle-c.angle)*h),typeof o.ratio=="number"&&(d.ratio=c.ratio+(o.ratio-c.ratio)*h),this.setState(d),this.nextFrame=requestAnimationFrame(l)};this.nextFrame?(cancelAnimationFrame(this.nextFrame),this.animationCallback&&this.animationCallback.call(null),this.nextFrame=requestAnimationFrame(l)):l(),this.animationCallback=i}animatedZoom(e){return e?typeof e=="number"?this.animate({ratio:this.ratio/e}):this.animate({ratio:this.ratio/(e.factor||tt)},e):this.animate({ratio:this.ratio/tt})}animatedUnzoom(e){return e?typeof e=="number"?this.animate({ratio:this.ratio*e}):this.animate({ratio:this.ratio*(e.factor||tt)},e):this.animate({ratio:this.ratio*tt})}animatedReset(e){return this.animate({x:.5,y:.5,ratio:1,angle:0},e)}copy(){return Te.from(this.getState())}}const sr={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:qi,defaultDrawNodeLabel:tr,defaultDrawNodeHover:Ki,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:{}},ps={circle:Qe},_s={arrow:sn,line:hn};function cr(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 ys(r,e){return{...J(r,e),delta:fn(r)}}const Es=2;function rt(r){const e=[];for(let t=0,i=Math.min(r.length,Es);tX(n,t)),previousTouches:e.map(n=>X(n,t)),sigmaDefaultPrevented:!1,preventSigmaDefault(){i.sigmaDefaultPrevented=!0},original:r};return i}function fn(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 gn extends ar{constructor(e,t){super(),this.container=e,this.renderer=t}}const Ts=["doubleClickTimeout","doubleClickZoomingDuration","doubleClickZoomingRatio","dragTimeout","draggedEventsTolerance","inertiaDuration","inertiaRatio","zoomDuration","zoomingRatio"].reduce((r,e)=>({...r,[e]:sr[e]}),{});class mn extends gn{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=Ts,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.refresh()},0),this.emit("mouseup",J(e,this.container))}handleMove(e){if(!this.enabled)return;const t=J(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 i=this.renderer.getCamera(),{x:n,y:o}=X(e,this.container),a=this.renderer.viewportToFramedGraph({x:this.lastMouseX,y:this.lastMouseY}),s=this.renderer.viewportToFramedGraph({x:n,y:o}),c=a.x-s.x,l=a.y-s.y,u=i.getState(),h=u.x+c,d=u.y+l;i.setState({x:h,y:d}),this.lastMouseX=n,this.lastMouseY=o,e.preventDefault(),e.stopPropagation()}}handleLeave(e){this.emit("mouseleave",J(e,this.container))}handleEnter(e){this.emit("mouseenter",J(e,this.container))}handleWheel(e){const t=this.renderer.getCamera();if(!this.enabled||!t.enabledZooming)return;const i=fn(e);if(!i)return;const n=ys(e,this.container);if(this.emit("wheel",n),n.sigmaDefaultPrevented){e.preventDefault(),e.stopPropagation();return}const o=t.getState().ratio,a=i>0?1/this.settings.zoomingRatio:this.settings.zoomingRatio,s=t.getBoundedRatio(o*a),c=i>0?1:-1,l=Date.now();o!==s&&(e.preventDefault(),e.stopPropagation(),!(this.currentWheelDirection===c&&this.lastWheelTriggerTime&&l-this.lastWheelTriggerTime{this.currentWheelDirection=0}),this.currentWheelDirection=c,this.lastWheelTriggerTime=l))}setSettings(e){this.settings=e}}const Rs=["dragTimeout","inertiaDuration","inertiaRatio","doubleClickTimeout","doubleClickZoomingRatio","doubleClickZoomingDuration","tapMoveTolerance"].reduce((r,e)=>({...r,[e]:sr[e]}),{});class Cs extends gn{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=Rs,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=rt(e.touches);if(this.touchMode=t.length,this.startCameraState=this.renderer.getCamera().getState(),this.startTouchesPositions=t.map(i=>X(i,this.container)),this.touchMode===2){const[{x:i,y:n},{x:o,y:a}]=this.startTouchesPositions;this.startTouchesAngle=Math.atan2(a-n,o-i),this.startTouchesDistance=Math.sqrt(Math.pow(o-i,2)+Math.pow(a-n,2))}this.emit("touchdown",ke(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(),i=t.getState(),n=t.getPreviousState()||{x:0,y:0};t.animate({x:i.x+this.settings.inertiaRatio*(i.x-n.x),y:i.y+this.settings.inertiaRatio*(i.y-n.y)},{duration:this.settings.inertiaDuration,easing:"quadraticOut"})}this.hasMoved=!1,this.isMoving=!1,this.touchMode=0;break}if(this.emit("touchup",ke(e,this.lastTouches,this.container)),!e.touches.length){const t=X(this.lastTouches[0],this.container),i=this.startTouchesPositions[0],n=(t.x-i.x)**2+(t.y-i.y)**2;if(!e.touches.length&&nX(l,this.container)),n=this.lastTouches;this.lastTouches=t,this.lastTouchesPositions=i;const o=ke(e,n,this.container);if(this.emit("touchmove",o),o.sigmaDefaultPrevented||(this.hasMoved||(this.hasMoved=i.some((l,u)=>{const h=this.startTouchesPositions[u];return h&&(l.x!==h.x||l.y!==h.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,c=this.renderer.getSetting("stagePadding");switch(this.touchMode){case 1:{const{x:l,y:u}=this.renderer.viewportToFramedGraph((this.startTouchesPositions||[])[0]),{x:h,y:d}=this.renderer.viewportToFramedGraph(i[0]);a.setState({x:s.x+l-h,y:s.y+u-d});break}case 2:{const l={x:.5,y:.5,angle:0,ratio:1},{x:u,y:h}=i[0],{x:d,y:m}=i[1],f=Math.atan2(m-h,d-u)-this.startTouchesAngle,p=Math.hypot(m-h,d-u)/this.startTouchesDistance,b=a.getBoundedRatio(s.ratio/p);l.ratio=b,l.angle=s.angle+f;const g=this.getDimensions(),_=this.renderer.viewportToFramedGraph((this.startTouchesPositions||[])[0],{cameraState:s}),v=Math.min(g.width,g.height)-2*c,y=v/g.width,C=v/g.height,S=b/v;let w=u-v/2/y,P=h-v/2/C;[w,P]=[w*Math.cos(-l.angle)-P*Math.sin(-l.angle),P*Math.cos(-l.angle)+w*Math.sin(-l.angle)],l.x=_.x-w*S,l.y=_.y+P*S,a.setState(l);break}}}setSettings(e){this.settings=e}}class vn{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 pn{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,i){const n=new vn(e,t),o=this.getIndex(i);let a=this.cells[o];a||(a=[],this.cells[o]=a),a.push(n)}organize(){for(const e in this.cells)this.cells[e].sort(vn.compare)}getLabelsToDisplay(e,t){const i=this.cellSize*this.cellSize,o=i/e/e*t/i,a=Math.ceil(o),s=[];for(const c in this.cells){const l=this.cells[c];for(let u=0;u{(c===t||l===t||i.has(c)||i.has(l)||n.has(c)&&n.has(l))&&o.push(a)}),o}const _n=150,bn=50,ee=Object.prototype.hasOwnProperty;function As(r,e,t){if(!ee.call(t,"x")||!ee.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),ee.call(t,"hidden")||(t.hidden=!1),ee.call(t,"highlighted")||(t.highlighted=!1),ee.call(t,"forceLabel")||(t.forceLabel=!1),(!t.type||t.type==="")&&(t.type=r.defaultNodeType),t.zIndex||(t.zIndex=0),t}function Ss(r,e,t){return t.color||(t.color=r.defaultEdgeColor),t.label||(t.label=""),t.size||(t.size=.5),ee.call(t,"hidden")||(t.hidden=!1),ee.call(t,"forceLabel")||(t.forceLabel=!1),(!t.type||t.type==="")&&(t.type=r.defaultEdgeType),t.zIndex||(t.zIndex=0),t}let yn=class extends ar{constructor(e,t,i={}){if(super(),this.elements={},this.canvasContexts={},this.webGLContexts={},this.pickingLayers=new Set,this.textures={},this.frameBuffers={},this.activeListeners={},this.labelGrid=new pn,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=V(),this.invMatrix=V(),this.correctionRatio=1,this.customBBox=null,this.normalizationFunction=qt({x:[0,1],y:[0,1]}),this.graphToViewportRatio=1,this.itemIDsIndex={},this.nodeIndices={},this.edgeIndices={},this.width=0,this.height=0,this.pixelRatio=Yt(),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=bs(i),cr(this.settings),Bi(e),!(t instanceof HTMLElement))throw new Error("Sigma: container should be an html element.");this.graph=e,this.container=t,this.createWebGLContext("edges",{picking:i.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 n in this.settings.nodeProgramClasses)this.registerNodeProgram(n,this.settings.nodeProgramClasses[n],this.settings.nodeHoverProgramClasses[n]);for(const n in this.settings.edgeProgramClasses)this.registerEdgeProgram(n,this.settings.edgeProgramClasses[n]);this.camera=new Te,this.bindCameraHandlers(),this.mouseCaptor=new mn(this.elements.mouse,this),this.mouseCaptor.setSettings(this.settings),this.touchCaptor=new Cs(this.elements.mouse,this),this.touchCaptor.setSettings(this.settings),this.bindEventHandlers(),this.bindGraphHandlers(),this.handleSettingsUpdate(),this.refresh()}registerNodeProgram(e,t,i){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(i||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,...i}=this.nodePrograms;t.kill(),this.nodePrograms=i}if(this.nodeHoverPrograms[e]){const{[e]:t,...i}=this.nodeHoverPrograms;t.kill(),this.nodePrograms=i}return this}unregisterEdgeProgram(e){if(this.edgePrograms[e]){const{[e]:t,...i}=this.edgePrograms;t.kill(),this.edgePrograms=i}return this}resetWebGLTexture(e){const t=this.webGLContexts[e],i=this.frameBuffers[e],n=this.textures[e];n&&t.deleteTexture(n);const o=t.createTexture();return t.bindFramebuffer(t.FRAMEBUFFER,i),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:i}=e,n=$t(this.webGLContexts.nodes,this.frameBuffers.nodes,t,i,this.pixelRatio,this.pickingDownSizingRatio),o=Ht(...n),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 i=Oe(t),n={event:i,preventSigmaDefault(){i.preventSigmaDefault()}},o=this.getNodeAtPosition(i);if(o&&this.hoveredNode!==o&&!this.nodeDataCache[o].hidden){this.hoveredNode&&this.emit("leaveNode",{...n,node:this.hoveredNode}),this.hoveredNode=o,this.emit("enterNode",{...n,node:o}),this.scheduleHighlightedNodesRender();return}if(this.hoveredNode&&this.getNodeAtPosition(i)!==this.hoveredNode){const a=this.hoveredNode;this.hoveredNode=null,this.emit("leaveNode",{...n,node:a}),this.scheduleHighlightedNodesRender();return}if(this.settings.enableEdgeEvents){const a=this.hoveredNode?null:this.getEdgeAtPoint(n.event.x,n.event.y);a!==this.hoveredEdge&&(this.hoveredEdge&&this.emit("leaveEdge",{...n,edge:this.hoveredEdge}),a&&this.emit("enterEdge",{...n,edge:a}),this.hoveredEdge=a)}},this.activeListeners.handleMoveBody=t=>{const i=Oe(t);this.emit("moveBody",{event:i,preventSigmaDefault(){i.preventSigmaDefault()}})},this.activeListeners.handleLeave=t=>{const i=Oe(t),n={event:i,preventSigmaDefault(){i.preventSigmaDefault()}};this.hoveredNode&&(this.emit("leaveNode",{...n,node:this.hoveredNode}),this.scheduleHighlightedNodesRender()),this.settings.enableEdgeEvents&&this.hoveredEdge&&(this.emit("leaveEdge",{...n,edge:this.hoveredEdge}),this.scheduleHighlightedNodesRender()),this.emit("leaveStage",{...n})},this.activeListeners.handleEnter=t=>{const i=Oe(t),n={event:i,preventSigmaDefault(){i.preventSigmaDefault()}};this.emit("enterStage",{...n})};const e=t=>i=>{const n=Oe(i),o={event:n,preventSigmaDefault:()=>{n.preventSigmaDefault()}},a=this.getNodeAtPosition(n);if(a)return this.emit(`${t}Node`,{...o,node:a});if(this.settings.enableEdgeEvents){const s=this.getEdgeAtPoint(n.x,n.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=i=>{var a;const n=(a=i.hints)==null?void 0:a.attributes;this.graph.forEachNode(s=>this.updateNode(s));const o=!n||n.some(s=>t.has(s));this.refresh({partialGraph:{nodes:e.nodes()},skipIndexation:!o,schedule:!0})},this.activeListeners.eachEdgeAttributesUpdatedGraphUpdate=i=>{var a;const n=(a=i.hints)==null?void 0:a.attributes;this.graph.forEachEdge(s=>this.updateEdge(s));const o=n&&["zIndex","type"].some(s=>n==null?void 0:n.includes(s));this.refresh({partialGraph:{edges:e.edges()},skipIndexation:!o,schedule:!0})},this.activeListeners.addNodeGraphUpdate=i=>{const n=i.key;this.addNode(n),this.refresh({partialGraph:{nodes:[n]},skipIndexation:!1,schedule:!0})},this.activeListeners.updateNodeGraphUpdate=i=>{const n=i.key;this.refresh({partialGraph:{nodes:[n]},skipIndexation:!1,schedule:!0})},this.activeListeners.dropNodeGraphUpdate=i=>{const n=i.key;this.removeNode(n),this.refresh({schedule:!0})},this.activeListeners.addEdgeGraphUpdate=i=>{const n=i.key;this.addEdge(n),this.refresh({partialGraph:{edges:[n]},schedule:!0})},this.activeListeners.updateEdgeGraphUpdate=i=>{const n=i.key;this.refresh({partialGraph:{edges:[n]},skipIndexation:!1,schedule:!0})},this.activeListeners.dropEdgeGraphUpdate=i=>{const n=i.key;this.removeEdge(n),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 i=$t(this.webGLContexts.edges,this.frameBuffers.edges,e,t,this.pixelRatio,this.pickingDownSizingRatio),n=Ht(...i),o=this.itemIDsIndex[n];return o&&o.type==="edge"?o.id:null}process(){this.emit("beforeProcess");const e=this.graph,t=this.settings,i=this.getDimensions();if(this.nodeExtent=Ui(this.graph),!this.settings.autoRescale){const{width:f,height:p}=i,{x:b,y:g}=this.nodeExtent;this.nodeExtent={x:[(b[0]+b[1])/2-f/2,(b[0]+b[1])/2+f/2],y:[(g[0]+g[1])/2-p/2,(g[0]+g[1])/2+p/2]}}this.normalizationFunction=qt(this.customBBox||this.nodeExtent);const n=new Te,o=Ee(n.getState(),i,this.getGraphDimensions(),this.getStagePadding());this.labelGrid.resizeAndClear(i,t.labelGridCellSize);const a={},s={},c={},l={};let u=1,h=e.nodes();for(let f=0,p=h.length;fthis.nodeDataCache[f].zIndex,h));for(let f=0,p=h.length;fthis.edgeDataCache[f].zIndex,m));for(const f in this.edgePrograms){if(!ee.call(this.edgePrograms,f))throw new Error(`Sigma: could not find a suitable program for edge type "${f}"!`);this.edgePrograms[f].reallocate(d[f]||0),d[f]=0}for(let f=0,p=m.length;fthis.cleanCameraState(i,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 i in t.edgeProgramClasses)t.edgeProgramClasses[i]!==e.edgeProgramClasses[i]&&this.registerEdgeProgram(i,t.edgeProgramClasses[i]);for(const i in e.edgeProgramClasses)t.edgeProgramClasses[i]||this.unregisterEdgeProgram(i)}if(e.nodeProgramClasses!==t.nodeProgramClasses||e.nodeHoverProgramClasses!==t.nodeHoverProgramClasses){for(const i in t.nodeProgramClasses)(t.nodeProgramClasses[i]!==e.nodeProgramClasses[i]||t.nodeHoverProgramClasses[i]!==e.nodeHoverProgramClasses[i])&&this.registerNodeProgram(i,t.nodeProgramClasses[i],t.nodeHoverProgramClasses[i]);for(const i in e.nodeProgramClasses)t.nodeProgramClasses[i]||this.unregisterNodeProgram(i)}}return this.mouseCaptor.setSettings(this.settings),this.touchCaptor.setSettings(this.settings),this}cleanCameraState(e,{tolerance:t=0,boundaries:i}={}){const n={...e},{x:[o,a],y:[s,c]}=i||this.nodeExtent,l=[this.graphToViewport({x:o,y:s},{cameraState:e}),this.graphToViewport({x:a,y:s},{cameraState:e}),this.graphToViewport({x:o,y:c},{cameraState:e}),this.graphToViewport({x:a,y:c},{cameraState:e})];let u=1/0,h=-1/0,d=1/0,m=-1/0;l.forEach(({x:y,y:C})=>{u=Math.min(u,y),h=Math.max(h,y),d=Math.min(d,C),m=Math.max(m,C)});const f=h-u,p=m-d,{width:b,height:g}=this.getDimensions();let _=0,v=0;if(f>=b?ht&&(_=u-t):h>b+t?_=h-(b+t):u<-t&&(_=u+t),p>=g?mt&&(v=d-t):m>g+t?v=m-(g+t):d<-t&&(v=d+t),_||v){const y=this.viewportToFramedGraph({x:0,y:0},{cameraState:e}),C=this.viewportToFramedGraph({x:_,y:v},{cameraState:e});_=C.x-y.x,v=C.y-y.y,n.x+=_,n.y+=v}return n}renderLabels(){if(!this.settings.renderLabels)return this;const e=this.camera.getState(),t=this.labelGrid.getLabelsToDisplay(e.ratio,this.settings.labelDensity);Wt(t,this.nodesWithForcedLabels),this.displayedNodeLabels=new Set;const i=this.canvasContexts.labels;for(let n=0,o=t.length;nthis.width+_n||l<-bn||l>this.height+bn)continue;this.displayedNodeLabels.add(a);const{defaultDrawNodeLabel:h}=this.settings,d=this.nodePrograms[s.type];((d==null?void 0:d.drawLabel)||h)(i,{key:a,...s,size:u,x:c,y:l},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=ws({graph:this.graph,hoveredNode:this.hoveredNode,displayedNodeLabels:this.displayedNodeLabels,highlightedNodes:this.highlightedNodes});Wt(t,this.edgesWithForcedLabels);const i=new Set;for(let n=0,o=t.length;n{const s=this.nodeDataCache[a],{x:c,y:l}=this.framedGraphToViewport(s),u=this.scaleSize(s.size),{defaultDrawNodeHover:h}=this.settings,d=this.nodePrograms[s.type];((d==null?void 0:d.drawHover)||h)(e,{key:a,...s,size:u,x:c,y:l},this.settings)},i=[];this.hoveredNode&&!this.nodeDataCache[this.hoveredNode].hidden&&i.push(this.hoveredNode),this.highlightedNodes.forEach(a=>{a!==this.hoveredNode&&i.push(a)}),i.forEach(a=>t(a));const n={};i.forEach(a=>{const s=this.nodeDataCache[a].type;n[s]=(n[s]||0)+1});for(const a in this.nodeHoverPrograms)this.nodeHoverPrograms[a].reallocate(n[a]||0),n[a]=0;i.forEach(a=>{const s=this.nodeDataCache[a];this.nodeHoverPrograms[s.type].process(0,n[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(l=>this.resetWebGLTexture(l)),!this.graph.order)return e();const t=this.mouseCaptor,i=this.camera.isAnimated()||t.isMoving||t.draggedEvents||t.currentWheelDirection,n=this.camera.getState(),o=this.getDimensions(),a=this.getGraphDimensions(),s=this.getStagePadding();this.matrix=Ee(n,o,a,s),this.invMatrix=Ee(n,o,a,s,!0),this.correctionRatio=zi(this.matrix,n,o),this.graphToViewportRatio=this.getGraphToViewportRatio();const c=this.getRenderParams();for(const l in this.nodePrograms)this.nodePrograms[l].render(c);if(!this.settings.hideEdgesOnMove||!i)for(const l in this.edgePrograms)this.edgePrograms[l].render(c);return this.settings.hideLabelsOnMove&&i||(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 i=As(this.settings,e,t);this.nodeDataCache[e]=i,this.nodesWithForcedLabels.delete(e),i.forceLabel&&!i.hidden&&this.nodesWithForcedLabels.add(e),this.highlightedNodes.delete(e),i.highlighted&&!i.hidden&&this.highlightedNodes.add(e),this.settings.zIndex&&(i.zIndexthis.nodeZExtent[1]&&(this.nodeZExtent[1]=i.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 i=Ss(this.settings,e,t);this.edgeDataCache[e]=i,this.edgesWithForcedLabels.delete(e),i.forceLabel&&!i.hidden&&this.edgesWithForcedLabels.add(e),this.settings.zIndex&&(i.zIndexthis.edgeZExtent[1]&&(this.edgeZExtent[1]=i.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 pn,this.nodeExtent={x:[0,1],y:[0,1]},this.nodeDataCache={},this.edgeProgramIndex={},this.nodesWithForcedLabels=new Set,this.nodeZExtent=[1/0,-1/0]}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,i){const n=this.nodeDataCache[e],o=this.nodePrograms[n.type];if(!o)throw new Error(`Sigma: could not find a suitable program for node type "${n.type}"!`);o.process(t,i,n),this.nodeProgramIndex[e]=i}addEdgeToProgram(e,t,i){const n=this.edgeDataCache[e],o=this.edgePrograms[n.type];if(!o)throw new Error(`Sigma: could not find a suitable program for edge type "${n.type}"!`);const a=this.graph.extremities(e),s=this.nodeDataCache[a[0]],c=this.nodeDataCache[a[1]];o.process(t,i,s,c,n),this.edgeProgramIndex[e]=i}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,i={}){if(this.elements[e])throw new Error(`Sigma: a layer named "${e}" already exists`);const n=Hi(t,{position:"absolute"},{class:`sigma-${e}`});return i.style&&Object.assign(n.style,i.style),this.elements[e]=n,"beforeLayer"in i&&i.beforeLayer?this.elements[i.beforeLayer].before(n):"afterLayer"in i&&i.afterLayer?this.elements[i.afterLayer].after(n):this.container.appendChild(n),n}createCanvas(e,t={}){return this.createLayer(e,"canvas",t)}createCanvasContext(e,t={}){const i=this.createCanvas(e,t),n={preserveDrawingBuffer:!1,antialias:!1};return this.canvasContexts[e]=i.getContext("2d",n),this}createWebGLContext(e,t={}){const i=(t==null?void 0:t.canvas)||this.createCanvas(e,t);t.hidden&&i.remove();const n={preserveDrawingBuffer:!1,antialias:!1,...t};let o;o=i.getContext("webgl2",n),o||(o=i.getContext("webgl",n)),o||(o=i.getContext("experimental-webgl",n));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 i;const t=this.elements[e];if(!t)throw new Error(`Sigma: cannot kill layer ${e}, which does not exist`);return this.webGLContexts[e]?((i=this.webGLContexts[e].getExtension("WEBGL_lose_context"))==null||i.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 i={...this.settings};return this.settings[e]=t,cr(this.settings),this.handleSettingsUpdate(i),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},cr(this.settings),this.handleSettingsUpdate(t),this.scheduleRefresh(),this}resize(e){const t=this.width,i=this.height;if(this.width=this.container.offsetWidth,this.height=this.container.offsetHeight,this.pixelRatio=Yt(),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&&i===this.height)return this;for(const n in this.elements){const o=this.elements[n];o.style.width=this.width+"px",o.style.height=this.height+"px"}for(const n in this.canvasContexts)this.elements[n].setAttribute("width",this.width*this.pixelRatio+"px"),this.elements[n].setAttribute("height",this.height*this.pixelRatio+"px"),this.pixelRatio!==1&&this.canvasContexts[n].scale(this.pixelRatio,this.pixelRatio);for(const n in this.webGLContexts){this.elements[n].setAttribute("width",this.width*this.pixelRatio+"px"),this.elements[n].setAttribute("height",this.height*this.pixelRatio+"px");const o=this.webGLContexts[n];if(o.viewport(0,0,this.width*this.pixelRatio,this.height*this.pixelRatio),this.pickingLayers.has(n)){const a=this.textures[n];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,i=(e==null?void 0:e.schedule)!==void 0?e.schedule:!1,n=!e||!e.partialGraph;if(n)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 l=0,u=(s==null?void 0:s.length)||0;l{this.render()})),this}scheduleRefresh(e){return this.refresh({...e,schedule:!0})}getViewportZoomedState(e,t){const{ratio:i,angle:n,x:o,y:a}=this.camera.getState(),{minCameraRatio:s,maxCameraRatio:c}=this.settings;typeof c=="number"&&(t=Math.min(t,c)),typeof s=="number"&&(t=Math.max(t,s));const l=t/i,u={x:this.width/2,y:this.height/2},h=this.viewportToFramedGraph(e),d=this.viewportToFramedGraph(u);return{angle:n,x:(h.x-d.x)*(1-l)+o,y:(h.y-d.y)*(1-l)+a,ratio:t}}viewRectangle(){const e=this.viewportToFramedGraph({x:0,y:0}),t=this.viewportToFramedGraph({x:this.width,y:0}),i=this.viewportToFramedGraph({x:0,y:this.height});return{x1:e.x,y1:e.y,x2:t.x,y2:t.y,height:t.y-i.y}}framedGraphToViewport(e,t={}){const i=!!t.cameraState||!!t.viewportDimensions||!!t.graphDimensions,n=t.matrix?t.matrix:i?Ee(t.cameraState||this.camera.getState(),t.viewportDimensions||this.getDimensions(),t.graphDimensions||this.getGraphDimensions(),t.padding||this.getStagePadding()):this.matrix,o=qe(n,e);return{x:(1+o.x)*this.width/2,y:(1-o.y)*this.height/2}}viewportToFramedGraph(e,t={}){const i=!!t.cameraState||!!t.viewportDimensions||!t.graphDimensions,n=t.matrix?t.matrix:i?Ee(t.cameraState||this.camera.getState(),t.viewportDimensions||this.getDimensions(),t.graphDimensions||this.getGraphDimensions(),t.padding||this.getStagePadding(),!0):this.invMatrix,o=qe(n,{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},i=Math.sqrt(Math.pow(e.x-t.x,2)+Math.pow(e.y-t.y,2)),n=this.graphToViewport(e),o=this.graphToViewport(t);return Math.sqrt(Math.pow(n.x-o.x,2)+Math.pow(n.y-o.y,2))/i}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);this.canvasContexts={},this.webGLContexts={},this.elements={};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)}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 he=class he extends yn{};he.Camera=Te,he.MouseCaptor=mn,he.Sigma=yn,he.rendering={...vs,createNodeBorderProgram:Zr,createNodeImageProgram:Pt,createNodePiechartProgram:Fa,EdgeCurveProgram:_o},he.utils=ka;let lr=he;return lr});