@cosmos.gl/graph 3.0.0-beta.4 → 3.0.0-beta.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.min.js CHANGED
@@ -2285,7 +2285,7 @@ void main() {
2285
2285
  }
2286
2286
 
2287
2287
  fragColor = pointPosition;
2288
- }`;function Ev(n,e=16384){if(!(n!=null&&n.length))return null;let t=0;for(const c of n){const u=Math.max(c.width,c.height);u>t&&(t=u)}if(t===0)return console.warn("Invalid image dimensions: all images have zero width or height"),null;const i=t,r=Math.ceil(Math.sqrt(n.length));let s=r*t,o=1;s>e&&(o=e/s,t=Math.max(1,Math.floor(t*o)),s=Math.max(1,Math.floor(s*o)),console.warn(`🖼️ Atlas scaling required: Original size ${(i*r).toLocaleString()}px exceeds WebGL limit ${e.toLocaleString()}px. Scaling down to ${s.toLocaleString()}px (${Math.round(o*100)}% of original quality)`));const a=new Uint8Array(s*s*4).fill(0),l=new Float32Array(r*r*4).fill(-1);for(const[c,u]of n.entries()){const f=u.width,h=u.height;if(f===0||h===0)continue;const d=Math.min(1,t/Math.max(f,h)),_=Math.floor(f*d),I=Math.floor(h*d),P=Math.floor(c/r),O=c%r*t,E=P*t;l[c*4]=O/s,l[c*4+1]=E/s,l[c*4+2]=(O+_)/s,l[c*4+3]=(E+I)/s;for(let y=0;y<I;y++)for(let R=0;R<_;R++){const N=Math.floor(R*(f/_)),W=(Math.floor(y*(h/I))*f+N)*4,q=((E+y)*s+(O+R))*4;a[q]=u.data[W]??0,a[q+1]=u.data[W+1]??0,a[q+2]=u.data[W+2]??0,a[q+3]=u.data[W+3]??255}}return{atlasData:a,atlasSize:s,atlasCoords:l,atlasCoordsSize:r}}class Rv extends Nt{constructor(){super(...arguments),this.imageCount=0,this.isPositionsUpToDate=!1,this.polygonPathLength=0}updatePositions(){const{device:e,store:t,data:i,config:{rescalePositions:r,enableSimulation:s}}=this,{pointsTextureSize:o}=t;if(!o||!i.pointPositions||i.pointsNumber===void 0)return;const a=o*o*4,l=new Float32Array(a),c=o*o*4*4,u=l.byteLength;u!==c&&console.error("Texture data size mismatch:",{pointsTextureSize:o,expectedBytes:c,actualBytes:u,textureDataSize:a,dataLength:l.length});let f=r;r===void 0&&!s&&(f=!0),this.shouldSkipRescale&&(f=!1),f?this.rescaleInitialNodePositions():this.shouldSkipRescale||(this.scaleX=void 0,this.scaleY=void 0),this.shouldSkipRescale=void 0;for(let _=0;_<i.pointsNumber;++_)l[_*4+0]=i.pointPositions[_*2+0],l[_*4+1]=i.pointPositions[_*2+1],l[_*4+2]=_;if(!this.currentPositionTexture||this.currentPositionTexture.width!==o||this.currentPositionTexture.height!==o?(this.currentPositionTexture&&!this.currentPositionTexture.destroyed&&this.currentPositionTexture.destroy(),this.currentPositionFbo&&!this.currentPositionFbo.destroyed&&this.currentPositionFbo.destroy(),this.currentPositionTexture=e.createTexture({width:o,height:o,format:"rgba32float"}),this.currentPositionTexture.copyImageData({data:l,bytesPerRow:ne("rgba32float",o),mipLevel:0,x:0,y:0}),this.currentPositionFbo=e.createFramebuffer({width:o,height:o,colorAttachments:[this.currentPositionTexture]})):this.currentPositionTexture.copyImageData({data:l,bytesPerRow:ne("rgba32float",o),mipLevel:0,x:0,y:0}),!this.previousPositionTexture||this.previousPositionTexture.width!==o||this.previousPositionTexture.height!==o?(this.previousPositionTexture&&!this.previousPositionTexture.destroyed&&this.previousPositionTexture.destroy(),this.previousPositionFbo&&!this.previousPositionFbo.destroyed&&this.previousPositionFbo.destroy(),this.previousPositionTexture=e.createTexture({width:o,height:o,format:"rgba32float"}),this.previousPositionTexture.copyImageData({data:l,bytesPerRow:ne("rgba32float",o),mipLevel:0,x:0,y:0}),this.previousPositionFbo=e.createFramebuffer({width:o,height:o,colorAttachments:[this.previousPositionTexture]})):this.previousPositionTexture.copyImageData({data:l,bytesPerRow:ne("rgba32float",o),mipLevel:0,x:0,y:0}),this.config.enableSimulation){const _=new Float32Array(o*o*4).fill(0);!this.velocityTexture||this.velocityTexture.width!==o||this.velocityTexture.height!==o?(this.velocityTexture&&!this.velocityTexture.destroyed&&this.velocityTexture.destroy(),this.velocityFbo&&!this.velocityFbo.destroyed&&this.velocityFbo.destroy(),this.velocityTexture=e.createTexture({width:o,height:o,format:"rgba32float"}),this.velocityTexture.copyImageData({data:_,bytesPerRow:ne("rgba32float",o),mipLevel:0,x:0,y:0}),this.velocityFbo=e.createFramebuffer({width:o,height:o,colorAttachments:[this.velocityTexture]})):this.velocityTexture.copyImageData({data:_,bytesPerRow:ne("rgba32float",o),mipLevel:0,x:0,y:0})}!this.selectedTexture||this.selectedTexture.width!==o||this.selectedTexture.height!==o?(this.selectedTexture&&!this.selectedTexture.destroyed&&this.selectedTexture.destroy(),this.selectedFbo&&!this.selectedFbo.destroyed&&this.selectedFbo.destroy(),this.selectedTexture=e.createTexture({width:o,height:o,format:"rgba32float"}),this.selectedTexture.copyImageData({data:l,bytesPerRow:ne("rgba32float",o),mipLevel:0,x:0,y:0}),this.selectedFbo=e.createFramebuffer({width:o,height:o,colorAttachments:[this.selectedTexture]})):this.selectedTexture.copyImageData({data:l,bytesPerRow:ne("rgba32float",o),mipLevel:0,x:0,y:0}),this.hoveredFbo||(this.hoveredFbo=e.createFramebuffer({width:2,height:2,colorAttachments:["rgba32float"]}));const h=yr(t.pointsTextureSize),d=h.byteLength;!this.drawPointIndices||this.drawPointIndices.byteLength!==d?(this.drawPointIndices&&!this.drawPointIndices.destroyed&&this.drawPointIndices.destroy(),this.drawPointIndices=e.createBuffer({data:h,usage:L.VERTEX|L.COPY_DST})):this.drawPointIndices.write(h),this.drawCommand&&this.drawCommand.setAttributes({pointIndices:this.drawPointIndices}),!this.hoveredPointIndices||this.hoveredPointIndices.byteLength!==d?(this.hoveredPointIndices&&!this.hoveredPointIndices.destroyed&&this.hoveredPointIndices.destroy(),this.hoveredPointIndices=e.createBuffer({data:h,usage:L.VERTEX|L.COPY_DST})):this.hoveredPointIndices.write(h),!this.sampledPointIndices||this.sampledPointIndices.byteLength!==d?(this.sampledPointIndices&&!this.sampledPointIndices.destroyed&&this.sampledPointIndices.destroy(),this.sampledPointIndices=e.createBuffer({data:h,usage:L.VERTEX|L.COPY_DST})):this.sampledPointIndices.write(h),this.fillSampledPointsFboCommand&&this.fillSampledPointsFboCommand.setAttributes({pointIndices:this.sampledPointIndices}),this.updateGreyoutStatus(),this.updatePinnedStatus(),this.updateSampledPointsGrid(),this.trackPointsByIndices()}initPrograms(){var s,o,a;const{device:e,config:t,store:i,data:r}=this;(!this.imageAtlasCoordsTexture||!this.imageAtlasTexture)&&this.createAtlas(),this.colorBuffer||this.updateColor(),this.sizeBuffer||this.updateSize(),this.shapeBuffer||this.updateShape(),this.imageIndicesBuffer||this.updateImageIndices(),this.imageSizesBuffer||this.updateImageSizes(),this.greyoutStatusTexture||this.updateGreyoutStatus(),t.enableSimulation&&(this.updatePositionVertexCoordBuffer||(this.updatePositionVertexCoordBuffer=e.createBuffer({data:new Float32Array([-1,-1,1,-1,-1,1,1,1])})),this.updatePositionUniformStore||(this.updatePositionUniformStore=new ye({updatePositionUniforms:{uniformTypes:{friction:"f32",spaceSize:"f32"},defaultUniforms:{friction:t.simulationFriction??0,spaceSize:i.adjustedSpaceSize??0}}})),this.updatePositionCommand||(this.updatePositionCommand=new _e(e,{fs:Cv,vs:tt,topology:"triangle-strip",vertexCount:4,attributes:{vertexCoord:this.updatePositionVertexCoordBuffer},bufferLayout:[{name:"vertexCoord",format:"float32x2"}],defines:{USE_UNIFORM_BUFFERS:!0},bindings:{updatePositionUniforms:this.updatePositionUniformStore.getManagedUniformBuffer(e,"updatePositionUniforms")}}))),this.dragPointVertexCoordBuffer||(this.dragPointVertexCoordBuffer=e.createBuffer({data:new Float32Array([-1,-1,1,-1,-1,1,1,1])})),this.dragPointUniformStore||(this.dragPointUniformStore=new ye({dragPointUniforms:{uniformTypes:{mousePos:"vec2<f32>",index:"f32"},defaultUniforms:{mousePos:re(i.mousePosition,[0,0]),index:((s=i.hoveredPoint)==null?void 0:s.index)??-1}}})),this.dragPointCommand||(this.dragPointCommand=new _e(e,{fs:Pv,vs:tt,topology:"triangle-strip",vertexCount:4,attributes:{vertexCoord:this.dragPointVertexCoordBuffer},bufferLayout:[{name:"vertexCoord",format:"float32x2"}],defines:{USE_UNIFORM_BUFFERS:!0},bindings:{dragPointUniforms:this.dragPointUniformStore.getManagedUniformBuffer(e,"dragPointUniforms")}})),this.drawUniformStore||(this.drawUniformStore=new ye({drawVertexUniforms:{uniformTypes:{ratio:"f32",transformationMatrix:"mat4x4<f32>",pointsTextureSize:"f32",sizeScale:"f32",spaceSize:"f32",screenSize:"vec2<f32>",greyoutColor:"vec4<f32>",backgroundColor:"vec4<f32>",scalePointsOnZoom:"f32",maxPointSize:"f32",isDarkenGreyout:"f32",skipSelected:"f32",skipUnselected:"f32",hasImages:"f32",imageCount:"f32",imageAtlasCoordsTextureSize:"f32"},defaultUniforms:{ratio:t.pixelRatio??V.pixelRatio,transformationMatrix:(()=>{const l=i.transform??[1,0,0,0,1,0,0,0,1];return[l[0],l[1],l[2],0,l[3],l[4],l[5],0,l[6],l[7],l[8],0,0,0,0,1]})(),pointsTextureSize:i.pointsTextureSize??0,sizeScale:t.pointSizeScale??1,spaceSize:i.adjustedSpaceSize??0,screenSize:re(i.screenSize,[0,0]),greyoutColor:Re(i.greyoutPointColor,[0,0,0,1]),backgroundColor:Re(i.backgroundColor,[0,0,0,1]),scalePointsOnZoom:t.scalePointsOnZoom??!0?1:0,maxPointSize:i.maxPointSize??100,isDarkenGreyout:i.isDarkenGreyout??!1?1:0,skipSelected:0,skipUnselected:0,hasImages:this.imageCount>0?1:0,imageCount:this.imageCount,imageAtlasCoordsTextureSize:this.imageAtlasCoordsTextureSize??0}},drawFragmentUniforms:{uniformTypes:{greyoutOpacity:"f32",pointOpacity:"f32",isDarkenGreyout:"f32",backgroundColor:"vec4<f32>"},defaultUniforms:{greyoutOpacity:t.pointGreyoutOpacity??-1,pointOpacity:t.pointOpacity??1,isDarkenGreyout:i.isDarkenGreyout??!1?1:0,backgroundColor:Re(i.backgroundColor,[0,0,0,1])}}})),this.drawCommand||(this.drawCommand=new _e(e,{fs:mv,vs:_v,topology:"point-list",vertexCount:r.pointsNumber??0,attributes:{...this.drawPointIndices&&{pointIndices:this.drawPointIndices},...this.sizeBuffer&&{size:this.sizeBuffer},...this.colorBuffer&&{color:this.colorBuffer},...this.shapeBuffer&&{shape:this.shapeBuffer},...this.imageIndicesBuffer&&{imageIndex:this.imageIndicesBuffer},...this.imageSizesBuffer&&{imageSize:this.imageSizesBuffer}},bufferLayout:[{name:"pointIndices",format:"float32x2"},{name:"size",format:"float32"},{name:"color",format:"float32x4"},{name:"shape",format:"float32"},{name:"imageIndex",format:"float32"},{name:"imageSize",format:"float32"}],defines:{USE_UNIFORM_BUFFERS:!0},bindings:{drawVertexUniforms:this.drawUniformStore.getManagedUniformBuffer(e,"drawVertexUniforms"),drawFragmentUniforms:this.drawUniformStore.getManagedUniformBuffer(e,"drawFragmentUniforms")},parameters:{blend:!0,blendColorOperation:"add",blendColorSrcFactor:"src-alpha",blendColorDstFactor:"one-minus-src-alpha",blendAlphaOperation:"add",blendAlphaSrcFactor:"one",blendAlphaDstFactor:"one-minus-src-alpha",depthWriteEnabled:!1,depthCompare:"always"}})),this.findPointsOnAreaSelectionVertexCoordBuffer||(this.findPointsOnAreaSelectionVertexCoordBuffer=e.createBuffer({data:new Float32Array([-1,-1,1,-1,-1,1,1,1])})),this.findPointsOnAreaSelectionUniformStore||(this.findPointsOnAreaSelectionUniformStore=new ye({findPointsOnAreaSelectionUniforms:{uniformTypes:{sizeScale:"f32",spaceSize:"f32",screenSize:"vec2<f32>",ratio:"f32",transformationMatrix:"mat4x4<f32>",selection0:"vec2<f32>",selection1:"vec2<f32>",scalePointsOnZoom:"f32",maxPointSize:"f32"},defaultUniforms:{sizeScale:t.pointSizeScale??1,spaceSize:i.adjustedSpaceSize??0,screenSize:re(i.screenSize,[0,0]),ratio:t.pixelRatio??V.pixelRatio,transformationMatrix:i.transformationMatrix4x4,selection0:re((o=i.selectedArea)==null?void 0:o[0],[0,0]),selection1:re((a=i.selectedArea)==null?void 0:a[1],[0,0]),scalePointsOnZoom:t.scalePointsOnZoom??!0?1:0,maxPointSize:i.maxPointSize??100}}})),this.findPointsOnAreaSelectionCommand||(this.findPointsOnAreaSelectionCommand=new _e(e,{fs:yv,vs:tt,topology:"triangle-strip",vertexCount:4,attributes:{vertexCoord:this.findPointsOnAreaSelectionVertexCoordBuffer},bufferLayout:[{name:"vertexCoord",format:"float32x2"}],defines:{USE_UNIFORM_BUFFERS:!0},bindings:{findPointsOnAreaSelectionUniforms:this.findPointsOnAreaSelectionUniformStore.getManagedUniformBuffer(e,"findPointsOnAreaSelectionUniforms")}})),this.findPointsOnPolygonSelectionVertexCoordBuffer||(this.findPointsOnPolygonSelectionVertexCoordBuffer=e.createBuffer({data:new Float32Array([-1,-1,1,-1,-1,1,1,1])})),this.findPointsOnPolygonSelectionUniformStore||(this.findPointsOnPolygonSelectionUniformStore=new ye({findPointsOnPolygonSelectionUniforms:{uniformTypes:{spaceSize:"f32",screenSize:"vec2<f32>",transformationMatrix:"mat4x4<f32>",polygonPathLength:"f32"},defaultUniforms:{spaceSize:i.adjustedSpaceSize??0,screenSize:re(i.screenSize,[0,0]),transformationMatrix:i.transformationMatrix4x4,polygonPathLength:this.polygonPathLength}}})),this.findPointsOnPolygonSelectionCommand||(this.findPointsOnPolygonSelectionCommand=new _e(e,{fs:xv,vs:tt,topology:"triangle-strip",vertexCount:4,attributes:{vertexCoord:this.findPointsOnPolygonSelectionVertexCoordBuffer},bufferLayout:[{name:"vertexCoord",format:"float32x2"}],defines:{USE_UNIFORM_BUFFERS:!0},bindings:{findPointsOnPolygonSelectionUniforms:this.findPointsOnPolygonSelectionUniformStore.getManagedUniformBuffer(e,"findPointsOnPolygonSelectionUniforms")}})),this.findHoveredPointUniformStore||(this.findHoveredPointUniformStore=new ye({findHoveredPointUniforms:{uniformTypes:{pointsTextureSize:"f32",sizeScale:"f32",spaceSize:"f32",screenSize:"vec2<f32>",ratio:"f32",transformationMatrix:"mat4x4<f32>",mousePosition:"vec2<f32>",scalePointsOnZoom:"f32",maxPointSize:"f32",skipSelected:"f32",skipUnselected:"f32"},defaultUniforms:{pointsTextureSize:i.pointsTextureSize??0,sizeScale:t.pointSizeScale??1,spaceSize:i.adjustedSpaceSize??0,screenSize:re(i.screenSize,[0,0]),ratio:t.pixelRatio??V.pixelRatio,transformationMatrix:i.transformationMatrix4x4,mousePosition:re(i.screenMousePosition,[0,0]),scalePointsOnZoom:t.scalePointsOnZoom??!0?1:0,maxPointSize:i.maxPointSize??100,skipSelected:0,skipUnselected:0}}})),this.findHoveredPointCommand||(this.findHoveredPointCommand=new _e(e,{fs:Sv,vs:Tv,topology:"point-list",vertexCount:r.pointsNumber??0,attributes:{...this.hoveredPointIndices&&{pointIndices:this.hoveredPointIndices},...this.sizeBuffer&&{size:this.sizeBuffer}},bufferLayout:[{name:"pointIndices",format:"float32x2"},{name:"size",format:"float32"}],defines:{USE_UNIFORM_BUFFERS:!0},bindings:{findHoveredPointUniforms:this.findHoveredPointUniformStore.getManagedUniformBuffer(e,"findHoveredPointUniforms")},parameters:{depthWriteEnabled:!1,depthCompare:"always",blend:!1}})),this.fillSampledPointsUniformStore||(this.fillSampledPointsUniformStore=new ye({fillSampledPointsUniforms:{uniformTypes:{pointsTextureSize:"f32",transformationMatrix:"mat4x4<f32>",spaceSize:"f32",screenSize:"vec2<f32>"},defaultUniforms:{pointsTextureSize:i.pointsTextureSize??0,transformationMatrix:i.transformationMatrix4x4,spaceSize:i.adjustedSpaceSize??0,screenSize:re(i.screenSize,[0,0])}}})),this.fillSampledPointsFboCommand||(this.fillSampledPointsFboCommand=new _e(e,{fs:wv,vs:Av,topology:"point-list",vertexCount:r.pointsNumber??0,attributes:{...this.sampledPointIndices&&{pointIndices:this.sampledPointIndices}},bufferLayout:[{name:"pointIndices",format:"float32x2"}],defines:{USE_UNIFORM_BUFFERS:!0},bindings:{fillSampledPointsUniforms:this.fillSampledPointsUniformStore.getManagedUniformBuffer(e,"fillSampledPointsUniforms")},parameters:{depthWriteEnabled:!1,depthCompare:"always"}})),this.drawHighlightedVertexCoordBuffer||(this.drawHighlightedVertexCoordBuffer=e.createBuffer({data:new Float32Array([-1,-1,1,-1,-1,1,1,1])})),this.drawHighlightedUniformStore||(this.drawHighlightedUniformStore=new ye({drawHighlightedUniforms:{uniformTypes:{size:"f32",transformationMatrix:"mat4x4<f32>",pointsTextureSize:"f32",sizeScale:"f32",spaceSize:"f32",screenSize:"vec2<f32>",scalePointsOnZoom:"f32",pointIndex:"f32",maxPointSize:"f32",color:"vec4<f32>",universalPointOpacity:"f32",greyoutOpacity:"f32",isDarkenGreyout:"f32",backgroundColor:"vec4<f32>",greyoutColor:"vec4<f32>",width:"f32"},defaultUniforms:{size:1,transformationMatrix:i.transformationMatrix4x4,pointsTextureSize:i.pointsTextureSize??0,sizeScale:t.pointSizeScale??1,spaceSize:i.adjustedSpaceSize??0,screenSize:re(i.screenSize,[0,0]),scalePointsOnZoom:t.scalePointsOnZoom??!0?1:0,pointIndex:-1,maxPointSize:i.maxPointSize??100,color:[0,0,0,1],universalPointOpacity:t.pointOpacity??1,greyoutOpacity:t.pointGreyoutOpacity??-1,isDarkenGreyout:i.isDarkenGreyout??!1?1:0,backgroundColor:Re(i.backgroundColor,[0,0,0,1]),greyoutColor:Re(i.greyoutPointColor,[0,0,0,1]),width:.85}}})),this.drawHighlightedCommand||(this.drawHighlightedCommand=new _e(e,{fs:vv,vs:bv,topology:"triangle-strip",vertexCount:4,attributes:{vertexCoord:this.drawHighlightedVertexCoordBuffer},bufferLayout:[{name:"vertexCoord",format:"float32x2"}],defines:{USE_UNIFORM_BUFFERS:!0},bindings:{drawHighlightedUniforms:this.drawHighlightedUniformStore.getManagedUniformBuffer(e,"drawHighlightedUniforms")},parameters:{blend:!0,blendColorOperation:"add",blendColorSrcFactor:"src-alpha",blendColorDstFactor:"one-minus-src-alpha",blendAlphaOperation:"add",blendAlphaSrcFactor:"one",blendAlphaDstFactor:"one-minus-src-alpha",depthWriteEnabled:!1,depthCompare:"always"}})),this.trackPointsVertexCoordBuffer||(this.trackPointsVertexCoordBuffer=e.createBuffer({data:new Float32Array([-1,-1,1,-1,-1,1,1,1])})),this.trackPointsUniformStore||(this.trackPointsUniformStore=new ye({trackPointsUniforms:{uniformTypes:{pointsTextureSize:"f32"},defaultUniforms:{pointsTextureSize:i.pointsTextureSize??0}}})),this.trackPointsCommand||(this.trackPointsCommand=new _e(e,{fs:Iv,vs:tt,topology:"triangle-strip",vertexCount:4,attributes:{vertexCoord:this.trackPointsVertexCoordBuffer},bufferLayout:[{name:"vertexCoord",format:"float32x2"}],defines:{USE_UNIFORM_BUFFERS:!0},bindings:{trackPointsUniforms:this.trackPointsUniformStore.getManagedUniformBuffer(e,"trackPointsUniforms")}}))}updateColor(){const{device:e,store:{pointsTextureSize:t},data:i}=this;if(!t)return;const r=i.pointColors,s=r.byteLength;!this.colorBuffer||this.colorBuffer.byteLength!==s?(this.colorBuffer&&!this.colorBuffer.destroyed&&this.colorBuffer.destroy(),this.colorBuffer=e.createBuffer({data:r,usage:L.VERTEX|L.COPY_DST})):this.colorBuffer.write(r),this.drawCommand&&this.drawCommand.setAttributes({color:this.colorBuffer})}updateGreyoutStatus(){const{device:e,store:{selectedIndices:t,pointsTextureSize:i}}=this;if(!i)return;const r=new Float32Array(i*i*4).fill(t?1:0);if(t)for(const s of t)r[s*4]=0;!this.greyoutStatusTexture||this.greyoutStatusTexture.width!==i||this.greyoutStatusTexture.height!==i?(this.greyoutStatusTexture&&!this.greyoutStatusTexture.destroyed&&this.greyoutStatusTexture.destroy(),this.greyoutStatusTexture=e.createTexture({width:i,height:i,format:"rgba32float"}),this.greyoutStatusTexture.copyImageData({data:r,bytesPerRow:ne("rgba32float",i),mipLevel:0,x:0,y:0})):this.greyoutStatusTexture.copyImageData({data:r,bytesPerRow:ne("rgba32float",i),mipLevel:0,x:0,y:0})}updatePinnedStatus(){const{device:e,store:{pointsTextureSize:t},data:i}=this;if(!t)return;const r=new Float32Array(t*t*4).fill(0);if(i.inputPinnedPoints&&i.pointsNumber!==void 0)for(const s of i.inputPinnedPoints)s>=0&&s<i.pointsNumber&&(r[s*4]=1);!this.pinnedStatusTexture||this.pinnedStatusTexture.width!==t||this.pinnedStatusTexture.height!==t?(this.pinnedStatusTexture&&!this.pinnedStatusTexture.destroyed&&this.pinnedStatusTexture.destroy(),this.pinnedStatusTexture=e.createTexture({width:t,height:t,format:"rgba32float"}),this.pinnedStatusTexture.copyImageData({data:r,bytesPerRow:ne("rgba32float",t),mipLevel:0,x:0,y:0})):this.pinnedStatusTexture.copyImageData({data:r,bytesPerRow:ne("rgba32float",t),mipLevel:0,x:0,y:0})}updateSize(){const{device:e,store:{pointsTextureSize:t},data:i}=this;if(!t||i.pointsNumber===void 0||i.pointSizes===void 0)return;const r=i.pointSizes,s=r.byteLength;!this.sizeBuffer||this.sizeBuffer.byteLength!==s?(this.sizeBuffer&&!this.sizeBuffer.destroyed&&this.sizeBuffer.destroy(),this.sizeBuffer=e.createBuffer({data:r,usage:L.VERTEX|L.COPY_DST})):this.sizeBuffer.write(r),this.drawCommand&&this.drawCommand.setAttributes({size:this.sizeBuffer});const o=new Float32Array(t*t*4);for(let a=0;a<i.pointsNumber;a++)o[a*4]=i.pointSizes[a];!this.sizeTexture||this.sizeTexture.width!==t||this.sizeTexture.height!==t?(this.sizeTexture&&!this.sizeTexture.destroyed&&this.sizeTexture.destroy(),this.sizeTexture=e.createTexture({width:t,height:t,format:"rgba32float"}),this.sizeTexture.copyImageData({data:o,bytesPerRow:ne("rgba32float",t),mipLevel:0,x:0,y:0})):this.sizeTexture.copyImageData({data:o,bytesPerRow:ne("rgba32float",t),mipLevel:0,x:0,y:0})}updateShape(){const{device:e,data:t}=this;if(t.pointsNumber===void 0||t.pointShapes===void 0)return;const i=t.pointShapes,r=i.byteLength;!this.shapeBuffer||this.shapeBuffer.byteLength!==r?(this.shapeBuffer&&!this.shapeBuffer.destroyed&&this.shapeBuffer.destroy(),this.shapeBuffer=e.createBuffer({data:i,usage:L.VERTEX|L.COPY_DST})):this.shapeBuffer.write(i),this.drawCommand&&this.drawCommand.setAttributes({shape:this.shapeBuffer})}updateImageIndices(){const{device:e,data:t}=this;if(t.pointsNumber===void 0||t.pointImageIndices===void 0)return;const i=t.pointImageIndices,r=i.byteLength;!this.imageIndicesBuffer||this.imageIndicesBuffer.byteLength!==r?(this.imageIndicesBuffer&&!this.imageIndicesBuffer.destroyed&&this.imageIndicesBuffer.destroy(),this.imageIndicesBuffer=e.createBuffer({data:i,usage:L.VERTEX|L.COPY_DST})):this.imageIndicesBuffer.write(i),this.drawCommand&&this.drawCommand.setAttributes({imageIndex:this.imageIndicesBuffer})}updateImageSizes(){const{device:e,data:t}=this;if(t.pointsNumber===void 0||t.pointImageSizes===void 0)return;const i=t.pointImageSizes,r=i.byteLength;!this.imageSizesBuffer||this.imageSizesBuffer.byteLength!==r?(this.imageSizesBuffer&&!this.imageSizesBuffer.destroyed&&this.imageSizesBuffer.destroy(),this.imageSizesBuffer=e.createBuffer({data:i,usage:L.VERTEX|L.COPY_DST})):this.imageSizesBuffer.write(i),this.drawCommand&&this.drawCommand.setAttributes({imageSize:this.imageSizesBuffer})}createAtlas(){var c;const{device:e,data:t,store:i}=this;if(!((c=t.inputImageData)!=null&&c.length)){this.imageCount=0,this.imageAtlasCoordsTextureSize=0,this.imageAtlasCoordsTexture||(this.imageAtlasCoordsTexture=e.createTexture({data:new Float32Array(4).fill(0),width:1,height:1,format:"rgba32float"})),this.imageAtlasTexture||(this.imageAtlasTexture=e.createTexture({data:new Uint8Array(4).fill(0),width:1,height:1,format:"rgba8unorm"}));return}const r=Ev(t.inputImageData,i.webglMaxTextureSize);if(!r){console.warn("Failed to create atlas from image data");return}this.imageCount=t.inputImageData.length;const{atlasData:s,atlasSize:o,atlasCoords:a,atlasCoordsSize:l}=r;this.imageAtlasCoordsTextureSize=l,this.imageAtlasTexture&&!this.imageAtlasTexture.destroyed&&this.imageAtlasTexture.destroy(),this.imageAtlasTexture=e.createTexture({width:o,height:o,format:"rgba8unorm"}),this.imageAtlasTexture.copyImageData({data:s,bytesPerRow:ne("rgba8unorm",o),rowsPerImage:o,mipLevel:0,x:0,y:0}),this.imageAtlasCoordsTexture&&!this.imageAtlasCoordsTexture.destroyed&&this.imageAtlasCoordsTexture.destroy(),this.imageAtlasCoordsTexture=e.createTexture({width:l,height:l,format:"rgba32float"}),this.imageAtlasCoordsTexture.copyImageData({data:a,bytesPerRow:ne("rgba32float",l),rowsPerImage:l,mipLevel:0,x:0,y:0})}updateSampledPointsGrid(){const{store:{screenSize:e},config:{pointSamplingDistance:t},device:i}=this;let r=t??Math.min(...e)/2;r===0&&(r=V.pointSamplingDistance);const s=Math.ceil(e[0]/r),o=Math.ceil(e[1]/r);(!this.sampledPointsFbo||this.sampledPointsFbo.width!==s||this.sampledPointsFbo.height!==o)&&(this.sampledPointsFbo&&!this.sampledPointsFbo.destroyed&&this.sampledPointsFbo.destroy(),this.sampledPointsFbo=i.createFramebuffer({width:s,height:o,colorAttachments:["rgba32float"]}))}trackPoints(){var t;if(!((t=this.trackedIndices)!=null&&t.length)||!this.trackPointsCommand||!this.trackPointsUniformStore||!this.trackedPositionsFbo||this.trackedPositionsFbo.destroyed||!this.currentPositionTexture||this.currentPositionTexture.destroyed||!this.trackedIndicesTexture||this.trackedIndicesTexture.destroyed)return;this.trackPointsUniformStore.setUniforms({trackPointsUniforms:{pointsTextureSize:this.store.pointsTextureSize??0}}),this.trackPointsCommand.setBindings({positionsTexture:this.currentPositionTexture,trackedIndices:this.trackedIndicesTexture});const e=this.device.beginRenderPass({framebuffer:this.trackedPositionsFbo});this.trackPointsCommand.draw(e),e.end()}draw(e){var a,l;const{data:t,config:i,store:r}=this;if(this.colorBuffer||this.updateColor(),this.sizeBuffer||this.updateSize(),this.shapeBuffer||this.updateShape(),this.imageIndicesBuffer||this.updateImageIndices(),this.imageSizesBuffer||this.updateImageSizes(),!this.drawCommand||!this.drawUniformStore||!this.currentPositionTexture||this.currentPositionTexture.destroyed||!this.greyoutStatusTexture||this.greyoutStatusTexture.destroyed||(!this.imageAtlasTexture||!this.imageAtlasCoordsTexture)&&(this.createAtlas(),!this.imageAtlasTexture||!this.imageAtlasCoordsTexture)||this.imageAtlasTexture.destroyed||this.imageAtlasCoordsTexture.destroyed||!t.pointsNumber||t.pointsNumber===0||!r.screenSize||r.screenSize[0]===0||r.screenSize[1]===0)return;this.drawCommand.setVertexCount(t.pointsNumber);const s={ratio:i.pixelRatio??V.pixelRatio,transformationMatrix:r.transformationMatrix4x4,pointsTextureSize:r.pointsTextureSize??0,sizeScale:i.pointSizeScale??1,spaceSize:r.adjustedSpaceSize??0,screenSize:re(r.screenSize,[0,0]),greyoutColor:Re(r.greyoutPointColor,[-1,-1,-1,-1]),backgroundColor:Re(r.backgroundColor,[0,0,0,1]),scalePointsOnZoom:i.scalePointsOnZoom??!0?1:0,maxPointSize:r.maxPointSize??100,isDarkenGreyout:r.isDarkenGreyout??!1?1:0,hasImages:this.imageCount>0?1:0,imageCount:this.imageCount,imageAtlasCoordsTextureSize:this.imageAtlasCoordsTextureSize??0},o={greyoutOpacity:i.pointGreyoutOpacity??-1,pointOpacity:i.pointOpacity??1,isDarkenGreyout:r.isDarkenGreyout??!1?1:0,backgroundColor:Re(r.backgroundColor,[0,0,0,1])};if(r.selectedIndices&&r.selectedIndices.length>0?(this.drawUniformStore.setUniforms({drawVertexUniforms:{...s,skipSelected:1,skipUnselected:0},drawFragmentUniforms:o}),this.drawCommand.setBindings({positionsTexture:this.currentPositionTexture,pointGreyoutStatus:this.greyoutStatusTexture,imageAtlasTexture:this.imageAtlasTexture,imageAtlasCoords:this.imageAtlasCoordsTexture}),this.drawCommand.draw(e),this.drawUniformStore.setUniforms({drawVertexUniforms:{...s,skipSelected:0,skipUnselected:1},drawFragmentUniforms:o}),this.drawCommand.setBindings({positionsTexture:this.currentPositionTexture,pointGreyoutStatus:this.greyoutStatusTexture,imageAtlasTexture:this.imageAtlasTexture,imageAtlasCoords:this.imageAtlasCoordsTexture}),this.drawCommand.draw(e)):(this.drawUniformStore.setUniforms({drawVertexUniforms:{...s,skipSelected:0,skipUnselected:0},drawFragmentUniforms:o}),this.drawCommand.setBindings({positionsTexture:this.currentPositionTexture,pointGreyoutStatus:this.greyoutStatusTexture,imageAtlasTexture:this.imageAtlasTexture,imageAtlasCoords:this.imageAtlasCoordsTexture}),this.drawCommand.draw(e)),i.renderHoveredPointRing&&r.hoveredPoint&&this.drawHighlightedCommand&&this.drawHighlightedUniformStore){if(!this.currentPositionTexture||this.currentPositionTexture.destroyed||!this.greyoutStatusTexture||this.greyoutStatusTexture.destroyed)return;const c=((a=t.pointSizes)==null?void 0:a[r.hoveredPoint.index])??1;this.drawHighlightedUniformStore.setUniforms({drawHighlightedUniforms:{size:c,transformationMatrix:r.transformationMatrix4x4,pointsTextureSize:r.pointsTextureSize??0,sizeScale:i.pointSizeScale??1,spaceSize:r.adjustedSpaceSize??0,screenSize:re(r.screenSize,[0,0]),scalePointsOnZoom:i.scalePointsOnZoom??!0?1:0,pointIndex:r.hoveredPoint.index,maxPointSize:r.maxPointSize??100,color:Re(r.hoveredPointRingColor,[0,0,0,1]),universalPointOpacity:i.pointOpacity??1,greyoutOpacity:i.pointGreyoutOpacity??-1,isDarkenGreyout:r.isDarkenGreyout??!1?1:0,backgroundColor:Re(r.backgroundColor,[0,0,0,1]),greyoutColor:Re(r.greyoutPointColor,[0,0,0,1]),width:.85}}),this.drawHighlightedCommand.setBindings({positionsTexture:this.currentPositionTexture,pointGreyoutStatusTexture:this.greyoutStatusTexture}),this.drawHighlightedCommand.draw(e)}if(r.focusedPoint&&this.drawHighlightedCommand&&this.drawHighlightedUniformStore){if(!this.currentPositionTexture||this.currentPositionTexture.destroyed||!this.greyoutStatusTexture||this.greyoutStatusTexture.destroyed)return;const c=((l=t.pointSizes)==null?void 0:l[r.focusedPoint.index])??1;this.drawHighlightedUniformStore.setUniforms({drawHighlightedUniforms:{size:c,transformationMatrix:r.transformationMatrix4x4,pointsTextureSize:r.pointsTextureSize??0,sizeScale:i.pointSizeScale??1,spaceSize:r.adjustedSpaceSize??0,screenSize:re(r.screenSize,[0,0]),scalePointsOnZoom:i.scalePointsOnZoom??!0?1:0,pointIndex:r.focusedPoint.index,maxPointSize:r.maxPointSize??100,color:Re(r.focusedPointRingColor,[0,0,0,1]),universalPointOpacity:i.pointOpacity??1,greyoutOpacity:i.pointGreyoutOpacity??-1,isDarkenGreyout:r.isDarkenGreyout??!1?1:0,backgroundColor:Re(r.backgroundColor,[0,0,0,1]),greyoutColor:Re(r.greyoutPointColor,[0,0,0,1]),width:.85}}),this.drawHighlightedCommand.setBindings({positionsTexture:this.currentPositionTexture,pointGreyoutStatusTexture:this.greyoutStatusTexture}),this.drawHighlightedCommand.draw(e)}}updatePosition(){if(!this.updatePositionCommand||!this.updatePositionUniformStore||!this.currentPositionFbo||this.currentPositionFbo.destroyed||!this.previousPositionTexture||this.previousPositionTexture.destroyed||!this.velocityTexture||this.velocityTexture.destroyed||!this.pinnedStatusTexture||this.pinnedStatusTexture.destroyed)return;this.updatePositionUniformStore.setUniforms({updatePositionUniforms:{friction:this.config.simulationFriction??0,spaceSize:this.store.adjustedSpaceSize??0}}),this.updatePositionCommand.setBindings({positionsTexture:this.previousPositionTexture,velocity:this.velocityTexture,pinnedStatusTexture:this.pinnedStatusTexture});const e=this.device.beginRenderPass({framebuffer:this.currentPositionFbo});this.updatePositionCommand.draw(e),e.end(),this.swapFbo(),this.isPositionsUpToDate=!1}drag(){var t;if(!this.dragPointCommand||!this.dragPointUniformStore||!this.currentPositionFbo||this.currentPositionFbo.destroyed||!this.previousPositionTexture||this.previousPositionTexture.destroyed)return;this.dragPointUniformStore.setUniforms({dragPointUniforms:{mousePos:re(this.store.mousePosition,[0,0]),index:((t=this.store.hoveredPoint)==null?void 0:t.index)??-1}}),this.dragPointCommand.setBindings({positionsTexture:this.previousPositionTexture});const e=this.device.beginRenderPass({framebuffer:this.currentPositionFbo});this.dragPointCommand.draw(e),e.end(),this.swapFbo(),this.isPositionsUpToDate=!1}findPointsOnAreaSelection(){var t,i;if(!this.findPointsOnAreaSelectionCommand||!this.findPointsOnAreaSelectionUniformStore||!this.selectedFbo||this.selectedFbo.destroyed||!this.currentPositionTexture||this.currentPositionTexture.destroyed||!this.sizeTexture||this.sizeTexture.destroyed)return;this.findPointsOnAreaSelectionUniformStore.setUniforms({findPointsOnAreaSelectionUniforms:{spaceSize:this.store.adjustedSpaceSize??0,screenSize:re(this.store.screenSize,[0,0]),sizeScale:this.config.pointSizeScale??1,transformationMatrix:this.store.transformationMatrix4x4,ratio:this.config.pixelRatio??V.pixelRatio,selection0:re((t=this.store.selectedArea)==null?void 0:t[0],[0,0]),selection1:re((i=this.store.selectedArea)==null?void 0:i[1],[0,0]),scalePointsOnZoom:this.config.scalePointsOnZoom??!0?1:0,maxPointSize:this.store.maxPointSize??100}}),this.findPointsOnAreaSelectionCommand.setBindings({positionsTexture:this.currentPositionTexture,pointSize:this.sizeTexture});const e=this.device.beginRenderPass({framebuffer:this.selectedFbo});this.findPointsOnAreaSelectionCommand.draw(e),e.end()}findPointsOnPolygonSelection(){if(!this.findPointsOnPolygonSelectionCommand||!this.findPointsOnPolygonSelectionUniformStore||!this.selectedFbo||this.selectedFbo.destroyed||!this.currentPositionTexture||this.currentPositionTexture.destroyed||!this.polygonPathTexture||this.polygonPathTexture.destroyed)return;this.findPointsOnPolygonSelectionUniformStore.setUniforms({findPointsOnPolygonSelectionUniforms:{spaceSize:this.store.adjustedSpaceSize??0,screenSize:re(this.store.screenSize,[0,0]),transformationMatrix:this.store.transformationMatrix4x4,polygonPathLength:this.polygonPathLength}}),this.findPointsOnPolygonSelectionCommand.setBindings({positionsTexture:this.currentPositionTexture,polygonPathTexture:this.polygonPathTexture});const e=this.device.beginRenderPass({framebuffer:this.selectedFbo});this.findPointsOnPolygonSelectionCommand.draw(e),e.end()}updatePolygonPath(e){const{device:t}=this;if(this.polygonPathLength=e.length,e.length===0){this.polygonPathTexture&&!this.polygonPathTexture.destroyed&&this.polygonPathTexture.destroy(),this.polygonPathTexture=void 0;return}const i=Math.ceil(Math.sqrt(e.length)),r=new Float32Array(i*i*4);for(const[s,o]of e.entries()){const[a,l]=o;r[s*4]=a,r[s*4+1]=l,r[s*4+2]=0,r[s*4+3]=0}!this.polygonPathTexture||this.polygonPathTexture.width!==i||this.polygonPathTexture.height!==i?(this.polygonPathTexture&&!this.polygonPathTexture.destroyed&&this.polygonPathTexture.destroy(),this.polygonPathTexture=t.createTexture({width:i,height:i,format:"rgba32float"}),this.polygonPathTexture.copyImageData({data:r,bytesPerRow:ne("rgba32float",i),mipLevel:0,x:0,y:0})):this.polygonPathTexture.copyImageData({data:r,bytesPerRow:ne("rgba32float",i),mipLevel:0,x:0,y:0})}findHoveredPoint(){if(!this.hoveredFbo||this.hoveredFbo.destroyed||!this.findHoveredPointCommand||!this.findHoveredPointUniformStore||!this.currentPositionTexture||this.currentPositionTexture.destroyed||(this.greyoutStatusTexture||this.updateGreyoutStatus(),!this.greyoutStatusTexture||this.greyoutStatusTexture.destroyed))return;this.findHoveredPointCommand.setVertexCount(this.data.pointsNumber??0),this.findHoveredPointCommand.setAttributes({...this.hoveredPointIndices&&{pointIndices:this.hoveredPointIndices},...this.sizeBuffer&&{size:this.sizeBuffer}});const e={ratio:this.config.pixelRatio??V.pixelRatio,sizeScale:this.config.pointSizeScale??1,pointsTextureSize:this.store.pointsTextureSize??0,transformationMatrix:this.store.transformationMatrix4x4,spaceSize:this.store.adjustedSpaceSize??0,screenSize:re(this.store.screenSize,[0,0]),scalePointsOnZoom:this.config.scalePointsOnZoom??!0?1:0,mousePosition:re(this.store.screenMousePosition,[0,0]),maxPointSize:this.store.maxPointSize??100},t={positionsTexture:this.currentPositionTexture,pointGreyoutStatus:this.greyoutStatusTexture},i=this.device.beginRenderPass({framebuffer:this.hoveredFbo,clearColor:[0,0,0,0]});this.store.selectedIndices&&this.store.selectedIndices.length>0?(this.findHoveredPointUniformStore.setUniforms({findHoveredPointUniforms:{...e,skipSelected:1,skipUnselected:0}}),this.findHoveredPointCommand.setBindings(t),this.findHoveredPointCommand.draw(i),this.findHoveredPointUniformStore.setUniforms({findHoveredPointUniforms:{...e,skipSelected:0,skipUnselected:1}}),this.findHoveredPointCommand.setBindings(t),this.findHoveredPointCommand.draw(i)):(this.findHoveredPointUniformStore.setUniforms({findHoveredPointUniforms:{...e,skipSelected:0,skipUnselected:0}}),this.findHoveredPointCommand.setBindings(t),this.findHoveredPointCommand.draw(i)),i.end()}trackPointsByIndices(e){const{store:{pointsTextureSize:t},device:i}=this;if(this.trackedIndices=e,this.trackedPositions=void 0,this.isPositionsUpToDate=!1,!(e!=null&&e.length)||!t)return;const r=Math.ceil(Math.sqrt(e.length)),s=new Float32Array(r*r*4).fill(-1);for(const[o,a]of e.entries())a!==void 0&&(s[o*4]=a%t,s[o*4+1]=Math.floor(a/t),s[o*4+2]=0,s[o*4+3]=0);!this.trackedIndicesTexture||this.trackedIndicesTexture.width!==r||this.trackedIndicesTexture.height!==r?(this.trackedIndicesTexture&&!this.trackedIndicesTexture.destroyed&&this.trackedIndicesTexture.destroy(),this.trackedIndicesTexture=i.createTexture({width:r,height:r,format:"rgba32float"}),this.trackedIndicesTexture.copyImageData({data:s,bytesPerRow:ne("rgba32float",r),mipLevel:0,x:0,y:0})):this.trackedIndicesTexture.copyImageData({data:s,bytesPerRow:ne("rgba32float",r),mipLevel:0,x:0,y:0}),(!this.trackedPositionsFbo||this.trackedPositionsFbo.width!==r||this.trackedPositionsFbo.height!==r)&&(this.trackedPositionsFbo&&!this.trackedPositionsFbo.destroyed&&this.trackedPositionsFbo.destroy(),this.trackedPositionsFbo=i.createFramebuffer({width:r,height:r,colorAttachments:["rgba32float"]})),this.trackPoints()}getTrackedPositionsMap(){if(!this.trackedIndices)return new Map;const{config:{enableSimulation:e},store:{isSimulationRunning:t}}=this;if((!e||!t)&&this.isPositionsUpToDate&&this.trackedPositions)return this.trackedPositions;if(!this.trackedPositionsFbo||this.trackedPositionsFbo.destroyed)return new Map;const i=Xe(this.device,this.trackedPositionsFbo),r=new Map;for(let s=0;s<i.length/4;s+=1){const o=i[s*4],a=i[s*4+1],l=this.trackedIndices[s];o!==void 0&&a!==void 0&&l!==void 0&&r.set(l,[o,a])}return(!e||!t)&&(this.trackedPositions=r,this.isPositionsUpToDate=!0),r}getSampledPointPositionsMap(){const e=new Map;if(!this.sampledPointsFbo||this.sampledPointsFbo.destroyed)return e;if(this.fillSampledPointsFboCommand&&this.fillSampledPointsUniformStore&&this.sampledPointsFbo){if(!this.currentPositionTexture||this.currentPositionTexture.destroyed)return e;this.fillSampledPointsFboCommand.setVertexCount(this.data.pointsNumber??0),this.fillSampledPointsUniformStore.setUniforms({fillSampledPointsUniforms:{pointsTextureSize:this.store.pointsTextureSize??0,transformationMatrix:this.store.transformationMatrix4x4,spaceSize:this.store.adjustedSpaceSize??0,screenSize:re(this.store.screenSize,[0,0])}}),this.fillSampledPointsFboCommand.setBindings({positionsTexture:this.currentPositionTexture});const i=this.device.beginRenderPass({framebuffer:this.sampledPointsFbo,clearColor:[0,0,0,0]});this.fillSampledPointsFboCommand.draw(i),i.end()}const t=Xe(this.device,this.sampledPointsFbo);for(let i=0;i<t.length/4;i++){const r=t[i*4],s=!!t[i*4+1],o=t[i*4+2],a=t[i*4+3];s&&r!==void 0&&o!==void 0&&a!==void 0&&e.set(r,[o,a])}return e}getSampledPoints(){const e=[],t=[];if(!this.sampledPointsFbo||this.sampledPointsFbo.destroyed)return{indices:e,positions:t};if(this.fillSampledPointsFboCommand&&this.fillSampledPointsUniformStore&&this.sampledPointsFbo){if(!this.currentPositionTexture||this.currentPositionTexture.destroyed)return{indices:e,positions:t};this.fillSampledPointsFboCommand.setVertexCount(this.data.pointsNumber??0),this.fillSampledPointsUniformStore.setUniforms({fillSampledPointsUniforms:{pointsTextureSize:this.store.pointsTextureSize??0,transformationMatrix:this.store.transformationMatrix4x4,spaceSize:this.store.adjustedSpaceSize??0,screenSize:re(this.store.screenSize,[0,0])}}),this.fillSampledPointsFboCommand.setBindings({positionsTexture:this.currentPositionTexture});const r=this.device.beginRenderPass({framebuffer:this.sampledPointsFbo,clearColor:[0,0,0,0]});this.fillSampledPointsFboCommand.draw(r),r.end()}const i=Xe(this.device,this.sampledPointsFbo);for(let r=0;r<i.length/4;r++){const s=i[r*4],o=!!i[r*4+1],a=i[r*4+2],l=i[r*4+3];o&&s!==void 0&&a!==void 0&&l!==void 0&&(e.push(s),t.push(a,l))}return{indices:e,positions:t}}getTrackedPositionsArray(){const e=[];if(!this.trackedIndices||!this.trackedPositionsFbo||this.trackedPositionsFbo.destroyed)return e;e.length=this.trackedIndices.length*2;const t=Xe(this.device,this.trackedPositionsFbo);for(let i=0;i<t.length/4;i+=1){const r=t[i*4],s=t[i*4+1],o=this.trackedIndices[i];r!==void 0&&s!==void 0&&o!==void 0&&(e[i*2]=r,e[i*2+1]=s)}return e}destroy(){var e,t,i,r,s,o,a,l,c,u,f,h,d,_,I,P,A,O;(e=this.drawCommand)==null||e.destroy(),this.drawCommand=void 0,(t=this.drawHighlightedCommand)==null||t.destroy(),this.drawHighlightedCommand=void 0,(i=this.updatePositionCommand)==null||i.destroy(),this.updatePositionCommand=void 0,(r=this.dragPointCommand)==null||r.destroy(),this.dragPointCommand=void 0,(s=this.findPointsOnAreaSelectionCommand)==null||s.destroy(),this.findPointsOnAreaSelectionCommand=void 0,(o=this.findPointsOnPolygonSelectionCommand)==null||o.destroy(),this.findPointsOnPolygonSelectionCommand=void 0,(a=this.findHoveredPointCommand)==null||a.destroy(),this.findHoveredPointCommand=void 0,(l=this.fillSampledPointsFboCommand)==null||l.destroy(),this.fillSampledPointsFboCommand=void 0,(c=this.trackPointsCommand)==null||c.destroy(),this.trackPointsCommand=void 0,this.currentPositionFbo&&!this.currentPositionFbo.destroyed&&this.currentPositionFbo.destroy(),this.currentPositionFbo=void 0,this.previousPositionFbo&&!this.previousPositionFbo.destroyed&&this.previousPositionFbo.destroy(),this.previousPositionFbo=void 0,this.velocityFbo&&!this.velocityFbo.destroyed&&this.velocityFbo.destroy(),this.velocityFbo=void 0,this.selectedFbo&&!this.selectedFbo.destroyed&&this.selectedFbo.destroy(),this.selectedFbo=void 0,this.hoveredFbo&&!this.hoveredFbo.destroyed&&this.hoveredFbo.destroy(),this.hoveredFbo=void 0,this.trackedPositionsFbo&&!this.trackedPositionsFbo.destroyed&&this.trackedPositionsFbo.destroy(),this.trackedPositionsFbo=void 0,this.sampledPointsFbo&&!this.sampledPointsFbo.destroyed&&this.sampledPointsFbo.destroy(),this.sampledPointsFbo=void 0,this.currentPositionTexture&&!this.currentPositionTexture.destroyed&&this.currentPositionTexture.destroy(),this.currentPositionTexture=void 0,this.previousPositionTexture&&!this.previousPositionTexture.destroyed&&this.previousPositionTexture.destroy(),this.previousPositionTexture=void 0,this.velocityTexture&&!this.velocityTexture.destroyed&&this.velocityTexture.destroy(),this.velocityTexture=void 0,this.selectedTexture&&!this.selectedTexture.destroyed&&this.selectedTexture.destroy(),this.selectedTexture=void 0,this.greyoutStatusTexture&&!this.greyoutStatusTexture.destroyed&&this.greyoutStatusTexture.destroy(),this.greyoutStatusTexture=void 0,this.sizeTexture&&!this.sizeTexture.destroyed&&this.sizeTexture.destroy(),this.sizeTexture=void 0,this.trackedIndicesTexture&&!this.trackedIndicesTexture.destroyed&&this.trackedIndicesTexture.destroy(),this.trackedIndicesTexture=void 0,this.polygonPathTexture&&!this.polygonPathTexture.destroyed&&this.polygonPathTexture.destroy(),this.polygonPathTexture=void 0,this.imageAtlasTexture&&!this.imageAtlasTexture.destroyed&&this.imageAtlasTexture.destroy(),this.imageAtlasTexture=void 0,this.imageAtlasCoordsTexture&&!this.imageAtlasCoordsTexture.destroyed&&this.imageAtlasCoordsTexture.destroy(),this.imageAtlasCoordsTexture=void 0,this.pinnedStatusTexture&&!this.pinnedStatusTexture.destroyed&&this.pinnedStatusTexture.destroy(),this.pinnedStatusTexture=void 0,(u=this.updatePositionUniformStore)==null||u.destroy(),this.updatePositionUniformStore=void 0,(f=this.dragPointUniformStore)==null||f.destroy(),this.dragPointUniformStore=void 0,(h=this.drawUniformStore)==null||h.destroy(),this.drawUniformStore=void 0,(d=this.findPointsOnAreaSelectionUniformStore)==null||d.destroy(),this.findPointsOnAreaSelectionUniformStore=void 0,(_=this.findPointsOnPolygonSelectionUniformStore)==null||_.destroy(),this.findPointsOnPolygonSelectionUniformStore=void 0,(I=this.findHoveredPointUniformStore)==null||I.destroy(),this.findHoveredPointUniformStore=void 0,(P=this.fillSampledPointsUniformStore)==null||P.destroy(),this.fillSampledPointsUniformStore=void 0,(A=this.drawHighlightedUniformStore)==null||A.destroy(),this.drawHighlightedUniformStore=void 0,(O=this.trackPointsUniformStore)==null||O.destroy(),this.trackPointsUniformStore=void 0,this.colorBuffer&&!this.colorBuffer.destroyed&&this.colorBuffer.destroy(),this.colorBuffer=void 0,this.sizeBuffer&&!this.sizeBuffer.destroyed&&this.sizeBuffer.destroy(),this.sizeBuffer=void 0,this.shapeBuffer&&!this.shapeBuffer.destroyed&&this.shapeBuffer.destroy(),this.shapeBuffer=void 0,this.imageIndicesBuffer&&!this.imageIndicesBuffer.destroyed&&this.imageIndicesBuffer.destroy(),this.imageIndicesBuffer=void 0,this.imageSizesBuffer&&!this.imageSizesBuffer.destroyed&&this.imageSizesBuffer.destroy(),this.imageSizesBuffer=void 0,this.drawPointIndices&&!this.drawPointIndices.destroyed&&this.drawPointIndices.destroy(),this.drawPointIndices=void 0,this.hoveredPointIndices&&!this.hoveredPointIndices.destroyed&&this.hoveredPointIndices.destroy(),this.hoveredPointIndices=void 0,this.sampledPointIndices&&!this.sampledPointIndices.destroyed&&this.sampledPointIndices.destroy(),this.sampledPointIndices=void 0,this.updatePositionVertexCoordBuffer&&!this.updatePositionVertexCoordBuffer.destroyed&&this.updatePositionVertexCoordBuffer.destroy(),this.updatePositionVertexCoordBuffer=void 0,this.dragPointVertexCoordBuffer&&!this.dragPointVertexCoordBuffer.destroyed&&this.dragPointVertexCoordBuffer.destroy(),this.dragPointVertexCoordBuffer=void 0,this.findPointsOnAreaSelectionVertexCoordBuffer&&!this.findPointsOnAreaSelectionVertexCoordBuffer.destroyed&&this.findPointsOnAreaSelectionVertexCoordBuffer.destroy(),this.findPointsOnAreaSelectionVertexCoordBuffer=void 0,this.findPointsOnPolygonSelectionVertexCoordBuffer&&!this.findPointsOnPolygonSelectionVertexCoordBuffer.destroyed&&this.findPointsOnPolygonSelectionVertexCoordBuffer.destroy(),this.findPointsOnPolygonSelectionVertexCoordBuffer=void 0,this.drawHighlightedVertexCoordBuffer&&!this.drawHighlightedVertexCoordBuffer.destroyed&&this.drawHighlightedVertexCoordBuffer.destroy(),this.drawHighlightedVertexCoordBuffer=void 0,this.trackPointsVertexCoordBuffer&&!this.trackPointsVertexCoordBuffer.destroyed&&this.trackPointsVertexCoordBuffer.destroy(),this.trackPointsVertexCoordBuffer=void 0}swapFbo(){if(!this.currentPositionTexture||this.currentPositionTexture.destroyed||!this.previousPositionTexture||this.previousPositionTexture.destroyed||!this.currentPositionFbo||this.currentPositionFbo.destroyed||!this.previousPositionFbo||this.previousPositionFbo.destroyed)return;const e=this.previousPositionTexture,t=this.previousPositionFbo;this.previousPositionTexture=this.currentPositionTexture,this.previousPositionFbo=this.currentPositionFbo,this.currentPositionTexture=e,this.currentPositionFbo=t}rescaleInitialNodePositions(){const{config:{spaceSize:e}}=this;if(!this.data.pointPositions||!e)return;const t=this.data.pointPositions,i=t.length/2;let r=1/0,s=-1/0,o=1/0,a=-1/0;for(let A=0;A<t.length;A+=2){const O=t[A],E=t[A+1];r=Math.min(r,O),s=Math.max(s,O),o=Math.min(o,E),a=Math.max(a,E)}const l=s-r,c=a-o,u=Math.max(l,c);if(u>e){this.scaleX=void 0,this.scaleY=void 0;return}const f=e*e*.001,h=i>f?e*Math.max(1.2,Math.sqrt(i)/e):e*.1,d=h/u,_=(e-h)/2,I=(u-l)/2*d+_,P=(u-c)/2*d+_;this.scaleX=A=>(A-r)*d+I,this.scaleY=A=>(A-o)*d+P;for(let A=0;A<i;A++)this.data.pointPositions[A*2]=this.scaleX(t[A*2]),this.data.pointPositions[A*2+1]=this.scaleY(t[A*2+1])}}const kv={passive:!1},ei={capture:!0,passive:!1};function Po(n){n.stopImmediatePropagation()}function xn(n){n.preventDefault(),n.stopImmediatePropagation()}function yu(n){var e=n.document.documentElement,t=we(n).on("dragstart.drag",xn,ei);"onselectstart"in e?t.on("selectstart.drag",xn,ei):(e.__noselect=e.style.MozUserSelect,e.style.MozUserSelect="none")}function xu(n,e){var t=n.document.documentElement,i=we(n).on("dragstart.drag",null);e&&(i.on("click.drag",xn,ei),setTimeout(function(){i.on("click.drag",null)},0)),"onselectstart"in t?i.on("selectstart.drag",null):(t.style.MozUserSelect=t.__noselect,delete t.__noselect)}const xr=n=>()=>n;function Eo(n,{sourceEvent:e,subject:t,target:i,identifier:r,active:s,x:o,y:a,dx:l,dy:c,dispatch:u}){Object.defineProperties(this,{type:{value:n,enumerable:!0,configurable:!0},sourceEvent:{value:e,enumerable:!0,configurable:!0},subject:{value:t,enumerable:!0,configurable:!0},target:{value:i,enumerable:!0,configurable:!0},identifier:{value:r,enumerable:!0,configurable:!0},active:{value:s,enumerable:!0,configurable:!0},x:{value:o,enumerable:!0,configurable:!0},y:{value:a,enumerable:!0,configurable:!0},dx:{value:l,enumerable:!0,configurable:!0},dy:{value:c,enumerable:!0,configurable:!0},_:{value:u}})}Eo.prototype.on=function(){var n=this._.on.apply(this._,arguments);return n===this._?this:n};function Dv(n){return!n.ctrlKey&&!n.button}function Mv(){return this.parentNode}function Fv(n,e){return e??{x:n.x,y:n.y}}function Nv(){return navigator.maxTouchPoints||"ontouchstart"in this}function Ov(){var n=Dv,e=Mv,t=Fv,i=Nv,r={},s=ui("start","drag","end"),o=0,a,l,c,u,f=0;function h(y){y.on("mousedown.drag",d).filter(i).on("touchstart.drag",P).on("touchmove.drag",A,kv).on("touchend.drag touchcancel.drag",O).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function d(y,R){if(!(u||!n.call(this,y,R))){var N=E(this,e.call(this,y,R),y,R,"mouse");N&&(we(y.view).on("mousemove.drag",_,ei).on("mouseup.drag",I,ei),yu(y.view),Po(y),c=!1,a=y.clientX,l=y.clientY,N("start",y))}}function _(y){if(xn(y),!c){var R=y.clientX-a,N=y.clientY-l;c=R*R+N*N>f}r.mouse("drag",y)}function I(y){we(y.view).on("mousemove.drag mouseup.drag",null),xu(y.view,c),xn(y),r.mouse("end",y)}function P(y,R){if(n.call(this,y,R)){var N=y.changedTouches,U=e.call(this,y,R),W=N.length,q,G;for(q=0;q<W;++q)(G=E(this,U,y,R,N[q].identifier,N[q]))&&(Po(y),G("start",y,N[q]))}}function A(y){var R=y.changedTouches,N=R.length,U,W;for(U=0;U<N;++U)(W=r[R[U].identifier])&&(xn(y),W("drag",y,R[U]))}function O(y){var R=y.changedTouches,N=R.length,U,W;for(u&&clearTimeout(u),u=setTimeout(function(){u=null},500),U=0;U<N;++U)(W=r[R[U].identifier])&&(Po(y),W("end",y,R[U]))}function E(y,R,N,U,W,q){var G=s.copy(),B=xt(q||N,R),he,ie,C;if((C=t.call(y,new Eo("beforestart",{sourceEvent:N,target:h,identifier:W,active:o,x:B[0],y:B[1],dx:0,dy:0,dispatch:G}),U))!=null)return he=C.x-B[0]||0,ie=C.y-B[1]||0,function H(M,$,Z){var j=B,ee;switch(M){case"start":r[W]=H,ee=o++;break;case"end":delete r[W],--o;case"drag":B=xt(Z||$,R),ee=o;break}G.call(M,y,new Eo(M,{sourceEvent:$,subject:C,target:h,identifier:W,active:ee,x:B[0]+he,y:B[1]+ie,dx:B[0]-j[0],dy:B[1]-j[1],dispatch:G}),U)}}return h.filter=function(y){return arguments.length?(n=typeof y=="function"?y:xr(!!y),h):n},h.container=function(y){return arguments.length?(e=typeof y=="function"?y:xr(y),h):e},h.subject=function(y){return arguments.length?(t=typeof y=="function"?y:xr(y),h):t},h.touchable=function(y){return arguments.length?(i=typeof y=="function"?y:xr(!!y),h):i},h.on=function(){var y=s.on.apply(s,arguments);return y===s?h:y},h.clickDistance=function(y){return arguments.length?(f=(y=+y)*y,h):Math.sqrt(f)},h}const vr=n=>()=>n;function Bv(n,{sourceEvent:e,target:t,transform:i,dispatch:r}){Object.defineProperties(this,{type:{value:n,enumerable:!0,configurable:!0},sourceEvent:{value:e,enumerable:!0,configurable:!0},target:{value:t,enumerable:!0,configurable:!0},transform:{value:i,enumerable:!0,configurable:!0},_:{value:r}})}function It(n,e,t){this.k=n,this.x=e,this.y=t}It.prototype={constructor:It,scale:function(n){return n===1?this:new It(this.k*n,this.x,this.y)},translate:function(n,e){return n===0&e===0?this:new It(this.k,this.x+this.k*n,this.y+this.k*e)},apply:function(n){return[n[0]*this.k+this.x,n[1]*this.k+this.y]},applyX:function(n){return n*this.k+this.x},applyY:function(n){return n*this.k+this.y},invert:function(n){return[(n[0]-this.x)/this.k,(n[1]-this.y)/this.k]},invertX:function(n){return(n-this.x)/this.k},invertY:function(n){return(n-this.y)/this.k},rescaleX:function(n){return n.copy().domain(n.range().map(this.invertX,this).map(n.invert,n))},rescaleY:function(n){return n.copy().domain(n.range().map(this.invertY,this).map(n.invert,n))},toString:function(){return"translate("+this.x+","+this.y+") scale("+this.k+")"}};var ti=new It(1,0,0);It.prototype;function Ro(n){n.stopImmediatePropagation()}function ni(n){n.preventDefault(),n.stopImmediatePropagation()}function Uv(n){return(!n.ctrlKey||n.type==="wheel")&&!n.button}function zv(){var n=this;return n instanceof SVGElement?(n=n.ownerSVGElement||n,n.hasAttribute("viewBox")?(n=n.viewBox.baseVal,[[n.x,n.y],[n.x+n.width,n.y+n.height]]):[[0,0],[n.width.baseVal.value,n.height.baseVal.value]]):[[0,0],[n.clientWidth,n.clientHeight]]}function vu(){return this.__zoom||ti}function Lv(n){return-n.deltaY*(n.deltaMode===1?.05:n.deltaMode?1:.002)*(n.ctrlKey?10:1)}function Vv(){return navigator.maxTouchPoints||"ontouchstart"in this}function Hv(n,e,t){var i=n.invertX(e[0][0])-t[0][0],r=n.invertX(e[1][0])-t[1][0],s=n.invertY(e[0][1])-t[0][1],o=n.invertY(e[1][1])-t[1][1];return n.translate(r>i?(i+r)/2:Math.min(0,i)||Math.max(0,r),o>s?(s+o)/2:Math.min(0,s)||Math.max(0,o))}function Wv(){var n=Uv,e=zv,t=Hv,i=Lv,r=Vv,s=[0,1/0],o=[[-1/0,-1/0],[1/0,1/0]],a=250,l=ld,c=ui("start","zoom","end"),u,f,h,d=500,_=150,I=0,P=10;function A(C){C.property("__zoom",vu).on("wheel.zoom",W,{passive:!1}).on("mousedown.zoom",q).on("dblclick.zoom",G).filter(r).on("touchstart.zoom",B).on("touchmove.zoom",he).on("touchend.zoom touchcancel.zoom",ie).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}A.transform=function(C,H,M,$){var Z=C.selection?C.selection():C;Z.property("__zoom",vu),C!==Z?R(C,H,M,$):Z.interrupt().each(function(){N(this,arguments).event($).start().zoom(null,typeof H=="function"?H.apply(this,arguments):H).end()})},A.scaleBy=function(C,H,M,$){A.scaleTo(C,function(){var Z=this.__zoom.k,j=typeof H=="function"?H.apply(this,arguments):H;return Z*j},M,$)},A.scaleTo=function(C,H,M,$){A.transform(C,function(){var Z=e.apply(this,arguments),j=this.__zoom,ee=M==null?y(Z):typeof M=="function"?M.apply(this,arguments):M,J=j.invert(ee),ge=typeof H=="function"?H.apply(this,arguments):H;return t(E(O(j,ge),ee,J),Z,o)},M,$)},A.translateBy=function(C,H,M,$){A.transform(C,function(){return t(this.__zoom.translate(typeof H=="function"?H.apply(this,arguments):H,typeof M=="function"?M.apply(this,arguments):M),e.apply(this,arguments),o)},null,$)},A.translateTo=function(C,H,M,$,Z){A.transform(C,function(){var j=e.apply(this,arguments),ee=this.__zoom,J=$==null?y(j):typeof $=="function"?$.apply(this,arguments):$;return t(ti.translate(J[0],J[1]).scale(ee.k).translate(typeof H=="function"?-H.apply(this,arguments):-H,typeof M=="function"?-M.apply(this,arguments):-M),j,o)},$,Z)};function O(C,H){return H=Math.max(s[0],Math.min(s[1],H)),H===C.k?C:new It(H,C.x,C.y)}function E(C,H,M){var $=H[0]-M[0]*C.k,Z=H[1]-M[1]*C.k;return $===C.x&&Z===C.y?C:new It(C.k,$,Z)}function y(C){return[(+C[0][0]+ +C[1][0])/2,(+C[0][1]+ +C[1][1])/2]}function R(C,H,M,$){C.on("start.zoom",function(){N(this,arguments).event($).start()}).on("interrupt.zoom end.zoom",function(){N(this,arguments).event($).end()}).tween("zoom",function(){var Z=this,j=arguments,ee=N(Z,j).event($),J=e.apply(Z,j),ge=M==null?y(J):typeof M=="function"?M.apply(Z,j):M,ue=Math.max(J[1][0]-J[0][0],J[1][1]-J[0][1]),Te=Z.__zoom,se=typeof H=="function"?H.apply(Z,j):H,He=l(Te.invert(ge).concat(ue/Te.k),se.invert(ge).concat(ue/se.k));return function(We){if(We===1)We=se;else{var nt=He(We),Gt=ue/nt[2];We=new It(Gt,ge[0]-nt[0]*Gt,ge[1]-nt[1]*Gt)}ee.zoom(null,We)}})}function N(C,H,M){return!M&&C.__zooming||new U(C,H)}function U(C,H){this.that=C,this.args=H,this.active=0,this.sourceEvent=null,this.extent=e.apply(C,H),this.taps=0}U.prototype={event:function(C){return C&&(this.sourceEvent=C),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(C,H){return this.mouse&&C!=="mouse"&&(this.mouse[1]=H.invert(this.mouse[0])),this.touch0&&C!=="touch"&&(this.touch0[1]=H.invert(this.touch0[0])),this.touch1&&C!=="touch"&&(this.touch1[1]=H.invert(this.touch1[0])),this.that.__zoom=H,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(C){var H=we(this.that).datum();c.call(C,this.that,new Bv(C,{sourceEvent:this.sourceEvent,target:A,transform:this.that.__zoom,dispatch:c}),H)}};function W(C,...H){if(!n.apply(this,arguments))return;var M=N(this,H).event(C),$=this.__zoom,Z=Math.max(s[0],Math.min(s[1],$.k*Math.pow(2,i.apply(this,arguments)))),j=xt(C);if(M.wheel)(M.mouse[0][0]!==j[0]||M.mouse[0][1]!==j[1])&&(M.mouse[1]=$.invert(M.mouse[0]=j)),clearTimeout(M.wheel);else{if($.k===Z)return;M.mouse=[j,$.invert(j)],xi(this),M.start()}ni(C),M.wheel=setTimeout(ee,_),M.zoom("mouse",t(E(O($,Z),M.mouse[0],M.mouse[1]),M.extent,o));function ee(){M.wheel=null,M.end()}}function q(C,...H){if(h||!n.apply(this,arguments))return;var M=C.currentTarget,$=N(this,H,!0).event(C),Z=we(C.view).on("mousemove.zoom",ge,!0).on("mouseup.zoom",ue,!0),j=xt(C,M),ee=C.clientX,J=C.clientY;yu(C.view),Ro(C),$.mouse=[j,this.__zoom.invert(j)],xi(this),$.start();function ge(Te){if(ni(Te),!$.moved){var se=Te.clientX-ee,He=Te.clientY-J;$.moved=se*se+He*He>I}$.event(Te).zoom("mouse",t(E($.that.__zoom,$.mouse[0]=xt(Te,M),$.mouse[1]),$.extent,o))}function ue(Te){Z.on("mousemove.zoom mouseup.zoom",null),xu(Te.view,$.moved),ni(Te),$.event(Te).end()}}function G(C,...H){if(n.apply(this,arguments)){var M=this.__zoom,$=xt(C.changedTouches?C.changedTouches[0]:C,this),Z=M.invert($),j=M.k*(C.shiftKey?.5:2),ee=t(E(O(M,j),$,Z),e.apply(this,H),o);ni(C),a>0?we(this).transition().duration(a).call(R,ee,$,C):we(this).call(A.transform,ee,$,C)}}function B(C,...H){if(n.apply(this,arguments)){var M=C.touches,$=M.length,Z=N(this,H,C.changedTouches.length===$).event(C),j,ee,J,ge;for(Ro(C),ee=0;ee<$;++ee)J=M[ee],ge=xt(J,this),ge=[ge,this.__zoom.invert(ge),J.identifier],Z.touch0?!Z.touch1&&Z.touch0[2]!==ge[2]&&(Z.touch1=ge,Z.taps=0):(Z.touch0=ge,j=!0,Z.taps=1+!!u);u&&(u=clearTimeout(u)),j&&(Z.taps<2&&(f=ge[0],u=setTimeout(function(){u=null},d)),xi(this),Z.start())}}function he(C,...H){if(this.__zooming){var M=N(this,H).event(C),$=C.changedTouches,Z=$.length,j,ee,J,ge;for(ni(C),j=0;j<Z;++j)ee=$[j],J=xt(ee,this),M.touch0&&M.touch0[2]===ee.identifier?M.touch0[0]=J:M.touch1&&M.touch1[2]===ee.identifier&&(M.touch1[0]=J);if(ee=M.that.__zoom,M.touch1){var ue=M.touch0[0],Te=M.touch0[1],se=M.touch1[0],He=M.touch1[1],We=(We=se[0]-ue[0])*We+(We=se[1]-ue[1])*We,nt=(nt=He[0]-Te[0])*nt+(nt=He[1]-Te[1])*nt;ee=O(ee,Math.sqrt(We/nt)),J=[(ue[0]+se[0])/2,(ue[1]+se[1])/2],ge=[(Te[0]+He[0])/2,(Te[1]+He[1])/2]}else if(M.touch0)J=M.touch0[0],ge=M.touch0[1];else return;M.zoom("touch",t(E(ee,J,ge),M.extent,o))}}function ie(C,...H){if(this.__zooming){var M=N(this,H).event(C),$=C.changedTouches,Z=$.length,j,ee;for(Ro(C),h&&clearTimeout(h),h=setTimeout(function(){h=null},d),j=0;j<Z;++j)ee=$[j],M.touch0&&M.touch0[2]===ee.identifier?delete M.touch0:M.touch1&&M.touch1[2]===ee.identifier&&delete M.touch1;if(M.touch1&&!M.touch0&&(M.touch0=M.touch1,delete M.touch1),M.touch0)M.touch0[1]=this.__zoom.invert(M.touch0[0]);else if(M.end(),M.taps===2&&(ee=xt(ee,this),Math.hypot(f[0]-ee[0],f[1]-ee[1])<P)){var J=we(this).on("dblclick.zoom");J&&J.apply(this,arguments)}}}return A.wheelDelta=function(C){return arguments.length?(i=typeof C=="function"?C:vr(+C),A):i},A.filter=function(C){return arguments.length?(n=typeof C=="function"?C:vr(!!C),A):n},A.touchable=function(C){return arguments.length?(r=typeof C=="function"?C:vr(!!C),A):r},A.extent=function(C){return arguments.length?(e=typeof C=="function"?C:vr([[+C[0][0],+C[0][1]],[+C[1][0],+C[1][1]]]),A):e},A.scaleExtent=function(C){return arguments.length?(s[0]=+C[0],s[1]=+C[1],A):[s[0],s[1]]},A.translateExtent=function(C){return arguments.length?(o[0][0]=+C[0][0],o[1][0]=+C[1][0],o[0][1]=+C[0][1],o[1][1]=+C[1][1],A):[[o[0][0],o[0][1]],[o[1][0],o[1][1]]]},A.constrain=function(C){return arguments.length?(t=C,A):t},A.duration=function(C){return arguments.length?(a=+C,A):a},A.interpolate=function(C){return arguments.length?(l=C,A):l},A.on=function(){var C=c.on.apply(c,arguments);return C===c?A:C},A.clickDistance=function(C){return arguments.length?(I=(C=+C)*C,A):Math.sqrt(I)},A.tapDistance=function(C){return arguments.length?(P=+C,A):P},A}class $v{constructor(e,t){this.eventTransform=ti,this.behavior=Wv().scaleExtent([.001,1/0]).on("start",i=>{var s,o;this.isRunning=!0;const r=!!i.sourceEvent;(o=(s=this.config)==null?void 0:s.onZoomStart)==null||o.call(s,i,r)}).on("zoom",i=>{var h,d;this.eventTransform=i.transform;const{eventTransform:{x:r,y:s,k:o},store:{transform:a,screenSize:l}}=this,c=l[0],u=l[1];if(!c||!u)return;ky(a,c,u),rc(a,a,[r,s]),qs(a,a,[o,o]),rc(a,a,[c/2,u/2]),qs(a,a,[c/2,u/2]),qs(a,a,[1,-1]);const f=!!i.sourceEvent;(d=(h=this.config)==null?void 0:h.onZoom)==null||d.call(h,i,f)}).on("end",i=>{var s,o;this.isRunning=!1;const r=!!i.sourceEvent;(o=(s=this.config)==null?void 0:s.onZoomEnd)==null||o.call(s,i,r)}),this.isRunning=!1,this.store=e,this.config=t}getTransform(e,t,i=.1){if(e.length===0)return this.eventTransform;const{store:{screenSize:r}}=this,s=r[0],o=r[1];let a=1/0,l=-1/0,c=1/0,u=-1/0;for(let R=0;R<e.length;R+=2){const N=e[R],U=e[R+1];N<a&&(a=N),N>l&&(l=N),U<c&&(c=U),U>u&&(u=U)}const f=[this.store.scaleX(a),this.store.scaleX(l)],h=[this.store.scaleY(c),this.store.scaleY(u)];f[0]===f[1]&&(f[0]-=.5,f[1]+=.5),h[0]===h[1]&&(h[0]+=.5,h[1]-=.5);const d=s*(1-i*2)/(f[1]-f[0]),_=o*(1-i*2)/(h[0]-h[1]),I=Sc(t??Math.min(d,_),...this.behavior.scaleExtent()),P=(f[1]+f[0])/2,A=(h[1]+h[0])/2,O=s/2-P*I,E=o/2-A*I;return ti.translate(O,E).scale(I)}getDistanceToPoint(e){const{x:t,y:i,k:r}=this.eventTransform,s=this.getTransform(e,r),o=t-s.x,a=i-s.y;return Math.sqrt(o*o+a*a)}getMiddlePointTransform(e){const{store:{screenSize:t},eventTransform:{x:i,y:r,k:s}}=this,o=t[0],a=t[1],l=(o/2-i)/s,c=(a/2-r)/s,u=this.store.scaleX(e[0]),f=this.store.scaleY(e[1]),h=(l+u)/2,d=(c+f)/2,_=1,I=o/2-h*_,P=a/2-d*_;return ti.translate(I,P).scale(_)}convertScreenToSpacePosition(e){const{eventTransform:{x:t,y:i,k:r},store:{screenSize:s}}=this,o=s[0],a=s[1],l=(e[0]-t)/r,c=(e[1]-i)/r,u=[l,a-c];return u[0]-=(o-this.store.adjustedSpaceSize)/2,u[1]-=(a-this.store.adjustedSpaceSize)/2,u}convertSpaceToScreenPosition(e){const t=this.eventTransform.applyX(this.store.scaleX(e[0])),i=this.eventTransform.applyY(this.store.scaleY(e[1]));return[t,i]}convertSpaceToScreenRadius(e){const{config:{scalePointsOnZoom:t},store:{maxPointSize:i},eventTransform:{k:r}}=this;let s=e*2;return t?s*=r:s*=Math.min(5,Math.max(1,r*.01)),Math.min(s,i)/2}}class Xv{constructor(e,t){this.isActive=!1,this.behavior=Ov().subject(i=>this.store.hoveredPoint&&!this.store.isSpaceKeyPressed?{x:i.x,y:i.y}:void 0).on("start",i=>{var r,s;this.store.hoveredPoint&&(this.store.draggingPointIndex=this.store.hoveredPoint.index,this.isActive=!0,(s=(r=this.config)==null?void 0:r.onDragStart)==null||s.call(r,i))}).on("drag",i=>{var r,s;(s=(r=this.config)==null?void 0:r.onDrag)==null||s.call(r,i)}).on("end",i=>{var r,s;this.isActive=!1,this.store.draggingPointIndex=void 0,(s=(r=this.config)==null?void 0:r.onDragEnd)==null||s.call(r,i)}),this.store=e,this.config=t}}class Yv{constructor(e,t,i){if(this.config=new bx,this.graph=new cv(this.config),this.requestAnimationFrameId=0,this.isRightClickMouse=!1,this.store=new vx,this.zoomInstance=new $v(this.store,this.config),this.dragInstance=new Xv(this.store,this.config),this._findHoveredItemExecutionCount=0,this._isMouseOnCanvas=!1,this._lastMouseX=0,this._lastMouseY=0,this._lastCheckedMouseX=0,this._lastCheckedMouseY=0,this._shouldForceHoverDetection=!1,this._isFirstRenderAfterInit=!0,this.isPointPositionsUpdateNeeded=!1,this.isPointColorUpdateNeeded=!1,this.isPointSizeUpdateNeeded=!1,this.isPointShapeUpdateNeeded=!1,this.isPointImageIndicesUpdateNeeded=!1,this.isLinksUpdateNeeded=!1,this.isLinkColorUpdateNeeded=!1,this.isLinkWidthUpdateNeeded=!1,this.isLinkArrowUpdateNeeded=!1,this.isPointClusterUpdateNeeded=!1,this.isForceManyBodyUpdateNeeded=!1,this.isForceLinkUpdateNeeded=!1,this.isForceCenterUpdateNeeded=!1,this.isPointImageSizesUpdateNeeded=!1,this._isDestroyed=!1,t&&this.config.init(t),i)this.deviceInitPromise=i,this.shouldDestroyDevice=!1;else{const r=document.createElement("canvas");this.deviceInitPromise=this.createDevice(r),this.shouldDestroyDevice=!0}this.deviceInitPromise.then(r=>{if(this._isDestroyed)return this.shouldDestroyDevice&&r.destroy(),r;this.device=r;const s=this.validateDevice(r);i&&s.setProps({useDevicePixels:this.config.pixelRatio}),this.store.div=e;const o=s.canvas;o.parentNode!==this.store.div&&(o.parentNode&&o.parentNode.removeChild(o),this.store.div.appendChild(o)),this.addAttribution(),o.style.width="100%",o.style.height="100%",this.canvas=o;const a=this.canvas.clientWidth,l=this.canvas.clientHeight;return this.store.adjustSpaceSize(this.config.spaceSize,this.device.limits.maxTextureDimension2D),this.store.setWebGLMaxTextureSize(this.device.limits.maxTextureDimension2D),this.store.updateScreenSize(a,l),this.canvasD3Selection=we(this.canvas),this.canvasD3Selection.on("mouseenter.cosmos",c=>{this._isMouseOnCanvas=!0,this._lastMouseX=c.clientX,this._lastMouseY=c.clientY}).on("mousemove.cosmos",c=>{this._isMouseOnCanvas=!0,this._lastMouseX=c.clientX,this._lastMouseY=c.clientY}).on("mouseleave.cosmos",c=>{this._isMouseOnCanvas=!1,this.currentEvent=c,this.store.hoveredPoint!==void 0&&this.config.onPointMouseOut&&this.config.onPointMouseOut(c),this.store.hoveredLinkIndex!==void 0&&this.config.onLinkMouseOut&&this.config.onLinkMouseOut(c),this.isRightClickMouse=!1,this.store.hoveredPoint=void 0,this.store.hoveredLinkIndex=void 0,this.updateCanvasCursor()}),we(document).on("keydown.cosmos",c=>{c.code==="Space"&&(this.store.isSpaceKeyPressed=!0)}).on("keyup.cosmos",c=>{c.code==="Space"&&(this.store.isSpaceKeyPressed=!1)}),this.zoomInstance.behavior.on("start.detect",c=>{this.currentEvent=c}).on("zoom.detect",c=>{!!c.sourceEvent&&this.updateMousePosition(c.sourceEvent),this.currentEvent=c}).on("end.detect",c=>{this.currentEvent=c,this._shouldForceHoverDetection=!0}),this.dragInstance.behavior.on("start.detect",c=>{this.currentEvent=c,this.updateCanvasCursor()}).on("drag.detect",c=>{this.dragInstance.isActive&&this.updateMousePosition(c),this.currentEvent=c}).on("end.detect",c=>{this.currentEvent=c,this.updateCanvasCursor()}),this.canvasD3Selection.call(this.dragInstance.behavior).call(this.zoomInstance.behavior).on("click",this.onClick.bind(this)).on("mousemove",this.onMouseMove.bind(this)).on("contextmenu",this.onContextMenu.bind(this)),(!this.config.enableZoom||!this.config.enableDrag)&&this.updateZoomDragBehaviors(),this.setZoomLevel(this.config.initialZoomLevel??1),this.store.maxPointSize=eo(r,this.config.pixelRatio),this.store.isSimulationRunning=this.config.enableSimulation,this.points=new Rv(r,this.config,this.store,this.graph),this.lines=new gv(r,this.config,this.store,this.graph,this.points),this.config.enableSimulation&&(this.forceGravity=new Y0(r,this.config,this.store,this.graph,this.points),this.forceCenter=new $0(r,this.config,this.store,this.graph,this.points),this.forceManyBody=new J0(r,this.config,this.store,this.graph,this.points),this.forceLinkIncoming=new gu(r,this.config,this.store,this.graph,this.points),this.forceLinkOutgoing=new gu(r,this.config,this.store,this.graph,this.points),this.forceMouse=new ev(r,this.config,this.store,this.graph,this.points)),this.clusters=new rv(r,this.config,this.store,this.graph,this.points),this.store.backgroundColor=Tt(this.config.backgroundColor),this.store.setHoveredPointRingColor(this.config.hoveredPointRingColor??V.hoveredPointRingColor),this.store.setFocusedPointRingColor(this.config.focusedPointRingColor??V.focusedPointRingColor),this.config.focusedPointIndex!==void 0&&this.store.setFocusedPoint(this.config.focusedPointIndex),this.store.setGreyoutPointColor(this.config.pointGreyoutColor??Ms),this.store.setHoveredLinkColor(this.config.hoveredLinkColor??V.hoveredLinkColor),this.store.updateLinkHoveringEnabled(this.config),this.config.showFPSMonitor&&(this.fpsMonitor=new mu(this.canvas)),this.config.randomSeed!==void 0&&this.store.addRandomSeed(this.config.randomSeed),r}).catch(r=>{throw console.error("Device initialization failed:",r),r})}get progress(){return this._isDestroyed?0:this.store.simulationProgress}get isSimulationRunning(){return this._isDestroyed?!1:this.store.isSimulationRunning}get maxPointSize(){return this._isDestroyed?0:this.store.maxPointSize}setConfig(e){var i,r,s,o,a,l,c,u,f;if(this._isDestroyed||this.ensureDevice(()=>this.setConfig(e)))return;const t={...this.config};this.config.init(e),(t.pointDefaultColor!==this.config.pointDefaultColor||t.pointColor!==this.config.pointColor)&&(this.graph.updatePointColor(),(i=this.points)==null||i.updateColor()),(t.pointDefaultSize!==this.config.pointDefaultSize||t.pointSize!==this.config.pointSize)&&(this.graph.updatePointSize(),(r=this.points)==null||r.updateSize()),(t.linkDefaultColor!==this.config.linkDefaultColor||t.linkColor!==this.config.linkColor)&&(this.graph.updateLinkColor(),(s=this.lines)==null||s.updateColor()),(t.linkDefaultWidth!==this.config.linkDefaultWidth||t.linkWidth!==this.config.linkWidth)&&(this.graph.updateLinkWidth(),(o=this.lines)==null||o.updateWidth()),(t.linkDefaultArrows!==this.config.linkDefaultArrows||t.linkArrows!==this.config.linkArrows)&&(this.graph.updateArrows(),(a=this.lines)==null||a.updateArrow()),(t.curvedLinkSegments!==this.config.curvedLinkSegments||t.curvedLinks!==this.config.curvedLinks)&&((l=this.lines)==null||l.updateCurveLineGeometry()),t.backgroundColor!==this.config.backgroundColor&&(this.store.backgroundColor=Tt(this.config.backgroundColor??Al)),t.hoveredPointRingColor!==this.config.hoveredPointRingColor&&this.store.setHoveredPointRingColor(this.config.hoveredPointRingColor??V.hoveredPointRingColor),t.focusedPointRingColor!==this.config.focusedPointRingColor&&this.store.setFocusedPointRingColor(this.config.focusedPointRingColor??V.focusedPointRingColor),t.pointGreyoutColor!==this.config.pointGreyoutColor&&this.store.setGreyoutPointColor(this.config.pointGreyoutColor??Ms),t.hoveredLinkColor!==this.config.hoveredLinkColor&&this.store.setHoveredLinkColor(this.config.hoveredLinkColor??V.hoveredLinkColor),t.focusedPointIndex!==this.config.focusedPointIndex&&this.store.setFocusedPoint(this.config.focusedPointIndex),t.pixelRatio!==this.config.pixelRatio&&(c=this.device)!=null&&c.canvasContext&&(this.device.canvasContext.setProps({useDevicePixels:this.config.pixelRatio}),this.store.maxPointSize=eo(this.device,this.config.pixelRatio)),t.spaceSize!==this.config.spaceSize&&(this.store.adjustSpaceSize(this.config.spaceSize,((u=this.device)==null?void 0:u.limits.maxTextureDimension2D)??4096),this.resizeCanvas(!0),this.update(this.store.isSimulationRunning?this.store.alpha:0)),t.showFPSMonitor!==this.config.showFPSMonitor&&(this.config.showFPSMonitor?this.fpsMonitor=new mu(this.canvas):((f=this.fpsMonitor)==null||f.destroy(),this.fpsMonitor=void 0)),(t.enableZoom!==this.config.enableZoom||t.enableDrag!==this.config.enableDrag)&&this.updateZoomDragBehaviors(),(t.onLinkClick!==this.config.onLinkClick||t.onLinkContextMenu!==this.config.onLinkContextMenu||t.onLinkMouseOver!==this.config.onLinkMouseOver||t.onLinkMouseOut!==this.config.onLinkMouseOut)&&this.store.updateLinkHoveringEnabled(this.config)}setPointPositions(e,t){this._isDestroyed||this.ensureDevice(()=>this.setPointPositions(e,t))||(this.graph.inputPointPositions=e,this.points.shouldSkipRescale=t,this.isPointPositionsUpdateNeeded=!0,this.isLinksUpdateNeeded=!0,this.isPointColorUpdateNeeded=!0,this.isPointSizeUpdateNeeded=!0,this.isPointShapeUpdateNeeded=!0,this.isPointImageIndicesUpdateNeeded=!0,this.isPointImageSizesUpdateNeeded=!0,this.isPointClusterUpdateNeeded=!0,this.isForceManyBodyUpdateNeeded=!0,this.isForceLinkUpdateNeeded=!0,this.isForceCenterUpdateNeeded=!0)}setPointColors(e){this._isDestroyed||this.ensureDevice(()=>this.setPointColors(e))||(this.graph.inputPointColors=e,this.isPointColorUpdateNeeded=!0)}getPointColors(){return this._isDestroyed?new Float32Array:this.graph.pointColors??new Float32Array}setPointSizes(e){this._isDestroyed||this.ensureDevice(()=>this.setPointSizes(e))||(this.graph.inputPointSizes=e,this.isPointSizeUpdateNeeded=!0)}setPointShapes(e){this._isDestroyed||this.ensureDevice(()=>this.setPointShapes(e))||(this.graph.inputPointShapes=e,this.isPointShapeUpdateNeeded=!0)}setImageData(e){var t;this._isDestroyed||this.ensureDevice(()=>this.setImageData(e))||(this.graph.inputImageData=e,(t=this.points)==null||t.createAtlas())}setPointImageIndices(e){this._isDestroyed||this.ensureDevice(()=>this.setPointImageIndices(e))||(this.graph.inputPointImageIndices=e,this.isPointImageIndicesUpdateNeeded=!0)}setPointImageSizes(e){this._isDestroyed||this.ensureDevice(()=>this.setPointImageSizes(e))||(this.graph.inputPointImageSizes=e,this.isPointImageSizesUpdateNeeded=!0)}getPointSizes(){return this._isDestroyed?new Float32Array:this.graph.pointSizes??new Float32Array}setLinks(e){this._isDestroyed||this.ensureDevice(()=>this.setLinks(e))||(this.graph.inputLinks=e,this.isLinksUpdateNeeded=!0,this.isLinkColorUpdateNeeded=!0,this.isLinkWidthUpdateNeeded=!0,this.isLinkArrowUpdateNeeded=!0,this.isForceLinkUpdateNeeded=!0)}setLinkColors(e){this._isDestroyed||this.ensureDevice(()=>this.setLinkColors(e))||(this.graph.inputLinkColors=e,this.isLinkColorUpdateNeeded=!0)}getLinkColors(){return this._isDestroyed?new Float32Array:this.graph.linkColors??new Float32Array}setLinkWidths(e){this._isDestroyed||this.ensureDevice(()=>this.setLinkWidths(e))||(this.graph.inputLinkWidths=e,this.isLinkWidthUpdateNeeded=!0)}getLinkWidths(){return this._isDestroyed?new Float32Array:this.graph.linkWidths??new Float32Array}setLinkArrows(e){this._isDestroyed||this.ensureDevice(()=>this.setLinkArrows(e))||(this.graph.linkArrowsBoolean=e,this.isLinkArrowUpdateNeeded=!0)}setLinkStrength(e){this._isDestroyed||this.ensureDevice(()=>this.setLinkStrength(e))||(this.graph.inputLinkStrength=e,this.isForceLinkUpdateNeeded=!0)}setPointClusters(e){this._isDestroyed||this.ensureDevice(()=>this.setPointClusters(e))||(this.graph.inputPointClusters=e,this.isPointClusterUpdateNeeded=!0)}setClusterPositions(e){this._isDestroyed||this.ensureDevice(()=>this.setClusterPositions(e))||(this.graph.inputClusterPositions=e,this.isPointClusterUpdateNeeded=!0)}setPointClusterStrength(e){this._isDestroyed||this.ensureDevice(()=>this.setPointClusterStrength(e))||(this.graph.inputClusterStrength=e,this.isPointClusterUpdateNeeded=!0)}setPinnedPoints(e){var t;this._isDestroyed||this.ensureDevice(()=>this.setPinnedPoints(e))||(this.graph.inputPinnedPoints=e&&e.length>0?e:void 0,(t=this.points)==null||t.updatePinnedStatus())}render(e){if(this._isDestroyed||this.ensureDevice(()=>this.render(e)))return;this.graph.update();const{fitViewOnInit:t,fitViewDelay:i,fitViewPadding:r,fitViewDuration:s,fitViewByPointsInRect:o,fitViewByPointIndices:a,initialZoomLevel:l}=this.config;if(!this.graph.pointsNumber&&!this.graph.linksNumber){this.stopFrames(),we(this.canvas).style("cursor",null),this.device&&(this.device.beginRenderPass({clearColor:this.store.backgroundColor,clearDepth:1,clearStencil:0}).end(),this.device.submit());return}this._isFirstRenderAfterInit&&t&&l===void 0&&(this._fitViewOnInitTimeoutID=window.setTimeout(()=>{a?this.fitViewByPointIndices(a,s,r):o?this.setZoomTransformByPointPositions(new Float32Array(this.flatten(o)),s,void 0,r):this.fitView(s,r)},i)),this.update(e),this.startFrames(),this._isFirstRenderAfterInit=!1}zoomToPointByIndex(e,t=700,i=M_,r=!0){if(this._isDestroyed||this.ensureDevice(()=>this.zoomToPointByIndex(e,t,i,r))||!this.device||!this.points||!this.canvasD3Selection)return;const{store:{screenSize:s}}=this,o=Xe(this.device,this.points.currentPositionFbo);if(e===void 0)return;const a=o[e*4+0],l=o[e*4+1];if(a===void 0||l===void 0)return;const c=this.zoomInstance.getDistanceToPoint([a,l]),u=r?i:Math.max(this.getZoomLevel(),i);if(c<Math.min(s[0],s[1]))this.setZoomTransformByPointPositions(new Float32Array([a,l]),t,u);else{const f=this.zoomInstance.getTransform([a,l],u),h=this.zoomInstance.getMiddlePointTransform([a,l]);this.canvasD3Selection.transition().ease(lp).duration(t/2).call(this.zoomInstance.behavior.transform,h).transition().ease(cp).duration(t/2).call(this.zoomInstance.behavior.transform,f)}}zoom(e,t=0){this._isDestroyed||this.setZoomLevel(e,t)}setZoomLevel(e,t=0){this._isDestroyed||this.ensureDevice(()=>this.setZoomLevel(e,t))||this.canvasD3Selection&&(t===0?this.canvasD3Selection.call(this.zoomInstance.behavior.scaleTo,e):this.canvasD3Selection.transition().duration(t).call(this.zoomInstance.behavior.scaleTo,e))}getZoomLevel(){return this._isDestroyed?0:this.zoomInstance.eventTransform.k}getPointPositions(){if(this._isDestroyed||!this.device||!this.points)return[];if(this.graph.pointsNumber===void 0)return[];const e=[],t=Xe(this.device,this.points.currentPositionFbo);e.length=this.graph.pointsNumber*2;for(let i=0;i<this.graph.pointsNumber;i+=1){const r=t[i*4+0],s=t[i*4+1];r!==void 0&&s!==void 0&&(e[i*2]=r,e[i*2+1]=s)}return e}getClusterPositions(){if(this._isDestroyed||!this.device||!this.clusters)return[];if(this.graph.pointClusters===void 0||this.clusters.clusterCount===void 0)return[];this.clusters.calculateCentermass();const e=[],t=Xe(this.device,this.clusters.centermassFbo);e.length=this.clusters.clusterCount*2;for(let i=0;i<e.length/2;i+=1){const r=t[i*4+0],s=t[i*4+1],o=t[i*4+2];r!==void 0&&s!==void 0&&o!==void 0&&(e[i*2]=r/o,e[i*2+1]=s/o)}return e}fitView(e=250,t=.1){this._isDestroyed||this.ensureDevice(()=>this.fitView(e,t))||this.setZoomTransformByPointPositions(new Float32Array(this.getPointPositions()),e,void 0,t)}fitViewByPointIndices(e,t=250,i=.1){if(this._isDestroyed||this.ensureDevice(()=>this.fitViewByPointIndices(e,t,i)))return;const r=this.getPointPositions(),s=new Float32Array(e.length*2);for(const[o,a]of e.entries())s[o*2]=r[a*2],s[o*2+1]=r[a*2+1];this.setZoomTransformByPointPositions(s,t,void 0,i)}fitViewByPointPositions(e,t=250,i=.1){this._isDestroyed||this.ensureDevice(()=>this.fitViewByPointPositions(e,t,i))||this.setZoomTransformByPointPositions(new Float32Array(e),t,void 0,i)}setZoomTransformByPointPositions(e,t=250,i,r=.1){var o;if(this._isDestroyed||this.ensureDevice(()=>this.setZoomTransformByPointPositions(e,t,i,r)))return;this.resizeCanvas();const s=this.zoomInstance.getTransform(e,i,r);(o=this.canvasD3Selection)==null||o.transition().ease(up).duration(t).call(this.zoomInstance.behavior.transform,s)}getPointsInRect(e){if(this._isDestroyed||!this.device||!this.points)return new Float32Array;const t=this.store.screenSize[1];return this.store.selectedArea=[[e[0][0],t-e[1][1]],[e[1][0],t-e[0][1]]],this.points.findPointsOnAreaSelection(),Xe(this.device,this.points.selectedFbo).map((r,s)=>s%4===0&&r!==0?s/4:-1).filter(r=>r!==-1)}getPointsInRange(e){return this.getPointsInRect(e)}getPointsInPolygon(e){if(this._isDestroyed||!this.device||!this.points)return new Float32Array;if(e.length<3)return new Float32Array;const t=this.store.screenSize[1],i=e.map(([s,o])=>[s,t-o]);return this.points.updatePolygonPath(i),this.points.findPointsOnPolygonSelection(),Xe(this.device,this.points.selectedFbo).map((s,o)=>o%4===0&&s!==0?o/4:-1).filter(s=>s!==-1)}selectPointsInRect(e){if(!this._isDestroyed&&!this.ensureDevice(()=>this.selectPointsInRect(e))&&!(!this.device||!this.points)){if(e){const t=this.store.screenSize[1];this.store.selectedArea=[[e[0][0],t-e[1][1]],[e[1][0],t-e[0][1]]],this.points.findPointsOnAreaSelection();const i=Xe(this.device,this.points.selectedFbo);this.store.selectedIndices=i.map((r,s)=>s%4===0&&r!==0?s/4:-1).filter(r=>r!==-1)}else this.store.selectedIndices=null;this.points.updateGreyoutStatus()}}selectPointsInRange(e){return this.selectPointsInRect(e)}selectPointsInPolygon(e){if(!this._isDestroyed&&!this.ensureDevice(()=>this.selectPointsInPolygon(e))&&!(!this.device||!this.points)){if(e){if(e.length<3){console.warn("Polygon path requires at least 3 points to form a polygon.");return}const t=this.store.screenSize[1],i=e.map(([s,o])=>[s,t-o]);this.points.updatePolygonPath(i),this.points.findPointsOnPolygonSelection();const r=Xe(this.device,this.points.selectedFbo);this.store.selectedIndices=r.map((s,o)=>o%4===0&&s!==0?o/4:-1).filter(s=>s!==-1)}else this.store.selectedIndices=null;this.points.updateGreyoutStatus()}}selectPointByIndex(e,t=!1){if(!this._isDestroyed&&!this.ensureDevice(()=>this.selectPointByIndex(e,t)))if(t){const i=this.graph.getAdjacentIndices(e)??[];this.selectPointsByIndices([e,...i])}else this.selectPointsByIndices([e])}selectPointsByIndices(e){this._isDestroyed||this.ensureDevice(()=>this.selectPointsByIndices(e))||this.points&&(e?e.length===0?this.store.selectedIndices=new Float32Array:this.store.selectedIndices=new Float32Array(e.filter(t=>t!==void 0)):this.store.selectedIndices=null,this.points.updateGreyoutStatus())}unselectPoints(){this._isDestroyed||this.ensureDevice(()=>this.unselectPoints())||this.points&&(this.store.selectedIndices=null,this.points.updateGreyoutStatus())}getSelectedIndices(){if(this._isDestroyed)return null;const{selectedIndices:e}=this.store;return e?Array.from(e):null}getAdjacentIndices(e){if(!this._isDestroyed)return this.graph.getAdjacentIndices(e)}spaceToScreenPosition(e){return this._isDestroyed?[0,0]:this.zoomInstance.convertSpaceToScreenPosition(e)}screenToSpacePosition(e){return this._isDestroyed?[0,0]:this.zoomInstance.convertScreenToSpacePosition(e)}spaceToScreenRadius(e){return this._isDestroyed?0:this.zoomInstance.convertSpaceToScreenRadius(e)}getPointRadiusByIndex(e){var t;if(!this._isDestroyed)return(t=this.graph.pointSizes)==null?void 0:t[e]}trackPointPositionsByIndices(e){this._isDestroyed||this.ensureDevice(()=>this.trackPointPositionsByIndices(e))||this.points&&this.points.trackPointsByIndices(e)}getTrackedPointPositionsMap(){return this._isDestroyed||!this.points?new Map:this.points.getTrackedPositionsMap()}getTrackedPointPositionsArray(){return this._isDestroyed||!this.points?[]:this.points.getTrackedPositionsArray()}getSampledPointPositionsMap(){return this._isDestroyed||!this.points?new Map:this.points.getSampledPointPositionsMap()}getSampledPoints(){return this._isDestroyed||!this.points?{indices:[],positions:[]}:this.points.getSampledPoints()}getScaleX(){if(!(this._isDestroyed||!this.points))return this.points.scaleX}getScaleY(){if(!(this._isDestroyed||!this.points))return this.points.scaleY}start(e=1){var t,i;this._isDestroyed||this.ensureDevice(()=>this.start(e))||this.graph.pointsNumber&&(this.store.isSimulationRunning=!0,this.store.simulationProgress=0,this.store.alpha=e,(i=(t=this.config).onSimulationStart)==null||i.call(t))}stop(){var e,t;this._isDestroyed||(this.store.isSimulationRunning=!1,this.store.simulationProgress=0,this.store.alpha=0,(t=(e=this.config).onSimulationEnd)==null||t.call(e))}pause(){var e,t;this._isDestroyed||this.ensureDevice(()=>this.pause())||(this.store.isSimulationRunning=!1,(t=(e=this.config).onSimulationPause)==null||t.call(e))}unpause(){var e,t;this._isDestroyed||this.ensureDevice(()=>this.unpause())||(this.store.isSimulationRunning=!0,(t=(e=this.config).onSimulationUnpause)==null||t.call(e))}restart(){var e,t;this._isDestroyed||this.ensureDevice(()=>this.restart())||(this.store.isSimulationRunning=!0,(t=(e=this.config).onSimulationRestart)==null||t.call(e))}step(){this._isDestroyed||this.ensureDevice(()=>this.step())||this.config.enableSimulation&&this.store.pointsTextureSize&&this.runSimulationStep(!0)}destroy(){var e,t,i,r,s,o,a,l,c,u,f,h,d;this._isDestroyed||(this._isDestroyed=!0,window.clearTimeout(this._fitViewOnInitTimeoutID),this.stopFrames(),this.canvasD3Selection&&this.canvasD3Selection.on("mouseenter.cosmos",null).on("mousemove.cosmos",null).on("mouseleave.cosmos",null).on("click",null).on("mousemove",null).on("contextmenu",null).on(".drag",null).on(".zoom",null),we(document).on("keydown.cosmos",null).on("keyup.cosmos",null),(e=this.zoomInstance)!=null&&e.behavior&&this.zoomInstance.behavior.on("start.detect",null).on("zoom.detect",null).on("end.detect",null),(t=this.dragInstance)!=null&&t.behavior&&this.dragInstance.behavior.on("start.detect",null).on("drag.detect",null).on("end.detect",null),(i=this.fpsMonitor)==null||i.destroy(),(r=this.points)==null||r.destroy(),(s=this.lines)==null||s.destroy(),(o=this.clusters)==null||o.destroy(),(a=this.forceGravity)==null||a.destroy(),(l=this.forceCenter)==null||l.destroy(),(c=this.forceManyBody)==null||c.destroy(),(u=this.forceLinkIncoming)==null||u.destroy(),(f=this.forceLinkOutgoing)==null||f.destroy(),(h=this.forceMouse)==null||h.destroy(),this.device&&this.shouldDestroyDevice&&(this.device.beginRenderPass({clearColor:this.store.backgroundColor,clearDepth:1,clearStencil:0}).end(),this.device.submit(),this.device.destroy()),this.shouldDestroyDevice&&this.canvas&&this.canvas.parentNode&&this.canvas.parentNode.removeChild(this.canvas),this.attributionDivElement&&this.attributionDivElement.parentNode&&this.attributionDivElement.parentNode.removeChild(this.attributionDivElement),(d=document.getElementById("gl-bench-style"))==null||d.remove(),this.canvasD3Selection=void 0,this.attributionDivElement=void 0)}create(){var e,t,i,r,s;this._isDestroyed||this.ensureDevice(()=>this.create())||this.points&&this.lines&&(this.isPointPositionsUpdateNeeded&&this.points.updatePositions(),this.isPointColorUpdateNeeded&&this.points.updateColor(),this.isPointSizeUpdateNeeded&&this.points.updateSize(),this.isPointShapeUpdateNeeded&&this.points.updateShape(),this.isPointImageIndicesUpdateNeeded&&this.points.updateImageIndices(),this.isPointImageSizesUpdateNeeded&&this.points.updateImageSizes(),this.isLinksUpdateNeeded&&this.lines.updatePointsBuffer(),this.isLinkColorUpdateNeeded&&this.lines.updateColor(),this.isLinkWidthUpdateNeeded&&this.lines.updateWidth(),this.isLinkArrowUpdateNeeded&&this.lines.updateArrow(),this.isForceManyBodyUpdateNeeded&&((e=this.forceManyBody)==null||e.create()),this.isForceLinkUpdateNeeded&&((t=this.forceLinkIncoming)==null||t.create(Io.INCOMING),(i=this.forceLinkOutgoing)==null||i.create(Io.OUTGOING)),this.isForceCenterUpdateNeeded&&((r=this.forceCenter)==null||r.create()),this.isPointClusterUpdateNeeded&&((s=this.clusters)==null||s.create()),this.isPointPositionsUpdateNeeded=!1,this.isPointColorUpdateNeeded=!1,this.isPointSizeUpdateNeeded=!1,this.isPointShapeUpdateNeeded=!1,this.isPointImageIndicesUpdateNeeded=!1,this.isPointImageSizesUpdateNeeded=!1,this.isLinksUpdateNeeded=!1,this.isLinkColorUpdateNeeded=!1,this.isLinkWidthUpdateNeeded=!1,this.isLinkArrowUpdateNeeded=!1,this.isPointClusterUpdateNeeded=!1,this.isForceManyBodyUpdateNeeded=!1,this.isForceLinkUpdateNeeded=!1,this.isForceCenterUpdateNeeded=!1)}flatten(e){return e.flat()}pair(e){const t=new Array(e.length/2);for(let i=0;i<e.length/2;i++)t[i]=[e[i*2],e[i*2+1]];return t}ensureDevice(e){return this.device?!1:(this.deviceInitPromise.then(()=>{this._isDestroyed||e()}).catch(t=>{console.error("Device initialization failed",t)}),!0)}validateDevice(e){const t=e.canvasContext;if(t===null||t.type==="offscreen-canvas")throw new Error("Device must have an HTMLCanvasElement canvas context. OffscreenCanvas and compute-only devices are not supported.");return t}async createDevice(e){return await jp.createDevice({type:"webgl",adapters:[qg],createCanvasContext:{canvas:e,useDevicePixels:this.config.pixelRatio,autoResize:!0,width:void 0,height:void 0}})}update(e=this.store.alpha){const{graph:t}=this;this.store.pointsTextureSize=Math.ceil(Math.sqrt(t.pointsNumber??0)),this.store.linksTextureSize=Math.ceil(Math.sqrt((t.linksNumber??0)*2)),this.create(),this.initPrograms(),this.store.hoveredPoint=void 0,this.store.alpha=e}runSimulationStep(e=!1){var a,l,c,u,f,h,d,_,I,P,A,O,E,y,R,N,U,W,q;const{config:{simulationGravity:t,simulationCenter:i,enableSimulation:r},store:{isSimulationRunning:s}}=this;if(!r)return;this.isRightClickMouse&&this.config.enableRightClickRepulsion&&((a=this.forceMouse)==null||a.run(),(l=this.points)==null||l.updatePosition()),(e||s&&!(this.zoomInstance.isRunning&&!this.config.enableSimulationDuringZoom))&&(t&&((c=this.forceGravity)==null||c.run(),(u=this.points)==null||u.updatePosition()),i&&((f=this.forceCenter)==null||f.run(),(h=this.points)==null||h.updatePosition()),(d=this.forceManyBody)==null||d.run(),(_=this.points)==null||_.updatePosition(),this.store.linksTextureSize&&((I=this.forceLinkIncoming)==null||I.run(),(P=this.points)==null||P.updatePosition(),(A=this.forceLinkOutgoing)==null||A.run(),(O=this.points)==null||O.updatePosition()),(this.graph.pointClusters||this.graph.clusterPositions)&&((E=this.clusters)==null||E.run(),(y=this.points)==null||y.updatePosition()),this.store.alpha+=this.store.addAlpha(this.config.simulationDecay??V.simulation.decay),this.isRightClickMouse&&this.config.enableRightClickRepulsion&&(this.store.alpha=Math.max(this.store.alpha,.1)),this.store.simulationProgress=Math.sqrt(Math.min(1,Qs/this.store.alpha)),(W=(U=this.config).onSimulationTick)==null||W.call(U,this.store.alpha,(R=this.store.hoveredPoint)==null?void 0:R.index,(N=this.store.hoveredPoint)==null?void 0:N.position)),(q=this.points)==null||q.trackPoints()}initPrograms(){var e,t,i,r,s,o;this._isDestroyed||!this.points||!this.lines||!this.clusters||(this.points.initPrograms(),this.lines.initPrograms(),(e=this.forceGravity)==null||e.initPrograms(),(t=this.forceManyBody)==null||t.initPrograms(),(i=this.forceCenter)==null||i.initPrograms(),(r=this.forceLinkIncoming)==null||r.initPrograms(),(s=this.forceLinkOutgoing)==null||s.initPrograms(),(o=this.forceMouse)==null||o.initPrograms(),this.clusters.initPrograms())}frame(){if(this._isDestroyed)return;const{store:{alpha:e,isSimulationRunning:t}}=this;e<Qs&&t&&this.end(),this.requestAnimationFrameId=window.requestAnimationFrame(i=>{this.renderFrame(i),this._isDestroyed||this.frame()})}renderFrame(e){var t,i,r,s,o,a,l;if(!this._isDestroyed&&this.store.pointsTextureSize){if((t=this.fpsMonitor)==null||t.begin(),this.resizeCanvas(),this.dragInstance.isActive||this.findHoveredItem(),this.runSimulationStep(!1),this.device){const c=this.store.backgroundColor??[0,0,0,1],u=this.device.beginRenderPass({clearColor:c,clearDepth:1,clearStencil:0}),{config:{renderLinks:f}}=this;f!==!1&&!!this.store.linksTextureSize&&!!this.graph.linksNumber&&this.graph.linksNumber>0&&((i=this.lines)==null||i.draw(u)),(r=this.points)==null||r.draw(u),this.dragInstance.isActive&&((s=this.points)==null||s.drag(),(o=this.points)==null||o.drag(),(a=this.points)==null||a.trackPoints()),u.end(),this.device.submit()}(l=this.fpsMonitor)==null||l.end(e??performance.now()),this.currentEvent=void 0}}stopFrames(){this.requestAnimationFrameId&&(window.cancelAnimationFrame(this.requestAnimationFrameId),this.requestAnimationFrameId=0)}startFrames(){this._isDestroyed||(this.stopFrames(),this.frame())}end(){var e,t;this.store.isSimulationRunning=!1,this.store.simulationProgress=1,(t=(e=this.config).onSimulationEnd)==null||t.call(e),this._shouldForceHoverDetection=!0}onClick(e){var t,i,r,s,o,a,l,c,u,f;(s=(r=this.config).onClick)==null||s.call(r,(t=this.store.hoveredPoint)==null?void 0:t.index,(i=this.store.hoveredPoint)==null?void 0:i.position,e),this.store.hoveredPoint?(a=(o=this.config).onPointClick)==null||a.call(o,this.store.hoveredPoint.index,this.store.hoveredPoint.position,e):this.store.hoveredLinkIndex!==void 0?(c=(l=this.config).onLinkClick)==null||c.call(l,this.store.hoveredLinkIndex,e):(f=(u=this.config).onBackgroundClick)==null||f.call(u,e)}updateMousePosition(e){if(!e)return;const t=e.offsetX??e.x,i=e.offsetY??e.y;t===void 0||i===void 0||(this.store.mousePosition=this.zoomInstance.convertScreenToSpacePosition([t,i]),this.store.screenMousePosition=[t,this.store.screenSize[1]-i])}onMouseMove(e){var t,i,r,s;this.currentEvent=e,this.updateMousePosition(e),this.isRightClickMouse=e.which===3,(s=(r=this.config).onMouseMove)==null||s.call(r,(t=this.store.hoveredPoint)==null?void 0:t.index,(i=this.store.hoveredPoint)==null?void 0:i.position,this.currentEvent)}onContextMenu(e){var t,i,r,s,o,a,l,c,u,f;e.preventDefault(),(s=(r=this.config).onContextMenu)==null||s.call(r,(t=this.store.hoveredPoint)==null?void 0:t.index,(i=this.store.hoveredPoint)==null?void 0:i.position,e),this.store.hoveredPoint?(a=(o=this.config).onPointContextMenu)==null||a.call(o,this.store.hoveredPoint.index,this.store.hoveredPoint.position,e):this.store.hoveredLinkIndex!==void 0?(c=(l=this.config).onLinkContextMenu)==null||c.call(l,this.store.hoveredLinkIndex,e):(f=(u=this.config).onBackgroundContextMenu)==null||f.call(u,e)}resizeCanvas(e=!1){var o,a,l;if(this._isDestroyed)return;const t=this.canvas.clientWidth,i=this.canvas.clientHeight,[r,s]=this.store.screenSize;if(e||r!==t||s!==i){const{k:c}=this.zoomInstance.eventTransform,u=this.zoomInstance.convertScreenToSpacePosition([r/2,s/2]);this.store.updateScreenSize(t,i),(o=this.canvasD3Selection)==null||o.call(this.zoomInstance.behavior.transform,this.zoomInstance.getTransform(u,c)),(a=this.points)==null||a.updateSampledPointsGrid(),this.store.isLinkHoveringEnabled&&((l=this.lines)==null||l.updateLinkIndexFbo())}}updateZoomDragBehaviors(){var e,t,i,r;this.config.enableDrag?(e=this.canvasD3Selection)==null||e.call(this.dragInstance.behavior):(t=this.canvasD3Selection)==null||t.call(this.dragInstance.behavior).on(".drag",null),this.config.enableZoom?(i=this.canvasD3Selection)==null||i.call(this.zoomInstance.behavior):(r=this.canvasD3Selection)==null||r.call(this.zoomInstance.behavior).on("wheel.zoom",null)}findHoveredItem(){if(this._isDestroyed||!this._isMouseOnCanvas)return;if(this._findHoveredItemExecutionCount<xx){this._findHoveredItemExecutionCount+=1;return}const e=Math.abs(this._lastMouseX-this._lastCheckedMouseX),t=Math.abs(this._lastMouseY-this._lastCheckedMouseY);if(!(!(e>_c||t>_c)&&!this._shouldForceHoverDetection)){if(this._lastCheckedMouseX=this._lastMouseX,this._lastCheckedMouseY=this._lastMouseY,this._shouldForceHoverDetection=!1,this._findHoveredItemExecutionCount=0,this.findHoveredPoint(),this.graph.linksNumber&&this.store.isLinkHoveringEnabled)this.findHoveredLine();else if(this.store.hoveredLinkIndex!==void 0){const r=this.store.hoveredLinkIndex!==void 0;this.store.hoveredLinkIndex=void 0,r&&this.config.onLinkMouseOut&&this.config.onLinkMouseOut(this.currentEvent)}this.updateCanvasCursor()}}findHoveredPoint(){var l,c,u,f,h;if(this._isDestroyed||!this.device||!this.points)return;this.points.findHoveredPoint();let e=!1,t=!1;const i=Xe(this.device,this.points.hoveredFbo,0,0,2,2),r=i[0],s=i[1],o=i[2],a=i[3];s>0?((this.store.hoveredPoint===void 0||this.store.hoveredPoint.index!==r)&&(e=!0),this.store.hoveredPoint={index:r,position:[o,a]}):(this.store.hoveredPoint&&(t=!0),this.store.hoveredPoint=void 0),e&&this.store.hoveredPoint&&((u=(c=this.config).onPointMouseOver)==null||u.call(c,this.store.hoveredPoint.index,this.store.hoveredPoint.position,this.currentEvent,((l=this.store.selectedIndices)==null?void 0:l.includes(this.store.hoveredPoint.index))??!1)),t&&((h=(f=this.config).onPointMouseOut)==null||h.call(f,this.currentEvent))}findHoveredLine(){var s,o,a,l,c,u;if(this._isDestroyed||!this.lines)return;if(this.store.hoveredPoint){this.store.hoveredLinkIndex!==void 0&&(this.store.hoveredLinkIndex=void 0,(o=(s=this.config).onLinkMouseOut)==null||o.call(s,this.currentEvent));return}this.lines.findHoveredLine();let e=!1,t=!1;if(!this.device)return;const r=Xe(this.device,this.lines.hoveredLineIndexFbo)[0];r>=0?(this.store.hoveredLinkIndex!==r&&(e=!0),this.store.hoveredLinkIndex=r):(this.store.hoveredLinkIndex!==void 0&&(t=!0),this.store.hoveredLinkIndex=void 0),e&&this.store.hoveredLinkIndex!==void 0&&((l=(a=this.config).onLinkMouseOver)==null||l.call(a,this.store.hoveredLinkIndex)),t&&((u=(c=this.config).onLinkMouseOut)==null||u.call(c,this.currentEvent))}updateCanvasCursor(){const{hoveredPointCursor:e,hoveredLinkCursor:t}=this.config;this.dragInstance.isActive?we(this.canvas).style("cursor","grabbing"):this.store.hoveredPoint?!this.config.enableDrag||this.store.isSpaceKeyPressed?we(this.canvas).style("cursor",e):we(this.canvas).style("cursor","grab"):this.store.isLinkHoveringEnabled&&this.store.hoveredLinkIndex!==void 0?we(this.canvas).style("cursor",t):we(this.canvas).style("cursor",null)}addAttribution(){var e;this.config.attribution&&(this.attributionDivElement=document.createElement("div"),this.attributionDivElement.style.cssText=`
2288
+ }`;function Ev(n,e=16384){if(!(n!=null&&n.length))return null;let t=0;for(const c of n){const u=Math.max(c.width,c.height);u>t&&(t=u)}if(t===0)return console.warn("Invalid image dimensions: all images have zero width or height"),null;const i=t,r=Math.ceil(Math.sqrt(n.length));let s=r*t,o=1;s>e&&(o=e/s,t=Math.max(1,Math.floor(t*o)),s=Math.max(1,Math.floor(s*o)),console.warn(`🖼️ Atlas scaling required: Original size ${(i*r).toLocaleString()}px exceeds WebGL limit ${e.toLocaleString()}px. Scaling down to ${s.toLocaleString()}px (${Math.round(o*100)}% of original quality)`));const a=new Uint8Array(s*s*4).fill(0),l=new Float32Array(r*r*4).fill(-1);for(const[c,u]of n.entries()){const f=u.width,h=u.height;if(f===0||h===0)continue;const d=Math.min(1,t/Math.max(f,h)),_=Math.floor(f*d),I=Math.floor(h*d),P=Math.floor(c/r),O=c%r*t,E=P*t;l[c*4]=O/s,l[c*4+1]=E/s,l[c*4+2]=(O+_)/s,l[c*4+3]=(E+I)/s;for(let y=0;y<I;y++)for(let R=0;R<_;R++){const N=Math.floor(R*(f/_)),W=(Math.floor(y*(h/I))*f+N)*4,q=((E+y)*s+(O+R))*4;a[q]=u.data[W]??0,a[q+1]=u.data[W+1]??0,a[q+2]=u.data[W+2]??0,a[q+3]=u.data[W+3]??255}}return{atlasData:a,atlasSize:s,atlasCoords:l,atlasCoordsSize:r}}class Rv extends Nt{constructor(){super(...arguments),this.imageCount=0,this.isPositionsUpToDate=!1,this.polygonPathLength=0}updatePositions(){const{device:e,store:t,data:i,config:{rescalePositions:r,enableSimulation:s}}=this,{pointsTextureSize:o}=t;if(!o||!i.pointPositions||i.pointsNumber===void 0)return;const a=o*o*4,l=new Float32Array(a),c=o*o*4*4,u=l.byteLength;u!==c&&console.error("Texture data size mismatch:",{pointsTextureSize:o,expectedBytes:c,actualBytes:u,textureDataSize:a,dataLength:l.length});let f=r;r===void 0&&!s&&(f=!0),this.shouldSkipRescale&&(f=!1),f?this.rescaleInitialNodePositions():this.shouldSkipRescale||(this.scaleX=void 0,this.scaleY=void 0),this.shouldSkipRescale=void 0;for(let _=0;_<i.pointsNumber;++_)l[_*4+0]=i.pointPositions[_*2+0],l[_*4+1]=i.pointPositions[_*2+1],l[_*4+2]=_;if(!this.currentPositionTexture||this.currentPositionTexture.width!==o||this.currentPositionTexture.height!==o?(this.currentPositionTexture&&!this.currentPositionTexture.destroyed&&this.currentPositionTexture.destroy(),this.currentPositionFbo&&!this.currentPositionFbo.destroyed&&this.currentPositionFbo.destroy(),this.currentPositionTexture=e.createTexture({width:o,height:o,format:"rgba32float"}),this.currentPositionTexture.copyImageData({data:l,bytesPerRow:ne("rgba32float",o),mipLevel:0,x:0,y:0}),this.currentPositionFbo=e.createFramebuffer({width:o,height:o,colorAttachments:[this.currentPositionTexture]})):this.currentPositionTexture.copyImageData({data:l,bytesPerRow:ne("rgba32float",o),mipLevel:0,x:0,y:0}),!this.previousPositionTexture||this.previousPositionTexture.width!==o||this.previousPositionTexture.height!==o?(this.previousPositionTexture&&!this.previousPositionTexture.destroyed&&this.previousPositionTexture.destroy(),this.previousPositionFbo&&!this.previousPositionFbo.destroyed&&this.previousPositionFbo.destroy(),this.previousPositionTexture=e.createTexture({width:o,height:o,format:"rgba32float"}),this.previousPositionTexture.copyImageData({data:l,bytesPerRow:ne("rgba32float",o),mipLevel:0,x:0,y:0}),this.previousPositionFbo=e.createFramebuffer({width:o,height:o,colorAttachments:[this.previousPositionTexture]})):this.previousPositionTexture.copyImageData({data:l,bytesPerRow:ne("rgba32float",o),mipLevel:0,x:0,y:0}),this.config.enableSimulation){const _=new Float32Array(o*o*4).fill(0);!this.velocityTexture||this.velocityTexture.width!==o||this.velocityTexture.height!==o?(this.velocityTexture&&!this.velocityTexture.destroyed&&this.velocityTexture.destroy(),this.velocityFbo&&!this.velocityFbo.destroyed&&this.velocityFbo.destroy(),this.velocityTexture=e.createTexture({width:o,height:o,format:"rgba32float"}),this.velocityTexture.copyImageData({data:_,bytesPerRow:ne("rgba32float",o),mipLevel:0,x:0,y:0}),this.velocityFbo=e.createFramebuffer({width:o,height:o,colorAttachments:[this.velocityTexture]})):this.velocityTexture.copyImageData({data:_,bytesPerRow:ne("rgba32float",o),mipLevel:0,x:0,y:0})}!this.selectedTexture||this.selectedTexture.width!==o||this.selectedTexture.height!==o?(this.selectedTexture&&!this.selectedTexture.destroyed&&this.selectedTexture.destroy(),this.selectedFbo&&!this.selectedFbo.destroyed&&this.selectedFbo.destroy(),this.selectedTexture=e.createTexture({width:o,height:o,format:"rgba32float"}),this.selectedTexture.copyImageData({data:l,bytesPerRow:ne("rgba32float",o),mipLevel:0,x:0,y:0}),this.selectedFbo=e.createFramebuffer({width:o,height:o,colorAttachments:[this.selectedTexture]})):this.selectedTexture.copyImageData({data:l,bytesPerRow:ne("rgba32float",o),mipLevel:0,x:0,y:0}),this.hoveredFbo||(this.hoveredFbo=e.createFramebuffer({width:2,height:2,colorAttachments:["rgba32float"]}));const h=yr(t.pointsTextureSize),d=h.byteLength;!this.drawPointIndices||this.drawPointIndices.byteLength!==d?(this.drawPointIndices&&!this.drawPointIndices.destroyed&&this.drawPointIndices.destroy(),this.drawPointIndices=e.createBuffer({data:h,usage:L.VERTEX|L.COPY_DST})):this.drawPointIndices.write(h),this.drawCommand&&this.drawCommand.setAttributes({pointIndices:this.drawPointIndices}),!this.hoveredPointIndices||this.hoveredPointIndices.byteLength!==d?(this.hoveredPointIndices&&!this.hoveredPointIndices.destroyed&&this.hoveredPointIndices.destroy(),this.hoveredPointIndices=e.createBuffer({data:h,usage:L.VERTEX|L.COPY_DST})):this.hoveredPointIndices.write(h),!this.sampledPointIndices||this.sampledPointIndices.byteLength!==d?(this.sampledPointIndices&&!this.sampledPointIndices.destroyed&&this.sampledPointIndices.destroy(),this.sampledPointIndices=e.createBuffer({data:h,usage:L.VERTEX|L.COPY_DST})):this.sampledPointIndices.write(h),this.fillSampledPointsFboCommand&&this.fillSampledPointsFboCommand.setAttributes({pointIndices:this.sampledPointIndices}),this.updateGreyoutStatus(),this.updatePinnedStatus(),this.updateSampledPointsGrid(),this.trackPointsByIndices()}initPrograms(){var s,o,a;const{device:e,config:t,store:i,data:r}=this;(!this.imageAtlasCoordsTexture||!this.imageAtlasTexture)&&this.createAtlas(),this.colorBuffer||this.updateColor(),this.sizeBuffer||this.updateSize(),this.shapeBuffer||this.updateShape(),this.imageIndicesBuffer||this.updateImageIndices(),this.imageSizesBuffer||this.updateImageSizes(),this.greyoutStatusTexture||this.updateGreyoutStatus(),t.enableSimulation&&(this.updatePositionVertexCoordBuffer||(this.updatePositionVertexCoordBuffer=e.createBuffer({data:new Float32Array([-1,-1,1,-1,-1,1,1,1])})),this.updatePositionUniformStore||(this.updatePositionUniformStore=new ye({updatePositionUniforms:{uniformTypes:{friction:"f32",spaceSize:"f32"},defaultUniforms:{friction:t.simulationFriction??0,spaceSize:i.adjustedSpaceSize??0}}})),this.updatePositionCommand||(this.updatePositionCommand=new _e(e,{fs:Cv,vs:tt,topology:"triangle-strip",vertexCount:4,attributes:{vertexCoord:this.updatePositionVertexCoordBuffer},bufferLayout:[{name:"vertexCoord",format:"float32x2"}],defines:{USE_UNIFORM_BUFFERS:!0},bindings:{updatePositionUniforms:this.updatePositionUniformStore.getManagedUniformBuffer(e,"updatePositionUniforms")}}))),this.dragPointVertexCoordBuffer||(this.dragPointVertexCoordBuffer=e.createBuffer({data:new Float32Array([-1,-1,1,-1,-1,1,1,1])})),this.dragPointUniformStore||(this.dragPointUniformStore=new ye({dragPointUniforms:{uniformTypes:{mousePos:"vec2<f32>",index:"f32"},defaultUniforms:{mousePos:re(i.mousePosition,[0,0]),index:((s=i.hoveredPoint)==null?void 0:s.index)??-1}}})),this.dragPointCommand||(this.dragPointCommand=new _e(e,{fs:Pv,vs:tt,topology:"triangle-strip",vertexCount:4,attributes:{vertexCoord:this.dragPointVertexCoordBuffer},bufferLayout:[{name:"vertexCoord",format:"float32x2"}],defines:{USE_UNIFORM_BUFFERS:!0},bindings:{dragPointUniforms:this.dragPointUniformStore.getManagedUniformBuffer(e,"dragPointUniforms")}})),this.drawUniformStore||(this.drawUniformStore=new ye({drawVertexUniforms:{uniformTypes:{ratio:"f32",transformationMatrix:"mat4x4<f32>",pointsTextureSize:"f32",sizeScale:"f32",spaceSize:"f32",screenSize:"vec2<f32>",greyoutColor:"vec4<f32>",backgroundColor:"vec4<f32>",scalePointsOnZoom:"f32",maxPointSize:"f32",isDarkenGreyout:"f32",skipSelected:"f32",skipUnselected:"f32",hasImages:"f32",imageCount:"f32",imageAtlasCoordsTextureSize:"f32"},defaultUniforms:{ratio:t.pixelRatio??V.pixelRatio,transformationMatrix:(()=>{const l=i.transform??[1,0,0,0,1,0,0,0,1];return[l[0],l[1],l[2],0,l[3],l[4],l[5],0,l[6],l[7],l[8],0,0,0,0,1]})(),pointsTextureSize:i.pointsTextureSize??0,sizeScale:t.pointSizeScale??1,spaceSize:i.adjustedSpaceSize??0,screenSize:re(i.screenSize,[0,0]),greyoutColor:Re(i.greyoutPointColor,[0,0,0,1]),backgroundColor:Re(i.backgroundColor,[0,0,0,1]),scalePointsOnZoom:t.scalePointsOnZoom??!0?1:0,maxPointSize:i.maxPointSize??100,isDarkenGreyout:i.isDarkenGreyout??!1?1:0,skipSelected:0,skipUnselected:0,hasImages:this.imageCount>0?1:0,imageCount:this.imageCount,imageAtlasCoordsTextureSize:this.imageAtlasCoordsTextureSize??0}},drawFragmentUniforms:{uniformTypes:{greyoutOpacity:"f32",pointOpacity:"f32",isDarkenGreyout:"f32",backgroundColor:"vec4<f32>"},defaultUniforms:{greyoutOpacity:t.pointGreyoutOpacity??-1,pointOpacity:t.pointOpacity??1,isDarkenGreyout:i.isDarkenGreyout??!1?1:0,backgroundColor:Re(i.backgroundColor,[0,0,0,1])}}})),this.drawCommand||(this.drawCommand=new _e(e,{fs:mv,vs:_v,topology:"point-list",vertexCount:r.pointsNumber??0,attributes:{...this.drawPointIndices&&{pointIndices:this.drawPointIndices},...this.sizeBuffer&&{size:this.sizeBuffer},...this.colorBuffer&&{color:this.colorBuffer},...this.shapeBuffer&&{shape:this.shapeBuffer},...this.imageIndicesBuffer&&{imageIndex:this.imageIndicesBuffer},...this.imageSizesBuffer&&{imageSize:this.imageSizesBuffer}},bufferLayout:[{name:"pointIndices",format:"float32x2"},{name:"size",format:"float32"},{name:"color",format:"float32x4"},{name:"shape",format:"float32"},{name:"imageIndex",format:"float32"},{name:"imageSize",format:"float32"}],defines:{USE_UNIFORM_BUFFERS:!0},bindings:{drawVertexUniforms:this.drawUniformStore.getManagedUniformBuffer(e,"drawVertexUniforms"),drawFragmentUniforms:this.drawUniformStore.getManagedUniformBuffer(e,"drawFragmentUniforms")},parameters:{blend:!0,blendColorOperation:"add",blendColorSrcFactor:"src-alpha",blendColorDstFactor:"one-minus-src-alpha",blendAlphaOperation:"add",blendAlphaSrcFactor:"one",blendAlphaDstFactor:"one-minus-src-alpha",depthWriteEnabled:!1,depthCompare:"always"}})),this.findPointsOnAreaSelectionVertexCoordBuffer||(this.findPointsOnAreaSelectionVertexCoordBuffer=e.createBuffer({data:new Float32Array([-1,-1,1,-1,-1,1,1,1])})),this.findPointsOnAreaSelectionUniformStore||(this.findPointsOnAreaSelectionUniformStore=new ye({findPointsOnAreaSelectionUniforms:{uniformTypes:{sizeScale:"f32",spaceSize:"f32",screenSize:"vec2<f32>",ratio:"f32",transformationMatrix:"mat4x4<f32>",selection0:"vec2<f32>",selection1:"vec2<f32>",scalePointsOnZoom:"f32",maxPointSize:"f32"},defaultUniforms:{sizeScale:t.pointSizeScale??1,spaceSize:i.adjustedSpaceSize??0,screenSize:re(i.screenSize,[0,0]),ratio:t.pixelRatio??V.pixelRatio,transformationMatrix:i.transformationMatrix4x4,selection0:re((o=i.selectedArea)==null?void 0:o[0],[0,0]),selection1:re((a=i.selectedArea)==null?void 0:a[1],[0,0]),scalePointsOnZoom:t.scalePointsOnZoom??!0?1:0,maxPointSize:i.maxPointSize??100}}})),this.findPointsOnAreaSelectionCommand||(this.findPointsOnAreaSelectionCommand=new _e(e,{fs:yv,vs:tt,topology:"triangle-strip",vertexCount:4,attributes:{vertexCoord:this.findPointsOnAreaSelectionVertexCoordBuffer},bufferLayout:[{name:"vertexCoord",format:"float32x2"}],defines:{USE_UNIFORM_BUFFERS:!0},bindings:{findPointsOnAreaSelectionUniforms:this.findPointsOnAreaSelectionUniformStore.getManagedUniformBuffer(e,"findPointsOnAreaSelectionUniforms")}})),this.findPointsOnPolygonSelectionVertexCoordBuffer||(this.findPointsOnPolygonSelectionVertexCoordBuffer=e.createBuffer({data:new Float32Array([-1,-1,1,-1,-1,1,1,1])})),this.findPointsOnPolygonSelectionUniformStore||(this.findPointsOnPolygonSelectionUniformStore=new ye({findPointsOnPolygonSelectionUniforms:{uniformTypes:{spaceSize:"f32",screenSize:"vec2<f32>",transformationMatrix:"mat4x4<f32>",polygonPathLength:"f32"},defaultUniforms:{spaceSize:i.adjustedSpaceSize??0,screenSize:re(i.screenSize,[0,0]),transformationMatrix:i.transformationMatrix4x4,polygonPathLength:this.polygonPathLength}}})),this.findPointsOnPolygonSelectionCommand||(this.findPointsOnPolygonSelectionCommand=new _e(e,{fs:xv,vs:tt,topology:"triangle-strip",vertexCount:4,attributes:{vertexCoord:this.findPointsOnPolygonSelectionVertexCoordBuffer},bufferLayout:[{name:"vertexCoord",format:"float32x2"}],defines:{USE_UNIFORM_BUFFERS:!0},bindings:{findPointsOnPolygonSelectionUniforms:this.findPointsOnPolygonSelectionUniformStore.getManagedUniformBuffer(e,"findPointsOnPolygonSelectionUniforms")}})),this.findHoveredPointUniformStore||(this.findHoveredPointUniformStore=new ye({findHoveredPointUniforms:{uniformTypes:{pointsTextureSize:"f32",sizeScale:"f32",spaceSize:"f32",screenSize:"vec2<f32>",ratio:"f32",transformationMatrix:"mat4x4<f32>",mousePosition:"vec2<f32>",scalePointsOnZoom:"f32",maxPointSize:"f32",skipSelected:"f32",skipUnselected:"f32"},defaultUniforms:{pointsTextureSize:i.pointsTextureSize??0,sizeScale:t.pointSizeScale??1,spaceSize:i.adjustedSpaceSize??0,screenSize:re(i.screenSize,[0,0]),ratio:t.pixelRatio??V.pixelRatio,transformationMatrix:i.transformationMatrix4x4,mousePosition:re(i.screenMousePosition,[0,0]),scalePointsOnZoom:t.scalePointsOnZoom??!0?1:0,maxPointSize:i.maxPointSize??100,skipSelected:0,skipUnselected:0}}})),this.findHoveredPointCommand||(this.findHoveredPointCommand=new _e(e,{fs:Sv,vs:Tv,topology:"point-list",vertexCount:r.pointsNumber??0,attributes:{...this.hoveredPointIndices&&{pointIndices:this.hoveredPointIndices},...this.sizeBuffer&&{size:this.sizeBuffer}},bufferLayout:[{name:"pointIndices",format:"float32x2"},{name:"size",format:"float32"}],defines:{USE_UNIFORM_BUFFERS:!0},bindings:{findHoveredPointUniforms:this.findHoveredPointUniformStore.getManagedUniformBuffer(e,"findHoveredPointUniforms")},parameters:{depthWriteEnabled:!1,depthCompare:"always",blend:!1}})),this.fillSampledPointsUniformStore||(this.fillSampledPointsUniformStore=new ye({fillSampledPointsUniforms:{uniformTypes:{pointsTextureSize:"f32",transformationMatrix:"mat4x4<f32>",spaceSize:"f32",screenSize:"vec2<f32>"},defaultUniforms:{pointsTextureSize:i.pointsTextureSize??0,transformationMatrix:i.transformationMatrix4x4,spaceSize:i.adjustedSpaceSize??0,screenSize:re(i.screenSize,[0,0])}}})),this.fillSampledPointsFboCommand||(this.fillSampledPointsFboCommand=new _e(e,{fs:wv,vs:Av,topology:"point-list",vertexCount:r.pointsNumber??0,attributes:{...this.sampledPointIndices&&{pointIndices:this.sampledPointIndices}},bufferLayout:[{name:"pointIndices",format:"float32x2"}],defines:{USE_UNIFORM_BUFFERS:!0},bindings:{fillSampledPointsUniforms:this.fillSampledPointsUniformStore.getManagedUniformBuffer(e,"fillSampledPointsUniforms")},parameters:{depthWriteEnabled:!1,depthCompare:"always"}})),this.drawHighlightedVertexCoordBuffer||(this.drawHighlightedVertexCoordBuffer=e.createBuffer({data:new Float32Array([-1,-1,1,-1,-1,1,1,1])})),this.drawHighlightedUniformStore||(this.drawHighlightedUniformStore=new ye({drawHighlightedUniforms:{uniformTypes:{size:"f32",transformationMatrix:"mat4x4<f32>",pointsTextureSize:"f32",sizeScale:"f32",spaceSize:"f32",screenSize:"vec2<f32>",scalePointsOnZoom:"f32",pointIndex:"f32",maxPointSize:"f32",color:"vec4<f32>",universalPointOpacity:"f32",greyoutOpacity:"f32",isDarkenGreyout:"f32",backgroundColor:"vec4<f32>",greyoutColor:"vec4<f32>",width:"f32"},defaultUniforms:{size:1,transformationMatrix:i.transformationMatrix4x4,pointsTextureSize:i.pointsTextureSize??0,sizeScale:t.pointSizeScale??1,spaceSize:i.adjustedSpaceSize??0,screenSize:re(i.screenSize,[0,0]),scalePointsOnZoom:t.scalePointsOnZoom??!0?1:0,pointIndex:-1,maxPointSize:i.maxPointSize??100,color:[0,0,0,1],universalPointOpacity:t.pointOpacity??1,greyoutOpacity:t.pointGreyoutOpacity??-1,isDarkenGreyout:i.isDarkenGreyout??!1?1:0,backgroundColor:Re(i.backgroundColor,[0,0,0,1]),greyoutColor:Re(i.greyoutPointColor,[0,0,0,1]),width:.85}}})),this.drawHighlightedCommand||(this.drawHighlightedCommand=new _e(e,{fs:vv,vs:bv,topology:"triangle-strip",vertexCount:4,attributes:{vertexCoord:this.drawHighlightedVertexCoordBuffer},bufferLayout:[{name:"vertexCoord",format:"float32x2"}],defines:{USE_UNIFORM_BUFFERS:!0},bindings:{drawHighlightedUniforms:this.drawHighlightedUniformStore.getManagedUniformBuffer(e,"drawHighlightedUniforms")},parameters:{blend:!0,blendColorOperation:"add",blendColorSrcFactor:"src-alpha",blendColorDstFactor:"one-minus-src-alpha",blendAlphaOperation:"add",blendAlphaSrcFactor:"one",blendAlphaDstFactor:"one-minus-src-alpha",depthWriteEnabled:!1,depthCompare:"always"}})),this.trackPointsVertexCoordBuffer||(this.trackPointsVertexCoordBuffer=e.createBuffer({data:new Float32Array([-1,-1,1,-1,-1,1,1,1])})),this.trackPointsUniformStore||(this.trackPointsUniformStore=new ye({trackPointsUniforms:{uniformTypes:{pointsTextureSize:"f32"},defaultUniforms:{pointsTextureSize:i.pointsTextureSize??0}}})),this.trackPointsCommand||(this.trackPointsCommand=new _e(e,{fs:Iv,vs:tt,topology:"triangle-strip",vertexCount:4,attributes:{vertexCoord:this.trackPointsVertexCoordBuffer},bufferLayout:[{name:"vertexCoord",format:"float32x2"}],defines:{USE_UNIFORM_BUFFERS:!0},bindings:{trackPointsUniforms:this.trackPointsUniformStore.getManagedUniformBuffer(e,"trackPointsUniforms")}}))}updateColor(){const{device:e,store:{pointsTextureSize:t},data:i}=this;if(!t)return;const r=i.pointColors,s=r.byteLength;!this.colorBuffer||this.colorBuffer.byteLength!==s?(this.colorBuffer&&!this.colorBuffer.destroyed&&this.colorBuffer.destroy(),this.colorBuffer=e.createBuffer({data:r,usage:L.VERTEX|L.COPY_DST})):this.colorBuffer.write(r),this.drawCommand&&this.drawCommand.setAttributes({color:this.colorBuffer})}updateGreyoutStatus(){const{device:e,store:{selectedIndices:t,pointsTextureSize:i}}=this;if(!i)return;const r=new Float32Array(i*i*4).fill(t?1:0);if(t)for(const s of t)r[s*4]=0;!this.greyoutStatusTexture||this.greyoutStatusTexture.width!==i||this.greyoutStatusTexture.height!==i?(this.greyoutStatusTexture&&!this.greyoutStatusTexture.destroyed&&this.greyoutStatusTexture.destroy(),this.greyoutStatusTexture=e.createTexture({width:i,height:i,format:"rgba32float"}),this.greyoutStatusTexture.copyImageData({data:r,bytesPerRow:ne("rgba32float",i),mipLevel:0,x:0,y:0})):this.greyoutStatusTexture.copyImageData({data:r,bytesPerRow:ne("rgba32float",i),mipLevel:0,x:0,y:0})}updatePinnedStatus(){const{device:e,store:{pointsTextureSize:t},data:i}=this;if(!t)return;const r=new Float32Array(t*t*4).fill(0);if(i.inputPinnedPoints&&i.pointsNumber!==void 0)for(const s of i.inputPinnedPoints)s>=0&&s<i.pointsNumber&&(r[s*4]=1);!this.pinnedStatusTexture||this.pinnedStatusTexture.width!==t||this.pinnedStatusTexture.height!==t?(this.pinnedStatusTexture&&!this.pinnedStatusTexture.destroyed&&this.pinnedStatusTexture.destroy(),this.pinnedStatusTexture=e.createTexture({width:t,height:t,format:"rgba32float"}),this.pinnedStatusTexture.copyImageData({data:r,bytesPerRow:ne("rgba32float",t),mipLevel:0,x:0,y:0})):this.pinnedStatusTexture.copyImageData({data:r,bytesPerRow:ne("rgba32float",t),mipLevel:0,x:0,y:0})}updateSize(){const{device:e,store:{pointsTextureSize:t},data:i}=this;if(!t||i.pointsNumber===void 0||i.pointSizes===void 0)return;const r=i.pointSizes,s=r.byteLength;!this.sizeBuffer||this.sizeBuffer.byteLength!==s?(this.sizeBuffer&&!this.sizeBuffer.destroyed&&this.sizeBuffer.destroy(),this.sizeBuffer=e.createBuffer({data:r,usage:L.VERTEX|L.COPY_DST})):this.sizeBuffer.write(r),this.drawCommand&&this.drawCommand.setAttributes({size:this.sizeBuffer});const o=new Float32Array(t*t*4);for(let a=0;a<i.pointsNumber;a++)o[a*4]=i.pointSizes[a];!this.sizeTexture||this.sizeTexture.width!==t||this.sizeTexture.height!==t?(this.sizeTexture&&!this.sizeTexture.destroyed&&this.sizeTexture.destroy(),this.sizeTexture=e.createTexture({width:t,height:t,format:"rgba32float"}),this.sizeTexture.copyImageData({data:o,bytesPerRow:ne("rgba32float",t),mipLevel:0,x:0,y:0})):this.sizeTexture.copyImageData({data:o,bytesPerRow:ne("rgba32float",t),mipLevel:0,x:0,y:0})}updateShape(){const{device:e,data:t}=this;if(t.pointsNumber===void 0||t.pointShapes===void 0)return;const i=t.pointShapes,r=i.byteLength;!this.shapeBuffer||this.shapeBuffer.byteLength!==r?(this.shapeBuffer&&!this.shapeBuffer.destroyed&&this.shapeBuffer.destroy(),this.shapeBuffer=e.createBuffer({data:i,usage:L.VERTEX|L.COPY_DST})):this.shapeBuffer.write(i),this.drawCommand&&this.drawCommand.setAttributes({shape:this.shapeBuffer})}updateImageIndices(){const{device:e,data:t}=this;if(t.pointsNumber===void 0||t.pointImageIndices===void 0)return;const i=t.pointImageIndices,r=i.byteLength;!this.imageIndicesBuffer||this.imageIndicesBuffer.byteLength!==r?(this.imageIndicesBuffer&&!this.imageIndicesBuffer.destroyed&&this.imageIndicesBuffer.destroy(),this.imageIndicesBuffer=e.createBuffer({data:i,usage:L.VERTEX|L.COPY_DST})):this.imageIndicesBuffer.write(i),this.drawCommand&&this.drawCommand.setAttributes({imageIndex:this.imageIndicesBuffer})}updateImageSizes(){const{device:e,data:t}=this;if(t.pointsNumber===void 0||t.pointImageSizes===void 0)return;const i=t.pointImageSizes,r=i.byteLength;!this.imageSizesBuffer||this.imageSizesBuffer.byteLength!==r?(this.imageSizesBuffer&&!this.imageSizesBuffer.destroyed&&this.imageSizesBuffer.destroy(),this.imageSizesBuffer=e.createBuffer({data:i,usage:L.VERTEX|L.COPY_DST})):this.imageSizesBuffer.write(i),this.drawCommand&&this.drawCommand.setAttributes({imageSize:this.imageSizesBuffer})}createAtlas(){var c;const{device:e,data:t,store:i}=this;if(!((c=t.inputImageData)!=null&&c.length)){this.imageCount=0,this.imageAtlasCoordsTextureSize=0,this.imageAtlasCoordsTexture||(this.imageAtlasCoordsTexture=e.createTexture({data:new Float32Array(4).fill(0),width:1,height:1,format:"rgba32float"})),this.imageAtlasTexture||(this.imageAtlasTexture=e.createTexture({data:new Uint8Array(4).fill(0),width:1,height:1,format:"rgba8unorm"}));return}const r=Ev(t.inputImageData,i.webglMaxTextureSize);if(!r){console.warn("Failed to create atlas from image data");return}this.imageCount=t.inputImageData.length;const{atlasData:s,atlasSize:o,atlasCoords:a,atlasCoordsSize:l}=r;this.imageAtlasCoordsTextureSize=l,this.imageAtlasTexture&&!this.imageAtlasTexture.destroyed&&this.imageAtlasTexture.destroy(),this.imageAtlasTexture=e.createTexture({width:o,height:o,format:"rgba8unorm"}),this.imageAtlasTexture.copyImageData({data:s,bytesPerRow:ne("rgba8unorm",o),rowsPerImage:o,mipLevel:0,x:0,y:0}),this.imageAtlasCoordsTexture&&!this.imageAtlasCoordsTexture.destroyed&&this.imageAtlasCoordsTexture.destroy(),this.imageAtlasCoordsTexture=e.createTexture({width:l,height:l,format:"rgba32float"}),this.imageAtlasCoordsTexture.copyImageData({data:a,bytesPerRow:ne("rgba32float",l),rowsPerImage:l,mipLevel:0,x:0,y:0})}updateSampledPointsGrid(){const{store:{screenSize:e},config:{pointSamplingDistance:t},device:i}=this;let r=t??Math.min(...e)/2;r===0&&(r=V.pointSamplingDistance);const s=Math.ceil(e[0]/r),o=Math.ceil(e[1]/r);(!this.sampledPointsFbo||this.sampledPointsFbo.width!==s||this.sampledPointsFbo.height!==o)&&(this.sampledPointsFbo&&!this.sampledPointsFbo.destroyed&&this.sampledPointsFbo.destroy(),this.sampledPointsFbo=i.createFramebuffer({width:s,height:o,colorAttachments:["rgba32float"]}))}trackPoints(){var t;if(!((t=this.trackedIndices)!=null&&t.length)||!this.trackPointsCommand||!this.trackPointsUniformStore||!this.trackedPositionsFbo||this.trackedPositionsFbo.destroyed||!this.currentPositionTexture||this.currentPositionTexture.destroyed||!this.trackedIndicesTexture||this.trackedIndicesTexture.destroyed)return;this.trackPointsUniformStore.setUniforms({trackPointsUniforms:{pointsTextureSize:this.store.pointsTextureSize??0}}),this.trackPointsCommand.setBindings({positionsTexture:this.currentPositionTexture,trackedIndices:this.trackedIndicesTexture});const e=this.device.beginRenderPass({framebuffer:this.trackedPositionsFbo});this.trackPointsCommand.draw(e),e.end()}draw(e){var a,l;const{data:t,config:i,store:r}=this;if(this.colorBuffer||this.updateColor(),this.sizeBuffer||this.updateSize(),this.shapeBuffer||this.updateShape(),this.imageIndicesBuffer||this.updateImageIndices(),this.imageSizesBuffer||this.updateImageSizes(),!this.drawCommand||!this.drawUniformStore||!this.currentPositionTexture||this.currentPositionTexture.destroyed||!this.greyoutStatusTexture||this.greyoutStatusTexture.destroyed||(!this.imageAtlasTexture||!this.imageAtlasCoordsTexture)&&(this.createAtlas(),!this.imageAtlasTexture||!this.imageAtlasCoordsTexture)||this.imageAtlasTexture.destroyed||this.imageAtlasCoordsTexture.destroyed||!t.pointsNumber||t.pointsNumber===0||!r.screenSize||r.screenSize[0]===0||r.screenSize[1]===0)return;this.drawCommand.setVertexCount(t.pointsNumber);const s={ratio:i.pixelRatio??V.pixelRatio,transformationMatrix:r.transformationMatrix4x4,pointsTextureSize:r.pointsTextureSize??0,sizeScale:i.pointSizeScale??1,spaceSize:r.adjustedSpaceSize??0,screenSize:re(r.screenSize,[0,0]),greyoutColor:Re(r.greyoutPointColor,[-1,-1,-1,-1]),backgroundColor:Re(r.backgroundColor,[0,0,0,1]),scalePointsOnZoom:i.scalePointsOnZoom??!0?1:0,maxPointSize:r.maxPointSize??100,isDarkenGreyout:r.isDarkenGreyout??!1?1:0,hasImages:this.imageCount>0?1:0,imageCount:this.imageCount,imageAtlasCoordsTextureSize:this.imageAtlasCoordsTextureSize??0},o={greyoutOpacity:i.pointGreyoutOpacity??-1,pointOpacity:i.pointOpacity??1,isDarkenGreyout:r.isDarkenGreyout??!1?1:0,backgroundColor:Re(r.backgroundColor,[0,0,0,1])};if(r.selectedIndices&&r.selectedIndices.length>0?(this.drawUniformStore.setUniforms({drawVertexUniforms:{...s,skipSelected:1,skipUnselected:0},drawFragmentUniforms:o}),this.drawCommand.setBindings({positionsTexture:this.currentPositionTexture,pointGreyoutStatus:this.greyoutStatusTexture,imageAtlasTexture:this.imageAtlasTexture,imageAtlasCoords:this.imageAtlasCoordsTexture}),this.drawCommand.draw(e),this.drawUniformStore.setUniforms({drawVertexUniforms:{...s,skipSelected:0,skipUnselected:1},drawFragmentUniforms:o}),this.drawCommand.setBindings({positionsTexture:this.currentPositionTexture,pointGreyoutStatus:this.greyoutStatusTexture,imageAtlasTexture:this.imageAtlasTexture,imageAtlasCoords:this.imageAtlasCoordsTexture}),this.drawCommand.draw(e)):(this.drawUniformStore.setUniforms({drawVertexUniforms:{...s,skipSelected:0,skipUnselected:0},drawFragmentUniforms:o}),this.drawCommand.setBindings({positionsTexture:this.currentPositionTexture,pointGreyoutStatus:this.greyoutStatusTexture,imageAtlasTexture:this.imageAtlasTexture,imageAtlasCoords:this.imageAtlasCoordsTexture}),this.drawCommand.draw(e)),i.renderHoveredPointRing&&r.hoveredPoint&&this.drawHighlightedCommand&&this.drawHighlightedUniformStore){if(!this.currentPositionTexture||this.currentPositionTexture.destroyed||!this.greyoutStatusTexture||this.greyoutStatusTexture.destroyed)return;const c=((a=t.pointSizes)==null?void 0:a[r.hoveredPoint.index])??1;this.drawHighlightedUniformStore.setUniforms({drawHighlightedUniforms:{size:c,transformationMatrix:r.transformationMatrix4x4,pointsTextureSize:r.pointsTextureSize??0,sizeScale:i.pointSizeScale??1,spaceSize:r.adjustedSpaceSize??0,screenSize:re(r.screenSize,[0,0]),scalePointsOnZoom:i.scalePointsOnZoom??!0?1:0,pointIndex:r.hoveredPoint.index,maxPointSize:r.maxPointSize??100,color:Re(r.hoveredPointRingColor,[0,0,0,1]),universalPointOpacity:i.pointOpacity??1,greyoutOpacity:i.pointGreyoutOpacity??-1,isDarkenGreyout:r.isDarkenGreyout??!1?1:0,backgroundColor:Re(r.backgroundColor,[0,0,0,1]),greyoutColor:Re(r.greyoutPointColor,[0,0,0,1]),width:.85}}),this.drawHighlightedCommand.setBindings({positionsTexture:this.currentPositionTexture,pointGreyoutStatusTexture:this.greyoutStatusTexture}),this.drawHighlightedCommand.draw(e)}if(r.focusedPoint&&this.drawHighlightedCommand&&this.drawHighlightedUniformStore){if(!this.currentPositionTexture||this.currentPositionTexture.destroyed||!this.greyoutStatusTexture||this.greyoutStatusTexture.destroyed)return;const c=((l=t.pointSizes)==null?void 0:l[r.focusedPoint.index])??1;this.drawHighlightedUniformStore.setUniforms({drawHighlightedUniforms:{size:c,transformationMatrix:r.transformationMatrix4x4,pointsTextureSize:r.pointsTextureSize??0,sizeScale:i.pointSizeScale??1,spaceSize:r.adjustedSpaceSize??0,screenSize:re(r.screenSize,[0,0]),scalePointsOnZoom:i.scalePointsOnZoom??!0?1:0,pointIndex:r.focusedPoint.index,maxPointSize:r.maxPointSize??100,color:Re(r.focusedPointRingColor,[0,0,0,1]),universalPointOpacity:i.pointOpacity??1,greyoutOpacity:i.pointGreyoutOpacity??-1,isDarkenGreyout:r.isDarkenGreyout??!1?1:0,backgroundColor:Re(r.backgroundColor,[0,0,0,1]),greyoutColor:Re(r.greyoutPointColor,[0,0,0,1]),width:.85}}),this.drawHighlightedCommand.setBindings({positionsTexture:this.currentPositionTexture,pointGreyoutStatusTexture:this.greyoutStatusTexture}),this.drawHighlightedCommand.draw(e)}}updatePosition(){if(!this.updatePositionCommand||!this.updatePositionUniformStore||!this.currentPositionFbo||this.currentPositionFbo.destroyed||!this.previousPositionTexture||this.previousPositionTexture.destroyed||!this.velocityTexture||this.velocityTexture.destroyed||!this.pinnedStatusTexture||this.pinnedStatusTexture.destroyed)return;this.updatePositionUniformStore.setUniforms({updatePositionUniforms:{friction:this.config.simulationFriction??0,spaceSize:this.store.adjustedSpaceSize??0}}),this.updatePositionCommand.setBindings({positionsTexture:this.previousPositionTexture,velocity:this.velocityTexture,pinnedStatusTexture:this.pinnedStatusTexture});const e=this.device.beginRenderPass({framebuffer:this.currentPositionFbo});this.updatePositionCommand.draw(e),e.end(),this.swapFbo(),this.isPositionsUpToDate=!1}drag(){var t;if(!this.dragPointCommand||!this.dragPointUniformStore||!this.currentPositionFbo||this.currentPositionFbo.destroyed||!this.previousPositionTexture||this.previousPositionTexture.destroyed)return;this.dragPointUniformStore.setUniforms({dragPointUniforms:{mousePos:re(this.store.mousePosition,[0,0]),index:((t=this.store.hoveredPoint)==null?void 0:t.index)??-1}}),this.dragPointCommand.setBindings({positionsTexture:this.previousPositionTexture});const e=this.device.beginRenderPass({framebuffer:this.currentPositionFbo});this.dragPointCommand.draw(e),e.end(),this.swapFbo(),this.isPositionsUpToDate=!1}findPointsOnAreaSelection(){var t,i;if(!this.findPointsOnAreaSelectionCommand||!this.findPointsOnAreaSelectionUniformStore||!this.selectedFbo||this.selectedFbo.destroyed||!this.currentPositionTexture||this.currentPositionTexture.destroyed||!this.sizeTexture||this.sizeTexture.destroyed)return;this.findPointsOnAreaSelectionUniformStore.setUniforms({findPointsOnAreaSelectionUniforms:{spaceSize:this.store.adjustedSpaceSize??0,screenSize:re(this.store.screenSize,[0,0]),sizeScale:this.config.pointSizeScale??1,transformationMatrix:this.store.transformationMatrix4x4,ratio:this.config.pixelRatio??V.pixelRatio,selection0:re((t=this.store.selectedArea)==null?void 0:t[0],[0,0]),selection1:re((i=this.store.selectedArea)==null?void 0:i[1],[0,0]),scalePointsOnZoom:this.config.scalePointsOnZoom??!0?1:0,maxPointSize:this.store.maxPointSize??100}}),this.findPointsOnAreaSelectionCommand.setBindings({positionsTexture:this.currentPositionTexture,pointSize:this.sizeTexture});const e=this.device.beginRenderPass({framebuffer:this.selectedFbo});this.findPointsOnAreaSelectionCommand.draw(e),e.end()}findPointsOnPolygonSelection(){if(!this.findPointsOnPolygonSelectionCommand||!this.findPointsOnPolygonSelectionUniformStore||!this.selectedFbo||this.selectedFbo.destroyed||!this.currentPositionTexture||this.currentPositionTexture.destroyed||!this.polygonPathTexture||this.polygonPathTexture.destroyed)return;this.findPointsOnPolygonSelectionUniformStore.setUniforms({findPointsOnPolygonSelectionUniforms:{spaceSize:this.store.adjustedSpaceSize??0,screenSize:re(this.store.screenSize,[0,0]),transformationMatrix:this.store.transformationMatrix4x4,polygonPathLength:this.polygonPathLength}}),this.findPointsOnPolygonSelectionCommand.setBindings({positionsTexture:this.currentPositionTexture,polygonPathTexture:this.polygonPathTexture});const e=this.device.beginRenderPass({framebuffer:this.selectedFbo});this.findPointsOnPolygonSelectionCommand.draw(e),e.end()}updatePolygonPath(e){const{device:t}=this;if(this.polygonPathLength=e.length,e.length===0){this.polygonPathTexture&&!this.polygonPathTexture.destroyed&&this.polygonPathTexture.destroy(),this.polygonPathTexture=void 0;return}const i=Math.ceil(Math.sqrt(e.length)),r=new Float32Array(i*i*4);for(const[s,o]of e.entries()){const[a,l]=o;r[s*4]=a,r[s*4+1]=l,r[s*4+2]=0,r[s*4+3]=0}!this.polygonPathTexture||this.polygonPathTexture.width!==i||this.polygonPathTexture.height!==i?(this.polygonPathTexture&&!this.polygonPathTexture.destroyed&&this.polygonPathTexture.destroy(),this.polygonPathTexture=t.createTexture({width:i,height:i,format:"rgba32float"}),this.polygonPathTexture.copyImageData({data:r,bytesPerRow:ne("rgba32float",i),mipLevel:0,x:0,y:0})):this.polygonPathTexture.copyImageData({data:r,bytesPerRow:ne("rgba32float",i),mipLevel:0,x:0,y:0})}findHoveredPoint(){if(!this.hoveredFbo||this.hoveredFbo.destroyed||!this.findHoveredPointCommand||!this.findHoveredPointUniformStore||!this.currentPositionTexture||this.currentPositionTexture.destroyed||(this.greyoutStatusTexture||this.updateGreyoutStatus(),!this.greyoutStatusTexture||this.greyoutStatusTexture.destroyed))return;this.findHoveredPointCommand.setVertexCount(this.data.pointsNumber??0),this.findHoveredPointCommand.setAttributes({...this.hoveredPointIndices&&{pointIndices:this.hoveredPointIndices},...this.sizeBuffer&&{size:this.sizeBuffer}});const e={ratio:this.config.pixelRatio??V.pixelRatio,sizeScale:this.config.pointSizeScale??1,pointsTextureSize:this.store.pointsTextureSize??0,transformationMatrix:this.store.transformationMatrix4x4,spaceSize:this.store.adjustedSpaceSize??0,screenSize:re(this.store.screenSize,[0,0]),scalePointsOnZoom:this.config.scalePointsOnZoom??!0?1:0,mousePosition:re(this.store.screenMousePosition,[0,0]),maxPointSize:this.store.maxPointSize??100},t={positionsTexture:this.currentPositionTexture,pointGreyoutStatus:this.greyoutStatusTexture},i=this.device.beginRenderPass({framebuffer:this.hoveredFbo,clearColor:[0,0,0,0]});this.store.selectedIndices&&this.store.selectedIndices.length>0?(this.findHoveredPointUniformStore.setUniforms({findHoveredPointUniforms:{...e,skipSelected:1,skipUnselected:0}}),this.findHoveredPointCommand.setBindings(t),this.findHoveredPointCommand.draw(i),this.findHoveredPointUniformStore.setUniforms({findHoveredPointUniforms:{...e,skipSelected:0,skipUnselected:1}}),this.findHoveredPointCommand.setBindings(t),this.findHoveredPointCommand.draw(i)):(this.findHoveredPointUniformStore.setUniforms({findHoveredPointUniforms:{...e,skipSelected:0,skipUnselected:0}}),this.findHoveredPointCommand.setBindings(t),this.findHoveredPointCommand.draw(i)),i.end()}trackPointsByIndices(e){const{store:{pointsTextureSize:t},device:i}=this;if(this.trackedIndices=e,this.trackedPositions=void 0,this.isPositionsUpToDate=!1,!(e!=null&&e.length)||!t)return;const r=Math.ceil(Math.sqrt(e.length)),s=new Float32Array(r*r*4).fill(-1);for(const[o,a]of e.entries())a!==void 0&&(s[o*4]=a%t,s[o*4+1]=Math.floor(a/t),s[o*4+2]=0,s[o*4+3]=0);!this.trackedIndicesTexture||this.trackedIndicesTexture.width!==r||this.trackedIndicesTexture.height!==r?(this.trackedIndicesTexture&&!this.trackedIndicesTexture.destroyed&&this.trackedIndicesTexture.destroy(),this.trackedIndicesTexture=i.createTexture({width:r,height:r,format:"rgba32float"}),this.trackedIndicesTexture.copyImageData({data:s,bytesPerRow:ne("rgba32float",r),mipLevel:0,x:0,y:0})):this.trackedIndicesTexture.copyImageData({data:s,bytesPerRow:ne("rgba32float",r),mipLevel:0,x:0,y:0}),(!this.trackedPositionsFbo||this.trackedPositionsFbo.width!==r||this.trackedPositionsFbo.height!==r)&&(this.trackedPositionsFbo&&!this.trackedPositionsFbo.destroyed&&this.trackedPositionsFbo.destroy(),this.trackedPositionsFbo=i.createFramebuffer({width:r,height:r,colorAttachments:["rgba32float"]})),this.trackPoints()}getTrackedPositionsMap(){if(!this.trackedIndices)return new Map;const{config:{enableSimulation:e},store:{isSimulationRunning:t}}=this;if((!e||!t)&&this.isPositionsUpToDate&&this.trackedPositions)return this.trackedPositions;if(!this.trackedPositionsFbo||this.trackedPositionsFbo.destroyed)return new Map;const i=Xe(this.device,this.trackedPositionsFbo),r=new Map;for(let s=0;s<i.length/4;s+=1){const o=i[s*4],a=i[s*4+1],l=this.trackedIndices[s];o!==void 0&&a!==void 0&&l!==void 0&&r.set(l,[o,a])}return(!e||!t)&&(this.trackedPositions=r,this.isPositionsUpToDate=!0),r}getSampledPointPositionsMap(){const e=new Map;if(!this.sampledPointsFbo||this.sampledPointsFbo.destroyed)return e;if(this.fillSampledPointsFboCommand&&this.fillSampledPointsUniformStore&&this.sampledPointsFbo){if(!this.currentPositionTexture||this.currentPositionTexture.destroyed)return e;this.fillSampledPointsFboCommand.setVertexCount(this.data.pointsNumber??0),this.fillSampledPointsUniformStore.setUniforms({fillSampledPointsUniforms:{pointsTextureSize:this.store.pointsTextureSize??0,transformationMatrix:this.store.transformationMatrix4x4,spaceSize:this.store.adjustedSpaceSize??0,screenSize:re(this.store.screenSize,[0,0])}}),this.fillSampledPointsFboCommand.setBindings({positionsTexture:this.currentPositionTexture});const i=this.device.beginRenderPass({framebuffer:this.sampledPointsFbo,clearColor:[0,0,0,0]});this.fillSampledPointsFboCommand.draw(i),i.end()}const t=Xe(this.device,this.sampledPointsFbo);for(let i=0;i<t.length/4;i++){const r=t[i*4],s=!!t[i*4+1],o=t[i*4+2],a=t[i*4+3];s&&r!==void 0&&o!==void 0&&a!==void 0&&e.set(r,[o,a])}return e}getSampledPoints(){const e=[],t=[];if(!this.sampledPointsFbo||this.sampledPointsFbo.destroyed)return{indices:e,positions:t};if(this.fillSampledPointsFboCommand&&this.fillSampledPointsUniformStore&&this.sampledPointsFbo){if(!this.currentPositionTexture||this.currentPositionTexture.destroyed)return{indices:e,positions:t};this.fillSampledPointsFboCommand.setVertexCount(this.data.pointsNumber??0),this.fillSampledPointsUniformStore.setUniforms({fillSampledPointsUniforms:{pointsTextureSize:this.store.pointsTextureSize??0,transformationMatrix:this.store.transformationMatrix4x4,spaceSize:this.store.adjustedSpaceSize??0,screenSize:re(this.store.screenSize,[0,0])}}),this.fillSampledPointsFboCommand.setBindings({positionsTexture:this.currentPositionTexture});const r=this.device.beginRenderPass({framebuffer:this.sampledPointsFbo,clearColor:[0,0,0,0]});this.fillSampledPointsFboCommand.draw(r),r.end()}const i=Xe(this.device,this.sampledPointsFbo);for(let r=0;r<i.length/4;r++){const s=i[r*4],o=!!i[r*4+1],a=i[r*4+2],l=i[r*4+3];o&&s!==void 0&&a!==void 0&&l!==void 0&&(e.push(s),t.push(a,l))}return{indices:e,positions:t}}getTrackedPositionsArray(){const e=[];if(!this.trackedIndices||!this.trackedPositionsFbo||this.trackedPositionsFbo.destroyed)return e;e.length=this.trackedIndices.length*2;const t=Xe(this.device,this.trackedPositionsFbo);for(let i=0;i<t.length/4;i+=1){const r=t[i*4],s=t[i*4+1],o=this.trackedIndices[i];r!==void 0&&s!==void 0&&o!==void 0&&(e[i*2]=r,e[i*2+1]=s)}return e}destroy(){var e,t,i,r,s,o,a,l,c,u,f,h,d,_,I,P,A,O;(e=this.drawCommand)==null||e.destroy(),this.drawCommand=void 0,(t=this.drawHighlightedCommand)==null||t.destroy(),this.drawHighlightedCommand=void 0,(i=this.updatePositionCommand)==null||i.destroy(),this.updatePositionCommand=void 0,(r=this.dragPointCommand)==null||r.destroy(),this.dragPointCommand=void 0,(s=this.findPointsOnAreaSelectionCommand)==null||s.destroy(),this.findPointsOnAreaSelectionCommand=void 0,(o=this.findPointsOnPolygonSelectionCommand)==null||o.destroy(),this.findPointsOnPolygonSelectionCommand=void 0,(a=this.findHoveredPointCommand)==null||a.destroy(),this.findHoveredPointCommand=void 0,(l=this.fillSampledPointsFboCommand)==null||l.destroy(),this.fillSampledPointsFboCommand=void 0,(c=this.trackPointsCommand)==null||c.destroy(),this.trackPointsCommand=void 0,this.currentPositionFbo&&!this.currentPositionFbo.destroyed&&this.currentPositionFbo.destroy(),this.currentPositionFbo=void 0,this.previousPositionFbo&&!this.previousPositionFbo.destroyed&&this.previousPositionFbo.destroy(),this.previousPositionFbo=void 0,this.velocityFbo&&!this.velocityFbo.destroyed&&this.velocityFbo.destroy(),this.velocityFbo=void 0,this.selectedFbo&&!this.selectedFbo.destroyed&&this.selectedFbo.destroy(),this.selectedFbo=void 0,this.hoveredFbo&&!this.hoveredFbo.destroyed&&this.hoveredFbo.destroy(),this.hoveredFbo=void 0,this.trackedPositionsFbo&&!this.trackedPositionsFbo.destroyed&&this.trackedPositionsFbo.destroy(),this.trackedPositionsFbo=void 0,this.sampledPointsFbo&&!this.sampledPointsFbo.destroyed&&this.sampledPointsFbo.destroy(),this.sampledPointsFbo=void 0,this.currentPositionTexture&&!this.currentPositionTexture.destroyed&&this.currentPositionTexture.destroy(),this.currentPositionTexture=void 0,this.previousPositionTexture&&!this.previousPositionTexture.destroyed&&this.previousPositionTexture.destroy(),this.previousPositionTexture=void 0,this.velocityTexture&&!this.velocityTexture.destroyed&&this.velocityTexture.destroy(),this.velocityTexture=void 0,this.selectedTexture&&!this.selectedTexture.destroyed&&this.selectedTexture.destroy(),this.selectedTexture=void 0,this.greyoutStatusTexture&&!this.greyoutStatusTexture.destroyed&&this.greyoutStatusTexture.destroy(),this.greyoutStatusTexture=void 0,this.sizeTexture&&!this.sizeTexture.destroyed&&this.sizeTexture.destroy(),this.sizeTexture=void 0,this.trackedIndicesTexture&&!this.trackedIndicesTexture.destroyed&&this.trackedIndicesTexture.destroy(),this.trackedIndicesTexture=void 0,this.polygonPathTexture&&!this.polygonPathTexture.destroyed&&this.polygonPathTexture.destroy(),this.polygonPathTexture=void 0,this.imageAtlasTexture&&!this.imageAtlasTexture.destroyed&&this.imageAtlasTexture.destroy(),this.imageAtlasTexture=void 0,this.imageAtlasCoordsTexture&&!this.imageAtlasCoordsTexture.destroyed&&this.imageAtlasCoordsTexture.destroy(),this.imageAtlasCoordsTexture=void 0,this.pinnedStatusTexture&&!this.pinnedStatusTexture.destroyed&&this.pinnedStatusTexture.destroy(),this.pinnedStatusTexture=void 0,(u=this.updatePositionUniformStore)==null||u.destroy(),this.updatePositionUniformStore=void 0,(f=this.dragPointUniformStore)==null||f.destroy(),this.dragPointUniformStore=void 0,(h=this.drawUniformStore)==null||h.destroy(),this.drawUniformStore=void 0,(d=this.findPointsOnAreaSelectionUniformStore)==null||d.destroy(),this.findPointsOnAreaSelectionUniformStore=void 0,(_=this.findPointsOnPolygonSelectionUniformStore)==null||_.destroy(),this.findPointsOnPolygonSelectionUniformStore=void 0,(I=this.findHoveredPointUniformStore)==null||I.destroy(),this.findHoveredPointUniformStore=void 0,(P=this.fillSampledPointsUniformStore)==null||P.destroy(),this.fillSampledPointsUniformStore=void 0,(A=this.drawHighlightedUniformStore)==null||A.destroy(),this.drawHighlightedUniformStore=void 0,(O=this.trackPointsUniformStore)==null||O.destroy(),this.trackPointsUniformStore=void 0,this.colorBuffer&&!this.colorBuffer.destroyed&&this.colorBuffer.destroy(),this.colorBuffer=void 0,this.sizeBuffer&&!this.sizeBuffer.destroyed&&this.sizeBuffer.destroy(),this.sizeBuffer=void 0,this.shapeBuffer&&!this.shapeBuffer.destroyed&&this.shapeBuffer.destroy(),this.shapeBuffer=void 0,this.imageIndicesBuffer&&!this.imageIndicesBuffer.destroyed&&this.imageIndicesBuffer.destroy(),this.imageIndicesBuffer=void 0,this.imageSizesBuffer&&!this.imageSizesBuffer.destroyed&&this.imageSizesBuffer.destroy(),this.imageSizesBuffer=void 0,this.drawPointIndices&&!this.drawPointIndices.destroyed&&this.drawPointIndices.destroy(),this.drawPointIndices=void 0,this.hoveredPointIndices&&!this.hoveredPointIndices.destroyed&&this.hoveredPointIndices.destroy(),this.hoveredPointIndices=void 0,this.sampledPointIndices&&!this.sampledPointIndices.destroyed&&this.sampledPointIndices.destroy(),this.sampledPointIndices=void 0,this.updatePositionVertexCoordBuffer&&!this.updatePositionVertexCoordBuffer.destroyed&&this.updatePositionVertexCoordBuffer.destroy(),this.updatePositionVertexCoordBuffer=void 0,this.dragPointVertexCoordBuffer&&!this.dragPointVertexCoordBuffer.destroyed&&this.dragPointVertexCoordBuffer.destroy(),this.dragPointVertexCoordBuffer=void 0,this.findPointsOnAreaSelectionVertexCoordBuffer&&!this.findPointsOnAreaSelectionVertexCoordBuffer.destroyed&&this.findPointsOnAreaSelectionVertexCoordBuffer.destroy(),this.findPointsOnAreaSelectionVertexCoordBuffer=void 0,this.findPointsOnPolygonSelectionVertexCoordBuffer&&!this.findPointsOnPolygonSelectionVertexCoordBuffer.destroyed&&this.findPointsOnPolygonSelectionVertexCoordBuffer.destroy(),this.findPointsOnPolygonSelectionVertexCoordBuffer=void 0,this.drawHighlightedVertexCoordBuffer&&!this.drawHighlightedVertexCoordBuffer.destroyed&&this.drawHighlightedVertexCoordBuffer.destroy(),this.drawHighlightedVertexCoordBuffer=void 0,this.trackPointsVertexCoordBuffer&&!this.trackPointsVertexCoordBuffer.destroyed&&this.trackPointsVertexCoordBuffer.destroy(),this.trackPointsVertexCoordBuffer=void 0}swapFbo(){if(!this.currentPositionTexture||this.currentPositionTexture.destroyed||!this.previousPositionTexture||this.previousPositionTexture.destroyed||!this.currentPositionFbo||this.currentPositionFbo.destroyed||!this.previousPositionFbo||this.previousPositionFbo.destroyed)return;const e=this.previousPositionTexture,t=this.previousPositionFbo;this.previousPositionTexture=this.currentPositionTexture,this.previousPositionFbo=this.currentPositionFbo,this.currentPositionTexture=e,this.currentPositionFbo=t}rescaleInitialNodePositions(){const{config:{spaceSize:e}}=this;if(!this.data.pointPositions||!e)return;const t=this.data.pointPositions,i=t.length/2;let r=1/0,s=-1/0,o=1/0,a=-1/0;for(let A=0;A<t.length;A+=2){const O=t[A],E=t[A+1];r=Math.min(r,O),s=Math.max(s,O),o=Math.min(o,E),a=Math.max(a,E)}const l=s-r,c=a-o,u=Math.max(l,c);if(u>e){this.scaleX=void 0,this.scaleY=void 0;return}const f=e*e*.001,h=i>f?e*Math.max(1.2,Math.sqrt(i)/e):e*.1,d=h/u,_=(e-h)/2,I=(u-l)/2*d+_,P=(u-c)/2*d+_;this.scaleX=A=>(A-r)*d+I,this.scaleY=A=>(A-o)*d+P;for(let A=0;A<i;A++)this.data.pointPositions[A*2]=this.scaleX(t[A*2]),this.data.pointPositions[A*2+1]=this.scaleY(t[A*2+1])}}const kv={passive:!1},ei={capture:!0,passive:!1};function Po(n){n.stopImmediatePropagation()}function xn(n){n.preventDefault(),n.stopImmediatePropagation()}function yu(n){var e=n.document.documentElement,t=we(n).on("dragstart.drag",xn,ei);"onselectstart"in e?t.on("selectstart.drag",xn,ei):(e.__noselect=e.style.MozUserSelect,e.style.MozUserSelect="none")}function xu(n,e){var t=n.document.documentElement,i=we(n).on("dragstart.drag",null);e&&(i.on("click.drag",xn,ei),setTimeout(function(){i.on("click.drag",null)},0)),"onselectstart"in t?i.on("selectstart.drag",null):(t.style.MozUserSelect=t.__noselect,delete t.__noselect)}const xr=n=>()=>n;function Eo(n,{sourceEvent:e,subject:t,target:i,identifier:r,active:s,x:o,y:a,dx:l,dy:c,dispatch:u}){Object.defineProperties(this,{type:{value:n,enumerable:!0,configurable:!0},sourceEvent:{value:e,enumerable:!0,configurable:!0},subject:{value:t,enumerable:!0,configurable:!0},target:{value:i,enumerable:!0,configurable:!0},identifier:{value:r,enumerable:!0,configurable:!0},active:{value:s,enumerable:!0,configurable:!0},x:{value:o,enumerable:!0,configurable:!0},y:{value:a,enumerable:!0,configurable:!0},dx:{value:l,enumerable:!0,configurable:!0},dy:{value:c,enumerable:!0,configurable:!0},_:{value:u}})}Eo.prototype.on=function(){var n=this._.on.apply(this._,arguments);return n===this._?this:n};function Dv(n){return!n.ctrlKey&&!n.button}function Mv(){return this.parentNode}function Fv(n,e){return e??{x:n.x,y:n.y}}function Nv(){return navigator.maxTouchPoints||"ontouchstart"in this}function Ov(){var n=Dv,e=Mv,t=Fv,i=Nv,r={},s=ui("start","drag","end"),o=0,a,l,c,u,f=0;function h(y){y.on("mousedown.drag",d).filter(i).on("touchstart.drag",P).on("touchmove.drag",A,kv).on("touchend.drag touchcancel.drag",O).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function d(y,R){if(!(u||!n.call(this,y,R))){var N=E(this,e.call(this,y,R),y,R,"mouse");N&&(we(y.view).on("mousemove.drag",_,ei).on("mouseup.drag",I,ei),yu(y.view),Po(y),c=!1,a=y.clientX,l=y.clientY,N("start",y))}}function _(y){if(xn(y),!c){var R=y.clientX-a,N=y.clientY-l;c=R*R+N*N>f}r.mouse("drag",y)}function I(y){we(y.view).on("mousemove.drag mouseup.drag",null),xu(y.view,c),xn(y),r.mouse("end",y)}function P(y,R){if(n.call(this,y,R)){var N=y.changedTouches,U=e.call(this,y,R),W=N.length,q,G;for(q=0;q<W;++q)(G=E(this,U,y,R,N[q].identifier,N[q]))&&(Po(y),G("start",y,N[q]))}}function A(y){var R=y.changedTouches,N=R.length,U,W;for(U=0;U<N;++U)(W=r[R[U].identifier])&&(xn(y),W("drag",y,R[U]))}function O(y){var R=y.changedTouches,N=R.length,U,W;for(u&&clearTimeout(u),u=setTimeout(function(){u=null},500),U=0;U<N;++U)(W=r[R[U].identifier])&&(Po(y),W("end",y,R[U]))}function E(y,R,N,U,W,q){var G=s.copy(),B=xt(q||N,R),he,ie,C;if((C=t.call(y,new Eo("beforestart",{sourceEvent:N,target:h,identifier:W,active:o,x:B[0],y:B[1],dx:0,dy:0,dispatch:G}),U))!=null)return he=C.x-B[0]||0,ie=C.y-B[1]||0,function H(M,$,Z){var j=B,ee;switch(M){case"start":r[W]=H,ee=o++;break;case"end":delete r[W],--o;case"drag":B=xt(Z||$,R),ee=o;break}G.call(M,y,new Eo(M,{sourceEvent:$,subject:C,target:h,identifier:W,active:ee,x:B[0]+he,y:B[1]+ie,dx:B[0]-j[0],dy:B[1]-j[1],dispatch:G}),U)}}return h.filter=function(y){return arguments.length?(n=typeof y=="function"?y:xr(!!y),h):n},h.container=function(y){return arguments.length?(e=typeof y=="function"?y:xr(y),h):e},h.subject=function(y){return arguments.length?(t=typeof y=="function"?y:xr(y),h):t},h.touchable=function(y){return arguments.length?(i=typeof y=="function"?y:xr(!!y),h):i},h.on=function(){var y=s.on.apply(s,arguments);return y===s?h:y},h.clickDistance=function(y){return arguments.length?(f=(y=+y)*y,h):Math.sqrt(f)},h}const vr=n=>()=>n;function Bv(n,{sourceEvent:e,target:t,transform:i,dispatch:r}){Object.defineProperties(this,{type:{value:n,enumerable:!0,configurable:!0},sourceEvent:{value:e,enumerable:!0,configurable:!0},target:{value:t,enumerable:!0,configurable:!0},transform:{value:i,enumerable:!0,configurable:!0},_:{value:r}})}function It(n,e,t){this.k=n,this.x=e,this.y=t}It.prototype={constructor:It,scale:function(n){return n===1?this:new It(this.k*n,this.x,this.y)},translate:function(n,e){return n===0&e===0?this:new It(this.k,this.x+this.k*n,this.y+this.k*e)},apply:function(n){return[n[0]*this.k+this.x,n[1]*this.k+this.y]},applyX:function(n){return n*this.k+this.x},applyY:function(n){return n*this.k+this.y},invert:function(n){return[(n[0]-this.x)/this.k,(n[1]-this.y)/this.k]},invertX:function(n){return(n-this.x)/this.k},invertY:function(n){return(n-this.y)/this.k},rescaleX:function(n){return n.copy().domain(n.range().map(this.invertX,this).map(n.invert,n))},rescaleY:function(n){return n.copy().domain(n.range().map(this.invertY,this).map(n.invert,n))},toString:function(){return"translate("+this.x+","+this.y+") scale("+this.k+")"}};var ti=new It(1,0,0);It.prototype;function Ro(n){n.stopImmediatePropagation()}function ni(n){n.preventDefault(),n.stopImmediatePropagation()}function Uv(n){return(!n.ctrlKey||n.type==="wheel")&&!n.button}function zv(){var n=this;return n instanceof SVGElement?(n=n.ownerSVGElement||n,n.hasAttribute("viewBox")?(n=n.viewBox.baseVal,[[n.x,n.y],[n.x+n.width,n.y+n.height]]):[[0,0],[n.width.baseVal.value,n.height.baseVal.value]]):[[0,0],[n.clientWidth,n.clientHeight]]}function vu(){return this.__zoom||ti}function Lv(n){return-n.deltaY*(n.deltaMode===1?.05:n.deltaMode?1:.002)*(n.ctrlKey?10:1)}function Vv(){return navigator.maxTouchPoints||"ontouchstart"in this}function Hv(n,e,t){var i=n.invertX(e[0][0])-t[0][0],r=n.invertX(e[1][0])-t[1][0],s=n.invertY(e[0][1])-t[0][1],o=n.invertY(e[1][1])-t[1][1];return n.translate(r>i?(i+r)/2:Math.min(0,i)||Math.max(0,r),o>s?(s+o)/2:Math.min(0,s)||Math.max(0,o))}function Wv(){var n=Uv,e=zv,t=Hv,i=Lv,r=Vv,s=[0,1/0],o=[[-1/0,-1/0],[1/0,1/0]],a=250,l=ld,c=ui("start","zoom","end"),u,f,h,d=500,_=150,I=0,P=10;function A(C){C.property("__zoom",vu).on("wheel.zoom",W,{passive:!1}).on("mousedown.zoom",q).on("dblclick.zoom",G).filter(r).on("touchstart.zoom",B).on("touchmove.zoom",he).on("touchend.zoom touchcancel.zoom",ie).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}A.transform=function(C,H,M,$){var Z=C.selection?C.selection():C;Z.property("__zoom",vu),C!==Z?R(C,H,M,$):Z.interrupt().each(function(){N(this,arguments).event($).start().zoom(null,typeof H=="function"?H.apply(this,arguments):H).end()})},A.scaleBy=function(C,H,M,$){A.scaleTo(C,function(){var Z=this.__zoom.k,j=typeof H=="function"?H.apply(this,arguments):H;return Z*j},M,$)},A.scaleTo=function(C,H,M,$){A.transform(C,function(){var Z=e.apply(this,arguments),j=this.__zoom,ee=M==null?y(Z):typeof M=="function"?M.apply(this,arguments):M,J=j.invert(ee),ge=typeof H=="function"?H.apply(this,arguments):H;return t(E(O(j,ge),ee,J),Z,o)},M,$)},A.translateBy=function(C,H,M,$){A.transform(C,function(){return t(this.__zoom.translate(typeof H=="function"?H.apply(this,arguments):H,typeof M=="function"?M.apply(this,arguments):M),e.apply(this,arguments),o)},null,$)},A.translateTo=function(C,H,M,$,Z){A.transform(C,function(){var j=e.apply(this,arguments),ee=this.__zoom,J=$==null?y(j):typeof $=="function"?$.apply(this,arguments):$;return t(ti.translate(J[0],J[1]).scale(ee.k).translate(typeof H=="function"?-H.apply(this,arguments):-H,typeof M=="function"?-M.apply(this,arguments):-M),j,o)},$,Z)};function O(C,H){return H=Math.max(s[0],Math.min(s[1],H)),H===C.k?C:new It(H,C.x,C.y)}function E(C,H,M){var $=H[0]-M[0]*C.k,Z=H[1]-M[1]*C.k;return $===C.x&&Z===C.y?C:new It(C.k,$,Z)}function y(C){return[(+C[0][0]+ +C[1][0])/2,(+C[0][1]+ +C[1][1])/2]}function R(C,H,M,$){C.on("start.zoom",function(){N(this,arguments).event($).start()}).on("interrupt.zoom end.zoom",function(){N(this,arguments).event($).end()}).tween("zoom",function(){var Z=this,j=arguments,ee=N(Z,j).event($),J=e.apply(Z,j),ge=M==null?y(J):typeof M=="function"?M.apply(Z,j):M,ue=Math.max(J[1][0]-J[0][0],J[1][1]-J[0][1]),Te=Z.__zoom,se=typeof H=="function"?H.apply(Z,j):H,He=l(Te.invert(ge).concat(ue/Te.k),se.invert(ge).concat(ue/se.k));return function(We){if(We===1)We=se;else{var nt=He(We),Gt=ue/nt[2];We=new It(Gt,ge[0]-nt[0]*Gt,ge[1]-nt[1]*Gt)}ee.zoom(null,We)}})}function N(C,H,M){return!M&&C.__zooming||new U(C,H)}function U(C,H){this.that=C,this.args=H,this.active=0,this.sourceEvent=null,this.extent=e.apply(C,H),this.taps=0}U.prototype={event:function(C){return C&&(this.sourceEvent=C),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(C,H){return this.mouse&&C!=="mouse"&&(this.mouse[1]=H.invert(this.mouse[0])),this.touch0&&C!=="touch"&&(this.touch0[1]=H.invert(this.touch0[0])),this.touch1&&C!=="touch"&&(this.touch1[1]=H.invert(this.touch1[0])),this.that.__zoom=H,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(C){var H=we(this.that).datum();c.call(C,this.that,new Bv(C,{sourceEvent:this.sourceEvent,target:A,transform:this.that.__zoom,dispatch:c}),H)}};function W(C,...H){if(!n.apply(this,arguments))return;var M=N(this,H).event(C),$=this.__zoom,Z=Math.max(s[0],Math.min(s[1],$.k*Math.pow(2,i.apply(this,arguments)))),j=xt(C);if(M.wheel)(M.mouse[0][0]!==j[0]||M.mouse[0][1]!==j[1])&&(M.mouse[1]=$.invert(M.mouse[0]=j)),clearTimeout(M.wheel);else{if($.k===Z)return;M.mouse=[j,$.invert(j)],xi(this),M.start()}ni(C),M.wheel=setTimeout(ee,_),M.zoom("mouse",t(E(O($,Z),M.mouse[0],M.mouse[1]),M.extent,o));function ee(){M.wheel=null,M.end()}}function q(C,...H){if(h||!n.apply(this,arguments))return;var M=C.currentTarget,$=N(this,H,!0).event(C),Z=we(C.view).on("mousemove.zoom",ge,!0).on("mouseup.zoom",ue,!0),j=xt(C,M),ee=C.clientX,J=C.clientY;yu(C.view),Ro(C),$.mouse=[j,this.__zoom.invert(j)],xi(this),$.start();function ge(Te){if(ni(Te),!$.moved){var se=Te.clientX-ee,He=Te.clientY-J;$.moved=se*se+He*He>I}$.event(Te).zoom("mouse",t(E($.that.__zoom,$.mouse[0]=xt(Te,M),$.mouse[1]),$.extent,o))}function ue(Te){Z.on("mousemove.zoom mouseup.zoom",null),xu(Te.view,$.moved),ni(Te),$.event(Te).end()}}function G(C,...H){if(n.apply(this,arguments)){var M=this.__zoom,$=xt(C.changedTouches?C.changedTouches[0]:C,this),Z=M.invert($),j=M.k*(C.shiftKey?.5:2),ee=t(E(O(M,j),$,Z),e.apply(this,H),o);ni(C),a>0?we(this).transition().duration(a).call(R,ee,$,C):we(this).call(A.transform,ee,$,C)}}function B(C,...H){if(n.apply(this,arguments)){var M=C.touches,$=M.length,Z=N(this,H,C.changedTouches.length===$).event(C),j,ee,J,ge;for(Ro(C),ee=0;ee<$;++ee)J=M[ee],ge=xt(J,this),ge=[ge,this.__zoom.invert(ge),J.identifier],Z.touch0?!Z.touch1&&Z.touch0[2]!==ge[2]&&(Z.touch1=ge,Z.taps=0):(Z.touch0=ge,j=!0,Z.taps=1+!!u);u&&(u=clearTimeout(u)),j&&(Z.taps<2&&(f=ge[0],u=setTimeout(function(){u=null},d)),xi(this),Z.start())}}function he(C,...H){if(this.__zooming){var M=N(this,H).event(C),$=C.changedTouches,Z=$.length,j,ee,J,ge;for(ni(C),j=0;j<Z;++j)ee=$[j],J=xt(ee,this),M.touch0&&M.touch0[2]===ee.identifier?M.touch0[0]=J:M.touch1&&M.touch1[2]===ee.identifier&&(M.touch1[0]=J);if(ee=M.that.__zoom,M.touch1){var ue=M.touch0[0],Te=M.touch0[1],se=M.touch1[0],He=M.touch1[1],We=(We=se[0]-ue[0])*We+(We=se[1]-ue[1])*We,nt=(nt=He[0]-Te[0])*nt+(nt=He[1]-Te[1])*nt;ee=O(ee,Math.sqrt(We/nt)),J=[(ue[0]+se[0])/2,(ue[1]+se[1])/2],ge=[(Te[0]+He[0])/2,(Te[1]+He[1])/2]}else if(M.touch0)J=M.touch0[0],ge=M.touch0[1];else return;M.zoom("touch",t(E(ee,J,ge),M.extent,o))}}function ie(C,...H){if(this.__zooming){var M=N(this,H).event(C),$=C.changedTouches,Z=$.length,j,ee;for(Ro(C),h&&clearTimeout(h),h=setTimeout(function(){h=null},d),j=0;j<Z;++j)ee=$[j],M.touch0&&M.touch0[2]===ee.identifier?delete M.touch0:M.touch1&&M.touch1[2]===ee.identifier&&delete M.touch1;if(M.touch1&&!M.touch0&&(M.touch0=M.touch1,delete M.touch1),M.touch0)M.touch0[1]=this.__zoom.invert(M.touch0[0]);else if(M.end(),M.taps===2&&(ee=xt(ee,this),Math.hypot(f[0]-ee[0],f[1]-ee[1])<P)){var J=we(this).on("dblclick.zoom");J&&J.apply(this,arguments)}}}return A.wheelDelta=function(C){return arguments.length?(i=typeof C=="function"?C:vr(+C),A):i},A.filter=function(C){return arguments.length?(n=typeof C=="function"?C:vr(!!C),A):n},A.touchable=function(C){return arguments.length?(r=typeof C=="function"?C:vr(!!C),A):r},A.extent=function(C){return arguments.length?(e=typeof C=="function"?C:vr([[+C[0][0],+C[0][1]],[+C[1][0],+C[1][1]]]),A):e},A.scaleExtent=function(C){return arguments.length?(s[0]=+C[0],s[1]=+C[1],A):[s[0],s[1]]},A.translateExtent=function(C){return arguments.length?(o[0][0]=+C[0][0],o[1][0]=+C[1][0],o[0][1]=+C[0][1],o[1][1]=+C[1][1],A):[[o[0][0],o[0][1]],[o[1][0],o[1][1]]]},A.constrain=function(C){return arguments.length?(t=C,A):t},A.duration=function(C){return arguments.length?(a=+C,A):a},A.interpolate=function(C){return arguments.length?(l=C,A):l},A.on=function(){var C=c.on.apply(c,arguments);return C===c?A:C},A.clickDistance=function(C){return arguments.length?(I=(C=+C)*C,A):Math.sqrt(I)},A.tapDistance=function(C){return arguments.length?(P=+C,A):P},A}class $v{constructor(e,t){this.eventTransform=ti,this.behavior=Wv().scaleExtent([.001,1/0]).on("start",i=>{var s,o;this.isRunning=!0;const r=!!i.sourceEvent;(o=(s=this.config)==null?void 0:s.onZoomStart)==null||o.call(s,i,r)}).on("zoom",i=>{var h,d;this.eventTransform=i.transform;const{eventTransform:{x:r,y:s,k:o},store:{transform:a,screenSize:l}}=this,c=l[0],u=l[1];if(!c||!u)return;ky(a,c,u),rc(a,a,[r,s]),qs(a,a,[o,o]),rc(a,a,[c/2,u/2]),qs(a,a,[c/2,u/2]),qs(a,a,[1,-1]);const f=!!i.sourceEvent;(d=(h=this.config)==null?void 0:h.onZoom)==null||d.call(h,i,f)}).on("end",i=>{var s,o;this.isRunning=!1;const r=!!i.sourceEvent;(o=(s=this.config)==null?void 0:s.onZoomEnd)==null||o.call(s,i,r)}),this.isRunning=!1,this.store=e,this.config=t}getTransform(e,t,i=.1){if(e.length===0)return this.eventTransform;const{store:{screenSize:r}}=this,s=r[0],o=r[1];let a=1/0,l=-1/0,c=1/0,u=-1/0;for(let R=0;R<e.length;R+=2){const N=e[R],U=e[R+1];N<a&&(a=N),N>l&&(l=N),U<c&&(c=U),U>u&&(u=U)}const f=[this.store.scaleX(a),this.store.scaleX(l)],h=[this.store.scaleY(c),this.store.scaleY(u)];f[0]===f[1]&&(f[0]-=.5,f[1]+=.5),h[0]===h[1]&&(h[0]+=.5,h[1]-=.5);const d=s*(1-i*2)/(f[1]-f[0]),_=o*(1-i*2)/(h[0]-h[1]),I=Sc(t??Math.min(d,_),...this.behavior.scaleExtent()),P=(f[1]+f[0])/2,A=(h[1]+h[0])/2,O=s/2-P*I,E=o/2-A*I;return ti.translate(O,E).scale(I)}getDistanceToPoint(e){const{x:t,y:i,k:r}=this.eventTransform,s=this.getTransform(e,r),o=t-s.x,a=i-s.y;return Math.sqrt(o*o+a*a)}getMiddlePointTransform(e){const{store:{screenSize:t},eventTransform:{x:i,y:r,k:s}}=this,o=t[0],a=t[1],l=(o/2-i)/s,c=(a/2-r)/s,u=this.store.scaleX(e[0]),f=this.store.scaleY(e[1]),h=(l+u)/2,d=(c+f)/2,_=1,I=o/2-h*_,P=a/2-d*_;return ti.translate(I,P).scale(_)}convertScreenToSpacePosition(e){const{eventTransform:{x:t,y:i,k:r},store:{screenSize:s}}=this,o=s[0],a=s[1],l=(e[0]-t)/r,c=(e[1]-i)/r,u=[l,a-c];return u[0]-=(o-this.store.adjustedSpaceSize)/2,u[1]-=(a-this.store.adjustedSpaceSize)/2,u}convertSpaceToScreenPosition(e){const t=this.eventTransform.applyX(this.store.scaleX(e[0])),i=this.eventTransform.applyY(this.store.scaleY(e[1]));return[t,i]}convertSpaceToScreenRadius(e){const{config:{scalePointsOnZoom:t},store:{maxPointSize:i},eventTransform:{k:r}}=this;let s=e*2;return t?s*=r:s*=Math.min(5,Math.max(1,r*.01)),Math.min(s,i)/2}}class Xv{constructor(e,t){this.isActive=!1,this.behavior=Ov().subject(i=>this.store.hoveredPoint&&!this.store.isSpaceKeyPressed?{x:i.x,y:i.y}:void 0).on("start",i=>{var r,s;this.store.hoveredPoint&&(this.store.draggingPointIndex=this.store.hoveredPoint.index,this.isActive=!0,(s=(r=this.config)==null?void 0:r.onDragStart)==null||s.call(r,i))}).on("drag",i=>{var r,s;(s=(r=this.config)==null?void 0:r.onDrag)==null||s.call(r,i)}).on("end",i=>{var r,s;this.isActive=!1,this.store.draggingPointIndex=void 0,(s=(r=this.config)==null?void 0:r.onDragEnd)==null||s.call(r,i)}),this.store=e,this.config=t}}class Yv{constructor(e,t,i){if(this.config=new bx,this.graph=new cv(this.config),this.isReady=!1,this.requestAnimationFrameId=0,this.isRightClickMouse=!1,this.store=new vx,this.zoomInstance=new $v(this.store,this.config),this.dragInstance=new Xv(this.store,this.config),this._findHoveredItemExecutionCount=0,this._isMouseOnCanvas=!1,this._lastMouseX=0,this._lastMouseY=0,this._lastCheckedMouseX=0,this._lastCheckedMouseY=0,this._shouldForceHoverDetection=!1,this._isFirstRenderAfterInit=!0,this.isPointPositionsUpdateNeeded=!1,this.isPointColorUpdateNeeded=!1,this.isPointSizeUpdateNeeded=!1,this.isPointShapeUpdateNeeded=!1,this.isPointImageIndicesUpdateNeeded=!1,this.isLinksUpdateNeeded=!1,this.isLinkColorUpdateNeeded=!1,this.isLinkWidthUpdateNeeded=!1,this.isLinkArrowUpdateNeeded=!1,this.isPointClusterUpdateNeeded=!1,this.isForceManyBodyUpdateNeeded=!1,this.isForceLinkUpdateNeeded=!1,this.isForceCenterUpdateNeeded=!1,this.isPointImageSizesUpdateNeeded=!1,this._isDestroyed=!1,t&&this.config.init(t),i)this.deviceInitPromise=i,this.shouldDestroyDevice=!1;else{const r=document.createElement("canvas");this.deviceInitPromise=this.createDevice(r),this.shouldDestroyDevice=!0}this.deviceInitPromise.then(r=>{if(this._isDestroyed)return this.shouldDestroyDevice&&r.destroy(),r;this.device=r,this.isReady=!0;const s=this.validateDevice(r);i&&s.setProps({useDevicePixels:this.config.pixelRatio}),this.store.div=e;const o=s.canvas;o.parentNode!==this.store.div&&(o.parentNode&&o.parentNode.removeChild(o),this.store.div.appendChild(o)),this.addAttribution(),o.style.width="100%",o.style.height="100%",this.canvas=o;const a=this.canvas.clientWidth,l=this.canvas.clientHeight;return this.store.adjustSpaceSize(this.config.spaceSize,this.device.limits.maxTextureDimension2D),this.store.setWebGLMaxTextureSize(this.device.limits.maxTextureDimension2D),this.store.updateScreenSize(a,l),this.canvasD3Selection=we(this.canvas),this.canvasD3Selection.on("mouseenter.cosmos",c=>{this._isMouseOnCanvas=!0,this._lastMouseX=c.clientX,this._lastMouseY=c.clientY}).on("mousemove.cosmos",c=>{this._isMouseOnCanvas=!0,this._lastMouseX=c.clientX,this._lastMouseY=c.clientY}).on("mouseleave.cosmos",c=>{this._isMouseOnCanvas=!1,this.currentEvent=c,this.store.hoveredPoint!==void 0&&this.config.onPointMouseOut&&this.config.onPointMouseOut(c),this.store.hoveredLinkIndex!==void 0&&this.config.onLinkMouseOut&&this.config.onLinkMouseOut(c),this.isRightClickMouse=!1,this.store.hoveredPoint=void 0,this.store.hoveredLinkIndex=void 0,this.updateCanvasCursor()}),we(document).on("keydown.cosmos",c=>{c.code==="Space"&&(this.store.isSpaceKeyPressed=!0)}).on("keyup.cosmos",c=>{c.code==="Space"&&(this.store.isSpaceKeyPressed=!1)}),this.zoomInstance.behavior.on("start.detect",c=>{this.currentEvent=c}).on("zoom.detect",c=>{!!c.sourceEvent&&this.updateMousePosition(c.sourceEvent),this.currentEvent=c}).on("end.detect",c=>{this.currentEvent=c,this._shouldForceHoverDetection=!0}),this.dragInstance.behavior.on("start.detect",c=>{this.currentEvent=c,this.updateCanvasCursor()}).on("drag.detect",c=>{this.dragInstance.isActive&&this.updateMousePosition(c),this.currentEvent=c}).on("end.detect",c=>{this.currentEvent=c,this.updateCanvasCursor()}),this.canvasD3Selection.call(this.dragInstance.behavior).call(this.zoomInstance.behavior).on("click",this.onClick.bind(this)).on("mousemove",this.onMouseMove.bind(this)).on("contextmenu",this.onContextMenu.bind(this)),(!this.config.enableZoom||!this.config.enableDrag)&&this.updateZoomDragBehaviors(),this.setZoomLevel(this.config.initialZoomLevel??1),this.store.maxPointSize=eo(r,this.config.pixelRatio),this.store.isSimulationRunning=this.config.enableSimulation,this.points=new Rv(r,this.config,this.store,this.graph),this.lines=new gv(r,this.config,this.store,this.graph,this.points),this.config.enableSimulation&&(this.forceGravity=new Y0(r,this.config,this.store,this.graph,this.points),this.forceCenter=new $0(r,this.config,this.store,this.graph,this.points),this.forceManyBody=new J0(r,this.config,this.store,this.graph,this.points),this.forceLinkIncoming=new gu(r,this.config,this.store,this.graph,this.points),this.forceLinkOutgoing=new gu(r,this.config,this.store,this.graph,this.points),this.forceMouse=new ev(r,this.config,this.store,this.graph,this.points)),this.clusters=new rv(r,this.config,this.store,this.graph,this.points),this.store.backgroundColor=Tt(this.config.backgroundColor),this.store.setHoveredPointRingColor(this.config.hoveredPointRingColor??V.hoveredPointRingColor),this.store.setFocusedPointRingColor(this.config.focusedPointRingColor??V.focusedPointRingColor),this.config.focusedPointIndex!==void 0&&this.store.setFocusedPoint(this.config.focusedPointIndex),this.store.setGreyoutPointColor(this.config.pointGreyoutColor??Ms),this.store.setHoveredLinkColor(this.config.hoveredLinkColor??V.hoveredLinkColor),this.store.updateLinkHoveringEnabled(this.config),this.config.showFPSMonitor&&(this.fpsMonitor=new mu(this.canvas)),this.config.randomSeed!==void 0&&this.store.addRandomSeed(this.config.randomSeed),r}).catch(r=>{throw this.device=void 0,this.isReady=!1,console.error("Device initialization failed:",r),r}),this.ready=this.deviceInitPromise.then(()=>{})}get progress(){return this._isDestroyed?0:this.store.simulationProgress}get isSimulationRunning(){return this._isDestroyed?!1:this.store.isSimulationRunning}get maxPointSize(){return this._isDestroyed?0:this.store.maxPointSize}setConfig(e){var i,r,s,o,a,l,c,u,f;if(this._isDestroyed||this.ensureDevice(()=>this.setConfig(e)))return;const t={...this.config};this.config.init(e),(t.pointDefaultColor!==this.config.pointDefaultColor||t.pointColor!==this.config.pointColor)&&(this.graph.updatePointColor(),(i=this.points)==null||i.updateColor()),(t.pointDefaultSize!==this.config.pointDefaultSize||t.pointSize!==this.config.pointSize)&&(this.graph.updatePointSize(),(r=this.points)==null||r.updateSize()),(t.linkDefaultColor!==this.config.linkDefaultColor||t.linkColor!==this.config.linkColor)&&(this.graph.updateLinkColor(),(s=this.lines)==null||s.updateColor()),(t.linkDefaultWidth!==this.config.linkDefaultWidth||t.linkWidth!==this.config.linkWidth)&&(this.graph.updateLinkWidth(),(o=this.lines)==null||o.updateWidth()),(t.linkDefaultArrows!==this.config.linkDefaultArrows||t.linkArrows!==this.config.linkArrows)&&(this.graph.updateArrows(),(a=this.lines)==null||a.updateArrow()),(t.curvedLinkSegments!==this.config.curvedLinkSegments||t.curvedLinks!==this.config.curvedLinks)&&((l=this.lines)==null||l.updateCurveLineGeometry()),t.backgroundColor!==this.config.backgroundColor&&(this.store.backgroundColor=Tt(this.config.backgroundColor??Al)),t.hoveredPointRingColor!==this.config.hoveredPointRingColor&&this.store.setHoveredPointRingColor(this.config.hoveredPointRingColor??V.hoveredPointRingColor),t.focusedPointRingColor!==this.config.focusedPointRingColor&&this.store.setFocusedPointRingColor(this.config.focusedPointRingColor??V.focusedPointRingColor),t.pointGreyoutColor!==this.config.pointGreyoutColor&&this.store.setGreyoutPointColor(this.config.pointGreyoutColor??Ms),t.hoveredLinkColor!==this.config.hoveredLinkColor&&this.store.setHoveredLinkColor(this.config.hoveredLinkColor??V.hoveredLinkColor),t.focusedPointIndex!==this.config.focusedPointIndex&&this.store.setFocusedPoint(this.config.focusedPointIndex),t.pixelRatio!==this.config.pixelRatio&&(c=this.device)!=null&&c.canvasContext&&(this.device.canvasContext.setProps({useDevicePixels:this.config.pixelRatio}),this.store.maxPointSize=eo(this.device,this.config.pixelRatio)),t.spaceSize!==this.config.spaceSize&&(this.store.adjustSpaceSize(this.config.spaceSize,((u=this.device)==null?void 0:u.limits.maxTextureDimension2D)??4096),this.resizeCanvas(!0),this.update(this.store.isSimulationRunning?this.store.alpha:0)),t.showFPSMonitor!==this.config.showFPSMonitor&&(this.config.showFPSMonitor?this.fpsMonitor=new mu(this.canvas):((f=this.fpsMonitor)==null||f.destroy(),this.fpsMonitor=void 0)),(t.enableZoom!==this.config.enableZoom||t.enableDrag!==this.config.enableDrag)&&this.updateZoomDragBehaviors(),(t.onLinkClick!==this.config.onLinkClick||t.onLinkContextMenu!==this.config.onLinkContextMenu||t.onLinkMouseOver!==this.config.onLinkMouseOver||t.onLinkMouseOut!==this.config.onLinkMouseOut)&&this.store.updateLinkHoveringEnabled(this.config)}setPointPositions(e,t){this._isDestroyed||this.ensureDevice(()=>this.setPointPositions(e,t))||(this.graph.inputPointPositions=e,this.points.shouldSkipRescale=t,this.isPointPositionsUpdateNeeded=!0,this.isLinksUpdateNeeded=!0,this.isPointColorUpdateNeeded=!0,this.isPointSizeUpdateNeeded=!0,this.isPointShapeUpdateNeeded=!0,this.isPointImageIndicesUpdateNeeded=!0,this.isPointImageSizesUpdateNeeded=!0,this.isPointClusterUpdateNeeded=!0,this.isForceManyBodyUpdateNeeded=!0,this.isForceLinkUpdateNeeded=!0,this.isForceCenterUpdateNeeded=!0)}setPointColors(e){this._isDestroyed||this.ensureDevice(()=>this.setPointColors(e))||(this.graph.inputPointColors=e,this.isPointColorUpdateNeeded=!0)}getPointColors(){return this._isDestroyed?new Float32Array:this.graph.pointColors??new Float32Array}setPointSizes(e){this._isDestroyed||this.ensureDevice(()=>this.setPointSizes(e))||(this.graph.inputPointSizes=e,this.isPointSizeUpdateNeeded=!0)}setPointShapes(e){this._isDestroyed||this.ensureDevice(()=>this.setPointShapes(e))||(this.graph.inputPointShapes=e,this.isPointShapeUpdateNeeded=!0)}setImageData(e){var t;this._isDestroyed||this.ensureDevice(()=>this.setImageData(e))||(this.graph.inputImageData=e,(t=this.points)==null||t.createAtlas())}setPointImageIndices(e){this._isDestroyed||this.ensureDevice(()=>this.setPointImageIndices(e))||(this.graph.inputPointImageIndices=e,this.isPointImageIndicesUpdateNeeded=!0)}setPointImageSizes(e){this._isDestroyed||this.ensureDevice(()=>this.setPointImageSizes(e))||(this.graph.inputPointImageSizes=e,this.isPointImageSizesUpdateNeeded=!0)}getPointSizes(){return this._isDestroyed?new Float32Array:this.graph.pointSizes??new Float32Array}setLinks(e){this._isDestroyed||this.ensureDevice(()=>this.setLinks(e))||(this.graph.inputLinks=e,this.isLinksUpdateNeeded=!0,this.isLinkColorUpdateNeeded=!0,this.isLinkWidthUpdateNeeded=!0,this.isLinkArrowUpdateNeeded=!0,this.isForceLinkUpdateNeeded=!0)}setLinkColors(e){this._isDestroyed||this.ensureDevice(()=>this.setLinkColors(e))||(this.graph.inputLinkColors=e,this.isLinkColorUpdateNeeded=!0)}getLinkColors(){return this._isDestroyed?new Float32Array:this.graph.linkColors??new Float32Array}setLinkWidths(e){this._isDestroyed||this.ensureDevice(()=>this.setLinkWidths(e))||(this.graph.inputLinkWidths=e,this.isLinkWidthUpdateNeeded=!0)}getLinkWidths(){return this._isDestroyed?new Float32Array:this.graph.linkWidths??new Float32Array}setLinkArrows(e){this._isDestroyed||this.ensureDevice(()=>this.setLinkArrows(e))||(this.graph.linkArrowsBoolean=e,this.isLinkArrowUpdateNeeded=!0)}setLinkStrength(e){this._isDestroyed||this.ensureDevice(()=>this.setLinkStrength(e))||(this.graph.inputLinkStrength=e,this.isForceLinkUpdateNeeded=!0)}setPointClusters(e){this._isDestroyed||this.ensureDevice(()=>this.setPointClusters(e))||(this.graph.inputPointClusters=e,this.isPointClusterUpdateNeeded=!0)}setClusterPositions(e){this._isDestroyed||this.ensureDevice(()=>this.setClusterPositions(e))||(this.graph.inputClusterPositions=e,this.isPointClusterUpdateNeeded=!0)}setPointClusterStrength(e){this._isDestroyed||this.ensureDevice(()=>this.setPointClusterStrength(e))||(this.graph.inputClusterStrength=e,this.isPointClusterUpdateNeeded=!0)}setPinnedPoints(e){var t;this._isDestroyed||this.ensureDevice(()=>this.setPinnedPoints(e))||(this.graph.inputPinnedPoints=e&&e.length>0?e:void 0,(t=this.points)==null||t.updatePinnedStatus())}render(e){if(this._isDestroyed||this.ensureDevice(()=>this.render(e)))return;this.graph.update();const{fitViewOnInit:t,fitViewDelay:i,fitViewPadding:r,fitViewDuration:s,fitViewByPointsInRect:o,fitViewByPointIndices:a,initialZoomLevel:l}=this.config;if(!this.graph.pointsNumber&&!this.graph.linksNumber){this.stopFrames(),we(this.canvas).style("cursor",null),this.device&&(this.device.beginRenderPass({clearColor:this.store.backgroundColor,clearDepth:1,clearStencil:0}).end(),this.device.submit());return}this._isFirstRenderAfterInit&&t&&l===void 0&&(this._fitViewOnInitTimeoutID=window.setTimeout(()=>{a?this.fitViewByPointIndices(a,s,r):o?this.setZoomTransformByPointPositions(new Float32Array(this.flatten(o)),s,void 0,r):this.fitView(s,r)},i)),this.update(e),this.startFrames(),this._isFirstRenderAfterInit=!1}zoomToPointByIndex(e,t=700,i=M_,r=!0){if(this._isDestroyed||this.ensureDevice(()=>this.zoomToPointByIndex(e,t,i,r))||!this.device||!this.points||!this.canvasD3Selection)return;const{store:{screenSize:s}}=this,o=Xe(this.device,this.points.currentPositionFbo);if(e===void 0)return;const a=o[e*4+0],l=o[e*4+1];if(a===void 0||l===void 0)return;const c=this.zoomInstance.getDistanceToPoint([a,l]),u=r?i:Math.max(this.getZoomLevel(),i);if(c<Math.min(s[0],s[1]))this.setZoomTransformByPointPositions(new Float32Array([a,l]),t,u);else{const f=this.zoomInstance.getTransform([a,l],u),h=this.zoomInstance.getMiddlePointTransform([a,l]);this.canvasD3Selection.transition().ease(lp).duration(t/2).call(this.zoomInstance.behavior.transform,h).transition().ease(cp).duration(t/2).call(this.zoomInstance.behavior.transform,f)}}zoom(e,t=0){this._isDestroyed||this.setZoomLevel(e,t)}setZoomLevel(e,t=0){this._isDestroyed||this.ensureDevice(()=>this.setZoomLevel(e,t))||this.canvasD3Selection&&(t===0?this.canvasD3Selection.call(this.zoomInstance.behavior.scaleTo,e):this.canvasD3Selection.transition().duration(t).call(this.zoomInstance.behavior.scaleTo,e))}getZoomLevel(){return this._isDestroyed?0:this.zoomInstance.eventTransform.k}getPointPositions(){if(this._isDestroyed||!this.device||!this.points)return[];if(this.graph.pointsNumber===void 0)return[];const e=[],t=Xe(this.device,this.points.currentPositionFbo);e.length=this.graph.pointsNumber*2;for(let i=0;i<this.graph.pointsNumber;i+=1){const r=t[i*4+0],s=t[i*4+1];r!==void 0&&s!==void 0&&(e[i*2]=r,e[i*2+1]=s)}return e}getClusterPositions(){if(this._isDestroyed||!this.device||!this.clusters)return[];if(this.graph.pointClusters===void 0||this.clusters.clusterCount===void 0)return[];this.clusters.calculateCentermass();const e=[],t=Xe(this.device,this.clusters.centermassFbo);e.length=this.clusters.clusterCount*2;for(let i=0;i<e.length/2;i+=1){const r=t[i*4+0],s=t[i*4+1],o=t[i*4+2];r!==void 0&&s!==void 0&&o!==void 0&&(e[i*2]=r/o,e[i*2+1]=s/o)}return e}fitView(e=250,t=.1){this._isDestroyed||this.ensureDevice(()=>this.fitView(e,t))||this.setZoomTransformByPointPositions(new Float32Array(this.getPointPositions()),e,void 0,t)}fitViewByPointIndices(e,t=250,i=.1){if(this._isDestroyed||this.ensureDevice(()=>this.fitViewByPointIndices(e,t,i)))return;const r=this.getPointPositions(),s=new Float32Array(e.length*2);for(const[o,a]of e.entries())s[o*2]=r[a*2],s[o*2+1]=r[a*2+1];this.setZoomTransformByPointPositions(s,t,void 0,i)}fitViewByPointPositions(e,t=250,i=.1){this._isDestroyed||this.ensureDevice(()=>this.fitViewByPointPositions(e,t,i))||this.setZoomTransformByPointPositions(new Float32Array(e),t,void 0,i)}setZoomTransformByPointPositions(e,t=250,i,r=.1){var o;if(this._isDestroyed||this.ensureDevice(()=>this.setZoomTransformByPointPositions(e,t,i,r)))return;this.resizeCanvas();const s=this.zoomInstance.getTransform(e,i,r);(o=this.canvasD3Selection)==null||o.transition().ease(up).duration(t).call(this.zoomInstance.behavior.transform,s)}getPointsInRect(e){if(this._isDestroyed||!this.device||!this.points)return new Float32Array;const t=this.store.screenSize[1];return this.store.selectedArea=[[e[0][0],t-e[1][1]],[e[1][0],t-e[0][1]]],this.points.findPointsOnAreaSelection(),Xe(this.device,this.points.selectedFbo).map((r,s)=>s%4===0&&r!==0?s/4:-1).filter(r=>r!==-1)}getPointsInRange(e){return this.getPointsInRect(e)}getPointsInPolygon(e){if(this._isDestroyed||!this.device||!this.points)return new Float32Array;if(e.length<3)return new Float32Array;const t=this.store.screenSize[1],i=e.map(([s,o])=>[s,t-o]);return this.points.updatePolygonPath(i),this.points.findPointsOnPolygonSelection(),Xe(this.device,this.points.selectedFbo).map((s,o)=>o%4===0&&s!==0?o/4:-1).filter(s=>s!==-1)}selectPointsInRect(e){if(!this._isDestroyed&&!this.ensureDevice(()=>this.selectPointsInRect(e))&&!(!this.device||!this.points)){if(e){const t=this.store.screenSize[1];this.store.selectedArea=[[e[0][0],t-e[1][1]],[e[1][0],t-e[0][1]]],this.points.findPointsOnAreaSelection();const i=Xe(this.device,this.points.selectedFbo);this.store.selectedIndices=i.map((r,s)=>s%4===0&&r!==0?s/4:-1).filter(r=>r!==-1)}else this.store.selectedIndices=null;this.points.updateGreyoutStatus()}}selectPointsInRange(e){return this.selectPointsInRect(e)}selectPointsInPolygon(e){if(!this._isDestroyed&&!this.ensureDevice(()=>this.selectPointsInPolygon(e))&&!(!this.device||!this.points)){if(e){if(e.length<3){console.warn("Polygon path requires at least 3 points to form a polygon.");return}const t=this.store.screenSize[1],i=e.map(([s,o])=>[s,t-o]);this.points.updatePolygonPath(i),this.points.findPointsOnPolygonSelection();const r=Xe(this.device,this.points.selectedFbo);this.store.selectedIndices=r.map((s,o)=>o%4===0&&s!==0?o/4:-1).filter(s=>s!==-1)}else this.store.selectedIndices=null;this.points.updateGreyoutStatus()}}selectPointByIndex(e,t=!1){if(!this._isDestroyed&&!this.ensureDevice(()=>this.selectPointByIndex(e,t)))if(t){const i=this.graph.getAdjacentIndices(e)??[];this.selectPointsByIndices([e,...i])}else this.selectPointsByIndices([e])}selectPointsByIndices(e){this._isDestroyed||this.ensureDevice(()=>this.selectPointsByIndices(e))||this.points&&(e?e.length===0?this.store.selectedIndices=new Float32Array:this.store.selectedIndices=new Float32Array(e.filter(t=>t!==void 0)):this.store.selectedIndices=null,this.points.updateGreyoutStatus())}unselectPoints(){this._isDestroyed||this.ensureDevice(()=>this.unselectPoints())||this.points&&(this.store.selectedIndices=null,this.points.updateGreyoutStatus())}getSelectedIndices(){if(this._isDestroyed)return null;const{selectedIndices:e}=this.store;return e?Array.from(e):null}getAdjacentIndices(e){if(!this._isDestroyed)return this.graph.getAdjacentIndices(e)}spaceToScreenPosition(e){return this._isDestroyed?[0,0]:this.zoomInstance.convertSpaceToScreenPosition(e)}screenToSpacePosition(e){return this._isDestroyed?[0,0]:this.zoomInstance.convertScreenToSpacePosition(e)}spaceToScreenRadius(e){return this._isDestroyed?0:this.zoomInstance.convertSpaceToScreenRadius(e)}getPointRadiusByIndex(e){var t;if(!this._isDestroyed)return(t=this.graph.pointSizes)==null?void 0:t[e]}trackPointPositionsByIndices(e){this._isDestroyed||this.ensureDevice(()=>this.trackPointPositionsByIndices(e))||this.points&&this.points.trackPointsByIndices(e)}getTrackedPointPositionsMap(){return this._isDestroyed||!this.points?new Map:this.points.getTrackedPositionsMap()}getTrackedPointPositionsArray(){return this._isDestroyed||!this.points?[]:this.points.getTrackedPositionsArray()}getSampledPointPositionsMap(){return this._isDestroyed||!this.points?new Map:this.points.getSampledPointPositionsMap()}getSampledPoints(){return this._isDestroyed||!this.points?{indices:[],positions:[]}:this.points.getSampledPoints()}getScaleX(){if(!(this._isDestroyed||!this.points))return this.points.scaleX}getScaleY(){if(!(this._isDestroyed||!this.points))return this.points.scaleY}start(e=1){var t,i;this._isDestroyed||this.ensureDevice(()=>this.start(e))||this.graph.pointsNumber&&(this.store.isSimulationRunning=!0,this.store.simulationProgress=0,this.store.alpha=e,(i=(t=this.config).onSimulationStart)==null||i.call(t))}stop(){var e,t;this._isDestroyed||(this.store.isSimulationRunning=!1,this.store.simulationProgress=0,this.store.alpha=0,(t=(e=this.config).onSimulationEnd)==null||t.call(e))}pause(){var e,t;this._isDestroyed||this.ensureDevice(()=>this.pause())||(this.store.isSimulationRunning=!1,(t=(e=this.config).onSimulationPause)==null||t.call(e))}unpause(){var e,t;this._isDestroyed||this.ensureDevice(()=>this.unpause())||(this.store.isSimulationRunning=!0,(t=(e=this.config).onSimulationUnpause)==null||t.call(e))}restart(){var e,t;this._isDestroyed||this.ensureDevice(()=>this.restart())||(this.store.isSimulationRunning=!0,(t=(e=this.config).onSimulationRestart)==null||t.call(e))}step(){this._isDestroyed||this.ensureDevice(()=>this.step())||this.config.enableSimulation&&this.store.pointsTextureSize&&this.runSimulationStep(!0)}destroy(){var e,t,i,r,s,o,a,l,c,u,f,h,d;this._isDestroyed||(this._isDestroyed=!0,this.isReady=!1,window.clearTimeout(this._fitViewOnInitTimeoutID),this.stopFrames(),this.canvasD3Selection&&this.canvasD3Selection.on("mouseenter.cosmos",null).on("mousemove.cosmos",null).on("mouseleave.cosmos",null).on("click",null).on("mousemove",null).on("contextmenu",null).on(".drag",null).on(".zoom",null),we(document).on("keydown.cosmos",null).on("keyup.cosmos",null),(e=this.zoomInstance)!=null&&e.behavior&&this.zoomInstance.behavior.on("start.detect",null).on("zoom.detect",null).on("end.detect",null),(t=this.dragInstance)!=null&&t.behavior&&this.dragInstance.behavior.on("start.detect",null).on("drag.detect",null).on("end.detect",null),(i=this.fpsMonitor)==null||i.destroy(),(r=this.points)==null||r.destroy(),(s=this.lines)==null||s.destroy(),(o=this.clusters)==null||o.destroy(),(a=this.forceGravity)==null||a.destroy(),(l=this.forceCenter)==null||l.destroy(),(c=this.forceManyBody)==null||c.destroy(),(u=this.forceLinkIncoming)==null||u.destroy(),(f=this.forceLinkOutgoing)==null||f.destroy(),(h=this.forceMouse)==null||h.destroy(),this.device&&this.shouldDestroyDevice&&(this.device.beginRenderPass({clearColor:this.store.backgroundColor,clearDepth:1,clearStencil:0}).end(),this.device.submit(),this.device.destroy()),this.shouldDestroyDevice&&this.canvas&&this.canvas.parentNode&&this.canvas.parentNode.removeChild(this.canvas),this.attributionDivElement&&this.attributionDivElement.parentNode&&this.attributionDivElement.parentNode.removeChild(this.attributionDivElement),(d=document.getElementById("gl-bench-style"))==null||d.remove(),this.canvasD3Selection=void 0,this.attributionDivElement=void 0)}create(){var e,t,i,r,s;this._isDestroyed||this.ensureDevice(()=>this.create())||this.points&&this.lines&&(this.isPointPositionsUpdateNeeded&&this.points.updatePositions(),this.isPointColorUpdateNeeded&&this.points.updateColor(),this.isPointSizeUpdateNeeded&&this.points.updateSize(),this.isPointShapeUpdateNeeded&&this.points.updateShape(),this.isPointImageIndicesUpdateNeeded&&this.points.updateImageIndices(),this.isPointImageSizesUpdateNeeded&&this.points.updateImageSizes(),this.isLinksUpdateNeeded&&this.lines.updatePointsBuffer(),this.isLinkColorUpdateNeeded&&this.lines.updateColor(),this.isLinkWidthUpdateNeeded&&this.lines.updateWidth(),this.isLinkArrowUpdateNeeded&&this.lines.updateArrow(),this.isForceManyBodyUpdateNeeded&&((e=this.forceManyBody)==null||e.create()),this.isForceLinkUpdateNeeded&&((t=this.forceLinkIncoming)==null||t.create(Io.INCOMING),(i=this.forceLinkOutgoing)==null||i.create(Io.OUTGOING)),this.isForceCenterUpdateNeeded&&((r=this.forceCenter)==null||r.create()),this.isPointClusterUpdateNeeded&&((s=this.clusters)==null||s.create()),this.isPointPositionsUpdateNeeded=!1,this.isPointColorUpdateNeeded=!1,this.isPointSizeUpdateNeeded=!1,this.isPointShapeUpdateNeeded=!1,this.isPointImageIndicesUpdateNeeded=!1,this.isPointImageSizesUpdateNeeded=!1,this.isLinksUpdateNeeded=!1,this.isLinkColorUpdateNeeded=!1,this.isLinkWidthUpdateNeeded=!1,this.isLinkArrowUpdateNeeded=!1,this.isPointClusterUpdateNeeded=!1,this.isForceManyBodyUpdateNeeded=!1,this.isForceLinkUpdateNeeded=!1,this.isForceCenterUpdateNeeded=!1)}flatten(e){return e.flat()}pair(e){const t=new Array(e.length/2);for(let i=0;i<e.length/2;i++)t[i]=[e[i*2],e[i*2+1]];return t}ensureDevice(e){return this.isReady?!1:(this.ready.then(()=>{this._isDestroyed||e()}).catch(t=>{console.error("Device initialization failed",t)}),!0)}validateDevice(e){const t=e.canvasContext;if(t===null||t.type==="offscreen-canvas")throw new Error("Device must have an HTMLCanvasElement canvas context. OffscreenCanvas and compute-only devices are not supported.");return t}async createDevice(e){return await jp.createDevice({type:"webgl",adapters:[qg],createCanvasContext:{canvas:e,useDevicePixels:this.config.pixelRatio,autoResize:!0,width:void 0,height:void 0}})}update(e=this.store.alpha){const{graph:t}=this;this.store.pointsTextureSize=Math.ceil(Math.sqrt(t.pointsNumber??0)),this.store.linksTextureSize=Math.ceil(Math.sqrt((t.linksNumber??0)*2)),this.create(),this.initPrograms(),this.store.hoveredPoint=void 0,this.store.alpha=e}runSimulationStep(e=!1){var a,l,c,u,f,h,d,_,I,P,A,O,E,y,R,N,U,W,q;const{config:{simulationGravity:t,simulationCenter:i,enableSimulation:r},store:{isSimulationRunning:s}}=this;if(!r)return;this.isRightClickMouse&&this.config.enableRightClickRepulsion&&((a=this.forceMouse)==null||a.run(),(l=this.points)==null||l.updatePosition()),(e||s&&!(this.zoomInstance.isRunning&&!this.config.enableSimulationDuringZoom))&&(t&&((c=this.forceGravity)==null||c.run(),(u=this.points)==null||u.updatePosition()),i&&((f=this.forceCenter)==null||f.run(),(h=this.points)==null||h.updatePosition()),(d=this.forceManyBody)==null||d.run(),(_=this.points)==null||_.updatePosition(),this.store.linksTextureSize&&((I=this.forceLinkIncoming)==null||I.run(),(P=this.points)==null||P.updatePosition(),(A=this.forceLinkOutgoing)==null||A.run(),(O=this.points)==null||O.updatePosition()),(this.graph.pointClusters||this.graph.clusterPositions)&&((E=this.clusters)==null||E.run(),(y=this.points)==null||y.updatePosition()),this.store.alpha+=this.store.addAlpha(this.config.simulationDecay??V.simulation.decay),this.isRightClickMouse&&this.config.enableRightClickRepulsion&&(this.store.alpha=Math.max(this.store.alpha,.1)),this.store.simulationProgress=Math.sqrt(Math.min(1,Qs/this.store.alpha)),(W=(U=this.config).onSimulationTick)==null||W.call(U,this.store.alpha,(R=this.store.hoveredPoint)==null?void 0:R.index,(N=this.store.hoveredPoint)==null?void 0:N.position)),(q=this.points)==null||q.trackPoints()}initPrograms(){var e,t,i,r,s,o;this._isDestroyed||!this.points||!this.lines||!this.clusters||(this.points.initPrograms(),this.lines.initPrograms(),(e=this.forceGravity)==null||e.initPrograms(),(t=this.forceManyBody)==null||t.initPrograms(),(i=this.forceCenter)==null||i.initPrograms(),(r=this.forceLinkIncoming)==null||r.initPrograms(),(s=this.forceLinkOutgoing)==null||s.initPrograms(),(o=this.forceMouse)==null||o.initPrograms(),this.clusters.initPrograms())}frame(){if(this._isDestroyed)return;const{store:{alpha:e,isSimulationRunning:t}}=this;e<Qs&&t&&this.end(),this.requestAnimationFrameId=window.requestAnimationFrame(i=>{this.renderFrame(i),this._isDestroyed||this.frame()})}renderFrame(e){var t,i,r,s,o,a,l;if(!this._isDestroyed&&this.store.pointsTextureSize){if((t=this.fpsMonitor)==null||t.begin(),this.resizeCanvas(),this.dragInstance.isActive||this.findHoveredItem(),this.runSimulationStep(!1),this.device){const c=this.store.backgroundColor??[0,0,0,1],u=this.device.beginRenderPass({clearColor:c,clearDepth:1,clearStencil:0}),{config:{renderLinks:f}}=this;f!==!1&&!!this.store.linksTextureSize&&!!this.graph.linksNumber&&this.graph.linksNumber>0&&((i=this.lines)==null||i.draw(u)),(r=this.points)==null||r.draw(u),this.dragInstance.isActive&&((s=this.points)==null||s.drag(),(o=this.points)==null||o.drag(),(a=this.points)==null||a.trackPoints()),u.end(),this.device.submit()}(l=this.fpsMonitor)==null||l.end(e??performance.now()),this.currentEvent=void 0}}stopFrames(){this.requestAnimationFrameId&&(window.cancelAnimationFrame(this.requestAnimationFrameId),this.requestAnimationFrameId=0)}startFrames(){this._isDestroyed||(this.stopFrames(),this.frame())}end(){var e,t;this.store.isSimulationRunning=!1,this.store.simulationProgress=1,(t=(e=this.config).onSimulationEnd)==null||t.call(e),this._shouldForceHoverDetection=!0}onClick(e){var t,i,r,s,o,a,l,c,u,f;(s=(r=this.config).onClick)==null||s.call(r,(t=this.store.hoveredPoint)==null?void 0:t.index,(i=this.store.hoveredPoint)==null?void 0:i.position,e),this.store.hoveredPoint?(a=(o=this.config).onPointClick)==null||a.call(o,this.store.hoveredPoint.index,this.store.hoveredPoint.position,e):this.store.hoveredLinkIndex!==void 0?(c=(l=this.config).onLinkClick)==null||c.call(l,this.store.hoveredLinkIndex,e):(f=(u=this.config).onBackgroundClick)==null||f.call(u,e)}updateMousePosition(e){if(!e)return;const t=e.offsetX??e.x,i=e.offsetY??e.y;t===void 0||i===void 0||(this.store.mousePosition=this.zoomInstance.convertScreenToSpacePosition([t,i]),this.store.screenMousePosition=[t,this.store.screenSize[1]-i])}onMouseMove(e){var t,i,r,s;this.currentEvent=e,this.updateMousePosition(e),this.isRightClickMouse=e.which===3,(s=(r=this.config).onMouseMove)==null||s.call(r,(t=this.store.hoveredPoint)==null?void 0:t.index,(i=this.store.hoveredPoint)==null?void 0:i.position,this.currentEvent)}onContextMenu(e){var t,i,r,s,o,a,l,c,u,f;e.preventDefault(),(s=(r=this.config).onContextMenu)==null||s.call(r,(t=this.store.hoveredPoint)==null?void 0:t.index,(i=this.store.hoveredPoint)==null?void 0:i.position,e),this.store.hoveredPoint?(a=(o=this.config).onPointContextMenu)==null||a.call(o,this.store.hoveredPoint.index,this.store.hoveredPoint.position,e):this.store.hoveredLinkIndex!==void 0?(c=(l=this.config).onLinkContextMenu)==null||c.call(l,this.store.hoveredLinkIndex,e):(f=(u=this.config).onBackgroundContextMenu)==null||f.call(u,e)}resizeCanvas(e=!1){var o,a,l;if(this._isDestroyed)return;const t=this.canvas.clientWidth,i=this.canvas.clientHeight,[r,s]=this.store.screenSize;if(e||r!==t||s!==i){const{k:c}=this.zoomInstance.eventTransform,u=this.zoomInstance.convertScreenToSpacePosition([r/2,s/2]);this.store.updateScreenSize(t,i),(o=this.canvasD3Selection)==null||o.call(this.zoomInstance.behavior.transform,this.zoomInstance.getTransform(u,c)),(a=this.points)==null||a.updateSampledPointsGrid(),this.store.isLinkHoveringEnabled&&((l=this.lines)==null||l.updateLinkIndexFbo())}}updateZoomDragBehaviors(){var e,t,i,r;this.config.enableDrag?(e=this.canvasD3Selection)==null||e.call(this.dragInstance.behavior):(t=this.canvasD3Selection)==null||t.call(this.dragInstance.behavior).on(".drag",null),this.config.enableZoom?(i=this.canvasD3Selection)==null||i.call(this.zoomInstance.behavior):(r=this.canvasD3Selection)==null||r.call(this.zoomInstance.behavior).on("wheel.zoom",null)}findHoveredItem(){if(this._isDestroyed||!this._isMouseOnCanvas)return;if(this._findHoveredItemExecutionCount<xx){this._findHoveredItemExecutionCount+=1;return}const e=Math.abs(this._lastMouseX-this._lastCheckedMouseX),t=Math.abs(this._lastMouseY-this._lastCheckedMouseY);if(!(!(e>_c||t>_c)&&!this._shouldForceHoverDetection)){if(this._lastCheckedMouseX=this._lastMouseX,this._lastCheckedMouseY=this._lastMouseY,this._shouldForceHoverDetection=!1,this._findHoveredItemExecutionCount=0,this.findHoveredPoint(),this.graph.linksNumber&&this.store.isLinkHoveringEnabled)this.findHoveredLine();else if(this.store.hoveredLinkIndex!==void 0){const r=this.store.hoveredLinkIndex!==void 0;this.store.hoveredLinkIndex=void 0,r&&this.config.onLinkMouseOut&&this.config.onLinkMouseOut(this.currentEvent)}this.updateCanvasCursor()}}findHoveredPoint(){var l,c,u,f,h;if(this._isDestroyed||!this.device||!this.points)return;this.points.findHoveredPoint();let e=!1,t=!1;const i=Xe(this.device,this.points.hoveredFbo,0,0,2,2),r=i[0],s=i[1],o=i[2],a=i[3];s>0?((this.store.hoveredPoint===void 0||this.store.hoveredPoint.index!==r)&&(e=!0),this.store.hoveredPoint={index:r,position:[o,a]}):(this.store.hoveredPoint&&(t=!0),this.store.hoveredPoint=void 0),e&&this.store.hoveredPoint&&((u=(c=this.config).onPointMouseOver)==null||u.call(c,this.store.hoveredPoint.index,this.store.hoveredPoint.position,this.currentEvent,((l=this.store.selectedIndices)==null?void 0:l.includes(this.store.hoveredPoint.index))??!1)),t&&((h=(f=this.config).onPointMouseOut)==null||h.call(f,this.currentEvent))}findHoveredLine(){var s,o,a,l,c,u;if(this._isDestroyed||!this.lines)return;if(this.store.hoveredPoint){this.store.hoveredLinkIndex!==void 0&&(this.store.hoveredLinkIndex=void 0,(o=(s=this.config).onLinkMouseOut)==null||o.call(s,this.currentEvent));return}this.lines.findHoveredLine();let e=!1,t=!1;if(!this.device)return;const r=Xe(this.device,this.lines.hoveredLineIndexFbo)[0];r>=0?(this.store.hoveredLinkIndex!==r&&(e=!0),this.store.hoveredLinkIndex=r):(this.store.hoveredLinkIndex!==void 0&&(t=!0),this.store.hoveredLinkIndex=void 0),e&&this.store.hoveredLinkIndex!==void 0&&((l=(a=this.config).onLinkMouseOver)==null||l.call(a,this.store.hoveredLinkIndex)),t&&((u=(c=this.config).onLinkMouseOut)==null||u.call(c,this.currentEvent))}updateCanvasCursor(){const{hoveredPointCursor:e,hoveredLinkCursor:t}=this.config;this.dragInstance.isActive?we(this.canvas).style("cursor","grabbing"):this.store.hoveredPoint?!this.config.enableDrag||this.store.isSpaceKeyPressed?we(this.canvas).style("cursor",e):we(this.canvas).style("cursor","grab"):this.store.isLinkHoveringEnabled&&this.store.hoveredLinkIndex!==void 0?we(this.canvas).style("cursor",t):we(this.canvas).style("cursor",null)}addAttribution(){var e;this.config.attribution&&(this.attributionDivElement=document.createElement("div"),this.attributionDivElement.style.cssText=`
2289
2289
  user-select: none;
2290
2290
  position: absolute;
2291
2291
  bottom: 0;