sigma
Version:
A JavaScript library aimed at visualizing graphs of thousands of nodes and edges.
543 lines (453 loc) • 187 kB
JavaScript
(function(Ee,ue){typeof exports=="object"&&typeof module<"u"?module.exports=ue():typeof define=="function"&&define.amd?define(ue):(Ee=typeof globalThis<"u"?globalThis:Ee||self,Ee.Sigma=ue())})(this,function(){"use strict";function Ee(r,e){if(typeof r!="object"||!r)return r;var t=r[Symbol.toPrimitive];if(t!==void 0){var n=t.call(r,e);if(typeof n!="object")return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return(e==="string"?String:Number)(r)}function ue(r){var e=Ee(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 oi(r,e){for(var t=0;t<e.length;t++){var n=e[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(r,ue(n.key),n)}}function ie(r,e,t){return e&&oi(r.prototype,e),Object.defineProperty(r,"prototype",{writable:!1}),r}function he(r){return he=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},he(r)}function lr(){try{var r=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch{}return(lr=function(){return!!r})()}function ai(r){if(r===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return r}function si(r,e){if(e&&(typeof e=="object"||typeof e=="function"))return e;if(e!==void 0)throw new TypeError("Derived constructors may only return object or undefined");return ai(r)}function Te(r,e,t){return e=he(e),si(r,lr()?Reflect.construct(e,t||[],he(r).constructor):e.apply(r,t))}function tt(r,e){return tt=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,n){return t.__proto__=n,t},tt(r,e)}function Re(r,e){if(typeof e!="function"&&e!==null)throw new TypeError("Super expression must either be null or a function");r.prototype=Object.create(e&&e.prototype,{constructor:{value:r,writable:!0,configurable:!0}}),Object.defineProperty(r,"prototype",{writable:!1}),e&&tt(r,e)}var rt={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"},ur=new Int8Array(4),Oe=new Int32Array(ur.buffer,0,1),hr=new Float32Array(ur.buffer,0,1),ci=/^\s*rgba?\s*\(/,li=/^\s*rgba?\s*\(\s*([0-9]*)\s*,\s*([0-9]*)\s*,\s*([0-9]*)(?:\s*,\s*(.*)?)?\)\s*$/;function ui(r){var e=0,t=0,n=0,i=1;if(r[0]==="#")r.length===4?(e=parseInt(r.charAt(1)+r.charAt(1),16),t=parseInt(r.charAt(2)+r.charAt(2),16),n=parseInt(r.charAt(3)+r.charAt(3),16)):(e=parseInt(r.charAt(1)+r.charAt(2),16),t=parseInt(r.charAt(3)+r.charAt(4),16),n=parseInt(r.charAt(5)+r.charAt(6),16)),r.length===9&&(i=parseInt(r.charAt(7)+r.charAt(8),16)/255);else if(ci.test(r)){var o=r.match(li);o&&(e=+o[1],t=+o[2],n=+o[3],o[4]&&(i=+o[4]))}return{r:e,g:t,b:n,a:i}}var de={};for(var De in rt)de[De]=X(rt[De]),de[rt[De]]=de[De];function dr(r,e,t,n,i){return Oe[0]=n<<24|t<<16|e<<8|r,Oe[0]=Oe[0]&4278190079,hr[0]}function X(r){if(r=r.toLowerCase(),typeof de[r]<"u")return de[r];var e=ui(r),t=e.r,n=e.g,i=e.b,o=e.a;o=o*255|0;var a=dr(t,n,i,o);return de[r]=a,a}function nt(r,e){hr[0]=X(r);var t=Oe[0],n=t&255,i=t>>8&255,o=t>>16&255,a=t>>24&255;return[n,i,o,a]}var it={};function fr(r){if(typeof it[r]<"u")return it[r];var e=(r&16711680)>>>16,t=(r&65280)>>>8,n=r&255,i=255,o=dr(e,t,n,i);return it[r]=o,o}function I(r,e,t){return(e=ue(e))in r?Object.defineProperty(r,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):r[e]=t,r}function gr(r,e){var t=Object.keys(r);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(r);e&&(n=n.filter(function(i){return Object.getOwnPropertyDescriptor(r,i).enumerable})),t.push.apply(t,n)}return t}function fe(r){for(var e=1;e<arguments.length;e++){var t=arguments[e]!=null?arguments[e]:{};e%2?gr(Object(t),!0).forEach(function(n){I(r,n,t[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(t)):gr(Object(t)).forEach(function(n){Object.defineProperty(r,n,Object.getOwnPropertyDescriptor(t,n))})}return r}function hi(r,e){for(;!{}.hasOwnProperty.call(r,e)&&(r=he(r))!==null;);return r}function ot(){return ot=typeof Reflect<"u"&&Reflect.get?Reflect.get.bind():function(r,e,t){var n=hi(r,e);if(n){var i=Object.getOwnPropertyDescriptor(n,e);return i.get?i.get.call(arguments.length<3?r:t):i.value}},ot.apply(null,arguments)}function mr(r,e,t,n){var i=ot(he(r.prototype),e,t);return typeof i=="function"?function(o){return i.apply(t,o)}:i}function di(r){return r.normalized?1:r.size}function at(r){var e=0;return r.forEach(function(t){return e+=di(t)}),e}function vr(r,e,t){var n=r==="VERTEX"?e.VERTEX_SHADER:e.FRAGMENT_SHADER,i=e.createShader(n);if(i===null)throw new Error("loadShader: error while creating the shader");e.shaderSource(i,t),e.compileShader(i);var o=e.getShaderParameter(i,e.COMPILE_STATUS);if(!o){var a=e.getShaderInfoLog(i);throw e.deleteShader(i),new Error(`loadShader: error while compiling the shader:
`.concat(a,`
`).concat(t))}return i}function fi(r,e){return vr("VERTEX",r,e)}function gi(r,e){return vr("FRAGMENT",r,e)}function mi(r,e){var t=r.createProgram();if(t===null)throw new Error("loadProgram: error while creating the program.");var n,i;for(n=0,i=e.length;n<i;n++)r.attachShader(t,e[n]);r.linkProgram(t);var o=r.getProgramParameter(t,r.LINK_STATUS);if(!o)throw r.deleteProgram(t),new Error("loadProgram: error while linking the program.");return t}function pr(r){var e=r.gl,t=r.buffer,n=r.program,i=r.vertexShader,o=r.fragmentShader;e.deleteShader(i),e.deleteShader(o),e.deleteProgram(n),e.deleteBuffer(t)}function st(r){return r%1===0?r.toFixed(1):r.toString()}var _r=`#define PICKING_MODE
`,vi=I(I(I(I(I(I(I(I({},WebGL2RenderingContext.BOOL,1),WebGL2RenderingContext.BYTE,1),WebGL2RenderingContext.UNSIGNED_BYTE,1),WebGL2RenderingContext.SHORT,2),WebGL2RenderingContext.UNSIGNED_SHORT,2),WebGL2RenderingContext.INT,4),WebGL2RenderingContext.UNSIGNED_INT,4),WebGL2RenderingContext.FLOAT,4),br=function(){function r(e,t,n){ne(this,r),I(this,"array",new Float32Array),I(this,"constantArray",new Float32Array),I(this,"capacity",0),I(this,"verticesCount",0);var i=this.getDefinition();if(this.VERTICES=i.VERTICES,this.VERTEX_SHADER_SOURCE=i.VERTEX_SHADER_SOURCE,this.FRAGMENT_SHADER_SOURCE=i.FRAGMENT_SHADER_SOURCE,this.UNIFORMS=i.UNIFORMS,this.ATTRIBUTES=i.ATTRIBUTES,this.METHOD=i.METHOD,this.CONSTANT_ATTRIBUTES="CONSTANT_ATTRIBUTES"in i?i.CONSTANT_ATTRIBUTES:[],this.CONSTANT_DATA="CONSTANT_DATA"in i?i.CONSTANT_DATA:[],this.isInstanced="CONSTANT_ATTRIBUTES"in i,this.ATTRIBUTES_ITEMS_COUNT=at(this.ATTRIBUTES),this.STRIDE=this.VERTICES*this.ATTRIBUTES_ITEMS_COUNT,this.renderer=n,this.normalProgram=this.getProgramInfo("normal",e,i.VERTEX_SHADER_SOURCE,i.FRAGMENT_SHADER_SOURCE,null),this.pickProgram=t?this.getProgramInfo("pick",e,_r+i.VERTEX_SHADER_SOURCE,_r+i.FRAGMENT_SHADER_SOURCE,t):null,this.isInstanced){var o=at(this.CONSTANT_ATTRIBUTES);if(this.CONSTANT_DATA.length!==this.VERTICES)throw new Error("Program: error while getting constant data (expected ".concat(this.VERTICES," items, received ").concat(this.CONSTANT_DATA.length," instead)"));this.constantArray=new Float32Array(this.CONSTANT_DATA.length*o);for(var a=0;a<this.CONSTANT_DATA.length;a++){var s=this.CONSTANT_DATA[a];if(s.length!==o)throw new Error("Program: error while getting constant data (one vector has ".concat(s.length," items instead of ").concat(o,")"));for(var l=0;l<s.length;l++)this.constantArray[a*o+l]=s[l]}this.STRIDE=this.ATTRIBUTES_ITEMS_COUNT}}return ie(r,[{key:"kill",value:function(){pr(this.normalProgram),this.pickProgram&&(pr(this.pickProgram),this.pickProgram=null)}},{key:"getProgramInfo",value:function(t,n,i,o,a){var s=this.getDefinition(),l=n.createBuffer();if(l===null)throw new Error("Program: error while creating the WebGL buffer.");var c=fi(n,i),u=gi(n,o),d=mi(n,[c,u]),h={};s.UNIFORMS.forEach(function(b){var E=n.getUniformLocation(d,b);E&&(h[b]=E)});var m={};s.ATTRIBUTES.forEach(function(b){m[b.name]=n.getAttribLocation(d,b.name)});var g;if("CONSTANT_ATTRIBUTES"in s&&(s.CONSTANT_ATTRIBUTES.forEach(function(b){m[b.name]=n.getAttribLocation(d,b.name)}),g=n.createBuffer(),g===null))throw new Error("Program: error while creating the WebGL constant buffer.");return{name:t,program:d,gl:n,frameBuffer:a,buffer:l,constantBuffer:g||{},uniformLocations:h,attributeLocations:m,isPicking:t==="pick",vertexShader:c,fragmentShader:u}}},{key:"bindProgram",value:function(t){var n=this,i=0,o=t.gl,a=t.buffer;this.isInstanced?(o.bindBuffer(o.ARRAY_BUFFER,t.constantBuffer),i=0,this.CONSTANT_ATTRIBUTES.forEach(function(s){return i+=n.bindAttribute(s,t,i,!1)}),o.bufferData(o.ARRAY_BUFFER,this.constantArray,o.STATIC_DRAW),o.bindBuffer(o.ARRAY_BUFFER,t.buffer),i=0,this.ATTRIBUTES.forEach(function(s){return i+=n.bindAttribute(s,t,i,!0)}),o.bufferData(o.ARRAY_BUFFER,this.array,o.DYNAMIC_DRAW)):(o.bindBuffer(o.ARRAY_BUFFER,a),i=0,this.ATTRIBUTES.forEach(function(s){return i+=n.bindAttribute(s,t,i)}),o.bufferData(o.ARRAY_BUFFER,this.array,o.DYNAMIC_DRAW)),o.bindBuffer(o.ARRAY_BUFFER,null)}},{key:"unbindProgram",value:function(t){var n=this;this.isInstanced?(this.CONSTANT_ATTRIBUTES.forEach(function(i){return n.unbindAttribute(i,t,!1)}),this.ATTRIBUTES.forEach(function(i){return n.unbindAttribute(i,t,!0)})):this.ATTRIBUTES.forEach(function(i){return n.unbindAttribute(i,t)})}},{key:"bindAttribute",value:function(t,n,i,o){var a=vi[t.type];if(typeof a!="number")throw new Error('Program.bind: yet unsupported attribute type "'.concat(t.type,'"'));var s=n.attributeLocations[t.name],l=n.gl;if(s!==-1){l.enableVertexAttribArray(s);var c=this.isInstanced?(o?this.ATTRIBUTES_ITEMS_COUNT:at(this.CONSTANT_ATTRIBUTES))*Float32Array.BYTES_PER_ELEMENT:this.ATTRIBUTES_ITEMS_COUNT*Float32Array.BYTES_PER_ELEMENT;if(l.vertexAttribPointer(s,t.size,t.type,t.normalized||!1,c,i),this.isInstanced&&o)if(l instanceof WebGL2RenderingContext)l.vertexAttribDivisor(s,1);else{var u=l.getExtension("ANGLE_instanced_arrays");u&&u.vertexAttribDivisorANGLE(s,1)}}return t.size*a}},{key:"unbindAttribute",value:function(t,n,i){var o=n.attributeLocations[t.name],a=n.gl;if(o!==-1&&(a.disableVertexAttribArray(o),this.isInstanced&&i))if(a instanceof WebGL2RenderingContext)a.vertexAttribDivisor(o,0);else{var s=a.getExtension("ANGLE_instanced_arrays");s&&s.vertexAttribDivisorANGLE(o,0)}}},{key:"reallocate",value:function(t){t!==this.capacity&&(this.capacity=t,this.verticesCount=this.VERTICES*t,this.array=new Float32Array(this.isInstanced?this.capacity*this.ATTRIBUTES_ITEMS_COUNT:this.verticesCount*this.ATTRIBUTES_ITEMS_COUNT))}},{key:"hasNothingToRender",value:function(){return this.verticesCount===0}},{key:"renderProgram",value:function(t,n){var i=n.gl,o=n.program;i.enable(i.BLEND),i.useProgram(o),this.setUniforms(t,n),this.drawWebGL(this.METHOD,n)}},{key:"render",value:function(t){this.hasNothingToRender()||(this.pickProgram&&(this.pickProgram.gl.viewport(0,0,t.width*t.pixelRatio/t.downSizingRatio,t.height*t.pixelRatio/t.downSizingRatio),this.bindProgram(this.pickProgram),this.renderProgram(fe(fe({},t),{},{pixelRatio:t.pixelRatio/t.downSizingRatio}),this.pickProgram),this.unbindProgram(this.pickProgram)),this.normalProgram.gl.viewport(0,0,t.width*t.pixelRatio,t.height*t.pixelRatio),this.bindProgram(this.normalProgram),this.renderProgram(t,this.normalProgram),this.unbindProgram(this.normalProgram))}},{key:"drawWebGL",value:function(t,n){var i=n.gl,o=n.frameBuffer;if(i.bindFramebuffer(i.FRAMEBUFFER,o),!this.isInstanced)i.drawArrays(t,0,this.verticesCount);else if(i instanceof WebGL2RenderingContext)i.drawArraysInstanced(t,0,this.VERTICES,this.capacity);else{var a=i.getExtension("ANGLE_instanced_arrays");a&&a.drawArraysInstancedANGLE(t,0,this.VERTICES,this.capacity)}}}])}(),ke=function(r){function e(){return ne(this,e),Te(this,e,arguments)}return Re(e,r),ie(e,[{key:"kill",value:function(){mr(e,"kill",this)([])}},{key:"process",value:function(n,i,o){var a=i*this.STRIDE;if(o.hidden){for(var s=a+this.STRIDE;a<s;a++)this.array[a]=0;return}return this.processVisibleItem(fr(n),a,o)}}])}(br),ct=function(r){function e(){var t;ne(this,e);for(var n=arguments.length,i=new Array(n),o=0;o<n;o++)i[o]=arguments[o];return t=Te(this,e,[].concat(i)),I(t,"drawLabel",void 0),t}return Re(e,r),ie(e,[{key:"kill",value:function(){mr(e,"kill",this)([])}},{key:"process",value:function(n,i,o,a,s){var l=i*this.STRIDE;if(s.hidden||o.hidden||a.hidden){for(var c=l+this.STRIDE;l<c;l++)this.array[l]=0;return}return this.processVisibleItem(fr(n),l,o,a,s)}}])}(br);function pi(r,e){return function(){function t(n,i,o){ne(this,t),I(this,"drawLabel",e),this.programs=r.map(function(a){return new a(n,i,o)})}return ie(t,[{key:"reallocate",value:function(i){this.programs.forEach(function(o){return o.reallocate(i)})}},{key:"process",value:function(i,o,a,s,l){this.programs.forEach(function(c){return c.process(i,o,a,s,l)})}},{key:"render",value:function(i){this.programs.forEach(function(o){return o.render(i)})}},{key:"kill",value:function(){this.programs.forEach(function(i){return i.kill()})}}])}()}var _i=`
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
}
`,bi=_i,yi=`
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;
}
`,Ei=yi,yr=WebGLRenderingContext,Er=yr.UNSIGNED_BYTE,lt=yr.FLOAT,Ti=["u_sizeRatio","u_correctionRatio","u_matrix"],ut=function(r){function e(){return ne(this,e),Te(this,e,arguments)}return Re(e,r),ie(e,[{key:"getDefinition",value:function(){return{VERTICES:3,VERTEX_SHADER_SOURCE:Ei,FRAGMENT_SHADER_SOURCE:bi,METHOD:WebGLRenderingContext.TRIANGLES,UNIFORMS:Ti,ATTRIBUTES:[{name:"a_position",size:2,type:lt},{name:"a_size",size:1,type:lt},{name:"a_color",size:4,type:Er,normalized:!0},{name:"a_id",size:4,type:Er,normalized:!0}],CONSTANT_ATTRIBUTES:[{name:"a_angle",size:1,type:lt}],CONSTANT_DATA:[[e.ANGLE_1],[e.ANGLE_2],[e.ANGLE_3]]}}},{key:"processVisibleItem",value:function(n,i,o){var a=this.array,s=X(o.color);a[i++]=o.x,a[i++]=o.y,a[i++]=o.size,a[i++]=s,a[i++]=n}},{key:"setUniforms",value:function(n,i){var o=i.gl,a=i.uniformLocations,s=a.u_sizeRatio,l=a.u_correctionRatio,c=a.u_matrix;o.uniform1f(l,n.correctionRatio),o.uniform1f(s,n.sizeRatio),o.uniformMatrix3fv(c,!1,n.matrix)}}])}(ke);I(ut,"ANGLE_1",0),I(ut,"ANGLE_2",2*Math.PI/3),I(ut,"ANGLE_3",4*Math.PI/3);var Ri=`
precision mediump float;
varying vec4 v_color;
void main(void) {
gl_FragColor = v_color;
}
`,Ci=Ri,wi=`
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;
}
`,Ai=wi,Tr=WebGLRenderingContext,Rr=Tr.UNSIGNED_BYTE,Ie=Tr.FLOAT,Si=["u_matrix","u_sizeRatio","u_correctionRatio","u_minEdgeThickness","u_lengthToThicknessRatio","u_widenessToThicknessRatio"],ze={extremity:"target",lengthToThicknessRatio:2.5,widenessToThicknessRatio:2};function Cr(r){var e=fe(fe({},ze),{});return function(t){function n(){return ne(this,n),Te(this,n,arguments)}return Re(n,t),ie(n,[{key:"getDefinition",value:function(){return{VERTICES:3,VERTEX_SHADER_SOURCE:Ai,FRAGMENT_SHADER_SOURCE:Ci,METHOD:WebGLRenderingContext.TRIANGLES,UNIFORMS:Si,ATTRIBUTES:[{name:"a_position",size:2,type:Ie},{name:"a_normal",size:2,type:Ie},{name:"a_radius",size:1,type:Ie},{name:"a_color",size:4,type:Rr,normalized:!0},{name:"a_id",size:4,type:Rr,normalized:!0}],CONSTANT_ATTRIBUTES:[{name:"a_barycentric",size:3,type:Ie}],CONSTANT_DATA:[[1,0,0],[0,1,0],[0,0,1]]}}},{key:"processVisibleItem",value:function(o,a,s,l,c){if(e.extremity==="source"){var u=[l,s];s=u[0],l=u[1]}var d=c.size||1,h=l.size||1,m=s.x,g=s.y,b=l.x,E=l.y,v=X(c.color),T=b-m,_=E-g,f=T*T+_*_,p=0,y=0;f&&(f=1/Math.sqrt(f),p=-_*f*d,y=T*f*d);var R=this.array;R[a++]=b,R[a++]=E,R[a++]=-p,R[a++]=-y,R[a++]=h,R[a++]=v,R[a++]=o}},{key:"setUniforms",value:function(o,a){var s=a.gl,l=a.uniformLocations,c=l.u_matrix,u=l.u_sizeRatio,d=l.u_correctionRatio,h=l.u_minEdgeThickness,m=l.u_lengthToThicknessRatio,g=l.u_widenessToThicknessRatio;s.uniformMatrix3fv(c,!1,o.matrix),s.uniform1f(u,o.sizeRatio),s.uniform1f(d,o.correctionRatio),s.uniform1f(h,o.minEdgeThickness),s.uniform1f(m,e.lengthToThicknessRatio),s.uniform1f(g,e.widenessToThicknessRatio)}}])}(ct)}Cr();var xi=`
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
}
`,Li=xi,Fi=`
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;
}
`,Ni=Fi,wr=WebGLRenderingContext,Ar=wr.UNSIGNED_BYTE,oe=wr.FLOAT,Pi=["u_matrix","u_zoomRatio","u_sizeRatio","u_correctionRatio","u_pixelRatio","u_feather","u_minEdgeThickness","u_lengthToThicknessRatio"],Oi={lengthToThicknessRatio:ze.lengthToThicknessRatio};function Sr(r){var e=fe(fe({},Oi),{});return function(t){function n(){return ne(this,n),Te(this,n,arguments)}return Re(n,t),ie(n,[{key:"getDefinition",value:function(){return{VERTICES:6,VERTEX_SHADER_SOURCE:Ni,FRAGMENT_SHADER_SOURCE:Li,METHOD:WebGLRenderingContext.TRIANGLES,UNIFORMS:Pi,ATTRIBUTES:[{name:"a_positionStart",size:2,type:oe},{name:"a_positionEnd",size:2,type:oe},{name:"a_normal",size:2,type:oe},{name:"a_color",size:4,type:Ar,normalized:!0},{name:"a_id",size:4,type:Ar,normalized:!0},{name:"a_radius",size:1,type:oe}],CONSTANT_ATTRIBUTES:[{name:"a_positionCoef",size:1,type:oe},{name:"a_normalCoef",size:1,type:oe},{name:"a_radiusCoef",size:1,type:oe}],CONSTANT_DATA:[[0,1,0],[0,-1,0],[1,1,1],[1,1,1],[0,-1,0],[1,-1,-1]]}}},{key:"processVisibleItem",value:function(o,a,s,l,c){var u=c.size||1,d=s.x,h=s.y,m=l.x,g=l.y,b=X(c.color),E=m-d,v=g-h,T=l.size||1,_=E*E+v*v,f=0,p=0;_&&(_=1/Math.sqrt(_),f=-v*_*u,p=E*_*u);var y=this.array;y[a++]=d,y[a++]=h,y[a++]=m,y[a++]=g,y[a++]=f,y[a++]=p,y[a++]=b,y[a++]=o,y[a++]=T}},{key:"setUniforms",value:function(o,a){var s=a.gl,l=a.uniformLocations,c=l.u_matrix,u=l.u_zoomRatio,d=l.u_feather,h=l.u_pixelRatio,m=l.u_correctionRatio,g=l.u_sizeRatio,b=l.u_minEdgeThickness,E=l.u_lengthToThicknessRatio;s.uniformMatrix3fv(c,!1,o.matrix),s.uniform1f(u,o.zoomRatio),s.uniform1f(g,o.sizeRatio),s.uniform1f(m,o.correctionRatio),s.uniform1f(h,o.pixelRatio),s.uniform1f(d,o.antiAliasingFeather),s.uniform1f(b,o.minEdgeThickness),s.uniform1f(E,e.lengthToThicknessRatio)}}])}(ct)}Sr();function Di(r){return pi([Sr(),Cr()])}Di();function ki(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}var ht,xr;function Ii(){return xr||(xr=1,ht=function(e){return e!==null&&typeof e=="object"&&typeof e.addUndirectedEdgeWithKey=="function"&&typeof e.dropNode=="function"&&typeof e.multi=="boolean"}),ht}var zi=Ii();const Gi=ki(zi);function Mi(r,e){if(typeof r!="object"||!r)return r;var t=r[Symbol.toPrimitive];if(t!==void 0){var n=t.call(r,e);if(typeof n!="object")return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return(e==="string"?String:Number)(r)}function Lr(r){var e=Mi(r,"string");return typeof e=="symbol"?e:e+""}function Fr(r,e,t){return(e=Lr(e))in r?Object.defineProperty(r,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):r[e]=t,r}function Nr(r,e){var t=Object.keys(r);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(r);e&&(n=n.filter(function(i){return Object.getOwnPropertyDescriptor(r,i).enumerable})),t.push.apply(t,n)}return t}function Ge(r){for(var e=1;e<arguments.length;e++){var t=arguments[e]!=null?arguments[e]:{};e%2?Nr(Object(t),!0).forEach(function(n){Fr(r,n,t[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(t)):Nr(Object(t)).forEach(function(n){Object.defineProperty(r,n,Object.getOwnPropertyDescriptor(t,n))})}return r}function Ui(r,e){if(!(r instanceof e))throw new TypeError("Cannot call a class as a function")}function Bi(r,e){for(var t=0;t<e.length;t++){var n=e[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(r,Lr(n.key),n)}}function Hi(r,e,t){return e&&Bi(r.prototype,e),Object.defineProperty(r,"prototype",{writable:!1}),r}function Me(r){return Me=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},Me(r)}function Pr(){try{var r=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch{}return(Pr=function(){return!!r})()}function $i(r){if(r===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return r}function ji(r,e){if(e&&(typeof e=="object"||typeof e=="function"))return e;if(e!==void 0)throw new TypeError("Derived constructors may only return object or undefined");return $i(r)}function Vi(r,e,t){return e=Me(e),ji(r,Pr()?Reflect.construct(e,t||[],Me(r).constructor):e.apply(r,t))}function dt(r,e){return dt=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,n){return t.__proto__=n,t},dt(r,e)}function Wi(r,e){if(typeof e!="function"&&e!==null)throw new TypeError("Super expression must either be null or a function");r.prototype=Object.create(e&&e.prototype,{constructor:{value:r,writable:!0,configurable:!0}}),Object.defineProperty(r,"prototype",{writable:!1}),e&&dt(r,e)}function ft(r,e){(e==null||e>r.length)&&(e=r.length);for(var t=0,n=Array(e);t<e;t++)n[t]=r[t];return n}function Yi(r){if(Array.isArray(r))return ft(r)}function Xi(r){if(typeof Symbol<"u"&&r[Symbol.iterator]!=null||r["@@iterator"]!=null)return Array.from(r)}function qi(r,e){if(r){if(typeof r=="string")return ft(r,e);var t={}.toString.call(r).slice(8,-1);return t==="Object"&&r.constructor&&(t=r.constructor.name),t==="Map"||t==="Set"?Array.from(r):t==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?ft(r,e):void 0}}function Ki(){throw new TypeError(`Invalid attempt to spread non-iterable instance.
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function gt(r){return Yi(r)||Xi(r)||qi(r)||Ki()}function Or(r,e,t,n){var i=Math.pow(1-r,2)*e.x+2*(1-r)*r*t.x+Math.pow(r,2)*n.x,o=Math.pow(1-r,2)*e.y+2*(1-r)*r*t.y+Math.pow(r,2)*n.y;return{x:i,y:o}}function Zi(r,e,t){for(var n=20,i=0,o=r,a=0;a<n;a++){var s=Or((a+1)/n,r,e,t);i+=Math.sqrt(Math.pow(o.x-s.x,2)+Math.pow(o.y-s.y,2)),o=s}return i}function Qi(r){var e=r.curvatureAttribute,t=r.defaultCurvature,n=r.keepLabelUpright,i=n===void 0?!0:n;return function(o,a,s,l,c){var u=c.edgeLabelSize,d=a[e]||t,h=c.edgeLabelFont,m=c.edgeLabelWeight,g=c.edgeLabelColor.attribute?a[c.edgeLabelColor.attribute]||c.edgeLabelColor.color||"#000":c.edgeLabelColor.color,b=a.label;if(b){o.fillStyle=g,o.font="".concat(m," ").concat(u,"px ").concat(h);var E=!i||s.x<l.x,v=E?s.x:l.x,T=E?s.y:l.y,_=E?l.x:s.x,f=E?l.y:s.y,p=(v+_)/2,y=(T+f)/2,R=_-v,S=f-T,F=Math.sqrt(Math.pow(R,2)+Math.pow(S,2)),x=E?1:-1,O=p+S*d*x,k=y-R*d*x,z=a.size*.7+5,M={x:k-T,y:-(O-v)},H=Math.sqrt(Math.pow(M.x,2)+Math.pow(M.y,2)),w={x:f-k,y:-(_-O)},C=Math.sqrt(Math.pow(w.x,2)+Math.pow(w.y,2));v+=z*M.x/H,T+=z*M.y/H,_+=z*w.x/C,f+=z*w.y/C,O+=z*S/F,k-=z*R/F;var A={x:O,y:k},N={x:v,y:T},L={x:_,y:f},P=Zi(N,A,L);if(!(P<s.size+l.size)){var D=o.measureText(b).width,U=P-s.size-l.size;if(D>U){var B="…";for(b=b+B,D=o.measureText(b).width;D>U&&b.length>1;)b=b.slice(0,-2)+B,D=o.measureText(b).width;if(b.length<4)return}for(var Y={},J=0,ee=b.length;J<ee;J++){var sr=b[J];Y[sr]||(Y[sr]=o.measureText(sr).width*(1+d*.35))}for(var ye=.5-D/P/2,cr=0,fs=b.length;cr<fs;cr++){var ni=b[cr],ii=Or(ye,N,A,L),gs=2*(1-ye)*(O-v)+2*ye*(_-O),ms=2*(1-ye)*(k-T)+2*ye*(f-k),vs=Math.atan2(ms,gs);o.save(),o.translate(ii.x,ii.y),o.rotate(vs),o.fillText(ni,0,0),o.restore(),ye+=Y[ni]/P}}}}}function Ji(r){var e=r.arrowHead,t=(e==null?void 0:e.extremity)==="target"||(e==null?void 0:e.extremity)==="both",n=(e==null?void 0:e.extremity)==="source"||(e==null?void 0:e.extremity)==="both",i=`
precision highp float;
varying vec4 v_color;
varying float v_thickness;
varying float v_feather;
varying vec2 v_cpA;
varying vec2 v_cpB;
varying vec2 v_cpC;
`.concat(t?`
varying float v_targetSize;
varying vec2 v_targetPoint;`:"",`
`).concat(n?`
varying float v_sourceSize;
varying vec2 v_sourcePoint;`:"",`
`).concat(e?`
uniform float u_lengthToThicknessRatio;
uniform float u_widenessToThicknessRatio;`:"",`
float det(vec2 a, vec2 b) {
return a.x * b.y - b.x * a.y;
}
vec2 getDistanceVector(vec2 b0, vec2 b1, vec2 b2) {
float a = det(b0, b2), b = 2.0 * det(b1, b0), d = 2.0 * det(b2, b1);
float f = b * d - a * a;
vec2 d21 = b2 - b1, d10 = b1 - b0, d20 = b2 - b0;
vec2 gf = 2.0 * (b * d21 + d * d10 + a * d20);
gf = vec2(gf.y, -gf.x);
vec2 pp = -f * gf / dot(gf, gf);
vec2 d0p = b0 - pp;
float ap = det(d0p, d20), bp = 2.0 * det(d10, d0p);
float t = clamp((ap + bp) / (2.0 * a + b + d), 0.0, 1.0);
return mix(mix(b0, b1, t), mix(b1, b2, t), t);
}
float distToQuadraticBezierCurve(vec2 p, vec2 b0, vec2 b1, vec2 b2) {
return length(getDistanceVector(b0 - p, b1 - p, b2 - p));
}
const vec4 transparent = vec4(0.0, 0.0, 0.0, 0.0);
void main(void) {
float dist = distToQuadraticBezierCurve(gl_FragCoord.xy, v_cpA, v_cpB, v_cpC);
float thickness = v_thickness;
`).concat(t?`
float distToTarget = length(gl_FragCoord.xy - v_targetPoint);
float targetArrowLength = v_targetSize + thickness * u_lengthToThicknessRatio;
if (distToTarget < targetArrowLength) {
thickness = (distToTarget - v_targetSize) / (targetArrowLength - v_targetSize) * u_widenessToThicknessRatio * thickness;
}`:"",`
`).concat(n?`
float distToSource = length(gl_FragCoord.xy - v_sourcePoint);
float sourceArrowLength = v_sourceSize + thickness * u_lengthToThicknessRatio;
if (distToSource < sourceArrowLength) {
thickness = (distToSource - v_sourceSize) / (sourceArrowLength - v_sourceSize) * u_widenessToThicknessRatio * thickness;
}`:"",`
float halfThickness = thickness / 2.0;
if (dist < halfThickness) {
#ifdef PICKING_MODE
gl_FragColor = v_color;
#else
float t = smoothstep(
halfThickness - v_feather,
halfThickness,
dist
);
gl_FragColor = mix(v_color, transparent, t);
#endif
} else {
gl_FragColor = transparent;
}
}
`);return i}function eo(r){var e=r.arrowHead,t=(e==null?void 0:e.extremity)==="target"||(e==null?void 0:e.extremity)==="both",n=(e==null?void 0:e.extremity)==="source"||(e==null?void 0:e.extremity)==="both",i=`
attribute vec4 a_id;
attribute vec4 a_color;
attribute float a_direction;
attribute float a_thickness;
attribute vec2 a_source;
attribute vec2 a_target;
attribute float a_current;
attribute float a_curvature;
`.concat(t?`attribute float a_targetSize;
`:"",`
`).concat(n?`attribute float a_sourceSize;
`:"",`
uniform mat3 u_matrix;
uniform float u_sizeRatio;
uniform float u_pixelRatio;
uniform vec2 u_dimensions;
uniform float u_minEdgeThickness;
uniform float u_feather;
varying vec4 v_color;
varying float v_thickness;
varying float v_feather;
varying vec2 v_cpA;
varying vec2 v_cpB;
varying vec2 v_cpC;
`).concat(t?`
varying float v_targetSize;
varying vec2 v_targetPoint;`:"",`
`).concat(n?`
varying float v_sourceSize;
varying vec2 v_sourcePoint;`:"",`
`).concat(e?`
uniform float u_widenessToThicknessRatio;`:"",`
const float bias = 255.0 / 254.0;
const float epsilon = 0.7;
vec2 clipspaceToViewport(vec2 pos, vec2 dimensions) {
return vec2(
(pos.x + 1.0) * dimensions.x / 2.0,
(pos.y + 1.0) * dimensions.y / 2.0
);
}
vec2 viewportToClipspace(vec2 pos, vec2 dimensions) {
return vec2(
pos.x / dimensions.x * 2.0 - 1.0,
pos.y / dimensions.y * 2.0 - 1.0
);
}
void main() {
float minThickness = u_minEdgeThickness;
// Selecting the correct position
// Branchless "position = a_source if a_current == 1.0 else a_target"
vec2 position = a_source * max(0.0, a_current) + a_target * max(0.0, 1.0 - a_current);
position = (u_matrix * vec3(position, 1)).xy;
vec2 source = (u_matrix * vec3(a_source, 1)).xy;
vec2 target = (u_matrix * vec3(a_target, 1)).xy;
vec2 viewportPosition = clipspaceToViewport(position, u_dimensions);
vec2 viewportSource = clipspaceToViewport(source, u_dimensions);
vec2 viewportTarget = clipspaceToViewport(target, u_dimensions);
vec2 delta = viewportTarget.xy - viewportSource.xy;
float len = length(delta);
vec2 normal = vec2(-delta.y, delta.x) * a_direction;
vec2 unitNormal = normal / len;
float boundingBoxThickness = len * a_curvature;
float curveThickness = max(minThickness, a_thickness / u_sizeRatio);
v_thickness = curveThickness * u_pixelRatio;
v_feather = u_feather;
v_cpA = viewportSource;
v_cpB = 0.5 * (viewportSource + viewportTarget) + unitNormal * a_direction * boundingBoxThickness;
v_cpC = viewportTarget;
vec2 viewportOffsetPosition = (
viewportPosition +
unitNormal * (boundingBoxThickness / 2.0 + sign(boundingBoxThickness) * (`).concat(e?"curveThickness * u_widenessToThicknessRatio":"curveThickness",` + epsilon)) *
max(0.0, a_direction) // NOTE: cutting the bounding box in half to avoid overdraw
);
position = viewportToClipspace(viewportOffsetPosition, u_dimensions);
gl_Position = vec4(position, 0, 1);
`).concat(t?`
v_targetSize = a_targetSize * u_pixelRatio / u_sizeRatio;
v_targetPoint = viewportTarget;
`:"",`
`).concat(n?`
v_sourceSize = a_sourceSize * u_pixelRatio / u_sizeRatio;
v_sourcePoint = viewportSource;
`:"",`
#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;
}
`);return i}var Dr=.25,to={arrowHead:null,curvatureAttribute:"curvature",defaultCurvature:Dr},kr=WebGLRenderingContext,Ir=kr.UNSIGNED_BYTE,te=kr.FLOAT;function mt(r){var e=Ge(Ge({},to),r||{}),t=e,n=t.arrowHead,i=t.curvatureAttribute,o=t.drawLabel,a=(n==null?void 0:n.extremity)==="target"||(n==null?void 0:n.extremity)==="both",s=(n==null?void 0:n.extremity)==="source"||(n==null?void 0:n.extremity)==="both",l=["u_matrix","u_sizeRatio","u_dimensions","u_pixelRatio","u_feather","u_minEdgeThickness"].concat(gt(n?["u_lengthToThicknessRatio","u_widenessToThicknessRatio"]:[]));return function(c){function u(){var d;Ui(this,u);for(var h=arguments.length,m=new Array(h),g=0;g<h;g++)m[g]=arguments[g];return d=Vi(this,u,[].concat(m)),Fr(d,"drawLabel",o||Qi(e)),d}return Wi(u,c),Hi(u,[{key:"getDefinition",value:function(){return{VERTICES:6,VERTEX_SHADER_SOURCE:eo(e),FRAGMENT_SHADER_SOURCE:Ji(e),METHOD:WebGLRenderingContext.TRIANGLES,UNIFORMS:l,ATTRIBUTES:[{name:"a_source",size:2,type:te},{name:"a_target",size:2,type:te}].concat(gt(a?[{name:"a_targetSize",size:1,type:te}]:[]),gt(s?[{name:"a_sourceSize",size:1,type:te}]:[]),[{name:"a_thickness",size:1,type:te},{name:"a_curvature",size:1,type:te},{name:"a_color",size:4,type:Ir,normalized:!0},{name:"a_id",size:4,type:Ir,normalized:!0}]),CONSTANT_ATTRIBUTES:[{name:"a_current",size:1,type:te},{name:"a_direction",size:1,type:te}],CONSTANT_DATA:[[0,1],[0,-1],[1,1],[0,-1],[1,1],[1,-1]]}}},{key:"processVisibleItem",value:function(h,m,g,b,E){var v,T=E.size||1,_=g.x,f=g.y,p=b.x,y=b.y,R=X(E.color),S=(v=E[i])!==null&&v!==void 0?v:Dr,F=this.array;F[m++]=_,F[m++]=f,F[m++]=p,F[m++]=y,a&&(F[m++]=b.size),s&&(F[m++]=g.size),F[m++]=T,F[m++]=S,F[m++]=R,F[m++]=h}},{key:"setUniforms",value:function(h,m){var g=m.gl,b=m.uniformLocations,E=b.u_matrix,v=b.u_pixelRatio,T=b.u_feather,_=b.u_sizeRatio,f=b.u_dimensions,p=b.u_minEdgeThickness;if(g.uniformMatrix3fv(E,!1,h.matrix),g.uniform1f(v,h.pixelRatio),g.uniform1f(_,h.sizeRatio),g.uniform1f(T,h.antiAliasingFeather),g.uniform2f(f,h.width*h.pixelRatio,h.height*h.pixelRatio),g.uniform1f(p,h.minEdgeThickness),n){var y=b.u_lengthToThicknessRatio,R=b.u_widenessToThicknessRatio;g.uniform1f(y,n.lengthToThicknessRatio),g.uniform1f(R,n.widenessToThicknessRatio)}}}])}(ct)}var ro=mt();mt({arrowHead:ze}),mt({arrowHead:Ge(Ge({},ze),{},{extremity:"both"})});function no(r){if(Array.isArray(r))return r}function io(r,e){var t=r==null?null:typeof Symbol<"u"&&r[Symbol.iterator]||r["@@iterator"];if(t!=null){var n,i,o,a,s=[],l=!0,c=!1;try{if(o=(t=t.call(r)).next,e!==0)for(;!(l=(n=o.call(t)).done)&&(s.push(n.value),s.length!==e);l=!0);}catch(u){c=!0,i=u}finally{try{if(!l&&t.return!=null&&(a=t.return(),Object(a)!==a))return}finally{if(c)throw i}}return s}}function vt(r,e){(e==null||e>r.length)&&(e=r.length);for(var t=0,n=Array(e);t<e;t++)n[t]=r[t];return n}function zr(r,e){if(r){if(typeof r=="string")return vt(r,e);var t={}.toString.call(r).slice(8,-1);return t==="Object"&&r.constructor&&(t=r.constructor.name),t==="Map"||t==="Set"?Array.from(r):t==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?vt(r,e):void 0}}function oo(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function ao(r,e){return no(r)||io(r,e)||zr(r,e)||oo()}function so(r,e){if(!(r instanceof e))throw new TypeError("Cannot call a class as a function")}function co(r,e){if(typeof r!="object"||!r)return r;var t=r[Symbol.toPrimitive];if(t!==void 0){var n=t.call(r,e);if(typeof n!="object")return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return(e==="string"?String:Number)(r)}function Gr(r){var e=co(r,"string");return typeof e=="symbol"?e:e+""}function lo(r,e){for(var t=0;t<e.length;t++){var n=e[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(r,Gr(n.key),n)}}function uo(r,e,t){return e&&lo(r.prototype,e),Object.defineProperty(r,"prototype",{writable:!1}),r}function Ue(r){return Ue=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},Ue(r)}function Mr(){try{var r=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch{}return(Mr=function(){return!!r})()}function ho(r){if(r===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return r}function fo(r,e){if(e&&(typeof e=="object"||typeof e=="function"))return e;if(e!==void 0)throw new TypeError("Derived constructors may only return object or undefined");return ho(r)}function go(r,e,t){return e=Ue(e),fo(r,Mr()?Reflect.construct(e,t||[],Ue(r).constructor):e.apply(r,t))}function pt(r,e){return pt=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,n){return t.__proto__=n,t},pt(r,e)}function mo(r,e){if(typeof e!="function"&&e!==null)throw new TypeError("Super expression must either be null or a function");r.prototype=Object.create(e&&e.prototype,{constructor:{value:r,writable:!0,configurable:!0}}),Object.defineProperty(r,"prototype",{writable:!1}),e&&pt(r,e)}function ge(r,e,t){return(e=Gr(e))in r?Object.defineProperty(r,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):r[e]=t,r}function vo(r){if(Array.isArray(r))return vt(r)}function po(r){if(typeof Symbol<"u"&&r[Symbol.iterator]!=null||r["@@iterator"]!=null)return Array.from(r)}function _o(){throw new TypeError(`Invalid attempt to spread non-iterable instance.
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function _t(r){return vo(r)||po(r)||zr(r)||_o()}function Ur(r,e){var t=Object.keys(r);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(r);e&&(n=n.filter(function(i){return Object.getOwnPropertyDescriptor(r,i).enumerable})),t.push.apply(t,n)}return t}function Br(r){for(var e=1;e<arguments.length;e++){var t=arguments[e]!=null?arguments[e]:{};e%2?Ur(Object(t),!0).forEach(function(n){ge(r,n,t[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(t)):Ur(Object(t)).forEach(function(n){Object.defineProperty(r,n,Object.getOwnPropertyDescriptor(t,n))})}return r}var bo="relative",yo={drawLabel:void 0,drawHover:void 0,borders:[{size:{value:.1},color:{attribute:"borderColor"}},{size:{fill:!0},color:{attribute:"color"}}]},Eo="#000000";function To(r){var e=r.borders,t=st(e.filter(function(i){var o=i.size;return"fill"in o}).length),n=`
precision highp float;
varying vec2 v_diffVector;
varying float v_radius;
#ifdef PICKING_MODE
varying vec4 v_color;
#else
// For normal mode, we use the border colors defined in the program:
`.concat(e.flatMap(function(i,o){var a=i.size;return"attribute"in a?["varying float v_borderSize_".concat(o+1,";")]:[]}).join(`
`),`
`).concat(e.flatMap(function(i,o){var a=i.color;return"attribute"in a?["varying vec4 v_borderColor_".concat(o+1,";")]:"value"in a?["uniform vec4 u_borderColor_".concat(o+1,";")]:[]}).join(`
`),`
#endif
uniform float u_correctionRatio;
const float bias = 255.0 / 254.0;
const vec4 transparent = vec4(0.0, 0.0, 0.0, 0.0);
void main(void) {
float dist = length(v_diffVector);
float aaBorder = 2.0 * u_correctionRatio;
float v_borderSize_0 = v_radius;
vec4 v_borderColor_0 = transparent;
// No antialiasing for picking mode:
#ifdef PICKING_MODE
if (dist > v_radius)
gl_FragColor = transparent;
else {
gl_FragColor = v_color;
gl_FragColor.a *= bias;
}
#else
// Sizes:
`).concat(e.flatMap(function(i,o){var a=i.size;if("fill"in a)return[];a=a;var s="attribute"in a?"v_borderSize_".concat(o+1):st(a.value),l=(a.mode||bo)==="pixels"?"u_correctionRatio":"v_radius";return[" float borderSize_".concat(o+1," = ").concat(l," * ").concat(s,";")]}).join(`
`),`
// Now, let's split the remaining space between "fill" borders:
float fillBorderSize = (v_radius - (`).concat(e.flatMap(function(i,o){var a=i.size;return"fill"in a?[]:["borderSize_".concat(o+1)]}).join(" + "),") ) / ").concat(t,`;
`).concat(e.flatMap(function(i,o){var a=i.size;return"fill"in a?[" float borderSize_".concat(o+1," = fillBorderSize;")]:[]}).join(`
`),`
// Finally, normalize all border sizes, to start from the full size and to end with the smallest:
float adjustedBorderSize_0 = v_radius;
`).concat(e.map(function(i,o){return" float adjustedBorderSize_".concat(o+1," = adjustedBorderSize_").concat(o," - borderSize_").concat(o+1,";")}).join(`
`),`
// Colors:
vec4 borderColor_0 = transparent;
`).concat(e.map(function(i,o){var a=i.color,s=[];return"attribute"in a?s.push(" vec4 borderColor_".concat(o+1," = v_borderColor_").concat(o+1,";")):"transparent"in a?s.push(" vec4 borderColor_".concat(o+1," = vec4(0.0, 0.0, 0.0, 0.0);")):s.push(" vec4 borderColor_".concat(o+1," = u_borderColor_").concat(o+1,";")),s.push(" borderColor_".concat(o+1,".a *= bias;")),s.push(" if (borderSize_".concat(o+1," <= 1.0 * u_correctionRatio) { borderColor_").concat(o+1," = borderColor_").concat(o,"; }")),s.join(`
`)}).join(`
`),`
if (dist > adjustedBorderSize_0) {
gl_FragColor = borderColor_0;
} else `).concat(e.map(function(i,o){return"if (dist > adjustedBorderSize_".concat(o,` - aaBorder) {
gl_FragColor = mix(borderColor_`).concat(o+1,", borderColor_").concat(o,", (dist - adjustedBorderSize_").concat(o,` + aaBorder) / aaBorder);
} else if (dist > adjustedBorderSize_`).concat(o+1,`) {
gl_FragColor = borderColor_`).concat(o+1,`;
} else `)}).join(""),` { /* Nothing to add here */ }
#endif
}
`);return n}function Ro(r){var e=r.borders,t=`
attribute vec2 a_position;
attribute float a_size;
attribute float a_angle;
uniform mat3 u_matrix;
uniform float u_sizeRatio;
uniform float u_correctionRatio;
varying vec2 v_diffVector;
varying float v_radius;
#ifdef PICKING_MODE
attribute vec4 a_id;
varying vec4 v_color;
#else
`.concat(e.flatMap(function(n,i){var o=n.size;return"attribute"in o?["attribute float a_borderSize_".concat(i+1,";"),"varying float v_borderSize_".concat(i+1,";")]:[]}).join(`
`),`
`).concat(e.flatMap(function(n,i){var o=n.color;return"attribute"in o?["attribute vec4 a_borderColor_".concat(i+1,";"),"varying vec4 v_borderColor_".concat(i+1,";")]:[]}).join(`
`),`
#endif
const float bias = 255.0 / 254.0;
const vec4 transparent = vec4(0.0, 0.0, 0.0, 0.0);
void main() {
float size = a_size * u_correctionRatio / u_sizeRatio * 4.0;
vec2 diffVector = size * vec2(cos(a_angle), sin(a_angle));
vec2 position = a_position + diffVector;
gl_Position = vec4(
(u_matrix * vec3(position, 1)).xy,
0,
1
);
v_radius = size / 2.0;
v_diffVector = diffVector;
#ifdef PICKING_MODE
v_color = a_id;
#else
`).concat(e.flatMap(function(n,i){var o=n.size;return"attribute"in o?[" v_borderSize_".concat(i+1," = a_borderSize_").concat(i+1,";")]:[]}).join(`
`),`
`).concat(e.flatMap(function(n,i){var o=n.color;return"attribute"in o?[" v_borderColor_".concat(i+1," = a_borderColor_").concat(i+1,";")]:[]}).join(`
`),`
#endif
}
`);return t}var Hr=WebGLRenderingContext,$r=Hr.UNSIGNED_BYTE,Be=Hr.FLOAT;function jr(r){var e,t=Br(Br({},yo),r||{}),n=t.borders,i=t.drawLabel,o=t.drawHover,a=["u_sizeRatio","u_correctionRatio","u_matrix"].concat(_t(n.flatMap(function(s,l){var c=s.color;return"value"in c?["u_borderColor_".concat(l+1)]:[]})));return e=function(s){function l(){var c;so(this,l);for(var u=arguments.length,d=new Array(u),h=0;h<u;h++)d[h]=arguments[h];return c=go(this,l,[].concat(d)),ge(c,"drawLabel",i),ge(c,"drawHover",o),c}return mo(l,s),uo(l,[{key:"getDefinition",value:function(){return{VERTICES:3,VERTEX_SHADER_SOURCE:Ro(t),FRAGMENT_SHADER_SOURCE:To(t),METHOD:WebGLRenderingContext.TRIANGLES,UNIFORMS:a,ATTRIBUTES:[{name:"a_position",size:2,type:Be},{name:"a_id",size:4,type:$r,normalized:!0},{name:"a_size",size:1,type:Be}].concat(_t(n.flatMap(function(u,d){var h=u.color;return"attribute"in h?[{name:"a_borderColor_".concat(d+1),size:4,type:$r,normalized:!0}]:[]})),_t(n.flatMap(function(u,d){var h=u.size;return"attribute"in h?[{name:"a_borderSize_".concat(d+1),size:1,type:Be}]:[]}))),CONSTANT_ATTRIBUTES:[{name:"a_angle",size:1,type:Be}],CONSTANT_DATA:[[l.ANGLE_1],[l.ANGLE_2],[l.ANGLE_3]]}}},{key:"processVisibl