From 6fb5c0d74c421a7f62aded356a52986014d4d469 Mon Sep 17 00:00:00 2001 From: AlexIchenskiy Date: Fri, 4 Sep 2026 10:29:30 +0200 Subject: [PATCH 1/3] New: Add rectangle selection --- docs/site/concepts/events.md | 9 + docs/site/concepts/interaction.md | 72 +++++++ .../public/demos/rectangle-selection.html | 158 +++++++++++++++ docs/site/public/orb.min.js | 2 +- package.json | 10 + src/common/area/area.ts | 28 +++ src/common/area/index.ts | 2 + src/common/area/rectangle.ts | 33 ++++ src/common/index.ts | 3 +- src/common/rectangle.ts | 14 ++ src/events.ts | 10 + src/index.ts | 3 +- src/interactions/index.ts | 10 + src/interactions/rectangle-selection.ts | 162 ++++++++++++++++ src/interactions/shared.ts | 50 +++++ src/models/edge.ts | 33 +++- src/models/graph.ts | 45 ++++- src/models/interaction.ts | 62 +++++- src/models/node.ts | 8 + src/renderer/canvas/canvas-renderer.ts | 5 + src/renderer/shared.ts | 9 + src/renderer/webgl/webgl-renderer.ts | 43 ++++- src/utils/graph.utils.ts | 40 ++++ src/views/background-drag.ts | 18 ++ src/views/orb-map-view.ts | 31 ++- src/views/orb-view.ts | 125 +++++++++++- src/views/shared.ts | 5 + test/common/area/rectangle.spec.ts | 38 ++++ test/models/selection.spec.ts | 180 ++++++++++++++++++ 29 files changed, 1183 insertions(+), 25 deletions(-) create mode 100644 docs/site/public/demos/rectangle-selection.html create mode 100644 src/common/area/area.ts create mode 100644 src/common/area/index.ts create mode 100644 src/common/area/rectangle.ts create mode 100644 src/interactions/index.ts create mode 100644 src/interactions/rectangle-selection.ts create mode 100644 src/interactions/shared.ts create mode 100644 src/views/background-drag.ts create mode 100644 test/common/area/rectangle.spec.ts create mode 100644 test/models/selection.spec.ts diff --git a/docs/site/concepts/events.md b/docs/site/concepts/events.md index 88f66f6..dc0ec8c 100644 --- a/docs/site/concepts/events.md +++ b/docs/site/concepts/events.md @@ -75,6 +75,15 @@ Node drag emits a sequence of `node` + position events. Dragging is controlled b | `NODE_DRAG` | `node`, position, `event` | The node moves during a drag. | | `NODE_DRAG_END` | `node`, position, `event` | The drag ends. | +Dragging the empty background emits a separate, subject-less sequence, off by default and +enabled with `interaction.backgroundDrag` - see [Selection & interaction](/concepts/interaction). + +| Event | Payload | Fires when | +| --- | --- | --- | +| `BACKGROUND_DRAG_START` | position, `event` | A background drag begins (modifier held, no node hit). | +| `BACKGROUND_DRAG` | position, `event` | The cursor moves during a background drag. | +| `BACKGROUND_DRAG_END` | position, `event` | The background drag ends. | + ## Examples ### A tooltip that follows the cursor diff --git a/docs/site/concepts/interaction.md b/docs/site/concepts/interaction.md index 7b3a52b..8869bfd 100644 --- a/docs/site/concepts/interaction.md +++ b/docs/site/concepts/interaction.md @@ -35,10 +35,19 @@ const orb = new OrbView(container, { interaction: { isDragEnabled: true, // drag nodes (default: true) isZoomEnabled: true, // scroll to zoom, drag background to pan (default: true) + backgroundDrag: { + isEnabled: false, // emit background-drag events on a modifier + drag (default: false) + modifier: 'shift', // 'shift' | 'ctrl' | 'alt' | 'meta' | null (default: 'shift') + }, }, }); ``` +- **Background drag** - off by default. When enabled, dragging the empty background with the + modifier held emits neutral `BACKGROUND_DRAG_*` [events](/concepts/events) instead of + panning; a plain drag still pans. It's the gesture [rectangle selection](#rectangle-selection) + is built on, and is equally usable for custom box-zoom or lasso. + To disable Orb's built-in selection entirely and handle it yourself, turn off the strategy flags and drive state from [events](/concepts/events). @@ -80,6 +89,12 @@ orb.interaction.unselectNodeById(1); orb.interaction.unselectEdgeById(10); orb.interaction.unselectAll(); +// Select many at once (non-cascading by default), returns the matched count +orb.interaction.selectNodesByIds([1, 2, 3]); +orb.interaction.unselectNodesByIds([1, 2, 3]); +orb.interaction.selectEdgesByIds([10, 11]); +orb.interaction.unselectEdgesByIds([10, 11]); + // Hover orb.interaction.hoverNodeById(1); orb.interaction.hoverEdgeById(10); @@ -107,6 +122,63 @@ searchInput.addEventListener('change', (e) => { }); ``` +## Rectangle selection + +Selecting a whole region at once - drag a box, select the nodes inside - ships as an opt-in +module, `@memgraph/orb/interactions`, kept out of the core bundle so you only pay for it when +you use it. + + + +It takes **two steps**: enable the background-drag gesture on the view, then attach a +`RectangleSelection` to it. + +```typescript +import { OrbView } from '@memgraph/orb'; +import { RectangleSelection } from '@memgraph/orb/interactions'; + +const orb = new OrbView(container, { + interaction: { backgroundDrag: { isEnabled: true, modifier: 'shift' } }, +}); + +const selection = new RectangleSelection(orb); +selection.on('select', ({ nodes, edges, mode }) => { + // nodes (and edges, if enabled) are now selected; mode is 'replace' or 'add' +}); +``` + +By default, **Shift-drag** over the empty background draws the box and replaces the +selection; holding **Ctrl/Cmd** as well adds to it. Dragging a node still moves it, and a +plain drag still pans. Call `selection.destroy()` to detach it. + +::: warning Requires background drag +`RectangleSelection` only listens - it does not enable the gesture. If +`interaction.backgroundDrag.isEnabled` is not set on the view, attaching it does nothing and +Shift-drag is a no-op. +::: + +`RectangleSelection` accepts `IRectangleSelectionOptions`: + +| Option | Type | Default | +| --- | --- | --- | +| `resolveMode` | `(event: MouseEvent) => 'replace' \| 'add'` | ctrl/meta → `add`, else `replace` | +| `includeEdges` | `'none' \| 'endpointsInside'` | `'none'` - `'endpointsInside'` also selects edges whose both endpoints fall in the box | +| `style` | `Partial` | dashed blue overlay | + +The overlay element carries the `orb-selection-rectangle` class, so you can also style it +from CSS. + +The module is built entirely on public API, so the same primitives are available if you want +a different gesture (lasso, custom modifiers): + +```typescript +import { RectangleArea } from '@memgraph/orb'; + +const area = new RectangleArea({ x, y, width, height }); +const nodes = orb.data.getNodesInArea(area); // nodes whose center is inside +orb.interaction.selectNodesByIds(nodes.map((n) => n.getId())); +``` + ## Dimming the rest of the graph On selection or hover, Orb dims everything else so the focus stands out. That transparency diff --git a/docs/site/public/demos/rectangle-selection.html b/docs/site/public/demos/rectangle-selection.html new file mode 100644 index 0000000..cdce3f7 --- /dev/null +++ b/docs/site/public/demos/rectangle-selection.html @@ -0,0 +1,158 @@ + + + + + + Orb - rectangle selection demo + + + + + +
+
+ Shift+drag to select · Ctrl/Cmd to add + + + 0 nodes, 0 edges +
+
+
+ + + + diff --git a/docs/site/public/orb.min.js b/docs/site/public/orb.min.js index 9e03f70..3358174 100644 --- a/docs/site/public/orb.min.js +++ b/docs/site/public/orb.min.js @@ -1,2 +1,2 @@ /*! For license information please see orb.min.js.LICENSE.txt */ -!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.Orb=e():t.Orb=e()}(self,()=>(()=>{var t={481(t,e){!function(t){"use strict";function e(t){var e,i,n,s;for(i=1,n=arguments.length;i0?Math.floor(t):Math.ceil(t)};function I(t,e,i){return t instanceof N?t:p(t)?new N(t[0],t[1]):null==t?t:"object"==typeof t&&"x"in t&&"y"in t?new N(t.x,t.y):new N(t,e,i)}function R(t,e){if(t)for(var i=e?[t,e]:t,n=0,s=i.length;n=this.min.x&&i.x<=this.max.x&&e.y>=this.min.y&&i.y<=this.max.y},intersects:function(t){t=O(t);var e=this.min,i=this.max,n=t.min,s=t.max,o=s.x>=e.x&&n.x<=i.x,r=s.y>=e.y&&n.y<=i.y;return o&&r},overlaps:function(t){t=O(t);var e=this.min,i=this.max,n=t.min,s=t.max,o=s.x>e.x&&n.xe.y&&n.y=n.lat&&i.lat<=s.lat&&e.lng>=n.lng&&i.lng<=s.lng},intersects:function(t){t=B(t);var e=this._southWest,i=this._northEast,n=t.getSouthWest(),s=t.getNorthEast(),o=s.lat>=e.lat&&n.lat<=i.lat,r=s.lng>=e.lng&&n.lng<=i.lng;return o&&r},overlaps:function(t){t=B(t);var e=this._southWest,i=this._northEast,n=t.getSouthWest(),s=t.getNorthEast(),o=s.lat>e.lat&&n.late.lng&&n.lng1,Ct=function(){var t=!1;try{var e=Object.defineProperty({},"passive",{get:function(){t=!0}});window.addEventListener("testPassiveEventSupport",h,e),window.removeEventListener("testPassiveEventSupport",h,e)}catch(t){}return t}(),Mt=!!document.createElement("canvas").getContext,Nt=!(!document.createElementNS||!Y("svg").createSVGRect),Dt=!!Nt&&((K=document.createElement("div")).innerHTML="","http://www.w3.org/2000/svg"===(K.firstChild&&K.firstChild.namespaceURI)),It=!Nt&&function(){try{var t=document.createElement("div");t.innerHTML='';var e=t.firstChild;return e.style.behavior="url(#default#VML)",e&&"object"==typeof e.adj}catch(t){return!1}}();function Lt(t){return navigator.userAgent.toLowerCase().indexOf(t)>=0}var Rt={ie:J,ielt9:tt,edge:et,webkit:it,android:nt,android23:st,androidStock:rt,opera:at,chrome:ht,gecko:lt,safari:dt,phantom:ut,opera12:ct,win:_t,ie3d:ft,webkit3d:gt,gecko3d:pt,any3d:mt,mobile:vt,mobileWebkit:yt,mobileWebkit3d:xt,msPointer:bt,pointer:St,touch:Tt,touchNative:wt,mobileOpera:Et,mobileGecko:Pt,retina:At,passiveEvents:Ct,canvas:Mt,svg:Nt,vml:It,inlineSvg:Dt,mac:0===navigator.platform.indexOf("Mac"),linux:0===navigator.platform.indexOf("Linux")},Ot=Rt.msPointer?"MSPointerDown":"pointerdown",kt=Rt.msPointer?"MSPointerMove":"pointermove",Bt=Rt.msPointer?"MSPointerUp":"pointerup",zt=Rt.msPointer?"MSPointerCancel":"pointercancel",Ut={touchstart:Ot,touchmove:kt,touchend:Bt,touchcancel:zt},Ft={touchstart:function(t,e){e.MSPOINTER_TYPE_TOUCH&&e.pointerType===e.MSPOINTER_TYPE_TOUCH&&Be(e),qt(t,e)},touchmove:qt,touchend:qt,touchcancel:qt},jt={},Wt=!1;function Zt(t,e,i){return"touchstart"===e&&(Wt||(document.addEventListener(Ot,Gt,!0),document.addEventListener(kt,Ht,!0),document.addEventListener(Bt,Xt,!0),document.addEventListener(zt,Xt,!0),Wt=!0)),Ft[e]?(i=Ft[e].bind(this,i),t.addEventListener(Ut[e],i,!1),i):(console.warn("wrong event specified:",e),h)}function Gt(t){jt[t.pointerId]=t}function Ht(t){jt[t.pointerId]&&(jt[t.pointerId]=t)}function Xt(t){delete jt[t.pointerId]}function qt(t,e){if(e.pointerType!==(e.MSPOINTER_TYPE_MOUSE||"mouse")){for(var i in e.touches=[],jt)e.touches.push(jt[i]);e.changedTouches=[e],t(e)}}var Vt,Yt,$t,Kt,Qt,Jt=ge(["transform","webkitTransform","OTransform","MozTransform","msTransform"]),te=ge(["webkitTransition","transition","OTransition","MozTransition","msTransition"]),ee="webkitTransition"===te||"OTransition"===te?te+"End":"transitionend";function ie(t){return"string"==typeof t?document.getElementById(t):t}function ne(t,e){var i=t.style[e]||t.currentStyle&&t.currentStyle[e];if((!i||"auto"===i)&&document.defaultView){var n=document.defaultView.getComputedStyle(t,null);i=n?n[e]:null}return"auto"===i?null:i}function se(t,e,i){var n=document.createElement(t);return n.className=e||"",i&&i.appendChild(n),n}function oe(t){var e=t.parentNode;e&&e.removeChild(t)}function re(t){for(;t.firstChild;)t.removeChild(t.firstChild)}function ae(t){var e=t.parentNode;e&&e.lastChild!==t&&e.appendChild(t)}function he(t){var e=t.parentNode;e&&e.firstChild!==t&&e.insertBefore(t,e.firstChild)}function le(t,e){if(void 0!==t.classList)return t.classList.contains(e);var i=_e(t);return i.length>0&&new RegExp("(^|\\s)"+e+"(\\s|$)").test(i)}function de(t,e){if(void 0!==t.classList)for(var i=u(e),n=0,s=i.length;n0?2*window.devicePixelRatio:1;function We(t){return Rt.edge?t.wheelDeltaY/2:t.deltaY&&0===t.deltaMode?-t.deltaY/je:t.deltaY&&1===t.deltaMode?20*-t.deltaY:t.deltaY&&2===t.deltaMode?60*-t.deltaY:t.deltaX||t.deltaZ?0:t.wheelDelta?(t.wheelDeltaY||t.wheelDelta)/2:t.detail&&Math.abs(t.detail)<32765?20*-t.detail:t.detail?t.detail/-32765*60:0}function Ze(t,e){var i=e.relatedTarget;if(!i)return!0;try{for(;i&&i!==t;)i=i.parentNode}catch(t){return!1}return i!==t}var Ge={__proto__:null,on:Ae,off:Me,stopPropagation:Re,disableScrollPropagation:Oe,disableClickPropagation:ke,preventDefault:Be,stop:ze,getPropagationPath:Ue,getMousePosition:Fe,getWheelDelta:We,isExternalTarget:Ze,addListener:Ae,removeListener:Me},He=M.extend({run:function(t,e,i,n){this.stop(),this._el=t,this._inProgress=!0,this._duration=i||.25,this._easeOutPower=1/Math.max(n||.5,.2),this._startPos=ve(t),this._offset=e.subtract(this._startPos),this._startTime=+new Date,this.fire("start"),this._animate()},stop:function(){this._inProgress&&(this._step(!0),this._complete())},_animate:function(){this._animId=T(this._animate,this),this._step()},_step:function(t){var e=+new Date-this._startTime,i=1e3*this._duration;ethis.options.maxZoom)?this.setZoom(t):this},panInsideBounds:function(t,e){this._enforcingBounds=!0;var i=this.getCenter(),n=this._limitCenter(i,this._zoom,B(t));return i.equals(n)||this.panTo(n,e),this._enforcingBounds=!1,this},panInside:function(t,e){var i=I((e=e||{}).paddingTopLeft||e.padding||[0,0]),n=I(e.paddingBottomRight||e.padding||[0,0]),s=this.project(this.getCenter()),o=this.project(t),r=this.getPixelBounds(),a=O([r.min.add(i),r.max.subtract(n)]),h=a.getSize();if(!a.contains(o)){this._enforcingBounds=!0;var l=o.subtract(a.getCenter()),d=a.extend(o).getSize().subtract(h);s.x+=l.x<0?-d.x:d.x,s.y+=l.y<0?-d.y:d.y,this.panTo(this.unproject(s),e),this._enforcingBounds=!1}return this},invalidateSize:function(t){if(!this._loaded)return this;t=e({animate:!1,pan:!0},!0===t?{animate:!0}:t);var i=this.getSize();this._sizeChanged=!0,this._lastCenter=null;var s=this.getSize(),o=i.divideBy(2).round(),r=s.divideBy(2).round(),a=o.subtract(r);return a.x||a.y?(t.animate&&t.pan?this.panBy(a):(t.pan&&this._rawPanBy(a),this.fire("move"),t.debounceMoveend?(clearTimeout(this._sizeTimer),this._sizeTimer=setTimeout(n(this.fire,this,"moveend"),200)):this.fire("moveend")),this.fire("resize",{oldSize:i,newSize:s})):this},stop:function(){return this.setZoom(this._limitZoom(this._zoom)),this.options.zoomSnap||this.fire("viewreset"),this._stop()},locate:function(t){if(t=this._locateOptions=e({timeout:1e4,watch:!1},t),!("geolocation"in navigator))return this._handleGeolocationError({code:0,message:"Geolocation not supported."}),this;var i=n(this._handleGeolocationResponse,this),s=n(this._handleGeolocationError,this);return t.watch?this._locationWatchId=navigator.geolocation.watchPosition(i,s,t):navigator.geolocation.getCurrentPosition(i,s,t),this},stopLocate:function(){return navigator.geolocation&&navigator.geolocation.clearWatch&&navigator.geolocation.clearWatch(this._locationWatchId),this._locateOptions&&(this._locateOptions.setView=!1),this},_handleGeolocationError:function(t){if(this._container._leaflet_id){var e=t.code,i=t.message||(1===e?"permission denied":2===e?"position unavailable":"timeout");this._locateOptions.setView&&!this._loaded&&this.fitWorld(),this.fire("locationerror",{code:e,message:"Geolocation error: "+i+"."})}},_handleGeolocationResponse:function(t){if(this._container._leaflet_id){var e=new z(t.coords.latitude,t.coords.longitude),i=e.toBounds(2*t.coords.accuracy),n=this._locateOptions;if(n.setView){var s=this.getBoundsZoom(i);this.setView(e,n.maxZoom?Math.min(s,n.maxZoom):s)}var o={latlng:e,bounds:i,timestamp:t.timestamp};for(var r in t.coords)"number"==typeof t.coords[r]&&(o[r]=t.coords[r]);this.fire("locationfound",o)}},addHandler:function(t,e){if(!e)return this;var i=this[t]=new e(this);return this._handlers.push(i),this.options[t]&&i.enable(),this},remove:function(){if(this._initEvents(!0),this.options.maxBounds&&this.off("moveend",this._panInsideMaxBounds),this._containerId!==this._container._leaflet_id)throw new Error("Map container is being reused by another instance");try{delete this._container._leaflet_id,delete this._containerId}catch(t){this._container._leaflet_id=void 0,this._containerId=void 0}var t;for(t in void 0!==this._locationWatchId&&this.stopLocate(),this._stop(),oe(this._mapPane),this._clearControlPos&&this._clearControlPos(),this._resizeRequest&&(E(this._resizeRequest),this._resizeRequest=null),this._clearHandlers(),this._loaded&&this.fire("unload"),this._layers)this._layers[t].remove();for(t in this._panes)oe(this._panes[t]);return this._layers=[],this._panes=[],delete this._mapPane,delete this._renderer,this},createPane:function(t,e){var i=se("div","leaflet-pane"+(t?" leaflet-"+t.replace("Pane","")+"-pane":""),e||this._mapPane);return t&&(this._panes[t]=i),i},getCenter:function(){return this._checkIfLoaded(),this._lastCenter&&!this._moved()?this._lastCenter.clone():this.layerPointToLatLng(this._getCenterLayerPoint())},getZoom:function(){return this._zoom},getBounds:function(){var t=this.getPixelBounds();return new k(this.unproject(t.getBottomLeft()),this.unproject(t.getTopRight()))},getMinZoom:function(){return void 0===this.options.minZoom?this._layersMinZoom||0:this.options.minZoom},getMaxZoom:function(){return void 0===this.options.maxZoom?void 0===this._layersMaxZoom?1/0:this._layersMaxZoom:this.options.maxZoom},getBoundsZoom:function(t,e,i){t=B(t),i=I(i||[0,0]);var n=this.getZoom()||0,s=this.getMinZoom(),o=this.getMaxZoom(),r=t.getNorthWest(),a=t.getSouthEast(),h=this.getSize().subtract(i),l=O(this.project(a,n),this.project(r,n)).getSize(),d=Rt.any3d?this.options.zoomSnap:1,u=h.x/l.x,c=h.y/l.y,_=e?Math.max(u,c):Math.min(u,c);return n=this.getScaleZoom(_,n),d&&(n=Math.round(n/(d/100))*(d/100),n=e?Math.ceil(n/d)*d:Math.floor(n/d)*d),Math.max(s,Math.min(o,n))},getSize:function(){return this._size&&!this._sizeChanged||(this._size=new N(this._container.clientWidth||0,this._container.clientHeight||0),this._sizeChanged=!1),this._size.clone()},getPixelBounds:function(t,e){var i=this._getTopLeftPoint(t,e);return new R(i,i.add(this.getSize()))},getPixelOrigin:function(){return this._checkIfLoaded(),this._pixelOrigin},getPixelWorldBounds:function(t){return this.options.crs.getProjectedBounds(void 0===t?this.getZoom():t)},getPane:function(t){return"string"==typeof t?this._panes[t]:t},getPanes:function(){return this._panes},getContainer:function(){return this._container},getZoomScale:function(t,e){var i=this.options.crs;return e=void 0===e?this._zoom:e,i.scale(t)/i.scale(e)},getScaleZoom:function(t,e){var i=this.options.crs;e=void 0===e?this._zoom:e;var n=i.zoom(t*i.scale(e));return isNaN(n)?1/0:n},project:function(t,e){return e=void 0===e?this._zoom:e,this.options.crs.latLngToPoint(U(t),e)},unproject:function(t,e){return e=void 0===e?this._zoom:e,this.options.crs.pointToLatLng(I(t),e)},layerPointToLatLng:function(t){var e=I(t).add(this.getPixelOrigin());return this.unproject(e)},latLngToLayerPoint:function(t){return this.project(U(t))._round()._subtract(this.getPixelOrigin())},wrapLatLng:function(t){return this.options.crs.wrapLatLng(U(t))},wrapLatLngBounds:function(t){return this.options.crs.wrapLatLngBounds(B(t))},distance:function(t,e){return this.options.crs.distance(U(t),U(e))},containerPointToLayerPoint:function(t){return I(t).subtract(this._getMapPanePos())},layerPointToContainerPoint:function(t){return I(t).add(this._getMapPanePos())},containerPointToLatLng:function(t){var e=this.containerPointToLayerPoint(I(t));return this.layerPointToLatLng(e)},latLngToContainerPoint:function(t){return this.layerPointToContainerPoint(this.latLngToLayerPoint(U(t)))},mouseEventToContainerPoint:function(t){return Fe(t,this._container)},mouseEventToLayerPoint:function(t){return this.containerPointToLayerPoint(this.mouseEventToContainerPoint(t))},mouseEventToLatLng:function(t){return this.layerPointToLatLng(this.mouseEventToLayerPoint(t))},_initContainer:function(t){var e=this._container=ie(t);if(!e)throw new Error("Map container not found.");if(e._leaflet_id)throw new Error("Map container is already initialized.");Ae(e,"scroll",this._onScroll,this),this._containerId=o(e)},_initLayout:function(){var t=this._container;this._fadeAnimated=this.options.fadeAnimation&&Rt.any3d,de(t,"leaflet-container"+(Rt.touch?" leaflet-touch":"")+(Rt.retina?" leaflet-retina":"")+(Rt.ielt9?" leaflet-oldie":"")+(Rt.safari?" leaflet-safari":"")+(this._fadeAnimated?" leaflet-fade-anim":""));var e=ne(t,"position");"absolute"!==e&&"relative"!==e&&"fixed"!==e&&"sticky"!==e&&(t.style.position="relative"),this._initPanes(),this._initControlPos&&this._initControlPos()},_initPanes:function(){var t=this._panes={};this._paneRenderers={},this._mapPane=this.createPane("mapPane",this._container),me(this._mapPane,new N(0,0)),this.createPane("tilePane"),this.createPane("overlayPane"),this.createPane("shadowPane"),this.createPane("markerPane"),this.createPane("tooltipPane"),this.createPane("popupPane"),this.options.markerZoomAnimation||(de(t.markerPane,"leaflet-zoom-hide"),de(t.shadowPane,"leaflet-zoom-hide"))},_resetView:function(t,e,i){me(this._mapPane,new N(0,0));var n=!this._loaded;this._loaded=!0,e=this._limitZoom(e),this.fire("viewprereset");var s=this._zoom!==e;this._moveStart(s,i)._move(t,e)._moveEnd(s),this.fire("viewreset"),n&&this.fire("load")},_moveStart:function(t,e){return t&&this.fire("zoomstart"),e||this.fire("movestart"),this},_move:function(t,e,i,n){void 0===e&&(e=this._zoom);var s=this._zoom!==e;return this._zoom=e,this._lastCenter=t,this._pixelOrigin=this._getNewPixelOrigin(t),n?i&&i.pinch&&this.fire("zoom",i):((s||i&&i.pinch)&&this.fire("zoom",i),this.fire("move",i)),this},_moveEnd:function(t){return t&&this.fire("zoomend"),this.fire("moveend")},_stop:function(){return E(this._flyToFrame),this._panAnim&&this._panAnim.stop(),this},_rawPanBy:function(t){me(this._mapPane,this._getMapPanePos().subtract(t))},_getZoomSpan:function(){return this.getMaxZoom()-this.getMinZoom()},_panInsideMaxBounds:function(){this._enforcingBounds||this.panInsideBounds(this.options.maxBounds)},_checkIfLoaded:function(){if(!this._loaded)throw new Error("Set map center and zoom first.")},_initEvents:function(t){this._targets={},this._targets[o(this._container)]=this;var e=t?Me:Ae;e(this._container,"click dblclick mousedown mouseup mouseover mouseout mousemove contextmenu keypress keydown keyup",this._handleDOMEvent,this),this.options.trackResize&&e(window,"resize",this._onResize,this),Rt.any3d&&this.options.transform3DLimit&&(t?this.off:this.on).call(this,"moveend",this._onMoveEnd)},_onResize:function(){E(this._resizeRequest),this._resizeRequest=T(function(){this.invalidateSize({debounceMoveend:!0})},this)},_onScroll:function(){this._container.scrollTop=0,this._container.scrollLeft=0},_onMoveEnd:function(){var t=this._getMapPanePos();Math.max(Math.abs(t.x),Math.abs(t.y))>=this.options.transform3DLimit&&this._resetView(this.getCenter(),this.getZoom())},_findEventTargets:function(t,e){for(var i,n=[],s="mouseout"===e||"mouseover"===e,r=t.target||t.srcElement,a=!1;r;){if((i=this._targets[o(r)])&&("click"===e||"preclick"===e)&&this._draggableMoved(i)){a=!0;break}if(i&&i.listens(e,!0)){if(s&&!Ze(r,t))break;if(n.push(i),s)break}if(r===this._container)break;r=r.parentNode}return n.length||a||s||!this.listens(e,!0)||(n=[this]),n},_isClickDisabled:function(t){for(;t&&t!==this._container;){if(t._leaflet_disable_click)return!0;t=t.parentNode}},_handleDOMEvent:function(t){var e=t.target||t.srcElement;if(!(!this._loaded||e._leaflet_disable_events||"click"===t.type&&this._isClickDisabled(e))){var i=t.type;"mousedown"===i&&Se(e),this._fireDOMEvent(t,i)}},_mouseEvents:["click","dblclick","mouseover","mouseout","contextmenu"],_fireDOMEvent:function(t,i,n){if("click"===t.type){var s=e({},t);s.type="preclick",this._fireDOMEvent(s,s.type,n)}var o=this._findEventTargets(t,i);if(n){for(var r=[],a=0;a0?Math.round(t-e)/2:Math.max(0,Math.ceil(t))-Math.max(0,Math.floor(e))},_limitZoom:function(t){var e=this.getMinZoom(),i=this.getMaxZoom(),n=Rt.any3d?this.options.zoomSnap:1;return n&&(t=Math.round(t/n)*n),Math.max(e,Math.min(i,t))},_onPanTransitionStep:function(){this.fire("move")},_onPanTransitionEnd:function(){ue(this._mapPane,"leaflet-pan-anim"),this.fire("moveend")},_tryAnimatedPan:function(t,e){var i=this._getCenterOffset(t)._trunc();return!(!0!==(e&&e.animate)&&!this.getSize().contains(i)||(this.panBy(i,e),0))},_createAnimProxy:function(){var t=this._proxy=se("div","leaflet-proxy leaflet-zoom-animated");this._panes.mapPane.appendChild(t),this.on("zoomanim",function(t){var e=Jt,i=this._proxy.style[e];pe(this._proxy,this.project(t.center,t.zoom),this.getZoomScale(t.zoom,1)),i===this._proxy.style[e]&&this._animatingZoom&&this._onZoomTransitionEnd()},this),this.on("load moveend",this._animMoveEnd,this),this._on("unload",this._destroyAnimProxy,this)},_destroyAnimProxy:function(){oe(this._proxy),this.off("load moveend",this._animMoveEnd,this),delete this._proxy},_animMoveEnd:function(){var t=this.getCenter(),e=this.getZoom();pe(this._proxy,this.project(t,e),this.getZoomScale(e,1))},_catchTransitionEnd:function(t){this._animatingZoom&&t.propertyName.indexOf("transform")>=0&&this._onZoomTransitionEnd()},_nothingToAnimate:function(){return!this._container.getElementsByClassName("leaflet-zoom-animated").length},_tryAnimatedZoom:function(t,e,i){if(this._animatingZoom)return!0;if(i=i||{},!this._zoomAnimated||!1===i.animate||this._nothingToAnimate()||Math.abs(e-this._zoom)>this.options.zoomAnimationThreshold)return!1;var n=this.getZoomScale(e),s=this._getCenterOffset(t)._divideBy(1-1/n);return!(!0!==i.animate&&!this.getSize().contains(s)||(T(function(){this._moveStart(!0,i.noMoveStart||!1)._animateZoom(t,e,!0)},this),0))},_animateZoom:function(t,e,i,s){this._mapPane&&(i&&(this._animatingZoom=!0,this._animateToCenter=t,this._animateToZoom=e,de(this._mapPane,"leaflet-zoom-anim")),this.fire("zoomanim",{center:t,zoom:e,noUpdate:s}),this._tempFireZoomEvent||(this._tempFireZoomEvent=this._zoom!==this._animateToZoom),this._move(this._animateToCenter,this._animateToZoom,void 0,!0),setTimeout(n(this._onZoomTransitionEnd,this),250))},_onZoomTransitionEnd:function(){this._animatingZoom&&(this._mapPane&&ue(this._mapPane,"leaflet-zoom-anim"),this._animatingZoom=!1,this._move(this._animateToCenter,this._animateToZoom,void 0,!0),this._tempFireZoomEvent&&this.fire("zoom"),delete this._tempFireZoomEvent,this.fire("move"),this._moveEnd(!0))}});var qe=A.extend({options:{position:"topright"},initialize:function(t){c(this,t)},getPosition:function(){return this.options.position},setPosition:function(t){var e=this._map;return e&&e.removeControl(this),this.options.position=t,e&&e.addControl(this),this},getContainer:function(){return this._container},addTo:function(t){this.remove(),this._map=t;var e=this._container=this.onAdd(t),i=this.getPosition(),n=t._controlCorners[i];return de(e,"leaflet-control"),-1!==i.indexOf("bottom")?n.insertBefore(e,n.firstChild):n.appendChild(e),this._map.on("unload",this.remove,this),this},remove:function(){return this._map?(oe(this._container),this.onRemove&&this.onRemove(this._map),this._map.off("unload",this.remove,this),this._map=null,this):this},_refocusOnMap:function(t){this._map&&t&&t.screenX>0&&t.screenY>0&&this._map.getContainer().focus()}}),Ve=function(t){return new qe(t)};Xe.include({addControl:function(t){return t.addTo(this),this},removeControl:function(t){return t.remove(),this},_initControlPos:function(){var t=this._controlCorners={},e="leaflet-",i=this._controlContainer=se("div",e+"control-container",this._container);function n(n,s){var o=e+n+" "+e+s;t[n+s]=se("div",o,i)}n("top","left"),n("top","right"),n("bottom","left"),n("bottom","right")},_clearControlPos:function(){for(var t in this._controlCorners)oe(this._controlCorners[t]);oe(this._controlContainer),delete this._controlCorners,delete this._controlContainer}});var Ye=qe.extend({options:{collapsed:!0,position:"topright",autoZIndex:!0,hideSingleBase:!1,sortLayers:!1,sortFunction:function(t,e,i,n){return i1,this._baseLayersList.style.display=t?"":"none"),this._separator.style.display=e&&t?"":"none",this},_onLayerChange:function(t){this._handlingClick||this._update();var e=this._getLayer(o(t.target)),i=e.overlay?"add"===t.type?"overlayadd":"overlayremove":"add"===t.type?"baselayerchange":null;i&&this._map.fire(i,e)},_createRadioElement:function(t,e){var i='",n=document.createElement("div");return n.innerHTML=i,n.firstChild},_addItem:function(t){var e,i=document.createElement("label"),n=this._map.hasLayer(t.layer);t.overlay?((e=document.createElement("input")).type="checkbox",e.className="leaflet-control-layers-selector",e.defaultChecked=n):e=this._createRadioElement("leaflet-base-layers_"+o(this),n),this._layerControlInputs.push(e),e.layerId=o(t.layer),Ae(e,"click",this._onInputClick,this);var s=document.createElement("span");s.innerHTML=" "+t.name;var r=document.createElement("span");return i.appendChild(r),r.appendChild(e),r.appendChild(s),(t.overlay?this._overlaysList:this._baseLayersList).appendChild(i),this._checkDisabledLayers(),i},_onInputClick:function(){if(!this._preventClick){var t,e,i=this._layerControlInputs,n=[],s=[];this._handlingClick=!0;for(var o=i.length-1;o>=0;o--)t=i[o],e=this._getLayer(t.layerId).layer,t.checked?n.push(e):t.checked||s.push(e);for(o=0;o=0;s--)t=i[s],e=this._getLayer(t.layerId).layer,t.disabled=void 0!==e.options.minZoom&&ne.options.maxZoom},_expandIfNotCollapsed:function(){return this._map&&!this.options.collapsed&&this.expand(),this},_expandSafely:function(){var t=this._section;this._preventClick=!0,Ae(t,"click",Be),this.expand();var e=this;setTimeout(function(){Me(t,"click",Be),e._preventClick=!1})}}),$e=qe.extend({options:{position:"topleft",zoomInText:'',zoomInTitle:"Zoom in",zoomOutText:'',zoomOutTitle:"Zoom out"},onAdd:function(t){var e="leaflet-control-zoom",i=se("div",e+" leaflet-bar"),n=this.options;return this._zoomInButton=this._createButton(n.zoomInText,n.zoomInTitle,e+"-in",i,this._zoomIn),this._zoomOutButton=this._createButton(n.zoomOutText,n.zoomOutTitle,e+"-out",i,this._zoomOut),this._updateDisabled(),t.on("zoomend zoomlevelschange",this._updateDisabled,this),i},onRemove:function(t){t.off("zoomend zoomlevelschange",this._updateDisabled,this)},disable:function(){return this._disabled=!0,this._updateDisabled(),this},enable:function(){return this._disabled=!1,this._updateDisabled(),this},_zoomIn:function(t){!this._disabled&&this._map._zoomthis._map.getMinZoom()&&this._map.zoomOut(this._map.options.zoomDelta*(t.shiftKey?3:1))},_createButton:function(t,e,i,n,s){var o=se("a",i,n);return o.innerHTML=t,o.href="#",o.title=e,o.setAttribute("role","button"),o.setAttribute("aria-label",e),ke(o),Ae(o,"click",ze),Ae(o,"click",s,this),Ae(o,"click",this._refocusOnMap,this),o},_updateDisabled:function(){var t=this._map,e="leaflet-disabled";ue(this._zoomInButton,e),ue(this._zoomOutButton,e),this._zoomInButton.setAttribute("aria-disabled","false"),this._zoomOutButton.setAttribute("aria-disabled","false"),(this._disabled||t._zoom===t.getMinZoom())&&(de(this._zoomOutButton,e),this._zoomOutButton.setAttribute("aria-disabled","true")),(this._disabled||t._zoom===t.getMaxZoom())&&(de(this._zoomInButton,e),this._zoomInButton.setAttribute("aria-disabled","true"))}});Xe.mergeOptions({zoomControl:!0}),Xe.addInitHook(function(){this.options.zoomControl&&(this.zoomControl=new $e,this.addControl(this.zoomControl))});var Ke=qe.extend({options:{position:"bottomleft",maxWidth:100,metric:!0,imperial:!0},onAdd:function(t){var e="leaflet-control-scale",i=se("div",e),n=this.options;return this._addScales(n,e+"-line",i),t.on(n.updateWhenIdle?"moveend":"move",this._update,this),t.whenReady(this._update,this),i},onRemove:function(t){t.off(this.options.updateWhenIdle?"moveend":"move",this._update,this)},_addScales:function(t,e,i){t.metric&&(this._mScale=se("div",e,i)),t.imperial&&(this._iScale=se("div",e,i))},_update:function(){var t=this._map,e=t.getSize().y/2,i=t.distance(t.containerPointToLatLng([0,e]),t.containerPointToLatLng([this.options.maxWidth,e]));this._updateScales(i)},_updateScales:function(t){this.options.metric&&t&&this._updateMetric(t),this.options.imperial&&t&&this._updateImperial(t)},_updateMetric:function(t){var e=this._getRoundNum(t),i=e<1e3?e+" m":e/1e3+" km";this._updateScale(this._mScale,i,e/t)},_updateImperial:function(t){var e,i,n,s=3.2808399*t;s>5280?(e=s/5280,i=this._getRoundNum(e),this._updateScale(this._iScale,i+" mi",i/e)):(n=this._getRoundNum(s),this._updateScale(this._iScale,n+" ft",n/s))},_updateScale:function(t,e,i){t.style.width=Math.round(this.options.maxWidth*i)+"px",t.innerHTML=e},_getRoundNum:function(t){var e=Math.pow(10,(Math.floor(t)+"").length-1),i=t/e;return e*(i>=10?10:i>=5?5:i>=3?3:i>=2?2:1)}}),Qe=qe.extend({options:{position:"bottomright",prefix:''+(Rt.inlineSvg?' ':"")+"Leaflet"},initialize:function(t){c(this,t),this._attributions={}},onAdd:function(t){for(var e in t.attributionControl=this,this._container=se("div","leaflet-control-attribution"),ke(this._container),t._layers)t._layers[e].getAttribution&&this.addAttribution(t._layers[e].getAttribution());return this._update(),t.on("layeradd",this._addAttribution,this),this._container},onRemove:function(t){t.off("layeradd",this._addAttribution,this)},_addAttribution:function(t){t.layer.getAttribution&&(this.addAttribution(t.layer.getAttribution()),t.layer.once("remove",function(){this.removeAttribution(t.layer.getAttribution())},this))},setPrefix:function(t){return this.options.prefix=t,this._update(),this},addAttribution:function(t){return t?(this._attributions[t]||(this._attributions[t]=0),this._attributions[t]++,this._update(),this):this},removeAttribution:function(t){return t?(this._attributions[t]&&(this._attributions[t]--,this._update()),this):this},_update:function(){if(this._map){var t=[];for(var e in this._attributions)this._attributions[e]&&t.push(e);var i=[];this.options.prefix&&i.push(this.options.prefix),t.length&&i.push(t.join(", ")),this._container.innerHTML=i.join(' ')}}});Xe.mergeOptions({attributionControl:!0}),Xe.addInitHook(function(){this.options.attributionControl&&(new Qe).addTo(this)});qe.Layers=Ye,qe.Zoom=$e,qe.Scale=Ke,qe.Attribution=Qe,Ve.layers=function(t,e,i){return new Ye(t,e,i)},Ve.zoom=function(t){return new $e(t)},Ve.scale=function(t){return new Ke(t)},Ve.attribution=function(t){return new Qe(t)};var Je=A.extend({initialize:function(t){this._map=t},enable:function(){return this._enabled||(this._enabled=!0,this.addHooks()),this},disable:function(){return this._enabled?(this._enabled=!1,this.removeHooks(),this):this},enabled:function(){return!!this._enabled}});Je.addTo=function(t,e){return t.addHandler(e,this),this};var ti={Events:C},ei=Rt.touch?"touchstart mousedown":"mousedown",ii=M.extend({options:{clickTolerance:3},initialize:function(t,e,i,n){c(this,n),this._element=t,this._dragStartTarget=e||t,this._preventOutline=i},enable:function(){this._enabled||(Ae(this._dragStartTarget,ei,this._onDown,this),this._enabled=!0)},disable:function(){this._enabled&&(ii._dragging===this&&this.finishDrag(!0),Me(this._dragStartTarget,ei,this._onDown,this),this._enabled=!1,this._moved=!1)},_onDown:function(t){if(this._enabled&&(this._moved=!1,!le(this._element,"leaflet-zoom-anim")))if(t.touches&&1!==t.touches.length)ii._dragging===this&&this.finishDrag();else if(!(ii._dragging||t.shiftKey||1!==t.which&&1!==t.button&&!t.touches||(ii._dragging=this,this._preventOutline&&Se(this._element),xe(),Vt(),this._moving))){this.fire("down");var e=t.touches?t.touches[0]:t,i=Te(this._element);this._startPoint=new N(e.clientX,e.clientY),this._startPos=ve(this._element),this._parentScale=Ee(i);var n="mousedown"===t.type;Ae(document,n?"mousemove":"touchmove",this._onMove,this),Ae(document,n?"mouseup":"touchend touchcancel",this._onUp,this)}},_onMove:function(t){if(this._enabled)if(t.touches&&t.touches.length>1)this._moved=!0;else{var e=t.touches&&1===t.touches.length?t.touches[0]:t,i=new N(e.clientX,e.clientY)._subtract(this._startPoint);(i.x||i.y)&&(Math.abs(i.x)+Math.abs(i.y)e&&(i.push(t[n]),s=n);return sh&&(o=r,h=a);h>i&&(e[o]=1,di(t,e,i,n,o),di(t,e,i,o,s))}function ui(t,e,i,n,s){var o,r,a,h=n?ri:_i(t,i),l=_i(e,i);for(ri=l;;){if(!(h|l))return[t,e];if(h&l)return!1;a=_i(r=ci(t,e,o=h||l,i,s),i),o===h?(t=r,h=a):(e=r,l=a)}}function ci(t,e,i,n,s){var o,r,a=e.x-t.x,h=e.y-t.y,l=n.min,d=n.max;return 8&i?(o=t.x+a*(d.y-t.y)/h,r=d.y):4&i?(o=t.x+a*(l.y-t.y)/h,r=l.y):2&i?(o=d.x,r=t.y+h*(d.x-t.x)/a):1&i&&(o=l.x,r=t.y+h*(l.x-t.x)/a),new N(o,r,s)}function _i(t,e){var i=0;return t.xe.max.x&&(i|=2),t.ye.max.y&&(i|=8),i}function fi(t,e){var i=e.x-t.x,n=e.y-t.y;return i*i+n*n}function gi(t,e,i,n){var s,o=e.x,r=e.y,a=i.x-o,h=i.y-r,l=a*a+h*h;return l>0&&((s=((t.x-o)*a+(t.y-r)*h)/l)>1?(o=i.x,r=i.y):s>0&&(o+=a*s,r+=h*s)),a=t.x-o,h=t.y-r,n?a*a+h*h:new N(o,r)}function pi(t){return!p(t[0])||"object"!=typeof t[0][0]&&void 0!==t[0][0]}function mi(t){return console.warn("Deprecated use of _flat, please use L.LineUtil.isFlat instead."),pi(t)}function vi(t,e){var i,n,s,o,r,a,h,l;if(!t||0===t.length)throw new Error("latlngs not passed");pi(t)||(console.warn("latlngs are not flat! Only the first ring will be used"),t=t[0]);var d=U([0,0]),u=B(t);u.getNorthWest().distanceTo(u.getSouthWest())*u.getNorthEast().distanceTo(u.getNorthWest())<1700&&(d=oi(t));var c=t.length,_=[];for(i=0;in){h=(o-n)/s,l=[a.x-h*(a.x-r.x),a.y-h*(a.y-r.y)];break}var g=e.unproject(I(l));return U([g.lat+d.lat,g.lng+d.lng])}var yi={__proto__:null,simplify:hi,pointToSegmentDistance:li,closestPointOnSegment:function(t,e,i){return gi(t,e,i)},clipSegment:ui,_getEdgeIntersection:ci,_getBitCode:_i,_sqClosestPointOnSegment:gi,isFlat:pi,_flat:mi,polylineCenter:vi},xi={project:function(t){return new N(t.lng,t.lat)},unproject:function(t){return new z(t.y,t.x)},bounds:new R([-180,-90],[180,90])},bi={R:6378137,R_MINOR:6356752.314245179,bounds:new R([-20037508.34279,-15496570.73972],[20037508.34279,18764656.23138]),project:function(t){var e=Math.PI/180,i=this.R,n=t.lat*e,s=this.R_MINOR/i,o=Math.sqrt(1-s*s),r=o*Math.sin(n),a=Math.tan(Math.PI/4-n/2)/Math.pow((1-r)/(1+r),o/2);return n=-i*Math.log(Math.max(a,1e-10)),new N(t.lng*e*i,n)},unproject:function(t){for(var e,i=180/Math.PI,n=this.R,s=this.R_MINOR/n,o=Math.sqrt(1-s*s),r=Math.exp(-t.y/n),a=Math.PI/2-2*Math.atan(r),h=0,l=.1;h<15&&Math.abs(l)>1e-7;h++)e=o*Math.sin(a),e=Math.pow((1-e)/(1+e),o/2),a+=l=Math.PI/2-2*Math.atan(r*e)-a;return new z(a*i,t.x*i/n)}},Si={__proto__:null,LonLat:xi,Mercator:bi,SphericalMercator:G},wi=e({},W,{code:"EPSG:3395",projection:bi,transformation:function(){var t=.5/(Math.PI*bi.R);return X(t,.5,-t,.5)}()}),Ti=e({},W,{code:"EPSG:4326",projection:xi,transformation:X(1/180,1,-1/180,.5)}),Ei=e({},j,{projection:xi,transformation:X(1,0,-1,0),scale:function(t){return Math.pow(2,t)},zoom:function(t){return Math.log(t)/Math.LN2},distance:function(t,e){var i=e.lng-t.lng,n=e.lat-t.lat;return Math.sqrt(i*i+n*n)},infinite:!0});j.Earth=W,j.EPSG3395=wi,j.EPSG3857=q,j.EPSG900913=V,j.EPSG4326=Ti,j.Simple=Ei;var Pi=M.extend({options:{pane:"overlayPane",attribution:null,bubblingMouseEvents:!0},addTo:function(t){return t.addLayer(this),this},remove:function(){return this.removeFrom(this._map||this._mapToAdd)},removeFrom:function(t){return t&&t.removeLayer(this),this},getPane:function(t){return this._map.getPane(t?this.options[t]||t:this.options.pane)},addInteractiveTarget:function(t){return this._map._targets[o(t)]=this,this},removeInteractiveTarget:function(t){return delete this._map._targets[o(t)],this},getAttribution:function(){return this.options.attribution},_layerAdd:function(t){var e=t.target;if(e.hasLayer(this)){if(this._map=e,this._zoomAnimated=e._zoomAnimated,this.getEvents){var i=this.getEvents();e.on(i,this),this.once("remove",function(){e.off(i,this)},this)}this.onAdd(e),this.fire("add"),e.fire("layeradd",{layer:this})}}});Xe.include({addLayer:function(t){if(!t._layerAdd)throw new Error("The provided object is not a Layer.");var e=o(t);return this._layers[e]||(this._layers[e]=t,t._mapToAdd=this,t.beforeAdd&&t.beforeAdd(this),this.whenReady(t._layerAdd,t)),this},removeLayer:function(t){var e=o(t);return this._layers[e]?(this._loaded&&t.onRemove(this),delete this._layers[e],this._loaded&&(this.fire("layerremove",{layer:t}),t.fire("remove")),t._map=t._mapToAdd=null,this):this},hasLayer:function(t){return o(t)in this._layers},eachLayer:function(t,e){for(var i in this._layers)t.call(e,this._layers[i]);return this},_addLayers:function(t){for(var e=0,i=(t=t?p(t)?t:[t]:[]).length;ethis._layersMaxZoom&&this.setZoom(this._layersMaxZoom),void 0===this.options.minZoom&&this._layersMinZoom&&this.getZoom()=2&&e[0]instanceof z&&e[0].equals(e[i-1])&&e.pop(),e},_setLatLngs:function(t){ki.prototype._setLatLngs.call(this,t),pi(this._latlngs)&&(this._latlngs=[this._latlngs])},_defaultShape:function(){return pi(this._latlngs[0])?this._latlngs[0]:this._latlngs[0][0]},_clipPoints:function(){var t=this._renderer._bounds,e=this.options.weight,i=new N(e,e);if(t=new R(t.min.subtract(i),t.max.add(i)),this._parts=[],this._pxBounds&&this._pxBounds.intersects(t))if(this.options.noClip)this._parts=this._rings;else for(var n,s=0,o=this._rings.length;st.y!=n.y>t.y&&t.x<(n.x-i.x)*(t.y-i.y)/(n.y-i.y)+i.x&&(l=!l);return l||ki.prototype._containsPoint.call(this,t,!0)}});var zi=Ci.extend({initialize:function(t,e){c(this,e),this._layers={},t&&this.addData(t)},addData:function(t){var e,i,n,s=p(t)?t:t.features;if(s){for(e=0,i=s.length;e0&&s.push(s[0].slice()),s}function Hi(t,i){return t.feature?e({},t.feature,{geometry:i}):Xi(i)}function Xi(t){return"Feature"===t.type||"FeatureCollection"===t.type?t:{type:"Feature",properties:{},geometry:t}}var qi={toGeoJSON:function(t){return Hi(this,{type:"Point",coordinates:Zi(this.getLatLng(),t)})}};function Vi(t,e){return new zi(t,e)}Ii.include(qi),Oi.include(qi),Ri.include(qi),ki.include({toGeoJSON:function(t){var e=!pi(this._latlngs);return Hi(this,{type:(e?"Multi":"")+"LineString",coordinates:Gi(this._latlngs,e?1:0,!1,t)})}}),Bi.include({toGeoJSON:function(t){var e=!pi(this._latlngs),i=e&&!pi(this._latlngs[0]),n=Gi(this._latlngs,i?2:e?1:0,!0,t);return e||(n=[n]),Hi(this,{type:(i?"Multi":"")+"Polygon",coordinates:n})}}),Ai.include({toMultiPoint:function(t){var e=[];return this.eachLayer(function(i){e.push(i.toGeoJSON(t).geometry.coordinates)}),Hi(this,{type:"MultiPoint",coordinates:e})},toGeoJSON:function(t){var e=this.feature&&this.feature.geometry&&this.feature.geometry.type;if("MultiPoint"===e)return this.toMultiPoint(t);var i="GeometryCollection"===e,n=[];return this.eachLayer(function(e){if(e.toGeoJSON){var s=e.toGeoJSON(t);if(i)n.push(s.geometry);else{var o=Xi(s);"FeatureCollection"===o.type?n.push.apply(n,o.features):n.push(o)}}}),i?Hi(this,{geometries:n,type:"GeometryCollection"}):{type:"FeatureCollection",features:n}}});var Yi=Vi,$i=Pi.extend({options:{opacity:1,alt:"",interactive:!1,crossOrigin:!1,errorOverlayUrl:"",zIndex:1,className:""},initialize:function(t,e,i){this._url=t,this._bounds=B(e),c(this,i)},onAdd:function(){this._image||(this._initImage(),this.options.opacity<1&&this._updateOpacity()),this.options.interactive&&(de(this._image,"leaflet-interactive"),this.addInteractiveTarget(this._image)),this.getPane().appendChild(this._image),this._reset()},onRemove:function(){oe(this._image),this.options.interactive&&this.removeInteractiveTarget(this._image)},setOpacity:function(t){return this.options.opacity=t,this._image&&this._updateOpacity(),this},setStyle:function(t){return t.opacity&&this.setOpacity(t.opacity),this},bringToFront:function(){return this._map&&ae(this._image),this},bringToBack:function(){return this._map&&he(this._image),this},setUrl:function(t){return this._url=t,this._image&&(this._image.src=t),this},setBounds:function(t){return this._bounds=B(t),this._map&&this._reset(),this},getEvents:function(){var t={zoom:this._reset,viewreset:this._reset};return this._zoomAnimated&&(t.zoomanim=this._animateZoom),t},setZIndex:function(t){return this.options.zIndex=t,this._updateZIndex(),this},getBounds:function(){return this._bounds},getElement:function(){return this._image},_initImage:function(){var t="IMG"===this._url.tagName,e=this._image=t?this._url:se("img");de(e,"leaflet-image-layer"),this._zoomAnimated&&de(e,"leaflet-zoom-animated"),this.options.className&&de(e,this.options.className),e.onselectstart=h,e.onmousemove=h,e.onload=n(this.fire,this,"load"),e.onerror=n(this._overlayOnError,this,"error"),(this.options.crossOrigin||""===this.options.crossOrigin)&&(e.crossOrigin=!0===this.options.crossOrigin?"":this.options.crossOrigin),this.options.zIndex&&this._updateZIndex(),t?this._url=e.src:(e.src=this._url,e.alt=this.options.alt)},_animateZoom:function(t){var e=this._map.getZoomScale(t.zoom),i=this._map._latLngBoundsToNewLayerBounds(this._bounds,t.zoom,t.center).min;pe(this._image,i,e)},_reset:function(){var t=this._image,e=new R(this._map.latLngToLayerPoint(this._bounds.getNorthWest()),this._map.latLngToLayerPoint(this._bounds.getSouthEast())),i=e.getSize();me(t,e.min),t.style.width=i.x+"px",t.style.height=i.y+"px"},_updateOpacity:function(){fe(this._image,this.options.opacity)},_updateZIndex:function(){this._image&&void 0!==this.options.zIndex&&null!==this.options.zIndex&&(this._image.style.zIndex=this.options.zIndex)},_overlayOnError:function(){this.fire("error");var t=this.options.errorOverlayUrl;t&&this._url!==t&&(this._url=t,this._image.src=t)},getCenter:function(){return this._bounds.getCenter()}}),Ki=$i.extend({options:{autoplay:!0,loop:!0,keepAspectRatio:!0,muted:!1,playsInline:!0},_initImage:function(){var t="VIDEO"===this._url.tagName,e=this._image=t?this._url:se("video");if(de(e,"leaflet-image-layer"),this._zoomAnimated&&de(e,"leaflet-zoom-animated"),this.options.className&&de(e,this.options.className),e.onselectstart=h,e.onmousemove=h,e.onloadeddata=n(this.fire,this,"load"),t){for(var i=e.getElementsByTagName("source"),s=[],o=0;o0?s:[e.src]}else{p(this._url)||(this._url=[this._url]),!this.options.keepAspectRatio&&Object.prototype.hasOwnProperty.call(e.style,"objectFit")&&(e.style.objectFit="fill"),e.autoplay=!!this.options.autoplay,e.loop=!!this.options.loop,e.muted=!!this.options.muted,e.playsInline=!!this.options.playsInline;for(var r=0;rs?(e.height=s+"px",de(t,o)):ue(t,o),this._containerWidth=this._container.offsetWidth},_animateZoom:function(t){var e=this._map._latLngToNewLayerPoint(this._latlng,t.zoom,t.center),i=this._getAnchor();me(this._container,e.add(i))},_adjustPan:function(){if(this.options.autoPan)if(this._map._panAnim&&this._map._panAnim.stop(),this._autopanning)this._autopanning=!1;else{var t=this._map,e=parseInt(ne(this._container,"marginBottom"),10)||0,i=this._container.offsetHeight+e,n=this._containerWidth,s=new N(this._containerLeft,-i-this._containerBottom);s._add(ve(this._container));var o=t.layerPointToContainerPoint(s),r=I(this.options.autoPanPadding),a=I(this.options.autoPanPaddingTopLeft||r),h=I(this.options.autoPanPaddingBottomRight||r),l=t.getSize(),d=0,u=0;o.x+n+h.x>l.x&&(d=o.x+n-l.x+h.x),o.x-d-a.x<0&&(d=o.x-a.x),o.y+i+h.y>l.y&&(u=o.y+i-l.y+h.y),o.y-u-a.y<0&&(u=o.y-a.y),(d||u)&&(this.options.keepInView&&(this._autopanning=!0),t.fire("autopanstart").panBy([d,u]))}},_getAnchor:function(){return I(this._source&&this._source._getPopupAnchor?this._source._getPopupAnchor():[0,0])}});Xe.mergeOptions({closePopupOnClick:!0}),Xe.include({openPopup:function(t,e,i){return this._initOverlay(tn,t,e,i).openOn(this),this},closePopup:function(t){return(t=arguments.length?t:this._popup)&&t.close(),this}}),Pi.include({bindPopup:function(t,e){return this._popup=this._initOverlay(tn,this._popup,t,e),this._popupHandlersAdded||(this.on({click:this._openPopup,keypress:this._onKeyPress,remove:this.closePopup,move:this._movePopup}),this._popupHandlersAdded=!0),this},unbindPopup:function(){return this._popup&&(this.off({click:this._openPopup,keypress:this._onKeyPress,remove:this.closePopup,move:this._movePopup}),this._popupHandlersAdded=!1,this._popup=null),this},openPopup:function(t){return this._popup&&(this instanceof Ci||(this._popup._source=this),this._popup._prepareOpen(t||this._latlng)&&this._popup.openOn(this._map)),this},closePopup:function(){return this._popup&&this._popup.close(),this},togglePopup:function(){return this._popup&&this._popup.toggle(this),this},isPopupOpen:function(){return!!this._popup&&this._popup.isOpen()},setPopupContent:function(t){return this._popup&&this._popup.setContent(t),this},getPopup:function(){return this._popup},_openPopup:function(t){if(this._popup&&this._map){ze(t);var e=t.layer||t.target;this._popup._source!==e||e instanceof Li?(this._popup._source=e,this.openPopup(t.latlng)):this._map.hasLayer(this._popup)?this.closePopup():this.openPopup(t.latlng)}},_movePopup:function(t){this._popup.setLatLng(t.latlng)},_onKeyPress:function(t){13===t.originalEvent.keyCode&&this._openPopup(t)}});var en=Ji.extend({options:{pane:"tooltipPane",offset:[0,0],direction:"auto",permanent:!1,sticky:!1,opacity:.9},onAdd:function(t){Ji.prototype.onAdd.call(this,t),this.setOpacity(this.options.opacity),t.fire("tooltipopen",{tooltip:this}),this._source&&(this.addEventParent(this._source),this._source.fire("tooltipopen",{tooltip:this},!0))},onRemove:function(t){Ji.prototype.onRemove.call(this,t),t.fire("tooltipclose",{tooltip:this}),this._source&&(this.removeEventParent(this._source),this._source.fire("tooltipclose",{tooltip:this},!0))},getEvents:function(){var t=Ji.prototype.getEvents.call(this);return this.options.permanent||(t.preclick=this.close),t},_initLayout:function(){var t="leaflet-tooltip "+(this.options.className||"")+" leaflet-zoom-"+(this._zoomAnimated?"animated":"hide");this._contentNode=this._container=se("div",t),this._container.setAttribute("role","tooltip"),this._container.setAttribute("id","leaflet-tooltip-"+o(this))},_updateLayout:function(){},_adjustPan:function(){},_setPosition:function(t){var e,i,n=this._map,s=this._container,o=n.latLngToContainerPoint(n.getCenter()),r=n.layerPointToContainerPoint(t),a=this.options.direction,h=s.offsetWidth,l=s.offsetHeight,d=I(this.options.offset),u=this._getAnchor();"top"===a?(e=h/2,i=l):"bottom"===a?(e=h/2,i=0):"center"===a?(e=h/2,i=l/2):"right"===a?(e=0,i=l/2):"left"===a?(e=h,i=l/2):r.xthis.options.maxZoom||in&&this._retainParent(s,o,r,n))},_retainChildren:function(t,e,i,n){for(var s=2*t;s<2*t+2;s++)for(var o=2*e;o<2*e+2;o++){var r=new N(s,o);r.z=i+1;var a=this._tileCoordsToKey(r),h=this._tiles[a];h&&h.active?h.retain=!0:(h&&h.loaded&&(h.retain=!0),i+1this.options.maxZoom||void 0!==this.options.minZoom&&s1)this._setView(t,i);else{for(var u=s.min.y;u<=s.max.y;u++)for(var c=s.min.x;c<=s.max.x;c++){var _=new N(c,u);if(_.z=this._tileZoom,this._isValidTile(_)){var f=this._tiles[this._tileCoordsToKey(_)];f?f.current=!0:r.push(_)}}if(r.sort(function(t,e){return t.distanceTo(o)-e.distanceTo(o)}),0!==r.length){this._loading||(this._loading=!0,this.fire("loading"));var g=document.createDocumentFragment();for(c=0;ci.max.x)||!e.wrapLat&&(t.yi.max.y))return!1}if(!this.options.bounds)return!0;var n=this._tileCoordsToBounds(t);return B(this.options.bounds).overlaps(n)},_keyToBounds:function(t){return this._tileCoordsToBounds(this._keyToTileCoords(t))},_tileCoordsToNwSe:function(t){var e=this._map,i=this.getTileSize(),n=t.scaleBy(i),s=n.add(i);return[e.unproject(n,t.z),e.unproject(s,t.z)]},_tileCoordsToBounds:function(t){var e=this._tileCoordsToNwSe(t),i=new k(e[0],e[1]);return this.options.noWrap||(i=this._map.wrapLatLngBounds(i)),i},_tileCoordsToKey:function(t){return t.x+":"+t.y+":"+t.z},_keyToTileCoords:function(t){var e=t.split(":"),i=new N(+e[0],+e[1]);return i.z=+e[2],i},_removeTile:function(t){var e=this._tiles[t];e&&(oe(e.el),delete this._tiles[t],this.fire("tileunload",{tile:e.el,coords:this._keyToTileCoords(t)}))},_initTile:function(t){de(t,"leaflet-tile");var e=this.getTileSize();t.style.width=e.x+"px",t.style.height=e.y+"px",t.onselectstart=h,t.onmousemove=h,Rt.ielt9&&this.options.opacity<1&&fe(t,this.options.opacity)},_addTile:function(t,e){var i=this._getTilePos(t),s=this._tileCoordsToKey(t),o=this.createTile(this._wrapCoords(t),n(this._tileReady,this,t));this._initTile(o),this.createTile.length<2&&T(n(this._tileReady,this,t,null,o)),me(o,i),this._tiles[s]={el:o,coords:t,current:!0},e.appendChild(o),this.fire("tileloadstart",{tile:o,coords:t})},_tileReady:function(t,e,i){e&&this.fire("tileerror",{error:e,tile:i,coords:t});var s=this._tileCoordsToKey(t);(i=this._tiles[s])&&(i.loaded=+new Date,this._map._fadeAnimated?(fe(i.el,0),E(this._fadeFrame),this._fadeFrame=T(this._updateOpacity,this)):(i.active=!0,this._pruneTiles()),e||(de(i.el,"leaflet-tile-loaded"),this.fire("tileload",{tile:i.el,coords:t})),this._noTilesToLoad()&&(this._loading=!1,this.fire("load"),Rt.ielt9||!this._map._fadeAnimated?T(this._pruneTiles,this):setTimeout(n(this._pruneTiles,this),250)))},_getTilePos:function(t){return t.scaleBy(this.getTileSize()).subtract(this._level.origin)},_wrapCoords:function(t){var e=new N(this._wrapX?a(t.x,this._wrapX):t.x,this._wrapY?a(t.y,this._wrapY):t.y);return e.z=t.z,e},_pxBoundsToTileRange:function(t){var e=this.getTileSize();return new R(t.min.unscaleBy(e).floor(),t.max.unscaleBy(e).ceil().subtract([1,1]))},_noTilesToLoad:function(){for(var t in this._tiles)if(!this._tiles[t].loaded)return!1;return!0}});var on=sn.extend({options:{minZoom:0,maxZoom:18,subdomains:"abc",errorTileUrl:"",zoomOffset:0,tms:!1,zoomReverse:!1,detectRetina:!1,crossOrigin:!1,referrerPolicy:!1},initialize:function(t,e){this._url=t,(e=c(this,e)).detectRetina&&Rt.retina&&e.maxZoom>0?(e.tileSize=Math.floor(e.tileSize/2),e.zoomReverse?(e.zoomOffset--,e.minZoom=Math.min(e.maxZoom,e.minZoom+1)):(e.zoomOffset++,e.maxZoom=Math.max(e.minZoom,e.maxZoom-1)),e.minZoom=Math.max(0,e.minZoom)):e.zoomReverse?e.minZoom=Math.min(e.maxZoom,e.minZoom):e.maxZoom=Math.max(e.minZoom,e.maxZoom),"string"==typeof e.subdomains&&(e.subdomains=e.subdomains.split("")),this.on("tileunload",this._onTileRemove)},setUrl:function(t,e){return this._url===t&&void 0===e&&(e=!0),this._url=t,e||this.redraw(),this},createTile:function(t,e){var i=document.createElement("img");return Ae(i,"load",n(this._tileOnLoad,this,e,i)),Ae(i,"error",n(this._tileOnError,this,e,i)),(this.options.crossOrigin||""===this.options.crossOrigin)&&(i.crossOrigin=!0===this.options.crossOrigin?"":this.options.crossOrigin),"string"==typeof this.options.referrerPolicy&&(i.referrerPolicy=this.options.referrerPolicy),i.alt="",i.src=this.getTileUrl(t),i},getTileUrl:function(t){var i={r:Rt.retina?"@2x":"",s:this._getSubdomain(t),x:t.x,y:t.y,z:this._getZoomForUrl()};if(this._map&&!this._map.options.crs.infinite){var n=this._globalTileRange.max.y-t.y;this.options.tms&&(i.y=n),i["-y"]=n}return g(this._url,e(i,this.options))},_tileOnLoad:function(t,e){Rt.ielt9?setTimeout(n(t,this,null,e),0):t(null,e)},_tileOnError:function(t,e,i){var n=this.options.errorTileUrl;n&&e.getAttribute("src")!==n&&(e.src=n),t(i,e)},_onTileRemove:function(t){t.tile.onload=null},_getZoomForUrl:function(){var t=this._tileZoom,e=this.options.maxZoom;return this.options.zoomReverse&&(t=e-t),t+this.options.zoomOffset},_getSubdomain:function(t){var e=Math.abs(t.x+t.y)%this.options.subdomains.length;return this.options.subdomains[e]},_abortLoading:function(){var t,e;for(t in this._tiles)if(this._tiles[t].coords.z!==this._tileZoom&&((e=this._tiles[t].el).onload=h,e.onerror=h,!e.complete)){e.src=v;var i=this._tiles[t].coords;oe(e),delete this._tiles[t],this.fire("tileabort",{tile:e,coords:i})}},_removeTile:function(t){var e=this._tiles[t];if(e)return e.el.setAttribute("src",v),sn.prototype._removeTile.call(this,t)},_tileReady:function(t,e,i){if(this._map&&(!i||i.getAttribute("src")!==v))return sn.prototype._tileReady.call(this,t,e,i)}});function rn(t,e){return new on(t,e)}var an=on.extend({defaultWmsParams:{service:"WMS",request:"GetMap",layers:"",styles:"",format:"image/jpeg",transparent:!1,version:"1.1.1"},options:{crs:null,uppercase:!1},initialize:function(t,i){this._url=t;var n=e({},this.defaultWmsParams);for(var s in i)s in this.options||(n[s]=i[s]);var o=(i=c(this,i)).detectRetina&&Rt.retina?2:1,r=this.getTileSize();n.width=r.x*o,n.height=r.y*o,this.wmsParams=n},onAdd:function(t){this._crs=this.options.crs||t.options.crs,this._wmsVersion=parseFloat(this.wmsParams.version);var e=this._wmsVersion>=1.3?"crs":"srs";this.wmsParams[e]=this._crs.code,on.prototype.onAdd.call(this,t)},getTileUrl:function(t){var e=this._tileCoordsToNwSe(t),i=this._crs,n=O(i.project(e[0]),i.project(e[1])),s=n.min,o=n.max,r=(this._wmsVersion>=1.3&&this._crs===Ti?[s.y,s.x,o.y,o.x]:[s.x,s.y,o.x,o.y]).join(","),a=on.prototype.getTileUrl.call(this,t);return a+_(this.wmsParams,a,this.options.uppercase)+(this.options.uppercase?"&BBOX=":"&bbox=")+r},setParams:function(t,i){return e(this.wmsParams,t),i||this.redraw(),this}});on.WMS=an,rn.wms=function(t,e){return new an(t,e)};var hn=Pi.extend({options:{padding:.1},initialize:function(t){c(this,t),o(this),this._layers=this._layers||{}},onAdd:function(){this._container||(this._initContainer(),de(this._container,"leaflet-zoom-animated")),this.getPane().appendChild(this._container),this._update(),this.on("update",this._updatePaths,this)},onRemove:function(){this.off("update",this._updatePaths,this),this._destroyContainer()},getEvents:function(){var t={viewreset:this._reset,zoom:this._onZoom,moveend:this._update,zoomend:this._onZoomEnd};return this._zoomAnimated&&(t.zoomanim=this._onAnimZoom),t},_onAnimZoom:function(t){this._updateTransform(t.center,t.zoom)},_onZoom:function(){this._updateTransform(this._map.getCenter(),this._map.getZoom())},_updateTransform:function(t,e){var i=this._map.getZoomScale(e,this._zoom),n=this._map.getSize().multiplyBy(.5+this.options.padding),s=this._map.project(this._center,e),o=n.multiplyBy(-i).add(s).subtract(this._map._getNewPixelOrigin(t,e));Rt.any3d?pe(this._container,o,i):me(this._container,o)},_reset:function(){for(var t in this._update(),this._updateTransform(this._center,this._zoom),this._layers)this._layers[t]._reset()},_onZoomEnd:function(){for(var t in this._layers)this._layers[t]._project()},_updatePaths:function(){for(var t in this._layers)this._layers[t]._update()},_update:function(){var t=this.options.padding,e=this._map.getSize(),i=this._map.containerPointToLayerPoint(e.multiplyBy(-t)).round();this._bounds=new R(i,i.add(e.multiplyBy(1+2*t)).round()),this._center=this._map.getCenter(),this._zoom=this._map.getZoom()}}),ln=hn.extend({options:{tolerance:0},getEvents:function(){var t=hn.prototype.getEvents.call(this);return t.viewprereset=this._onViewPreReset,t},_onViewPreReset:function(){this._postponeUpdatePaths=!0},onAdd:function(){hn.prototype.onAdd.call(this),this._draw()},_initContainer:function(){var t=this._container=document.createElement("canvas");Ae(t,"mousemove",this._onMouseMove,this),Ae(t,"click dblclick mousedown mouseup contextmenu",this._onClick,this),Ae(t,"mouseout",this._handleMouseOut,this),t._leaflet_disable_events=!0,this._ctx=t.getContext("2d")},_destroyContainer:function(){E(this._redrawRequest),delete this._ctx,oe(this._container),Me(this._container),delete this._container},_updatePaths:function(){if(!this._postponeUpdatePaths){for(var t in this._redrawBounds=null,this._layers)this._layers[t]._update();this._redraw()}},_update:function(){if(!this._map._animatingZoom||!this._bounds){hn.prototype._update.call(this);var t=this._bounds,e=this._container,i=t.getSize(),n=Rt.retina?2:1;me(e,t.min),e.width=n*i.x,e.height=n*i.y,e.style.width=i.x+"px",e.style.height=i.y+"px",Rt.retina&&this._ctx.scale(2,2),this._ctx.translate(-t.min.x,-t.min.y),this.fire("update")}},_reset:function(){hn.prototype._reset.call(this),this._postponeUpdatePaths&&(this._postponeUpdatePaths=!1,this._updatePaths())},_initPath:function(t){this._updateDashArray(t),this._layers[o(t)]=t;var e=t._order={layer:t,prev:this._drawLast,next:null};this._drawLast&&(this._drawLast.next=e),this._drawLast=e,this._drawFirst=this._drawFirst||this._drawLast},_addPath:function(t){this._requestRedraw(t)},_removePath:function(t){var e=t._order,i=e.next,n=e.prev;i?i.prev=n:this._drawLast=n,n?n.next=i:this._drawFirst=i,delete t._order,delete this._layers[o(t)],this._requestRedraw(t)},_updatePath:function(t){this._extendRedrawBounds(t),t._project(),t._update(),this._requestRedraw(t)},_updateStyle:function(t){this._updateDashArray(t),this._requestRedraw(t)},_updateDashArray:function(t){if("string"==typeof t.options.dashArray){var e,i,n=t.options.dashArray.split(/[, ]+/),s=[];for(i=0;i')}}catch(t){}return function(t){return document.createElement("<"+t+' xmlns="urn:schemas-microsoft.com:vml" class="lvml">')}}(),cn={_initContainer:function(){this._container=se("div","leaflet-vml-container")},_update:function(){this._map._animatingZoom||(hn.prototype._update.call(this),this.fire("update"))},_initPath:function(t){var e=t._container=un("shape");de(e,"leaflet-vml-shape "+(this.options.className||"")),e.coordsize="1 1",t._path=un("path"),e.appendChild(t._path),this._updateStyle(t),this._layers[o(t)]=t},_addPath:function(t){var e=t._container;this._container.appendChild(e),t.options.interactive&&t.addInteractiveTarget(e)},_removePath:function(t){var e=t._container;oe(e),t.removeInteractiveTarget(e),delete this._layers[o(t)]},_updateStyle:function(t){var e=t._stroke,i=t._fill,n=t.options,s=t._container;s.stroked=!!n.stroke,s.filled=!!n.fill,n.stroke?(e||(e=t._stroke=un("stroke")),s.appendChild(e),e.weight=n.weight+"px",e.color=n.color,e.opacity=n.opacity,n.dashArray?e.dashStyle=p(n.dashArray)?n.dashArray.join(" "):n.dashArray.replace(/( *, *)/g," "):e.dashStyle="",e.endcap=n.lineCap.replace("butt","flat"),e.joinstyle=n.lineJoin):e&&(s.removeChild(e),t._stroke=null),n.fill?(i||(i=t._fill=un("fill")),s.appendChild(i),i.color=n.fillColor||n.color,i.opacity=n.fillOpacity):i&&(s.removeChild(i),t._fill=null)},_updateCircle:function(t){var e=t._point.round(),i=Math.round(t._radius),n=Math.round(t._radiusY||i);this._setPath(t,t._empty()?"M0 0":"AL "+e.x+","+e.y+" "+i+","+n+" 0,23592600")},_setPath:function(t,e){t._path.v=e},_bringToFront:function(t){ae(t._container)},_bringToBack:function(t){he(t._container)}},_n=Rt.vml?un:Y,fn=hn.extend({_initContainer:function(){this._container=_n("svg"),this._container.setAttribute("pointer-events","none"),this._rootGroup=_n("g"),this._container.appendChild(this._rootGroup)},_destroyContainer:function(){oe(this._container),Me(this._container),delete this._container,delete this._rootGroup,delete this._svgSize},_update:function(){if(!this._map._animatingZoom||!this._bounds){hn.prototype._update.call(this);var t=this._bounds,e=t.getSize(),i=this._container;this._svgSize&&this._svgSize.equals(e)||(this._svgSize=e,i.setAttribute("width",e.x),i.setAttribute("height",e.y)),me(i,t.min),i.setAttribute("viewBox",[t.min.x,t.min.y,e.x,e.y].join(" ")),this.fire("update")}},_initPath:function(t){var e=t._path=_n("path");t.options.className&&de(e,t.options.className),t.options.interactive&&de(e,"leaflet-interactive"),this._updateStyle(t),this._layers[o(t)]=t},_addPath:function(t){this._rootGroup||this._initContainer(),this._rootGroup.appendChild(t._path),t.addInteractiveTarget(t._path)},_removePath:function(t){oe(t._path),t.removeInteractiveTarget(t._path),delete this._layers[o(t)]},_updatePath:function(t){t._project(),t._update()},_updateStyle:function(t){var e=t._path,i=t.options;e&&(i.stroke?(e.setAttribute("stroke",i.color),e.setAttribute("stroke-opacity",i.opacity),e.setAttribute("stroke-width",i.weight),e.setAttribute("stroke-linecap",i.lineCap),e.setAttribute("stroke-linejoin",i.lineJoin),i.dashArray?e.setAttribute("stroke-dasharray",i.dashArray):e.removeAttribute("stroke-dasharray"),i.dashOffset?e.setAttribute("stroke-dashoffset",i.dashOffset):e.removeAttribute("stroke-dashoffset")):e.setAttribute("stroke","none"),i.fill?(e.setAttribute("fill",i.fillColor||i.color),e.setAttribute("fill-opacity",i.fillOpacity),e.setAttribute("fill-rule",i.fillRule||"evenodd")):e.setAttribute("fill","none"))},_updatePoly:function(t,e){this._setPath(t,$(t._parts,e))},_updateCircle:function(t){var e=t._point,i=Math.max(Math.round(t._radius),1),n="a"+i+","+(Math.max(Math.round(t._radiusY),1)||i)+" 0 1,0 ",s=t._empty()?"M0 0":"M"+(e.x-i)+","+e.y+n+2*i+",0 "+n+2*-i+",0 ";this._setPath(t,s)},_setPath:function(t,e){t._path.setAttribute("d",e)},_bringToFront:function(t){ae(t._path)},_bringToBack:function(t){he(t._path)}});function gn(t){return Rt.svg||Rt.vml?new fn(t):null}Rt.vml&&fn.include(cn),Xe.include({getRenderer:function(t){var e=t.options.renderer||this._getPaneRenderer(t.options.pane)||this.options.renderer||this._renderer;return e||(e=this._renderer=this._createRenderer()),this.hasLayer(e)||this.addLayer(e),e},_getPaneRenderer:function(t){if("overlayPane"===t||void 0===t)return!1;var e=this._paneRenderers[t];return void 0===e&&(e=this._createRenderer({pane:t}),this._paneRenderers[t]=e),e},_createRenderer:function(t){return this.options.preferCanvas&&dn(t)||gn(t)}});var pn=Bi.extend({initialize:function(t,e){Bi.prototype.initialize.call(this,this._boundsToLatLngs(t),e)},setBounds:function(t){return this.setLatLngs(this._boundsToLatLngs(t))},_boundsToLatLngs:function(t){return[(t=B(t)).getSouthWest(),t.getNorthWest(),t.getNorthEast(),t.getSouthEast()]}});fn.create=_n,fn.pointsToPath=$,zi.geometryToLayer=Ui,zi.coordsToLatLng=ji,zi.coordsToLatLngs=Wi,zi.latLngToCoords=Zi,zi.latLngsToCoords=Gi,zi.getFeature=Hi,zi.asFeature=Xi,Xe.mergeOptions({boxZoom:!0});var mn=Je.extend({initialize:function(t){this._map=t,this._container=t._container,this._pane=t._panes.overlayPane,this._resetStateTimeout=0,t.on("unload",this._destroy,this)},addHooks:function(){Ae(this._container,"mousedown",this._onMouseDown,this)},removeHooks:function(){Me(this._container,"mousedown",this._onMouseDown,this)},moved:function(){return this._moved},_destroy:function(){oe(this._pane),delete this._pane},_resetState:function(){this._resetStateTimeout=0,this._moved=!1},_clearDeferredResetState:function(){0!==this._resetStateTimeout&&(clearTimeout(this._resetStateTimeout),this._resetStateTimeout=0)},_onMouseDown:function(t){if(!t.shiftKey||1!==t.which&&1!==t.button)return!1;this._clearDeferredResetState(),this._resetState(),Vt(),xe(),this._startPoint=this._map.mouseEventToContainerPoint(t),Ae(document,{contextmenu:ze,mousemove:this._onMouseMove,mouseup:this._onMouseUp,keydown:this._onKeyDown},this)},_onMouseMove:function(t){this._moved||(this._moved=!0,this._box=se("div","leaflet-zoom-box",this._container),de(this._container,"leaflet-crosshair"),this._map.fire("boxzoomstart")),this._point=this._map.mouseEventToContainerPoint(t);var e=new R(this._point,this._startPoint),i=e.getSize();me(this._box,e.min),this._box.style.width=i.x+"px",this._box.style.height=i.y+"px"},_finish:function(){this._moved&&(oe(this._box),ue(this._container,"leaflet-crosshair")),Yt(),be(),Me(document,{contextmenu:ze,mousemove:this._onMouseMove,mouseup:this._onMouseUp,keydown:this._onKeyDown},this)},_onMouseUp:function(t){if((1===t.which||1===t.button)&&(this._finish(),this._moved)){this._clearDeferredResetState(),this._resetStateTimeout=setTimeout(n(this._resetState,this),0);var e=new k(this._map.containerPointToLatLng(this._startPoint),this._map.containerPointToLatLng(this._point));this._map.fitBounds(e).fire("boxzoomend",{boxZoomBounds:e})}},_onKeyDown:function(t){27===t.keyCode&&(this._finish(),this._clearDeferredResetState(),this._resetState())}});Xe.addInitHook("addHandler","boxZoom",mn),Xe.mergeOptions({doubleClickZoom:!0});var vn=Je.extend({addHooks:function(){this._map.on("dblclick",this._onDoubleClick,this)},removeHooks:function(){this._map.off("dblclick",this._onDoubleClick,this)},_onDoubleClick:function(t){var e=this._map,i=e.getZoom(),n=e.options.zoomDelta,s=t.originalEvent.shiftKey?i-n:i+n;"center"===e.options.doubleClickZoom?e.setZoom(s):e.setZoomAround(t.containerPoint,s)}});Xe.addInitHook("addHandler","doubleClickZoom",vn),Xe.mergeOptions({dragging:!0,inertia:!0,inertiaDeceleration:3400,inertiaMaxSpeed:1/0,easeLinearity:.2,worldCopyJump:!1,maxBoundsViscosity:0});var yn=Je.extend({addHooks:function(){if(!this._draggable){var t=this._map;this._draggable=new ii(t._mapPane,t._container),this._draggable.on({dragstart:this._onDragStart,drag:this._onDrag,dragend:this._onDragEnd},this),this._draggable.on("predrag",this._onPreDragLimit,this),t.options.worldCopyJump&&(this._draggable.on("predrag",this._onPreDragWrap,this),t.on("zoomend",this._onZoomEnd,this),t.whenReady(this._onZoomEnd,this))}de(this._map._container,"leaflet-grab leaflet-touch-drag"),this._draggable.enable(),this._positions=[],this._times=[]},removeHooks:function(){ue(this._map._container,"leaflet-grab"),ue(this._map._container,"leaflet-touch-drag"),this._draggable.disable()},moved:function(){return this._draggable&&this._draggable._moved},moving:function(){return this._draggable&&this._draggable._moving},_onDragStart:function(){var t=this._map;if(t._stop(),this._map.options.maxBounds&&this._map.options.maxBoundsViscosity){var e=B(this._map.options.maxBounds);this._offsetLimit=O(this._map.latLngToContainerPoint(e.getNorthWest()).multiplyBy(-1),this._map.latLngToContainerPoint(e.getSouthEast()).multiplyBy(-1).add(this._map.getSize())),this._viscosity=Math.min(1,Math.max(0,this._map.options.maxBoundsViscosity))}else this._offsetLimit=null;t.fire("movestart").fire("dragstart"),t.options.inertia&&(this._positions=[],this._times=[])},_onDrag:function(t){if(this._map.options.inertia){var e=this._lastTime=+new Date,i=this._lastPos=this._draggable._absPos||this._draggable._newPos;this._positions.push(i),this._times.push(e),this._prunePositions(e)}this._map.fire("move",t).fire("drag",t)},_prunePositions:function(t){for(;this._positions.length>1&&t-this._times[0]>50;)this._positions.shift(),this._times.shift()},_onZoomEnd:function(){var t=this._map.getSize().divideBy(2),e=this._map.latLngToLayerPoint([0,0]);this._initialWorldOffset=e.subtract(t).x,this._worldWidth=this._map.getPixelWorldBounds().getSize().x},_viscousLimit:function(t,e){return t-(t-e)*this._viscosity},_onPreDragLimit:function(){if(this._viscosity&&this._offsetLimit){var t=this._draggable._newPos.subtract(this._draggable._startPos),e=this._offsetLimit;t.xe.max.x&&(t.x=this._viscousLimit(t.x,e.max.x)),t.y>e.max.y&&(t.y=this._viscousLimit(t.y,e.max.y)),this._draggable._newPos=this._draggable._startPos.add(t)}},_onPreDragWrap:function(){var t=this._worldWidth,e=Math.round(t/2),i=this._initialWorldOffset,n=this._draggable._newPos.x,s=(n-e+i)%t+e-i,o=(n+e+i)%t-e-i,r=Math.abs(s+i)0?o:-o))-e;this._delta=0,this._startTime=null,r&&("center"===t.options.scrollWheelZoom?t.setZoom(e+r):t.setZoomAround(this._lastMousePos,e+r))}});Xe.addInitHook("addHandler","scrollWheelZoom",bn);Xe.mergeOptions({tapHold:Rt.touchNative&&Rt.safari&&Rt.mobile,tapTolerance:15});var Sn=Je.extend({addHooks:function(){Ae(this._map._container,"touchstart",this._onDown,this)},removeHooks:function(){Me(this._map._container,"touchstart",this._onDown,this)},_onDown:function(t){if(clearTimeout(this._holdTimeout),1===t.touches.length){var e=t.touches[0];this._startPos=this._newPos=new N(e.clientX,e.clientY),this._holdTimeout=setTimeout(n(function(){this._cancel(),this._isTapValid()&&(Ae(document,"touchend",Be),Ae(document,"touchend touchcancel",this._cancelClickPrevent),this._simulateEvent("contextmenu",e))},this),600),Ae(document,"touchend touchcancel contextmenu",this._cancel,this),Ae(document,"touchmove",this._onMove,this)}},_cancelClickPrevent:function t(){Me(document,"touchend",Be),Me(document,"touchend touchcancel",t)},_cancel:function(){clearTimeout(this._holdTimeout),Me(document,"touchend touchcancel contextmenu",this._cancel,this),Me(document,"touchmove",this._onMove,this)},_onMove:function(t){var e=t.touches[0];this._newPos=new N(e.clientX,e.clientY)},_isTapValid:function(){return this._newPos.distanceTo(this._startPos)<=this._map.options.tapTolerance},_simulateEvent:function(t,e){var i=new MouseEvent(t,{bubbles:!0,cancelable:!0,view:window,screenX:e.screenX,screenY:e.screenY,clientX:e.clientX,clientY:e.clientY});i._simulated=!0,e.target.dispatchEvent(i)}});Xe.addInitHook("addHandler","tapHold",Sn),Xe.mergeOptions({touchZoom:Rt.touch,bounceAtZoomLimits:!0});var wn=Je.extend({addHooks:function(){de(this._map._container,"leaflet-touch-zoom"),Ae(this._map._container,"touchstart",this._onTouchStart,this)},removeHooks:function(){ue(this._map._container,"leaflet-touch-zoom"),Me(this._map._container,"touchstart",this._onTouchStart,this)},_onTouchStart:function(t){var e=this._map;if(t.touches&&2===t.touches.length&&!e._animatingZoom&&!this._zooming){var i=e.mouseEventToContainerPoint(t.touches[0]),n=e.mouseEventToContainerPoint(t.touches[1]);this._centerPoint=e.getSize()._divideBy(2),this._startLatLng=e.containerPointToLatLng(this._centerPoint),"center"!==e.options.touchZoom&&(this._pinchStartLatLng=e.containerPointToLatLng(i.add(n)._divideBy(2))),this._startDist=i.distanceTo(n),this._startZoom=e.getZoom(),this._moved=!1,this._zooming=!0,e._stop(),Ae(document,"touchmove",this._onTouchMove,this),Ae(document,"touchend touchcancel",this._onTouchEnd,this),Be(t)}},_onTouchMove:function(t){if(t.touches&&2===t.touches.length&&this._zooming){var e=this._map,i=e.mouseEventToContainerPoint(t.touches[0]),s=e.mouseEventToContainerPoint(t.touches[1]),o=i.distanceTo(s)/this._startDist;if(this._zoom=e.getScaleZoom(o,this._startZoom),!e.options.bounceAtZoomLimits&&(this._zoome.getMaxZoom()&&o>1)&&(this._zoom=e._limitZoom(this._zoom)),"center"===e.options.touchZoom){if(this._center=this._startLatLng,1===o)return}else{var r=i._add(s)._divideBy(2)._subtract(this._centerPoint);if(1===o&&0===r.x&&0===r.y)return;this._center=e.unproject(e.project(this._pinchStartLatLng,this._zoom).subtract(r),this._zoom)}this._moved||(e._moveStart(!0,!1),this._moved=!0),E(this._animRequest);var a=n(e._move,e,this._center,this._zoom,{pinch:!0,round:!1},void 0);this._animRequest=T(a,this,!0),Be(t)}},_onTouchEnd:function(){this._moved&&this._zooming?(this._zooming=!1,E(this._animRequest),Me(document,"touchmove",this._onTouchMove,this),Me(document,"touchend touchcancel",this._onTouchEnd,this),this._map.options.zoomAnimation?this._map._animateZoom(this._center,this._map._limitZoom(this._zoom),!0,this._map.options.zoomSnap):this._map._resetView(this._center,this._map._limitZoom(this._zoom))):this._zooming=!1}});Xe.addInitHook("addHandler","touchZoom",wn),Xe.BoxZoom=mn,Xe.DoubleClickZoom=vn,Xe.Drag=yn,Xe.Keyboard=xn,Xe.ScrollWheelZoom=bn,Xe.TapHold=Sn,Xe.TouchZoom=wn,t.Bounds=R,t.Browser=Rt,t.CRS=j,t.Canvas=ln,t.Circle=Oi,t.CircleMarker=Ri,t.Class=A,t.Control=qe,t.DivIcon=nn,t.DivOverlay=Ji,t.DomEvent=Ge,t.DomUtil=Pe,t.Draggable=ii,t.Evented=M,t.FeatureGroup=Ci,t.GeoJSON=zi,t.GridLayer=sn,t.Handler=Je,t.Icon=Mi,t.ImageOverlay=$i,t.LatLng=z,t.LatLngBounds=k,t.Layer=Pi,t.LayerGroup=Ai,t.LineUtil=yi,t.Map=Xe,t.Marker=Ii,t.Mixin=ti,t.Path=Li,t.Point=N,t.PolyUtil=ai,t.Polygon=Bi,t.Polyline=ki,t.Popup=tn,t.PosAnimation=He,t.Projection=Si,t.Rectangle=pn,t.Renderer=hn,t.SVG=fn,t.SVGOverlay=Qi,t.TileLayer=on,t.Tooltip=en,t.Transformation=H,t.Util=P,t.VideoOverlay=Ki,t.bind=n,t.bounds=O,t.canvas=dn,t.circle=function(t,e,i){return new Oi(t,e,i)},t.circleMarker=function(t,e){return new Ri(t,e)},t.control=Ve,t.divIcon=function(t){return new nn(t)},t.extend=e,t.featureGroup=function(t,e){return new Ci(t,e)},t.geoJSON=Vi,t.geoJson=Yi,t.gridLayer=function(t){return new sn(t)},t.icon=function(t){return new Mi(t)},t.imageOverlay=function(t,e,i){return new $i(t,e,i)},t.latLng=U,t.latLngBounds=B,t.layerGroup=function(t,e){return new Ai(t,e)},t.map=function(t,e){return new Xe(t,e)},t.marker=function(t,e){return new Ii(t,e)},t.point=I,t.polygon=function(t,e){return new Bi(t,e)},t.polyline=function(t,e){return new ki(t,e)},t.popup=function(t,e){return new tn(t,e)},t.rectangle=function(t,e){return new pn(t,e)},t.setOptions=c,t.stamp=o,t.svg=gn,t.svgOverlay=function(t,e,i){return new Qi(t,e,i)},t.tileLayer=rn,t.tooltip=function(t,e){return new en(t,e)},t.transformation=X,t.version="1.9.4",t.videoOverlay=function(t,e,i){return new Ki(t,e,i)};var Tn=window.L;t.noConflict=function(){return window.L=Tn,this},window.L=t}(e)}};const e={};function i(n){const s=e[n];if(void 0!==s)return s.exports;const o=e[n]={exports:{}};return t[n].call(o.exports,o,o.exports,i),o.exports}i.d=(t,e)=>{if(Array.isArray(e))for(var n=0;nObject.prototype.hasOwnProperty.call(t,e),i.r=t=>{Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};let n={};return(()=>{"use strict";i.r(n),i.d(n,{Color:()=>U,EdgeLineStyleType:()=>M,EdgeType:()=>N,GraphObjectState:()=>r,NodeShapeType:()=>S,OrbError:()=>o,OrbEventType:()=>e,OrbMapView:()=>hr,OrbView:()=>rr,RendererType:()=>ks,getDefaultGraphStyle:()=>H,graphToSVG:()=>Ko,isEdge:()=>I,isNode:()=>T});class t{constructor(){this._listeners=new Map}once(t,e){const i={callable:e,isOnce:!0},n=this._listeners.get(t);return n?n.push(i):this._listeners.set(t,[i]),this}on(t,e){const i={callable:e},n=this._listeners.get(t);return n?n.push(i):this._listeners.set(t,[i]),this}off(t,e){const i=this._listeners.get(t);if(i){const n=i.filter(t=>t.callable!==e);this._listeners.set(t,n)}return this}emit(t,e){const i=this._listeners.get(t);if(!i||0===i.length)return!1;let n=!1;for(let t=0;t!t.isOnce);this._listeners.set(t,e)}return!0}eventNames(){return[...this._listeners.keys()]}listenerCount(t){const e=this._listeners.get(t);return e?e.length:0}listeners(t){const e=this._listeners.get(t);return e?e.map(t=>t.callable):[]}addListener(t,e){return this.on(t,e)}removeListener(t,e){return this.off(t,e)}removeAllListeners(t){return t?this._listeners.delete(t):this._listeners.clear(),this}}var e;!function(t){t.RENDER_START="render-start",t.RENDER_END="render-end",t.SIMULATION_START="simulation-start",t.SIMULATION_STEP="simulation-step",t.SIMULATION_END="simulation-end",t.NODE_CLICK="node-click",t.NODE_HOVER="node-hover",t.EDGE_CLICK="edge-click",t.EDGE_HOVER="edge-hover",t.MOUSE_CLICK="mouse-click",t.MOUSE_MOVE="mouse-move",t.TRANSFORM="transform",t.NODE_DRAG_START="node-drag-start",t.NODE_DRAG="node-drag",t.NODE_DRAG_END="node-drag-end",t.NODE_RIGHT_CLICK="node-right-click",t.EDGE_RIGHT_CLICK="edge-right-click",t.MOUSE_RIGHT_CLICK="mouse-right-click",t.NODE_DOUBLE_CLICK="node-double-click",t.EDGE_DOUBLE_CLICK="edge-double-click",t.MOUSE_DOUBLE_CLICK="mouse-double-click"}(e||(e={}));class s extends t{}class o extends Error{constructor(t){super(t),this.message=t,Object.setPrototypeOf(this,new.target.prototype),this.name=this.constructor.name}}const r={NONE:0,SELECTED:1,HOVERED:2};class a{constructor(){this._imageByUrl={}}static getInstance(){return a._instance||(a._instance=new a),a._instance}getImage(t){return this._imageByUrl[t]}loadImage(t,e){const i=this.getImage(t);if(i)return i;const n=new Image;return this._imageByUrl[t]=n,n.onload=()=>{h(n),null==e||e()},n.onerror=()=>{null==e||e(new Error(`Image ${t} failed to load.`))},n.src=t,n}loadImages(t,e){const i=[],n=new Set(t),s=t=>{n.delete(t),0===n.size&&(null==e||e())};for(let e=0;e{h(a),s(o)},a.onerror=()=>{s(o)},a.src=o,i.push(a)}return i}}const h=t=>t&&0===t.width?(document.body.appendChild(t),t.width=t.offsetWidth,t.height=t.offsetHeight,document.body.removeChild(t),t):t;class l{constructor(){this.listeners=[]}addListener(t){this.listeners.push(t)}getListeners(){return[...this.listeners]}removeListener(t){const e=this.listeners.indexOf(t);-1!==e&&this.listeners.splice(e,1)}notifyListeners(t){for(let e=0;e"number"==typeof t,u=t=>"boolean"==typeof t,c=t=>t instanceof Date,_=t=>Array.isArray(t),f=t=>null!==t&&"object"==typeof t&&"Object"===t.constructor.name,g=t=>"function"==typeof t,p=t=>c(t)?v(t):_(t)?y(t):f(t)?x(t):t,m=(t,e)=>{const i=c(t),n=c(e);if(i&&!n||!i&&n)return!1;if(i&&n)return t.getTime()===e.getTime();const s=_(t),o=_(e);if(s&&!o||!s&&o)return!1;if(s&&o)return t.length===e.length&&t.every((t,i)=>m(t,e[i]));const r=f(t),a=f(e);if(r&&!a||!r&&a)return!1;if(r&&a){const i=Object.keys(t),n=Object.keys(e);return!!m(i,n)&&i.every(i=>m(t[i],e[i]))}return t===e},v=t=>new Date(t),y=t=>t.map(t=>p(t)),x=t=>{const e={};return Object.keys(t).forEach(i=>{e[i]=p(t[i])}),e},b=(t,e)=>{const i=Object.keys(e);for(let n=0;nt instanceof E;class E extends l{constructor(t,e){super(),this._style={},this._state=r.NONE,this._inEdgesById={},this._outEdgesById={},this.id=t.data.id,this._data=t.data,this._position={id:this.id},this._onLoadedImage=null==e?void 0:e.onLoadedImage,e&&e.listeners&&(this.listeners=e.listeners)}getId(){return this.id}getData(){return this._data}getPosition(){return this._position}getStyle(){return this._style}getState(){return this._state}clearPosition(){this._position.x=void 0,this._position.y=void 0,this.notifyListeners()}getCenter(){return void 0===this._position.x||void 0===this._position.y?{x:0,y:0}:{x:this._position.x,y:this._position.y}}getRadius(){var t;return null!==(t=this._style.size)&&void 0!==t?t:0}getBorderedRadius(){return this.getRadius()+this.getBorderWidth()/2}getBoundingBox(){const t=this.getCenter(),e=this.getBorderedRadius();return{x:t.x-e,y:t.y-e,width:2*e,height:2*e}}getInEdges(){return Object.values(this._inEdgesById)}getOutEdges(){return Object.values(this._outEdgesById)}getEdges(){const t={},e=this.getOutEdges();for(let i=0;i0}addEdge(t){t.start===this.id&&(this._outEdgesById[t.getId()]=t),t.end===this.id&&(this._inEdgesById[t.getId()]=t)}removeEdge(t){delete this._outEdgesById[t.getId()],delete this._inEdgesById[t.getId()]}isSelected(){return this._state===r.SELECTED}isHovered(){return this._state===r.HOVERED}clearState(){this.setState(r.NONE,{isNotifySkipped:!0})}getDistanceToBorder(){return this.getBorderedRadius()}includesPoint(t){const e=this._isPointInBoundingBox(t);if(!e)return!1;if(this._style.shape===S.SQUARE)return e;const i=this.getCenter(),n=this.getBorderedRadius(),s=t.x-i.x,o=t.y-i.y;return Math.sqrt(s*s+o*o)<=n}hasShadow(){var t,e,i;return(null!==(t=this._style.shadowSize)&&void 0!==t?t:0)>0||(null!==(e=this._style.shadowOffsetX)&&void 0!==e?e:0)>0||(null!==(i=this._style.shadowOffsetY)&&void 0!==i?i:0)>0}hasBorder(){var t,e;const i=(null!==(t=this._style.borderWidth)&&void 0!==t?t:0)>0,n=(null!==(e=this._style.borderWidthSelected)&&void 0!==e?e:0)>0;return i||this.isSelected()&&n}getLabel(){return this._style.label}getColor(){let t;return this._style.color&&(t=this._style.color),this.isHovered()&&this._style.colorHover&&(t=this._style.colorHover),this.isSelected()&&this._style.colorSelected&&(t=this._style.colorSelected),t}getBorderWidth(){let t=0;return this._style.borderWidth&&this._style.borderWidth>0&&(t=this._style.borderWidth),this.isSelected()&&this._style.borderWidthSelected&&this._style.borderWidthSelected>0&&(t=this._style.borderWidthSelected),t}getBorderColor(){if(!this.hasBorder())return;let t;return this._style.borderColor&&(t=this._style.borderColor),this.isHovered()&&this._style.borderColorHover&&(t=this._style.borderColorHover),this.isSelected()&&this._style.borderColorSelected&&(t=this._style.borderColorSelected.toString()),t}getBackgroundImage(){var t;if((null!==(t=this._style.size)&&void 0!==t?t:0)<=0)return;let e;if(this._style.imageUrl&&(e=this._style.imageUrl),this.isSelected()&&this._style.imageUrlSelected&&(e=this._style.imageUrlSelected),!e)return;return a.getInstance().getImage(e)||a.getInstance().loadImage(e,t=>{var e;t||null===(e=this._onLoadedImage)||void 0===e||e.call(this)})}setData(t){g(t)?this._data=t(this):this._data=t,this.notifyListeners()}patchData(t){let e;e=g(t)?t(this):t,b(this._data,e),this.notifyListeners()}setPosition(t,e){let i;i=g(t)?t(this):t,"x"in i&&"y"in i&&(this._position.x=i.x,this._position.y=i.y,"id"in i&&(this._position.id=i.id)),(null==e?void 0:e.isNotifySkipped)||this.notifyListeners(Object.assign({id:this.id},i))}setStyle(t,e){g(t)?this._style=t(this):this._style=t,(null==e?void 0:e.isNotifySkipped)||this.notifyListeners()}patchStyle(t,e){let i;i=g(t)?t(this):t,b(this._style,i),(null==e?void 0:e.isNotifySkipped)||this.notifyListeners()}setState(t,e){let i;if(i=g(t)?t(this):t,d(i))this._state=i;else if(f(i)){const t=i.options;if(this._state=this._handleState(i.state,t),t)return void this.notifyListeners({id:this.id,type:"node",options:t})}(null==e?void 0:e.isNotifySkipped)||this.notifyListeners()}_isPointInBoundingBox(t){return((t,e)=>{const i=t.x+t.width,n=t.y+t.height;return e.x>=t.x&&e.x<=i&&e.y>=t.y&&e.y<=n})(this.getBoundingBox(),t)}_handleState(t,e){return(null==e?void 0:e.isToggle)&&this._state===t?r.NONE:t}}const P=(t,e,i)=>{const n=e.x-t.x,s=e.y-t.y;let o=((i.x-t.x)*n+(i.y-t.y)*s)/(n*n+s*s);o>1&&(o=1),o<0&&(o=0);const r=t.x+o*n,a=t.y+o*s,h=r-i.x,l=a-i.y;return Math.sqrt(h*h+l*l)},A=[5,5],C=[1,1];var M,N;!function(t){t.SOLID="solid",t.DASHED="dashed",t.DOTTED="dotted",t.CUSTOM="custom"}(M||(M={})),function(t){t.STRAIGHT="straight",t.LOOPBACK="loopback",t.CURVED="curved"}(N||(N={}));class D{static create(t,e){switch(R(t)){case N.STRAIGHT:return new O(t,e);case N.LOOPBACK:return new B(t,e);case N.CURVED:return new k(t,e);default:return new O(t,e)}}static copy(t,e){const i=D.create({data:t.getData(),offset:void 0!==(null==e?void 0:e.offset)?e.offset:t.offset,startNode:t.startNode,endNode:t.endNode});i.setState(t.getState()),i.setStyle(t.getStyle());const n=t.getListeners();for(let t=0;tt instanceof O||t instanceof k||t instanceof B;class L extends l{constructor(t,e){var i;super(),this._style={},this._state=r.NONE,this._type=N.STRAIGHT,this.id=t.data.id,this._data=t.data,this.offset=null!==(i=t.offset)&&void 0!==i?i:0,this.startNode=t.startNode,this.endNode=t.endNode,this._type=R(t),this._position={id:this.id,source:this.startNode.getId(),target:this.endNode.getId()},this.startNode.addEdge(this),this.endNode.addEdge(this),e&&e.listeners&&(this.listeners=e.listeners)}getId(){return this.id}getData(){return this._data}getPosition(){return this._position}getStyle(){return this._style}getState(){return this._state}get type(){return this._type}get start(){return this._data.start}get end(){return this._data.end}hasStyle(){return this._style&&Object.keys(this._style).length>0}isSelected(){return this._state===r.SELECTED}isHovered(){return this._state===r.HOVERED}clearState(){this._state=r.NONE}isLoopback(){return this._type===N.LOOPBACK}isStraight(){return this._type===N.STRAIGHT}isCurved(){return this._type===N.CURVED}getCenter(){var t,e;const i=null===(t=this.startNode)||void 0===t?void 0:t.getCenter(),n=null===(e=this.endNode)||void 0===e?void 0:e.getCenter();return i&&n?{x:(i.x+n.x)/2,y:(i.y+n.y)/2}:{x:0,y:0}}getDistance(t){const e=this.startNode.getCenter(),i=this.endNode.getCenter();return e&&i?P(e,i,t):0}getLabel(){return this._style.label}hasShadow(){var t,e,i;return(null!==(t=this._style.shadowSize)&&void 0!==t?t:0)>0||(null!==(e=this._style.shadowOffsetX)&&void 0!==e?e:0)>0||(null!==(i=this._style.shadowOffsetY)&&void 0!==i?i:0)>0}getWidth(){let t=0;return void 0!==this._style.width&&(t=this._style.width),this.isHovered()&&void 0!==this._style.widthHover&&(t=this._style.widthHover),this.isSelected()&&void 0!==this._style.widthSelected&&(t=this._style.widthSelected),t}getColor(){let t;return this._style.color&&(t=this._style.color),this.isHovered()&&this._style.colorHover&&(t=this._style.colorHover),this.isSelected()&&this._style.colorSelected&&(t=this._style.colorSelected),t}getLineDashPattern(){const t=this._style.lineStyle;if(void 0===t||t.type===M.SOLID)return null;switch(t.type){case M.DASHED:return A;case M.DOTTED:return C;case M.CUSTOM:return e=t.pattern,_(e)&&e.every(t=>d(t))?t.pattern:null;default:return null}var e}setData(t){g(t)?this._data=t(this):this._data=t,this.notifyListeners()}patchData(t){let e;e=g(t)?t(this):t,b(this._data,e),this.notifyListeners()}setStyle(t,e){g(t)?this._style=t(this):this._style=t,(null==e?void 0:e.isNotifySkipped)||this.notifyListeners()}patchStyle(t,e){let i;i=g(t)?t(this):t,b(this._style,i),(null==e?void 0:e.isNotifySkipped)||this.notifyListeners()}setState(t,e){let i;if(i=g(t)?t(this):t,d(i))this._state=i;else if(f(i)){const t=i.options;if(this._state=this._handleState(i.state,t),t)return void this.notifyListeners({id:this.id,type:"edge",options:t})}(null==e?void 0:e.isNotifySkipped)||this.notifyListeners()}_handleState(t,e){return(null==e?void 0:e.isToggle)&&this._state===t?r.NONE:t}}const R=t=>{var e;return t.startNode.getId()===t.endNode.getId()?N.LOOPBACK:0===(null!==(e=t.offset)&&void 0!==e?e:0)?N.STRAIGHT:N.CURVED};class O extends L{getCenter(){var t,e;const i=null===(t=this.startNode)||void 0===t?void 0:t.getCenter(),n=null===(e=this.endNode)||void 0===e?void 0:e.getCenter();return i&&n?{x:(i.x+n.x)/2,y:(i.y+n.y)/2}:{x:0,y:0}}getDistance(t){var e,i;const n=null===(e=this.startNode)||void 0===e?void 0:e.getCenter(),s=null===(i=this.endNode)||void 0===i?void 0:i.getCenter();return n&&s?P(n,s,t):0}}class k extends L{getCenter(){return this.getCurvedControlPoint(2)}getDistance(t){var e,i;const n=null===(e=this.startNode)||void 0===e?void 0:e.getCenter(),s=null===(i=this.endNode)||void 0===i?void 0:i.getCenter();if(!n||!s)return 0;const o=this.getCurvedControlPoint();let r,a,h,l,d,u=1e9,c=n.x,_=n.y;for(a=1;a<10;a++)h=.1*a,l=Math.pow(1-h,2)*n.x+2*h*(1-h)*o.x+Math.pow(h,2)*s.x,d=Math.pow(1-h,2)*n.y+2*h*(1-h)*o.y+Math.pow(h,2)*s.y,a>0&&(r=P({x:c,y:_},{x:l,y:d},t),u=r({r:parseInt(t.substring(1,3),16),g:parseInt(t.substring(3,5),16),b:parseInt(t.substring(5,7),16)}),j=t=>"#"+((1<<24)+(t.r<<16)+(t.g<<8)+t.b).toString(16).slice(1),W=["label","name"],Z={size:5,color:new U("#1d87c9")},G={color:new U("#ababab"),width:.3},H=()=>({getNodeStyle:t=>Object.assign(Object.assign({},Z),{label:X(t)}),getEdgeStyle:t=>Object.assign(Object.assign({},G),{label:X(t)})}),X=t=>{const e=t.getData();for(let t=0;t{}};function V(){for(var t,e=0,i=arguments.length,n={};e=0&&(e=t.slice(i+1),t=t.slice(0,i)),t&&!n.hasOwnProperty(t))throw new Error("unknown type: "+t);return{type:t,name:e}})),r=-1,a=o.length;if(!(arguments.length<2)){if(null!=e&&"function"!=typeof e)throw new Error("invalid callback: "+e);for(;++r0)for(var i,n,s=new Array(i),o=0;oe?1:t>=e?0:NaN}dt.prototype={constructor:dt,appendChild:function(t){return this._parent.insertBefore(t,this._next)},insertBefore:function(t,e){return this._parent.insertBefore(t,e)},querySelector:function(t){return this._parent.querySelector(t)},querySelectorAll:function(t){return this._parent.querySelectorAll(t)}};var pt="http://www.w3.org/1999/xhtml";const mt={svg:"http://www.w3.org/2000/svg",xhtml:pt,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function vt(t){var e=t+="",i=e.indexOf(":");return i>=0&&"xmlns"!==(e=t.slice(0,i))&&(t=t.slice(i+1)),mt.hasOwnProperty(e)?{space:mt[e],local:t}:t}function yt(t){return function(){this.removeAttribute(t)}}function xt(t){return function(){this.removeAttributeNS(t.space,t.local)}}function bt(t,e){return function(){this.setAttribute(t,e)}}function St(t,e){return function(){this.setAttributeNS(t.space,t.local,e)}}function wt(t,e){return function(){var i=e.apply(this,arguments);null==i?this.removeAttribute(t):this.setAttribute(t,i)}}function Tt(t,e){return function(){var i=e.apply(this,arguments);null==i?this.removeAttributeNS(t.space,t.local):this.setAttributeNS(t.space,t.local,i)}}function Et(t){return t.ownerDocument&&t.ownerDocument.defaultView||t.document&&t||t.defaultView}function Pt(t){return function(){this.style.removeProperty(t)}}function At(t,e,i){return function(){this.style.setProperty(t,e,i)}}function Ct(t,e,i){return function(){var n=e.apply(this,arguments);null==n?this.style.removeProperty(t):this.style.setProperty(t,n,i)}}function Mt(t,e){return t.style.getPropertyValue(e)||Et(t).getComputedStyle(t,null).getPropertyValue(e)}function Nt(t){return function(){delete this[t]}}function Dt(t,e){return function(){this[t]=e}}function It(t,e){return function(){var i=e.apply(this,arguments);null==i?delete this[t]:this[t]=i}}function Lt(t){return t.trim().split(/^|\s+/)}function Rt(t){return t.classList||new Ot(t)}function Ot(t){this._node=t,this._names=Lt(t.getAttribute("class")||"")}function kt(t,e){for(var i=Rt(t),n=-1,s=e.length;++n=0&&(this._names.splice(e,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(t){return this._names.indexOf(t)>=0}};var ae=[null];function he(t,e){this._groups=t,this._parents=e}function le(){return new he([[document.documentElement]],ae)}he.prototype=le.prototype={constructor:he,select:function(t){"function"!=typeof t&&(t=tt(t));for(var e=this._groups,i=e.length,n=new Array(i),s=0;s=x&&(x=y+1);!(v=p[x])&&++x=0;)(n=s[o])&&(r&&4^n.compareDocumentPosition(r)&&r.parentNode.insertBefore(n,r),r=n);return this},sort:function(t){function e(e,i){return e&&i?t(e.__data__,i.__data__):!e-!i}t||(t=gt);for(var i=this._groups,n=i.length,s=new Array(n),o=0;o1?this.each((null==e?Pt:"function"==typeof e?Ct:At)(t,e,i??"")):Mt(this.node(),t)},property:function(t,e){return arguments.length>1?this.each((null==e?Nt:"function"==typeof e?It:Dt)(t,e)):this.node()[t]},classed:function(t,e){var i=Lt(t+"");if(arguments.length<2){for(var n=Rt(this.node()),s=-1,o=i.length;++s=0&&(e=t.slice(i+1),t=t.slice(0,i)),{type:t,name:e}})}(t+""),r=o.length;if(!(arguments.length<2)){for(a=e?ne:ie,n=0;n()=>t;function xe(t,{sourceEvent:e,subject:i,target:n,identifier:s,active:o,x:r,y:a,dx:h,dy:l,dispatch:d}){Object.defineProperties(this,{type:{value:t,enumerable:!0,configurable:!0},sourceEvent:{value:e,enumerable:!0,configurable:!0},subject:{value:i,enumerable:!0,configurable:!0},target:{value:n,enumerable:!0,configurable:!0},identifier:{value:s,enumerable:!0,configurable:!0},active:{value:o,enumerable:!0,configurable:!0},x:{value:r,enumerable:!0,configurable:!0},y:{value:a,enumerable:!0,configurable:!0},dx:{value:h,enumerable:!0,configurable:!0},dy:{value:l,enumerable:!0,configurable:!0},_:{value:d}})}function be(t){return!t.ctrlKey&&!t.button}function Se(){return this.parentNode}function we(t,e){return e??{x:t.x,y:t.y}}function Te(){return navigator.maxTouchPoints||"ontouchstart"in this}xe.prototype.on=function(){var t=this._.on.apply(this._,arguments);return t===this._?this:t};const Ee=t=>+t;function Pe(t){return((t=Math.exp(t))+1/t)/2}const Ae=function t(e,i,n){function s(t,s){var o,r,a=t[0],h=t[1],l=t[2],d=s[0],u=s[1],c=s[2],_=d-a,f=u-h,g=_*_+f*f;if(g<1e-12)r=Math.log(c/l)/e,o=function(t){return[a+t*_,h+t*f,l*Math.exp(e*t*r)]};else{var p=Math.sqrt(g),m=(c*c-l*l+n*g)/(2*l*i*p),v=(c*c-l*l-n*g)/(2*c*i*p),y=Math.log(Math.sqrt(m*m+1)-m),x=Math.log(Math.sqrt(v*v+1)-v);r=(x-y)/e,o=function(t){var n=t*r,s=Pe(y),o=l/(i*p)*(s*function(t){return((t=Math.exp(2*t))-1)/(t+1)}(e*n+y)-function(t){return((t=Math.exp(t))-1/t)/2}(y));return[a+o*_,h+o*f,l*s/Pe(e*n+y)]}}return o.duration=1e3*r*e/Math.SQRT2,o}return s.rho=function(e){var i=Math.max(.001,+e),n=i*i;return t(i,n,n*n)},s}(Math.SQRT2,2,4);var Ce,Me,Ne=0,De=0,Ie=0,Le=0,Re=0,Oe=0,ke="object"==typeof performance&&performance.now?performance:Date,Be="object"==typeof window&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(t){setTimeout(t,17)};function ze(){return Re||(Be(Ue),Re=ke.now()+Oe)}function Ue(){Re=0}function Fe(){this._call=this._time=this._next=null}function je(t,e,i){var n=new Fe;return n.restart(t,e,i),n}function We(){Re=(Le=ke.now())+Oe,Ne=De=0;try{!function(){ze(),++Ne;for(var t,e=Ce;e;)(t=Re-e._time)>=0&&e._call.call(void 0,t),e=e._next;--Ne}()}finally{Ne=0,function(){for(var t,e,i=Ce,n=1/0;i;)i._call?(n>i._time&&(n=i._time),t=i,i=i._next):(e=i._next,i._next=null,i=t?t._next=e:Ce=e);Me=t,Ge(n)}(),Re=0}}function Ze(){var t=ke.now(),e=t-Le;e>1e3&&(Oe-=e,Le=t)}function Ge(t){Ne||(De&&(De=clearTimeout(De)),t-Re>24?(t<1/0&&(De=setTimeout(We,t-ke.now()-Oe)),Ie&&(Ie=clearInterval(Ie))):(Ie||(Le=ke.now(),Ie=setInterval(Ze,1e3)),Ne=1,Be(We)))}function He(t,e,i){var n=new Fe;return e=null==e?0:+e,n.restart(i=>{n.stop(),t(i+e)},e,i),n}Fe.prototype=je.prototype={constructor:Fe,restart:function(t,e,i){if("function"!=typeof t)throw new TypeError("callback is not a function");i=(null==i?ze():+i)+(null==e?0:+e),this._next||Me===this||(Me?Me._next=this:Ce=this,Me=this),this._call=t,this._time=i,Ge()},stop:function(){this._call&&(this._call=null,this._time=1/0,Ge())}};var Xe=Q("start","end","cancel","interrupt"),qe=[];function Ve(t,e,i,n,s,o){var r=t.__transition;if(r){if(i in r)return}else t.__transition={};!function(t,e,i){var n,s=t.__transition;function o(h){var l,d,u,c;if(1!==i.state)return a();for(l in s)if((c=s[l]).name===i.name){if(3===c.state)return He(o);4===c.state?(c.state=6,c.timer.stop(),c.on.call("interrupt",t,t.__data__,c.index,c.group),delete s[l]):+l0)throw new Error("too late; already scheduled");return i}function $e(t,e){var i=Ke(t,e);if(i.state>3)throw new Error("too late; already running");return i}function Ke(t,e){var i=t.__transition;if(!i||!(i=i[e]))throw new Error("transition not found");return i}function Qe(t,e){var i,n,s,o=t.__transition,r=!0;if(o){for(s in e=null==e?null:e+"",o)(i=o[s]).name===e?(n=i.state>2&&i.state<5,i.state=6,i.timer.stop(),i.on.call(n?"interrupt":"cancel",t,t.__data__,i.index,i.group),delete o[s]):r=!1;r&&delete t.__transition}}function Je(t,e){return t=+t,e=+e,function(i){return t*(1-i)+e*i}}var ti,ei=180/Math.PI,ii={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function ni(t,e,i,n,s,o){var r,a,h;return(r=Math.sqrt(t*t+e*e))&&(t/=r,e/=r),(h=t*i+e*n)&&(i-=t*h,n-=e*h),(a=Math.sqrt(i*i+n*n))&&(i/=a,n/=a,h/=a),t*n180?e+=360:e-t>180&&(t+=360),o.push({i:i.push(s(i)+"rotate(",null,n)-2,x:Je(t,e)})):e&&i.push(s(i)+"rotate("+e+n)}(o.rotate,r.rotate,a,h),function(t,e,i,o){t!==e?o.push({i:i.push(s(i)+"skewX(",null,n)-2,x:Je(t,e)}):e&&i.push(s(i)+"skewX("+e+n)}(o.skewX,r.skewX,a,h),function(t,e,i,n,o,r){if(t!==i||e!==n){var a=o.push(s(o)+"scale(",null,",",null,")");r.push({i:a-4,x:Je(t,i)},{i:a-2,x:Je(e,n)})}else 1===i&&1===n||o.push(s(o)+"scale("+i+","+n+")")}(o.scaleX,o.scaleY,r.scaleX,r.scaleY,a,h),o=r=null,function(t){for(var e,i=-1,n=h.length;++i>8&15|e>>4&240,e>>4&15|240&e,(15&e)<<4|15&e,1):8===i?Ni(e>>24&255,e>>16&255,e>>8&255,(255&e)/255):4===i?Ni(e>>12&15|e>>8&240,e>>8&15|e>>4&240,e>>4&15|240&e,((15&e)<<4|15&e)/255):null):(e=yi.exec(t))?new Ii(e[1],e[2],e[3],1):(e=xi.exec(t))?new Ii(255*e[1]/100,255*e[2]/100,255*e[3]/100,1):(e=bi.exec(t))?Ni(e[1],e[2],e[3],e[4]):(e=Si.exec(t))?Ni(255*e[1]/100,255*e[2]/100,255*e[3]/100,e[4]):(e=wi.exec(t))?zi(e[1],e[2]/100,e[3]/100,1):(e=Ti.exec(t))?zi(e[1],e[2]/100,e[3]/100,e[4]):Ei.hasOwnProperty(t)?Mi(Ei[t]):"transparent"===t?new Ii(NaN,NaN,NaN,0):null}function Mi(t){return new Ii(t>>16&255,t>>8&255,255&t,1)}function Ni(t,e,i,n){return n<=0&&(t=e=i=NaN),new Ii(t,e,i,n)}function Di(t,e,i,n){return 1===arguments.length?((s=t)instanceof ci||(s=Ci(s)),s?new Ii((s=s.rgb()).r,s.g,s.b,s.opacity):new Ii):new Ii(t,e,i,n??1);var s}function Ii(t,e,i,n){this.r=+t,this.g=+e,this.b=+i,this.opacity=+n}function Li(){return`#${Bi(this.r)}${Bi(this.g)}${Bi(this.b)}`}function Ri(){const t=Oi(this.opacity);return`${1===t?"rgb(":"rgba("}${ki(this.r)}, ${ki(this.g)}, ${ki(this.b)}${1===t?")":`, ${t})`}`}function Oi(t){return isNaN(t)?1:Math.max(0,Math.min(1,t))}function ki(t){return Math.max(0,Math.min(255,Math.round(t)||0))}function Bi(t){return((t=ki(t))<16?"0":"")+t.toString(16)}function zi(t,e,i,n){return n<=0?t=e=i=NaN:i<=0||i>=1?t=e=NaN:e<=0&&(t=NaN),new Fi(t,e,i,n)}function Ui(t){if(t instanceof Fi)return new Fi(t.h,t.s,t.l,t.opacity);if(t instanceof ci||(t=Ci(t)),!t)return new Fi;if(t instanceof Fi)return t;var e=(t=t.rgb()).r/255,i=t.g/255,n=t.b/255,s=Math.min(e,i,n),o=Math.max(e,i,n),r=NaN,a=o-s,h=(o+s)/2;return a?(r=e===o?(i-n)/a+6*(i0&&h<1?0:r,new Fi(r,a,h,t.opacity)}function Fi(t,e,i,n){this.h=+t,this.s=+e,this.l=+i,this.opacity=+n}function ji(t){return(t=(t||0)%360)<0?t+360:t}function Wi(t){return Math.max(0,Math.min(1,t||0))}function Zi(t,e,i){return 255*(t<60?e+(i-e)*t/60:t<180?i:t<240?e+(i-e)*(240-t)/60:e)}function Gi(t,e,i,n,s){var o=t*t,r=o*t;return((1-3*t+3*o-r)*e+(4-6*o+3*r)*i+(1+3*t+3*o-3*r)*n+r*s)/6}di(ci,Ci,{copy(t){return Object.assign(new this.constructor,this,t)},displayable(){return this.rgb().displayable()},hex:Pi,formatHex:Pi,formatHex8:function(){return this.rgb().formatHex8()},formatHsl:function(){return Ui(this).formatHsl()},formatRgb:Ai,toString:Ai}),di(Ii,Di,ui(ci,{brighter(t){return t=null==t?fi:Math.pow(fi,t),new Ii(this.r*t,this.g*t,this.b*t,this.opacity)},darker(t){return t=null==t?_i:Math.pow(_i,t),new Ii(this.r*t,this.g*t,this.b*t,this.opacity)},rgb(){return this},clamp(){return new Ii(ki(this.r),ki(this.g),ki(this.b),Oi(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:Li,formatHex:Li,formatHex8:function(){return`#${Bi(this.r)}${Bi(this.g)}${Bi(this.b)}${Bi(255*(isNaN(this.opacity)?1:this.opacity))}`},formatRgb:Ri,toString:Ri})),di(Fi,function(t,e,i,n){return 1===arguments.length?Ui(t):new Fi(t,e,i,n??1)},ui(ci,{brighter(t){return t=null==t?fi:Math.pow(fi,t),new Fi(this.h,this.s,this.l*t,this.opacity)},darker(t){return t=null==t?_i:Math.pow(_i,t),new Fi(this.h,this.s,this.l*t,this.opacity)},rgb(){var t=this.h%360+360*(this.h<0),e=isNaN(t)||isNaN(this.s)?0:this.s,i=this.l,n=i+(i<.5?i:1-i)*e,s=2*i-n;return new Ii(Zi(t>=240?t-240:t+120,s,n),Zi(t,s,n),Zi(t<120?t+240:t-120,s,n),this.opacity)},clamp(){return new Fi(ji(this.h),Wi(this.s),Wi(this.l),Oi(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){const t=Oi(this.opacity);return`${1===t?"hsl(":"hsla("}${ji(this.h)}, ${100*Wi(this.s)}%, ${100*Wi(this.l)}%${1===t?")":`, ${t})`}`}}));const Hi=t=>()=>t;function Xi(t,e){var i=e-t;return i?function(t,e){return function(i){return t+i*e}}(t,i):Hi(isNaN(t)?e:t)}const qi=function t(e){var i=function(t){return 1===(t=+t)?Xi:function(e,i){return i-e?function(t,e,i){return t=Math.pow(t,i),e=Math.pow(e,i)-t,i=1/i,function(n){return Math.pow(t+n*e,i)}}(e,i,t):Hi(isNaN(e)?i:e)}}(e);function n(t,e){var n=i((t=Di(t)).r,(e=Di(e)).r),s=i(t.g,e.g),o=i(t.b,e.b),r=Xi(t.opacity,e.opacity);return function(e){return t.r=n(e),t.g=s(e),t.b=o(e),t.opacity=r(e),t+""}}return n.gamma=t,n}(1);function Vi(t){return function(e){var i,n,s=e.length,o=new Array(s),r=new Array(s),a=new Array(s);for(i=0;i=1?(i=1,e-1):Math.floor(i*e),s=t[n],o=t[n+1],r=n>0?t[n-1]:2*s-o,a=no&&(s=e.slice(o,s),a[r]?a[r]+=s:a[++r]=s),(i=i[0])===(n=n[0])?a[r]?a[r]+=n:a[++r]=n:(a[++r]=null,h.push({i:r,x:Je(i,n)})),o=$i.lastIndex;return o=0&&(t=t.slice(0,e)),!t||"start"===t})}(e)?Ye:$e;return function(){var r=o(this,t),a=r.on;a!==n&&(s=(n=a).copy()).on(e,i),r.on=s}}(i,t,e))},attr:function(t,e){var i=vt(t),n="transform"===i?ri:Qi;return this.attrTween(t,"function"==typeof e?(i.local?on:sn)(i,n,li(this,"attr."+t,e)):null==e?(i.local?tn:Ji)(i):(i.local?nn:en)(i,n,e))},attrTween:function(t,e){var i="attr."+t;if(arguments.length<2)return(i=this.tween(i))&&i._value;if(null==e)return this.tween(i,null);if("function"!=typeof e)throw new Error;var n=vt(t);return this.tween(i,(n.local?rn:an)(n,e))},style:function(t,e,i){var n="transform"==(t+="")?oi:Qi;return null==e?this.styleTween(t,function(t,e){var i,n,s;return function(){var o=Mt(this,t),r=(this.style.removeProperty(t),Mt(this,t));return o===r?null:o===i&&r===n?s:s=e(i=o,n=r)}}(t,n)).on("end.style."+t,_n(t)):"function"==typeof e?this.styleTween(t,function(t,e,i){var n,s,o;return function(){var r=Mt(this,t),a=i(this),h=a+"";return null==a&&(this.style.removeProperty(t),h=a=Mt(this,t)),r===h?null:r===n&&h===s?o:(s=h,o=e(n=r,a))}}(t,n,li(this,"style."+t,e))).each(function(t,e){var i,n,s,o,r="style."+e,a="end."+r;return function(){var h=$e(this,t),l=h.on,d=null==h.value[r]?o||(o=_n(e)):void 0;l===i&&s===d||(n=(i=l).copy()).on(a,s=d),h.on=n}}(this._id,t)):this.styleTween(t,function(t,e,i){var n,s,o=i+"";return function(){var r=Mt(this,t);return r===o?null:r===n?s:s=e(n=r,i)}}(t,n,e),i).on("end.style."+t,null)},styleTween:function(t,e,i){var n="style."+(t+="");if(arguments.length<2)return(n=this.tween(n))&&n._value;if(null==e)return this.tween(n,null);if("function"!=typeof e)throw new Error;return this.tween(n,function(t,e,i){var n,s;function o(){var o=e.apply(this,arguments);return o!==s&&(n=(s=o)&&function(t,e,i){return function(n){this.style.setProperty(t,e.call(this,n),i)}}(t,o,i)),n}return o._value=e,o}(t,e,i??""))},text:function(t){return this.tween("text","function"==typeof t?function(t){return function(){var e=t(this);this.textContent=e??""}}(li(this,"text",t)):function(t){return function(){this.textContent=t}}(null==t?"":t+""))},textTween:function(t){var e="text";if(arguments.length<1)return(e=this.tween(e))&&e._value;if(null==t)return this.tween(e,null);if("function"!=typeof t)throw new Error;return this.tween(e,function(t){var e,i;function n(){var n=t.apply(this,arguments);return n!==i&&(e=(i=n)&&function(t){return function(e){this.textContent=t.call(this,e)}}(n)),e}return n._value=t,n}(t))},remove:function(){return this.on("end.remove",function(t){return function(){var e=this.parentNode;for(var i in this.__transition)if(+i!==t)return;e&&e.removeChild(this)}}(this._id))},tween:function(t,e){var i=this._id;if(t+="",arguments.length<2){for(var n,s=Ke(this.node(),i).tween,o=0,r=s.length;o()=>t;function bn(t,{sourceEvent:e,target:i,transform:n,dispatch:s}){Object.defineProperties(this,{type:{value:t,enumerable:!0,configurable:!0},sourceEvent:{value:e,enumerable:!0,configurable:!0},target:{value:i,enumerable:!0,configurable:!0},transform:{value:n,enumerable:!0,configurable:!0},_:{value:s}})}function Sn(t,e,i){this.k=t,this.x=e,this.y=i}Sn.prototype={constructor:Sn,scale:function(t){return 1===t?this:new Sn(this.k*t,this.x,this.y)},translate:function(t,e){return 0===t&0===e?this:new Sn(this.k,this.x+this.k*t,this.y+this.k*e)},apply:function(t){return[t[0]*this.k+this.x,t[1]*this.k+this.y]},applyX:function(t){return t*this.k+this.x},applyY:function(t){return t*this.k+this.y},invert:function(t){return[(t[0]-this.x)/this.k,(t[1]-this.y)/this.k]},invertX:function(t){return(t-this.x)/this.k},invertY:function(t){return(t-this.y)/this.k},rescaleX:function(t){return t.copy().domain(t.range().map(this.invertX,this).map(t.invert,t))},rescaleY:function(t){return t.copy().domain(t.range().map(this.invertY,this).map(t.invert,t))},toString:function(){return"translate("+this.x+","+this.y+") scale("+this.k+")"}};var wn=new Sn(1,0,0);function Tn(t){t.stopImmediatePropagation()}function En(t){t.preventDefault(),t.stopImmediatePropagation()}function Pn(t){return!(t.ctrlKey&&"wheel"!==t.type||t.button)}function An(){var t=this;return t instanceof SVGElement?(t=t.ownerSVGElement||t).hasAttribute("viewBox")?[[(t=t.viewBox.baseVal).x,t.y],[t.x+t.width,t.y+t.height]]:[[0,0],[t.width.baseVal.value,t.height.baseVal.value]]:[[0,0],[t.clientWidth,t.clientHeight]]}function Cn(){return this.__zoom||wn}function Mn(t){return-t.deltaY*(1===t.deltaMode?.05:t.deltaMode?1:.002)*(t.ctrlKey?10:1)}function Nn(){return navigator.maxTouchPoints||"ontouchstart"in this}function Dn(t,e,i){var n=t.invertX(e[0][0])-i[0][0],s=t.invertX(e[1][0])-i[1][0],o=t.invertY(e[0][1])-i[0][1],r=t.invertY(e[1][1])-i[1][1];return t.translate(s>n?(n+s)/2:Math.min(0,n)||Math.max(0,s),r>o?(o+r)/2:Math.min(0,o)||Math.max(0,r))}Sn.prototype;const In=(t,e)=>!!t&&!!e&&t.x===e.x&&t.y===e.y;var Ln;function Rn(t,e,i){t.on(Ln.SIMULATION_START,()=>{e.emit(Ln.SIMULATION_START,void 0),i(!0)}),t.on(Ln.SIMULATION_PROGRESS,t=>{e.emit(Ln.SIMULATION_PROGRESS,t)}),t.on(Ln.SIMULATION_END,t=>{e.emit(Ln.SIMULATION_END,t),i(!1)}),t.on(Ln.SIMULATION_STEP,t=>{e.emit(Ln.SIMULATION_STEP,t)}),t.on(Ln.NODE_DRAG,t=>{e.emit(Ln.NODE_DRAG,t)}),t.on(Ln.SETTINGS_UPDATE,t=>{e.emit(Ln.SETTINGS_UPDATE,t)})}function On(t){return function(){return t}}function kn(t){return 1e-6*(t()-.5)}function Bn(t){return t.index}function zn(t,e){var i=t.get(e);if(!i)throw new Error("node not found: "+e);return i}!function(t){t.SIMULATION_START="simulation-start",t.SIMULATION_STEP="simulation-step",t.SIMULATION_PROGRESS="simulation-progress",t.SIMULATION_END="simulation-end",t.NODE_DRAG="node-drag",t.NODE_DRAG_END="node-drag-end",t.SETTINGS_UPDATE="settings-update"}(Ln||(Ln={}));const Un=4294967296;function Fn(t){return t.x}function jn(t){return t.y}var Wn=Math.PI*(3-Math.sqrt(5));function Zn(t,e,i,n){if(isNaN(e)||isNaN(i))return t;var s,o,r,a,h,l,d,u,c,_=t._root,f={data:n},g=t._x0,p=t._y0,m=t._x1,v=t._y1;if(!_)return t._root=f,t;for(;_.length;)if((l=e>=(o=(g+m)/2))?g=o:m=o,(d=i>=(r=(p+v)/2))?p=r:v=r,s=_,!(_=_[u=d<<1|l]))return s[u]=f,t;if(a=+t._x.call(null,_.data),h=+t._y.call(null,_.data),e===a&&i===h)return f.next=_,s?s[u]=f:t._root=f,t;do{s=s?s[u]=new Array(4):t._root=new Array(4),(l=e>=(o=(g+m)/2))?g=o:m=o,(d=i>=(r=(p+v)/2))?p=r:v=r}while((u=d<<1|l)==(c=(h>=r)<<1|a>=o));return s[c]=_,s[u]=f,t}function Gn(t,e,i,n,s){this.node=t,this.x0=e,this.y0=i,this.x1=n,this.y1=s}function Hn(t){return t[0]}function Xn(t){return t[1]}function qn(t,e,i){var n=new Vn(e??Hn,i??Xn,NaN,NaN,NaN,NaN);return null==t?n:n.addAll(t)}function Vn(t,e,i,n,s,o){this._x=t,this._y=e,this._x0=i,this._y0=n,this._x1=s,this._y1=o,this._root=void 0}function Yn(t){for(var e={data:t.data},i=e;t=t.next;)i=i.next={data:t.data};return e}var $n=qn.prototype=Vn.prototype;function Kn(t){return t.x+t.vx}function Qn(t){return t.y+t.vy}$n.copy=function(){var t,e,i=new Vn(this._x,this._y,this._x0,this._y0,this._x1,this._y1),n=this._root;if(!n)return i;if(!n.length)return i._root=Yn(n),i;for(t=[{source:n,target:i._root=new Array(4)}];n=t.pop();)for(var s=0;s<4;++s)(e=n.source[s])&&(e.length?t.push({source:e,target:n.target[s]=new Array(4)}):n.target[s]=Yn(e));return i},$n.add=function(t){const e=+this._x.call(null,t),i=+this._y.call(null,t);return Zn(this.cover(e,i),e,i,t)},$n.addAll=function(t){var e,i,n,s,o=t.length,r=new Array(o),a=new Array(o),h=1/0,l=1/0,d=-1/0,u=-1/0;for(i=0;id&&(d=n),su&&(u=s));if(h>d||l>u)return this;for(this.cover(h,l).cover(d,u),i=0;it||t>=s||n>e||e>=o;)switch(a=(ec||(o=h.y0)>_||(r=h.x1)=m)<<1|t>=p)&&(h=f[f.length-1],f[f.length-1]=f[f.length-1-l],f[f.length-1-l]=h)}else{var v=t-+this._x.call(null,g.data),y=e-+this._y.call(null,g.data),x=v*v+y*y;if(x=(a=(f+p)/2))?f=a:p=a,(d=r>=(h=(g+m)/2))?g=h:m=h,e=_,!(_=_[u=d<<1|l]))return this;if(!_.length)break;(e[u+1&3]||e[u+2&3]||e[u+3&3])&&(i=e,c=u)}for(;_.data!==t;)if(n=_,!(_=_.next))return this;return(s=_.next)&&delete _.next,n?(s?n.next=s:delete n.next,this):e?(s?e[u]=s:delete e[u],(_=e[0]||e[1]||e[2]||e[3])&&_===(e[3]||e[2]||e[1]||e[0])&&!_.length&&(i?i[c]=_:this._root=_),this):(this._root=s,this)},$n.removeAll=function(t){for(var e=0,i=t.length;e100*(t>0?t:1),es={useGPU:!1,isSimulatingOnDataUpdate:!0,isSimulatingOnSettingsUpdate:!0,isSimulatingOnUnstick:!0,isPhysicsEnabled:!1,alpha:{alpha:1,alphaMin:.05,alphaDecay:.028,alphaTarget:0},centering:{x:0,y:0,strength:1},collision:{radius:15,strength:1,iterations:1},links:{distance:50,strength:1,iterations:1},manyBody:{strength:-100,theta:.9,distanceMin:1,distanceMax:ts(50)},positioning:{forceX:{x:0,strength:.1},forceY:{y:0,strength:.1}},anchorX:"center",anchorY:"center"},is={rowGap:50,colGap:50},ns={nodeGap:50,levelGap:50,treeGap:100,orientation:"vertical",reversed:!1};class ss extends t{constructor(){super(...arguments),this._nodes=[],this._edges=[],this._nodeIndexByNodeId={},this._cancelSimulation=!1,this._schedulerPort=null}terminate(){var t;this._cancelSimulation=!0,null===(t=this._schedulerPort)||void 0===t||t.close(),this._schedulerPort=null,this.removeAllListeners()}_scheduleNext(t){if("undefined"!=typeof MessageChannel){const e=new MessageChannel;this._schedulerPort=e.port2,e.port1.onmessage=()=>{this._schedulerPort=null,t()},e.port2.postMessage(null)}else setTimeout(t,0)}_rebuildNodeIndex(){this._nodeIndexByNodeId={};for(let t=0;t0&&this.activateSimulation())}setupData(t){this.clearData(),this._initializeNewData(t),this._settings.isSimulatingOnDataUpdate&&(this._updateSimulationData(),this._runSimulation())}mergeData(t){this._initializeNewData(t),this._settings.isPhysicsEnabled||this._pinNodes(),this._settings.isSimulatingOnDataUpdate&&(this._updateSimulationData(),this.activateSimulation())}updateData(t){const e=new Set(t.nodes.map(t=>t.id)),i=this._nodes.filter(t=>e.has(t.id)),n=t.nodes.filter(t=>void 0===this._nodeIndexByNodeId[t.id]);this._nodes=[...i,...n],this._rebuildNodeIndex(),this._edges=t.edges,this._settings.isSimulatingOnSettingsUpdate&&(this._updateSimulationData(),this.activateSimulation())}deleteData(t){if(t.nodeIds){const e=new Set(t.nodeIds);this._nodes=this._nodes.filter(t=>!e.has(t.id))}if(t.edgeIds){const e=new Set(t.edgeIds);this._edges=this._edges.filter(t=>!e.has(t.id))}this._rebuildNodeIndex(),this._settings.isSimulatingOnDataUpdate&&(this._updateSimulationData(),this.activateSimulation())}patchData(t){if(t.nodes){const e={};for(let t=0;t0&&this.activateSimulation()}terminate(){var t;super.terminate(),null===(t=this._simulation)||void 0===t||t.stop()}_resetSimulation(){this._simulation&&(this._simulation.stop(),this._simulation.on("tick",null).on("end",null)),this._linkForce=function(t){var e,i,n,s,o,r,a=Bn,h=function(t){return 1/Math.min(s[t.source.index],s[t.target.index])},l=On(30),d=1;function u(n){for(var s=0,a=t.length;s[a(t,e,n),t]));for(r=0,s=new Array(l);rt.id),this._simulation=function(t){var e,i=1,n=.001,s=1-Math.pow(n,1/300),o=0,r=.6,a=new Map,h=je(u),l=Q("tick","end"),d=function(){let t=1;return()=>(t=(1664525*t+1013904223)%Un)/Un}();function u(){c(),l.call("tick",e),i1?(null==i?a.delete(t):a.set(t,f(i)),e):a.get(t)},find:function(e,i,n){var s,o,r,a,h,l=0,d=t.length;for(null==n?n=1/0:n*=n,l=0;l1?(l.on(t,i),e):l.on(t)}}}(this._nodes).force("link",this._linkForce).stop(),this._applySettingsToSimulation(this._settings),this._simulation.on("tick",()=>{this.emit(Ln.SIMULATION_STEP,{nodes:this._nodes,edges:this._edges})}),this._simulation.on("end",()=>{this._isDragging=!1,this._isStabilizing=!1,this.emit(Ln.SIMULATION_END,{nodes:this._nodes,edges:this._edges}),this._settings.isPhysicsEnabled||this._pinNodes()})}_runSimulation(t){if(this._isStabilizing||this._cancelSimulation)return;(this._settings.isPhysicsEnabled||(null==t?void 0:t.isUpdatingSettings))&&this._unpinNodes(),this.emit(Ln.SIMULATION_START,void 0),this._isStabilizing=!0,this._simulation.alpha(this._settings.alpha.alpha).alphaTarget(this._settings.alpha.alphaTarget).stop();const e=Math.min(500,Math.ceil(Math.log(this._settings.alpha.alphaMin)/Math.log(1-this._settings.alpha.alphaDecay)));let i=-1,n=0;const s=()=>{if(this._cancelSimulation)return this._isStabilizing=!1,void(this._cancelSimulation=!1);const t=Math.min(n+100,e);for(;ni&&(i=t,this.emit(Ln.SIMULATION_PROGRESS,{nodes:this._nodes,edges:this._edges,progress:t/100}))}nl+f||od+f||rh.index){var g=l-a.x-a.vx,p=d-a.y-a.vy,m=g*g+p*p;mt.r&&(t.r=t[e].r)}function h(){if(e){var n,s,o=e.length;for(i=new Array(o),n=0;n=a)){(t.data!==e||t.next)&&(0===u&&(f+=(u=kn(i))*u),0===c&&(f+=(c=kn(i))*c),f=s)continue;h<1&&(h=1);const u=-t*e/h;o.vx+=r*u,o.vy+=a*u}}}return o.initialize=t=>{n=t},o}(t.manyBody.strength,t.manyBody.distanceMax,()=>this._edges)):this._simulation.force("edgeMidpointRepulsion",null)}if(null===t.manyBody&&(this._simulation.force("charge",null),this._simulation.force("edgeMidpointRepulsion",null)),null===(e=t.positioning)||void 0===e?void 0:e.forceX){const e=function(t){var e,i,n,s=On(.1);function o(t){for(var s,o=0,r=e.length;o{const n=t.createShader(i===rs.VERTEX?t.VERTEX_SHADER:t.FRAGMENT_SHADER);if(!n)throw new o("Failed to create shader.");if(t.shaderSource(n,e),t.compileShader(n),!t.getShaderParameter(n,t.COMPILE_STATUS)){const e=t.getShaderInfoLog(n);throw t.deleteShader(n),new o(`Failed to compile shader: ${e}`)}return n};class hs extends ss{constructor(t){super(),this._isStabilizing=!1,this._isDragging=!1,this._dragLoopRunning=!1,this._pendingRestart=!1,this._simulationGeneration=0,this._currentAlpha=0,this._currentStep=0,this._totalSteps=0,this._dragAlpha=0,this._dragNeedsReheat=!1,this._dirtyNodes=new Set,this._forceProgram=null,this._quadBuffer=null,this._quadVAO=null,this._stateTexA=null,this._stateTexB=null,this._fixedTex=null,this._fboA=null,this._fboB=null,this._texWidth=0,this._treeDataTexture=null,this._treeChildrenTexture=null,this._treeGeometryTexture=null,this._adjOffsetsTexture=null,this._adjEdgesTexture=null,this._cachedAdjacency=null,this._treeTexWidth=1,this._treeNodeCount=0,this._pingPong=!0,this._uniforms={},this.type="force",this._settings=Object.assign(Object.assign({},es),t);const e=document.createElement("canvas").getContext("webgl2");if(!e)throw new o("Failed to create WebGL2 context for GPU force layout engine.");this._gl=e,this._initGPU(),this.clearData()}setSettings(t){const e=t;this._initialSettings||(this._initialSettings=Object.assign(p(es),e));const i=p(this._settings);Object.assign(this._settings,e),m(this._settings,i)||(this.emit(Ln.SETTINGS_UPDATE,{settings:{type:"force",options:this._settings}}),i.isPhysicsEnabled&&!e.isPhysicsEnabled?this.stopSimulation():this._settings.isSimulatingOnSettingsUpdate&&this._nodes.length>0&&this.activateSimulation())}setupData(t){this.clearData(),this._initializeNewData(t),this._settings.isSimulatingOnDataUpdate&&this._runSimulation()}mergeData(t){this._initializeNewData(t),this._settings.isPhysicsEnabled||this._pinNodes(),this._settings.isSimulatingOnDataUpdate&&this.activateSimulation()}updateData(t){const e=new Set(t.nodes.map(t=>t.id)),i=this._nodes.filter(t=>e.has(t.id)),n=t.nodes.filter(t=>void 0===this._nodeIndexByNodeId[t.id]);this._nodes=[...i,...n],this._rebuildNodeIndex(),this._edges=t.edges,this._cachedAdjacency=null,this._settings.isSimulatingOnSettingsUpdate&&this.activateSimulation()}deleteData(t){if(t.nodeIds){const e=new Set(t.nodeIds);this._nodes=this._nodes.filter(t=>!e.has(t.id))}if(t.edgeIds){const e=new Set(t.edgeIds);this._edges=this._edges.filter(t=>!e.has(t.id))}this._rebuildNodeIndex(),this._cachedAdjacency=null,this._settings.isSimulatingOnDataUpdate&&this.activateSimulation()}patchData(t){if(t.nodes){const e={};for(let t=0;t0&&this.activateSimulation()}terminate(){var t;super.terminate();const e=this._gl;e&&(e.deleteBuffer(this._quadBuffer),e.deleteVertexArray(this._quadVAO),e.deleteProgram(this._forceProgram),e.deleteTexture(this._stateTexA),e.deleteTexture(this._stateTexB),e.deleteTexture(this._fixedTex),e.deleteTexture(this._treeDataTexture),e.deleteTexture(this._treeChildrenTexture),e.deleteTexture(this._treeGeometryTexture),e.deleteTexture(this._adjOffsetsTexture),e.deleteTexture(this._adjEdgesTexture),e.deleteFramebuffer(this._fboA),e.deleteFramebuffer(this._fboB),null===(t=e.getExtension("WEBGL_lose_context"))||void 0===t||t.loseContext())}reheat(){const t=this._settings.alpha;this._currentAlpha=t.alpha,this._totalSteps=Math.min(500,Math.ceil(Math.log(t.alphaMin)/Math.log(1-t.alphaDecay))),this._currentStep=0,this._isStabilizing||(this._ensurePositions(),this._uploadDataToGPU(),this._cachedAdjacency||this._buildAndUploadAdjacency(),this._startSimulationLoop())}_runSimulation(){this._isStabilizing||this._cancelSimulation||(this._ensurePositions(),this._uploadDataToGPU(),this._buildAndUploadAdjacency(),this._startSimulationLoop())}_startDragLoop(){if(this._dragLoopRunning)return;this._dragLoopRunning=!0;const t=this._settings.alpha.alphaDecay,e=this._settings.alpha.alphaMin;this._dragAlpha=.3,this._dragNeedsReheat=!1;const i=()=>{this._isDragging?(this._dragNeedsReheat&&(this._dragAlpha=.3,this._dragNeedsReheat=!1),this._dragAlpha+=(0-this._dragAlpha)*t,this._dragAlpha{if(t!==this._simulationGeneration)return;if(this._cancelSimulation)return this._isStabilizing=!1,this._cancelSimulation=!1,void this.emit(Ln.SIMULATION_END,{nodes:this._nodes,edges:this._edges});if(this._readbackFromGPU(),this._pendingRestart)return this._isStabilizing=!1,this._pendingRestart=!1,this._ensurePositions(),this._uploadDataToGPU(),this._cachedAdjacency||this._buildAndUploadAdjacency(),void this._startSimulationLoop();this._flushDirtyNodes(),this._buildAndUploadQuadTree();const r=Math.min(this._currentStep+1,this._totalSteps);for(;this._currentSteps&&(s=a,this.emit(Ln.SIMULATION_PROGRESS,{nodes:this._nodes,edges:this._edges,progress:a/100})),this._currentStep0&&(s=s.concat(t))}const o=function(t,e){var i,n;const s=t.length;if(0===s)return{treeData:new Float32Array(0),treeChildren:new Float32Array(0),treeGeometry:new Float32Array(0),nodeCount:0,texWidth:1};let o=1/0,r=1/0,a=-1/0,h=-1/0;for(let e=0;ea&&(a=i),n>h&&(h=n)}let l=Math.max(a-o,h-r);l<1e-6&&(l=1),l*=1.01;const d=.5*l,u=.5*(o+a)-d,c=.5*(r+h)-d,_=[];function f(t){const e=_.length;return _.push({cx:0,cy:0,charge:0,size:t,bodyIndex:-1,children:[null,null,null,null]}),e}const g=f(l),p=[u],m=[c];function v(t,e,i,n,s){return 2*(e>=n+.5*s?1:0)+(t>=i+.5*s?1:0)}function y(t,e,i,n){const s=.5*n;return{cx0:1&t?e+s:e,cy0:2&t?i+s:i,csz:s}}function x(t,i,n){let s=g,o=u,r=c,a=l;for(let h=0;h<50;h++){const h=_[s];if(-1===h.bodyIndex&&null===h.children[0]&&null===h.children[1]&&null===h.children[2]&&null===h.children[3])return h.bodyIndex=t,h.cx=i,h.cy=n,void(h.charge=e);if(h.bodyIndex>=0){const t=h.bodyIndex,i=h.cx,n=h.cy;h.bodyIndex=-1;const s=v(i,n,o,r,a),{cx0:l,cy0:d,csz:u}=y(s,o,r,a),c=f(u);p[c]=l,m[c]=d,h.children[s]=c,_[c].bodyIndex=t,_[c].cx=i,_[c].cy=n,_[c].charge=e}const l=v(i,n,o,r,a);if(null===h.children[l]){const{cx0:s,cy0:d,csz:u}=y(l,o,r,a),c=f(u);return p[c]=s,m[c]=d,h.children[l]=c,_[c].bodyIndex=t,_[c].cx=i,_[c].cy=n,void(_[c].charge=e)}const{cx0:d,cy0:u,csz:c}=y(l,o,r,a);s=h.children[l],o=d,r=u,a=c}}for(let e=0;e=0)return;let n=0,s=0,o=0,r=0;for(let e=0;e<4;e++){const a=i.children[e];if(null===a)continue;t(a);const h=_[a],l=Math.abs(h.charge);n+=h.charge,s+=h.cx*l,o+=h.cy*l,r+=l}r>0&&(i.cx=s/r,i.cy=o/r),i.charge=n}(g);const b=_.length,S=Math.ceil(Math.sqrt(b)),w=S*S,T=new Float32Array(4*w),E=new Float32Array(4*w),P=new Float32Array(4*w);for(let t=0;t=0?T[s+3]=-(e.bodyIndex+1):T[s+3]=e.size,E[s]=null!==e.children[0]?e.children[0]:-1,E[s+1]=null!==e.children[1]?e.children[1]:-1,E[s+2]=null!==e.children[2]?e.children[2]:-1,E[s+3]=null!==e.children[3]?e.children[3]:-1,P[s]=null!==(i=p[t])&&void 0!==i?i:0,P[s+1]=null!==(n=m[t])&&void 0!==n?n:0,P[s+2]=e.size,P[s+3]=0}for(let t=b;t= uNodeCount) {\n fragColor = vec4(0.0);\n return;\n }\n\n vec4 fixedData = texelFetch(uFixed, fc, 0);\n if (fixedData.x > 0.5) {\n fragColor = vec4(fixedData.yz, 0.0, 0.0);\n return;\n }\n\n vec4 state = texelFetch(uState, fc, 0);\n vec2 pos = state.xy;\n vec2 vel = state.zw;\n\n if (uHasManyBody > 0.5 && uTreeNodeCount > 0) {\n int stack[128];\n int top = 0;\n stack[top++] = 0;\n\n while (top > 0) {\n int idx = stack[--top];\n vec4 data = texelFetch(uTreeData, texCoord(idx, uTreeTexWidth), 0);\n float w = data.w;\n\n if (w < -0.5) {\n int bodyIdx = int(-w - 0.5);\n if (bodyIdx != nodeId) {\n vec2 delta = data.xy - pos;\n float distSq = dot(delta, delta);\n\n if (distSq < 1e-8) {\n delta = vec2(float(nodeId) * 1e-4 - float(bodyIdx) * 1e-4 + 1e-4, 1e-4);\n distSq = dot(delta, delta);\n }\n\n if (distSq < uDistanceMax2) {\n float l = distSq;\n if (l < uDistanceMin2) l = sqrt(uDistanceMin2 * l);\n vel += delta * (data.z * uAlpha / max(l, 1e-6));\n }\n }\n } else {\n vec2 delta = data.xy - pos;\n float distSq = dot(delta, delta);\n\n if (distSq > 0.0 && w * w / distSq < uTheta2) {\n if (distSq < uDistanceMax2) {\n float l = distSq;\n if (l < uDistanceMin2) l = sqrt(uDistanceMin2 * l);\n vel += delta * (data.z * uAlpha / max(l, 1e-6));\n }\n } else {\n vec4 ch = texelFetch(uTreeChildren, texCoord(idx, uTreeTexWidth), 0);\n if (ch.w >= 0.0 && top < 64) stack[top++] = int(ch.w + 0.5);\n if (ch.z >= 0.0 && top < 64) stack[top++] = int(ch.z + 0.5);\n if (ch.y >= 0.0 && top < 64) stack[top++] = int(ch.y + 0.5);\n if (ch.x >= 0.0 && top < 64) stack[top++] = int(ch.x + 0.5);\n }\n }\n }\n }\n\n if (uHasCollision > 0.5 && uCollisionRadius > 0.0 && uTreeNodeCount > 0) {\n float collisionDiam = uCollisionRadius * 2.0;\n vec2 predictedPos = state.xy + state.zw;\n int stack[64];\n int top = 0;\n stack[top++] = 0;\n\n while (top > 0) {\n int idx = stack[--top];\n vec4 data = texelFetch(uTreeData, texCoord(idx, uTreeTexWidth), 0);\n float w = data.w;\n\n if (w < -0.5) {\n int bodyIdx = int(-w - 0.5);\n if (bodyIdx != nodeId && bodyIdx < uNodeCount) {\n vec2 delta = data.xy - predictedPos;\n float dist = length(delta);\n\n if (dist < collisionDiam && dist > 0.0) {\n float push = (collisionDiam - dist) * uCollisionStrength;\n vel -= (delta / dist) * push * 0.5;\n }\n }\n } else {\n vec4 geo = texelFetch(uTreeGeometry, texCoord(idx, uTreeTexWidth), 0);\n float cellSize = geo.z;\n vec2 nearest = clamp(predictedPos, geo.xy, geo.xy + cellSize);\n float distToCell = length(nearest - predictedPos);\n\n if (distToCell < collisionDiam) {\n vec4 ch = texelFetch(uTreeChildren, texCoord(idx, uTreeTexWidth), 0);\n if (ch.w >= 0.0 && top < 64) stack[top++] = int(ch.w + 0.5);\n if (ch.z >= 0.0 && top < 64) stack[top++] = int(ch.z + 0.5);\n if (ch.y >= 0.0 && top < 64) stack[top++] = int(ch.y + 0.5);\n if (ch.x >= 0.0 && top < 64) stack[top++] = int(ch.x + 0.5);\n }\n }\n }\n }\n\n if (uHasLinks > 0.5) {\n vec4 offData = texelFetch(uAdjOffsets, texCoord(nodeId, uAdjOffsetsTexWidth), 0);\n int start = int(offData.x + 0.5);\n int count = int(offData.y + 0.5);\n\n for (int e = 0; e < count; e++) {\n vec4 edgeData = texelFetch(uAdjEdges, texCoord(start + e, uAdjEdgesTexWidth), 0);\n int targetId = int(edgeData.x + 0.5);\n float restDist = edgeData.y;\n float strength = edgeData.z;\n float dirBias = edgeData.w;\n\n vec4 targetState = texelFetch(uState, texCoord(targetId, uTexWidth), 0);\n vec2 delta = (targetState.xy + targetState.zw) - (state.xy + state.zw);\n float d = length(delta);\n\n if (d < 1e-6) {\n delta = vec2(1e-3, 1e-3);\n d = length(delta);\n }\n\n float scale = (d - restDist) / d * uAlpha * strength;\n vel += delta * scale * dirBias;\n }\n }\n\n if (uHasCentering > 0.5) {\n vel += (uCenter - pos) * uCenterStrength * uAlpha;\n }\n\n if (uHasPositioning > 0.5) {\n vel.x += (uForceXTarget - pos.x) * uForceXStrength * uAlpha;\n vel.y += (uForceYTarget - pos.y) * uForceYStrength * uAlpha;\n }\n\n vel *= uDamping;\n pos += vel;\n\n fragColor = vec4(pos, vel);\n}\n",rs.FRAGMENT),n=t.createProgram();if(!n)throw new o("Failed to create program.");if(this._forceProgram=n,t.attachShader(n,e),t.attachShader(n,i),t.linkProgram(n),!t.getProgramParameter(n,t.LINK_STATUS)){const e=t.getProgramInfoLog(n);throw new o(`Failed to link force program: ${e}`)}this._cacheUniformLocations(n),this._quadBuffer=t.createBuffer();const s=new Float32Array([-1,-1,1,-1,-1,1,1,1]);t.bindBuffer(t.ARRAY_BUFFER,this._quadBuffer),t.bufferData(t.ARRAY_BUFFER,s,t.STATIC_DRAW),this._quadVAO=t.createVertexArray(),t.bindVertexArray(this._quadVAO);const r=t.getAttribLocation(n,"aPosition");t.enableVertexAttribArray(r),t.vertexAttribPointer(r,2,t.FLOAT,!1,0,0),t.bindVertexArray(null),this._stateTexA=t.createTexture(),this._stateTexB=t.createTexture(),this._fixedTex=t.createTexture(),this._treeDataTexture=t.createTexture(),this._treeChildrenTexture=t.createTexture(),this._treeGeometryTexture=t.createTexture(),this._adjOffsetsTexture=t.createTexture(),this._adjEdgesTexture=t.createTexture(),this._fboA=t.createFramebuffer(),this._fboB=t.createFramebuffer()}_cacheUniformLocations(t){const e=this._gl,i=["uState","uFixed","uTreeData","uTreeChildren","uTreeGeometry","uAdjOffsets","uAdjEdges","uNodeCount","uTexWidth","uAlpha","uDamping","uManyBodyStrength","uTheta2","uDistanceMin2","uDistanceMax2","uTreeNodeCount","uTreeTexWidth","uAdjOffsetsTexWidth","uAdjEdgesTexWidth","uCenter","uCenterStrength","uCollisionRadius","uCollisionStrength","uForceXTarget","uForceXStrength","uForceYTarget","uForceYStrength","uHasManyBody","uHasLinks","uHasCentering","uHasCollision","uHasPositioning"];for(const n of i)this._uniforms[n]=e.getUniformLocation(t,n)}_uploadDataToGPU(){var t,e,i,n,s,o,r,a;const h=this._gl,l=this._nodes.length;this._texWidth=Math.max(1,Math.ceil(Math.sqrt(l)));const d=this._texWidth*this._texWidth,u=new Float32Array(4*d),c=new Float32Array(4*d);for(let h=0;h0?t.distanceMax:ts(null!==(i=null===(e=this._settings.links)||void 0===e?void 0:e.distance)&&void 0!==i?i:50);c.uniform1f(g.uDistanceMax2,s*s),c.uniform1i(g.uTreeNodeCount,this._treeNodeCount),c.uniform1i(g.uTreeTexWidth,this._treeTexWidth)}const m=null!==this._cachedAdjacency&&this._edges.length>0;c.uniform1f(g.uHasLinks,m?1:0),m&&(c.uniform1i(g.uAdjOffsetsTexWidth,this._cachedAdjacency.offsetsTexWidth),c.uniform1i(g.uAdjEdgesTexWidth,this._cachedAdjacency.edgesTexWidth)),c.uniform1f(g.uHasCentering,0);const v=null!==this._settings.collision&&void 0!==this._settings.collision;c.uniform1f(g.uHasCollision,v?1:0),v&&(c.uniform1f(g.uCollisionRadius,this._settings.collision.radius),c.uniform1f(g.uCollisionStrength,this._settings.collision.strength));const y=null!==this._settings.positioning&&void 0!==this._settings.positioning;if(c.uniform1f(g.uHasPositioning,y?1:0),y){const t=this._settings.positioning;c.uniform1f(g.uForceXTarget,null!==(s=null===(n=t.forceX)||void 0===n?void 0:n.x)&&void 0!==s?s:0),c.uniform1f(g.uForceXStrength,null!==(a=null===(r=t.forceX)||void 0===r?void 0:r.strength)&&void 0!==a?a:0),c.uniform1f(g.uForceYTarget,null!==(l=null===(h=t.forceY)||void 0===h?void 0:h.y)&&void 0!==l?l:0),c.uniform1f(g.uForceYStrength,null!==(u=null===(d=t.forceY)||void 0===d?void 0:d.strength)&&void 0!==u?u:0)}const x=this._pingPong?this._stateTexA:this._stateTexB,b=this._pingPong?this._fboB:this._fboA;c.activeTexture(c.TEXTURE0),c.bindTexture(c.TEXTURE_2D,x),c.uniform1i(g.uState,0),c.activeTexture(c.TEXTURE1),c.bindTexture(c.TEXTURE_2D,this._fixedTex),c.uniform1i(g.uFixed,1),c.activeTexture(c.TEXTURE2),c.bindTexture(c.TEXTURE_2D,this._treeDataTexture),c.uniform1i(g.uTreeData,2),c.activeTexture(c.TEXTURE3),c.bindTexture(c.TEXTURE_2D,this._treeChildrenTexture),c.uniform1i(g.uTreeChildren,3),c.activeTexture(c.TEXTURE4),c.bindTexture(c.TEXTURE_2D,this._adjOffsetsTexture),c.uniform1i(g.uAdjOffsets,4),c.activeTexture(c.TEXTURE5),c.bindTexture(c.TEXTURE_2D,this._adjEdgesTexture),c.uniform1i(g.uAdjEdges,5),c.activeTexture(c.TEXTURE6),c.bindTexture(c.TEXTURE_2D,this._treeGeometryTexture),c.uniform1i(g.uTreeGeometry,6),c.bindFramebuffer(c.FRAMEBUFFER,b),c.viewport(0,0,this._texWidth,this._texWidth),c.bindVertexArray(this._quadVAO),c.drawArrays(c.TRIANGLE_STRIP,0,4),c.bindVertexArray(null),c.bindFramebuffer(c.FRAMEBUFFER,null),this._pingPong=!this._pingPong}_readbackFromGPU(){const t=this._gl,e=this._nodes.length;if(0===e)return;const i=this._pingPong?this._fboA:this._fboB,n=this._texWidth*this._texWidth,s=new Float32Array(4*n);t.bindFramebuffer(t.FRAMEBUFFER,i),t.readPixels(0,0,this._texWidth,this._texWidth,t.RGBA,t.FLOAT,s),t.bindFramebuffer(t.FRAMEBUFFER,null);for(let t=0;tt.id)),i=this._nodes.filter(t=>e.has(t.id)),n=t.nodes.filter(t=>void 0===this._nodeIndexByNodeId[t.id]);this._nodes=[...i,...n],this._edges=t.edges,this._rebuildNodeIndex(),this._calculateAndEmit()}deleteData(t){if(t.nodeIds){const e=new Set(t.nodeIds);this._nodes=this._nodes.filter(t=>!e.has(t.id))}if(t.edgeIds){const e=new Set(t.edgeIds);this._edges=this._edges.filter(t=>!e.has(t.id))}this._rebuildNodeIndex(),this._calculateAndEmit()}patchData(t){if(t.nodes)for(let e=0;e0&&this._calculateAndEmit()}terminate(){this._pendingRecalculation=!1,super.terminate()}_calculateAndEmit(){0===this._nodes.length||this._cancelSimulation||(this._isCalculating?this._pendingRecalculation=!0:(this._isCalculating=!0,this.emit(Ln.SIMULATION_START,void 0),this.calculatePositions(this._nodes,this._edges,t=>{this.emit(Ln.SIMULATION_PROGRESS,{nodes:this._nodes,edges:this._edges,progress:t})},()=>this._cancelSimulation,()=>{this._isCalculating=!1,this._cancelSimulation||this.emit(Ln.SIMULATION_END,{nodes:this._nodes,edges:this._edges}),this._cancelSimulation=!1,this._pendingRecalculation&&(this._pendingRecalculation=!1,this._calculateAndEmit())})))}_emitProgress(t,e,i,n){const s=Math.round(100*t/e);return s>i?(n(s/100),s):i}}class ds extends ls{constructor(t){super(),this.type="circular",this._config=Object.assign(Object.assign({},Jn),t)}calculatePositions(t,e,i,n,s){const o=2*Math.PI/t.length;let r=-1,a=0;const h=()=>{if(n())return void s();const e=Math.min(a+5e3,t.length);for(;a{if(n())return void s();const e=Math.min(h+5e3,t.length);for(;h{if(n()||c>=a.length)return!n()&&this._config.reversed&&this._applyReversal(t,h,l),void s();const e=this._assignLevels(a[c],o,r),f=Math.max(...Array.from(e.values()).map(t=>t.length));e.size*this._config.levelGap>l&&(l=e.size*this._config.levelGap);let g=0===c?0:this._config.treeGap+h;c>0&&(g+=(f-1)*this._config.nodeGap/2);for(let i=0;ih&&(h=a),void 0!==r&&(t[r].x="horizontal"===this._config.orientation?n:a,t[r].y="horizontal"===this._config.orientation?a:n),d++}}c++,c0;){const t=h.pop();if(void 0===t)continue;a.push(t);const s=null!==(i=e.get(t))&&void 0!==i?i:[];for(let t=0;t{var e;return 0===(null!==(e=i.get(t))&&void 0!==e?e:0)});void 0===a&&(a=t.reduce((t,e)=>{var n,s;return(null!==(n=i.get(e))&&void 0!==n?n:0)<(null!==(s=i.get(t))&&void 0!==s?s:0)?e:t}));const h=[[a,0]];for(const[t,i]of h){if(r.has(t))continue;r.add(t),o.has(i)?null===(n=o.get(i))||void 0===n||n.push(t):o.set(i,[t]);const a=null!==(s=e.get(t))&&void 0!==s?s:[];for(let t=0;t{this._isSimulationRunning=t})}}var gs,ps;!function(t){t.SetupData="Set Data",t.MergeData="Add Data",t.UpdateData="Update Data",t.DeleteData="Delete Data",t.PatchData="Patch Data",t.ClearData="Clear Data",t.ActivateSimulation="Activate Simulation",t.UpdateSimulation="Update Simulation",t.StopSimulation="Stop Simulation",t.StartDragNode="Start Drag Node",t.DragNode="Drag Node",t.EndDragNode="End Drag Node",t.FixNodes="Fix Nodes",t.ReleaseNodes="Release Nodes",t.SetSettings="Set Settings"}(gs||(gs={})),function(t){t.READY="ready",t.SIMULATION_START="simulation-start",t.SIMULATION_STEP="simulation-step",t.SIMULATION_PROGRESS="simulation-progress",t.SIMULATION_END="simulation-end",t.SIMULATION_TICK="simulation-tick",t.NODE_DRAG="node-drag",t.NODE_DRAG_END="node-drag-end",t.SETTINGS_UPDATE="settings-update"}(ps||(ps={}));class ms extends t{constructor(t){let e;super(),this._isSimulationRunning=!1,this._fallback=null,this._ready=!1,this._pending=[],this._hasWarned=!1,this._handleWorkerMessage=({data:t})=>{switch(t.type){case ps.READY:this._markReady();break;case ps.SIMULATION_START:this.emit(Ln.SIMULATION_START,void 0),this._isSimulationRunning=!0;break;case ps.SIMULATION_PROGRESS:this.emit(Ln.SIMULATION_PROGRESS,t.data);break;case ps.SIMULATION_END:this.emit(Ln.SIMULATION_END,t.data),this._isSimulationRunning=!1;break;case ps.SIMULATION_STEP:this.emit(Ln.SIMULATION_STEP,t.data);break;case ps.NODE_DRAG:this.emit(Ln.NODE_DRAG,t.data);break;case ps.NODE_DRAG_END:this.emit(Ln.NODE_DRAG_END,t.data);break;case ps.SETTINGS_UPDATE:this.emit(Ln.SETTINGS_UPDATE,t.data)}},this._settings=t;try{this._blobUrl=URL.createObjectURL(new Blob(['"use strict";(()=>{function Ee(n,r){var e,t=1;n==null&&(n=0),r==null&&(r=0);function i(){var o,s=e.length,a,u=0,l=0;for(o=0;o=(_=(a+l)/2))?a=_:l=_,(h=e>=(m=(u+c)/2))?u=m:c=m,i=o,!(o=o[p=h<<1|f]))return i[p]=s,n;if(d=+n._x.call(null,o.data),g=+n._y.call(null,o.data),r===d&&e===g)return s.next=o,i?i[p]=s:n._root=s,n;do i=i?i[p]=new Array(4):n._root=new Array(4),(f=r>=(_=(a+l)/2))?a=_:l=_,(h=e>=(m=(u+c)/2))?u=m:c=m;while((p=h<<1|f)===(y=(g>=m)<<1|d>=_));return i[y]=o,i[p]=s,n}function Be(n){var r,e,t=n.length,i,o,s=new Array(t),a=new Array(t),u=1/0,l=1/0,c=-1/0,_=-1/0;for(e=0;ec&&(c=i),o_&&(_=o));if(u>c||l>_)return this;for(this.cover(u,l).cover(c,_),e=0;en||n>=i||t>r||r>=o;)switch(l=(rc||(a=g.y0)>_||(u=g.x1)=p)<<1|n>=h)&&(g=m[m.length-1],m[m.length-1]=m[m.length-1-f],m[m.length-1-f]=g)}else{var y=n-+this._x.call(null,d.data),T=r-+this._y.call(null,d.data),x=y*y+T*T;if(x=(m=(s+u)/2))?s=m:u=m,(f=_>=(d=(a+l)/2))?a=d:l=d,r=e,!(e=e[h=f<<1|g]))return this;if(!e.length)break;(r[h+1&3]||r[h+2&3]||r[h+3&3])&&(t=r,p=h)}for(;e.data!==n;)if(i=e,!(e=e.next))return this;return(o=e.next)&&delete e.next,i?(o?i.next=o:delete i.next,this):r?(o?r[h]=o:delete r[h],(e=r[0]||r[1]||r[2]||r[3])&&e===(r[3]||r[2]||r[1]||r[0])&&!e.length&&(t?t[p]=e:this._root=e),this):(this._root=o,this)}function He(n){for(var r=0,e=n.length;rm.index){var M=d-D.x-D.vx,v=g-D.y-D.vy,S=M*M+v*v;Sd+b||Eg+b||Pl.r&&(l.r=l[c].r)}function u(){if(r){var l,c=r.length,_;for(e=new Array(c),l=0;l[r(I,E,s),I])),x;for(h=0,a=new Array(p);h{}};function rt(){for(var n=0,r=arguments.length,e={},t;n=0&&(t=e.slice(i+1),e=e.slice(0,i)),e&&!r.hasOwnProperty(e))throw new Error("unknown type: "+e);return{type:e,name:t}})}le.prototype=rt.prototype={constructor:le,on:function(n,r){var e=this._,t=Rt(n+"",e),i,o=-1,s=t.length;if(arguments.length<2){for(;++o0)for(var e=new Array(i),t=0,i,o;t=0&&n._call.call(void 0,r),n=n._next;--J}function st(){Z=(de=oe.now())+ce,J=ie=0;try{ut()}finally{J=0,Gt(),Z=0}}function Ft(){var n=oe.now(),r=n-de;r>at&&(ce-=r,de=n)}function Gt(){for(var n,r=ue,e,t=1/0;r;)r._call?(t>r._time&&(t=r._time),n=r,r=r._next):(e=r._next,r._next=null,r=n?n._next=e:ue=e);ne=n,Le(t)}function Le(n){if(!J){ie&&(ie=clearTimeout(ie));var r=n-Z;r>24?(n<1/0&&(ie=setTimeout(st,n-oe.now()-ce)),te&&(te=clearInterval(te))):(te||(de=oe.now(),te=setInterval(Ft,at)),J=1,lt(st))}}function dt(){let n=1;return()=>(n=(1664525*n+1013904223)%4294967296)/4294967296}function ct(n){return n.x}function ht(n){return n.y}var kt=10,Wt=Math.PI*(3-Math.sqrt(5));function Me(n){var r,e=1,t=.001,i=1-Math.pow(t,1/300),o=0,s=.6,a=new Map,u=he(_),l=Ae("tick","end"),c=dt();n==null&&(n=[]);function _(){m(),l.call("tick",r),e1?(h==null?a.delete(f):a.set(f,g(h)),r):a.get(f)},find:function(f,h,p){var y=0,T=n.length,x,I,E,P,D;for(p==null?p=1/0:p*=p,y=0;y1?(l.on(f,h),r):l.on(f)}}}function Re(){var n,r,e,t,i=O(-30),o,s=1,a=1/0,u=.81;function l(d){var g,f=n.length,h=Q(n,ct,ht).visitAfter(_);for(t=d,g=0;g=a)return;(d.data!==r||d.next)&&(p===0&&(p=k(e),x+=p*p),y===0&&(y=k(e),x+=y*y),xn instanceof Date,pe=n=>Array.isArray(n),me=n=>n!==null&&typeof n=="object"&&n.constructor.name==="Object";var C=n=>fe(n)?Ct(n):pe(n)?Bt(n):me(n)?Kt(n):n,j=(n,r)=>{let e=fe(n),t=fe(r);if(e&&!t||!e&&t)return!1;if(e&&t)return n.getTime()===r.getTime();let i=pe(n),o=pe(r);if(i&&!o||!i&&o)return!1;if(i&&o)return n.length!==r.length?!1:n.every((u,l)=>j(u,r[l]));let s=me(n),a=me(r);if(s&&!a||!s&&a)return!1;if(s&&a){let u=Object.keys(n),l=Object.keys(r);return j(u,l)?u.every(c=>j(n[c],r[c])):!1}return n===r},Ct=n=>new Date(n),Bt=n=>n.map(r=>C(r)),Kt=n=>{let r={};return Object.keys(n).forEach(e=>{r[e]=C(n[e])}),r};var pt={radius:100,centerX:0,centerY:0},zt=100,ft=50,Fe=n=>(n>0?n:1)*zt,ee={useGPU:!1,isSimulatingOnDataUpdate:!0,isSimulatingOnSettingsUpdate:!0,isSimulatingOnUnstick:!0,isPhysicsEnabled:!1,alpha:{alpha:1,alphaMin:.05,alphaDecay:.028,alphaTarget:0},centering:{x:0,y:0,strength:1},collision:{radius:15,strength:1,iterations:1},links:{distance:ft,strength:1,iterations:1},manyBody:{strength:-100,theta:.9,distanceMin:1,distanceMax:Fe(ft)},positioning:{forceX:{x:0,strength:.1},forceY:{y:0,strength:.1}},anchorX:"center",anchorY:"center"},mt={rowGap:50,colGap:50},gt={nodeGap:50,levelGap:50,treeGap:100,orientation:"vertical",reversed:!1};var ge=class{constructor(){this._listeners=new Map}once(r,e){let t={callable:e,isOnce:!0},i=this._listeners.get(r);return i?i.push(t):this._listeners.set(r,[t]),this}on(r,e){let t={callable:e},i=this._listeners.get(r);return i?i.push(t):this._listeners.set(r,[t]),this}off(r,e){let t=this._listeners.get(r);if(t){let i=t.filter(o=>o.callable!==e);this._listeners.set(r,i)}return this}emit(r,e){let t=this._listeners.get(r);if(!t||t.length===0)return!1;let i=!1;for(let o=0;o!s.isOnce);this._listeners.set(r,o)}return!0}eventNames(){return[...this._listeners.keys()]}listenerCount(r){let e=this._listeners.get(r);return e?e.length:0}listeners(r){let e=this._listeners.get(r);return e?e.map(t=>t.callable):[]}addListener(r,e){return this.on(r,e)}removeListener(r,e){return this.off(r,e)}removeAllListeners(r){return r?this._listeners.delete(r):this._listeners.clear(),this}};var Y=class extends ge{constructor(){super(...arguments);this._nodes=[];this._edges=[];this._nodeIndexByNodeId={};this._cancelSimulation=!1;this._schedulerPort=null}terminate(){this._cancelSimulation=!0,this._schedulerPort?.close(),this._schedulerPort=null,this.removeAllListeners()}_scheduleNext(e){if(typeof MessageChannel<"u"){let t=new MessageChannel;this._schedulerPort=t.port2,t.port1.onmessage=()=>{this._schedulerPort=null,e()},t.port2.postMessage(null)}else setTimeout(e,0)}_rebuildNodeIndex(){this._nodeIndexByNodeId={};for(let e=0;e=i)continue;p<1&&(p=1);let y=-n*s/p;g.vx+=f*y,g.vy+=h*y}}}return o.initialize=s=>{t=s},o}var re=class extends Y{constructor(e){super();this._isDragging=!1;this._isStabilizing=!1;this.type="force";this._settings={...ee,...e},this.clearData()}setSettings(e){let t=e;this._initialSettings||(this._initialSettings=Object.assign(C(ee),t));let i=C(this._settings);if(Object.assign(this._settings,t),j(this._settings,i))return;this._applySettingsToSimulation(t),this.emit("settings-update",{settings:{type:"force",options:this._settings}}),i.isPhysicsEnabled&&!t.isPhysicsEnabled?this._simulation.stop():this._settings.isSimulatingOnSettingsUpdate&&this._nodes.length>0&&this.activateSimulation()}setupData(e){this.clearData(),this._initializeNewData(e),this._settings.isSimulatingOnDataUpdate&&(this._updateSimulationData(),this._runSimulation())}mergeData(e){this._initializeNewData(e),this._settings.isPhysicsEnabled||this._pinNodes(),this._settings.isSimulatingOnDataUpdate&&(this._updateSimulationData(),this.activateSimulation())}updateData(e){let t=new Set(e.nodes.map(s=>s.id)),i=this._nodes.filter(s=>t.has(s.id)),o=e.nodes.filter(s=>this._nodeIndexByNodeId[s.id]===void 0);this._nodes=[...i,...o],this._rebuildNodeIndex(),this._edges=e.edges,this._settings.isSimulatingOnSettingsUpdate&&(this._updateSimulationData(),this.activateSimulation())}deleteData(e){if(e.nodeIds){let t=new Set(e.nodeIds);this._nodes=this._nodes.filter(i=>!t.has(i.id))}if(e.edgeIds){let t=new Set(e.edgeIds);this._edges=this._edges.filter(i=>!t.has(i.id))}this._rebuildNodeIndex(),this._settings.isSimulatingOnDataUpdate&&(this._updateSimulationData(),this.activateSimulation())}patchData(e){if(e.nodes){let t={};for(let i=0;i0&&this.activateSimulation()}terminate(){super.terminate(),this._simulation?.stop()}_resetSimulation(){this._simulation&&(this._simulation.stop(),this._simulation.on("tick",null).on("end",null)),this._linkForce=De(this._edges).id(e=>e.id),this._simulation=Me(this._nodes).force("link",this._linkForce).stop(),this._applySettingsToSimulation(this._settings),this._simulation.on("tick",()=>{this.emit("simulation-step",{nodes:this._nodes,edges:this._edges})}),this._simulation.on("end",()=>{this._isDragging=!1,this._isStabilizing=!1,this.emit("simulation-end",{nodes:this._nodes,edges:this._edges}),this._settings.isPhysicsEnabled||this._pinNodes()})}_runSimulation(e){if(this._isStabilizing||this._cancelSimulation)return;(this._settings.isPhysicsEnabled||e?.isUpdatingSettings)&&this._unpinNodes(),this.emit("simulation-start",void 0),this._isStabilizing=!0,this._simulation.alpha(this._settings.alpha.alpha).alphaTarget(this._settings.alpha.alphaTarget).stop();let t=Math.min(jt,Math.ceil(Math.log(this._settings.alpha.alphaMin)/Math.log(1-this._settings.alpha.alphaDecay))),i=-1,o=0,s=()=>{if(this._cancelSimulation){this._isStabilizing=!1,this._cancelSimulation=!1;return}let a=Math.min(o+Xt,t);for(;oi&&(i=u,this.emit("simulation-progress",{nodes:this._nodes,edges:this._edges,progress:u/100}))}othis._edges)):this._simulation.force("edgeMidpointRepulsion",null)}if(e.manyBody===null&&(this._simulation.force("charge",null),this._simulation.force("edgeMidpointRepulsion",null)),e.positioning?.forceX){let t=we(e.positioning.forceX.x).strength(e.positioning.forceX.strength);this._simulation.force("x",t)}if(e.positioning?.forceX===null&&this._simulation.force("x",null),e.positioning?.forceY){let t=Ue(e.positioning.forceY.y).strength(e.positioning.forceY.strength);this._simulation.force("y",t)}if(e.positioning?.forceY===null&&this._simulation.force("y",null),e.centering){let t=Ee(e.centering.x,e.centering.y).strength(e.centering.strength);this._simulation.force("center",t)}e.centering===null&&this._simulation.force("center",null)}};var B=class extends Error{constructor(r){super(r),this.message=r,Object.setPrototypeOf(this,new.target.prototype),this.name=this.constructor.name}};var ke=(n,r,e)=>{let t=n.createShader(e==="vertex"?n.VERTEX_SHADER:n.FRAGMENT_SHADER);if(!t)throw new B("Failed to create shader.");if(n.shaderSource(t,r),n.compileShader(t),!n.getShaderParameter(t,n.COMPILE_STATUS)){let i=n.getShaderInfoLog(t);throw n.deleteShader(t),new B(`Failed to compile shader: ${i}`)}return t};var _t=`#version 300 es\n\nin vec2 aPosition;\n\nvoid main() {\n gl_Position = vec4(aPosition, 0.0, 1.0);\n}\n`;var yt=`#version 300 es\n\nprecision highp float;\n\nuniform sampler2D uState;\nuniform sampler2D uFixed;\nuniform sampler2D uTreeData;\nuniform sampler2D uTreeChildren;\nuniform sampler2D uTreeGeometry;\nuniform sampler2D uAdjOffsets;\nuniform sampler2D uAdjEdges;\n\nuniform int uNodeCount;\nuniform int uTexWidth;\nuniform float uAlpha;\nuniform float uDamping;\n\nuniform float uManyBodyStrength;\nuniform float uTheta2;\nuniform float uDistanceMin2;\nuniform float uDistanceMax2;\nuniform int uTreeNodeCount;\nuniform int uTreeTexWidth;\n\nuniform int uAdjOffsetsTexWidth;\nuniform int uAdjEdgesTexWidth;\n\nuniform vec2 uCenter;\nuniform float uCenterStrength;\n\nuniform float uCollisionRadius;\nuniform float uCollisionStrength;\n\nuniform float uForceXTarget;\nuniform float uForceXStrength;\nuniform float uForceYTarget;\nuniform float uForceYStrength;\n\nuniform float uHasManyBody;\nuniform float uHasLinks;\nuniform float uHasCentering;\nuniform float uHasCollision;\nuniform float uHasPositioning;\n\nout vec4 fragColor;\n\nivec2 texCoord(int idx, int tw) {\n return ivec2(idx % tw, idx / tw);\n}\n\nvoid main() {\n ivec2 fc = ivec2(gl_FragCoord.xy);\n int nodeId = fc.y * uTexWidth + fc.x;\n\n if (nodeId >= uNodeCount) {\n fragColor = vec4(0.0);\n return;\n }\n\n vec4 fixedData = texelFetch(uFixed, fc, 0);\n if (fixedData.x > 0.5) {\n fragColor = vec4(fixedData.yz, 0.0, 0.0);\n return;\n }\n\n vec4 state = texelFetch(uState, fc, 0);\n vec2 pos = state.xy;\n vec2 vel = state.zw;\n\n if (uHasManyBody > 0.5 && uTreeNodeCount > 0) {\n int stack[128];\n int top = 0;\n stack[top++] = 0;\n\n while (top > 0) {\n int idx = stack[--top];\n vec4 data = texelFetch(uTreeData, texCoord(idx, uTreeTexWidth), 0);\n float w = data.w;\n\n if (w < -0.5) {\n int bodyIdx = int(-w - 0.5);\n if (bodyIdx != nodeId) {\n vec2 delta = data.xy - pos;\n float distSq = dot(delta, delta);\n\n if (distSq < 1e-8) {\n delta = vec2(float(nodeId) * 1e-4 - float(bodyIdx) * 1e-4 + 1e-4, 1e-4);\n distSq = dot(delta, delta);\n }\n\n if (distSq < uDistanceMax2) {\n float l = distSq;\n if (l < uDistanceMin2) l = sqrt(uDistanceMin2 * l);\n vel += delta * (data.z * uAlpha / max(l, 1e-6));\n }\n }\n } else {\n vec2 delta = data.xy - pos;\n float distSq = dot(delta, delta);\n\n if (distSq > 0.0 && w * w / distSq < uTheta2) {\n if (distSq < uDistanceMax2) {\n float l = distSq;\n if (l < uDistanceMin2) l = sqrt(uDistanceMin2 * l);\n vel += delta * (data.z * uAlpha / max(l, 1e-6));\n }\n } else {\n vec4 ch = texelFetch(uTreeChildren, texCoord(idx, uTreeTexWidth), 0);\n if (ch.w >= 0.0 && top < 64) stack[top++] = int(ch.w + 0.5);\n if (ch.z >= 0.0 && top < 64) stack[top++] = int(ch.z + 0.5);\n if (ch.y >= 0.0 && top < 64) stack[top++] = int(ch.y + 0.5);\n if (ch.x >= 0.0 && top < 64) stack[top++] = int(ch.x + 0.5);\n }\n }\n }\n }\n\n if (uHasCollision > 0.5 && uCollisionRadius > 0.0 && uTreeNodeCount > 0) {\n float collisionDiam = uCollisionRadius * 2.0;\n vec2 predictedPos = state.xy + state.zw;\n int stack[64];\n int top = 0;\n stack[top++] = 0;\n\n while (top > 0) {\n int idx = stack[--top];\n vec4 data = texelFetch(uTreeData, texCoord(idx, uTreeTexWidth), 0);\n float w = data.w;\n\n if (w < -0.5) {\n int bodyIdx = int(-w - 0.5);\n if (bodyIdx != nodeId && bodyIdx < uNodeCount) {\n vec2 delta = data.xy - predictedPos;\n float dist = length(delta);\n\n if (dist < collisionDiam && dist > 0.0) {\n float push = (collisionDiam - dist) * uCollisionStrength;\n vel -= (delta / dist) * push * 0.5;\n }\n }\n } else {\n vec4 geo = texelFetch(uTreeGeometry, texCoord(idx, uTreeTexWidth), 0);\n float cellSize = geo.z;\n vec2 nearest = clamp(predictedPos, geo.xy, geo.xy + cellSize);\n float distToCell = length(nearest - predictedPos);\n\n if (distToCell < collisionDiam) {\n vec4 ch = texelFetch(uTreeChildren, texCoord(idx, uTreeTexWidth), 0);\n if (ch.w >= 0.0 && top < 64) stack[top++] = int(ch.w + 0.5);\n if (ch.z >= 0.0 && top < 64) stack[top++] = int(ch.z + 0.5);\n if (ch.y >= 0.0 && top < 64) stack[top++] = int(ch.y + 0.5);\n if (ch.x >= 0.0 && top < 64) stack[top++] = int(ch.x + 0.5);\n }\n }\n }\n }\n\n if (uHasLinks > 0.5) {\n vec4 offData = texelFetch(uAdjOffsets, texCoord(nodeId, uAdjOffsetsTexWidth), 0);\n int start = int(offData.x + 0.5);\n int count = int(offData.y + 0.5);\n\n for (int e = 0; e < count; e++) {\n vec4 edgeData = texelFetch(uAdjEdges, texCoord(start + e, uAdjEdgesTexWidth), 0);\n int targetId = int(edgeData.x + 0.5);\n float restDist = edgeData.y;\n float strength = edgeData.z;\n float dirBias = edgeData.w;\n\n vec4 targetState = texelFetch(uState, texCoord(targetId, uTexWidth), 0);\n vec2 delta = (targetState.xy + targetState.zw) - (state.xy + state.zw);\n float d = length(delta);\n\n if (d < 1e-6) {\n delta = vec2(1e-3, 1e-3);\n d = length(delta);\n }\n\n float scale = (d - restDist) / d * uAlpha * strength;\n vel += delta * scale * dirBias;\n }\n }\n\n if (uHasCentering > 0.5) {\n vel += (uCenter - pos) * uCenterStrength * uAlpha;\n }\n\n if (uHasPositioning > 0.5) {\n vel.x += (uForceXTarget - pos.x) * uForceXStrength * uAlpha;\n vel.y += (uForceYTarget - pos.y) * uForceYStrength * uAlpha;\n }\n\n vel *= uDamping;\n pos += vel;\n\n fragColor = vec4(pos, vel);\n}\n`;function It(n,r){let e=n.length;if(e===0)return{treeData:new Float32Array(0),treeChildren:new Float32Array(0),treeGeometry:new Float32Array(0),nodeCount:0,texWidth:1};let t=1/0,i=1/0,o=-1/0,s=-1/0;for(let v=0;vo&&(o=S),A>s&&(s=A)}let a=Math.max(o-t,s-i);a<1e-6&&(a=1),a*=1.01;let u=(t+o)*.5,l=(i+s)*.5,c=a*.5,_=u-c,m=l-c,d=[];function g(v){let S=d.length;return d.push({cx:0,cy:0,charge:0,size:v,bodyIndex:-1,children:[null,null,null,null]}),S}let f=g(a),h=[_],p=[m];function y(v,S,A,K,w){let U=A+w*.5,G=K+w*.5,X=v>=U?1:0;return(S>=G?1:0)*2+X}function T(v,S,A,K){let w=K*.5,U=v&1?S+w:S,G=v&2?A+w:A;return{cx0:U,cy0:G,csz:w}}function x(v,S,A){let K=f,w=_,U=m,G=a;for(let X=0;X<50;X++){let L=d[K];if(L.bodyIndex===-1&&L.children[0]===null&&L.children[1]===null&&L.children[2]===null&&L.children[3]===null){L.bodyIndex=v,L.cx=S,L.cy=A,L.charge=r;return}if(L.bodyIndex>=0){let ve=L.bodyIndex,se=L.cx,ae=L.cy;L.bodyIndex=-1;let W=y(se,ae,w,U,G),{cx0:bt,cy0:Dt,csz:At}=T(W,w,U,G),V=g(At);h[V]=bt,p[V]=Dt,L.children[W]=V,d[V].bodyIndex=ve,d[V].cx=se,d[V].cy=ae,d[V].charge=r}let z=y(S,A,w,U,G);if(L.children[z]===null){let{cx0:ve,cy0:se,csz:ae}=T(z,w,U,G),W=g(ae);h[W]=ve,p[W]=se,L.children[z]=W,d[W].bodyIndex=v,d[W].cx=S,d[W].cy=A,d[W].charge=r;return}let{cx0:vt,cy0:Et,csz:Nt}=T(z,w,U,G);K=L.children[z],w=vt,U=Et,G=Nt}}for(let v=0;v=0)return;let A=0,K=0,w=0,U=0;for(let G=0;G<4;G++){let X=S.children[G];if(X===null)continue;I(X);let L=d[X],z=Math.abs(L.charge);A+=L.charge,K+=L.cx*z,w+=L.cy*z,U+=z}U>0&&(S.cx=K/U,S.cy=w/U),S.charge=A}I(f);let E=d.length,P=Math.ceil(Math.sqrt(E)),D=P*P,N=new Float32Array(D*4),b=new Float32Array(D*4),M=new Float32Array(D*4);for(let v=0;v=0?N[A+3]=-(S.bodyIndex+1):N[A+3]=S.size,b[A]=S.children[0]!==null?S.children[0]:-1,b[A+1]=S.children[1]!==null?S.children[1]:-1,b[A+2]=S.children[2]!==null?S.children[2]:-1,b[A+3]=S.children[3]!==null?S.children[3]:-1,M[A]=h[v]??0,M[A+1]=p[v]??0,M[A+2]=S.size,M[A+3]=0}for(let v=E;v0&&this.activateSimulation()}setupData(e){this.clearData(),this._initializeNewData(e),this._settings.isSimulatingOnDataUpdate&&this._runSimulation()}mergeData(e){this._initializeNewData(e),this._settings.isPhysicsEnabled||this._pinNodes(),this._settings.isSimulatingOnDataUpdate&&this.activateSimulation()}updateData(e){let t=new Set(e.nodes.map(s=>s.id)),i=this._nodes.filter(s=>t.has(s.id)),o=e.nodes.filter(s=>this._nodeIndexByNodeId[s.id]===void 0);this._nodes=[...i,...o],this._rebuildNodeIndex(),this._edges=e.edges,this._cachedAdjacency=null,this._settings.isSimulatingOnSettingsUpdate&&this.activateSimulation()}deleteData(e){if(e.nodeIds){let t=new Set(e.nodeIds);this._nodes=this._nodes.filter(i=>!t.has(i.id))}if(e.edgeIds){let t=new Set(e.edgeIds);this._edges=this._edges.filter(i=>!t.has(i.id))}this._rebuildNodeIndex(),this._cachedAdjacency=null,this._settings.isSimulatingOnDataUpdate&&this.activateSimulation()}patchData(e){if(e.nodes){let t={};for(let i=0;i0&&this.activateSimulation()}terminate(){super.terminate();let e=this._gl;e&&(e.deleteBuffer(this._quadBuffer),e.deleteVertexArray(this._quadVAO),e.deleteProgram(this._forceProgram),e.deleteTexture(this._stateTexA),e.deleteTexture(this._stateTexB),e.deleteTexture(this._fixedTex),e.deleteTexture(this._treeDataTexture),e.deleteTexture(this._treeChildrenTexture),e.deleteTexture(this._treeGeometryTexture),e.deleteTexture(this._adjOffsetsTexture),e.deleteTexture(this._adjEdgesTexture),e.deleteFramebuffer(this._fboA),e.deleteFramebuffer(this._fboB),e.getExtension("WEBGL_lose_context")?.loseContext())}reheat(){let e=this._settings.alpha;this._currentAlpha=e.alpha,this._totalSteps=Math.min(St,Math.ceil(Math.log(e.alphaMin)/Math.log(1-e.alphaDecay))),this._currentStep=0,!this._isStabilizing&&(this._ensurePositions(),this._uploadDataToGPU(),this._cachedAdjacency||this._buildAndUploadAdjacency(),this._startSimulationLoop())}_runSimulation(){this._isStabilizing||this._cancelSimulation||(this._ensurePositions(),this._uploadDataToGPU(),this._buildAndUploadAdjacency(),this._startSimulationLoop())}_startDragLoop(){if(this._dragLoopRunning)return;this._dragLoopRunning=!0;let e=this._settings.alpha.alphaDecay,t=this._settings.alpha.alphaMin;this._dragAlpha=.3,this._dragNeedsReheat=!1;let i=()=>{if(!this._isDragging){this._dragLoopRunning=!1;return}if(this._dragNeedsReheat&&(this._dragAlpha=.3,this._dragNeedsReheat=!1),this._dragAlpha+=(0-this._dragAlpha)*e,this._dragAlpha{if(e!==this._simulationGeneration)return;if(this._cancelSimulation){this._isStabilizing=!1,this._cancelSimulation=!1,this.emit("simulation-end",{nodes:this._nodes,edges:this._edges});return}if(this._readbackFromGPU(),this._pendingRestart){this._isStabilizing=!1,this._pendingRestart=!1,this._ensurePositions(),this._uploadDataToGPU(),this._cachedAdjacency||this._buildAndUploadAdjacency(),this._startSimulationLoop();return}this._flushDirtyNodes(),this._buildAndUploadQuadTree();let u=Math.min(this._currentStep+Ht,this._totalSteps);for(;this._currentSteps&&(s=l,this.emit("simulation-progress",{nodes:this._nodes,edges:this._edges,progress:l/100})),this._currentStep0&&(i=i.concat(s))}let o=It(i,t);this._uploadTexture(this._treeDataTexture,o.treeData,o.texWidth),this._uploadTexture(this._treeChildrenTexture,o.treeChildren,o.texWidth),this._uploadTexture(this._treeGeometryTexture,o.treeGeometry,o.texWidth),this._treeTexWidth=o.texWidth,this._treeNodeCount=o.nodeCount}_getEdgeMidpoints(){let e=[];for(let t=0;t0?d.distanceMax:Fe(this._settings.links?.distance??50);t.uniform1f(s.uDistanceMax2,f*f),t.uniform1i(s.uTreeNodeCount,this._treeNodeCount),t.uniform1i(s.uTreeTexWidth,this._treeTexWidth)}let u=this._cachedAdjacency!==null&&this._edges.length>0;t.uniform1f(s.uHasLinks,u?1:0),u&&(t.uniform1i(s.uAdjOffsetsTexWidth,this._cachedAdjacency.offsetsTexWidth),t.uniform1i(s.uAdjEdgesTexWidth,this._cachedAdjacency.edgesTexWidth)),t.uniform1f(s.uHasCentering,0);let l=this._settings.collision!==null&&this._settings.collision!==void 0;t.uniform1f(s.uHasCollision,l?1:0),l&&(t.uniform1f(s.uCollisionRadius,this._settings.collision.radius),t.uniform1f(s.uCollisionStrength,this._settings.collision.strength));let c=this._settings.positioning!==null&&this._settings.positioning!==void 0;if(t.uniform1f(s.uHasPositioning,c?1:0),c){let d=this._settings.positioning;t.uniform1f(s.uForceXTarget,d.forceX?.x??0),t.uniform1f(s.uForceXStrength,d.forceX?.strength??0),t.uniform1f(s.uForceYTarget,d.forceY?.y??0),t.uniform1f(s.uForceYStrength,d.forceY?.strength??0)}let _=this._pingPong?this._stateTexA:this._stateTexB,m=this._pingPong?this._fboB:this._fboA;t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,_),t.uniform1i(s.uState,0),t.activeTexture(t.TEXTURE1),t.bindTexture(t.TEXTURE_2D,this._fixedTex),t.uniform1i(s.uFixed,1),t.activeTexture(t.TEXTURE2),t.bindTexture(t.TEXTURE_2D,this._treeDataTexture),t.uniform1i(s.uTreeData,2),t.activeTexture(t.TEXTURE3),t.bindTexture(t.TEXTURE_2D,this._treeChildrenTexture),t.uniform1i(s.uTreeChildren,3),t.activeTexture(t.TEXTURE4),t.bindTexture(t.TEXTURE_2D,this._adjOffsetsTexture),t.uniform1i(s.uAdjOffsets,4),t.activeTexture(t.TEXTURE5),t.bindTexture(t.TEXTURE_2D,this._adjEdgesTexture),t.uniform1i(s.uAdjEdges,5),t.activeTexture(t.TEXTURE6),t.bindTexture(t.TEXTURE_2D,this._treeGeometryTexture),t.uniform1i(s.uTreeGeometry,6),t.bindFramebuffer(t.FRAMEBUFFER,m),t.viewport(0,0,this._texWidth,this._texWidth),t.bindVertexArray(this._quadVAO),t.drawArrays(t.TRIANGLE_STRIP,0,4),t.bindVertexArray(null),t.bindFramebuffer(t.FRAMEBUFFER,null),this._pingPong=!this._pingPong}_readbackFromGPU(){let e=this._gl,t=this._nodes.length;if(t===0)return;let i=this._pingPong?this._fboA:this._fboB,o=this._texWidth*this._texWidth,s=new Float32Array(o*4);e.bindFramebuffer(e.FRAMEBUFFER,i),e.readPixels(0,0,this._texWidth,this._texWidth,e.RGBA,e.FLOAT,s),e.bindFramebuffer(e.FRAMEBUFFER,null);for(let a=0;as.id)),i=this._nodes.filter(s=>t.has(s.id)),o=e.nodes.filter(s=>this._nodeIndexByNodeId[s.id]===void 0);this._nodes=[...i,...o],this._edges=e.edges,this._rebuildNodeIndex(),this._calculateAndEmit()}deleteData(e){if(e.nodeIds){let t=new Set(e.nodeIds);this._nodes=this._nodes.filter(i=>!t.has(i.id))}if(e.edgeIds){let t=new Set(e.edgeIds);this._edges=this._edges.filter(i=>!t.has(i.id))}this._rebuildNodeIndex(),this._calculateAndEmit()}patchData(e){if(e.nodes)for(let t=0;t0&&this._calculateAndEmit()}terminate(){this._pendingRecalculation=!1,super.terminate()}_calculateAndEmit(){if(!(this._nodes.length===0||this._cancelSimulation)){if(this._isCalculating){this._pendingRecalculation=!0;return}this._isCalculating=!0,this.emit("simulation-start",void 0),this.calculatePositions(this._nodes,this._edges,e=>{this.emit("simulation-progress",{nodes:this._nodes,edges:this._edges,progress:e})},()=>this._cancelSimulation,()=>{this._isCalculating=!1,this._cancelSimulation||this.emit("simulation-end",{nodes:this._nodes,edges:this._edges}),this._cancelSimulation=!1,this._pendingRecalculation&&(this._pendingRecalculation=!1,this._calculateAndEmit())})}}_emitProgress(e,t,i,o){let s=Math.round(e*100/t);return s>i?(o(s/100),s):i}};var Ie=class extends H{constructor(e){super();this.type="circular";this._config={...pt,...e}}calculatePositions(e,t,i,o,s){let a=2*Math.PI/e.length,u=-1,l=0,c=()=>{if(o()){s();return}let _=Math.min(l+ye,e.length);for(;l<_;l++)e[l].x=this._config.centerX+this._config.radius*Math.cos(a*l),e[l].y=this._config.centerY+this._config.radius*Math.sin(a*l);l{if(o()){s();return}let m=Math.min(c+ye,e.length);for(;c{if(o()||g>=l.length){!o()&&this._config.reversed&&this._applyReversal(e,c,_),s();return}let h=this._assignLevels(l[g],a,u),p=Math.max(...Array.from(h.values()).map(T=>T.length));h.size*this._config.levelGap>_&&(_=h.size*this._config.levelGap);let y=g===0?0:this._config.treeGap+c;g>0&&(y+=(p-1)*this._config.nodeGap/2);for(let T=0;Tc&&(c=b),N!==void 0&&(e[N].x=this._config.orientation==="horizontal"?x:b,e[N].y=this._config.orientation==="horizontal"?b:x),m++}}g++,g0;){let c=l.pop();if(c===void 0)continue;u.push(c);let _=t.get(c)??[];for(let m=0;m<_.length;m++)i.has(_[m])||(i.add(_[m]),l.push(_[m]))}o.push(u)}return o}_assignLevels(e,t,i){let o=new Map,s=new Set,a=e.find(l=>(i.get(l)??0)===0);a===void 0&&(a=e.reduce((l,c)=>(i.get(c)??0)<(i.get(l)??0)?c:l));let u=[[a,0]];for(let[l,c]of u){if(s.has(l))continue;s.add(l),o.has(c)?o.get(c)?.push(l):o.set(c,[l]);let _=t.get(l)??[];for(let m=0;m<_.length;m++)u.push([_[m],c+1])}return o}_getEdgeEndpointId(e){return typeof e=="object"?e.id:e}};var Te=class{static create(r){switch(r?.type){case"circular":return new Ie(r.options);case"grid":return new xe(r.options);case"hierarchical":return new Se(r.options);default:{let e=r?.options;if(e?.useGPU)try{return new _e(e)}catch{return console.warn("WebGL2 unavailable, falling back to CPU force layout engine."),new re(e)}return new re(e)}}}};function Tt(n,r){switch(r.type){case"Set Data":n.setupData(r.data);break;case"Add Data":n.mergeData(r.data);break;case"Update Data":n.updateData(r.data);break;case"Delete Data":n.deleteData(r.data);break;case"Patch Data":n.patchData(r.data);break;case"Clear Data":n.clearData();break;case"Activate Simulation":n.activateSimulation();break;case"Stop Simulation":n.stopSimulation();break;case"Start Drag Node":n.startDragNode();break;case"Drag Node":n.dragNode(r.data.id,{x:r.data.x,y:r.data.y});break;case"End Drag Node":n.endDragNode(r.data.id);break;case"Fix Nodes":n.fixNodes(r.data.nodes);break;case"Release Nodes":n.releaseNodes(r.data.nodes);break;default:break}}var q=null,$=n=>postMessage(n);function Vt(n){n.on("simulation-start",()=>$({type:"simulation-start"})),n.on("simulation-progress",r=>$({type:"simulation-progress",data:r})),n.on("simulation-end",r=>$({type:"simulation-end",data:r})),n.on("simulation-step",r=>$({type:"simulation-step",data:r})),n.on("node-drag",r=>$({type:"node-drag",data:r})),n.on("settings-update",r=>$({type:"settings-update",data:r}))}$({type:"ready"});addEventListener("message",({data:n})=>{if(n.type==="Set Settings"){let r=n.data;if(r.type===q?.type&&r.options){q?.setSettings(r.options);return}q?.removeAllListeners(),q?.terminate(),q=Te.create(r),Vt(q);return}q&&Tt(q,n)});})();\n'],{type:"text/javascript"})),e=new Worker(this._blobUrl)}catch(t){return void this._activateFallback(t)}this._worker=e,e.onerror=t=>{this._ready?this._warnWorkerError(t):this._activateFallback(t)},e.onmessage=this._handleWorkerMessage,this._readyTimer=setTimeout(()=>{this._ready||this._fallback||this._activateFallback(new Error("Web Worker readiness handshake timed out."))},3e3),this.emitToWorker({type:gs.SetSettings,data:t})}setupData(t){this.emitToWorker({type:gs.SetupData,data:t})}mergeData(t){this.emitToWorker({type:gs.MergeData,data:t})}updateData(t){this.emitToWorker({type:gs.UpdateData,data:t})}deleteData(t){this.emitToWorker({type:gs.DeleteData,data:t})}patchData(t){this.emitToWorker({type:gs.PatchData,data:t})}clearData(){this.emitToWorker({type:gs.ClearData})}activateSimulation(){this.emitToWorker({type:gs.ActivateSimulation})}stopSimulation(){this.emitToWorker({type:gs.StopSimulation})}updateSimulation(t,e){this.emitToWorker({type:gs.UpdateSimulation,data:{nodes:t,edges:e}})}startDragNode(){this.emitToWorker({type:gs.StartDragNode})}dragNode(t,e){this.emitToWorker({type:gs.DragNode,data:Object.assign({id:t},e)})}endDragNode(t){this.emitToWorker({type:gs.EndDragNode,data:{id:t}})}fixNodes(t){this.emitToWorker({type:gs.FixNodes,data:{nodes:t}})}releaseNodes(t){this.emitToWorker({type:gs.ReleaseNodes,data:{nodes:t}})}setSettings(t){this.emitToWorker({type:gs.SetSettings,data:t})}isSimulationRunning(){return this._fallback?this._fallback.isSimulationRunning():this._isSimulationRunning}terminate(){var t;void 0!==this._readyTimer&&(clearTimeout(this._readyTimer),this._readyTimer=void 0),this._revokeBlobUrl(),this._worker&&(this._worker.onmessage=null,this._worker.onerror=null,this._worker.terminate(),this._worker=void 0),null===(t=this._fallback)||void 0===t||t.terminate(),this.removeAllListeners()}emitToWorker(t){var e;this._fallback?this._applyToFallback(this._fallback,t):(this._ready||this._pending.push(t),null===(e=this._worker)||void 0===e||e.postMessage(t))}_markReady(){this._ready||(this._ready=!0,this._pending=[],void 0!==this._readyTimer&&(clearTimeout(this._readyTimer),this._readyTimer=void 0),this._revokeBlobUrl())}_activateFallback(t){if(this._fallback)return;if(this._warnFallback(t),void 0!==this._readyTimer&&(clearTimeout(this._readyTimer),this._readyTimer=void 0),this._worker){this._worker.onmessage=null,this._worker.onerror=null;try{this._worker.terminate()}catch(t){}this._worker=void 0}this._revokeBlobUrl();const e=new fs(this._settings);this._wireFallbackEvents(e),this._fallback=e;const i=this._pending;this._pending=[];for(const t of i)this._applyToFallback(e,t)}_wireFallbackEvents(t){Rn(t,this,t=>{this._isSimulationRunning=t})}_applyToFallback(t,e){e.type!==gs.SetSettings?function(t,e){switch(e.type){case gs.SetupData:t.setupData(e.data);break;case gs.MergeData:t.mergeData(e.data);break;case gs.UpdateData:t.updateData(e.data);break;case gs.DeleteData:t.deleteData(e.data);break;case gs.PatchData:t.patchData(e.data);break;case gs.ClearData:t.clearData();break;case gs.ActivateSimulation:t.activateSimulation();break;case gs.StopSimulation:t.stopSimulation();break;case gs.StartDragNode:t.startDragNode();break;case gs.DragNode:t.dragNode(e.data.id,{x:e.data.x,y:e.data.y});break;case gs.EndDragNode:t.endDragNode(e.data.id);break;case gs.FixNodes:t.fixNodes(e.data.nodes);break;case gs.ReleaseNodes:t.releaseNodes(e.data.nodes)}}(t,e):t.setSettings(e.data)}_revokeBlobUrl(){this._blobUrl&&(URL.revokeObjectURL(this._blobUrl),this._blobUrl=void 0)}_warnWorkerError(t){this._hasWarned||(this._hasWarned=!0,console.warn("Orb: the layout Web Worker errored after it had started. The current layout is kept and no further updates will be simulated; reload the graph to recover.",t))}_warnFallback(t){this._hasWarned||(this._hasWarned=!0,console.warn("Orb: the layout Web Worker could not start; falling back to the main-thread simulator. Layout is still correct but runs on the main thread. Under a strict Content Security Policy, allow blob workers (e.g. `worker-src blob:` or `child-src blob:`) to re-enable off-main-thread layout.",t))}}class vs{static getSimulator(t){const e=Object.assign({type:"force"},t),i=e.options;if("force"===e.type&&(null==i?void 0:i.useGPU))return new fs(e);try{if("undefined"!=typeof Worker)return new ms(e);throw new Error("WebWorkers are unavailable in your environment.")}catch(t){return console.error("Could not create simulator in a WebWorker context. All calculations will be done in the main thread.",t),new fs(e)}}}const ys=t=>{const e=t.start,i=t.end;return e{if(!this.sortBy)return 0;const i=this.getOne(t),n=this.getOne(e);return void 0===i||void 0===n?0:this.sortBy(i,n)})}get size(){return this.entityById.size}}const bs=(...t)=>{const e=t.reduce((t,e)=>t.concat(e),[]);return Array.from(new Set(e))};class Ss extends l{constructor(t,e){var i,n;super(),this._nodes=new xs({getId:t=>t.getId(),sortBy:(t,e)=>{var i,n;return(null!==(i=t.getStyle().zIndex)&&void 0!==i?i:0)-(null!==(n=e.getStyle().zIndex)&&void 0!==n?n:0)}}),this._edges=new xs({getId:t=>t.getId(),sortBy:(t,e)=>{var i,n;return(null!==(i=t.getStyle().zIndex)&&void 0!==i?i:0)-(null!==(n=e.getStyle().zIndex)&&void 0!==n?n:0)}}),this._update=t=>{if(t&&"type"in t&&"options"in t&&"isSingle"in t.options){if("node"===t.type&&t.options.isSingle){const e=this._nodes.getAll();for(let i=0;it.isSelected())}getSelectedEdges(){return this.getEdges(t=>t.isSelected())}getHoveredNodes(){return this.getNodes(t=>t.isHovered())}getHoveredEdges(){return this.getEdges(t=>t.isHovered())}getNodePositions(t){const e=this.getNodes(t),i=new Array(e.length);for(let t=0;tt.id),e=this._edges.getAll().map(t=>t.id);this.remove({nodeIds:t,edgeIds:e})}removeAllEdges(){const t=this._edges.getAll().map(t=>t.id);this.remove({edgeIds:t})}removeAllNodes(){this.removeAll()}isEqual(t){if(this.getNodeCount()!==t.getNodeCount())return!1;if(this.getEdgeCount()!==t.getEdgeCount())return!1;const e=this.getNodes();for(let i=0;ii.x&&(i.x=s+r),s-ri.y&&(i.y=o+r),o-r=0;i--)if(e[i].includesPoint(t))return e[i]}getNearestEdge(t,e=3){let i,n=e;const s=this.getEdges();for(let e=0;e{var t,e;return null===(e=null===(t=this._settings)||void 0===t?void 0:t.onLoadedImages)||void 0===e?void 0:e.call(t)},listeners:[this._update]});this._nodes.setMany(e)}_insertEdges(t){const e=[];for(let i=0;i{var t,e;return null===(e=null===(t=this._settings)||void 0===t?void 0:t.onLoadedImages)||void 0===e?void 0:e.call(t)},listeners:[this._update]}))}this._nodes.setMany(e)}_upsertEdges(t){const e=[],i=[];for(let n=0;n{var e;const i=new Array(t.length),n=(t=>{var e;const i={},n=new Set;for(let s=0;se+1);continue}if(r<=1)continue;const a=[];r%2!=0&&a.push(0);for(let t=2;t<=r;t+=2)a.push(t/2),a.push(t/2*-1);s[e]=a}return s})(t);for(let s=0;s{var t,e;null===(e=null===(t=this._settings)||void 0===t?void 0:t.onLoadedImages)||void 0===e||e.call(t)}),this._nodes.sort(),this._edges.sort()}}const ws=(t,e)=>{var i;null===(i=null==e?void 0:e.cascade)||void 0===i||i?Is(t,r.SELECTED,{isStateOverride:!0}):t.setState(r.SELECTED,{isNotifySkipped:!0})},Ts=(t,e)=>{var i;null===(i=null==e?void 0:e.cascade)||void 0===i||i?Ls(t,r.SELECTED,{isStateOverride:!0}):t.setState(r.SELECTED,{isNotifySkipped:!0})},Es=(t,e)=>{var i;null===(i=null==e?void 0:e.cascade)||void 0===i||i?Is(t,r.NONE,{isStateOverride:!0}):t.clearState()},Ps=(t,e)=>{var i;null===(i=null==e?void 0:e.cascade)||void 0===i||i?Ls(t,r.NONE,{isStateOverride:!0}):t.clearState()},As=(t,e,i)=>{Ms(t),ws(e,i)},Cs=(t,e,i)=>{Ms(t),Ts(e,i)},Ms=t=>{const e=t.getNodes(t=>t.isSelected());for(let t=0;tt.isSelected());for(let t=0;t{Is(t,r.HOVERED)},Ds=t=>{const e=t.getNodes(t=>t.isHovered());for(let t=0;tt.isHovered());for(let t=0;t{Rs(t,i)&&t.setState(e,{isNotifySkipped:!0}),t.getInEdges().forEach(t=>{t&&Rs(t,i)&&t.setState(e,{isNotifySkipped:!0}),t.startNode&&Rs(t.startNode,i)&&t.startNode.setState(e,{isNotifySkipped:!0})}),t.getOutEdges().forEach(t=>{t&&Rs(t,i)&&t.setState(e,{isNotifySkipped:!0}),t.endNode&&Rs(t.endNode,i)&&t.endNode.setState(e,{isNotifySkipped:!0})})},Ls=(t,e,i)=>{Rs(t,i)&&t.setState(e,{isNotifySkipped:!0}),t.startNode&&Rs(t.startNode,i)&&t.startNode.setState(e,{isNotifySkipped:!0}),t.endNode&&Rs(t.endNode,i)&&t.endNode.setState(e,{isNotifySkipped:!0})},Rs=(t,e)=>{const i=null==e?void 0:e.isStateOverride;return i||!i&&!t.getState()};class Os{constructor(t){this.isSelectEnabled=t.isDefaultSelectEnabled,this.isHoverEnabled=t.isDefaultHoverEnabled,this.isMultiSelectEnabled=t.isDefaultMultiSelectEnabled,this.isSelectCascadeEnabled=t.isDefaultSelectCascadeEnabled}onMouseClick(t,e,i){var n;const s=this.isMultiSelectEnabled&&null!==(n=null==i?void 0:i.isAppend)&&void 0!==n&&n,o=t.getNearestNode(e);if(o)return this.isSelectEnabled&&(s?(t=>{t.isSelected()?Es(t,{cascade:!1}):ws(t,{cascade:!1})})(o):As(t,o,{cascade:this.isSelectCascadeEnabled})),{isStateChanged:!0,changedSubject:o};const r=t.getNearestEdge(e);if(r)return this.isSelectEnabled&&(s?(t=>{t.isSelected()?Ps(t,{cascade:!1}):Ts(t,{cascade:!1})})(r):Cs(t,r,{cascade:this.isSelectCascadeEnabled})),{isStateChanged:!0,changedSubject:r};if(!this.isSelectEnabled||s)return{isStateChanged:!1};const{changedCount:a}=Ms(t);return{isStateChanged:a>0}}onMouseMove(t,e){const i=t.getNearestNode(e);if(i&&(!this.isSelectEnabled||this.isSelectEnabled&&!i.isSelected()))return i===this._lastHoveredNode?{changedSubject:i,isStateChanged:!1}:(this.isHoverEnabled&&((t,e)=>{Ds(t),Ns(e)})(t,i),this._lastHoveredNode=i,{isStateChanged:!0,changedSubject:i});if(this._lastHoveredNode=void 0,!i&&this.isHoverEnabled){const{changedCount:e}=Ds(t);return{isStateChanged:e>0}}return{isStateChanged:!1}}onMouseRightClick(t,e){const i=t.getNearestNode(e);if(i)return this.isSelectEnabled&&As(t,i,{cascade:this.isSelectCascadeEnabled}),{isStateChanged:!0,changedSubject:i};const n=t.getNearestEdge(e);if(n)return this.isSelectEnabled&&Cs(t,n,{cascade:this.isSelectCascadeEnabled}),{isStateChanged:!0,changedSubject:n};if(!this.isSelectEnabled)return{isStateChanged:!1};const{changedCount:s}=Ms(t);return{isStateChanged:s>0}}onMouseDoubleClick(t,e){const i=t.getNearestNode(e);if(i)return this.isSelectEnabled&&As(t,i,{cascade:this.isSelectCascadeEnabled}),{isStateChanged:!0,changedSubject:i};const n=t.getNearestEdge(e);if(n)return this.isSelectEnabled&&Cs(t,n,{cascade:this.isSelectCascadeEnabled}),{isStateChanged:!0,changedSubject:n};if(!this.isSelectEnabled)return{isStateChanged:!1};const{changedCount:s}=Ms(t);return{isStateChanged:s>0}}}var ks,Bs;!function(t){t.CANVAS="canvas",t.WEBGL="webgl"}(ks||(ks={})),function(t){t.RESIZE="resize",t.RENDER_START="render-start",t.RENDER_END="render-end"}(Bs||(Bs={}));const zs={devicePixelRatio:null,fps:60,minZoom:.25,maxZoom:8,fitZoomMargin:.2,labelsIsEnabled:!0,labelsOnEventIsEnabled:!0,shadowIsEnabled:!0,shadowOnEventIsEnabled:!0,contextAlphaOnEvent:.3,contextAlphaOnEventIsEnabled:!0,backgroundColor:null,areCollapsedContainerDimensionsAllowed:!1},Us="Roboto, sans-serif";var Fs;!function(t){t.TOP="top",t.MIDDLE="middle"}(Fs||(Fs={}));class js{constructor(t,e){var i,n;this.textLines=[],this.fontSize=4,this.fontFamily=Hs(4,Us),this.text=`${void 0===t?"":t}`,this.textLines=Xs(this.text),this.position=e.position,this.properties=e.properties,this.textBaseline=e.textBaseline,(void 0!==this.properties.fontSize||this.properties.fontFamily)&&(this.fontSize=Math.max(null!==(i=this.properties.fontSize)&&void 0!==i?i:0,0),this.fontFamily=Hs(this.fontSize,null!==(n=this.properties.fontFamily)&&void 0!==n?n:Us)),this._fixPosition()}_fixPosition(){if(this.textBaseline===Fs.MIDDLE&&this.textLines.length){const t=Math.floor(this.textLines.length/2),e=(this.textLines.length-1)/2;this.position.y-=e*this.fontSize-t*(1.2-1)}}}const Ws=(t,e)=>{e.textLines.length>0&&e.fontSize>0&&e.position&&(Zs(t,e),Gs(t,e))},Zs=(t,e)=>{if(!e.properties.fontBackgroundColor||!e.position)return;t.fillStyle=e.properties.fontBackgroundColor.toString();const i=.12*e.fontSize,n=e.fontSize+2*i,s=1.2*e.fontSize,o=e.textBaseline===Fs.MIDDLE?e.fontSize/2:0;for(let r=0;r{var i;if(!e.position)return;t.fillStyle=(null!==(i=e.properties.fontColor)&&void 0!==i?i:"#000000").toString(),t.font=e.fontFamily,t.textBaseline=e.textBaseline,t.textAlign="center";const n=1.2*e.fontSize;for(let i=0;i`${t}px ${e}`,Xs=t=>{const e=t.split("\n"),i=[];for(let t=0;t{var e,i;const n=null!==(e=t.getStyle().arrowSize)&&void 0!==e?e:1,s=null!==(i=t.getWidth())&&void 0!==i?i:1,o=t.endNode,r=t.getCurvedControlPoint(),a=Ys(t,o),h=Vs(t,Math.max(0,Math.min(1,a.t+-.1)),r),l=Math.atan2(a.y-h.y,a.x-h.x),d=1.5*n+3*s;return{point:a,core:{x:a.x-.9*d*Math.cos(l),y:a.y-.9*d*Math.sin(l)},angle:l,length:d}},Vs=(t,e,i)=>{const n=t.startNode.getCenter(),s=t.endNode.getCenter();if(!n||!s)return{x:0,y:0};const o=e;return{x:Math.pow(1-o,2)*n.x+2*o*(1-o)*i.x+Math.pow(o,2)*s.x,y:Math.pow(1-o,2)*n.y+2*o*(1-o)*i.y+Math.pow(o,2)*s.y}},Ys=(t,e)=>{let i,n,s,o=0,r=0,a=1,h={x:0,y:0,t:0};const l=t.getCurvedControlPoint();let d=t.endNode,u=!1;e.getId()===t.startNode.getId()&&(d=t.startNode,u=!0);const c=d.getCenter();let _;for(;r<=a&&o<10&&(_=.5*(r+a),h=Object.assign(Object.assign({},Vs(t,_,l)),{t:0}),i=d.getDistanceToBorder(),n=Math.sqrt(Math.pow(h.x-c.x,2)+Math.pow(h.y-c.y,2)),s=i-n,!(Math.abs(s)<.2));)s<0?!1===u?r=_:a=_:!1===u?a=_:r=_,o++;return h.t=null!=_?_:0,h},$s=t=>{var e,i;const n=null!==(e=t.getStyle().arrowSize)&&void 0!==e?e:1,s=null!==(i=t.getWidth())&&void 0!==i?i:1,o=t.startNode,r=Qs(t,o),a=-2*r.t*Math.PI+.45*Math.PI,h=1.5*n+3*s;return{point:r,core:{x:r.x-.9*h*Math.cos(a),y:r.y-.9*h*Math.sin(a)},angle:a,length:h}},Ks=(t,e)=>{const i=2*e*Math.PI;return{x:t.x+t.radius*Math.cos(i),y:t.y-t.radius*Math.sin(i)}},Qs=(t,e)=>{const i=t.getCircularData();let n=.6,s=1;let o,r,a,h=0,l={x:0,y:0,t:0},d=.5*(n+s);const u=e.getCenter();for(;n<=s&&h<10&&(d=.5*(n+s),l=Object.assign(Object.assign({},Ks(i,d)),{t:0}),o=e.getDistanceToBorder(),r=Math.sqrt(Math.pow(l.x-u.x,2)+Math.pow(l.y-u.y,2)),a=o-r,!(Math.abs(a)<.05));)a>0?n=d:s=d,h++;return l.t=null!=d?d:0,l},Js=t=>{var e,i;const n=null!==(e=t.getStyle().arrowSize)&&void 0!==e?e:1,s=null!==(i=t.getWidth())&&void 0!==i?i:1,o=t.startNode.getCenter(),r=t.endNode.getCenter(),a=Math.atan2(r.y-o.y,r.x-o.x),h=to(t,t.endNode),l=1.5*n+3*s;return{point:h,core:{x:h.x-.9*l*Math.cos(a),y:h.y-.9*l*Math.sin(a)},angle:a,length:l}},to=(t,e)=>{let i=t.endNode,n=t.startNode;e.getId()===t.startNode.getId()&&(i=t.startNode,n=t.endNode);const s=i.getCenter(),o=n.getCenter(),r=s.x-o.x,a=s.y-o.y,h=Math.sqrt(r*r+a*a),l=(h-e.getDistanceToBorder())/h;return{x:(1-l)*o.x+l*s.x,y:(1-l)*o.y+l*s.y,t:0}},eo=t=>{if(t instanceof O)return Js(t);if(t instanceof k)return qs(t);if(t instanceof B)return $s(t);throw new Error("Failed to draw unsupported edge type")},io=(t,e)=>{const i=e.point.x,n=e.point.y,s=e.angle,o=e.length;for(let e=0;e{const i=e.getCenter(),n=e.getRadius();switch(e.getStyle().shape){case S.SQUARE:((t,e,i,n)=>{t.beginPath(),t.rect(e-n,i-n,2*n,2*n),t.closePath()})(t,i.x,i.y,n);break;case S.DIAMOND:((t,e,i,n)=>{t.beginPath(),t.lineTo(e,i+n),t.lineTo(e+n,i),t.lineTo(e,i-n),t.lineTo(e-n,i),t.closePath()})(t,i.x,i.y,n);break;case S.TRIANGLE:((t,e,i,n)=>{t.beginPath(),i+=.275*(n*=1.15);const s=2*n,o=Math.sqrt(3)*s/6,r=Math.sqrt(s*s-n*n);t.moveTo(e,i-(r-o)),t.lineTo(e+n,i+o),t.lineTo(e-n,i+o),t.lineTo(e,i-(r-o)),t.closePath()})(t,i.x,i.y,n);break;case S.TRIANGLE_DOWN:((t,e,i,n)=>{t.beginPath(),i-=.275*(n*=1.15);const s=2*n,o=Math.sqrt(3)*s/6,r=Math.sqrt(s*s-n*n);t.moveTo(e,i+(r-o)),t.lineTo(e+n,i-o),t.lineTo(e-n,i-o),t.lineTo(e,i+(r-o)),t.closePath()})(t,i.x,i.y,n);break;case S.STAR:((t,e,i,n)=>{t.beginPath(),i+=.1*(n*=.82);for(let s=0;s<10;s++){const o=n*(s%2==0?1.3:.5),r=e+o*Math.sin(2*s*Math.PI/10),a=i-o*Math.cos(2*s*Math.PI/10);t.lineTo(r,a)}t.closePath()})(t,i.x,i.y,n);break;case S.HEXAGON:((t,e,i,n)=>{((t,e,i,n,s)=>{t.beginPath(),t.moveTo(e+n,i);const o=2*Math.PI/s;for(let r=1;r{t.beginPath(),t.arc(e,i,n,0,2*Math.PI,!1),t.closePath()})(t,i.x,i.y,n)}},so=(t,e=300)=>{let i=0,n=null;return function(){const s=arguments,o=Date.now(),r=e-(o-i);r<=0?(n&&(clearTimeout(n),n=null),i=o,t(...s)):n||(n=setTimeout(()=>{i=Date.now(),n=null,t(...s)},r))}},oo=t=>{const e=Math.max(t,1);return Math.round(1e3/e)},ro=(t,e=!1)=>{t.style.position="relative";const i=getComputedStyle(t);i.display||(t.style.display="block",console.warn("[Orb] Graph container doesn't have defined 'display' property. Setting 'display' to 'block'...")),!e&&ho(i.width)&&(t.style.width="100%",ho(getComputedStyle(t).width)?(t.style.width="400px",console.warn("[Orb] The graph container element and its parent don't have defined width properties.","If you are using percentage values,","please make sure that the parent element of the graph container has a defined position and width.","Setting the width of the graph container to an arbitrary value of '400px'...")):console.warn("[Orb] The graph container element doesn't have defined width. Setting width to 100%...")),!e&&ho(i.height)&&(t.style.height="100%",ho(getComputedStyle(t).height)?(t.style.height="400px",console.warn("[Orb] The graph container element and its parent don't have defined height properties.","If you are using percentage values,","please make sure that the parent element of the graph container has a defined position and height.","Setting the height of the graph container to an arbitrary value of '400px'...")):console.warn("[Orb] Graph container doesn't have defined height. Setting height to 100%..."))},ao=/^\s*0+\s*(?:px|rem|em|vh|vw)?\s*$/i,ho=t=>null==t||""===t||ao.test(t),lo=t=>{const e=document.createElement("canvas");return e.style.position="absolute",e.style.top="0",e.style.left="0",t.appendChild(e),e},uo=t=>{let e=window.devicePixelRatio,i=()=>{};const n=()=>{i();const s=matchMedia(`(resolution: ${e}dppx)`);s.addEventListener("change",n),i=()=>s.removeEventListener("change",n),window.devicePixelRatio!==e&&(e=window.devicePixelRatio,t(e))};return n(),()=>i()};class co extends t{constructor(t,e){super(),this._isOriginCentered=!1,this._isInitiallyRendered=!1,ro(t,null==e?void 0:e.areCollapsedContainerDimensionsAllowed),this._container=t,this._canvas=lo(t);const i=this._canvas.getContext("2d");if(!i)throw new o("Failed to create Canvas context.");this._context=i,this._width=640,this._height=480,this.transform=wn,this._settings=Object.assign(Object.assign({},zs),e),this._resizeObs=new ResizeObserver(()=>this._resize()),this._resizeObs.observe(this._container),this._resize(),d(null==e?void 0:e.devicePixelRatio)||(this._dprObserveUnsubscribe=uo(()=>this._resize())),this._throttleRender=so(t=>{this._render(t)},oo(this._settings.fps))}get width(){return this._width}get height(){return this._height}get container(){return this._container}get canvas(){return this._canvas}get isInitiallyRendered(){return this._isInitiallyRendered}getSettings(){return p(this._settings)}setSettings(t){var e;const i=t.fps&&t.fps!==this._settings.fps,n=this._settings.devicePixelRatio,s=t.devicePixelRatio;this._settings=Object.assign(Object.assign({},this._settings),t),i&&(this._throttleRender=so(t=>{this._render(t)},oo(this._settings.fps))),!d(n)&&d(s)&&(null===(e=this._dprObserveUnsubscribe)||void 0===e||e.call(this),this._resize()),d(n)&&null===s&&(this._dprObserveUnsubscribe=uo(()=>this._resize()))}render(t){this._throttleRender(t)}_render(t){this.emit(Bs.RENDER_START,void 0);const e=Date.now();this._context.clearRect(0,0,this._width,this._height),this._settings.backgroundColor&&(this._context.fillStyle=this._settings.backgroundColor.toString(),this._context.fillRect(0,0,this._width,this._height)),this._context.save(),this._context.translate(this.transform.x,this.transform.y),this._context.scale(this.transform.k,this.transform.k),this._isOriginCentered&&this._context.translate(this._width/2,this._height/2),this.drawObjects(t.getEdges()),this.drawObjects(t.getNodes()),this._context.restore(),this.emit(Bs.RENDER_END,{durationMs:Date.now()-e}),this._isInitiallyRendered=!0}drawObjects(t){if(0===t.length)return;const e=[],i=[];for(let n=0;n{var n,s;const o=null===(n=null==i?void 0:i.isShadowEnabled)||void 0===n||n,r=null===(s=null==i?void 0:i.isLabelEnabled)||void 0===s||s,a=e.hasShadow();((t,e)=>{if(e.hasBorder()){t.lineWidth=e.getBorderWidth();const i=e.getBorderColor();i&&(t.strokeStyle=i.toString())}const i=e.getColor();i&&(t.fillStyle=i.toString())})(t,e),o&&a&&((t,e)=>{const i=e.getStyle();i.shadowColor&&(t.shadowColor=i.shadowColor.toString()),i.shadowSize&&(t.shadowBlur=i.shadowSize),i.shadowOffsetX&&(t.shadowOffsetX=i.shadowOffsetX),i.shadowOffsetY&&(t.shadowOffsetY=i.shadowOffsetY)})(t,e),no(t,e),t.fill();const h=e.getBackgroundImage();h&&((t,e,i)=>{if(!i.width||!i.height)return;const n=e.getCenter(),s=e.getRadius(),o=Math.max(2*s/i.width,2*s/i.height),r=i.height*o,a=i.width*o;t.save(),t.clip(),t.drawImage(i,n.x-a/2,n.y-r/2,a,r),t.restore()})(t,e,h),o&&a&&((t,e)=>{const i=e.getStyle();i.shadowColor&&(t.shadowColor="rgba(0,0,0,0)"),i.shadowSize&&(t.shadowBlur=0),i.shadowOffsetX&&(t.shadowOffsetX=0),i.shadowOffsetY&&(t.shadowOffsetY=0)})(t,e),e.hasBorder()&&t.stroke(),r&&((t,e)=>{const i=e.getLabel();if(!i)return;const n=e.getCenter(),s=1.2*e.getBorderedRadius(),o=e.getStyle(),r=new js(i,{position:{x:n.x,y:n.y+s},textBaseline:Fs.TOP,properties:{fontBackgroundColor:o.fontBackgroundColor,fontColor:o.fontColor,fontFamily:o.fontFamily,fontSize:o.fontSize}});Ws(t,r)})(t,e)})(this._context,t,e):((t,e,i)=>{var n,s;if(!e.getWidth())return;const o=null===(n=null==i?void 0:i.isShadowEnabled)||void 0===n||n,r=null===(s=null==i?void 0:i.isLabelEnabled)||void 0===s||s,a=e.hasShadow();((t,e)=>{const i=e.getWidth();i>0&&(t.lineWidth=i);const n=e.getColor();n&&(t.strokeStyle=n.toString(),t.fillStyle=n.toString())})(t,e),o&&a&&((t,e)=>{const i=e.getStyle();i.shadowColor&&(t.shadowColor=i.shadowColor.toString()),i.shadowSize&&(t.shadowBlur=i.shadowSize),i.shadowOffsetX&&(t.shadowOffsetX=i.shadowOffsetX),i.shadowOffsetY&&(t.shadowOffsetY=i.shadowOffsetY)})(t,e),((t,e)=>{if(0===e.getStyle().arrowSize)return;const i=eo(e),n=io([{x:0,y:0},{x:-1,y:.4},{x:-1,y:-.4}],i);t.beginPath();for(let e=0;e{if(e instanceof O)return((t,e)=>{const i=e.startNode.getCenter(),n=e.endNode.getCenter();if(!i||!n)return;t.beginPath(),t.moveTo(i.x,i.y),t.lineTo(n.x,n.y);const s=e.getLineDashPattern();t.setLineDash(null!=s?s:[]),t.stroke()})(t,e);if(e instanceof k)return((t,e)=>{const i=e.startNode.getCenter(),n=e.endNode.getCenter();if(!i||!n)return;const s=e.getCurvedControlPoint();t.beginPath(),t.moveTo(i.x,i.y),t.quadraticCurveTo(s.x,s.y,n.x,n.y);const o=e.getLineDashPattern();t.setLineDash(null!=o?o:[]),t.stroke()})(t,e);if(e instanceof B)return((t,e)=>{const{x:i,y:n,radius:s}=e.getCircularData();t.beginPath(),t.arc(i,n,s,0,2*Math.PI,!1),t.closePath();const o=e.getLineDashPattern();t.setLineDash(null!=o?o:[]),t.stroke()})(t,e);throw new Error("Failed to draw unsupported edge type")})(t,e),o&&a&&((t,e)=>{const i=e.getStyle();i.shadowColor&&(t.shadowColor="rgba(0,0,0,0)"),i.shadowSize&&(t.shadowBlur=0),i.shadowOffsetX&&(t.shadowOffsetX=0),i.shadowOffsetY&&(t.shadowOffsetY=0)})(t,e),r&&((t,e)=>{const i=e.getLabel();if(!i)return;const n=e.getStyle(),s=new js(i,{position:e.getCenter(),textBaseline:Fs.MIDDLE,properties:{fontBackgroundColor:n.fontBackgroundColor,fontColor:n.fontColor,fontFamily:n.fontFamily,fontSize:n.fontSize}});Ws(t,s)})(t,e)})(this._context,t,e)}reset(){this.transform=wn,this._context.clearRect(0,0,this._width,this._height),this._context.save()}getFitZoomTransform(t,e){const i=t.getBoundingBox(),n="center"===(null==e?void 0:e.anchorX)?i.x+i.width/2:"end"===(null==e?void 0:e.anchorX)?i.x+i.width:0,s="center"===(null==e?void 0:e.anchorY)?i.y+i.height/2:"end"===(null==e?void 0:e.anchorY)?i.y+i.height:0,o=this.getSimulationViewRectangle(),r=o.height/(i.height*(1+this._settings.fitZoomMargin)),a=o.width/(i.width*(1+this._settings.fitZoomMargin)),h=Math.min(r,a),l=this.transform.k,d=Math.max(Math.min(h*l,this._settings.maxZoom),this._settings.minZoom),u=o.width/2*l*(1-d)-n*d,c=o.height/2*l*(1-d)-s*d;return wn.translate(u,c).scale(d)}getSimulationPosition(t){const[e,i]=this.transform.invert([t.x,t.y]);return{x:e-this._width/2,y:i-this._height/2}}getSimulationViewRectangle(){const t=this.getSimulationPosition({x:0,y:0}),e=this.getSimulationPosition({x:this._width,y:this._height});return{x:t.x,y:t.y,width:e.x-t.x,height:e.y-t.y}}translateOriginToCenter(){this._isOriginCentered=!0}destroy(){var t;this._resizeObs.unobserve(this._container),null===(t=this._dprObserveUnsubscribe)||void 0===t||t.call(this),this.removeAllListeners(),this._canvas.remove()}}const _o=(t,e,i)=>{const n=as(t,e,rs.VERTEX),s=as(t,i,rs.FRAGMENT),r=t.createProgram();if(!r)throw new o("Failed to create GL program.");if(t.attachShader(r,n),t.attachShader(r,s),t.linkProgram(r),!t.getProgramParameter(r,t.LINK_STATUS)){const e=t.getProgramInfoLog(r);throw t.deleteProgram(r),new o(`Failed to link GL program: ${e}`)}return t.deleteShader(n),t.deleteShader(s),r},fo=2048,go=2048;class po{constructor(t){this._texture=null,this._cache=new Map,this._shelves=[],this._isDirty=!1,this._isTextureAllocated=!1,this._gl=t,this._canvas=document.createElement("canvas"),this._canvas.width=fo,this._canvas.height=go,this._ctx=this._canvas.getContext("2d",{willReadFrequently:!1}),this._texture=t.createTexture(),t.bindTexture(t.TEXTURE_2D,this._texture),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.bindTexture(t.TEXTURE_2D,null)}getOrCreate(t,e,i,n,s){const o=`${t}|${e}|${i}|${n}|${null!=s?s:""}`,r=this._cache.get(o);if(r)return r;const a=t.split("\n").map(t=>t.trim());if(0===a.length||1===a.length&&""===a[0])return null;const h=this._ctx,l=`48px ${i}`;h.font=l;let d=0;for(let t=0;td&&(d=e)}const u=48*1.2,c=48+(a.length-1)*u,_=Math.ceil(d+11.52)+4,f=Math.ceil(c+11.52)+4,g=this._allocate(_,f);if(!g)return null;const p=g.x+2,m=g.y+2;s&&(h.fillStyle=s,h.fillRect(p,m,_-4,f-4)),h.font=l,h.fillStyle=n,h.textBaseline="top",h.textAlign="center";const v=p+(_-4)/2;for(let t=0;tgo)return null;const n={y:i,height:e,x:t};return this._shelves.push(n),{x:0,y:i}}}const mo=2048,vo=2048;class yo{constructor(t){this._texture=null,this._cache=new Map,this._pending=new Map,this._shelves=[],this._isDirty=!1,this._isTextureAllocated=!1,this._gl=t,this._canvas=document.createElement("canvas"),this._canvas.width=mo,this._canvas.height=vo,this._ctx=this._canvas.getContext("2d",{willReadFrequently:!1}),this._texture=t.createTexture(),t.bindTexture(t.TEXTURE_2D,this._texture),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.bindTexture(t.TEXTURE_2D,null)}getOrCreate(t){const e=this._cache.get(t);if(e)return e;const i=this._pending.get(t);if(i)return i.loaded?this._packImage(t,i.image):null;const n=new Image;n.crossOrigin="anonymous";const s={image:n,loaded:!1};return this._pending.set(t,s),n.onload=()=>{s.loaded=!0},n.onerror=()=>{this._pending.delete(t)},n.src=t,null}bind(t){const e=this._gl;e.activeTexture(e.TEXTURE0+t),e.bindTexture(e.TEXTURE_2D,this._texture)}uploadIfDirty(){if(!this._isDirty)return;const t=this._gl;t.bindTexture(t.TEXTURE_2D,this._texture),this._isTextureAllocated||(t.texImage2D(t.TEXTURE_2D,0,t.RGBA,mo,vo,0,t.RGBA,t.UNSIGNED_BYTE,null),this._isTextureAllocated=!0),t.texSubImage2D(t.TEXTURE_2D,0,0,0,t.RGBA,t.UNSIGNED_BYTE,this._canvas),t.bindTexture(t.TEXTURE_2D,null),this._isDirty=!1}clear(){this._cache.clear(),this._pending.clear(),this._shelves=[],this._isDirty=!1,this._ctx.clearRect(0,0,mo,vo)}_packImage(t,e){if(!e.naturalWidth||!e.naturalHeight)return null;const i=e.naturalWidth/e.naturalHeight;let n,s;e.naturalWidth>=e.naturalHeight?(n=Math.min(e.naturalWidth,128),s=Math.round(n/i)):(s=Math.min(e.naturalHeight,128),n=Math.round(s*i));const o=n+4,r=s+4,a=this._allocate(o,r);if(!a)return null;this._ctx.drawImage(e,a.x+2,a.y+2,n,s);const h={u0:(a.x+2)/mo,v0:(a.y+2)/vo,u1:(a.x+2+n)/mo,v1:(a.y+2+s)/vo,aspect:i};return this._cache.set(t,h),this._pending.delete(t),this._isDirty=!0,h}_allocate(t,e){for(let i=0;ivo)return null;const n={y:i,height:e,x:t};return this._shelves.push(n),{x:0,y:i}}}const xo=[0,0,0,0],bo=[.6,.6,.6,1],So=[1,0,0,1],wo={[S.CIRCLE]:0,[S.DOT]:1,[S.SQUARE]:2,[S.DIAMOND]:3,[S.TRIANGLE]:4,[S.TRIANGLE_DOWN]:5,[S.STAR]:6,[S.HEXAGON]:7},To="Roboto, sans-serif",Eo="#000000";class Po extends t{constructor(t,e){super(),this._isOriginCentered=!1,this._isInitiallyRendered=!1,this._nodeProgram=null,this._edgeProgram=null,this._labelProgram=null,this._nodeVao=null,this._edgeVao=null,this._labelVao=null,this._nodeInstanceBuffer=null,this._edgeInstanceBuffer=null,this._labelInstanceBuffer=null,this._labelCache=null,this._imageAtlas=null,this._isColorCacheDirty=!0,this._nodeColorCache=new Map,this._nodeBorderColorCache=new Map,this._nodeShadowColorCache=new Map,this._edgeColorCache=new Map,this._edgeShadowColorCache=new Map,this._lastNodeCount=0,this._lastEdgeCount=0,this._edgeInstanceData=null,this._nodeInstanceData=null,this._buffersAreCurrent=!1,this._bufferCacheStats={hits:0,misses:0},this._timerExt=null,this._timerEdgeQueries=[],this._timerNodeQueries=[],this._timerQueryIdx=0,this._lastEdgeGpuMs=null,this._lastNodeGpuMs=null,ro(t,null==e?void 0:e.areCollapsedContainerDimensionsAllowed),this._container=t,this._canvas=lo(t);const i=this._canvas.getContext("webgl2",{antialias:!0});if(!i)throw new o("Failed to create WebGL context.");if(this._gl=i,this._width=640,this._height=480,this.transform=wn,this._settings=Object.assign(Object.assign({},zs),e),"number"!=typeof(null==e?void 0:e.devicePixelRatio)&&(this._dprObserveUnsubscribe=uo(()=>{this._isInitiallyRendered&&this.emit(Bs.RESIZE,void 0)})),this._initShaders(),this._initNodeBuffers(),this._initEdgeBuffers(),this._initLabelBuffers(),this._labelCache=new po(this._gl),this._imageAtlas=new yo(this._gl),this._timerExt=i.getExtension("EXT_disjoint_timer_query_webgl2"),this._timerExt)for(let t=0;t<4;t++){const t=i.createQuery(),e=i.createQuery();t&&this._timerEdgeQueries.push(t),e&&this._timerNodeQueries.push(e)}}_pollTimerQuery(t){if(!this._timerExt)return null;const e=this._gl;return e.getQueryParameter(t,e.QUERY_RESULT_AVAILABLE)?e.getParameter(this._timerExt.GPU_DISJOINT_EXT)?null:e.getQueryParameter(t,e.QUERY_RESULT)/1e6:null}getGpuTimeStats(){return{edgeMs:this._lastEdgeGpuMs,nodeMs:this._lastNodeGpuMs,supported:null!==this._timerExt}}_initShaders(){this._nodeProgram=_o(this._gl,"#version 300 es\n\nprecision highp float;\n\nin vec2 aQuadPosition;\n\nin vec2 aCenter;\nin float aRadius;\nin vec4 aColor;\nin vec4 aBorderColor;\nin float aBorderWidth;\nin vec4 aShadowColor;\nin float aShadowSize;\nin float aShadowOffsetX;\nin float aShadowOffsetY;\nin float aShapeType;\nin vec2 aImageUV0;\nin vec2 aImageUV1;\nin float aImageAspect;\n\nuniform vec2 uResolution;\nuniform vec2 uTranslation;\nuniform float uScale;\nuniform vec2 uOriginOffset;\n\nout vec2 vUV;\nout vec4 vColor;\nout vec4 vBorderColor;\nout float vBorderThreshold;\nout vec4 vShadowColor;\nout float vNodeRadius;\nout vec2 vShadowOffset;\nout float vShadowBlur;\nflat out int vShapeType;\nout vec2 vImageUV0;\nout vec2 vImageUV1;\nout float vImageAspect;\n\nvoid main() {\n vShapeType = int(aShapeType + 0.5);\n vColor = aColor;\n vBorderColor = aBorderColor;\n vShadowColor = aShadowColor;\n vImageUV0 = aImageUV0;\n vImageUV1 = aImageUV1;\n vImageAspect = aImageAspect;\n\n float totalRadius = aRadius + aShadowSize + abs(aShadowOffsetX) + abs(aShadowOffsetY);\n\n vUV = aQuadPosition;\n vNodeRadius = aRadius / totalRadius;\n\n vBorderThreshold = vNodeRadius * (1.0 - aBorderWidth / aRadius);\n\n vShadowOffset = vec2(aShadowOffsetX, aShadowOffsetY) / totalRadius;\n\n vShadowBlur = aShadowSize / totalRadius;\n\n vec2 worldPos = aCenter + aQuadPosition * totalRadius;\n vec2 screenPos = (worldPos + uOriginOffset) * uScale + uTranslation;\n\n vec2 clip = (screenPos / uResolution) * 2.0 - 1.0;\n gl_Position = vec4(clip.x, -clip.y, 0.0, 1.0);\n}\n","#version 300 es\n\nprecision highp float;\n\nin vec2 vUV;\nin vec4 vColor;\nin vec4 vBorderColor;\nin float vBorderThreshold;\nin vec4 vShadowColor;\nin float vNodeRadius;\nin vec2 vShadowOffset;\nin float vShadowBlur;\nflat in int vShapeType;\nin vec2 vImageUV0;\nin vec2 vImageUV1;\nin float vImageAspect;\n\nuniform sampler2D uImageAtlas;\n\nout vec4 fragColor;\n\nconst int SHAPE_CIRCLE = 0;\nconst int SHAPE_DOT = 1;\nconst int SHAPE_SQUARE = 2;\nconst int SHAPE_DIAMOND = 3;\nconst int SHAPE_TRIANGLE = 4;\nconst int SHAPE_TRIANGLE_DOWN = 5;\nconst int SHAPE_STAR = 6;\nconst int SHAPE_HEXAGON = 7;\n\nfloat sdCircle(vec2 p, float r) {\n return length(p) - r;\n}\n\nfloat sdSquare(vec2 p, float r) {\n vec2 d = abs(p) - vec2(r);\n return max(d.x, d.y);\n}\n\nfloat sdDiamond(vec2 p, float r) {\n return (abs(p.x) + abs(p.y)) - r;\n}\n\nfloat sdTriangleDown(vec2 p, float r) {\n float sr = r * 1.15;\n vec2 q = vec2(p.x, p.y - 0.275 * sr);\n\n float k = sqrt(3.0);\n q.x = abs(q.x) - sr;\n q.y = q.y + sr / k;\n if (q.x + k * q.y > 0.0) {\n q = vec2(q.x - k * q.y, -k * q.x - q.y) / 2.0;\n }\n q.x -= clamp(q.x, -2.0 * sr, 0.0);\n return -length(q) * sign(q.y);\n}\n\nfloat sdTriangleUp(vec2 p, float r) {\n return sdTriangleDown(vec2(p.x, -p.y), r);\n}\n\nfloat sdStar(vec2 p, float r) {\n float sr = r * 0.82;\n vec2 q = vec2(p.x, p.y - 0.1 * sr);\n\n float outerR = sr * 1.3;\n float innerR = sr * 0.5;\n\n float angle = atan(q.x, -q.y);\n float sector = 6.2831853 / 5.0;\n float a = mod(angle + sector * 0.5, sector) - sector * 0.5;\n\n float cosA = cos(a);\n float sinA = abs(sin(a));\n\n float halfSector = sector * 0.5;\n vec2 outerPt = vec2(outerR, 0.0);\n vec2 innerPt = vec2(innerR * cos(halfSector), innerR * sin(halfSector));\n\n vec2 sp = vec2(cosA, sinA) * length(q);\n\n vec2 edge = innerPt - outerPt;\n vec2 toP = sp - outerPt;\n float t = clamp(dot(toP, edge) / dot(edge, edge), 0.0, 1.0);\n float dist = length(toP - edge * t);\n\n float cross2d = edge.x * toP.y - edge.y * toP.x;\n return cross2d > 0.0 ? -dist : dist;\n}\n\nfloat sdHexagon(vec2 p, float r) {\n vec2 q = abs(p);\n float k = sqrt(3.0);\n float d = max(q.x, (q.x * 0.5 + q.y * (k * 0.5)));\n return d - r;\n}\n\nfloat shapeSDF(vec2 p, float r, int shapeType) {\n if (shapeType == SHAPE_SQUARE) return sdSquare(p, r);\n if (shapeType == SHAPE_DIAMOND) return sdDiamond(p, r);\n if (shapeType == SHAPE_TRIANGLE) return sdTriangleUp(p, r);\n if (shapeType == SHAPE_TRIANGLE_DOWN) return sdTriangleDown(p, r);\n if (shapeType == SHAPE_STAR) return sdStar(p, r);\n if (shapeType == SHAPE_HEXAGON) return sdHexagon(p, r);\n\n return sdCircle(p, r);\n}\n\nvoid main() {\n // Body SDF - always needed.\n float dist = shapeSDF(vUV, vNodeRadius, vShapeType);\n\n float aa = 0.02 * vNodeRadius;\n float nodeAlpha = 1.0 - smoothstep(-aa, 0.0, dist);\n\n // Shadow SDF - skip entirely when no shadow. Avoids a second full shapeSDF() call\n // (which is a cascade of ifs) and the exp() per fragment.\n float shadowAlpha = 0.0;\n if (vShadowBlur > 0.0) {\n float shadowDist = shapeSDF(vUV - vShadowOffset, vNodeRadius, vShapeType);\n float t = max(shadowDist, 0.0) / vShadowBlur;\n shadowAlpha = exp(-t * t * 1.5) * 0.5 * vShadowColor.a;\n }\n\n vec4 fillColor = vColor;\n if (vImageAspect > 0.0 && dist < 0.0) {\n vec2 uv01 = (vUV / vNodeRadius) * 0.5 + 0.5;\n if (vImageAspect > 1.0) {\n uv01.x = (uv01.x - 0.5) / vImageAspect + 0.5;\n } else {\n uv01.y = (uv01.y - 0.5) * vImageAspect + 0.5;\n }\n if (uv01.x >= 0.0 && uv01.x <= 1.0 && uv01.y >= 0.0 && uv01.y <= 1.0) {\n vec2 atlasUV = mix(vImageUV0, vImageUV1, uv01);\n vec4 imgTexel = texture(uImageAtlas, atlasUV);\n fillColor = mix(fillColor, vec4(imgTexel.rgb, 1.0), imgTexel.a);\n }\n }\n\n vec4 nodeColor;\n if (vBorderThreshold < vNodeRadius) {\n float borderDist = shapeSDF(vUV, vBorderThreshold, vShapeType);\n float borderMix = smoothstep(-aa, aa, borderDist);\n nodeColor = mix(fillColor, vBorderColor, borderMix);\n } else {\n nodeColor = fillColor;\n }\n nodeColor.a *= nodeAlpha;\n\n float finalAlpha = nodeColor.a + shadowAlpha * (1.0 - nodeColor.a);\n\n if (finalAlpha < 0.001) {\n discard;\n }\n\n if (shadowAlpha > 0.0) {\n vec3 finalRGB = (nodeColor.rgb * nodeColor.a + vShadowColor.rgb * shadowAlpha * (1.0 - nodeColor.a)) / finalAlpha;\n fragColor = vec4(finalRGB, finalAlpha);\n } else {\n fragColor = nodeColor;\n }\n}\n"),this._edgeProgram=_o(this._gl,"#version 300 es\n\nprecision highp float;\n\nin vec2 aQuadPosition;\n\nin vec2 aStart;\nin vec2 aEnd;\nin vec2 aControl;\nin float aWidth;\nin float aEdgeType;\nin float aLoopbackRadius;\nin float aArrowSize;\nin vec2 aArrowTip;\nin vec2 aArrowDir;\nin vec4 aColor;\nin vec4 aShadowColor;\nin float aShadowSize;\nin float aShadowOffsetX;\nin float aShadowOffsetY;\n\nuniform vec2 uResolution;\nuniform vec2 uTranslation;\nuniform float uScale;\nuniform vec2 uOriginOffset;\n\nout vec2 vWorldPos;\nout vec2 vStart;\nout vec2 vEnd;\nout vec2 vControl;\nout float vHalfWidth;\nout float vWidthFade;\nout float vHalfWidthPx;\nout float vPerpPx;\nout float vLoopbackRadius;\nout float vArrowSize;\nout vec2 vArrowTip;\nout vec2 vArrowDir;\nout vec4 vColor;\nout vec4 vShadowColor;\nout float vShadowSize;\nout vec2 vShadowOffset;\nflat out int vEdgeType;\n\nvoid main() {\n vEdgeType = int(aEdgeType + 0.5);\n vStart = aStart;\n vEnd = aEnd;\n vControl = aControl;\n float effectiveWidth = max(aWidth, 1.0 / uScale);\n vHalfWidth = effectiveWidth * 0.5;\n vWidthFade = clamp(aWidth * uScale, 0.0, 1.0);\n vHalfWidthPx = vHalfWidth * uScale;\n vPerpPx = 0.0;\n vLoopbackRadius = aLoopbackRadius;\n vArrowSize = aArrowSize;\n vArrowTip = aArrowTip;\n vArrowDir = aArrowDir;\n vColor = aColor;\n vShadowColor = aShadowColor;\n vShadowSize = aShadowSize;\n vShadowOffset = vec2(aShadowOffsetX, aShadowOffsetY);\n\n float pad = vHalfWidth + aShadowSize + abs(aShadowOffsetX) + abs(aShadowOffsetY);\n\n vec2 worldPos;\n\n if (vEdgeType == 0) {\n vec2 dir = aEnd - aStart;\n float len = length(dir);\n vec2 unitDir = dir / max(len, 0.0001);\n vec2 perp = vec2(-unitDir.y, unitDir.x);\n float totalHalf = pad + aArrowSize;\n vec2 midpoint = (aStart + aEnd) * 0.5;\n worldPos = midpoint\n + unitDir * (len * 0.5 + totalHalf) * aQuadPosition.x\n + perp * totalHalf * aQuadPosition.y;\n vPerpPx = totalHalf * aQuadPosition.y * uScale;\n } else if (vEdgeType == 1) {\n float margin = pad + aArrowSize;\n vec2 bboxMin = min(min(aStart, aEnd), aControl) - margin;\n vec2 bboxMax = max(max(aStart, aEnd), aControl) + margin;\n vec2 center = (bboxMin + bboxMax) * 0.5;\n vec2 halfSize = (bboxMax - bboxMin) * 0.5;\n worldPos = center + aQuadPosition * halfSize;\n } else {\n float margin = pad + aArrowSize;\n vec2 ctr = aControl;\n float r = aLoopbackRadius;\n vec2 bboxMin = min(ctr - (r + margin), aStart - margin);\n vec2 bboxMax = max(ctr + (r + margin), aStart + margin);\n vec2 center = (bboxMin + bboxMax) * 0.5;\n vec2 halfSize = (bboxMax - bboxMin) * 0.5;\n worldPos = center + aQuadPosition * halfSize;\n }\n\n vWorldPos = worldPos;\n vec2 screenPos = (worldPos + uOriginOffset) * uScale + uTranslation;\n vec2 clip = (screenPos / uResolution) * 2.0 - 1.0;\n gl_Position = vec4(clip.x, -clip.y, 0.0, 1.0);\n}\n","#version 300 es\n\nprecision highp float;\n\nin vec2 vWorldPos;\nin vec2 vStart;\nin vec2 vEnd;\nin vec2 vControl;\nin float vHalfWidth;\nin float vWidthFade;\nin float vHalfWidthPx;\nin float vPerpPx;\nin float vLoopbackRadius;\nin float vArrowSize;\nin vec2 vArrowTip;\nin vec2 vArrowDir;\nin vec4 vColor;\nin vec4 vShadowColor;\nin float vShadowSize;\nin vec2 vShadowOffset;\nflat in int vEdgeType;\n\nuniform bool uSimpleMode;\n\nout vec4 fragColor;\n\nfloat sdSegment(vec2 p, vec2 a, vec2 b) {\n vec2 pa = p - a;\n vec2 ba = b - a;\n float h = clamp(dot(pa, ba) / dot(ba, ba), 0.0, 1.0);\n return length(pa - ba * h);\n}\n\nfloat sdBezier(vec2 pos, vec2 A, vec2 B, vec2 C) {\n vec2 a = B - A;\n vec2 b = A - 2.0 * B + C;\n vec2 c = a * 2.0;\n vec2 d = A - pos;\n\n float kk = 1.0 / max(dot(b, b), 0.0001);\n float kx = kk * dot(a, b);\n float ky = kk * (2.0 * dot(a, a) + dot(d, b)) / 3.0;\n float kz = kk * dot(d, a);\n\n float p = ky - kx * kx;\n float q = kx * (2.0 * kx * kx - 3.0 * ky) + kz;\n float p3 = p * p * p;\n float q2 = q * q;\n float h = q2 + 4.0 * p3;\n\n float res;\n if (h >= 0.0) {\n h = sqrt(h);\n vec2 x = (vec2(h, -h) - q) / 2.0;\n vec2 uv = sign(x) * pow(abs(x), vec2(1.0 / 3.0));\n float t = clamp(uv.x + uv.y - kx, 0.0, 1.0);\n vec2 qo = d + (c + b * t) * t;\n res = dot(qo, qo);\n } else {\n float z = sqrt(-p);\n float v = acos(q / (p * z * 2.0)) / 3.0;\n float m = cos(v);\n float n = sin(v) * 1.732050808;\n vec3 t = clamp(vec3(m + m, -n - m, n - m) * z - kx, 0.0, 1.0);\n vec2 qx = d + (c + b * t.x) * t.x;\n float dx = dot(qx, qx);\n vec2 qy = d + (c + b * t.y) * t.y;\n float dy = dot(qy, qy);\n res = min(dx, dy);\n }\n\n return sqrt(res);\n}\n\nfloat sdArrow(vec2 p, vec2 tip, vec2 dir, float size) {\n if (size <= 0.0) return 1e6;\n\n vec2 perp = vec2(-dir.y, dir.x);\n vec2 rel = p - tip;\n float along = dot(rel, -dir);\n float across = dot(rel, perp);\n\n if (along < 0.0) return length(rel);\n if (along > size) {\n float hw = size * 0.4;\n float closest = clamp(across, -hw, hw);\n vec2 pt = tip - dir * size + perp * closest;\n return length(p - pt);\n }\n\n float halfW = (along / size) * size * 0.4;\n float d = abs(across) - halfW;\n return d;\n}\n\nvoid main() {\n if (uSimpleMode && vEdgeType == 0) {\n float cover = clamp(vHalfWidthPx - abs(vPerpPx) + 0.5, 0.0, 1.0);\n float a = cover * vWidthFade;\n if (a < 0.001) discard;\n fragColor = vec4(vColor.rgb, vColor.a * a);\n return;\n }\n\n float dist;\n if (vEdgeType == 0) {\n dist = sdSegment(vWorldPos, vStart, vEnd);\n } else if (vEdgeType == 1) {\n dist = sdBezier(vWorldPos, vStart, vControl, vEnd);\n } else {\n dist = abs(length(vWorldPos - vControl) - vLoopbackRadius);\n }\n\n float edgeSdf = dist - vHalfWidth;\n float combinedSdf = edgeSdf;\n\n if (vArrowSize > 0.0) {\n float arrowDist = sdArrow(vWorldPos, vArrowTip, vArrowDir, vArrowSize);\n combinedSdf = min(edgeSdf, arrowDist);\n }\n\n float shadowAlpha = 0.0;\n if (vShadowSize > 0.0) {\n vec2 shadowPos = vWorldPos - vShadowOffset;\n float shadowDist;\n if (vEdgeType == 0) {\n shadowDist = sdSegment(shadowPos, vStart, vEnd);\n } else if (vEdgeType == 1) {\n shadowDist = sdBezier(shadowPos, vStart, vControl, vEnd);\n } else {\n shadowDist = abs(length(shadowPos - vControl) - vLoopbackRadius);\n }\n float shadowArrowDist = vArrowSize > 0.0\n ? sdArrow(shadowPos, vArrowTip, vArrowDir, vArrowSize)\n : 1.0e6;\n float shadowCombined = min(shadowDist - vHalfWidth, shadowArrowDist);\n float t = max(shadowCombined, 0.0) / vShadowSize;\n shadowAlpha = exp(-t * t * 1.5) * 0.5 * vShadowColor.a;\n }\n\n float aa = fwidth(combinedSdf);\n float edgeAlpha = (1.0 - smoothstep(-aa, aa, combinedSdf)) * vWidthFade;\n vec4 edgeColor = vColor;\n edgeColor.a *= edgeAlpha;\n\n float finalAlpha = edgeColor.a + shadowAlpha * (1.0 - edgeColor.a);\n\n if (finalAlpha < 0.001) discard;\n\n if (shadowAlpha > 0.0) {\n vec3 finalRGB = (edgeColor.rgb * edgeColor.a + vShadowColor.rgb * shadowAlpha * (1.0 - edgeColor.a)) / finalAlpha;\n fragColor = vec4(finalRGB, finalAlpha);\n } else {\n fragColor = edgeColor;\n }\n}\n"),this._labelProgram=_o(this._gl,"#version 300 es\n\nin vec2 aQuadPosition;\n\nin vec2 aLabelCenter;\nin vec2 aLabelSize;\nin vec2 aLabelUV0;\nin vec2 aLabelUV1;\n\nuniform vec2 uResolution;\nuniform vec2 uTranslation;\nuniform float uScale;\nuniform vec2 uOriginOffset;\n\nout vec2 vAtlasUV;\n\nvoid main() {\n vec2 worldPos = aLabelCenter + aQuadPosition * aLabelSize;\n vec2 screenPos = (worldPos + uOriginOffset) * uScale + uTranslation;\n vec2 clip = (screenPos / uResolution) * 2.0 - 1.0;\n gl_Position = vec4(clip.x, -clip.y, 0.0, 1.0);\n\n vec2 uv01 = aQuadPosition * 0.5 + 0.5;\n vAtlasUV = mix(aLabelUV0, aLabelUV1, uv01);\n}\n","#version 300 es\n\nprecision highp float;\n\nuniform sampler2D uAtlas;\n\nin vec2 vAtlasUV;\n\nout vec4 fragColor;\n\nvoid main() {\n vec4 texel = texture(uAtlas, vAtlasUV);\n if (texel.a < 0.01) discard;\n fragColor = texel;\n}\n")}_initNodeBuffers(){if(!this._nodeProgram)throw new o("Node program not initialized.");const t=this._gl;this._nodeVao=t.createVertexArray(),t.bindVertexArray(this._nodeVao);const e=new Float32Array([-1,-1,1,-1,-1,1,1,1]),i=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,i),t.bufferData(t.ARRAY_BUFFER,e,t.STATIC_DRAW);const n=t.getAttribLocation(this._nodeProgram,"aQuadPosition");t.enableVertexAttribArray(n),t.vertexAttribPointer(n,2,t.FLOAT,!1,0,0),this._nodeInstanceBuffer=t.createBuffer(),t.bindBuffer(t.ARRAY_BUFFER,this._nodeInstanceBuffer);const s=25*Float32Array.BYTES_PER_ELEMENT,r=(e,i,n)=>{const o=t.getAttribLocation(this._nodeProgram,e);t.enableVertexAttribArray(o),t.vertexAttribPointer(o,i,t.FLOAT,!1,s,4*n),t.vertexAttribDivisor(o,1)};r("aCenter",2,0),r("aRadius",1,2),r("aColor",4,3),r("aBorderColor",4,7),r("aBorderWidth",1,11),r("aShadowColor",4,12),r("aShadowSize",1,16),r("aShadowOffsetX",1,17),r("aShadowOffsetY",1,18),r("aShapeType",1,19),r("aImageUV0",2,20),r("aImageUV1",2,22),r("aImageAspect",1,24),t.bindVertexArray(null)}_initEdgeBuffers(){if(!this._edgeProgram)throw new o("Edge program not initialized.");const t=this._gl;this._edgeVao=t.createVertexArray(),t.bindVertexArray(this._edgeVao);const e=new Float32Array([-1,-1,1,-1,-1,1,1,1]),i=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,i),t.bufferData(t.ARRAY_BUFFER,e,t.STATIC_DRAW);const n=t.getAttribLocation(this._edgeProgram,"aQuadPosition");t.enableVertexAttribArray(n),t.vertexAttribPointer(n,2,t.FLOAT,!1,0,0),this._edgeInstanceBuffer=t.createBuffer(),t.bindBuffer(t.ARRAY_BUFFER,this._edgeInstanceBuffer);const s=(e,i,n)=>{const s=t.getAttribLocation(this._edgeProgram,e);t.enableVertexAttribArray(s),t.vertexAttribPointer(s,i,t.FLOAT,!1,100,4*n),t.vertexAttribDivisor(s,1)};s("aStart",2,0),s("aEnd",2,2),s("aControl",2,4),s("aWidth",1,6),s("aEdgeType",1,7),s("aLoopbackRadius",1,8),s("aArrowSize",1,9),s("aArrowTip",2,10),s("aArrowDir",2,12),s("aColor",4,14),s("aShadowColor",4,18),s("aShadowSize",1,22),s("aShadowOffsetX",1,23),s("aShadowOffsetY",1,24),t.bindVertexArray(null)}_initLabelBuffers(){if(!this._labelProgram)throw new o("Label program not initialized.");const t=this._gl;this._labelVao=t.createVertexArray(),t.bindVertexArray(this._labelVao);const e=new Float32Array([-1,-1,1,-1,-1,1,1,1]),i=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,i),t.bufferData(t.ARRAY_BUFFER,e,t.STATIC_DRAW);const n=t.getAttribLocation(this._labelProgram,"aQuadPosition");t.enableVertexAttribArray(n),t.vertexAttribPointer(n,2,t.FLOAT,!1,0,0),this._labelInstanceBuffer=t.createBuffer(),t.bindBuffer(t.ARRAY_BUFFER,this._labelInstanceBuffer);const s=(e,i,n)=>{const s=t.getAttribLocation(this._labelProgram,e);t.enableVertexAttribArray(s),t.vertexAttribPointer(s,i,t.FLOAT,!1,32,4*n),t.vertexAttribDivisor(s,1)};s("aLabelCenter",2,0),s("aLabelSize",2,2),s("aLabelUV0",2,4),s("aLabelUV1",2,6),t.bindVertexArray(null)}_resolveColor(t){if(!t)return[1,0,0,1];if(t instanceof U)return[t.rgb.r/255,t.rgb.g/255,t.rgb.b/255,1];const e=t.match(/^rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+))?\s*\)$/);if(e)return[parseInt(e[1])/255,parseInt(e[2])/255,parseInt(e[3])/255,void 0!==e[4]?parseFloat(e[4]):1];const i=new U(t);return[i.rgb.r/255,i.rgb.g/255,i.rgb.b/255,1]}_buildNodeColorCache(t){this._nodeColorCache.clear();for(let e=0;e0)if(M=1.5*R+3*(w||1),0===E){const t=a-o,e=h-r,i=Math.sqrt(t*t+e*e);i>0&&(I=t/i,L=e/i,N=a-I*l,D=h-L*l)}else if(1===E){let t=1,e=.5,i=1;for(let n=0;n<8;n++){const n=.5*(e+i),s=1-n,d=s*s*o+2*n*s*P+n*n*a,u=s*s*r+2*n*s*A+n*n*h,c=Math.sqrt(Math.pow(d-a,2)+Math.pow(u-h,2));if(Math.abs(c-l)<.1){t=n;break}c>l?e=n:i=n,t=n}const n=1-t;N=n*n*o+2*t*n*P+t*t*a,D=n*n*r+2*t*n*A+t*t*h;const s=2*n*(P-o)+2*t*(a-P),d=2*n*(A-r)+2*t*(h-A),u=Math.sqrt(s*s+d*d);u>0&&(I=s/u,L=d/u)}else{let t=.8,e=.6,i=1;for(let n=0;n<8;n++){const n=.5*(e+i),s=2*n*Math.PI,a=P+C*Math.cos(s),h=A-C*Math.sin(s),l=Math.sqrt(Math.pow(a-o,2)+Math.pow(h-r,2));if(Math.abs(l-d)<.1){t=n;break}l>d?i=n:e=n,t=n}const n=2*t*Math.PI;N=P+C*Math.cos(n),D=A-C*Math.sin(n);const s=-2*t*Math.PI+.45*Math.PI;I=Math.cos(s),L=Math.sin(s)}p[S]=o,p[S+1]=r,p[S+2]=a,p[S+3]=h,p[S+4]=P,p[S+5]=A,p[S+6]=w,p[S+7]=E,p[S+8]=C,p[S+9]=M,p[S+10]=N,p[S+11]=D,p[S+12]=I,p[S+13]=L,p[S+14]=T[0],p[S+15]=T[1],p[S+16]=T[2],p[S+17]=T[3],p[S+18]=m[0],p[S+19]=m[1],p[S+20]=m[2],p[S+21]=m[3],p[S+22]=c,p[S+23]=f,p[S+24]=g}h.useProgram(this._edgeProgram),this._setViewUniforms(this._edgeProgram),h.bindBuffer(h.ARRAY_BUFFER,this._edgeInstanceBuffer),m||(h.bufferData(h.ARRAY_BUFFER,p.byteLength,h.STREAM_DRAW),h.bufferSubData(h.ARRAY_BUFFER,0,p));const w=this.transform.k<=.2,T=h.getUniformLocation(this._edgeProgram,"uSimpleMode");if(h.uniform1i(T,w?1:0),h.bindVertexArray(this._edgeVao),this._timerExt&&this._timerEdgeQueries.length>0){const t=this._timerEdgeQueries[this._timerQueryIdx],e=this._pollTimerQuery(t);null!==e&&(this._lastEdgeGpuMs=e),h.beginQuery(this._timerExt.TIME_ELAPSED_EXT,t)}h.drawArraysInstanced(h.TRIANGLE_STRIP,0,4,_.length),this._timerExt&&this._timerEdgeQueries.length>0&&h.endQuery(this._timerExt.TIME_ELAPSED_EXT),h.bindVertexArray(null),w&&h.enable(h.BLEND),h.useProgram(this._nodeProgram),this._setViewUniforms(this._nodeProgram),this._imageAtlas&&(this._imageAtlas.uploadIfDirty(),this._imageAtlas.bind(0),h.uniform1i(h.getUniformLocation(this._nodeProgram,"uImageAtlas"),0));const E=t.getNodes(),P=this.transform.k,A=25*E.length,C=null===this._nodeInstanceData||this._nodeInstanceData.length!==A;C&&(this._nodeInstanceData=new Float32Array(A));const M=this._nodeInstanceData,N=m&&!C;if(N||E.length===this._lastNodeCount&&!this._isColorCacheDirty||(this._buildNodeColorCache(E),this._buildNodeBorderColorCache(E),this._buildNodeShadowColorCache(E),this._isColorCacheDirty=!1,this._lastNodeCount=E.length),!N)for(let t=0;t=4){const t=e.isSelected()&&r.imageUrlSelected||r.imageUrl;if(t&&this._imageAtlas){const e=this._imageAtlas.getOrCreate(t);e&&(g=e.u0,p=e.v0,m=e.u1,v=e.v1,y=e.aspect)}}M[u+20]=g,M[u+21]=p,M[u+22]=m,M[u+23]=v,M[u+24]=y}if(h.bindBuffer(h.ARRAY_BUFFER,this._nodeInstanceBuffer),N||(h.bufferData(h.ARRAY_BUFFER,M.byteLength,h.STREAM_DRAW),h.bufferSubData(h.ARRAY_BUFFER,0,M)),this._buffersAreCurrent=!0,h.bindVertexArray(this._nodeVao),this._timerExt&&this._timerNodeQueries.length>0){const t=this._timerNodeQueries[this._timerQueryIdx],e=this._pollTimerQuery(t);null!==e&&(this._lastNodeGpuMs=e),h.beginQuery(this._timerExt.TIME_ELAPSED_EXT,t)}if(h.drawArraysInstanced(h.TRIANGLE_STRIP,0,4,E.length),this._timerExt&&this._timerNodeQueries.length>0&&(h.endQuery(this._timerExt.TIME_ELAPSED_EXT),this._timerQueryIdx=(this._timerQueryIdx+1)%this._timerNodeQueries.length),h.bindVertexArray(null),this._labelProgram&&this._labelCache&&this._settings.labelsIsEnabled){const t=this._labelCache,e=t.rasterFontPx;let i=0;const n=E.length+_.length,o=new Float32Array(8*n);for(let n=0;n0&&(t.uploadIfDirty(),h.useProgram(this._labelProgram),this._setViewUniforms(this._labelProgram),t.bind(0),h.uniform1i(h.getUniformLocation(this._labelProgram,"uAtlas"),0),h.bindBuffer(h.ARRAY_BUFFER,this._labelInstanceBuffer),h.bufferData(h.ARRAY_BUFFER,o.subarray(0,8*i),h.DYNAMIC_DRAW),h.bindVertexArray(this._labelVao),h.drawArraysInstanced(h.TRIANGLE_STRIP,0,4,i),h.bindVertexArray(null))}this._isInitiallyRendered=!0,this.emit(Bs.RENDER_END,{durationMs:performance.now()-a})}reset(){this.transform=wn;const t=this._gl;t.clearColor(0,0,0,0),t.clear(t.COLOR_BUFFER_BIT)}getFitZoomTransform(t){const e=t.getBoundingBox(),i=e.x+e.width/2,n=e.y+e.height/2,s=this.getSimulationViewRectangle(),o=s.height/(e.height*(1+this._settings.fitZoomMargin)),r=s.width/(e.width*(1+this._settings.fitZoomMargin)),a=Math.min(o,r),h=this.transform.k,l=Math.max(Math.min(a*h,this._settings.maxZoom),this._settings.minZoom),d=s.width/2*h*(1-l)-i*l,u=s.height/2*h*(1-l)-n*l;return wn.translate(d,u).scale(l)}getSimulationPosition(t){const[e,i]=this.transform.invert([t.x,t.y]);return{x:e-this._width/2,y:i-this._height/2}}getSimulationViewRectangle(){const t=this.getSimulationPosition({x:0,y:0}),e=this.getSimulationPosition({x:this._width,y:this._height});return{x:t.x,y:t.y,width:e.x-t.x,height:e.y-t.y}}translateOriginToCenter(){this._isOriginCentered=!0}destroy(){var t,e;null===(t=this._dprObserveUnsubscribe)||void 0===t||t.call(this),this.removeAllListeners(),null===(e=this._gl.getExtension("WEBGL_lose_context"))||void 0===e||e.loseContext(),this._canvas.remove()}_setViewUniforms(t){const e=this._gl,i=this._isOriginCentered?this._width/2:0,n=this._isOriginCentered?this._height/2:0;e.uniform2f(e.getUniformLocation(t,"uResolution"),this._width,this._height),e.uniform2f(e.getUniformLocation(t,"uTranslation"),this.transform.x,this.transform.y),e.uniform1f(e.getUniformLocation(t,"uScale"),this.transform.k),e.uniform2f(e.getUniformLocation(t,"uOriginOffset"),i,n)}}class Ao{static getRenderer(t,e=ks.CANVAS,i){return e===ks.WEBGL?new Po(t,i):new co(t,i)}}const Co=t=>isFinite(t)?""+Math.round(1e3*t)/1e3:"0",Mo=t=>t.replace(/&/g,"&").replace(//g,">").replace(/"/g,""").replace(/'/g,"'"),No=(t,e,i)=>{const n=Object.keys(e).filter(t=>{const i=e[t];return null!=i&&""!==i}).map(t=>{const i=e[t];return`${t}="${"number"==typeof i?Co(i):Mo(String(i))}"`}).join(" "),s=n?`${t} ${n}`:t;return void 0===i?`<${s}/>`:`<${s}>${i}`},Do=t=>t.map(t=>`${Co(t.x)},${Co(t.y)}`).join(" "),Io=t=>({tag:"polygon",attributes:{points:Do(t)}}),Lo=(t,e)=>{var i,n;if(null==t||""==`${t}`)return"";const s=new js(t,{position:e.position,textBaseline:e.textBaseline,properties:e.properties});if(!s.textLines.length||s.fontSize<=0)return"";const o=null!==(i=e.properties.fontFamily)&&void 0!==i?i:"Roboto, sans-serif",r=(null!==(n=e.properties.fontColor)&&void 0!==n?n:"#000000").toString(),a=1.2*s.fontSize,h=e.textBaseline===Fs.MIDDLE?"middle":"text-before-edge",l=Ro(s,a),d=s.textLines.map((t,e)=>No("tspan",{x:s.position.x,dy:0===e?0:a},Mo(t))).join("");return`${l}${No("text",{x:s.position.x,y:s.position.y,"font-size":s.fontSize,"font-family":o,fill:r,"text-anchor":"middle","dominant-baseline":h},d)}`},Ro=(t,e)=>{const i=t.properties.fontBackgroundColor;if(!i)return"";const n=.12*t.fontSize,s=t.fontSize+2*n,o=t.textBaseline===Fs.MIDDLE?t.fontSize/2:0,r=i.toString();return t.textLines.map((i,a)=>{const h=i.length*t.fontSize*.6+2*n;return No("rect",{x:t.position.x-h/2,y:t.position.y-o-n+a*e,width:h,height:s,fill:r})}).join("")},Oo=t=>{if("undefined"!=typeof document)try{const e=document.createElement("canvas");e.width=t.naturalWidth||t.width,e.height=t.naturalHeight||t.height;const i=e.getContext("2d");if(!i)return;return i.drawImage(t,0,0),e.toDataURL()}catch(t){return}},ko=t=>{var e,i,n;return t.shadowColor?{color:t.shadowColor,size:null!==(e=t.shadowSize)&&void 0!==e?e:0,offsetX:null!==(i=t.shadowOffsetX)&&void 0!==i?i:0,offsetY:null!==(n=t.shadowOffsetY)&&void 0!==n?n:0}:null},Bo=(t,e)=>{const{color:i,opacity:n}=Uo(e.color.toString()),s=Math.max(.5*e.size,0),o=`shadow:${i}:${n}:${s}:${e.offsetX}:${e.offsetY}`;return t.add(o,o=>zo(o,i,n,s,e.offsetX,e.offsetY,t.filterRegion))},zo=(t,e,i,n,s,o,r)=>{const a=r?`filterUnits="userSpaceOnUse" x="${Co(r.x)}" y="${Co(r.y)}" width="${Co(r.width)}" height="${Co(r.height)}"`:'filterUnits="objectBoundingBox" x="-50%" y="-50%" width="200%" height="200%"';return``},Uo=t=>{const e=t.match(/^rgba\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)\s*\)$/i);if(e)return{color:`rgb(${e[1]}, ${e[2]}, ${e[3]})`,opacity:Fo(Number(e[4]))};const i=t.match(/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i);if(i)return{color:`#${i[1]}${i[2]}${i[3]}`,opacity:parseInt(i[4],16)/255};const n=t.match(/^#([0-9a-f])([0-9a-f])([0-9a-f])([0-9a-f])$/i);return n?{color:`#${n[1]}${n[2]}${n[3]}`,opacity:parseInt(n[4],16)/15}:{color:t,opacity:1}},Fo=t=>isFinite(t)?Math.min(Math.max(t,0),1):1,jo=(t,e,i)=>{var n,s,o,r,a,h;const l=null===(n=null==i?void 0:i.isLabelEnabled)||void 0===n||n,d=null===(s=null==i?void 0:i.isShadowEnabled)||void 0===s||s,u=null===(o=null==i?void 0:i.isImageEnabled)||void 0===o||o,c=t.getCenter(),_=t.getRadius();if(_<=0)return"";const f=((t,e,i,n)=>{switch(t){case S.SQUARE:return{tag:"rect",attributes:{x:e-n,y:i-n,width:2*n,height:2*n}};case S.DIAMOND:return Io([{x:e,y:i+n},{x:e+n,y:i},{x:e,y:i-n},{x:e-n,y:i}]);case S.TRIANGLE:return Io(((t,e,i)=>{e+=.275*(i*=1.15);const n=2*i,s=Math.sqrt(3)*n/6;return[{x:t,y:e-(Math.sqrt(n*n-i*i)-s)},{x:t+i,y:e+s},{x:t-i,y:e+s}]})(e,i,n));case S.TRIANGLE_DOWN:return Io(((t,e,i)=>{e-=.275*(i*=1.15);const n=2*i,s=Math.sqrt(3)*n/6;return[{x:t,y:e+(Math.sqrt(n*n-i*i)-s)},{x:t+i,y:e-s},{x:t-i,y:e-s}]})(e,i,n));case S.STAR:return Io(((t,e,i)=>{e+=.1*(i*=.82);const n=[];for(let s=0;s<10;s++){const o=i*(s%2==0?1.3:.5);n.push({x:t+o*Math.sin(2*s*Math.PI/10),y:e-o*Math.cos(2*s*Math.PI/10)})}return n})(e,i,n));case S.HEXAGON:return Io(((t,e,i,n)=>{const s=[],o=2*Math.PI/n;for(let r=0;r{const n=t.getBackgroundImage();if(!n||!n.width||!n.height)return"";const s=((t,e)=>{var i,n;const s=Oo(e);if(s)return s;const o=t.getStyle();return t.isSelected()&&o.imageUrlSelected?o.imageUrlSelected:null!==(n=null!==(i=o.imageUrl)&&void 0!==i?i:e.src)&&void 0!==n?n:void 0})(t,n);if(!s)return"";const o=t.getCenter(),r=t.getRadius(),a=Object.keys(i.attributes).map(t=>`${t}=${i.attributes[t]}`).join(","),h=e.add(`clip:${i.tag}:${a}`,t=>No("clipPath",{id:t},No(i.tag,i.attributes)));return No("image",{href:s,"xlink:href":s,x:o.x-r,y:o.y-r,width:2*r,height:2*r,preserveAspectRatio:"xMidYMid slice","clip-path":`url(#${h})`})})(t,e,f):"",y=d&&t.hasShadow()?ko(t.getStyle()):null;let x;if(v||y){let t=`${No(f.tag,Object.assign(Object.assign({},f.attributes),{fill:g}))}${v}`;y&&(t=No("g",{filter:`url(#${Bo(e,y)})`},t)),x=`${t}${p?No(f.tag,Object.assign(Object.assign(Object.assign({},f.attributes),{fill:"none"}),m)):""}`}else x=No(f.tag,Object.assign(Object.assign(Object.assign({},f.attributes),{fill:g}),m));const b=l?Wo(t):"";return No("g",{},`${x}${b}`)},Wo=t=>{const e=t.getLabel();if(!e)return"";const i=t.getCenter(),n=1.2*t.getBorderedRadius(),s=t.getStyle();return Lo(e,{position:{x:i.x,y:i.y+n},textBaseline:Fs.TOP,properties:{fontBackgroundColor:s.fontBackgroundColor,fontColor:s.fontColor,fontFamily:s.fontFamily,fontSize:s.fontSize}})},Zo=[{x:0,y:0},{x:-1,y:.4},{x:-1,y:-.4}],Go=(t,e,i)=>{var n,s,o;const r=t.getWidth();if(!r)return"";const a=null===(n=null==i?void 0:i.isLabelEnabled)||void 0===n||n,h=null===(s=null==i?void 0:i.isShadowEnabled)||void 0===s||s,l=(null!==(o=t.getColor())&&void 0!==o?o:"#000000").toString(),d=Xo(t,l),u=Ho(t,r,l),c=h&&t.hasShadow()?ko(t.getStyle()):null;let _=`${d}${u}`;c&&(_=No("g",{filter:`url(#${Bo(e,c)})`},_));const f=a?Yo(t):"";return No("g",{},`${_}${f}`)},Ho=(t,e,i)=>{const n=t.getLineDashPattern(),s={stroke:i,"stroke-width":e,fill:"none","stroke-dasharray":n?n.join(" "):void 0};if(t instanceof O){const e=t.startNode.getCenter(),i=t.endNode.getCenter(),n=`M ${Co(e.x)} ${Co(e.y)} L ${Co(i.x)} ${Co(i.y)}`;return No("path",Object.assign({d:n},s))}if(t instanceof k){const e=t.startNode.getCenter(),i=t.endNode.getCenter(),n=t.getCurvedControlPoint(),o=`M ${Co(e.x)} ${Co(e.y)} Q ${Co(n.x)} ${Co(n.y)} ${Co(i.x)} ${Co(i.y)}`;return No("path",Object.assign({d:o},s))}if(t instanceof B){const{x:e,y:i,radius:n}=t.getCircularData();return No("circle",Object.assign({cx:e,cy:i,r:n},s))}return""},Xo=(t,e)=>{if(0===t.getStyle().arrowSize)return"";const i=qo(t);if(!i)return"";const n=Vo(Zo,i).map(t=>`${Co(t.x)},${Co(t.y)}`).join(" ");return No("polygon",{points:n,fill:e})},qo=t=>t instanceof O?Js(t):t instanceof k?qs(t):t instanceof B?$s(t):null,Vo=(t,e)=>t.map(t=>{const i=t.x*Math.cos(e.angle)-t.y*Math.sin(e.angle),n=t.x*Math.sin(e.angle)+t.y*Math.cos(e.angle);return{x:e.point.x+e.length*i,y:e.point.y+e.length*n}}),Yo=t=>{const e=t.getLabel();if(!e)return"";const i=t.getStyle();return Lo(e,{position:t.getCenter(),textBaseline:Fs.MIDDLE,properties:{fontBackgroundColor:i.fontBackgroundColor,fontColor:i.fontColor,fontFamily:i.fontFamily,fontSize:i.fontSize}})};class $o{constructor(t){this.filterRegion=t,this._idBySignature=new Map,this._entries=[],this._counter=0}add(t,e){const i=this._idBySignature.get(t);if(void 0!==i)return i;const n=`orb-def-${this._counter}`;return this._counter+=1,this._idBySignature.set(t,n),this._entries.push(e(n)),n}toSVG(){return this._entries.length?`${this._entries.join("")}`:""}}const Ko=(t,e={})=>{var i,n,s,o;const r=null!==(i=e.padding)&&void 0!==i?i:20,a=null===(n=e.isLabelEnabled)||void 0===n||n,h=null===(s=e.isShadowEnabled)||void 0===s||s,l=null===(o=e.isImageEnabled)||void 0===o||o,d=t.getNodes(),u=t.getEdges(),c=Qo(d,u,a,h),_=c.x-r,f=c.y-r,g=Math.max(c.width+2*r,1),p=Math.max(c.height+2*r,1),m=new $o({x:_,y:f,width:g,height:p}),v=[];e.backgroundColor&&v.push(No("rect",{x:_,y:f,width:g,height:p,fill:e.backgroundColor.toString()}));for(let t=0;t{const s={minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0};for(let e=0;e{et.maxX&&(t.maxX=e),i>t.maxY&&(t.maxY=i)},tr=(t,e,i,n,s)=>{Jo(t,e-n,i-s),Jo(t,e+n,i+s)},er=(t,e,i,n)=>{var s;if(e.getRadius()<=0)return;const o=e.getCenter(),r=e.getBorderedRadius(),a=n?sr(e.hasShadow(),e.getStyle()):0;if(tr(t,o.x,o.y,r+a,r+a),i&&e.getLabel()){const i=e.getStyle(),n=o.y+1.2*e.getBorderedRadius();nr(t,e.getLabel(),o.x,n,null!==(s=i.fontSize)&&void 0!==s?s:4,!1)}},ir=(t,e,i,n)=>{var s;if(!e.getWidth())return;const o=e.getStyle(),r=n?sr(e.hasShadow(),o):0;if(e instanceof B){const i=e.getCircularData();tr(t,i.x,i.y,i.radius+r,i.radius+r)}else if(e instanceof k){const i=e.getCurvedControlPoint();tr(t,i.x,i.y,r,r)}if(i&&e.getLabel()){const i=e.getCenter();nr(t,e.getLabel(),i.x,i.y,null!==(s=o.fontSize)&&void 0!==s?s:4,!0)}},nr=(t,e,i,n,s,o)=>{if(s<=0)return;const r=`${e}`.split("\n"),a=.12*s,h=r.reduce((t,e)=>Math.max(t,e.trim().length),0)*s*.6+2*a,l=r.length*s*1.2+2*a,d=o?n-l/2:n;Jo(t,i-h/2,d),Jo(t,i+h/2,d+l)},sr=(t,e)=>{var i,n,s;return t&&e.shadowColor?(null!==(i=e.shadowSize)&&void 0!==i?i:0)+Math.max(Math.abs(null!==(n=e.shadowOffsetX)&&void 0!==n?n:0),Math.abs(null!==(s=e.shadowOffsetY)&&void 0!==s?s:0)):0};class or{constructor(t){this._graph=t}selectNodeById(t,e){const i=this._graph.getNodeById(t);return!!i&&(ws(i,e),!0)}selectEdgeById(t,e){const i=this._graph.getEdgeById(t);return!!i&&(Ts(i,e),!0)}unselectNodeById(t,e){const i=this._graph.getNodeById(t);return!!i&&(Es(i,e),!0)}unselectEdgeById(t,e){const i=this._graph.getEdgeById(t);return!!i&&(Ps(i,e),!0)}unselectAll(){const{changedCount:t}=Ms(this._graph);return t}hoverNodeById(t){const e=this._graph.getNodeById(t);return!!e&&(Ns(e),!0)}hoverEdgeById(t){const e=this._graph.getEdgeById(t);return!!e&&((t=>{Ls(t,r.HOVERED)})(e),!0)}unhoverAll(){const{changedCount:t}=Ds(this._graph);return t}}class rr{constructor(t,i){var n,o,r,a,h,l,d;this._simulatorUsesGPU=!1,this._simulationStartedAt=Date.now(),this._assignPositions=t=>{if(this._settings.getPosition)for(let e=0;e{var e;const i=this.getCanvasMousePosition(t.sourceEvent),n=null===(e=this._renderer)||void 0===e?void 0:e.getSimulationPosition(i);return this._graph.getNearestNode(n)},this.dragStarted=t=>{if(!this._settings.interaction.isDragEnabled)return;const i=this.getCanvasMousePosition(t.sourceEvent),n=this._renderer.getSimulationPosition(i);this._events.emit(e.NODE_DRAG_START,{node:t.subject,event:t.sourceEvent,localPoint:n,globalPoint:i}),this._dragStartPosition=i},this.dragged=t=>{if(!this._settings.interaction.isDragEnabled)return;const i=this.getCanvasMousePosition(t.sourceEvent),n=this._renderer.getSimulationPosition(i);In(this._dragStartPosition,i)||(this._dragStartPosition=void 0),this._simulator.dragNode(t.subject.getId(),n),this._events.emit(e.NODE_DRAG,{node:t.subject,event:t.sourceEvent,localPoint:n,globalPoint:i})},this.dragEnded=t=>{if(!this._settings.interaction.isDragEnabled)return;const i=this.getCanvasMousePosition(t.sourceEvent),n=this._renderer.getSimulationPosition(i);In(this._dragStartPosition,i)||this._simulator.endDragNode(t.subject.getId()),this._events.emit(e.NODE_DRAG_END,{node:t.subject,event:t.sourceEvent,localPoint:n,globalPoint:i})},this.zoomed=t=>{this._settings.interaction.isZoomEnabled&&(this._renderer.transform=t.transform,setTimeout(()=>{this.render(),this._events.emit(e.TRANSFORM,{transform:t.transform})},1))},this.mouseMoved=t=>{const i=this.getCanvasMousePosition(t),n=this._renderer.getSimulationPosition(i),s=this._strategy.onMouseMove(this._graph,n),o=s.changedSubject;o&&s.isStateChanged&&(T(o)&&this._events.emit(e.NODE_HOVER,{node:o,event:t,localPoint:n,globalPoint:i}),I(o)&&this._events.emit(e.EDGE_HOVER,{edge:o,event:t,localPoint:n,globalPoint:i})),this._events.emit(e.MOUSE_MOVE,{subject:o,event:t,localPoint:n,globalPoint:i}),s.isStateChanged&&(this._invalidateStyles(),this.render())},this.mouseClicked=t=>{const i=this.getCanvasMousePosition(t),n=this._renderer.getSimulationPosition(i),s=this._strategy.onMouseClick(this._graph,n,{isAppend:t.shiftKey}),o=s.changedSubject;o&&(T(o)&&this._events.emit(e.NODE_CLICK,{node:o,event:t,localPoint:n,globalPoint:i}),I(o)&&this._events.emit(e.EDGE_CLICK,{edge:o,event:t,localPoint:n,globalPoint:i})),this._events.emit(e.MOUSE_CLICK,{subject:o,event:t,localPoint:n,globalPoint:i}),(s.isStateChanged||s.changedSubject)&&(this._invalidateStyles(),this.render())},this.mouseRightClicked=t=>{const i=this.getCanvasMousePosition(t),n=this._renderer.getSimulationPosition(i),s=this._strategy.onMouseRightClick(this._graph,n),o=s.changedSubject;o&&(T(o)&&this._events.emit(e.NODE_RIGHT_CLICK,{node:o,event:t,localPoint:n,globalPoint:i}),I(o)&&this._events.emit(e.EDGE_RIGHT_CLICK,{edge:o,event:t,localPoint:n,globalPoint:i})),this._events.emit(e.MOUSE_RIGHT_CLICK,{subject:o,event:t,localPoint:n,globalPoint:i}),(s.isStateChanged||s.changedSubject)&&(this._invalidateStyles(),this.render())},this.mouseDoubleClicked=t=>{const i=this.getCanvasMousePosition(t),n=this._renderer.getSimulationPosition(i),s=this._strategy.onMouseDoubleClick(this._graph,n),o=s.changedSubject;o&&(T(o)&&this._events.emit(e.NODE_DOUBLE_CLICK,{node:o,event:t,localPoint:n,globalPoint:i}),I(o)&&this._events.emit(e.EDGE_DOUBLE_CLICK,{edge:o,event:t,localPoint:n,globalPoint:i})),this._events.emit(e.MOUSE_DOUBLE_CLICK,{subject:o,event:t,localPoint:n,globalPoint:i}),(s.isStateChanged||s.changedSubject)&&(this._invalidateStyles(),this.render())},this.zoomIn=t=>{ue(this._renderer.canvas).transition().duration(this._settings.zoomFitTransitionMs).ease(Ee).call(this._d3Zoom.scaleBy,1.2).on("end",()=>this.render(t))},this.zoomOut=t=>{ue(this._renderer.canvas).transition().duration(this._settings.zoomFitTransitionMs).ease(Ee).call(this._d3Zoom.scaleBy,.8).on("end",()=>this.render(t))},this._invalidateStyles=()=>{var t,e;null===(e=(t=this._renderer).invalidateStyles)||void 0===e||e.call(t)},this._update=t=>{t&&"x"in t&&"y"in t&&"id"in t&&this._simulator.patchData({nodes:[{x:t.x,y:t.y,sx:t.x,sy:t.y,fx:t.x,fy:t.y,id:t.id}],edges:[]}),this._invalidateStyles(),this.render()},this._initializeSimulationEvents=()=>{this._simulator.on(Ln.SIMULATION_START,()=>{this._simulationStartedAt=Date.now(),this._events.emit(e.SIMULATION_START,void 0)});const t=()=>{var t,e;return null===(e=(t=this._renderer).invalidateBuffers)||void 0===e?void 0:e.call(t)};this._simulator.on(Ln.SIMULATION_PROGRESS,i=>{this._graph.setNodePositions(i.nodes),t(),this._events.emit(e.SIMULATION_STEP,{progress:i.progress}),this.render()}),this._simulator.on(Ln.SIMULATION_END,i=>{this._graph.setNodePositions(i.nodes),t(),this.render(),this._events.emit(e.SIMULATION_END,{durationMs:Date.now()-this._simulationStartedAt})}),this._simulator.on(Ln.SIMULATION_STEP,e=>{this._graph.setNodePositions(e.nodes),t(),this.render()}),this._simulator.on(Ln.NODE_DRAG,e=>{this._graph.setNodePositions(e.nodes),t(),this.render()}),this._simulator.on(Ln.SETTINGS_UPDATE,t=>{var e;this._settings.layout.options=null===(e=t.settings)||void 0===e?void 0:e.options})},this._container=t,this._settings=Object.assign(Object.assign({getPosition:null==i?void 0:i.getPosition,zoomFitTransitionMs:200,isOutOfBoundsDragEnabled:!1,areCoordinatesRounded:!0},i),{layout:Object.assign({type:"force"},null!==(n=null==i?void 0:i.layout)&&void 0!==n?n:es),render:Object.assign({},null==i?void 0:i.render),strategy:Object.assign({isDefaultHoverEnabled:!0,isDefaultSelectEnabled:!0,isDefaultMultiSelectEnabled:!1,isDefaultSelectCascadeEnabled:!0},null==i?void 0:i.strategy),interaction:Object.assign({isDragEnabled:!0,isZoomEnabled:!0},null==i?void 0:i.interaction)}),this._graph=new Ss(void 0,{onLoadedImages:()=>{this._renderer.isInitiallyRendered&&this.render()},listeners:[this._update]}),this._graph.setDefaultStyle(H()),this._events=new s,this._interaction=new or(this._graph),this._strategy=new Os({isDefaultSelectEnabled:null!==(o=this._settings.strategy.isDefaultSelectEnabled)&&void 0!==o&&o,isDefaultHoverEnabled:null!==(r=this._settings.strategy.isDefaultHoverEnabled)&&void 0!==r&&r,isDefaultMultiSelectEnabled:null===(a=this._settings.strategy.isDefaultMultiSelectEnabled)||void 0===a||a,isDefaultSelectCascadeEnabled:null===(h=this._settings.strategy.isDefaultSelectCascadeEnabled)||void 0===h||h}),this._rendererType=null!==(d=null===(l=null==i?void 0:i.render)||void 0===l?void 0:l.type)&&void 0!==d?d:ks.CANVAS,this._initRenderer(this._rendererType),this._simulator=vs.getSimulator(this._settings.layout),this._simulatorUsesGPU=rr._needsGPU(this._settings.layout),this._initializeSimulationEvents(),this._graph.setSettings({onSetupData:()=>{this._assignPositions(this._graph.getNodes());const t=this._graph.getNodePositions(),e=this._graph.getEdgePositions();this._simulator.setupData({nodes:t,edges:e})},onMergeData:t=>{var e,i;const n=new Set(null===(e=t.nodes)||void 0===e?void 0:e.map(t=>t.id)),s=t=>n.has(t.getId()),o=new Set(null===(i=t.edges)||void 0===i?void 0:i.map(t=>t.id));this._assignPositions(this._graph.getNodes(s));const r=this._graph.getNodePositions(s),a=this._graph.getEdgePositions(t=>o.has(t.getId()));this._simulator.mergeData({nodes:r,edges:a})},onRemoveData:t=>{this._simulator.deleteData(t)}})}_initRenderer(t){try{this._renderer=Ao.getRenderer(this._container,t,this._settings.render)}catch(t){throw this._container.textContent=t.message,t}this._renderer.on(Bs.RENDER_START,()=>{this._events.emit(e.RENDER_START,void 0)}),this._renderer.on(Bs.RENDER_END,t=>{this._events.emit(e.RENDER_END,t)}),this._renderer.on(Bs.RESIZE,()=>{this._renderer.isInitiallyRendered&&this._renderer.render(this._graph)}),this._renderer.translateOriginToCenter(),this._settings.render=this._renderer.getSettings(),this._d3Zoom=function(){var t,e,i,n=Pn,s=An,o=Dn,r=Mn,a=Nn,h=[0,1/0],l=[[-1/0,-1/0],[1/0,1/0]],d=250,u=Ae,c=Q("start","zoom","end"),_=0,f=10;function g(t){t.property("__zoom",Cn).on("wheel.zoom",S,{passive:!1}).on("mousedown.zoom",w).on("dblclick.zoom",T).filter(a).on("touchstart.zoom",E).on("touchmove.zoom",P).on("touchend.zoom touchcancel.zoom",A).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function p(t,e){return(e=Math.max(h[0],Math.min(h[1],e)))===t.k?t:new Sn(e,t.x,t.y)}function m(t,e,i){var n=e[0]-i[0]*t.k,s=e[1]-i[1]*t.k;return n===t.x&&s===t.y?t:new Sn(t.k,n,s)}function v(t){return[(+t[0][0]+ +t[1][0])/2,(+t[0][1]+ +t[1][1])/2]}function y(t,e,i,n){t.on("start.zoom",function(){x(this,arguments).event(n).start()}).on("interrupt.zoom end.zoom",function(){x(this,arguments).event(n).end()}).tween("zoom",function(){var t=this,o=arguments,r=x(t,o).event(n),a=s.apply(t,o),h=null==i?v(a):"function"==typeof i?i.apply(t,o):i,l=Math.max(a[1][0]-a[0][0],a[1][1]-a[0][1]),d=t.__zoom,c="function"==typeof e?e.apply(t,o):e,_=u(d.invert(h).concat(l/d.k),c.invert(h).concat(l/c.k));return function(t){if(1===t)t=c;else{var e=_(t),i=l/e[2];t=new Sn(i,h[0]-e[0]*i,h[1]-e[1]*i)}r.zoom(null,t)}})}function x(t,e,i){return!i&&t.__zooming||new b(t,e)}function b(t,e){this.that=t,this.args=e,this.active=0,this.sourceEvent=null,this.extent=s.apply(t,e),this.taps=0}function S(t,...e){if(n.apply(this,arguments)){var i=x(this,e).event(t),s=this.__zoom,a=Math.max(h[0],Math.min(h[1],s.k*Math.pow(2,r.apply(this,arguments)))),d=ce(t);if(i.wheel)i.mouse[0][0]===d[0]&&i.mouse[0][1]===d[1]||(i.mouse[1]=s.invert(i.mouse[0]=d)),clearTimeout(i.wheel);else{if(s.k===a)return;i.mouse=[d,s.invert(d)],Qe(this),i.start()}En(t),i.wheel=setTimeout(function(){i.wheel=null,i.end()},150),i.zoom("mouse",o(m(p(s,a),i.mouse[0],i.mouse[1]),i.extent,l))}}function w(t,...e){if(!i&&n.apply(this,arguments)){var s=t.currentTarget,r=x(this,e,!0).event(t),a=ue(t.view).on("mousemove.zoom",function(t){if(En(t),!r.moved){var e=t.clientX-d,i=t.clientY-u;r.moved=e*e+i*i>_}r.event(t).zoom("mouse",o(m(r.that.__zoom,r.mouse[0]=ce(t,s),r.mouse[1]),r.extent,l))},!0).on("mouseup.zoom",function(t){a.on("mousemove.zoom mouseup.zoom",null),ve(t.view,r.moved),En(t),r.event(t).end()},!0),h=ce(t,s),d=t.clientX,u=t.clientY;me(t.view),Tn(t),r.mouse=[h,this.__zoom.invert(h)],Qe(this),r.start()}}function T(t,...e){if(n.apply(this,arguments)){var i=this.__zoom,r=ce(t.changedTouches?t.changedTouches[0]:t,this),a=i.invert(r),h=i.k*(t.shiftKey?.5:2),u=o(m(p(i,h),r,a),s.apply(this,e),l);En(t),d>0?ue(this).transition().duration(d).call(y,u,r,t):ue(this).call(g.transform,u,r,t)}}function E(i,...s){if(n.apply(this,arguments)){var o,r,a,h,l=i.touches,d=l.length,u=x(this,s,i.changedTouches.length===d).event(i);for(Tn(i),r=0;ru}h.mouse("drag",n)}function g(t){ue(t.view).on("mousemove.drag mouseup.drag",null),ve(t.view,i),pe(t),h.mouse("end",t)}function p(t,e){if(s.call(this,t,e)){var i,n,r=t.changedTouches,a=o.call(this,t,e),h=r.length;for(i=0;i{this.recenter()}),this._simulator.setupData({nodes:n,edges:s})}t.strategy&&(u(t.strategy.isDefaultHoverEnabled)&&(this._settings.strategy.isDefaultHoverEnabled=t.strategy.isDefaultHoverEnabled,this._strategy.isHoverEnabled=this._settings.strategy.isDefaultHoverEnabled),u(t.strategy.isDefaultSelectEnabled)&&(this._settings.strategy.isDefaultSelectEnabled=t.strategy.isDefaultSelectEnabled,this._strategy.isSelectEnabled=this._settings.strategy.isDefaultSelectEnabled),u(t.strategy.isDefaultMultiSelectEnabled)&&(this._settings.strategy.isDefaultMultiSelectEnabled=t.strategy.isDefaultMultiSelectEnabled,this._strategy.isMultiSelectEnabled=this._settings.strategy.isDefaultMultiSelectEnabled),u(t.strategy.isDefaultSelectCascadeEnabled)&&(this._settings.strategy.isDefaultSelectCascadeEnabled=t.strategy.isDefaultSelectCascadeEnabled,this._strategy.isSelectCascadeEnabled=this._settings.strategy.isDefaultSelectCascadeEnabled)),t.interaction&&(u(t.interaction.isDragEnabled)&&(this._settings.interaction.isDragEnabled=t.interaction.isDragEnabled),u(t.interaction.isZoomEnabled)&&(this._settings.interaction.isZoomEnabled=t.interaction.isZoomEnabled))}static _needsGPU(t){var e;return"force"===t.type&&!!(null===(e=t.options)||void 0===e?void 0:e.useGPU)}render(t){t&&(this._simulator.isSimulationRunning()?this._simulator.once(Ln.SIMULATION_END,()=>{this._renderer.once(Bs.RENDER_END,()=>t())}):this._renderer.once(Bs.RENDER_END,()=>t())),this._renderer.render(this._graph)}recenter(t,e){"function"==typeof t&&(e=t,t=void 0);const i=(t=>{var e,i,n,s,o,r;if("hierarchical"===t.type){const n=t.options;return{anchorX:null!==(e=n.anchorX)&&void 0!==e?e:"horizontal"===n.orientation?n.reversed?"end":"start":"center",anchorY:null!==(i=n.anchorY)&&void 0!==i?i:"vertical"===n.orientation?n.reversed?"end":"start":"center"}}return{anchorX:null!==(s=null===(n=t.options)||void 0===n?void 0:n.anchorX)&&void 0!==s?s:"center",anchorY:null!==(r=null===(o=t.options)||void 0===o?void 0:o.anchorY)&&void 0!==r?r:"center"}})(this._settings.layout),n=Object.assign(Object.assign({},i),t),s=this._renderer.getFitZoomTransform(this._graph,n);ue(this._renderer.canvas).transition().duration(this._settings.zoomFitTransitionMs).ease(Ee).call(this._d3Zoom.transform,s).on("end",()=>this.render(e))}getSVG(t){return Ko(this._graph,Object.assign({backgroundColor:this._settings.render.backgroundColor},t))}destroy(){this._renderer.destroy(),this._simulator.terminate()}getCanvasMousePosition(t){var e,i,n,s;const o=this._renderer.canvas.getBoundingClientRect();let r=null!==(i=null!==(e=t.clientX)&&void 0!==e?e:t.pageX)&&void 0!==i?i:t.x,a=null!==(s=null!==(n=t.clientY)&&void 0!==n?n:t.pageY)&&void 0!==s?s:t.y;return r-=o.left,a-=o.top,this._settings.areCoordinatesRounded&&(r=Math.floor(r),a=Math.floor(a)),this._settings.isOutOfBoundsDragEnabled||(r=Math.max(0,Math.min(this._renderer.width,r)),a=Math.max(0,Math.min(this._renderer.height,a))),{x:r,y:a}}fixNodes(){this._simulator.fixNodes()}releaseNodes(){this._simulator.releaseNodes()}}var ar=i(481);class hr{constructor(t,e){var i,n,o,r,a,h,l,d,u,c,_,f;this._invalidateStyles=()=>{var t,e;null===(e=(t=this._renderer).invalidateStyles)||void 0===e||e.call(t)},this._update=()=>{this._invalidateStyles(),this.render()},this._container=t,this._graph=new Ss(void 0,{onLoadedImages:()=>{this._renderer.isInitiallyRendered&&this.render()},listeners:[this._update]}),this._graph.setDefaultStyle(H()),this._events=new s,this._interaction=new or(this._graph),this._settings=Object.assign(Object.assign({areCollapsedContainerDimensionsAllowed:!1},e),{map:{zoomLevel:null!==(n=null===(i=e.map)||void 0===i?void 0:i.zoomLevel)&&void 0!==n?n:2,tile:null!==(r=null===(o=e.map)||void 0===o?void 0:o.tile)&&void 0!==r?r:{instance:new ar.TileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"),attribution:'Leaflet | Map data © OpenStreetMap contributors'},nodeSizeMode:null!==(h=null===(a=e.map)||void 0===a?void 0:a.nodeSizeMode)&&void 0!==h?h:"geographic"},render:Object.assign({type:ks.CANVAS},e.render),strategy:Object.assign({isDefaultHoverEnabled:!0,isDefaultSelectEnabled:!0,isDefaultMultiSelectEnabled:!1,isDefaultSelectCascadeEnabled:!0},null==e?void 0:e.strategy)}),this._strategy=new Os({isDefaultSelectEnabled:null!==(l=this._settings.strategy.isDefaultSelectEnabled)&&void 0!==l&&l,isDefaultHoverEnabled:null!==(d=this._settings.strategy.isDefaultHoverEnabled)&&void 0!==d&&d,isDefaultMultiSelectEnabled:null===(u=this._settings.strategy.isDefaultMultiSelectEnabled)||void 0===u||u,isDefaultSelectCascadeEnabled:null===(c=this._settings.strategy.isDefaultSelectCascadeEnabled)||void 0===c||c}),this._rendererType=null!==(f=null===(_=null==e?void 0:e.render)||void 0===_?void 0:_.type)&&void 0!==f?f:ks.CANVAS,this._initRenderer(this._rendererType),this._map=this._initMap(),this._leaflet=this._initLeaflet(),this._handleTileChange()}_initRenderer(t){try{this._renderer=Ao.getRenderer(this._container,t,this._settings.render)}catch(t){throw this._container.textContent=t.message,t}this._renderer.on(Bs.RENDER_END,t=>{this._events.emit(e.RENDER_END,t)}),this._renderer.on(Bs.RESIZE,()=>{this._renderer.isInitiallyRendered&&(this._leaflet.invalidateSize(!1),this._renderer.render(this._graph))}),this._settings.render=this._renderer.getSettings(),this._renderer.canvas.style.zIndex="2",this._renderer.canvas.style.pointerEvents="none"}setRenderer(t){if(t===this._rendererType)return;this._renderer.destroy(),this._initRenderer(t),this._rendererType=t;const e=this._leaflet._mapPane._leaflet_pos,i=this._getStyleScale();this._renderer.transform=Object.assign(Object.assign({},e),{k:i}),this.render()}get data(){return this._graph}get events(){return this._events}get interaction(){return this._interaction}get leaflet(){return this._leaflet}getSettings(){return p(this._settings)}setSettings(t){if(t.getGeoPosition&&(this._settings.getGeoPosition=t.getGeoPosition,this._updateGraphPositions()),t.map&&("number"==typeof t.map.zoomLevel&&(this._settings.map.zoomLevel=t.map.zoomLevel,this._leaflet.setZoom(t.map.zoomLevel)),t.map.tile&&(this._settings.map.tile=t.map.tile,this._handleTileChange()),t.map.nodeSizeMode&&t.map.nodeSizeMode!==this._settings.map.nodeSizeMode)){this._settings.map.nodeSizeMode=t.map.nodeSizeMode,this._updateGraphPositions();const e=this._leaflet._mapPane._leaflet_pos,i=this._getStyleScale();this._renderer.transform=Object.assign(Object.assign({},e),{k:i}),this._renderer.render(this._graph)}t.render&&(t.render.type&&t.render.type!==this._rendererType&&this.setRenderer(t.render.type),this._renderer.setSettings(t.render),this._settings.render=this._renderer.getSettings()),t.strategy&&(u(t.strategy.isDefaultHoverEnabled)&&(this._settings.strategy.isDefaultHoverEnabled=t.strategy.isDefaultHoverEnabled,this._strategy.isHoverEnabled=this._settings.strategy.isDefaultHoverEnabled),u(t.strategy.isDefaultSelectEnabled)&&(this._settings.strategy.isDefaultSelectEnabled=t.strategy.isDefaultSelectEnabled,this._strategy.isSelectEnabled=this._settings.strategy.isDefaultSelectEnabled),u(t.strategy.isDefaultMultiSelectEnabled)&&(this._settings.strategy.isDefaultMultiSelectEnabled=t.strategy.isDefaultMultiSelectEnabled,this._strategy.isMultiSelectEnabled=this._settings.strategy.isDefaultMultiSelectEnabled),u(t.strategy.isDefaultSelectCascadeEnabled)&&(this._settings.strategy.isDefaultSelectCascadeEnabled=t.strategy.isDefaultSelectCascadeEnabled,this._strategy.isSelectCascadeEnabled=this._settings.strategy.isDefaultSelectCascadeEnabled))}render(t){t&&this._renderer.once(Bs.RENDER_END,()=>t()),this._updateGraphPositions(),this._renderer.render(this._graph)}zoomIn(t){this._leaflet.zoomIn(),null==t||t()}recenter(t){const e=this._graph.getBoundingBox(),i=this._getStyleScale(),n=this._leaflet.layerPointToLatLng([e.x*i,e.y*i]),s=this._leaflet.layerPointToLatLng([(e.x+e.width)*i,(e.y+e.height)*i]);this._leaflet.fitBounds(ar.latLngBounds(n,s)),null==t||t()}zoomOut(t){this._leaflet.zoomOut(),null==t||t()}getSVG(){throw new Error("SVG export is not supported on OrbMapView.")}destroy(){this._renderer.destroy(),this._leaflet.off(),this._leaflet.remove(),this._leaflet.getContainer().outerHTML=""}_initMap(){const t=document.createElement("div");return t.style.position="absolute",t.style.width="100%",t.style.height="100%",t.style.zIndex="1",t.style.cursor="default",this._container.appendChild(t),t}_initLeaflet(){const t=ar.map(this._map,{doubleClickZoom:!1,zoomControl:!1}).setView([0,0],this._settings.map.zoomLevel);return t.on("zoomstart",()=>{this._renderer.reset()}),t.on("zoom",t=>{var i,n;this._updateGraphPositions(),null===(n=(i=this._renderer).invalidateBuffers)||void 0===n||n.call(i);const s=t.target._mapPane._leaflet_pos,o=this._getStyleScale();this._renderer.transform=Object.assign(Object.assign({},s),{k:o}),this._renderer.render(this._graph),this._events.emit(e.TRANSFORM,{transform:Object.assign(Object.assign({},s),{k:o})})}),t.on("mousemove",t=>{const i=this._toSimulationPoint(t.layerPoint),n={x:t.containerPoint.x,y:t.containerPoint.y},s=this._strategy.onMouseMove(this._graph,i),o=s.changedSubject;o&&s.isStateChanged&&(T(o)&&this._events.emit(e.NODE_HOVER,{node:o,event:t.originalEvent,localPoint:i,globalPoint:n}),I(o)&&this._events.emit(e.EDGE_HOVER,{edge:o,event:t.originalEvent,localPoint:i,globalPoint:n})),this._events.emit(e.MOUSE_MOVE,{subject:o,event:t.originalEvent,localPoint:i,globalPoint:n}),s.isStateChanged&&(this._invalidateStyles(),this._renderer.render(this._graph))}),t.on("click contextmenu dblclick",t=>{const i=this._toSimulationPoint(t.layerPoint),n={x:t.containerPoint.x,y:t.containerPoint.y};if("contextmenu"===t.type){const s=this._strategy.onMouseRightClick(this._graph,i),o=s.changedSubject;o&&(T(o)&&this._events.emit(e.NODE_RIGHT_CLICK,{node:o,event:t.originalEvent,localPoint:i,globalPoint:n}),I(o)&&this._events.emit(e.EDGE_RIGHT_CLICK,{edge:o,event:t.originalEvent,localPoint:i,globalPoint:n})),this._events.emit(e.MOUSE_RIGHT_CLICK,{subject:o,event:t.originalEvent,localPoint:i,globalPoint:n}),s.isStateChanged&&(this._invalidateStyles(),this._renderer.render(this._graph))}else if("click"===t.type){const s=this._strategy.onMouseClick(this._graph,i,{isAppend:t.originalEvent.shiftKey}),o=s.changedSubject;o&&(T(o)&&this._events.emit(e.NODE_CLICK,{node:o,event:t.originalEvent,localPoint:i,globalPoint:n}),I(o)&&this._events.emit(e.EDGE_CLICK,{edge:o,event:t.originalEvent,localPoint:i,globalPoint:n})),this._events.emit(e.MOUSE_CLICK,{subject:o,event:t.originalEvent,localPoint:i,globalPoint:n}),(s.isStateChanged||s.changedSubject)&&(this._invalidateStyles(),this._renderer.render(this._graph))}else if("dblclick"===t.type){const s=this._strategy.onMouseDoubleClick(this._graph,i),o=s.changedSubject;if(o&&(T(o)&&this._events.emit(e.NODE_DOUBLE_CLICK,{node:o,event:t.originalEvent,localPoint:i,globalPoint:n}),I(o)&&this._events.emit(e.EDGE_DOUBLE_CLICK,{edge:o,event:t.originalEvent,localPoint:i,globalPoint:n})),this._events.emit(e.MOUSE_DOUBLE_CLICK,{subject:o,event:t.originalEvent,localPoint:i,globalPoint:n}),!o){const e=t.target._zoom+1;t.target.setZoomAround(t.layerPoint,e)}(s.isStateChanged||s.changedSubject)&&(this._invalidateStyles(),this._renderer.render(this._graph))}}),t.on("moveend",t=>{const e=t.target._mapPane._leaflet_pos,i=this._getStyleScale();this._renderer.transform=Object.assign(Object.assign({},e),{k:i}),this._renderer.render(this._graph)}),t.on("drag",t=>{const i=t.target._mapPane._leaflet_pos,n=this._getStyleScale();this._renderer.transform=Object.assign(Object.assign({},i),{k:n}),this._renderer.render(this._graph),this._events.emit(e.TRANSFORM,{transform:Object.assign(Object.assign({},i),{k:n})})}),t}_updateGraphPositions(){const t=this._graph.getNodes(),e=this._getStyleScale();for(let i=0;i{this._leaflet.attributionControl.setPrefix(t.attribution),this._leaflet.eachLayer(t=>this._leaflet.removeLayer(t)),t.instance.addTo(this._leaflet)})}}})(),n})()); \ No newline at end of file +!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.Orb=e():t.Orb=e()}(self,()=>(()=>{var t={481(t,e){!function(t){"use strict";function e(t){var e,i,n,s;for(i=1,n=arguments.length;i0?Math.floor(t):Math.ceil(t)};function I(t,e,i){return t instanceof N?t:p(t)?new N(t[0],t[1]):null==t?t:"object"==typeof t&&"x"in t&&"y"in t?new N(t.x,t.y):new N(t,e,i)}function R(t,e){if(t)for(var i=e?[t,e]:t,n=0,s=i.length;n=this.min.x&&i.x<=this.max.x&&e.y>=this.min.y&&i.y<=this.max.y},intersects:function(t){t=O(t);var e=this.min,i=this.max,n=t.min,s=t.max,o=s.x>=e.x&&n.x<=i.x,r=s.y>=e.y&&n.y<=i.y;return o&&r},overlaps:function(t){t=O(t);var e=this.min,i=this.max,n=t.min,s=t.max,o=s.x>e.x&&n.xe.y&&n.y=n.lat&&i.lat<=s.lat&&e.lng>=n.lng&&i.lng<=s.lng},intersects:function(t){t=B(t);var e=this._southWest,i=this._northEast,n=t.getSouthWest(),s=t.getNorthEast(),o=s.lat>=e.lat&&n.lat<=i.lat,r=s.lng>=e.lng&&n.lng<=i.lng;return o&&r},overlaps:function(t){t=B(t);var e=this._southWest,i=this._northEast,n=t.getSouthWest(),s=t.getNorthEast(),o=s.lat>e.lat&&n.late.lng&&n.lng1,Ct=function(){var t=!1;try{var e=Object.defineProperty({},"passive",{get:function(){t=!0}});window.addEventListener("testPassiveEventSupport",h,e),window.removeEventListener("testPassiveEventSupport",h,e)}catch(t){}return t}(),Mt=!!document.createElement("canvas").getContext,Nt=!(!document.createElementNS||!Y("svg").createSVGRect),Dt=!!Nt&&((K=document.createElement("div")).innerHTML="","http://www.w3.org/2000/svg"===(K.firstChild&&K.firstChild.namespaceURI)),It=!Nt&&function(){try{var t=document.createElement("div");t.innerHTML='';var e=t.firstChild;return e.style.behavior="url(#default#VML)",e&&"object"==typeof e.adj}catch(t){return!1}}();function Lt(t){return navigator.userAgent.toLowerCase().indexOf(t)>=0}var Rt={ie:J,ielt9:tt,edge:et,webkit:it,android:nt,android23:st,androidStock:rt,opera:at,chrome:ht,gecko:lt,safari:dt,phantom:ut,opera12:ct,win:_t,ie3d:ft,webkit3d:gt,gecko3d:pt,any3d:mt,mobile:vt,mobileWebkit:yt,mobileWebkit3d:xt,msPointer:bt,pointer:St,touch:Tt,touchNative:wt,mobileOpera:Et,mobileGecko:Pt,retina:At,passiveEvents:Ct,canvas:Mt,svg:Nt,vml:It,inlineSvg:Dt,mac:0===navigator.platform.indexOf("Mac"),linux:0===navigator.platform.indexOf("Linux")},Ot=Rt.msPointer?"MSPointerDown":"pointerdown",kt=Rt.msPointer?"MSPointerMove":"pointermove",Bt=Rt.msPointer?"MSPointerUp":"pointerup",zt=Rt.msPointer?"MSPointerCancel":"pointercancel",Ut={touchstart:Ot,touchmove:kt,touchend:Bt,touchcancel:zt},Ft={touchstart:function(t,e){e.MSPOINTER_TYPE_TOUCH&&e.pointerType===e.MSPOINTER_TYPE_TOUCH&&Be(e),qt(t,e)},touchmove:qt,touchend:qt,touchcancel:qt},jt={},Wt=!1;function Gt(t,e,i){return"touchstart"===e&&(Wt||(document.addEventListener(Ot,Zt,!0),document.addEventListener(kt,Ht,!0),document.addEventListener(Bt,Xt,!0),document.addEventListener(zt,Xt,!0),Wt=!0)),Ft[e]?(i=Ft[e].bind(this,i),t.addEventListener(Ut[e],i,!1),i):(console.warn("wrong event specified:",e),h)}function Zt(t){jt[t.pointerId]=t}function Ht(t){jt[t.pointerId]&&(jt[t.pointerId]=t)}function Xt(t){delete jt[t.pointerId]}function qt(t,e){if(e.pointerType!==(e.MSPOINTER_TYPE_MOUSE||"mouse")){for(var i in e.touches=[],jt)e.touches.push(jt[i]);e.changedTouches=[e],t(e)}}var Vt,Yt,$t,Kt,Qt,Jt=ge(["transform","webkitTransform","OTransform","MozTransform","msTransform"]),te=ge(["webkitTransition","transition","OTransition","MozTransition","msTransition"]),ee="webkitTransition"===te||"OTransition"===te?te+"End":"transitionend";function ie(t){return"string"==typeof t?document.getElementById(t):t}function ne(t,e){var i=t.style[e]||t.currentStyle&&t.currentStyle[e];if((!i||"auto"===i)&&document.defaultView){var n=document.defaultView.getComputedStyle(t,null);i=n?n[e]:null}return"auto"===i?null:i}function se(t,e,i){var n=document.createElement(t);return n.className=e||"",i&&i.appendChild(n),n}function oe(t){var e=t.parentNode;e&&e.removeChild(t)}function re(t){for(;t.firstChild;)t.removeChild(t.firstChild)}function ae(t){var e=t.parentNode;e&&e.lastChild!==t&&e.appendChild(t)}function he(t){var e=t.parentNode;e&&e.firstChild!==t&&e.insertBefore(t,e.firstChild)}function le(t,e){if(void 0!==t.classList)return t.classList.contains(e);var i=_e(t);return i.length>0&&new RegExp("(^|\\s)"+e+"(\\s|$)").test(i)}function de(t,e){if(void 0!==t.classList)for(var i=u(e),n=0,s=i.length;n0?2*window.devicePixelRatio:1;function We(t){return Rt.edge?t.wheelDeltaY/2:t.deltaY&&0===t.deltaMode?-t.deltaY/je:t.deltaY&&1===t.deltaMode?20*-t.deltaY:t.deltaY&&2===t.deltaMode?60*-t.deltaY:t.deltaX||t.deltaZ?0:t.wheelDelta?(t.wheelDeltaY||t.wheelDelta)/2:t.detail&&Math.abs(t.detail)<32765?20*-t.detail:t.detail?t.detail/-32765*60:0}function Ge(t,e){var i=e.relatedTarget;if(!i)return!0;try{for(;i&&i!==t;)i=i.parentNode}catch(t){return!1}return i!==t}var Ze={__proto__:null,on:Ae,off:Me,stopPropagation:Re,disableScrollPropagation:Oe,disableClickPropagation:ke,preventDefault:Be,stop:ze,getPropagationPath:Ue,getMousePosition:Fe,getWheelDelta:We,isExternalTarget:Ge,addListener:Ae,removeListener:Me},He=M.extend({run:function(t,e,i,n){this.stop(),this._el=t,this._inProgress=!0,this._duration=i||.25,this._easeOutPower=1/Math.max(n||.5,.2),this._startPos=ve(t),this._offset=e.subtract(this._startPos),this._startTime=+new Date,this.fire("start"),this._animate()},stop:function(){this._inProgress&&(this._step(!0),this._complete())},_animate:function(){this._animId=T(this._animate,this),this._step()},_step:function(t){var e=+new Date-this._startTime,i=1e3*this._duration;ethis.options.maxZoom)?this.setZoom(t):this},panInsideBounds:function(t,e){this._enforcingBounds=!0;var i=this.getCenter(),n=this._limitCenter(i,this._zoom,B(t));return i.equals(n)||this.panTo(n,e),this._enforcingBounds=!1,this},panInside:function(t,e){var i=I((e=e||{}).paddingTopLeft||e.padding||[0,0]),n=I(e.paddingBottomRight||e.padding||[0,0]),s=this.project(this.getCenter()),o=this.project(t),r=this.getPixelBounds(),a=O([r.min.add(i),r.max.subtract(n)]),h=a.getSize();if(!a.contains(o)){this._enforcingBounds=!0;var l=o.subtract(a.getCenter()),d=a.extend(o).getSize().subtract(h);s.x+=l.x<0?-d.x:d.x,s.y+=l.y<0?-d.y:d.y,this.panTo(this.unproject(s),e),this._enforcingBounds=!1}return this},invalidateSize:function(t){if(!this._loaded)return this;t=e({animate:!1,pan:!0},!0===t?{animate:!0}:t);var i=this.getSize();this._sizeChanged=!0,this._lastCenter=null;var s=this.getSize(),o=i.divideBy(2).round(),r=s.divideBy(2).round(),a=o.subtract(r);return a.x||a.y?(t.animate&&t.pan?this.panBy(a):(t.pan&&this._rawPanBy(a),this.fire("move"),t.debounceMoveend?(clearTimeout(this._sizeTimer),this._sizeTimer=setTimeout(n(this.fire,this,"moveend"),200)):this.fire("moveend")),this.fire("resize",{oldSize:i,newSize:s})):this},stop:function(){return this.setZoom(this._limitZoom(this._zoom)),this.options.zoomSnap||this.fire("viewreset"),this._stop()},locate:function(t){if(t=this._locateOptions=e({timeout:1e4,watch:!1},t),!("geolocation"in navigator))return this._handleGeolocationError({code:0,message:"Geolocation not supported."}),this;var i=n(this._handleGeolocationResponse,this),s=n(this._handleGeolocationError,this);return t.watch?this._locationWatchId=navigator.geolocation.watchPosition(i,s,t):navigator.geolocation.getCurrentPosition(i,s,t),this},stopLocate:function(){return navigator.geolocation&&navigator.geolocation.clearWatch&&navigator.geolocation.clearWatch(this._locationWatchId),this._locateOptions&&(this._locateOptions.setView=!1),this},_handleGeolocationError:function(t){if(this._container._leaflet_id){var e=t.code,i=t.message||(1===e?"permission denied":2===e?"position unavailable":"timeout");this._locateOptions.setView&&!this._loaded&&this.fitWorld(),this.fire("locationerror",{code:e,message:"Geolocation error: "+i+"."})}},_handleGeolocationResponse:function(t){if(this._container._leaflet_id){var e=new z(t.coords.latitude,t.coords.longitude),i=e.toBounds(2*t.coords.accuracy),n=this._locateOptions;if(n.setView){var s=this.getBoundsZoom(i);this.setView(e,n.maxZoom?Math.min(s,n.maxZoom):s)}var o={latlng:e,bounds:i,timestamp:t.timestamp};for(var r in t.coords)"number"==typeof t.coords[r]&&(o[r]=t.coords[r]);this.fire("locationfound",o)}},addHandler:function(t,e){if(!e)return this;var i=this[t]=new e(this);return this._handlers.push(i),this.options[t]&&i.enable(),this},remove:function(){if(this._initEvents(!0),this.options.maxBounds&&this.off("moveend",this._panInsideMaxBounds),this._containerId!==this._container._leaflet_id)throw new Error("Map container is being reused by another instance");try{delete this._container._leaflet_id,delete this._containerId}catch(t){this._container._leaflet_id=void 0,this._containerId=void 0}var t;for(t in void 0!==this._locationWatchId&&this.stopLocate(),this._stop(),oe(this._mapPane),this._clearControlPos&&this._clearControlPos(),this._resizeRequest&&(E(this._resizeRequest),this._resizeRequest=null),this._clearHandlers(),this._loaded&&this.fire("unload"),this._layers)this._layers[t].remove();for(t in this._panes)oe(this._panes[t]);return this._layers=[],this._panes=[],delete this._mapPane,delete this._renderer,this},createPane:function(t,e){var i=se("div","leaflet-pane"+(t?" leaflet-"+t.replace("Pane","")+"-pane":""),e||this._mapPane);return t&&(this._panes[t]=i),i},getCenter:function(){return this._checkIfLoaded(),this._lastCenter&&!this._moved()?this._lastCenter.clone():this.layerPointToLatLng(this._getCenterLayerPoint())},getZoom:function(){return this._zoom},getBounds:function(){var t=this.getPixelBounds();return new k(this.unproject(t.getBottomLeft()),this.unproject(t.getTopRight()))},getMinZoom:function(){return void 0===this.options.minZoom?this._layersMinZoom||0:this.options.minZoom},getMaxZoom:function(){return void 0===this.options.maxZoom?void 0===this._layersMaxZoom?1/0:this._layersMaxZoom:this.options.maxZoom},getBoundsZoom:function(t,e,i){t=B(t),i=I(i||[0,0]);var n=this.getZoom()||0,s=this.getMinZoom(),o=this.getMaxZoom(),r=t.getNorthWest(),a=t.getSouthEast(),h=this.getSize().subtract(i),l=O(this.project(a,n),this.project(r,n)).getSize(),d=Rt.any3d?this.options.zoomSnap:1,u=h.x/l.x,c=h.y/l.y,_=e?Math.max(u,c):Math.min(u,c);return n=this.getScaleZoom(_,n),d&&(n=Math.round(n/(d/100))*(d/100),n=e?Math.ceil(n/d)*d:Math.floor(n/d)*d),Math.max(s,Math.min(o,n))},getSize:function(){return this._size&&!this._sizeChanged||(this._size=new N(this._container.clientWidth||0,this._container.clientHeight||0),this._sizeChanged=!1),this._size.clone()},getPixelBounds:function(t,e){var i=this._getTopLeftPoint(t,e);return new R(i,i.add(this.getSize()))},getPixelOrigin:function(){return this._checkIfLoaded(),this._pixelOrigin},getPixelWorldBounds:function(t){return this.options.crs.getProjectedBounds(void 0===t?this.getZoom():t)},getPane:function(t){return"string"==typeof t?this._panes[t]:t},getPanes:function(){return this._panes},getContainer:function(){return this._container},getZoomScale:function(t,e){var i=this.options.crs;return e=void 0===e?this._zoom:e,i.scale(t)/i.scale(e)},getScaleZoom:function(t,e){var i=this.options.crs;e=void 0===e?this._zoom:e;var n=i.zoom(t*i.scale(e));return isNaN(n)?1/0:n},project:function(t,e){return e=void 0===e?this._zoom:e,this.options.crs.latLngToPoint(U(t),e)},unproject:function(t,e){return e=void 0===e?this._zoom:e,this.options.crs.pointToLatLng(I(t),e)},layerPointToLatLng:function(t){var e=I(t).add(this.getPixelOrigin());return this.unproject(e)},latLngToLayerPoint:function(t){return this.project(U(t))._round()._subtract(this.getPixelOrigin())},wrapLatLng:function(t){return this.options.crs.wrapLatLng(U(t))},wrapLatLngBounds:function(t){return this.options.crs.wrapLatLngBounds(B(t))},distance:function(t,e){return this.options.crs.distance(U(t),U(e))},containerPointToLayerPoint:function(t){return I(t).subtract(this._getMapPanePos())},layerPointToContainerPoint:function(t){return I(t).add(this._getMapPanePos())},containerPointToLatLng:function(t){var e=this.containerPointToLayerPoint(I(t));return this.layerPointToLatLng(e)},latLngToContainerPoint:function(t){return this.layerPointToContainerPoint(this.latLngToLayerPoint(U(t)))},mouseEventToContainerPoint:function(t){return Fe(t,this._container)},mouseEventToLayerPoint:function(t){return this.containerPointToLayerPoint(this.mouseEventToContainerPoint(t))},mouseEventToLatLng:function(t){return this.layerPointToLatLng(this.mouseEventToLayerPoint(t))},_initContainer:function(t){var e=this._container=ie(t);if(!e)throw new Error("Map container not found.");if(e._leaflet_id)throw new Error("Map container is already initialized.");Ae(e,"scroll",this._onScroll,this),this._containerId=o(e)},_initLayout:function(){var t=this._container;this._fadeAnimated=this.options.fadeAnimation&&Rt.any3d,de(t,"leaflet-container"+(Rt.touch?" leaflet-touch":"")+(Rt.retina?" leaflet-retina":"")+(Rt.ielt9?" leaflet-oldie":"")+(Rt.safari?" leaflet-safari":"")+(this._fadeAnimated?" leaflet-fade-anim":""));var e=ne(t,"position");"absolute"!==e&&"relative"!==e&&"fixed"!==e&&"sticky"!==e&&(t.style.position="relative"),this._initPanes(),this._initControlPos&&this._initControlPos()},_initPanes:function(){var t=this._panes={};this._paneRenderers={},this._mapPane=this.createPane("mapPane",this._container),me(this._mapPane,new N(0,0)),this.createPane("tilePane"),this.createPane("overlayPane"),this.createPane("shadowPane"),this.createPane("markerPane"),this.createPane("tooltipPane"),this.createPane("popupPane"),this.options.markerZoomAnimation||(de(t.markerPane,"leaflet-zoom-hide"),de(t.shadowPane,"leaflet-zoom-hide"))},_resetView:function(t,e,i){me(this._mapPane,new N(0,0));var n=!this._loaded;this._loaded=!0,e=this._limitZoom(e),this.fire("viewprereset");var s=this._zoom!==e;this._moveStart(s,i)._move(t,e)._moveEnd(s),this.fire("viewreset"),n&&this.fire("load")},_moveStart:function(t,e){return t&&this.fire("zoomstart"),e||this.fire("movestart"),this},_move:function(t,e,i,n){void 0===e&&(e=this._zoom);var s=this._zoom!==e;return this._zoom=e,this._lastCenter=t,this._pixelOrigin=this._getNewPixelOrigin(t),n?i&&i.pinch&&this.fire("zoom",i):((s||i&&i.pinch)&&this.fire("zoom",i),this.fire("move",i)),this},_moveEnd:function(t){return t&&this.fire("zoomend"),this.fire("moveend")},_stop:function(){return E(this._flyToFrame),this._panAnim&&this._panAnim.stop(),this},_rawPanBy:function(t){me(this._mapPane,this._getMapPanePos().subtract(t))},_getZoomSpan:function(){return this.getMaxZoom()-this.getMinZoom()},_panInsideMaxBounds:function(){this._enforcingBounds||this.panInsideBounds(this.options.maxBounds)},_checkIfLoaded:function(){if(!this._loaded)throw new Error("Set map center and zoom first.")},_initEvents:function(t){this._targets={},this._targets[o(this._container)]=this;var e=t?Me:Ae;e(this._container,"click dblclick mousedown mouseup mouseover mouseout mousemove contextmenu keypress keydown keyup",this._handleDOMEvent,this),this.options.trackResize&&e(window,"resize",this._onResize,this),Rt.any3d&&this.options.transform3DLimit&&(t?this.off:this.on).call(this,"moveend",this._onMoveEnd)},_onResize:function(){E(this._resizeRequest),this._resizeRequest=T(function(){this.invalidateSize({debounceMoveend:!0})},this)},_onScroll:function(){this._container.scrollTop=0,this._container.scrollLeft=0},_onMoveEnd:function(){var t=this._getMapPanePos();Math.max(Math.abs(t.x),Math.abs(t.y))>=this.options.transform3DLimit&&this._resetView(this.getCenter(),this.getZoom())},_findEventTargets:function(t,e){for(var i,n=[],s="mouseout"===e||"mouseover"===e,r=t.target||t.srcElement,a=!1;r;){if((i=this._targets[o(r)])&&("click"===e||"preclick"===e)&&this._draggableMoved(i)){a=!0;break}if(i&&i.listens(e,!0)){if(s&&!Ge(r,t))break;if(n.push(i),s)break}if(r===this._container)break;r=r.parentNode}return n.length||a||s||!this.listens(e,!0)||(n=[this]),n},_isClickDisabled:function(t){for(;t&&t!==this._container;){if(t._leaflet_disable_click)return!0;t=t.parentNode}},_handleDOMEvent:function(t){var e=t.target||t.srcElement;if(!(!this._loaded||e._leaflet_disable_events||"click"===t.type&&this._isClickDisabled(e))){var i=t.type;"mousedown"===i&&Se(e),this._fireDOMEvent(t,i)}},_mouseEvents:["click","dblclick","mouseover","mouseout","contextmenu"],_fireDOMEvent:function(t,i,n){if("click"===t.type){var s=e({},t);s.type="preclick",this._fireDOMEvent(s,s.type,n)}var o=this._findEventTargets(t,i);if(n){for(var r=[],a=0;a0?Math.round(t-e)/2:Math.max(0,Math.ceil(t))-Math.max(0,Math.floor(e))},_limitZoom:function(t){var e=this.getMinZoom(),i=this.getMaxZoom(),n=Rt.any3d?this.options.zoomSnap:1;return n&&(t=Math.round(t/n)*n),Math.max(e,Math.min(i,t))},_onPanTransitionStep:function(){this.fire("move")},_onPanTransitionEnd:function(){ue(this._mapPane,"leaflet-pan-anim"),this.fire("moveend")},_tryAnimatedPan:function(t,e){var i=this._getCenterOffset(t)._trunc();return!(!0!==(e&&e.animate)&&!this.getSize().contains(i)||(this.panBy(i,e),0))},_createAnimProxy:function(){var t=this._proxy=se("div","leaflet-proxy leaflet-zoom-animated");this._panes.mapPane.appendChild(t),this.on("zoomanim",function(t){var e=Jt,i=this._proxy.style[e];pe(this._proxy,this.project(t.center,t.zoom),this.getZoomScale(t.zoom,1)),i===this._proxy.style[e]&&this._animatingZoom&&this._onZoomTransitionEnd()},this),this.on("load moveend",this._animMoveEnd,this),this._on("unload",this._destroyAnimProxy,this)},_destroyAnimProxy:function(){oe(this._proxy),this.off("load moveend",this._animMoveEnd,this),delete this._proxy},_animMoveEnd:function(){var t=this.getCenter(),e=this.getZoom();pe(this._proxy,this.project(t,e),this.getZoomScale(e,1))},_catchTransitionEnd:function(t){this._animatingZoom&&t.propertyName.indexOf("transform")>=0&&this._onZoomTransitionEnd()},_nothingToAnimate:function(){return!this._container.getElementsByClassName("leaflet-zoom-animated").length},_tryAnimatedZoom:function(t,e,i){if(this._animatingZoom)return!0;if(i=i||{},!this._zoomAnimated||!1===i.animate||this._nothingToAnimate()||Math.abs(e-this._zoom)>this.options.zoomAnimationThreshold)return!1;var n=this.getZoomScale(e),s=this._getCenterOffset(t)._divideBy(1-1/n);return!(!0!==i.animate&&!this.getSize().contains(s)||(T(function(){this._moveStart(!0,i.noMoveStart||!1)._animateZoom(t,e,!0)},this),0))},_animateZoom:function(t,e,i,s){this._mapPane&&(i&&(this._animatingZoom=!0,this._animateToCenter=t,this._animateToZoom=e,de(this._mapPane,"leaflet-zoom-anim")),this.fire("zoomanim",{center:t,zoom:e,noUpdate:s}),this._tempFireZoomEvent||(this._tempFireZoomEvent=this._zoom!==this._animateToZoom),this._move(this._animateToCenter,this._animateToZoom,void 0,!0),setTimeout(n(this._onZoomTransitionEnd,this),250))},_onZoomTransitionEnd:function(){this._animatingZoom&&(this._mapPane&&ue(this._mapPane,"leaflet-zoom-anim"),this._animatingZoom=!1,this._move(this._animateToCenter,this._animateToZoom,void 0,!0),this._tempFireZoomEvent&&this.fire("zoom"),delete this._tempFireZoomEvent,this.fire("move"),this._moveEnd(!0))}});var qe=A.extend({options:{position:"topright"},initialize:function(t){c(this,t)},getPosition:function(){return this.options.position},setPosition:function(t){var e=this._map;return e&&e.removeControl(this),this.options.position=t,e&&e.addControl(this),this},getContainer:function(){return this._container},addTo:function(t){this.remove(),this._map=t;var e=this._container=this.onAdd(t),i=this.getPosition(),n=t._controlCorners[i];return de(e,"leaflet-control"),-1!==i.indexOf("bottom")?n.insertBefore(e,n.firstChild):n.appendChild(e),this._map.on("unload",this.remove,this),this},remove:function(){return this._map?(oe(this._container),this.onRemove&&this.onRemove(this._map),this._map.off("unload",this.remove,this),this._map=null,this):this},_refocusOnMap:function(t){this._map&&t&&t.screenX>0&&t.screenY>0&&this._map.getContainer().focus()}}),Ve=function(t){return new qe(t)};Xe.include({addControl:function(t){return t.addTo(this),this},removeControl:function(t){return t.remove(),this},_initControlPos:function(){var t=this._controlCorners={},e="leaflet-",i=this._controlContainer=se("div",e+"control-container",this._container);function n(n,s){var o=e+n+" "+e+s;t[n+s]=se("div",o,i)}n("top","left"),n("top","right"),n("bottom","left"),n("bottom","right")},_clearControlPos:function(){for(var t in this._controlCorners)oe(this._controlCorners[t]);oe(this._controlContainer),delete this._controlCorners,delete this._controlContainer}});var Ye=qe.extend({options:{collapsed:!0,position:"topright",autoZIndex:!0,hideSingleBase:!1,sortLayers:!1,sortFunction:function(t,e,i,n){return i1,this._baseLayersList.style.display=t?"":"none"),this._separator.style.display=e&&t?"":"none",this},_onLayerChange:function(t){this._handlingClick||this._update();var e=this._getLayer(o(t.target)),i=e.overlay?"add"===t.type?"overlayadd":"overlayremove":"add"===t.type?"baselayerchange":null;i&&this._map.fire(i,e)},_createRadioElement:function(t,e){var i='",n=document.createElement("div");return n.innerHTML=i,n.firstChild},_addItem:function(t){var e,i=document.createElement("label"),n=this._map.hasLayer(t.layer);t.overlay?((e=document.createElement("input")).type="checkbox",e.className="leaflet-control-layers-selector",e.defaultChecked=n):e=this._createRadioElement("leaflet-base-layers_"+o(this),n),this._layerControlInputs.push(e),e.layerId=o(t.layer),Ae(e,"click",this._onInputClick,this);var s=document.createElement("span");s.innerHTML=" "+t.name;var r=document.createElement("span");return i.appendChild(r),r.appendChild(e),r.appendChild(s),(t.overlay?this._overlaysList:this._baseLayersList).appendChild(i),this._checkDisabledLayers(),i},_onInputClick:function(){if(!this._preventClick){var t,e,i=this._layerControlInputs,n=[],s=[];this._handlingClick=!0;for(var o=i.length-1;o>=0;o--)t=i[o],e=this._getLayer(t.layerId).layer,t.checked?n.push(e):t.checked||s.push(e);for(o=0;o=0;s--)t=i[s],e=this._getLayer(t.layerId).layer,t.disabled=void 0!==e.options.minZoom&&ne.options.maxZoom},_expandIfNotCollapsed:function(){return this._map&&!this.options.collapsed&&this.expand(),this},_expandSafely:function(){var t=this._section;this._preventClick=!0,Ae(t,"click",Be),this.expand();var e=this;setTimeout(function(){Me(t,"click",Be),e._preventClick=!1})}}),$e=qe.extend({options:{position:"topleft",zoomInText:'',zoomInTitle:"Zoom in",zoomOutText:'',zoomOutTitle:"Zoom out"},onAdd:function(t){var e="leaflet-control-zoom",i=se("div",e+" leaflet-bar"),n=this.options;return this._zoomInButton=this._createButton(n.zoomInText,n.zoomInTitle,e+"-in",i,this._zoomIn),this._zoomOutButton=this._createButton(n.zoomOutText,n.zoomOutTitle,e+"-out",i,this._zoomOut),this._updateDisabled(),t.on("zoomend zoomlevelschange",this._updateDisabled,this),i},onRemove:function(t){t.off("zoomend zoomlevelschange",this._updateDisabled,this)},disable:function(){return this._disabled=!0,this._updateDisabled(),this},enable:function(){return this._disabled=!1,this._updateDisabled(),this},_zoomIn:function(t){!this._disabled&&this._map._zoomthis._map.getMinZoom()&&this._map.zoomOut(this._map.options.zoomDelta*(t.shiftKey?3:1))},_createButton:function(t,e,i,n,s){var o=se("a",i,n);return o.innerHTML=t,o.href="#",o.title=e,o.setAttribute("role","button"),o.setAttribute("aria-label",e),ke(o),Ae(o,"click",ze),Ae(o,"click",s,this),Ae(o,"click",this._refocusOnMap,this),o},_updateDisabled:function(){var t=this._map,e="leaflet-disabled";ue(this._zoomInButton,e),ue(this._zoomOutButton,e),this._zoomInButton.setAttribute("aria-disabled","false"),this._zoomOutButton.setAttribute("aria-disabled","false"),(this._disabled||t._zoom===t.getMinZoom())&&(de(this._zoomOutButton,e),this._zoomOutButton.setAttribute("aria-disabled","true")),(this._disabled||t._zoom===t.getMaxZoom())&&(de(this._zoomInButton,e),this._zoomInButton.setAttribute("aria-disabled","true"))}});Xe.mergeOptions({zoomControl:!0}),Xe.addInitHook(function(){this.options.zoomControl&&(this.zoomControl=new $e,this.addControl(this.zoomControl))});var Ke=qe.extend({options:{position:"bottomleft",maxWidth:100,metric:!0,imperial:!0},onAdd:function(t){var e="leaflet-control-scale",i=se("div",e),n=this.options;return this._addScales(n,e+"-line",i),t.on(n.updateWhenIdle?"moveend":"move",this._update,this),t.whenReady(this._update,this),i},onRemove:function(t){t.off(this.options.updateWhenIdle?"moveend":"move",this._update,this)},_addScales:function(t,e,i){t.metric&&(this._mScale=se("div",e,i)),t.imperial&&(this._iScale=se("div",e,i))},_update:function(){var t=this._map,e=t.getSize().y/2,i=t.distance(t.containerPointToLatLng([0,e]),t.containerPointToLatLng([this.options.maxWidth,e]));this._updateScales(i)},_updateScales:function(t){this.options.metric&&t&&this._updateMetric(t),this.options.imperial&&t&&this._updateImperial(t)},_updateMetric:function(t){var e=this._getRoundNum(t),i=e<1e3?e+" m":e/1e3+" km";this._updateScale(this._mScale,i,e/t)},_updateImperial:function(t){var e,i,n,s=3.2808399*t;s>5280?(e=s/5280,i=this._getRoundNum(e),this._updateScale(this._iScale,i+" mi",i/e)):(n=this._getRoundNum(s),this._updateScale(this._iScale,n+" ft",n/s))},_updateScale:function(t,e,i){t.style.width=Math.round(this.options.maxWidth*i)+"px",t.innerHTML=e},_getRoundNum:function(t){var e=Math.pow(10,(Math.floor(t)+"").length-1),i=t/e;return e*(i>=10?10:i>=5?5:i>=3?3:i>=2?2:1)}}),Qe=qe.extend({options:{position:"bottomright",prefix:''+(Rt.inlineSvg?' ':"")+"Leaflet"},initialize:function(t){c(this,t),this._attributions={}},onAdd:function(t){for(var e in t.attributionControl=this,this._container=se("div","leaflet-control-attribution"),ke(this._container),t._layers)t._layers[e].getAttribution&&this.addAttribution(t._layers[e].getAttribution());return this._update(),t.on("layeradd",this._addAttribution,this),this._container},onRemove:function(t){t.off("layeradd",this._addAttribution,this)},_addAttribution:function(t){t.layer.getAttribution&&(this.addAttribution(t.layer.getAttribution()),t.layer.once("remove",function(){this.removeAttribution(t.layer.getAttribution())},this))},setPrefix:function(t){return this.options.prefix=t,this._update(),this},addAttribution:function(t){return t?(this._attributions[t]||(this._attributions[t]=0),this._attributions[t]++,this._update(),this):this},removeAttribution:function(t){return t?(this._attributions[t]&&(this._attributions[t]--,this._update()),this):this},_update:function(){if(this._map){var t=[];for(var e in this._attributions)this._attributions[e]&&t.push(e);var i=[];this.options.prefix&&i.push(this.options.prefix),t.length&&i.push(t.join(", ")),this._container.innerHTML=i.join(' ')}}});Xe.mergeOptions({attributionControl:!0}),Xe.addInitHook(function(){this.options.attributionControl&&(new Qe).addTo(this)});qe.Layers=Ye,qe.Zoom=$e,qe.Scale=Ke,qe.Attribution=Qe,Ve.layers=function(t,e,i){return new Ye(t,e,i)},Ve.zoom=function(t){return new $e(t)},Ve.scale=function(t){return new Ke(t)},Ve.attribution=function(t){return new Qe(t)};var Je=A.extend({initialize:function(t){this._map=t},enable:function(){return this._enabled||(this._enabled=!0,this.addHooks()),this},disable:function(){return this._enabled?(this._enabled=!1,this.removeHooks(),this):this},enabled:function(){return!!this._enabled}});Je.addTo=function(t,e){return t.addHandler(e,this),this};var ti={Events:C},ei=Rt.touch?"touchstart mousedown":"mousedown",ii=M.extend({options:{clickTolerance:3},initialize:function(t,e,i,n){c(this,n),this._element=t,this._dragStartTarget=e||t,this._preventOutline=i},enable:function(){this._enabled||(Ae(this._dragStartTarget,ei,this._onDown,this),this._enabled=!0)},disable:function(){this._enabled&&(ii._dragging===this&&this.finishDrag(!0),Me(this._dragStartTarget,ei,this._onDown,this),this._enabled=!1,this._moved=!1)},_onDown:function(t){if(this._enabled&&(this._moved=!1,!le(this._element,"leaflet-zoom-anim")))if(t.touches&&1!==t.touches.length)ii._dragging===this&&this.finishDrag();else if(!(ii._dragging||t.shiftKey||1!==t.which&&1!==t.button&&!t.touches||(ii._dragging=this,this._preventOutline&&Se(this._element),xe(),Vt(),this._moving))){this.fire("down");var e=t.touches?t.touches[0]:t,i=Te(this._element);this._startPoint=new N(e.clientX,e.clientY),this._startPos=ve(this._element),this._parentScale=Ee(i);var n="mousedown"===t.type;Ae(document,n?"mousemove":"touchmove",this._onMove,this),Ae(document,n?"mouseup":"touchend touchcancel",this._onUp,this)}},_onMove:function(t){if(this._enabled)if(t.touches&&t.touches.length>1)this._moved=!0;else{var e=t.touches&&1===t.touches.length?t.touches[0]:t,i=new N(e.clientX,e.clientY)._subtract(this._startPoint);(i.x||i.y)&&(Math.abs(i.x)+Math.abs(i.y)e&&(i.push(t[n]),s=n);return sh&&(o=r,h=a);h>i&&(e[o]=1,di(t,e,i,n,o),di(t,e,i,o,s))}function ui(t,e,i,n,s){var o,r,a,h=n?ri:_i(t,i),l=_i(e,i);for(ri=l;;){if(!(h|l))return[t,e];if(h&l)return!1;a=_i(r=ci(t,e,o=h||l,i,s),i),o===h?(t=r,h=a):(e=r,l=a)}}function ci(t,e,i,n,s){var o,r,a=e.x-t.x,h=e.y-t.y,l=n.min,d=n.max;return 8&i?(o=t.x+a*(d.y-t.y)/h,r=d.y):4&i?(o=t.x+a*(l.y-t.y)/h,r=l.y):2&i?(o=d.x,r=t.y+h*(d.x-t.x)/a):1&i&&(o=l.x,r=t.y+h*(l.x-t.x)/a),new N(o,r,s)}function _i(t,e){var i=0;return t.xe.max.x&&(i|=2),t.ye.max.y&&(i|=8),i}function fi(t,e){var i=e.x-t.x,n=e.y-t.y;return i*i+n*n}function gi(t,e,i,n){var s,o=e.x,r=e.y,a=i.x-o,h=i.y-r,l=a*a+h*h;return l>0&&((s=((t.x-o)*a+(t.y-r)*h)/l)>1?(o=i.x,r=i.y):s>0&&(o+=a*s,r+=h*s)),a=t.x-o,h=t.y-r,n?a*a+h*h:new N(o,r)}function pi(t){return!p(t[0])||"object"!=typeof t[0][0]&&void 0!==t[0][0]}function mi(t){return console.warn("Deprecated use of _flat, please use L.LineUtil.isFlat instead."),pi(t)}function vi(t,e){var i,n,s,o,r,a,h,l;if(!t||0===t.length)throw new Error("latlngs not passed");pi(t)||(console.warn("latlngs are not flat! Only the first ring will be used"),t=t[0]);var d=U([0,0]),u=B(t);u.getNorthWest().distanceTo(u.getSouthWest())*u.getNorthEast().distanceTo(u.getNorthWest())<1700&&(d=oi(t));var c=t.length,_=[];for(i=0;in){h=(o-n)/s,l=[a.x-h*(a.x-r.x),a.y-h*(a.y-r.y)];break}var g=e.unproject(I(l));return U([g.lat+d.lat,g.lng+d.lng])}var yi={__proto__:null,simplify:hi,pointToSegmentDistance:li,closestPointOnSegment:function(t,e,i){return gi(t,e,i)},clipSegment:ui,_getEdgeIntersection:ci,_getBitCode:_i,_sqClosestPointOnSegment:gi,isFlat:pi,_flat:mi,polylineCenter:vi},xi={project:function(t){return new N(t.lng,t.lat)},unproject:function(t){return new z(t.y,t.x)},bounds:new R([-180,-90],[180,90])},bi={R:6378137,R_MINOR:6356752.314245179,bounds:new R([-20037508.34279,-15496570.73972],[20037508.34279,18764656.23138]),project:function(t){var e=Math.PI/180,i=this.R,n=t.lat*e,s=this.R_MINOR/i,o=Math.sqrt(1-s*s),r=o*Math.sin(n),a=Math.tan(Math.PI/4-n/2)/Math.pow((1-r)/(1+r),o/2);return n=-i*Math.log(Math.max(a,1e-10)),new N(t.lng*e*i,n)},unproject:function(t){for(var e,i=180/Math.PI,n=this.R,s=this.R_MINOR/n,o=Math.sqrt(1-s*s),r=Math.exp(-t.y/n),a=Math.PI/2-2*Math.atan(r),h=0,l=.1;h<15&&Math.abs(l)>1e-7;h++)e=o*Math.sin(a),e=Math.pow((1-e)/(1+e),o/2),a+=l=Math.PI/2-2*Math.atan(r*e)-a;return new z(a*i,t.x*i/n)}},Si={__proto__:null,LonLat:xi,Mercator:bi,SphericalMercator:Z},wi=e({},W,{code:"EPSG:3395",projection:bi,transformation:function(){var t=.5/(Math.PI*bi.R);return X(t,.5,-t,.5)}()}),Ti=e({},W,{code:"EPSG:4326",projection:xi,transformation:X(1/180,1,-1/180,.5)}),Ei=e({},j,{projection:xi,transformation:X(1,0,-1,0),scale:function(t){return Math.pow(2,t)},zoom:function(t){return Math.log(t)/Math.LN2},distance:function(t,e){var i=e.lng-t.lng,n=e.lat-t.lat;return Math.sqrt(i*i+n*n)},infinite:!0});j.Earth=W,j.EPSG3395=wi,j.EPSG3857=q,j.EPSG900913=V,j.EPSG4326=Ti,j.Simple=Ei;var Pi=M.extend({options:{pane:"overlayPane",attribution:null,bubblingMouseEvents:!0},addTo:function(t){return t.addLayer(this),this},remove:function(){return this.removeFrom(this._map||this._mapToAdd)},removeFrom:function(t){return t&&t.removeLayer(this),this},getPane:function(t){return this._map.getPane(t?this.options[t]||t:this.options.pane)},addInteractiveTarget:function(t){return this._map._targets[o(t)]=this,this},removeInteractiveTarget:function(t){return delete this._map._targets[o(t)],this},getAttribution:function(){return this.options.attribution},_layerAdd:function(t){var e=t.target;if(e.hasLayer(this)){if(this._map=e,this._zoomAnimated=e._zoomAnimated,this.getEvents){var i=this.getEvents();e.on(i,this),this.once("remove",function(){e.off(i,this)},this)}this.onAdd(e),this.fire("add"),e.fire("layeradd",{layer:this})}}});Xe.include({addLayer:function(t){if(!t._layerAdd)throw new Error("The provided object is not a Layer.");var e=o(t);return this._layers[e]||(this._layers[e]=t,t._mapToAdd=this,t.beforeAdd&&t.beforeAdd(this),this.whenReady(t._layerAdd,t)),this},removeLayer:function(t){var e=o(t);return this._layers[e]?(this._loaded&&t.onRemove(this),delete this._layers[e],this._loaded&&(this.fire("layerremove",{layer:t}),t.fire("remove")),t._map=t._mapToAdd=null,this):this},hasLayer:function(t){return o(t)in this._layers},eachLayer:function(t,e){for(var i in this._layers)t.call(e,this._layers[i]);return this},_addLayers:function(t){for(var e=0,i=(t=t?p(t)?t:[t]:[]).length;ethis._layersMaxZoom&&this.setZoom(this._layersMaxZoom),void 0===this.options.minZoom&&this._layersMinZoom&&this.getZoom()=2&&e[0]instanceof z&&e[0].equals(e[i-1])&&e.pop(),e},_setLatLngs:function(t){ki.prototype._setLatLngs.call(this,t),pi(this._latlngs)&&(this._latlngs=[this._latlngs])},_defaultShape:function(){return pi(this._latlngs[0])?this._latlngs[0]:this._latlngs[0][0]},_clipPoints:function(){var t=this._renderer._bounds,e=this.options.weight,i=new N(e,e);if(t=new R(t.min.subtract(i),t.max.add(i)),this._parts=[],this._pxBounds&&this._pxBounds.intersects(t))if(this.options.noClip)this._parts=this._rings;else for(var n,s=0,o=this._rings.length;st.y!=n.y>t.y&&t.x<(n.x-i.x)*(t.y-i.y)/(n.y-i.y)+i.x&&(l=!l);return l||ki.prototype._containsPoint.call(this,t,!0)}});var zi=Ci.extend({initialize:function(t,e){c(this,e),this._layers={},t&&this.addData(t)},addData:function(t){var e,i,n,s=p(t)?t:t.features;if(s){for(e=0,i=s.length;e0&&s.push(s[0].slice()),s}function Hi(t,i){return t.feature?e({},t.feature,{geometry:i}):Xi(i)}function Xi(t){return"Feature"===t.type||"FeatureCollection"===t.type?t:{type:"Feature",properties:{},geometry:t}}var qi={toGeoJSON:function(t){return Hi(this,{type:"Point",coordinates:Gi(this.getLatLng(),t)})}};function Vi(t,e){return new zi(t,e)}Ii.include(qi),Oi.include(qi),Ri.include(qi),ki.include({toGeoJSON:function(t){var e=!pi(this._latlngs);return Hi(this,{type:(e?"Multi":"")+"LineString",coordinates:Zi(this._latlngs,e?1:0,!1,t)})}}),Bi.include({toGeoJSON:function(t){var e=!pi(this._latlngs),i=e&&!pi(this._latlngs[0]),n=Zi(this._latlngs,i?2:e?1:0,!0,t);return e||(n=[n]),Hi(this,{type:(i?"Multi":"")+"Polygon",coordinates:n})}}),Ai.include({toMultiPoint:function(t){var e=[];return this.eachLayer(function(i){e.push(i.toGeoJSON(t).geometry.coordinates)}),Hi(this,{type:"MultiPoint",coordinates:e})},toGeoJSON:function(t){var e=this.feature&&this.feature.geometry&&this.feature.geometry.type;if("MultiPoint"===e)return this.toMultiPoint(t);var i="GeometryCollection"===e,n=[];return this.eachLayer(function(e){if(e.toGeoJSON){var s=e.toGeoJSON(t);if(i)n.push(s.geometry);else{var o=Xi(s);"FeatureCollection"===o.type?n.push.apply(n,o.features):n.push(o)}}}),i?Hi(this,{geometries:n,type:"GeometryCollection"}):{type:"FeatureCollection",features:n}}});var Yi=Vi,$i=Pi.extend({options:{opacity:1,alt:"",interactive:!1,crossOrigin:!1,errorOverlayUrl:"",zIndex:1,className:""},initialize:function(t,e,i){this._url=t,this._bounds=B(e),c(this,i)},onAdd:function(){this._image||(this._initImage(),this.options.opacity<1&&this._updateOpacity()),this.options.interactive&&(de(this._image,"leaflet-interactive"),this.addInteractiveTarget(this._image)),this.getPane().appendChild(this._image),this._reset()},onRemove:function(){oe(this._image),this.options.interactive&&this.removeInteractiveTarget(this._image)},setOpacity:function(t){return this.options.opacity=t,this._image&&this._updateOpacity(),this},setStyle:function(t){return t.opacity&&this.setOpacity(t.opacity),this},bringToFront:function(){return this._map&&ae(this._image),this},bringToBack:function(){return this._map&&he(this._image),this},setUrl:function(t){return this._url=t,this._image&&(this._image.src=t),this},setBounds:function(t){return this._bounds=B(t),this._map&&this._reset(),this},getEvents:function(){var t={zoom:this._reset,viewreset:this._reset};return this._zoomAnimated&&(t.zoomanim=this._animateZoom),t},setZIndex:function(t){return this.options.zIndex=t,this._updateZIndex(),this},getBounds:function(){return this._bounds},getElement:function(){return this._image},_initImage:function(){var t="IMG"===this._url.tagName,e=this._image=t?this._url:se("img");de(e,"leaflet-image-layer"),this._zoomAnimated&&de(e,"leaflet-zoom-animated"),this.options.className&&de(e,this.options.className),e.onselectstart=h,e.onmousemove=h,e.onload=n(this.fire,this,"load"),e.onerror=n(this._overlayOnError,this,"error"),(this.options.crossOrigin||""===this.options.crossOrigin)&&(e.crossOrigin=!0===this.options.crossOrigin?"":this.options.crossOrigin),this.options.zIndex&&this._updateZIndex(),t?this._url=e.src:(e.src=this._url,e.alt=this.options.alt)},_animateZoom:function(t){var e=this._map.getZoomScale(t.zoom),i=this._map._latLngBoundsToNewLayerBounds(this._bounds,t.zoom,t.center).min;pe(this._image,i,e)},_reset:function(){var t=this._image,e=new R(this._map.latLngToLayerPoint(this._bounds.getNorthWest()),this._map.latLngToLayerPoint(this._bounds.getSouthEast())),i=e.getSize();me(t,e.min),t.style.width=i.x+"px",t.style.height=i.y+"px"},_updateOpacity:function(){fe(this._image,this.options.opacity)},_updateZIndex:function(){this._image&&void 0!==this.options.zIndex&&null!==this.options.zIndex&&(this._image.style.zIndex=this.options.zIndex)},_overlayOnError:function(){this.fire("error");var t=this.options.errorOverlayUrl;t&&this._url!==t&&(this._url=t,this._image.src=t)},getCenter:function(){return this._bounds.getCenter()}}),Ki=$i.extend({options:{autoplay:!0,loop:!0,keepAspectRatio:!0,muted:!1,playsInline:!0},_initImage:function(){var t="VIDEO"===this._url.tagName,e=this._image=t?this._url:se("video");if(de(e,"leaflet-image-layer"),this._zoomAnimated&&de(e,"leaflet-zoom-animated"),this.options.className&&de(e,this.options.className),e.onselectstart=h,e.onmousemove=h,e.onloadeddata=n(this.fire,this,"load"),t){for(var i=e.getElementsByTagName("source"),s=[],o=0;o0?s:[e.src]}else{p(this._url)||(this._url=[this._url]),!this.options.keepAspectRatio&&Object.prototype.hasOwnProperty.call(e.style,"objectFit")&&(e.style.objectFit="fill"),e.autoplay=!!this.options.autoplay,e.loop=!!this.options.loop,e.muted=!!this.options.muted,e.playsInline=!!this.options.playsInline;for(var r=0;rs?(e.height=s+"px",de(t,o)):ue(t,o),this._containerWidth=this._container.offsetWidth},_animateZoom:function(t){var e=this._map._latLngToNewLayerPoint(this._latlng,t.zoom,t.center),i=this._getAnchor();me(this._container,e.add(i))},_adjustPan:function(){if(this.options.autoPan)if(this._map._panAnim&&this._map._panAnim.stop(),this._autopanning)this._autopanning=!1;else{var t=this._map,e=parseInt(ne(this._container,"marginBottom"),10)||0,i=this._container.offsetHeight+e,n=this._containerWidth,s=new N(this._containerLeft,-i-this._containerBottom);s._add(ve(this._container));var o=t.layerPointToContainerPoint(s),r=I(this.options.autoPanPadding),a=I(this.options.autoPanPaddingTopLeft||r),h=I(this.options.autoPanPaddingBottomRight||r),l=t.getSize(),d=0,u=0;o.x+n+h.x>l.x&&(d=o.x+n-l.x+h.x),o.x-d-a.x<0&&(d=o.x-a.x),o.y+i+h.y>l.y&&(u=o.y+i-l.y+h.y),o.y-u-a.y<0&&(u=o.y-a.y),(d||u)&&(this.options.keepInView&&(this._autopanning=!0),t.fire("autopanstart").panBy([d,u]))}},_getAnchor:function(){return I(this._source&&this._source._getPopupAnchor?this._source._getPopupAnchor():[0,0])}});Xe.mergeOptions({closePopupOnClick:!0}),Xe.include({openPopup:function(t,e,i){return this._initOverlay(tn,t,e,i).openOn(this),this},closePopup:function(t){return(t=arguments.length?t:this._popup)&&t.close(),this}}),Pi.include({bindPopup:function(t,e){return this._popup=this._initOverlay(tn,this._popup,t,e),this._popupHandlersAdded||(this.on({click:this._openPopup,keypress:this._onKeyPress,remove:this.closePopup,move:this._movePopup}),this._popupHandlersAdded=!0),this},unbindPopup:function(){return this._popup&&(this.off({click:this._openPopup,keypress:this._onKeyPress,remove:this.closePopup,move:this._movePopup}),this._popupHandlersAdded=!1,this._popup=null),this},openPopup:function(t){return this._popup&&(this instanceof Ci||(this._popup._source=this),this._popup._prepareOpen(t||this._latlng)&&this._popup.openOn(this._map)),this},closePopup:function(){return this._popup&&this._popup.close(),this},togglePopup:function(){return this._popup&&this._popup.toggle(this),this},isPopupOpen:function(){return!!this._popup&&this._popup.isOpen()},setPopupContent:function(t){return this._popup&&this._popup.setContent(t),this},getPopup:function(){return this._popup},_openPopup:function(t){if(this._popup&&this._map){ze(t);var e=t.layer||t.target;this._popup._source!==e||e instanceof Li?(this._popup._source=e,this.openPopup(t.latlng)):this._map.hasLayer(this._popup)?this.closePopup():this.openPopup(t.latlng)}},_movePopup:function(t){this._popup.setLatLng(t.latlng)},_onKeyPress:function(t){13===t.originalEvent.keyCode&&this._openPopup(t)}});var en=Ji.extend({options:{pane:"tooltipPane",offset:[0,0],direction:"auto",permanent:!1,sticky:!1,opacity:.9},onAdd:function(t){Ji.prototype.onAdd.call(this,t),this.setOpacity(this.options.opacity),t.fire("tooltipopen",{tooltip:this}),this._source&&(this.addEventParent(this._source),this._source.fire("tooltipopen",{tooltip:this},!0))},onRemove:function(t){Ji.prototype.onRemove.call(this,t),t.fire("tooltipclose",{tooltip:this}),this._source&&(this.removeEventParent(this._source),this._source.fire("tooltipclose",{tooltip:this},!0))},getEvents:function(){var t=Ji.prototype.getEvents.call(this);return this.options.permanent||(t.preclick=this.close),t},_initLayout:function(){var t="leaflet-tooltip "+(this.options.className||"")+" leaflet-zoom-"+(this._zoomAnimated?"animated":"hide");this._contentNode=this._container=se("div",t),this._container.setAttribute("role","tooltip"),this._container.setAttribute("id","leaflet-tooltip-"+o(this))},_updateLayout:function(){},_adjustPan:function(){},_setPosition:function(t){var e,i,n=this._map,s=this._container,o=n.latLngToContainerPoint(n.getCenter()),r=n.layerPointToContainerPoint(t),a=this.options.direction,h=s.offsetWidth,l=s.offsetHeight,d=I(this.options.offset),u=this._getAnchor();"top"===a?(e=h/2,i=l):"bottom"===a?(e=h/2,i=0):"center"===a?(e=h/2,i=l/2):"right"===a?(e=0,i=l/2):"left"===a?(e=h,i=l/2):r.xthis.options.maxZoom||in&&this._retainParent(s,o,r,n))},_retainChildren:function(t,e,i,n){for(var s=2*t;s<2*t+2;s++)for(var o=2*e;o<2*e+2;o++){var r=new N(s,o);r.z=i+1;var a=this._tileCoordsToKey(r),h=this._tiles[a];h&&h.active?h.retain=!0:(h&&h.loaded&&(h.retain=!0),i+1this.options.maxZoom||void 0!==this.options.minZoom&&s1)this._setView(t,i);else{for(var u=s.min.y;u<=s.max.y;u++)for(var c=s.min.x;c<=s.max.x;c++){var _=new N(c,u);if(_.z=this._tileZoom,this._isValidTile(_)){var f=this._tiles[this._tileCoordsToKey(_)];f?f.current=!0:r.push(_)}}if(r.sort(function(t,e){return t.distanceTo(o)-e.distanceTo(o)}),0!==r.length){this._loading||(this._loading=!0,this.fire("loading"));var g=document.createDocumentFragment();for(c=0;ci.max.x)||!e.wrapLat&&(t.yi.max.y))return!1}if(!this.options.bounds)return!0;var n=this._tileCoordsToBounds(t);return B(this.options.bounds).overlaps(n)},_keyToBounds:function(t){return this._tileCoordsToBounds(this._keyToTileCoords(t))},_tileCoordsToNwSe:function(t){var e=this._map,i=this.getTileSize(),n=t.scaleBy(i),s=n.add(i);return[e.unproject(n,t.z),e.unproject(s,t.z)]},_tileCoordsToBounds:function(t){var e=this._tileCoordsToNwSe(t),i=new k(e[0],e[1]);return this.options.noWrap||(i=this._map.wrapLatLngBounds(i)),i},_tileCoordsToKey:function(t){return t.x+":"+t.y+":"+t.z},_keyToTileCoords:function(t){var e=t.split(":"),i=new N(+e[0],+e[1]);return i.z=+e[2],i},_removeTile:function(t){var e=this._tiles[t];e&&(oe(e.el),delete this._tiles[t],this.fire("tileunload",{tile:e.el,coords:this._keyToTileCoords(t)}))},_initTile:function(t){de(t,"leaflet-tile");var e=this.getTileSize();t.style.width=e.x+"px",t.style.height=e.y+"px",t.onselectstart=h,t.onmousemove=h,Rt.ielt9&&this.options.opacity<1&&fe(t,this.options.opacity)},_addTile:function(t,e){var i=this._getTilePos(t),s=this._tileCoordsToKey(t),o=this.createTile(this._wrapCoords(t),n(this._tileReady,this,t));this._initTile(o),this.createTile.length<2&&T(n(this._tileReady,this,t,null,o)),me(o,i),this._tiles[s]={el:o,coords:t,current:!0},e.appendChild(o),this.fire("tileloadstart",{tile:o,coords:t})},_tileReady:function(t,e,i){e&&this.fire("tileerror",{error:e,tile:i,coords:t});var s=this._tileCoordsToKey(t);(i=this._tiles[s])&&(i.loaded=+new Date,this._map._fadeAnimated?(fe(i.el,0),E(this._fadeFrame),this._fadeFrame=T(this._updateOpacity,this)):(i.active=!0,this._pruneTiles()),e||(de(i.el,"leaflet-tile-loaded"),this.fire("tileload",{tile:i.el,coords:t})),this._noTilesToLoad()&&(this._loading=!1,this.fire("load"),Rt.ielt9||!this._map._fadeAnimated?T(this._pruneTiles,this):setTimeout(n(this._pruneTiles,this),250)))},_getTilePos:function(t){return t.scaleBy(this.getTileSize()).subtract(this._level.origin)},_wrapCoords:function(t){var e=new N(this._wrapX?a(t.x,this._wrapX):t.x,this._wrapY?a(t.y,this._wrapY):t.y);return e.z=t.z,e},_pxBoundsToTileRange:function(t){var e=this.getTileSize();return new R(t.min.unscaleBy(e).floor(),t.max.unscaleBy(e).ceil().subtract([1,1]))},_noTilesToLoad:function(){for(var t in this._tiles)if(!this._tiles[t].loaded)return!1;return!0}});var on=sn.extend({options:{minZoom:0,maxZoom:18,subdomains:"abc",errorTileUrl:"",zoomOffset:0,tms:!1,zoomReverse:!1,detectRetina:!1,crossOrigin:!1,referrerPolicy:!1},initialize:function(t,e){this._url=t,(e=c(this,e)).detectRetina&&Rt.retina&&e.maxZoom>0?(e.tileSize=Math.floor(e.tileSize/2),e.zoomReverse?(e.zoomOffset--,e.minZoom=Math.min(e.maxZoom,e.minZoom+1)):(e.zoomOffset++,e.maxZoom=Math.max(e.minZoom,e.maxZoom-1)),e.minZoom=Math.max(0,e.minZoom)):e.zoomReverse?e.minZoom=Math.min(e.maxZoom,e.minZoom):e.maxZoom=Math.max(e.minZoom,e.maxZoom),"string"==typeof e.subdomains&&(e.subdomains=e.subdomains.split("")),this.on("tileunload",this._onTileRemove)},setUrl:function(t,e){return this._url===t&&void 0===e&&(e=!0),this._url=t,e||this.redraw(),this},createTile:function(t,e){var i=document.createElement("img");return Ae(i,"load",n(this._tileOnLoad,this,e,i)),Ae(i,"error",n(this._tileOnError,this,e,i)),(this.options.crossOrigin||""===this.options.crossOrigin)&&(i.crossOrigin=!0===this.options.crossOrigin?"":this.options.crossOrigin),"string"==typeof this.options.referrerPolicy&&(i.referrerPolicy=this.options.referrerPolicy),i.alt="",i.src=this.getTileUrl(t),i},getTileUrl:function(t){var i={r:Rt.retina?"@2x":"",s:this._getSubdomain(t),x:t.x,y:t.y,z:this._getZoomForUrl()};if(this._map&&!this._map.options.crs.infinite){var n=this._globalTileRange.max.y-t.y;this.options.tms&&(i.y=n),i["-y"]=n}return g(this._url,e(i,this.options))},_tileOnLoad:function(t,e){Rt.ielt9?setTimeout(n(t,this,null,e),0):t(null,e)},_tileOnError:function(t,e,i){var n=this.options.errorTileUrl;n&&e.getAttribute("src")!==n&&(e.src=n),t(i,e)},_onTileRemove:function(t){t.tile.onload=null},_getZoomForUrl:function(){var t=this._tileZoom,e=this.options.maxZoom;return this.options.zoomReverse&&(t=e-t),t+this.options.zoomOffset},_getSubdomain:function(t){var e=Math.abs(t.x+t.y)%this.options.subdomains.length;return this.options.subdomains[e]},_abortLoading:function(){var t,e;for(t in this._tiles)if(this._tiles[t].coords.z!==this._tileZoom&&((e=this._tiles[t].el).onload=h,e.onerror=h,!e.complete)){e.src=v;var i=this._tiles[t].coords;oe(e),delete this._tiles[t],this.fire("tileabort",{tile:e,coords:i})}},_removeTile:function(t){var e=this._tiles[t];if(e)return e.el.setAttribute("src",v),sn.prototype._removeTile.call(this,t)},_tileReady:function(t,e,i){if(this._map&&(!i||i.getAttribute("src")!==v))return sn.prototype._tileReady.call(this,t,e,i)}});function rn(t,e){return new on(t,e)}var an=on.extend({defaultWmsParams:{service:"WMS",request:"GetMap",layers:"",styles:"",format:"image/jpeg",transparent:!1,version:"1.1.1"},options:{crs:null,uppercase:!1},initialize:function(t,i){this._url=t;var n=e({},this.defaultWmsParams);for(var s in i)s in this.options||(n[s]=i[s]);var o=(i=c(this,i)).detectRetina&&Rt.retina?2:1,r=this.getTileSize();n.width=r.x*o,n.height=r.y*o,this.wmsParams=n},onAdd:function(t){this._crs=this.options.crs||t.options.crs,this._wmsVersion=parseFloat(this.wmsParams.version);var e=this._wmsVersion>=1.3?"crs":"srs";this.wmsParams[e]=this._crs.code,on.prototype.onAdd.call(this,t)},getTileUrl:function(t){var e=this._tileCoordsToNwSe(t),i=this._crs,n=O(i.project(e[0]),i.project(e[1])),s=n.min,o=n.max,r=(this._wmsVersion>=1.3&&this._crs===Ti?[s.y,s.x,o.y,o.x]:[s.x,s.y,o.x,o.y]).join(","),a=on.prototype.getTileUrl.call(this,t);return a+_(this.wmsParams,a,this.options.uppercase)+(this.options.uppercase?"&BBOX=":"&bbox=")+r},setParams:function(t,i){return e(this.wmsParams,t),i||this.redraw(),this}});on.WMS=an,rn.wms=function(t,e){return new an(t,e)};var hn=Pi.extend({options:{padding:.1},initialize:function(t){c(this,t),o(this),this._layers=this._layers||{}},onAdd:function(){this._container||(this._initContainer(),de(this._container,"leaflet-zoom-animated")),this.getPane().appendChild(this._container),this._update(),this.on("update",this._updatePaths,this)},onRemove:function(){this.off("update",this._updatePaths,this),this._destroyContainer()},getEvents:function(){var t={viewreset:this._reset,zoom:this._onZoom,moveend:this._update,zoomend:this._onZoomEnd};return this._zoomAnimated&&(t.zoomanim=this._onAnimZoom),t},_onAnimZoom:function(t){this._updateTransform(t.center,t.zoom)},_onZoom:function(){this._updateTransform(this._map.getCenter(),this._map.getZoom())},_updateTransform:function(t,e){var i=this._map.getZoomScale(e,this._zoom),n=this._map.getSize().multiplyBy(.5+this.options.padding),s=this._map.project(this._center,e),o=n.multiplyBy(-i).add(s).subtract(this._map._getNewPixelOrigin(t,e));Rt.any3d?pe(this._container,o,i):me(this._container,o)},_reset:function(){for(var t in this._update(),this._updateTransform(this._center,this._zoom),this._layers)this._layers[t]._reset()},_onZoomEnd:function(){for(var t in this._layers)this._layers[t]._project()},_updatePaths:function(){for(var t in this._layers)this._layers[t]._update()},_update:function(){var t=this.options.padding,e=this._map.getSize(),i=this._map.containerPointToLayerPoint(e.multiplyBy(-t)).round();this._bounds=new R(i,i.add(e.multiplyBy(1+2*t)).round()),this._center=this._map.getCenter(),this._zoom=this._map.getZoom()}}),ln=hn.extend({options:{tolerance:0},getEvents:function(){var t=hn.prototype.getEvents.call(this);return t.viewprereset=this._onViewPreReset,t},_onViewPreReset:function(){this._postponeUpdatePaths=!0},onAdd:function(){hn.prototype.onAdd.call(this),this._draw()},_initContainer:function(){var t=this._container=document.createElement("canvas");Ae(t,"mousemove",this._onMouseMove,this),Ae(t,"click dblclick mousedown mouseup contextmenu",this._onClick,this),Ae(t,"mouseout",this._handleMouseOut,this),t._leaflet_disable_events=!0,this._ctx=t.getContext("2d")},_destroyContainer:function(){E(this._redrawRequest),delete this._ctx,oe(this._container),Me(this._container),delete this._container},_updatePaths:function(){if(!this._postponeUpdatePaths){for(var t in this._redrawBounds=null,this._layers)this._layers[t]._update();this._redraw()}},_update:function(){if(!this._map._animatingZoom||!this._bounds){hn.prototype._update.call(this);var t=this._bounds,e=this._container,i=t.getSize(),n=Rt.retina?2:1;me(e,t.min),e.width=n*i.x,e.height=n*i.y,e.style.width=i.x+"px",e.style.height=i.y+"px",Rt.retina&&this._ctx.scale(2,2),this._ctx.translate(-t.min.x,-t.min.y),this.fire("update")}},_reset:function(){hn.prototype._reset.call(this),this._postponeUpdatePaths&&(this._postponeUpdatePaths=!1,this._updatePaths())},_initPath:function(t){this._updateDashArray(t),this._layers[o(t)]=t;var e=t._order={layer:t,prev:this._drawLast,next:null};this._drawLast&&(this._drawLast.next=e),this._drawLast=e,this._drawFirst=this._drawFirst||this._drawLast},_addPath:function(t){this._requestRedraw(t)},_removePath:function(t){var e=t._order,i=e.next,n=e.prev;i?i.prev=n:this._drawLast=n,n?n.next=i:this._drawFirst=i,delete t._order,delete this._layers[o(t)],this._requestRedraw(t)},_updatePath:function(t){this._extendRedrawBounds(t),t._project(),t._update(),this._requestRedraw(t)},_updateStyle:function(t){this._updateDashArray(t),this._requestRedraw(t)},_updateDashArray:function(t){if("string"==typeof t.options.dashArray){var e,i,n=t.options.dashArray.split(/[, ]+/),s=[];for(i=0;i')}}catch(t){}return function(t){return document.createElement("<"+t+' xmlns="urn:schemas-microsoft.com:vml" class="lvml">')}}(),cn={_initContainer:function(){this._container=se("div","leaflet-vml-container")},_update:function(){this._map._animatingZoom||(hn.prototype._update.call(this),this.fire("update"))},_initPath:function(t){var e=t._container=un("shape");de(e,"leaflet-vml-shape "+(this.options.className||"")),e.coordsize="1 1",t._path=un("path"),e.appendChild(t._path),this._updateStyle(t),this._layers[o(t)]=t},_addPath:function(t){var e=t._container;this._container.appendChild(e),t.options.interactive&&t.addInteractiveTarget(e)},_removePath:function(t){var e=t._container;oe(e),t.removeInteractiveTarget(e),delete this._layers[o(t)]},_updateStyle:function(t){var e=t._stroke,i=t._fill,n=t.options,s=t._container;s.stroked=!!n.stroke,s.filled=!!n.fill,n.stroke?(e||(e=t._stroke=un("stroke")),s.appendChild(e),e.weight=n.weight+"px",e.color=n.color,e.opacity=n.opacity,n.dashArray?e.dashStyle=p(n.dashArray)?n.dashArray.join(" "):n.dashArray.replace(/( *, *)/g," "):e.dashStyle="",e.endcap=n.lineCap.replace("butt","flat"),e.joinstyle=n.lineJoin):e&&(s.removeChild(e),t._stroke=null),n.fill?(i||(i=t._fill=un("fill")),s.appendChild(i),i.color=n.fillColor||n.color,i.opacity=n.fillOpacity):i&&(s.removeChild(i),t._fill=null)},_updateCircle:function(t){var e=t._point.round(),i=Math.round(t._radius),n=Math.round(t._radiusY||i);this._setPath(t,t._empty()?"M0 0":"AL "+e.x+","+e.y+" "+i+","+n+" 0,23592600")},_setPath:function(t,e){t._path.v=e},_bringToFront:function(t){ae(t._container)},_bringToBack:function(t){he(t._container)}},_n=Rt.vml?un:Y,fn=hn.extend({_initContainer:function(){this._container=_n("svg"),this._container.setAttribute("pointer-events","none"),this._rootGroup=_n("g"),this._container.appendChild(this._rootGroup)},_destroyContainer:function(){oe(this._container),Me(this._container),delete this._container,delete this._rootGroup,delete this._svgSize},_update:function(){if(!this._map._animatingZoom||!this._bounds){hn.prototype._update.call(this);var t=this._bounds,e=t.getSize(),i=this._container;this._svgSize&&this._svgSize.equals(e)||(this._svgSize=e,i.setAttribute("width",e.x),i.setAttribute("height",e.y)),me(i,t.min),i.setAttribute("viewBox",[t.min.x,t.min.y,e.x,e.y].join(" ")),this.fire("update")}},_initPath:function(t){var e=t._path=_n("path");t.options.className&&de(e,t.options.className),t.options.interactive&&de(e,"leaflet-interactive"),this._updateStyle(t),this._layers[o(t)]=t},_addPath:function(t){this._rootGroup||this._initContainer(),this._rootGroup.appendChild(t._path),t.addInteractiveTarget(t._path)},_removePath:function(t){oe(t._path),t.removeInteractiveTarget(t._path),delete this._layers[o(t)]},_updatePath:function(t){t._project(),t._update()},_updateStyle:function(t){var e=t._path,i=t.options;e&&(i.stroke?(e.setAttribute("stroke",i.color),e.setAttribute("stroke-opacity",i.opacity),e.setAttribute("stroke-width",i.weight),e.setAttribute("stroke-linecap",i.lineCap),e.setAttribute("stroke-linejoin",i.lineJoin),i.dashArray?e.setAttribute("stroke-dasharray",i.dashArray):e.removeAttribute("stroke-dasharray"),i.dashOffset?e.setAttribute("stroke-dashoffset",i.dashOffset):e.removeAttribute("stroke-dashoffset")):e.setAttribute("stroke","none"),i.fill?(e.setAttribute("fill",i.fillColor||i.color),e.setAttribute("fill-opacity",i.fillOpacity),e.setAttribute("fill-rule",i.fillRule||"evenodd")):e.setAttribute("fill","none"))},_updatePoly:function(t,e){this._setPath(t,$(t._parts,e))},_updateCircle:function(t){var e=t._point,i=Math.max(Math.round(t._radius),1),n="a"+i+","+(Math.max(Math.round(t._radiusY),1)||i)+" 0 1,0 ",s=t._empty()?"M0 0":"M"+(e.x-i)+","+e.y+n+2*i+",0 "+n+2*-i+",0 ";this._setPath(t,s)},_setPath:function(t,e){t._path.setAttribute("d",e)},_bringToFront:function(t){ae(t._path)},_bringToBack:function(t){he(t._path)}});function gn(t){return Rt.svg||Rt.vml?new fn(t):null}Rt.vml&&fn.include(cn),Xe.include({getRenderer:function(t){var e=t.options.renderer||this._getPaneRenderer(t.options.pane)||this.options.renderer||this._renderer;return e||(e=this._renderer=this._createRenderer()),this.hasLayer(e)||this.addLayer(e),e},_getPaneRenderer:function(t){if("overlayPane"===t||void 0===t)return!1;var e=this._paneRenderers[t];return void 0===e&&(e=this._createRenderer({pane:t}),this._paneRenderers[t]=e),e},_createRenderer:function(t){return this.options.preferCanvas&&dn(t)||gn(t)}});var pn=Bi.extend({initialize:function(t,e){Bi.prototype.initialize.call(this,this._boundsToLatLngs(t),e)},setBounds:function(t){return this.setLatLngs(this._boundsToLatLngs(t))},_boundsToLatLngs:function(t){return[(t=B(t)).getSouthWest(),t.getNorthWest(),t.getNorthEast(),t.getSouthEast()]}});fn.create=_n,fn.pointsToPath=$,zi.geometryToLayer=Ui,zi.coordsToLatLng=ji,zi.coordsToLatLngs=Wi,zi.latLngToCoords=Gi,zi.latLngsToCoords=Zi,zi.getFeature=Hi,zi.asFeature=Xi,Xe.mergeOptions({boxZoom:!0});var mn=Je.extend({initialize:function(t){this._map=t,this._container=t._container,this._pane=t._panes.overlayPane,this._resetStateTimeout=0,t.on("unload",this._destroy,this)},addHooks:function(){Ae(this._container,"mousedown",this._onMouseDown,this)},removeHooks:function(){Me(this._container,"mousedown",this._onMouseDown,this)},moved:function(){return this._moved},_destroy:function(){oe(this._pane),delete this._pane},_resetState:function(){this._resetStateTimeout=0,this._moved=!1},_clearDeferredResetState:function(){0!==this._resetStateTimeout&&(clearTimeout(this._resetStateTimeout),this._resetStateTimeout=0)},_onMouseDown:function(t){if(!t.shiftKey||1!==t.which&&1!==t.button)return!1;this._clearDeferredResetState(),this._resetState(),Vt(),xe(),this._startPoint=this._map.mouseEventToContainerPoint(t),Ae(document,{contextmenu:ze,mousemove:this._onMouseMove,mouseup:this._onMouseUp,keydown:this._onKeyDown},this)},_onMouseMove:function(t){this._moved||(this._moved=!0,this._box=se("div","leaflet-zoom-box",this._container),de(this._container,"leaflet-crosshair"),this._map.fire("boxzoomstart")),this._point=this._map.mouseEventToContainerPoint(t);var e=new R(this._point,this._startPoint),i=e.getSize();me(this._box,e.min),this._box.style.width=i.x+"px",this._box.style.height=i.y+"px"},_finish:function(){this._moved&&(oe(this._box),ue(this._container,"leaflet-crosshair")),Yt(),be(),Me(document,{contextmenu:ze,mousemove:this._onMouseMove,mouseup:this._onMouseUp,keydown:this._onKeyDown},this)},_onMouseUp:function(t){if((1===t.which||1===t.button)&&(this._finish(),this._moved)){this._clearDeferredResetState(),this._resetStateTimeout=setTimeout(n(this._resetState,this),0);var e=new k(this._map.containerPointToLatLng(this._startPoint),this._map.containerPointToLatLng(this._point));this._map.fitBounds(e).fire("boxzoomend",{boxZoomBounds:e})}},_onKeyDown:function(t){27===t.keyCode&&(this._finish(),this._clearDeferredResetState(),this._resetState())}});Xe.addInitHook("addHandler","boxZoom",mn),Xe.mergeOptions({doubleClickZoom:!0});var vn=Je.extend({addHooks:function(){this._map.on("dblclick",this._onDoubleClick,this)},removeHooks:function(){this._map.off("dblclick",this._onDoubleClick,this)},_onDoubleClick:function(t){var e=this._map,i=e.getZoom(),n=e.options.zoomDelta,s=t.originalEvent.shiftKey?i-n:i+n;"center"===e.options.doubleClickZoom?e.setZoom(s):e.setZoomAround(t.containerPoint,s)}});Xe.addInitHook("addHandler","doubleClickZoom",vn),Xe.mergeOptions({dragging:!0,inertia:!0,inertiaDeceleration:3400,inertiaMaxSpeed:1/0,easeLinearity:.2,worldCopyJump:!1,maxBoundsViscosity:0});var yn=Je.extend({addHooks:function(){if(!this._draggable){var t=this._map;this._draggable=new ii(t._mapPane,t._container),this._draggable.on({dragstart:this._onDragStart,drag:this._onDrag,dragend:this._onDragEnd},this),this._draggable.on("predrag",this._onPreDragLimit,this),t.options.worldCopyJump&&(this._draggable.on("predrag",this._onPreDragWrap,this),t.on("zoomend",this._onZoomEnd,this),t.whenReady(this._onZoomEnd,this))}de(this._map._container,"leaflet-grab leaflet-touch-drag"),this._draggable.enable(),this._positions=[],this._times=[]},removeHooks:function(){ue(this._map._container,"leaflet-grab"),ue(this._map._container,"leaflet-touch-drag"),this._draggable.disable()},moved:function(){return this._draggable&&this._draggable._moved},moving:function(){return this._draggable&&this._draggable._moving},_onDragStart:function(){var t=this._map;if(t._stop(),this._map.options.maxBounds&&this._map.options.maxBoundsViscosity){var e=B(this._map.options.maxBounds);this._offsetLimit=O(this._map.latLngToContainerPoint(e.getNorthWest()).multiplyBy(-1),this._map.latLngToContainerPoint(e.getSouthEast()).multiplyBy(-1).add(this._map.getSize())),this._viscosity=Math.min(1,Math.max(0,this._map.options.maxBoundsViscosity))}else this._offsetLimit=null;t.fire("movestart").fire("dragstart"),t.options.inertia&&(this._positions=[],this._times=[])},_onDrag:function(t){if(this._map.options.inertia){var e=this._lastTime=+new Date,i=this._lastPos=this._draggable._absPos||this._draggable._newPos;this._positions.push(i),this._times.push(e),this._prunePositions(e)}this._map.fire("move",t).fire("drag",t)},_prunePositions:function(t){for(;this._positions.length>1&&t-this._times[0]>50;)this._positions.shift(),this._times.shift()},_onZoomEnd:function(){var t=this._map.getSize().divideBy(2),e=this._map.latLngToLayerPoint([0,0]);this._initialWorldOffset=e.subtract(t).x,this._worldWidth=this._map.getPixelWorldBounds().getSize().x},_viscousLimit:function(t,e){return t-(t-e)*this._viscosity},_onPreDragLimit:function(){if(this._viscosity&&this._offsetLimit){var t=this._draggable._newPos.subtract(this._draggable._startPos),e=this._offsetLimit;t.xe.max.x&&(t.x=this._viscousLimit(t.x,e.max.x)),t.y>e.max.y&&(t.y=this._viscousLimit(t.y,e.max.y)),this._draggable._newPos=this._draggable._startPos.add(t)}},_onPreDragWrap:function(){var t=this._worldWidth,e=Math.round(t/2),i=this._initialWorldOffset,n=this._draggable._newPos.x,s=(n-e+i)%t+e-i,o=(n+e+i)%t-e-i,r=Math.abs(s+i)0?o:-o))-e;this._delta=0,this._startTime=null,r&&("center"===t.options.scrollWheelZoom?t.setZoom(e+r):t.setZoomAround(this._lastMousePos,e+r))}});Xe.addInitHook("addHandler","scrollWheelZoom",bn);Xe.mergeOptions({tapHold:Rt.touchNative&&Rt.safari&&Rt.mobile,tapTolerance:15});var Sn=Je.extend({addHooks:function(){Ae(this._map._container,"touchstart",this._onDown,this)},removeHooks:function(){Me(this._map._container,"touchstart",this._onDown,this)},_onDown:function(t){if(clearTimeout(this._holdTimeout),1===t.touches.length){var e=t.touches[0];this._startPos=this._newPos=new N(e.clientX,e.clientY),this._holdTimeout=setTimeout(n(function(){this._cancel(),this._isTapValid()&&(Ae(document,"touchend",Be),Ae(document,"touchend touchcancel",this._cancelClickPrevent),this._simulateEvent("contextmenu",e))},this),600),Ae(document,"touchend touchcancel contextmenu",this._cancel,this),Ae(document,"touchmove",this._onMove,this)}},_cancelClickPrevent:function t(){Me(document,"touchend",Be),Me(document,"touchend touchcancel",t)},_cancel:function(){clearTimeout(this._holdTimeout),Me(document,"touchend touchcancel contextmenu",this._cancel,this),Me(document,"touchmove",this._onMove,this)},_onMove:function(t){var e=t.touches[0];this._newPos=new N(e.clientX,e.clientY)},_isTapValid:function(){return this._newPos.distanceTo(this._startPos)<=this._map.options.tapTolerance},_simulateEvent:function(t,e){var i=new MouseEvent(t,{bubbles:!0,cancelable:!0,view:window,screenX:e.screenX,screenY:e.screenY,clientX:e.clientX,clientY:e.clientY});i._simulated=!0,e.target.dispatchEvent(i)}});Xe.addInitHook("addHandler","tapHold",Sn),Xe.mergeOptions({touchZoom:Rt.touch,bounceAtZoomLimits:!0});var wn=Je.extend({addHooks:function(){de(this._map._container,"leaflet-touch-zoom"),Ae(this._map._container,"touchstart",this._onTouchStart,this)},removeHooks:function(){ue(this._map._container,"leaflet-touch-zoom"),Me(this._map._container,"touchstart",this._onTouchStart,this)},_onTouchStart:function(t){var e=this._map;if(t.touches&&2===t.touches.length&&!e._animatingZoom&&!this._zooming){var i=e.mouseEventToContainerPoint(t.touches[0]),n=e.mouseEventToContainerPoint(t.touches[1]);this._centerPoint=e.getSize()._divideBy(2),this._startLatLng=e.containerPointToLatLng(this._centerPoint),"center"!==e.options.touchZoom&&(this._pinchStartLatLng=e.containerPointToLatLng(i.add(n)._divideBy(2))),this._startDist=i.distanceTo(n),this._startZoom=e.getZoom(),this._moved=!1,this._zooming=!0,e._stop(),Ae(document,"touchmove",this._onTouchMove,this),Ae(document,"touchend touchcancel",this._onTouchEnd,this),Be(t)}},_onTouchMove:function(t){if(t.touches&&2===t.touches.length&&this._zooming){var e=this._map,i=e.mouseEventToContainerPoint(t.touches[0]),s=e.mouseEventToContainerPoint(t.touches[1]),o=i.distanceTo(s)/this._startDist;if(this._zoom=e.getScaleZoom(o,this._startZoom),!e.options.bounceAtZoomLimits&&(this._zoome.getMaxZoom()&&o>1)&&(this._zoom=e._limitZoom(this._zoom)),"center"===e.options.touchZoom){if(this._center=this._startLatLng,1===o)return}else{var r=i._add(s)._divideBy(2)._subtract(this._centerPoint);if(1===o&&0===r.x&&0===r.y)return;this._center=e.unproject(e.project(this._pinchStartLatLng,this._zoom).subtract(r),this._zoom)}this._moved||(e._moveStart(!0,!1),this._moved=!0),E(this._animRequest);var a=n(e._move,e,this._center,this._zoom,{pinch:!0,round:!1},void 0);this._animRequest=T(a,this,!0),Be(t)}},_onTouchEnd:function(){this._moved&&this._zooming?(this._zooming=!1,E(this._animRequest),Me(document,"touchmove",this._onTouchMove,this),Me(document,"touchend touchcancel",this._onTouchEnd,this),this._map.options.zoomAnimation?this._map._animateZoom(this._center,this._map._limitZoom(this._zoom),!0,this._map.options.zoomSnap):this._map._resetView(this._center,this._map._limitZoom(this._zoom))):this._zooming=!1}});Xe.addInitHook("addHandler","touchZoom",wn),Xe.BoxZoom=mn,Xe.DoubleClickZoom=vn,Xe.Drag=yn,Xe.Keyboard=xn,Xe.ScrollWheelZoom=bn,Xe.TapHold=Sn,Xe.TouchZoom=wn,t.Bounds=R,t.Browser=Rt,t.CRS=j,t.Canvas=ln,t.Circle=Oi,t.CircleMarker=Ri,t.Class=A,t.Control=qe,t.DivIcon=nn,t.DivOverlay=Ji,t.DomEvent=Ze,t.DomUtil=Pe,t.Draggable=ii,t.Evented=M,t.FeatureGroup=Ci,t.GeoJSON=zi,t.GridLayer=sn,t.Handler=Je,t.Icon=Mi,t.ImageOverlay=$i,t.LatLng=z,t.LatLngBounds=k,t.Layer=Pi,t.LayerGroup=Ai,t.LineUtil=yi,t.Map=Xe,t.Marker=Ii,t.Mixin=ti,t.Path=Li,t.Point=N,t.PolyUtil=ai,t.Polygon=Bi,t.Polyline=ki,t.Popup=tn,t.PosAnimation=He,t.Projection=Si,t.Rectangle=pn,t.Renderer=hn,t.SVG=fn,t.SVGOverlay=Qi,t.TileLayer=on,t.Tooltip=en,t.Transformation=H,t.Util=P,t.VideoOverlay=Ki,t.bind=n,t.bounds=O,t.canvas=dn,t.circle=function(t,e,i){return new Oi(t,e,i)},t.circleMarker=function(t,e){return new Ri(t,e)},t.control=Ve,t.divIcon=function(t){return new nn(t)},t.extend=e,t.featureGroup=function(t,e){return new Ci(t,e)},t.geoJSON=Vi,t.geoJson=Yi,t.gridLayer=function(t){return new sn(t)},t.icon=function(t){return new Mi(t)},t.imageOverlay=function(t,e,i){return new $i(t,e,i)},t.latLng=U,t.latLngBounds=B,t.layerGroup=function(t,e){return new Ai(t,e)},t.map=function(t,e){return new Xe(t,e)},t.marker=function(t,e){return new Ii(t,e)},t.point=I,t.polygon=function(t,e){return new Bi(t,e)},t.polyline=function(t,e){return new ki(t,e)},t.popup=function(t,e){return new tn(t,e)},t.rectangle=function(t,e){return new pn(t,e)},t.setOptions=c,t.stamp=o,t.svg=gn,t.svgOverlay=function(t,e,i){return new Qi(t,e,i)},t.tileLayer=rn,t.tooltip=function(t,e){return new en(t,e)},t.transformation=X,t.version="1.9.4",t.videoOverlay=function(t,e,i){return new Ki(t,e,i)};var Tn=window.L;t.noConflict=function(){return window.L=Tn,this},window.L=t}(e)}};const e={};function i(n){const s=e[n];if(void 0!==s)return s.exports;const o=e[n]={exports:{}};return t[n].call(o.exports,o,o.exports,i),o.exports}i.d=(t,e)=>{if(Array.isArray(e))for(var n=0;nObject.prototype.hasOwnProperty.call(t,e),i.r=t=>{Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};let n={};return(()=>{"use strict";i.r(n),i.d(n,{Color:()=>F,EdgeLineStyleType:()=>N,EdgeType:()=>D,GraphObjectState:()=>r,NodeShapeType:()=>w,OrbError:()=>o,OrbEventType:()=>e,OrbMapView:()=>cr,OrbView:()=>dr,RectangleArea:()=>V,RendererType:()=>zs,getDefaultGraphStyle:()=>X,graphToSVG:()=>Jo,isEdge:()=>L,isNode:()=>E});class t{constructor(){this._listeners=new Map}once(t,e){const i={callable:e,isOnce:!0},n=this._listeners.get(t);return n?n.push(i):this._listeners.set(t,[i]),this}on(t,e){const i={callable:e},n=this._listeners.get(t);return n?n.push(i):this._listeners.set(t,[i]),this}off(t,e){const i=this._listeners.get(t);if(i){const n=i.filter(t=>t.callable!==e);this._listeners.set(t,n)}return this}emit(t,e){const i=this._listeners.get(t);if(!i||0===i.length)return!1;let n=!1;for(let t=0;t!t.isOnce);this._listeners.set(t,e)}return!0}eventNames(){return[...this._listeners.keys()]}listenerCount(t){const e=this._listeners.get(t);return e?e.length:0}listeners(t){const e=this._listeners.get(t);return e?e.map(t=>t.callable):[]}addListener(t,e){return this.on(t,e)}removeListener(t,e){return this.off(t,e)}removeAllListeners(t){return t?this._listeners.delete(t):this._listeners.clear(),this}}var e;!function(t){t.RENDER_START="render-start",t.RENDER_END="render-end",t.SIMULATION_START="simulation-start",t.SIMULATION_STEP="simulation-step",t.SIMULATION_END="simulation-end",t.NODE_CLICK="node-click",t.NODE_HOVER="node-hover",t.EDGE_CLICK="edge-click",t.EDGE_HOVER="edge-hover",t.MOUSE_CLICK="mouse-click",t.MOUSE_MOVE="mouse-move",t.TRANSFORM="transform",t.NODE_DRAG_START="node-drag-start",t.NODE_DRAG="node-drag",t.NODE_DRAG_END="node-drag-end",t.BACKGROUND_DRAG_START="background-drag-start",t.BACKGROUND_DRAG="background-drag",t.BACKGROUND_DRAG_END="background-drag-end",t.NODE_RIGHT_CLICK="node-right-click",t.EDGE_RIGHT_CLICK="edge-right-click",t.MOUSE_RIGHT_CLICK="mouse-right-click",t.NODE_DOUBLE_CLICK="node-double-click",t.EDGE_DOUBLE_CLICK="edge-double-click",t.MOUSE_DOUBLE_CLICK="mouse-double-click"}(e||(e={}));class s extends t{}class o extends Error{constructor(t){super(t),this.message=t,Object.setPrototypeOf(this,new.target.prototype),this.name=this.constructor.name}}const r={NONE:0,SELECTED:1,HOVERED:2},a=(t,e)=>{const i=t.x+t.width,n=t.y+t.height;return e.x>=t.x&&e.x<=i&&e.y>=t.y&&e.y<=n};class h{constructor(){this._imageByUrl={}}static getInstance(){return h._instance||(h._instance=new h),h._instance}getImage(t){return this._imageByUrl[t]}loadImage(t,e){const i=this.getImage(t);if(i)return i;const n=new Image;return this._imageByUrl[t]=n,n.onload=()=>{l(n),null==e||e()},n.onerror=()=>{null==e||e(new Error(`Image ${t} failed to load.`))},n.src=t,n}loadImages(t,e){const i=[],n=new Set(t),s=t=>{n.delete(t),0===n.size&&(null==e||e())};for(let e=0;e{l(a),s(o)},a.onerror=()=>{s(o)},a.src=o,i.push(a)}return i}}const l=t=>t&&0===t.width?(document.body.appendChild(t),t.width=t.offsetWidth,t.height=t.offsetHeight,document.body.removeChild(t),t):t;class d{constructor(){this.listeners=[]}addListener(t){this.listeners.push(t)}getListeners(){return[...this.listeners]}removeListener(t){const e=this.listeners.indexOf(t);-1!==e&&this.listeners.splice(e,1)}notifyListeners(t){for(let e=0;e"number"==typeof t,c=t=>"boolean"==typeof t,_=t=>t instanceof Date,f=t=>Array.isArray(t),g=t=>null!==t&&"object"==typeof t&&"Object"===t.constructor.name,p=t=>"function"==typeof t,m=t=>_(t)?y(t):f(t)?x(t):g(t)?b(t):t,v=(t,e)=>{const i=_(t),n=_(e);if(i&&!n||!i&&n)return!1;if(i&&n)return t.getTime()===e.getTime();const s=f(t),o=f(e);if(s&&!o||!s&&o)return!1;if(s&&o)return t.length===e.length&&t.every((t,i)=>v(t,e[i]));const r=g(t),a=g(e);if(r&&!a||!r&&a)return!1;if(r&&a){const i=Object.keys(t),n=Object.keys(e);return!!v(i,n)&&i.every(i=>v(t[i],e[i]))}return t===e},y=t=>new Date(t),x=t=>t.map(t=>m(t)),b=t=>{const e={};return Object.keys(t).forEach(i=>{e[i]=m(t[i])}),e},S=(t,e)=>{const i=Object.keys(e);for(let n=0;nt instanceof P;class P extends d{constructor(t,e){super(),this._style={},this._state=r.NONE,this._inEdgesById={},this._outEdgesById={},this.id=t.data.id,this._data=t.data,this._position={id:this.id},this._onLoadedImage=null==e?void 0:e.onLoadedImage,this._onStateChange=null==e?void 0:e.onStateChange,e&&e.listeners&&(this.listeners=e.listeners)}getId(){return this.id}getData(){return this._data}getPosition(){return this._position}getStyle(){return this._style}getState(){return this._state}clearPosition(){this._position.x=void 0,this._position.y=void 0,this.notifyListeners()}getCenter(){return void 0===this._position.x||void 0===this._position.y?{x:0,y:0}:{x:this._position.x,y:this._position.y}}getRadius(){var t;return null!==(t=this._style.size)&&void 0!==t?t:0}getBorderedRadius(){return this.getRadius()+this.getBorderWidth()/2}getBoundingBox(){const t=this.getCenter(),e=this.getBorderedRadius();return{x:t.x-e,y:t.y-e,width:2*e,height:2*e}}getInEdges(){return Object.values(this._inEdgesById)}getOutEdges(){return Object.values(this._outEdgesById)}getEdges(){const t={},e=this.getOutEdges();for(let i=0;i0}addEdge(t){t.start===this.id&&(this._outEdgesById[t.getId()]=t),t.end===this.id&&(this._inEdgesById[t.getId()]=t)}removeEdge(t){delete this._outEdgesById[t.getId()],delete this._inEdgesById[t.getId()]}isSelected(){return this._state===r.SELECTED}isHovered(){return this._state===r.HOVERED}clearState(){this.setState(r.NONE,{isNotifySkipped:!0})}getDistanceToBorder(){return this.getBorderedRadius()}includesPoint(t){const e=this._isPointInBoundingBox(t);if(!e)return!1;if(this._style.shape===w.SQUARE)return e;const i=this.getCenter(),n=this.getBorderedRadius(),s=t.x-i.x,o=t.y-i.y;return Math.sqrt(s*s+o*o)<=n}hasShadow(){var t,e,i;return(null!==(t=this._style.shadowSize)&&void 0!==t?t:0)>0||(null!==(e=this._style.shadowOffsetX)&&void 0!==e?e:0)>0||(null!==(i=this._style.shadowOffsetY)&&void 0!==i?i:0)>0}hasBorder(){var t,e;const i=(null!==(t=this._style.borderWidth)&&void 0!==t?t:0)>0,n=(null!==(e=this._style.borderWidthSelected)&&void 0!==e?e:0)>0;return i||this.isSelected()&&n}getLabel(){return this._style.label}getColor(){let t;return this._style.color&&(t=this._style.color),this.isHovered()&&this._style.colorHover&&(t=this._style.colorHover),this.isSelected()&&this._style.colorSelected&&(t=this._style.colorSelected),t}getBorderWidth(){let t=0;return this._style.borderWidth&&this._style.borderWidth>0&&(t=this._style.borderWidth),this.isSelected()&&this._style.borderWidthSelected&&this._style.borderWidthSelected>0&&(t=this._style.borderWidthSelected),t}getBorderColor(){if(!this.hasBorder())return;let t;return this._style.borderColor&&(t=this._style.borderColor),this.isHovered()&&this._style.borderColorHover&&(t=this._style.borderColorHover),this.isSelected()&&this._style.borderColorSelected&&(t=this._style.borderColorSelected.toString()),t}getBackgroundImage(){var t;if((null!==(t=this._style.size)&&void 0!==t?t:0)<=0)return;let e;if(this._style.imageUrl&&(e=this._style.imageUrl),this.isSelected()&&this._style.imageUrlSelected&&(e=this._style.imageUrlSelected),!e)return;return h.getInstance().getImage(e)||h.getInstance().loadImage(e,t=>{var e;t||null===(e=this._onLoadedImage)||void 0===e||e.call(this)})}setData(t){p(t)?this._data=t(this):this._data=t,this.notifyListeners()}patchData(t){let e;e=p(t)?t(this):t,S(this._data,e),this.notifyListeners()}setPosition(t,e){let i;i=p(t)?t(this):t,"x"in i&&"y"in i&&(this._position.x=i.x,this._position.y=i.y,"id"in i&&(this._position.id=i.id)),(null==e?void 0:e.isNotifySkipped)||this.notifyListeners(Object.assign({id:this.id},i))}setStyle(t,e){p(t)?this._style=t(this):this._style=t,(null==e?void 0:e.isNotifySkipped)||this.notifyListeners()}patchStyle(t,e){let i;i=p(t)?t(this):t,S(this._style,i),(null==e?void 0:e.isNotifySkipped)||this.notifyListeners()}setState(t,e){var i;const n=this._state;let s;if(s=p(t)?t(this):t,u(s))this._state=s;else if(g(s)){const t=s.options;if(this._state=this._handleState(s.state,t),t)return void this.notifyListeners({id:this.id,type:"node",options:t})}(null==e?void 0:e.isNotifySkipped)?this._state!==n&&(null===(i=this._onStateChange)||void 0===i||i.call(this)):this.notifyListeners()}_isPointInBoundingBox(t){return a(this.getBoundingBox(),t)}_handleState(t,e){return(null==e?void 0:e.isToggle)&&this._state===t?r.NONE:t}}const A=(t,e,i)=>{const n=e.x-t.x,s=e.y-t.y;let o=((i.x-t.x)*n+(i.y-t.y)*s)/(n*n+s*s);o>1&&(o=1),o<0&&(o=0);const r=t.x+o*n,a=t.y+o*s,h=r-i.x,l=a-i.y;return Math.sqrt(h*h+l*l)},C=[5,5],M=[1,1];var N,D;!function(t){t.SOLID="solid",t.DASHED="dashed",t.DOTTED="dotted",t.CUSTOM="custom"}(N||(N={})),function(t){t.STRAIGHT="straight",t.LOOPBACK="loopback",t.CURVED="curved"}(D||(D={}));class I{static create(t,e){switch(O(t)){case D.STRAIGHT:return new k(t,e);case D.LOOPBACK:return new z(t,e);case D.CURVED:return new B(t,e);default:return new k(t,e)}}static copy(t,e){const i=I.create({data:t.getData(),offset:void 0!==(null==e?void 0:e.offset)?e.offset:t.offset,startNode:t.startNode,endNode:t.endNode},{listeners:[],onStateChange:t.getOnStateChange()});i.setState(t.getState()),i.setStyle(t.getStyle());const n=t.getListeners();for(let t=0;tt instanceof k||t instanceof B||t instanceof z;class R extends d{constructor(t,e){var i;super(),this._style={},this._state=r.NONE,this._type=D.STRAIGHT,this.id=t.data.id,this._data=t.data,this.offset=null!==(i=t.offset)&&void 0!==i?i:0,this.startNode=t.startNode,this.endNode=t.endNode,this._type=O(t),this._position={id:this.id,source:this.startNode.getId(),target:this.endNode.getId()},this.startNode.addEdge(this),this.endNode.addEdge(this),this._onStateChange=null==e?void 0:e.onStateChange,e&&e.listeners&&(this.listeners=e.listeners)}getId(){return this.id}getData(){return this._data}getPosition(){return this._position}getStyle(){return this._style}getState(){return this._state}getOnStateChange(){return this._onStateChange}get type(){return this._type}get start(){return this._data.start}get end(){return this._data.end}hasStyle(){return this._style&&Object.keys(this._style).length>0}isSelected(){return this._state===r.SELECTED}isHovered(){return this._state===r.HOVERED}clearState(){var t;this._state!==r.NONE&&(this._state=r.NONE,null===(t=this._onStateChange)||void 0===t||t.call(this))}isLoopback(){return this._type===D.LOOPBACK}isStraight(){return this._type===D.STRAIGHT}isCurved(){return this._type===D.CURVED}getCenter(){var t,e;const i=null===(t=this.startNode)||void 0===t?void 0:t.getCenter(),n=null===(e=this.endNode)||void 0===e?void 0:e.getCenter();return i&&n?{x:(i.x+n.x)/2,y:(i.y+n.y)/2}:{x:0,y:0}}getDistance(t){const e=this.startNode.getCenter(),i=this.endNode.getCenter();return e&&i?A(e,i,t):0}getLabel(){return this._style.label}hasShadow(){var t,e,i;return(null!==(t=this._style.shadowSize)&&void 0!==t?t:0)>0||(null!==(e=this._style.shadowOffsetX)&&void 0!==e?e:0)>0||(null!==(i=this._style.shadowOffsetY)&&void 0!==i?i:0)>0}getWidth(){let t=0;return void 0!==this._style.width&&(t=this._style.width),this.isHovered()&&void 0!==this._style.widthHover&&(t=this._style.widthHover),this.isSelected()&&void 0!==this._style.widthSelected&&(t=this._style.widthSelected),t}getColor(){let t;return this._style.color&&(t=this._style.color),this.isHovered()&&this._style.colorHover&&(t=this._style.colorHover),this.isSelected()&&this._style.colorSelected&&(t=this._style.colorSelected),t}getLineDashPattern(){const t=this._style.lineStyle;if(void 0===t||t.type===N.SOLID)return null;switch(t.type){case N.DASHED:return C;case N.DOTTED:return M;case N.CUSTOM:return e=t.pattern,f(e)&&e.every(t=>u(t))?t.pattern:null;default:return null}var e}setData(t){p(t)?this._data=t(this):this._data=t,this.notifyListeners()}patchData(t){let e;e=p(t)?t(this):t,S(this._data,e),this.notifyListeners()}setStyle(t,e){p(t)?this._style=t(this):this._style=t,(null==e?void 0:e.isNotifySkipped)||this.notifyListeners()}patchStyle(t,e){let i;i=p(t)?t(this):t,S(this._style,i),(null==e?void 0:e.isNotifySkipped)||this.notifyListeners()}setState(t,e){var i;const n=this._state;let s;if(s=p(t)?t(this):t,u(s))this._state=s;else if(g(s)){const t=s.options;if(this._state=this._handleState(s.state,t),t)return void this.notifyListeners({id:this.id,type:"edge",options:t})}(null==e?void 0:e.isNotifySkipped)?this._state!==n&&(null===(i=this._onStateChange)||void 0===i||i.call(this)):this.notifyListeners()}_handleState(t,e){return(null==e?void 0:e.isToggle)&&this._state===t?r.NONE:t}}const O=t=>{var e;return t.startNode.getId()===t.endNode.getId()?D.LOOPBACK:0===(null!==(e=t.offset)&&void 0!==e?e:0)?D.STRAIGHT:D.CURVED};class k extends R{getCenter(){var t,e;const i=null===(t=this.startNode)||void 0===t?void 0:t.getCenter(),n=null===(e=this.endNode)||void 0===e?void 0:e.getCenter();return i&&n?{x:(i.x+n.x)/2,y:(i.y+n.y)/2}:{x:0,y:0}}getDistance(t){var e,i;const n=null===(e=this.startNode)||void 0===e?void 0:e.getCenter(),s=null===(i=this.endNode)||void 0===i?void 0:i.getCenter();return n&&s?A(n,s,t):0}}class B extends R{getCenter(){return this.getCurvedControlPoint(2)}getDistance(t){var e,i;const n=null===(e=this.startNode)||void 0===e?void 0:e.getCenter(),s=null===(i=this.endNode)||void 0===i?void 0:i.getCenter();if(!n||!s)return 0;const o=this.getCurvedControlPoint();let r,a,h,l,d,u=1e9,c=n.x,_=n.y;for(a=1;a<10;a++)h=.1*a,l=Math.pow(1-h,2)*n.x+2*h*(1-h)*o.x+Math.pow(h,2)*s.x,d=Math.pow(1-h,2)*n.y+2*h*(1-h)*o.y+Math.pow(h,2)*s.y,a>0&&(r=A({x:c,y:_},{x:l,y:d},t),u=r({r:parseInt(t.substring(1,3),16),g:parseInt(t.substring(3,5),16),b:parseInt(t.substring(5,7),16)}),W=t=>"#"+((1<<24)+(t.r<<16)+(t.g<<8)+t.b).toString(16).slice(1),G=["label","name"],Z={size:5,color:new F("#1d87c9")},H={color:new F("#ababab"),width:.3},X=()=>({getNodeStyle:t=>Object.assign(Object.assign({},Z),{label:q(t)}),getEdgeStyle:t=>Object.assign(Object.assign({},H),{label:q(t)})}),q=t=>{const e=t.getData();for(let t=0;t({x:Math.min(t.x,e.x),y:Math.min(t.y,e.y),width:Math.abs(t.x-e.x),height:Math.abs(t.y-e.y)}))(t,e))}contains(t){return a(this._rectangle,t)}getBoundingBox(){return this._rectangle}}var Y={value:()=>{}};function $(){for(var t,e=0,i=arguments.length,n={};e=0&&(e=t.slice(i+1),t=t.slice(0,i)),t&&!n.hasOwnProperty(t))throw new Error("unknown type: "+t);return{type:t,name:e}})),r=-1,a=o.length;if(!(arguments.length<2)){if(null!=e&&"function"!=typeof e)throw new Error("invalid callback: "+e);for(;++r0)for(var i,n,s=new Array(i),o=0;oe?1:t>=e?0:NaN}ct.prototype={constructor:ct,appendChild:function(t){return this._parent.insertBefore(t,this._next)},insertBefore:function(t,e){return this._parent.insertBefore(t,e)},querySelector:function(t){return this._parent.querySelector(t)},querySelectorAll:function(t){return this._parent.querySelectorAll(t)}};var vt="http://www.w3.org/1999/xhtml";const yt={svg:"http://www.w3.org/2000/svg",xhtml:vt,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function xt(t){var e=t+="",i=e.indexOf(":");return i>=0&&"xmlns"!==(e=t.slice(0,i))&&(t=t.slice(i+1)),yt.hasOwnProperty(e)?{space:yt[e],local:t}:t}function bt(t){return function(){this.removeAttribute(t)}}function St(t){return function(){this.removeAttributeNS(t.space,t.local)}}function wt(t,e){return function(){this.setAttribute(t,e)}}function Tt(t,e){return function(){this.setAttributeNS(t.space,t.local,e)}}function Et(t,e){return function(){var i=e.apply(this,arguments);null==i?this.removeAttribute(t):this.setAttribute(t,i)}}function Pt(t,e){return function(){var i=e.apply(this,arguments);null==i?this.removeAttributeNS(t.space,t.local):this.setAttributeNS(t.space,t.local,i)}}function At(t){return t.ownerDocument&&t.ownerDocument.defaultView||t.document&&t||t.defaultView}function Ct(t){return function(){this.style.removeProperty(t)}}function Mt(t,e,i){return function(){this.style.setProperty(t,e,i)}}function Nt(t,e,i){return function(){var n=e.apply(this,arguments);null==n?this.style.removeProperty(t):this.style.setProperty(t,n,i)}}function Dt(t,e){return t.style.getPropertyValue(e)||At(t).getComputedStyle(t,null).getPropertyValue(e)}function It(t){return function(){delete this[t]}}function Lt(t,e){return function(){this[t]=e}}function Rt(t,e){return function(){var i=e.apply(this,arguments);null==i?delete this[t]:this[t]=i}}function Ot(t){return t.trim().split(/^|\s+/)}function kt(t){return t.classList||new Bt(t)}function Bt(t){this._node=t,this._names=Ot(t.getAttribute("class")||"")}function zt(t,e){for(var i=kt(t),n=-1,s=e.length;++n=0&&(this._names.splice(e,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(t){return this._names.indexOf(t)>=0}};var le=[null];function de(t,e){this._groups=t,this._parents=e}function ue(){return new de([[document.documentElement]],le)}de.prototype=ue.prototype={constructor:de,select:function(t){"function"!=typeof t&&(t=it(t));for(var e=this._groups,i=e.length,n=new Array(i),s=0;s=x&&(x=y+1);!(v=p[x])&&++x=0;)(n=s[o])&&(r&&4^n.compareDocumentPosition(r)&&r.parentNode.insertBefore(n,r),r=n);return this},sort:function(t){function e(e,i){return e&&i?t(e.__data__,i.__data__):!e-!i}t||(t=mt);for(var i=this._groups,n=i.length,s=new Array(n),o=0;o1?this.each((null==e?Ct:"function"==typeof e?Nt:Mt)(t,e,i??"")):Dt(this.node(),t)},property:function(t,e){return arguments.length>1?this.each((null==e?It:"function"==typeof e?Rt:Lt)(t,e)):this.node()[t]},classed:function(t,e){var i=Ot(t+"");if(arguments.length<2){for(var n=kt(this.node()),s=-1,o=i.length;++s=0&&(e=t.slice(i+1),t=t.slice(0,i)),{type:t,name:e}})}(t+""),r=o.length;if(!(arguments.length<2)){for(a=e?oe:se,n=0;n()=>t;function Se(t,{sourceEvent:e,subject:i,target:n,identifier:s,active:o,x:r,y:a,dx:h,dy:l,dispatch:d}){Object.defineProperties(this,{type:{value:t,enumerable:!0,configurable:!0},sourceEvent:{value:e,enumerable:!0,configurable:!0},subject:{value:i,enumerable:!0,configurable:!0},target:{value:n,enumerable:!0,configurable:!0},identifier:{value:s,enumerable:!0,configurable:!0},active:{value:o,enumerable:!0,configurable:!0},x:{value:r,enumerable:!0,configurable:!0},y:{value:a,enumerable:!0,configurable:!0},dx:{value:h,enumerable:!0,configurable:!0},dy:{value:l,enumerable:!0,configurable:!0},_:{value:d}})}function we(t){return!t.ctrlKey&&!t.button}function Te(){return this.parentNode}function Ee(t,e){return e??{x:t.x,y:t.y}}function Pe(){return navigator.maxTouchPoints||"ontouchstart"in this}Se.prototype.on=function(){var t=this._.on.apply(this._,arguments);return t===this._?this:t};const Ae=t=>+t;function Ce(t){return((t=Math.exp(t))+1/t)/2}const Me=function t(e,i,n){function s(t,s){var o,r,a=t[0],h=t[1],l=t[2],d=s[0],u=s[1],c=s[2],_=d-a,f=u-h,g=_*_+f*f;if(g<1e-12)r=Math.log(c/l)/e,o=function(t){return[a+t*_,h+t*f,l*Math.exp(e*t*r)]};else{var p=Math.sqrt(g),m=(c*c-l*l+n*g)/(2*l*i*p),v=(c*c-l*l-n*g)/(2*c*i*p),y=Math.log(Math.sqrt(m*m+1)-m),x=Math.log(Math.sqrt(v*v+1)-v);r=(x-y)/e,o=function(t){var n=t*r,s=Ce(y),o=l/(i*p)*(s*function(t){return((t=Math.exp(2*t))-1)/(t+1)}(e*n+y)-function(t){return((t=Math.exp(t))-1/t)/2}(y));return[a+o*_,h+o*f,l*s/Ce(e*n+y)]}}return o.duration=1e3*r*e/Math.SQRT2,o}return s.rho=function(e){var i=Math.max(.001,+e),n=i*i;return t(i,n,n*n)},s}(Math.SQRT2,2,4);var Ne,De,Ie=0,Le=0,Re=0,Oe=0,ke=0,Be=0,ze="object"==typeof performance&&performance.now?performance:Date,Ue="object"==typeof window&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(t){setTimeout(t,17)};function Fe(){return ke||(Ue(je),ke=ze.now()+Be)}function je(){ke=0}function We(){this._call=this._time=this._next=null}function Ge(t,e,i){var n=new We;return n.restart(t,e,i),n}function Ze(){ke=(Oe=ze.now())+Be,Ie=Le=0;try{!function(){Fe(),++Ie;for(var t,e=Ne;e;)(t=ke-e._time)>=0&&e._call.call(void 0,t),e=e._next;--Ie}()}finally{Ie=0,function(){for(var t,e,i=Ne,n=1/0;i;)i._call?(n>i._time&&(n=i._time),t=i,i=i._next):(e=i._next,i._next=null,i=t?t._next=e:Ne=e);De=t,Xe(n)}(),ke=0}}function He(){var t=ze.now(),e=t-Oe;e>1e3&&(Be-=e,Oe=t)}function Xe(t){Ie||(Le&&(Le=clearTimeout(Le)),t-ke>24?(t<1/0&&(Le=setTimeout(Ze,t-ze.now()-Be)),Re&&(Re=clearInterval(Re))):(Re||(Oe=ze.now(),Re=setInterval(He,1e3)),Ie=1,Ue(Ze)))}function qe(t,e,i){var n=new We;return e=null==e?0:+e,n.restart(i=>{n.stop(),t(i+e)},e,i),n}We.prototype=Ge.prototype={constructor:We,restart:function(t,e,i){if("function"!=typeof t)throw new TypeError("callback is not a function");i=(null==i?Fe():+i)+(null==e?0:+e),this._next||De===this||(De?De._next=this:Ne=this,De=this),this._call=t,this._time=i,Xe()},stop:function(){this._call&&(this._call=null,this._time=1/0,Xe())}};var Ve=tt("start","end","cancel","interrupt"),Ye=[];function $e(t,e,i,n,s,o){var r=t.__transition;if(r){if(i in r)return}else t.__transition={};!function(t,e,i){var n,s=t.__transition;function o(h){var l,d,u,c;if(1!==i.state)return a();for(l in s)if((c=s[l]).name===i.name){if(3===c.state)return qe(o);4===c.state?(c.state=6,c.timer.stop(),c.on.call("interrupt",t,t.__data__,c.index,c.group),delete s[l]):+l0)throw new Error("too late; already scheduled");return i}function Qe(t,e){var i=Je(t,e);if(i.state>3)throw new Error("too late; already running");return i}function Je(t,e){var i=t.__transition;if(!i||!(i=i[e]))throw new Error("transition not found");return i}function ti(t,e){var i,n,s,o=t.__transition,r=!0;if(o){for(s in e=null==e?null:e+"",o)(i=o[s]).name===e?(n=i.state>2&&i.state<5,i.state=6,i.timer.stop(),i.on.call(n?"interrupt":"cancel",t,t.__data__,i.index,i.group),delete o[s]):r=!1;r&&delete t.__transition}}function ei(t,e){return t=+t,e=+e,function(i){return t*(1-i)+e*i}}var ii,ni=180/Math.PI,si={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function oi(t,e,i,n,s,o){var r,a,h;return(r=Math.sqrt(t*t+e*e))&&(t/=r,e/=r),(h=t*i+e*n)&&(i-=t*h,n-=e*h),(a=Math.sqrt(i*i+n*n))&&(i/=a,n/=a,h/=a),t*n180?e+=360:e-t>180&&(t+=360),o.push({i:i.push(s(i)+"rotate(",null,n)-2,x:ei(t,e)})):e&&i.push(s(i)+"rotate("+e+n)}(o.rotate,r.rotate,a,h),function(t,e,i,o){t!==e?o.push({i:i.push(s(i)+"skewX(",null,n)-2,x:ei(t,e)}):e&&i.push(s(i)+"skewX("+e+n)}(o.skewX,r.skewX,a,h),function(t,e,i,n,o,r){if(t!==i||e!==n){var a=o.push(s(o)+"scale(",null,",",null,")");r.push({i:a-4,x:ei(t,i)},{i:a-2,x:ei(e,n)})}else 1===i&&1===n||o.push(s(o)+"scale("+i+","+n+")")}(o.scaleX,o.scaleY,r.scaleX,r.scaleY,a,h),o=r=null,function(t){for(var e,i=-1,n=h.length;++i>8&15|e>>4&240,e>>4&15|240&e,(15&e)<<4|15&e,1):8===i?Ii(e>>24&255,e>>16&255,e>>8&255,(255&e)/255):4===i?Ii(e>>12&15|e>>8&240,e>>8&15|e>>4&240,e>>4&15|240&e,((15&e)<<4|15&e)/255):null):(e=bi.exec(t))?new Ri(e[1],e[2],e[3],1):(e=Si.exec(t))?new Ri(255*e[1]/100,255*e[2]/100,255*e[3]/100,1):(e=wi.exec(t))?Ii(e[1],e[2],e[3],e[4]):(e=Ti.exec(t))?Ii(255*e[1]/100,255*e[2]/100,255*e[3]/100,e[4]):(e=Ei.exec(t))?Fi(e[1],e[2]/100,e[3]/100,1):(e=Pi.exec(t))?Fi(e[1],e[2]/100,e[3]/100,e[4]):Ai.hasOwnProperty(t)?Di(Ai[t]):"transparent"===t?new Ri(NaN,NaN,NaN,0):null}function Di(t){return new Ri(t>>16&255,t>>8&255,255&t,1)}function Ii(t,e,i,n){return n<=0&&(t=e=i=NaN),new Ri(t,e,i,n)}function Li(t,e,i,n){return 1===arguments.length?((s=t)instanceof fi||(s=Ni(s)),s?new Ri((s=s.rgb()).r,s.g,s.b,s.opacity):new Ri):new Ri(t,e,i,n??1);var s}function Ri(t,e,i,n){this.r=+t,this.g=+e,this.b=+i,this.opacity=+n}function Oi(){return`#${Ui(this.r)}${Ui(this.g)}${Ui(this.b)}`}function ki(){const t=Bi(this.opacity);return`${1===t?"rgb(":"rgba("}${zi(this.r)}, ${zi(this.g)}, ${zi(this.b)}${1===t?")":`, ${t})`}`}function Bi(t){return isNaN(t)?1:Math.max(0,Math.min(1,t))}function zi(t){return Math.max(0,Math.min(255,Math.round(t)||0))}function Ui(t){return((t=zi(t))<16?"0":"")+t.toString(16)}function Fi(t,e,i,n){return n<=0?t=e=i=NaN:i<=0||i>=1?t=e=NaN:e<=0&&(t=NaN),new Wi(t,e,i,n)}function ji(t){if(t instanceof Wi)return new Wi(t.h,t.s,t.l,t.opacity);if(t instanceof fi||(t=Ni(t)),!t)return new Wi;if(t instanceof Wi)return t;var e=(t=t.rgb()).r/255,i=t.g/255,n=t.b/255,s=Math.min(e,i,n),o=Math.max(e,i,n),r=NaN,a=o-s,h=(o+s)/2;return a?(r=e===o?(i-n)/a+6*(i0&&h<1?0:r,new Wi(r,a,h,t.opacity)}function Wi(t,e,i,n){this.h=+t,this.s=+e,this.l=+i,this.opacity=+n}function Gi(t){return(t=(t||0)%360)<0?t+360:t}function Zi(t){return Math.max(0,Math.min(1,t||0))}function Hi(t,e,i){return 255*(t<60?e+(i-e)*t/60:t<180?i:t<240?e+(i-e)*(240-t)/60:e)}function Xi(t,e,i,n,s){var o=t*t,r=o*t;return((1-3*t+3*o-r)*e+(4-6*o+3*r)*i+(1+3*t+3*o-3*r)*n+r*s)/6}ci(fi,Ni,{copy(t){return Object.assign(new this.constructor,this,t)},displayable(){return this.rgb().displayable()},hex:Ci,formatHex:Ci,formatHex8:function(){return this.rgb().formatHex8()},formatHsl:function(){return ji(this).formatHsl()},formatRgb:Mi,toString:Mi}),ci(Ri,Li,_i(fi,{brighter(t){return t=null==t?pi:Math.pow(pi,t),new Ri(this.r*t,this.g*t,this.b*t,this.opacity)},darker(t){return t=null==t?gi:Math.pow(gi,t),new Ri(this.r*t,this.g*t,this.b*t,this.opacity)},rgb(){return this},clamp(){return new Ri(zi(this.r),zi(this.g),zi(this.b),Bi(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:Oi,formatHex:Oi,formatHex8:function(){return`#${Ui(this.r)}${Ui(this.g)}${Ui(this.b)}${Ui(255*(isNaN(this.opacity)?1:this.opacity))}`},formatRgb:ki,toString:ki})),ci(Wi,function(t,e,i,n){return 1===arguments.length?ji(t):new Wi(t,e,i,n??1)},_i(fi,{brighter(t){return t=null==t?pi:Math.pow(pi,t),new Wi(this.h,this.s,this.l*t,this.opacity)},darker(t){return t=null==t?gi:Math.pow(gi,t),new Wi(this.h,this.s,this.l*t,this.opacity)},rgb(){var t=this.h%360+360*(this.h<0),e=isNaN(t)||isNaN(this.s)?0:this.s,i=this.l,n=i+(i<.5?i:1-i)*e,s=2*i-n;return new Ri(Hi(t>=240?t-240:t+120,s,n),Hi(t,s,n),Hi(t<120?t+240:t-120,s,n),this.opacity)},clamp(){return new Wi(Gi(this.h),Zi(this.s),Zi(this.l),Bi(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){const t=Bi(this.opacity);return`${1===t?"hsl(":"hsla("}${Gi(this.h)}, ${100*Zi(this.s)}%, ${100*Zi(this.l)}%${1===t?")":`, ${t})`}`}}));const qi=t=>()=>t;function Vi(t,e){var i=e-t;return i?function(t,e){return function(i){return t+i*e}}(t,i):qi(isNaN(t)?e:t)}const Yi=function t(e){var i=function(t){return 1===(t=+t)?Vi:function(e,i){return i-e?function(t,e,i){return t=Math.pow(t,i),e=Math.pow(e,i)-t,i=1/i,function(n){return Math.pow(t+n*e,i)}}(e,i,t):qi(isNaN(e)?i:e)}}(e);function n(t,e){var n=i((t=Li(t)).r,(e=Li(e)).r),s=i(t.g,e.g),o=i(t.b,e.b),r=Vi(t.opacity,e.opacity);return function(e){return t.r=n(e),t.g=s(e),t.b=o(e),t.opacity=r(e),t+""}}return n.gamma=t,n}(1);function $i(t){return function(e){var i,n,s=e.length,o=new Array(s),r=new Array(s),a=new Array(s);for(i=0;i=1?(i=1,e-1):Math.floor(i*e),s=t[n],o=t[n+1],r=n>0?t[n-1]:2*s-o,a=no&&(s=e.slice(o,s),a[r]?a[r]+=s:a[++r]=s),(i=i[0])===(n=n[0])?a[r]?a[r]+=n:a[++r]=n:(a[++r]=null,h.push({i:r,x:ei(i,n)})),o=Qi.lastIndex;return o=0&&(t=t.slice(0,e)),!t||"start"===t})}(e)?Ke:Qe;return function(){var r=o(this,t),a=r.on;a!==n&&(s=(n=a).copy()).on(e,i),r.on=s}}(i,t,e))},attr:function(t,e){var i=xt(t),n="transform"===i?hi:tn;return this.attrTween(t,"function"==typeof e?(i.local?an:rn)(i,n,ui(this,"attr."+t,e)):null==e?(i.local?nn:en)(i):(i.local?on:sn)(i,n,e))},attrTween:function(t,e){var i="attr."+t;if(arguments.length<2)return(i=this.tween(i))&&i._value;if(null==e)return this.tween(i,null);if("function"!=typeof e)throw new Error;var n=xt(t);return this.tween(i,(n.local?hn:ln)(n,e))},style:function(t,e,i){var n="transform"==(t+="")?ai:tn;return null==e?this.styleTween(t,function(t,e){var i,n,s;return function(){var o=Dt(this,t),r=(this.style.removeProperty(t),Dt(this,t));return o===r?null:o===i&&r===n?s:s=e(i=o,n=r)}}(t,n)).on("end.style."+t,gn(t)):"function"==typeof e?this.styleTween(t,function(t,e,i){var n,s,o;return function(){var r=Dt(this,t),a=i(this),h=a+"";return null==a&&(this.style.removeProperty(t),h=a=Dt(this,t)),r===h?null:r===n&&h===s?o:(s=h,o=e(n=r,a))}}(t,n,ui(this,"style."+t,e))).each(function(t,e){var i,n,s,o,r="style."+e,a="end."+r;return function(){var h=Qe(this,t),l=h.on,d=null==h.value[r]?o||(o=gn(e)):void 0;l===i&&s===d||(n=(i=l).copy()).on(a,s=d),h.on=n}}(this._id,t)):this.styleTween(t,function(t,e,i){var n,s,o=i+"";return function(){var r=Dt(this,t);return r===o?null:r===n?s:s=e(n=r,i)}}(t,n,e),i).on("end.style."+t,null)},styleTween:function(t,e,i){var n="style."+(t+="");if(arguments.length<2)return(n=this.tween(n))&&n._value;if(null==e)return this.tween(n,null);if("function"!=typeof e)throw new Error;return this.tween(n,function(t,e,i){var n,s;function o(){var o=e.apply(this,arguments);return o!==s&&(n=(s=o)&&function(t,e,i){return function(n){this.style.setProperty(t,e.call(this,n),i)}}(t,o,i)),n}return o._value=e,o}(t,e,i??""))},text:function(t){return this.tween("text","function"==typeof t?function(t){return function(){var e=t(this);this.textContent=e??""}}(ui(this,"text",t)):function(t){return function(){this.textContent=t}}(null==t?"":t+""))},textTween:function(t){var e="text";if(arguments.length<1)return(e=this.tween(e))&&e._value;if(null==t)return this.tween(e,null);if("function"!=typeof t)throw new Error;return this.tween(e,function(t){var e,i;function n(){var n=t.apply(this,arguments);return n!==i&&(e=(i=n)&&function(t){return function(e){this.textContent=t.call(this,e)}}(n)),e}return n._value=t,n}(t))},remove:function(){return this.on("end.remove",function(t){return function(){var e=this.parentNode;for(var i in this.__transition)if(+i!==t)return;e&&e.removeChild(this)}}(this._id))},tween:function(t,e){var i=this._id;if(t+="",arguments.length<2){for(var n,s=Je(this.node(),i).tween,o=0,r=s.length;o()=>t;function wn(t,{sourceEvent:e,target:i,transform:n,dispatch:s}){Object.defineProperties(this,{type:{value:t,enumerable:!0,configurable:!0},sourceEvent:{value:e,enumerable:!0,configurable:!0},target:{value:i,enumerable:!0,configurable:!0},transform:{value:n,enumerable:!0,configurable:!0},_:{value:s}})}function Tn(t,e,i){this.k=t,this.x=e,this.y=i}Tn.prototype={constructor:Tn,scale:function(t){return 1===t?this:new Tn(this.k*t,this.x,this.y)},translate:function(t,e){return 0===t&0===e?this:new Tn(this.k,this.x+this.k*t,this.y+this.k*e)},apply:function(t){return[t[0]*this.k+this.x,t[1]*this.k+this.y]},applyX:function(t){return t*this.k+this.x},applyY:function(t){return t*this.k+this.y},invert:function(t){return[(t[0]-this.x)/this.k,(t[1]-this.y)/this.k]},invertX:function(t){return(t-this.x)/this.k},invertY:function(t){return(t-this.y)/this.k},rescaleX:function(t){return t.copy().domain(t.range().map(this.invertX,this).map(t.invert,t))},rescaleY:function(t){return t.copy().domain(t.range().map(this.invertY,this).map(t.invert,t))},toString:function(){return"translate("+this.x+","+this.y+") scale("+this.k+")"}};var En=new Tn(1,0,0);function Pn(t){t.stopImmediatePropagation()}function An(t){t.preventDefault(),t.stopImmediatePropagation()}function Cn(t){return!(t.ctrlKey&&"wheel"!==t.type||t.button)}function Mn(){var t=this;return t instanceof SVGElement?(t=t.ownerSVGElement||t).hasAttribute("viewBox")?[[(t=t.viewBox.baseVal).x,t.y],[t.x+t.width,t.y+t.height]]:[[0,0],[t.width.baseVal.value,t.height.baseVal.value]]:[[0,0],[t.clientWidth,t.clientHeight]]}function Nn(){return this.__zoom||En}function Dn(t){return-t.deltaY*(1===t.deltaMode?.05:t.deltaMode?1:.002)*(t.ctrlKey?10:1)}function In(){return navigator.maxTouchPoints||"ontouchstart"in this}function Ln(t,e,i){var n=t.invertX(e[0][0])-i[0][0],s=t.invertX(e[1][0])-i[1][0],o=t.invertY(e[0][1])-i[0][1],r=t.invertY(e[1][1])-i[1][1];return t.translate(s>n?(n+s)/2:Math.min(0,n)||Math.max(0,s),r>o?(o+r)/2:Math.min(0,o)||Math.max(0,r))}Tn.prototype;const Rn=(t,e)=>!!t&&!!e&&t.x===e.x&&t.y===e.y;var On;function kn(t,e,i){t.on(On.SIMULATION_START,()=>{e.emit(On.SIMULATION_START,void 0),i(!0)}),t.on(On.SIMULATION_PROGRESS,t=>{e.emit(On.SIMULATION_PROGRESS,t)}),t.on(On.SIMULATION_END,t=>{e.emit(On.SIMULATION_END,t),i(!1)}),t.on(On.SIMULATION_STEP,t=>{e.emit(On.SIMULATION_STEP,t)}),t.on(On.NODE_DRAG,t=>{e.emit(On.NODE_DRAG,t)}),t.on(On.SETTINGS_UPDATE,t=>{e.emit(On.SETTINGS_UPDATE,t)})}function Bn(t){return function(){return t}}function zn(t){return 1e-6*(t()-.5)}function Un(t){return t.index}function Fn(t,e){var i=t.get(e);if(!i)throw new Error("node not found: "+e);return i}!function(t){t.SIMULATION_START="simulation-start",t.SIMULATION_STEP="simulation-step",t.SIMULATION_PROGRESS="simulation-progress",t.SIMULATION_END="simulation-end",t.NODE_DRAG="node-drag",t.NODE_DRAG_END="node-drag-end",t.SETTINGS_UPDATE="settings-update"}(On||(On={}));const jn=4294967296;function Wn(t){return t.x}function Gn(t){return t.y}var Zn=Math.PI*(3-Math.sqrt(5));function Hn(t,e,i,n){if(isNaN(e)||isNaN(i))return t;var s,o,r,a,h,l,d,u,c,_=t._root,f={data:n},g=t._x0,p=t._y0,m=t._x1,v=t._y1;if(!_)return t._root=f,t;for(;_.length;)if((l=e>=(o=(g+m)/2))?g=o:m=o,(d=i>=(r=(p+v)/2))?p=r:v=r,s=_,!(_=_[u=d<<1|l]))return s[u]=f,t;if(a=+t._x.call(null,_.data),h=+t._y.call(null,_.data),e===a&&i===h)return f.next=_,s?s[u]=f:t._root=f,t;do{s=s?s[u]=new Array(4):t._root=new Array(4),(l=e>=(o=(g+m)/2))?g=o:m=o,(d=i>=(r=(p+v)/2))?p=r:v=r}while((u=d<<1|l)==(c=(h>=r)<<1|a>=o));return s[c]=_,s[u]=f,t}function Xn(t,e,i,n,s){this.node=t,this.x0=e,this.y0=i,this.x1=n,this.y1=s}function qn(t){return t[0]}function Vn(t){return t[1]}function Yn(t,e,i){var n=new $n(e??qn,i??Vn,NaN,NaN,NaN,NaN);return null==t?n:n.addAll(t)}function $n(t,e,i,n,s,o){this._x=t,this._y=e,this._x0=i,this._y0=n,this._x1=s,this._y1=o,this._root=void 0}function Kn(t){for(var e={data:t.data},i=e;t=t.next;)i=i.next={data:t.data};return e}var Qn=Yn.prototype=$n.prototype;function Jn(t){return t.x+t.vx}function ts(t){return t.y+t.vy}Qn.copy=function(){var t,e,i=new $n(this._x,this._y,this._x0,this._y0,this._x1,this._y1),n=this._root;if(!n)return i;if(!n.length)return i._root=Kn(n),i;for(t=[{source:n,target:i._root=new Array(4)}];n=t.pop();)for(var s=0;s<4;++s)(e=n.source[s])&&(e.length?t.push({source:e,target:n.target[s]=new Array(4)}):n.target[s]=Kn(e));return i},Qn.add=function(t){const e=+this._x.call(null,t),i=+this._y.call(null,t);return Hn(this.cover(e,i),e,i,t)},Qn.addAll=function(t){var e,i,n,s,o=t.length,r=new Array(o),a=new Array(o),h=1/0,l=1/0,d=-1/0,u=-1/0;for(i=0;id&&(d=n),su&&(u=s));if(h>d||l>u)return this;for(this.cover(h,l).cover(d,u),i=0;it||t>=s||n>e||e>=o;)switch(a=(ec||(o=h.y0)>_||(r=h.x1)=m)<<1|t>=p)&&(h=f[f.length-1],f[f.length-1]=f[f.length-1-l],f[f.length-1-l]=h)}else{var v=t-+this._x.call(null,g.data),y=e-+this._y.call(null,g.data),x=v*v+y*y;if(x=(a=(f+p)/2))?f=a:p=a,(d=r>=(h=(g+m)/2))?g=h:m=h,e=_,!(_=_[u=d<<1|l]))return this;if(!_.length)break;(e[u+1&3]||e[u+2&3]||e[u+3&3])&&(i=e,c=u)}for(;_.data!==t;)if(n=_,!(_=_.next))return this;return(s=_.next)&&delete _.next,n?(s?n.next=s:delete n.next,this):e?(s?e[u]=s:delete e[u],(_=e[0]||e[1]||e[2]||e[3])&&_===(e[3]||e[2]||e[1]||e[0])&&!_.length&&(i?i[c]=_:this._root=_),this):(this._root=s,this)},Qn.removeAll=function(t){for(var e=0,i=t.length;e100*(t>0?t:1),ns={useGPU:!1,isSimulatingOnDataUpdate:!0,isSimulatingOnSettingsUpdate:!0,isSimulatingOnUnstick:!0,isPhysicsEnabled:!1,alpha:{alpha:1,alphaMin:.05,alphaDecay:.028,alphaTarget:0},centering:{x:0,y:0,strength:1},collision:{radius:15,strength:1,iterations:1},links:{distance:50,strength:1,iterations:1},manyBody:{strength:-100,theta:.9,distanceMin:1,distanceMax:is(50)},positioning:{forceX:{x:0,strength:.1},forceY:{y:0,strength:.1}},anchorX:"center",anchorY:"center"},ss={rowGap:50,colGap:50},os={nodeGap:50,levelGap:50,treeGap:100,orientation:"vertical",reversed:!1};class rs extends t{constructor(){super(...arguments),this._nodes=[],this._edges=[],this._nodeIndexByNodeId={},this._cancelSimulation=!1,this._schedulerPort=null}terminate(){var t;this._cancelSimulation=!0,null===(t=this._schedulerPort)||void 0===t||t.close(),this._schedulerPort=null,this.removeAllListeners()}_scheduleNext(t){if("undefined"!=typeof MessageChannel){const e=new MessageChannel;this._schedulerPort=e.port2,e.port1.onmessage=()=>{this._schedulerPort=null,t()},e.port2.postMessage(null)}else setTimeout(t,0)}_rebuildNodeIndex(){this._nodeIndexByNodeId={};for(let t=0;t0&&this.activateSimulation())}setupData(t){this.clearData(),this._initializeNewData(t),this._settings.isSimulatingOnDataUpdate&&(this._updateSimulationData(),this._runSimulation())}mergeData(t){this._initializeNewData(t),this._settings.isPhysicsEnabled||this._pinNodes(),this._settings.isSimulatingOnDataUpdate&&(this._updateSimulationData(),this.activateSimulation())}updateData(t){const e=new Set(t.nodes.map(t=>t.id)),i=this._nodes.filter(t=>e.has(t.id)),n=t.nodes.filter(t=>void 0===this._nodeIndexByNodeId[t.id]);this._nodes=[...i,...n],this._rebuildNodeIndex(),this._edges=t.edges,this._settings.isSimulatingOnSettingsUpdate&&(this._updateSimulationData(),this.activateSimulation())}deleteData(t){if(t.nodeIds){const e=new Set(t.nodeIds);this._nodes=this._nodes.filter(t=>!e.has(t.id))}if(t.edgeIds){const e=new Set(t.edgeIds);this._edges=this._edges.filter(t=>!e.has(t.id))}this._rebuildNodeIndex(),this._settings.isSimulatingOnDataUpdate&&(this._updateSimulationData(),this.activateSimulation())}patchData(t){if(t.nodes){const e={};for(let t=0;t0&&this.activateSimulation()}terminate(){var t;super.terminate(),null===(t=this._simulation)||void 0===t||t.stop()}_resetSimulation(){this._simulation&&(this._simulation.stop(),this._simulation.on("tick",null).on("end",null)),this._linkForce=function(t){var e,i,n,s,o,r,a=Un,h=function(t){return 1/Math.min(s[t.source.index],s[t.target.index])},l=Bn(30),d=1;function u(n){for(var s=0,a=t.length;s[a(t,e,n),t]));for(r=0,s=new Array(l);rt.id),this._simulation=function(t){var e,i=1,n=.001,s=1-Math.pow(n,1/300),o=0,r=.6,a=new Map,h=Ge(u),l=tt("tick","end"),d=function(){let t=1;return()=>(t=(1664525*t+1013904223)%jn)/jn}();function u(){c(),l.call("tick",e),i1?(null==i?a.delete(t):a.set(t,f(i)),e):a.get(t)},find:function(e,i,n){var s,o,r,a,h,l=0,d=t.length;for(null==n?n=1/0:n*=n,l=0;l1?(l.on(t,i),e):l.on(t)}}}(this._nodes).force("link",this._linkForce).stop(),this._applySettingsToSimulation(this._settings),this._simulation.on("tick",()=>{this.emit(On.SIMULATION_STEP,{nodes:this._nodes,edges:this._edges})}),this._simulation.on("end",()=>{this._isDragging=!1,this._isStabilizing=!1,this.emit(On.SIMULATION_END,{nodes:this._nodes,edges:this._edges}),this._settings.isPhysicsEnabled||this._pinNodes()})}_runSimulation(t){if(this._isStabilizing||this._cancelSimulation)return;(this._settings.isPhysicsEnabled||(null==t?void 0:t.isUpdatingSettings))&&this._unpinNodes(),this.emit(On.SIMULATION_START,void 0),this._isStabilizing=!0,this._simulation.alpha(this._settings.alpha.alpha).alphaTarget(this._settings.alpha.alphaTarget).stop();const e=Math.min(500,Math.ceil(Math.log(this._settings.alpha.alphaMin)/Math.log(1-this._settings.alpha.alphaDecay)));let i=-1,n=0;const s=()=>{if(this._cancelSimulation)return this._isStabilizing=!1,void(this._cancelSimulation=!1);const t=Math.min(n+100,e);for(;ni&&(i=t,this.emit(On.SIMULATION_PROGRESS,{nodes:this._nodes,edges:this._edges,progress:t/100}))}nl+f||od+f||rh.index){var g=l-a.x-a.vx,p=d-a.y-a.vy,m=g*g+p*p;mt.r&&(t.r=t[e].r)}function h(){if(e){var n,s,o=e.length;for(i=new Array(o),n=0;n=a)){(t.data!==e||t.next)&&(0===u&&(f+=(u=zn(i))*u),0===c&&(f+=(c=zn(i))*c),f=s)continue;h<1&&(h=1);const u=-t*e/h;o.vx+=r*u,o.vy+=a*u}}}return o.initialize=t=>{n=t},o}(t.manyBody.strength,t.manyBody.distanceMax,()=>this._edges)):this._simulation.force("edgeMidpointRepulsion",null)}if(null===t.manyBody&&(this._simulation.force("charge",null),this._simulation.force("edgeMidpointRepulsion",null)),null===(e=t.positioning)||void 0===e?void 0:e.forceX){const e=function(t){var e,i,n,s=Bn(.1);function o(t){for(var s,o=0,r=e.length;o{const n=t.createShader(i===hs.VERTEX?t.VERTEX_SHADER:t.FRAGMENT_SHADER);if(!n)throw new o("Failed to create shader.");if(t.shaderSource(n,e),t.compileShader(n),!t.getShaderParameter(n,t.COMPILE_STATUS)){const e=t.getShaderInfoLog(n);throw t.deleteShader(n),new o(`Failed to compile shader: ${e}`)}return n};class ds extends rs{constructor(t){super(),this._isStabilizing=!1,this._isDragging=!1,this._dragLoopRunning=!1,this._pendingRestart=!1,this._simulationGeneration=0,this._currentAlpha=0,this._currentStep=0,this._totalSteps=0,this._dragAlpha=0,this._dragNeedsReheat=!1,this._dirtyNodes=new Set,this._forceProgram=null,this._quadBuffer=null,this._quadVAO=null,this._stateTexA=null,this._stateTexB=null,this._fixedTex=null,this._fboA=null,this._fboB=null,this._texWidth=0,this._treeDataTexture=null,this._treeChildrenTexture=null,this._treeGeometryTexture=null,this._adjOffsetsTexture=null,this._adjEdgesTexture=null,this._cachedAdjacency=null,this._treeTexWidth=1,this._treeNodeCount=0,this._pingPong=!0,this._uniforms={},this.type="force",this._settings=Object.assign(Object.assign({},ns),t);const e=document.createElement("canvas").getContext("webgl2");if(!e)throw new o("Failed to create WebGL2 context for GPU force layout engine.");this._gl=e,this._initGPU(),this.clearData()}setSettings(t){const e=t;this._initialSettings||(this._initialSettings=Object.assign(m(ns),e));const i=m(this._settings);Object.assign(this._settings,e),v(this._settings,i)||(this.emit(On.SETTINGS_UPDATE,{settings:{type:"force",options:this._settings}}),i.isPhysicsEnabled&&!e.isPhysicsEnabled?this.stopSimulation():this._settings.isSimulatingOnSettingsUpdate&&this._nodes.length>0&&this.activateSimulation())}setupData(t){this.clearData(),this._initializeNewData(t),this._settings.isSimulatingOnDataUpdate&&this._runSimulation()}mergeData(t){this._initializeNewData(t),this._settings.isPhysicsEnabled||this._pinNodes(),this._settings.isSimulatingOnDataUpdate&&this.activateSimulation()}updateData(t){const e=new Set(t.nodes.map(t=>t.id)),i=this._nodes.filter(t=>e.has(t.id)),n=t.nodes.filter(t=>void 0===this._nodeIndexByNodeId[t.id]);this._nodes=[...i,...n],this._rebuildNodeIndex(),this._edges=t.edges,this._cachedAdjacency=null,this._settings.isSimulatingOnSettingsUpdate&&this.activateSimulation()}deleteData(t){if(t.nodeIds){const e=new Set(t.nodeIds);this._nodes=this._nodes.filter(t=>!e.has(t.id))}if(t.edgeIds){const e=new Set(t.edgeIds);this._edges=this._edges.filter(t=>!e.has(t.id))}this._rebuildNodeIndex(),this._cachedAdjacency=null,this._settings.isSimulatingOnDataUpdate&&this.activateSimulation()}patchData(t){if(t.nodes){const e={};for(let t=0;t0&&this.activateSimulation()}terminate(){var t;super.terminate();const e=this._gl;e&&(e.deleteBuffer(this._quadBuffer),e.deleteVertexArray(this._quadVAO),e.deleteProgram(this._forceProgram),e.deleteTexture(this._stateTexA),e.deleteTexture(this._stateTexB),e.deleteTexture(this._fixedTex),e.deleteTexture(this._treeDataTexture),e.deleteTexture(this._treeChildrenTexture),e.deleteTexture(this._treeGeometryTexture),e.deleteTexture(this._adjOffsetsTexture),e.deleteTexture(this._adjEdgesTexture),e.deleteFramebuffer(this._fboA),e.deleteFramebuffer(this._fboB),null===(t=e.getExtension("WEBGL_lose_context"))||void 0===t||t.loseContext())}reheat(){const t=this._settings.alpha;this._currentAlpha=t.alpha,this._totalSteps=Math.min(500,Math.ceil(Math.log(t.alphaMin)/Math.log(1-t.alphaDecay))),this._currentStep=0,this._isStabilizing||(this._ensurePositions(),this._uploadDataToGPU(),this._cachedAdjacency||this._buildAndUploadAdjacency(),this._startSimulationLoop())}_runSimulation(){this._isStabilizing||this._cancelSimulation||(this._ensurePositions(),this._uploadDataToGPU(),this._buildAndUploadAdjacency(),this._startSimulationLoop())}_startDragLoop(){if(this._dragLoopRunning)return;this._dragLoopRunning=!0;const t=this._settings.alpha.alphaDecay,e=this._settings.alpha.alphaMin;this._dragAlpha=.3,this._dragNeedsReheat=!1;const i=()=>{this._isDragging?(this._dragNeedsReheat&&(this._dragAlpha=.3,this._dragNeedsReheat=!1),this._dragAlpha+=(0-this._dragAlpha)*t,this._dragAlpha{if(t!==this._simulationGeneration)return;if(this._cancelSimulation)return this._isStabilizing=!1,this._cancelSimulation=!1,void this.emit(On.SIMULATION_END,{nodes:this._nodes,edges:this._edges});if(this._readbackFromGPU(),this._pendingRestart)return this._isStabilizing=!1,this._pendingRestart=!1,this._ensurePositions(),this._uploadDataToGPU(),this._cachedAdjacency||this._buildAndUploadAdjacency(),void this._startSimulationLoop();this._flushDirtyNodes(),this._buildAndUploadQuadTree();const r=Math.min(this._currentStep+1,this._totalSteps);for(;this._currentSteps&&(s=a,this.emit(On.SIMULATION_PROGRESS,{nodes:this._nodes,edges:this._edges,progress:a/100})),this._currentStep0&&(s=s.concat(t))}const o=function(t,e){var i,n;const s=t.length;if(0===s)return{treeData:new Float32Array(0),treeChildren:new Float32Array(0),treeGeometry:new Float32Array(0),nodeCount:0,texWidth:1};let o=1/0,r=1/0,a=-1/0,h=-1/0;for(let e=0;ea&&(a=i),n>h&&(h=n)}let l=Math.max(a-o,h-r);l<1e-6&&(l=1),l*=1.01;const d=.5*l,u=.5*(o+a)-d,c=.5*(r+h)-d,_=[];function f(t){const e=_.length;return _.push({cx:0,cy:0,charge:0,size:t,bodyIndex:-1,children:[null,null,null,null]}),e}const g=f(l),p=[u],m=[c];function v(t,e,i,n,s){return 2*(e>=n+.5*s?1:0)+(t>=i+.5*s?1:0)}function y(t,e,i,n){const s=.5*n;return{cx0:1&t?e+s:e,cy0:2&t?i+s:i,csz:s}}function x(t,i,n){let s=g,o=u,r=c,a=l;for(let h=0;h<50;h++){const h=_[s];if(-1===h.bodyIndex&&null===h.children[0]&&null===h.children[1]&&null===h.children[2]&&null===h.children[3])return h.bodyIndex=t,h.cx=i,h.cy=n,void(h.charge=e);if(h.bodyIndex>=0){const t=h.bodyIndex,i=h.cx,n=h.cy;h.bodyIndex=-1;const s=v(i,n,o,r,a),{cx0:l,cy0:d,csz:u}=y(s,o,r,a),c=f(u);p[c]=l,m[c]=d,h.children[s]=c,_[c].bodyIndex=t,_[c].cx=i,_[c].cy=n,_[c].charge=e}const l=v(i,n,o,r,a);if(null===h.children[l]){const{cx0:s,cy0:d,csz:u}=y(l,o,r,a),c=f(u);return p[c]=s,m[c]=d,h.children[l]=c,_[c].bodyIndex=t,_[c].cx=i,_[c].cy=n,void(_[c].charge=e)}const{cx0:d,cy0:u,csz:c}=y(l,o,r,a);s=h.children[l],o=d,r=u,a=c}}for(let e=0;e=0)return;let n=0,s=0,o=0,r=0;for(let e=0;e<4;e++){const a=i.children[e];if(null===a)continue;t(a);const h=_[a],l=Math.abs(h.charge);n+=h.charge,s+=h.cx*l,o+=h.cy*l,r+=l}r>0&&(i.cx=s/r,i.cy=o/r),i.charge=n}(g);const b=_.length,S=Math.ceil(Math.sqrt(b)),w=S*S,T=new Float32Array(4*w),E=new Float32Array(4*w),P=new Float32Array(4*w);for(let t=0;t=0?T[s+3]=-(e.bodyIndex+1):T[s+3]=e.size,E[s]=null!==e.children[0]?e.children[0]:-1,E[s+1]=null!==e.children[1]?e.children[1]:-1,E[s+2]=null!==e.children[2]?e.children[2]:-1,E[s+3]=null!==e.children[3]?e.children[3]:-1,P[s]=null!==(i=p[t])&&void 0!==i?i:0,P[s+1]=null!==(n=m[t])&&void 0!==n?n:0,P[s+2]=e.size,P[s+3]=0}for(let t=b;t= uNodeCount) {\n fragColor = vec4(0.0);\n return;\n }\n\n vec4 fixedData = texelFetch(uFixed, fc, 0);\n if (fixedData.x > 0.5) {\n fragColor = vec4(fixedData.yz, 0.0, 0.0);\n return;\n }\n\n vec4 state = texelFetch(uState, fc, 0);\n vec2 pos = state.xy;\n vec2 vel = state.zw;\n\n if (uHasManyBody > 0.5 && uTreeNodeCount > 0) {\n int stack[128];\n int top = 0;\n stack[top++] = 0;\n\n while (top > 0) {\n int idx = stack[--top];\n vec4 data = texelFetch(uTreeData, texCoord(idx, uTreeTexWidth), 0);\n float w = data.w;\n\n if (w < -0.5) {\n int bodyIdx = int(-w - 0.5);\n if (bodyIdx != nodeId) {\n vec2 delta = data.xy - pos;\n float distSq = dot(delta, delta);\n\n if (distSq < 1e-8) {\n delta = vec2(float(nodeId) * 1e-4 - float(bodyIdx) * 1e-4 + 1e-4, 1e-4);\n distSq = dot(delta, delta);\n }\n\n if (distSq < uDistanceMax2) {\n float l = distSq;\n if (l < uDistanceMin2) l = sqrt(uDistanceMin2 * l);\n vel += delta * (data.z * uAlpha / max(l, 1e-6));\n }\n }\n } else {\n vec2 delta = data.xy - pos;\n float distSq = dot(delta, delta);\n\n if (distSq > 0.0 && w * w / distSq < uTheta2) {\n if (distSq < uDistanceMax2) {\n float l = distSq;\n if (l < uDistanceMin2) l = sqrt(uDistanceMin2 * l);\n vel += delta * (data.z * uAlpha / max(l, 1e-6));\n }\n } else {\n vec4 ch = texelFetch(uTreeChildren, texCoord(idx, uTreeTexWidth), 0);\n if (ch.w >= 0.0 && top < 64) stack[top++] = int(ch.w + 0.5);\n if (ch.z >= 0.0 && top < 64) stack[top++] = int(ch.z + 0.5);\n if (ch.y >= 0.0 && top < 64) stack[top++] = int(ch.y + 0.5);\n if (ch.x >= 0.0 && top < 64) stack[top++] = int(ch.x + 0.5);\n }\n }\n }\n }\n\n if (uHasCollision > 0.5 && uCollisionRadius > 0.0 && uTreeNodeCount > 0) {\n float collisionDiam = uCollisionRadius * 2.0;\n vec2 predictedPos = state.xy + state.zw;\n int stack[64];\n int top = 0;\n stack[top++] = 0;\n\n while (top > 0) {\n int idx = stack[--top];\n vec4 data = texelFetch(uTreeData, texCoord(idx, uTreeTexWidth), 0);\n float w = data.w;\n\n if (w < -0.5) {\n int bodyIdx = int(-w - 0.5);\n if (bodyIdx != nodeId && bodyIdx < uNodeCount) {\n vec2 delta = data.xy - predictedPos;\n float dist = length(delta);\n\n if (dist < collisionDiam && dist > 0.0) {\n float push = (collisionDiam - dist) * uCollisionStrength;\n vel -= (delta / dist) * push * 0.5;\n }\n }\n } else {\n vec4 geo = texelFetch(uTreeGeometry, texCoord(idx, uTreeTexWidth), 0);\n float cellSize = geo.z;\n vec2 nearest = clamp(predictedPos, geo.xy, geo.xy + cellSize);\n float distToCell = length(nearest - predictedPos);\n\n if (distToCell < collisionDiam) {\n vec4 ch = texelFetch(uTreeChildren, texCoord(idx, uTreeTexWidth), 0);\n if (ch.w >= 0.0 && top < 64) stack[top++] = int(ch.w + 0.5);\n if (ch.z >= 0.0 && top < 64) stack[top++] = int(ch.z + 0.5);\n if (ch.y >= 0.0 && top < 64) stack[top++] = int(ch.y + 0.5);\n if (ch.x >= 0.0 && top < 64) stack[top++] = int(ch.x + 0.5);\n }\n }\n }\n }\n\n if (uHasLinks > 0.5) {\n vec4 offData = texelFetch(uAdjOffsets, texCoord(nodeId, uAdjOffsetsTexWidth), 0);\n int start = int(offData.x + 0.5);\n int count = int(offData.y + 0.5);\n\n for (int e = 0; e < count; e++) {\n vec4 edgeData = texelFetch(uAdjEdges, texCoord(start + e, uAdjEdgesTexWidth), 0);\n int targetId = int(edgeData.x + 0.5);\n float restDist = edgeData.y;\n float strength = edgeData.z;\n float dirBias = edgeData.w;\n\n vec4 targetState = texelFetch(uState, texCoord(targetId, uTexWidth), 0);\n vec2 delta = (targetState.xy + targetState.zw) - (state.xy + state.zw);\n float d = length(delta);\n\n if (d < 1e-6) {\n delta = vec2(1e-3, 1e-3);\n d = length(delta);\n }\n\n float scale = (d - restDist) / d * uAlpha * strength;\n vel += delta * scale * dirBias;\n }\n }\n\n if (uHasCentering > 0.5) {\n vel += (uCenter - pos) * uCenterStrength * uAlpha;\n }\n\n if (uHasPositioning > 0.5) {\n vel.x += (uForceXTarget - pos.x) * uForceXStrength * uAlpha;\n vel.y += (uForceYTarget - pos.y) * uForceYStrength * uAlpha;\n }\n\n vel *= uDamping;\n pos += vel;\n\n fragColor = vec4(pos, vel);\n}\n",hs.FRAGMENT),n=t.createProgram();if(!n)throw new o("Failed to create program.");if(this._forceProgram=n,t.attachShader(n,e),t.attachShader(n,i),t.linkProgram(n),!t.getProgramParameter(n,t.LINK_STATUS)){const e=t.getProgramInfoLog(n);throw new o(`Failed to link force program: ${e}`)}this._cacheUniformLocations(n),this._quadBuffer=t.createBuffer();const s=new Float32Array([-1,-1,1,-1,-1,1,1,1]);t.bindBuffer(t.ARRAY_BUFFER,this._quadBuffer),t.bufferData(t.ARRAY_BUFFER,s,t.STATIC_DRAW),this._quadVAO=t.createVertexArray(),t.bindVertexArray(this._quadVAO);const r=t.getAttribLocation(n,"aPosition");t.enableVertexAttribArray(r),t.vertexAttribPointer(r,2,t.FLOAT,!1,0,0),t.bindVertexArray(null),this._stateTexA=t.createTexture(),this._stateTexB=t.createTexture(),this._fixedTex=t.createTexture(),this._treeDataTexture=t.createTexture(),this._treeChildrenTexture=t.createTexture(),this._treeGeometryTexture=t.createTexture(),this._adjOffsetsTexture=t.createTexture(),this._adjEdgesTexture=t.createTexture(),this._fboA=t.createFramebuffer(),this._fboB=t.createFramebuffer()}_cacheUniformLocations(t){const e=this._gl,i=["uState","uFixed","uTreeData","uTreeChildren","uTreeGeometry","uAdjOffsets","uAdjEdges","uNodeCount","uTexWidth","uAlpha","uDamping","uManyBodyStrength","uTheta2","uDistanceMin2","uDistanceMax2","uTreeNodeCount","uTreeTexWidth","uAdjOffsetsTexWidth","uAdjEdgesTexWidth","uCenter","uCenterStrength","uCollisionRadius","uCollisionStrength","uForceXTarget","uForceXStrength","uForceYTarget","uForceYStrength","uHasManyBody","uHasLinks","uHasCentering","uHasCollision","uHasPositioning"];for(const n of i)this._uniforms[n]=e.getUniformLocation(t,n)}_uploadDataToGPU(){var t,e,i,n,s,o,r,a;const h=this._gl,l=this._nodes.length;this._texWidth=Math.max(1,Math.ceil(Math.sqrt(l)));const d=this._texWidth*this._texWidth,u=new Float32Array(4*d),c=new Float32Array(4*d);for(let h=0;h0?t.distanceMax:is(null!==(i=null===(e=this._settings.links)||void 0===e?void 0:e.distance)&&void 0!==i?i:50);c.uniform1f(g.uDistanceMax2,s*s),c.uniform1i(g.uTreeNodeCount,this._treeNodeCount),c.uniform1i(g.uTreeTexWidth,this._treeTexWidth)}const m=null!==this._cachedAdjacency&&this._edges.length>0;c.uniform1f(g.uHasLinks,m?1:0),m&&(c.uniform1i(g.uAdjOffsetsTexWidth,this._cachedAdjacency.offsetsTexWidth),c.uniform1i(g.uAdjEdgesTexWidth,this._cachedAdjacency.edgesTexWidth)),c.uniform1f(g.uHasCentering,0);const v=null!==this._settings.collision&&void 0!==this._settings.collision;c.uniform1f(g.uHasCollision,v?1:0),v&&(c.uniform1f(g.uCollisionRadius,this._settings.collision.radius),c.uniform1f(g.uCollisionStrength,this._settings.collision.strength));const y=null!==this._settings.positioning&&void 0!==this._settings.positioning;if(c.uniform1f(g.uHasPositioning,y?1:0),y){const t=this._settings.positioning;c.uniform1f(g.uForceXTarget,null!==(s=null===(n=t.forceX)||void 0===n?void 0:n.x)&&void 0!==s?s:0),c.uniform1f(g.uForceXStrength,null!==(a=null===(r=t.forceX)||void 0===r?void 0:r.strength)&&void 0!==a?a:0),c.uniform1f(g.uForceYTarget,null!==(l=null===(h=t.forceY)||void 0===h?void 0:h.y)&&void 0!==l?l:0),c.uniform1f(g.uForceYStrength,null!==(u=null===(d=t.forceY)||void 0===d?void 0:d.strength)&&void 0!==u?u:0)}const x=this._pingPong?this._stateTexA:this._stateTexB,b=this._pingPong?this._fboB:this._fboA;c.activeTexture(c.TEXTURE0),c.bindTexture(c.TEXTURE_2D,x),c.uniform1i(g.uState,0),c.activeTexture(c.TEXTURE1),c.bindTexture(c.TEXTURE_2D,this._fixedTex),c.uniform1i(g.uFixed,1),c.activeTexture(c.TEXTURE2),c.bindTexture(c.TEXTURE_2D,this._treeDataTexture),c.uniform1i(g.uTreeData,2),c.activeTexture(c.TEXTURE3),c.bindTexture(c.TEXTURE_2D,this._treeChildrenTexture),c.uniform1i(g.uTreeChildren,3),c.activeTexture(c.TEXTURE4),c.bindTexture(c.TEXTURE_2D,this._adjOffsetsTexture),c.uniform1i(g.uAdjOffsets,4),c.activeTexture(c.TEXTURE5),c.bindTexture(c.TEXTURE_2D,this._adjEdgesTexture),c.uniform1i(g.uAdjEdges,5),c.activeTexture(c.TEXTURE6),c.bindTexture(c.TEXTURE_2D,this._treeGeometryTexture),c.uniform1i(g.uTreeGeometry,6),c.bindFramebuffer(c.FRAMEBUFFER,b),c.viewport(0,0,this._texWidth,this._texWidth),c.bindVertexArray(this._quadVAO),c.drawArrays(c.TRIANGLE_STRIP,0,4),c.bindVertexArray(null),c.bindFramebuffer(c.FRAMEBUFFER,null),this._pingPong=!this._pingPong}_readbackFromGPU(){const t=this._gl,e=this._nodes.length;if(0===e)return;const i=this._pingPong?this._fboA:this._fboB,n=this._texWidth*this._texWidth,s=new Float32Array(4*n);t.bindFramebuffer(t.FRAMEBUFFER,i),t.readPixels(0,0,this._texWidth,this._texWidth,t.RGBA,t.FLOAT,s),t.bindFramebuffer(t.FRAMEBUFFER,null);for(let t=0;tt.id)),i=this._nodes.filter(t=>e.has(t.id)),n=t.nodes.filter(t=>void 0===this._nodeIndexByNodeId[t.id]);this._nodes=[...i,...n],this._edges=t.edges,this._rebuildNodeIndex(),this._calculateAndEmit()}deleteData(t){if(t.nodeIds){const e=new Set(t.nodeIds);this._nodes=this._nodes.filter(t=>!e.has(t.id))}if(t.edgeIds){const e=new Set(t.edgeIds);this._edges=this._edges.filter(t=>!e.has(t.id))}this._rebuildNodeIndex(),this._calculateAndEmit()}patchData(t){if(t.nodes)for(let e=0;e0&&this._calculateAndEmit()}terminate(){this._pendingRecalculation=!1,super.terminate()}_calculateAndEmit(){0===this._nodes.length||this._cancelSimulation||(this._isCalculating?this._pendingRecalculation=!0:(this._isCalculating=!0,this.emit(On.SIMULATION_START,void 0),this.calculatePositions(this._nodes,this._edges,t=>{this.emit(On.SIMULATION_PROGRESS,{nodes:this._nodes,edges:this._edges,progress:t})},()=>this._cancelSimulation,()=>{this._isCalculating=!1,this._cancelSimulation||this.emit(On.SIMULATION_END,{nodes:this._nodes,edges:this._edges}),this._cancelSimulation=!1,this._pendingRecalculation&&(this._pendingRecalculation=!1,this._calculateAndEmit())})))}_emitProgress(t,e,i,n){const s=Math.round(100*t/e);return s>i?(n(s/100),s):i}}class cs extends us{constructor(t){super(),this.type="circular",this._config=Object.assign(Object.assign({},es),t)}calculatePositions(t,e,i,n,s){const o=2*Math.PI/t.length;let r=-1,a=0;const h=()=>{if(n())return void s();const e=Math.min(a+5e3,t.length);for(;a{if(n())return void s();const e=Math.min(h+5e3,t.length);for(;h{if(n()||c>=a.length)return!n()&&this._config.reversed&&this._applyReversal(t,h,l),void s();const e=this._assignLevels(a[c],o,r),f=Math.max(...Array.from(e.values()).map(t=>t.length));e.size*this._config.levelGap>l&&(l=e.size*this._config.levelGap);let g=0===c?0:this._config.treeGap+h;c>0&&(g+=(f-1)*this._config.nodeGap/2);for(let i=0;ih&&(h=a),void 0!==r&&(t[r].x="horizontal"===this._config.orientation?n:a,t[r].y="horizontal"===this._config.orientation?a:n),d++}}c++,c0;){const t=h.pop();if(void 0===t)continue;a.push(t);const s=null!==(i=e.get(t))&&void 0!==i?i:[];for(let t=0;t{var e;return 0===(null!==(e=i.get(t))&&void 0!==e?e:0)});void 0===a&&(a=t.reduce((t,e)=>{var n,s;return(null!==(n=i.get(e))&&void 0!==n?n:0)<(null!==(s=i.get(t))&&void 0!==s?s:0)?e:t}));const h=[[a,0]];for(const[t,i]of h){if(r.has(t))continue;r.add(t),o.has(i)?null===(n=o.get(i))||void 0===n||n.push(t):o.set(i,[t]);const a=null!==(s=e.get(t))&&void 0!==s?s:[];for(let t=0;t{this._isSimulationRunning=t})}}var ms,vs;!function(t){t.SetupData="Set Data",t.MergeData="Add Data",t.UpdateData="Update Data",t.DeleteData="Delete Data",t.PatchData="Patch Data",t.ClearData="Clear Data",t.ActivateSimulation="Activate Simulation",t.UpdateSimulation="Update Simulation",t.StopSimulation="Stop Simulation",t.StartDragNode="Start Drag Node",t.DragNode="Drag Node",t.EndDragNode="End Drag Node",t.FixNodes="Fix Nodes",t.ReleaseNodes="Release Nodes",t.SetSettings="Set Settings"}(ms||(ms={})),function(t){t.READY="ready",t.SIMULATION_START="simulation-start",t.SIMULATION_STEP="simulation-step",t.SIMULATION_PROGRESS="simulation-progress",t.SIMULATION_END="simulation-end",t.SIMULATION_TICK="simulation-tick",t.NODE_DRAG="node-drag",t.NODE_DRAG_END="node-drag-end",t.SETTINGS_UPDATE="settings-update"}(vs||(vs={}));class ys extends t{constructor(t){let e;super(),this._isSimulationRunning=!1,this._fallback=null,this._ready=!1,this._pending=[],this._hasWarned=!1,this._handleWorkerMessage=({data:t})=>{switch(t.type){case vs.READY:this._markReady();break;case vs.SIMULATION_START:this.emit(On.SIMULATION_START,void 0),this._isSimulationRunning=!0;break;case vs.SIMULATION_PROGRESS:this.emit(On.SIMULATION_PROGRESS,t.data);break;case vs.SIMULATION_END:this.emit(On.SIMULATION_END,t.data),this._isSimulationRunning=!1;break;case vs.SIMULATION_STEP:this.emit(On.SIMULATION_STEP,t.data);break;case vs.NODE_DRAG:this.emit(On.NODE_DRAG,t.data);break;case vs.NODE_DRAG_END:this.emit(On.NODE_DRAG_END,t.data);break;case vs.SETTINGS_UPDATE:this.emit(On.SETTINGS_UPDATE,t.data)}},this._settings=t;try{this._blobUrl=URL.createObjectURL(new Blob(['"use strict";(()=>{function Ee(n,r){var e,t=1;n==null&&(n=0),r==null&&(r=0);function i(){var o,s=e.length,a,u=0,l=0;for(o=0;o=(_=(a+l)/2))?a=_:l=_,(h=e>=(m=(u+c)/2))?u=m:c=m,i=o,!(o=o[p=h<<1|f]))return i[p]=s,n;if(d=+n._x.call(null,o.data),g=+n._y.call(null,o.data),r===d&&e===g)return s.next=o,i?i[p]=s:n._root=s,n;do i=i?i[p]=new Array(4):n._root=new Array(4),(f=r>=(_=(a+l)/2))?a=_:l=_,(h=e>=(m=(u+c)/2))?u=m:c=m;while((p=h<<1|f)===(y=(g>=m)<<1|d>=_));return i[y]=o,i[p]=s,n}function Be(n){var r,e,t=n.length,i,o,s=new Array(t),a=new Array(t),u=1/0,l=1/0,c=-1/0,_=-1/0;for(e=0;ec&&(c=i),o_&&(_=o));if(u>c||l>_)return this;for(this.cover(u,l).cover(c,_),e=0;en||n>=i||t>r||r>=o;)switch(l=(rc||(a=g.y0)>_||(u=g.x1)=p)<<1|n>=h)&&(g=m[m.length-1],m[m.length-1]=m[m.length-1-f],m[m.length-1-f]=g)}else{var y=n-+this._x.call(null,d.data),T=r-+this._y.call(null,d.data),x=y*y+T*T;if(x=(m=(s+u)/2))?s=m:u=m,(f=_>=(d=(a+l)/2))?a=d:l=d,r=e,!(e=e[h=f<<1|g]))return this;if(!e.length)break;(r[h+1&3]||r[h+2&3]||r[h+3&3])&&(t=r,p=h)}for(;e.data!==n;)if(i=e,!(e=e.next))return this;return(o=e.next)&&delete e.next,i?(o?i.next=o:delete i.next,this):r?(o?r[h]=o:delete r[h],(e=r[0]||r[1]||r[2]||r[3])&&e===(r[3]||r[2]||r[1]||r[0])&&!e.length&&(t?t[p]=e:this._root=e),this):(this._root=o,this)}function He(n){for(var r=0,e=n.length;rm.index){var M=d-D.x-D.vx,v=g-D.y-D.vy,S=M*M+v*v;Sd+b||Eg+b||Pl.r&&(l.r=l[c].r)}function u(){if(r){var l,c=r.length,_;for(e=new Array(c),l=0;l[r(I,E,s),I])),x;for(h=0,a=new Array(p);h{}};function rt(){for(var n=0,r=arguments.length,e={},t;n=0&&(t=e.slice(i+1),e=e.slice(0,i)),e&&!r.hasOwnProperty(e))throw new Error("unknown type: "+e);return{type:e,name:t}})}le.prototype=rt.prototype={constructor:le,on:function(n,r){var e=this._,t=Rt(n+"",e),i,o=-1,s=t.length;if(arguments.length<2){for(;++o0)for(var e=new Array(i),t=0,i,o;t=0&&n._call.call(void 0,r),n=n._next;--J}function st(){Z=(de=oe.now())+ce,J=ie=0;try{ut()}finally{J=0,Gt(),Z=0}}function Ft(){var n=oe.now(),r=n-de;r>at&&(ce-=r,de=n)}function Gt(){for(var n,r=ue,e,t=1/0;r;)r._call?(t>r._time&&(t=r._time),n=r,r=r._next):(e=r._next,r._next=null,r=n?n._next=e:ue=e);ne=n,Le(t)}function Le(n){if(!J){ie&&(ie=clearTimeout(ie));var r=n-Z;r>24?(n<1/0&&(ie=setTimeout(st,n-oe.now()-ce)),te&&(te=clearInterval(te))):(te||(de=oe.now(),te=setInterval(Ft,at)),J=1,lt(st))}}function dt(){let n=1;return()=>(n=(1664525*n+1013904223)%4294967296)/4294967296}function ct(n){return n.x}function ht(n){return n.y}var kt=10,Wt=Math.PI*(3-Math.sqrt(5));function Me(n){var r,e=1,t=.001,i=1-Math.pow(t,1/300),o=0,s=.6,a=new Map,u=he(_),l=Ae("tick","end"),c=dt();n==null&&(n=[]);function _(){m(),l.call("tick",r),e1?(h==null?a.delete(f):a.set(f,g(h)),r):a.get(f)},find:function(f,h,p){var y=0,T=n.length,x,I,E,P,D;for(p==null?p=1/0:p*=p,y=0;y1?(l.on(f,h),r):l.on(f)}}}function Re(){var n,r,e,t,i=O(-30),o,s=1,a=1/0,u=.81;function l(d){var g,f=n.length,h=Q(n,ct,ht).visitAfter(_);for(t=d,g=0;g=a)return;(d.data!==r||d.next)&&(p===0&&(p=k(e),x+=p*p),y===0&&(y=k(e),x+=y*y),xn instanceof Date,pe=n=>Array.isArray(n),me=n=>n!==null&&typeof n=="object"&&n.constructor.name==="Object";var C=n=>fe(n)?Ct(n):pe(n)?Bt(n):me(n)?Kt(n):n,j=(n,r)=>{let e=fe(n),t=fe(r);if(e&&!t||!e&&t)return!1;if(e&&t)return n.getTime()===r.getTime();let i=pe(n),o=pe(r);if(i&&!o||!i&&o)return!1;if(i&&o)return n.length!==r.length?!1:n.every((u,l)=>j(u,r[l]));let s=me(n),a=me(r);if(s&&!a||!s&&a)return!1;if(s&&a){let u=Object.keys(n),l=Object.keys(r);return j(u,l)?u.every(c=>j(n[c],r[c])):!1}return n===r},Ct=n=>new Date(n),Bt=n=>n.map(r=>C(r)),Kt=n=>{let r={};return Object.keys(n).forEach(e=>{r[e]=C(n[e])}),r};var pt={radius:100,centerX:0,centerY:0},zt=100,ft=50,Fe=n=>(n>0?n:1)*zt,ee={useGPU:!1,isSimulatingOnDataUpdate:!0,isSimulatingOnSettingsUpdate:!0,isSimulatingOnUnstick:!0,isPhysicsEnabled:!1,alpha:{alpha:1,alphaMin:.05,alphaDecay:.028,alphaTarget:0},centering:{x:0,y:0,strength:1},collision:{radius:15,strength:1,iterations:1},links:{distance:ft,strength:1,iterations:1},manyBody:{strength:-100,theta:.9,distanceMin:1,distanceMax:Fe(ft)},positioning:{forceX:{x:0,strength:.1},forceY:{y:0,strength:.1}},anchorX:"center",anchorY:"center"},mt={rowGap:50,colGap:50},gt={nodeGap:50,levelGap:50,treeGap:100,orientation:"vertical",reversed:!1};var ge=class{constructor(){this._listeners=new Map}once(r,e){let t={callable:e,isOnce:!0},i=this._listeners.get(r);return i?i.push(t):this._listeners.set(r,[t]),this}on(r,e){let t={callable:e},i=this._listeners.get(r);return i?i.push(t):this._listeners.set(r,[t]),this}off(r,e){let t=this._listeners.get(r);if(t){let i=t.filter(o=>o.callable!==e);this._listeners.set(r,i)}return this}emit(r,e){let t=this._listeners.get(r);if(!t||t.length===0)return!1;let i=!1;for(let o=0;o!s.isOnce);this._listeners.set(r,o)}return!0}eventNames(){return[...this._listeners.keys()]}listenerCount(r){let e=this._listeners.get(r);return e?e.length:0}listeners(r){let e=this._listeners.get(r);return e?e.map(t=>t.callable):[]}addListener(r,e){return this.on(r,e)}removeListener(r,e){return this.off(r,e)}removeAllListeners(r){return r?this._listeners.delete(r):this._listeners.clear(),this}};var Y=class extends ge{constructor(){super(...arguments);this._nodes=[];this._edges=[];this._nodeIndexByNodeId={};this._cancelSimulation=!1;this._schedulerPort=null}terminate(){this._cancelSimulation=!0,this._schedulerPort?.close(),this._schedulerPort=null,this.removeAllListeners()}_scheduleNext(e){if(typeof MessageChannel<"u"){let t=new MessageChannel;this._schedulerPort=t.port2,t.port1.onmessage=()=>{this._schedulerPort=null,e()},t.port2.postMessage(null)}else setTimeout(e,0)}_rebuildNodeIndex(){this._nodeIndexByNodeId={};for(let e=0;e=i)continue;p<1&&(p=1);let y=-n*s/p;g.vx+=f*y,g.vy+=h*y}}}return o.initialize=s=>{t=s},o}var re=class extends Y{constructor(e){super();this._isDragging=!1;this._isStabilizing=!1;this.type="force";this._settings={...ee,...e},this.clearData()}setSettings(e){let t=e;this._initialSettings||(this._initialSettings=Object.assign(C(ee),t));let i=C(this._settings);if(Object.assign(this._settings,t),j(this._settings,i))return;this._applySettingsToSimulation(t),this.emit("settings-update",{settings:{type:"force",options:this._settings}}),i.isPhysicsEnabled&&!t.isPhysicsEnabled?this._simulation.stop():this._settings.isSimulatingOnSettingsUpdate&&this._nodes.length>0&&this.activateSimulation()}setupData(e){this.clearData(),this._initializeNewData(e),this._settings.isSimulatingOnDataUpdate&&(this._updateSimulationData(),this._runSimulation())}mergeData(e){this._initializeNewData(e),this._settings.isPhysicsEnabled||this._pinNodes(),this._settings.isSimulatingOnDataUpdate&&(this._updateSimulationData(),this.activateSimulation())}updateData(e){let t=new Set(e.nodes.map(s=>s.id)),i=this._nodes.filter(s=>t.has(s.id)),o=e.nodes.filter(s=>this._nodeIndexByNodeId[s.id]===void 0);this._nodes=[...i,...o],this._rebuildNodeIndex(),this._edges=e.edges,this._settings.isSimulatingOnSettingsUpdate&&(this._updateSimulationData(),this.activateSimulation())}deleteData(e){if(e.nodeIds){let t=new Set(e.nodeIds);this._nodes=this._nodes.filter(i=>!t.has(i.id))}if(e.edgeIds){let t=new Set(e.edgeIds);this._edges=this._edges.filter(i=>!t.has(i.id))}this._rebuildNodeIndex(),this._settings.isSimulatingOnDataUpdate&&(this._updateSimulationData(),this.activateSimulation())}patchData(e){if(e.nodes){let t={};for(let i=0;i0&&this.activateSimulation()}terminate(){super.terminate(),this._simulation?.stop()}_resetSimulation(){this._simulation&&(this._simulation.stop(),this._simulation.on("tick",null).on("end",null)),this._linkForce=De(this._edges).id(e=>e.id),this._simulation=Me(this._nodes).force("link",this._linkForce).stop(),this._applySettingsToSimulation(this._settings),this._simulation.on("tick",()=>{this.emit("simulation-step",{nodes:this._nodes,edges:this._edges})}),this._simulation.on("end",()=>{this._isDragging=!1,this._isStabilizing=!1,this.emit("simulation-end",{nodes:this._nodes,edges:this._edges}),this._settings.isPhysicsEnabled||this._pinNodes()})}_runSimulation(e){if(this._isStabilizing||this._cancelSimulation)return;(this._settings.isPhysicsEnabled||e?.isUpdatingSettings)&&this._unpinNodes(),this.emit("simulation-start",void 0),this._isStabilizing=!0,this._simulation.alpha(this._settings.alpha.alpha).alphaTarget(this._settings.alpha.alphaTarget).stop();let t=Math.min(jt,Math.ceil(Math.log(this._settings.alpha.alphaMin)/Math.log(1-this._settings.alpha.alphaDecay))),i=-1,o=0,s=()=>{if(this._cancelSimulation){this._isStabilizing=!1,this._cancelSimulation=!1;return}let a=Math.min(o+Xt,t);for(;oi&&(i=u,this.emit("simulation-progress",{nodes:this._nodes,edges:this._edges,progress:u/100}))}othis._edges)):this._simulation.force("edgeMidpointRepulsion",null)}if(e.manyBody===null&&(this._simulation.force("charge",null),this._simulation.force("edgeMidpointRepulsion",null)),e.positioning?.forceX){let t=we(e.positioning.forceX.x).strength(e.positioning.forceX.strength);this._simulation.force("x",t)}if(e.positioning?.forceX===null&&this._simulation.force("x",null),e.positioning?.forceY){let t=Ue(e.positioning.forceY.y).strength(e.positioning.forceY.strength);this._simulation.force("y",t)}if(e.positioning?.forceY===null&&this._simulation.force("y",null),e.centering){let t=Ee(e.centering.x,e.centering.y).strength(e.centering.strength);this._simulation.force("center",t)}e.centering===null&&this._simulation.force("center",null)}};var B=class extends Error{constructor(r){super(r),this.message=r,Object.setPrototypeOf(this,new.target.prototype),this.name=this.constructor.name}};var ke=(n,r,e)=>{let t=n.createShader(e==="vertex"?n.VERTEX_SHADER:n.FRAGMENT_SHADER);if(!t)throw new B("Failed to create shader.");if(n.shaderSource(t,r),n.compileShader(t),!n.getShaderParameter(t,n.COMPILE_STATUS)){let i=n.getShaderInfoLog(t);throw n.deleteShader(t),new B(`Failed to compile shader: ${i}`)}return t};var _t=`#version 300 es\n\nin vec2 aPosition;\n\nvoid main() {\n gl_Position = vec4(aPosition, 0.0, 1.0);\n}\n`;var yt=`#version 300 es\n\nprecision highp float;\n\nuniform sampler2D uState;\nuniform sampler2D uFixed;\nuniform sampler2D uTreeData;\nuniform sampler2D uTreeChildren;\nuniform sampler2D uTreeGeometry;\nuniform sampler2D uAdjOffsets;\nuniform sampler2D uAdjEdges;\n\nuniform int uNodeCount;\nuniform int uTexWidth;\nuniform float uAlpha;\nuniform float uDamping;\n\nuniform float uManyBodyStrength;\nuniform float uTheta2;\nuniform float uDistanceMin2;\nuniform float uDistanceMax2;\nuniform int uTreeNodeCount;\nuniform int uTreeTexWidth;\n\nuniform int uAdjOffsetsTexWidth;\nuniform int uAdjEdgesTexWidth;\n\nuniform vec2 uCenter;\nuniform float uCenterStrength;\n\nuniform float uCollisionRadius;\nuniform float uCollisionStrength;\n\nuniform float uForceXTarget;\nuniform float uForceXStrength;\nuniform float uForceYTarget;\nuniform float uForceYStrength;\n\nuniform float uHasManyBody;\nuniform float uHasLinks;\nuniform float uHasCentering;\nuniform float uHasCollision;\nuniform float uHasPositioning;\n\nout vec4 fragColor;\n\nivec2 texCoord(int idx, int tw) {\n return ivec2(idx % tw, idx / tw);\n}\n\nvoid main() {\n ivec2 fc = ivec2(gl_FragCoord.xy);\n int nodeId = fc.y * uTexWidth + fc.x;\n\n if (nodeId >= uNodeCount) {\n fragColor = vec4(0.0);\n return;\n }\n\n vec4 fixedData = texelFetch(uFixed, fc, 0);\n if (fixedData.x > 0.5) {\n fragColor = vec4(fixedData.yz, 0.0, 0.0);\n return;\n }\n\n vec4 state = texelFetch(uState, fc, 0);\n vec2 pos = state.xy;\n vec2 vel = state.zw;\n\n if (uHasManyBody > 0.5 && uTreeNodeCount > 0) {\n int stack[128];\n int top = 0;\n stack[top++] = 0;\n\n while (top > 0) {\n int idx = stack[--top];\n vec4 data = texelFetch(uTreeData, texCoord(idx, uTreeTexWidth), 0);\n float w = data.w;\n\n if (w < -0.5) {\n int bodyIdx = int(-w - 0.5);\n if (bodyIdx != nodeId) {\n vec2 delta = data.xy - pos;\n float distSq = dot(delta, delta);\n\n if (distSq < 1e-8) {\n delta = vec2(float(nodeId) * 1e-4 - float(bodyIdx) * 1e-4 + 1e-4, 1e-4);\n distSq = dot(delta, delta);\n }\n\n if (distSq < uDistanceMax2) {\n float l = distSq;\n if (l < uDistanceMin2) l = sqrt(uDistanceMin2 * l);\n vel += delta * (data.z * uAlpha / max(l, 1e-6));\n }\n }\n } else {\n vec2 delta = data.xy - pos;\n float distSq = dot(delta, delta);\n\n if (distSq > 0.0 && w * w / distSq < uTheta2) {\n if (distSq < uDistanceMax2) {\n float l = distSq;\n if (l < uDistanceMin2) l = sqrt(uDistanceMin2 * l);\n vel += delta * (data.z * uAlpha / max(l, 1e-6));\n }\n } else {\n vec4 ch = texelFetch(uTreeChildren, texCoord(idx, uTreeTexWidth), 0);\n if (ch.w >= 0.0 && top < 64) stack[top++] = int(ch.w + 0.5);\n if (ch.z >= 0.0 && top < 64) stack[top++] = int(ch.z + 0.5);\n if (ch.y >= 0.0 && top < 64) stack[top++] = int(ch.y + 0.5);\n if (ch.x >= 0.0 && top < 64) stack[top++] = int(ch.x + 0.5);\n }\n }\n }\n }\n\n if (uHasCollision > 0.5 && uCollisionRadius > 0.0 && uTreeNodeCount > 0) {\n float collisionDiam = uCollisionRadius * 2.0;\n vec2 predictedPos = state.xy + state.zw;\n int stack[64];\n int top = 0;\n stack[top++] = 0;\n\n while (top > 0) {\n int idx = stack[--top];\n vec4 data = texelFetch(uTreeData, texCoord(idx, uTreeTexWidth), 0);\n float w = data.w;\n\n if (w < -0.5) {\n int bodyIdx = int(-w - 0.5);\n if (bodyIdx != nodeId && bodyIdx < uNodeCount) {\n vec2 delta = data.xy - predictedPos;\n float dist = length(delta);\n\n if (dist < collisionDiam && dist > 0.0) {\n float push = (collisionDiam - dist) * uCollisionStrength;\n vel -= (delta / dist) * push * 0.5;\n }\n }\n } else {\n vec4 geo = texelFetch(uTreeGeometry, texCoord(idx, uTreeTexWidth), 0);\n float cellSize = geo.z;\n vec2 nearest = clamp(predictedPos, geo.xy, geo.xy + cellSize);\n float distToCell = length(nearest - predictedPos);\n\n if (distToCell < collisionDiam) {\n vec4 ch = texelFetch(uTreeChildren, texCoord(idx, uTreeTexWidth), 0);\n if (ch.w >= 0.0 && top < 64) stack[top++] = int(ch.w + 0.5);\n if (ch.z >= 0.0 && top < 64) stack[top++] = int(ch.z + 0.5);\n if (ch.y >= 0.0 && top < 64) stack[top++] = int(ch.y + 0.5);\n if (ch.x >= 0.0 && top < 64) stack[top++] = int(ch.x + 0.5);\n }\n }\n }\n }\n\n if (uHasLinks > 0.5) {\n vec4 offData = texelFetch(uAdjOffsets, texCoord(nodeId, uAdjOffsetsTexWidth), 0);\n int start = int(offData.x + 0.5);\n int count = int(offData.y + 0.5);\n\n for (int e = 0; e < count; e++) {\n vec4 edgeData = texelFetch(uAdjEdges, texCoord(start + e, uAdjEdgesTexWidth), 0);\n int targetId = int(edgeData.x + 0.5);\n float restDist = edgeData.y;\n float strength = edgeData.z;\n float dirBias = edgeData.w;\n\n vec4 targetState = texelFetch(uState, texCoord(targetId, uTexWidth), 0);\n vec2 delta = (targetState.xy + targetState.zw) - (state.xy + state.zw);\n float d = length(delta);\n\n if (d < 1e-6) {\n delta = vec2(1e-3, 1e-3);\n d = length(delta);\n }\n\n float scale = (d - restDist) / d * uAlpha * strength;\n vel += delta * scale * dirBias;\n }\n }\n\n if (uHasCentering > 0.5) {\n vel += (uCenter - pos) * uCenterStrength * uAlpha;\n }\n\n if (uHasPositioning > 0.5) {\n vel.x += (uForceXTarget - pos.x) * uForceXStrength * uAlpha;\n vel.y += (uForceYTarget - pos.y) * uForceYStrength * uAlpha;\n }\n\n vel *= uDamping;\n pos += vel;\n\n fragColor = vec4(pos, vel);\n}\n`;function It(n,r){let e=n.length;if(e===0)return{treeData:new Float32Array(0),treeChildren:new Float32Array(0),treeGeometry:new Float32Array(0),nodeCount:0,texWidth:1};let t=1/0,i=1/0,o=-1/0,s=-1/0;for(let v=0;vo&&(o=S),A>s&&(s=A)}let a=Math.max(o-t,s-i);a<1e-6&&(a=1),a*=1.01;let u=(t+o)*.5,l=(i+s)*.5,c=a*.5,_=u-c,m=l-c,d=[];function g(v){let S=d.length;return d.push({cx:0,cy:0,charge:0,size:v,bodyIndex:-1,children:[null,null,null,null]}),S}let f=g(a),h=[_],p=[m];function y(v,S,A,K,w){let U=A+w*.5,G=K+w*.5,X=v>=U?1:0;return(S>=G?1:0)*2+X}function T(v,S,A,K){let w=K*.5,U=v&1?S+w:S,G=v&2?A+w:A;return{cx0:U,cy0:G,csz:w}}function x(v,S,A){let K=f,w=_,U=m,G=a;for(let X=0;X<50;X++){let L=d[K];if(L.bodyIndex===-1&&L.children[0]===null&&L.children[1]===null&&L.children[2]===null&&L.children[3]===null){L.bodyIndex=v,L.cx=S,L.cy=A,L.charge=r;return}if(L.bodyIndex>=0){let ve=L.bodyIndex,se=L.cx,ae=L.cy;L.bodyIndex=-1;let W=y(se,ae,w,U,G),{cx0:bt,cy0:Dt,csz:At}=T(W,w,U,G),V=g(At);h[V]=bt,p[V]=Dt,L.children[W]=V,d[V].bodyIndex=ve,d[V].cx=se,d[V].cy=ae,d[V].charge=r}let z=y(S,A,w,U,G);if(L.children[z]===null){let{cx0:ve,cy0:se,csz:ae}=T(z,w,U,G),W=g(ae);h[W]=ve,p[W]=se,L.children[z]=W,d[W].bodyIndex=v,d[W].cx=S,d[W].cy=A,d[W].charge=r;return}let{cx0:vt,cy0:Et,csz:Nt}=T(z,w,U,G);K=L.children[z],w=vt,U=Et,G=Nt}}for(let v=0;v=0)return;let A=0,K=0,w=0,U=0;for(let G=0;G<4;G++){let X=S.children[G];if(X===null)continue;I(X);let L=d[X],z=Math.abs(L.charge);A+=L.charge,K+=L.cx*z,w+=L.cy*z,U+=z}U>0&&(S.cx=K/U,S.cy=w/U),S.charge=A}I(f);let E=d.length,P=Math.ceil(Math.sqrt(E)),D=P*P,N=new Float32Array(D*4),b=new Float32Array(D*4),M=new Float32Array(D*4);for(let v=0;v=0?N[A+3]=-(S.bodyIndex+1):N[A+3]=S.size,b[A]=S.children[0]!==null?S.children[0]:-1,b[A+1]=S.children[1]!==null?S.children[1]:-1,b[A+2]=S.children[2]!==null?S.children[2]:-1,b[A+3]=S.children[3]!==null?S.children[3]:-1,M[A]=h[v]??0,M[A+1]=p[v]??0,M[A+2]=S.size,M[A+3]=0}for(let v=E;v0&&this.activateSimulation()}setupData(e){this.clearData(),this._initializeNewData(e),this._settings.isSimulatingOnDataUpdate&&this._runSimulation()}mergeData(e){this._initializeNewData(e),this._settings.isPhysicsEnabled||this._pinNodes(),this._settings.isSimulatingOnDataUpdate&&this.activateSimulation()}updateData(e){let t=new Set(e.nodes.map(s=>s.id)),i=this._nodes.filter(s=>t.has(s.id)),o=e.nodes.filter(s=>this._nodeIndexByNodeId[s.id]===void 0);this._nodes=[...i,...o],this._rebuildNodeIndex(),this._edges=e.edges,this._cachedAdjacency=null,this._settings.isSimulatingOnSettingsUpdate&&this.activateSimulation()}deleteData(e){if(e.nodeIds){let t=new Set(e.nodeIds);this._nodes=this._nodes.filter(i=>!t.has(i.id))}if(e.edgeIds){let t=new Set(e.edgeIds);this._edges=this._edges.filter(i=>!t.has(i.id))}this._rebuildNodeIndex(),this._cachedAdjacency=null,this._settings.isSimulatingOnDataUpdate&&this.activateSimulation()}patchData(e){if(e.nodes){let t={};for(let i=0;i0&&this.activateSimulation()}terminate(){super.terminate();let e=this._gl;e&&(e.deleteBuffer(this._quadBuffer),e.deleteVertexArray(this._quadVAO),e.deleteProgram(this._forceProgram),e.deleteTexture(this._stateTexA),e.deleteTexture(this._stateTexB),e.deleteTexture(this._fixedTex),e.deleteTexture(this._treeDataTexture),e.deleteTexture(this._treeChildrenTexture),e.deleteTexture(this._treeGeometryTexture),e.deleteTexture(this._adjOffsetsTexture),e.deleteTexture(this._adjEdgesTexture),e.deleteFramebuffer(this._fboA),e.deleteFramebuffer(this._fboB),e.getExtension("WEBGL_lose_context")?.loseContext())}reheat(){let e=this._settings.alpha;this._currentAlpha=e.alpha,this._totalSteps=Math.min(St,Math.ceil(Math.log(e.alphaMin)/Math.log(1-e.alphaDecay))),this._currentStep=0,!this._isStabilizing&&(this._ensurePositions(),this._uploadDataToGPU(),this._cachedAdjacency||this._buildAndUploadAdjacency(),this._startSimulationLoop())}_runSimulation(){this._isStabilizing||this._cancelSimulation||(this._ensurePositions(),this._uploadDataToGPU(),this._buildAndUploadAdjacency(),this._startSimulationLoop())}_startDragLoop(){if(this._dragLoopRunning)return;this._dragLoopRunning=!0;let e=this._settings.alpha.alphaDecay,t=this._settings.alpha.alphaMin;this._dragAlpha=.3,this._dragNeedsReheat=!1;let i=()=>{if(!this._isDragging){this._dragLoopRunning=!1;return}if(this._dragNeedsReheat&&(this._dragAlpha=.3,this._dragNeedsReheat=!1),this._dragAlpha+=(0-this._dragAlpha)*e,this._dragAlpha{if(e!==this._simulationGeneration)return;if(this._cancelSimulation){this._isStabilizing=!1,this._cancelSimulation=!1,this.emit("simulation-end",{nodes:this._nodes,edges:this._edges});return}if(this._readbackFromGPU(),this._pendingRestart){this._isStabilizing=!1,this._pendingRestart=!1,this._ensurePositions(),this._uploadDataToGPU(),this._cachedAdjacency||this._buildAndUploadAdjacency(),this._startSimulationLoop();return}this._flushDirtyNodes(),this._buildAndUploadQuadTree();let u=Math.min(this._currentStep+Ht,this._totalSteps);for(;this._currentSteps&&(s=l,this.emit("simulation-progress",{nodes:this._nodes,edges:this._edges,progress:l/100})),this._currentStep0&&(i=i.concat(s))}let o=It(i,t);this._uploadTexture(this._treeDataTexture,o.treeData,o.texWidth),this._uploadTexture(this._treeChildrenTexture,o.treeChildren,o.texWidth),this._uploadTexture(this._treeGeometryTexture,o.treeGeometry,o.texWidth),this._treeTexWidth=o.texWidth,this._treeNodeCount=o.nodeCount}_getEdgeMidpoints(){let e=[];for(let t=0;t0?d.distanceMax:Fe(this._settings.links?.distance??50);t.uniform1f(s.uDistanceMax2,f*f),t.uniform1i(s.uTreeNodeCount,this._treeNodeCount),t.uniform1i(s.uTreeTexWidth,this._treeTexWidth)}let u=this._cachedAdjacency!==null&&this._edges.length>0;t.uniform1f(s.uHasLinks,u?1:0),u&&(t.uniform1i(s.uAdjOffsetsTexWidth,this._cachedAdjacency.offsetsTexWidth),t.uniform1i(s.uAdjEdgesTexWidth,this._cachedAdjacency.edgesTexWidth)),t.uniform1f(s.uHasCentering,0);let l=this._settings.collision!==null&&this._settings.collision!==void 0;t.uniform1f(s.uHasCollision,l?1:0),l&&(t.uniform1f(s.uCollisionRadius,this._settings.collision.radius),t.uniform1f(s.uCollisionStrength,this._settings.collision.strength));let c=this._settings.positioning!==null&&this._settings.positioning!==void 0;if(t.uniform1f(s.uHasPositioning,c?1:0),c){let d=this._settings.positioning;t.uniform1f(s.uForceXTarget,d.forceX?.x??0),t.uniform1f(s.uForceXStrength,d.forceX?.strength??0),t.uniform1f(s.uForceYTarget,d.forceY?.y??0),t.uniform1f(s.uForceYStrength,d.forceY?.strength??0)}let _=this._pingPong?this._stateTexA:this._stateTexB,m=this._pingPong?this._fboB:this._fboA;t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,_),t.uniform1i(s.uState,0),t.activeTexture(t.TEXTURE1),t.bindTexture(t.TEXTURE_2D,this._fixedTex),t.uniform1i(s.uFixed,1),t.activeTexture(t.TEXTURE2),t.bindTexture(t.TEXTURE_2D,this._treeDataTexture),t.uniform1i(s.uTreeData,2),t.activeTexture(t.TEXTURE3),t.bindTexture(t.TEXTURE_2D,this._treeChildrenTexture),t.uniform1i(s.uTreeChildren,3),t.activeTexture(t.TEXTURE4),t.bindTexture(t.TEXTURE_2D,this._adjOffsetsTexture),t.uniform1i(s.uAdjOffsets,4),t.activeTexture(t.TEXTURE5),t.bindTexture(t.TEXTURE_2D,this._adjEdgesTexture),t.uniform1i(s.uAdjEdges,5),t.activeTexture(t.TEXTURE6),t.bindTexture(t.TEXTURE_2D,this._treeGeometryTexture),t.uniform1i(s.uTreeGeometry,6),t.bindFramebuffer(t.FRAMEBUFFER,m),t.viewport(0,0,this._texWidth,this._texWidth),t.bindVertexArray(this._quadVAO),t.drawArrays(t.TRIANGLE_STRIP,0,4),t.bindVertexArray(null),t.bindFramebuffer(t.FRAMEBUFFER,null),this._pingPong=!this._pingPong}_readbackFromGPU(){let e=this._gl,t=this._nodes.length;if(t===0)return;let i=this._pingPong?this._fboA:this._fboB,o=this._texWidth*this._texWidth,s=new Float32Array(o*4);e.bindFramebuffer(e.FRAMEBUFFER,i),e.readPixels(0,0,this._texWidth,this._texWidth,e.RGBA,e.FLOAT,s),e.bindFramebuffer(e.FRAMEBUFFER,null);for(let a=0;as.id)),i=this._nodes.filter(s=>t.has(s.id)),o=e.nodes.filter(s=>this._nodeIndexByNodeId[s.id]===void 0);this._nodes=[...i,...o],this._edges=e.edges,this._rebuildNodeIndex(),this._calculateAndEmit()}deleteData(e){if(e.nodeIds){let t=new Set(e.nodeIds);this._nodes=this._nodes.filter(i=>!t.has(i.id))}if(e.edgeIds){let t=new Set(e.edgeIds);this._edges=this._edges.filter(i=>!t.has(i.id))}this._rebuildNodeIndex(),this._calculateAndEmit()}patchData(e){if(e.nodes)for(let t=0;t0&&this._calculateAndEmit()}terminate(){this._pendingRecalculation=!1,super.terminate()}_calculateAndEmit(){if(!(this._nodes.length===0||this._cancelSimulation)){if(this._isCalculating){this._pendingRecalculation=!0;return}this._isCalculating=!0,this.emit("simulation-start",void 0),this.calculatePositions(this._nodes,this._edges,e=>{this.emit("simulation-progress",{nodes:this._nodes,edges:this._edges,progress:e})},()=>this._cancelSimulation,()=>{this._isCalculating=!1,this._cancelSimulation||this.emit("simulation-end",{nodes:this._nodes,edges:this._edges}),this._cancelSimulation=!1,this._pendingRecalculation&&(this._pendingRecalculation=!1,this._calculateAndEmit())})}}_emitProgress(e,t,i,o){let s=Math.round(e*100/t);return s>i?(o(s/100),s):i}};var Ie=class extends H{constructor(e){super();this.type="circular";this._config={...pt,...e}}calculatePositions(e,t,i,o,s){let a=2*Math.PI/e.length,u=-1,l=0,c=()=>{if(o()){s();return}let _=Math.min(l+ye,e.length);for(;l<_;l++)e[l].x=this._config.centerX+this._config.radius*Math.cos(a*l),e[l].y=this._config.centerY+this._config.radius*Math.sin(a*l);l{if(o()){s();return}let m=Math.min(c+ye,e.length);for(;c{if(o()||g>=l.length){!o()&&this._config.reversed&&this._applyReversal(e,c,_),s();return}let h=this._assignLevels(l[g],a,u),p=Math.max(...Array.from(h.values()).map(T=>T.length));h.size*this._config.levelGap>_&&(_=h.size*this._config.levelGap);let y=g===0?0:this._config.treeGap+c;g>0&&(y+=(p-1)*this._config.nodeGap/2);for(let T=0;Tc&&(c=b),N!==void 0&&(e[N].x=this._config.orientation==="horizontal"?x:b,e[N].y=this._config.orientation==="horizontal"?b:x),m++}}g++,g0;){let c=l.pop();if(c===void 0)continue;u.push(c);let _=t.get(c)??[];for(let m=0;m<_.length;m++)i.has(_[m])||(i.add(_[m]),l.push(_[m]))}o.push(u)}return o}_assignLevels(e,t,i){let o=new Map,s=new Set,a=e.find(l=>(i.get(l)??0)===0);a===void 0&&(a=e.reduce((l,c)=>(i.get(c)??0)<(i.get(l)??0)?c:l));let u=[[a,0]];for(let[l,c]of u){if(s.has(l))continue;s.add(l),o.has(c)?o.get(c)?.push(l):o.set(c,[l]);let _=t.get(l)??[];for(let m=0;m<_.length;m++)u.push([_[m],c+1])}return o}_getEdgeEndpointId(e){return typeof e=="object"?e.id:e}};var Te=class{static create(r){switch(r?.type){case"circular":return new Ie(r.options);case"grid":return new xe(r.options);case"hierarchical":return new Se(r.options);default:{let e=r?.options;if(e?.useGPU)try{return new _e(e)}catch{return console.warn("WebGL2 unavailable, falling back to CPU force layout engine."),new re(e)}return new re(e)}}}};function Tt(n,r){switch(r.type){case"Set Data":n.setupData(r.data);break;case"Add Data":n.mergeData(r.data);break;case"Update Data":n.updateData(r.data);break;case"Delete Data":n.deleteData(r.data);break;case"Patch Data":n.patchData(r.data);break;case"Clear Data":n.clearData();break;case"Activate Simulation":n.activateSimulation();break;case"Stop Simulation":n.stopSimulation();break;case"Start Drag Node":n.startDragNode();break;case"Drag Node":n.dragNode(r.data.id,{x:r.data.x,y:r.data.y});break;case"End Drag Node":n.endDragNode(r.data.id);break;case"Fix Nodes":n.fixNodes(r.data.nodes);break;case"Release Nodes":n.releaseNodes(r.data.nodes);break;default:break}}var q=null,$=n=>postMessage(n);function Vt(n){n.on("simulation-start",()=>$({type:"simulation-start"})),n.on("simulation-progress",r=>$({type:"simulation-progress",data:r})),n.on("simulation-end",r=>$({type:"simulation-end",data:r})),n.on("simulation-step",r=>$({type:"simulation-step",data:r})),n.on("node-drag",r=>$({type:"node-drag",data:r})),n.on("settings-update",r=>$({type:"settings-update",data:r}))}$({type:"ready"});addEventListener("message",({data:n})=>{if(n.type==="Set Settings"){let r=n.data;if(r.type===q?.type&&r.options){q?.setSettings(r.options);return}q?.removeAllListeners(),q?.terminate(),q=Te.create(r),Vt(q);return}q&&Tt(q,n)});})();\n'],{type:"text/javascript"})),e=new Worker(this._blobUrl)}catch(t){return void this._activateFallback(t)}this._worker=e,e.onerror=t=>{this._ready?this._warnWorkerError(t):this._activateFallback(t)},e.onmessage=this._handleWorkerMessage,this._readyTimer=setTimeout(()=>{this._ready||this._fallback||this._activateFallback(new Error("Web Worker readiness handshake timed out."))},3e3),this.emitToWorker({type:ms.SetSettings,data:t})}setupData(t){this.emitToWorker({type:ms.SetupData,data:t})}mergeData(t){this.emitToWorker({type:ms.MergeData,data:t})}updateData(t){this.emitToWorker({type:ms.UpdateData,data:t})}deleteData(t){this.emitToWorker({type:ms.DeleteData,data:t})}patchData(t){this.emitToWorker({type:ms.PatchData,data:t})}clearData(){this.emitToWorker({type:ms.ClearData})}activateSimulation(){this.emitToWorker({type:ms.ActivateSimulation})}stopSimulation(){this.emitToWorker({type:ms.StopSimulation})}updateSimulation(t,e){this.emitToWorker({type:ms.UpdateSimulation,data:{nodes:t,edges:e}})}startDragNode(){this.emitToWorker({type:ms.StartDragNode})}dragNode(t,e){this.emitToWorker({type:ms.DragNode,data:Object.assign({id:t},e)})}endDragNode(t){this.emitToWorker({type:ms.EndDragNode,data:{id:t}})}fixNodes(t){this.emitToWorker({type:ms.FixNodes,data:{nodes:t}})}releaseNodes(t){this.emitToWorker({type:ms.ReleaseNodes,data:{nodes:t}})}setSettings(t){this.emitToWorker({type:ms.SetSettings,data:t})}isSimulationRunning(){return this._fallback?this._fallback.isSimulationRunning():this._isSimulationRunning}terminate(){var t;void 0!==this._readyTimer&&(clearTimeout(this._readyTimer),this._readyTimer=void 0),this._revokeBlobUrl(),this._worker&&(this._worker.onmessage=null,this._worker.onerror=null,this._worker.terminate(),this._worker=void 0),null===(t=this._fallback)||void 0===t||t.terminate(),this.removeAllListeners()}emitToWorker(t){var e;this._fallback?this._applyToFallback(this._fallback,t):(this._ready||this._pending.push(t),null===(e=this._worker)||void 0===e||e.postMessage(t))}_markReady(){this._ready||(this._ready=!0,this._pending=[],void 0!==this._readyTimer&&(clearTimeout(this._readyTimer),this._readyTimer=void 0),this._revokeBlobUrl())}_activateFallback(t){if(this._fallback)return;if(this._warnFallback(t),void 0!==this._readyTimer&&(clearTimeout(this._readyTimer),this._readyTimer=void 0),this._worker){this._worker.onmessage=null,this._worker.onerror=null;try{this._worker.terminate()}catch(t){}this._worker=void 0}this._revokeBlobUrl();const e=new ps(this._settings);this._wireFallbackEvents(e),this._fallback=e;const i=this._pending;this._pending=[];for(const t of i)this._applyToFallback(e,t)}_wireFallbackEvents(t){kn(t,this,t=>{this._isSimulationRunning=t})}_applyToFallback(t,e){e.type!==ms.SetSettings?function(t,e){switch(e.type){case ms.SetupData:t.setupData(e.data);break;case ms.MergeData:t.mergeData(e.data);break;case ms.UpdateData:t.updateData(e.data);break;case ms.DeleteData:t.deleteData(e.data);break;case ms.PatchData:t.patchData(e.data);break;case ms.ClearData:t.clearData();break;case ms.ActivateSimulation:t.activateSimulation();break;case ms.StopSimulation:t.stopSimulation();break;case ms.StartDragNode:t.startDragNode();break;case ms.DragNode:t.dragNode(e.data.id,{x:e.data.x,y:e.data.y});break;case ms.EndDragNode:t.endDragNode(e.data.id);break;case ms.FixNodes:t.fixNodes(e.data.nodes);break;case ms.ReleaseNodes:t.releaseNodes(e.data.nodes)}}(t,e):t.setSettings(e.data)}_revokeBlobUrl(){this._blobUrl&&(URL.revokeObjectURL(this._blobUrl),this._blobUrl=void 0)}_warnWorkerError(t){this._hasWarned||(this._hasWarned=!0,console.warn("Orb: the layout Web Worker errored after it had started. The current layout is kept and no further updates will be simulated; reload the graph to recover.",t))}_warnFallback(t){this._hasWarned||(this._hasWarned=!0,console.warn("Orb: the layout Web Worker could not start; falling back to the main-thread simulator. Layout is still correct but runs on the main thread. Under a strict Content Security Policy, allow blob workers (e.g. `worker-src blob:` or `child-src blob:`) to re-enable off-main-thread layout.",t))}}class xs{static getSimulator(t){const e=Object.assign({type:"force"},t),i=e.options;if("force"===e.type&&(null==i?void 0:i.useGPU))return new ps(e);try{if("undefined"!=typeof Worker)return new ys(e);throw new Error("WebWorkers are unavailable in your environment.")}catch(t){return console.error("Could not create simulator in a WebWorker context. All calculations will be done in the main thread.",t),new ps(e)}}}const bs=t=>{const e=t.start,i=t.end;return e{if(!this.sortBy)return 0;const i=this.getOne(t),n=this.getOne(e);return void 0===i||void 0===n?0:this.sortBy(i,n)})}get size(){return this.entityById.size}}const ws=(...t)=>{const e=t.reduce((t,e)=>t.concat(e),[]);return Array.from(new Set(e))};class Ts extends d{constructor(t,e){var i,n;super(),this._nodes=new Ss({getId:t=>t.getId(),sortBy:(t,e)=>{var i,n;return(null!==(i=t.getStyle().zIndex)&&void 0!==i?i:0)-(null!==(n=e.getStyle().zIndex)&&void 0!==n?n:0)}}),this._edges=new Ss({getId:t=>t.getId(),sortBy:(t,e)=>{var i,n;return(null!==(i=t.getStyle().zIndex)&&void 0!==i?i:0)-(null!==(n=e.getStyle().zIndex)&&void 0!==n?n:0)}}),this._styleVersion=0,this._bumpStyleVersion=()=>{this._styleVersion++},this._update=t=>{if(t&&"type"in t&&"options"in t&&"isSingle"in t.options){if("node"===t.type&&t.options.isSingle){const e=this._nodes.getAll();for(let i=0;it.isSelected())}getSelectedEdges(){return this.getEdges(t=>t.isSelected())}getHoveredNodes(){return this.getNodes(t=>t.isHovered())}getHoveredEdges(){return this.getEdges(t=>t.isHovered())}getNodePositions(t){const e=this.getNodes(t),i=new Array(e.length);for(let t=0;tt.id),e=this._edges.getAll().map(t=>t.id);this.remove({nodeIds:t,edgeIds:e})}removeAllEdges(){const t=this._edges.getAll().map(t=>t.id);this.remove({edgeIds:t})}removeAllNodes(){this.removeAll()}isEqual(t){if(this.getNodeCount()!==t.getNodeCount())return!1;if(this.getEdgeCount()!==t.getEdgeCount())return!1;const e=this.getNodes();for(let i=0;ii.x&&(i.x=s+r),s-ri.y&&(i.y=o+r),o-r=0;i--)if(e[i].includesPoint(t))return e[i]}getNearestEdge(t,e=3){let i,n=e;const s=this.getEdges();for(let e=0;e{const n=i.getPosition();if(void 0===n.x||void 0===n.y)return!1;const s={x:n.x,y:n.y};return a(e,s)&&t.contains(s)})}getStyleVersion(){return this._styleVersion}_insertNodes(t){const e=new Array(t.length);for(let i=0;i{var t,e;return null===(e=null===(t=this._settings)||void 0===t?void 0:t.onLoadedImages)||void 0===e?void 0:e.call(t)},listeners:[this._update],onStateChange:this._bumpStyleVersion});this._nodes.setMany(e)}_insertEdges(t){const e=[];for(let i=0;i{var t,e;return null===(e=null===(t=this._settings)||void 0===t?void 0:t.onLoadedImages)||void 0===e?void 0:e.call(t)},listeners:[this._update],onStateChange:this._bumpStyleVersion}))}this._nodes.setMany(e)}_upsertEdges(t){const e=[],i=[];for(let n=0;n{var e;const i=new Array(t.length),n=(t=>{var e;const i={},n=new Set;for(let s=0;se+1);continue}if(r<=1)continue;const a=[];r%2!=0&&a.push(0);for(let t=2;t<=r;t+=2)a.push(t/2),a.push(t/2*-1);s[e]=a}return s})(t);for(let s=0;s{var t,e;null===(e=null===(t=this._settings)||void 0===t?void 0:t.onLoadedImages)||void 0===e||e.call(t)}),this._nodes.sort(),this._edges.sort()}}const Es=(t,e)=>{var i;null===(i=null==e?void 0:e.cascade)||void 0===i||i?Rs(t,r.SELECTED,{isStateOverride:!0}):t.setState(r.SELECTED,{isNotifySkipped:!0})},Ps=(t,e)=>{var i;null===(i=null==e?void 0:e.cascade)||void 0===i||i?Os(t,r.SELECTED,{isStateOverride:!0}):t.setState(r.SELECTED,{isNotifySkipped:!0})},As=(t,e)=>{var i;null===(i=null==e?void 0:e.cascade)||void 0===i||i?Rs(t,r.NONE,{isStateOverride:!0}):t.clearState()},Cs=(t,e)=>{var i;null===(i=null==e?void 0:e.cascade)||void 0===i||i?Os(t,r.NONE,{isStateOverride:!0}):t.clearState()},Ms=(t,e,i)=>{Ds(t),Es(e,i)},Ns=(t,e,i)=>{Ds(t),Ps(e,i)},Ds=t=>{const e=t.getNodes(t=>t.isSelected());for(let t=0;tt.isSelected());for(let t=0;t{Rs(t,r.HOVERED)},Ls=t=>{const e=t.getNodes(t=>t.isHovered());for(let t=0;tt.isHovered());for(let t=0;t{ks(t,i)&&t.setState(e,{isNotifySkipped:!0}),t.getInEdges().forEach(t=>{t&&ks(t,i)&&t.setState(e,{isNotifySkipped:!0}),t.startNode&&ks(t.startNode,i)&&t.startNode.setState(e,{isNotifySkipped:!0})}),t.getOutEdges().forEach(t=>{t&&ks(t,i)&&t.setState(e,{isNotifySkipped:!0}),t.endNode&&ks(t.endNode,i)&&t.endNode.setState(e,{isNotifySkipped:!0})})},Os=(t,e,i)=>{ks(t,i)&&t.setState(e,{isNotifySkipped:!0}),t.startNode&&ks(t.startNode,i)&&t.startNode.setState(e,{isNotifySkipped:!0}),t.endNode&&ks(t.endNode,i)&&t.endNode.setState(e,{isNotifySkipped:!0})},ks=(t,e)=>{const i=null==e?void 0:e.isStateOverride;return i||!i&&!t.getState()};class Bs{constructor(t){this.isSelectEnabled=t.isDefaultSelectEnabled,this.isHoverEnabled=t.isDefaultHoverEnabled,this.isMultiSelectEnabled=t.isDefaultMultiSelectEnabled,this.isSelectCascadeEnabled=t.isDefaultSelectCascadeEnabled}onMouseClick(t,e,i){var n;const s=this.isMultiSelectEnabled&&null!==(n=null==i?void 0:i.isAppend)&&void 0!==n&&n,o=t.getNearestNode(e);if(o)return this.isSelectEnabled&&(s?(t=>{t.isSelected()?As(t,{cascade:!1}):Es(t,{cascade:!1})})(o):Ms(t,o,{cascade:this.isSelectCascadeEnabled})),{isStateChanged:!0,changedSubject:o};const r=t.getNearestEdge(e);if(r)return this.isSelectEnabled&&(s?(t=>{t.isSelected()?Cs(t,{cascade:!1}):Ps(t,{cascade:!1})})(r):Ns(t,r,{cascade:this.isSelectCascadeEnabled})),{isStateChanged:!0,changedSubject:r};if(!this.isSelectEnabled||s)return{isStateChanged:!1};const{changedCount:a}=Ds(t);return{isStateChanged:a>0}}onMouseMove(t,e){const i=t.getNearestNode(e);if(i&&(!this.isSelectEnabled||this.isSelectEnabled&&!i.isSelected()))return i===this._lastHoveredNode?{changedSubject:i,isStateChanged:!1}:(this.isHoverEnabled&&((t,e)=>{Ls(t),Is(e)})(t,i),this._lastHoveredNode=i,{isStateChanged:!0,changedSubject:i});if(this._lastHoveredNode=void 0,!i&&this.isHoverEnabled){const{changedCount:e}=Ls(t);return{isStateChanged:e>0}}return{isStateChanged:!1}}onMouseRightClick(t,e){const i=t.getNearestNode(e);if(i)return this.isSelectEnabled&&Ms(t,i,{cascade:this.isSelectCascadeEnabled}),{isStateChanged:!0,changedSubject:i};const n=t.getNearestEdge(e);if(n)return this.isSelectEnabled&&Ns(t,n,{cascade:this.isSelectCascadeEnabled}),{isStateChanged:!0,changedSubject:n};if(!this.isSelectEnabled)return{isStateChanged:!1};const{changedCount:s}=Ds(t);return{isStateChanged:s>0}}onMouseDoubleClick(t,e){const i=t.getNearestNode(e);if(i)return this.isSelectEnabled&&Ms(t,i,{cascade:this.isSelectCascadeEnabled}),{isStateChanged:!0,changedSubject:i};const n=t.getNearestEdge(e);if(n)return this.isSelectEnabled&&Ns(t,n,{cascade:this.isSelectCascadeEnabled}),{isStateChanged:!0,changedSubject:n};if(!this.isSelectEnabled)return{isStateChanged:!1};const{changedCount:s}=Ds(t);return{isStateChanged:s>0}}}var zs,Us;!function(t){t.CANVAS="canvas",t.WEBGL="webgl"}(zs||(zs={})),function(t){t.RESIZE="resize",t.RENDER_START="render-start",t.RENDER_END="render-end"}(Us||(Us={}));const Fs={devicePixelRatio:null,fps:60,minZoom:.25,maxZoom:8,fitZoomMargin:.2,labelsIsEnabled:!0,labelsOnEventIsEnabled:!0,shadowIsEnabled:!0,shadowOnEventIsEnabled:!0,contextAlphaOnEvent:.3,contextAlphaOnEventIsEnabled:!0,backgroundColor:null,areCollapsedContainerDimensionsAllowed:!1},js="Roboto, sans-serif";var Ws;!function(t){t.TOP="top",t.MIDDLE="middle"}(Ws||(Ws={}));class Gs{constructor(t,e){var i,n;this.textLines=[],this.fontSize=4,this.fontFamily=qs(4,js),this.text=`${void 0===t?"":t}`,this.textLines=Vs(this.text),this.position=e.position,this.properties=e.properties,this.textBaseline=e.textBaseline,(void 0!==this.properties.fontSize||this.properties.fontFamily)&&(this.fontSize=Math.max(null!==(i=this.properties.fontSize)&&void 0!==i?i:0,0),this.fontFamily=qs(this.fontSize,null!==(n=this.properties.fontFamily)&&void 0!==n?n:js)),this._fixPosition()}_fixPosition(){if(this.textBaseline===Ws.MIDDLE&&this.textLines.length){const t=Math.floor(this.textLines.length/2),e=(this.textLines.length-1)/2;this.position.y-=e*this.fontSize-t*(1.2-1)}}}const Zs=(t,e)=>{e.textLines.length>0&&e.fontSize>0&&e.position&&(Hs(t,e),Xs(t,e))},Hs=(t,e)=>{if(!e.properties.fontBackgroundColor||!e.position)return;t.fillStyle=e.properties.fontBackgroundColor.toString();const i=.12*e.fontSize,n=e.fontSize+2*i,s=1.2*e.fontSize,o=e.textBaseline===Ws.MIDDLE?e.fontSize/2:0;for(let r=0;r{var i;if(!e.position)return;t.fillStyle=(null!==(i=e.properties.fontColor)&&void 0!==i?i:"#000000").toString(),t.font=e.fontFamily,t.textBaseline=e.textBaseline,t.textAlign="center";const n=1.2*e.fontSize;for(let i=0;i`${t}px ${e}`,Vs=t=>{const e=t.split("\n"),i=[];for(let t=0;t{var e,i;const n=null!==(e=t.getStyle().arrowSize)&&void 0!==e?e:1,s=null!==(i=t.getWidth())&&void 0!==i?i:1,o=t.endNode,r=t.getCurvedControlPoint(),a=Ks(t,o),h=$s(t,Math.max(0,Math.min(1,a.t+-.1)),r),l=Math.atan2(a.y-h.y,a.x-h.x),d=1.5*n+3*s;return{point:a,core:{x:a.x-.9*d*Math.cos(l),y:a.y-.9*d*Math.sin(l)},angle:l,length:d}},$s=(t,e,i)=>{const n=t.startNode.getCenter(),s=t.endNode.getCenter();if(!n||!s)return{x:0,y:0};const o=e;return{x:Math.pow(1-o,2)*n.x+2*o*(1-o)*i.x+Math.pow(o,2)*s.x,y:Math.pow(1-o,2)*n.y+2*o*(1-o)*i.y+Math.pow(o,2)*s.y}},Ks=(t,e)=>{let i,n,s,o=0,r=0,a=1,h={x:0,y:0,t:0};const l=t.getCurvedControlPoint();let d=t.endNode,u=!1;e.getId()===t.startNode.getId()&&(d=t.startNode,u=!0);const c=d.getCenter();let _;for(;r<=a&&o<10&&(_=.5*(r+a),h=Object.assign(Object.assign({},$s(t,_,l)),{t:0}),i=d.getDistanceToBorder(),n=Math.sqrt(Math.pow(h.x-c.x,2)+Math.pow(h.y-c.y,2)),s=i-n,!(Math.abs(s)<.2));)s<0?!1===u?r=_:a=_:!1===u?a=_:r=_,o++;return h.t=null!=_?_:0,h},Qs=t=>{var e,i;const n=null!==(e=t.getStyle().arrowSize)&&void 0!==e?e:1,s=null!==(i=t.getWidth())&&void 0!==i?i:1,o=t.startNode,r=to(t,o),a=-2*r.t*Math.PI+.45*Math.PI,h=1.5*n+3*s;return{point:r,core:{x:r.x-.9*h*Math.cos(a),y:r.y-.9*h*Math.sin(a)},angle:a,length:h}},Js=(t,e)=>{const i=2*e*Math.PI;return{x:t.x+t.radius*Math.cos(i),y:t.y-t.radius*Math.sin(i)}},to=(t,e)=>{const i=t.getCircularData();let n=.6,s=1;let o,r,a,h=0,l={x:0,y:0,t:0},d=.5*(n+s);const u=e.getCenter();for(;n<=s&&h<10&&(d=.5*(n+s),l=Object.assign(Object.assign({},Js(i,d)),{t:0}),o=e.getDistanceToBorder(),r=Math.sqrt(Math.pow(l.x-u.x,2)+Math.pow(l.y-u.y,2)),a=o-r,!(Math.abs(a)<.05));)a>0?n=d:s=d,h++;return l.t=null!=d?d:0,l},eo=t=>{var e,i;const n=null!==(e=t.getStyle().arrowSize)&&void 0!==e?e:1,s=null!==(i=t.getWidth())&&void 0!==i?i:1,o=t.startNode.getCenter(),r=t.endNode.getCenter(),a=Math.atan2(r.y-o.y,r.x-o.x),h=io(t,t.endNode),l=1.5*n+3*s;return{point:h,core:{x:h.x-.9*l*Math.cos(a),y:h.y-.9*l*Math.sin(a)},angle:a,length:l}},io=(t,e)=>{let i=t.endNode,n=t.startNode;e.getId()===t.startNode.getId()&&(i=t.startNode,n=t.endNode);const s=i.getCenter(),o=n.getCenter(),r=s.x-o.x,a=s.y-o.y,h=Math.sqrt(r*r+a*a),l=(h-e.getDistanceToBorder())/h;return{x:(1-l)*o.x+l*s.x,y:(1-l)*o.y+l*s.y,t:0}},no=t=>{if(t instanceof k)return eo(t);if(t instanceof B)return Ys(t);if(t instanceof z)return Qs(t);throw new Error("Failed to draw unsupported edge type")},so=(t,e)=>{const i=e.point.x,n=e.point.y,s=e.angle,o=e.length;for(let e=0;e{const i=e.getCenter(),n=e.getRadius();switch(e.getStyle().shape){case w.SQUARE:((t,e,i,n)=>{t.beginPath(),t.rect(e-n,i-n,2*n,2*n),t.closePath()})(t,i.x,i.y,n);break;case w.DIAMOND:((t,e,i,n)=>{t.beginPath(),t.lineTo(e,i+n),t.lineTo(e+n,i),t.lineTo(e,i-n),t.lineTo(e-n,i),t.closePath()})(t,i.x,i.y,n);break;case w.TRIANGLE:((t,e,i,n)=>{t.beginPath(),i+=.275*(n*=1.15);const s=2*n,o=Math.sqrt(3)*s/6,r=Math.sqrt(s*s-n*n);t.moveTo(e,i-(r-o)),t.lineTo(e+n,i+o),t.lineTo(e-n,i+o),t.lineTo(e,i-(r-o)),t.closePath()})(t,i.x,i.y,n);break;case w.TRIANGLE_DOWN:((t,e,i,n)=>{t.beginPath(),i-=.275*(n*=1.15);const s=2*n,o=Math.sqrt(3)*s/6,r=Math.sqrt(s*s-n*n);t.moveTo(e,i+(r-o)),t.lineTo(e+n,i-o),t.lineTo(e-n,i-o),t.lineTo(e,i+(r-o)),t.closePath()})(t,i.x,i.y,n);break;case w.STAR:((t,e,i,n)=>{t.beginPath(),i+=.1*(n*=.82);for(let s=0;s<10;s++){const o=n*(s%2==0?1.3:.5),r=e+o*Math.sin(2*s*Math.PI/10),a=i-o*Math.cos(2*s*Math.PI/10);t.lineTo(r,a)}t.closePath()})(t,i.x,i.y,n);break;case w.HEXAGON:((t,e,i,n)=>{((t,e,i,n,s)=>{t.beginPath(),t.moveTo(e+n,i);const o=2*Math.PI/s;for(let r=1;r{t.beginPath(),t.arc(e,i,n,0,2*Math.PI,!1),t.closePath()})(t,i.x,i.y,n)}},ro=(t,e=300)=>{let i=0,n=null;return function(){const s=arguments,o=Date.now(),r=e-(o-i);r<=0?(n&&(clearTimeout(n),n=null),i=o,t(...s)):n||(n=setTimeout(()=>{i=Date.now(),n=null,t(...s)},r))}},ao=t=>{const e=Math.max(t,1);return Math.round(1e3/e)},ho=(t,e=!1)=>{t.style.position="relative";const i=getComputedStyle(t);i.display||(t.style.display="block",console.warn("[Orb] Graph container doesn't have defined 'display' property. Setting 'display' to 'block'...")),!e&&uo(i.width)&&(t.style.width="100%",uo(getComputedStyle(t).width)?(t.style.width="400px",console.warn("[Orb] The graph container element and its parent don't have defined width properties.","If you are using percentage values,","please make sure that the parent element of the graph container has a defined position and width.","Setting the width of the graph container to an arbitrary value of '400px'...")):console.warn("[Orb] The graph container element doesn't have defined width. Setting width to 100%...")),!e&&uo(i.height)&&(t.style.height="100%",uo(getComputedStyle(t).height)?(t.style.height="400px",console.warn("[Orb] The graph container element and its parent don't have defined height properties.","If you are using percentage values,","please make sure that the parent element of the graph container has a defined position and height.","Setting the height of the graph container to an arbitrary value of '400px'...")):console.warn("[Orb] Graph container doesn't have defined height. Setting height to 100%..."))},lo=/^\s*0+\s*(?:px|rem|em|vh|vw)?\s*$/i,uo=t=>null==t||""===t||lo.test(t),co=t=>{const e=document.createElement("canvas");return e.style.position="absolute",e.style.top="0",e.style.left="0",t.appendChild(e),e},_o=t=>{let e=window.devicePixelRatio,i=()=>{};const n=()=>{i();const s=matchMedia(`(resolution: ${e}dppx)`);s.addEventListener("change",n),i=()=>s.removeEventListener("change",n),window.devicePixelRatio!==e&&(e=window.devicePixelRatio,t(e))};return n(),()=>i()};class fo extends t{constructor(t,e){super(),this._isOriginCentered=!1,this._isInitiallyRendered=!1,ho(t,null==e?void 0:e.areCollapsedContainerDimensionsAllowed),this._container=t,this._canvas=co(t);const i=this._canvas.getContext("2d");if(!i)throw new o("Failed to create Canvas context.");this._context=i,this._width=640,this._height=480,this.transform=En,this._settings=Object.assign(Object.assign({},Fs),e),this._resizeObs=new ResizeObserver(()=>this._resize()),this._resizeObs.observe(this._container),this._resize(),u(null==e?void 0:e.devicePixelRatio)||(this._dprObserveUnsubscribe=_o(()=>this._resize())),this._throttleRender=ro(t=>{this._render(t)},ao(this._settings.fps))}get width(){return this._width}get height(){return this._height}get container(){return this._container}get canvas(){return this._canvas}get isInitiallyRendered(){return this._isInitiallyRendered}getSettings(){return m(this._settings)}setSettings(t){var e;const i=t.fps&&t.fps!==this._settings.fps,n=this._settings.devicePixelRatio,s=t.devicePixelRatio;this._settings=Object.assign(Object.assign({},this._settings),t),i&&(this._throttleRender=ro(t=>{this._render(t)},ao(this._settings.fps))),!u(n)&&u(s)&&(null===(e=this._dprObserveUnsubscribe)||void 0===e||e.call(this),this._resize()),u(n)&&null===s&&(this._dprObserveUnsubscribe=_o(()=>this._resize()))}render(t){this._throttleRender(t)}_render(t){this.emit(Us.RENDER_START,void 0);const e=Date.now();this._context.clearRect(0,0,this._width,this._height),this._settings.backgroundColor&&(this._context.fillStyle=this._settings.backgroundColor.toString(),this._context.fillRect(0,0,this._width,this._height)),this._context.save(),this._context.translate(this.transform.x,this.transform.y),this._context.scale(this.transform.k,this.transform.k),this._isOriginCentered&&this._context.translate(this._width/2,this._height/2),this.drawObjects(t.getEdges()),this.drawObjects(t.getNodes()),this._context.restore(),this.emit(Us.RENDER_END,{durationMs:Date.now()-e}),this._isInitiallyRendered=!0}drawObjects(t){if(0===t.length)return;const e=[],i=[];for(let n=0;n{var n,s;const o=null===(n=null==i?void 0:i.isShadowEnabled)||void 0===n||n,r=null===(s=null==i?void 0:i.isLabelEnabled)||void 0===s||s,a=e.hasShadow();((t,e)=>{if(e.hasBorder()){t.lineWidth=e.getBorderWidth();const i=e.getBorderColor();i&&(t.strokeStyle=i.toString())}const i=e.getColor();i&&(t.fillStyle=i.toString())})(t,e),o&&a&&((t,e)=>{const i=e.getStyle();i.shadowColor&&(t.shadowColor=i.shadowColor.toString()),i.shadowSize&&(t.shadowBlur=i.shadowSize),i.shadowOffsetX&&(t.shadowOffsetX=i.shadowOffsetX),i.shadowOffsetY&&(t.shadowOffsetY=i.shadowOffsetY)})(t,e),oo(t,e),t.fill();const h=e.getBackgroundImage();h&&((t,e,i)=>{if(!i.width||!i.height)return;const n=e.getCenter(),s=e.getRadius(),o=Math.max(2*s/i.width,2*s/i.height),r=i.height*o,a=i.width*o;t.save(),t.clip(),t.drawImage(i,n.x-a/2,n.y-r/2,a,r),t.restore()})(t,e,h),o&&a&&((t,e)=>{const i=e.getStyle();i.shadowColor&&(t.shadowColor="rgba(0,0,0,0)"),i.shadowSize&&(t.shadowBlur=0),i.shadowOffsetX&&(t.shadowOffsetX=0),i.shadowOffsetY&&(t.shadowOffsetY=0)})(t,e),e.hasBorder()&&t.stroke(),r&&((t,e)=>{const i=e.getLabel();if(!i)return;const n=e.getCenter(),s=1.2*e.getBorderedRadius(),o=e.getStyle(),r=new Gs(i,{position:{x:n.x,y:n.y+s},textBaseline:Ws.TOP,properties:{fontBackgroundColor:o.fontBackgroundColor,fontColor:o.fontColor,fontFamily:o.fontFamily,fontSize:o.fontSize}});Zs(t,r)})(t,e)})(this._context,t,e):((t,e,i)=>{var n,s;if(!e.getWidth())return;const o=null===(n=null==i?void 0:i.isShadowEnabled)||void 0===n||n,r=null===(s=null==i?void 0:i.isLabelEnabled)||void 0===s||s,a=e.hasShadow();((t,e)=>{const i=e.getWidth();i>0&&(t.lineWidth=i);const n=e.getColor();n&&(t.strokeStyle=n.toString(),t.fillStyle=n.toString())})(t,e),o&&a&&((t,e)=>{const i=e.getStyle();i.shadowColor&&(t.shadowColor=i.shadowColor.toString()),i.shadowSize&&(t.shadowBlur=i.shadowSize),i.shadowOffsetX&&(t.shadowOffsetX=i.shadowOffsetX),i.shadowOffsetY&&(t.shadowOffsetY=i.shadowOffsetY)})(t,e),((t,e)=>{if(0===e.getStyle().arrowSize)return;const i=no(e),n=so([{x:0,y:0},{x:-1,y:.4},{x:-1,y:-.4}],i);t.beginPath();for(let e=0;e{if(e instanceof k)return((t,e)=>{const i=e.startNode.getCenter(),n=e.endNode.getCenter();if(!i||!n)return;t.beginPath(),t.moveTo(i.x,i.y),t.lineTo(n.x,n.y);const s=e.getLineDashPattern();t.setLineDash(null!=s?s:[]),t.stroke()})(t,e);if(e instanceof B)return((t,e)=>{const i=e.startNode.getCenter(),n=e.endNode.getCenter();if(!i||!n)return;const s=e.getCurvedControlPoint();t.beginPath(),t.moveTo(i.x,i.y),t.quadraticCurveTo(s.x,s.y,n.x,n.y);const o=e.getLineDashPattern();t.setLineDash(null!=o?o:[]),t.stroke()})(t,e);if(e instanceof z)return((t,e)=>{const{x:i,y:n,radius:s}=e.getCircularData();t.beginPath(),t.arc(i,n,s,0,2*Math.PI,!1),t.closePath();const o=e.getLineDashPattern();t.setLineDash(null!=o?o:[]),t.stroke()})(t,e);throw new Error("Failed to draw unsupported edge type")})(t,e),o&&a&&((t,e)=>{const i=e.getStyle();i.shadowColor&&(t.shadowColor="rgba(0,0,0,0)"),i.shadowSize&&(t.shadowBlur=0),i.shadowOffsetX&&(t.shadowOffsetX=0),i.shadowOffsetY&&(t.shadowOffsetY=0)})(t,e),r&&((t,e)=>{const i=e.getLabel();if(!i)return;const n=e.getStyle(),s=new Gs(i,{position:e.getCenter(),textBaseline:Ws.MIDDLE,properties:{fontBackgroundColor:n.fontBackgroundColor,fontColor:n.fontColor,fontFamily:n.fontFamily,fontSize:n.fontSize}});Zs(t,s)})(t,e)})(this._context,t,e)}reset(){this.transform=En,this._context.clearRect(0,0,this._width,this._height),this._context.save()}getFitZoomTransform(t,e){const i=t.getBoundingBox(),n="center"===(null==e?void 0:e.anchorX)?i.x+i.width/2:"end"===(null==e?void 0:e.anchorX)?i.x+i.width:0,s="center"===(null==e?void 0:e.anchorY)?i.y+i.height/2:"end"===(null==e?void 0:e.anchorY)?i.y+i.height:0,o=this.getSimulationViewRectangle(),r=o.height/(i.height*(1+this._settings.fitZoomMargin)),a=o.width/(i.width*(1+this._settings.fitZoomMargin)),h=Math.min(r,a),l=this.transform.k,d=Math.max(Math.min(h*l,this._settings.maxZoom),this._settings.minZoom),u=o.width/2*l*(1-d)-n*d,c=o.height/2*l*(1-d)-s*d;return En.translate(u,c).scale(d)}getSimulationPosition(t){const[e,i]=this.transform.invert([t.x,t.y]);return{x:e-this._width/2,y:i-this._height/2}}getCanvasPosition(t){const[e,i]=this.transform.apply([t.x+this._width/2,t.y+this._height/2]);return{x:e,y:i}}getSimulationViewRectangle(){const t=this.getSimulationPosition({x:0,y:0}),e=this.getSimulationPosition({x:this._width,y:this._height});return{x:t.x,y:t.y,width:e.x-t.x,height:e.y-t.y}}translateOriginToCenter(){this._isOriginCentered=!0}destroy(){var t;this._resizeObs.unobserve(this._container),null===(t=this._dprObserveUnsubscribe)||void 0===t||t.call(this),this.removeAllListeners(),this._canvas.remove()}}const go=(t,e,i)=>{const n=ls(t,e,hs.VERTEX),s=ls(t,i,hs.FRAGMENT),r=t.createProgram();if(!r)throw new o("Failed to create GL program.");if(t.attachShader(r,n),t.attachShader(r,s),t.linkProgram(r),!t.getProgramParameter(r,t.LINK_STATUS)){const e=t.getProgramInfoLog(r);throw t.deleteProgram(r),new o(`Failed to link GL program: ${e}`)}return t.deleteShader(n),t.deleteShader(s),r},po=2048,mo=2048;class vo{constructor(t){this._texture=null,this._cache=new Map,this._shelves=[],this._isDirty=!1,this._isTextureAllocated=!1,this._gl=t,this._canvas=document.createElement("canvas"),this._canvas.width=po,this._canvas.height=mo,this._ctx=this._canvas.getContext("2d",{willReadFrequently:!1}),this._texture=t.createTexture(),t.bindTexture(t.TEXTURE_2D,this._texture),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.bindTexture(t.TEXTURE_2D,null)}getOrCreate(t,e,i,n,s){const o=`${t}|${e}|${i}|${n}|${null!=s?s:""}`,r=this._cache.get(o);if(r)return r;const a=t.split("\n").map(t=>t.trim());if(0===a.length||1===a.length&&""===a[0])return null;const h=this._ctx,l=`48px ${i}`;h.font=l;let d=0;for(let t=0;td&&(d=e)}const u=48*1.2,c=48+(a.length-1)*u,_=Math.ceil(d+11.52)+4,f=Math.ceil(c+11.52)+4,g=this._allocate(_,f);if(!g)return null;const p=g.x+2,m=g.y+2;s&&(h.fillStyle=s,h.fillRect(p,m,_-4,f-4)),h.font=l,h.fillStyle=n,h.textBaseline="top",h.textAlign="center";const v=p+(_-4)/2;for(let t=0;tmo)return null;const n={y:i,height:e,x:t};return this._shelves.push(n),{x:0,y:i}}}const yo=2048,xo=2048;class bo{constructor(t){this._texture=null,this._cache=new Map,this._pending=new Map,this._shelves=[],this._isDirty=!1,this._isTextureAllocated=!1,this._gl=t,this._canvas=document.createElement("canvas"),this._canvas.width=yo,this._canvas.height=xo,this._ctx=this._canvas.getContext("2d",{willReadFrequently:!1}),this._texture=t.createTexture(),t.bindTexture(t.TEXTURE_2D,this._texture),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.bindTexture(t.TEXTURE_2D,null)}getOrCreate(t){const e=this._cache.get(t);if(e)return e;const i=this._pending.get(t);if(i)return i.loaded?this._packImage(t,i.image):null;const n=new Image;n.crossOrigin="anonymous";const s={image:n,loaded:!1};return this._pending.set(t,s),n.onload=()=>{s.loaded=!0},n.onerror=()=>{this._pending.delete(t)},n.src=t,null}bind(t){const e=this._gl;e.activeTexture(e.TEXTURE0+t),e.bindTexture(e.TEXTURE_2D,this._texture)}uploadIfDirty(){if(!this._isDirty)return;const t=this._gl;t.bindTexture(t.TEXTURE_2D,this._texture),this._isTextureAllocated||(t.texImage2D(t.TEXTURE_2D,0,t.RGBA,yo,xo,0,t.RGBA,t.UNSIGNED_BYTE,null),this._isTextureAllocated=!0),t.texSubImage2D(t.TEXTURE_2D,0,0,0,t.RGBA,t.UNSIGNED_BYTE,this._canvas),t.bindTexture(t.TEXTURE_2D,null),this._isDirty=!1}clear(){this._cache.clear(),this._pending.clear(),this._shelves=[],this._isDirty=!1,this._ctx.clearRect(0,0,yo,xo)}_packImage(t,e){if(!e.naturalWidth||!e.naturalHeight)return null;const i=e.naturalWidth/e.naturalHeight;let n,s;e.naturalWidth>=e.naturalHeight?(n=Math.min(e.naturalWidth,128),s=Math.round(n/i)):(s=Math.min(e.naturalHeight,128),n=Math.round(s*i));const o=n+4,r=s+4,a=this._allocate(o,r);if(!a)return null;this._ctx.drawImage(e,a.x+2,a.y+2,n,s);const h={u0:(a.x+2)/yo,v0:(a.y+2)/xo,u1:(a.x+2+n)/yo,v1:(a.y+2+s)/xo,aspect:i};return this._cache.set(t,h),this._pending.delete(t),this._isDirty=!0,h}_allocate(t,e){for(let i=0;ixo)return null;const n={y:i,height:e,x:t};return this._shelves.push(n),{x:0,y:i}}}const So=[0,0,0,0],wo=[.6,.6,.6,1],To=[1,0,0,1],Eo={[w.CIRCLE]:0,[w.DOT]:1,[w.SQUARE]:2,[w.DIAMOND]:3,[w.TRIANGLE]:4,[w.TRIANGLE_DOWN]:5,[w.STAR]:6,[w.HEXAGON]:7},Po="Roboto, sans-serif",Ao="#000000";class Co extends t{constructor(t,e){super(),this._isOriginCentered=!1,this._isInitiallyRendered=!1,this._nodeProgram=null,this._edgeProgram=null,this._labelProgram=null,this._nodeVao=null,this._edgeVao=null,this._labelVao=null,this._nodeInstanceBuffer=null,this._edgeInstanceBuffer=null,this._labelInstanceBuffer=null,this._labelCache=null,this._imageAtlas=null,this._isColorCacheDirty=!0,this._nodeColorCache=new Map,this._nodeBorderColorCache=new Map,this._nodeShadowColorCache=new Map,this._edgeColorCache=new Map,this._edgeShadowColorCache=new Map,this._lastNodeCount=0,this._lastEdgeCount=0,this._edgeInstanceData=null,this._nodeInstanceData=null,this._buffersAreCurrent=!1,this._bufferCacheStats={hits:0,misses:0},this._timerExt=null,this._timerEdgeQueries=[],this._timerNodeQueries=[],this._timerQueryIdx=0,this._lastEdgeGpuMs=null,this._lastNodeGpuMs=null,this._lastStyleVersion=-1,ho(t,null==e?void 0:e.areCollapsedContainerDimensionsAllowed),this._container=t,this._canvas=co(t);const i=this._canvas.getContext("webgl2",{antialias:!0});if(!i)throw new o("Failed to create WebGL context.");if(this._gl=i,this._width=640,this._height=480,this.transform=En,this._settings=Object.assign(Object.assign({},Fs),e),"number"!=typeof(null==e?void 0:e.devicePixelRatio)&&(this._dprObserveUnsubscribe=_o(()=>{this._isInitiallyRendered&&this.emit(Us.RESIZE,void 0)})),this._initShaders(),this._initNodeBuffers(),this._initEdgeBuffers(),this._initLabelBuffers(),this._labelCache=new vo(this._gl),this._imageAtlas=new bo(this._gl),this._timerExt=i.getExtension("EXT_disjoint_timer_query_webgl2"),this._timerExt)for(let t=0;t<4;t++){const t=i.createQuery(),e=i.createQuery();t&&this._timerEdgeQueries.push(t),e&&this._timerNodeQueries.push(e)}}_pollTimerQuery(t){if(!this._timerExt)return null;const e=this._gl;return e.getQueryParameter(t,e.QUERY_RESULT_AVAILABLE)?e.getParameter(this._timerExt.GPU_DISJOINT_EXT)?null:e.getQueryParameter(t,e.QUERY_RESULT)/1e6:null}getGpuTimeStats(){return{edgeMs:this._lastEdgeGpuMs,nodeMs:this._lastNodeGpuMs,supported:null!==this._timerExt}}_initShaders(){this._nodeProgram=go(this._gl,"#version 300 es\n\nprecision highp float;\n\nin vec2 aQuadPosition;\n\nin vec2 aCenter;\nin float aRadius;\nin vec4 aColor;\nin vec4 aBorderColor;\nin float aBorderWidth;\nin vec4 aShadowColor;\nin float aShadowSize;\nin float aShadowOffsetX;\nin float aShadowOffsetY;\nin float aShapeType;\nin vec2 aImageUV0;\nin vec2 aImageUV1;\nin float aImageAspect;\n\nuniform vec2 uResolution;\nuniform vec2 uTranslation;\nuniform float uScale;\nuniform vec2 uOriginOffset;\n\nout vec2 vUV;\nout vec4 vColor;\nout vec4 vBorderColor;\nout float vBorderThreshold;\nout vec4 vShadowColor;\nout float vNodeRadius;\nout vec2 vShadowOffset;\nout float vShadowBlur;\nflat out int vShapeType;\nout vec2 vImageUV0;\nout vec2 vImageUV1;\nout float vImageAspect;\n\nvoid main() {\n vShapeType = int(aShapeType + 0.5);\n vColor = aColor;\n vBorderColor = aBorderColor;\n vShadowColor = aShadowColor;\n vImageUV0 = aImageUV0;\n vImageUV1 = aImageUV1;\n vImageAspect = aImageAspect;\n\n float totalRadius = aRadius + aShadowSize + abs(aShadowOffsetX) + abs(aShadowOffsetY);\n\n vUV = aQuadPosition;\n vNodeRadius = aRadius / totalRadius;\n\n vBorderThreshold = vNodeRadius * (1.0 - aBorderWidth / aRadius);\n\n vShadowOffset = vec2(aShadowOffsetX, aShadowOffsetY) / totalRadius;\n\n vShadowBlur = aShadowSize / totalRadius;\n\n vec2 worldPos = aCenter + aQuadPosition * totalRadius;\n vec2 screenPos = (worldPos + uOriginOffset) * uScale + uTranslation;\n\n vec2 clip = (screenPos / uResolution) * 2.0 - 1.0;\n gl_Position = vec4(clip.x, -clip.y, 0.0, 1.0);\n}\n","#version 300 es\n\nprecision highp float;\n\nin vec2 vUV;\nin vec4 vColor;\nin vec4 vBorderColor;\nin float vBorderThreshold;\nin vec4 vShadowColor;\nin float vNodeRadius;\nin vec2 vShadowOffset;\nin float vShadowBlur;\nflat in int vShapeType;\nin vec2 vImageUV0;\nin vec2 vImageUV1;\nin float vImageAspect;\n\nuniform sampler2D uImageAtlas;\n\nout vec4 fragColor;\n\nconst int SHAPE_CIRCLE = 0;\nconst int SHAPE_DOT = 1;\nconst int SHAPE_SQUARE = 2;\nconst int SHAPE_DIAMOND = 3;\nconst int SHAPE_TRIANGLE = 4;\nconst int SHAPE_TRIANGLE_DOWN = 5;\nconst int SHAPE_STAR = 6;\nconst int SHAPE_HEXAGON = 7;\n\nfloat sdCircle(vec2 p, float r) {\n return length(p) - r;\n}\n\nfloat sdSquare(vec2 p, float r) {\n vec2 d = abs(p) - vec2(r);\n return max(d.x, d.y);\n}\n\nfloat sdDiamond(vec2 p, float r) {\n return (abs(p.x) + abs(p.y)) - r;\n}\n\nfloat sdTriangleDown(vec2 p, float r) {\n float sr = r * 1.15;\n vec2 q = vec2(p.x, p.y - 0.275 * sr);\n\n float k = sqrt(3.0);\n q.x = abs(q.x) - sr;\n q.y = q.y + sr / k;\n if (q.x + k * q.y > 0.0) {\n q = vec2(q.x - k * q.y, -k * q.x - q.y) / 2.0;\n }\n q.x -= clamp(q.x, -2.0 * sr, 0.0);\n return -length(q) * sign(q.y);\n}\n\nfloat sdTriangleUp(vec2 p, float r) {\n return sdTriangleDown(vec2(p.x, -p.y), r);\n}\n\nfloat sdStar(vec2 p, float r) {\n float sr = r * 0.82;\n vec2 q = vec2(p.x, p.y - 0.1 * sr);\n\n float outerR = sr * 1.3;\n float innerR = sr * 0.5;\n\n float angle = atan(q.x, -q.y);\n float sector = 6.2831853 / 5.0;\n float a = mod(angle + sector * 0.5, sector) - sector * 0.5;\n\n float cosA = cos(a);\n float sinA = abs(sin(a));\n\n float halfSector = sector * 0.5;\n vec2 outerPt = vec2(outerR, 0.0);\n vec2 innerPt = vec2(innerR * cos(halfSector), innerR * sin(halfSector));\n\n vec2 sp = vec2(cosA, sinA) * length(q);\n\n vec2 edge = innerPt - outerPt;\n vec2 toP = sp - outerPt;\n float t = clamp(dot(toP, edge) / dot(edge, edge), 0.0, 1.0);\n float dist = length(toP - edge * t);\n\n float cross2d = edge.x * toP.y - edge.y * toP.x;\n return cross2d > 0.0 ? -dist : dist;\n}\n\nfloat sdHexagon(vec2 p, float r) {\n vec2 q = abs(p);\n float k = sqrt(3.0);\n float d = max(q.x, (q.x * 0.5 + q.y * (k * 0.5)));\n return d - r;\n}\n\nfloat shapeSDF(vec2 p, float r, int shapeType) {\n if (shapeType == SHAPE_SQUARE) return sdSquare(p, r);\n if (shapeType == SHAPE_DIAMOND) return sdDiamond(p, r);\n if (shapeType == SHAPE_TRIANGLE) return sdTriangleUp(p, r);\n if (shapeType == SHAPE_TRIANGLE_DOWN) return sdTriangleDown(p, r);\n if (shapeType == SHAPE_STAR) return sdStar(p, r);\n if (shapeType == SHAPE_HEXAGON) return sdHexagon(p, r);\n\n return sdCircle(p, r);\n}\n\nvoid main() {\n // Body SDF - always needed.\n float dist = shapeSDF(vUV, vNodeRadius, vShapeType);\n\n float aa = 0.02 * vNodeRadius;\n float nodeAlpha = 1.0 - smoothstep(-aa, 0.0, dist);\n\n // Shadow SDF - skip entirely when no shadow. Avoids a second full shapeSDF() call\n // (which is a cascade of ifs) and the exp() per fragment.\n float shadowAlpha = 0.0;\n if (vShadowBlur > 0.0) {\n float shadowDist = shapeSDF(vUV - vShadowOffset, vNodeRadius, vShapeType);\n float t = max(shadowDist, 0.0) / vShadowBlur;\n shadowAlpha = exp(-t * t * 1.5) * 0.5 * vShadowColor.a;\n }\n\n vec4 fillColor = vColor;\n if (vImageAspect > 0.0 && dist < 0.0) {\n vec2 uv01 = (vUV / vNodeRadius) * 0.5 + 0.5;\n if (vImageAspect > 1.0) {\n uv01.x = (uv01.x - 0.5) / vImageAspect + 0.5;\n } else {\n uv01.y = (uv01.y - 0.5) * vImageAspect + 0.5;\n }\n if (uv01.x >= 0.0 && uv01.x <= 1.0 && uv01.y >= 0.0 && uv01.y <= 1.0) {\n vec2 atlasUV = mix(vImageUV0, vImageUV1, uv01);\n vec4 imgTexel = texture(uImageAtlas, atlasUV);\n fillColor = mix(fillColor, vec4(imgTexel.rgb, 1.0), imgTexel.a);\n }\n }\n\n vec4 nodeColor;\n if (vBorderThreshold < vNodeRadius) {\n float borderDist = shapeSDF(vUV, vBorderThreshold, vShapeType);\n float borderMix = smoothstep(-aa, aa, borderDist);\n nodeColor = mix(fillColor, vBorderColor, borderMix);\n } else {\n nodeColor = fillColor;\n }\n nodeColor.a *= nodeAlpha;\n\n float finalAlpha = nodeColor.a + shadowAlpha * (1.0 - nodeColor.a);\n\n if (finalAlpha < 0.001) {\n discard;\n }\n\n if (shadowAlpha > 0.0) {\n vec3 finalRGB = (nodeColor.rgb * nodeColor.a + vShadowColor.rgb * shadowAlpha * (1.0 - nodeColor.a)) / finalAlpha;\n fragColor = vec4(finalRGB, finalAlpha);\n } else {\n fragColor = nodeColor;\n }\n}\n"),this._edgeProgram=go(this._gl,"#version 300 es\n\nprecision highp float;\n\nin vec2 aQuadPosition;\n\nin vec2 aStart;\nin vec2 aEnd;\nin vec2 aControl;\nin float aWidth;\nin float aEdgeType;\nin float aLoopbackRadius;\nin float aArrowSize;\nin vec2 aArrowTip;\nin vec2 aArrowDir;\nin vec4 aColor;\nin vec4 aShadowColor;\nin float aShadowSize;\nin float aShadowOffsetX;\nin float aShadowOffsetY;\n\nuniform vec2 uResolution;\nuniform vec2 uTranslation;\nuniform float uScale;\nuniform vec2 uOriginOffset;\n\nout vec2 vWorldPos;\nout vec2 vStart;\nout vec2 vEnd;\nout vec2 vControl;\nout float vHalfWidth;\nout float vWidthFade;\nout float vHalfWidthPx;\nout float vPerpPx;\nout float vLoopbackRadius;\nout float vArrowSize;\nout vec2 vArrowTip;\nout vec2 vArrowDir;\nout vec4 vColor;\nout vec4 vShadowColor;\nout float vShadowSize;\nout vec2 vShadowOffset;\nflat out int vEdgeType;\n\nvoid main() {\n vEdgeType = int(aEdgeType + 0.5);\n vStart = aStart;\n vEnd = aEnd;\n vControl = aControl;\n float effectiveWidth = max(aWidth, 1.0 / uScale);\n vHalfWidth = effectiveWidth * 0.5;\n vWidthFade = clamp(aWidth * uScale, 0.0, 1.0);\n vHalfWidthPx = vHalfWidth * uScale;\n vPerpPx = 0.0;\n vLoopbackRadius = aLoopbackRadius;\n vArrowSize = aArrowSize;\n vArrowTip = aArrowTip;\n vArrowDir = aArrowDir;\n vColor = aColor;\n vShadowColor = aShadowColor;\n vShadowSize = aShadowSize;\n vShadowOffset = vec2(aShadowOffsetX, aShadowOffsetY);\n\n float pad = vHalfWidth + aShadowSize + abs(aShadowOffsetX) + abs(aShadowOffsetY);\n\n vec2 worldPos;\n\n if (vEdgeType == 0) {\n vec2 dir = aEnd - aStart;\n float len = length(dir);\n vec2 unitDir = dir / max(len, 0.0001);\n vec2 perp = vec2(-unitDir.y, unitDir.x);\n float totalHalf = pad + aArrowSize;\n vec2 midpoint = (aStart + aEnd) * 0.5;\n worldPos = midpoint\n + unitDir * (len * 0.5 + totalHalf) * aQuadPosition.x\n + perp * totalHalf * aQuadPosition.y;\n vPerpPx = totalHalf * aQuadPosition.y * uScale;\n } else if (vEdgeType == 1) {\n float margin = pad + aArrowSize;\n vec2 bboxMin = min(min(aStart, aEnd), aControl) - margin;\n vec2 bboxMax = max(max(aStart, aEnd), aControl) + margin;\n vec2 center = (bboxMin + bboxMax) * 0.5;\n vec2 halfSize = (bboxMax - bboxMin) * 0.5;\n worldPos = center + aQuadPosition * halfSize;\n } else {\n float margin = pad + aArrowSize;\n vec2 ctr = aControl;\n float r = aLoopbackRadius;\n vec2 bboxMin = min(ctr - (r + margin), aStart - margin);\n vec2 bboxMax = max(ctr + (r + margin), aStart + margin);\n vec2 center = (bboxMin + bboxMax) * 0.5;\n vec2 halfSize = (bboxMax - bboxMin) * 0.5;\n worldPos = center + aQuadPosition * halfSize;\n }\n\n vWorldPos = worldPos;\n vec2 screenPos = (worldPos + uOriginOffset) * uScale + uTranslation;\n vec2 clip = (screenPos / uResolution) * 2.0 - 1.0;\n gl_Position = vec4(clip.x, -clip.y, 0.0, 1.0);\n}\n","#version 300 es\n\nprecision highp float;\n\nin vec2 vWorldPos;\nin vec2 vStart;\nin vec2 vEnd;\nin vec2 vControl;\nin float vHalfWidth;\nin float vWidthFade;\nin float vHalfWidthPx;\nin float vPerpPx;\nin float vLoopbackRadius;\nin float vArrowSize;\nin vec2 vArrowTip;\nin vec2 vArrowDir;\nin vec4 vColor;\nin vec4 vShadowColor;\nin float vShadowSize;\nin vec2 vShadowOffset;\nflat in int vEdgeType;\n\nuniform bool uSimpleMode;\n\nout vec4 fragColor;\n\nfloat sdSegment(vec2 p, vec2 a, vec2 b) {\n vec2 pa = p - a;\n vec2 ba = b - a;\n float h = clamp(dot(pa, ba) / dot(ba, ba), 0.0, 1.0);\n return length(pa - ba * h);\n}\n\nfloat sdBezier(vec2 pos, vec2 A, vec2 B, vec2 C) {\n vec2 a = B - A;\n vec2 b = A - 2.0 * B + C;\n vec2 c = a * 2.0;\n vec2 d = A - pos;\n\n float kk = 1.0 / max(dot(b, b), 0.0001);\n float kx = kk * dot(a, b);\n float ky = kk * (2.0 * dot(a, a) + dot(d, b)) / 3.0;\n float kz = kk * dot(d, a);\n\n float p = ky - kx * kx;\n float q = kx * (2.0 * kx * kx - 3.0 * ky) + kz;\n float p3 = p * p * p;\n float q2 = q * q;\n float h = q2 + 4.0 * p3;\n\n float res;\n if (h >= 0.0) {\n h = sqrt(h);\n vec2 x = (vec2(h, -h) - q) / 2.0;\n vec2 uv = sign(x) * pow(abs(x), vec2(1.0 / 3.0));\n float t = clamp(uv.x + uv.y - kx, 0.0, 1.0);\n vec2 qo = d + (c + b * t) * t;\n res = dot(qo, qo);\n } else {\n float z = sqrt(-p);\n float v = acos(q / (p * z * 2.0)) / 3.0;\n float m = cos(v);\n float n = sin(v) * 1.732050808;\n vec3 t = clamp(vec3(m + m, -n - m, n - m) * z - kx, 0.0, 1.0);\n vec2 qx = d + (c + b * t.x) * t.x;\n float dx = dot(qx, qx);\n vec2 qy = d + (c + b * t.y) * t.y;\n float dy = dot(qy, qy);\n res = min(dx, dy);\n }\n\n return sqrt(res);\n}\n\nfloat sdArrow(vec2 p, vec2 tip, vec2 dir, float size) {\n if (size <= 0.0) return 1e6;\n\n vec2 perp = vec2(-dir.y, dir.x);\n vec2 rel = p - tip;\n float along = dot(rel, -dir);\n float across = dot(rel, perp);\n\n if (along < 0.0) return length(rel);\n if (along > size) {\n float hw = size * 0.4;\n float closest = clamp(across, -hw, hw);\n vec2 pt = tip - dir * size + perp * closest;\n return length(p - pt);\n }\n\n float halfW = (along / size) * size * 0.4;\n float d = abs(across) - halfW;\n return d;\n}\n\nvoid main() {\n if (uSimpleMode && vEdgeType == 0) {\n float cover = clamp(vHalfWidthPx - abs(vPerpPx) + 0.5, 0.0, 1.0);\n float a = cover * vWidthFade;\n if (a < 0.001) discard;\n fragColor = vec4(vColor.rgb, vColor.a * a);\n return;\n }\n\n float dist;\n if (vEdgeType == 0) {\n dist = sdSegment(vWorldPos, vStart, vEnd);\n } else if (vEdgeType == 1) {\n dist = sdBezier(vWorldPos, vStart, vControl, vEnd);\n } else {\n dist = abs(length(vWorldPos - vControl) - vLoopbackRadius);\n }\n\n float edgeSdf = dist - vHalfWidth;\n float combinedSdf = edgeSdf;\n\n if (vArrowSize > 0.0) {\n float arrowDist = sdArrow(vWorldPos, vArrowTip, vArrowDir, vArrowSize);\n combinedSdf = min(edgeSdf, arrowDist);\n }\n\n float shadowAlpha = 0.0;\n if (vShadowSize > 0.0) {\n vec2 shadowPos = vWorldPos - vShadowOffset;\n float shadowDist;\n if (vEdgeType == 0) {\n shadowDist = sdSegment(shadowPos, vStart, vEnd);\n } else if (vEdgeType == 1) {\n shadowDist = sdBezier(shadowPos, vStart, vControl, vEnd);\n } else {\n shadowDist = abs(length(shadowPos - vControl) - vLoopbackRadius);\n }\n float shadowArrowDist = vArrowSize > 0.0\n ? sdArrow(shadowPos, vArrowTip, vArrowDir, vArrowSize)\n : 1.0e6;\n float shadowCombined = min(shadowDist - vHalfWidth, shadowArrowDist);\n float t = max(shadowCombined, 0.0) / vShadowSize;\n shadowAlpha = exp(-t * t * 1.5) * 0.5 * vShadowColor.a;\n }\n\n float aa = fwidth(combinedSdf);\n float edgeAlpha = (1.0 - smoothstep(-aa, aa, combinedSdf)) * vWidthFade;\n vec4 edgeColor = vColor;\n edgeColor.a *= edgeAlpha;\n\n float finalAlpha = edgeColor.a + shadowAlpha * (1.0 - edgeColor.a);\n\n if (finalAlpha < 0.001) discard;\n\n if (shadowAlpha > 0.0) {\n vec3 finalRGB = (edgeColor.rgb * edgeColor.a + vShadowColor.rgb * shadowAlpha * (1.0 - edgeColor.a)) / finalAlpha;\n fragColor = vec4(finalRGB, finalAlpha);\n } else {\n fragColor = edgeColor;\n }\n}\n"),this._labelProgram=go(this._gl,"#version 300 es\n\nin vec2 aQuadPosition;\n\nin vec2 aLabelCenter;\nin vec2 aLabelSize;\nin vec2 aLabelUV0;\nin vec2 aLabelUV1;\n\nuniform vec2 uResolution;\nuniform vec2 uTranslation;\nuniform float uScale;\nuniform vec2 uOriginOffset;\n\nout vec2 vAtlasUV;\n\nvoid main() {\n vec2 worldPos = aLabelCenter + aQuadPosition * aLabelSize;\n vec2 screenPos = (worldPos + uOriginOffset) * uScale + uTranslation;\n vec2 clip = (screenPos / uResolution) * 2.0 - 1.0;\n gl_Position = vec4(clip.x, -clip.y, 0.0, 1.0);\n\n vec2 uv01 = aQuadPosition * 0.5 + 0.5;\n vAtlasUV = mix(aLabelUV0, aLabelUV1, uv01);\n}\n","#version 300 es\n\nprecision highp float;\n\nuniform sampler2D uAtlas;\n\nin vec2 vAtlasUV;\n\nout vec4 fragColor;\n\nvoid main() {\n vec4 texel = texture(uAtlas, vAtlasUV);\n if (texel.a < 0.01) discard;\n fragColor = texel;\n}\n")}_initNodeBuffers(){if(!this._nodeProgram)throw new o("Node program not initialized.");const t=this._gl;this._nodeVao=t.createVertexArray(),t.bindVertexArray(this._nodeVao);const e=new Float32Array([-1,-1,1,-1,-1,1,1,1]),i=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,i),t.bufferData(t.ARRAY_BUFFER,e,t.STATIC_DRAW);const n=t.getAttribLocation(this._nodeProgram,"aQuadPosition");t.enableVertexAttribArray(n),t.vertexAttribPointer(n,2,t.FLOAT,!1,0,0),this._nodeInstanceBuffer=t.createBuffer(),t.bindBuffer(t.ARRAY_BUFFER,this._nodeInstanceBuffer);const s=25*Float32Array.BYTES_PER_ELEMENT,r=(e,i,n)=>{const o=t.getAttribLocation(this._nodeProgram,e);t.enableVertexAttribArray(o),t.vertexAttribPointer(o,i,t.FLOAT,!1,s,4*n),t.vertexAttribDivisor(o,1)};r("aCenter",2,0),r("aRadius",1,2),r("aColor",4,3),r("aBorderColor",4,7),r("aBorderWidth",1,11),r("aShadowColor",4,12),r("aShadowSize",1,16),r("aShadowOffsetX",1,17),r("aShadowOffsetY",1,18),r("aShapeType",1,19),r("aImageUV0",2,20),r("aImageUV1",2,22),r("aImageAspect",1,24),t.bindVertexArray(null)}_initEdgeBuffers(){if(!this._edgeProgram)throw new o("Edge program not initialized.");const t=this._gl;this._edgeVao=t.createVertexArray(),t.bindVertexArray(this._edgeVao);const e=new Float32Array([-1,-1,1,-1,-1,1,1,1]),i=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,i),t.bufferData(t.ARRAY_BUFFER,e,t.STATIC_DRAW);const n=t.getAttribLocation(this._edgeProgram,"aQuadPosition");t.enableVertexAttribArray(n),t.vertexAttribPointer(n,2,t.FLOAT,!1,0,0),this._edgeInstanceBuffer=t.createBuffer(),t.bindBuffer(t.ARRAY_BUFFER,this._edgeInstanceBuffer);const s=(e,i,n)=>{const s=t.getAttribLocation(this._edgeProgram,e);t.enableVertexAttribArray(s),t.vertexAttribPointer(s,i,t.FLOAT,!1,100,4*n),t.vertexAttribDivisor(s,1)};s("aStart",2,0),s("aEnd",2,2),s("aControl",2,4),s("aWidth",1,6),s("aEdgeType",1,7),s("aLoopbackRadius",1,8),s("aArrowSize",1,9),s("aArrowTip",2,10),s("aArrowDir",2,12),s("aColor",4,14),s("aShadowColor",4,18),s("aShadowSize",1,22),s("aShadowOffsetX",1,23),s("aShadowOffsetY",1,24),t.bindVertexArray(null)}_initLabelBuffers(){if(!this._labelProgram)throw new o("Label program not initialized.");const t=this._gl;this._labelVao=t.createVertexArray(),t.bindVertexArray(this._labelVao);const e=new Float32Array([-1,-1,1,-1,-1,1,1,1]),i=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,i),t.bufferData(t.ARRAY_BUFFER,e,t.STATIC_DRAW);const n=t.getAttribLocation(this._labelProgram,"aQuadPosition");t.enableVertexAttribArray(n),t.vertexAttribPointer(n,2,t.FLOAT,!1,0,0),this._labelInstanceBuffer=t.createBuffer(),t.bindBuffer(t.ARRAY_BUFFER,this._labelInstanceBuffer);const s=(e,i,n)=>{const s=t.getAttribLocation(this._labelProgram,e);t.enableVertexAttribArray(s),t.vertexAttribPointer(s,i,t.FLOAT,!1,32,4*n),t.vertexAttribDivisor(s,1)};s("aLabelCenter",2,0),s("aLabelSize",2,2),s("aLabelUV0",2,4),s("aLabelUV1",2,6),t.bindVertexArray(null)}_resolveColor(t){if(!t)return[1,0,0,1];if(t instanceof F)return[t.rgb.r/255,t.rgb.g/255,t.rgb.b/255,1];const e=t.match(/^rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+))?\s*\)$/);if(e)return[parseInt(e[1])/255,parseInt(e[2])/255,parseInt(e[3])/255,void 0!==e[4]?parseFloat(e[4]):1];const i=new F(t);return[i.rgb.r/255,i.rgb.g/255,i.rgb.b/255,1]}_buildNodeColorCache(t){this._nodeColorCache.clear();for(let e=0;et.isSelected()||t.isHovered()),S=x&&t.getEdges().some(t=>t.isSelected()||t.isHovered());let T=null,E=null,P=null,A=null;if(!v){const e=t.getNodes();T=new Float64Array(e.length),E=new Float64Array(e.length),P=new Float64Array(e.length),A=new Map;for(let t=0;t0)if(I=1.5*B+3*(x||1),0===C){const t=a-o,e=h-r,i=Math.sqrt(t*t+e*e);i>0&&(O=t/i,k=e/i,L=a-O*l,R=h-k*l)}else if(1===C){let t=1,e=.5,i=1;for(let n=0;n<8;n++){const n=.5*(e+i),s=1-n,d=s*s*o+2*n*s*M+n*n*a,u=s*s*r+2*n*s*N+n*n*h,c=Math.sqrt(Math.pow(d-a,2)+Math.pow(u-h,2));if(Math.abs(c-l)<.1){t=n;break}c>l?e=n:i=n,t=n}const n=1-t;L=n*n*o+2*t*n*M+t*t*a,R=n*n*r+2*t*n*N+t*t*h;const s=2*n*(M-o)+2*t*(a-M),d=2*n*(N-r)+2*t*(h-N),u=Math.sqrt(s*s+d*d);u>0&&(O=s/u,k=d/u)}else{let t=.8,e=.6,i=1;for(let n=0;n<8;n++){const n=.5*(e+i),s=2*n*Math.PI,a=M+D*Math.cos(s),h=N-D*Math.sin(s),l=Math.sqrt(Math.pow(a-o,2)+Math.pow(h-r,2));if(Math.abs(l-d)<.1){t=n;break}l>d?i=n:e=n,t=n}const n=2*t*Math.PI;L=M+D*Math.cos(n),R=N-D*Math.sin(n);const s=-2*t*Math.PI+.45*Math.PI;O=Math.cos(s),k=Math.sin(s)}m[v]=o,m[v+1]=r,m[v+2]=a,m[v+3]=h,m[v+4]=M,m[v+5]=N,m[v+6]=x,m[v+7]=C,m[v+8]=D,m[v+9]=I,m[v+10]=L,m[v+11]=R,m[v+12]=O,m[v+13]=k,m[v+14]=b[0],m[v+15]=b[1],m[v+16]=b[2],m[v+17]=b[3]*w,m[v+18]=p[0],m[v+19]=p[1],m[v+20]=p[2],m[v+21]=p[3]*w,m[v+22]=c,m[v+23]=_,m[v+24]=g}l.useProgram(this._edgeProgram),this._setViewUniforms(this._edgeProgram),l.bindBuffer(l.ARRAY_BUFFER,this._edgeInstanceBuffer),v||(l.bufferData(l.ARRAY_BUFFER,m.byteLength,l.STREAM_DRAW),l.bufferSubData(l.ARRAY_BUFFER,0,m));const C=this.transform.k<=.2,M=l.getUniformLocation(this._edgeProgram,"uSimpleMode");if(l.uniform1i(M,C?1:0),l.bindVertexArray(this._edgeVao),this._timerExt&&this._timerEdgeQueries.length>0){const t=this._timerEdgeQueries[this._timerQueryIdx],e=this._pollTimerQuery(t);null!==e&&(this._lastEdgeGpuMs=e),l.beginQuery(this._timerExt.TIME_ELAPSED_EXT,t)}l.drawArraysInstanced(l.TRIANGLE_STRIP,0,4,f.length),this._timerExt&&this._timerEdgeQueries.length>0&&l.endQuery(this._timerExt.TIME_ELAPSED_EXT),l.bindVertexArray(null),C&&l.enable(l.BLEND),l.useProgram(this._nodeProgram),this._setViewUniforms(this._nodeProgram),this._imageAtlas&&(this._imageAtlas.uploadIfDirty(),this._imageAtlas.bind(0),l.uniform1i(l.getUniformLocation(this._nodeProgram,"uImageAtlas"),0));const N=t.getNodes(),D=this.transform.k,I=25*N.length,L=null===this._nodeInstanceData||this._nodeInstanceData.length!==I;L&&(this._nodeInstanceData=new Float32Array(I));const R=this._nodeInstanceData,O=v&&!L;if(O||N.length===this._lastNodeCount&&!this._isColorCacheDirty||(this._buildNodeColorCache(N),this._buildNodeBorderColorCache(N),this._buildNodeShadowColorCache(N),this._isColorCacheDirty=!1,this._lastNodeCount=N.length),!O)for(let t=0;t=4){const t=e.isSelected()&&r.imageUrlSelected||r.imageUrl;if(t&&this._imageAtlas){const e=this._imageAtlas.getOrCreate(t);e&&(p=e.u0,m=e.v0,v=e.u1,x=e.v1,S=e.aspect)}}R[u+20]=p,R[u+21]=m,R[u+22]=v,R[u+23]=x,R[u+24]=S}if(l.bindBuffer(l.ARRAY_BUFFER,this._nodeInstanceBuffer),O||(l.bufferData(l.ARRAY_BUFFER,R.byteLength,l.STREAM_DRAW),l.bufferSubData(l.ARRAY_BUFFER,0,R)),this._buffersAreCurrent=!0,l.bindVertexArray(this._nodeVao),this._timerExt&&this._timerNodeQueries.length>0){const t=this._timerNodeQueries[this._timerQueryIdx],e=this._pollTimerQuery(t);null!==e&&(this._lastNodeGpuMs=e),l.beginQuery(this._timerExt.TIME_ELAPSED_EXT,t)}if(l.drawArraysInstanced(l.TRIANGLE_STRIP,0,4,N.length),this._timerExt&&this._timerNodeQueries.length>0&&(l.endQuery(this._timerExt.TIME_ELAPSED_EXT),this._timerQueryIdx=(this._timerQueryIdx+1)%this._timerNodeQueries.length),l.bindVertexArray(null),this._labelProgram&&this._labelCache&&this._settings.labelsIsEnabled){const t=this._labelCache,e=t.rasterFontPx;let i=0;const n=N.length+f.length,o=new Float32Array(8*n);for(let n=0;n0&&(t.uploadIfDirty(),l.useProgram(this._labelProgram),this._setViewUniforms(this._labelProgram),t.bind(0),l.uniform1i(l.getUniformLocation(this._labelProgram,"uAtlas"),0),l.bindBuffer(l.ARRAY_BUFFER,this._labelInstanceBuffer),l.bufferData(l.ARRAY_BUFFER,o.subarray(0,8*i),l.DYNAMIC_DRAW),l.bindVertexArray(this._labelVao),l.drawArraysInstanced(l.TRIANGLE_STRIP,0,4,i),l.bindVertexArray(null))}this._isInitiallyRendered=!0,this.emit(Us.RENDER_END,{durationMs:performance.now()-a})}reset(){this.transform=En;const t=this._gl;t.clearColor(0,0,0,0),t.clear(t.COLOR_BUFFER_BIT)}getFitZoomTransform(t){const e=t.getBoundingBox(),i=e.x+e.width/2,n=e.y+e.height/2,s=this.getSimulationViewRectangle(),o=s.height/(e.height*(1+this._settings.fitZoomMargin)),r=s.width/(e.width*(1+this._settings.fitZoomMargin)),a=Math.min(o,r),h=this.transform.k,l=Math.max(Math.min(a*h,this._settings.maxZoom),this._settings.minZoom),d=s.width/2*h*(1-l)-i*l,u=s.height/2*h*(1-l)-n*l;return En.translate(d,u).scale(l)}getSimulationPosition(t){const[e,i]=this.transform.invert([t.x,t.y]);return{x:e-this._width/2,y:i-this._height/2}}getCanvasPosition(t){const[e,i]=this.transform.apply([t.x+this._width/2,t.y+this._height/2]);return{x:e,y:i}}getSimulationViewRectangle(){const t=this.getSimulationPosition({x:0,y:0}),e=this.getSimulationPosition({x:this._width,y:this._height});return{x:t.x,y:t.y,width:e.x-t.x,height:e.y-t.y}}translateOriginToCenter(){this._isOriginCentered=!0}destroy(){var t,e;null===(t=this._dprObserveUnsubscribe)||void 0===t||t.call(this),this.removeAllListeners(),null===(e=this._gl.getExtension("WEBGL_lose_context"))||void 0===e||e.loseContext(),this._canvas.remove()}_setViewUniforms(t){const e=this._gl,i=this._isOriginCentered?this._width/2:0,n=this._isOriginCentered?this._height/2:0;e.uniform2f(e.getUniformLocation(t,"uResolution"),this._width,this._height),e.uniform2f(e.getUniformLocation(t,"uTranslation"),this.transform.x,this.transform.y),e.uniform1f(e.getUniformLocation(t,"uScale"),this.transform.k),e.uniform2f(e.getUniformLocation(t,"uOriginOffset"),i,n)}}class Mo{static getRenderer(t,e=zs.CANVAS,i){return e===zs.WEBGL?new Co(t,i):new fo(t,i)}}const No=t=>isFinite(t)?""+Math.round(1e3*t)/1e3:"0",Do=t=>t.replace(/&/g,"&").replace(//g,">").replace(/"/g,""").replace(/'/g,"'"),Io=(t,e,i)=>{const n=Object.keys(e).filter(t=>{const i=e[t];return null!=i&&""!==i}).map(t=>{const i=e[t];return`${t}="${"number"==typeof i?No(i):Do(String(i))}"`}).join(" "),s=n?`${t} ${n}`:t;return void 0===i?`<${s}/>`:`<${s}>${i}`},Lo=t=>t.map(t=>`${No(t.x)},${No(t.y)}`).join(" "),Ro=t=>({tag:"polygon",attributes:{points:Lo(t)}}),Oo=(t,e)=>{var i,n;if(null==t||""==`${t}`)return"";const s=new Gs(t,{position:e.position,textBaseline:e.textBaseline,properties:e.properties});if(!s.textLines.length||s.fontSize<=0)return"";const o=null!==(i=e.properties.fontFamily)&&void 0!==i?i:"Roboto, sans-serif",r=(null!==(n=e.properties.fontColor)&&void 0!==n?n:"#000000").toString(),a=1.2*s.fontSize,h=e.textBaseline===Ws.MIDDLE?"middle":"text-before-edge",l=ko(s,a),d=s.textLines.map((t,e)=>Io("tspan",{x:s.position.x,dy:0===e?0:a},Do(t))).join("");return`${l}${Io("text",{x:s.position.x,y:s.position.y,"font-size":s.fontSize,"font-family":o,fill:r,"text-anchor":"middle","dominant-baseline":h},d)}`},ko=(t,e)=>{const i=t.properties.fontBackgroundColor;if(!i)return"";const n=.12*t.fontSize,s=t.fontSize+2*n,o=t.textBaseline===Ws.MIDDLE?t.fontSize/2:0,r=i.toString();return t.textLines.map((i,a)=>{const h=i.length*t.fontSize*.6+2*n;return Io("rect",{x:t.position.x-h/2,y:t.position.y-o-n+a*e,width:h,height:s,fill:r})}).join("")},Bo=t=>{if("undefined"!=typeof document)try{const e=document.createElement("canvas");e.width=t.naturalWidth||t.width,e.height=t.naturalHeight||t.height;const i=e.getContext("2d");if(!i)return;return i.drawImage(t,0,0),e.toDataURL()}catch(t){return}},zo=t=>{var e,i,n;return t.shadowColor?{color:t.shadowColor,size:null!==(e=t.shadowSize)&&void 0!==e?e:0,offsetX:null!==(i=t.shadowOffsetX)&&void 0!==i?i:0,offsetY:null!==(n=t.shadowOffsetY)&&void 0!==n?n:0}:null},Uo=(t,e)=>{const{color:i,opacity:n}=jo(e.color.toString()),s=Math.max(.5*e.size,0),o=`shadow:${i}:${n}:${s}:${e.offsetX}:${e.offsetY}`;return t.add(o,o=>Fo(o,i,n,s,e.offsetX,e.offsetY,t.filterRegion))},Fo=(t,e,i,n,s,o,r)=>{const a=r?`filterUnits="userSpaceOnUse" x="${No(r.x)}" y="${No(r.y)}" width="${No(r.width)}" height="${No(r.height)}"`:'filterUnits="objectBoundingBox" x="-50%" y="-50%" width="200%" height="200%"';return``},jo=t=>{const e=t.match(/^rgba\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)\s*\)$/i);if(e)return{color:`rgb(${e[1]}, ${e[2]}, ${e[3]})`,opacity:Wo(Number(e[4]))};const i=t.match(/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i);if(i)return{color:`#${i[1]}${i[2]}${i[3]}`,opacity:parseInt(i[4],16)/255};const n=t.match(/^#([0-9a-f])([0-9a-f])([0-9a-f])([0-9a-f])$/i);return n?{color:`#${n[1]}${n[2]}${n[3]}`,opacity:parseInt(n[4],16)/15}:{color:t,opacity:1}},Wo=t=>isFinite(t)?Math.min(Math.max(t,0),1):1,Go=(t,e,i)=>{var n,s,o,r,a,h;const l=null===(n=null==i?void 0:i.isLabelEnabled)||void 0===n||n,d=null===(s=null==i?void 0:i.isShadowEnabled)||void 0===s||s,u=null===(o=null==i?void 0:i.isImageEnabled)||void 0===o||o,c=t.getCenter(),_=t.getRadius();if(_<=0)return"";const f=((t,e,i,n)=>{switch(t){case w.SQUARE:return{tag:"rect",attributes:{x:e-n,y:i-n,width:2*n,height:2*n}};case w.DIAMOND:return Ro([{x:e,y:i+n},{x:e+n,y:i},{x:e,y:i-n},{x:e-n,y:i}]);case w.TRIANGLE:return Ro(((t,e,i)=>{e+=.275*(i*=1.15);const n=2*i,s=Math.sqrt(3)*n/6;return[{x:t,y:e-(Math.sqrt(n*n-i*i)-s)},{x:t+i,y:e+s},{x:t-i,y:e+s}]})(e,i,n));case w.TRIANGLE_DOWN:return Ro(((t,e,i)=>{e-=.275*(i*=1.15);const n=2*i,s=Math.sqrt(3)*n/6;return[{x:t,y:e+(Math.sqrt(n*n-i*i)-s)},{x:t+i,y:e-s},{x:t-i,y:e-s}]})(e,i,n));case w.STAR:return Ro(((t,e,i)=>{e+=.1*(i*=.82);const n=[];for(let s=0;s<10;s++){const o=i*(s%2==0?1.3:.5);n.push({x:t+o*Math.sin(2*s*Math.PI/10),y:e-o*Math.cos(2*s*Math.PI/10)})}return n})(e,i,n));case w.HEXAGON:return Ro(((t,e,i,n)=>{const s=[],o=2*Math.PI/n;for(let r=0;r{const n=t.getBackgroundImage();if(!n||!n.width||!n.height)return"";const s=((t,e)=>{var i,n;const s=Bo(e);if(s)return s;const o=t.getStyle();return t.isSelected()&&o.imageUrlSelected?o.imageUrlSelected:null!==(n=null!==(i=o.imageUrl)&&void 0!==i?i:e.src)&&void 0!==n?n:void 0})(t,n);if(!s)return"";const o=t.getCenter(),r=t.getRadius(),a=Object.keys(i.attributes).map(t=>`${t}=${i.attributes[t]}`).join(","),h=e.add(`clip:${i.tag}:${a}`,t=>Io("clipPath",{id:t},Io(i.tag,i.attributes)));return Io("image",{href:s,"xlink:href":s,x:o.x-r,y:o.y-r,width:2*r,height:2*r,preserveAspectRatio:"xMidYMid slice","clip-path":`url(#${h})`})})(t,e,f):"",y=d&&t.hasShadow()?zo(t.getStyle()):null;let x;if(v||y){let t=`${Io(f.tag,Object.assign(Object.assign({},f.attributes),{fill:g}))}${v}`;y&&(t=Io("g",{filter:`url(#${Uo(e,y)})`},t)),x=`${t}${p?Io(f.tag,Object.assign(Object.assign(Object.assign({},f.attributes),{fill:"none"}),m)):""}`}else x=Io(f.tag,Object.assign(Object.assign(Object.assign({},f.attributes),{fill:g}),m));const b=l?Zo(t):"";return Io("g",{},`${x}${b}`)},Zo=t=>{const e=t.getLabel();if(!e)return"";const i=t.getCenter(),n=1.2*t.getBorderedRadius(),s=t.getStyle();return Oo(e,{position:{x:i.x,y:i.y+n},textBaseline:Ws.TOP,properties:{fontBackgroundColor:s.fontBackgroundColor,fontColor:s.fontColor,fontFamily:s.fontFamily,fontSize:s.fontSize}})},Ho=[{x:0,y:0},{x:-1,y:.4},{x:-1,y:-.4}],Xo=(t,e,i)=>{var n,s,o;const r=t.getWidth();if(!r)return"";const a=null===(n=null==i?void 0:i.isLabelEnabled)||void 0===n||n,h=null===(s=null==i?void 0:i.isShadowEnabled)||void 0===s||s,l=(null!==(o=t.getColor())&&void 0!==o?o:"#000000").toString(),d=Vo(t,l),u=qo(t,r,l),c=h&&t.hasShadow()?zo(t.getStyle()):null;let _=`${d}${u}`;c&&(_=Io("g",{filter:`url(#${Uo(e,c)})`},_));const f=a?Ko(t):"";return Io("g",{},`${_}${f}`)},qo=(t,e,i)=>{const n=t.getLineDashPattern(),s={stroke:i,"stroke-width":e,fill:"none","stroke-dasharray":n?n.join(" "):void 0};if(t instanceof k){const e=t.startNode.getCenter(),i=t.endNode.getCenter(),n=`M ${No(e.x)} ${No(e.y)} L ${No(i.x)} ${No(i.y)}`;return Io("path",Object.assign({d:n},s))}if(t instanceof B){const e=t.startNode.getCenter(),i=t.endNode.getCenter(),n=t.getCurvedControlPoint(),o=`M ${No(e.x)} ${No(e.y)} Q ${No(n.x)} ${No(n.y)} ${No(i.x)} ${No(i.y)}`;return Io("path",Object.assign({d:o},s))}if(t instanceof z){const{x:e,y:i,radius:n}=t.getCircularData();return Io("circle",Object.assign({cx:e,cy:i,r:n},s))}return""},Vo=(t,e)=>{if(0===t.getStyle().arrowSize)return"";const i=Yo(t);if(!i)return"";const n=$o(Ho,i).map(t=>`${No(t.x)},${No(t.y)}`).join(" ");return Io("polygon",{points:n,fill:e})},Yo=t=>t instanceof k?eo(t):t instanceof B?Ys(t):t instanceof z?Qs(t):null,$o=(t,e)=>t.map(t=>{const i=t.x*Math.cos(e.angle)-t.y*Math.sin(e.angle),n=t.x*Math.sin(e.angle)+t.y*Math.cos(e.angle);return{x:e.point.x+e.length*i,y:e.point.y+e.length*n}}),Ko=t=>{const e=t.getLabel();if(!e)return"";const i=t.getStyle();return Oo(e,{position:t.getCenter(),textBaseline:Ws.MIDDLE,properties:{fontBackgroundColor:i.fontBackgroundColor,fontColor:i.fontColor,fontFamily:i.fontFamily,fontSize:i.fontSize}})};class Qo{constructor(t){this.filterRegion=t,this._idBySignature=new Map,this._entries=[],this._counter=0}add(t,e){const i=this._idBySignature.get(t);if(void 0!==i)return i;const n=`orb-def-${this._counter}`;return this._counter+=1,this._idBySignature.set(t,n),this._entries.push(e(n)),n}toSVG(){return this._entries.length?`${this._entries.join("")}`:""}}const Jo=(t,e={})=>{var i,n,s,o;const r=null!==(i=e.padding)&&void 0!==i?i:20,a=null===(n=e.isLabelEnabled)||void 0===n||n,h=null===(s=e.isShadowEnabled)||void 0===s||s,l=null===(o=e.isImageEnabled)||void 0===o||o,d=t.getNodes(),u=t.getEdges(),c=tr(d,u,a,h),_=c.x-r,f=c.y-r,g=Math.max(c.width+2*r,1),p=Math.max(c.height+2*r,1),m=new Qo({x:_,y:f,width:g,height:p}),v=[];e.backgroundColor&&v.push(Io("rect",{x:_,y:f,width:g,height:p,fill:e.backgroundColor.toString()}));for(let t=0;t{const s={minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0};for(let e=0;e{et.maxX&&(t.maxX=e),i>t.maxY&&(t.maxY=i)},ir=(t,e,i,n,s)=>{er(t,e-n,i-s),er(t,e+n,i+s)},nr=(t,e,i,n)=>{var s;if(e.getRadius()<=0)return;const o=e.getCenter(),r=e.getBorderedRadius(),a=n?rr(e.hasShadow(),e.getStyle()):0;if(ir(t,o.x,o.y,r+a,r+a),i&&e.getLabel()){const i=e.getStyle(),n=o.y+1.2*e.getBorderedRadius();or(t,e.getLabel(),o.x,n,null!==(s=i.fontSize)&&void 0!==s?s:4,!1)}},sr=(t,e,i,n)=>{var s;if(!e.getWidth())return;const o=e.getStyle(),r=n?rr(e.hasShadow(),o):0;if(e instanceof z){const i=e.getCircularData();ir(t,i.x,i.y,i.radius+r,i.radius+r)}else if(e instanceof B){const i=e.getCurvedControlPoint();ir(t,i.x,i.y,r,r)}if(i&&e.getLabel()){const i=e.getCenter();or(t,e.getLabel(),i.x,i.y,null!==(s=o.fontSize)&&void 0!==s?s:4,!0)}},or=(t,e,i,n,s,o)=>{if(s<=0)return;const r=`${e}`.split("\n"),a=.12*s,h=r.reduce((t,e)=>Math.max(t,e.trim().length),0)*s*.6+2*a,l=r.length*s*1.2+2*a,d=o?n-l/2:n;er(t,i-h/2,d),er(t,i+h/2,d+l)},rr=(t,e)=>{var i,n,s;return t&&e.shadowColor?(null!==(i=e.shadowSize)&&void 0!==i?i:0)+Math.max(Math.abs(null!==(n=e.shadowOffsetX)&&void 0!==n?n:0),Math.abs(null!==(s=e.shadowOffsetY)&&void 0!==s?s:0)):0};class ar{constructor(t){this._graph=t}selectNodeById(t,e){const i=this._graph.getNodeById(t);return!!i&&(Es(i,e),!0)}selectNodesByIds(t,e){const i=[];for(let e=0;e{for(let i=0;i{for(let i=0;i{for(let i=0;i{for(let i=0;i{Os(t,r.HOVERED)})(e),!0)}unhoverAll(){const{changedCount:t}=Ls(this._graph);return t}}const hr={isBackgroundDrag:!0},lr=t=>!!t&&!0===t.isBackgroundDrag;class dr{constructor(t,i){var n,o,r,a,h,l,d,u;this._simulatorUsesGPU=!1,this._simulationStartedAt=Date.now(),this._assignPositions=t=>{if(this._settings.getPosition)for(let e=0;e!(t.button||t.ctrlKey&&"wheel"!==t.type||"wheel"!==t.type&&this._isBackgroundDragModifierActive(t)),this._dragFilter=t=>!(t.button||!this._isBackgroundDragModifierActive(t)&&t.ctrlKey),this.dragSubject=t=>{var e;const i=this.getCanvasMousePosition(t.sourceEvent),n=null===(e=this._renderer)||void 0===e?void 0:e.getSimulationPosition(i);return this._graph.getNearestNode(n)||(this._isBackgroundDragModifierActive(t.sourceEvent)?hr:void 0)},this.dragStarted=t=>{if(lr(t.subject))return void this._emitBackgroundDrag(e.BACKGROUND_DRAG_START,t.sourceEvent);if(!this._settings.interaction.isDragEnabled)return;const i=this.getCanvasMousePosition(t.sourceEvent),n=this._renderer.getSimulationPosition(i);this._events.emit(e.NODE_DRAG_START,{node:t.subject,event:t.sourceEvent,localPoint:n,globalPoint:i}),this._dragStartPosition=i},this.dragged=t=>{if(lr(t.subject))return void this._emitBackgroundDrag(e.BACKGROUND_DRAG,t.sourceEvent);if(!this._settings.interaction.isDragEnabled)return;const i=this.getCanvasMousePosition(t.sourceEvent),n=this._renderer.getSimulationPosition(i);Rn(this._dragStartPosition,i)||(this._dragStartPosition=void 0),this._simulator.dragNode(t.subject.getId(),n),this._events.emit(e.NODE_DRAG,{node:t.subject,event:t.sourceEvent,localPoint:n,globalPoint:i})},this.dragEnded=t=>{if(lr(t.subject))return void this._emitBackgroundDrag(e.BACKGROUND_DRAG_END,t.sourceEvent);if(!this._settings.interaction.isDragEnabled)return;const i=this.getCanvasMousePosition(t.sourceEvent),n=this._renderer.getSimulationPosition(i);Rn(this._dragStartPosition,i)||this._simulator.endDragNode(t.subject.getId()),this._events.emit(e.NODE_DRAG_END,{node:t.subject,event:t.sourceEvent,localPoint:n,globalPoint:i})},this.zoomed=t=>{this._settings.interaction.isZoomEnabled&&(this._renderer.transform=t.transform,setTimeout(()=>{this.render(),this._events.emit(e.TRANSFORM,{transform:t.transform})},1))},this.mouseMoved=t=>{const i=this.getCanvasMousePosition(t),n=this._renderer.getSimulationPosition(i),s=this._strategy.onMouseMove(this._graph,n),o=s.changedSubject;o&&s.isStateChanged&&(E(o)&&this._events.emit(e.NODE_HOVER,{node:o,event:t,localPoint:n,globalPoint:i}),L(o)&&this._events.emit(e.EDGE_HOVER,{edge:o,event:t,localPoint:n,globalPoint:i})),this._events.emit(e.MOUSE_MOVE,{subject:o,event:t,localPoint:n,globalPoint:i}),s.isStateChanged&&(this._invalidateStyles(),this.render())},this.mouseClicked=t=>{const i=this.getCanvasMousePosition(t),n=this._renderer.getSimulationPosition(i),s=this._strategy.onMouseClick(this._graph,n,{isAppend:t.shiftKey}),o=s.changedSubject;o&&(E(o)&&this._events.emit(e.NODE_CLICK,{node:o,event:t,localPoint:n,globalPoint:i}),L(o)&&this._events.emit(e.EDGE_CLICK,{edge:o,event:t,localPoint:n,globalPoint:i})),this._events.emit(e.MOUSE_CLICK,{subject:o,event:t,localPoint:n,globalPoint:i}),(s.isStateChanged||s.changedSubject)&&(this._invalidateStyles(),this.render())},this.mouseRightClicked=t=>{const i=this.getCanvasMousePosition(t),n=this._renderer.getSimulationPosition(i),s=this._strategy.onMouseRightClick(this._graph,n),o=s.changedSubject;o&&(E(o)&&this._events.emit(e.NODE_RIGHT_CLICK,{node:o,event:t,localPoint:n,globalPoint:i}),L(o)&&this._events.emit(e.EDGE_RIGHT_CLICK,{edge:o,event:t,localPoint:n,globalPoint:i})),this._events.emit(e.MOUSE_RIGHT_CLICK,{subject:o,event:t,localPoint:n,globalPoint:i}),(s.isStateChanged||s.changedSubject)&&(this._invalidateStyles(),this.render())},this.mouseDoubleClicked=t=>{const i=this.getCanvasMousePosition(t),n=this._renderer.getSimulationPosition(i),s=this._strategy.onMouseDoubleClick(this._graph,n),o=s.changedSubject;o&&(E(o)&&this._events.emit(e.NODE_DOUBLE_CLICK,{node:o,event:t,localPoint:n,globalPoint:i}),L(o)&&this._events.emit(e.EDGE_DOUBLE_CLICK,{edge:o,event:t,localPoint:n,globalPoint:i})),this._events.emit(e.MOUSE_DOUBLE_CLICK,{subject:o,event:t,localPoint:n,globalPoint:i}),(s.isStateChanged||s.changedSubject)&&(this._invalidateStyles(),this.render())},this.zoomIn=t=>{_e(this._renderer.canvas).transition().duration(this._settings.zoomFitTransitionMs).ease(Ae).call(this._d3Zoom.scaleBy,1.2).on("end",()=>this.render(t))},this.zoomOut=t=>{_e(this._renderer.canvas).transition().duration(this._settings.zoomFitTransitionMs).ease(Ae).call(this._d3Zoom.scaleBy,.8).on("end",()=>this.render(t))},this._invalidateStyles=()=>{var t,e;null===(e=(t=this._renderer).invalidateStyles)||void 0===e||e.call(t)},this._update=t=>{t&&"x"in t&&"y"in t&&"id"in t&&this._simulator.patchData({nodes:[{x:t.x,y:t.y,sx:t.x,sy:t.y,fx:t.x,fy:t.y,id:t.id}],edges:[]}),this._invalidateStyles(),this.render()},this._initializeSimulationEvents=()=>{this._simulator.on(On.SIMULATION_START,()=>{this._simulationStartedAt=Date.now(),this._events.emit(e.SIMULATION_START,void 0)});const t=()=>{var t,e;return null===(e=(t=this._renderer).invalidateBuffers)||void 0===e?void 0:e.call(t)};this._simulator.on(On.SIMULATION_PROGRESS,i=>{this._graph.setNodePositions(i.nodes),t(),this._events.emit(e.SIMULATION_STEP,{progress:i.progress}),this.render()}),this._simulator.on(On.SIMULATION_END,i=>{this._graph.setNodePositions(i.nodes),t(),this.render(),this._events.emit(e.SIMULATION_END,{durationMs:Date.now()-this._simulationStartedAt})}),this._simulator.on(On.SIMULATION_STEP,e=>{this._graph.setNodePositions(e.nodes),t(),this.render()}),this._simulator.on(On.NODE_DRAG,e=>{this._graph.setNodePositions(e.nodes),t(),this.render()}),this._simulator.on(On.SETTINGS_UPDATE,t=>{var e;this._settings.layout.options=null===(e=t.settings)||void 0===e?void 0:e.options})},this._container=t,this._settings=Object.assign(Object.assign({getPosition:null==i?void 0:i.getPosition,zoomFitTransitionMs:200,isOutOfBoundsDragEnabled:!1,areCoordinatesRounded:!0},i),{layout:Object.assign({type:"force"},null!==(n=null==i?void 0:i.layout)&&void 0!==n?n:ns),render:Object.assign({},null==i?void 0:i.render),strategy:Object.assign({isDefaultHoverEnabled:!0,isDefaultSelectEnabled:!0,isDefaultMultiSelectEnabled:!1,isDefaultSelectCascadeEnabled:!0},null==i?void 0:i.strategy),interaction:Object.assign(Object.assign({isDragEnabled:!0,isZoomEnabled:!0},null==i?void 0:i.interaction),{backgroundDrag:Object.assign({isEnabled:!1,modifier:"shift"},null===(o=null==i?void 0:i.interaction)||void 0===o?void 0:o.backgroundDrag)})}),this._graph=new Ts(void 0,{onLoadedImages:()=>{this._renderer.isInitiallyRendered&&this.render()},listeners:[this._update]}),this._graph.setDefaultStyle(X()),this._events=new s,this._interaction=new ar(this._graph),this._strategy=new Bs({isDefaultSelectEnabled:null!==(r=this._settings.strategy.isDefaultSelectEnabled)&&void 0!==r&&r,isDefaultHoverEnabled:null!==(a=this._settings.strategy.isDefaultHoverEnabled)&&void 0!==a&&a,isDefaultMultiSelectEnabled:null===(h=this._settings.strategy.isDefaultMultiSelectEnabled)||void 0===h||h,isDefaultSelectCascadeEnabled:null===(l=this._settings.strategy.isDefaultSelectCascadeEnabled)||void 0===l||l}),this._rendererType=null!==(u=null===(d=null==i?void 0:i.render)||void 0===d?void 0:d.type)&&void 0!==u?u:zs.CANVAS,this._initRenderer(this._rendererType),this._simulator=xs.getSimulator(this._settings.layout),this._simulatorUsesGPU=dr._needsGPU(this._settings.layout),this._initializeSimulationEvents(),this._graph.setSettings({onSetupData:()=>{this._assignPositions(this._graph.getNodes());const t=this._graph.getNodePositions(),e=this._graph.getEdgePositions();this._simulator.setupData({nodes:t,edges:e})},onMergeData:t=>{var e,i;const n=new Set(null===(e=t.nodes)||void 0===e?void 0:e.map(t=>t.id)),s=t=>n.has(t.getId()),o=new Set(null===(i=t.edges)||void 0===i?void 0:i.map(t=>t.id));this._assignPositions(this._graph.getNodes(s));const r=this._graph.getNodePositions(s),a=this._graph.getEdgePositions(t=>o.has(t.getId()));this._simulator.mergeData({nodes:r,edges:a})},onRemoveData:t=>{this._simulator.deleteData(t)}})}_initRenderer(t){try{this._renderer=Mo.getRenderer(this._container,t,this._settings.render)}catch(t){throw this._container.textContent=t.message,t}this._renderer.on(Us.RENDER_START,()=>{this._events.emit(e.RENDER_START,void 0)}),this._renderer.on(Us.RENDER_END,t=>{this._events.emit(e.RENDER_END,t)}),this._renderer.on(Us.RESIZE,()=>{this._renderer.isInitiallyRendered&&this._renderer.render(this._graph)}),this._renderer.translateOriginToCenter(),this._settings.render=this._renderer.getSettings(),this._d3Zoom=function(){var t,e,i,n=Cn,s=Mn,o=Ln,r=Dn,a=In,h=[0,1/0],l=[[-1/0,-1/0],[1/0,1/0]],d=250,u=Me,c=tt("start","zoom","end"),_=0,f=10;function g(t){t.property("__zoom",Nn).on("wheel.zoom",S,{passive:!1}).on("mousedown.zoom",w).on("dblclick.zoom",T).filter(a).on("touchstart.zoom",E).on("touchmove.zoom",P).on("touchend.zoom touchcancel.zoom",A).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function p(t,e){return(e=Math.max(h[0],Math.min(h[1],e)))===t.k?t:new Tn(e,t.x,t.y)}function m(t,e,i){var n=e[0]-i[0]*t.k,s=e[1]-i[1]*t.k;return n===t.x&&s===t.y?t:new Tn(t.k,n,s)}function v(t){return[(+t[0][0]+ +t[1][0])/2,(+t[0][1]+ +t[1][1])/2]}function y(t,e,i,n){t.on("start.zoom",function(){x(this,arguments).event(n).start()}).on("interrupt.zoom end.zoom",function(){x(this,arguments).event(n).end()}).tween("zoom",function(){var t=this,o=arguments,r=x(t,o).event(n),a=s.apply(t,o),h=null==i?v(a):"function"==typeof i?i.apply(t,o):i,l=Math.max(a[1][0]-a[0][0],a[1][1]-a[0][1]),d=t.__zoom,c="function"==typeof e?e.apply(t,o):e,_=u(d.invert(h).concat(l/d.k),c.invert(h).concat(l/c.k));return function(t){if(1===t)t=c;else{var e=_(t),i=l/e[2];t=new Tn(i,h[0]-e[0]*i,h[1]-e[1]*i)}r.zoom(null,t)}})}function x(t,e,i){return!i&&t.__zooming||new b(t,e)}function b(t,e){this.that=t,this.args=e,this.active=0,this.sourceEvent=null,this.extent=s.apply(t,e),this.taps=0}function S(t,...e){if(n.apply(this,arguments)){var i=x(this,e).event(t),s=this.__zoom,a=Math.max(h[0],Math.min(h[1],s.k*Math.pow(2,r.apply(this,arguments)))),d=fe(t);if(i.wheel)i.mouse[0][0]===d[0]&&i.mouse[0][1]===d[1]||(i.mouse[1]=s.invert(i.mouse[0]=d)),clearTimeout(i.wheel);else{if(s.k===a)return;i.mouse=[d,s.invert(d)],ti(this),i.start()}An(t),i.wheel=setTimeout(function(){i.wheel=null,i.end()},150),i.zoom("mouse",o(m(p(s,a),i.mouse[0],i.mouse[1]),i.extent,l))}}function w(t,...e){if(!i&&n.apply(this,arguments)){var s=t.currentTarget,r=x(this,e,!0).event(t),a=_e(t.view).on("mousemove.zoom",function(t){if(An(t),!r.moved){var e=t.clientX-d,i=t.clientY-u;r.moved=e*e+i*i>_}r.event(t).zoom("mouse",o(m(r.that.__zoom,r.mouse[0]=fe(t,s),r.mouse[1]),r.extent,l))},!0).on("mouseup.zoom",function(t){a.on("mousemove.zoom mouseup.zoom",null),xe(t.view,r.moved),An(t),r.event(t).end()},!0),h=fe(t,s),d=t.clientX,u=t.clientY;ye(t.view),Pn(t),r.mouse=[h,this.__zoom.invert(h)],ti(this),r.start()}}function T(t,...e){if(n.apply(this,arguments)){var i=this.__zoom,r=fe(t.changedTouches?t.changedTouches[0]:t,this),a=i.invert(r),h=i.k*(t.shiftKey?.5:2),u=o(m(p(i,h),r,a),s.apply(this,e),l);An(t),d>0?_e(this).transition().duration(d).call(y,u,r,t):_e(this).call(g.transform,u,r,t)}}function E(i,...s){if(n.apply(this,arguments)){var o,r,a,h,l=i.touches,d=l.length,u=x(this,s,i.changedTouches.length===d).event(i);for(Pn(i),r=0;ru}h.mouse("drag",n)}function g(t){_e(t.view).on("mousemove.drag mouseup.drag",null),xe(t.view,i),ve(t),h.mouse("end",t)}function p(t,e){if(s.call(this,t,e)){var i,n,r=t.changedTouches,a=o.call(this,t,e),h=r.length;for(i=0;i{this.recenter()}),this._simulator.setupData({nodes:n,edges:s})}t.strategy&&(c(t.strategy.isDefaultHoverEnabled)&&(this._settings.strategy.isDefaultHoverEnabled=t.strategy.isDefaultHoverEnabled,this._strategy.isHoverEnabled=this._settings.strategy.isDefaultHoverEnabled),c(t.strategy.isDefaultSelectEnabled)&&(this._settings.strategy.isDefaultSelectEnabled=t.strategy.isDefaultSelectEnabled,this._strategy.isSelectEnabled=this._settings.strategy.isDefaultSelectEnabled),c(t.strategy.isDefaultMultiSelectEnabled)&&(this._settings.strategy.isDefaultMultiSelectEnabled=t.strategy.isDefaultMultiSelectEnabled,this._strategy.isMultiSelectEnabled=this._settings.strategy.isDefaultMultiSelectEnabled),c(t.strategy.isDefaultSelectCascadeEnabled)&&(this._settings.strategy.isDefaultSelectCascadeEnabled=t.strategy.isDefaultSelectCascadeEnabled,this._strategy.isSelectCascadeEnabled=this._settings.strategy.isDefaultSelectCascadeEnabled)),t.interaction&&(c(t.interaction.isDragEnabled)&&(this._settings.interaction.isDragEnabled=t.interaction.isDragEnabled),c(t.interaction.isZoomEnabled)&&(this._settings.interaction.isZoomEnabled=t.interaction.isZoomEnabled),t.interaction.backgroundDrag&&(this._settings.interaction.backgroundDrag=Object.assign(Object.assign({},this._settings.interaction.backgroundDrag),t.interaction.backgroundDrag)))}static _needsGPU(t){var e;return"force"===t.type&&!!(null===(e=t.options)||void 0===e?void 0:e.useGPU)}render(t){t&&(this._simulator.isSimulationRunning()?this._simulator.once(On.SIMULATION_END,()=>{this._renderer.once(Us.RENDER_END,()=>t())}):this._renderer.once(Us.RENDER_END,()=>t())),this._renderer.render(this._graph)}recenter(t,e){"function"==typeof t&&(e=t,t=void 0);const i=(t=>{var e,i,n,s,o,r;if("hierarchical"===t.type){const n=t.options;return{anchorX:null!==(e=n.anchorX)&&void 0!==e?e:"horizontal"===n.orientation?n.reversed?"end":"start":"center",anchorY:null!==(i=n.anchorY)&&void 0!==i?i:"vertical"===n.orientation?n.reversed?"end":"start":"center"}}return{anchorX:null!==(s=null===(n=t.options)||void 0===n?void 0:n.anchorX)&&void 0!==s?s:"center",anchorY:null!==(r=null===(o=t.options)||void 0===o?void 0:o.anchorY)&&void 0!==r?r:"center"}})(this._settings.layout),n=Object.assign(Object.assign({},i),t),s=this._renderer.getFitZoomTransform(this._graph,n);_e(this._renderer.canvas).transition().duration(this._settings.zoomFitTransitionMs).ease(Ae).call(this._d3Zoom.transform,s).on("end",()=>this.render(e))}getSVG(t){return Jo(this._graph,Object.assign({backgroundColor:this._settings.render.backgroundColor},t))}destroy(){this._renderer.destroy(),this._simulator.terminate()}_isBackgroundDragModifierActive(t){var e;const i=this._settings.interaction.backgroundDrag;if(!(null==i?void 0:i.isEnabled))return!1;switch(null!==(e=i.modifier)&&void 0!==e?e:"shift"){case"shift":return t.shiftKey;case"ctrl":return t.ctrlKey;case"alt":return t.altKey;case"meta":return t.metaKey;case null:return!0;default:return!1}}_emitBackgroundDrag(t,e){const i=this.getCanvasMousePosition(e),n=this._renderer.getSimulationPosition(i);this._events.emit(t,{event:e,localPoint:n,globalPoint:i})}getCanvasMousePosition(t){var e,i,n,s;const o=this._renderer.canvas.getBoundingClientRect();let r=null!==(i=null!==(e=t.clientX)&&void 0!==e?e:t.pageX)&&void 0!==i?i:t.x,a=null!==(s=null!==(n=t.clientY)&&void 0!==n?n:t.pageY)&&void 0!==s?s:t.y;return r-=o.left,a-=o.top,this._settings.areCoordinatesRounded&&(r=Math.floor(r),a=Math.floor(a)),this._settings.isOutOfBoundsDragEnabled||(r=Math.max(0,Math.min(this._renderer.width,r)),a=Math.max(0,Math.min(this._renderer.height,a))),{x:r,y:a}}fixNodes(){this._simulator.fixNodes()}releaseNodes(){this._simulator.releaseNodes()}}var ur=i(481);class cr{constructor(t,e){var i,n,o,r,a,h,l,d,u,c,_,f;this._invalidateStyles=()=>{var t,e;null===(e=(t=this._renderer).invalidateStyles)||void 0===e||e.call(t)},this._update=()=>{this._invalidateStyles(),this.render()},this._container=t,this._graph=new Ts(void 0,{onLoadedImages:()=>{this._renderer.isInitiallyRendered&&this.render()},listeners:[this._update]}),this._graph.setDefaultStyle(X()),this._events=new s,this._interaction=new ar(this._graph),this._settings=Object.assign(Object.assign({areCollapsedContainerDimensionsAllowed:!1},e),{map:{zoomLevel:null!==(n=null===(i=e.map)||void 0===i?void 0:i.zoomLevel)&&void 0!==n?n:2,tile:null!==(r=null===(o=e.map)||void 0===o?void 0:o.tile)&&void 0!==r?r:{instance:new ur.TileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"),attribution:'Leaflet | Map data © OpenStreetMap contributors'},nodeSizeMode:null!==(h=null===(a=e.map)||void 0===a?void 0:a.nodeSizeMode)&&void 0!==h?h:"geographic"},render:Object.assign({type:zs.CANVAS},e.render),strategy:Object.assign({isDefaultHoverEnabled:!0,isDefaultSelectEnabled:!0,isDefaultMultiSelectEnabled:!1,isDefaultSelectCascadeEnabled:!0},null==e?void 0:e.strategy)}),this._strategy=new Bs({isDefaultSelectEnabled:null!==(l=this._settings.strategy.isDefaultSelectEnabled)&&void 0!==l&&l,isDefaultHoverEnabled:null!==(d=this._settings.strategy.isDefaultHoverEnabled)&&void 0!==d&&d,isDefaultMultiSelectEnabled:null===(u=this._settings.strategy.isDefaultMultiSelectEnabled)||void 0===u||u,isDefaultSelectCascadeEnabled:null===(c=this._settings.strategy.isDefaultSelectCascadeEnabled)||void 0===c||c}),this._rendererType=null!==(f=null===(_=null==e?void 0:e.render)||void 0===_?void 0:_.type)&&void 0!==f?f:zs.CANVAS,this._initRenderer(this._rendererType),this._map=this._initMap(),this._leaflet=this._initLeaflet(),this._handleTileChange()}_initRenderer(t){try{this._renderer=Mo.getRenderer(this._container,t,this._settings.render)}catch(t){throw this._container.textContent=t.message,t}this._renderer.on(Us.RENDER_END,t=>{this._events.emit(e.RENDER_END,t)}),this._renderer.on(Us.RESIZE,()=>{this._renderer.isInitiallyRendered&&(this._leaflet.invalidateSize(!1),this._renderer.render(this._graph))}),this._settings.render=this._renderer.getSettings(),this._renderer.canvas.style.zIndex="2",this._renderer.canvas.style.pointerEvents="none"}setRenderer(t){if(t===this._rendererType)return;this._renderer.destroy(),this._initRenderer(t),this._rendererType=t;const e=this._leaflet._mapPane._leaflet_pos,i=this._getStyleScale();this._renderer.transform=Object.assign(Object.assign({},e),{k:i}),this.render()}get data(){return this._graph}get events(){return this._events}get interaction(){return this._interaction}get leaflet(){return this._leaflet}get canvas(){return this._renderer.canvas}getSimulationPosition(t){const e=this._leaflet.containerPointToLayerPoint([t.x,t.y]);return this._toSimulationPoint(e)}getCanvasPosition(t){const e=this._getStyleScale(),i=this._leaflet.layerPointToContainerPoint([t.x*e,t.y*e]);return{x:i.x,y:i.y}}getSimulationViewRectangle(){const t=this._leaflet.getSize(),e=this.getSimulationPosition({x:0,y:0}),i=this.getSimulationPosition({x:t.x,y:t.y});return{x:e.x,y:e.y,width:i.x-e.x,height:i.y-e.y}}getSettings(){return m(this._settings)}setSettings(t){if(t.getGeoPosition&&(this._settings.getGeoPosition=t.getGeoPosition,this._updateGraphPositions()),t.map&&("number"==typeof t.map.zoomLevel&&(this._settings.map.zoomLevel=t.map.zoomLevel,this._leaflet.setZoom(t.map.zoomLevel)),t.map.tile&&(this._settings.map.tile=t.map.tile,this._handleTileChange()),t.map.nodeSizeMode&&t.map.nodeSizeMode!==this._settings.map.nodeSizeMode)){this._settings.map.nodeSizeMode=t.map.nodeSizeMode,this._updateGraphPositions();const e=this._leaflet._mapPane._leaflet_pos,i=this._getStyleScale();this._renderer.transform=Object.assign(Object.assign({},e),{k:i}),this._renderer.render(this._graph)}t.render&&(t.render.type&&t.render.type!==this._rendererType&&this.setRenderer(t.render.type),this._renderer.setSettings(t.render),this._settings.render=this._renderer.getSettings()),t.strategy&&(c(t.strategy.isDefaultHoverEnabled)&&(this._settings.strategy.isDefaultHoverEnabled=t.strategy.isDefaultHoverEnabled,this._strategy.isHoverEnabled=this._settings.strategy.isDefaultHoverEnabled),c(t.strategy.isDefaultSelectEnabled)&&(this._settings.strategy.isDefaultSelectEnabled=t.strategy.isDefaultSelectEnabled,this._strategy.isSelectEnabled=this._settings.strategy.isDefaultSelectEnabled),c(t.strategy.isDefaultMultiSelectEnabled)&&(this._settings.strategy.isDefaultMultiSelectEnabled=t.strategy.isDefaultMultiSelectEnabled,this._strategy.isMultiSelectEnabled=this._settings.strategy.isDefaultMultiSelectEnabled),c(t.strategy.isDefaultSelectCascadeEnabled)&&(this._settings.strategy.isDefaultSelectCascadeEnabled=t.strategy.isDefaultSelectCascadeEnabled,this._strategy.isSelectCascadeEnabled=this._settings.strategy.isDefaultSelectCascadeEnabled))}render(t){t&&this._renderer.once(Us.RENDER_END,()=>t()),this._updateGraphPositions(),this._renderer.render(this._graph)}zoomIn(t){this._leaflet.zoomIn(),null==t||t()}recenter(t){const e=this._graph.getBoundingBox(),i=this._getStyleScale(),n=this._leaflet.layerPointToLatLng([e.x*i,e.y*i]),s=this._leaflet.layerPointToLatLng([(e.x+e.width)*i,(e.y+e.height)*i]);this._leaflet.fitBounds(ur.latLngBounds(n,s)),null==t||t()}zoomOut(t){this._leaflet.zoomOut(),null==t||t()}getSVG(){throw new Error("SVG export is not supported on OrbMapView.")}destroy(){this._renderer.destroy(),this._leaflet.off(),this._leaflet.remove(),this._leaflet.getContainer().outerHTML=""}_initMap(){const t=document.createElement("div");return t.style.position="absolute",t.style.width="100%",t.style.height="100%",t.style.zIndex="1",t.style.cursor="default",this._container.appendChild(t),t}_initLeaflet(){const t=ur.map(this._map,{doubleClickZoom:!1,zoomControl:!1}).setView([0,0],this._settings.map.zoomLevel);return t.on("zoomstart",()=>{this._renderer.reset()}),t.on("zoom",t=>{var i,n;this._updateGraphPositions(),null===(n=(i=this._renderer).invalidateBuffers)||void 0===n||n.call(i);const s=t.target._mapPane._leaflet_pos,o=this._getStyleScale();this._renderer.transform=Object.assign(Object.assign({},s),{k:o}),this._renderer.render(this._graph),this._events.emit(e.TRANSFORM,{transform:Object.assign(Object.assign({},s),{k:o})})}),t.on("mousemove",t=>{const i=this._toSimulationPoint(t.layerPoint),n={x:t.containerPoint.x,y:t.containerPoint.y},s=this._strategy.onMouseMove(this._graph,i),o=s.changedSubject;o&&s.isStateChanged&&(E(o)&&this._events.emit(e.NODE_HOVER,{node:o,event:t.originalEvent,localPoint:i,globalPoint:n}),L(o)&&this._events.emit(e.EDGE_HOVER,{edge:o,event:t.originalEvent,localPoint:i,globalPoint:n})),this._events.emit(e.MOUSE_MOVE,{subject:o,event:t.originalEvent,localPoint:i,globalPoint:n}),s.isStateChanged&&(this._invalidateStyles(),this._renderer.render(this._graph))}),t.on("click contextmenu dblclick",t=>{const i=this._toSimulationPoint(t.layerPoint),n={x:t.containerPoint.x,y:t.containerPoint.y};if("contextmenu"===t.type){const s=this._strategy.onMouseRightClick(this._graph,i),o=s.changedSubject;o&&(E(o)&&this._events.emit(e.NODE_RIGHT_CLICK,{node:o,event:t.originalEvent,localPoint:i,globalPoint:n}),L(o)&&this._events.emit(e.EDGE_RIGHT_CLICK,{edge:o,event:t.originalEvent,localPoint:i,globalPoint:n})),this._events.emit(e.MOUSE_RIGHT_CLICK,{subject:o,event:t.originalEvent,localPoint:i,globalPoint:n}),s.isStateChanged&&(this._invalidateStyles(),this._renderer.render(this._graph))}else if("click"===t.type){const s=this._strategy.onMouseClick(this._graph,i,{isAppend:t.originalEvent.shiftKey}),o=s.changedSubject;o&&(E(o)&&this._events.emit(e.NODE_CLICK,{node:o,event:t.originalEvent,localPoint:i,globalPoint:n}),L(o)&&this._events.emit(e.EDGE_CLICK,{edge:o,event:t.originalEvent,localPoint:i,globalPoint:n})),this._events.emit(e.MOUSE_CLICK,{subject:o,event:t.originalEvent,localPoint:i,globalPoint:n}),(s.isStateChanged||s.changedSubject)&&(this._invalidateStyles(),this._renderer.render(this._graph))}else if("dblclick"===t.type){const s=this._strategy.onMouseDoubleClick(this._graph,i),o=s.changedSubject;if(o&&(E(o)&&this._events.emit(e.NODE_DOUBLE_CLICK,{node:o,event:t.originalEvent,localPoint:i,globalPoint:n}),L(o)&&this._events.emit(e.EDGE_DOUBLE_CLICK,{edge:o,event:t.originalEvent,localPoint:i,globalPoint:n})),this._events.emit(e.MOUSE_DOUBLE_CLICK,{subject:o,event:t.originalEvent,localPoint:i,globalPoint:n}),!o){const e=t.target._zoom+1;t.target.setZoomAround(t.layerPoint,e)}(s.isStateChanged||s.changedSubject)&&(this._invalidateStyles(),this._renderer.render(this._graph))}}),t.on("moveend",t=>{const e=t.target._mapPane._leaflet_pos,i=this._getStyleScale();this._renderer.transform=Object.assign(Object.assign({},e),{k:i}),this._renderer.render(this._graph)}),t.on("drag",t=>{const i=t.target._mapPane._leaflet_pos,n=this._getStyleScale();this._renderer.transform=Object.assign(Object.assign({},i),{k:n}),this._renderer.render(this._graph),this._events.emit(e.TRANSFORM,{transform:Object.assign(Object.assign({},i),{k:n})})}),t}_updateGraphPositions(){const t=this._graph.getNodes(),e=this._getStyleScale();for(let i=0;i{this._leaflet.attributionControl.setPrefix(t.attribution),this._leaflet.eachLayer(t=>this._leaflet.removeLayer(t)),t.instance.addTo(this._leaflet)})}}})(),n})()); \ No newline at end of file diff --git a/package.json b/package.json index b7696ae..ead235d 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,16 @@ }, "main": "dist/index.js", "types": "dist/index.d.ts", + "exports": { + ".": { + "types": "./dist/index.d.ts", + "default": "./dist/index.js" + }, + "./interactions": { + "types": "./dist/interactions/index.d.ts", + "default": "./dist/interactions/index.js" + } + }, "contributors": [ { "name": "David Lozic", diff --git a/src/common/area/area.ts b/src/common/area/area.ts new file mode 100644 index 0000000..5501a56 --- /dev/null +++ b/src/common/area/area.ts @@ -0,0 +1,28 @@ +import { IPosition } from '../position'; +import { IRectangle } from '../rectangle'; + +/** + * A 2D region used to test which graph objects fall within a selection. + * + * Implementations describe an arbitrary shape (a rectangle today, e.g. a polygon + * later) through a point-containment predicate. This keeps area-based queries + * such as `IGraph.getNodesInArea` shape-agnostic. + */ +export interface ISelectionArea { + /** + * Checks if the point (x, y) is inside the area. + * + * @param {IPosition} point Point (x, y) in simulation coordinates + * @return {boolean} True if the point is inside the area, otherwise false + */ + contains(point: IPosition): boolean; + + /** + * Returns the axis-aligned bounding box of the area. + * + * Used as a cheap pre-filter before the (possibly more expensive) contains check. + * + * @return {IRectangle} Bounding box of the area + */ + getBoundingBox(): IRectangle; +} diff --git a/src/common/area/index.ts b/src/common/area/index.ts new file mode 100644 index 0000000..07dfadd --- /dev/null +++ b/src/common/area/index.ts @@ -0,0 +1,2 @@ +export { ISelectionArea } from './area'; +export { RectangleArea } from './rectangle'; diff --git a/src/common/area/rectangle.ts b/src/common/area/rectangle.ts new file mode 100644 index 0000000..e51b08f --- /dev/null +++ b/src/common/area/rectangle.ts @@ -0,0 +1,33 @@ +import { IPosition } from '../position'; +import { getRectangleFromPoints, IRectangle, isPointInRectangle } from '../rectangle'; +import { ISelectionArea } from './area'; + +/** + * Rectangular {@link ISelectionArea} defined by an axis-aligned rectangle. + */ +export class RectangleArea implements ISelectionArea { + private readonly _rectangle: IRectangle; + + constructor(rectangle: IRectangle) { + this._rectangle = rectangle; + } + + /** + * Creates a rectangular area from two opposite corner points, given in any order. + * + * @param {IPosition} pointA First corner (x, y) + * @param {IPosition} pointB Opposite corner (x, y) + * @return {RectangleArea} Rectangular area spanning the two corners + */ + static fromPoints(pointA: IPosition, pointB: IPosition): RectangleArea { + return new RectangleArea(getRectangleFromPoints(pointA, pointB)); + } + + contains(point: IPosition): boolean { + return isPointInRectangle(this._rectangle, point); + } + + getBoundingBox(): IRectangle { + return this._rectangle; + } +} diff --git a/src/common/index.ts b/src/common/index.ts index c660560..65bea8b 100644 --- a/src/common/index.ts +++ b/src/common/index.ts @@ -2,4 +2,5 @@ export { ICircle } from './circle'; export { Color, IColorRGB } from './color'; export { getDistanceToLine } from './distance'; export { IPosition, isEqualPosition } from './position'; -export { IRectangle, isPointInRectangle } from './rectangle'; +export { IRectangle, isPointInRectangle, getRectangleFromPoints } from './rectangle'; +export { ISelectionArea, RectangleArea } from './area'; diff --git a/src/common/rectangle.ts b/src/common/rectangle.ts index b27c11d..d7f37a1 100644 --- a/src/common/rectangle.ts +++ b/src/common/rectangle.ts @@ -22,3 +22,17 @@ export const isPointInRectangle = (rectangle: IRectangle, point: IPosition): boo const endY = rectangle.y + rectangle.height; return point.x >= rectangle.x && point.x <= endX && point.y >= rectangle.y && point.y <= endY; }; + +/** + * Builds a normalized rectangle spanning two opposite corner points, given in any order. + * + * @param {IPosition} pointA First corner (x, y) + * @param {IPosition} pointB Opposite corner (x, y) + * @return {IRectangle} Rectangle spanning the two corners + */ +export const getRectangleFromPoints = (pointA: IPosition, pointB: IPosition): IRectangle => ({ + x: Math.min(pointA.x, pointB.x), + y: Math.min(pointA.y, pointB.y), + width: Math.abs(pointA.x - pointB.x), + height: Math.abs(pointA.y - pointB.y), +}); diff --git a/src/events.ts b/src/events.ts index 22e5924..7ec30d8 100644 --- a/src/events.ts +++ b/src/events.ts @@ -24,6 +24,11 @@ export enum OrbEventType { NODE_DRAG_START = 'node-drag-start', NODE_DRAG = 'node-drag', NODE_DRAG_END = 'node-drag-end', + // Neutral drag on the empty background (e.g. shift-drag), not on a node. + BACKGROUND_DRAG_START = 'background-drag-start', + BACKGROUND_DRAG = 'background-drag', + BACKGROUND_DRAG_END = 'background-drag-end', + // Right click events NODE_RIGHT_CLICK = 'node-right-click', EDGE_RIGHT_CLICK = 'edge-right-click', MOUSE_RIGHT_CLICK = 'mouse-right-click', @@ -107,6 +112,8 @@ export type IOrbEventNodeDrag = IOrbEv export type IOrbEventNodeDragEnd = IOrbEventMouseNodeEvent & IOrbEventMouseMoveEvent; +export type IOrbEventBackgroundDrag = IOrbEventMouseMoveEvent; + export class OrbEmitter extends Emitter<{ [OrbEventType.RENDER_START]: undefined; [OrbEventType.RENDER_END]: IOrbEventRenderEnd; @@ -123,6 +130,9 @@ export class OrbEmitter extends Emitte [OrbEventType.NODE_DRAG_START]: IOrbEventNodeDragStart; [OrbEventType.NODE_DRAG]: IOrbEventNodeDrag; [OrbEventType.NODE_DRAG_END]: IOrbEventNodeDragEnd; + [OrbEventType.BACKGROUND_DRAG_START]: IOrbEventBackgroundDrag; + [OrbEventType.BACKGROUND_DRAG]: IOrbEventBackgroundDrag; + [OrbEventType.BACKGROUND_DRAG_END]: IOrbEventBackgroundDrag; [OrbEventType.NODE_RIGHT_CLICK]: IOrbEventMouseNodeEvent & IOrbEventMouseClickEvent; [OrbEventType.EDGE_RIGHT_CLICK]: IOrbEventMouseEdgeEvent & IOrbEventMouseClickEvent; [OrbEventType.MOUSE_RIGHT_CLICK]: IOrbEventMouseEvent & IOrbEventMouseClickEvent; diff --git a/src/index.ts b/src/index.ts index 6e9b312..091a93b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -13,6 +13,7 @@ export { IOrbEventNodeDragStart, IOrbEventNodeDrag, IOrbEventNodeDragEnd, + IOrbEventBackgroundDrag, } from './events'; export { OrbError } from './exceptions'; export { IGraph, IGraphData, INodeFilter, IEdgeFilter } from './models/graph'; @@ -29,7 +30,7 @@ export { IEdgeLineStyle, } from './models/edge'; export { IGraphStyle, getDefaultGraphStyle } from './models/style'; -export { ICircle, IPosition, IRectangle, Color, IColorRGB } from './common'; +export { ICircle, IPosition, IRectangle, Color, IColorRGB, ISelectionArea, RectangleArea } from './common'; export { OrbView, OrbMapView, IOrbView, IOrbMapViewSettings, IOrbViewSettings } from './views'; export { graphToSVG, ISVGExportOptions } from './renderer/svg'; export { RendererType, IRendererSettings, IRendererSettingsInit, IFitZoomTransformOptions } from './renderer/shared'; diff --git a/src/interactions/index.ts b/src/interactions/index.ts new file mode 100644 index 0000000..dad1d52 --- /dev/null +++ b/src/interactions/index.ts @@ -0,0 +1,10 @@ +export { RectangleSelection } from './rectangle-selection'; +export { + IRectangleSelectionOptions, + IRectangleSelectionStyle, + IRectangleSelectionSelectEvent, + IRectangleSelectionMode, + IRectangleSelectionEdgeMode, + RectangleSelectionEventType, + DEFAULT_RECTANGLE_SELECTION_STYLE, +} from './shared'; diff --git a/src/interactions/rectangle-selection.ts b/src/interactions/rectangle-selection.ts new file mode 100644 index 0000000..03faca8 --- /dev/null +++ b/src/interactions/rectangle-selection.ts @@ -0,0 +1,162 @@ +import { Emitter } from '../utils/emitter.utils'; +import { IOrbView } from '../views/shared'; +import { OrbEventType, IOrbEventBackgroundDrag } from '../events'; +import { getRectangleFromPoints, IPosition, RectangleArea } from '../common'; +import { INode, INodeBase } from '../models/node'; +import { IEdge, IEdgeBase } from '../models/edge'; +import { + CLASS_NAME, + DEFAULT_RECTANGLE_SELECTION_STYLE, + IRectangleSelectionEdgeMode, + IRectangleSelectionMode, + IRectangleSelectionOptions, + IRectangleSelectionStyle, + RectangleSelectionEvents, + RectangleSelectionEventType, +} from './shared'; + +const DEFAULT_RESOLVE_MODE = (event: MouseEvent): IRectangleSelectionMode => + event.ctrlKey || event.metaKey ? 'add' : 'replace'; + +// Marquee selection built on Orb's public API: it listens for the view's neutral +// BACKGROUND_DRAG_* events, draws its own DOM overlay, and applies the selection +// via getNodesInArea + selectNodesByIds. Requires background drag to be enabled on +// the view (interaction.backgroundDrag). +export class RectangleSelection extends Emitter< + RectangleSelectionEvents +> { + private readonly _view: IOrbView; + private readonly _resolveMode: (event: MouseEvent) => IRectangleSelectionMode; + private readonly _includeEdges: IRectangleSelectionEdgeMode; + private readonly _style: IRectangleSelectionStyle; + + private _overlay?: HTMLDivElement; + private _start?: { canvas: IPosition; simulation: IPosition }; + private _previousCursor?: string; + + constructor(view: IOrbView, options?: IRectangleSelectionOptions) { + super(); + this._view = view; + this._resolveMode = options?.resolveMode ?? DEFAULT_RESOLVE_MODE; + this._includeEdges = options?.includeEdges ?? 'none'; + this._style = { ...DEFAULT_RECTANGLE_SELECTION_STYLE, ...options?.style }; + + this._view.events.on(OrbEventType.BACKGROUND_DRAG_START, this._onDragStart); + this._view.events.on(OrbEventType.BACKGROUND_DRAG, this._onDrag); + this._view.events.on(OrbEventType.BACKGROUND_DRAG_END, this._onDragEnd); + } + + // Detaches all listeners and removes any lingering overlay. + destroy(): void { + this._view.events.off(OrbEventType.BACKGROUND_DRAG_START, this._onDragStart); + this._view.events.off(OrbEventType.BACKGROUND_DRAG, this._onDrag); + this._view.events.off(OrbEventType.BACKGROUND_DRAG_END, this._onDragEnd); + this._removeOverlay(); + this.removeAllListeners(); + } + + private _onDragStart = (event: IOrbEventBackgroundDrag): void => { + this._start = { canvas: event.globalPoint, simulation: event.localPoint }; + this._createOverlay(); + this._updateOverlay(event.globalPoint); + }; + + private _onDrag = (event: IOrbEventBackgroundDrag): void => { + if (!this._start) { + return; + } + this._updateOverlay(event.globalPoint); + }; + + private _onDragEnd = (event: IOrbEventBackgroundDrag): void => { + if (!this._start) { + this._removeOverlay(); + return; + } + + const area = RectangleArea.fromPoints(this._start.simulation, event.localPoint); + const nodes = this._view.data.getNodesInArea(area); + const mode = this._resolveMode(event.event); + + if (mode === 'replace') { + this._view.interaction.unselectAll(); + } + this._view.interaction.selectNodesByIds(nodes.map((node) => node.getId())); + + const edges = this._selectEdges(nodes); + + this._view.render(); + this._removeOverlay(); + this._start = undefined; + + this.emit(RectangleSelectionEventType.SELECT, { nodes, edges, area, mode }); + }; + + private _selectEdges(nodes: INode[]): IEdge[] { + if (this._includeEdges !== 'endpointsInside') { + return []; + } + + const nodeIds = new Set(nodes.map((node) => node.getId())); + const edges = this._view.data.getEdges( + (edge) => nodeIds.has(edge.startNode?.getId()) && nodeIds.has(edge.endNode?.getId()), + ); + this._view.interaction.selectEdgesByIds(edges.map((edge) => edge.getId())); + return edges; + } + + private _createOverlay(): void { + const canvas = this._view.canvas; + const container = canvas.parentElement; + if (!container) { + return; + } + + // The overlay is absolutely positioned, so the container needs to be a positioning context. + if (getComputedStyle(container).position === 'static') { + container.style.position = 'relative'; + } + + const overlay = document.createElement('div'); + overlay.className = CLASS_NAME; + overlay.style.position = 'absolute'; + overlay.style.pointerEvents = 'none'; + overlay.style.boxSizing = 'border-box'; + overlay.style.left = '0px'; + overlay.style.top = '0px'; + overlay.style.width = '0px'; + overlay.style.height = '0px'; + overlay.style.background = this._style.fillColor; + overlay.style.border = `${this._style.borderWidth}px ${this._style.borderStyle} ${this._style.borderColor}`; + overlay.style.borderRadius = `${this._style.borderRadius}px`; + container.appendChild(overlay); + this._overlay = overlay; + + this._previousCursor = canvas.style.cursor; + canvas.style.cursor = 'crosshair'; + } + + private _updateOverlay(currentCanvas: IPosition): void { + if (!this._overlay || !this._start) { + return; + } + + // The canvas fills the container at (0, 0), so canvas pixels are container pixels. + const rectangle = getRectangleFromPoints(this._start.canvas, currentCanvas); + this._overlay.style.left = `${rectangle.x}px`; + this._overlay.style.top = `${rectangle.y}px`; + this._overlay.style.width = `${rectangle.width}px`; + this._overlay.style.height = `${rectangle.height}px`; + } + + private _removeOverlay(): void { + if (this._overlay) { + this._overlay.remove(); + this._overlay = undefined; + } + if (this._previousCursor !== undefined) { + this._view.canvas.style.cursor = this._previousCursor; + this._previousCursor = undefined; + } + } +} diff --git a/src/interactions/shared.ts b/src/interactions/shared.ts new file mode 100644 index 0000000..bd7455e --- /dev/null +++ b/src/interactions/shared.ts @@ -0,0 +1,50 @@ +import { INode, INodeBase } from '../models/node'; +import { IEdge, IEdgeBase } from '../models/edge'; +import { RectangleArea } from '../common'; + +export type IRectangleSelectionMode = 'replace' | 'add'; + +export type IRectangleSelectionEdgeMode = 'none' | 'endpointsInside'; + +// Applied as inline styles on the overlay element, which also carries the +// `orb-selection-rectangle` class for CSS overrides. +export interface IRectangleSelectionStyle { + fillColor: string; + borderColor: string; + borderWidth: number; + borderStyle: 'solid' | 'dashed' | 'dotted'; + borderRadius: number; +} + +export interface IRectangleSelectionOptions { + // Defaults to: ctrl/meta held -> 'add', otherwise 'replace'. + resolveMode?: (event: MouseEvent) => IRectangleSelectionMode; + // 'endpointsInside' also selects edges whose both endpoints fall in the area. + includeEdges?: IRectangleSelectionEdgeMode; + style?: Partial; +} + +export interface IRectangleSelectionSelectEvent { + nodes: INode[]; + edges: IEdge[]; + area: RectangleArea; + mode: IRectangleSelectionMode; +} + +export enum RectangleSelectionEventType { + SELECT = 'select', +} + +export type RectangleSelectionEvents = { + [RectangleSelectionEventType.SELECT]: IRectangleSelectionSelectEvent; +}; + +export const DEFAULT_RECTANGLE_SELECTION_STYLE: IRectangleSelectionStyle = { + fillColor: 'rgba(63, 127, 191, 0.12)', + borderColor: 'rgba(63, 127, 191, 0.9)', + borderWidth: 1, + borderStyle: 'dashed', + borderRadius: 2, +}; + +export const CLASS_NAME = 'orb-selection-rectangle'; diff --git a/src/models/edge.ts b/src/models/edge.ts index 0a3374b..a2c412b 100644 --- a/src/models/edge.ts +++ b/src/models/edge.ts @@ -105,6 +105,7 @@ export interface IEdge extends ISubjec getStyle(): IEdgeStyle; getState(): number; getListeners(): IObserver[]; + getOnStateChange(): (() => void) | undefined; hasStyle(): boolean; isSelected(): boolean; isHovered(): boolean; @@ -135,6 +136,9 @@ export interface IEdge extends ISubjec export interface IEdgeSettings { listeners: IObserver[]; + // Called on every state change, including ones that skip listener notification, + // so renderers with cached styles can detect it. + onStateChange?: () => void; } export class EdgeFactory { @@ -159,12 +163,15 @@ export class EdgeFactory { edge: IEdge, data?: Omit, 'data' | 'startNode' | 'endNode'>, ): IEdge { - const newEdge = EdgeFactory.create({ - data: edge.getData(), - offset: data?.offset !== undefined ? data.offset : edge.offset, - startNode: edge.startNode, - endNode: edge.endNode, - }); + const newEdge = EdgeFactory.create( + { + data: edge.getData(), + offset: data?.offset !== undefined ? data.offset : edge.offset, + startNode: edge.startNode, + endNode: edge.endNode, + }, + { listeners: [], onStateChange: edge.getOnStateChange() }, + ); newEdge.setState(edge.getState()); newEdge.setStyle(edge.getStyle()); const listeners = edge.getListeners(); @@ -194,6 +201,7 @@ abstract class Edge extends Subject im protected _position: IEdgePosition; private _type: EdgeType = EdgeType.STRAIGHT; + private readonly _onStateChange?: () => void; constructor(data: IEdgeData, settings?: IEdgeSettings) { super(); @@ -208,6 +216,7 @@ abstract class Edge extends Subject im this.startNode.addEdge(this); this.endNode.addEdge(this); + this._onStateChange = settings?.onStateChange; if (settings && settings.listeners) { this.listeners = settings.listeners; } @@ -236,6 +245,10 @@ abstract class Edge extends Subject im return this._state; } + getOnStateChange(): (() => void) | undefined { + return this._onStateChange; + } + get type(): EdgeType { return this._type; } @@ -261,7 +274,10 @@ abstract class Edge extends Subject im } clearState(): void { - this._state = GraphObjectState.NONE; + if (this._state !== GraphObjectState.NONE) { + this._state = GraphObjectState.NONE; + this._onStateChange?.(); + } } isLoopback(): boolean { @@ -428,6 +444,7 @@ abstract class Edge extends Subject im | ((edge: IEdge) => IGraphObjectStateParameters), options?: IEdgeSetStateOptions, ): void { + const previousState = this._state; let result: number | IGraphObjectStateParameters; if (isFunction(arg)) { @@ -456,6 +473,8 @@ abstract class Edge extends Subject im if (!options?.isNotifySkipped) { this.notifyListeners(); + } else if (this._state !== previousState) { + this._onStateChange?.(); } } diff --git a/src/models/graph.ts b/src/models/graph.ts index 8b7801e..cb68b4a 100644 --- a/src/models/graph.ts +++ b/src/models/graph.ts @@ -1,6 +1,6 @@ import { INode, INodeBase, INodePosition, NodeFactory } from './node'; import { IEdge, EdgeFactory, IEdgeBase, IEdgePosition } from './edge'; -import { IPosition, IRectangle } from '../common'; +import { IPosition, IRectangle, ISelectionArea, isPointInRectangle } from '../common'; import { IGraphStyle } from './style'; import { ImageHandler } from '../services/images'; import { getEdgeOffsets } from './topology'; @@ -49,6 +49,8 @@ export interface IGraph extends ISubje getBoundingBox(): IRectangle; getNearestNode(point: IPosition): INode | undefined; getNearestEdge(point: IPosition, minDistance?: number): IEdge | undefined; + getNodesInArea(area: ISelectionArea): INode[]; + getStyleVersion(): number; setSettings(settings: Partial>): void; } @@ -74,6 +76,14 @@ export class Graph extends Subject imp private _defaultStyle?: Partial>; private _settings: IGraphSettings; + // Monotonic counter bumped whenever a node/edge state changes silently (notify skipped). + // Renderers that cache styles (WebGL) compare it to detect selection/hover changes a + // bare render() would otherwise miss; the canvas renderer reads state fresh and ignores it. + private _styleVersion = 0; + private _bumpStyleVersion = (): void => { + this._styleVersion++; + }; + constructor(data?: Partial>, settings?: Partial>) { // TODO(dlozic): How to use object assign here? If I add add and export a default const here, it needs N, E. super(); @@ -410,6 +420,24 @@ export class Graph extends Subject imp return nearestEdge; } + getNodesInArea(area: ISelectionArea): INode[] { + const boundingBox = area.getBoundingBox(); + return this.getNodes((node) => { + const position = node.getPosition(); + // Skip unpositioned nodes; getCenter() would report them at (0, 0). + if (position.x === undefined || position.y === undefined) { + return false; + } + const center: IPosition = { x: position.x, y: position.y }; + // Cheap bounding-box reject before the exact contains check. + return isPointInRectangle(boundingBox, center) && area.contains(center); + }); + } + + getStyleVersion(): number { + return this._styleVersion; + } + // Arrow function is used because they inherit the context from the enclosing scope // which is important for the callback to notify listeners as expected private _update: IObserver = (data?: IObserverDataPayload): void => { @@ -443,7 +471,11 @@ export class Graph extends Subject imp for (let i = 0; i < nodes.length; i++) { newNodes[i] = NodeFactory.create( { data: nodes[i] }, - { onLoadedImage: () => this._settings?.onLoadedImages?.(), listeners: [this._update] }, + { + onLoadedImage: () => this._settings?.onLoadedImages?.(), + listeners: [this._update], + onStateChange: this._bumpStyleVersion, + }, ); } this._nodes.setMany(newNodes); @@ -465,6 +497,7 @@ export class Graph extends Subject imp }, { listeners: [this._update], + onStateChange: this._bumpStyleVersion, }, ), ); @@ -486,7 +519,11 @@ export class Graph extends Subject imp newNodes.push( NodeFactory.create( { data: nodes[i] }, - { onLoadedImage: () => this._settings?.onLoadedImages?.(), listeners: [this._update] }, + { + onLoadedImage: () => this._settings?.onLoadedImages?.(), + listeners: [this._update], + onStateChange: this._bumpStyleVersion, + }, ), ); } @@ -515,6 +552,7 @@ export class Graph extends Subject imp }, { listeners: [this._update], + onStateChange: this._bumpStyleVersion, }, ); newEdges.push(edge); @@ -548,6 +586,7 @@ export class Graph extends Subject imp }, { listeners: [this._update], + onStateChange: this._bumpStyleVersion, }, ); edge.setState(existingEdge.getState(), { isNotifySkipped: true }); diff --git a/src/models/interaction.ts b/src/models/interaction.ts index a8fedd6..6957742 100644 --- a/src/models/interaction.ts +++ b/src/models/interaction.ts @@ -3,21 +3,29 @@ import { hoverNode, ISelectionOptions, selectEdge, + selectEdges, selectNode, + selectNodes, unhoverAll, unselectAll, unselectEdge, + unselectEdges, unselectNode, + unselectNodes, } from '../utils/graph.utils'; -import { IEdgeBase } from './edge'; +import { IEdge, IEdgeBase } from './edge'; import { IGraph } from './graph'; -import { INodeBase } from './node'; +import { INode, INodeBase } from './node'; export interface IGraphInteraction { selectNodeById(id: any, options?: ISelectionOptions): boolean; + selectNodesByIds(ids: any[], options?: ISelectionOptions): number; selectEdgeById(id: any, options?: ISelectionOptions): boolean; + selectEdgesByIds(ids: any[], options?: ISelectionOptions): number; unselectNodeById(id: any, options?: ISelectionOptions): boolean; + unselectNodesByIds(ids: any[], options?: ISelectionOptions): number; unselectEdgeById(id: any, options?: ISelectionOptions): boolean; + unselectEdgesByIds(ids: any[], options?: ISelectionOptions): number; unselectAll(): number; hoverNodeById(id: any): boolean; hoverEdgeById(id: any): boolean; @@ -40,6 +48,19 @@ export class GraphInteraction implemen return true; } + // Defaults to non-cascading (unlike selectNodeById): only the listed nodes change state. + selectNodesByIds(ids: any[], options?: ISelectionOptions): number { + const nodes: INode[] = []; + for (let i = 0; i < ids.length; i++) { + const node = this._graph.getNodeById(ids[i]); + if (node) { + nodes.push(node); + } + } + const { changedCount } = selectNodes(nodes, { cascade: false, ...options }); + return changedCount; + } + selectEdgeById(id: any, options?: ISelectionOptions): boolean { const edge = this._graph.getEdgeById(id); if (!edge) { @@ -49,6 +70,19 @@ export class GraphInteraction implemen return true; } + // Defaults to non-cascading (unlike selectEdgeById): only the listed edges change state. + selectEdgesByIds(ids: any[], options?: ISelectionOptions): number { + const edges: IEdge[] = []; + for (let i = 0; i < ids.length; i++) { + const edge = this._graph.getEdgeById(ids[i]); + if (edge) { + edges.push(edge); + } + } + const { changedCount } = selectEdges(edges, { cascade: false, ...options }); + return changedCount; + } + unselectNodeById(id: any, options?: ISelectionOptions): boolean { const node = this._graph.getNodeById(id); if (!node) { @@ -58,6 +92,18 @@ export class GraphInteraction implemen return true; } + unselectNodesByIds(ids: any[], options?: ISelectionOptions): number { + const nodes: INode[] = []; + for (let i = 0; i < ids.length; i++) { + const node = this._graph.getNodeById(ids[i]); + if (node) { + nodes.push(node); + } + } + const { changedCount } = unselectNodes(nodes, { cascade: false, ...options }); + return changedCount; + } + unselectEdgeById(id: any, options?: ISelectionOptions): boolean { const edge = this._graph.getEdgeById(id); if (!edge) { @@ -67,6 +113,18 @@ export class GraphInteraction implemen return true; } + unselectEdgesByIds(ids: any[], options?: ISelectionOptions): number { + const edges: IEdge[] = []; + for (let i = 0; i < ids.length; i++) { + const edge = this._graph.getEdgeById(ids[i]); + if (edge) { + edges.push(edge); + } + } + const { changedCount } = unselectEdges(edges, { cascade: false, ...options }); + return changedCount; + } + unselectAll(): number { const { changedCount } = unselectAll(this._graph); return changedCount; diff --git a/src/models/node.ts b/src/models/node.ts index 262c4a9..99190c3 100644 --- a/src/models/node.ts +++ b/src/models/node.ts @@ -140,6 +140,9 @@ export interface INode extends ISubjec export interface INodeSettings { onLoadedImage: () => void; listeners: IObserver[]; + // Called on every state change, including ones that skip listener notification + // (e.g. batched selection), so renderers with cached styles can detect it. + onStateChange: () => void; } export class NodeFactory { @@ -165,6 +168,7 @@ export class Node extends Subject impl private readonly _inEdgesById: { [id: number]: IEdge } = {}; private readonly _outEdgesById: { [id: number]: IEdge } = {}; private readonly _onLoadedImage?: () => void; + private readonly _onStateChange?: () => void; constructor(data: INodeData, settings?: Partial) { super(); @@ -172,6 +176,7 @@ export class Node extends Subject impl this._data = data.data; this._position = { id: this.id }; this._onLoadedImage = settings?.onLoadedImage; + this._onStateChange = settings?.onStateChange; if (settings && settings.listeners) { this.listeners = settings.listeners; } @@ -530,6 +535,7 @@ export class Node extends Subject impl | ((node: INode) => IGraphObjectStateParameters), options?: INodeSetStateOptions, ): void { + const previousState = this._state; let result: number | IGraphObjectStateParameters; if (isFunction(arg)) { @@ -558,6 +564,8 @@ export class Node extends Subject impl if (!options?.isNotifySkipped) { this.notifyListeners(); + } else if (this._state !== previousState) { + this._onStateChange?.(); } } diff --git a/src/renderer/canvas/canvas-renderer.ts b/src/renderer/canvas/canvas-renderer.ts index fa17af5..69ad50f 100644 --- a/src/renderer/canvas/canvas-renderer.ts +++ b/src/renderer/canvas/canvas-renderer.ts @@ -343,6 +343,11 @@ export class CanvasRenderer extends Em }; } + getCanvasPosition(simulationPoint: IPosition): IPosition { + const [x, y] = this.transform.apply([simulationPoint.x + this._width / 2, simulationPoint.y + this._height / 2]); + return { x, y }; + } + /** * Returns the visible rectangle view in the simulation coordinates. * diff --git a/src/renderer/shared.ts b/src/renderer/shared.ts index 7ad965e..72cace9 100644 --- a/src/renderer/shared.ts +++ b/src/renderer/shared.ts @@ -68,6 +68,15 @@ export interface IRenderer extends IEm getFitZoomTransform(graph: IGraph, options?: IFitZoomTransformOptions): ZoomTransform; getSimulationPosition(canvasPoint: IPosition): IPosition; + /** + * Converts a point in simulation coordinates into canvas (screen) pixels. + * Inverse of {@link getSimulationPosition}. + * + * @param {IPosition} simulationPoint Point (x, y) in simulation coordinates + * @return {IPosition} Point (x, y) relative to the canvas element + */ + getCanvasPosition(simulationPoint: IPosition): IPosition; + /** * Returns the visible rectangle view in the simulation coordinates. * diff --git a/src/renderer/webgl/webgl-renderer.ts b/src/renderer/webgl/webgl-renderer.ts index 9bc7a32..83114b9 100644 --- a/src/renderer/webgl/webgl-renderer.ts +++ b/src/renderer/webgl/webgl-renderer.ts @@ -432,6 +432,10 @@ export class WebGLRenderer extends Emi this._isColorCacheDirty = true; } + // Graph style version seen at the last render, to detect silent (notify-skipped) + // state changes such as programmatic/batched selection. + private _lastStyleVersion = -1; + getRenderCacheStats(): { hits: number; misses: number } { return { ...this._bufferCacheStats }; } @@ -455,6 +459,13 @@ export class WebGLRenderer extends Emi this.emit(RenderEventType.RENDER_START, undefined); const renderStartedAt = performance.now(); + // Silent state changes (skipped notify) bump the graph style version; rebuild colours when it moves. + const styleVersion = graph.getStyleVersion(); + if (styleVersion !== this._lastStyleVersion) { + this.invalidateStyles(); + this._lastStyleVersion = styleVersion; + } + const gl = this._gl; const rect = this._container.getBoundingClientRect(); @@ -481,7 +492,10 @@ export class WebGLRenderer extends Emi gl.clear(gl.COLOR_BUFFER_BIT); gl.enable(gl.BLEND); - gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA); + // Separate alpha factors: colour blends straight-over, but the framebuffer alpha must + // accumulate with ONE (not SRC_ALPHA) or semi-transparent shapes over the transparent + // clear get their alpha squared and wash out when the canvas composites over the page. + gl.blendFuncSeparate(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA); const edges = graph.getEdges(); const FLOATS_PER_EDGE = 25; @@ -499,6 +513,16 @@ export class WebGLRenderer extends Emi this._bufferCacheStats.misses++; } + // Match the canvas renderer's contextAlphaOnEvent behaviour: dim non-selected/hovered + // shapes when any is selected/hovered. Evaluated per type (like canvas), so selecting only + // nodes dims the other nodes but leaves edges untouched. Only on a rebuild, so panning stays free. + const contextAlpha = this._settings.contextAlphaOnEventIsEnabled ? this._settings.contextAlphaOnEvent : 1; + const isDimmingActive = !canSkipRebuild && contextAlpha < 1; + const hasStateChangedNodes = + isDimmingActive && graph.getNodes().some((node) => node.isSelected() || node.isHovered()); + const hasStateChangedEdges = + isDimmingActive && graph.getEdges().some((edge) => edge.isSelected() || edge.isHovered()); + let nodeCxCache: Float64Array | null = null; let nodeCyCache: Float64Array | null = null; let nodeBorderCache: Float64Array | null = null; @@ -569,6 +593,7 @@ export class WebGLRenderer extends Emi edge.isHovered() || edge.isSelected() ? this._resolveColor(edge.getColor()) : this._edgeColorCache.get(edge.id) || EDGE_DEFAULT_RGBA; + const dim = hasStateChangedEdges && !(edge.isHovered() || edge.isSelected()) ? contextAlpha : 1; let edgeType = EDGE_TYPE_STRAIGHT; let controlX = 0; @@ -689,11 +714,11 @@ export class WebGLRenderer extends Emi edgeData[off + 14] = rgba[0]; edgeData[off + 15] = rgba[1]; edgeData[off + 16] = rgba[2]; - edgeData[off + 17] = rgba[3]; + edgeData[off + 17] = rgba[3] * dim; edgeData[off + 18] = shadowColor[0]; edgeData[off + 19] = shadowColor[1]; edgeData[off + 20] = shadowColor[2]; - edgeData[off + 21] = shadowColor[3]; + edgeData[off + 21] = shadowColor[3] * dim; edgeData[off + 22] = shadowSize; edgeData[off + 23] = shadowOffsetX; edgeData[off + 24] = shadowOffsetY; @@ -787,6 +812,7 @@ export class WebGLRenderer extends Emi borderColor = this._nodeBorderColorCache.get(node.id) || TRANSPARENT_RGBA; borderWidth = node.getBorderWidth(); } + const dim = hasStateChangedNodes && !(node.isHovered() || node.isSelected()) ? contextAlpha : 1; instanceData[off] = center.x; instanceData[off + 1] = center.y; @@ -794,16 +820,16 @@ export class WebGLRenderer extends Emi instanceData[off + 3] = rgba[0]; instanceData[off + 4] = rgba[1]; instanceData[off + 5] = rgba[2]; - instanceData[off + 6] = rgba[3]; + instanceData[off + 6] = rgba[3] * dim; instanceData[off + 7] = borderColor[0]; instanceData[off + 8] = borderColor[1]; instanceData[off + 9] = borderColor[2]; - instanceData[off + 10] = borderColor[3]; + instanceData[off + 10] = borderColor[3] * dim; instanceData[off + 11] = borderWidth; instanceData[off + 12] = shadowColor[0]; instanceData[off + 13] = shadowColor[1]; instanceData[off + 14] = shadowColor[2]; - instanceData[off + 15] = shadowColor[3]; + instanceData[off + 15] = shadowColor[3] * dim; instanceData[off + 16] = shadowSize; instanceData[off + 17] = shadowOffsetX; instanceData[off + 18] = shadowOffsetY; @@ -1003,6 +1029,11 @@ export class WebGLRenderer extends Emi }; } + getCanvasPosition(simulationPoint: IPosition): IPosition { + const [x, y] = this.transform.apply([simulationPoint.x + this._width / 2, simulationPoint.y + this._height / 2]); + return { x, y }; + } + getSimulationViewRectangle(): IRectangle { const topLeftPosition = this.getSimulationPosition({ x: 0, y: 0 }); const bottomRightPosition = this.getSimulationPosition({ x: this._width, y: this._height }); diff --git a/src/utils/graph.utils.ts b/src/utils/graph.utils.ts index 6d0765f..4bad778 100644 --- a/src/utils/graph.utils.ts +++ b/src/utils/graph.utils.ts @@ -63,6 +63,46 @@ export const selectOnlyNode = ( selectNode(node, options); }; +export const selectNodes = ( + nodes: INode[], + options?: ISelectionOptions, +): { changedCount: number } => { + for (let i = 0; i < nodes.length; i++) { + selectNode(nodes[i], options); + } + return { changedCount: nodes.length }; +}; + +export const unselectNodes = ( + nodes: INode[], + options?: ISelectionOptions, +): { changedCount: number } => { + for (let i = 0; i < nodes.length; i++) { + unselectNode(nodes[i], options); + } + return { changedCount: nodes.length }; +}; + +export const selectEdges = ( + edges: IEdge[], + options?: ISelectionOptions, +): { changedCount: number } => { + for (let i = 0; i < edges.length; i++) { + selectEdge(edges[i], options); + } + return { changedCount: edges.length }; +}; + +export const unselectEdges = ( + edges: IEdge[], + options?: ISelectionOptions, +): { changedCount: number } => { + for (let i = 0; i < edges.length; i++) { + unselectEdge(edges[i], options); + } + return { changedCount: edges.length }; +}; + export const selectOnlyEdge = ( graph: IGraph, edge: IEdge, diff --git a/src/views/background-drag.ts b/src/views/background-drag.ts new file mode 100644 index 0000000..276addb --- /dev/null +++ b/src/views/background-drag.ts @@ -0,0 +1,18 @@ +export type IBackgroundDragModifier = 'shift' | 'ctrl' | 'alt' | 'meta' | null; + +export interface IBackgroundDragSettings { + isEnabled: boolean; + // `null` claims every background drag (disabling drag-to-pan). Defaults to 'shift'. + modifier?: IBackgroundDragModifier; +} + +// Sentinel returned by OrbView.dragSubject to route an empty-canvas drag to the +// background-drag handlers instead of node dragging. +export interface IBackgroundDragSubject { + isBackgroundDrag: true; +} + +export const BACKGROUND_DRAG_SUBJECT: IBackgroundDragSubject = { isBackgroundDrag: true }; + +export const isBackgroundDragSubject = (subject: unknown): subject is IBackgroundDragSubject => + !!subject && (subject as IBackgroundDragSubject).isBackgroundDrag === true; diff --git a/src/views/orb-map-view.ts b/src/views/orb-map-view.ts index 68de689..f2c29f4 100644 --- a/src/views/orb-map-view.ts +++ b/src/views/orb-map-view.ts @@ -3,7 +3,7 @@ import { IEdgeBase, isEdge } from '../models/edge'; import { INode, INodeBase, isNode } from '../models/node'; import { Graph, IGraph } from '../models/graph'; import { IOrbView } from './shared'; -import { IPosition } from '../common'; +import { IPosition, IRectangle } from '../common'; import { DefaultEventStrategy, IEventStrategy, IEventStrategySettings } from '../models/strategy'; import { copyObject } from '../utils/object.utils'; import { OrbEmitter, OrbEventType } from '../events'; @@ -199,6 +199,35 @@ export class OrbMapView implements IOr return this._leaflet; } + get canvas(): HTMLCanvasElement { + return this._renderer.canvas; + } + + getSimulationPosition(canvasPoint: IPosition): IPosition { + // The canvas overlays the Leaflet container, so canvas pixels are container pixels. + // The renderer's own conversion assumes origin centering, which the map view doesn't apply. + const layerPoint = this._leaflet.containerPointToLayerPoint([canvasPoint.x, canvasPoint.y]); + return this._toSimulationPoint(layerPoint); + } + + getCanvasPosition(simulationPoint: IPosition): IPosition { + const k = this._getStyleScale(); + const containerPoint = this._leaflet.layerPointToContainerPoint([simulationPoint.x * k, simulationPoint.y * k]); + return { x: containerPoint.x, y: containerPoint.y }; + } + + getSimulationViewRectangle(): IRectangle { + const size = this._leaflet.getSize(); + const topLeft = this.getSimulationPosition({ x: 0, y: 0 }); + const bottomRight = this.getSimulationPosition({ x: size.x, y: size.y }); + return { + x: topLeft.x, + y: topLeft.y, + width: bottomRight.x - topLeft.x, + height: bottomRight.y - topLeft.y, + }; + } + getSettings(): IOrbMapViewSettings { return copyObject(this._settings); } diff --git a/src/views/orb-view.ts b/src/views/orb-view.ts index eeb092f..0455ac4 100644 --- a/src/views/orb-view.ts +++ b/src/views/orb-view.ts @@ -6,7 +6,7 @@ import transition from 'd3-transition'; /* eslint-enable @typescript-eslint/no-unused-vars */ import { D3ZoomEvent, zoom, ZoomBehavior } from 'd3-zoom'; import { select } from 'd3-selection'; -import { IPosition, isEqualPosition } from '../common'; +import { IPosition, IRectangle, isEqualPosition } from '../common'; import { ISimulator, SimulatorFactory } from '../simulator'; import { Graph, IGraph, INodeFilter, IEdgeFilter } from '../models/graph'; import { INode, INodeBase, isNode } from '../models/node'; @@ -32,10 +32,17 @@ import { isBoolean } from '../utils/type.utils'; import { IObserver, IObserverDataPayload } from '../utils/observer.utils'; import { GraphInteraction, IGraphInteraction } from '../models/interaction'; import { getLayoutAnchors } from '../utils/graph.utils'; +import { + BACKGROUND_DRAG_SUBJECT, + IBackgroundDragSettings, + IBackgroundDragSubject, + isBackgroundDragSubject, +} from './background-drag'; export interface IGraphInteractionSettings { isDragEnabled: boolean; isZoomEnabled: boolean; + backgroundDrag: IBackgroundDragSettings; } export interface IOrbViewSettings { @@ -97,6 +104,11 @@ export class OrbView implements IOrbVi isDragEnabled: true, isZoomEnabled: true, ...settings?.interaction, + backgroundDrag: { + isEnabled: false, + modifier: 'shift', + ...settings?.interaction?.backgroundDrag, + }, }, }; @@ -180,11 +192,13 @@ export class OrbView implements IOrbVi this._d3Zoom = zoom() .scaleExtent([this._renderer.getSettings().minZoom, this._renderer.getSettings().maxZoom]) + .filter(this._zoomFilter) .on('zoom', this.zoomed); select(this._renderer.canvas) .call( drag() + .filter(this._dragFilter) .container(this._renderer.canvas) .subject(this.dragSubject) .on('start', this.dragStarted) @@ -227,6 +241,22 @@ export class OrbView implements IOrbVi return this._interaction; } + get canvas(): HTMLCanvasElement { + return this._renderer.canvas; + } + + getSimulationPosition(canvasPoint: IPosition): IPosition { + return this._renderer.getSimulationPosition(canvasPoint); + } + + getCanvasPosition(simulationPoint: IPosition): IPosition { + return this._renderer.getCanvasPosition(simulationPoint); + } + + getSimulationViewRectangle(): IRectangle { + return this._renderer.getSimulationViewRectangle(); + } + getSettings(): IOrbViewSettings { return copyObject(this._settings); } @@ -317,6 +347,14 @@ export class OrbView implements IOrbVi // Update the internal isZoomEnabled setting based on the provided value this._settings.interaction.isZoomEnabled = settings.interaction.isZoomEnabled; } + + // The zoom filter and drag subject read this live, so no renderer re-init is needed. + if (settings.interaction.backgroundDrag) { + this._settings.interaction.backgroundDrag = { + ...this._settings.interaction.backgroundDrag, + ...settings.interaction.backgroundDrag, + }; + } } } @@ -384,13 +422,84 @@ export class OrbView implements IOrbVi this._simulator.terminate(); } - dragSubject = (event: D3DragEvent>) => { + private _isBackgroundDragModifierActive( + event: Pick, + ): boolean { + const backgroundDrag = this._settings.interaction.backgroundDrag; + if (!backgroundDrag?.isEnabled) { + return false; + } + switch (backgroundDrag.modifier ?? 'shift') { + case 'shift': + return event.shiftKey; + case 'ctrl': + return event.ctrlKey; + case 'alt': + return event.altKey; + case 'meta': + return event.metaKey; + case null: + return true; + default: + return false; + } + } + + // Mirror d3-zoom's default filter, but skip panning for modifier-matched background drags. + private _zoomFilter = (event: any): boolean => { + if (event.button) { + return false; + } + if (event.ctrlKey && event.type !== 'wheel') { + return false; + } + if (event.type === 'wheel') { + return true; + } + return !this._isBackgroundDragModifierActive(event); + }; + + // d3-drag's default filter rejects ctrl+drag; allow it through for background-drag gestures. + private _dragFilter = (event: any): boolean => { + if (event.button) { + return false; + } + if (this._isBackgroundDragModifierActive(event)) { + return true; + } + return !event.ctrlKey; + }; + + private _emitBackgroundDrag( + type: OrbEventType.BACKGROUND_DRAG_START | OrbEventType.BACKGROUND_DRAG | OrbEventType.BACKGROUND_DRAG_END, + sourceEvent: MouseEvent, + ): void { + const globalPoint = this.getCanvasMousePosition(sourceEvent); + const localPoint = this._renderer.getSimulationPosition(globalPoint); + this._events.emit(type, { event: sourceEvent, localPoint, globalPoint }); + } + + dragSubject = ( + event: D3DragEvent>, + ): INode | IBackgroundDragSubject | undefined => { const mousePoint = this.getCanvasMousePosition(event.sourceEvent); const simulationPoint = this._renderer?.getSimulationPosition(mousePoint); - return this._graph.getNearestNode(simulationPoint); + const node = this._graph.getNearestNode(simulationPoint); + if (node) { + return node; + } + if (this._isBackgroundDragModifierActive(event.sourceEvent)) { + return BACKGROUND_DRAG_SUBJECT; + } + return undefined; }; dragStarted = (event: D3DragEvent>) => { + if (isBackgroundDragSubject(event.subject)) { + this._emitBackgroundDrag(OrbEventType.BACKGROUND_DRAG_START, event.sourceEvent); + return; + } + // If drag is disabled then return if (!this._settings.interaction.isDragEnabled) { return; @@ -411,6 +520,11 @@ export class OrbView implements IOrbVi }; dragged = (event: D3DragEvent>) => { + if (isBackgroundDragSubject(event.subject)) { + this._emitBackgroundDrag(OrbEventType.BACKGROUND_DRAG, event.sourceEvent); + return; + } + // If drag is disabled then return if (!this._settings.interaction.isDragEnabled) { return; @@ -434,6 +548,11 @@ export class OrbView implements IOrbVi }; dragEnded = (event: D3DragEvent>) => { + if (isBackgroundDragSubject(event.subject)) { + this._emitBackgroundDrag(OrbEventType.BACKGROUND_DRAG_END, event.sourceEvent); + return; + } + // If drag is disabled then return if (!this._settings.interaction.isDragEnabled) { return; diff --git a/src/views/shared.ts b/src/views/shared.ts index 00903e3..bf09526 100644 --- a/src/views/shared.ts +++ b/src/views/shared.ts @@ -5,16 +5,21 @@ import { OrbEmitter } from '../events'; import { IGraphInteraction } from '../models/interaction'; import { ISVGExportOptions } from '../renderer/svg'; import { RendererType } from '../renderer/shared'; +import { IPosition, IRectangle } from '../common'; export interface IOrbView { data: IGraph; events: OrbEmitter; interaction: IGraphInteraction; + canvas: HTMLCanvasElement; getSettings(): S; setSettings(settings: Partial): void; setRenderer(type: RendererType): void; render(onRendered?: () => void): void; recenter(onRendered?: () => void): void; getSVG(options?: ISVGExportOptions): string; + getSimulationPosition(canvasPoint: IPosition): IPosition; + getCanvasPosition(simulationPoint: IPosition): IPosition; + getSimulationViewRectangle(): IRectangle; destroy(): void; } diff --git a/test/common/area/rectangle.spec.ts b/test/common/area/rectangle.spec.ts new file mode 100644 index 0000000..75ec197 --- /dev/null +++ b/test/common/area/rectangle.spec.ts @@ -0,0 +1,38 @@ +import { RectangleArea } from '../../../src/common/area/rectangle'; + +describe('RectangleArea', () => { + describe('fromPoints', () => { + test('builds a normalized rectangle from top-left and bottom-right corners', () => { + const area = RectangleArea.fromPoints({ x: 10, y: 20 }, { x: 110, y: 220 }); + expect(area.getBoundingBox()).toEqual({ x: 10, y: 20, width: 100, height: 200 }); + }); + + test('normalizes corners given in any order', () => { + const area = RectangleArea.fromPoints({ x: 110, y: 220 }, { x: 10, y: 20 }); + expect(area.getBoundingBox()).toEqual({ x: 10, y: 20, width: 100, height: 200 }); + }); + + test('supports negative coordinates', () => { + const area = RectangleArea.fromPoints({ x: -50, y: 30 }, { x: 50, y: -70 }); + expect(area.getBoundingBox()).toEqual({ x: -50, y: -70, width: 100, height: 100 }); + }); + }); + + describe('contains', () => { + const area = RectangleArea.fromPoints({ x: 0, y: 0 }, { x: 100, y: 100 }); + + test('returns true for a point inside', () => { + expect(area.contains({ x: 50, y: 50 })).toBe(true); + }); + + test('returns true for points on the border (inclusive)', () => { + expect(area.contains({ x: 0, y: 0 })).toBe(true); + expect(area.contains({ x: 100, y: 100 })).toBe(true); + }); + + test('returns false for a point outside', () => { + expect(area.contains({ x: 150, y: 50 })).toBe(false); + expect(area.contains({ x: 50, y: -1 })).toBe(false); + }); + }); +}); diff --git a/test/models/selection.spec.ts b/test/models/selection.spec.ts new file mode 100644 index 0000000..6a16949 --- /dev/null +++ b/test/models/selection.spec.ts @@ -0,0 +1,180 @@ +import { Graph } from '../../src/models/graph'; +import { GraphInteraction } from '../../src/models/interaction'; +import { RectangleArea } from '../../src/common/area/rectangle'; +import { getDefaultGraphStyle } from '../../src/models/style'; +import { INodeBase } from '../../src/models/node'; +import { IEdgeBase } from '../../src/models/edge'; + +interface ITestNode extends INodeBase { + name: string; +} + +type ITestEdge = IEdgeBase; + +const buildGraph = () => { + const nodes: ITestNode[] = [ + { id: 0, name: 'origin' }, + { id: 1, name: 'near' }, + { id: 2, name: 'far' }, + { id: 3, name: 'unpositioned' }, + ]; + const edges: ITestEdge[] = [ + { id: 0, start: 0, end: 1 }, + { id: 1, start: 1, end: 2 }, + ]; + const graph = new Graph({ nodes, edges }); + graph.setDefaultStyle(getDefaultGraphStyle()); + + graph.getNodeById(0)!.setPosition({ x: 0, y: 0 }); + graph.getNodeById(1)!.setPosition({ x: 100, y: 100 }); + graph.getNodeById(2)!.setPosition({ x: 500, y: 500 }); + // Node 3 is intentionally left without a position. + + return graph; +}; + +describe('Graph.getNodesInArea', () => { + test('returns nodes whose center is inside the area', () => { + const graph = buildGraph(); + const area = RectangleArea.fromPoints({ x: -10, y: -10 }, { x: 150, y: 150 }); + + const ids = graph + .getNodesInArea(area) + .map((node) => node.getId()) + .sort(); + + expect(ids).toEqual([0, 1]); + }); + + test('is independent of corner order', () => { + const graph = buildGraph(); + const area = RectangleArea.fromPoints({ x: 150, y: 150 }, { x: -10, y: -10 }); + + const ids = graph + .getNodesInArea(area) + .map((node) => node.getId()) + .sort(); + + expect(ids).toEqual([0, 1]); + }); + + test('ignores nodes without a resolved position, even when the area covers the origin', () => { + const graph = buildGraph(); + const area = RectangleArea.fromPoints({ x: -50, y: -50 }, { x: 50, y: 50 }); + + const ids = graph.getNodesInArea(area).map((node) => node.getId()); + + expect(ids).toContain(0); + expect(ids).not.toContain(3); + }); + + test('returns an empty list when no node falls inside', () => { + const graph = buildGraph(); + const area = RectangleArea.fromPoints({ x: 1000, y: 1000 }, { x: 1100, y: 1100 }); + + expect(graph.getNodesInArea(area)).toHaveLength(0); + }); +}); + +describe('GraphInteraction batch selection', () => { + test('selectNodesByIds selects only the listed nodes (non-cascading)', () => { + const graph = buildGraph(); + const interaction = new GraphInteraction(graph); + + const count = interaction.selectNodesByIds([0, 1]); + + expect(count).toBe(2); + expect(graph.getNodeById(0)!.isSelected()).toBe(true); + expect(graph.getNodeById(1)!.isSelected()).toBe(true); + expect(graph.getNodeById(2)!.isSelected()).toBe(false); + // Non-cascading: the edge between the two selected nodes is not pulled in. + expect(graph.getEdgeById(0)!.isSelected()).toBe(false); + }); + + test('selectNodesByIds skips unknown ids and counts only matches', () => { + const graph = buildGraph(); + const interaction = new GraphInteraction(graph); + + const count = interaction.selectNodesByIds([0, 999]); + + expect(count).toBe(1); + expect(graph.getNodeById(0)!.isSelected()).toBe(true); + }); + + test('unselectNodesByIds clears only the listed nodes', () => { + const graph = buildGraph(); + const interaction = new GraphInteraction(graph); + interaction.selectNodesByIds([0, 1]); + + const removed = interaction.unselectNodesByIds([0]); + + expect(removed).toBe(1); + expect(graph.getNodeById(0)!.isSelected()).toBe(false); + expect(graph.getNodeById(1)!.isSelected()).toBe(true); + }); + + test('selectEdgesByIds selects only the listed edges (non-cascading)', () => { + const graph = buildGraph(); + const interaction = new GraphInteraction(graph); + + const count = interaction.selectEdgesByIds([0]); + + expect(count).toBe(1); + expect(graph.getEdgeById(0)!.isSelected()).toBe(true); + expect(graph.getEdgeById(1)!.isSelected()).toBe(false); + // Non-cascading: the edge's endpoints are not pulled in. + expect(graph.getNodeById(0)!.isSelected()).toBe(false); + expect(graph.getNodeById(1)!.isSelected()).toBe(false); + }); + + test('selectEdgesByIds skips unknown ids and counts only matches', () => { + const graph = buildGraph(); + const interaction = new GraphInteraction(graph); + + const count = interaction.selectEdgesByIds([0, 999]); + + expect(count).toBe(1); + expect(graph.getEdgeById(0)!.isSelected()).toBe(true); + }); + + test('unselectEdgesByIds clears only the listed edges', () => { + const graph = buildGraph(); + const interaction = new GraphInteraction(graph); + interaction.selectEdgesByIds([0, 1]); + + const removed = interaction.unselectEdgesByIds([0]); + + expect(removed).toBe(1); + expect(graph.getEdgeById(0)!.isSelected()).toBe(false); + expect(graph.getEdgeById(1)!.isSelected()).toBe(true); + }); +}); + +describe('Graph.getStyleVersion', () => { + test('bumps when a node/edge state changes silently, so cached-style renderers can detect it', () => { + const graph = buildGraph(); + const interaction = new GraphInteraction(graph); + + const v0 = graph.getStyleVersion(); + interaction.selectNodesByIds([0, 1]); + const v1 = graph.getStyleVersion(); + interaction.unselectAll(); + const v2 = graph.getStyleVersion(); + interaction.selectEdgesByIds([0]); + const v3 = graph.getStyleVersion(); + + expect(v1).toBeGreaterThan(v0); + expect(v2).toBeGreaterThan(v1); + expect(v3).toBeGreaterThan(v2); + }); + + test('does not bump when nothing actually changes state', () => { + const graph = buildGraph(); + const interaction = new GraphInteraction(graph); + interaction.selectNodesByIds([0]); + + const before = graph.getStyleVersion(); + interaction.selectNodesByIds([0]); // already selected -> no state change + expect(graph.getStyleVersion()).toBe(before); + }); +}); From 69fb8047ac00bbf2e4cf47bc45ecbc7f69f73ee8 Mon Sep 17 00:00:00 2001 From: AlexIchenskiy Date: Mon, 7 Sep 2026 11:52:43 +0200 Subject: [PATCH 2/3] Chore: Refactor interactions quality --- docs/site/concepts/interaction.md | 19 ++++++++----- .../public/demos/rectangle-selection.html | 5 ++-- docs/site/public/orb.min.js | 2 +- src/interactions/index.ts | 1 - src/interactions/rectangle-selection.ts | 28 ++++--------------- src/interactions/shared.ts | 9 ++---- src/utils/graph.utils.ts | 28 ++++++++++++++++--- test/models/selection.spec.ts | 13 +++++++++ 8 files changed, 61 insertions(+), 44 deletions(-) diff --git a/docs/site/concepts/interaction.md b/docs/site/concepts/interaction.md index 8869bfd..0a071e3 100644 --- a/docs/site/concepts/interaction.md +++ b/docs/site/concepts/interaction.md @@ -142,14 +142,20 @@ const orb = new OrbView(container, { }); const selection = new RectangleSelection(orb); -selection.on('select', ({ nodes, edges, mode }) => { - // nodes (and edges, if enabled) are now selected; mode is 'replace' or 'add' +selection.on('select', ({ nodes, area, mode }) => { + // nodes are now selected; mode is 'add' or 'replace'. Want edges too? You have the + // nodes, so select whichever edges you like - e.g. those fully inside the box: + const ids = new Set(nodes.map((n) => n.getId())); + const edges = orb.data.getEdges((e) => ids.has(e.startNode?.getId()) && ids.has(e.endNode?.getId())); + orb.interaction.selectEdgesByIds(edges.map((e) => e.getId())); + orb.render(); }); ``` -By default, **Shift-drag** over the empty background draws the box and replaces the -selection; holding **Ctrl/Cmd** as well adds to it. Dragging a node still moves it, and a -plain drag still pans. Call `selection.destroy()` to detach it. +By default, **Shift-drag** over the empty background draws the box and adds the nodes to +the selection (mirroring Shift-click); holding **Ctrl/Cmd** as well replaces it instead. +Dragging a node still moves it, and a plain drag still pans. Call `selection.destroy()` to +detach it. ::: warning Requires background drag `RectangleSelection` only listens - it does not enable the gesture. If @@ -161,8 +167,7 @@ Shift-drag is a no-op. | Option | Type | Default | | --- | --- | --- | -| `resolveMode` | `(event: MouseEvent) => 'replace' \| 'add'` | ctrl/meta → `add`, else `replace` | -| `includeEdges` | `'none' \| 'endpointsInside'` | `'none'` - `'endpointsInside'` also selects edges whose both endpoints fall in the box | +| `resolveMode` | `(event: MouseEvent) => 'add' \| 'replace'` | ctrl/meta → `replace`, else `add` | | `style` | `Partial` | dashed blue overlay | The overlay element carries the `orb-selection-rectangle` class, so you can also style it diff --git a/docs/site/public/demos/rectangle-selection.html b/docs/site/public/demos/rectangle-selection.html index cdce3f7..6180281 100644 --- a/docs/site/public/demos/rectangle-selection.html +++ b/docs/site/public/demos/rectangle-selection.html @@ -24,7 +24,7 @@
- Shift+drag to select · Ctrl/Cmd to add + Shift+drag to add · Ctrl/Cmd to replace 0 nodes, 0 edges @@ -139,7 +139,8 @@ if (!start) return; const area = RectangleArea.fromPoints(start.sim, e.localPoint); const selected = orb.data.getNodesInArea(area); - if (!(e.event.ctrlKey || e.event.metaKey)) orb.interaction.unselectAll(); + // Shift-drag adds (like Shift-click); holding Ctrl/Cmd replaces instead. + if (e.event.ctrlKey || e.event.metaKey) orb.interaction.unselectAll(); orb.interaction.selectNodesByIds(selected.map((n) => n.getId())); if (includeEdgesEl.checked) { const set = new Set(selected.map((n) => n.getId())); diff --git a/docs/site/public/orb.min.js b/docs/site/public/orb.min.js index 3358174..c68883a 100644 --- a/docs/site/public/orb.min.js +++ b/docs/site/public/orb.min.js @@ -1,2 +1,2 @@ /*! For license information please see orb.min.js.LICENSE.txt */ -!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.Orb=e():t.Orb=e()}(self,()=>(()=>{var t={481(t,e){!function(t){"use strict";function e(t){var e,i,n,s;for(i=1,n=arguments.length;i0?Math.floor(t):Math.ceil(t)};function I(t,e,i){return t instanceof N?t:p(t)?new N(t[0],t[1]):null==t?t:"object"==typeof t&&"x"in t&&"y"in t?new N(t.x,t.y):new N(t,e,i)}function R(t,e){if(t)for(var i=e?[t,e]:t,n=0,s=i.length;n=this.min.x&&i.x<=this.max.x&&e.y>=this.min.y&&i.y<=this.max.y},intersects:function(t){t=O(t);var e=this.min,i=this.max,n=t.min,s=t.max,o=s.x>=e.x&&n.x<=i.x,r=s.y>=e.y&&n.y<=i.y;return o&&r},overlaps:function(t){t=O(t);var e=this.min,i=this.max,n=t.min,s=t.max,o=s.x>e.x&&n.xe.y&&n.y=n.lat&&i.lat<=s.lat&&e.lng>=n.lng&&i.lng<=s.lng},intersects:function(t){t=B(t);var e=this._southWest,i=this._northEast,n=t.getSouthWest(),s=t.getNorthEast(),o=s.lat>=e.lat&&n.lat<=i.lat,r=s.lng>=e.lng&&n.lng<=i.lng;return o&&r},overlaps:function(t){t=B(t);var e=this._southWest,i=this._northEast,n=t.getSouthWest(),s=t.getNorthEast(),o=s.lat>e.lat&&n.late.lng&&n.lng1,Ct=function(){var t=!1;try{var e=Object.defineProperty({},"passive",{get:function(){t=!0}});window.addEventListener("testPassiveEventSupport",h,e),window.removeEventListener("testPassiveEventSupport",h,e)}catch(t){}return t}(),Mt=!!document.createElement("canvas").getContext,Nt=!(!document.createElementNS||!Y("svg").createSVGRect),Dt=!!Nt&&((K=document.createElement("div")).innerHTML="","http://www.w3.org/2000/svg"===(K.firstChild&&K.firstChild.namespaceURI)),It=!Nt&&function(){try{var t=document.createElement("div");t.innerHTML='';var e=t.firstChild;return e.style.behavior="url(#default#VML)",e&&"object"==typeof e.adj}catch(t){return!1}}();function Lt(t){return navigator.userAgent.toLowerCase().indexOf(t)>=0}var Rt={ie:J,ielt9:tt,edge:et,webkit:it,android:nt,android23:st,androidStock:rt,opera:at,chrome:ht,gecko:lt,safari:dt,phantom:ut,opera12:ct,win:_t,ie3d:ft,webkit3d:gt,gecko3d:pt,any3d:mt,mobile:vt,mobileWebkit:yt,mobileWebkit3d:xt,msPointer:bt,pointer:St,touch:Tt,touchNative:wt,mobileOpera:Et,mobileGecko:Pt,retina:At,passiveEvents:Ct,canvas:Mt,svg:Nt,vml:It,inlineSvg:Dt,mac:0===navigator.platform.indexOf("Mac"),linux:0===navigator.platform.indexOf("Linux")},Ot=Rt.msPointer?"MSPointerDown":"pointerdown",kt=Rt.msPointer?"MSPointerMove":"pointermove",Bt=Rt.msPointer?"MSPointerUp":"pointerup",zt=Rt.msPointer?"MSPointerCancel":"pointercancel",Ut={touchstart:Ot,touchmove:kt,touchend:Bt,touchcancel:zt},Ft={touchstart:function(t,e){e.MSPOINTER_TYPE_TOUCH&&e.pointerType===e.MSPOINTER_TYPE_TOUCH&&Be(e),qt(t,e)},touchmove:qt,touchend:qt,touchcancel:qt},jt={},Wt=!1;function Gt(t,e,i){return"touchstart"===e&&(Wt||(document.addEventListener(Ot,Zt,!0),document.addEventListener(kt,Ht,!0),document.addEventListener(Bt,Xt,!0),document.addEventListener(zt,Xt,!0),Wt=!0)),Ft[e]?(i=Ft[e].bind(this,i),t.addEventListener(Ut[e],i,!1),i):(console.warn("wrong event specified:",e),h)}function Zt(t){jt[t.pointerId]=t}function Ht(t){jt[t.pointerId]&&(jt[t.pointerId]=t)}function Xt(t){delete jt[t.pointerId]}function qt(t,e){if(e.pointerType!==(e.MSPOINTER_TYPE_MOUSE||"mouse")){for(var i in e.touches=[],jt)e.touches.push(jt[i]);e.changedTouches=[e],t(e)}}var Vt,Yt,$t,Kt,Qt,Jt=ge(["transform","webkitTransform","OTransform","MozTransform","msTransform"]),te=ge(["webkitTransition","transition","OTransition","MozTransition","msTransition"]),ee="webkitTransition"===te||"OTransition"===te?te+"End":"transitionend";function ie(t){return"string"==typeof t?document.getElementById(t):t}function ne(t,e){var i=t.style[e]||t.currentStyle&&t.currentStyle[e];if((!i||"auto"===i)&&document.defaultView){var n=document.defaultView.getComputedStyle(t,null);i=n?n[e]:null}return"auto"===i?null:i}function se(t,e,i){var n=document.createElement(t);return n.className=e||"",i&&i.appendChild(n),n}function oe(t){var e=t.parentNode;e&&e.removeChild(t)}function re(t){for(;t.firstChild;)t.removeChild(t.firstChild)}function ae(t){var e=t.parentNode;e&&e.lastChild!==t&&e.appendChild(t)}function he(t){var e=t.parentNode;e&&e.firstChild!==t&&e.insertBefore(t,e.firstChild)}function le(t,e){if(void 0!==t.classList)return t.classList.contains(e);var i=_e(t);return i.length>0&&new RegExp("(^|\\s)"+e+"(\\s|$)").test(i)}function de(t,e){if(void 0!==t.classList)for(var i=u(e),n=0,s=i.length;n0?2*window.devicePixelRatio:1;function We(t){return Rt.edge?t.wheelDeltaY/2:t.deltaY&&0===t.deltaMode?-t.deltaY/je:t.deltaY&&1===t.deltaMode?20*-t.deltaY:t.deltaY&&2===t.deltaMode?60*-t.deltaY:t.deltaX||t.deltaZ?0:t.wheelDelta?(t.wheelDeltaY||t.wheelDelta)/2:t.detail&&Math.abs(t.detail)<32765?20*-t.detail:t.detail?t.detail/-32765*60:0}function Ge(t,e){var i=e.relatedTarget;if(!i)return!0;try{for(;i&&i!==t;)i=i.parentNode}catch(t){return!1}return i!==t}var Ze={__proto__:null,on:Ae,off:Me,stopPropagation:Re,disableScrollPropagation:Oe,disableClickPropagation:ke,preventDefault:Be,stop:ze,getPropagationPath:Ue,getMousePosition:Fe,getWheelDelta:We,isExternalTarget:Ge,addListener:Ae,removeListener:Me},He=M.extend({run:function(t,e,i,n){this.stop(),this._el=t,this._inProgress=!0,this._duration=i||.25,this._easeOutPower=1/Math.max(n||.5,.2),this._startPos=ve(t),this._offset=e.subtract(this._startPos),this._startTime=+new Date,this.fire("start"),this._animate()},stop:function(){this._inProgress&&(this._step(!0),this._complete())},_animate:function(){this._animId=T(this._animate,this),this._step()},_step:function(t){var e=+new Date-this._startTime,i=1e3*this._duration;ethis.options.maxZoom)?this.setZoom(t):this},panInsideBounds:function(t,e){this._enforcingBounds=!0;var i=this.getCenter(),n=this._limitCenter(i,this._zoom,B(t));return i.equals(n)||this.panTo(n,e),this._enforcingBounds=!1,this},panInside:function(t,e){var i=I((e=e||{}).paddingTopLeft||e.padding||[0,0]),n=I(e.paddingBottomRight||e.padding||[0,0]),s=this.project(this.getCenter()),o=this.project(t),r=this.getPixelBounds(),a=O([r.min.add(i),r.max.subtract(n)]),h=a.getSize();if(!a.contains(o)){this._enforcingBounds=!0;var l=o.subtract(a.getCenter()),d=a.extend(o).getSize().subtract(h);s.x+=l.x<0?-d.x:d.x,s.y+=l.y<0?-d.y:d.y,this.panTo(this.unproject(s),e),this._enforcingBounds=!1}return this},invalidateSize:function(t){if(!this._loaded)return this;t=e({animate:!1,pan:!0},!0===t?{animate:!0}:t);var i=this.getSize();this._sizeChanged=!0,this._lastCenter=null;var s=this.getSize(),o=i.divideBy(2).round(),r=s.divideBy(2).round(),a=o.subtract(r);return a.x||a.y?(t.animate&&t.pan?this.panBy(a):(t.pan&&this._rawPanBy(a),this.fire("move"),t.debounceMoveend?(clearTimeout(this._sizeTimer),this._sizeTimer=setTimeout(n(this.fire,this,"moveend"),200)):this.fire("moveend")),this.fire("resize",{oldSize:i,newSize:s})):this},stop:function(){return this.setZoom(this._limitZoom(this._zoom)),this.options.zoomSnap||this.fire("viewreset"),this._stop()},locate:function(t){if(t=this._locateOptions=e({timeout:1e4,watch:!1},t),!("geolocation"in navigator))return this._handleGeolocationError({code:0,message:"Geolocation not supported."}),this;var i=n(this._handleGeolocationResponse,this),s=n(this._handleGeolocationError,this);return t.watch?this._locationWatchId=navigator.geolocation.watchPosition(i,s,t):navigator.geolocation.getCurrentPosition(i,s,t),this},stopLocate:function(){return navigator.geolocation&&navigator.geolocation.clearWatch&&navigator.geolocation.clearWatch(this._locationWatchId),this._locateOptions&&(this._locateOptions.setView=!1),this},_handleGeolocationError:function(t){if(this._container._leaflet_id){var e=t.code,i=t.message||(1===e?"permission denied":2===e?"position unavailable":"timeout");this._locateOptions.setView&&!this._loaded&&this.fitWorld(),this.fire("locationerror",{code:e,message:"Geolocation error: "+i+"."})}},_handleGeolocationResponse:function(t){if(this._container._leaflet_id){var e=new z(t.coords.latitude,t.coords.longitude),i=e.toBounds(2*t.coords.accuracy),n=this._locateOptions;if(n.setView){var s=this.getBoundsZoom(i);this.setView(e,n.maxZoom?Math.min(s,n.maxZoom):s)}var o={latlng:e,bounds:i,timestamp:t.timestamp};for(var r in t.coords)"number"==typeof t.coords[r]&&(o[r]=t.coords[r]);this.fire("locationfound",o)}},addHandler:function(t,e){if(!e)return this;var i=this[t]=new e(this);return this._handlers.push(i),this.options[t]&&i.enable(),this},remove:function(){if(this._initEvents(!0),this.options.maxBounds&&this.off("moveend",this._panInsideMaxBounds),this._containerId!==this._container._leaflet_id)throw new Error("Map container is being reused by another instance");try{delete this._container._leaflet_id,delete this._containerId}catch(t){this._container._leaflet_id=void 0,this._containerId=void 0}var t;for(t in void 0!==this._locationWatchId&&this.stopLocate(),this._stop(),oe(this._mapPane),this._clearControlPos&&this._clearControlPos(),this._resizeRequest&&(E(this._resizeRequest),this._resizeRequest=null),this._clearHandlers(),this._loaded&&this.fire("unload"),this._layers)this._layers[t].remove();for(t in this._panes)oe(this._panes[t]);return this._layers=[],this._panes=[],delete this._mapPane,delete this._renderer,this},createPane:function(t,e){var i=se("div","leaflet-pane"+(t?" leaflet-"+t.replace("Pane","")+"-pane":""),e||this._mapPane);return t&&(this._panes[t]=i),i},getCenter:function(){return this._checkIfLoaded(),this._lastCenter&&!this._moved()?this._lastCenter.clone():this.layerPointToLatLng(this._getCenterLayerPoint())},getZoom:function(){return this._zoom},getBounds:function(){var t=this.getPixelBounds();return new k(this.unproject(t.getBottomLeft()),this.unproject(t.getTopRight()))},getMinZoom:function(){return void 0===this.options.minZoom?this._layersMinZoom||0:this.options.minZoom},getMaxZoom:function(){return void 0===this.options.maxZoom?void 0===this._layersMaxZoom?1/0:this._layersMaxZoom:this.options.maxZoom},getBoundsZoom:function(t,e,i){t=B(t),i=I(i||[0,0]);var n=this.getZoom()||0,s=this.getMinZoom(),o=this.getMaxZoom(),r=t.getNorthWest(),a=t.getSouthEast(),h=this.getSize().subtract(i),l=O(this.project(a,n),this.project(r,n)).getSize(),d=Rt.any3d?this.options.zoomSnap:1,u=h.x/l.x,c=h.y/l.y,_=e?Math.max(u,c):Math.min(u,c);return n=this.getScaleZoom(_,n),d&&(n=Math.round(n/(d/100))*(d/100),n=e?Math.ceil(n/d)*d:Math.floor(n/d)*d),Math.max(s,Math.min(o,n))},getSize:function(){return this._size&&!this._sizeChanged||(this._size=new N(this._container.clientWidth||0,this._container.clientHeight||0),this._sizeChanged=!1),this._size.clone()},getPixelBounds:function(t,e){var i=this._getTopLeftPoint(t,e);return new R(i,i.add(this.getSize()))},getPixelOrigin:function(){return this._checkIfLoaded(),this._pixelOrigin},getPixelWorldBounds:function(t){return this.options.crs.getProjectedBounds(void 0===t?this.getZoom():t)},getPane:function(t){return"string"==typeof t?this._panes[t]:t},getPanes:function(){return this._panes},getContainer:function(){return this._container},getZoomScale:function(t,e){var i=this.options.crs;return e=void 0===e?this._zoom:e,i.scale(t)/i.scale(e)},getScaleZoom:function(t,e){var i=this.options.crs;e=void 0===e?this._zoom:e;var n=i.zoom(t*i.scale(e));return isNaN(n)?1/0:n},project:function(t,e){return e=void 0===e?this._zoom:e,this.options.crs.latLngToPoint(U(t),e)},unproject:function(t,e){return e=void 0===e?this._zoom:e,this.options.crs.pointToLatLng(I(t),e)},layerPointToLatLng:function(t){var e=I(t).add(this.getPixelOrigin());return this.unproject(e)},latLngToLayerPoint:function(t){return this.project(U(t))._round()._subtract(this.getPixelOrigin())},wrapLatLng:function(t){return this.options.crs.wrapLatLng(U(t))},wrapLatLngBounds:function(t){return this.options.crs.wrapLatLngBounds(B(t))},distance:function(t,e){return this.options.crs.distance(U(t),U(e))},containerPointToLayerPoint:function(t){return I(t).subtract(this._getMapPanePos())},layerPointToContainerPoint:function(t){return I(t).add(this._getMapPanePos())},containerPointToLatLng:function(t){var e=this.containerPointToLayerPoint(I(t));return this.layerPointToLatLng(e)},latLngToContainerPoint:function(t){return this.layerPointToContainerPoint(this.latLngToLayerPoint(U(t)))},mouseEventToContainerPoint:function(t){return Fe(t,this._container)},mouseEventToLayerPoint:function(t){return this.containerPointToLayerPoint(this.mouseEventToContainerPoint(t))},mouseEventToLatLng:function(t){return this.layerPointToLatLng(this.mouseEventToLayerPoint(t))},_initContainer:function(t){var e=this._container=ie(t);if(!e)throw new Error("Map container not found.");if(e._leaflet_id)throw new Error("Map container is already initialized.");Ae(e,"scroll",this._onScroll,this),this._containerId=o(e)},_initLayout:function(){var t=this._container;this._fadeAnimated=this.options.fadeAnimation&&Rt.any3d,de(t,"leaflet-container"+(Rt.touch?" leaflet-touch":"")+(Rt.retina?" leaflet-retina":"")+(Rt.ielt9?" leaflet-oldie":"")+(Rt.safari?" leaflet-safari":"")+(this._fadeAnimated?" leaflet-fade-anim":""));var e=ne(t,"position");"absolute"!==e&&"relative"!==e&&"fixed"!==e&&"sticky"!==e&&(t.style.position="relative"),this._initPanes(),this._initControlPos&&this._initControlPos()},_initPanes:function(){var t=this._panes={};this._paneRenderers={},this._mapPane=this.createPane("mapPane",this._container),me(this._mapPane,new N(0,0)),this.createPane("tilePane"),this.createPane("overlayPane"),this.createPane("shadowPane"),this.createPane("markerPane"),this.createPane("tooltipPane"),this.createPane("popupPane"),this.options.markerZoomAnimation||(de(t.markerPane,"leaflet-zoom-hide"),de(t.shadowPane,"leaflet-zoom-hide"))},_resetView:function(t,e,i){me(this._mapPane,new N(0,0));var n=!this._loaded;this._loaded=!0,e=this._limitZoom(e),this.fire("viewprereset");var s=this._zoom!==e;this._moveStart(s,i)._move(t,e)._moveEnd(s),this.fire("viewreset"),n&&this.fire("load")},_moveStart:function(t,e){return t&&this.fire("zoomstart"),e||this.fire("movestart"),this},_move:function(t,e,i,n){void 0===e&&(e=this._zoom);var s=this._zoom!==e;return this._zoom=e,this._lastCenter=t,this._pixelOrigin=this._getNewPixelOrigin(t),n?i&&i.pinch&&this.fire("zoom",i):((s||i&&i.pinch)&&this.fire("zoom",i),this.fire("move",i)),this},_moveEnd:function(t){return t&&this.fire("zoomend"),this.fire("moveend")},_stop:function(){return E(this._flyToFrame),this._panAnim&&this._panAnim.stop(),this},_rawPanBy:function(t){me(this._mapPane,this._getMapPanePos().subtract(t))},_getZoomSpan:function(){return this.getMaxZoom()-this.getMinZoom()},_panInsideMaxBounds:function(){this._enforcingBounds||this.panInsideBounds(this.options.maxBounds)},_checkIfLoaded:function(){if(!this._loaded)throw new Error("Set map center and zoom first.")},_initEvents:function(t){this._targets={},this._targets[o(this._container)]=this;var e=t?Me:Ae;e(this._container,"click dblclick mousedown mouseup mouseover mouseout mousemove contextmenu keypress keydown keyup",this._handleDOMEvent,this),this.options.trackResize&&e(window,"resize",this._onResize,this),Rt.any3d&&this.options.transform3DLimit&&(t?this.off:this.on).call(this,"moveend",this._onMoveEnd)},_onResize:function(){E(this._resizeRequest),this._resizeRequest=T(function(){this.invalidateSize({debounceMoveend:!0})},this)},_onScroll:function(){this._container.scrollTop=0,this._container.scrollLeft=0},_onMoveEnd:function(){var t=this._getMapPanePos();Math.max(Math.abs(t.x),Math.abs(t.y))>=this.options.transform3DLimit&&this._resetView(this.getCenter(),this.getZoom())},_findEventTargets:function(t,e){for(var i,n=[],s="mouseout"===e||"mouseover"===e,r=t.target||t.srcElement,a=!1;r;){if((i=this._targets[o(r)])&&("click"===e||"preclick"===e)&&this._draggableMoved(i)){a=!0;break}if(i&&i.listens(e,!0)){if(s&&!Ge(r,t))break;if(n.push(i),s)break}if(r===this._container)break;r=r.parentNode}return n.length||a||s||!this.listens(e,!0)||(n=[this]),n},_isClickDisabled:function(t){for(;t&&t!==this._container;){if(t._leaflet_disable_click)return!0;t=t.parentNode}},_handleDOMEvent:function(t){var e=t.target||t.srcElement;if(!(!this._loaded||e._leaflet_disable_events||"click"===t.type&&this._isClickDisabled(e))){var i=t.type;"mousedown"===i&&Se(e),this._fireDOMEvent(t,i)}},_mouseEvents:["click","dblclick","mouseover","mouseout","contextmenu"],_fireDOMEvent:function(t,i,n){if("click"===t.type){var s=e({},t);s.type="preclick",this._fireDOMEvent(s,s.type,n)}var o=this._findEventTargets(t,i);if(n){for(var r=[],a=0;a0?Math.round(t-e)/2:Math.max(0,Math.ceil(t))-Math.max(0,Math.floor(e))},_limitZoom:function(t){var e=this.getMinZoom(),i=this.getMaxZoom(),n=Rt.any3d?this.options.zoomSnap:1;return n&&(t=Math.round(t/n)*n),Math.max(e,Math.min(i,t))},_onPanTransitionStep:function(){this.fire("move")},_onPanTransitionEnd:function(){ue(this._mapPane,"leaflet-pan-anim"),this.fire("moveend")},_tryAnimatedPan:function(t,e){var i=this._getCenterOffset(t)._trunc();return!(!0!==(e&&e.animate)&&!this.getSize().contains(i)||(this.panBy(i,e),0))},_createAnimProxy:function(){var t=this._proxy=se("div","leaflet-proxy leaflet-zoom-animated");this._panes.mapPane.appendChild(t),this.on("zoomanim",function(t){var e=Jt,i=this._proxy.style[e];pe(this._proxy,this.project(t.center,t.zoom),this.getZoomScale(t.zoom,1)),i===this._proxy.style[e]&&this._animatingZoom&&this._onZoomTransitionEnd()},this),this.on("load moveend",this._animMoveEnd,this),this._on("unload",this._destroyAnimProxy,this)},_destroyAnimProxy:function(){oe(this._proxy),this.off("load moveend",this._animMoveEnd,this),delete this._proxy},_animMoveEnd:function(){var t=this.getCenter(),e=this.getZoom();pe(this._proxy,this.project(t,e),this.getZoomScale(e,1))},_catchTransitionEnd:function(t){this._animatingZoom&&t.propertyName.indexOf("transform")>=0&&this._onZoomTransitionEnd()},_nothingToAnimate:function(){return!this._container.getElementsByClassName("leaflet-zoom-animated").length},_tryAnimatedZoom:function(t,e,i){if(this._animatingZoom)return!0;if(i=i||{},!this._zoomAnimated||!1===i.animate||this._nothingToAnimate()||Math.abs(e-this._zoom)>this.options.zoomAnimationThreshold)return!1;var n=this.getZoomScale(e),s=this._getCenterOffset(t)._divideBy(1-1/n);return!(!0!==i.animate&&!this.getSize().contains(s)||(T(function(){this._moveStart(!0,i.noMoveStart||!1)._animateZoom(t,e,!0)},this),0))},_animateZoom:function(t,e,i,s){this._mapPane&&(i&&(this._animatingZoom=!0,this._animateToCenter=t,this._animateToZoom=e,de(this._mapPane,"leaflet-zoom-anim")),this.fire("zoomanim",{center:t,zoom:e,noUpdate:s}),this._tempFireZoomEvent||(this._tempFireZoomEvent=this._zoom!==this._animateToZoom),this._move(this._animateToCenter,this._animateToZoom,void 0,!0),setTimeout(n(this._onZoomTransitionEnd,this),250))},_onZoomTransitionEnd:function(){this._animatingZoom&&(this._mapPane&&ue(this._mapPane,"leaflet-zoom-anim"),this._animatingZoom=!1,this._move(this._animateToCenter,this._animateToZoom,void 0,!0),this._tempFireZoomEvent&&this.fire("zoom"),delete this._tempFireZoomEvent,this.fire("move"),this._moveEnd(!0))}});var qe=A.extend({options:{position:"topright"},initialize:function(t){c(this,t)},getPosition:function(){return this.options.position},setPosition:function(t){var e=this._map;return e&&e.removeControl(this),this.options.position=t,e&&e.addControl(this),this},getContainer:function(){return this._container},addTo:function(t){this.remove(),this._map=t;var e=this._container=this.onAdd(t),i=this.getPosition(),n=t._controlCorners[i];return de(e,"leaflet-control"),-1!==i.indexOf("bottom")?n.insertBefore(e,n.firstChild):n.appendChild(e),this._map.on("unload",this.remove,this),this},remove:function(){return this._map?(oe(this._container),this.onRemove&&this.onRemove(this._map),this._map.off("unload",this.remove,this),this._map=null,this):this},_refocusOnMap:function(t){this._map&&t&&t.screenX>0&&t.screenY>0&&this._map.getContainer().focus()}}),Ve=function(t){return new qe(t)};Xe.include({addControl:function(t){return t.addTo(this),this},removeControl:function(t){return t.remove(),this},_initControlPos:function(){var t=this._controlCorners={},e="leaflet-",i=this._controlContainer=se("div",e+"control-container",this._container);function n(n,s){var o=e+n+" "+e+s;t[n+s]=se("div",o,i)}n("top","left"),n("top","right"),n("bottom","left"),n("bottom","right")},_clearControlPos:function(){for(var t in this._controlCorners)oe(this._controlCorners[t]);oe(this._controlContainer),delete this._controlCorners,delete this._controlContainer}});var Ye=qe.extend({options:{collapsed:!0,position:"topright",autoZIndex:!0,hideSingleBase:!1,sortLayers:!1,sortFunction:function(t,e,i,n){return i1,this._baseLayersList.style.display=t?"":"none"),this._separator.style.display=e&&t?"":"none",this},_onLayerChange:function(t){this._handlingClick||this._update();var e=this._getLayer(o(t.target)),i=e.overlay?"add"===t.type?"overlayadd":"overlayremove":"add"===t.type?"baselayerchange":null;i&&this._map.fire(i,e)},_createRadioElement:function(t,e){var i='",n=document.createElement("div");return n.innerHTML=i,n.firstChild},_addItem:function(t){var e,i=document.createElement("label"),n=this._map.hasLayer(t.layer);t.overlay?((e=document.createElement("input")).type="checkbox",e.className="leaflet-control-layers-selector",e.defaultChecked=n):e=this._createRadioElement("leaflet-base-layers_"+o(this),n),this._layerControlInputs.push(e),e.layerId=o(t.layer),Ae(e,"click",this._onInputClick,this);var s=document.createElement("span");s.innerHTML=" "+t.name;var r=document.createElement("span");return i.appendChild(r),r.appendChild(e),r.appendChild(s),(t.overlay?this._overlaysList:this._baseLayersList).appendChild(i),this._checkDisabledLayers(),i},_onInputClick:function(){if(!this._preventClick){var t,e,i=this._layerControlInputs,n=[],s=[];this._handlingClick=!0;for(var o=i.length-1;o>=0;o--)t=i[o],e=this._getLayer(t.layerId).layer,t.checked?n.push(e):t.checked||s.push(e);for(o=0;o=0;s--)t=i[s],e=this._getLayer(t.layerId).layer,t.disabled=void 0!==e.options.minZoom&&ne.options.maxZoom},_expandIfNotCollapsed:function(){return this._map&&!this.options.collapsed&&this.expand(),this},_expandSafely:function(){var t=this._section;this._preventClick=!0,Ae(t,"click",Be),this.expand();var e=this;setTimeout(function(){Me(t,"click",Be),e._preventClick=!1})}}),$e=qe.extend({options:{position:"topleft",zoomInText:'',zoomInTitle:"Zoom in",zoomOutText:'',zoomOutTitle:"Zoom out"},onAdd:function(t){var e="leaflet-control-zoom",i=se("div",e+" leaflet-bar"),n=this.options;return this._zoomInButton=this._createButton(n.zoomInText,n.zoomInTitle,e+"-in",i,this._zoomIn),this._zoomOutButton=this._createButton(n.zoomOutText,n.zoomOutTitle,e+"-out",i,this._zoomOut),this._updateDisabled(),t.on("zoomend zoomlevelschange",this._updateDisabled,this),i},onRemove:function(t){t.off("zoomend zoomlevelschange",this._updateDisabled,this)},disable:function(){return this._disabled=!0,this._updateDisabled(),this},enable:function(){return this._disabled=!1,this._updateDisabled(),this},_zoomIn:function(t){!this._disabled&&this._map._zoomthis._map.getMinZoom()&&this._map.zoomOut(this._map.options.zoomDelta*(t.shiftKey?3:1))},_createButton:function(t,e,i,n,s){var o=se("a",i,n);return o.innerHTML=t,o.href="#",o.title=e,o.setAttribute("role","button"),o.setAttribute("aria-label",e),ke(o),Ae(o,"click",ze),Ae(o,"click",s,this),Ae(o,"click",this._refocusOnMap,this),o},_updateDisabled:function(){var t=this._map,e="leaflet-disabled";ue(this._zoomInButton,e),ue(this._zoomOutButton,e),this._zoomInButton.setAttribute("aria-disabled","false"),this._zoomOutButton.setAttribute("aria-disabled","false"),(this._disabled||t._zoom===t.getMinZoom())&&(de(this._zoomOutButton,e),this._zoomOutButton.setAttribute("aria-disabled","true")),(this._disabled||t._zoom===t.getMaxZoom())&&(de(this._zoomInButton,e),this._zoomInButton.setAttribute("aria-disabled","true"))}});Xe.mergeOptions({zoomControl:!0}),Xe.addInitHook(function(){this.options.zoomControl&&(this.zoomControl=new $e,this.addControl(this.zoomControl))});var Ke=qe.extend({options:{position:"bottomleft",maxWidth:100,metric:!0,imperial:!0},onAdd:function(t){var e="leaflet-control-scale",i=se("div",e),n=this.options;return this._addScales(n,e+"-line",i),t.on(n.updateWhenIdle?"moveend":"move",this._update,this),t.whenReady(this._update,this),i},onRemove:function(t){t.off(this.options.updateWhenIdle?"moveend":"move",this._update,this)},_addScales:function(t,e,i){t.metric&&(this._mScale=se("div",e,i)),t.imperial&&(this._iScale=se("div",e,i))},_update:function(){var t=this._map,e=t.getSize().y/2,i=t.distance(t.containerPointToLatLng([0,e]),t.containerPointToLatLng([this.options.maxWidth,e]));this._updateScales(i)},_updateScales:function(t){this.options.metric&&t&&this._updateMetric(t),this.options.imperial&&t&&this._updateImperial(t)},_updateMetric:function(t){var e=this._getRoundNum(t),i=e<1e3?e+" m":e/1e3+" km";this._updateScale(this._mScale,i,e/t)},_updateImperial:function(t){var e,i,n,s=3.2808399*t;s>5280?(e=s/5280,i=this._getRoundNum(e),this._updateScale(this._iScale,i+" mi",i/e)):(n=this._getRoundNum(s),this._updateScale(this._iScale,n+" ft",n/s))},_updateScale:function(t,e,i){t.style.width=Math.round(this.options.maxWidth*i)+"px",t.innerHTML=e},_getRoundNum:function(t){var e=Math.pow(10,(Math.floor(t)+"").length-1),i=t/e;return e*(i>=10?10:i>=5?5:i>=3?3:i>=2?2:1)}}),Qe=qe.extend({options:{position:"bottomright",prefix:''+(Rt.inlineSvg?' ':"")+"Leaflet"},initialize:function(t){c(this,t),this._attributions={}},onAdd:function(t){for(var e in t.attributionControl=this,this._container=se("div","leaflet-control-attribution"),ke(this._container),t._layers)t._layers[e].getAttribution&&this.addAttribution(t._layers[e].getAttribution());return this._update(),t.on("layeradd",this._addAttribution,this),this._container},onRemove:function(t){t.off("layeradd",this._addAttribution,this)},_addAttribution:function(t){t.layer.getAttribution&&(this.addAttribution(t.layer.getAttribution()),t.layer.once("remove",function(){this.removeAttribution(t.layer.getAttribution())},this))},setPrefix:function(t){return this.options.prefix=t,this._update(),this},addAttribution:function(t){return t?(this._attributions[t]||(this._attributions[t]=0),this._attributions[t]++,this._update(),this):this},removeAttribution:function(t){return t?(this._attributions[t]&&(this._attributions[t]--,this._update()),this):this},_update:function(){if(this._map){var t=[];for(var e in this._attributions)this._attributions[e]&&t.push(e);var i=[];this.options.prefix&&i.push(this.options.prefix),t.length&&i.push(t.join(", ")),this._container.innerHTML=i.join(' ')}}});Xe.mergeOptions({attributionControl:!0}),Xe.addInitHook(function(){this.options.attributionControl&&(new Qe).addTo(this)});qe.Layers=Ye,qe.Zoom=$e,qe.Scale=Ke,qe.Attribution=Qe,Ve.layers=function(t,e,i){return new Ye(t,e,i)},Ve.zoom=function(t){return new $e(t)},Ve.scale=function(t){return new Ke(t)},Ve.attribution=function(t){return new Qe(t)};var Je=A.extend({initialize:function(t){this._map=t},enable:function(){return this._enabled||(this._enabled=!0,this.addHooks()),this},disable:function(){return this._enabled?(this._enabled=!1,this.removeHooks(),this):this},enabled:function(){return!!this._enabled}});Je.addTo=function(t,e){return t.addHandler(e,this),this};var ti={Events:C},ei=Rt.touch?"touchstart mousedown":"mousedown",ii=M.extend({options:{clickTolerance:3},initialize:function(t,e,i,n){c(this,n),this._element=t,this._dragStartTarget=e||t,this._preventOutline=i},enable:function(){this._enabled||(Ae(this._dragStartTarget,ei,this._onDown,this),this._enabled=!0)},disable:function(){this._enabled&&(ii._dragging===this&&this.finishDrag(!0),Me(this._dragStartTarget,ei,this._onDown,this),this._enabled=!1,this._moved=!1)},_onDown:function(t){if(this._enabled&&(this._moved=!1,!le(this._element,"leaflet-zoom-anim")))if(t.touches&&1!==t.touches.length)ii._dragging===this&&this.finishDrag();else if(!(ii._dragging||t.shiftKey||1!==t.which&&1!==t.button&&!t.touches||(ii._dragging=this,this._preventOutline&&Se(this._element),xe(),Vt(),this._moving))){this.fire("down");var e=t.touches?t.touches[0]:t,i=Te(this._element);this._startPoint=new N(e.clientX,e.clientY),this._startPos=ve(this._element),this._parentScale=Ee(i);var n="mousedown"===t.type;Ae(document,n?"mousemove":"touchmove",this._onMove,this),Ae(document,n?"mouseup":"touchend touchcancel",this._onUp,this)}},_onMove:function(t){if(this._enabled)if(t.touches&&t.touches.length>1)this._moved=!0;else{var e=t.touches&&1===t.touches.length?t.touches[0]:t,i=new N(e.clientX,e.clientY)._subtract(this._startPoint);(i.x||i.y)&&(Math.abs(i.x)+Math.abs(i.y)e&&(i.push(t[n]),s=n);return sh&&(o=r,h=a);h>i&&(e[o]=1,di(t,e,i,n,o),di(t,e,i,o,s))}function ui(t,e,i,n,s){var o,r,a,h=n?ri:_i(t,i),l=_i(e,i);for(ri=l;;){if(!(h|l))return[t,e];if(h&l)return!1;a=_i(r=ci(t,e,o=h||l,i,s),i),o===h?(t=r,h=a):(e=r,l=a)}}function ci(t,e,i,n,s){var o,r,a=e.x-t.x,h=e.y-t.y,l=n.min,d=n.max;return 8&i?(o=t.x+a*(d.y-t.y)/h,r=d.y):4&i?(o=t.x+a*(l.y-t.y)/h,r=l.y):2&i?(o=d.x,r=t.y+h*(d.x-t.x)/a):1&i&&(o=l.x,r=t.y+h*(l.x-t.x)/a),new N(o,r,s)}function _i(t,e){var i=0;return t.xe.max.x&&(i|=2),t.ye.max.y&&(i|=8),i}function fi(t,e){var i=e.x-t.x,n=e.y-t.y;return i*i+n*n}function gi(t,e,i,n){var s,o=e.x,r=e.y,a=i.x-o,h=i.y-r,l=a*a+h*h;return l>0&&((s=((t.x-o)*a+(t.y-r)*h)/l)>1?(o=i.x,r=i.y):s>0&&(o+=a*s,r+=h*s)),a=t.x-o,h=t.y-r,n?a*a+h*h:new N(o,r)}function pi(t){return!p(t[0])||"object"!=typeof t[0][0]&&void 0!==t[0][0]}function mi(t){return console.warn("Deprecated use of _flat, please use L.LineUtil.isFlat instead."),pi(t)}function vi(t,e){var i,n,s,o,r,a,h,l;if(!t||0===t.length)throw new Error("latlngs not passed");pi(t)||(console.warn("latlngs are not flat! Only the first ring will be used"),t=t[0]);var d=U([0,0]),u=B(t);u.getNorthWest().distanceTo(u.getSouthWest())*u.getNorthEast().distanceTo(u.getNorthWest())<1700&&(d=oi(t));var c=t.length,_=[];for(i=0;in){h=(o-n)/s,l=[a.x-h*(a.x-r.x),a.y-h*(a.y-r.y)];break}var g=e.unproject(I(l));return U([g.lat+d.lat,g.lng+d.lng])}var yi={__proto__:null,simplify:hi,pointToSegmentDistance:li,closestPointOnSegment:function(t,e,i){return gi(t,e,i)},clipSegment:ui,_getEdgeIntersection:ci,_getBitCode:_i,_sqClosestPointOnSegment:gi,isFlat:pi,_flat:mi,polylineCenter:vi},xi={project:function(t){return new N(t.lng,t.lat)},unproject:function(t){return new z(t.y,t.x)},bounds:new R([-180,-90],[180,90])},bi={R:6378137,R_MINOR:6356752.314245179,bounds:new R([-20037508.34279,-15496570.73972],[20037508.34279,18764656.23138]),project:function(t){var e=Math.PI/180,i=this.R,n=t.lat*e,s=this.R_MINOR/i,o=Math.sqrt(1-s*s),r=o*Math.sin(n),a=Math.tan(Math.PI/4-n/2)/Math.pow((1-r)/(1+r),o/2);return n=-i*Math.log(Math.max(a,1e-10)),new N(t.lng*e*i,n)},unproject:function(t){for(var e,i=180/Math.PI,n=this.R,s=this.R_MINOR/n,o=Math.sqrt(1-s*s),r=Math.exp(-t.y/n),a=Math.PI/2-2*Math.atan(r),h=0,l=.1;h<15&&Math.abs(l)>1e-7;h++)e=o*Math.sin(a),e=Math.pow((1-e)/(1+e),o/2),a+=l=Math.PI/2-2*Math.atan(r*e)-a;return new z(a*i,t.x*i/n)}},Si={__proto__:null,LonLat:xi,Mercator:bi,SphericalMercator:Z},wi=e({},W,{code:"EPSG:3395",projection:bi,transformation:function(){var t=.5/(Math.PI*bi.R);return X(t,.5,-t,.5)}()}),Ti=e({},W,{code:"EPSG:4326",projection:xi,transformation:X(1/180,1,-1/180,.5)}),Ei=e({},j,{projection:xi,transformation:X(1,0,-1,0),scale:function(t){return Math.pow(2,t)},zoom:function(t){return Math.log(t)/Math.LN2},distance:function(t,e){var i=e.lng-t.lng,n=e.lat-t.lat;return Math.sqrt(i*i+n*n)},infinite:!0});j.Earth=W,j.EPSG3395=wi,j.EPSG3857=q,j.EPSG900913=V,j.EPSG4326=Ti,j.Simple=Ei;var Pi=M.extend({options:{pane:"overlayPane",attribution:null,bubblingMouseEvents:!0},addTo:function(t){return t.addLayer(this),this},remove:function(){return this.removeFrom(this._map||this._mapToAdd)},removeFrom:function(t){return t&&t.removeLayer(this),this},getPane:function(t){return this._map.getPane(t?this.options[t]||t:this.options.pane)},addInteractiveTarget:function(t){return this._map._targets[o(t)]=this,this},removeInteractiveTarget:function(t){return delete this._map._targets[o(t)],this},getAttribution:function(){return this.options.attribution},_layerAdd:function(t){var e=t.target;if(e.hasLayer(this)){if(this._map=e,this._zoomAnimated=e._zoomAnimated,this.getEvents){var i=this.getEvents();e.on(i,this),this.once("remove",function(){e.off(i,this)},this)}this.onAdd(e),this.fire("add"),e.fire("layeradd",{layer:this})}}});Xe.include({addLayer:function(t){if(!t._layerAdd)throw new Error("The provided object is not a Layer.");var e=o(t);return this._layers[e]||(this._layers[e]=t,t._mapToAdd=this,t.beforeAdd&&t.beforeAdd(this),this.whenReady(t._layerAdd,t)),this},removeLayer:function(t){var e=o(t);return this._layers[e]?(this._loaded&&t.onRemove(this),delete this._layers[e],this._loaded&&(this.fire("layerremove",{layer:t}),t.fire("remove")),t._map=t._mapToAdd=null,this):this},hasLayer:function(t){return o(t)in this._layers},eachLayer:function(t,e){for(var i in this._layers)t.call(e,this._layers[i]);return this},_addLayers:function(t){for(var e=0,i=(t=t?p(t)?t:[t]:[]).length;ethis._layersMaxZoom&&this.setZoom(this._layersMaxZoom),void 0===this.options.minZoom&&this._layersMinZoom&&this.getZoom()=2&&e[0]instanceof z&&e[0].equals(e[i-1])&&e.pop(),e},_setLatLngs:function(t){ki.prototype._setLatLngs.call(this,t),pi(this._latlngs)&&(this._latlngs=[this._latlngs])},_defaultShape:function(){return pi(this._latlngs[0])?this._latlngs[0]:this._latlngs[0][0]},_clipPoints:function(){var t=this._renderer._bounds,e=this.options.weight,i=new N(e,e);if(t=new R(t.min.subtract(i),t.max.add(i)),this._parts=[],this._pxBounds&&this._pxBounds.intersects(t))if(this.options.noClip)this._parts=this._rings;else for(var n,s=0,o=this._rings.length;st.y!=n.y>t.y&&t.x<(n.x-i.x)*(t.y-i.y)/(n.y-i.y)+i.x&&(l=!l);return l||ki.prototype._containsPoint.call(this,t,!0)}});var zi=Ci.extend({initialize:function(t,e){c(this,e),this._layers={},t&&this.addData(t)},addData:function(t){var e,i,n,s=p(t)?t:t.features;if(s){for(e=0,i=s.length;e0&&s.push(s[0].slice()),s}function Hi(t,i){return t.feature?e({},t.feature,{geometry:i}):Xi(i)}function Xi(t){return"Feature"===t.type||"FeatureCollection"===t.type?t:{type:"Feature",properties:{},geometry:t}}var qi={toGeoJSON:function(t){return Hi(this,{type:"Point",coordinates:Gi(this.getLatLng(),t)})}};function Vi(t,e){return new zi(t,e)}Ii.include(qi),Oi.include(qi),Ri.include(qi),ki.include({toGeoJSON:function(t){var e=!pi(this._latlngs);return Hi(this,{type:(e?"Multi":"")+"LineString",coordinates:Zi(this._latlngs,e?1:0,!1,t)})}}),Bi.include({toGeoJSON:function(t){var e=!pi(this._latlngs),i=e&&!pi(this._latlngs[0]),n=Zi(this._latlngs,i?2:e?1:0,!0,t);return e||(n=[n]),Hi(this,{type:(i?"Multi":"")+"Polygon",coordinates:n})}}),Ai.include({toMultiPoint:function(t){var e=[];return this.eachLayer(function(i){e.push(i.toGeoJSON(t).geometry.coordinates)}),Hi(this,{type:"MultiPoint",coordinates:e})},toGeoJSON:function(t){var e=this.feature&&this.feature.geometry&&this.feature.geometry.type;if("MultiPoint"===e)return this.toMultiPoint(t);var i="GeometryCollection"===e,n=[];return this.eachLayer(function(e){if(e.toGeoJSON){var s=e.toGeoJSON(t);if(i)n.push(s.geometry);else{var o=Xi(s);"FeatureCollection"===o.type?n.push.apply(n,o.features):n.push(o)}}}),i?Hi(this,{geometries:n,type:"GeometryCollection"}):{type:"FeatureCollection",features:n}}});var Yi=Vi,$i=Pi.extend({options:{opacity:1,alt:"",interactive:!1,crossOrigin:!1,errorOverlayUrl:"",zIndex:1,className:""},initialize:function(t,e,i){this._url=t,this._bounds=B(e),c(this,i)},onAdd:function(){this._image||(this._initImage(),this.options.opacity<1&&this._updateOpacity()),this.options.interactive&&(de(this._image,"leaflet-interactive"),this.addInteractiveTarget(this._image)),this.getPane().appendChild(this._image),this._reset()},onRemove:function(){oe(this._image),this.options.interactive&&this.removeInteractiveTarget(this._image)},setOpacity:function(t){return this.options.opacity=t,this._image&&this._updateOpacity(),this},setStyle:function(t){return t.opacity&&this.setOpacity(t.opacity),this},bringToFront:function(){return this._map&&ae(this._image),this},bringToBack:function(){return this._map&&he(this._image),this},setUrl:function(t){return this._url=t,this._image&&(this._image.src=t),this},setBounds:function(t){return this._bounds=B(t),this._map&&this._reset(),this},getEvents:function(){var t={zoom:this._reset,viewreset:this._reset};return this._zoomAnimated&&(t.zoomanim=this._animateZoom),t},setZIndex:function(t){return this.options.zIndex=t,this._updateZIndex(),this},getBounds:function(){return this._bounds},getElement:function(){return this._image},_initImage:function(){var t="IMG"===this._url.tagName,e=this._image=t?this._url:se("img");de(e,"leaflet-image-layer"),this._zoomAnimated&&de(e,"leaflet-zoom-animated"),this.options.className&&de(e,this.options.className),e.onselectstart=h,e.onmousemove=h,e.onload=n(this.fire,this,"load"),e.onerror=n(this._overlayOnError,this,"error"),(this.options.crossOrigin||""===this.options.crossOrigin)&&(e.crossOrigin=!0===this.options.crossOrigin?"":this.options.crossOrigin),this.options.zIndex&&this._updateZIndex(),t?this._url=e.src:(e.src=this._url,e.alt=this.options.alt)},_animateZoom:function(t){var e=this._map.getZoomScale(t.zoom),i=this._map._latLngBoundsToNewLayerBounds(this._bounds,t.zoom,t.center).min;pe(this._image,i,e)},_reset:function(){var t=this._image,e=new R(this._map.latLngToLayerPoint(this._bounds.getNorthWest()),this._map.latLngToLayerPoint(this._bounds.getSouthEast())),i=e.getSize();me(t,e.min),t.style.width=i.x+"px",t.style.height=i.y+"px"},_updateOpacity:function(){fe(this._image,this.options.opacity)},_updateZIndex:function(){this._image&&void 0!==this.options.zIndex&&null!==this.options.zIndex&&(this._image.style.zIndex=this.options.zIndex)},_overlayOnError:function(){this.fire("error");var t=this.options.errorOverlayUrl;t&&this._url!==t&&(this._url=t,this._image.src=t)},getCenter:function(){return this._bounds.getCenter()}}),Ki=$i.extend({options:{autoplay:!0,loop:!0,keepAspectRatio:!0,muted:!1,playsInline:!0},_initImage:function(){var t="VIDEO"===this._url.tagName,e=this._image=t?this._url:se("video");if(de(e,"leaflet-image-layer"),this._zoomAnimated&&de(e,"leaflet-zoom-animated"),this.options.className&&de(e,this.options.className),e.onselectstart=h,e.onmousemove=h,e.onloadeddata=n(this.fire,this,"load"),t){for(var i=e.getElementsByTagName("source"),s=[],o=0;o0?s:[e.src]}else{p(this._url)||(this._url=[this._url]),!this.options.keepAspectRatio&&Object.prototype.hasOwnProperty.call(e.style,"objectFit")&&(e.style.objectFit="fill"),e.autoplay=!!this.options.autoplay,e.loop=!!this.options.loop,e.muted=!!this.options.muted,e.playsInline=!!this.options.playsInline;for(var r=0;rs?(e.height=s+"px",de(t,o)):ue(t,o),this._containerWidth=this._container.offsetWidth},_animateZoom:function(t){var e=this._map._latLngToNewLayerPoint(this._latlng,t.zoom,t.center),i=this._getAnchor();me(this._container,e.add(i))},_adjustPan:function(){if(this.options.autoPan)if(this._map._panAnim&&this._map._panAnim.stop(),this._autopanning)this._autopanning=!1;else{var t=this._map,e=parseInt(ne(this._container,"marginBottom"),10)||0,i=this._container.offsetHeight+e,n=this._containerWidth,s=new N(this._containerLeft,-i-this._containerBottom);s._add(ve(this._container));var o=t.layerPointToContainerPoint(s),r=I(this.options.autoPanPadding),a=I(this.options.autoPanPaddingTopLeft||r),h=I(this.options.autoPanPaddingBottomRight||r),l=t.getSize(),d=0,u=0;o.x+n+h.x>l.x&&(d=o.x+n-l.x+h.x),o.x-d-a.x<0&&(d=o.x-a.x),o.y+i+h.y>l.y&&(u=o.y+i-l.y+h.y),o.y-u-a.y<0&&(u=o.y-a.y),(d||u)&&(this.options.keepInView&&(this._autopanning=!0),t.fire("autopanstart").panBy([d,u]))}},_getAnchor:function(){return I(this._source&&this._source._getPopupAnchor?this._source._getPopupAnchor():[0,0])}});Xe.mergeOptions({closePopupOnClick:!0}),Xe.include({openPopup:function(t,e,i){return this._initOverlay(tn,t,e,i).openOn(this),this},closePopup:function(t){return(t=arguments.length?t:this._popup)&&t.close(),this}}),Pi.include({bindPopup:function(t,e){return this._popup=this._initOverlay(tn,this._popup,t,e),this._popupHandlersAdded||(this.on({click:this._openPopup,keypress:this._onKeyPress,remove:this.closePopup,move:this._movePopup}),this._popupHandlersAdded=!0),this},unbindPopup:function(){return this._popup&&(this.off({click:this._openPopup,keypress:this._onKeyPress,remove:this.closePopup,move:this._movePopup}),this._popupHandlersAdded=!1,this._popup=null),this},openPopup:function(t){return this._popup&&(this instanceof Ci||(this._popup._source=this),this._popup._prepareOpen(t||this._latlng)&&this._popup.openOn(this._map)),this},closePopup:function(){return this._popup&&this._popup.close(),this},togglePopup:function(){return this._popup&&this._popup.toggle(this),this},isPopupOpen:function(){return!!this._popup&&this._popup.isOpen()},setPopupContent:function(t){return this._popup&&this._popup.setContent(t),this},getPopup:function(){return this._popup},_openPopup:function(t){if(this._popup&&this._map){ze(t);var e=t.layer||t.target;this._popup._source!==e||e instanceof Li?(this._popup._source=e,this.openPopup(t.latlng)):this._map.hasLayer(this._popup)?this.closePopup():this.openPopup(t.latlng)}},_movePopup:function(t){this._popup.setLatLng(t.latlng)},_onKeyPress:function(t){13===t.originalEvent.keyCode&&this._openPopup(t)}});var en=Ji.extend({options:{pane:"tooltipPane",offset:[0,0],direction:"auto",permanent:!1,sticky:!1,opacity:.9},onAdd:function(t){Ji.prototype.onAdd.call(this,t),this.setOpacity(this.options.opacity),t.fire("tooltipopen",{tooltip:this}),this._source&&(this.addEventParent(this._source),this._source.fire("tooltipopen",{tooltip:this},!0))},onRemove:function(t){Ji.prototype.onRemove.call(this,t),t.fire("tooltipclose",{tooltip:this}),this._source&&(this.removeEventParent(this._source),this._source.fire("tooltipclose",{tooltip:this},!0))},getEvents:function(){var t=Ji.prototype.getEvents.call(this);return this.options.permanent||(t.preclick=this.close),t},_initLayout:function(){var t="leaflet-tooltip "+(this.options.className||"")+" leaflet-zoom-"+(this._zoomAnimated?"animated":"hide");this._contentNode=this._container=se("div",t),this._container.setAttribute("role","tooltip"),this._container.setAttribute("id","leaflet-tooltip-"+o(this))},_updateLayout:function(){},_adjustPan:function(){},_setPosition:function(t){var e,i,n=this._map,s=this._container,o=n.latLngToContainerPoint(n.getCenter()),r=n.layerPointToContainerPoint(t),a=this.options.direction,h=s.offsetWidth,l=s.offsetHeight,d=I(this.options.offset),u=this._getAnchor();"top"===a?(e=h/2,i=l):"bottom"===a?(e=h/2,i=0):"center"===a?(e=h/2,i=l/2):"right"===a?(e=0,i=l/2):"left"===a?(e=h,i=l/2):r.xthis.options.maxZoom||in&&this._retainParent(s,o,r,n))},_retainChildren:function(t,e,i,n){for(var s=2*t;s<2*t+2;s++)for(var o=2*e;o<2*e+2;o++){var r=new N(s,o);r.z=i+1;var a=this._tileCoordsToKey(r),h=this._tiles[a];h&&h.active?h.retain=!0:(h&&h.loaded&&(h.retain=!0),i+1this.options.maxZoom||void 0!==this.options.minZoom&&s1)this._setView(t,i);else{for(var u=s.min.y;u<=s.max.y;u++)for(var c=s.min.x;c<=s.max.x;c++){var _=new N(c,u);if(_.z=this._tileZoom,this._isValidTile(_)){var f=this._tiles[this._tileCoordsToKey(_)];f?f.current=!0:r.push(_)}}if(r.sort(function(t,e){return t.distanceTo(o)-e.distanceTo(o)}),0!==r.length){this._loading||(this._loading=!0,this.fire("loading"));var g=document.createDocumentFragment();for(c=0;ci.max.x)||!e.wrapLat&&(t.yi.max.y))return!1}if(!this.options.bounds)return!0;var n=this._tileCoordsToBounds(t);return B(this.options.bounds).overlaps(n)},_keyToBounds:function(t){return this._tileCoordsToBounds(this._keyToTileCoords(t))},_tileCoordsToNwSe:function(t){var e=this._map,i=this.getTileSize(),n=t.scaleBy(i),s=n.add(i);return[e.unproject(n,t.z),e.unproject(s,t.z)]},_tileCoordsToBounds:function(t){var e=this._tileCoordsToNwSe(t),i=new k(e[0],e[1]);return this.options.noWrap||(i=this._map.wrapLatLngBounds(i)),i},_tileCoordsToKey:function(t){return t.x+":"+t.y+":"+t.z},_keyToTileCoords:function(t){var e=t.split(":"),i=new N(+e[0],+e[1]);return i.z=+e[2],i},_removeTile:function(t){var e=this._tiles[t];e&&(oe(e.el),delete this._tiles[t],this.fire("tileunload",{tile:e.el,coords:this._keyToTileCoords(t)}))},_initTile:function(t){de(t,"leaflet-tile");var e=this.getTileSize();t.style.width=e.x+"px",t.style.height=e.y+"px",t.onselectstart=h,t.onmousemove=h,Rt.ielt9&&this.options.opacity<1&&fe(t,this.options.opacity)},_addTile:function(t,e){var i=this._getTilePos(t),s=this._tileCoordsToKey(t),o=this.createTile(this._wrapCoords(t),n(this._tileReady,this,t));this._initTile(o),this.createTile.length<2&&T(n(this._tileReady,this,t,null,o)),me(o,i),this._tiles[s]={el:o,coords:t,current:!0},e.appendChild(o),this.fire("tileloadstart",{tile:o,coords:t})},_tileReady:function(t,e,i){e&&this.fire("tileerror",{error:e,tile:i,coords:t});var s=this._tileCoordsToKey(t);(i=this._tiles[s])&&(i.loaded=+new Date,this._map._fadeAnimated?(fe(i.el,0),E(this._fadeFrame),this._fadeFrame=T(this._updateOpacity,this)):(i.active=!0,this._pruneTiles()),e||(de(i.el,"leaflet-tile-loaded"),this.fire("tileload",{tile:i.el,coords:t})),this._noTilesToLoad()&&(this._loading=!1,this.fire("load"),Rt.ielt9||!this._map._fadeAnimated?T(this._pruneTiles,this):setTimeout(n(this._pruneTiles,this),250)))},_getTilePos:function(t){return t.scaleBy(this.getTileSize()).subtract(this._level.origin)},_wrapCoords:function(t){var e=new N(this._wrapX?a(t.x,this._wrapX):t.x,this._wrapY?a(t.y,this._wrapY):t.y);return e.z=t.z,e},_pxBoundsToTileRange:function(t){var e=this.getTileSize();return new R(t.min.unscaleBy(e).floor(),t.max.unscaleBy(e).ceil().subtract([1,1]))},_noTilesToLoad:function(){for(var t in this._tiles)if(!this._tiles[t].loaded)return!1;return!0}});var on=sn.extend({options:{minZoom:0,maxZoom:18,subdomains:"abc",errorTileUrl:"",zoomOffset:0,tms:!1,zoomReverse:!1,detectRetina:!1,crossOrigin:!1,referrerPolicy:!1},initialize:function(t,e){this._url=t,(e=c(this,e)).detectRetina&&Rt.retina&&e.maxZoom>0?(e.tileSize=Math.floor(e.tileSize/2),e.zoomReverse?(e.zoomOffset--,e.minZoom=Math.min(e.maxZoom,e.minZoom+1)):(e.zoomOffset++,e.maxZoom=Math.max(e.minZoom,e.maxZoom-1)),e.minZoom=Math.max(0,e.minZoom)):e.zoomReverse?e.minZoom=Math.min(e.maxZoom,e.minZoom):e.maxZoom=Math.max(e.minZoom,e.maxZoom),"string"==typeof e.subdomains&&(e.subdomains=e.subdomains.split("")),this.on("tileunload",this._onTileRemove)},setUrl:function(t,e){return this._url===t&&void 0===e&&(e=!0),this._url=t,e||this.redraw(),this},createTile:function(t,e){var i=document.createElement("img");return Ae(i,"load",n(this._tileOnLoad,this,e,i)),Ae(i,"error",n(this._tileOnError,this,e,i)),(this.options.crossOrigin||""===this.options.crossOrigin)&&(i.crossOrigin=!0===this.options.crossOrigin?"":this.options.crossOrigin),"string"==typeof this.options.referrerPolicy&&(i.referrerPolicy=this.options.referrerPolicy),i.alt="",i.src=this.getTileUrl(t),i},getTileUrl:function(t){var i={r:Rt.retina?"@2x":"",s:this._getSubdomain(t),x:t.x,y:t.y,z:this._getZoomForUrl()};if(this._map&&!this._map.options.crs.infinite){var n=this._globalTileRange.max.y-t.y;this.options.tms&&(i.y=n),i["-y"]=n}return g(this._url,e(i,this.options))},_tileOnLoad:function(t,e){Rt.ielt9?setTimeout(n(t,this,null,e),0):t(null,e)},_tileOnError:function(t,e,i){var n=this.options.errorTileUrl;n&&e.getAttribute("src")!==n&&(e.src=n),t(i,e)},_onTileRemove:function(t){t.tile.onload=null},_getZoomForUrl:function(){var t=this._tileZoom,e=this.options.maxZoom;return this.options.zoomReverse&&(t=e-t),t+this.options.zoomOffset},_getSubdomain:function(t){var e=Math.abs(t.x+t.y)%this.options.subdomains.length;return this.options.subdomains[e]},_abortLoading:function(){var t,e;for(t in this._tiles)if(this._tiles[t].coords.z!==this._tileZoom&&((e=this._tiles[t].el).onload=h,e.onerror=h,!e.complete)){e.src=v;var i=this._tiles[t].coords;oe(e),delete this._tiles[t],this.fire("tileabort",{tile:e,coords:i})}},_removeTile:function(t){var e=this._tiles[t];if(e)return e.el.setAttribute("src",v),sn.prototype._removeTile.call(this,t)},_tileReady:function(t,e,i){if(this._map&&(!i||i.getAttribute("src")!==v))return sn.prototype._tileReady.call(this,t,e,i)}});function rn(t,e){return new on(t,e)}var an=on.extend({defaultWmsParams:{service:"WMS",request:"GetMap",layers:"",styles:"",format:"image/jpeg",transparent:!1,version:"1.1.1"},options:{crs:null,uppercase:!1},initialize:function(t,i){this._url=t;var n=e({},this.defaultWmsParams);for(var s in i)s in this.options||(n[s]=i[s]);var o=(i=c(this,i)).detectRetina&&Rt.retina?2:1,r=this.getTileSize();n.width=r.x*o,n.height=r.y*o,this.wmsParams=n},onAdd:function(t){this._crs=this.options.crs||t.options.crs,this._wmsVersion=parseFloat(this.wmsParams.version);var e=this._wmsVersion>=1.3?"crs":"srs";this.wmsParams[e]=this._crs.code,on.prototype.onAdd.call(this,t)},getTileUrl:function(t){var e=this._tileCoordsToNwSe(t),i=this._crs,n=O(i.project(e[0]),i.project(e[1])),s=n.min,o=n.max,r=(this._wmsVersion>=1.3&&this._crs===Ti?[s.y,s.x,o.y,o.x]:[s.x,s.y,o.x,o.y]).join(","),a=on.prototype.getTileUrl.call(this,t);return a+_(this.wmsParams,a,this.options.uppercase)+(this.options.uppercase?"&BBOX=":"&bbox=")+r},setParams:function(t,i){return e(this.wmsParams,t),i||this.redraw(),this}});on.WMS=an,rn.wms=function(t,e){return new an(t,e)};var hn=Pi.extend({options:{padding:.1},initialize:function(t){c(this,t),o(this),this._layers=this._layers||{}},onAdd:function(){this._container||(this._initContainer(),de(this._container,"leaflet-zoom-animated")),this.getPane().appendChild(this._container),this._update(),this.on("update",this._updatePaths,this)},onRemove:function(){this.off("update",this._updatePaths,this),this._destroyContainer()},getEvents:function(){var t={viewreset:this._reset,zoom:this._onZoom,moveend:this._update,zoomend:this._onZoomEnd};return this._zoomAnimated&&(t.zoomanim=this._onAnimZoom),t},_onAnimZoom:function(t){this._updateTransform(t.center,t.zoom)},_onZoom:function(){this._updateTransform(this._map.getCenter(),this._map.getZoom())},_updateTransform:function(t,e){var i=this._map.getZoomScale(e,this._zoom),n=this._map.getSize().multiplyBy(.5+this.options.padding),s=this._map.project(this._center,e),o=n.multiplyBy(-i).add(s).subtract(this._map._getNewPixelOrigin(t,e));Rt.any3d?pe(this._container,o,i):me(this._container,o)},_reset:function(){for(var t in this._update(),this._updateTransform(this._center,this._zoom),this._layers)this._layers[t]._reset()},_onZoomEnd:function(){for(var t in this._layers)this._layers[t]._project()},_updatePaths:function(){for(var t in this._layers)this._layers[t]._update()},_update:function(){var t=this.options.padding,e=this._map.getSize(),i=this._map.containerPointToLayerPoint(e.multiplyBy(-t)).round();this._bounds=new R(i,i.add(e.multiplyBy(1+2*t)).round()),this._center=this._map.getCenter(),this._zoom=this._map.getZoom()}}),ln=hn.extend({options:{tolerance:0},getEvents:function(){var t=hn.prototype.getEvents.call(this);return t.viewprereset=this._onViewPreReset,t},_onViewPreReset:function(){this._postponeUpdatePaths=!0},onAdd:function(){hn.prototype.onAdd.call(this),this._draw()},_initContainer:function(){var t=this._container=document.createElement("canvas");Ae(t,"mousemove",this._onMouseMove,this),Ae(t,"click dblclick mousedown mouseup contextmenu",this._onClick,this),Ae(t,"mouseout",this._handleMouseOut,this),t._leaflet_disable_events=!0,this._ctx=t.getContext("2d")},_destroyContainer:function(){E(this._redrawRequest),delete this._ctx,oe(this._container),Me(this._container),delete this._container},_updatePaths:function(){if(!this._postponeUpdatePaths){for(var t in this._redrawBounds=null,this._layers)this._layers[t]._update();this._redraw()}},_update:function(){if(!this._map._animatingZoom||!this._bounds){hn.prototype._update.call(this);var t=this._bounds,e=this._container,i=t.getSize(),n=Rt.retina?2:1;me(e,t.min),e.width=n*i.x,e.height=n*i.y,e.style.width=i.x+"px",e.style.height=i.y+"px",Rt.retina&&this._ctx.scale(2,2),this._ctx.translate(-t.min.x,-t.min.y),this.fire("update")}},_reset:function(){hn.prototype._reset.call(this),this._postponeUpdatePaths&&(this._postponeUpdatePaths=!1,this._updatePaths())},_initPath:function(t){this._updateDashArray(t),this._layers[o(t)]=t;var e=t._order={layer:t,prev:this._drawLast,next:null};this._drawLast&&(this._drawLast.next=e),this._drawLast=e,this._drawFirst=this._drawFirst||this._drawLast},_addPath:function(t){this._requestRedraw(t)},_removePath:function(t){var e=t._order,i=e.next,n=e.prev;i?i.prev=n:this._drawLast=n,n?n.next=i:this._drawFirst=i,delete t._order,delete this._layers[o(t)],this._requestRedraw(t)},_updatePath:function(t){this._extendRedrawBounds(t),t._project(),t._update(),this._requestRedraw(t)},_updateStyle:function(t){this._updateDashArray(t),this._requestRedraw(t)},_updateDashArray:function(t){if("string"==typeof t.options.dashArray){var e,i,n=t.options.dashArray.split(/[, ]+/),s=[];for(i=0;i')}}catch(t){}return function(t){return document.createElement("<"+t+' xmlns="urn:schemas-microsoft.com:vml" class="lvml">')}}(),cn={_initContainer:function(){this._container=se("div","leaflet-vml-container")},_update:function(){this._map._animatingZoom||(hn.prototype._update.call(this),this.fire("update"))},_initPath:function(t){var e=t._container=un("shape");de(e,"leaflet-vml-shape "+(this.options.className||"")),e.coordsize="1 1",t._path=un("path"),e.appendChild(t._path),this._updateStyle(t),this._layers[o(t)]=t},_addPath:function(t){var e=t._container;this._container.appendChild(e),t.options.interactive&&t.addInteractiveTarget(e)},_removePath:function(t){var e=t._container;oe(e),t.removeInteractiveTarget(e),delete this._layers[o(t)]},_updateStyle:function(t){var e=t._stroke,i=t._fill,n=t.options,s=t._container;s.stroked=!!n.stroke,s.filled=!!n.fill,n.stroke?(e||(e=t._stroke=un("stroke")),s.appendChild(e),e.weight=n.weight+"px",e.color=n.color,e.opacity=n.opacity,n.dashArray?e.dashStyle=p(n.dashArray)?n.dashArray.join(" "):n.dashArray.replace(/( *, *)/g," "):e.dashStyle="",e.endcap=n.lineCap.replace("butt","flat"),e.joinstyle=n.lineJoin):e&&(s.removeChild(e),t._stroke=null),n.fill?(i||(i=t._fill=un("fill")),s.appendChild(i),i.color=n.fillColor||n.color,i.opacity=n.fillOpacity):i&&(s.removeChild(i),t._fill=null)},_updateCircle:function(t){var e=t._point.round(),i=Math.round(t._radius),n=Math.round(t._radiusY||i);this._setPath(t,t._empty()?"M0 0":"AL "+e.x+","+e.y+" "+i+","+n+" 0,23592600")},_setPath:function(t,e){t._path.v=e},_bringToFront:function(t){ae(t._container)},_bringToBack:function(t){he(t._container)}},_n=Rt.vml?un:Y,fn=hn.extend({_initContainer:function(){this._container=_n("svg"),this._container.setAttribute("pointer-events","none"),this._rootGroup=_n("g"),this._container.appendChild(this._rootGroup)},_destroyContainer:function(){oe(this._container),Me(this._container),delete this._container,delete this._rootGroup,delete this._svgSize},_update:function(){if(!this._map._animatingZoom||!this._bounds){hn.prototype._update.call(this);var t=this._bounds,e=t.getSize(),i=this._container;this._svgSize&&this._svgSize.equals(e)||(this._svgSize=e,i.setAttribute("width",e.x),i.setAttribute("height",e.y)),me(i,t.min),i.setAttribute("viewBox",[t.min.x,t.min.y,e.x,e.y].join(" ")),this.fire("update")}},_initPath:function(t){var e=t._path=_n("path");t.options.className&&de(e,t.options.className),t.options.interactive&&de(e,"leaflet-interactive"),this._updateStyle(t),this._layers[o(t)]=t},_addPath:function(t){this._rootGroup||this._initContainer(),this._rootGroup.appendChild(t._path),t.addInteractiveTarget(t._path)},_removePath:function(t){oe(t._path),t.removeInteractiveTarget(t._path),delete this._layers[o(t)]},_updatePath:function(t){t._project(),t._update()},_updateStyle:function(t){var e=t._path,i=t.options;e&&(i.stroke?(e.setAttribute("stroke",i.color),e.setAttribute("stroke-opacity",i.opacity),e.setAttribute("stroke-width",i.weight),e.setAttribute("stroke-linecap",i.lineCap),e.setAttribute("stroke-linejoin",i.lineJoin),i.dashArray?e.setAttribute("stroke-dasharray",i.dashArray):e.removeAttribute("stroke-dasharray"),i.dashOffset?e.setAttribute("stroke-dashoffset",i.dashOffset):e.removeAttribute("stroke-dashoffset")):e.setAttribute("stroke","none"),i.fill?(e.setAttribute("fill",i.fillColor||i.color),e.setAttribute("fill-opacity",i.fillOpacity),e.setAttribute("fill-rule",i.fillRule||"evenodd")):e.setAttribute("fill","none"))},_updatePoly:function(t,e){this._setPath(t,$(t._parts,e))},_updateCircle:function(t){var e=t._point,i=Math.max(Math.round(t._radius),1),n="a"+i+","+(Math.max(Math.round(t._radiusY),1)||i)+" 0 1,0 ",s=t._empty()?"M0 0":"M"+(e.x-i)+","+e.y+n+2*i+",0 "+n+2*-i+",0 ";this._setPath(t,s)},_setPath:function(t,e){t._path.setAttribute("d",e)},_bringToFront:function(t){ae(t._path)},_bringToBack:function(t){he(t._path)}});function gn(t){return Rt.svg||Rt.vml?new fn(t):null}Rt.vml&&fn.include(cn),Xe.include({getRenderer:function(t){var e=t.options.renderer||this._getPaneRenderer(t.options.pane)||this.options.renderer||this._renderer;return e||(e=this._renderer=this._createRenderer()),this.hasLayer(e)||this.addLayer(e),e},_getPaneRenderer:function(t){if("overlayPane"===t||void 0===t)return!1;var e=this._paneRenderers[t];return void 0===e&&(e=this._createRenderer({pane:t}),this._paneRenderers[t]=e),e},_createRenderer:function(t){return this.options.preferCanvas&&dn(t)||gn(t)}});var pn=Bi.extend({initialize:function(t,e){Bi.prototype.initialize.call(this,this._boundsToLatLngs(t),e)},setBounds:function(t){return this.setLatLngs(this._boundsToLatLngs(t))},_boundsToLatLngs:function(t){return[(t=B(t)).getSouthWest(),t.getNorthWest(),t.getNorthEast(),t.getSouthEast()]}});fn.create=_n,fn.pointsToPath=$,zi.geometryToLayer=Ui,zi.coordsToLatLng=ji,zi.coordsToLatLngs=Wi,zi.latLngToCoords=Gi,zi.latLngsToCoords=Zi,zi.getFeature=Hi,zi.asFeature=Xi,Xe.mergeOptions({boxZoom:!0});var mn=Je.extend({initialize:function(t){this._map=t,this._container=t._container,this._pane=t._panes.overlayPane,this._resetStateTimeout=0,t.on("unload",this._destroy,this)},addHooks:function(){Ae(this._container,"mousedown",this._onMouseDown,this)},removeHooks:function(){Me(this._container,"mousedown",this._onMouseDown,this)},moved:function(){return this._moved},_destroy:function(){oe(this._pane),delete this._pane},_resetState:function(){this._resetStateTimeout=0,this._moved=!1},_clearDeferredResetState:function(){0!==this._resetStateTimeout&&(clearTimeout(this._resetStateTimeout),this._resetStateTimeout=0)},_onMouseDown:function(t){if(!t.shiftKey||1!==t.which&&1!==t.button)return!1;this._clearDeferredResetState(),this._resetState(),Vt(),xe(),this._startPoint=this._map.mouseEventToContainerPoint(t),Ae(document,{contextmenu:ze,mousemove:this._onMouseMove,mouseup:this._onMouseUp,keydown:this._onKeyDown},this)},_onMouseMove:function(t){this._moved||(this._moved=!0,this._box=se("div","leaflet-zoom-box",this._container),de(this._container,"leaflet-crosshair"),this._map.fire("boxzoomstart")),this._point=this._map.mouseEventToContainerPoint(t);var e=new R(this._point,this._startPoint),i=e.getSize();me(this._box,e.min),this._box.style.width=i.x+"px",this._box.style.height=i.y+"px"},_finish:function(){this._moved&&(oe(this._box),ue(this._container,"leaflet-crosshair")),Yt(),be(),Me(document,{contextmenu:ze,mousemove:this._onMouseMove,mouseup:this._onMouseUp,keydown:this._onKeyDown},this)},_onMouseUp:function(t){if((1===t.which||1===t.button)&&(this._finish(),this._moved)){this._clearDeferredResetState(),this._resetStateTimeout=setTimeout(n(this._resetState,this),0);var e=new k(this._map.containerPointToLatLng(this._startPoint),this._map.containerPointToLatLng(this._point));this._map.fitBounds(e).fire("boxzoomend",{boxZoomBounds:e})}},_onKeyDown:function(t){27===t.keyCode&&(this._finish(),this._clearDeferredResetState(),this._resetState())}});Xe.addInitHook("addHandler","boxZoom",mn),Xe.mergeOptions({doubleClickZoom:!0});var vn=Je.extend({addHooks:function(){this._map.on("dblclick",this._onDoubleClick,this)},removeHooks:function(){this._map.off("dblclick",this._onDoubleClick,this)},_onDoubleClick:function(t){var e=this._map,i=e.getZoom(),n=e.options.zoomDelta,s=t.originalEvent.shiftKey?i-n:i+n;"center"===e.options.doubleClickZoom?e.setZoom(s):e.setZoomAround(t.containerPoint,s)}});Xe.addInitHook("addHandler","doubleClickZoom",vn),Xe.mergeOptions({dragging:!0,inertia:!0,inertiaDeceleration:3400,inertiaMaxSpeed:1/0,easeLinearity:.2,worldCopyJump:!1,maxBoundsViscosity:0});var yn=Je.extend({addHooks:function(){if(!this._draggable){var t=this._map;this._draggable=new ii(t._mapPane,t._container),this._draggable.on({dragstart:this._onDragStart,drag:this._onDrag,dragend:this._onDragEnd},this),this._draggable.on("predrag",this._onPreDragLimit,this),t.options.worldCopyJump&&(this._draggable.on("predrag",this._onPreDragWrap,this),t.on("zoomend",this._onZoomEnd,this),t.whenReady(this._onZoomEnd,this))}de(this._map._container,"leaflet-grab leaflet-touch-drag"),this._draggable.enable(),this._positions=[],this._times=[]},removeHooks:function(){ue(this._map._container,"leaflet-grab"),ue(this._map._container,"leaflet-touch-drag"),this._draggable.disable()},moved:function(){return this._draggable&&this._draggable._moved},moving:function(){return this._draggable&&this._draggable._moving},_onDragStart:function(){var t=this._map;if(t._stop(),this._map.options.maxBounds&&this._map.options.maxBoundsViscosity){var e=B(this._map.options.maxBounds);this._offsetLimit=O(this._map.latLngToContainerPoint(e.getNorthWest()).multiplyBy(-1),this._map.latLngToContainerPoint(e.getSouthEast()).multiplyBy(-1).add(this._map.getSize())),this._viscosity=Math.min(1,Math.max(0,this._map.options.maxBoundsViscosity))}else this._offsetLimit=null;t.fire("movestart").fire("dragstart"),t.options.inertia&&(this._positions=[],this._times=[])},_onDrag:function(t){if(this._map.options.inertia){var e=this._lastTime=+new Date,i=this._lastPos=this._draggable._absPos||this._draggable._newPos;this._positions.push(i),this._times.push(e),this._prunePositions(e)}this._map.fire("move",t).fire("drag",t)},_prunePositions:function(t){for(;this._positions.length>1&&t-this._times[0]>50;)this._positions.shift(),this._times.shift()},_onZoomEnd:function(){var t=this._map.getSize().divideBy(2),e=this._map.latLngToLayerPoint([0,0]);this._initialWorldOffset=e.subtract(t).x,this._worldWidth=this._map.getPixelWorldBounds().getSize().x},_viscousLimit:function(t,e){return t-(t-e)*this._viscosity},_onPreDragLimit:function(){if(this._viscosity&&this._offsetLimit){var t=this._draggable._newPos.subtract(this._draggable._startPos),e=this._offsetLimit;t.xe.max.x&&(t.x=this._viscousLimit(t.x,e.max.x)),t.y>e.max.y&&(t.y=this._viscousLimit(t.y,e.max.y)),this._draggable._newPos=this._draggable._startPos.add(t)}},_onPreDragWrap:function(){var t=this._worldWidth,e=Math.round(t/2),i=this._initialWorldOffset,n=this._draggable._newPos.x,s=(n-e+i)%t+e-i,o=(n+e+i)%t-e-i,r=Math.abs(s+i)0?o:-o))-e;this._delta=0,this._startTime=null,r&&("center"===t.options.scrollWheelZoom?t.setZoom(e+r):t.setZoomAround(this._lastMousePos,e+r))}});Xe.addInitHook("addHandler","scrollWheelZoom",bn);Xe.mergeOptions({tapHold:Rt.touchNative&&Rt.safari&&Rt.mobile,tapTolerance:15});var Sn=Je.extend({addHooks:function(){Ae(this._map._container,"touchstart",this._onDown,this)},removeHooks:function(){Me(this._map._container,"touchstart",this._onDown,this)},_onDown:function(t){if(clearTimeout(this._holdTimeout),1===t.touches.length){var e=t.touches[0];this._startPos=this._newPos=new N(e.clientX,e.clientY),this._holdTimeout=setTimeout(n(function(){this._cancel(),this._isTapValid()&&(Ae(document,"touchend",Be),Ae(document,"touchend touchcancel",this._cancelClickPrevent),this._simulateEvent("contextmenu",e))},this),600),Ae(document,"touchend touchcancel contextmenu",this._cancel,this),Ae(document,"touchmove",this._onMove,this)}},_cancelClickPrevent:function t(){Me(document,"touchend",Be),Me(document,"touchend touchcancel",t)},_cancel:function(){clearTimeout(this._holdTimeout),Me(document,"touchend touchcancel contextmenu",this._cancel,this),Me(document,"touchmove",this._onMove,this)},_onMove:function(t){var e=t.touches[0];this._newPos=new N(e.clientX,e.clientY)},_isTapValid:function(){return this._newPos.distanceTo(this._startPos)<=this._map.options.tapTolerance},_simulateEvent:function(t,e){var i=new MouseEvent(t,{bubbles:!0,cancelable:!0,view:window,screenX:e.screenX,screenY:e.screenY,clientX:e.clientX,clientY:e.clientY});i._simulated=!0,e.target.dispatchEvent(i)}});Xe.addInitHook("addHandler","tapHold",Sn),Xe.mergeOptions({touchZoom:Rt.touch,bounceAtZoomLimits:!0});var wn=Je.extend({addHooks:function(){de(this._map._container,"leaflet-touch-zoom"),Ae(this._map._container,"touchstart",this._onTouchStart,this)},removeHooks:function(){ue(this._map._container,"leaflet-touch-zoom"),Me(this._map._container,"touchstart",this._onTouchStart,this)},_onTouchStart:function(t){var e=this._map;if(t.touches&&2===t.touches.length&&!e._animatingZoom&&!this._zooming){var i=e.mouseEventToContainerPoint(t.touches[0]),n=e.mouseEventToContainerPoint(t.touches[1]);this._centerPoint=e.getSize()._divideBy(2),this._startLatLng=e.containerPointToLatLng(this._centerPoint),"center"!==e.options.touchZoom&&(this._pinchStartLatLng=e.containerPointToLatLng(i.add(n)._divideBy(2))),this._startDist=i.distanceTo(n),this._startZoom=e.getZoom(),this._moved=!1,this._zooming=!0,e._stop(),Ae(document,"touchmove",this._onTouchMove,this),Ae(document,"touchend touchcancel",this._onTouchEnd,this),Be(t)}},_onTouchMove:function(t){if(t.touches&&2===t.touches.length&&this._zooming){var e=this._map,i=e.mouseEventToContainerPoint(t.touches[0]),s=e.mouseEventToContainerPoint(t.touches[1]),o=i.distanceTo(s)/this._startDist;if(this._zoom=e.getScaleZoom(o,this._startZoom),!e.options.bounceAtZoomLimits&&(this._zoome.getMaxZoom()&&o>1)&&(this._zoom=e._limitZoom(this._zoom)),"center"===e.options.touchZoom){if(this._center=this._startLatLng,1===o)return}else{var r=i._add(s)._divideBy(2)._subtract(this._centerPoint);if(1===o&&0===r.x&&0===r.y)return;this._center=e.unproject(e.project(this._pinchStartLatLng,this._zoom).subtract(r),this._zoom)}this._moved||(e._moveStart(!0,!1),this._moved=!0),E(this._animRequest);var a=n(e._move,e,this._center,this._zoom,{pinch:!0,round:!1},void 0);this._animRequest=T(a,this,!0),Be(t)}},_onTouchEnd:function(){this._moved&&this._zooming?(this._zooming=!1,E(this._animRequest),Me(document,"touchmove",this._onTouchMove,this),Me(document,"touchend touchcancel",this._onTouchEnd,this),this._map.options.zoomAnimation?this._map._animateZoom(this._center,this._map._limitZoom(this._zoom),!0,this._map.options.zoomSnap):this._map._resetView(this._center,this._map._limitZoom(this._zoom))):this._zooming=!1}});Xe.addInitHook("addHandler","touchZoom",wn),Xe.BoxZoom=mn,Xe.DoubleClickZoom=vn,Xe.Drag=yn,Xe.Keyboard=xn,Xe.ScrollWheelZoom=bn,Xe.TapHold=Sn,Xe.TouchZoom=wn,t.Bounds=R,t.Browser=Rt,t.CRS=j,t.Canvas=ln,t.Circle=Oi,t.CircleMarker=Ri,t.Class=A,t.Control=qe,t.DivIcon=nn,t.DivOverlay=Ji,t.DomEvent=Ze,t.DomUtil=Pe,t.Draggable=ii,t.Evented=M,t.FeatureGroup=Ci,t.GeoJSON=zi,t.GridLayer=sn,t.Handler=Je,t.Icon=Mi,t.ImageOverlay=$i,t.LatLng=z,t.LatLngBounds=k,t.Layer=Pi,t.LayerGroup=Ai,t.LineUtil=yi,t.Map=Xe,t.Marker=Ii,t.Mixin=ti,t.Path=Li,t.Point=N,t.PolyUtil=ai,t.Polygon=Bi,t.Polyline=ki,t.Popup=tn,t.PosAnimation=He,t.Projection=Si,t.Rectangle=pn,t.Renderer=hn,t.SVG=fn,t.SVGOverlay=Qi,t.TileLayer=on,t.Tooltip=en,t.Transformation=H,t.Util=P,t.VideoOverlay=Ki,t.bind=n,t.bounds=O,t.canvas=dn,t.circle=function(t,e,i){return new Oi(t,e,i)},t.circleMarker=function(t,e){return new Ri(t,e)},t.control=Ve,t.divIcon=function(t){return new nn(t)},t.extend=e,t.featureGroup=function(t,e){return new Ci(t,e)},t.geoJSON=Vi,t.geoJson=Yi,t.gridLayer=function(t){return new sn(t)},t.icon=function(t){return new Mi(t)},t.imageOverlay=function(t,e,i){return new $i(t,e,i)},t.latLng=U,t.latLngBounds=B,t.layerGroup=function(t,e){return new Ai(t,e)},t.map=function(t,e){return new Xe(t,e)},t.marker=function(t,e){return new Ii(t,e)},t.point=I,t.polygon=function(t,e){return new Bi(t,e)},t.polyline=function(t,e){return new ki(t,e)},t.popup=function(t,e){return new tn(t,e)},t.rectangle=function(t,e){return new pn(t,e)},t.setOptions=c,t.stamp=o,t.svg=gn,t.svgOverlay=function(t,e,i){return new Qi(t,e,i)},t.tileLayer=rn,t.tooltip=function(t,e){return new en(t,e)},t.transformation=X,t.version="1.9.4",t.videoOverlay=function(t,e,i){return new Ki(t,e,i)};var Tn=window.L;t.noConflict=function(){return window.L=Tn,this},window.L=t}(e)}};const e={};function i(n){const s=e[n];if(void 0!==s)return s.exports;const o=e[n]={exports:{}};return t[n].call(o.exports,o,o.exports,i),o.exports}i.d=(t,e)=>{if(Array.isArray(e))for(var n=0;nObject.prototype.hasOwnProperty.call(t,e),i.r=t=>{Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};let n={};return(()=>{"use strict";i.r(n),i.d(n,{Color:()=>F,EdgeLineStyleType:()=>N,EdgeType:()=>D,GraphObjectState:()=>r,NodeShapeType:()=>w,OrbError:()=>o,OrbEventType:()=>e,OrbMapView:()=>cr,OrbView:()=>dr,RectangleArea:()=>V,RendererType:()=>zs,getDefaultGraphStyle:()=>X,graphToSVG:()=>Jo,isEdge:()=>L,isNode:()=>E});class t{constructor(){this._listeners=new Map}once(t,e){const i={callable:e,isOnce:!0},n=this._listeners.get(t);return n?n.push(i):this._listeners.set(t,[i]),this}on(t,e){const i={callable:e},n=this._listeners.get(t);return n?n.push(i):this._listeners.set(t,[i]),this}off(t,e){const i=this._listeners.get(t);if(i){const n=i.filter(t=>t.callable!==e);this._listeners.set(t,n)}return this}emit(t,e){const i=this._listeners.get(t);if(!i||0===i.length)return!1;let n=!1;for(let t=0;t!t.isOnce);this._listeners.set(t,e)}return!0}eventNames(){return[...this._listeners.keys()]}listenerCount(t){const e=this._listeners.get(t);return e?e.length:0}listeners(t){const e=this._listeners.get(t);return e?e.map(t=>t.callable):[]}addListener(t,e){return this.on(t,e)}removeListener(t,e){return this.off(t,e)}removeAllListeners(t){return t?this._listeners.delete(t):this._listeners.clear(),this}}var e;!function(t){t.RENDER_START="render-start",t.RENDER_END="render-end",t.SIMULATION_START="simulation-start",t.SIMULATION_STEP="simulation-step",t.SIMULATION_END="simulation-end",t.NODE_CLICK="node-click",t.NODE_HOVER="node-hover",t.EDGE_CLICK="edge-click",t.EDGE_HOVER="edge-hover",t.MOUSE_CLICK="mouse-click",t.MOUSE_MOVE="mouse-move",t.TRANSFORM="transform",t.NODE_DRAG_START="node-drag-start",t.NODE_DRAG="node-drag",t.NODE_DRAG_END="node-drag-end",t.BACKGROUND_DRAG_START="background-drag-start",t.BACKGROUND_DRAG="background-drag",t.BACKGROUND_DRAG_END="background-drag-end",t.NODE_RIGHT_CLICK="node-right-click",t.EDGE_RIGHT_CLICK="edge-right-click",t.MOUSE_RIGHT_CLICK="mouse-right-click",t.NODE_DOUBLE_CLICK="node-double-click",t.EDGE_DOUBLE_CLICK="edge-double-click",t.MOUSE_DOUBLE_CLICK="mouse-double-click"}(e||(e={}));class s extends t{}class o extends Error{constructor(t){super(t),this.message=t,Object.setPrototypeOf(this,new.target.prototype),this.name=this.constructor.name}}const r={NONE:0,SELECTED:1,HOVERED:2},a=(t,e)=>{const i=t.x+t.width,n=t.y+t.height;return e.x>=t.x&&e.x<=i&&e.y>=t.y&&e.y<=n};class h{constructor(){this._imageByUrl={}}static getInstance(){return h._instance||(h._instance=new h),h._instance}getImage(t){return this._imageByUrl[t]}loadImage(t,e){const i=this.getImage(t);if(i)return i;const n=new Image;return this._imageByUrl[t]=n,n.onload=()=>{l(n),null==e||e()},n.onerror=()=>{null==e||e(new Error(`Image ${t} failed to load.`))},n.src=t,n}loadImages(t,e){const i=[],n=new Set(t),s=t=>{n.delete(t),0===n.size&&(null==e||e())};for(let e=0;e{l(a),s(o)},a.onerror=()=>{s(o)},a.src=o,i.push(a)}return i}}const l=t=>t&&0===t.width?(document.body.appendChild(t),t.width=t.offsetWidth,t.height=t.offsetHeight,document.body.removeChild(t),t):t;class d{constructor(){this.listeners=[]}addListener(t){this.listeners.push(t)}getListeners(){return[...this.listeners]}removeListener(t){const e=this.listeners.indexOf(t);-1!==e&&this.listeners.splice(e,1)}notifyListeners(t){for(let e=0;e"number"==typeof t,c=t=>"boolean"==typeof t,_=t=>t instanceof Date,f=t=>Array.isArray(t),g=t=>null!==t&&"object"==typeof t&&"Object"===t.constructor.name,p=t=>"function"==typeof t,m=t=>_(t)?y(t):f(t)?x(t):g(t)?b(t):t,v=(t,e)=>{const i=_(t),n=_(e);if(i&&!n||!i&&n)return!1;if(i&&n)return t.getTime()===e.getTime();const s=f(t),o=f(e);if(s&&!o||!s&&o)return!1;if(s&&o)return t.length===e.length&&t.every((t,i)=>v(t,e[i]));const r=g(t),a=g(e);if(r&&!a||!r&&a)return!1;if(r&&a){const i=Object.keys(t),n=Object.keys(e);return!!v(i,n)&&i.every(i=>v(t[i],e[i]))}return t===e},y=t=>new Date(t),x=t=>t.map(t=>m(t)),b=t=>{const e={};return Object.keys(t).forEach(i=>{e[i]=m(t[i])}),e},S=(t,e)=>{const i=Object.keys(e);for(let n=0;nt instanceof P;class P extends d{constructor(t,e){super(),this._style={},this._state=r.NONE,this._inEdgesById={},this._outEdgesById={},this.id=t.data.id,this._data=t.data,this._position={id:this.id},this._onLoadedImage=null==e?void 0:e.onLoadedImage,this._onStateChange=null==e?void 0:e.onStateChange,e&&e.listeners&&(this.listeners=e.listeners)}getId(){return this.id}getData(){return this._data}getPosition(){return this._position}getStyle(){return this._style}getState(){return this._state}clearPosition(){this._position.x=void 0,this._position.y=void 0,this.notifyListeners()}getCenter(){return void 0===this._position.x||void 0===this._position.y?{x:0,y:0}:{x:this._position.x,y:this._position.y}}getRadius(){var t;return null!==(t=this._style.size)&&void 0!==t?t:0}getBorderedRadius(){return this.getRadius()+this.getBorderWidth()/2}getBoundingBox(){const t=this.getCenter(),e=this.getBorderedRadius();return{x:t.x-e,y:t.y-e,width:2*e,height:2*e}}getInEdges(){return Object.values(this._inEdgesById)}getOutEdges(){return Object.values(this._outEdgesById)}getEdges(){const t={},e=this.getOutEdges();for(let i=0;i0}addEdge(t){t.start===this.id&&(this._outEdgesById[t.getId()]=t),t.end===this.id&&(this._inEdgesById[t.getId()]=t)}removeEdge(t){delete this._outEdgesById[t.getId()],delete this._inEdgesById[t.getId()]}isSelected(){return this._state===r.SELECTED}isHovered(){return this._state===r.HOVERED}clearState(){this.setState(r.NONE,{isNotifySkipped:!0})}getDistanceToBorder(){return this.getBorderedRadius()}includesPoint(t){const e=this._isPointInBoundingBox(t);if(!e)return!1;if(this._style.shape===w.SQUARE)return e;const i=this.getCenter(),n=this.getBorderedRadius(),s=t.x-i.x,o=t.y-i.y;return Math.sqrt(s*s+o*o)<=n}hasShadow(){var t,e,i;return(null!==(t=this._style.shadowSize)&&void 0!==t?t:0)>0||(null!==(e=this._style.shadowOffsetX)&&void 0!==e?e:0)>0||(null!==(i=this._style.shadowOffsetY)&&void 0!==i?i:0)>0}hasBorder(){var t,e;const i=(null!==(t=this._style.borderWidth)&&void 0!==t?t:0)>0,n=(null!==(e=this._style.borderWidthSelected)&&void 0!==e?e:0)>0;return i||this.isSelected()&&n}getLabel(){return this._style.label}getColor(){let t;return this._style.color&&(t=this._style.color),this.isHovered()&&this._style.colorHover&&(t=this._style.colorHover),this.isSelected()&&this._style.colorSelected&&(t=this._style.colorSelected),t}getBorderWidth(){let t=0;return this._style.borderWidth&&this._style.borderWidth>0&&(t=this._style.borderWidth),this.isSelected()&&this._style.borderWidthSelected&&this._style.borderWidthSelected>0&&(t=this._style.borderWidthSelected),t}getBorderColor(){if(!this.hasBorder())return;let t;return this._style.borderColor&&(t=this._style.borderColor),this.isHovered()&&this._style.borderColorHover&&(t=this._style.borderColorHover),this.isSelected()&&this._style.borderColorSelected&&(t=this._style.borderColorSelected.toString()),t}getBackgroundImage(){var t;if((null!==(t=this._style.size)&&void 0!==t?t:0)<=0)return;let e;if(this._style.imageUrl&&(e=this._style.imageUrl),this.isSelected()&&this._style.imageUrlSelected&&(e=this._style.imageUrlSelected),!e)return;return h.getInstance().getImage(e)||h.getInstance().loadImage(e,t=>{var e;t||null===(e=this._onLoadedImage)||void 0===e||e.call(this)})}setData(t){p(t)?this._data=t(this):this._data=t,this.notifyListeners()}patchData(t){let e;e=p(t)?t(this):t,S(this._data,e),this.notifyListeners()}setPosition(t,e){let i;i=p(t)?t(this):t,"x"in i&&"y"in i&&(this._position.x=i.x,this._position.y=i.y,"id"in i&&(this._position.id=i.id)),(null==e?void 0:e.isNotifySkipped)||this.notifyListeners(Object.assign({id:this.id},i))}setStyle(t,e){p(t)?this._style=t(this):this._style=t,(null==e?void 0:e.isNotifySkipped)||this.notifyListeners()}patchStyle(t,e){let i;i=p(t)?t(this):t,S(this._style,i),(null==e?void 0:e.isNotifySkipped)||this.notifyListeners()}setState(t,e){var i;const n=this._state;let s;if(s=p(t)?t(this):t,u(s))this._state=s;else if(g(s)){const t=s.options;if(this._state=this._handleState(s.state,t),t)return void this.notifyListeners({id:this.id,type:"node",options:t})}(null==e?void 0:e.isNotifySkipped)?this._state!==n&&(null===(i=this._onStateChange)||void 0===i||i.call(this)):this.notifyListeners()}_isPointInBoundingBox(t){return a(this.getBoundingBox(),t)}_handleState(t,e){return(null==e?void 0:e.isToggle)&&this._state===t?r.NONE:t}}const A=(t,e,i)=>{const n=e.x-t.x,s=e.y-t.y;let o=((i.x-t.x)*n+(i.y-t.y)*s)/(n*n+s*s);o>1&&(o=1),o<0&&(o=0);const r=t.x+o*n,a=t.y+o*s,h=r-i.x,l=a-i.y;return Math.sqrt(h*h+l*l)},C=[5,5],M=[1,1];var N,D;!function(t){t.SOLID="solid",t.DASHED="dashed",t.DOTTED="dotted",t.CUSTOM="custom"}(N||(N={})),function(t){t.STRAIGHT="straight",t.LOOPBACK="loopback",t.CURVED="curved"}(D||(D={}));class I{static create(t,e){switch(O(t)){case D.STRAIGHT:return new k(t,e);case D.LOOPBACK:return new z(t,e);case D.CURVED:return new B(t,e);default:return new k(t,e)}}static copy(t,e){const i=I.create({data:t.getData(),offset:void 0!==(null==e?void 0:e.offset)?e.offset:t.offset,startNode:t.startNode,endNode:t.endNode},{listeners:[],onStateChange:t.getOnStateChange()});i.setState(t.getState()),i.setStyle(t.getStyle());const n=t.getListeners();for(let t=0;tt instanceof k||t instanceof B||t instanceof z;class R extends d{constructor(t,e){var i;super(),this._style={},this._state=r.NONE,this._type=D.STRAIGHT,this.id=t.data.id,this._data=t.data,this.offset=null!==(i=t.offset)&&void 0!==i?i:0,this.startNode=t.startNode,this.endNode=t.endNode,this._type=O(t),this._position={id:this.id,source:this.startNode.getId(),target:this.endNode.getId()},this.startNode.addEdge(this),this.endNode.addEdge(this),this._onStateChange=null==e?void 0:e.onStateChange,e&&e.listeners&&(this.listeners=e.listeners)}getId(){return this.id}getData(){return this._data}getPosition(){return this._position}getStyle(){return this._style}getState(){return this._state}getOnStateChange(){return this._onStateChange}get type(){return this._type}get start(){return this._data.start}get end(){return this._data.end}hasStyle(){return this._style&&Object.keys(this._style).length>0}isSelected(){return this._state===r.SELECTED}isHovered(){return this._state===r.HOVERED}clearState(){var t;this._state!==r.NONE&&(this._state=r.NONE,null===(t=this._onStateChange)||void 0===t||t.call(this))}isLoopback(){return this._type===D.LOOPBACK}isStraight(){return this._type===D.STRAIGHT}isCurved(){return this._type===D.CURVED}getCenter(){var t,e;const i=null===(t=this.startNode)||void 0===t?void 0:t.getCenter(),n=null===(e=this.endNode)||void 0===e?void 0:e.getCenter();return i&&n?{x:(i.x+n.x)/2,y:(i.y+n.y)/2}:{x:0,y:0}}getDistance(t){const e=this.startNode.getCenter(),i=this.endNode.getCenter();return e&&i?A(e,i,t):0}getLabel(){return this._style.label}hasShadow(){var t,e,i;return(null!==(t=this._style.shadowSize)&&void 0!==t?t:0)>0||(null!==(e=this._style.shadowOffsetX)&&void 0!==e?e:0)>0||(null!==(i=this._style.shadowOffsetY)&&void 0!==i?i:0)>0}getWidth(){let t=0;return void 0!==this._style.width&&(t=this._style.width),this.isHovered()&&void 0!==this._style.widthHover&&(t=this._style.widthHover),this.isSelected()&&void 0!==this._style.widthSelected&&(t=this._style.widthSelected),t}getColor(){let t;return this._style.color&&(t=this._style.color),this.isHovered()&&this._style.colorHover&&(t=this._style.colorHover),this.isSelected()&&this._style.colorSelected&&(t=this._style.colorSelected),t}getLineDashPattern(){const t=this._style.lineStyle;if(void 0===t||t.type===N.SOLID)return null;switch(t.type){case N.DASHED:return C;case N.DOTTED:return M;case N.CUSTOM:return e=t.pattern,f(e)&&e.every(t=>u(t))?t.pattern:null;default:return null}var e}setData(t){p(t)?this._data=t(this):this._data=t,this.notifyListeners()}patchData(t){let e;e=p(t)?t(this):t,S(this._data,e),this.notifyListeners()}setStyle(t,e){p(t)?this._style=t(this):this._style=t,(null==e?void 0:e.isNotifySkipped)||this.notifyListeners()}patchStyle(t,e){let i;i=p(t)?t(this):t,S(this._style,i),(null==e?void 0:e.isNotifySkipped)||this.notifyListeners()}setState(t,e){var i;const n=this._state;let s;if(s=p(t)?t(this):t,u(s))this._state=s;else if(g(s)){const t=s.options;if(this._state=this._handleState(s.state,t),t)return void this.notifyListeners({id:this.id,type:"edge",options:t})}(null==e?void 0:e.isNotifySkipped)?this._state!==n&&(null===(i=this._onStateChange)||void 0===i||i.call(this)):this.notifyListeners()}_handleState(t,e){return(null==e?void 0:e.isToggle)&&this._state===t?r.NONE:t}}const O=t=>{var e;return t.startNode.getId()===t.endNode.getId()?D.LOOPBACK:0===(null!==(e=t.offset)&&void 0!==e?e:0)?D.STRAIGHT:D.CURVED};class k extends R{getCenter(){var t,e;const i=null===(t=this.startNode)||void 0===t?void 0:t.getCenter(),n=null===(e=this.endNode)||void 0===e?void 0:e.getCenter();return i&&n?{x:(i.x+n.x)/2,y:(i.y+n.y)/2}:{x:0,y:0}}getDistance(t){var e,i;const n=null===(e=this.startNode)||void 0===e?void 0:e.getCenter(),s=null===(i=this.endNode)||void 0===i?void 0:i.getCenter();return n&&s?A(n,s,t):0}}class B extends R{getCenter(){return this.getCurvedControlPoint(2)}getDistance(t){var e,i;const n=null===(e=this.startNode)||void 0===e?void 0:e.getCenter(),s=null===(i=this.endNode)||void 0===i?void 0:i.getCenter();if(!n||!s)return 0;const o=this.getCurvedControlPoint();let r,a,h,l,d,u=1e9,c=n.x,_=n.y;for(a=1;a<10;a++)h=.1*a,l=Math.pow(1-h,2)*n.x+2*h*(1-h)*o.x+Math.pow(h,2)*s.x,d=Math.pow(1-h,2)*n.y+2*h*(1-h)*o.y+Math.pow(h,2)*s.y,a>0&&(r=A({x:c,y:_},{x:l,y:d},t),u=r({r:parseInt(t.substring(1,3),16),g:parseInt(t.substring(3,5),16),b:parseInt(t.substring(5,7),16)}),W=t=>"#"+((1<<24)+(t.r<<16)+(t.g<<8)+t.b).toString(16).slice(1),G=["label","name"],Z={size:5,color:new F("#1d87c9")},H={color:new F("#ababab"),width:.3},X=()=>({getNodeStyle:t=>Object.assign(Object.assign({},Z),{label:q(t)}),getEdgeStyle:t=>Object.assign(Object.assign({},H),{label:q(t)})}),q=t=>{const e=t.getData();for(let t=0;t({x:Math.min(t.x,e.x),y:Math.min(t.y,e.y),width:Math.abs(t.x-e.x),height:Math.abs(t.y-e.y)}))(t,e))}contains(t){return a(this._rectangle,t)}getBoundingBox(){return this._rectangle}}var Y={value:()=>{}};function $(){for(var t,e=0,i=arguments.length,n={};e=0&&(e=t.slice(i+1),t=t.slice(0,i)),t&&!n.hasOwnProperty(t))throw new Error("unknown type: "+t);return{type:t,name:e}})),r=-1,a=o.length;if(!(arguments.length<2)){if(null!=e&&"function"!=typeof e)throw new Error("invalid callback: "+e);for(;++r0)for(var i,n,s=new Array(i),o=0;oe?1:t>=e?0:NaN}ct.prototype={constructor:ct,appendChild:function(t){return this._parent.insertBefore(t,this._next)},insertBefore:function(t,e){return this._parent.insertBefore(t,e)},querySelector:function(t){return this._parent.querySelector(t)},querySelectorAll:function(t){return this._parent.querySelectorAll(t)}};var vt="http://www.w3.org/1999/xhtml";const yt={svg:"http://www.w3.org/2000/svg",xhtml:vt,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function xt(t){var e=t+="",i=e.indexOf(":");return i>=0&&"xmlns"!==(e=t.slice(0,i))&&(t=t.slice(i+1)),yt.hasOwnProperty(e)?{space:yt[e],local:t}:t}function bt(t){return function(){this.removeAttribute(t)}}function St(t){return function(){this.removeAttributeNS(t.space,t.local)}}function wt(t,e){return function(){this.setAttribute(t,e)}}function Tt(t,e){return function(){this.setAttributeNS(t.space,t.local,e)}}function Et(t,e){return function(){var i=e.apply(this,arguments);null==i?this.removeAttribute(t):this.setAttribute(t,i)}}function Pt(t,e){return function(){var i=e.apply(this,arguments);null==i?this.removeAttributeNS(t.space,t.local):this.setAttributeNS(t.space,t.local,i)}}function At(t){return t.ownerDocument&&t.ownerDocument.defaultView||t.document&&t||t.defaultView}function Ct(t){return function(){this.style.removeProperty(t)}}function Mt(t,e,i){return function(){this.style.setProperty(t,e,i)}}function Nt(t,e,i){return function(){var n=e.apply(this,arguments);null==n?this.style.removeProperty(t):this.style.setProperty(t,n,i)}}function Dt(t,e){return t.style.getPropertyValue(e)||At(t).getComputedStyle(t,null).getPropertyValue(e)}function It(t){return function(){delete this[t]}}function Lt(t,e){return function(){this[t]=e}}function Rt(t,e){return function(){var i=e.apply(this,arguments);null==i?delete this[t]:this[t]=i}}function Ot(t){return t.trim().split(/^|\s+/)}function kt(t){return t.classList||new Bt(t)}function Bt(t){this._node=t,this._names=Ot(t.getAttribute("class")||"")}function zt(t,e){for(var i=kt(t),n=-1,s=e.length;++n=0&&(this._names.splice(e,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(t){return this._names.indexOf(t)>=0}};var le=[null];function de(t,e){this._groups=t,this._parents=e}function ue(){return new de([[document.documentElement]],le)}de.prototype=ue.prototype={constructor:de,select:function(t){"function"!=typeof t&&(t=it(t));for(var e=this._groups,i=e.length,n=new Array(i),s=0;s=x&&(x=y+1);!(v=p[x])&&++x=0;)(n=s[o])&&(r&&4^n.compareDocumentPosition(r)&&r.parentNode.insertBefore(n,r),r=n);return this},sort:function(t){function e(e,i){return e&&i?t(e.__data__,i.__data__):!e-!i}t||(t=mt);for(var i=this._groups,n=i.length,s=new Array(n),o=0;o1?this.each((null==e?Ct:"function"==typeof e?Nt:Mt)(t,e,i??"")):Dt(this.node(),t)},property:function(t,e){return arguments.length>1?this.each((null==e?It:"function"==typeof e?Rt:Lt)(t,e)):this.node()[t]},classed:function(t,e){var i=Ot(t+"");if(arguments.length<2){for(var n=kt(this.node()),s=-1,o=i.length;++s=0&&(e=t.slice(i+1),t=t.slice(0,i)),{type:t,name:e}})}(t+""),r=o.length;if(!(arguments.length<2)){for(a=e?oe:se,n=0;n()=>t;function Se(t,{sourceEvent:e,subject:i,target:n,identifier:s,active:o,x:r,y:a,dx:h,dy:l,dispatch:d}){Object.defineProperties(this,{type:{value:t,enumerable:!0,configurable:!0},sourceEvent:{value:e,enumerable:!0,configurable:!0},subject:{value:i,enumerable:!0,configurable:!0},target:{value:n,enumerable:!0,configurable:!0},identifier:{value:s,enumerable:!0,configurable:!0},active:{value:o,enumerable:!0,configurable:!0},x:{value:r,enumerable:!0,configurable:!0},y:{value:a,enumerable:!0,configurable:!0},dx:{value:h,enumerable:!0,configurable:!0},dy:{value:l,enumerable:!0,configurable:!0},_:{value:d}})}function we(t){return!t.ctrlKey&&!t.button}function Te(){return this.parentNode}function Ee(t,e){return e??{x:t.x,y:t.y}}function Pe(){return navigator.maxTouchPoints||"ontouchstart"in this}Se.prototype.on=function(){var t=this._.on.apply(this._,arguments);return t===this._?this:t};const Ae=t=>+t;function Ce(t){return((t=Math.exp(t))+1/t)/2}const Me=function t(e,i,n){function s(t,s){var o,r,a=t[0],h=t[1],l=t[2],d=s[0],u=s[1],c=s[2],_=d-a,f=u-h,g=_*_+f*f;if(g<1e-12)r=Math.log(c/l)/e,o=function(t){return[a+t*_,h+t*f,l*Math.exp(e*t*r)]};else{var p=Math.sqrt(g),m=(c*c-l*l+n*g)/(2*l*i*p),v=(c*c-l*l-n*g)/(2*c*i*p),y=Math.log(Math.sqrt(m*m+1)-m),x=Math.log(Math.sqrt(v*v+1)-v);r=(x-y)/e,o=function(t){var n=t*r,s=Ce(y),o=l/(i*p)*(s*function(t){return((t=Math.exp(2*t))-1)/(t+1)}(e*n+y)-function(t){return((t=Math.exp(t))-1/t)/2}(y));return[a+o*_,h+o*f,l*s/Ce(e*n+y)]}}return o.duration=1e3*r*e/Math.SQRT2,o}return s.rho=function(e){var i=Math.max(.001,+e),n=i*i;return t(i,n,n*n)},s}(Math.SQRT2,2,4);var Ne,De,Ie=0,Le=0,Re=0,Oe=0,ke=0,Be=0,ze="object"==typeof performance&&performance.now?performance:Date,Ue="object"==typeof window&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(t){setTimeout(t,17)};function Fe(){return ke||(Ue(je),ke=ze.now()+Be)}function je(){ke=0}function We(){this._call=this._time=this._next=null}function Ge(t,e,i){var n=new We;return n.restart(t,e,i),n}function Ze(){ke=(Oe=ze.now())+Be,Ie=Le=0;try{!function(){Fe(),++Ie;for(var t,e=Ne;e;)(t=ke-e._time)>=0&&e._call.call(void 0,t),e=e._next;--Ie}()}finally{Ie=0,function(){for(var t,e,i=Ne,n=1/0;i;)i._call?(n>i._time&&(n=i._time),t=i,i=i._next):(e=i._next,i._next=null,i=t?t._next=e:Ne=e);De=t,Xe(n)}(),ke=0}}function He(){var t=ze.now(),e=t-Oe;e>1e3&&(Be-=e,Oe=t)}function Xe(t){Ie||(Le&&(Le=clearTimeout(Le)),t-ke>24?(t<1/0&&(Le=setTimeout(Ze,t-ze.now()-Be)),Re&&(Re=clearInterval(Re))):(Re||(Oe=ze.now(),Re=setInterval(He,1e3)),Ie=1,Ue(Ze)))}function qe(t,e,i){var n=new We;return e=null==e?0:+e,n.restart(i=>{n.stop(),t(i+e)},e,i),n}We.prototype=Ge.prototype={constructor:We,restart:function(t,e,i){if("function"!=typeof t)throw new TypeError("callback is not a function");i=(null==i?Fe():+i)+(null==e?0:+e),this._next||De===this||(De?De._next=this:Ne=this,De=this),this._call=t,this._time=i,Xe()},stop:function(){this._call&&(this._call=null,this._time=1/0,Xe())}};var Ve=tt("start","end","cancel","interrupt"),Ye=[];function $e(t,e,i,n,s,o){var r=t.__transition;if(r){if(i in r)return}else t.__transition={};!function(t,e,i){var n,s=t.__transition;function o(h){var l,d,u,c;if(1!==i.state)return a();for(l in s)if((c=s[l]).name===i.name){if(3===c.state)return qe(o);4===c.state?(c.state=6,c.timer.stop(),c.on.call("interrupt",t,t.__data__,c.index,c.group),delete s[l]):+l0)throw new Error("too late; already scheduled");return i}function Qe(t,e){var i=Je(t,e);if(i.state>3)throw new Error("too late; already running");return i}function Je(t,e){var i=t.__transition;if(!i||!(i=i[e]))throw new Error("transition not found");return i}function ti(t,e){var i,n,s,o=t.__transition,r=!0;if(o){for(s in e=null==e?null:e+"",o)(i=o[s]).name===e?(n=i.state>2&&i.state<5,i.state=6,i.timer.stop(),i.on.call(n?"interrupt":"cancel",t,t.__data__,i.index,i.group),delete o[s]):r=!1;r&&delete t.__transition}}function ei(t,e){return t=+t,e=+e,function(i){return t*(1-i)+e*i}}var ii,ni=180/Math.PI,si={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function oi(t,e,i,n,s,o){var r,a,h;return(r=Math.sqrt(t*t+e*e))&&(t/=r,e/=r),(h=t*i+e*n)&&(i-=t*h,n-=e*h),(a=Math.sqrt(i*i+n*n))&&(i/=a,n/=a,h/=a),t*n180?e+=360:e-t>180&&(t+=360),o.push({i:i.push(s(i)+"rotate(",null,n)-2,x:ei(t,e)})):e&&i.push(s(i)+"rotate("+e+n)}(o.rotate,r.rotate,a,h),function(t,e,i,o){t!==e?o.push({i:i.push(s(i)+"skewX(",null,n)-2,x:ei(t,e)}):e&&i.push(s(i)+"skewX("+e+n)}(o.skewX,r.skewX,a,h),function(t,e,i,n,o,r){if(t!==i||e!==n){var a=o.push(s(o)+"scale(",null,",",null,")");r.push({i:a-4,x:ei(t,i)},{i:a-2,x:ei(e,n)})}else 1===i&&1===n||o.push(s(o)+"scale("+i+","+n+")")}(o.scaleX,o.scaleY,r.scaleX,r.scaleY,a,h),o=r=null,function(t){for(var e,i=-1,n=h.length;++i>8&15|e>>4&240,e>>4&15|240&e,(15&e)<<4|15&e,1):8===i?Ii(e>>24&255,e>>16&255,e>>8&255,(255&e)/255):4===i?Ii(e>>12&15|e>>8&240,e>>8&15|e>>4&240,e>>4&15|240&e,((15&e)<<4|15&e)/255):null):(e=bi.exec(t))?new Ri(e[1],e[2],e[3],1):(e=Si.exec(t))?new Ri(255*e[1]/100,255*e[2]/100,255*e[3]/100,1):(e=wi.exec(t))?Ii(e[1],e[2],e[3],e[4]):(e=Ti.exec(t))?Ii(255*e[1]/100,255*e[2]/100,255*e[3]/100,e[4]):(e=Ei.exec(t))?Fi(e[1],e[2]/100,e[3]/100,1):(e=Pi.exec(t))?Fi(e[1],e[2]/100,e[3]/100,e[4]):Ai.hasOwnProperty(t)?Di(Ai[t]):"transparent"===t?new Ri(NaN,NaN,NaN,0):null}function Di(t){return new Ri(t>>16&255,t>>8&255,255&t,1)}function Ii(t,e,i,n){return n<=0&&(t=e=i=NaN),new Ri(t,e,i,n)}function Li(t,e,i,n){return 1===arguments.length?((s=t)instanceof fi||(s=Ni(s)),s?new Ri((s=s.rgb()).r,s.g,s.b,s.opacity):new Ri):new Ri(t,e,i,n??1);var s}function Ri(t,e,i,n){this.r=+t,this.g=+e,this.b=+i,this.opacity=+n}function Oi(){return`#${Ui(this.r)}${Ui(this.g)}${Ui(this.b)}`}function ki(){const t=Bi(this.opacity);return`${1===t?"rgb(":"rgba("}${zi(this.r)}, ${zi(this.g)}, ${zi(this.b)}${1===t?")":`, ${t})`}`}function Bi(t){return isNaN(t)?1:Math.max(0,Math.min(1,t))}function zi(t){return Math.max(0,Math.min(255,Math.round(t)||0))}function Ui(t){return((t=zi(t))<16?"0":"")+t.toString(16)}function Fi(t,e,i,n){return n<=0?t=e=i=NaN:i<=0||i>=1?t=e=NaN:e<=0&&(t=NaN),new Wi(t,e,i,n)}function ji(t){if(t instanceof Wi)return new Wi(t.h,t.s,t.l,t.opacity);if(t instanceof fi||(t=Ni(t)),!t)return new Wi;if(t instanceof Wi)return t;var e=(t=t.rgb()).r/255,i=t.g/255,n=t.b/255,s=Math.min(e,i,n),o=Math.max(e,i,n),r=NaN,a=o-s,h=(o+s)/2;return a?(r=e===o?(i-n)/a+6*(i0&&h<1?0:r,new Wi(r,a,h,t.opacity)}function Wi(t,e,i,n){this.h=+t,this.s=+e,this.l=+i,this.opacity=+n}function Gi(t){return(t=(t||0)%360)<0?t+360:t}function Zi(t){return Math.max(0,Math.min(1,t||0))}function Hi(t,e,i){return 255*(t<60?e+(i-e)*t/60:t<180?i:t<240?e+(i-e)*(240-t)/60:e)}function Xi(t,e,i,n,s){var o=t*t,r=o*t;return((1-3*t+3*o-r)*e+(4-6*o+3*r)*i+(1+3*t+3*o-3*r)*n+r*s)/6}ci(fi,Ni,{copy(t){return Object.assign(new this.constructor,this,t)},displayable(){return this.rgb().displayable()},hex:Ci,formatHex:Ci,formatHex8:function(){return this.rgb().formatHex8()},formatHsl:function(){return ji(this).formatHsl()},formatRgb:Mi,toString:Mi}),ci(Ri,Li,_i(fi,{brighter(t){return t=null==t?pi:Math.pow(pi,t),new Ri(this.r*t,this.g*t,this.b*t,this.opacity)},darker(t){return t=null==t?gi:Math.pow(gi,t),new Ri(this.r*t,this.g*t,this.b*t,this.opacity)},rgb(){return this},clamp(){return new Ri(zi(this.r),zi(this.g),zi(this.b),Bi(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:Oi,formatHex:Oi,formatHex8:function(){return`#${Ui(this.r)}${Ui(this.g)}${Ui(this.b)}${Ui(255*(isNaN(this.opacity)?1:this.opacity))}`},formatRgb:ki,toString:ki})),ci(Wi,function(t,e,i,n){return 1===arguments.length?ji(t):new Wi(t,e,i,n??1)},_i(fi,{brighter(t){return t=null==t?pi:Math.pow(pi,t),new Wi(this.h,this.s,this.l*t,this.opacity)},darker(t){return t=null==t?gi:Math.pow(gi,t),new Wi(this.h,this.s,this.l*t,this.opacity)},rgb(){var t=this.h%360+360*(this.h<0),e=isNaN(t)||isNaN(this.s)?0:this.s,i=this.l,n=i+(i<.5?i:1-i)*e,s=2*i-n;return new Ri(Hi(t>=240?t-240:t+120,s,n),Hi(t,s,n),Hi(t<120?t+240:t-120,s,n),this.opacity)},clamp(){return new Wi(Gi(this.h),Zi(this.s),Zi(this.l),Bi(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){const t=Bi(this.opacity);return`${1===t?"hsl(":"hsla("}${Gi(this.h)}, ${100*Zi(this.s)}%, ${100*Zi(this.l)}%${1===t?")":`, ${t})`}`}}));const qi=t=>()=>t;function Vi(t,e){var i=e-t;return i?function(t,e){return function(i){return t+i*e}}(t,i):qi(isNaN(t)?e:t)}const Yi=function t(e){var i=function(t){return 1===(t=+t)?Vi:function(e,i){return i-e?function(t,e,i){return t=Math.pow(t,i),e=Math.pow(e,i)-t,i=1/i,function(n){return Math.pow(t+n*e,i)}}(e,i,t):qi(isNaN(e)?i:e)}}(e);function n(t,e){var n=i((t=Li(t)).r,(e=Li(e)).r),s=i(t.g,e.g),o=i(t.b,e.b),r=Vi(t.opacity,e.opacity);return function(e){return t.r=n(e),t.g=s(e),t.b=o(e),t.opacity=r(e),t+""}}return n.gamma=t,n}(1);function $i(t){return function(e){var i,n,s=e.length,o=new Array(s),r=new Array(s),a=new Array(s);for(i=0;i=1?(i=1,e-1):Math.floor(i*e),s=t[n],o=t[n+1],r=n>0?t[n-1]:2*s-o,a=no&&(s=e.slice(o,s),a[r]?a[r]+=s:a[++r]=s),(i=i[0])===(n=n[0])?a[r]?a[r]+=n:a[++r]=n:(a[++r]=null,h.push({i:r,x:ei(i,n)})),o=Qi.lastIndex;return o=0&&(t=t.slice(0,e)),!t||"start"===t})}(e)?Ke:Qe;return function(){var r=o(this,t),a=r.on;a!==n&&(s=(n=a).copy()).on(e,i),r.on=s}}(i,t,e))},attr:function(t,e){var i=xt(t),n="transform"===i?hi:tn;return this.attrTween(t,"function"==typeof e?(i.local?an:rn)(i,n,ui(this,"attr."+t,e)):null==e?(i.local?nn:en)(i):(i.local?on:sn)(i,n,e))},attrTween:function(t,e){var i="attr."+t;if(arguments.length<2)return(i=this.tween(i))&&i._value;if(null==e)return this.tween(i,null);if("function"!=typeof e)throw new Error;var n=xt(t);return this.tween(i,(n.local?hn:ln)(n,e))},style:function(t,e,i){var n="transform"==(t+="")?ai:tn;return null==e?this.styleTween(t,function(t,e){var i,n,s;return function(){var o=Dt(this,t),r=(this.style.removeProperty(t),Dt(this,t));return o===r?null:o===i&&r===n?s:s=e(i=o,n=r)}}(t,n)).on("end.style."+t,gn(t)):"function"==typeof e?this.styleTween(t,function(t,e,i){var n,s,o;return function(){var r=Dt(this,t),a=i(this),h=a+"";return null==a&&(this.style.removeProperty(t),h=a=Dt(this,t)),r===h?null:r===n&&h===s?o:(s=h,o=e(n=r,a))}}(t,n,ui(this,"style."+t,e))).each(function(t,e){var i,n,s,o,r="style."+e,a="end."+r;return function(){var h=Qe(this,t),l=h.on,d=null==h.value[r]?o||(o=gn(e)):void 0;l===i&&s===d||(n=(i=l).copy()).on(a,s=d),h.on=n}}(this._id,t)):this.styleTween(t,function(t,e,i){var n,s,o=i+"";return function(){var r=Dt(this,t);return r===o?null:r===n?s:s=e(n=r,i)}}(t,n,e),i).on("end.style."+t,null)},styleTween:function(t,e,i){var n="style."+(t+="");if(arguments.length<2)return(n=this.tween(n))&&n._value;if(null==e)return this.tween(n,null);if("function"!=typeof e)throw new Error;return this.tween(n,function(t,e,i){var n,s;function o(){var o=e.apply(this,arguments);return o!==s&&(n=(s=o)&&function(t,e,i){return function(n){this.style.setProperty(t,e.call(this,n),i)}}(t,o,i)),n}return o._value=e,o}(t,e,i??""))},text:function(t){return this.tween("text","function"==typeof t?function(t){return function(){var e=t(this);this.textContent=e??""}}(ui(this,"text",t)):function(t){return function(){this.textContent=t}}(null==t?"":t+""))},textTween:function(t){var e="text";if(arguments.length<1)return(e=this.tween(e))&&e._value;if(null==t)return this.tween(e,null);if("function"!=typeof t)throw new Error;return this.tween(e,function(t){var e,i;function n(){var n=t.apply(this,arguments);return n!==i&&(e=(i=n)&&function(t){return function(e){this.textContent=t.call(this,e)}}(n)),e}return n._value=t,n}(t))},remove:function(){return this.on("end.remove",function(t){return function(){var e=this.parentNode;for(var i in this.__transition)if(+i!==t)return;e&&e.removeChild(this)}}(this._id))},tween:function(t,e){var i=this._id;if(t+="",arguments.length<2){for(var n,s=Je(this.node(),i).tween,o=0,r=s.length;o()=>t;function wn(t,{sourceEvent:e,target:i,transform:n,dispatch:s}){Object.defineProperties(this,{type:{value:t,enumerable:!0,configurable:!0},sourceEvent:{value:e,enumerable:!0,configurable:!0},target:{value:i,enumerable:!0,configurable:!0},transform:{value:n,enumerable:!0,configurable:!0},_:{value:s}})}function Tn(t,e,i){this.k=t,this.x=e,this.y=i}Tn.prototype={constructor:Tn,scale:function(t){return 1===t?this:new Tn(this.k*t,this.x,this.y)},translate:function(t,e){return 0===t&0===e?this:new Tn(this.k,this.x+this.k*t,this.y+this.k*e)},apply:function(t){return[t[0]*this.k+this.x,t[1]*this.k+this.y]},applyX:function(t){return t*this.k+this.x},applyY:function(t){return t*this.k+this.y},invert:function(t){return[(t[0]-this.x)/this.k,(t[1]-this.y)/this.k]},invertX:function(t){return(t-this.x)/this.k},invertY:function(t){return(t-this.y)/this.k},rescaleX:function(t){return t.copy().domain(t.range().map(this.invertX,this).map(t.invert,t))},rescaleY:function(t){return t.copy().domain(t.range().map(this.invertY,this).map(t.invert,t))},toString:function(){return"translate("+this.x+","+this.y+") scale("+this.k+")"}};var En=new Tn(1,0,0);function Pn(t){t.stopImmediatePropagation()}function An(t){t.preventDefault(),t.stopImmediatePropagation()}function Cn(t){return!(t.ctrlKey&&"wheel"!==t.type||t.button)}function Mn(){var t=this;return t instanceof SVGElement?(t=t.ownerSVGElement||t).hasAttribute("viewBox")?[[(t=t.viewBox.baseVal).x,t.y],[t.x+t.width,t.y+t.height]]:[[0,0],[t.width.baseVal.value,t.height.baseVal.value]]:[[0,0],[t.clientWidth,t.clientHeight]]}function Nn(){return this.__zoom||En}function Dn(t){return-t.deltaY*(1===t.deltaMode?.05:t.deltaMode?1:.002)*(t.ctrlKey?10:1)}function In(){return navigator.maxTouchPoints||"ontouchstart"in this}function Ln(t,e,i){var n=t.invertX(e[0][0])-i[0][0],s=t.invertX(e[1][0])-i[1][0],o=t.invertY(e[0][1])-i[0][1],r=t.invertY(e[1][1])-i[1][1];return t.translate(s>n?(n+s)/2:Math.min(0,n)||Math.max(0,s),r>o?(o+r)/2:Math.min(0,o)||Math.max(0,r))}Tn.prototype;const Rn=(t,e)=>!!t&&!!e&&t.x===e.x&&t.y===e.y;var On;function kn(t,e,i){t.on(On.SIMULATION_START,()=>{e.emit(On.SIMULATION_START,void 0),i(!0)}),t.on(On.SIMULATION_PROGRESS,t=>{e.emit(On.SIMULATION_PROGRESS,t)}),t.on(On.SIMULATION_END,t=>{e.emit(On.SIMULATION_END,t),i(!1)}),t.on(On.SIMULATION_STEP,t=>{e.emit(On.SIMULATION_STEP,t)}),t.on(On.NODE_DRAG,t=>{e.emit(On.NODE_DRAG,t)}),t.on(On.SETTINGS_UPDATE,t=>{e.emit(On.SETTINGS_UPDATE,t)})}function Bn(t){return function(){return t}}function zn(t){return 1e-6*(t()-.5)}function Un(t){return t.index}function Fn(t,e){var i=t.get(e);if(!i)throw new Error("node not found: "+e);return i}!function(t){t.SIMULATION_START="simulation-start",t.SIMULATION_STEP="simulation-step",t.SIMULATION_PROGRESS="simulation-progress",t.SIMULATION_END="simulation-end",t.NODE_DRAG="node-drag",t.NODE_DRAG_END="node-drag-end",t.SETTINGS_UPDATE="settings-update"}(On||(On={}));const jn=4294967296;function Wn(t){return t.x}function Gn(t){return t.y}var Zn=Math.PI*(3-Math.sqrt(5));function Hn(t,e,i,n){if(isNaN(e)||isNaN(i))return t;var s,o,r,a,h,l,d,u,c,_=t._root,f={data:n},g=t._x0,p=t._y0,m=t._x1,v=t._y1;if(!_)return t._root=f,t;for(;_.length;)if((l=e>=(o=(g+m)/2))?g=o:m=o,(d=i>=(r=(p+v)/2))?p=r:v=r,s=_,!(_=_[u=d<<1|l]))return s[u]=f,t;if(a=+t._x.call(null,_.data),h=+t._y.call(null,_.data),e===a&&i===h)return f.next=_,s?s[u]=f:t._root=f,t;do{s=s?s[u]=new Array(4):t._root=new Array(4),(l=e>=(o=(g+m)/2))?g=o:m=o,(d=i>=(r=(p+v)/2))?p=r:v=r}while((u=d<<1|l)==(c=(h>=r)<<1|a>=o));return s[c]=_,s[u]=f,t}function Xn(t,e,i,n,s){this.node=t,this.x0=e,this.y0=i,this.x1=n,this.y1=s}function qn(t){return t[0]}function Vn(t){return t[1]}function Yn(t,e,i){var n=new $n(e??qn,i??Vn,NaN,NaN,NaN,NaN);return null==t?n:n.addAll(t)}function $n(t,e,i,n,s,o){this._x=t,this._y=e,this._x0=i,this._y0=n,this._x1=s,this._y1=o,this._root=void 0}function Kn(t){for(var e={data:t.data},i=e;t=t.next;)i=i.next={data:t.data};return e}var Qn=Yn.prototype=$n.prototype;function Jn(t){return t.x+t.vx}function ts(t){return t.y+t.vy}Qn.copy=function(){var t,e,i=new $n(this._x,this._y,this._x0,this._y0,this._x1,this._y1),n=this._root;if(!n)return i;if(!n.length)return i._root=Kn(n),i;for(t=[{source:n,target:i._root=new Array(4)}];n=t.pop();)for(var s=0;s<4;++s)(e=n.source[s])&&(e.length?t.push({source:e,target:n.target[s]=new Array(4)}):n.target[s]=Kn(e));return i},Qn.add=function(t){const e=+this._x.call(null,t),i=+this._y.call(null,t);return Hn(this.cover(e,i),e,i,t)},Qn.addAll=function(t){var e,i,n,s,o=t.length,r=new Array(o),a=new Array(o),h=1/0,l=1/0,d=-1/0,u=-1/0;for(i=0;id&&(d=n),su&&(u=s));if(h>d||l>u)return this;for(this.cover(h,l).cover(d,u),i=0;it||t>=s||n>e||e>=o;)switch(a=(ec||(o=h.y0)>_||(r=h.x1)=m)<<1|t>=p)&&(h=f[f.length-1],f[f.length-1]=f[f.length-1-l],f[f.length-1-l]=h)}else{var v=t-+this._x.call(null,g.data),y=e-+this._y.call(null,g.data),x=v*v+y*y;if(x=(a=(f+p)/2))?f=a:p=a,(d=r>=(h=(g+m)/2))?g=h:m=h,e=_,!(_=_[u=d<<1|l]))return this;if(!_.length)break;(e[u+1&3]||e[u+2&3]||e[u+3&3])&&(i=e,c=u)}for(;_.data!==t;)if(n=_,!(_=_.next))return this;return(s=_.next)&&delete _.next,n?(s?n.next=s:delete n.next,this):e?(s?e[u]=s:delete e[u],(_=e[0]||e[1]||e[2]||e[3])&&_===(e[3]||e[2]||e[1]||e[0])&&!_.length&&(i?i[c]=_:this._root=_),this):(this._root=s,this)},Qn.removeAll=function(t){for(var e=0,i=t.length;e100*(t>0?t:1),ns={useGPU:!1,isSimulatingOnDataUpdate:!0,isSimulatingOnSettingsUpdate:!0,isSimulatingOnUnstick:!0,isPhysicsEnabled:!1,alpha:{alpha:1,alphaMin:.05,alphaDecay:.028,alphaTarget:0},centering:{x:0,y:0,strength:1},collision:{radius:15,strength:1,iterations:1},links:{distance:50,strength:1,iterations:1},manyBody:{strength:-100,theta:.9,distanceMin:1,distanceMax:is(50)},positioning:{forceX:{x:0,strength:.1},forceY:{y:0,strength:.1}},anchorX:"center",anchorY:"center"},ss={rowGap:50,colGap:50},os={nodeGap:50,levelGap:50,treeGap:100,orientation:"vertical",reversed:!1};class rs extends t{constructor(){super(...arguments),this._nodes=[],this._edges=[],this._nodeIndexByNodeId={},this._cancelSimulation=!1,this._schedulerPort=null}terminate(){var t;this._cancelSimulation=!0,null===(t=this._schedulerPort)||void 0===t||t.close(),this._schedulerPort=null,this.removeAllListeners()}_scheduleNext(t){if("undefined"!=typeof MessageChannel){const e=new MessageChannel;this._schedulerPort=e.port2,e.port1.onmessage=()=>{this._schedulerPort=null,t()},e.port2.postMessage(null)}else setTimeout(t,0)}_rebuildNodeIndex(){this._nodeIndexByNodeId={};for(let t=0;t0&&this.activateSimulation())}setupData(t){this.clearData(),this._initializeNewData(t),this._settings.isSimulatingOnDataUpdate&&(this._updateSimulationData(),this._runSimulation())}mergeData(t){this._initializeNewData(t),this._settings.isPhysicsEnabled||this._pinNodes(),this._settings.isSimulatingOnDataUpdate&&(this._updateSimulationData(),this.activateSimulation())}updateData(t){const e=new Set(t.nodes.map(t=>t.id)),i=this._nodes.filter(t=>e.has(t.id)),n=t.nodes.filter(t=>void 0===this._nodeIndexByNodeId[t.id]);this._nodes=[...i,...n],this._rebuildNodeIndex(),this._edges=t.edges,this._settings.isSimulatingOnSettingsUpdate&&(this._updateSimulationData(),this.activateSimulation())}deleteData(t){if(t.nodeIds){const e=new Set(t.nodeIds);this._nodes=this._nodes.filter(t=>!e.has(t.id))}if(t.edgeIds){const e=new Set(t.edgeIds);this._edges=this._edges.filter(t=>!e.has(t.id))}this._rebuildNodeIndex(),this._settings.isSimulatingOnDataUpdate&&(this._updateSimulationData(),this.activateSimulation())}patchData(t){if(t.nodes){const e={};for(let t=0;t0&&this.activateSimulation()}terminate(){var t;super.terminate(),null===(t=this._simulation)||void 0===t||t.stop()}_resetSimulation(){this._simulation&&(this._simulation.stop(),this._simulation.on("tick",null).on("end",null)),this._linkForce=function(t){var e,i,n,s,o,r,a=Un,h=function(t){return 1/Math.min(s[t.source.index],s[t.target.index])},l=Bn(30),d=1;function u(n){for(var s=0,a=t.length;s[a(t,e,n),t]));for(r=0,s=new Array(l);rt.id),this._simulation=function(t){var e,i=1,n=.001,s=1-Math.pow(n,1/300),o=0,r=.6,a=new Map,h=Ge(u),l=tt("tick","end"),d=function(){let t=1;return()=>(t=(1664525*t+1013904223)%jn)/jn}();function u(){c(),l.call("tick",e),i1?(null==i?a.delete(t):a.set(t,f(i)),e):a.get(t)},find:function(e,i,n){var s,o,r,a,h,l=0,d=t.length;for(null==n?n=1/0:n*=n,l=0;l1?(l.on(t,i),e):l.on(t)}}}(this._nodes).force("link",this._linkForce).stop(),this._applySettingsToSimulation(this._settings),this._simulation.on("tick",()=>{this.emit(On.SIMULATION_STEP,{nodes:this._nodes,edges:this._edges})}),this._simulation.on("end",()=>{this._isDragging=!1,this._isStabilizing=!1,this.emit(On.SIMULATION_END,{nodes:this._nodes,edges:this._edges}),this._settings.isPhysicsEnabled||this._pinNodes()})}_runSimulation(t){if(this._isStabilizing||this._cancelSimulation)return;(this._settings.isPhysicsEnabled||(null==t?void 0:t.isUpdatingSettings))&&this._unpinNodes(),this.emit(On.SIMULATION_START,void 0),this._isStabilizing=!0,this._simulation.alpha(this._settings.alpha.alpha).alphaTarget(this._settings.alpha.alphaTarget).stop();const e=Math.min(500,Math.ceil(Math.log(this._settings.alpha.alphaMin)/Math.log(1-this._settings.alpha.alphaDecay)));let i=-1,n=0;const s=()=>{if(this._cancelSimulation)return this._isStabilizing=!1,void(this._cancelSimulation=!1);const t=Math.min(n+100,e);for(;ni&&(i=t,this.emit(On.SIMULATION_PROGRESS,{nodes:this._nodes,edges:this._edges,progress:t/100}))}nl+f||od+f||rh.index){var g=l-a.x-a.vx,p=d-a.y-a.vy,m=g*g+p*p;mt.r&&(t.r=t[e].r)}function h(){if(e){var n,s,o=e.length;for(i=new Array(o),n=0;n=a)){(t.data!==e||t.next)&&(0===u&&(f+=(u=zn(i))*u),0===c&&(f+=(c=zn(i))*c),f=s)continue;h<1&&(h=1);const u=-t*e/h;o.vx+=r*u,o.vy+=a*u}}}return o.initialize=t=>{n=t},o}(t.manyBody.strength,t.manyBody.distanceMax,()=>this._edges)):this._simulation.force("edgeMidpointRepulsion",null)}if(null===t.manyBody&&(this._simulation.force("charge",null),this._simulation.force("edgeMidpointRepulsion",null)),null===(e=t.positioning)||void 0===e?void 0:e.forceX){const e=function(t){var e,i,n,s=Bn(.1);function o(t){for(var s,o=0,r=e.length;o{const n=t.createShader(i===hs.VERTEX?t.VERTEX_SHADER:t.FRAGMENT_SHADER);if(!n)throw new o("Failed to create shader.");if(t.shaderSource(n,e),t.compileShader(n),!t.getShaderParameter(n,t.COMPILE_STATUS)){const e=t.getShaderInfoLog(n);throw t.deleteShader(n),new o(`Failed to compile shader: ${e}`)}return n};class ds extends rs{constructor(t){super(),this._isStabilizing=!1,this._isDragging=!1,this._dragLoopRunning=!1,this._pendingRestart=!1,this._simulationGeneration=0,this._currentAlpha=0,this._currentStep=0,this._totalSteps=0,this._dragAlpha=0,this._dragNeedsReheat=!1,this._dirtyNodes=new Set,this._forceProgram=null,this._quadBuffer=null,this._quadVAO=null,this._stateTexA=null,this._stateTexB=null,this._fixedTex=null,this._fboA=null,this._fboB=null,this._texWidth=0,this._treeDataTexture=null,this._treeChildrenTexture=null,this._treeGeometryTexture=null,this._adjOffsetsTexture=null,this._adjEdgesTexture=null,this._cachedAdjacency=null,this._treeTexWidth=1,this._treeNodeCount=0,this._pingPong=!0,this._uniforms={},this.type="force",this._settings=Object.assign(Object.assign({},ns),t);const e=document.createElement("canvas").getContext("webgl2");if(!e)throw new o("Failed to create WebGL2 context for GPU force layout engine.");this._gl=e,this._initGPU(),this.clearData()}setSettings(t){const e=t;this._initialSettings||(this._initialSettings=Object.assign(m(ns),e));const i=m(this._settings);Object.assign(this._settings,e),v(this._settings,i)||(this.emit(On.SETTINGS_UPDATE,{settings:{type:"force",options:this._settings}}),i.isPhysicsEnabled&&!e.isPhysicsEnabled?this.stopSimulation():this._settings.isSimulatingOnSettingsUpdate&&this._nodes.length>0&&this.activateSimulation())}setupData(t){this.clearData(),this._initializeNewData(t),this._settings.isSimulatingOnDataUpdate&&this._runSimulation()}mergeData(t){this._initializeNewData(t),this._settings.isPhysicsEnabled||this._pinNodes(),this._settings.isSimulatingOnDataUpdate&&this.activateSimulation()}updateData(t){const e=new Set(t.nodes.map(t=>t.id)),i=this._nodes.filter(t=>e.has(t.id)),n=t.nodes.filter(t=>void 0===this._nodeIndexByNodeId[t.id]);this._nodes=[...i,...n],this._rebuildNodeIndex(),this._edges=t.edges,this._cachedAdjacency=null,this._settings.isSimulatingOnSettingsUpdate&&this.activateSimulation()}deleteData(t){if(t.nodeIds){const e=new Set(t.nodeIds);this._nodes=this._nodes.filter(t=>!e.has(t.id))}if(t.edgeIds){const e=new Set(t.edgeIds);this._edges=this._edges.filter(t=>!e.has(t.id))}this._rebuildNodeIndex(),this._cachedAdjacency=null,this._settings.isSimulatingOnDataUpdate&&this.activateSimulation()}patchData(t){if(t.nodes){const e={};for(let t=0;t0&&this.activateSimulation()}terminate(){var t;super.terminate();const e=this._gl;e&&(e.deleteBuffer(this._quadBuffer),e.deleteVertexArray(this._quadVAO),e.deleteProgram(this._forceProgram),e.deleteTexture(this._stateTexA),e.deleteTexture(this._stateTexB),e.deleteTexture(this._fixedTex),e.deleteTexture(this._treeDataTexture),e.deleteTexture(this._treeChildrenTexture),e.deleteTexture(this._treeGeometryTexture),e.deleteTexture(this._adjOffsetsTexture),e.deleteTexture(this._adjEdgesTexture),e.deleteFramebuffer(this._fboA),e.deleteFramebuffer(this._fboB),null===(t=e.getExtension("WEBGL_lose_context"))||void 0===t||t.loseContext())}reheat(){const t=this._settings.alpha;this._currentAlpha=t.alpha,this._totalSteps=Math.min(500,Math.ceil(Math.log(t.alphaMin)/Math.log(1-t.alphaDecay))),this._currentStep=0,this._isStabilizing||(this._ensurePositions(),this._uploadDataToGPU(),this._cachedAdjacency||this._buildAndUploadAdjacency(),this._startSimulationLoop())}_runSimulation(){this._isStabilizing||this._cancelSimulation||(this._ensurePositions(),this._uploadDataToGPU(),this._buildAndUploadAdjacency(),this._startSimulationLoop())}_startDragLoop(){if(this._dragLoopRunning)return;this._dragLoopRunning=!0;const t=this._settings.alpha.alphaDecay,e=this._settings.alpha.alphaMin;this._dragAlpha=.3,this._dragNeedsReheat=!1;const i=()=>{this._isDragging?(this._dragNeedsReheat&&(this._dragAlpha=.3,this._dragNeedsReheat=!1),this._dragAlpha+=(0-this._dragAlpha)*t,this._dragAlpha{if(t!==this._simulationGeneration)return;if(this._cancelSimulation)return this._isStabilizing=!1,this._cancelSimulation=!1,void this.emit(On.SIMULATION_END,{nodes:this._nodes,edges:this._edges});if(this._readbackFromGPU(),this._pendingRestart)return this._isStabilizing=!1,this._pendingRestart=!1,this._ensurePositions(),this._uploadDataToGPU(),this._cachedAdjacency||this._buildAndUploadAdjacency(),void this._startSimulationLoop();this._flushDirtyNodes(),this._buildAndUploadQuadTree();const r=Math.min(this._currentStep+1,this._totalSteps);for(;this._currentSteps&&(s=a,this.emit(On.SIMULATION_PROGRESS,{nodes:this._nodes,edges:this._edges,progress:a/100})),this._currentStep0&&(s=s.concat(t))}const o=function(t,e){var i,n;const s=t.length;if(0===s)return{treeData:new Float32Array(0),treeChildren:new Float32Array(0),treeGeometry:new Float32Array(0),nodeCount:0,texWidth:1};let o=1/0,r=1/0,a=-1/0,h=-1/0;for(let e=0;ea&&(a=i),n>h&&(h=n)}let l=Math.max(a-o,h-r);l<1e-6&&(l=1),l*=1.01;const d=.5*l,u=.5*(o+a)-d,c=.5*(r+h)-d,_=[];function f(t){const e=_.length;return _.push({cx:0,cy:0,charge:0,size:t,bodyIndex:-1,children:[null,null,null,null]}),e}const g=f(l),p=[u],m=[c];function v(t,e,i,n,s){return 2*(e>=n+.5*s?1:0)+(t>=i+.5*s?1:0)}function y(t,e,i,n){const s=.5*n;return{cx0:1&t?e+s:e,cy0:2&t?i+s:i,csz:s}}function x(t,i,n){let s=g,o=u,r=c,a=l;for(let h=0;h<50;h++){const h=_[s];if(-1===h.bodyIndex&&null===h.children[0]&&null===h.children[1]&&null===h.children[2]&&null===h.children[3])return h.bodyIndex=t,h.cx=i,h.cy=n,void(h.charge=e);if(h.bodyIndex>=0){const t=h.bodyIndex,i=h.cx,n=h.cy;h.bodyIndex=-1;const s=v(i,n,o,r,a),{cx0:l,cy0:d,csz:u}=y(s,o,r,a),c=f(u);p[c]=l,m[c]=d,h.children[s]=c,_[c].bodyIndex=t,_[c].cx=i,_[c].cy=n,_[c].charge=e}const l=v(i,n,o,r,a);if(null===h.children[l]){const{cx0:s,cy0:d,csz:u}=y(l,o,r,a),c=f(u);return p[c]=s,m[c]=d,h.children[l]=c,_[c].bodyIndex=t,_[c].cx=i,_[c].cy=n,void(_[c].charge=e)}const{cx0:d,cy0:u,csz:c}=y(l,o,r,a);s=h.children[l],o=d,r=u,a=c}}for(let e=0;e=0)return;let n=0,s=0,o=0,r=0;for(let e=0;e<4;e++){const a=i.children[e];if(null===a)continue;t(a);const h=_[a],l=Math.abs(h.charge);n+=h.charge,s+=h.cx*l,o+=h.cy*l,r+=l}r>0&&(i.cx=s/r,i.cy=o/r),i.charge=n}(g);const b=_.length,S=Math.ceil(Math.sqrt(b)),w=S*S,T=new Float32Array(4*w),E=new Float32Array(4*w),P=new Float32Array(4*w);for(let t=0;t=0?T[s+3]=-(e.bodyIndex+1):T[s+3]=e.size,E[s]=null!==e.children[0]?e.children[0]:-1,E[s+1]=null!==e.children[1]?e.children[1]:-1,E[s+2]=null!==e.children[2]?e.children[2]:-1,E[s+3]=null!==e.children[3]?e.children[3]:-1,P[s]=null!==(i=p[t])&&void 0!==i?i:0,P[s+1]=null!==(n=m[t])&&void 0!==n?n:0,P[s+2]=e.size,P[s+3]=0}for(let t=b;t= uNodeCount) {\n fragColor = vec4(0.0);\n return;\n }\n\n vec4 fixedData = texelFetch(uFixed, fc, 0);\n if (fixedData.x > 0.5) {\n fragColor = vec4(fixedData.yz, 0.0, 0.0);\n return;\n }\n\n vec4 state = texelFetch(uState, fc, 0);\n vec2 pos = state.xy;\n vec2 vel = state.zw;\n\n if (uHasManyBody > 0.5 && uTreeNodeCount > 0) {\n int stack[128];\n int top = 0;\n stack[top++] = 0;\n\n while (top > 0) {\n int idx = stack[--top];\n vec4 data = texelFetch(uTreeData, texCoord(idx, uTreeTexWidth), 0);\n float w = data.w;\n\n if (w < -0.5) {\n int bodyIdx = int(-w - 0.5);\n if (bodyIdx != nodeId) {\n vec2 delta = data.xy - pos;\n float distSq = dot(delta, delta);\n\n if (distSq < 1e-8) {\n delta = vec2(float(nodeId) * 1e-4 - float(bodyIdx) * 1e-4 + 1e-4, 1e-4);\n distSq = dot(delta, delta);\n }\n\n if (distSq < uDistanceMax2) {\n float l = distSq;\n if (l < uDistanceMin2) l = sqrt(uDistanceMin2 * l);\n vel += delta * (data.z * uAlpha / max(l, 1e-6));\n }\n }\n } else {\n vec2 delta = data.xy - pos;\n float distSq = dot(delta, delta);\n\n if (distSq > 0.0 && w * w / distSq < uTheta2) {\n if (distSq < uDistanceMax2) {\n float l = distSq;\n if (l < uDistanceMin2) l = sqrt(uDistanceMin2 * l);\n vel += delta * (data.z * uAlpha / max(l, 1e-6));\n }\n } else {\n vec4 ch = texelFetch(uTreeChildren, texCoord(idx, uTreeTexWidth), 0);\n if (ch.w >= 0.0 && top < 64) stack[top++] = int(ch.w + 0.5);\n if (ch.z >= 0.0 && top < 64) stack[top++] = int(ch.z + 0.5);\n if (ch.y >= 0.0 && top < 64) stack[top++] = int(ch.y + 0.5);\n if (ch.x >= 0.0 && top < 64) stack[top++] = int(ch.x + 0.5);\n }\n }\n }\n }\n\n if (uHasCollision > 0.5 && uCollisionRadius > 0.0 && uTreeNodeCount > 0) {\n float collisionDiam = uCollisionRadius * 2.0;\n vec2 predictedPos = state.xy + state.zw;\n int stack[64];\n int top = 0;\n stack[top++] = 0;\n\n while (top > 0) {\n int idx = stack[--top];\n vec4 data = texelFetch(uTreeData, texCoord(idx, uTreeTexWidth), 0);\n float w = data.w;\n\n if (w < -0.5) {\n int bodyIdx = int(-w - 0.5);\n if (bodyIdx != nodeId && bodyIdx < uNodeCount) {\n vec2 delta = data.xy - predictedPos;\n float dist = length(delta);\n\n if (dist < collisionDiam && dist > 0.0) {\n float push = (collisionDiam - dist) * uCollisionStrength;\n vel -= (delta / dist) * push * 0.5;\n }\n }\n } else {\n vec4 geo = texelFetch(uTreeGeometry, texCoord(idx, uTreeTexWidth), 0);\n float cellSize = geo.z;\n vec2 nearest = clamp(predictedPos, geo.xy, geo.xy + cellSize);\n float distToCell = length(nearest - predictedPos);\n\n if (distToCell < collisionDiam) {\n vec4 ch = texelFetch(uTreeChildren, texCoord(idx, uTreeTexWidth), 0);\n if (ch.w >= 0.0 && top < 64) stack[top++] = int(ch.w + 0.5);\n if (ch.z >= 0.0 && top < 64) stack[top++] = int(ch.z + 0.5);\n if (ch.y >= 0.0 && top < 64) stack[top++] = int(ch.y + 0.5);\n if (ch.x >= 0.0 && top < 64) stack[top++] = int(ch.x + 0.5);\n }\n }\n }\n }\n\n if (uHasLinks > 0.5) {\n vec4 offData = texelFetch(uAdjOffsets, texCoord(nodeId, uAdjOffsetsTexWidth), 0);\n int start = int(offData.x + 0.5);\n int count = int(offData.y + 0.5);\n\n for (int e = 0; e < count; e++) {\n vec4 edgeData = texelFetch(uAdjEdges, texCoord(start + e, uAdjEdgesTexWidth), 0);\n int targetId = int(edgeData.x + 0.5);\n float restDist = edgeData.y;\n float strength = edgeData.z;\n float dirBias = edgeData.w;\n\n vec4 targetState = texelFetch(uState, texCoord(targetId, uTexWidth), 0);\n vec2 delta = (targetState.xy + targetState.zw) - (state.xy + state.zw);\n float d = length(delta);\n\n if (d < 1e-6) {\n delta = vec2(1e-3, 1e-3);\n d = length(delta);\n }\n\n float scale = (d - restDist) / d * uAlpha * strength;\n vel += delta * scale * dirBias;\n }\n }\n\n if (uHasCentering > 0.5) {\n vel += (uCenter - pos) * uCenterStrength * uAlpha;\n }\n\n if (uHasPositioning > 0.5) {\n vel.x += (uForceXTarget - pos.x) * uForceXStrength * uAlpha;\n vel.y += (uForceYTarget - pos.y) * uForceYStrength * uAlpha;\n }\n\n vel *= uDamping;\n pos += vel;\n\n fragColor = vec4(pos, vel);\n}\n",hs.FRAGMENT),n=t.createProgram();if(!n)throw new o("Failed to create program.");if(this._forceProgram=n,t.attachShader(n,e),t.attachShader(n,i),t.linkProgram(n),!t.getProgramParameter(n,t.LINK_STATUS)){const e=t.getProgramInfoLog(n);throw new o(`Failed to link force program: ${e}`)}this._cacheUniformLocations(n),this._quadBuffer=t.createBuffer();const s=new Float32Array([-1,-1,1,-1,-1,1,1,1]);t.bindBuffer(t.ARRAY_BUFFER,this._quadBuffer),t.bufferData(t.ARRAY_BUFFER,s,t.STATIC_DRAW),this._quadVAO=t.createVertexArray(),t.bindVertexArray(this._quadVAO);const r=t.getAttribLocation(n,"aPosition");t.enableVertexAttribArray(r),t.vertexAttribPointer(r,2,t.FLOAT,!1,0,0),t.bindVertexArray(null),this._stateTexA=t.createTexture(),this._stateTexB=t.createTexture(),this._fixedTex=t.createTexture(),this._treeDataTexture=t.createTexture(),this._treeChildrenTexture=t.createTexture(),this._treeGeometryTexture=t.createTexture(),this._adjOffsetsTexture=t.createTexture(),this._adjEdgesTexture=t.createTexture(),this._fboA=t.createFramebuffer(),this._fboB=t.createFramebuffer()}_cacheUniformLocations(t){const e=this._gl,i=["uState","uFixed","uTreeData","uTreeChildren","uTreeGeometry","uAdjOffsets","uAdjEdges","uNodeCount","uTexWidth","uAlpha","uDamping","uManyBodyStrength","uTheta2","uDistanceMin2","uDistanceMax2","uTreeNodeCount","uTreeTexWidth","uAdjOffsetsTexWidth","uAdjEdgesTexWidth","uCenter","uCenterStrength","uCollisionRadius","uCollisionStrength","uForceXTarget","uForceXStrength","uForceYTarget","uForceYStrength","uHasManyBody","uHasLinks","uHasCentering","uHasCollision","uHasPositioning"];for(const n of i)this._uniforms[n]=e.getUniformLocation(t,n)}_uploadDataToGPU(){var t,e,i,n,s,o,r,a;const h=this._gl,l=this._nodes.length;this._texWidth=Math.max(1,Math.ceil(Math.sqrt(l)));const d=this._texWidth*this._texWidth,u=new Float32Array(4*d),c=new Float32Array(4*d);for(let h=0;h0?t.distanceMax:is(null!==(i=null===(e=this._settings.links)||void 0===e?void 0:e.distance)&&void 0!==i?i:50);c.uniform1f(g.uDistanceMax2,s*s),c.uniform1i(g.uTreeNodeCount,this._treeNodeCount),c.uniform1i(g.uTreeTexWidth,this._treeTexWidth)}const m=null!==this._cachedAdjacency&&this._edges.length>0;c.uniform1f(g.uHasLinks,m?1:0),m&&(c.uniform1i(g.uAdjOffsetsTexWidth,this._cachedAdjacency.offsetsTexWidth),c.uniform1i(g.uAdjEdgesTexWidth,this._cachedAdjacency.edgesTexWidth)),c.uniform1f(g.uHasCentering,0);const v=null!==this._settings.collision&&void 0!==this._settings.collision;c.uniform1f(g.uHasCollision,v?1:0),v&&(c.uniform1f(g.uCollisionRadius,this._settings.collision.radius),c.uniform1f(g.uCollisionStrength,this._settings.collision.strength));const y=null!==this._settings.positioning&&void 0!==this._settings.positioning;if(c.uniform1f(g.uHasPositioning,y?1:0),y){const t=this._settings.positioning;c.uniform1f(g.uForceXTarget,null!==(s=null===(n=t.forceX)||void 0===n?void 0:n.x)&&void 0!==s?s:0),c.uniform1f(g.uForceXStrength,null!==(a=null===(r=t.forceX)||void 0===r?void 0:r.strength)&&void 0!==a?a:0),c.uniform1f(g.uForceYTarget,null!==(l=null===(h=t.forceY)||void 0===h?void 0:h.y)&&void 0!==l?l:0),c.uniform1f(g.uForceYStrength,null!==(u=null===(d=t.forceY)||void 0===d?void 0:d.strength)&&void 0!==u?u:0)}const x=this._pingPong?this._stateTexA:this._stateTexB,b=this._pingPong?this._fboB:this._fboA;c.activeTexture(c.TEXTURE0),c.bindTexture(c.TEXTURE_2D,x),c.uniform1i(g.uState,0),c.activeTexture(c.TEXTURE1),c.bindTexture(c.TEXTURE_2D,this._fixedTex),c.uniform1i(g.uFixed,1),c.activeTexture(c.TEXTURE2),c.bindTexture(c.TEXTURE_2D,this._treeDataTexture),c.uniform1i(g.uTreeData,2),c.activeTexture(c.TEXTURE3),c.bindTexture(c.TEXTURE_2D,this._treeChildrenTexture),c.uniform1i(g.uTreeChildren,3),c.activeTexture(c.TEXTURE4),c.bindTexture(c.TEXTURE_2D,this._adjOffsetsTexture),c.uniform1i(g.uAdjOffsets,4),c.activeTexture(c.TEXTURE5),c.bindTexture(c.TEXTURE_2D,this._adjEdgesTexture),c.uniform1i(g.uAdjEdges,5),c.activeTexture(c.TEXTURE6),c.bindTexture(c.TEXTURE_2D,this._treeGeometryTexture),c.uniform1i(g.uTreeGeometry,6),c.bindFramebuffer(c.FRAMEBUFFER,b),c.viewport(0,0,this._texWidth,this._texWidth),c.bindVertexArray(this._quadVAO),c.drawArrays(c.TRIANGLE_STRIP,0,4),c.bindVertexArray(null),c.bindFramebuffer(c.FRAMEBUFFER,null),this._pingPong=!this._pingPong}_readbackFromGPU(){const t=this._gl,e=this._nodes.length;if(0===e)return;const i=this._pingPong?this._fboA:this._fboB,n=this._texWidth*this._texWidth,s=new Float32Array(4*n);t.bindFramebuffer(t.FRAMEBUFFER,i),t.readPixels(0,0,this._texWidth,this._texWidth,t.RGBA,t.FLOAT,s),t.bindFramebuffer(t.FRAMEBUFFER,null);for(let t=0;tt.id)),i=this._nodes.filter(t=>e.has(t.id)),n=t.nodes.filter(t=>void 0===this._nodeIndexByNodeId[t.id]);this._nodes=[...i,...n],this._edges=t.edges,this._rebuildNodeIndex(),this._calculateAndEmit()}deleteData(t){if(t.nodeIds){const e=new Set(t.nodeIds);this._nodes=this._nodes.filter(t=>!e.has(t.id))}if(t.edgeIds){const e=new Set(t.edgeIds);this._edges=this._edges.filter(t=>!e.has(t.id))}this._rebuildNodeIndex(),this._calculateAndEmit()}patchData(t){if(t.nodes)for(let e=0;e0&&this._calculateAndEmit()}terminate(){this._pendingRecalculation=!1,super.terminate()}_calculateAndEmit(){0===this._nodes.length||this._cancelSimulation||(this._isCalculating?this._pendingRecalculation=!0:(this._isCalculating=!0,this.emit(On.SIMULATION_START,void 0),this.calculatePositions(this._nodes,this._edges,t=>{this.emit(On.SIMULATION_PROGRESS,{nodes:this._nodes,edges:this._edges,progress:t})},()=>this._cancelSimulation,()=>{this._isCalculating=!1,this._cancelSimulation||this.emit(On.SIMULATION_END,{nodes:this._nodes,edges:this._edges}),this._cancelSimulation=!1,this._pendingRecalculation&&(this._pendingRecalculation=!1,this._calculateAndEmit())})))}_emitProgress(t,e,i,n){const s=Math.round(100*t/e);return s>i?(n(s/100),s):i}}class cs extends us{constructor(t){super(),this.type="circular",this._config=Object.assign(Object.assign({},es),t)}calculatePositions(t,e,i,n,s){const o=2*Math.PI/t.length;let r=-1,a=0;const h=()=>{if(n())return void s();const e=Math.min(a+5e3,t.length);for(;a{if(n())return void s();const e=Math.min(h+5e3,t.length);for(;h{if(n()||c>=a.length)return!n()&&this._config.reversed&&this._applyReversal(t,h,l),void s();const e=this._assignLevels(a[c],o,r),f=Math.max(...Array.from(e.values()).map(t=>t.length));e.size*this._config.levelGap>l&&(l=e.size*this._config.levelGap);let g=0===c?0:this._config.treeGap+h;c>0&&(g+=(f-1)*this._config.nodeGap/2);for(let i=0;ih&&(h=a),void 0!==r&&(t[r].x="horizontal"===this._config.orientation?n:a,t[r].y="horizontal"===this._config.orientation?a:n),d++}}c++,c0;){const t=h.pop();if(void 0===t)continue;a.push(t);const s=null!==(i=e.get(t))&&void 0!==i?i:[];for(let t=0;t{var e;return 0===(null!==(e=i.get(t))&&void 0!==e?e:0)});void 0===a&&(a=t.reduce((t,e)=>{var n,s;return(null!==(n=i.get(e))&&void 0!==n?n:0)<(null!==(s=i.get(t))&&void 0!==s?s:0)?e:t}));const h=[[a,0]];for(const[t,i]of h){if(r.has(t))continue;r.add(t),o.has(i)?null===(n=o.get(i))||void 0===n||n.push(t):o.set(i,[t]);const a=null!==(s=e.get(t))&&void 0!==s?s:[];for(let t=0;t{this._isSimulationRunning=t})}}var ms,vs;!function(t){t.SetupData="Set Data",t.MergeData="Add Data",t.UpdateData="Update Data",t.DeleteData="Delete Data",t.PatchData="Patch Data",t.ClearData="Clear Data",t.ActivateSimulation="Activate Simulation",t.UpdateSimulation="Update Simulation",t.StopSimulation="Stop Simulation",t.StartDragNode="Start Drag Node",t.DragNode="Drag Node",t.EndDragNode="End Drag Node",t.FixNodes="Fix Nodes",t.ReleaseNodes="Release Nodes",t.SetSettings="Set Settings"}(ms||(ms={})),function(t){t.READY="ready",t.SIMULATION_START="simulation-start",t.SIMULATION_STEP="simulation-step",t.SIMULATION_PROGRESS="simulation-progress",t.SIMULATION_END="simulation-end",t.SIMULATION_TICK="simulation-tick",t.NODE_DRAG="node-drag",t.NODE_DRAG_END="node-drag-end",t.SETTINGS_UPDATE="settings-update"}(vs||(vs={}));class ys extends t{constructor(t){let e;super(),this._isSimulationRunning=!1,this._fallback=null,this._ready=!1,this._pending=[],this._hasWarned=!1,this._handleWorkerMessage=({data:t})=>{switch(t.type){case vs.READY:this._markReady();break;case vs.SIMULATION_START:this.emit(On.SIMULATION_START,void 0),this._isSimulationRunning=!0;break;case vs.SIMULATION_PROGRESS:this.emit(On.SIMULATION_PROGRESS,t.data);break;case vs.SIMULATION_END:this.emit(On.SIMULATION_END,t.data),this._isSimulationRunning=!1;break;case vs.SIMULATION_STEP:this.emit(On.SIMULATION_STEP,t.data);break;case vs.NODE_DRAG:this.emit(On.NODE_DRAG,t.data);break;case vs.NODE_DRAG_END:this.emit(On.NODE_DRAG_END,t.data);break;case vs.SETTINGS_UPDATE:this.emit(On.SETTINGS_UPDATE,t.data)}},this._settings=t;try{this._blobUrl=URL.createObjectURL(new Blob(['"use strict";(()=>{function Ee(n,r){var e,t=1;n==null&&(n=0),r==null&&(r=0);function i(){var o,s=e.length,a,u=0,l=0;for(o=0;o=(_=(a+l)/2))?a=_:l=_,(h=e>=(m=(u+c)/2))?u=m:c=m,i=o,!(o=o[p=h<<1|f]))return i[p]=s,n;if(d=+n._x.call(null,o.data),g=+n._y.call(null,o.data),r===d&&e===g)return s.next=o,i?i[p]=s:n._root=s,n;do i=i?i[p]=new Array(4):n._root=new Array(4),(f=r>=(_=(a+l)/2))?a=_:l=_,(h=e>=(m=(u+c)/2))?u=m:c=m;while((p=h<<1|f)===(y=(g>=m)<<1|d>=_));return i[y]=o,i[p]=s,n}function Be(n){var r,e,t=n.length,i,o,s=new Array(t),a=new Array(t),u=1/0,l=1/0,c=-1/0,_=-1/0;for(e=0;ec&&(c=i),o_&&(_=o));if(u>c||l>_)return this;for(this.cover(u,l).cover(c,_),e=0;en||n>=i||t>r||r>=o;)switch(l=(rc||(a=g.y0)>_||(u=g.x1)=p)<<1|n>=h)&&(g=m[m.length-1],m[m.length-1]=m[m.length-1-f],m[m.length-1-f]=g)}else{var y=n-+this._x.call(null,d.data),T=r-+this._y.call(null,d.data),x=y*y+T*T;if(x=(m=(s+u)/2))?s=m:u=m,(f=_>=(d=(a+l)/2))?a=d:l=d,r=e,!(e=e[h=f<<1|g]))return this;if(!e.length)break;(r[h+1&3]||r[h+2&3]||r[h+3&3])&&(t=r,p=h)}for(;e.data!==n;)if(i=e,!(e=e.next))return this;return(o=e.next)&&delete e.next,i?(o?i.next=o:delete i.next,this):r?(o?r[h]=o:delete r[h],(e=r[0]||r[1]||r[2]||r[3])&&e===(r[3]||r[2]||r[1]||r[0])&&!e.length&&(t?t[p]=e:this._root=e),this):(this._root=o,this)}function He(n){for(var r=0,e=n.length;rm.index){var M=d-D.x-D.vx,v=g-D.y-D.vy,S=M*M+v*v;Sd+b||Eg+b||Pl.r&&(l.r=l[c].r)}function u(){if(r){var l,c=r.length,_;for(e=new Array(c),l=0;l[r(I,E,s),I])),x;for(h=0,a=new Array(p);h{}};function rt(){for(var n=0,r=arguments.length,e={},t;n=0&&(t=e.slice(i+1),e=e.slice(0,i)),e&&!r.hasOwnProperty(e))throw new Error("unknown type: "+e);return{type:e,name:t}})}le.prototype=rt.prototype={constructor:le,on:function(n,r){var e=this._,t=Rt(n+"",e),i,o=-1,s=t.length;if(arguments.length<2){for(;++o0)for(var e=new Array(i),t=0,i,o;t=0&&n._call.call(void 0,r),n=n._next;--J}function st(){Z=(de=oe.now())+ce,J=ie=0;try{ut()}finally{J=0,Gt(),Z=0}}function Ft(){var n=oe.now(),r=n-de;r>at&&(ce-=r,de=n)}function Gt(){for(var n,r=ue,e,t=1/0;r;)r._call?(t>r._time&&(t=r._time),n=r,r=r._next):(e=r._next,r._next=null,r=n?n._next=e:ue=e);ne=n,Le(t)}function Le(n){if(!J){ie&&(ie=clearTimeout(ie));var r=n-Z;r>24?(n<1/0&&(ie=setTimeout(st,n-oe.now()-ce)),te&&(te=clearInterval(te))):(te||(de=oe.now(),te=setInterval(Ft,at)),J=1,lt(st))}}function dt(){let n=1;return()=>(n=(1664525*n+1013904223)%4294967296)/4294967296}function ct(n){return n.x}function ht(n){return n.y}var kt=10,Wt=Math.PI*(3-Math.sqrt(5));function Me(n){var r,e=1,t=.001,i=1-Math.pow(t,1/300),o=0,s=.6,a=new Map,u=he(_),l=Ae("tick","end"),c=dt();n==null&&(n=[]);function _(){m(),l.call("tick",r),e1?(h==null?a.delete(f):a.set(f,g(h)),r):a.get(f)},find:function(f,h,p){var y=0,T=n.length,x,I,E,P,D;for(p==null?p=1/0:p*=p,y=0;y1?(l.on(f,h),r):l.on(f)}}}function Re(){var n,r,e,t,i=O(-30),o,s=1,a=1/0,u=.81;function l(d){var g,f=n.length,h=Q(n,ct,ht).visitAfter(_);for(t=d,g=0;g=a)return;(d.data!==r||d.next)&&(p===0&&(p=k(e),x+=p*p),y===0&&(y=k(e),x+=y*y),xn instanceof Date,pe=n=>Array.isArray(n),me=n=>n!==null&&typeof n=="object"&&n.constructor.name==="Object";var C=n=>fe(n)?Ct(n):pe(n)?Bt(n):me(n)?Kt(n):n,j=(n,r)=>{let e=fe(n),t=fe(r);if(e&&!t||!e&&t)return!1;if(e&&t)return n.getTime()===r.getTime();let i=pe(n),o=pe(r);if(i&&!o||!i&&o)return!1;if(i&&o)return n.length!==r.length?!1:n.every((u,l)=>j(u,r[l]));let s=me(n),a=me(r);if(s&&!a||!s&&a)return!1;if(s&&a){let u=Object.keys(n),l=Object.keys(r);return j(u,l)?u.every(c=>j(n[c],r[c])):!1}return n===r},Ct=n=>new Date(n),Bt=n=>n.map(r=>C(r)),Kt=n=>{let r={};return Object.keys(n).forEach(e=>{r[e]=C(n[e])}),r};var pt={radius:100,centerX:0,centerY:0},zt=100,ft=50,Fe=n=>(n>0?n:1)*zt,ee={useGPU:!1,isSimulatingOnDataUpdate:!0,isSimulatingOnSettingsUpdate:!0,isSimulatingOnUnstick:!0,isPhysicsEnabled:!1,alpha:{alpha:1,alphaMin:.05,alphaDecay:.028,alphaTarget:0},centering:{x:0,y:0,strength:1},collision:{radius:15,strength:1,iterations:1},links:{distance:ft,strength:1,iterations:1},manyBody:{strength:-100,theta:.9,distanceMin:1,distanceMax:Fe(ft)},positioning:{forceX:{x:0,strength:.1},forceY:{y:0,strength:.1}},anchorX:"center",anchorY:"center"},mt={rowGap:50,colGap:50},gt={nodeGap:50,levelGap:50,treeGap:100,orientation:"vertical",reversed:!1};var ge=class{constructor(){this._listeners=new Map}once(r,e){let t={callable:e,isOnce:!0},i=this._listeners.get(r);return i?i.push(t):this._listeners.set(r,[t]),this}on(r,e){let t={callable:e},i=this._listeners.get(r);return i?i.push(t):this._listeners.set(r,[t]),this}off(r,e){let t=this._listeners.get(r);if(t){let i=t.filter(o=>o.callable!==e);this._listeners.set(r,i)}return this}emit(r,e){let t=this._listeners.get(r);if(!t||t.length===0)return!1;let i=!1;for(let o=0;o!s.isOnce);this._listeners.set(r,o)}return!0}eventNames(){return[...this._listeners.keys()]}listenerCount(r){let e=this._listeners.get(r);return e?e.length:0}listeners(r){let e=this._listeners.get(r);return e?e.map(t=>t.callable):[]}addListener(r,e){return this.on(r,e)}removeListener(r,e){return this.off(r,e)}removeAllListeners(r){return r?this._listeners.delete(r):this._listeners.clear(),this}};var Y=class extends ge{constructor(){super(...arguments);this._nodes=[];this._edges=[];this._nodeIndexByNodeId={};this._cancelSimulation=!1;this._schedulerPort=null}terminate(){this._cancelSimulation=!0,this._schedulerPort?.close(),this._schedulerPort=null,this.removeAllListeners()}_scheduleNext(e){if(typeof MessageChannel<"u"){let t=new MessageChannel;this._schedulerPort=t.port2,t.port1.onmessage=()=>{this._schedulerPort=null,e()},t.port2.postMessage(null)}else setTimeout(e,0)}_rebuildNodeIndex(){this._nodeIndexByNodeId={};for(let e=0;e=i)continue;p<1&&(p=1);let y=-n*s/p;g.vx+=f*y,g.vy+=h*y}}}return o.initialize=s=>{t=s},o}var re=class extends Y{constructor(e){super();this._isDragging=!1;this._isStabilizing=!1;this.type="force";this._settings={...ee,...e},this.clearData()}setSettings(e){let t=e;this._initialSettings||(this._initialSettings=Object.assign(C(ee),t));let i=C(this._settings);if(Object.assign(this._settings,t),j(this._settings,i))return;this._applySettingsToSimulation(t),this.emit("settings-update",{settings:{type:"force",options:this._settings}}),i.isPhysicsEnabled&&!t.isPhysicsEnabled?this._simulation.stop():this._settings.isSimulatingOnSettingsUpdate&&this._nodes.length>0&&this.activateSimulation()}setupData(e){this.clearData(),this._initializeNewData(e),this._settings.isSimulatingOnDataUpdate&&(this._updateSimulationData(),this._runSimulation())}mergeData(e){this._initializeNewData(e),this._settings.isPhysicsEnabled||this._pinNodes(),this._settings.isSimulatingOnDataUpdate&&(this._updateSimulationData(),this.activateSimulation())}updateData(e){let t=new Set(e.nodes.map(s=>s.id)),i=this._nodes.filter(s=>t.has(s.id)),o=e.nodes.filter(s=>this._nodeIndexByNodeId[s.id]===void 0);this._nodes=[...i,...o],this._rebuildNodeIndex(),this._edges=e.edges,this._settings.isSimulatingOnSettingsUpdate&&(this._updateSimulationData(),this.activateSimulation())}deleteData(e){if(e.nodeIds){let t=new Set(e.nodeIds);this._nodes=this._nodes.filter(i=>!t.has(i.id))}if(e.edgeIds){let t=new Set(e.edgeIds);this._edges=this._edges.filter(i=>!t.has(i.id))}this._rebuildNodeIndex(),this._settings.isSimulatingOnDataUpdate&&(this._updateSimulationData(),this.activateSimulation())}patchData(e){if(e.nodes){let t={};for(let i=0;i0&&this.activateSimulation()}terminate(){super.terminate(),this._simulation?.stop()}_resetSimulation(){this._simulation&&(this._simulation.stop(),this._simulation.on("tick",null).on("end",null)),this._linkForce=De(this._edges).id(e=>e.id),this._simulation=Me(this._nodes).force("link",this._linkForce).stop(),this._applySettingsToSimulation(this._settings),this._simulation.on("tick",()=>{this.emit("simulation-step",{nodes:this._nodes,edges:this._edges})}),this._simulation.on("end",()=>{this._isDragging=!1,this._isStabilizing=!1,this.emit("simulation-end",{nodes:this._nodes,edges:this._edges}),this._settings.isPhysicsEnabled||this._pinNodes()})}_runSimulation(e){if(this._isStabilizing||this._cancelSimulation)return;(this._settings.isPhysicsEnabled||e?.isUpdatingSettings)&&this._unpinNodes(),this.emit("simulation-start",void 0),this._isStabilizing=!0,this._simulation.alpha(this._settings.alpha.alpha).alphaTarget(this._settings.alpha.alphaTarget).stop();let t=Math.min(jt,Math.ceil(Math.log(this._settings.alpha.alphaMin)/Math.log(1-this._settings.alpha.alphaDecay))),i=-1,o=0,s=()=>{if(this._cancelSimulation){this._isStabilizing=!1,this._cancelSimulation=!1;return}let a=Math.min(o+Xt,t);for(;oi&&(i=u,this.emit("simulation-progress",{nodes:this._nodes,edges:this._edges,progress:u/100}))}othis._edges)):this._simulation.force("edgeMidpointRepulsion",null)}if(e.manyBody===null&&(this._simulation.force("charge",null),this._simulation.force("edgeMidpointRepulsion",null)),e.positioning?.forceX){let t=we(e.positioning.forceX.x).strength(e.positioning.forceX.strength);this._simulation.force("x",t)}if(e.positioning?.forceX===null&&this._simulation.force("x",null),e.positioning?.forceY){let t=Ue(e.positioning.forceY.y).strength(e.positioning.forceY.strength);this._simulation.force("y",t)}if(e.positioning?.forceY===null&&this._simulation.force("y",null),e.centering){let t=Ee(e.centering.x,e.centering.y).strength(e.centering.strength);this._simulation.force("center",t)}e.centering===null&&this._simulation.force("center",null)}};var B=class extends Error{constructor(r){super(r),this.message=r,Object.setPrototypeOf(this,new.target.prototype),this.name=this.constructor.name}};var ke=(n,r,e)=>{let t=n.createShader(e==="vertex"?n.VERTEX_SHADER:n.FRAGMENT_SHADER);if(!t)throw new B("Failed to create shader.");if(n.shaderSource(t,r),n.compileShader(t),!n.getShaderParameter(t,n.COMPILE_STATUS)){let i=n.getShaderInfoLog(t);throw n.deleteShader(t),new B(`Failed to compile shader: ${i}`)}return t};var _t=`#version 300 es\n\nin vec2 aPosition;\n\nvoid main() {\n gl_Position = vec4(aPosition, 0.0, 1.0);\n}\n`;var yt=`#version 300 es\n\nprecision highp float;\n\nuniform sampler2D uState;\nuniform sampler2D uFixed;\nuniform sampler2D uTreeData;\nuniform sampler2D uTreeChildren;\nuniform sampler2D uTreeGeometry;\nuniform sampler2D uAdjOffsets;\nuniform sampler2D uAdjEdges;\n\nuniform int uNodeCount;\nuniform int uTexWidth;\nuniform float uAlpha;\nuniform float uDamping;\n\nuniform float uManyBodyStrength;\nuniform float uTheta2;\nuniform float uDistanceMin2;\nuniform float uDistanceMax2;\nuniform int uTreeNodeCount;\nuniform int uTreeTexWidth;\n\nuniform int uAdjOffsetsTexWidth;\nuniform int uAdjEdgesTexWidth;\n\nuniform vec2 uCenter;\nuniform float uCenterStrength;\n\nuniform float uCollisionRadius;\nuniform float uCollisionStrength;\n\nuniform float uForceXTarget;\nuniform float uForceXStrength;\nuniform float uForceYTarget;\nuniform float uForceYStrength;\n\nuniform float uHasManyBody;\nuniform float uHasLinks;\nuniform float uHasCentering;\nuniform float uHasCollision;\nuniform float uHasPositioning;\n\nout vec4 fragColor;\n\nivec2 texCoord(int idx, int tw) {\n return ivec2(idx % tw, idx / tw);\n}\n\nvoid main() {\n ivec2 fc = ivec2(gl_FragCoord.xy);\n int nodeId = fc.y * uTexWidth + fc.x;\n\n if (nodeId >= uNodeCount) {\n fragColor = vec4(0.0);\n return;\n }\n\n vec4 fixedData = texelFetch(uFixed, fc, 0);\n if (fixedData.x > 0.5) {\n fragColor = vec4(fixedData.yz, 0.0, 0.0);\n return;\n }\n\n vec4 state = texelFetch(uState, fc, 0);\n vec2 pos = state.xy;\n vec2 vel = state.zw;\n\n if (uHasManyBody > 0.5 && uTreeNodeCount > 0) {\n int stack[128];\n int top = 0;\n stack[top++] = 0;\n\n while (top > 0) {\n int idx = stack[--top];\n vec4 data = texelFetch(uTreeData, texCoord(idx, uTreeTexWidth), 0);\n float w = data.w;\n\n if (w < -0.5) {\n int bodyIdx = int(-w - 0.5);\n if (bodyIdx != nodeId) {\n vec2 delta = data.xy - pos;\n float distSq = dot(delta, delta);\n\n if (distSq < 1e-8) {\n delta = vec2(float(nodeId) * 1e-4 - float(bodyIdx) * 1e-4 + 1e-4, 1e-4);\n distSq = dot(delta, delta);\n }\n\n if (distSq < uDistanceMax2) {\n float l = distSq;\n if (l < uDistanceMin2) l = sqrt(uDistanceMin2 * l);\n vel += delta * (data.z * uAlpha / max(l, 1e-6));\n }\n }\n } else {\n vec2 delta = data.xy - pos;\n float distSq = dot(delta, delta);\n\n if (distSq > 0.0 && w * w / distSq < uTheta2) {\n if (distSq < uDistanceMax2) {\n float l = distSq;\n if (l < uDistanceMin2) l = sqrt(uDistanceMin2 * l);\n vel += delta * (data.z * uAlpha / max(l, 1e-6));\n }\n } else {\n vec4 ch = texelFetch(uTreeChildren, texCoord(idx, uTreeTexWidth), 0);\n if (ch.w >= 0.0 && top < 64) stack[top++] = int(ch.w + 0.5);\n if (ch.z >= 0.0 && top < 64) stack[top++] = int(ch.z + 0.5);\n if (ch.y >= 0.0 && top < 64) stack[top++] = int(ch.y + 0.5);\n if (ch.x >= 0.0 && top < 64) stack[top++] = int(ch.x + 0.5);\n }\n }\n }\n }\n\n if (uHasCollision > 0.5 && uCollisionRadius > 0.0 && uTreeNodeCount > 0) {\n float collisionDiam = uCollisionRadius * 2.0;\n vec2 predictedPos = state.xy + state.zw;\n int stack[64];\n int top = 0;\n stack[top++] = 0;\n\n while (top > 0) {\n int idx = stack[--top];\n vec4 data = texelFetch(uTreeData, texCoord(idx, uTreeTexWidth), 0);\n float w = data.w;\n\n if (w < -0.5) {\n int bodyIdx = int(-w - 0.5);\n if (bodyIdx != nodeId && bodyIdx < uNodeCount) {\n vec2 delta = data.xy - predictedPos;\n float dist = length(delta);\n\n if (dist < collisionDiam && dist > 0.0) {\n float push = (collisionDiam - dist) * uCollisionStrength;\n vel -= (delta / dist) * push * 0.5;\n }\n }\n } else {\n vec4 geo = texelFetch(uTreeGeometry, texCoord(idx, uTreeTexWidth), 0);\n float cellSize = geo.z;\n vec2 nearest = clamp(predictedPos, geo.xy, geo.xy + cellSize);\n float distToCell = length(nearest - predictedPos);\n\n if (distToCell < collisionDiam) {\n vec4 ch = texelFetch(uTreeChildren, texCoord(idx, uTreeTexWidth), 0);\n if (ch.w >= 0.0 && top < 64) stack[top++] = int(ch.w + 0.5);\n if (ch.z >= 0.0 && top < 64) stack[top++] = int(ch.z + 0.5);\n if (ch.y >= 0.0 && top < 64) stack[top++] = int(ch.y + 0.5);\n if (ch.x >= 0.0 && top < 64) stack[top++] = int(ch.x + 0.5);\n }\n }\n }\n }\n\n if (uHasLinks > 0.5) {\n vec4 offData = texelFetch(uAdjOffsets, texCoord(nodeId, uAdjOffsetsTexWidth), 0);\n int start = int(offData.x + 0.5);\n int count = int(offData.y + 0.5);\n\n for (int e = 0; e < count; e++) {\n vec4 edgeData = texelFetch(uAdjEdges, texCoord(start + e, uAdjEdgesTexWidth), 0);\n int targetId = int(edgeData.x + 0.5);\n float restDist = edgeData.y;\n float strength = edgeData.z;\n float dirBias = edgeData.w;\n\n vec4 targetState = texelFetch(uState, texCoord(targetId, uTexWidth), 0);\n vec2 delta = (targetState.xy + targetState.zw) - (state.xy + state.zw);\n float d = length(delta);\n\n if (d < 1e-6) {\n delta = vec2(1e-3, 1e-3);\n d = length(delta);\n }\n\n float scale = (d - restDist) / d * uAlpha * strength;\n vel += delta * scale * dirBias;\n }\n }\n\n if (uHasCentering > 0.5) {\n vel += (uCenter - pos) * uCenterStrength * uAlpha;\n }\n\n if (uHasPositioning > 0.5) {\n vel.x += (uForceXTarget - pos.x) * uForceXStrength * uAlpha;\n vel.y += (uForceYTarget - pos.y) * uForceYStrength * uAlpha;\n }\n\n vel *= uDamping;\n pos += vel;\n\n fragColor = vec4(pos, vel);\n}\n`;function It(n,r){let e=n.length;if(e===0)return{treeData:new Float32Array(0),treeChildren:new Float32Array(0),treeGeometry:new Float32Array(0),nodeCount:0,texWidth:1};let t=1/0,i=1/0,o=-1/0,s=-1/0;for(let v=0;vo&&(o=S),A>s&&(s=A)}let a=Math.max(o-t,s-i);a<1e-6&&(a=1),a*=1.01;let u=(t+o)*.5,l=(i+s)*.5,c=a*.5,_=u-c,m=l-c,d=[];function g(v){let S=d.length;return d.push({cx:0,cy:0,charge:0,size:v,bodyIndex:-1,children:[null,null,null,null]}),S}let f=g(a),h=[_],p=[m];function y(v,S,A,K,w){let U=A+w*.5,G=K+w*.5,X=v>=U?1:0;return(S>=G?1:0)*2+X}function T(v,S,A,K){let w=K*.5,U=v&1?S+w:S,G=v&2?A+w:A;return{cx0:U,cy0:G,csz:w}}function x(v,S,A){let K=f,w=_,U=m,G=a;for(let X=0;X<50;X++){let L=d[K];if(L.bodyIndex===-1&&L.children[0]===null&&L.children[1]===null&&L.children[2]===null&&L.children[3]===null){L.bodyIndex=v,L.cx=S,L.cy=A,L.charge=r;return}if(L.bodyIndex>=0){let ve=L.bodyIndex,se=L.cx,ae=L.cy;L.bodyIndex=-1;let W=y(se,ae,w,U,G),{cx0:bt,cy0:Dt,csz:At}=T(W,w,U,G),V=g(At);h[V]=bt,p[V]=Dt,L.children[W]=V,d[V].bodyIndex=ve,d[V].cx=se,d[V].cy=ae,d[V].charge=r}let z=y(S,A,w,U,G);if(L.children[z]===null){let{cx0:ve,cy0:se,csz:ae}=T(z,w,U,G),W=g(ae);h[W]=ve,p[W]=se,L.children[z]=W,d[W].bodyIndex=v,d[W].cx=S,d[W].cy=A,d[W].charge=r;return}let{cx0:vt,cy0:Et,csz:Nt}=T(z,w,U,G);K=L.children[z],w=vt,U=Et,G=Nt}}for(let v=0;v=0)return;let A=0,K=0,w=0,U=0;for(let G=0;G<4;G++){let X=S.children[G];if(X===null)continue;I(X);let L=d[X],z=Math.abs(L.charge);A+=L.charge,K+=L.cx*z,w+=L.cy*z,U+=z}U>0&&(S.cx=K/U,S.cy=w/U),S.charge=A}I(f);let E=d.length,P=Math.ceil(Math.sqrt(E)),D=P*P,N=new Float32Array(D*4),b=new Float32Array(D*4),M=new Float32Array(D*4);for(let v=0;v=0?N[A+3]=-(S.bodyIndex+1):N[A+3]=S.size,b[A]=S.children[0]!==null?S.children[0]:-1,b[A+1]=S.children[1]!==null?S.children[1]:-1,b[A+2]=S.children[2]!==null?S.children[2]:-1,b[A+3]=S.children[3]!==null?S.children[3]:-1,M[A]=h[v]??0,M[A+1]=p[v]??0,M[A+2]=S.size,M[A+3]=0}for(let v=E;v0&&this.activateSimulation()}setupData(e){this.clearData(),this._initializeNewData(e),this._settings.isSimulatingOnDataUpdate&&this._runSimulation()}mergeData(e){this._initializeNewData(e),this._settings.isPhysicsEnabled||this._pinNodes(),this._settings.isSimulatingOnDataUpdate&&this.activateSimulation()}updateData(e){let t=new Set(e.nodes.map(s=>s.id)),i=this._nodes.filter(s=>t.has(s.id)),o=e.nodes.filter(s=>this._nodeIndexByNodeId[s.id]===void 0);this._nodes=[...i,...o],this._rebuildNodeIndex(),this._edges=e.edges,this._cachedAdjacency=null,this._settings.isSimulatingOnSettingsUpdate&&this.activateSimulation()}deleteData(e){if(e.nodeIds){let t=new Set(e.nodeIds);this._nodes=this._nodes.filter(i=>!t.has(i.id))}if(e.edgeIds){let t=new Set(e.edgeIds);this._edges=this._edges.filter(i=>!t.has(i.id))}this._rebuildNodeIndex(),this._cachedAdjacency=null,this._settings.isSimulatingOnDataUpdate&&this.activateSimulation()}patchData(e){if(e.nodes){let t={};for(let i=0;i0&&this.activateSimulation()}terminate(){super.terminate();let e=this._gl;e&&(e.deleteBuffer(this._quadBuffer),e.deleteVertexArray(this._quadVAO),e.deleteProgram(this._forceProgram),e.deleteTexture(this._stateTexA),e.deleteTexture(this._stateTexB),e.deleteTexture(this._fixedTex),e.deleteTexture(this._treeDataTexture),e.deleteTexture(this._treeChildrenTexture),e.deleteTexture(this._treeGeometryTexture),e.deleteTexture(this._adjOffsetsTexture),e.deleteTexture(this._adjEdgesTexture),e.deleteFramebuffer(this._fboA),e.deleteFramebuffer(this._fboB),e.getExtension("WEBGL_lose_context")?.loseContext())}reheat(){let e=this._settings.alpha;this._currentAlpha=e.alpha,this._totalSteps=Math.min(St,Math.ceil(Math.log(e.alphaMin)/Math.log(1-e.alphaDecay))),this._currentStep=0,!this._isStabilizing&&(this._ensurePositions(),this._uploadDataToGPU(),this._cachedAdjacency||this._buildAndUploadAdjacency(),this._startSimulationLoop())}_runSimulation(){this._isStabilizing||this._cancelSimulation||(this._ensurePositions(),this._uploadDataToGPU(),this._buildAndUploadAdjacency(),this._startSimulationLoop())}_startDragLoop(){if(this._dragLoopRunning)return;this._dragLoopRunning=!0;let e=this._settings.alpha.alphaDecay,t=this._settings.alpha.alphaMin;this._dragAlpha=.3,this._dragNeedsReheat=!1;let i=()=>{if(!this._isDragging){this._dragLoopRunning=!1;return}if(this._dragNeedsReheat&&(this._dragAlpha=.3,this._dragNeedsReheat=!1),this._dragAlpha+=(0-this._dragAlpha)*e,this._dragAlpha{if(e!==this._simulationGeneration)return;if(this._cancelSimulation){this._isStabilizing=!1,this._cancelSimulation=!1,this.emit("simulation-end",{nodes:this._nodes,edges:this._edges});return}if(this._readbackFromGPU(),this._pendingRestart){this._isStabilizing=!1,this._pendingRestart=!1,this._ensurePositions(),this._uploadDataToGPU(),this._cachedAdjacency||this._buildAndUploadAdjacency(),this._startSimulationLoop();return}this._flushDirtyNodes(),this._buildAndUploadQuadTree();let u=Math.min(this._currentStep+Ht,this._totalSteps);for(;this._currentSteps&&(s=l,this.emit("simulation-progress",{nodes:this._nodes,edges:this._edges,progress:l/100})),this._currentStep0&&(i=i.concat(s))}let o=It(i,t);this._uploadTexture(this._treeDataTexture,o.treeData,o.texWidth),this._uploadTexture(this._treeChildrenTexture,o.treeChildren,o.texWidth),this._uploadTexture(this._treeGeometryTexture,o.treeGeometry,o.texWidth),this._treeTexWidth=o.texWidth,this._treeNodeCount=o.nodeCount}_getEdgeMidpoints(){let e=[];for(let t=0;t0?d.distanceMax:Fe(this._settings.links?.distance??50);t.uniform1f(s.uDistanceMax2,f*f),t.uniform1i(s.uTreeNodeCount,this._treeNodeCount),t.uniform1i(s.uTreeTexWidth,this._treeTexWidth)}let u=this._cachedAdjacency!==null&&this._edges.length>0;t.uniform1f(s.uHasLinks,u?1:0),u&&(t.uniform1i(s.uAdjOffsetsTexWidth,this._cachedAdjacency.offsetsTexWidth),t.uniform1i(s.uAdjEdgesTexWidth,this._cachedAdjacency.edgesTexWidth)),t.uniform1f(s.uHasCentering,0);let l=this._settings.collision!==null&&this._settings.collision!==void 0;t.uniform1f(s.uHasCollision,l?1:0),l&&(t.uniform1f(s.uCollisionRadius,this._settings.collision.radius),t.uniform1f(s.uCollisionStrength,this._settings.collision.strength));let c=this._settings.positioning!==null&&this._settings.positioning!==void 0;if(t.uniform1f(s.uHasPositioning,c?1:0),c){let d=this._settings.positioning;t.uniform1f(s.uForceXTarget,d.forceX?.x??0),t.uniform1f(s.uForceXStrength,d.forceX?.strength??0),t.uniform1f(s.uForceYTarget,d.forceY?.y??0),t.uniform1f(s.uForceYStrength,d.forceY?.strength??0)}let _=this._pingPong?this._stateTexA:this._stateTexB,m=this._pingPong?this._fboB:this._fboA;t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,_),t.uniform1i(s.uState,0),t.activeTexture(t.TEXTURE1),t.bindTexture(t.TEXTURE_2D,this._fixedTex),t.uniform1i(s.uFixed,1),t.activeTexture(t.TEXTURE2),t.bindTexture(t.TEXTURE_2D,this._treeDataTexture),t.uniform1i(s.uTreeData,2),t.activeTexture(t.TEXTURE3),t.bindTexture(t.TEXTURE_2D,this._treeChildrenTexture),t.uniform1i(s.uTreeChildren,3),t.activeTexture(t.TEXTURE4),t.bindTexture(t.TEXTURE_2D,this._adjOffsetsTexture),t.uniform1i(s.uAdjOffsets,4),t.activeTexture(t.TEXTURE5),t.bindTexture(t.TEXTURE_2D,this._adjEdgesTexture),t.uniform1i(s.uAdjEdges,5),t.activeTexture(t.TEXTURE6),t.bindTexture(t.TEXTURE_2D,this._treeGeometryTexture),t.uniform1i(s.uTreeGeometry,6),t.bindFramebuffer(t.FRAMEBUFFER,m),t.viewport(0,0,this._texWidth,this._texWidth),t.bindVertexArray(this._quadVAO),t.drawArrays(t.TRIANGLE_STRIP,0,4),t.bindVertexArray(null),t.bindFramebuffer(t.FRAMEBUFFER,null),this._pingPong=!this._pingPong}_readbackFromGPU(){let e=this._gl,t=this._nodes.length;if(t===0)return;let i=this._pingPong?this._fboA:this._fboB,o=this._texWidth*this._texWidth,s=new Float32Array(o*4);e.bindFramebuffer(e.FRAMEBUFFER,i),e.readPixels(0,0,this._texWidth,this._texWidth,e.RGBA,e.FLOAT,s),e.bindFramebuffer(e.FRAMEBUFFER,null);for(let a=0;as.id)),i=this._nodes.filter(s=>t.has(s.id)),o=e.nodes.filter(s=>this._nodeIndexByNodeId[s.id]===void 0);this._nodes=[...i,...o],this._edges=e.edges,this._rebuildNodeIndex(),this._calculateAndEmit()}deleteData(e){if(e.nodeIds){let t=new Set(e.nodeIds);this._nodes=this._nodes.filter(i=>!t.has(i.id))}if(e.edgeIds){let t=new Set(e.edgeIds);this._edges=this._edges.filter(i=>!t.has(i.id))}this._rebuildNodeIndex(),this._calculateAndEmit()}patchData(e){if(e.nodes)for(let t=0;t0&&this._calculateAndEmit()}terminate(){this._pendingRecalculation=!1,super.terminate()}_calculateAndEmit(){if(!(this._nodes.length===0||this._cancelSimulation)){if(this._isCalculating){this._pendingRecalculation=!0;return}this._isCalculating=!0,this.emit("simulation-start",void 0),this.calculatePositions(this._nodes,this._edges,e=>{this.emit("simulation-progress",{nodes:this._nodes,edges:this._edges,progress:e})},()=>this._cancelSimulation,()=>{this._isCalculating=!1,this._cancelSimulation||this.emit("simulation-end",{nodes:this._nodes,edges:this._edges}),this._cancelSimulation=!1,this._pendingRecalculation&&(this._pendingRecalculation=!1,this._calculateAndEmit())})}}_emitProgress(e,t,i,o){let s=Math.round(e*100/t);return s>i?(o(s/100),s):i}};var Ie=class extends H{constructor(e){super();this.type="circular";this._config={...pt,...e}}calculatePositions(e,t,i,o,s){let a=2*Math.PI/e.length,u=-1,l=0,c=()=>{if(o()){s();return}let _=Math.min(l+ye,e.length);for(;l<_;l++)e[l].x=this._config.centerX+this._config.radius*Math.cos(a*l),e[l].y=this._config.centerY+this._config.radius*Math.sin(a*l);l{if(o()){s();return}let m=Math.min(c+ye,e.length);for(;c{if(o()||g>=l.length){!o()&&this._config.reversed&&this._applyReversal(e,c,_),s();return}let h=this._assignLevels(l[g],a,u),p=Math.max(...Array.from(h.values()).map(T=>T.length));h.size*this._config.levelGap>_&&(_=h.size*this._config.levelGap);let y=g===0?0:this._config.treeGap+c;g>0&&(y+=(p-1)*this._config.nodeGap/2);for(let T=0;Tc&&(c=b),N!==void 0&&(e[N].x=this._config.orientation==="horizontal"?x:b,e[N].y=this._config.orientation==="horizontal"?b:x),m++}}g++,g0;){let c=l.pop();if(c===void 0)continue;u.push(c);let _=t.get(c)??[];for(let m=0;m<_.length;m++)i.has(_[m])||(i.add(_[m]),l.push(_[m]))}o.push(u)}return o}_assignLevels(e,t,i){let o=new Map,s=new Set,a=e.find(l=>(i.get(l)??0)===0);a===void 0&&(a=e.reduce((l,c)=>(i.get(c)??0)<(i.get(l)??0)?c:l));let u=[[a,0]];for(let[l,c]of u){if(s.has(l))continue;s.add(l),o.has(c)?o.get(c)?.push(l):o.set(c,[l]);let _=t.get(l)??[];for(let m=0;m<_.length;m++)u.push([_[m],c+1])}return o}_getEdgeEndpointId(e){return typeof e=="object"?e.id:e}};var Te=class{static create(r){switch(r?.type){case"circular":return new Ie(r.options);case"grid":return new xe(r.options);case"hierarchical":return new Se(r.options);default:{let e=r?.options;if(e?.useGPU)try{return new _e(e)}catch{return console.warn("WebGL2 unavailable, falling back to CPU force layout engine."),new re(e)}return new re(e)}}}};function Tt(n,r){switch(r.type){case"Set Data":n.setupData(r.data);break;case"Add Data":n.mergeData(r.data);break;case"Update Data":n.updateData(r.data);break;case"Delete Data":n.deleteData(r.data);break;case"Patch Data":n.patchData(r.data);break;case"Clear Data":n.clearData();break;case"Activate Simulation":n.activateSimulation();break;case"Stop Simulation":n.stopSimulation();break;case"Start Drag Node":n.startDragNode();break;case"Drag Node":n.dragNode(r.data.id,{x:r.data.x,y:r.data.y});break;case"End Drag Node":n.endDragNode(r.data.id);break;case"Fix Nodes":n.fixNodes(r.data.nodes);break;case"Release Nodes":n.releaseNodes(r.data.nodes);break;default:break}}var q=null,$=n=>postMessage(n);function Vt(n){n.on("simulation-start",()=>$({type:"simulation-start"})),n.on("simulation-progress",r=>$({type:"simulation-progress",data:r})),n.on("simulation-end",r=>$({type:"simulation-end",data:r})),n.on("simulation-step",r=>$({type:"simulation-step",data:r})),n.on("node-drag",r=>$({type:"node-drag",data:r})),n.on("settings-update",r=>$({type:"settings-update",data:r}))}$({type:"ready"});addEventListener("message",({data:n})=>{if(n.type==="Set Settings"){let r=n.data;if(r.type===q?.type&&r.options){q?.setSettings(r.options);return}q?.removeAllListeners(),q?.terminate(),q=Te.create(r),Vt(q);return}q&&Tt(q,n)});})();\n'],{type:"text/javascript"})),e=new Worker(this._blobUrl)}catch(t){return void this._activateFallback(t)}this._worker=e,e.onerror=t=>{this._ready?this._warnWorkerError(t):this._activateFallback(t)},e.onmessage=this._handleWorkerMessage,this._readyTimer=setTimeout(()=>{this._ready||this._fallback||this._activateFallback(new Error("Web Worker readiness handshake timed out."))},3e3),this.emitToWorker({type:ms.SetSettings,data:t})}setupData(t){this.emitToWorker({type:ms.SetupData,data:t})}mergeData(t){this.emitToWorker({type:ms.MergeData,data:t})}updateData(t){this.emitToWorker({type:ms.UpdateData,data:t})}deleteData(t){this.emitToWorker({type:ms.DeleteData,data:t})}patchData(t){this.emitToWorker({type:ms.PatchData,data:t})}clearData(){this.emitToWorker({type:ms.ClearData})}activateSimulation(){this.emitToWorker({type:ms.ActivateSimulation})}stopSimulation(){this.emitToWorker({type:ms.StopSimulation})}updateSimulation(t,e){this.emitToWorker({type:ms.UpdateSimulation,data:{nodes:t,edges:e}})}startDragNode(){this.emitToWorker({type:ms.StartDragNode})}dragNode(t,e){this.emitToWorker({type:ms.DragNode,data:Object.assign({id:t},e)})}endDragNode(t){this.emitToWorker({type:ms.EndDragNode,data:{id:t}})}fixNodes(t){this.emitToWorker({type:ms.FixNodes,data:{nodes:t}})}releaseNodes(t){this.emitToWorker({type:ms.ReleaseNodes,data:{nodes:t}})}setSettings(t){this.emitToWorker({type:ms.SetSettings,data:t})}isSimulationRunning(){return this._fallback?this._fallback.isSimulationRunning():this._isSimulationRunning}terminate(){var t;void 0!==this._readyTimer&&(clearTimeout(this._readyTimer),this._readyTimer=void 0),this._revokeBlobUrl(),this._worker&&(this._worker.onmessage=null,this._worker.onerror=null,this._worker.terminate(),this._worker=void 0),null===(t=this._fallback)||void 0===t||t.terminate(),this.removeAllListeners()}emitToWorker(t){var e;this._fallback?this._applyToFallback(this._fallback,t):(this._ready||this._pending.push(t),null===(e=this._worker)||void 0===e||e.postMessage(t))}_markReady(){this._ready||(this._ready=!0,this._pending=[],void 0!==this._readyTimer&&(clearTimeout(this._readyTimer),this._readyTimer=void 0),this._revokeBlobUrl())}_activateFallback(t){if(this._fallback)return;if(this._warnFallback(t),void 0!==this._readyTimer&&(clearTimeout(this._readyTimer),this._readyTimer=void 0),this._worker){this._worker.onmessage=null,this._worker.onerror=null;try{this._worker.terminate()}catch(t){}this._worker=void 0}this._revokeBlobUrl();const e=new ps(this._settings);this._wireFallbackEvents(e),this._fallback=e;const i=this._pending;this._pending=[];for(const t of i)this._applyToFallback(e,t)}_wireFallbackEvents(t){kn(t,this,t=>{this._isSimulationRunning=t})}_applyToFallback(t,e){e.type!==ms.SetSettings?function(t,e){switch(e.type){case ms.SetupData:t.setupData(e.data);break;case ms.MergeData:t.mergeData(e.data);break;case ms.UpdateData:t.updateData(e.data);break;case ms.DeleteData:t.deleteData(e.data);break;case ms.PatchData:t.patchData(e.data);break;case ms.ClearData:t.clearData();break;case ms.ActivateSimulation:t.activateSimulation();break;case ms.StopSimulation:t.stopSimulation();break;case ms.StartDragNode:t.startDragNode();break;case ms.DragNode:t.dragNode(e.data.id,{x:e.data.x,y:e.data.y});break;case ms.EndDragNode:t.endDragNode(e.data.id);break;case ms.FixNodes:t.fixNodes(e.data.nodes);break;case ms.ReleaseNodes:t.releaseNodes(e.data.nodes)}}(t,e):t.setSettings(e.data)}_revokeBlobUrl(){this._blobUrl&&(URL.revokeObjectURL(this._blobUrl),this._blobUrl=void 0)}_warnWorkerError(t){this._hasWarned||(this._hasWarned=!0,console.warn("Orb: the layout Web Worker errored after it had started. The current layout is kept and no further updates will be simulated; reload the graph to recover.",t))}_warnFallback(t){this._hasWarned||(this._hasWarned=!0,console.warn("Orb: the layout Web Worker could not start; falling back to the main-thread simulator. Layout is still correct but runs on the main thread. Under a strict Content Security Policy, allow blob workers (e.g. `worker-src blob:` or `child-src blob:`) to re-enable off-main-thread layout.",t))}}class xs{static getSimulator(t){const e=Object.assign({type:"force"},t),i=e.options;if("force"===e.type&&(null==i?void 0:i.useGPU))return new ps(e);try{if("undefined"!=typeof Worker)return new ys(e);throw new Error("WebWorkers are unavailable in your environment.")}catch(t){return console.error("Could not create simulator in a WebWorker context. All calculations will be done in the main thread.",t),new ps(e)}}}const bs=t=>{const e=t.start,i=t.end;return e{if(!this.sortBy)return 0;const i=this.getOne(t),n=this.getOne(e);return void 0===i||void 0===n?0:this.sortBy(i,n)})}get size(){return this.entityById.size}}const ws=(...t)=>{const e=t.reduce((t,e)=>t.concat(e),[]);return Array.from(new Set(e))};class Ts extends d{constructor(t,e){var i,n;super(),this._nodes=new Ss({getId:t=>t.getId(),sortBy:(t,e)=>{var i,n;return(null!==(i=t.getStyle().zIndex)&&void 0!==i?i:0)-(null!==(n=e.getStyle().zIndex)&&void 0!==n?n:0)}}),this._edges=new Ss({getId:t=>t.getId(),sortBy:(t,e)=>{var i,n;return(null!==(i=t.getStyle().zIndex)&&void 0!==i?i:0)-(null!==(n=e.getStyle().zIndex)&&void 0!==n?n:0)}}),this._styleVersion=0,this._bumpStyleVersion=()=>{this._styleVersion++},this._update=t=>{if(t&&"type"in t&&"options"in t&&"isSingle"in t.options){if("node"===t.type&&t.options.isSingle){const e=this._nodes.getAll();for(let i=0;it.isSelected())}getSelectedEdges(){return this.getEdges(t=>t.isSelected())}getHoveredNodes(){return this.getNodes(t=>t.isHovered())}getHoveredEdges(){return this.getEdges(t=>t.isHovered())}getNodePositions(t){const e=this.getNodes(t),i=new Array(e.length);for(let t=0;tt.id),e=this._edges.getAll().map(t=>t.id);this.remove({nodeIds:t,edgeIds:e})}removeAllEdges(){const t=this._edges.getAll().map(t=>t.id);this.remove({edgeIds:t})}removeAllNodes(){this.removeAll()}isEqual(t){if(this.getNodeCount()!==t.getNodeCount())return!1;if(this.getEdgeCount()!==t.getEdgeCount())return!1;const e=this.getNodes();for(let i=0;ii.x&&(i.x=s+r),s-ri.y&&(i.y=o+r),o-r=0;i--)if(e[i].includesPoint(t))return e[i]}getNearestEdge(t,e=3){let i,n=e;const s=this.getEdges();for(let e=0;e{const n=i.getPosition();if(void 0===n.x||void 0===n.y)return!1;const s={x:n.x,y:n.y};return a(e,s)&&t.contains(s)})}getStyleVersion(){return this._styleVersion}_insertNodes(t){const e=new Array(t.length);for(let i=0;i{var t,e;return null===(e=null===(t=this._settings)||void 0===t?void 0:t.onLoadedImages)||void 0===e?void 0:e.call(t)},listeners:[this._update],onStateChange:this._bumpStyleVersion});this._nodes.setMany(e)}_insertEdges(t){const e=[];for(let i=0;i{var t,e;return null===(e=null===(t=this._settings)||void 0===t?void 0:t.onLoadedImages)||void 0===e?void 0:e.call(t)},listeners:[this._update],onStateChange:this._bumpStyleVersion}))}this._nodes.setMany(e)}_upsertEdges(t){const e=[],i=[];for(let n=0;n{var e;const i=new Array(t.length),n=(t=>{var e;const i={},n=new Set;for(let s=0;se+1);continue}if(r<=1)continue;const a=[];r%2!=0&&a.push(0);for(let t=2;t<=r;t+=2)a.push(t/2),a.push(t/2*-1);s[e]=a}return s})(t);for(let s=0;s{var t,e;null===(e=null===(t=this._settings)||void 0===t?void 0:t.onLoadedImages)||void 0===e||e.call(t)}),this._nodes.sort(),this._edges.sort()}}const Es=(t,e)=>{var i;null===(i=null==e?void 0:e.cascade)||void 0===i||i?Rs(t,r.SELECTED,{isStateOverride:!0}):t.setState(r.SELECTED,{isNotifySkipped:!0})},Ps=(t,e)=>{var i;null===(i=null==e?void 0:e.cascade)||void 0===i||i?Os(t,r.SELECTED,{isStateOverride:!0}):t.setState(r.SELECTED,{isNotifySkipped:!0})},As=(t,e)=>{var i;null===(i=null==e?void 0:e.cascade)||void 0===i||i?Rs(t,r.NONE,{isStateOverride:!0}):t.clearState()},Cs=(t,e)=>{var i;null===(i=null==e?void 0:e.cascade)||void 0===i||i?Os(t,r.NONE,{isStateOverride:!0}):t.clearState()},Ms=(t,e,i)=>{Ds(t),Es(e,i)},Ns=(t,e,i)=>{Ds(t),Ps(e,i)},Ds=t=>{const e=t.getNodes(t=>t.isSelected());for(let t=0;tt.isSelected());for(let t=0;t{Rs(t,r.HOVERED)},Ls=t=>{const e=t.getNodes(t=>t.isHovered());for(let t=0;tt.isHovered());for(let t=0;t{ks(t,i)&&t.setState(e,{isNotifySkipped:!0}),t.getInEdges().forEach(t=>{t&&ks(t,i)&&t.setState(e,{isNotifySkipped:!0}),t.startNode&&ks(t.startNode,i)&&t.startNode.setState(e,{isNotifySkipped:!0})}),t.getOutEdges().forEach(t=>{t&&ks(t,i)&&t.setState(e,{isNotifySkipped:!0}),t.endNode&&ks(t.endNode,i)&&t.endNode.setState(e,{isNotifySkipped:!0})})},Os=(t,e,i)=>{ks(t,i)&&t.setState(e,{isNotifySkipped:!0}),t.startNode&&ks(t.startNode,i)&&t.startNode.setState(e,{isNotifySkipped:!0}),t.endNode&&ks(t.endNode,i)&&t.endNode.setState(e,{isNotifySkipped:!0})},ks=(t,e)=>{const i=null==e?void 0:e.isStateOverride;return i||!i&&!t.getState()};class Bs{constructor(t){this.isSelectEnabled=t.isDefaultSelectEnabled,this.isHoverEnabled=t.isDefaultHoverEnabled,this.isMultiSelectEnabled=t.isDefaultMultiSelectEnabled,this.isSelectCascadeEnabled=t.isDefaultSelectCascadeEnabled}onMouseClick(t,e,i){var n;const s=this.isMultiSelectEnabled&&null!==(n=null==i?void 0:i.isAppend)&&void 0!==n&&n,o=t.getNearestNode(e);if(o)return this.isSelectEnabled&&(s?(t=>{t.isSelected()?As(t,{cascade:!1}):Es(t,{cascade:!1})})(o):Ms(t,o,{cascade:this.isSelectCascadeEnabled})),{isStateChanged:!0,changedSubject:o};const r=t.getNearestEdge(e);if(r)return this.isSelectEnabled&&(s?(t=>{t.isSelected()?Cs(t,{cascade:!1}):Ps(t,{cascade:!1})})(r):Ns(t,r,{cascade:this.isSelectCascadeEnabled})),{isStateChanged:!0,changedSubject:r};if(!this.isSelectEnabled||s)return{isStateChanged:!1};const{changedCount:a}=Ds(t);return{isStateChanged:a>0}}onMouseMove(t,e){const i=t.getNearestNode(e);if(i&&(!this.isSelectEnabled||this.isSelectEnabled&&!i.isSelected()))return i===this._lastHoveredNode?{changedSubject:i,isStateChanged:!1}:(this.isHoverEnabled&&((t,e)=>{Ls(t),Is(e)})(t,i),this._lastHoveredNode=i,{isStateChanged:!0,changedSubject:i});if(this._lastHoveredNode=void 0,!i&&this.isHoverEnabled){const{changedCount:e}=Ls(t);return{isStateChanged:e>0}}return{isStateChanged:!1}}onMouseRightClick(t,e){const i=t.getNearestNode(e);if(i)return this.isSelectEnabled&&Ms(t,i,{cascade:this.isSelectCascadeEnabled}),{isStateChanged:!0,changedSubject:i};const n=t.getNearestEdge(e);if(n)return this.isSelectEnabled&&Ns(t,n,{cascade:this.isSelectCascadeEnabled}),{isStateChanged:!0,changedSubject:n};if(!this.isSelectEnabled)return{isStateChanged:!1};const{changedCount:s}=Ds(t);return{isStateChanged:s>0}}onMouseDoubleClick(t,e){const i=t.getNearestNode(e);if(i)return this.isSelectEnabled&&Ms(t,i,{cascade:this.isSelectCascadeEnabled}),{isStateChanged:!0,changedSubject:i};const n=t.getNearestEdge(e);if(n)return this.isSelectEnabled&&Ns(t,n,{cascade:this.isSelectCascadeEnabled}),{isStateChanged:!0,changedSubject:n};if(!this.isSelectEnabled)return{isStateChanged:!1};const{changedCount:s}=Ds(t);return{isStateChanged:s>0}}}var zs,Us;!function(t){t.CANVAS="canvas",t.WEBGL="webgl"}(zs||(zs={})),function(t){t.RESIZE="resize",t.RENDER_START="render-start",t.RENDER_END="render-end"}(Us||(Us={}));const Fs={devicePixelRatio:null,fps:60,minZoom:.25,maxZoom:8,fitZoomMargin:.2,labelsIsEnabled:!0,labelsOnEventIsEnabled:!0,shadowIsEnabled:!0,shadowOnEventIsEnabled:!0,contextAlphaOnEvent:.3,contextAlphaOnEventIsEnabled:!0,backgroundColor:null,areCollapsedContainerDimensionsAllowed:!1},js="Roboto, sans-serif";var Ws;!function(t){t.TOP="top",t.MIDDLE="middle"}(Ws||(Ws={}));class Gs{constructor(t,e){var i,n;this.textLines=[],this.fontSize=4,this.fontFamily=qs(4,js),this.text=`${void 0===t?"":t}`,this.textLines=Vs(this.text),this.position=e.position,this.properties=e.properties,this.textBaseline=e.textBaseline,(void 0!==this.properties.fontSize||this.properties.fontFamily)&&(this.fontSize=Math.max(null!==(i=this.properties.fontSize)&&void 0!==i?i:0,0),this.fontFamily=qs(this.fontSize,null!==(n=this.properties.fontFamily)&&void 0!==n?n:js)),this._fixPosition()}_fixPosition(){if(this.textBaseline===Ws.MIDDLE&&this.textLines.length){const t=Math.floor(this.textLines.length/2),e=(this.textLines.length-1)/2;this.position.y-=e*this.fontSize-t*(1.2-1)}}}const Zs=(t,e)=>{e.textLines.length>0&&e.fontSize>0&&e.position&&(Hs(t,e),Xs(t,e))},Hs=(t,e)=>{if(!e.properties.fontBackgroundColor||!e.position)return;t.fillStyle=e.properties.fontBackgroundColor.toString();const i=.12*e.fontSize,n=e.fontSize+2*i,s=1.2*e.fontSize,o=e.textBaseline===Ws.MIDDLE?e.fontSize/2:0;for(let r=0;r{var i;if(!e.position)return;t.fillStyle=(null!==(i=e.properties.fontColor)&&void 0!==i?i:"#000000").toString(),t.font=e.fontFamily,t.textBaseline=e.textBaseline,t.textAlign="center";const n=1.2*e.fontSize;for(let i=0;i`${t}px ${e}`,Vs=t=>{const e=t.split("\n"),i=[];for(let t=0;t{var e,i;const n=null!==(e=t.getStyle().arrowSize)&&void 0!==e?e:1,s=null!==(i=t.getWidth())&&void 0!==i?i:1,o=t.endNode,r=t.getCurvedControlPoint(),a=Ks(t,o),h=$s(t,Math.max(0,Math.min(1,a.t+-.1)),r),l=Math.atan2(a.y-h.y,a.x-h.x),d=1.5*n+3*s;return{point:a,core:{x:a.x-.9*d*Math.cos(l),y:a.y-.9*d*Math.sin(l)},angle:l,length:d}},$s=(t,e,i)=>{const n=t.startNode.getCenter(),s=t.endNode.getCenter();if(!n||!s)return{x:0,y:0};const o=e;return{x:Math.pow(1-o,2)*n.x+2*o*(1-o)*i.x+Math.pow(o,2)*s.x,y:Math.pow(1-o,2)*n.y+2*o*(1-o)*i.y+Math.pow(o,2)*s.y}},Ks=(t,e)=>{let i,n,s,o=0,r=0,a=1,h={x:0,y:0,t:0};const l=t.getCurvedControlPoint();let d=t.endNode,u=!1;e.getId()===t.startNode.getId()&&(d=t.startNode,u=!0);const c=d.getCenter();let _;for(;r<=a&&o<10&&(_=.5*(r+a),h=Object.assign(Object.assign({},$s(t,_,l)),{t:0}),i=d.getDistanceToBorder(),n=Math.sqrt(Math.pow(h.x-c.x,2)+Math.pow(h.y-c.y,2)),s=i-n,!(Math.abs(s)<.2));)s<0?!1===u?r=_:a=_:!1===u?a=_:r=_,o++;return h.t=null!=_?_:0,h},Qs=t=>{var e,i;const n=null!==(e=t.getStyle().arrowSize)&&void 0!==e?e:1,s=null!==(i=t.getWidth())&&void 0!==i?i:1,o=t.startNode,r=to(t,o),a=-2*r.t*Math.PI+.45*Math.PI,h=1.5*n+3*s;return{point:r,core:{x:r.x-.9*h*Math.cos(a),y:r.y-.9*h*Math.sin(a)},angle:a,length:h}},Js=(t,e)=>{const i=2*e*Math.PI;return{x:t.x+t.radius*Math.cos(i),y:t.y-t.radius*Math.sin(i)}},to=(t,e)=>{const i=t.getCircularData();let n=.6,s=1;let o,r,a,h=0,l={x:0,y:0,t:0},d=.5*(n+s);const u=e.getCenter();for(;n<=s&&h<10&&(d=.5*(n+s),l=Object.assign(Object.assign({},Js(i,d)),{t:0}),o=e.getDistanceToBorder(),r=Math.sqrt(Math.pow(l.x-u.x,2)+Math.pow(l.y-u.y,2)),a=o-r,!(Math.abs(a)<.05));)a>0?n=d:s=d,h++;return l.t=null!=d?d:0,l},eo=t=>{var e,i;const n=null!==(e=t.getStyle().arrowSize)&&void 0!==e?e:1,s=null!==(i=t.getWidth())&&void 0!==i?i:1,o=t.startNode.getCenter(),r=t.endNode.getCenter(),a=Math.atan2(r.y-o.y,r.x-o.x),h=io(t,t.endNode),l=1.5*n+3*s;return{point:h,core:{x:h.x-.9*l*Math.cos(a),y:h.y-.9*l*Math.sin(a)},angle:a,length:l}},io=(t,e)=>{let i=t.endNode,n=t.startNode;e.getId()===t.startNode.getId()&&(i=t.startNode,n=t.endNode);const s=i.getCenter(),o=n.getCenter(),r=s.x-o.x,a=s.y-o.y,h=Math.sqrt(r*r+a*a),l=(h-e.getDistanceToBorder())/h;return{x:(1-l)*o.x+l*s.x,y:(1-l)*o.y+l*s.y,t:0}},no=t=>{if(t instanceof k)return eo(t);if(t instanceof B)return Ys(t);if(t instanceof z)return Qs(t);throw new Error("Failed to draw unsupported edge type")},so=(t,e)=>{const i=e.point.x,n=e.point.y,s=e.angle,o=e.length;for(let e=0;e{const i=e.getCenter(),n=e.getRadius();switch(e.getStyle().shape){case w.SQUARE:((t,e,i,n)=>{t.beginPath(),t.rect(e-n,i-n,2*n,2*n),t.closePath()})(t,i.x,i.y,n);break;case w.DIAMOND:((t,e,i,n)=>{t.beginPath(),t.lineTo(e,i+n),t.lineTo(e+n,i),t.lineTo(e,i-n),t.lineTo(e-n,i),t.closePath()})(t,i.x,i.y,n);break;case w.TRIANGLE:((t,e,i,n)=>{t.beginPath(),i+=.275*(n*=1.15);const s=2*n,o=Math.sqrt(3)*s/6,r=Math.sqrt(s*s-n*n);t.moveTo(e,i-(r-o)),t.lineTo(e+n,i+o),t.lineTo(e-n,i+o),t.lineTo(e,i-(r-o)),t.closePath()})(t,i.x,i.y,n);break;case w.TRIANGLE_DOWN:((t,e,i,n)=>{t.beginPath(),i-=.275*(n*=1.15);const s=2*n,o=Math.sqrt(3)*s/6,r=Math.sqrt(s*s-n*n);t.moveTo(e,i+(r-o)),t.lineTo(e+n,i-o),t.lineTo(e-n,i-o),t.lineTo(e,i+(r-o)),t.closePath()})(t,i.x,i.y,n);break;case w.STAR:((t,e,i,n)=>{t.beginPath(),i+=.1*(n*=.82);for(let s=0;s<10;s++){const o=n*(s%2==0?1.3:.5),r=e+o*Math.sin(2*s*Math.PI/10),a=i-o*Math.cos(2*s*Math.PI/10);t.lineTo(r,a)}t.closePath()})(t,i.x,i.y,n);break;case w.HEXAGON:((t,e,i,n)=>{((t,e,i,n,s)=>{t.beginPath(),t.moveTo(e+n,i);const o=2*Math.PI/s;for(let r=1;r{t.beginPath(),t.arc(e,i,n,0,2*Math.PI,!1),t.closePath()})(t,i.x,i.y,n)}},ro=(t,e=300)=>{let i=0,n=null;return function(){const s=arguments,o=Date.now(),r=e-(o-i);r<=0?(n&&(clearTimeout(n),n=null),i=o,t(...s)):n||(n=setTimeout(()=>{i=Date.now(),n=null,t(...s)},r))}},ao=t=>{const e=Math.max(t,1);return Math.round(1e3/e)},ho=(t,e=!1)=>{t.style.position="relative";const i=getComputedStyle(t);i.display||(t.style.display="block",console.warn("[Orb] Graph container doesn't have defined 'display' property. Setting 'display' to 'block'...")),!e&&uo(i.width)&&(t.style.width="100%",uo(getComputedStyle(t).width)?(t.style.width="400px",console.warn("[Orb] The graph container element and its parent don't have defined width properties.","If you are using percentage values,","please make sure that the parent element of the graph container has a defined position and width.","Setting the width of the graph container to an arbitrary value of '400px'...")):console.warn("[Orb] The graph container element doesn't have defined width. Setting width to 100%...")),!e&&uo(i.height)&&(t.style.height="100%",uo(getComputedStyle(t).height)?(t.style.height="400px",console.warn("[Orb] The graph container element and its parent don't have defined height properties.","If you are using percentage values,","please make sure that the parent element of the graph container has a defined position and height.","Setting the height of the graph container to an arbitrary value of '400px'...")):console.warn("[Orb] Graph container doesn't have defined height. Setting height to 100%..."))},lo=/^\s*0+\s*(?:px|rem|em|vh|vw)?\s*$/i,uo=t=>null==t||""===t||lo.test(t),co=t=>{const e=document.createElement("canvas");return e.style.position="absolute",e.style.top="0",e.style.left="0",t.appendChild(e),e},_o=t=>{let e=window.devicePixelRatio,i=()=>{};const n=()=>{i();const s=matchMedia(`(resolution: ${e}dppx)`);s.addEventListener("change",n),i=()=>s.removeEventListener("change",n),window.devicePixelRatio!==e&&(e=window.devicePixelRatio,t(e))};return n(),()=>i()};class fo extends t{constructor(t,e){super(),this._isOriginCentered=!1,this._isInitiallyRendered=!1,ho(t,null==e?void 0:e.areCollapsedContainerDimensionsAllowed),this._container=t,this._canvas=co(t);const i=this._canvas.getContext("2d");if(!i)throw new o("Failed to create Canvas context.");this._context=i,this._width=640,this._height=480,this.transform=En,this._settings=Object.assign(Object.assign({},Fs),e),this._resizeObs=new ResizeObserver(()=>this._resize()),this._resizeObs.observe(this._container),this._resize(),u(null==e?void 0:e.devicePixelRatio)||(this._dprObserveUnsubscribe=_o(()=>this._resize())),this._throttleRender=ro(t=>{this._render(t)},ao(this._settings.fps))}get width(){return this._width}get height(){return this._height}get container(){return this._container}get canvas(){return this._canvas}get isInitiallyRendered(){return this._isInitiallyRendered}getSettings(){return m(this._settings)}setSettings(t){var e;const i=t.fps&&t.fps!==this._settings.fps,n=this._settings.devicePixelRatio,s=t.devicePixelRatio;this._settings=Object.assign(Object.assign({},this._settings),t),i&&(this._throttleRender=ro(t=>{this._render(t)},ao(this._settings.fps))),!u(n)&&u(s)&&(null===(e=this._dprObserveUnsubscribe)||void 0===e||e.call(this),this._resize()),u(n)&&null===s&&(this._dprObserveUnsubscribe=_o(()=>this._resize()))}render(t){this._throttleRender(t)}_render(t){this.emit(Us.RENDER_START,void 0);const e=Date.now();this._context.clearRect(0,0,this._width,this._height),this._settings.backgroundColor&&(this._context.fillStyle=this._settings.backgroundColor.toString(),this._context.fillRect(0,0,this._width,this._height)),this._context.save(),this._context.translate(this.transform.x,this.transform.y),this._context.scale(this.transform.k,this.transform.k),this._isOriginCentered&&this._context.translate(this._width/2,this._height/2),this.drawObjects(t.getEdges()),this.drawObjects(t.getNodes()),this._context.restore(),this.emit(Us.RENDER_END,{durationMs:Date.now()-e}),this._isInitiallyRendered=!0}drawObjects(t){if(0===t.length)return;const e=[],i=[];for(let n=0;n{var n,s;const o=null===(n=null==i?void 0:i.isShadowEnabled)||void 0===n||n,r=null===(s=null==i?void 0:i.isLabelEnabled)||void 0===s||s,a=e.hasShadow();((t,e)=>{if(e.hasBorder()){t.lineWidth=e.getBorderWidth();const i=e.getBorderColor();i&&(t.strokeStyle=i.toString())}const i=e.getColor();i&&(t.fillStyle=i.toString())})(t,e),o&&a&&((t,e)=>{const i=e.getStyle();i.shadowColor&&(t.shadowColor=i.shadowColor.toString()),i.shadowSize&&(t.shadowBlur=i.shadowSize),i.shadowOffsetX&&(t.shadowOffsetX=i.shadowOffsetX),i.shadowOffsetY&&(t.shadowOffsetY=i.shadowOffsetY)})(t,e),oo(t,e),t.fill();const h=e.getBackgroundImage();h&&((t,e,i)=>{if(!i.width||!i.height)return;const n=e.getCenter(),s=e.getRadius(),o=Math.max(2*s/i.width,2*s/i.height),r=i.height*o,a=i.width*o;t.save(),t.clip(),t.drawImage(i,n.x-a/2,n.y-r/2,a,r),t.restore()})(t,e,h),o&&a&&((t,e)=>{const i=e.getStyle();i.shadowColor&&(t.shadowColor="rgba(0,0,0,0)"),i.shadowSize&&(t.shadowBlur=0),i.shadowOffsetX&&(t.shadowOffsetX=0),i.shadowOffsetY&&(t.shadowOffsetY=0)})(t,e),e.hasBorder()&&t.stroke(),r&&((t,e)=>{const i=e.getLabel();if(!i)return;const n=e.getCenter(),s=1.2*e.getBorderedRadius(),o=e.getStyle(),r=new Gs(i,{position:{x:n.x,y:n.y+s},textBaseline:Ws.TOP,properties:{fontBackgroundColor:o.fontBackgroundColor,fontColor:o.fontColor,fontFamily:o.fontFamily,fontSize:o.fontSize}});Zs(t,r)})(t,e)})(this._context,t,e):((t,e,i)=>{var n,s;if(!e.getWidth())return;const o=null===(n=null==i?void 0:i.isShadowEnabled)||void 0===n||n,r=null===(s=null==i?void 0:i.isLabelEnabled)||void 0===s||s,a=e.hasShadow();((t,e)=>{const i=e.getWidth();i>0&&(t.lineWidth=i);const n=e.getColor();n&&(t.strokeStyle=n.toString(),t.fillStyle=n.toString())})(t,e),o&&a&&((t,e)=>{const i=e.getStyle();i.shadowColor&&(t.shadowColor=i.shadowColor.toString()),i.shadowSize&&(t.shadowBlur=i.shadowSize),i.shadowOffsetX&&(t.shadowOffsetX=i.shadowOffsetX),i.shadowOffsetY&&(t.shadowOffsetY=i.shadowOffsetY)})(t,e),((t,e)=>{if(0===e.getStyle().arrowSize)return;const i=no(e),n=so([{x:0,y:0},{x:-1,y:.4},{x:-1,y:-.4}],i);t.beginPath();for(let e=0;e{if(e instanceof k)return((t,e)=>{const i=e.startNode.getCenter(),n=e.endNode.getCenter();if(!i||!n)return;t.beginPath(),t.moveTo(i.x,i.y),t.lineTo(n.x,n.y);const s=e.getLineDashPattern();t.setLineDash(null!=s?s:[]),t.stroke()})(t,e);if(e instanceof B)return((t,e)=>{const i=e.startNode.getCenter(),n=e.endNode.getCenter();if(!i||!n)return;const s=e.getCurvedControlPoint();t.beginPath(),t.moveTo(i.x,i.y),t.quadraticCurveTo(s.x,s.y,n.x,n.y);const o=e.getLineDashPattern();t.setLineDash(null!=o?o:[]),t.stroke()})(t,e);if(e instanceof z)return((t,e)=>{const{x:i,y:n,radius:s}=e.getCircularData();t.beginPath(),t.arc(i,n,s,0,2*Math.PI,!1),t.closePath();const o=e.getLineDashPattern();t.setLineDash(null!=o?o:[]),t.stroke()})(t,e);throw new Error("Failed to draw unsupported edge type")})(t,e),o&&a&&((t,e)=>{const i=e.getStyle();i.shadowColor&&(t.shadowColor="rgba(0,0,0,0)"),i.shadowSize&&(t.shadowBlur=0),i.shadowOffsetX&&(t.shadowOffsetX=0),i.shadowOffsetY&&(t.shadowOffsetY=0)})(t,e),r&&((t,e)=>{const i=e.getLabel();if(!i)return;const n=e.getStyle(),s=new Gs(i,{position:e.getCenter(),textBaseline:Ws.MIDDLE,properties:{fontBackgroundColor:n.fontBackgroundColor,fontColor:n.fontColor,fontFamily:n.fontFamily,fontSize:n.fontSize}});Zs(t,s)})(t,e)})(this._context,t,e)}reset(){this.transform=En,this._context.clearRect(0,0,this._width,this._height),this._context.save()}getFitZoomTransform(t,e){const i=t.getBoundingBox(),n="center"===(null==e?void 0:e.anchorX)?i.x+i.width/2:"end"===(null==e?void 0:e.anchorX)?i.x+i.width:0,s="center"===(null==e?void 0:e.anchorY)?i.y+i.height/2:"end"===(null==e?void 0:e.anchorY)?i.y+i.height:0,o=this.getSimulationViewRectangle(),r=o.height/(i.height*(1+this._settings.fitZoomMargin)),a=o.width/(i.width*(1+this._settings.fitZoomMargin)),h=Math.min(r,a),l=this.transform.k,d=Math.max(Math.min(h*l,this._settings.maxZoom),this._settings.minZoom),u=o.width/2*l*(1-d)-n*d,c=o.height/2*l*(1-d)-s*d;return En.translate(u,c).scale(d)}getSimulationPosition(t){const[e,i]=this.transform.invert([t.x,t.y]);return{x:e-this._width/2,y:i-this._height/2}}getCanvasPosition(t){const[e,i]=this.transform.apply([t.x+this._width/2,t.y+this._height/2]);return{x:e,y:i}}getSimulationViewRectangle(){const t=this.getSimulationPosition({x:0,y:0}),e=this.getSimulationPosition({x:this._width,y:this._height});return{x:t.x,y:t.y,width:e.x-t.x,height:e.y-t.y}}translateOriginToCenter(){this._isOriginCentered=!0}destroy(){var t;this._resizeObs.unobserve(this._container),null===(t=this._dprObserveUnsubscribe)||void 0===t||t.call(this),this.removeAllListeners(),this._canvas.remove()}}const go=(t,e,i)=>{const n=ls(t,e,hs.VERTEX),s=ls(t,i,hs.FRAGMENT),r=t.createProgram();if(!r)throw new o("Failed to create GL program.");if(t.attachShader(r,n),t.attachShader(r,s),t.linkProgram(r),!t.getProgramParameter(r,t.LINK_STATUS)){const e=t.getProgramInfoLog(r);throw t.deleteProgram(r),new o(`Failed to link GL program: ${e}`)}return t.deleteShader(n),t.deleteShader(s),r},po=2048,mo=2048;class vo{constructor(t){this._texture=null,this._cache=new Map,this._shelves=[],this._isDirty=!1,this._isTextureAllocated=!1,this._gl=t,this._canvas=document.createElement("canvas"),this._canvas.width=po,this._canvas.height=mo,this._ctx=this._canvas.getContext("2d",{willReadFrequently:!1}),this._texture=t.createTexture(),t.bindTexture(t.TEXTURE_2D,this._texture),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.bindTexture(t.TEXTURE_2D,null)}getOrCreate(t,e,i,n,s){const o=`${t}|${e}|${i}|${n}|${null!=s?s:""}`,r=this._cache.get(o);if(r)return r;const a=t.split("\n").map(t=>t.trim());if(0===a.length||1===a.length&&""===a[0])return null;const h=this._ctx,l=`48px ${i}`;h.font=l;let d=0;for(let t=0;td&&(d=e)}const u=48*1.2,c=48+(a.length-1)*u,_=Math.ceil(d+11.52)+4,f=Math.ceil(c+11.52)+4,g=this._allocate(_,f);if(!g)return null;const p=g.x+2,m=g.y+2;s&&(h.fillStyle=s,h.fillRect(p,m,_-4,f-4)),h.font=l,h.fillStyle=n,h.textBaseline="top",h.textAlign="center";const v=p+(_-4)/2;for(let t=0;tmo)return null;const n={y:i,height:e,x:t};return this._shelves.push(n),{x:0,y:i}}}const yo=2048,xo=2048;class bo{constructor(t){this._texture=null,this._cache=new Map,this._pending=new Map,this._shelves=[],this._isDirty=!1,this._isTextureAllocated=!1,this._gl=t,this._canvas=document.createElement("canvas"),this._canvas.width=yo,this._canvas.height=xo,this._ctx=this._canvas.getContext("2d",{willReadFrequently:!1}),this._texture=t.createTexture(),t.bindTexture(t.TEXTURE_2D,this._texture),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.bindTexture(t.TEXTURE_2D,null)}getOrCreate(t){const e=this._cache.get(t);if(e)return e;const i=this._pending.get(t);if(i)return i.loaded?this._packImage(t,i.image):null;const n=new Image;n.crossOrigin="anonymous";const s={image:n,loaded:!1};return this._pending.set(t,s),n.onload=()=>{s.loaded=!0},n.onerror=()=>{this._pending.delete(t)},n.src=t,null}bind(t){const e=this._gl;e.activeTexture(e.TEXTURE0+t),e.bindTexture(e.TEXTURE_2D,this._texture)}uploadIfDirty(){if(!this._isDirty)return;const t=this._gl;t.bindTexture(t.TEXTURE_2D,this._texture),this._isTextureAllocated||(t.texImage2D(t.TEXTURE_2D,0,t.RGBA,yo,xo,0,t.RGBA,t.UNSIGNED_BYTE,null),this._isTextureAllocated=!0),t.texSubImage2D(t.TEXTURE_2D,0,0,0,t.RGBA,t.UNSIGNED_BYTE,this._canvas),t.bindTexture(t.TEXTURE_2D,null),this._isDirty=!1}clear(){this._cache.clear(),this._pending.clear(),this._shelves=[],this._isDirty=!1,this._ctx.clearRect(0,0,yo,xo)}_packImage(t,e){if(!e.naturalWidth||!e.naturalHeight)return null;const i=e.naturalWidth/e.naturalHeight;let n,s;e.naturalWidth>=e.naturalHeight?(n=Math.min(e.naturalWidth,128),s=Math.round(n/i)):(s=Math.min(e.naturalHeight,128),n=Math.round(s*i));const o=n+4,r=s+4,a=this._allocate(o,r);if(!a)return null;this._ctx.drawImage(e,a.x+2,a.y+2,n,s);const h={u0:(a.x+2)/yo,v0:(a.y+2)/xo,u1:(a.x+2+n)/yo,v1:(a.y+2+s)/xo,aspect:i};return this._cache.set(t,h),this._pending.delete(t),this._isDirty=!0,h}_allocate(t,e){for(let i=0;ixo)return null;const n={y:i,height:e,x:t};return this._shelves.push(n),{x:0,y:i}}}const So=[0,0,0,0],wo=[.6,.6,.6,1],To=[1,0,0,1],Eo={[w.CIRCLE]:0,[w.DOT]:1,[w.SQUARE]:2,[w.DIAMOND]:3,[w.TRIANGLE]:4,[w.TRIANGLE_DOWN]:5,[w.STAR]:6,[w.HEXAGON]:7},Po="Roboto, sans-serif",Ao="#000000";class Co extends t{constructor(t,e){super(),this._isOriginCentered=!1,this._isInitiallyRendered=!1,this._nodeProgram=null,this._edgeProgram=null,this._labelProgram=null,this._nodeVao=null,this._edgeVao=null,this._labelVao=null,this._nodeInstanceBuffer=null,this._edgeInstanceBuffer=null,this._labelInstanceBuffer=null,this._labelCache=null,this._imageAtlas=null,this._isColorCacheDirty=!0,this._nodeColorCache=new Map,this._nodeBorderColorCache=new Map,this._nodeShadowColorCache=new Map,this._edgeColorCache=new Map,this._edgeShadowColorCache=new Map,this._lastNodeCount=0,this._lastEdgeCount=0,this._edgeInstanceData=null,this._nodeInstanceData=null,this._buffersAreCurrent=!1,this._bufferCacheStats={hits:0,misses:0},this._timerExt=null,this._timerEdgeQueries=[],this._timerNodeQueries=[],this._timerQueryIdx=0,this._lastEdgeGpuMs=null,this._lastNodeGpuMs=null,this._lastStyleVersion=-1,ho(t,null==e?void 0:e.areCollapsedContainerDimensionsAllowed),this._container=t,this._canvas=co(t);const i=this._canvas.getContext("webgl2",{antialias:!0});if(!i)throw new o("Failed to create WebGL context.");if(this._gl=i,this._width=640,this._height=480,this.transform=En,this._settings=Object.assign(Object.assign({},Fs),e),"number"!=typeof(null==e?void 0:e.devicePixelRatio)&&(this._dprObserveUnsubscribe=_o(()=>{this._isInitiallyRendered&&this.emit(Us.RESIZE,void 0)})),this._initShaders(),this._initNodeBuffers(),this._initEdgeBuffers(),this._initLabelBuffers(),this._labelCache=new vo(this._gl),this._imageAtlas=new bo(this._gl),this._timerExt=i.getExtension("EXT_disjoint_timer_query_webgl2"),this._timerExt)for(let t=0;t<4;t++){const t=i.createQuery(),e=i.createQuery();t&&this._timerEdgeQueries.push(t),e&&this._timerNodeQueries.push(e)}}_pollTimerQuery(t){if(!this._timerExt)return null;const e=this._gl;return e.getQueryParameter(t,e.QUERY_RESULT_AVAILABLE)?e.getParameter(this._timerExt.GPU_DISJOINT_EXT)?null:e.getQueryParameter(t,e.QUERY_RESULT)/1e6:null}getGpuTimeStats(){return{edgeMs:this._lastEdgeGpuMs,nodeMs:this._lastNodeGpuMs,supported:null!==this._timerExt}}_initShaders(){this._nodeProgram=go(this._gl,"#version 300 es\n\nprecision highp float;\n\nin vec2 aQuadPosition;\n\nin vec2 aCenter;\nin float aRadius;\nin vec4 aColor;\nin vec4 aBorderColor;\nin float aBorderWidth;\nin vec4 aShadowColor;\nin float aShadowSize;\nin float aShadowOffsetX;\nin float aShadowOffsetY;\nin float aShapeType;\nin vec2 aImageUV0;\nin vec2 aImageUV1;\nin float aImageAspect;\n\nuniform vec2 uResolution;\nuniform vec2 uTranslation;\nuniform float uScale;\nuniform vec2 uOriginOffset;\n\nout vec2 vUV;\nout vec4 vColor;\nout vec4 vBorderColor;\nout float vBorderThreshold;\nout vec4 vShadowColor;\nout float vNodeRadius;\nout vec2 vShadowOffset;\nout float vShadowBlur;\nflat out int vShapeType;\nout vec2 vImageUV0;\nout vec2 vImageUV1;\nout float vImageAspect;\n\nvoid main() {\n vShapeType = int(aShapeType + 0.5);\n vColor = aColor;\n vBorderColor = aBorderColor;\n vShadowColor = aShadowColor;\n vImageUV0 = aImageUV0;\n vImageUV1 = aImageUV1;\n vImageAspect = aImageAspect;\n\n float totalRadius = aRadius + aShadowSize + abs(aShadowOffsetX) + abs(aShadowOffsetY);\n\n vUV = aQuadPosition;\n vNodeRadius = aRadius / totalRadius;\n\n vBorderThreshold = vNodeRadius * (1.0 - aBorderWidth / aRadius);\n\n vShadowOffset = vec2(aShadowOffsetX, aShadowOffsetY) / totalRadius;\n\n vShadowBlur = aShadowSize / totalRadius;\n\n vec2 worldPos = aCenter + aQuadPosition * totalRadius;\n vec2 screenPos = (worldPos + uOriginOffset) * uScale + uTranslation;\n\n vec2 clip = (screenPos / uResolution) * 2.0 - 1.0;\n gl_Position = vec4(clip.x, -clip.y, 0.0, 1.0);\n}\n","#version 300 es\n\nprecision highp float;\n\nin vec2 vUV;\nin vec4 vColor;\nin vec4 vBorderColor;\nin float vBorderThreshold;\nin vec4 vShadowColor;\nin float vNodeRadius;\nin vec2 vShadowOffset;\nin float vShadowBlur;\nflat in int vShapeType;\nin vec2 vImageUV0;\nin vec2 vImageUV1;\nin float vImageAspect;\n\nuniform sampler2D uImageAtlas;\n\nout vec4 fragColor;\n\nconst int SHAPE_CIRCLE = 0;\nconst int SHAPE_DOT = 1;\nconst int SHAPE_SQUARE = 2;\nconst int SHAPE_DIAMOND = 3;\nconst int SHAPE_TRIANGLE = 4;\nconst int SHAPE_TRIANGLE_DOWN = 5;\nconst int SHAPE_STAR = 6;\nconst int SHAPE_HEXAGON = 7;\n\nfloat sdCircle(vec2 p, float r) {\n return length(p) - r;\n}\n\nfloat sdSquare(vec2 p, float r) {\n vec2 d = abs(p) - vec2(r);\n return max(d.x, d.y);\n}\n\nfloat sdDiamond(vec2 p, float r) {\n return (abs(p.x) + abs(p.y)) - r;\n}\n\nfloat sdTriangleDown(vec2 p, float r) {\n float sr = r * 1.15;\n vec2 q = vec2(p.x, p.y - 0.275 * sr);\n\n float k = sqrt(3.0);\n q.x = abs(q.x) - sr;\n q.y = q.y + sr / k;\n if (q.x + k * q.y > 0.0) {\n q = vec2(q.x - k * q.y, -k * q.x - q.y) / 2.0;\n }\n q.x -= clamp(q.x, -2.0 * sr, 0.0);\n return -length(q) * sign(q.y);\n}\n\nfloat sdTriangleUp(vec2 p, float r) {\n return sdTriangleDown(vec2(p.x, -p.y), r);\n}\n\nfloat sdStar(vec2 p, float r) {\n float sr = r * 0.82;\n vec2 q = vec2(p.x, p.y - 0.1 * sr);\n\n float outerR = sr * 1.3;\n float innerR = sr * 0.5;\n\n float angle = atan(q.x, -q.y);\n float sector = 6.2831853 / 5.0;\n float a = mod(angle + sector * 0.5, sector) - sector * 0.5;\n\n float cosA = cos(a);\n float sinA = abs(sin(a));\n\n float halfSector = sector * 0.5;\n vec2 outerPt = vec2(outerR, 0.0);\n vec2 innerPt = vec2(innerR * cos(halfSector), innerR * sin(halfSector));\n\n vec2 sp = vec2(cosA, sinA) * length(q);\n\n vec2 edge = innerPt - outerPt;\n vec2 toP = sp - outerPt;\n float t = clamp(dot(toP, edge) / dot(edge, edge), 0.0, 1.0);\n float dist = length(toP - edge * t);\n\n float cross2d = edge.x * toP.y - edge.y * toP.x;\n return cross2d > 0.0 ? -dist : dist;\n}\n\nfloat sdHexagon(vec2 p, float r) {\n vec2 q = abs(p);\n float k = sqrt(3.0);\n float d = max(q.x, (q.x * 0.5 + q.y * (k * 0.5)));\n return d - r;\n}\n\nfloat shapeSDF(vec2 p, float r, int shapeType) {\n if (shapeType == SHAPE_SQUARE) return sdSquare(p, r);\n if (shapeType == SHAPE_DIAMOND) return sdDiamond(p, r);\n if (shapeType == SHAPE_TRIANGLE) return sdTriangleUp(p, r);\n if (shapeType == SHAPE_TRIANGLE_DOWN) return sdTriangleDown(p, r);\n if (shapeType == SHAPE_STAR) return sdStar(p, r);\n if (shapeType == SHAPE_HEXAGON) return sdHexagon(p, r);\n\n return sdCircle(p, r);\n}\n\nvoid main() {\n // Body SDF - always needed.\n float dist = shapeSDF(vUV, vNodeRadius, vShapeType);\n\n float aa = 0.02 * vNodeRadius;\n float nodeAlpha = 1.0 - smoothstep(-aa, 0.0, dist);\n\n // Shadow SDF - skip entirely when no shadow. Avoids a second full shapeSDF() call\n // (which is a cascade of ifs) and the exp() per fragment.\n float shadowAlpha = 0.0;\n if (vShadowBlur > 0.0) {\n float shadowDist = shapeSDF(vUV - vShadowOffset, vNodeRadius, vShapeType);\n float t = max(shadowDist, 0.0) / vShadowBlur;\n shadowAlpha = exp(-t * t * 1.5) * 0.5 * vShadowColor.a;\n }\n\n vec4 fillColor = vColor;\n if (vImageAspect > 0.0 && dist < 0.0) {\n vec2 uv01 = (vUV / vNodeRadius) * 0.5 + 0.5;\n if (vImageAspect > 1.0) {\n uv01.x = (uv01.x - 0.5) / vImageAspect + 0.5;\n } else {\n uv01.y = (uv01.y - 0.5) * vImageAspect + 0.5;\n }\n if (uv01.x >= 0.0 && uv01.x <= 1.0 && uv01.y >= 0.0 && uv01.y <= 1.0) {\n vec2 atlasUV = mix(vImageUV0, vImageUV1, uv01);\n vec4 imgTexel = texture(uImageAtlas, atlasUV);\n fillColor = mix(fillColor, vec4(imgTexel.rgb, 1.0), imgTexel.a);\n }\n }\n\n vec4 nodeColor;\n if (vBorderThreshold < vNodeRadius) {\n float borderDist = shapeSDF(vUV, vBorderThreshold, vShapeType);\n float borderMix = smoothstep(-aa, aa, borderDist);\n nodeColor = mix(fillColor, vBorderColor, borderMix);\n } else {\n nodeColor = fillColor;\n }\n nodeColor.a *= nodeAlpha;\n\n float finalAlpha = nodeColor.a + shadowAlpha * (1.0 - nodeColor.a);\n\n if (finalAlpha < 0.001) {\n discard;\n }\n\n if (shadowAlpha > 0.0) {\n vec3 finalRGB = (nodeColor.rgb * nodeColor.a + vShadowColor.rgb * shadowAlpha * (1.0 - nodeColor.a)) / finalAlpha;\n fragColor = vec4(finalRGB, finalAlpha);\n } else {\n fragColor = nodeColor;\n }\n}\n"),this._edgeProgram=go(this._gl,"#version 300 es\n\nprecision highp float;\n\nin vec2 aQuadPosition;\n\nin vec2 aStart;\nin vec2 aEnd;\nin vec2 aControl;\nin float aWidth;\nin float aEdgeType;\nin float aLoopbackRadius;\nin float aArrowSize;\nin vec2 aArrowTip;\nin vec2 aArrowDir;\nin vec4 aColor;\nin vec4 aShadowColor;\nin float aShadowSize;\nin float aShadowOffsetX;\nin float aShadowOffsetY;\n\nuniform vec2 uResolution;\nuniform vec2 uTranslation;\nuniform float uScale;\nuniform vec2 uOriginOffset;\n\nout vec2 vWorldPos;\nout vec2 vStart;\nout vec2 vEnd;\nout vec2 vControl;\nout float vHalfWidth;\nout float vWidthFade;\nout float vHalfWidthPx;\nout float vPerpPx;\nout float vLoopbackRadius;\nout float vArrowSize;\nout vec2 vArrowTip;\nout vec2 vArrowDir;\nout vec4 vColor;\nout vec4 vShadowColor;\nout float vShadowSize;\nout vec2 vShadowOffset;\nflat out int vEdgeType;\n\nvoid main() {\n vEdgeType = int(aEdgeType + 0.5);\n vStart = aStart;\n vEnd = aEnd;\n vControl = aControl;\n float effectiveWidth = max(aWidth, 1.0 / uScale);\n vHalfWidth = effectiveWidth * 0.5;\n vWidthFade = clamp(aWidth * uScale, 0.0, 1.0);\n vHalfWidthPx = vHalfWidth * uScale;\n vPerpPx = 0.0;\n vLoopbackRadius = aLoopbackRadius;\n vArrowSize = aArrowSize;\n vArrowTip = aArrowTip;\n vArrowDir = aArrowDir;\n vColor = aColor;\n vShadowColor = aShadowColor;\n vShadowSize = aShadowSize;\n vShadowOffset = vec2(aShadowOffsetX, aShadowOffsetY);\n\n float pad = vHalfWidth + aShadowSize + abs(aShadowOffsetX) + abs(aShadowOffsetY);\n\n vec2 worldPos;\n\n if (vEdgeType == 0) {\n vec2 dir = aEnd - aStart;\n float len = length(dir);\n vec2 unitDir = dir / max(len, 0.0001);\n vec2 perp = vec2(-unitDir.y, unitDir.x);\n float totalHalf = pad + aArrowSize;\n vec2 midpoint = (aStart + aEnd) * 0.5;\n worldPos = midpoint\n + unitDir * (len * 0.5 + totalHalf) * aQuadPosition.x\n + perp * totalHalf * aQuadPosition.y;\n vPerpPx = totalHalf * aQuadPosition.y * uScale;\n } else if (vEdgeType == 1) {\n float margin = pad + aArrowSize;\n vec2 bboxMin = min(min(aStart, aEnd), aControl) - margin;\n vec2 bboxMax = max(max(aStart, aEnd), aControl) + margin;\n vec2 center = (bboxMin + bboxMax) * 0.5;\n vec2 halfSize = (bboxMax - bboxMin) * 0.5;\n worldPos = center + aQuadPosition * halfSize;\n } else {\n float margin = pad + aArrowSize;\n vec2 ctr = aControl;\n float r = aLoopbackRadius;\n vec2 bboxMin = min(ctr - (r + margin), aStart - margin);\n vec2 bboxMax = max(ctr + (r + margin), aStart + margin);\n vec2 center = (bboxMin + bboxMax) * 0.5;\n vec2 halfSize = (bboxMax - bboxMin) * 0.5;\n worldPos = center + aQuadPosition * halfSize;\n }\n\n vWorldPos = worldPos;\n vec2 screenPos = (worldPos + uOriginOffset) * uScale + uTranslation;\n vec2 clip = (screenPos / uResolution) * 2.0 - 1.0;\n gl_Position = vec4(clip.x, -clip.y, 0.0, 1.0);\n}\n","#version 300 es\n\nprecision highp float;\n\nin vec2 vWorldPos;\nin vec2 vStart;\nin vec2 vEnd;\nin vec2 vControl;\nin float vHalfWidth;\nin float vWidthFade;\nin float vHalfWidthPx;\nin float vPerpPx;\nin float vLoopbackRadius;\nin float vArrowSize;\nin vec2 vArrowTip;\nin vec2 vArrowDir;\nin vec4 vColor;\nin vec4 vShadowColor;\nin float vShadowSize;\nin vec2 vShadowOffset;\nflat in int vEdgeType;\n\nuniform bool uSimpleMode;\n\nout vec4 fragColor;\n\nfloat sdSegment(vec2 p, vec2 a, vec2 b) {\n vec2 pa = p - a;\n vec2 ba = b - a;\n float h = clamp(dot(pa, ba) / dot(ba, ba), 0.0, 1.0);\n return length(pa - ba * h);\n}\n\nfloat sdBezier(vec2 pos, vec2 A, vec2 B, vec2 C) {\n vec2 a = B - A;\n vec2 b = A - 2.0 * B + C;\n vec2 c = a * 2.0;\n vec2 d = A - pos;\n\n float kk = 1.0 / max(dot(b, b), 0.0001);\n float kx = kk * dot(a, b);\n float ky = kk * (2.0 * dot(a, a) + dot(d, b)) / 3.0;\n float kz = kk * dot(d, a);\n\n float p = ky - kx * kx;\n float q = kx * (2.0 * kx * kx - 3.0 * ky) + kz;\n float p3 = p * p * p;\n float q2 = q * q;\n float h = q2 + 4.0 * p3;\n\n float res;\n if (h >= 0.0) {\n h = sqrt(h);\n vec2 x = (vec2(h, -h) - q) / 2.0;\n vec2 uv = sign(x) * pow(abs(x), vec2(1.0 / 3.0));\n float t = clamp(uv.x + uv.y - kx, 0.0, 1.0);\n vec2 qo = d + (c + b * t) * t;\n res = dot(qo, qo);\n } else {\n float z = sqrt(-p);\n float v = acos(q / (p * z * 2.0)) / 3.0;\n float m = cos(v);\n float n = sin(v) * 1.732050808;\n vec3 t = clamp(vec3(m + m, -n - m, n - m) * z - kx, 0.0, 1.0);\n vec2 qx = d + (c + b * t.x) * t.x;\n float dx = dot(qx, qx);\n vec2 qy = d + (c + b * t.y) * t.y;\n float dy = dot(qy, qy);\n res = min(dx, dy);\n }\n\n return sqrt(res);\n}\n\nfloat sdArrow(vec2 p, vec2 tip, vec2 dir, float size) {\n if (size <= 0.0) return 1e6;\n\n vec2 perp = vec2(-dir.y, dir.x);\n vec2 rel = p - tip;\n float along = dot(rel, -dir);\n float across = dot(rel, perp);\n\n if (along < 0.0) return length(rel);\n if (along > size) {\n float hw = size * 0.4;\n float closest = clamp(across, -hw, hw);\n vec2 pt = tip - dir * size + perp * closest;\n return length(p - pt);\n }\n\n float halfW = (along / size) * size * 0.4;\n float d = abs(across) - halfW;\n return d;\n}\n\nvoid main() {\n if (uSimpleMode && vEdgeType == 0) {\n float cover = clamp(vHalfWidthPx - abs(vPerpPx) + 0.5, 0.0, 1.0);\n float a = cover * vWidthFade;\n if (a < 0.001) discard;\n fragColor = vec4(vColor.rgb, vColor.a * a);\n return;\n }\n\n float dist;\n if (vEdgeType == 0) {\n dist = sdSegment(vWorldPos, vStart, vEnd);\n } else if (vEdgeType == 1) {\n dist = sdBezier(vWorldPos, vStart, vControl, vEnd);\n } else {\n dist = abs(length(vWorldPos - vControl) - vLoopbackRadius);\n }\n\n float edgeSdf = dist - vHalfWidth;\n float combinedSdf = edgeSdf;\n\n if (vArrowSize > 0.0) {\n float arrowDist = sdArrow(vWorldPos, vArrowTip, vArrowDir, vArrowSize);\n combinedSdf = min(edgeSdf, arrowDist);\n }\n\n float shadowAlpha = 0.0;\n if (vShadowSize > 0.0) {\n vec2 shadowPos = vWorldPos - vShadowOffset;\n float shadowDist;\n if (vEdgeType == 0) {\n shadowDist = sdSegment(shadowPos, vStart, vEnd);\n } else if (vEdgeType == 1) {\n shadowDist = sdBezier(shadowPos, vStart, vControl, vEnd);\n } else {\n shadowDist = abs(length(shadowPos - vControl) - vLoopbackRadius);\n }\n float shadowArrowDist = vArrowSize > 0.0\n ? sdArrow(shadowPos, vArrowTip, vArrowDir, vArrowSize)\n : 1.0e6;\n float shadowCombined = min(shadowDist - vHalfWidth, shadowArrowDist);\n float t = max(shadowCombined, 0.0) / vShadowSize;\n shadowAlpha = exp(-t * t * 1.5) * 0.5 * vShadowColor.a;\n }\n\n float aa = fwidth(combinedSdf);\n float edgeAlpha = (1.0 - smoothstep(-aa, aa, combinedSdf)) * vWidthFade;\n vec4 edgeColor = vColor;\n edgeColor.a *= edgeAlpha;\n\n float finalAlpha = edgeColor.a + shadowAlpha * (1.0 - edgeColor.a);\n\n if (finalAlpha < 0.001) discard;\n\n if (shadowAlpha > 0.0) {\n vec3 finalRGB = (edgeColor.rgb * edgeColor.a + vShadowColor.rgb * shadowAlpha * (1.0 - edgeColor.a)) / finalAlpha;\n fragColor = vec4(finalRGB, finalAlpha);\n } else {\n fragColor = edgeColor;\n }\n}\n"),this._labelProgram=go(this._gl,"#version 300 es\n\nin vec2 aQuadPosition;\n\nin vec2 aLabelCenter;\nin vec2 aLabelSize;\nin vec2 aLabelUV0;\nin vec2 aLabelUV1;\n\nuniform vec2 uResolution;\nuniform vec2 uTranslation;\nuniform float uScale;\nuniform vec2 uOriginOffset;\n\nout vec2 vAtlasUV;\n\nvoid main() {\n vec2 worldPos = aLabelCenter + aQuadPosition * aLabelSize;\n vec2 screenPos = (worldPos + uOriginOffset) * uScale + uTranslation;\n vec2 clip = (screenPos / uResolution) * 2.0 - 1.0;\n gl_Position = vec4(clip.x, -clip.y, 0.0, 1.0);\n\n vec2 uv01 = aQuadPosition * 0.5 + 0.5;\n vAtlasUV = mix(aLabelUV0, aLabelUV1, uv01);\n}\n","#version 300 es\n\nprecision highp float;\n\nuniform sampler2D uAtlas;\n\nin vec2 vAtlasUV;\n\nout vec4 fragColor;\n\nvoid main() {\n vec4 texel = texture(uAtlas, vAtlasUV);\n if (texel.a < 0.01) discard;\n fragColor = texel;\n}\n")}_initNodeBuffers(){if(!this._nodeProgram)throw new o("Node program not initialized.");const t=this._gl;this._nodeVao=t.createVertexArray(),t.bindVertexArray(this._nodeVao);const e=new Float32Array([-1,-1,1,-1,-1,1,1,1]),i=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,i),t.bufferData(t.ARRAY_BUFFER,e,t.STATIC_DRAW);const n=t.getAttribLocation(this._nodeProgram,"aQuadPosition");t.enableVertexAttribArray(n),t.vertexAttribPointer(n,2,t.FLOAT,!1,0,0),this._nodeInstanceBuffer=t.createBuffer(),t.bindBuffer(t.ARRAY_BUFFER,this._nodeInstanceBuffer);const s=25*Float32Array.BYTES_PER_ELEMENT,r=(e,i,n)=>{const o=t.getAttribLocation(this._nodeProgram,e);t.enableVertexAttribArray(o),t.vertexAttribPointer(o,i,t.FLOAT,!1,s,4*n),t.vertexAttribDivisor(o,1)};r("aCenter",2,0),r("aRadius",1,2),r("aColor",4,3),r("aBorderColor",4,7),r("aBorderWidth",1,11),r("aShadowColor",4,12),r("aShadowSize",1,16),r("aShadowOffsetX",1,17),r("aShadowOffsetY",1,18),r("aShapeType",1,19),r("aImageUV0",2,20),r("aImageUV1",2,22),r("aImageAspect",1,24),t.bindVertexArray(null)}_initEdgeBuffers(){if(!this._edgeProgram)throw new o("Edge program not initialized.");const t=this._gl;this._edgeVao=t.createVertexArray(),t.bindVertexArray(this._edgeVao);const e=new Float32Array([-1,-1,1,-1,-1,1,1,1]),i=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,i),t.bufferData(t.ARRAY_BUFFER,e,t.STATIC_DRAW);const n=t.getAttribLocation(this._edgeProgram,"aQuadPosition");t.enableVertexAttribArray(n),t.vertexAttribPointer(n,2,t.FLOAT,!1,0,0),this._edgeInstanceBuffer=t.createBuffer(),t.bindBuffer(t.ARRAY_BUFFER,this._edgeInstanceBuffer);const s=(e,i,n)=>{const s=t.getAttribLocation(this._edgeProgram,e);t.enableVertexAttribArray(s),t.vertexAttribPointer(s,i,t.FLOAT,!1,100,4*n),t.vertexAttribDivisor(s,1)};s("aStart",2,0),s("aEnd",2,2),s("aControl",2,4),s("aWidth",1,6),s("aEdgeType",1,7),s("aLoopbackRadius",1,8),s("aArrowSize",1,9),s("aArrowTip",2,10),s("aArrowDir",2,12),s("aColor",4,14),s("aShadowColor",4,18),s("aShadowSize",1,22),s("aShadowOffsetX",1,23),s("aShadowOffsetY",1,24),t.bindVertexArray(null)}_initLabelBuffers(){if(!this._labelProgram)throw new o("Label program not initialized.");const t=this._gl;this._labelVao=t.createVertexArray(),t.bindVertexArray(this._labelVao);const e=new Float32Array([-1,-1,1,-1,-1,1,1,1]),i=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,i),t.bufferData(t.ARRAY_BUFFER,e,t.STATIC_DRAW);const n=t.getAttribLocation(this._labelProgram,"aQuadPosition");t.enableVertexAttribArray(n),t.vertexAttribPointer(n,2,t.FLOAT,!1,0,0),this._labelInstanceBuffer=t.createBuffer(),t.bindBuffer(t.ARRAY_BUFFER,this._labelInstanceBuffer);const s=(e,i,n)=>{const s=t.getAttribLocation(this._labelProgram,e);t.enableVertexAttribArray(s),t.vertexAttribPointer(s,i,t.FLOAT,!1,32,4*n),t.vertexAttribDivisor(s,1)};s("aLabelCenter",2,0),s("aLabelSize",2,2),s("aLabelUV0",2,4),s("aLabelUV1",2,6),t.bindVertexArray(null)}_resolveColor(t){if(!t)return[1,0,0,1];if(t instanceof F)return[t.rgb.r/255,t.rgb.g/255,t.rgb.b/255,1];const e=t.match(/^rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+))?\s*\)$/);if(e)return[parseInt(e[1])/255,parseInt(e[2])/255,parseInt(e[3])/255,void 0!==e[4]?parseFloat(e[4]):1];const i=new F(t);return[i.rgb.r/255,i.rgb.g/255,i.rgb.b/255,1]}_buildNodeColorCache(t){this._nodeColorCache.clear();for(let e=0;et.isSelected()||t.isHovered()),S=x&&t.getEdges().some(t=>t.isSelected()||t.isHovered());let T=null,E=null,P=null,A=null;if(!v){const e=t.getNodes();T=new Float64Array(e.length),E=new Float64Array(e.length),P=new Float64Array(e.length),A=new Map;for(let t=0;t0)if(I=1.5*B+3*(x||1),0===C){const t=a-o,e=h-r,i=Math.sqrt(t*t+e*e);i>0&&(O=t/i,k=e/i,L=a-O*l,R=h-k*l)}else if(1===C){let t=1,e=.5,i=1;for(let n=0;n<8;n++){const n=.5*(e+i),s=1-n,d=s*s*o+2*n*s*M+n*n*a,u=s*s*r+2*n*s*N+n*n*h,c=Math.sqrt(Math.pow(d-a,2)+Math.pow(u-h,2));if(Math.abs(c-l)<.1){t=n;break}c>l?e=n:i=n,t=n}const n=1-t;L=n*n*o+2*t*n*M+t*t*a,R=n*n*r+2*t*n*N+t*t*h;const s=2*n*(M-o)+2*t*(a-M),d=2*n*(N-r)+2*t*(h-N),u=Math.sqrt(s*s+d*d);u>0&&(O=s/u,k=d/u)}else{let t=.8,e=.6,i=1;for(let n=0;n<8;n++){const n=.5*(e+i),s=2*n*Math.PI,a=M+D*Math.cos(s),h=N-D*Math.sin(s),l=Math.sqrt(Math.pow(a-o,2)+Math.pow(h-r,2));if(Math.abs(l-d)<.1){t=n;break}l>d?i=n:e=n,t=n}const n=2*t*Math.PI;L=M+D*Math.cos(n),R=N-D*Math.sin(n);const s=-2*t*Math.PI+.45*Math.PI;O=Math.cos(s),k=Math.sin(s)}m[v]=o,m[v+1]=r,m[v+2]=a,m[v+3]=h,m[v+4]=M,m[v+5]=N,m[v+6]=x,m[v+7]=C,m[v+8]=D,m[v+9]=I,m[v+10]=L,m[v+11]=R,m[v+12]=O,m[v+13]=k,m[v+14]=b[0],m[v+15]=b[1],m[v+16]=b[2],m[v+17]=b[3]*w,m[v+18]=p[0],m[v+19]=p[1],m[v+20]=p[2],m[v+21]=p[3]*w,m[v+22]=c,m[v+23]=_,m[v+24]=g}l.useProgram(this._edgeProgram),this._setViewUniforms(this._edgeProgram),l.bindBuffer(l.ARRAY_BUFFER,this._edgeInstanceBuffer),v||(l.bufferData(l.ARRAY_BUFFER,m.byteLength,l.STREAM_DRAW),l.bufferSubData(l.ARRAY_BUFFER,0,m));const C=this.transform.k<=.2,M=l.getUniformLocation(this._edgeProgram,"uSimpleMode");if(l.uniform1i(M,C?1:0),l.bindVertexArray(this._edgeVao),this._timerExt&&this._timerEdgeQueries.length>0){const t=this._timerEdgeQueries[this._timerQueryIdx],e=this._pollTimerQuery(t);null!==e&&(this._lastEdgeGpuMs=e),l.beginQuery(this._timerExt.TIME_ELAPSED_EXT,t)}l.drawArraysInstanced(l.TRIANGLE_STRIP,0,4,f.length),this._timerExt&&this._timerEdgeQueries.length>0&&l.endQuery(this._timerExt.TIME_ELAPSED_EXT),l.bindVertexArray(null),C&&l.enable(l.BLEND),l.useProgram(this._nodeProgram),this._setViewUniforms(this._nodeProgram),this._imageAtlas&&(this._imageAtlas.uploadIfDirty(),this._imageAtlas.bind(0),l.uniform1i(l.getUniformLocation(this._nodeProgram,"uImageAtlas"),0));const N=t.getNodes(),D=this.transform.k,I=25*N.length,L=null===this._nodeInstanceData||this._nodeInstanceData.length!==I;L&&(this._nodeInstanceData=new Float32Array(I));const R=this._nodeInstanceData,O=v&&!L;if(O||N.length===this._lastNodeCount&&!this._isColorCacheDirty||(this._buildNodeColorCache(N),this._buildNodeBorderColorCache(N),this._buildNodeShadowColorCache(N),this._isColorCacheDirty=!1,this._lastNodeCount=N.length),!O)for(let t=0;t=4){const t=e.isSelected()&&r.imageUrlSelected||r.imageUrl;if(t&&this._imageAtlas){const e=this._imageAtlas.getOrCreate(t);e&&(p=e.u0,m=e.v0,v=e.u1,x=e.v1,S=e.aspect)}}R[u+20]=p,R[u+21]=m,R[u+22]=v,R[u+23]=x,R[u+24]=S}if(l.bindBuffer(l.ARRAY_BUFFER,this._nodeInstanceBuffer),O||(l.bufferData(l.ARRAY_BUFFER,R.byteLength,l.STREAM_DRAW),l.bufferSubData(l.ARRAY_BUFFER,0,R)),this._buffersAreCurrent=!0,l.bindVertexArray(this._nodeVao),this._timerExt&&this._timerNodeQueries.length>0){const t=this._timerNodeQueries[this._timerQueryIdx],e=this._pollTimerQuery(t);null!==e&&(this._lastNodeGpuMs=e),l.beginQuery(this._timerExt.TIME_ELAPSED_EXT,t)}if(l.drawArraysInstanced(l.TRIANGLE_STRIP,0,4,N.length),this._timerExt&&this._timerNodeQueries.length>0&&(l.endQuery(this._timerExt.TIME_ELAPSED_EXT),this._timerQueryIdx=(this._timerQueryIdx+1)%this._timerNodeQueries.length),l.bindVertexArray(null),this._labelProgram&&this._labelCache&&this._settings.labelsIsEnabled){const t=this._labelCache,e=t.rasterFontPx;let i=0;const n=N.length+f.length,o=new Float32Array(8*n);for(let n=0;n0&&(t.uploadIfDirty(),l.useProgram(this._labelProgram),this._setViewUniforms(this._labelProgram),t.bind(0),l.uniform1i(l.getUniformLocation(this._labelProgram,"uAtlas"),0),l.bindBuffer(l.ARRAY_BUFFER,this._labelInstanceBuffer),l.bufferData(l.ARRAY_BUFFER,o.subarray(0,8*i),l.DYNAMIC_DRAW),l.bindVertexArray(this._labelVao),l.drawArraysInstanced(l.TRIANGLE_STRIP,0,4,i),l.bindVertexArray(null))}this._isInitiallyRendered=!0,this.emit(Us.RENDER_END,{durationMs:performance.now()-a})}reset(){this.transform=En;const t=this._gl;t.clearColor(0,0,0,0),t.clear(t.COLOR_BUFFER_BIT)}getFitZoomTransform(t){const e=t.getBoundingBox(),i=e.x+e.width/2,n=e.y+e.height/2,s=this.getSimulationViewRectangle(),o=s.height/(e.height*(1+this._settings.fitZoomMargin)),r=s.width/(e.width*(1+this._settings.fitZoomMargin)),a=Math.min(o,r),h=this.transform.k,l=Math.max(Math.min(a*h,this._settings.maxZoom),this._settings.minZoom),d=s.width/2*h*(1-l)-i*l,u=s.height/2*h*(1-l)-n*l;return En.translate(d,u).scale(l)}getSimulationPosition(t){const[e,i]=this.transform.invert([t.x,t.y]);return{x:e-this._width/2,y:i-this._height/2}}getCanvasPosition(t){const[e,i]=this.transform.apply([t.x+this._width/2,t.y+this._height/2]);return{x:e,y:i}}getSimulationViewRectangle(){const t=this.getSimulationPosition({x:0,y:0}),e=this.getSimulationPosition({x:this._width,y:this._height});return{x:t.x,y:t.y,width:e.x-t.x,height:e.y-t.y}}translateOriginToCenter(){this._isOriginCentered=!0}destroy(){var t,e;null===(t=this._dprObserveUnsubscribe)||void 0===t||t.call(this),this.removeAllListeners(),null===(e=this._gl.getExtension("WEBGL_lose_context"))||void 0===e||e.loseContext(),this._canvas.remove()}_setViewUniforms(t){const e=this._gl,i=this._isOriginCentered?this._width/2:0,n=this._isOriginCentered?this._height/2:0;e.uniform2f(e.getUniformLocation(t,"uResolution"),this._width,this._height),e.uniform2f(e.getUniformLocation(t,"uTranslation"),this.transform.x,this.transform.y),e.uniform1f(e.getUniformLocation(t,"uScale"),this.transform.k),e.uniform2f(e.getUniformLocation(t,"uOriginOffset"),i,n)}}class Mo{static getRenderer(t,e=zs.CANVAS,i){return e===zs.WEBGL?new Co(t,i):new fo(t,i)}}const No=t=>isFinite(t)?""+Math.round(1e3*t)/1e3:"0",Do=t=>t.replace(/&/g,"&").replace(//g,">").replace(/"/g,""").replace(/'/g,"'"),Io=(t,e,i)=>{const n=Object.keys(e).filter(t=>{const i=e[t];return null!=i&&""!==i}).map(t=>{const i=e[t];return`${t}="${"number"==typeof i?No(i):Do(String(i))}"`}).join(" "),s=n?`${t} ${n}`:t;return void 0===i?`<${s}/>`:`<${s}>${i}`},Lo=t=>t.map(t=>`${No(t.x)},${No(t.y)}`).join(" "),Ro=t=>({tag:"polygon",attributes:{points:Lo(t)}}),Oo=(t,e)=>{var i,n;if(null==t||""==`${t}`)return"";const s=new Gs(t,{position:e.position,textBaseline:e.textBaseline,properties:e.properties});if(!s.textLines.length||s.fontSize<=0)return"";const o=null!==(i=e.properties.fontFamily)&&void 0!==i?i:"Roboto, sans-serif",r=(null!==(n=e.properties.fontColor)&&void 0!==n?n:"#000000").toString(),a=1.2*s.fontSize,h=e.textBaseline===Ws.MIDDLE?"middle":"text-before-edge",l=ko(s,a),d=s.textLines.map((t,e)=>Io("tspan",{x:s.position.x,dy:0===e?0:a},Do(t))).join("");return`${l}${Io("text",{x:s.position.x,y:s.position.y,"font-size":s.fontSize,"font-family":o,fill:r,"text-anchor":"middle","dominant-baseline":h},d)}`},ko=(t,e)=>{const i=t.properties.fontBackgroundColor;if(!i)return"";const n=.12*t.fontSize,s=t.fontSize+2*n,o=t.textBaseline===Ws.MIDDLE?t.fontSize/2:0,r=i.toString();return t.textLines.map((i,a)=>{const h=i.length*t.fontSize*.6+2*n;return Io("rect",{x:t.position.x-h/2,y:t.position.y-o-n+a*e,width:h,height:s,fill:r})}).join("")},Bo=t=>{if("undefined"!=typeof document)try{const e=document.createElement("canvas");e.width=t.naturalWidth||t.width,e.height=t.naturalHeight||t.height;const i=e.getContext("2d");if(!i)return;return i.drawImage(t,0,0),e.toDataURL()}catch(t){return}},zo=t=>{var e,i,n;return t.shadowColor?{color:t.shadowColor,size:null!==(e=t.shadowSize)&&void 0!==e?e:0,offsetX:null!==(i=t.shadowOffsetX)&&void 0!==i?i:0,offsetY:null!==(n=t.shadowOffsetY)&&void 0!==n?n:0}:null},Uo=(t,e)=>{const{color:i,opacity:n}=jo(e.color.toString()),s=Math.max(.5*e.size,0),o=`shadow:${i}:${n}:${s}:${e.offsetX}:${e.offsetY}`;return t.add(o,o=>Fo(o,i,n,s,e.offsetX,e.offsetY,t.filterRegion))},Fo=(t,e,i,n,s,o,r)=>{const a=r?`filterUnits="userSpaceOnUse" x="${No(r.x)}" y="${No(r.y)}" width="${No(r.width)}" height="${No(r.height)}"`:'filterUnits="objectBoundingBox" x="-50%" y="-50%" width="200%" height="200%"';return``},jo=t=>{const e=t.match(/^rgba\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)\s*\)$/i);if(e)return{color:`rgb(${e[1]}, ${e[2]}, ${e[3]})`,opacity:Wo(Number(e[4]))};const i=t.match(/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i);if(i)return{color:`#${i[1]}${i[2]}${i[3]}`,opacity:parseInt(i[4],16)/255};const n=t.match(/^#([0-9a-f])([0-9a-f])([0-9a-f])([0-9a-f])$/i);return n?{color:`#${n[1]}${n[2]}${n[3]}`,opacity:parseInt(n[4],16)/15}:{color:t,opacity:1}},Wo=t=>isFinite(t)?Math.min(Math.max(t,0),1):1,Go=(t,e,i)=>{var n,s,o,r,a,h;const l=null===(n=null==i?void 0:i.isLabelEnabled)||void 0===n||n,d=null===(s=null==i?void 0:i.isShadowEnabled)||void 0===s||s,u=null===(o=null==i?void 0:i.isImageEnabled)||void 0===o||o,c=t.getCenter(),_=t.getRadius();if(_<=0)return"";const f=((t,e,i,n)=>{switch(t){case w.SQUARE:return{tag:"rect",attributes:{x:e-n,y:i-n,width:2*n,height:2*n}};case w.DIAMOND:return Ro([{x:e,y:i+n},{x:e+n,y:i},{x:e,y:i-n},{x:e-n,y:i}]);case w.TRIANGLE:return Ro(((t,e,i)=>{e+=.275*(i*=1.15);const n=2*i,s=Math.sqrt(3)*n/6;return[{x:t,y:e-(Math.sqrt(n*n-i*i)-s)},{x:t+i,y:e+s},{x:t-i,y:e+s}]})(e,i,n));case w.TRIANGLE_DOWN:return Ro(((t,e,i)=>{e-=.275*(i*=1.15);const n=2*i,s=Math.sqrt(3)*n/6;return[{x:t,y:e+(Math.sqrt(n*n-i*i)-s)},{x:t+i,y:e-s},{x:t-i,y:e-s}]})(e,i,n));case w.STAR:return Ro(((t,e,i)=>{e+=.1*(i*=.82);const n=[];for(let s=0;s<10;s++){const o=i*(s%2==0?1.3:.5);n.push({x:t+o*Math.sin(2*s*Math.PI/10),y:e-o*Math.cos(2*s*Math.PI/10)})}return n})(e,i,n));case w.HEXAGON:return Ro(((t,e,i,n)=>{const s=[],o=2*Math.PI/n;for(let r=0;r{const n=t.getBackgroundImage();if(!n||!n.width||!n.height)return"";const s=((t,e)=>{var i,n;const s=Bo(e);if(s)return s;const o=t.getStyle();return t.isSelected()&&o.imageUrlSelected?o.imageUrlSelected:null!==(n=null!==(i=o.imageUrl)&&void 0!==i?i:e.src)&&void 0!==n?n:void 0})(t,n);if(!s)return"";const o=t.getCenter(),r=t.getRadius(),a=Object.keys(i.attributes).map(t=>`${t}=${i.attributes[t]}`).join(","),h=e.add(`clip:${i.tag}:${a}`,t=>Io("clipPath",{id:t},Io(i.tag,i.attributes)));return Io("image",{href:s,"xlink:href":s,x:o.x-r,y:o.y-r,width:2*r,height:2*r,preserveAspectRatio:"xMidYMid slice","clip-path":`url(#${h})`})})(t,e,f):"",y=d&&t.hasShadow()?zo(t.getStyle()):null;let x;if(v||y){let t=`${Io(f.tag,Object.assign(Object.assign({},f.attributes),{fill:g}))}${v}`;y&&(t=Io("g",{filter:`url(#${Uo(e,y)})`},t)),x=`${t}${p?Io(f.tag,Object.assign(Object.assign(Object.assign({},f.attributes),{fill:"none"}),m)):""}`}else x=Io(f.tag,Object.assign(Object.assign(Object.assign({},f.attributes),{fill:g}),m));const b=l?Zo(t):"";return Io("g",{},`${x}${b}`)},Zo=t=>{const e=t.getLabel();if(!e)return"";const i=t.getCenter(),n=1.2*t.getBorderedRadius(),s=t.getStyle();return Oo(e,{position:{x:i.x,y:i.y+n},textBaseline:Ws.TOP,properties:{fontBackgroundColor:s.fontBackgroundColor,fontColor:s.fontColor,fontFamily:s.fontFamily,fontSize:s.fontSize}})},Ho=[{x:0,y:0},{x:-1,y:.4},{x:-1,y:-.4}],Xo=(t,e,i)=>{var n,s,o;const r=t.getWidth();if(!r)return"";const a=null===(n=null==i?void 0:i.isLabelEnabled)||void 0===n||n,h=null===(s=null==i?void 0:i.isShadowEnabled)||void 0===s||s,l=(null!==(o=t.getColor())&&void 0!==o?o:"#000000").toString(),d=Vo(t,l),u=qo(t,r,l),c=h&&t.hasShadow()?zo(t.getStyle()):null;let _=`${d}${u}`;c&&(_=Io("g",{filter:`url(#${Uo(e,c)})`},_));const f=a?Ko(t):"";return Io("g",{},`${_}${f}`)},qo=(t,e,i)=>{const n=t.getLineDashPattern(),s={stroke:i,"stroke-width":e,fill:"none","stroke-dasharray":n?n.join(" "):void 0};if(t instanceof k){const e=t.startNode.getCenter(),i=t.endNode.getCenter(),n=`M ${No(e.x)} ${No(e.y)} L ${No(i.x)} ${No(i.y)}`;return Io("path",Object.assign({d:n},s))}if(t instanceof B){const e=t.startNode.getCenter(),i=t.endNode.getCenter(),n=t.getCurvedControlPoint(),o=`M ${No(e.x)} ${No(e.y)} Q ${No(n.x)} ${No(n.y)} ${No(i.x)} ${No(i.y)}`;return Io("path",Object.assign({d:o},s))}if(t instanceof z){const{x:e,y:i,radius:n}=t.getCircularData();return Io("circle",Object.assign({cx:e,cy:i,r:n},s))}return""},Vo=(t,e)=>{if(0===t.getStyle().arrowSize)return"";const i=Yo(t);if(!i)return"";const n=$o(Ho,i).map(t=>`${No(t.x)},${No(t.y)}`).join(" ");return Io("polygon",{points:n,fill:e})},Yo=t=>t instanceof k?eo(t):t instanceof B?Ys(t):t instanceof z?Qs(t):null,$o=(t,e)=>t.map(t=>{const i=t.x*Math.cos(e.angle)-t.y*Math.sin(e.angle),n=t.x*Math.sin(e.angle)+t.y*Math.cos(e.angle);return{x:e.point.x+e.length*i,y:e.point.y+e.length*n}}),Ko=t=>{const e=t.getLabel();if(!e)return"";const i=t.getStyle();return Oo(e,{position:t.getCenter(),textBaseline:Ws.MIDDLE,properties:{fontBackgroundColor:i.fontBackgroundColor,fontColor:i.fontColor,fontFamily:i.fontFamily,fontSize:i.fontSize}})};class Qo{constructor(t){this.filterRegion=t,this._idBySignature=new Map,this._entries=[],this._counter=0}add(t,e){const i=this._idBySignature.get(t);if(void 0!==i)return i;const n=`orb-def-${this._counter}`;return this._counter+=1,this._idBySignature.set(t,n),this._entries.push(e(n)),n}toSVG(){return this._entries.length?`${this._entries.join("")}`:""}}const Jo=(t,e={})=>{var i,n,s,o;const r=null!==(i=e.padding)&&void 0!==i?i:20,a=null===(n=e.isLabelEnabled)||void 0===n||n,h=null===(s=e.isShadowEnabled)||void 0===s||s,l=null===(o=e.isImageEnabled)||void 0===o||o,d=t.getNodes(),u=t.getEdges(),c=tr(d,u,a,h),_=c.x-r,f=c.y-r,g=Math.max(c.width+2*r,1),p=Math.max(c.height+2*r,1),m=new Qo({x:_,y:f,width:g,height:p}),v=[];e.backgroundColor&&v.push(Io("rect",{x:_,y:f,width:g,height:p,fill:e.backgroundColor.toString()}));for(let t=0;t{const s={minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0};for(let e=0;e{et.maxX&&(t.maxX=e),i>t.maxY&&(t.maxY=i)},ir=(t,e,i,n,s)=>{er(t,e-n,i-s),er(t,e+n,i+s)},nr=(t,e,i,n)=>{var s;if(e.getRadius()<=0)return;const o=e.getCenter(),r=e.getBorderedRadius(),a=n?rr(e.hasShadow(),e.getStyle()):0;if(ir(t,o.x,o.y,r+a,r+a),i&&e.getLabel()){const i=e.getStyle(),n=o.y+1.2*e.getBorderedRadius();or(t,e.getLabel(),o.x,n,null!==(s=i.fontSize)&&void 0!==s?s:4,!1)}},sr=(t,e,i,n)=>{var s;if(!e.getWidth())return;const o=e.getStyle(),r=n?rr(e.hasShadow(),o):0;if(e instanceof z){const i=e.getCircularData();ir(t,i.x,i.y,i.radius+r,i.radius+r)}else if(e instanceof B){const i=e.getCurvedControlPoint();ir(t,i.x,i.y,r,r)}if(i&&e.getLabel()){const i=e.getCenter();or(t,e.getLabel(),i.x,i.y,null!==(s=o.fontSize)&&void 0!==s?s:4,!0)}},or=(t,e,i,n,s,o)=>{if(s<=0)return;const r=`${e}`.split("\n"),a=.12*s,h=r.reduce((t,e)=>Math.max(t,e.trim().length),0)*s*.6+2*a,l=r.length*s*1.2+2*a,d=o?n-l/2:n;er(t,i-h/2,d),er(t,i+h/2,d+l)},rr=(t,e)=>{var i,n,s;return t&&e.shadowColor?(null!==(i=e.shadowSize)&&void 0!==i?i:0)+Math.max(Math.abs(null!==(n=e.shadowOffsetX)&&void 0!==n?n:0),Math.abs(null!==(s=e.shadowOffsetY)&&void 0!==s?s:0)):0};class ar{constructor(t){this._graph=t}selectNodeById(t,e){const i=this._graph.getNodeById(t);return!!i&&(Es(i,e),!0)}selectNodesByIds(t,e){const i=[];for(let e=0;e{for(let i=0;i{for(let i=0;i{for(let i=0;i{for(let i=0;i{Os(t,r.HOVERED)})(e),!0)}unhoverAll(){const{changedCount:t}=Ls(this._graph);return t}}const hr={isBackgroundDrag:!0},lr=t=>!!t&&!0===t.isBackgroundDrag;class dr{constructor(t,i){var n,o,r,a,h,l,d,u;this._simulatorUsesGPU=!1,this._simulationStartedAt=Date.now(),this._assignPositions=t=>{if(this._settings.getPosition)for(let e=0;e!(t.button||t.ctrlKey&&"wheel"!==t.type||"wheel"!==t.type&&this._isBackgroundDragModifierActive(t)),this._dragFilter=t=>!(t.button||!this._isBackgroundDragModifierActive(t)&&t.ctrlKey),this.dragSubject=t=>{var e;const i=this.getCanvasMousePosition(t.sourceEvent),n=null===(e=this._renderer)||void 0===e?void 0:e.getSimulationPosition(i);return this._graph.getNearestNode(n)||(this._isBackgroundDragModifierActive(t.sourceEvent)?hr:void 0)},this.dragStarted=t=>{if(lr(t.subject))return void this._emitBackgroundDrag(e.BACKGROUND_DRAG_START,t.sourceEvent);if(!this._settings.interaction.isDragEnabled)return;const i=this.getCanvasMousePosition(t.sourceEvent),n=this._renderer.getSimulationPosition(i);this._events.emit(e.NODE_DRAG_START,{node:t.subject,event:t.sourceEvent,localPoint:n,globalPoint:i}),this._dragStartPosition=i},this.dragged=t=>{if(lr(t.subject))return void this._emitBackgroundDrag(e.BACKGROUND_DRAG,t.sourceEvent);if(!this._settings.interaction.isDragEnabled)return;const i=this.getCanvasMousePosition(t.sourceEvent),n=this._renderer.getSimulationPosition(i);Rn(this._dragStartPosition,i)||(this._dragStartPosition=void 0),this._simulator.dragNode(t.subject.getId(),n),this._events.emit(e.NODE_DRAG,{node:t.subject,event:t.sourceEvent,localPoint:n,globalPoint:i})},this.dragEnded=t=>{if(lr(t.subject))return void this._emitBackgroundDrag(e.BACKGROUND_DRAG_END,t.sourceEvent);if(!this._settings.interaction.isDragEnabled)return;const i=this.getCanvasMousePosition(t.sourceEvent),n=this._renderer.getSimulationPosition(i);Rn(this._dragStartPosition,i)||this._simulator.endDragNode(t.subject.getId()),this._events.emit(e.NODE_DRAG_END,{node:t.subject,event:t.sourceEvent,localPoint:n,globalPoint:i})},this.zoomed=t=>{this._settings.interaction.isZoomEnabled&&(this._renderer.transform=t.transform,setTimeout(()=>{this.render(),this._events.emit(e.TRANSFORM,{transform:t.transform})},1))},this.mouseMoved=t=>{const i=this.getCanvasMousePosition(t),n=this._renderer.getSimulationPosition(i),s=this._strategy.onMouseMove(this._graph,n),o=s.changedSubject;o&&s.isStateChanged&&(E(o)&&this._events.emit(e.NODE_HOVER,{node:o,event:t,localPoint:n,globalPoint:i}),L(o)&&this._events.emit(e.EDGE_HOVER,{edge:o,event:t,localPoint:n,globalPoint:i})),this._events.emit(e.MOUSE_MOVE,{subject:o,event:t,localPoint:n,globalPoint:i}),s.isStateChanged&&(this._invalidateStyles(),this.render())},this.mouseClicked=t=>{const i=this.getCanvasMousePosition(t),n=this._renderer.getSimulationPosition(i),s=this._strategy.onMouseClick(this._graph,n,{isAppend:t.shiftKey}),o=s.changedSubject;o&&(E(o)&&this._events.emit(e.NODE_CLICK,{node:o,event:t,localPoint:n,globalPoint:i}),L(o)&&this._events.emit(e.EDGE_CLICK,{edge:o,event:t,localPoint:n,globalPoint:i})),this._events.emit(e.MOUSE_CLICK,{subject:o,event:t,localPoint:n,globalPoint:i}),(s.isStateChanged||s.changedSubject)&&(this._invalidateStyles(),this.render())},this.mouseRightClicked=t=>{const i=this.getCanvasMousePosition(t),n=this._renderer.getSimulationPosition(i),s=this._strategy.onMouseRightClick(this._graph,n),o=s.changedSubject;o&&(E(o)&&this._events.emit(e.NODE_RIGHT_CLICK,{node:o,event:t,localPoint:n,globalPoint:i}),L(o)&&this._events.emit(e.EDGE_RIGHT_CLICK,{edge:o,event:t,localPoint:n,globalPoint:i})),this._events.emit(e.MOUSE_RIGHT_CLICK,{subject:o,event:t,localPoint:n,globalPoint:i}),(s.isStateChanged||s.changedSubject)&&(this._invalidateStyles(),this.render())},this.mouseDoubleClicked=t=>{const i=this.getCanvasMousePosition(t),n=this._renderer.getSimulationPosition(i),s=this._strategy.onMouseDoubleClick(this._graph,n),o=s.changedSubject;o&&(E(o)&&this._events.emit(e.NODE_DOUBLE_CLICK,{node:o,event:t,localPoint:n,globalPoint:i}),L(o)&&this._events.emit(e.EDGE_DOUBLE_CLICK,{edge:o,event:t,localPoint:n,globalPoint:i})),this._events.emit(e.MOUSE_DOUBLE_CLICK,{subject:o,event:t,localPoint:n,globalPoint:i}),(s.isStateChanged||s.changedSubject)&&(this._invalidateStyles(),this.render())},this.zoomIn=t=>{_e(this._renderer.canvas).transition().duration(this._settings.zoomFitTransitionMs).ease(Ae).call(this._d3Zoom.scaleBy,1.2).on("end",()=>this.render(t))},this.zoomOut=t=>{_e(this._renderer.canvas).transition().duration(this._settings.zoomFitTransitionMs).ease(Ae).call(this._d3Zoom.scaleBy,.8).on("end",()=>this.render(t))},this._invalidateStyles=()=>{var t,e;null===(e=(t=this._renderer).invalidateStyles)||void 0===e||e.call(t)},this._update=t=>{t&&"x"in t&&"y"in t&&"id"in t&&this._simulator.patchData({nodes:[{x:t.x,y:t.y,sx:t.x,sy:t.y,fx:t.x,fy:t.y,id:t.id}],edges:[]}),this._invalidateStyles(),this.render()},this._initializeSimulationEvents=()=>{this._simulator.on(On.SIMULATION_START,()=>{this._simulationStartedAt=Date.now(),this._events.emit(e.SIMULATION_START,void 0)});const t=()=>{var t,e;return null===(e=(t=this._renderer).invalidateBuffers)||void 0===e?void 0:e.call(t)};this._simulator.on(On.SIMULATION_PROGRESS,i=>{this._graph.setNodePositions(i.nodes),t(),this._events.emit(e.SIMULATION_STEP,{progress:i.progress}),this.render()}),this._simulator.on(On.SIMULATION_END,i=>{this._graph.setNodePositions(i.nodes),t(),this.render(),this._events.emit(e.SIMULATION_END,{durationMs:Date.now()-this._simulationStartedAt})}),this._simulator.on(On.SIMULATION_STEP,e=>{this._graph.setNodePositions(e.nodes),t(),this.render()}),this._simulator.on(On.NODE_DRAG,e=>{this._graph.setNodePositions(e.nodes),t(),this.render()}),this._simulator.on(On.SETTINGS_UPDATE,t=>{var e;this._settings.layout.options=null===(e=t.settings)||void 0===e?void 0:e.options})},this._container=t,this._settings=Object.assign(Object.assign({getPosition:null==i?void 0:i.getPosition,zoomFitTransitionMs:200,isOutOfBoundsDragEnabled:!1,areCoordinatesRounded:!0},i),{layout:Object.assign({type:"force"},null!==(n=null==i?void 0:i.layout)&&void 0!==n?n:ns),render:Object.assign({},null==i?void 0:i.render),strategy:Object.assign({isDefaultHoverEnabled:!0,isDefaultSelectEnabled:!0,isDefaultMultiSelectEnabled:!1,isDefaultSelectCascadeEnabled:!0},null==i?void 0:i.strategy),interaction:Object.assign(Object.assign({isDragEnabled:!0,isZoomEnabled:!0},null==i?void 0:i.interaction),{backgroundDrag:Object.assign({isEnabled:!1,modifier:"shift"},null===(o=null==i?void 0:i.interaction)||void 0===o?void 0:o.backgroundDrag)})}),this._graph=new Ts(void 0,{onLoadedImages:()=>{this._renderer.isInitiallyRendered&&this.render()},listeners:[this._update]}),this._graph.setDefaultStyle(X()),this._events=new s,this._interaction=new ar(this._graph),this._strategy=new Bs({isDefaultSelectEnabled:null!==(r=this._settings.strategy.isDefaultSelectEnabled)&&void 0!==r&&r,isDefaultHoverEnabled:null!==(a=this._settings.strategy.isDefaultHoverEnabled)&&void 0!==a&&a,isDefaultMultiSelectEnabled:null===(h=this._settings.strategy.isDefaultMultiSelectEnabled)||void 0===h||h,isDefaultSelectCascadeEnabled:null===(l=this._settings.strategy.isDefaultSelectCascadeEnabled)||void 0===l||l}),this._rendererType=null!==(u=null===(d=null==i?void 0:i.render)||void 0===d?void 0:d.type)&&void 0!==u?u:zs.CANVAS,this._initRenderer(this._rendererType),this._simulator=xs.getSimulator(this._settings.layout),this._simulatorUsesGPU=dr._needsGPU(this._settings.layout),this._initializeSimulationEvents(),this._graph.setSettings({onSetupData:()=>{this._assignPositions(this._graph.getNodes());const t=this._graph.getNodePositions(),e=this._graph.getEdgePositions();this._simulator.setupData({nodes:t,edges:e})},onMergeData:t=>{var e,i;const n=new Set(null===(e=t.nodes)||void 0===e?void 0:e.map(t=>t.id)),s=t=>n.has(t.getId()),o=new Set(null===(i=t.edges)||void 0===i?void 0:i.map(t=>t.id));this._assignPositions(this._graph.getNodes(s));const r=this._graph.getNodePositions(s),a=this._graph.getEdgePositions(t=>o.has(t.getId()));this._simulator.mergeData({nodes:r,edges:a})},onRemoveData:t=>{this._simulator.deleteData(t)}})}_initRenderer(t){try{this._renderer=Mo.getRenderer(this._container,t,this._settings.render)}catch(t){throw this._container.textContent=t.message,t}this._renderer.on(Us.RENDER_START,()=>{this._events.emit(e.RENDER_START,void 0)}),this._renderer.on(Us.RENDER_END,t=>{this._events.emit(e.RENDER_END,t)}),this._renderer.on(Us.RESIZE,()=>{this._renderer.isInitiallyRendered&&this._renderer.render(this._graph)}),this._renderer.translateOriginToCenter(),this._settings.render=this._renderer.getSettings(),this._d3Zoom=function(){var t,e,i,n=Cn,s=Mn,o=Ln,r=Dn,a=In,h=[0,1/0],l=[[-1/0,-1/0],[1/0,1/0]],d=250,u=Me,c=tt("start","zoom","end"),_=0,f=10;function g(t){t.property("__zoom",Nn).on("wheel.zoom",S,{passive:!1}).on("mousedown.zoom",w).on("dblclick.zoom",T).filter(a).on("touchstart.zoom",E).on("touchmove.zoom",P).on("touchend.zoom touchcancel.zoom",A).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function p(t,e){return(e=Math.max(h[0],Math.min(h[1],e)))===t.k?t:new Tn(e,t.x,t.y)}function m(t,e,i){var n=e[0]-i[0]*t.k,s=e[1]-i[1]*t.k;return n===t.x&&s===t.y?t:new Tn(t.k,n,s)}function v(t){return[(+t[0][0]+ +t[1][0])/2,(+t[0][1]+ +t[1][1])/2]}function y(t,e,i,n){t.on("start.zoom",function(){x(this,arguments).event(n).start()}).on("interrupt.zoom end.zoom",function(){x(this,arguments).event(n).end()}).tween("zoom",function(){var t=this,o=arguments,r=x(t,o).event(n),a=s.apply(t,o),h=null==i?v(a):"function"==typeof i?i.apply(t,o):i,l=Math.max(a[1][0]-a[0][0],a[1][1]-a[0][1]),d=t.__zoom,c="function"==typeof e?e.apply(t,o):e,_=u(d.invert(h).concat(l/d.k),c.invert(h).concat(l/c.k));return function(t){if(1===t)t=c;else{var e=_(t),i=l/e[2];t=new Tn(i,h[0]-e[0]*i,h[1]-e[1]*i)}r.zoom(null,t)}})}function x(t,e,i){return!i&&t.__zooming||new b(t,e)}function b(t,e){this.that=t,this.args=e,this.active=0,this.sourceEvent=null,this.extent=s.apply(t,e),this.taps=0}function S(t,...e){if(n.apply(this,arguments)){var i=x(this,e).event(t),s=this.__zoom,a=Math.max(h[0],Math.min(h[1],s.k*Math.pow(2,r.apply(this,arguments)))),d=fe(t);if(i.wheel)i.mouse[0][0]===d[0]&&i.mouse[0][1]===d[1]||(i.mouse[1]=s.invert(i.mouse[0]=d)),clearTimeout(i.wheel);else{if(s.k===a)return;i.mouse=[d,s.invert(d)],ti(this),i.start()}An(t),i.wheel=setTimeout(function(){i.wheel=null,i.end()},150),i.zoom("mouse",o(m(p(s,a),i.mouse[0],i.mouse[1]),i.extent,l))}}function w(t,...e){if(!i&&n.apply(this,arguments)){var s=t.currentTarget,r=x(this,e,!0).event(t),a=_e(t.view).on("mousemove.zoom",function(t){if(An(t),!r.moved){var e=t.clientX-d,i=t.clientY-u;r.moved=e*e+i*i>_}r.event(t).zoom("mouse",o(m(r.that.__zoom,r.mouse[0]=fe(t,s),r.mouse[1]),r.extent,l))},!0).on("mouseup.zoom",function(t){a.on("mousemove.zoom mouseup.zoom",null),xe(t.view,r.moved),An(t),r.event(t).end()},!0),h=fe(t,s),d=t.clientX,u=t.clientY;ye(t.view),Pn(t),r.mouse=[h,this.__zoom.invert(h)],ti(this),r.start()}}function T(t,...e){if(n.apply(this,arguments)){var i=this.__zoom,r=fe(t.changedTouches?t.changedTouches[0]:t,this),a=i.invert(r),h=i.k*(t.shiftKey?.5:2),u=o(m(p(i,h),r,a),s.apply(this,e),l);An(t),d>0?_e(this).transition().duration(d).call(y,u,r,t):_e(this).call(g.transform,u,r,t)}}function E(i,...s){if(n.apply(this,arguments)){var o,r,a,h,l=i.touches,d=l.length,u=x(this,s,i.changedTouches.length===d).event(i);for(Pn(i),r=0;ru}h.mouse("drag",n)}function g(t){_e(t.view).on("mousemove.drag mouseup.drag",null),xe(t.view,i),ve(t),h.mouse("end",t)}function p(t,e){if(s.call(this,t,e)){var i,n,r=t.changedTouches,a=o.call(this,t,e),h=r.length;for(i=0;i{this.recenter()}),this._simulator.setupData({nodes:n,edges:s})}t.strategy&&(c(t.strategy.isDefaultHoverEnabled)&&(this._settings.strategy.isDefaultHoverEnabled=t.strategy.isDefaultHoverEnabled,this._strategy.isHoverEnabled=this._settings.strategy.isDefaultHoverEnabled),c(t.strategy.isDefaultSelectEnabled)&&(this._settings.strategy.isDefaultSelectEnabled=t.strategy.isDefaultSelectEnabled,this._strategy.isSelectEnabled=this._settings.strategy.isDefaultSelectEnabled),c(t.strategy.isDefaultMultiSelectEnabled)&&(this._settings.strategy.isDefaultMultiSelectEnabled=t.strategy.isDefaultMultiSelectEnabled,this._strategy.isMultiSelectEnabled=this._settings.strategy.isDefaultMultiSelectEnabled),c(t.strategy.isDefaultSelectCascadeEnabled)&&(this._settings.strategy.isDefaultSelectCascadeEnabled=t.strategy.isDefaultSelectCascadeEnabled,this._strategy.isSelectCascadeEnabled=this._settings.strategy.isDefaultSelectCascadeEnabled)),t.interaction&&(c(t.interaction.isDragEnabled)&&(this._settings.interaction.isDragEnabled=t.interaction.isDragEnabled),c(t.interaction.isZoomEnabled)&&(this._settings.interaction.isZoomEnabled=t.interaction.isZoomEnabled),t.interaction.backgroundDrag&&(this._settings.interaction.backgroundDrag=Object.assign(Object.assign({},this._settings.interaction.backgroundDrag),t.interaction.backgroundDrag)))}static _needsGPU(t){var e;return"force"===t.type&&!!(null===(e=t.options)||void 0===e?void 0:e.useGPU)}render(t){t&&(this._simulator.isSimulationRunning()?this._simulator.once(On.SIMULATION_END,()=>{this._renderer.once(Us.RENDER_END,()=>t())}):this._renderer.once(Us.RENDER_END,()=>t())),this._renderer.render(this._graph)}recenter(t,e){"function"==typeof t&&(e=t,t=void 0);const i=(t=>{var e,i,n,s,o,r;if("hierarchical"===t.type){const n=t.options;return{anchorX:null!==(e=n.anchorX)&&void 0!==e?e:"horizontal"===n.orientation?n.reversed?"end":"start":"center",anchorY:null!==(i=n.anchorY)&&void 0!==i?i:"vertical"===n.orientation?n.reversed?"end":"start":"center"}}return{anchorX:null!==(s=null===(n=t.options)||void 0===n?void 0:n.anchorX)&&void 0!==s?s:"center",anchorY:null!==(r=null===(o=t.options)||void 0===o?void 0:o.anchorY)&&void 0!==r?r:"center"}})(this._settings.layout),n=Object.assign(Object.assign({},i),t),s=this._renderer.getFitZoomTransform(this._graph,n);_e(this._renderer.canvas).transition().duration(this._settings.zoomFitTransitionMs).ease(Ae).call(this._d3Zoom.transform,s).on("end",()=>this.render(e))}getSVG(t){return Jo(this._graph,Object.assign({backgroundColor:this._settings.render.backgroundColor},t))}destroy(){this._renderer.destroy(),this._simulator.terminate()}_isBackgroundDragModifierActive(t){var e;const i=this._settings.interaction.backgroundDrag;if(!(null==i?void 0:i.isEnabled))return!1;switch(null!==(e=i.modifier)&&void 0!==e?e:"shift"){case"shift":return t.shiftKey;case"ctrl":return t.ctrlKey;case"alt":return t.altKey;case"meta":return t.metaKey;case null:return!0;default:return!1}}_emitBackgroundDrag(t,e){const i=this.getCanvasMousePosition(e),n=this._renderer.getSimulationPosition(i);this._events.emit(t,{event:e,localPoint:n,globalPoint:i})}getCanvasMousePosition(t){var e,i,n,s;const o=this._renderer.canvas.getBoundingClientRect();let r=null!==(i=null!==(e=t.clientX)&&void 0!==e?e:t.pageX)&&void 0!==i?i:t.x,a=null!==(s=null!==(n=t.clientY)&&void 0!==n?n:t.pageY)&&void 0!==s?s:t.y;return r-=o.left,a-=o.top,this._settings.areCoordinatesRounded&&(r=Math.floor(r),a=Math.floor(a)),this._settings.isOutOfBoundsDragEnabled||(r=Math.max(0,Math.min(this._renderer.width,r)),a=Math.max(0,Math.min(this._renderer.height,a))),{x:r,y:a}}fixNodes(){this._simulator.fixNodes()}releaseNodes(){this._simulator.releaseNodes()}}var ur=i(481);class cr{constructor(t,e){var i,n,o,r,a,h,l,d,u,c,_,f;this._invalidateStyles=()=>{var t,e;null===(e=(t=this._renderer).invalidateStyles)||void 0===e||e.call(t)},this._update=()=>{this._invalidateStyles(),this.render()},this._container=t,this._graph=new Ts(void 0,{onLoadedImages:()=>{this._renderer.isInitiallyRendered&&this.render()},listeners:[this._update]}),this._graph.setDefaultStyle(X()),this._events=new s,this._interaction=new ar(this._graph),this._settings=Object.assign(Object.assign({areCollapsedContainerDimensionsAllowed:!1},e),{map:{zoomLevel:null!==(n=null===(i=e.map)||void 0===i?void 0:i.zoomLevel)&&void 0!==n?n:2,tile:null!==(r=null===(o=e.map)||void 0===o?void 0:o.tile)&&void 0!==r?r:{instance:new ur.TileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"),attribution:'Leaflet | Map data © OpenStreetMap contributors'},nodeSizeMode:null!==(h=null===(a=e.map)||void 0===a?void 0:a.nodeSizeMode)&&void 0!==h?h:"geographic"},render:Object.assign({type:zs.CANVAS},e.render),strategy:Object.assign({isDefaultHoverEnabled:!0,isDefaultSelectEnabled:!0,isDefaultMultiSelectEnabled:!1,isDefaultSelectCascadeEnabled:!0},null==e?void 0:e.strategy)}),this._strategy=new Bs({isDefaultSelectEnabled:null!==(l=this._settings.strategy.isDefaultSelectEnabled)&&void 0!==l&&l,isDefaultHoverEnabled:null!==(d=this._settings.strategy.isDefaultHoverEnabled)&&void 0!==d&&d,isDefaultMultiSelectEnabled:null===(u=this._settings.strategy.isDefaultMultiSelectEnabled)||void 0===u||u,isDefaultSelectCascadeEnabled:null===(c=this._settings.strategy.isDefaultSelectCascadeEnabled)||void 0===c||c}),this._rendererType=null!==(f=null===(_=null==e?void 0:e.render)||void 0===_?void 0:_.type)&&void 0!==f?f:zs.CANVAS,this._initRenderer(this._rendererType),this._map=this._initMap(),this._leaflet=this._initLeaflet(),this._handleTileChange()}_initRenderer(t){try{this._renderer=Mo.getRenderer(this._container,t,this._settings.render)}catch(t){throw this._container.textContent=t.message,t}this._renderer.on(Us.RENDER_END,t=>{this._events.emit(e.RENDER_END,t)}),this._renderer.on(Us.RESIZE,()=>{this._renderer.isInitiallyRendered&&(this._leaflet.invalidateSize(!1),this._renderer.render(this._graph))}),this._settings.render=this._renderer.getSettings(),this._renderer.canvas.style.zIndex="2",this._renderer.canvas.style.pointerEvents="none"}setRenderer(t){if(t===this._rendererType)return;this._renderer.destroy(),this._initRenderer(t),this._rendererType=t;const e=this._leaflet._mapPane._leaflet_pos,i=this._getStyleScale();this._renderer.transform=Object.assign(Object.assign({},e),{k:i}),this.render()}get data(){return this._graph}get events(){return this._events}get interaction(){return this._interaction}get leaflet(){return this._leaflet}get canvas(){return this._renderer.canvas}getSimulationPosition(t){const e=this._leaflet.containerPointToLayerPoint([t.x,t.y]);return this._toSimulationPoint(e)}getCanvasPosition(t){const e=this._getStyleScale(),i=this._leaflet.layerPointToContainerPoint([t.x*e,t.y*e]);return{x:i.x,y:i.y}}getSimulationViewRectangle(){const t=this._leaflet.getSize(),e=this.getSimulationPosition({x:0,y:0}),i=this.getSimulationPosition({x:t.x,y:t.y});return{x:e.x,y:e.y,width:i.x-e.x,height:i.y-e.y}}getSettings(){return m(this._settings)}setSettings(t){if(t.getGeoPosition&&(this._settings.getGeoPosition=t.getGeoPosition,this._updateGraphPositions()),t.map&&("number"==typeof t.map.zoomLevel&&(this._settings.map.zoomLevel=t.map.zoomLevel,this._leaflet.setZoom(t.map.zoomLevel)),t.map.tile&&(this._settings.map.tile=t.map.tile,this._handleTileChange()),t.map.nodeSizeMode&&t.map.nodeSizeMode!==this._settings.map.nodeSizeMode)){this._settings.map.nodeSizeMode=t.map.nodeSizeMode,this._updateGraphPositions();const e=this._leaflet._mapPane._leaflet_pos,i=this._getStyleScale();this._renderer.transform=Object.assign(Object.assign({},e),{k:i}),this._renderer.render(this._graph)}t.render&&(t.render.type&&t.render.type!==this._rendererType&&this.setRenderer(t.render.type),this._renderer.setSettings(t.render),this._settings.render=this._renderer.getSettings()),t.strategy&&(c(t.strategy.isDefaultHoverEnabled)&&(this._settings.strategy.isDefaultHoverEnabled=t.strategy.isDefaultHoverEnabled,this._strategy.isHoverEnabled=this._settings.strategy.isDefaultHoverEnabled),c(t.strategy.isDefaultSelectEnabled)&&(this._settings.strategy.isDefaultSelectEnabled=t.strategy.isDefaultSelectEnabled,this._strategy.isSelectEnabled=this._settings.strategy.isDefaultSelectEnabled),c(t.strategy.isDefaultMultiSelectEnabled)&&(this._settings.strategy.isDefaultMultiSelectEnabled=t.strategy.isDefaultMultiSelectEnabled,this._strategy.isMultiSelectEnabled=this._settings.strategy.isDefaultMultiSelectEnabled),c(t.strategy.isDefaultSelectCascadeEnabled)&&(this._settings.strategy.isDefaultSelectCascadeEnabled=t.strategy.isDefaultSelectCascadeEnabled,this._strategy.isSelectCascadeEnabled=this._settings.strategy.isDefaultSelectCascadeEnabled))}render(t){t&&this._renderer.once(Us.RENDER_END,()=>t()),this._updateGraphPositions(),this._renderer.render(this._graph)}zoomIn(t){this._leaflet.zoomIn(),null==t||t()}recenter(t){const e=this._graph.getBoundingBox(),i=this._getStyleScale(),n=this._leaflet.layerPointToLatLng([e.x*i,e.y*i]),s=this._leaflet.layerPointToLatLng([(e.x+e.width)*i,(e.y+e.height)*i]);this._leaflet.fitBounds(ur.latLngBounds(n,s)),null==t||t()}zoomOut(t){this._leaflet.zoomOut(),null==t||t()}getSVG(){throw new Error("SVG export is not supported on OrbMapView.")}destroy(){this._renderer.destroy(),this._leaflet.off(),this._leaflet.remove(),this._leaflet.getContainer().outerHTML=""}_initMap(){const t=document.createElement("div");return t.style.position="absolute",t.style.width="100%",t.style.height="100%",t.style.zIndex="1",t.style.cursor="default",this._container.appendChild(t),t}_initLeaflet(){const t=ur.map(this._map,{doubleClickZoom:!1,zoomControl:!1}).setView([0,0],this._settings.map.zoomLevel);return t.on("zoomstart",()=>{this._renderer.reset()}),t.on("zoom",t=>{var i,n;this._updateGraphPositions(),null===(n=(i=this._renderer).invalidateBuffers)||void 0===n||n.call(i);const s=t.target._mapPane._leaflet_pos,o=this._getStyleScale();this._renderer.transform=Object.assign(Object.assign({},s),{k:o}),this._renderer.render(this._graph),this._events.emit(e.TRANSFORM,{transform:Object.assign(Object.assign({},s),{k:o})})}),t.on("mousemove",t=>{const i=this._toSimulationPoint(t.layerPoint),n={x:t.containerPoint.x,y:t.containerPoint.y},s=this._strategy.onMouseMove(this._graph,i),o=s.changedSubject;o&&s.isStateChanged&&(E(o)&&this._events.emit(e.NODE_HOVER,{node:o,event:t.originalEvent,localPoint:i,globalPoint:n}),L(o)&&this._events.emit(e.EDGE_HOVER,{edge:o,event:t.originalEvent,localPoint:i,globalPoint:n})),this._events.emit(e.MOUSE_MOVE,{subject:o,event:t.originalEvent,localPoint:i,globalPoint:n}),s.isStateChanged&&(this._invalidateStyles(),this._renderer.render(this._graph))}),t.on("click contextmenu dblclick",t=>{const i=this._toSimulationPoint(t.layerPoint),n={x:t.containerPoint.x,y:t.containerPoint.y};if("contextmenu"===t.type){const s=this._strategy.onMouseRightClick(this._graph,i),o=s.changedSubject;o&&(E(o)&&this._events.emit(e.NODE_RIGHT_CLICK,{node:o,event:t.originalEvent,localPoint:i,globalPoint:n}),L(o)&&this._events.emit(e.EDGE_RIGHT_CLICK,{edge:o,event:t.originalEvent,localPoint:i,globalPoint:n})),this._events.emit(e.MOUSE_RIGHT_CLICK,{subject:o,event:t.originalEvent,localPoint:i,globalPoint:n}),s.isStateChanged&&(this._invalidateStyles(),this._renderer.render(this._graph))}else if("click"===t.type){const s=this._strategy.onMouseClick(this._graph,i,{isAppend:t.originalEvent.shiftKey}),o=s.changedSubject;o&&(E(o)&&this._events.emit(e.NODE_CLICK,{node:o,event:t.originalEvent,localPoint:i,globalPoint:n}),L(o)&&this._events.emit(e.EDGE_CLICK,{edge:o,event:t.originalEvent,localPoint:i,globalPoint:n})),this._events.emit(e.MOUSE_CLICK,{subject:o,event:t.originalEvent,localPoint:i,globalPoint:n}),(s.isStateChanged||s.changedSubject)&&(this._invalidateStyles(),this._renderer.render(this._graph))}else if("dblclick"===t.type){const s=this._strategy.onMouseDoubleClick(this._graph,i),o=s.changedSubject;if(o&&(E(o)&&this._events.emit(e.NODE_DOUBLE_CLICK,{node:o,event:t.originalEvent,localPoint:i,globalPoint:n}),L(o)&&this._events.emit(e.EDGE_DOUBLE_CLICK,{edge:o,event:t.originalEvent,localPoint:i,globalPoint:n})),this._events.emit(e.MOUSE_DOUBLE_CLICK,{subject:o,event:t.originalEvent,localPoint:i,globalPoint:n}),!o){const e=t.target._zoom+1;t.target.setZoomAround(t.layerPoint,e)}(s.isStateChanged||s.changedSubject)&&(this._invalidateStyles(),this._renderer.render(this._graph))}}),t.on("moveend",t=>{const e=t.target._mapPane._leaflet_pos,i=this._getStyleScale();this._renderer.transform=Object.assign(Object.assign({},e),{k:i}),this._renderer.render(this._graph)}),t.on("drag",t=>{const i=t.target._mapPane._leaflet_pos,n=this._getStyleScale();this._renderer.transform=Object.assign(Object.assign({},i),{k:n}),this._renderer.render(this._graph),this._events.emit(e.TRANSFORM,{transform:Object.assign(Object.assign({},i),{k:n})})}),t}_updateGraphPositions(){const t=this._graph.getNodes(),e=this._getStyleScale();for(let i=0;i{this._leaflet.attributionControl.setPrefix(t.attribution),this._leaflet.eachLayer(t=>this._leaflet.removeLayer(t)),t.instance.addTo(this._leaflet)})}}})(),n})()); \ No newline at end of file +!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.Orb=e():t.Orb=e()}(self,()=>(()=>{var t={481(t,e){!function(t){"use strict";function e(t){var e,i,n,s;for(i=1,n=arguments.length;i0?Math.floor(t):Math.ceil(t)};function I(t,e,i){return t instanceof N?t:p(t)?new N(t[0],t[1]):null==t?t:"object"==typeof t&&"x"in t&&"y"in t?new N(t.x,t.y):new N(t,e,i)}function R(t,e){if(t)for(var i=e?[t,e]:t,n=0,s=i.length;n=this.min.x&&i.x<=this.max.x&&e.y>=this.min.y&&i.y<=this.max.y},intersects:function(t){t=O(t);var e=this.min,i=this.max,n=t.min,s=t.max,o=s.x>=e.x&&n.x<=i.x,r=s.y>=e.y&&n.y<=i.y;return o&&r},overlaps:function(t){t=O(t);var e=this.min,i=this.max,n=t.min,s=t.max,o=s.x>e.x&&n.xe.y&&n.y=n.lat&&i.lat<=s.lat&&e.lng>=n.lng&&i.lng<=s.lng},intersects:function(t){t=B(t);var e=this._southWest,i=this._northEast,n=t.getSouthWest(),s=t.getNorthEast(),o=s.lat>=e.lat&&n.lat<=i.lat,r=s.lng>=e.lng&&n.lng<=i.lng;return o&&r},overlaps:function(t){t=B(t);var e=this._southWest,i=this._northEast,n=t.getSouthWest(),s=t.getNorthEast(),o=s.lat>e.lat&&n.late.lng&&n.lng1,Ct=function(){var t=!1;try{var e=Object.defineProperty({},"passive",{get:function(){t=!0}});window.addEventListener("testPassiveEventSupport",h,e),window.removeEventListener("testPassiveEventSupport",h,e)}catch(t){}return t}(),Mt=!!document.createElement("canvas").getContext,Nt=!(!document.createElementNS||!Y("svg").createSVGRect),Dt=!!Nt&&((K=document.createElement("div")).innerHTML="","http://www.w3.org/2000/svg"===(K.firstChild&&K.firstChild.namespaceURI)),It=!Nt&&function(){try{var t=document.createElement("div");t.innerHTML='';var e=t.firstChild;return e.style.behavior="url(#default#VML)",e&&"object"==typeof e.adj}catch(t){return!1}}();function Lt(t){return navigator.userAgent.toLowerCase().indexOf(t)>=0}var Rt={ie:J,ielt9:tt,edge:et,webkit:it,android:nt,android23:st,androidStock:rt,opera:at,chrome:ht,gecko:lt,safari:dt,phantom:ut,opera12:ct,win:_t,ie3d:ft,webkit3d:gt,gecko3d:pt,any3d:mt,mobile:vt,mobileWebkit:yt,mobileWebkit3d:xt,msPointer:bt,pointer:St,touch:Tt,touchNative:wt,mobileOpera:Et,mobileGecko:Pt,retina:At,passiveEvents:Ct,canvas:Mt,svg:Nt,vml:It,inlineSvg:Dt,mac:0===navigator.platform.indexOf("Mac"),linux:0===navigator.platform.indexOf("Linux")},Ot=Rt.msPointer?"MSPointerDown":"pointerdown",kt=Rt.msPointer?"MSPointerMove":"pointermove",Bt=Rt.msPointer?"MSPointerUp":"pointerup",zt=Rt.msPointer?"MSPointerCancel":"pointercancel",Ut={touchstart:Ot,touchmove:kt,touchend:Bt,touchcancel:zt},Ft={touchstart:function(t,e){e.MSPOINTER_TYPE_TOUCH&&e.pointerType===e.MSPOINTER_TYPE_TOUCH&&Be(e),qt(t,e)},touchmove:qt,touchend:qt,touchcancel:qt},jt={},Wt=!1;function Gt(t,e,i){return"touchstart"===e&&(Wt||(document.addEventListener(Ot,Zt,!0),document.addEventListener(kt,Ht,!0),document.addEventListener(Bt,Xt,!0),document.addEventListener(zt,Xt,!0),Wt=!0)),Ft[e]?(i=Ft[e].bind(this,i),t.addEventListener(Ut[e],i,!1),i):(console.warn("wrong event specified:",e),h)}function Zt(t){jt[t.pointerId]=t}function Ht(t){jt[t.pointerId]&&(jt[t.pointerId]=t)}function Xt(t){delete jt[t.pointerId]}function qt(t,e){if(e.pointerType!==(e.MSPOINTER_TYPE_MOUSE||"mouse")){for(var i in e.touches=[],jt)e.touches.push(jt[i]);e.changedTouches=[e],t(e)}}var Vt,Yt,$t,Kt,Qt,Jt=ge(["transform","webkitTransform","OTransform","MozTransform","msTransform"]),te=ge(["webkitTransition","transition","OTransition","MozTransition","msTransition"]),ee="webkitTransition"===te||"OTransition"===te?te+"End":"transitionend";function ie(t){return"string"==typeof t?document.getElementById(t):t}function ne(t,e){var i=t.style[e]||t.currentStyle&&t.currentStyle[e];if((!i||"auto"===i)&&document.defaultView){var n=document.defaultView.getComputedStyle(t,null);i=n?n[e]:null}return"auto"===i?null:i}function se(t,e,i){var n=document.createElement(t);return n.className=e||"",i&&i.appendChild(n),n}function oe(t){var e=t.parentNode;e&&e.removeChild(t)}function re(t){for(;t.firstChild;)t.removeChild(t.firstChild)}function ae(t){var e=t.parentNode;e&&e.lastChild!==t&&e.appendChild(t)}function he(t){var e=t.parentNode;e&&e.firstChild!==t&&e.insertBefore(t,e.firstChild)}function le(t,e){if(void 0!==t.classList)return t.classList.contains(e);var i=_e(t);return i.length>0&&new RegExp("(^|\\s)"+e+"(\\s|$)").test(i)}function de(t,e){if(void 0!==t.classList)for(var i=u(e),n=0,s=i.length;n0?2*window.devicePixelRatio:1;function We(t){return Rt.edge?t.wheelDeltaY/2:t.deltaY&&0===t.deltaMode?-t.deltaY/je:t.deltaY&&1===t.deltaMode?20*-t.deltaY:t.deltaY&&2===t.deltaMode?60*-t.deltaY:t.deltaX||t.deltaZ?0:t.wheelDelta?(t.wheelDeltaY||t.wheelDelta)/2:t.detail&&Math.abs(t.detail)<32765?20*-t.detail:t.detail?t.detail/-32765*60:0}function Ge(t,e){var i=e.relatedTarget;if(!i)return!0;try{for(;i&&i!==t;)i=i.parentNode}catch(t){return!1}return i!==t}var Ze={__proto__:null,on:Ae,off:Me,stopPropagation:Re,disableScrollPropagation:Oe,disableClickPropagation:ke,preventDefault:Be,stop:ze,getPropagationPath:Ue,getMousePosition:Fe,getWheelDelta:We,isExternalTarget:Ge,addListener:Ae,removeListener:Me},He=M.extend({run:function(t,e,i,n){this.stop(),this._el=t,this._inProgress=!0,this._duration=i||.25,this._easeOutPower=1/Math.max(n||.5,.2),this._startPos=ve(t),this._offset=e.subtract(this._startPos),this._startTime=+new Date,this.fire("start"),this._animate()},stop:function(){this._inProgress&&(this._step(!0),this._complete())},_animate:function(){this._animId=T(this._animate,this),this._step()},_step:function(t){var e=+new Date-this._startTime,i=1e3*this._duration;ethis.options.maxZoom)?this.setZoom(t):this},panInsideBounds:function(t,e){this._enforcingBounds=!0;var i=this.getCenter(),n=this._limitCenter(i,this._zoom,B(t));return i.equals(n)||this.panTo(n,e),this._enforcingBounds=!1,this},panInside:function(t,e){var i=I((e=e||{}).paddingTopLeft||e.padding||[0,0]),n=I(e.paddingBottomRight||e.padding||[0,0]),s=this.project(this.getCenter()),o=this.project(t),r=this.getPixelBounds(),a=O([r.min.add(i),r.max.subtract(n)]),h=a.getSize();if(!a.contains(o)){this._enforcingBounds=!0;var l=o.subtract(a.getCenter()),d=a.extend(o).getSize().subtract(h);s.x+=l.x<0?-d.x:d.x,s.y+=l.y<0?-d.y:d.y,this.panTo(this.unproject(s),e),this._enforcingBounds=!1}return this},invalidateSize:function(t){if(!this._loaded)return this;t=e({animate:!1,pan:!0},!0===t?{animate:!0}:t);var i=this.getSize();this._sizeChanged=!0,this._lastCenter=null;var s=this.getSize(),o=i.divideBy(2).round(),r=s.divideBy(2).round(),a=o.subtract(r);return a.x||a.y?(t.animate&&t.pan?this.panBy(a):(t.pan&&this._rawPanBy(a),this.fire("move"),t.debounceMoveend?(clearTimeout(this._sizeTimer),this._sizeTimer=setTimeout(n(this.fire,this,"moveend"),200)):this.fire("moveend")),this.fire("resize",{oldSize:i,newSize:s})):this},stop:function(){return this.setZoom(this._limitZoom(this._zoom)),this.options.zoomSnap||this.fire("viewreset"),this._stop()},locate:function(t){if(t=this._locateOptions=e({timeout:1e4,watch:!1},t),!("geolocation"in navigator))return this._handleGeolocationError({code:0,message:"Geolocation not supported."}),this;var i=n(this._handleGeolocationResponse,this),s=n(this._handleGeolocationError,this);return t.watch?this._locationWatchId=navigator.geolocation.watchPosition(i,s,t):navigator.geolocation.getCurrentPosition(i,s,t),this},stopLocate:function(){return navigator.geolocation&&navigator.geolocation.clearWatch&&navigator.geolocation.clearWatch(this._locationWatchId),this._locateOptions&&(this._locateOptions.setView=!1),this},_handleGeolocationError:function(t){if(this._container._leaflet_id){var e=t.code,i=t.message||(1===e?"permission denied":2===e?"position unavailable":"timeout");this._locateOptions.setView&&!this._loaded&&this.fitWorld(),this.fire("locationerror",{code:e,message:"Geolocation error: "+i+"."})}},_handleGeolocationResponse:function(t){if(this._container._leaflet_id){var e=new z(t.coords.latitude,t.coords.longitude),i=e.toBounds(2*t.coords.accuracy),n=this._locateOptions;if(n.setView){var s=this.getBoundsZoom(i);this.setView(e,n.maxZoom?Math.min(s,n.maxZoom):s)}var o={latlng:e,bounds:i,timestamp:t.timestamp};for(var r in t.coords)"number"==typeof t.coords[r]&&(o[r]=t.coords[r]);this.fire("locationfound",o)}},addHandler:function(t,e){if(!e)return this;var i=this[t]=new e(this);return this._handlers.push(i),this.options[t]&&i.enable(),this},remove:function(){if(this._initEvents(!0),this.options.maxBounds&&this.off("moveend",this._panInsideMaxBounds),this._containerId!==this._container._leaflet_id)throw new Error("Map container is being reused by another instance");try{delete this._container._leaflet_id,delete this._containerId}catch(t){this._container._leaflet_id=void 0,this._containerId=void 0}var t;for(t in void 0!==this._locationWatchId&&this.stopLocate(),this._stop(),oe(this._mapPane),this._clearControlPos&&this._clearControlPos(),this._resizeRequest&&(E(this._resizeRequest),this._resizeRequest=null),this._clearHandlers(),this._loaded&&this.fire("unload"),this._layers)this._layers[t].remove();for(t in this._panes)oe(this._panes[t]);return this._layers=[],this._panes=[],delete this._mapPane,delete this._renderer,this},createPane:function(t,e){var i=se("div","leaflet-pane"+(t?" leaflet-"+t.replace("Pane","")+"-pane":""),e||this._mapPane);return t&&(this._panes[t]=i),i},getCenter:function(){return this._checkIfLoaded(),this._lastCenter&&!this._moved()?this._lastCenter.clone():this.layerPointToLatLng(this._getCenterLayerPoint())},getZoom:function(){return this._zoom},getBounds:function(){var t=this.getPixelBounds();return new k(this.unproject(t.getBottomLeft()),this.unproject(t.getTopRight()))},getMinZoom:function(){return void 0===this.options.minZoom?this._layersMinZoom||0:this.options.minZoom},getMaxZoom:function(){return void 0===this.options.maxZoom?void 0===this._layersMaxZoom?1/0:this._layersMaxZoom:this.options.maxZoom},getBoundsZoom:function(t,e,i){t=B(t),i=I(i||[0,0]);var n=this.getZoom()||0,s=this.getMinZoom(),o=this.getMaxZoom(),r=t.getNorthWest(),a=t.getSouthEast(),h=this.getSize().subtract(i),l=O(this.project(a,n),this.project(r,n)).getSize(),d=Rt.any3d?this.options.zoomSnap:1,u=h.x/l.x,c=h.y/l.y,_=e?Math.max(u,c):Math.min(u,c);return n=this.getScaleZoom(_,n),d&&(n=Math.round(n/(d/100))*(d/100),n=e?Math.ceil(n/d)*d:Math.floor(n/d)*d),Math.max(s,Math.min(o,n))},getSize:function(){return this._size&&!this._sizeChanged||(this._size=new N(this._container.clientWidth||0,this._container.clientHeight||0),this._sizeChanged=!1),this._size.clone()},getPixelBounds:function(t,e){var i=this._getTopLeftPoint(t,e);return new R(i,i.add(this.getSize()))},getPixelOrigin:function(){return this._checkIfLoaded(),this._pixelOrigin},getPixelWorldBounds:function(t){return this.options.crs.getProjectedBounds(void 0===t?this.getZoom():t)},getPane:function(t){return"string"==typeof t?this._panes[t]:t},getPanes:function(){return this._panes},getContainer:function(){return this._container},getZoomScale:function(t,e){var i=this.options.crs;return e=void 0===e?this._zoom:e,i.scale(t)/i.scale(e)},getScaleZoom:function(t,e){var i=this.options.crs;e=void 0===e?this._zoom:e;var n=i.zoom(t*i.scale(e));return isNaN(n)?1/0:n},project:function(t,e){return e=void 0===e?this._zoom:e,this.options.crs.latLngToPoint(U(t),e)},unproject:function(t,e){return e=void 0===e?this._zoom:e,this.options.crs.pointToLatLng(I(t),e)},layerPointToLatLng:function(t){var e=I(t).add(this.getPixelOrigin());return this.unproject(e)},latLngToLayerPoint:function(t){return this.project(U(t))._round()._subtract(this.getPixelOrigin())},wrapLatLng:function(t){return this.options.crs.wrapLatLng(U(t))},wrapLatLngBounds:function(t){return this.options.crs.wrapLatLngBounds(B(t))},distance:function(t,e){return this.options.crs.distance(U(t),U(e))},containerPointToLayerPoint:function(t){return I(t).subtract(this._getMapPanePos())},layerPointToContainerPoint:function(t){return I(t).add(this._getMapPanePos())},containerPointToLatLng:function(t){var e=this.containerPointToLayerPoint(I(t));return this.layerPointToLatLng(e)},latLngToContainerPoint:function(t){return this.layerPointToContainerPoint(this.latLngToLayerPoint(U(t)))},mouseEventToContainerPoint:function(t){return Fe(t,this._container)},mouseEventToLayerPoint:function(t){return this.containerPointToLayerPoint(this.mouseEventToContainerPoint(t))},mouseEventToLatLng:function(t){return this.layerPointToLatLng(this.mouseEventToLayerPoint(t))},_initContainer:function(t){var e=this._container=ie(t);if(!e)throw new Error("Map container not found.");if(e._leaflet_id)throw new Error("Map container is already initialized.");Ae(e,"scroll",this._onScroll,this),this._containerId=o(e)},_initLayout:function(){var t=this._container;this._fadeAnimated=this.options.fadeAnimation&&Rt.any3d,de(t,"leaflet-container"+(Rt.touch?" leaflet-touch":"")+(Rt.retina?" leaflet-retina":"")+(Rt.ielt9?" leaflet-oldie":"")+(Rt.safari?" leaflet-safari":"")+(this._fadeAnimated?" leaflet-fade-anim":""));var e=ne(t,"position");"absolute"!==e&&"relative"!==e&&"fixed"!==e&&"sticky"!==e&&(t.style.position="relative"),this._initPanes(),this._initControlPos&&this._initControlPos()},_initPanes:function(){var t=this._panes={};this._paneRenderers={},this._mapPane=this.createPane("mapPane",this._container),me(this._mapPane,new N(0,0)),this.createPane("tilePane"),this.createPane("overlayPane"),this.createPane("shadowPane"),this.createPane("markerPane"),this.createPane("tooltipPane"),this.createPane("popupPane"),this.options.markerZoomAnimation||(de(t.markerPane,"leaflet-zoom-hide"),de(t.shadowPane,"leaflet-zoom-hide"))},_resetView:function(t,e,i){me(this._mapPane,new N(0,0));var n=!this._loaded;this._loaded=!0,e=this._limitZoom(e),this.fire("viewprereset");var s=this._zoom!==e;this._moveStart(s,i)._move(t,e)._moveEnd(s),this.fire("viewreset"),n&&this.fire("load")},_moveStart:function(t,e){return t&&this.fire("zoomstart"),e||this.fire("movestart"),this},_move:function(t,e,i,n){void 0===e&&(e=this._zoom);var s=this._zoom!==e;return this._zoom=e,this._lastCenter=t,this._pixelOrigin=this._getNewPixelOrigin(t),n?i&&i.pinch&&this.fire("zoom",i):((s||i&&i.pinch)&&this.fire("zoom",i),this.fire("move",i)),this},_moveEnd:function(t){return t&&this.fire("zoomend"),this.fire("moveend")},_stop:function(){return E(this._flyToFrame),this._panAnim&&this._panAnim.stop(),this},_rawPanBy:function(t){me(this._mapPane,this._getMapPanePos().subtract(t))},_getZoomSpan:function(){return this.getMaxZoom()-this.getMinZoom()},_panInsideMaxBounds:function(){this._enforcingBounds||this.panInsideBounds(this.options.maxBounds)},_checkIfLoaded:function(){if(!this._loaded)throw new Error("Set map center and zoom first.")},_initEvents:function(t){this._targets={},this._targets[o(this._container)]=this;var e=t?Me:Ae;e(this._container,"click dblclick mousedown mouseup mouseover mouseout mousemove contextmenu keypress keydown keyup",this._handleDOMEvent,this),this.options.trackResize&&e(window,"resize",this._onResize,this),Rt.any3d&&this.options.transform3DLimit&&(t?this.off:this.on).call(this,"moveend",this._onMoveEnd)},_onResize:function(){E(this._resizeRequest),this._resizeRequest=T(function(){this.invalidateSize({debounceMoveend:!0})},this)},_onScroll:function(){this._container.scrollTop=0,this._container.scrollLeft=0},_onMoveEnd:function(){var t=this._getMapPanePos();Math.max(Math.abs(t.x),Math.abs(t.y))>=this.options.transform3DLimit&&this._resetView(this.getCenter(),this.getZoom())},_findEventTargets:function(t,e){for(var i,n=[],s="mouseout"===e||"mouseover"===e,r=t.target||t.srcElement,a=!1;r;){if((i=this._targets[o(r)])&&("click"===e||"preclick"===e)&&this._draggableMoved(i)){a=!0;break}if(i&&i.listens(e,!0)){if(s&&!Ge(r,t))break;if(n.push(i),s)break}if(r===this._container)break;r=r.parentNode}return n.length||a||s||!this.listens(e,!0)||(n=[this]),n},_isClickDisabled:function(t){for(;t&&t!==this._container;){if(t._leaflet_disable_click)return!0;t=t.parentNode}},_handleDOMEvent:function(t){var e=t.target||t.srcElement;if(!(!this._loaded||e._leaflet_disable_events||"click"===t.type&&this._isClickDisabled(e))){var i=t.type;"mousedown"===i&&Se(e),this._fireDOMEvent(t,i)}},_mouseEvents:["click","dblclick","mouseover","mouseout","contextmenu"],_fireDOMEvent:function(t,i,n){if("click"===t.type){var s=e({},t);s.type="preclick",this._fireDOMEvent(s,s.type,n)}var o=this._findEventTargets(t,i);if(n){for(var r=[],a=0;a0?Math.round(t-e)/2:Math.max(0,Math.ceil(t))-Math.max(0,Math.floor(e))},_limitZoom:function(t){var e=this.getMinZoom(),i=this.getMaxZoom(),n=Rt.any3d?this.options.zoomSnap:1;return n&&(t=Math.round(t/n)*n),Math.max(e,Math.min(i,t))},_onPanTransitionStep:function(){this.fire("move")},_onPanTransitionEnd:function(){ue(this._mapPane,"leaflet-pan-anim"),this.fire("moveend")},_tryAnimatedPan:function(t,e){var i=this._getCenterOffset(t)._trunc();return!(!0!==(e&&e.animate)&&!this.getSize().contains(i)||(this.panBy(i,e),0))},_createAnimProxy:function(){var t=this._proxy=se("div","leaflet-proxy leaflet-zoom-animated");this._panes.mapPane.appendChild(t),this.on("zoomanim",function(t){var e=Jt,i=this._proxy.style[e];pe(this._proxy,this.project(t.center,t.zoom),this.getZoomScale(t.zoom,1)),i===this._proxy.style[e]&&this._animatingZoom&&this._onZoomTransitionEnd()},this),this.on("load moveend",this._animMoveEnd,this),this._on("unload",this._destroyAnimProxy,this)},_destroyAnimProxy:function(){oe(this._proxy),this.off("load moveend",this._animMoveEnd,this),delete this._proxy},_animMoveEnd:function(){var t=this.getCenter(),e=this.getZoom();pe(this._proxy,this.project(t,e),this.getZoomScale(e,1))},_catchTransitionEnd:function(t){this._animatingZoom&&t.propertyName.indexOf("transform")>=0&&this._onZoomTransitionEnd()},_nothingToAnimate:function(){return!this._container.getElementsByClassName("leaflet-zoom-animated").length},_tryAnimatedZoom:function(t,e,i){if(this._animatingZoom)return!0;if(i=i||{},!this._zoomAnimated||!1===i.animate||this._nothingToAnimate()||Math.abs(e-this._zoom)>this.options.zoomAnimationThreshold)return!1;var n=this.getZoomScale(e),s=this._getCenterOffset(t)._divideBy(1-1/n);return!(!0!==i.animate&&!this.getSize().contains(s)||(T(function(){this._moveStart(!0,i.noMoveStart||!1)._animateZoom(t,e,!0)},this),0))},_animateZoom:function(t,e,i,s){this._mapPane&&(i&&(this._animatingZoom=!0,this._animateToCenter=t,this._animateToZoom=e,de(this._mapPane,"leaflet-zoom-anim")),this.fire("zoomanim",{center:t,zoom:e,noUpdate:s}),this._tempFireZoomEvent||(this._tempFireZoomEvent=this._zoom!==this._animateToZoom),this._move(this._animateToCenter,this._animateToZoom,void 0,!0),setTimeout(n(this._onZoomTransitionEnd,this),250))},_onZoomTransitionEnd:function(){this._animatingZoom&&(this._mapPane&&ue(this._mapPane,"leaflet-zoom-anim"),this._animatingZoom=!1,this._move(this._animateToCenter,this._animateToZoom,void 0,!0),this._tempFireZoomEvent&&this.fire("zoom"),delete this._tempFireZoomEvent,this.fire("move"),this._moveEnd(!0))}});var qe=A.extend({options:{position:"topright"},initialize:function(t){c(this,t)},getPosition:function(){return this.options.position},setPosition:function(t){var e=this._map;return e&&e.removeControl(this),this.options.position=t,e&&e.addControl(this),this},getContainer:function(){return this._container},addTo:function(t){this.remove(),this._map=t;var e=this._container=this.onAdd(t),i=this.getPosition(),n=t._controlCorners[i];return de(e,"leaflet-control"),-1!==i.indexOf("bottom")?n.insertBefore(e,n.firstChild):n.appendChild(e),this._map.on("unload",this.remove,this),this},remove:function(){return this._map?(oe(this._container),this.onRemove&&this.onRemove(this._map),this._map.off("unload",this.remove,this),this._map=null,this):this},_refocusOnMap:function(t){this._map&&t&&t.screenX>0&&t.screenY>0&&this._map.getContainer().focus()}}),Ve=function(t){return new qe(t)};Xe.include({addControl:function(t){return t.addTo(this),this},removeControl:function(t){return t.remove(),this},_initControlPos:function(){var t=this._controlCorners={},e="leaflet-",i=this._controlContainer=se("div",e+"control-container",this._container);function n(n,s){var o=e+n+" "+e+s;t[n+s]=se("div",o,i)}n("top","left"),n("top","right"),n("bottom","left"),n("bottom","right")},_clearControlPos:function(){for(var t in this._controlCorners)oe(this._controlCorners[t]);oe(this._controlContainer),delete this._controlCorners,delete this._controlContainer}});var Ye=qe.extend({options:{collapsed:!0,position:"topright",autoZIndex:!0,hideSingleBase:!1,sortLayers:!1,sortFunction:function(t,e,i,n){return i1,this._baseLayersList.style.display=t?"":"none"),this._separator.style.display=e&&t?"":"none",this},_onLayerChange:function(t){this._handlingClick||this._update();var e=this._getLayer(o(t.target)),i=e.overlay?"add"===t.type?"overlayadd":"overlayremove":"add"===t.type?"baselayerchange":null;i&&this._map.fire(i,e)},_createRadioElement:function(t,e){var i='",n=document.createElement("div");return n.innerHTML=i,n.firstChild},_addItem:function(t){var e,i=document.createElement("label"),n=this._map.hasLayer(t.layer);t.overlay?((e=document.createElement("input")).type="checkbox",e.className="leaflet-control-layers-selector",e.defaultChecked=n):e=this._createRadioElement("leaflet-base-layers_"+o(this),n),this._layerControlInputs.push(e),e.layerId=o(t.layer),Ae(e,"click",this._onInputClick,this);var s=document.createElement("span");s.innerHTML=" "+t.name;var r=document.createElement("span");return i.appendChild(r),r.appendChild(e),r.appendChild(s),(t.overlay?this._overlaysList:this._baseLayersList).appendChild(i),this._checkDisabledLayers(),i},_onInputClick:function(){if(!this._preventClick){var t,e,i=this._layerControlInputs,n=[],s=[];this._handlingClick=!0;for(var o=i.length-1;o>=0;o--)t=i[o],e=this._getLayer(t.layerId).layer,t.checked?n.push(e):t.checked||s.push(e);for(o=0;o=0;s--)t=i[s],e=this._getLayer(t.layerId).layer,t.disabled=void 0!==e.options.minZoom&&ne.options.maxZoom},_expandIfNotCollapsed:function(){return this._map&&!this.options.collapsed&&this.expand(),this},_expandSafely:function(){var t=this._section;this._preventClick=!0,Ae(t,"click",Be),this.expand();var e=this;setTimeout(function(){Me(t,"click",Be),e._preventClick=!1})}}),$e=qe.extend({options:{position:"topleft",zoomInText:'',zoomInTitle:"Zoom in",zoomOutText:'',zoomOutTitle:"Zoom out"},onAdd:function(t){var e="leaflet-control-zoom",i=se("div",e+" leaflet-bar"),n=this.options;return this._zoomInButton=this._createButton(n.zoomInText,n.zoomInTitle,e+"-in",i,this._zoomIn),this._zoomOutButton=this._createButton(n.zoomOutText,n.zoomOutTitle,e+"-out",i,this._zoomOut),this._updateDisabled(),t.on("zoomend zoomlevelschange",this._updateDisabled,this),i},onRemove:function(t){t.off("zoomend zoomlevelschange",this._updateDisabled,this)},disable:function(){return this._disabled=!0,this._updateDisabled(),this},enable:function(){return this._disabled=!1,this._updateDisabled(),this},_zoomIn:function(t){!this._disabled&&this._map._zoomthis._map.getMinZoom()&&this._map.zoomOut(this._map.options.zoomDelta*(t.shiftKey?3:1))},_createButton:function(t,e,i,n,s){var o=se("a",i,n);return o.innerHTML=t,o.href="#",o.title=e,o.setAttribute("role","button"),o.setAttribute("aria-label",e),ke(o),Ae(o,"click",ze),Ae(o,"click",s,this),Ae(o,"click",this._refocusOnMap,this),o},_updateDisabled:function(){var t=this._map,e="leaflet-disabled";ue(this._zoomInButton,e),ue(this._zoomOutButton,e),this._zoomInButton.setAttribute("aria-disabled","false"),this._zoomOutButton.setAttribute("aria-disabled","false"),(this._disabled||t._zoom===t.getMinZoom())&&(de(this._zoomOutButton,e),this._zoomOutButton.setAttribute("aria-disabled","true")),(this._disabled||t._zoom===t.getMaxZoom())&&(de(this._zoomInButton,e),this._zoomInButton.setAttribute("aria-disabled","true"))}});Xe.mergeOptions({zoomControl:!0}),Xe.addInitHook(function(){this.options.zoomControl&&(this.zoomControl=new $e,this.addControl(this.zoomControl))});var Ke=qe.extend({options:{position:"bottomleft",maxWidth:100,metric:!0,imperial:!0},onAdd:function(t){var e="leaflet-control-scale",i=se("div",e),n=this.options;return this._addScales(n,e+"-line",i),t.on(n.updateWhenIdle?"moveend":"move",this._update,this),t.whenReady(this._update,this),i},onRemove:function(t){t.off(this.options.updateWhenIdle?"moveend":"move",this._update,this)},_addScales:function(t,e,i){t.metric&&(this._mScale=se("div",e,i)),t.imperial&&(this._iScale=se("div",e,i))},_update:function(){var t=this._map,e=t.getSize().y/2,i=t.distance(t.containerPointToLatLng([0,e]),t.containerPointToLatLng([this.options.maxWidth,e]));this._updateScales(i)},_updateScales:function(t){this.options.metric&&t&&this._updateMetric(t),this.options.imperial&&t&&this._updateImperial(t)},_updateMetric:function(t){var e=this._getRoundNum(t),i=e<1e3?e+" m":e/1e3+" km";this._updateScale(this._mScale,i,e/t)},_updateImperial:function(t){var e,i,n,s=3.2808399*t;s>5280?(e=s/5280,i=this._getRoundNum(e),this._updateScale(this._iScale,i+" mi",i/e)):(n=this._getRoundNum(s),this._updateScale(this._iScale,n+" ft",n/s))},_updateScale:function(t,e,i){t.style.width=Math.round(this.options.maxWidth*i)+"px",t.innerHTML=e},_getRoundNum:function(t){var e=Math.pow(10,(Math.floor(t)+"").length-1),i=t/e;return e*(i>=10?10:i>=5?5:i>=3?3:i>=2?2:1)}}),Qe=qe.extend({options:{position:"bottomright",prefix:''+(Rt.inlineSvg?' ':"")+"Leaflet"},initialize:function(t){c(this,t),this._attributions={}},onAdd:function(t){for(var e in t.attributionControl=this,this._container=se("div","leaflet-control-attribution"),ke(this._container),t._layers)t._layers[e].getAttribution&&this.addAttribution(t._layers[e].getAttribution());return this._update(),t.on("layeradd",this._addAttribution,this),this._container},onRemove:function(t){t.off("layeradd",this._addAttribution,this)},_addAttribution:function(t){t.layer.getAttribution&&(this.addAttribution(t.layer.getAttribution()),t.layer.once("remove",function(){this.removeAttribution(t.layer.getAttribution())},this))},setPrefix:function(t){return this.options.prefix=t,this._update(),this},addAttribution:function(t){return t?(this._attributions[t]||(this._attributions[t]=0),this._attributions[t]++,this._update(),this):this},removeAttribution:function(t){return t?(this._attributions[t]&&(this._attributions[t]--,this._update()),this):this},_update:function(){if(this._map){var t=[];for(var e in this._attributions)this._attributions[e]&&t.push(e);var i=[];this.options.prefix&&i.push(this.options.prefix),t.length&&i.push(t.join(", ")),this._container.innerHTML=i.join(' ')}}});Xe.mergeOptions({attributionControl:!0}),Xe.addInitHook(function(){this.options.attributionControl&&(new Qe).addTo(this)});qe.Layers=Ye,qe.Zoom=$e,qe.Scale=Ke,qe.Attribution=Qe,Ve.layers=function(t,e,i){return new Ye(t,e,i)},Ve.zoom=function(t){return new $e(t)},Ve.scale=function(t){return new Ke(t)},Ve.attribution=function(t){return new Qe(t)};var Je=A.extend({initialize:function(t){this._map=t},enable:function(){return this._enabled||(this._enabled=!0,this.addHooks()),this},disable:function(){return this._enabled?(this._enabled=!1,this.removeHooks(),this):this},enabled:function(){return!!this._enabled}});Je.addTo=function(t,e){return t.addHandler(e,this),this};var ti={Events:C},ei=Rt.touch?"touchstart mousedown":"mousedown",ii=M.extend({options:{clickTolerance:3},initialize:function(t,e,i,n){c(this,n),this._element=t,this._dragStartTarget=e||t,this._preventOutline=i},enable:function(){this._enabled||(Ae(this._dragStartTarget,ei,this._onDown,this),this._enabled=!0)},disable:function(){this._enabled&&(ii._dragging===this&&this.finishDrag(!0),Me(this._dragStartTarget,ei,this._onDown,this),this._enabled=!1,this._moved=!1)},_onDown:function(t){if(this._enabled&&(this._moved=!1,!le(this._element,"leaflet-zoom-anim")))if(t.touches&&1!==t.touches.length)ii._dragging===this&&this.finishDrag();else if(!(ii._dragging||t.shiftKey||1!==t.which&&1!==t.button&&!t.touches||(ii._dragging=this,this._preventOutline&&Se(this._element),xe(),Vt(),this._moving))){this.fire("down");var e=t.touches?t.touches[0]:t,i=Te(this._element);this._startPoint=new N(e.clientX,e.clientY),this._startPos=ve(this._element),this._parentScale=Ee(i);var n="mousedown"===t.type;Ae(document,n?"mousemove":"touchmove",this._onMove,this),Ae(document,n?"mouseup":"touchend touchcancel",this._onUp,this)}},_onMove:function(t){if(this._enabled)if(t.touches&&t.touches.length>1)this._moved=!0;else{var e=t.touches&&1===t.touches.length?t.touches[0]:t,i=new N(e.clientX,e.clientY)._subtract(this._startPoint);(i.x||i.y)&&(Math.abs(i.x)+Math.abs(i.y)e&&(i.push(t[n]),s=n);return sh&&(o=r,h=a);h>i&&(e[o]=1,di(t,e,i,n,o),di(t,e,i,o,s))}function ui(t,e,i,n,s){var o,r,a,h=n?ri:_i(t,i),l=_i(e,i);for(ri=l;;){if(!(h|l))return[t,e];if(h&l)return!1;a=_i(r=ci(t,e,o=h||l,i,s),i),o===h?(t=r,h=a):(e=r,l=a)}}function ci(t,e,i,n,s){var o,r,a=e.x-t.x,h=e.y-t.y,l=n.min,d=n.max;return 8&i?(o=t.x+a*(d.y-t.y)/h,r=d.y):4&i?(o=t.x+a*(l.y-t.y)/h,r=l.y):2&i?(o=d.x,r=t.y+h*(d.x-t.x)/a):1&i&&(o=l.x,r=t.y+h*(l.x-t.x)/a),new N(o,r,s)}function _i(t,e){var i=0;return t.xe.max.x&&(i|=2),t.ye.max.y&&(i|=8),i}function fi(t,e){var i=e.x-t.x,n=e.y-t.y;return i*i+n*n}function gi(t,e,i,n){var s,o=e.x,r=e.y,a=i.x-o,h=i.y-r,l=a*a+h*h;return l>0&&((s=((t.x-o)*a+(t.y-r)*h)/l)>1?(o=i.x,r=i.y):s>0&&(o+=a*s,r+=h*s)),a=t.x-o,h=t.y-r,n?a*a+h*h:new N(o,r)}function pi(t){return!p(t[0])||"object"!=typeof t[0][0]&&void 0!==t[0][0]}function mi(t){return console.warn("Deprecated use of _flat, please use L.LineUtil.isFlat instead."),pi(t)}function vi(t,e){var i,n,s,o,r,a,h,l;if(!t||0===t.length)throw new Error("latlngs not passed");pi(t)||(console.warn("latlngs are not flat! Only the first ring will be used"),t=t[0]);var d=U([0,0]),u=B(t);u.getNorthWest().distanceTo(u.getSouthWest())*u.getNorthEast().distanceTo(u.getNorthWest())<1700&&(d=oi(t));var c=t.length,_=[];for(i=0;in){h=(o-n)/s,l=[a.x-h*(a.x-r.x),a.y-h*(a.y-r.y)];break}var g=e.unproject(I(l));return U([g.lat+d.lat,g.lng+d.lng])}var yi={__proto__:null,simplify:hi,pointToSegmentDistance:li,closestPointOnSegment:function(t,e,i){return gi(t,e,i)},clipSegment:ui,_getEdgeIntersection:ci,_getBitCode:_i,_sqClosestPointOnSegment:gi,isFlat:pi,_flat:mi,polylineCenter:vi},xi={project:function(t){return new N(t.lng,t.lat)},unproject:function(t){return new z(t.y,t.x)},bounds:new R([-180,-90],[180,90])},bi={R:6378137,R_MINOR:6356752.314245179,bounds:new R([-20037508.34279,-15496570.73972],[20037508.34279,18764656.23138]),project:function(t){var e=Math.PI/180,i=this.R,n=t.lat*e,s=this.R_MINOR/i,o=Math.sqrt(1-s*s),r=o*Math.sin(n),a=Math.tan(Math.PI/4-n/2)/Math.pow((1-r)/(1+r),o/2);return n=-i*Math.log(Math.max(a,1e-10)),new N(t.lng*e*i,n)},unproject:function(t){for(var e,i=180/Math.PI,n=this.R,s=this.R_MINOR/n,o=Math.sqrt(1-s*s),r=Math.exp(-t.y/n),a=Math.PI/2-2*Math.atan(r),h=0,l=.1;h<15&&Math.abs(l)>1e-7;h++)e=o*Math.sin(a),e=Math.pow((1-e)/(1+e),o/2),a+=l=Math.PI/2-2*Math.atan(r*e)-a;return new z(a*i,t.x*i/n)}},Si={__proto__:null,LonLat:xi,Mercator:bi,SphericalMercator:Z},wi=e({},W,{code:"EPSG:3395",projection:bi,transformation:function(){var t=.5/(Math.PI*bi.R);return X(t,.5,-t,.5)}()}),Ti=e({},W,{code:"EPSG:4326",projection:xi,transformation:X(1/180,1,-1/180,.5)}),Ei=e({},j,{projection:xi,transformation:X(1,0,-1,0),scale:function(t){return Math.pow(2,t)},zoom:function(t){return Math.log(t)/Math.LN2},distance:function(t,e){var i=e.lng-t.lng,n=e.lat-t.lat;return Math.sqrt(i*i+n*n)},infinite:!0});j.Earth=W,j.EPSG3395=wi,j.EPSG3857=q,j.EPSG900913=V,j.EPSG4326=Ti,j.Simple=Ei;var Pi=M.extend({options:{pane:"overlayPane",attribution:null,bubblingMouseEvents:!0},addTo:function(t){return t.addLayer(this),this},remove:function(){return this.removeFrom(this._map||this._mapToAdd)},removeFrom:function(t){return t&&t.removeLayer(this),this},getPane:function(t){return this._map.getPane(t?this.options[t]||t:this.options.pane)},addInteractiveTarget:function(t){return this._map._targets[o(t)]=this,this},removeInteractiveTarget:function(t){return delete this._map._targets[o(t)],this},getAttribution:function(){return this.options.attribution},_layerAdd:function(t){var e=t.target;if(e.hasLayer(this)){if(this._map=e,this._zoomAnimated=e._zoomAnimated,this.getEvents){var i=this.getEvents();e.on(i,this),this.once("remove",function(){e.off(i,this)},this)}this.onAdd(e),this.fire("add"),e.fire("layeradd",{layer:this})}}});Xe.include({addLayer:function(t){if(!t._layerAdd)throw new Error("The provided object is not a Layer.");var e=o(t);return this._layers[e]||(this._layers[e]=t,t._mapToAdd=this,t.beforeAdd&&t.beforeAdd(this),this.whenReady(t._layerAdd,t)),this},removeLayer:function(t){var e=o(t);return this._layers[e]?(this._loaded&&t.onRemove(this),delete this._layers[e],this._loaded&&(this.fire("layerremove",{layer:t}),t.fire("remove")),t._map=t._mapToAdd=null,this):this},hasLayer:function(t){return o(t)in this._layers},eachLayer:function(t,e){for(var i in this._layers)t.call(e,this._layers[i]);return this},_addLayers:function(t){for(var e=0,i=(t=t?p(t)?t:[t]:[]).length;ethis._layersMaxZoom&&this.setZoom(this._layersMaxZoom),void 0===this.options.minZoom&&this._layersMinZoom&&this.getZoom()=2&&e[0]instanceof z&&e[0].equals(e[i-1])&&e.pop(),e},_setLatLngs:function(t){ki.prototype._setLatLngs.call(this,t),pi(this._latlngs)&&(this._latlngs=[this._latlngs])},_defaultShape:function(){return pi(this._latlngs[0])?this._latlngs[0]:this._latlngs[0][0]},_clipPoints:function(){var t=this._renderer._bounds,e=this.options.weight,i=new N(e,e);if(t=new R(t.min.subtract(i),t.max.add(i)),this._parts=[],this._pxBounds&&this._pxBounds.intersects(t))if(this.options.noClip)this._parts=this._rings;else for(var n,s=0,o=this._rings.length;st.y!=n.y>t.y&&t.x<(n.x-i.x)*(t.y-i.y)/(n.y-i.y)+i.x&&(l=!l);return l||ki.prototype._containsPoint.call(this,t,!0)}});var zi=Ci.extend({initialize:function(t,e){c(this,e),this._layers={},t&&this.addData(t)},addData:function(t){var e,i,n,s=p(t)?t:t.features;if(s){for(e=0,i=s.length;e0&&s.push(s[0].slice()),s}function Hi(t,i){return t.feature?e({},t.feature,{geometry:i}):Xi(i)}function Xi(t){return"Feature"===t.type||"FeatureCollection"===t.type?t:{type:"Feature",properties:{},geometry:t}}var qi={toGeoJSON:function(t){return Hi(this,{type:"Point",coordinates:Gi(this.getLatLng(),t)})}};function Vi(t,e){return new zi(t,e)}Ii.include(qi),Oi.include(qi),Ri.include(qi),ki.include({toGeoJSON:function(t){var e=!pi(this._latlngs);return Hi(this,{type:(e?"Multi":"")+"LineString",coordinates:Zi(this._latlngs,e?1:0,!1,t)})}}),Bi.include({toGeoJSON:function(t){var e=!pi(this._latlngs),i=e&&!pi(this._latlngs[0]),n=Zi(this._latlngs,i?2:e?1:0,!0,t);return e||(n=[n]),Hi(this,{type:(i?"Multi":"")+"Polygon",coordinates:n})}}),Ai.include({toMultiPoint:function(t){var e=[];return this.eachLayer(function(i){e.push(i.toGeoJSON(t).geometry.coordinates)}),Hi(this,{type:"MultiPoint",coordinates:e})},toGeoJSON:function(t){var e=this.feature&&this.feature.geometry&&this.feature.geometry.type;if("MultiPoint"===e)return this.toMultiPoint(t);var i="GeometryCollection"===e,n=[];return this.eachLayer(function(e){if(e.toGeoJSON){var s=e.toGeoJSON(t);if(i)n.push(s.geometry);else{var o=Xi(s);"FeatureCollection"===o.type?n.push.apply(n,o.features):n.push(o)}}}),i?Hi(this,{geometries:n,type:"GeometryCollection"}):{type:"FeatureCollection",features:n}}});var Yi=Vi,$i=Pi.extend({options:{opacity:1,alt:"",interactive:!1,crossOrigin:!1,errorOverlayUrl:"",zIndex:1,className:""},initialize:function(t,e,i){this._url=t,this._bounds=B(e),c(this,i)},onAdd:function(){this._image||(this._initImage(),this.options.opacity<1&&this._updateOpacity()),this.options.interactive&&(de(this._image,"leaflet-interactive"),this.addInteractiveTarget(this._image)),this.getPane().appendChild(this._image),this._reset()},onRemove:function(){oe(this._image),this.options.interactive&&this.removeInteractiveTarget(this._image)},setOpacity:function(t){return this.options.opacity=t,this._image&&this._updateOpacity(),this},setStyle:function(t){return t.opacity&&this.setOpacity(t.opacity),this},bringToFront:function(){return this._map&&ae(this._image),this},bringToBack:function(){return this._map&&he(this._image),this},setUrl:function(t){return this._url=t,this._image&&(this._image.src=t),this},setBounds:function(t){return this._bounds=B(t),this._map&&this._reset(),this},getEvents:function(){var t={zoom:this._reset,viewreset:this._reset};return this._zoomAnimated&&(t.zoomanim=this._animateZoom),t},setZIndex:function(t){return this.options.zIndex=t,this._updateZIndex(),this},getBounds:function(){return this._bounds},getElement:function(){return this._image},_initImage:function(){var t="IMG"===this._url.tagName,e=this._image=t?this._url:se("img");de(e,"leaflet-image-layer"),this._zoomAnimated&&de(e,"leaflet-zoom-animated"),this.options.className&&de(e,this.options.className),e.onselectstart=h,e.onmousemove=h,e.onload=n(this.fire,this,"load"),e.onerror=n(this._overlayOnError,this,"error"),(this.options.crossOrigin||""===this.options.crossOrigin)&&(e.crossOrigin=!0===this.options.crossOrigin?"":this.options.crossOrigin),this.options.zIndex&&this._updateZIndex(),t?this._url=e.src:(e.src=this._url,e.alt=this.options.alt)},_animateZoom:function(t){var e=this._map.getZoomScale(t.zoom),i=this._map._latLngBoundsToNewLayerBounds(this._bounds,t.zoom,t.center).min;pe(this._image,i,e)},_reset:function(){var t=this._image,e=new R(this._map.latLngToLayerPoint(this._bounds.getNorthWest()),this._map.latLngToLayerPoint(this._bounds.getSouthEast())),i=e.getSize();me(t,e.min),t.style.width=i.x+"px",t.style.height=i.y+"px"},_updateOpacity:function(){fe(this._image,this.options.opacity)},_updateZIndex:function(){this._image&&void 0!==this.options.zIndex&&null!==this.options.zIndex&&(this._image.style.zIndex=this.options.zIndex)},_overlayOnError:function(){this.fire("error");var t=this.options.errorOverlayUrl;t&&this._url!==t&&(this._url=t,this._image.src=t)},getCenter:function(){return this._bounds.getCenter()}}),Ki=$i.extend({options:{autoplay:!0,loop:!0,keepAspectRatio:!0,muted:!1,playsInline:!0},_initImage:function(){var t="VIDEO"===this._url.tagName,e=this._image=t?this._url:se("video");if(de(e,"leaflet-image-layer"),this._zoomAnimated&&de(e,"leaflet-zoom-animated"),this.options.className&&de(e,this.options.className),e.onselectstart=h,e.onmousemove=h,e.onloadeddata=n(this.fire,this,"load"),t){for(var i=e.getElementsByTagName("source"),s=[],o=0;o0?s:[e.src]}else{p(this._url)||(this._url=[this._url]),!this.options.keepAspectRatio&&Object.prototype.hasOwnProperty.call(e.style,"objectFit")&&(e.style.objectFit="fill"),e.autoplay=!!this.options.autoplay,e.loop=!!this.options.loop,e.muted=!!this.options.muted,e.playsInline=!!this.options.playsInline;for(var r=0;rs?(e.height=s+"px",de(t,o)):ue(t,o),this._containerWidth=this._container.offsetWidth},_animateZoom:function(t){var e=this._map._latLngToNewLayerPoint(this._latlng,t.zoom,t.center),i=this._getAnchor();me(this._container,e.add(i))},_adjustPan:function(){if(this.options.autoPan)if(this._map._panAnim&&this._map._panAnim.stop(),this._autopanning)this._autopanning=!1;else{var t=this._map,e=parseInt(ne(this._container,"marginBottom"),10)||0,i=this._container.offsetHeight+e,n=this._containerWidth,s=new N(this._containerLeft,-i-this._containerBottom);s._add(ve(this._container));var o=t.layerPointToContainerPoint(s),r=I(this.options.autoPanPadding),a=I(this.options.autoPanPaddingTopLeft||r),h=I(this.options.autoPanPaddingBottomRight||r),l=t.getSize(),d=0,u=0;o.x+n+h.x>l.x&&(d=o.x+n-l.x+h.x),o.x-d-a.x<0&&(d=o.x-a.x),o.y+i+h.y>l.y&&(u=o.y+i-l.y+h.y),o.y-u-a.y<0&&(u=o.y-a.y),(d||u)&&(this.options.keepInView&&(this._autopanning=!0),t.fire("autopanstart").panBy([d,u]))}},_getAnchor:function(){return I(this._source&&this._source._getPopupAnchor?this._source._getPopupAnchor():[0,0])}});Xe.mergeOptions({closePopupOnClick:!0}),Xe.include({openPopup:function(t,e,i){return this._initOverlay(tn,t,e,i).openOn(this),this},closePopup:function(t){return(t=arguments.length?t:this._popup)&&t.close(),this}}),Pi.include({bindPopup:function(t,e){return this._popup=this._initOverlay(tn,this._popup,t,e),this._popupHandlersAdded||(this.on({click:this._openPopup,keypress:this._onKeyPress,remove:this.closePopup,move:this._movePopup}),this._popupHandlersAdded=!0),this},unbindPopup:function(){return this._popup&&(this.off({click:this._openPopup,keypress:this._onKeyPress,remove:this.closePopup,move:this._movePopup}),this._popupHandlersAdded=!1,this._popup=null),this},openPopup:function(t){return this._popup&&(this instanceof Ci||(this._popup._source=this),this._popup._prepareOpen(t||this._latlng)&&this._popup.openOn(this._map)),this},closePopup:function(){return this._popup&&this._popup.close(),this},togglePopup:function(){return this._popup&&this._popup.toggle(this),this},isPopupOpen:function(){return!!this._popup&&this._popup.isOpen()},setPopupContent:function(t){return this._popup&&this._popup.setContent(t),this},getPopup:function(){return this._popup},_openPopup:function(t){if(this._popup&&this._map){ze(t);var e=t.layer||t.target;this._popup._source!==e||e instanceof Li?(this._popup._source=e,this.openPopup(t.latlng)):this._map.hasLayer(this._popup)?this.closePopup():this.openPopup(t.latlng)}},_movePopup:function(t){this._popup.setLatLng(t.latlng)},_onKeyPress:function(t){13===t.originalEvent.keyCode&&this._openPopup(t)}});var en=Ji.extend({options:{pane:"tooltipPane",offset:[0,0],direction:"auto",permanent:!1,sticky:!1,opacity:.9},onAdd:function(t){Ji.prototype.onAdd.call(this,t),this.setOpacity(this.options.opacity),t.fire("tooltipopen",{tooltip:this}),this._source&&(this.addEventParent(this._source),this._source.fire("tooltipopen",{tooltip:this},!0))},onRemove:function(t){Ji.prototype.onRemove.call(this,t),t.fire("tooltipclose",{tooltip:this}),this._source&&(this.removeEventParent(this._source),this._source.fire("tooltipclose",{tooltip:this},!0))},getEvents:function(){var t=Ji.prototype.getEvents.call(this);return this.options.permanent||(t.preclick=this.close),t},_initLayout:function(){var t="leaflet-tooltip "+(this.options.className||"")+" leaflet-zoom-"+(this._zoomAnimated?"animated":"hide");this._contentNode=this._container=se("div",t),this._container.setAttribute("role","tooltip"),this._container.setAttribute("id","leaflet-tooltip-"+o(this))},_updateLayout:function(){},_adjustPan:function(){},_setPosition:function(t){var e,i,n=this._map,s=this._container,o=n.latLngToContainerPoint(n.getCenter()),r=n.layerPointToContainerPoint(t),a=this.options.direction,h=s.offsetWidth,l=s.offsetHeight,d=I(this.options.offset),u=this._getAnchor();"top"===a?(e=h/2,i=l):"bottom"===a?(e=h/2,i=0):"center"===a?(e=h/2,i=l/2):"right"===a?(e=0,i=l/2):"left"===a?(e=h,i=l/2):r.xthis.options.maxZoom||in&&this._retainParent(s,o,r,n))},_retainChildren:function(t,e,i,n){for(var s=2*t;s<2*t+2;s++)for(var o=2*e;o<2*e+2;o++){var r=new N(s,o);r.z=i+1;var a=this._tileCoordsToKey(r),h=this._tiles[a];h&&h.active?h.retain=!0:(h&&h.loaded&&(h.retain=!0),i+1this.options.maxZoom||void 0!==this.options.minZoom&&s1)this._setView(t,i);else{for(var u=s.min.y;u<=s.max.y;u++)for(var c=s.min.x;c<=s.max.x;c++){var _=new N(c,u);if(_.z=this._tileZoom,this._isValidTile(_)){var f=this._tiles[this._tileCoordsToKey(_)];f?f.current=!0:r.push(_)}}if(r.sort(function(t,e){return t.distanceTo(o)-e.distanceTo(o)}),0!==r.length){this._loading||(this._loading=!0,this.fire("loading"));var g=document.createDocumentFragment();for(c=0;ci.max.x)||!e.wrapLat&&(t.yi.max.y))return!1}if(!this.options.bounds)return!0;var n=this._tileCoordsToBounds(t);return B(this.options.bounds).overlaps(n)},_keyToBounds:function(t){return this._tileCoordsToBounds(this._keyToTileCoords(t))},_tileCoordsToNwSe:function(t){var e=this._map,i=this.getTileSize(),n=t.scaleBy(i),s=n.add(i);return[e.unproject(n,t.z),e.unproject(s,t.z)]},_tileCoordsToBounds:function(t){var e=this._tileCoordsToNwSe(t),i=new k(e[0],e[1]);return this.options.noWrap||(i=this._map.wrapLatLngBounds(i)),i},_tileCoordsToKey:function(t){return t.x+":"+t.y+":"+t.z},_keyToTileCoords:function(t){var e=t.split(":"),i=new N(+e[0],+e[1]);return i.z=+e[2],i},_removeTile:function(t){var e=this._tiles[t];e&&(oe(e.el),delete this._tiles[t],this.fire("tileunload",{tile:e.el,coords:this._keyToTileCoords(t)}))},_initTile:function(t){de(t,"leaflet-tile");var e=this.getTileSize();t.style.width=e.x+"px",t.style.height=e.y+"px",t.onselectstart=h,t.onmousemove=h,Rt.ielt9&&this.options.opacity<1&&fe(t,this.options.opacity)},_addTile:function(t,e){var i=this._getTilePos(t),s=this._tileCoordsToKey(t),o=this.createTile(this._wrapCoords(t),n(this._tileReady,this,t));this._initTile(o),this.createTile.length<2&&T(n(this._tileReady,this,t,null,o)),me(o,i),this._tiles[s]={el:o,coords:t,current:!0},e.appendChild(o),this.fire("tileloadstart",{tile:o,coords:t})},_tileReady:function(t,e,i){e&&this.fire("tileerror",{error:e,tile:i,coords:t});var s=this._tileCoordsToKey(t);(i=this._tiles[s])&&(i.loaded=+new Date,this._map._fadeAnimated?(fe(i.el,0),E(this._fadeFrame),this._fadeFrame=T(this._updateOpacity,this)):(i.active=!0,this._pruneTiles()),e||(de(i.el,"leaflet-tile-loaded"),this.fire("tileload",{tile:i.el,coords:t})),this._noTilesToLoad()&&(this._loading=!1,this.fire("load"),Rt.ielt9||!this._map._fadeAnimated?T(this._pruneTiles,this):setTimeout(n(this._pruneTiles,this),250)))},_getTilePos:function(t){return t.scaleBy(this.getTileSize()).subtract(this._level.origin)},_wrapCoords:function(t){var e=new N(this._wrapX?a(t.x,this._wrapX):t.x,this._wrapY?a(t.y,this._wrapY):t.y);return e.z=t.z,e},_pxBoundsToTileRange:function(t){var e=this.getTileSize();return new R(t.min.unscaleBy(e).floor(),t.max.unscaleBy(e).ceil().subtract([1,1]))},_noTilesToLoad:function(){for(var t in this._tiles)if(!this._tiles[t].loaded)return!1;return!0}});var on=sn.extend({options:{minZoom:0,maxZoom:18,subdomains:"abc",errorTileUrl:"",zoomOffset:0,tms:!1,zoomReverse:!1,detectRetina:!1,crossOrigin:!1,referrerPolicy:!1},initialize:function(t,e){this._url=t,(e=c(this,e)).detectRetina&&Rt.retina&&e.maxZoom>0?(e.tileSize=Math.floor(e.tileSize/2),e.zoomReverse?(e.zoomOffset--,e.minZoom=Math.min(e.maxZoom,e.minZoom+1)):(e.zoomOffset++,e.maxZoom=Math.max(e.minZoom,e.maxZoom-1)),e.minZoom=Math.max(0,e.minZoom)):e.zoomReverse?e.minZoom=Math.min(e.maxZoom,e.minZoom):e.maxZoom=Math.max(e.minZoom,e.maxZoom),"string"==typeof e.subdomains&&(e.subdomains=e.subdomains.split("")),this.on("tileunload",this._onTileRemove)},setUrl:function(t,e){return this._url===t&&void 0===e&&(e=!0),this._url=t,e||this.redraw(),this},createTile:function(t,e){var i=document.createElement("img");return Ae(i,"load",n(this._tileOnLoad,this,e,i)),Ae(i,"error",n(this._tileOnError,this,e,i)),(this.options.crossOrigin||""===this.options.crossOrigin)&&(i.crossOrigin=!0===this.options.crossOrigin?"":this.options.crossOrigin),"string"==typeof this.options.referrerPolicy&&(i.referrerPolicy=this.options.referrerPolicy),i.alt="",i.src=this.getTileUrl(t),i},getTileUrl:function(t){var i={r:Rt.retina?"@2x":"",s:this._getSubdomain(t),x:t.x,y:t.y,z:this._getZoomForUrl()};if(this._map&&!this._map.options.crs.infinite){var n=this._globalTileRange.max.y-t.y;this.options.tms&&(i.y=n),i["-y"]=n}return g(this._url,e(i,this.options))},_tileOnLoad:function(t,e){Rt.ielt9?setTimeout(n(t,this,null,e),0):t(null,e)},_tileOnError:function(t,e,i){var n=this.options.errorTileUrl;n&&e.getAttribute("src")!==n&&(e.src=n),t(i,e)},_onTileRemove:function(t){t.tile.onload=null},_getZoomForUrl:function(){var t=this._tileZoom,e=this.options.maxZoom;return this.options.zoomReverse&&(t=e-t),t+this.options.zoomOffset},_getSubdomain:function(t){var e=Math.abs(t.x+t.y)%this.options.subdomains.length;return this.options.subdomains[e]},_abortLoading:function(){var t,e;for(t in this._tiles)if(this._tiles[t].coords.z!==this._tileZoom&&((e=this._tiles[t].el).onload=h,e.onerror=h,!e.complete)){e.src=v;var i=this._tiles[t].coords;oe(e),delete this._tiles[t],this.fire("tileabort",{tile:e,coords:i})}},_removeTile:function(t){var e=this._tiles[t];if(e)return e.el.setAttribute("src",v),sn.prototype._removeTile.call(this,t)},_tileReady:function(t,e,i){if(this._map&&(!i||i.getAttribute("src")!==v))return sn.prototype._tileReady.call(this,t,e,i)}});function rn(t,e){return new on(t,e)}var an=on.extend({defaultWmsParams:{service:"WMS",request:"GetMap",layers:"",styles:"",format:"image/jpeg",transparent:!1,version:"1.1.1"},options:{crs:null,uppercase:!1},initialize:function(t,i){this._url=t;var n=e({},this.defaultWmsParams);for(var s in i)s in this.options||(n[s]=i[s]);var o=(i=c(this,i)).detectRetina&&Rt.retina?2:1,r=this.getTileSize();n.width=r.x*o,n.height=r.y*o,this.wmsParams=n},onAdd:function(t){this._crs=this.options.crs||t.options.crs,this._wmsVersion=parseFloat(this.wmsParams.version);var e=this._wmsVersion>=1.3?"crs":"srs";this.wmsParams[e]=this._crs.code,on.prototype.onAdd.call(this,t)},getTileUrl:function(t){var e=this._tileCoordsToNwSe(t),i=this._crs,n=O(i.project(e[0]),i.project(e[1])),s=n.min,o=n.max,r=(this._wmsVersion>=1.3&&this._crs===Ti?[s.y,s.x,o.y,o.x]:[s.x,s.y,o.x,o.y]).join(","),a=on.prototype.getTileUrl.call(this,t);return a+_(this.wmsParams,a,this.options.uppercase)+(this.options.uppercase?"&BBOX=":"&bbox=")+r},setParams:function(t,i){return e(this.wmsParams,t),i||this.redraw(),this}});on.WMS=an,rn.wms=function(t,e){return new an(t,e)};var hn=Pi.extend({options:{padding:.1},initialize:function(t){c(this,t),o(this),this._layers=this._layers||{}},onAdd:function(){this._container||(this._initContainer(),de(this._container,"leaflet-zoom-animated")),this.getPane().appendChild(this._container),this._update(),this.on("update",this._updatePaths,this)},onRemove:function(){this.off("update",this._updatePaths,this),this._destroyContainer()},getEvents:function(){var t={viewreset:this._reset,zoom:this._onZoom,moveend:this._update,zoomend:this._onZoomEnd};return this._zoomAnimated&&(t.zoomanim=this._onAnimZoom),t},_onAnimZoom:function(t){this._updateTransform(t.center,t.zoom)},_onZoom:function(){this._updateTransform(this._map.getCenter(),this._map.getZoom())},_updateTransform:function(t,e){var i=this._map.getZoomScale(e,this._zoom),n=this._map.getSize().multiplyBy(.5+this.options.padding),s=this._map.project(this._center,e),o=n.multiplyBy(-i).add(s).subtract(this._map._getNewPixelOrigin(t,e));Rt.any3d?pe(this._container,o,i):me(this._container,o)},_reset:function(){for(var t in this._update(),this._updateTransform(this._center,this._zoom),this._layers)this._layers[t]._reset()},_onZoomEnd:function(){for(var t in this._layers)this._layers[t]._project()},_updatePaths:function(){for(var t in this._layers)this._layers[t]._update()},_update:function(){var t=this.options.padding,e=this._map.getSize(),i=this._map.containerPointToLayerPoint(e.multiplyBy(-t)).round();this._bounds=new R(i,i.add(e.multiplyBy(1+2*t)).round()),this._center=this._map.getCenter(),this._zoom=this._map.getZoom()}}),ln=hn.extend({options:{tolerance:0},getEvents:function(){var t=hn.prototype.getEvents.call(this);return t.viewprereset=this._onViewPreReset,t},_onViewPreReset:function(){this._postponeUpdatePaths=!0},onAdd:function(){hn.prototype.onAdd.call(this),this._draw()},_initContainer:function(){var t=this._container=document.createElement("canvas");Ae(t,"mousemove",this._onMouseMove,this),Ae(t,"click dblclick mousedown mouseup contextmenu",this._onClick,this),Ae(t,"mouseout",this._handleMouseOut,this),t._leaflet_disable_events=!0,this._ctx=t.getContext("2d")},_destroyContainer:function(){E(this._redrawRequest),delete this._ctx,oe(this._container),Me(this._container),delete this._container},_updatePaths:function(){if(!this._postponeUpdatePaths){for(var t in this._redrawBounds=null,this._layers)this._layers[t]._update();this._redraw()}},_update:function(){if(!this._map._animatingZoom||!this._bounds){hn.prototype._update.call(this);var t=this._bounds,e=this._container,i=t.getSize(),n=Rt.retina?2:1;me(e,t.min),e.width=n*i.x,e.height=n*i.y,e.style.width=i.x+"px",e.style.height=i.y+"px",Rt.retina&&this._ctx.scale(2,2),this._ctx.translate(-t.min.x,-t.min.y),this.fire("update")}},_reset:function(){hn.prototype._reset.call(this),this._postponeUpdatePaths&&(this._postponeUpdatePaths=!1,this._updatePaths())},_initPath:function(t){this._updateDashArray(t),this._layers[o(t)]=t;var e=t._order={layer:t,prev:this._drawLast,next:null};this._drawLast&&(this._drawLast.next=e),this._drawLast=e,this._drawFirst=this._drawFirst||this._drawLast},_addPath:function(t){this._requestRedraw(t)},_removePath:function(t){var e=t._order,i=e.next,n=e.prev;i?i.prev=n:this._drawLast=n,n?n.next=i:this._drawFirst=i,delete t._order,delete this._layers[o(t)],this._requestRedraw(t)},_updatePath:function(t){this._extendRedrawBounds(t),t._project(),t._update(),this._requestRedraw(t)},_updateStyle:function(t){this._updateDashArray(t),this._requestRedraw(t)},_updateDashArray:function(t){if("string"==typeof t.options.dashArray){var e,i,n=t.options.dashArray.split(/[, ]+/),s=[];for(i=0;i')}}catch(t){}return function(t){return document.createElement("<"+t+' xmlns="urn:schemas-microsoft.com:vml" class="lvml">')}}(),cn={_initContainer:function(){this._container=se("div","leaflet-vml-container")},_update:function(){this._map._animatingZoom||(hn.prototype._update.call(this),this.fire("update"))},_initPath:function(t){var e=t._container=un("shape");de(e,"leaflet-vml-shape "+(this.options.className||"")),e.coordsize="1 1",t._path=un("path"),e.appendChild(t._path),this._updateStyle(t),this._layers[o(t)]=t},_addPath:function(t){var e=t._container;this._container.appendChild(e),t.options.interactive&&t.addInteractiveTarget(e)},_removePath:function(t){var e=t._container;oe(e),t.removeInteractiveTarget(e),delete this._layers[o(t)]},_updateStyle:function(t){var e=t._stroke,i=t._fill,n=t.options,s=t._container;s.stroked=!!n.stroke,s.filled=!!n.fill,n.stroke?(e||(e=t._stroke=un("stroke")),s.appendChild(e),e.weight=n.weight+"px",e.color=n.color,e.opacity=n.opacity,n.dashArray?e.dashStyle=p(n.dashArray)?n.dashArray.join(" "):n.dashArray.replace(/( *, *)/g," "):e.dashStyle="",e.endcap=n.lineCap.replace("butt","flat"),e.joinstyle=n.lineJoin):e&&(s.removeChild(e),t._stroke=null),n.fill?(i||(i=t._fill=un("fill")),s.appendChild(i),i.color=n.fillColor||n.color,i.opacity=n.fillOpacity):i&&(s.removeChild(i),t._fill=null)},_updateCircle:function(t){var e=t._point.round(),i=Math.round(t._radius),n=Math.round(t._radiusY||i);this._setPath(t,t._empty()?"M0 0":"AL "+e.x+","+e.y+" "+i+","+n+" 0,23592600")},_setPath:function(t,e){t._path.v=e},_bringToFront:function(t){ae(t._container)},_bringToBack:function(t){he(t._container)}},_n=Rt.vml?un:Y,fn=hn.extend({_initContainer:function(){this._container=_n("svg"),this._container.setAttribute("pointer-events","none"),this._rootGroup=_n("g"),this._container.appendChild(this._rootGroup)},_destroyContainer:function(){oe(this._container),Me(this._container),delete this._container,delete this._rootGroup,delete this._svgSize},_update:function(){if(!this._map._animatingZoom||!this._bounds){hn.prototype._update.call(this);var t=this._bounds,e=t.getSize(),i=this._container;this._svgSize&&this._svgSize.equals(e)||(this._svgSize=e,i.setAttribute("width",e.x),i.setAttribute("height",e.y)),me(i,t.min),i.setAttribute("viewBox",[t.min.x,t.min.y,e.x,e.y].join(" ")),this.fire("update")}},_initPath:function(t){var e=t._path=_n("path");t.options.className&&de(e,t.options.className),t.options.interactive&&de(e,"leaflet-interactive"),this._updateStyle(t),this._layers[o(t)]=t},_addPath:function(t){this._rootGroup||this._initContainer(),this._rootGroup.appendChild(t._path),t.addInteractiveTarget(t._path)},_removePath:function(t){oe(t._path),t.removeInteractiveTarget(t._path),delete this._layers[o(t)]},_updatePath:function(t){t._project(),t._update()},_updateStyle:function(t){var e=t._path,i=t.options;e&&(i.stroke?(e.setAttribute("stroke",i.color),e.setAttribute("stroke-opacity",i.opacity),e.setAttribute("stroke-width",i.weight),e.setAttribute("stroke-linecap",i.lineCap),e.setAttribute("stroke-linejoin",i.lineJoin),i.dashArray?e.setAttribute("stroke-dasharray",i.dashArray):e.removeAttribute("stroke-dasharray"),i.dashOffset?e.setAttribute("stroke-dashoffset",i.dashOffset):e.removeAttribute("stroke-dashoffset")):e.setAttribute("stroke","none"),i.fill?(e.setAttribute("fill",i.fillColor||i.color),e.setAttribute("fill-opacity",i.fillOpacity),e.setAttribute("fill-rule",i.fillRule||"evenodd")):e.setAttribute("fill","none"))},_updatePoly:function(t,e){this._setPath(t,$(t._parts,e))},_updateCircle:function(t){var e=t._point,i=Math.max(Math.round(t._radius),1),n="a"+i+","+(Math.max(Math.round(t._radiusY),1)||i)+" 0 1,0 ",s=t._empty()?"M0 0":"M"+(e.x-i)+","+e.y+n+2*i+",0 "+n+2*-i+",0 ";this._setPath(t,s)},_setPath:function(t,e){t._path.setAttribute("d",e)},_bringToFront:function(t){ae(t._path)},_bringToBack:function(t){he(t._path)}});function gn(t){return Rt.svg||Rt.vml?new fn(t):null}Rt.vml&&fn.include(cn),Xe.include({getRenderer:function(t){var e=t.options.renderer||this._getPaneRenderer(t.options.pane)||this.options.renderer||this._renderer;return e||(e=this._renderer=this._createRenderer()),this.hasLayer(e)||this.addLayer(e),e},_getPaneRenderer:function(t){if("overlayPane"===t||void 0===t)return!1;var e=this._paneRenderers[t];return void 0===e&&(e=this._createRenderer({pane:t}),this._paneRenderers[t]=e),e},_createRenderer:function(t){return this.options.preferCanvas&&dn(t)||gn(t)}});var pn=Bi.extend({initialize:function(t,e){Bi.prototype.initialize.call(this,this._boundsToLatLngs(t),e)},setBounds:function(t){return this.setLatLngs(this._boundsToLatLngs(t))},_boundsToLatLngs:function(t){return[(t=B(t)).getSouthWest(),t.getNorthWest(),t.getNorthEast(),t.getSouthEast()]}});fn.create=_n,fn.pointsToPath=$,zi.geometryToLayer=Ui,zi.coordsToLatLng=ji,zi.coordsToLatLngs=Wi,zi.latLngToCoords=Gi,zi.latLngsToCoords=Zi,zi.getFeature=Hi,zi.asFeature=Xi,Xe.mergeOptions({boxZoom:!0});var mn=Je.extend({initialize:function(t){this._map=t,this._container=t._container,this._pane=t._panes.overlayPane,this._resetStateTimeout=0,t.on("unload",this._destroy,this)},addHooks:function(){Ae(this._container,"mousedown",this._onMouseDown,this)},removeHooks:function(){Me(this._container,"mousedown",this._onMouseDown,this)},moved:function(){return this._moved},_destroy:function(){oe(this._pane),delete this._pane},_resetState:function(){this._resetStateTimeout=0,this._moved=!1},_clearDeferredResetState:function(){0!==this._resetStateTimeout&&(clearTimeout(this._resetStateTimeout),this._resetStateTimeout=0)},_onMouseDown:function(t){if(!t.shiftKey||1!==t.which&&1!==t.button)return!1;this._clearDeferredResetState(),this._resetState(),Vt(),xe(),this._startPoint=this._map.mouseEventToContainerPoint(t),Ae(document,{contextmenu:ze,mousemove:this._onMouseMove,mouseup:this._onMouseUp,keydown:this._onKeyDown},this)},_onMouseMove:function(t){this._moved||(this._moved=!0,this._box=se("div","leaflet-zoom-box",this._container),de(this._container,"leaflet-crosshair"),this._map.fire("boxzoomstart")),this._point=this._map.mouseEventToContainerPoint(t);var e=new R(this._point,this._startPoint),i=e.getSize();me(this._box,e.min),this._box.style.width=i.x+"px",this._box.style.height=i.y+"px"},_finish:function(){this._moved&&(oe(this._box),ue(this._container,"leaflet-crosshair")),Yt(),be(),Me(document,{contextmenu:ze,mousemove:this._onMouseMove,mouseup:this._onMouseUp,keydown:this._onKeyDown},this)},_onMouseUp:function(t){if((1===t.which||1===t.button)&&(this._finish(),this._moved)){this._clearDeferredResetState(),this._resetStateTimeout=setTimeout(n(this._resetState,this),0);var e=new k(this._map.containerPointToLatLng(this._startPoint),this._map.containerPointToLatLng(this._point));this._map.fitBounds(e).fire("boxzoomend",{boxZoomBounds:e})}},_onKeyDown:function(t){27===t.keyCode&&(this._finish(),this._clearDeferredResetState(),this._resetState())}});Xe.addInitHook("addHandler","boxZoom",mn),Xe.mergeOptions({doubleClickZoom:!0});var vn=Je.extend({addHooks:function(){this._map.on("dblclick",this._onDoubleClick,this)},removeHooks:function(){this._map.off("dblclick",this._onDoubleClick,this)},_onDoubleClick:function(t){var e=this._map,i=e.getZoom(),n=e.options.zoomDelta,s=t.originalEvent.shiftKey?i-n:i+n;"center"===e.options.doubleClickZoom?e.setZoom(s):e.setZoomAround(t.containerPoint,s)}});Xe.addInitHook("addHandler","doubleClickZoom",vn),Xe.mergeOptions({dragging:!0,inertia:!0,inertiaDeceleration:3400,inertiaMaxSpeed:1/0,easeLinearity:.2,worldCopyJump:!1,maxBoundsViscosity:0});var yn=Je.extend({addHooks:function(){if(!this._draggable){var t=this._map;this._draggable=new ii(t._mapPane,t._container),this._draggable.on({dragstart:this._onDragStart,drag:this._onDrag,dragend:this._onDragEnd},this),this._draggable.on("predrag",this._onPreDragLimit,this),t.options.worldCopyJump&&(this._draggable.on("predrag",this._onPreDragWrap,this),t.on("zoomend",this._onZoomEnd,this),t.whenReady(this._onZoomEnd,this))}de(this._map._container,"leaflet-grab leaflet-touch-drag"),this._draggable.enable(),this._positions=[],this._times=[]},removeHooks:function(){ue(this._map._container,"leaflet-grab"),ue(this._map._container,"leaflet-touch-drag"),this._draggable.disable()},moved:function(){return this._draggable&&this._draggable._moved},moving:function(){return this._draggable&&this._draggable._moving},_onDragStart:function(){var t=this._map;if(t._stop(),this._map.options.maxBounds&&this._map.options.maxBoundsViscosity){var e=B(this._map.options.maxBounds);this._offsetLimit=O(this._map.latLngToContainerPoint(e.getNorthWest()).multiplyBy(-1),this._map.latLngToContainerPoint(e.getSouthEast()).multiplyBy(-1).add(this._map.getSize())),this._viscosity=Math.min(1,Math.max(0,this._map.options.maxBoundsViscosity))}else this._offsetLimit=null;t.fire("movestart").fire("dragstart"),t.options.inertia&&(this._positions=[],this._times=[])},_onDrag:function(t){if(this._map.options.inertia){var e=this._lastTime=+new Date,i=this._lastPos=this._draggable._absPos||this._draggable._newPos;this._positions.push(i),this._times.push(e),this._prunePositions(e)}this._map.fire("move",t).fire("drag",t)},_prunePositions:function(t){for(;this._positions.length>1&&t-this._times[0]>50;)this._positions.shift(),this._times.shift()},_onZoomEnd:function(){var t=this._map.getSize().divideBy(2),e=this._map.latLngToLayerPoint([0,0]);this._initialWorldOffset=e.subtract(t).x,this._worldWidth=this._map.getPixelWorldBounds().getSize().x},_viscousLimit:function(t,e){return t-(t-e)*this._viscosity},_onPreDragLimit:function(){if(this._viscosity&&this._offsetLimit){var t=this._draggable._newPos.subtract(this._draggable._startPos),e=this._offsetLimit;t.xe.max.x&&(t.x=this._viscousLimit(t.x,e.max.x)),t.y>e.max.y&&(t.y=this._viscousLimit(t.y,e.max.y)),this._draggable._newPos=this._draggable._startPos.add(t)}},_onPreDragWrap:function(){var t=this._worldWidth,e=Math.round(t/2),i=this._initialWorldOffset,n=this._draggable._newPos.x,s=(n-e+i)%t+e-i,o=(n+e+i)%t-e-i,r=Math.abs(s+i)0?o:-o))-e;this._delta=0,this._startTime=null,r&&("center"===t.options.scrollWheelZoom?t.setZoom(e+r):t.setZoomAround(this._lastMousePos,e+r))}});Xe.addInitHook("addHandler","scrollWheelZoom",bn);Xe.mergeOptions({tapHold:Rt.touchNative&&Rt.safari&&Rt.mobile,tapTolerance:15});var Sn=Je.extend({addHooks:function(){Ae(this._map._container,"touchstart",this._onDown,this)},removeHooks:function(){Me(this._map._container,"touchstart",this._onDown,this)},_onDown:function(t){if(clearTimeout(this._holdTimeout),1===t.touches.length){var e=t.touches[0];this._startPos=this._newPos=new N(e.clientX,e.clientY),this._holdTimeout=setTimeout(n(function(){this._cancel(),this._isTapValid()&&(Ae(document,"touchend",Be),Ae(document,"touchend touchcancel",this._cancelClickPrevent),this._simulateEvent("contextmenu",e))},this),600),Ae(document,"touchend touchcancel contextmenu",this._cancel,this),Ae(document,"touchmove",this._onMove,this)}},_cancelClickPrevent:function t(){Me(document,"touchend",Be),Me(document,"touchend touchcancel",t)},_cancel:function(){clearTimeout(this._holdTimeout),Me(document,"touchend touchcancel contextmenu",this._cancel,this),Me(document,"touchmove",this._onMove,this)},_onMove:function(t){var e=t.touches[0];this._newPos=new N(e.clientX,e.clientY)},_isTapValid:function(){return this._newPos.distanceTo(this._startPos)<=this._map.options.tapTolerance},_simulateEvent:function(t,e){var i=new MouseEvent(t,{bubbles:!0,cancelable:!0,view:window,screenX:e.screenX,screenY:e.screenY,clientX:e.clientX,clientY:e.clientY});i._simulated=!0,e.target.dispatchEvent(i)}});Xe.addInitHook("addHandler","tapHold",Sn),Xe.mergeOptions({touchZoom:Rt.touch,bounceAtZoomLimits:!0});var wn=Je.extend({addHooks:function(){de(this._map._container,"leaflet-touch-zoom"),Ae(this._map._container,"touchstart",this._onTouchStart,this)},removeHooks:function(){ue(this._map._container,"leaflet-touch-zoom"),Me(this._map._container,"touchstart",this._onTouchStart,this)},_onTouchStart:function(t){var e=this._map;if(t.touches&&2===t.touches.length&&!e._animatingZoom&&!this._zooming){var i=e.mouseEventToContainerPoint(t.touches[0]),n=e.mouseEventToContainerPoint(t.touches[1]);this._centerPoint=e.getSize()._divideBy(2),this._startLatLng=e.containerPointToLatLng(this._centerPoint),"center"!==e.options.touchZoom&&(this._pinchStartLatLng=e.containerPointToLatLng(i.add(n)._divideBy(2))),this._startDist=i.distanceTo(n),this._startZoom=e.getZoom(),this._moved=!1,this._zooming=!0,e._stop(),Ae(document,"touchmove",this._onTouchMove,this),Ae(document,"touchend touchcancel",this._onTouchEnd,this),Be(t)}},_onTouchMove:function(t){if(t.touches&&2===t.touches.length&&this._zooming){var e=this._map,i=e.mouseEventToContainerPoint(t.touches[0]),s=e.mouseEventToContainerPoint(t.touches[1]),o=i.distanceTo(s)/this._startDist;if(this._zoom=e.getScaleZoom(o,this._startZoom),!e.options.bounceAtZoomLimits&&(this._zoome.getMaxZoom()&&o>1)&&(this._zoom=e._limitZoom(this._zoom)),"center"===e.options.touchZoom){if(this._center=this._startLatLng,1===o)return}else{var r=i._add(s)._divideBy(2)._subtract(this._centerPoint);if(1===o&&0===r.x&&0===r.y)return;this._center=e.unproject(e.project(this._pinchStartLatLng,this._zoom).subtract(r),this._zoom)}this._moved||(e._moveStart(!0,!1),this._moved=!0),E(this._animRequest);var a=n(e._move,e,this._center,this._zoom,{pinch:!0,round:!1},void 0);this._animRequest=T(a,this,!0),Be(t)}},_onTouchEnd:function(){this._moved&&this._zooming?(this._zooming=!1,E(this._animRequest),Me(document,"touchmove",this._onTouchMove,this),Me(document,"touchend touchcancel",this._onTouchEnd,this),this._map.options.zoomAnimation?this._map._animateZoom(this._center,this._map._limitZoom(this._zoom),!0,this._map.options.zoomSnap):this._map._resetView(this._center,this._map._limitZoom(this._zoom))):this._zooming=!1}});Xe.addInitHook("addHandler","touchZoom",wn),Xe.BoxZoom=mn,Xe.DoubleClickZoom=vn,Xe.Drag=yn,Xe.Keyboard=xn,Xe.ScrollWheelZoom=bn,Xe.TapHold=Sn,Xe.TouchZoom=wn,t.Bounds=R,t.Browser=Rt,t.CRS=j,t.Canvas=ln,t.Circle=Oi,t.CircleMarker=Ri,t.Class=A,t.Control=qe,t.DivIcon=nn,t.DivOverlay=Ji,t.DomEvent=Ze,t.DomUtil=Pe,t.Draggable=ii,t.Evented=M,t.FeatureGroup=Ci,t.GeoJSON=zi,t.GridLayer=sn,t.Handler=Je,t.Icon=Mi,t.ImageOverlay=$i,t.LatLng=z,t.LatLngBounds=k,t.Layer=Pi,t.LayerGroup=Ai,t.LineUtil=yi,t.Map=Xe,t.Marker=Ii,t.Mixin=ti,t.Path=Li,t.Point=N,t.PolyUtil=ai,t.Polygon=Bi,t.Polyline=ki,t.Popup=tn,t.PosAnimation=He,t.Projection=Si,t.Rectangle=pn,t.Renderer=hn,t.SVG=fn,t.SVGOverlay=Qi,t.TileLayer=on,t.Tooltip=en,t.Transformation=H,t.Util=P,t.VideoOverlay=Ki,t.bind=n,t.bounds=O,t.canvas=dn,t.circle=function(t,e,i){return new Oi(t,e,i)},t.circleMarker=function(t,e){return new Ri(t,e)},t.control=Ve,t.divIcon=function(t){return new nn(t)},t.extend=e,t.featureGroup=function(t,e){return new Ci(t,e)},t.geoJSON=Vi,t.geoJson=Yi,t.gridLayer=function(t){return new sn(t)},t.icon=function(t){return new Mi(t)},t.imageOverlay=function(t,e,i){return new $i(t,e,i)},t.latLng=U,t.latLngBounds=B,t.layerGroup=function(t,e){return new Ai(t,e)},t.map=function(t,e){return new Xe(t,e)},t.marker=function(t,e){return new Ii(t,e)},t.point=I,t.polygon=function(t,e){return new Bi(t,e)},t.polyline=function(t,e){return new ki(t,e)},t.popup=function(t,e){return new tn(t,e)},t.rectangle=function(t,e){return new pn(t,e)},t.setOptions=c,t.stamp=o,t.svg=gn,t.svgOverlay=function(t,e,i){return new Qi(t,e,i)},t.tileLayer=rn,t.tooltip=function(t,e){return new en(t,e)},t.transformation=X,t.version="1.9.4",t.videoOverlay=function(t,e,i){return new Ki(t,e,i)};var Tn=window.L;t.noConflict=function(){return window.L=Tn,this},window.L=t}(e)}};const e={};function i(n){const s=e[n];if(void 0!==s)return s.exports;const o=e[n]={exports:{}};return t[n].call(o.exports,o,o.exports,i),o.exports}i.d=(t,e)=>{if(Array.isArray(e))for(var n=0;nObject.prototype.hasOwnProperty.call(t,e),i.r=t=>{Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};let n={};return(()=>{"use strict";i.r(n),i.d(n,{Color:()=>F,EdgeLineStyleType:()=>N,EdgeType:()=>D,GraphObjectState:()=>r,NodeShapeType:()=>w,OrbError:()=>o,OrbEventType:()=>e,OrbMapView:()=>cr,OrbView:()=>dr,RectangleArea:()=>V,RendererType:()=>zs,getDefaultGraphStyle:()=>X,graphToSVG:()=>Jo,isEdge:()=>L,isNode:()=>E});class t{constructor(){this._listeners=new Map}once(t,e){const i={callable:e,isOnce:!0},n=this._listeners.get(t);return n?n.push(i):this._listeners.set(t,[i]),this}on(t,e){const i={callable:e},n=this._listeners.get(t);return n?n.push(i):this._listeners.set(t,[i]),this}off(t,e){const i=this._listeners.get(t);if(i){const n=i.filter(t=>t.callable!==e);this._listeners.set(t,n)}return this}emit(t,e){const i=this._listeners.get(t);if(!i||0===i.length)return!1;let n=!1;for(let t=0;t!t.isOnce);this._listeners.set(t,e)}return!0}eventNames(){return[...this._listeners.keys()]}listenerCount(t){const e=this._listeners.get(t);return e?e.length:0}listeners(t){const e=this._listeners.get(t);return e?e.map(t=>t.callable):[]}addListener(t,e){return this.on(t,e)}removeListener(t,e){return this.off(t,e)}removeAllListeners(t){return t?this._listeners.delete(t):this._listeners.clear(),this}}var e;!function(t){t.RENDER_START="render-start",t.RENDER_END="render-end",t.SIMULATION_START="simulation-start",t.SIMULATION_STEP="simulation-step",t.SIMULATION_END="simulation-end",t.NODE_CLICK="node-click",t.NODE_HOVER="node-hover",t.EDGE_CLICK="edge-click",t.EDGE_HOVER="edge-hover",t.MOUSE_CLICK="mouse-click",t.MOUSE_MOVE="mouse-move",t.TRANSFORM="transform",t.NODE_DRAG_START="node-drag-start",t.NODE_DRAG="node-drag",t.NODE_DRAG_END="node-drag-end",t.BACKGROUND_DRAG_START="background-drag-start",t.BACKGROUND_DRAG="background-drag",t.BACKGROUND_DRAG_END="background-drag-end",t.NODE_RIGHT_CLICK="node-right-click",t.EDGE_RIGHT_CLICK="edge-right-click",t.MOUSE_RIGHT_CLICK="mouse-right-click",t.NODE_DOUBLE_CLICK="node-double-click",t.EDGE_DOUBLE_CLICK="edge-double-click",t.MOUSE_DOUBLE_CLICK="mouse-double-click"}(e||(e={}));class s extends t{}class o extends Error{constructor(t){super(t),this.message=t,Object.setPrototypeOf(this,new.target.prototype),this.name=this.constructor.name}}const r={NONE:0,SELECTED:1,HOVERED:2},a=(t,e)=>{const i=t.x+t.width,n=t.y+t.height;return e.x>=t.x&&e.x<=i&&e.y>=t.y&&e.y<=n};class h{constructor(){this._imageByUrl={}}static getInstance(){return h._instance||(h._instance=new h),h._instance}getImage(t){return this._imageByUrl[t]}loadImage(t,e){const i=this.getImage(t);if(i)return i;const n=new Image;return this._imageByUrl[t]=n,n.onload=()=>{l(n),null==e||e()},n.onerror=()=>{null==e||e(new Error(`Image ${t} failed to load.`))},n.src=t,n}loadImages(t,e){const i=[],n=new Set(t),s=t=>{n.delete(t),0===n.size&&(null==e||e())};for(let e=0;e{l(a),s(o)},a.onerror=()=>{s(o)},a.src=o,i.push(a)}return i}}const l=t=>t&&0===t.width?(document.body.appendChild(t),t.width=t.offsetWidth,t.height=t.offsetHeight,document.body.removeChild(t),t):t;class d{constructor(){this.listeners=[]}addListener(t){this.listeners.push(t)}getListeners(){return[...this.listeners]}removeListener(t){const e=this.listeners.indexOf(t);-1!==e&&this.listeners.splice(e,1)}notifyListeners(t){for(let e=0;e"number"==typeof t,c=t=>"boolean"==typeof t,_=t=>t instanceof Date,f=t=>Array.isArray(t),g=t=>null!==t&&"object"==typeof t&&"Object"===t.constructor.name,p=t=>"function"==typeof t,m=t=>_(t)?y(t):f(t)?x(t):g(t)?b(t):t,v=(t,e)=>{const i=_(t),n=_(e);if(i&&!n||!i&&n)return!1;if(i&&n)return t.getTime()===e.getTime();const s=f(t),o=f(e);if(s&&!o||!s&&o)return!1;if(s&&o)return t.length===e.length&&t.every((t,i)=>v(t,e[i]));const r=g(t),a=g(e);if(r&&!a||!r&&a)return!1;if(r&&a){const i=Object.keys(t),n=Object.keys(e);return!!v(i,n)&&i.every(i=>v(t[i],e[i]))}return t===e},y=t=>new Date(t),x=t=>t.map(t=>m(t)),b=t=>{const e={};return Object.keys(t).forEach(i=>{e[i]=m(t[i])}),e},S=(t,e)=>{const i=Object.keys(e);for(let n=0;nt instanceof P;class P extends d{constructor(t,e){super(),this._style={},this._state=r.NONE,this._inEdgesById={},this._outEdgesById={},this.id=t.data.id,this._data=t.data,this._position={id:this.id},this._onLoadedImage=null==e?void 0:e.onLoadedImage,this._onStateChange=null==e?void 0:e.onStateChange,e&&e.listeners&&(this.listeners=e.listeners)}getId(){return this.id}getData(){return this._data}getPosition(){return this._position}getStyle(){return this._style}getState(){return this._state}clearPosition(){this._position.x=void 0,this._position.y=void 0,this.notifyListeners()}getCenter(){return void 0===this._position.x||void 0===this._position.y?{x:0,y:0}:{x:this._position.x,y:this._position.y}}getRadius(){var t;return null!==(t=this._style.size)&&void 0!==t?t:0}getBorderedRadius(){return this.getRadius()+this.getBorderWidth()/2}getBoundingBox(){const t=this.getCenter(),e=this.getBorderedRadius();return{x:t.x-e,y:t.y-e,width:2*e,height:2*e}}getInEdges(){return Object.values(this._inEdgesById)}getOutEdges(){return Object.values(this._outEdgesById)}getEdges(){const t={},e=this.getOutEdges();for(let i=0;i0}addEdge(t){t.start===this.id&&(this._outEdgesById[t.getId()]=t),t.end===this.id&&(this._inEdgesById[t.getId()]=t)}removeEdge(t){delete this._outEdgesById[t.getId()],delete this._inEdgesById[t.getId()]}isSelected(){return this._state===r.SELECTED}isHovered(){return this._state===r.HOVERED}clearState(){this.setState(r.NONE,{isNotifySkipped:!0})}getDistanceToBorder(){return this.getBorderedRadius()}includesPoint(t){const e=this._isPointInBoundingBox(t);if(!e)return!1;if(this._style.shape===w.SQUARE)return e;const i=this.getCenter(),n=this.getBorderedRadius(),s=t.x-i.x,o=t.y-i.y;return Math.sqrt(s*s+o*o)<=n}hasShadow(){var t,e,i;return(null!==(t=this._style.shadowSize)&&void 0!==t?t:0)>0||(null!==(e=this._style.shadowOffsetX)&&void 0!==e?e:0)>0||(null!==(i=this._style.shadowOffsetY)&&void 0!==i?i:0)>0}hasBorder(){var t,e;const i=(null!==(t=this._style.borderWidth)&&void 0!==t?t:0)>0,n=(null!==(e=this._style.borderWidthSelected)&&void 0!==e?e:0)>0;return i||this.isSelected()&&n}getLabel(){return this._style.label}getColor(){let t;return this._style.color&&(t=this._style.color),this.isHovered()&&this._style.colorHover&&(t=this._style.colorHover),this.isSelected()&&this._style.colorSelected&&(t=this._style.colorSelected),t}getBorderWidth(){let t=0;return this._style.borderWidth&&this._style.borderWidth>0&&(t=this._style.borderWidth),this.isSelected()&&this._style.borderWidthSelected&&this._style.borderWidthSelected>0&&(t=this._style.borderWidthSelected),t}getBorderColor(){if(!this.hasBorder())return;let t;return this._style.borderColor&&(t=this._style.borderColor),this.isHovered()&&this._style.borderColorHover&&(t=this._style.borderColorHover),this.isSelected()&&this._style.borderColorSelected&&(t=this._style.borderColorSelected.toString()),t}getBackgroundImage(){var t;if((null!==(t=this._style.size)&&void 0!==t?t:0)<=0)return;let e;if(this._style.imageUrl&&(e=this._style.imageUrl),this.isSelected()&&this._style.imageUrlSelected&&(e=this._style.imageUrlSelected),!e)return;return h.getInstance().getImage(e)||h.getInstance().loadImage(e,t=>{var e;t||null===(e=this._onLoadedImage)||void 0===e||e.call(this)})}setData(t){p(t)?this._data=t(this):this._data=t,this.notifyListeners()}patchData(t){let e;e=p(t)?t(this):t,S(this._data,e),this.notifyListeners()}setPosition(t,e){let i;i=p(t)?t(this):t,"x"in i&&"y"in i&&(this._position.x=i.x,this._position.y=i.y,"id"in i&&(this._position.id=i.id)),(null==e?void 0:e.isNotifySkipped)||this.notifyListeners(Object.assign({id:this.id},i))}setStyle(t,e){p(t)?this._style=t(this):this._style=t,(null==e?void 0:e.isNotifySkipped)||this.notifyListeners()}patchStyle(t,e){let i;i=p(t)?t(this):t,S(this._style,i),(null==e?void 0:e.isNotifySkipped)||this.notifyListeners()}setState(t,e){var i;const n=this._state;let s;if(s=p(t)?t(this):t,u(s))this._state=s;else if(g(s)){const t=s.options;if(this._state=this._handleState(s.state,t),t)return void this.notifyListeners({id:this.id,type:"node",options:t})}(null==e?void 0:e.isNotifySkipped)?this._state!==n&&(null===(i=this._onStateChange)||void 0===i||i.call(this)):this.notifyListeners()}_isPointInBoundingBox(t){return a(this.getBoundingBox(),t)}_handleState(t,e){return(null==e?void 0:e.isToggle)&&this._state===t?r.NONE:t}}const A=(t,e,i)=>{const n=e.x-t.x,s=e.y-t.y;let o=((i.x-t.x)*n+(i.y-t.y)*s)/(n*n+s*s);o>1&&(o=1),o<0&&(o=0);const r=t.x+o*n,a=t.y+o*s,h=r-i.x,l=a-i.y;return Math.sqrt(h*h+l*l)},C=[5,5],M=[1,1];var N,D;!function(t){t.SOLID="solid",t.DASHED="dashed",t.DOTTED="dotted",t.CUSTOM="custom"}(N||(N={})),function(t){t.STRAIGHT="straight",t.LOOPBACK="loopback",t.CURVED="curved"}(D||(D={}));class I{static create(t,e){switch(O(t)){case D.STRAIGHT:return new k(t,e);case D.LOOPBACK:return new z(t,e);case D.CURVED:return new B(t,e);default:return new k(t,e)}}static copy(t,e){const i=I.create({data:t.getData(),offset:void 0!==(null==e?void 0:e.offset)?e.offset:t.offset,startNode:t.startNode,endNode:t.endNode},{listeners:[],onStateChange:t.getOnStateChange()});i.setState(t.getState()),i.setStyle(t.getStyle());const n=t.getListeners();for(let t=0;tt instanceof k||t instanceof B||t instanceof z;class R extends d{constructor(t,e){var i;super(),this._style={},this._state=r.NONE,this._type=D.STRAIGHT,this.id=t.data.id,this._data=t.data,this.offset=null!==(i=t.offset)&&void 0!==i?i:0,this.startNode=t.startNode,this.endNode=t.endNode,this._type=O(t),this._position={id:this.id,source:this.startNode.getId(),target:this.endNode.getId()},this.startNode.addEdge(this),this.endNode.addEdge(this),this._onStateChange=null==e?void 0:e.onStateChange,e&&e.listeners&&(this.listeners=e.listeners)}getId(){return this.id}getData(){return this._data}getPosition(){return this._position}getStyle(){return this._style}getState(){return this._state}getOnStateChange(){return this._onStateChange}get type(){return this._type}get start(){return this._data.start}get end(){return this._data.end}hasStyle(){return this._style&&Object.keys(this._style).length>0}isSelected(){return this._state===r.SELECTED}isHovered(){return this._state===r.HOVERED}clearState(){var t;this._state!==r.NONE&&(this._state=r.NONE,null===(t=this._onStateChange)||void 0===t||t.call(this))}isLoopback(){return this._type===D.LOOPBACK}isStraight(){return this._type===D.STRAIGHT}isCurved(){return this._type===D.CURVED}getCenter(){var t,e;const i=null===(t=this.startNode)||void 0===t?void 0:t.getCenter(),n=null===(e=this.endNode)||void 0===e?void 0:e.getCenter();return i&&n?{x:(i.x+n.x)/2,y:(i.y+n.y)/2}:{x:0,y:0}}getDistance(t){const e=this.startNode.getCenter(),i=this.endNode.getCenter();return e&&i?A(e,i,t):0}getLabel(){return this._style.label}hasShadow(){var t,e,i;return(null!==(t=this._style.shadowSize)&&void 0!==t?t:0)>0||(null!==(e=this._style.shadowOffsetX)&&void 0!==e?e:0)>0||(null!==(i=this._style.shadowOffsetY)&&void 0!==i?i:0)>0}getWidth(){let t=0;return void 0!==this._style.width&&(t=this._style.width),this.isHovered()&&void 0!==this._style.widthHover&&(t=this._style.widthHover),this.isSelected()&&void 0!==this._style.widthSelected&&(t=this._style.widthSelected),t}getColor(){let t;return this._style.color&&(t=this._style.color),this.isHovered()&&this._style.colorHover&&(t=this._style.colorHover),this.isSelected()&&this._style.colorSelected&&(t=this._style.colorSelected),t}getLineDashPattern(){const t=this._style.lineStyle;if(void 0===t||t.type===N.SOLID)return null;switch(t.type){case N.DASHED:return C;case N.DOTTED:return M;case N.CUSTOM:return e=t.pattern,f(e)&&e.every(t=>u(t))?t.pattern:null;default:return null}var e}setData(t){p(t)?this._data=t(this):this._data=t,this.notifyListeners()}patchData(t){let e;e=p(t)?t(this):t,S(this._data,e),this.notifyListeners()}setStyle(t,e){p(t)?this._style=t(this):this._style=t,(null==e?void 0:e.isNotifySkipped)||this.notifyListeners()}patchStyle(t,e){let i;i=p(t)?t(this):t,S(this._style,i),(null==e?void 0:e.isNotifySkipped)||this.notifyListeners()}setState(t,e){var i;const n=this._state;let s;if(s=p(t)?t(this):t,u(s))this._state=s;else if(g(s)){const t=s.options;if(this._state=this._handleState(s.state,t),t)return void this.notifyListeners({id:this.id,type:"edge",options:t})}(null==e?void 0:e.isNotifySkipped)?this._state!==n&&(null===(i=this._onStateChange)||void 0===i||i.call(this)):this.notifyListeners()}_handleState(t,e){return(null==e?void 0:e.isToggle)&&this._state===t?r.NONE:t}}const O=t=>{var e;return t.startNode.getId()===t.endNode.getId()?D.LOOPBACK:0===(null!==(e=t.offset)&&void 0!==e?e:0)?D.STRAIGHT:D.CURVED};class k extends R{getCenter(){var t,e;const i=null===(t=this.startNode)||void 0===t?void 0:t.getCenter(),n=null===(e=this.endNode)||void 0===e?void 0:e.getCenter();return i&&n?{x:(i.x+n.x)/2,y:(i.y+n.y)/2}:{x:0,y:0}}getDistance(t){var e,i;const n=null===(e=this.startNode)||void 0===e?void 0:e.getCenter(),s=null===(i=this.endNode)||void 0===i?void 0:i.getCenter();return n&&s?A(n,s,t):0}}class B extends R{getCenter(){return this.getCurvedControlPoint(2)}getDistance(t){var e,i;const n=null===(e=this.startNode)||void 0===e?void 0:e.getCenter(),s=null===(i=this.endNode)||void 0===i?void 0:i.getCenter();if(!n||!s)return 0;const o=this.getCurvedControlPoint();let r,a,h,l,d,u=1e9,c=n.x,_=n.y;for(a=1;a<10;a++)h=.1*a,l=Math.pow(1-h,2)*n.x+2*h*(1-h)*o.x+Math.pow(h,2)*s.x,d=Math.pow(1-h,2)*n.y+2*h*(1-h)*o.y+Math.pow(h,2)*s.y,a>0&&(r=A({x:c,y:_},{x:l,y:d},t),u=r({r:parseInt(t.substring(1,3),16),g:parseInt(t.substring(3,5),16),b:parseInt(t.substring(5,7),16)}),W=t=>"#"+((1<<24)+(t.r<<16)+(t.g<<8)+t.b).toString(16).slice(1),G=["label","name"],Z={size:5,color:new F("#1d87c9")},H={color:new F("#ababab"),width:.3},X=()=>({getNodeStyle:t=>Object.assign(Object.assign({},Z),{label:q(t)}),getEdgeStyle:t=>Object.assign(Object.assign({},H),{label:q(t)})}),q=t=>{const e=t.getData();for(let t=0;t({x:Math.min(t.x,e.x),y:Math.min(t.y,e.y),width:Math.abs(t.x-e.x),height:Math.abs(t.y-e.y)}))(t,e))}contains(t){return a(this._rectangle,t)}getBoundingBox(){return this._rectangle}}var Y={value:()=>{}};function $(){for(var t,e=0,i=arguments.length,n={};e=0&&(e=t.slice(i+1),t=t.slice(0,i)),t&&!n.hasOwnProperty(t))throw new Error("unknown type: "+t);return{type:t,name:e}})),r=-1,a=o.length;if(!(arguments.length<2)){if(null!=e&&"function"!=typeof e)throw new Error("invalid callback: "+e);for(;++r0)for(var i,n,s=new Array(i),o=0;oe?1:t>=e?0:NaN}ct.prototype={constructor:ct,appendChild:function(t){return this._parent.insertBefore(t,this._next)},insertBefore:function(t,e){return this._parent.insertBefore(t,e)},querySelector:function(t){return this._parent.querySelector(t)},querySelectorAll:function(t){return this._parent.querySelectorAll(t)}};var vt="http://www.w3.org/1999/xhtml";const yt={svg:"http://www.w3.org/2000/svg",xhtml:vt,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function xt(t){var e=t+="",i=e.indexOf(":");return i>=0&&"xmlns"!==(e=t.slice(0,i))&&(t=t.slice(i+1)),yt.hasOwnProperty(e)?{space:yt[e],local:t}:t}function bt(t){return function(){this.removeAttribute(t)}}function St(t){return function(){this.removeAttributeNS(t.space,t.local)}}function wt(t,e){return function(){this.setAttribute(t,e)}}function Tt(t,e){return function(){this.setAttributeNS(t.space,t.local,e)}}function Et(t,e){return function(){var i=e.apply(this,arguments);null==i?this.removeAttribute(t):this.setAttribute(t,i)}}function Pt(t,e){return function(){var i=e.apply(this,arguments);null==i?this.removeAttributeNS(t.space,t.local):this.setAttributeNS(t.space,t.local,i)}}function At(t){return t.ownerDocument&&t.ownerDocument.defaultView||t.document&&t||t.defaultView}function Ct(t){return function(){this.style.removeProperty(t)}}function Mt(t,e,i){return function(){this.style.setProperty(t,e,i)}}function Nt(t,e,i){return function(){var n=e.apply(this,arguments);null==n?this.style.removeProperty(t):this.style.setProperty(t,n,i)}}function Dt(t,e){return t.style.getPropertyValue(e)||At(t).getComputedStyle(t,null).getPropertyValue(e)}function It(t){return function(){delete this[t]}}function Lt(t,e){return function(){this[t]=e}}function Rt(t,e){return function(){var i=e.apply(this,arguments);null==i?delete this[t]:this[t]=i}}function Ot(t){return t.trim().split(/^|\s+/)}function kt(t){return t.classList||new Bt(t)}function Bt(t){this._node=t,this._names=Ot(t.getAttribute("class")||"")}function zt(t,e){for(var i=kt(t),n=-1,s=e.length;++n=0&&(this._names.splice(e,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(t){return this._names.indexOf(t)>=0}};var le=[null];function de(t,e){this._groups=t,this._parents=e}function ue(){return new de([[document.documentElement]],le)}de.prototype=ue.prototype={constructor:de,select:function(t){"function"!=typeof t&&(t=it(t));for(var e=this._groups,i=e.length,n=new Array(i),s=0;s=x&&(x=y+1);!(v=p[x])&&++x=0;)(n=s[o])&&(r&&4^n.compareDocumentPosition(r)&&r.parentNode.insertBefore(n,r),r=n);return this},sort:function(t){function e(e,i){return e&&i?t(e.__data__,i.__data__):!e-!i}t||(t=mt);for(var i=this._groups,n=i.length,s=new Array(n),o=0;o1?this.each((null==e?Ct:"function"==typeof e?Nt:Mt)(t,e,i??"")):Dt(this.node(),t)},property:function(t,e){return arguments.length>1?this.each((null==e?It:"function"==typeof e?Rt:Lt)(t,e)):this.node()[t]},classed:function(t,e){var i=Ot(t+"");if(arguments.length<2){for(var n=kt(this.node()),s=-1,o=i.length;++s=0&&(e=t.slice(i+1),t=t.slice(0,i)),{type:t,name:e}})}(t+""),r=o.length;if(!(arguments.length<2)){for(a=e?oe:se,n=0;n()=>t;function Se(t,{sourceEvent:e,subject:i,target:n,identifier:s,active:o,x:r,y:a,dx:h,dy:l,dispatch:d}){Object.defineProperties(this,{type:{value:t,enumerable:!0,configurable:!0},sourceEvent:{value:e,enumerable:!0,configurable:!0},subject:{value:i,enumerable:!0,configurable:!0},target:{value:n,enumerable:!0,configurable:!0},identifier:{value:s,enumerable:!0,configurable:!0},active:{value:o,enumerable:!0,configurable:!0},x:{value:r,enumerable:!0,configurable:!0},y:{value:a,enumerable:!0,configurable:!0},dx:{value:h,enumerable:!0,configurable:!0},dy:{value:l,enumerable:!0,configurable:!0},_:{value:d}})}function we(t){return!t.ctrlKey&&!t.button}function Te(){return this.parentNode}function Ee(t,e){return e??{x:t.x,y:t.y}}function Pe(){return navigator.maxTouchPoints||"ontouchstart"in this}Se.prototype.on=function(){var t=this._.on.apply(this._,arguments);return t===this._?this:t};const Ae=t=>+t;function Ce(t){return((t=Math.exp(t))+1/t)/2}const Me=function t(e,i,n){function s(t,s){var o,r,a=t[0],h=t[1],l=t[2],d=s[0],u=s[1],c=s[2],_=d-a,f=u-h,g=_*_+f*f;if(g<1e-12)r=Math.log(c/l)/e,o=function(t){return[a+t*_,h+t*f,l*Math.exp(e*t*r)]};else{var p=Math.sqrt(g),m=(c*c-l*l+n*g)/(2*l*i*p),v=(c*c-l*l-n*g)/(2*c*i*p),y=Math.log(Math.sqrt(m*m+1)-m),x=Math.log(Math.sqrt(v*v+1)-v);r=(x-y)/e,o=function(t){var n=t*r,s=Ce(y),o=l/(i*p)*(s*function(t){return((t=Math.exp(2*t))-1)/(t+1)}(e*n+y)-function(t){return((t=Math.exp(t))-1/t)/2}(y));return[a+o*_,h+o*f,l*s/Ce(e*n+y)]}}return o.duration=1e3*r*e/Math.SQRT2,o}return s.rho=function(e){var i=Math.max(.001,+e),n=i*i;return t(i,n,n*n)},s}(Math.SQRT2,2,4);var Ne,De,Ie=0,Le=0,Re=0,Oe=0,ke=0,Be=0,ze="object"==typeof performance&&performance.now?performance:Date,Ue="object"==typeof window&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(t){setTimeout(t,17)};function Fe(){return ke||(Ue(je),ke=ze.now()+Be)}function je(){ke=0}function We(){this._call=this._time=this._next=null}function Ge(t,e,i){var n=new We;return n.restart(t,e,i),n}function Ze(){ke=(Oe=ze.now())+Be,Ie=Le=0;try{!function(){Fe(),++Ie;for(var t,e=Ne;e;)(t=ke-e._time)>=0&&e._call.call(void 0,t),e=e._next;--Ie}()}finally{Ie=0,function(){for(var t,e,i=Ne,n=1/0;i;)i._call?(n>i._time&&(n=i._time),t=i,i=i._next):(e=i._next,i._next=null,i=t?t._next=e:Ne=e);De=t,Xe(n)}(),ke=0}}function He(){var t=ze.now(),e=t-Oe;e>1e3&&(Be-=e,Oe=t)}function Xe(t){Ie||(Le&&(Le=clearTimeout(Le)),t-ke>24?(t<1/0&&(Le=setTimeout(Ze,t-ze.now()-Be)),Re&&(Re=clearInterval(Re))):(Re||(Oe=ze.now(),Re=setInterval(He,1e3)),Ie=1,Ue(Ze)))}function qe(t,e,i){var n=new We;return e=null==e?0:+e,n.restart(i=>{n.stop(),t(i+e)},e,i),n}We.prototype=Ge.prototype={constructor:We,restart:function(t,e,i){if("function"!=typeof t)throw new TypeError("callback is not a function");i=(null==i?Fe():+i)+(null==e?0:+e),this._next||De===this||(De?De._next=this:Ne=this,De=this),this._call=t,this._time=i,Xe()},stop:function(){this._call&&(this._call=null,this._time=1/0,Xe())}};var Ve=tt("start","end","cancel","interrupt"),Ye=[];function $e(t,e,i,n,s,o){var r=t.__transition;if(r){if(i in r)return}else t.__transition={};!function(t,e,i){var n,s=t.__transition;function o(h){var l,d,u,c;if(1!==i.state)return a();for(l in s)if((c=s[l]).name===i.name){if(3===c.state)return qe(o);4===c.state?(c.state=6,c.timer.stop(),c.on.call("interrupt",t,t.__data__,c.index,c.group),delete s[l]):+l0)throw new Error("too late; already scheduled");return i}function Qe(t,e){var i=Je(t,e);if(i.state>3)throw new Error("too late; already running");return i}function Je(t,e){var i=t.__transition;if(!i||!(i=i[e]))throw new Error("transition not found");return i}function ti(t,e){var i,n,s,o=t.__transition,r=!0;if(o){for(s in e=null==e?null:e+"",o)(i=o[s]).name===e?(n=i.state>2&&i.state<5,i.state=6,i.timer.stop(),i.on.call(n?"interrupt":"cancel",t,t.__data__,i.index,i.group),delete o[s]):r=!1;r&&delete t.__transition}}function ei(t,e){return t=+t,e=+e,function(i){return t*(1-i)+e*i}}var ii,ni=180/Math.PI,si={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function oi(t,e,i,n,s,o){var r,a,h;return(r=Math.sqrt(t*t+e*e))&&(t/=r,e/=r),(h=t*i+e*n)&&(i-=t*h,n-=e*h),(a=Math.sqrt(i*i+n*n))&&(i/=a,n/=a,h/=a),t*n180?e+=360:e-t>180&&(t+=360),o.push({i:i.push(s(i)+"rotate(",null,n)-2,x:ei(t,e)})):e&&i.push(s(i)+"rotate("+e+n)}(o.rotate,r.rotate,a,h),function(t,e,i,o){t!==e?o.push({i:i.push(s(i)+"skewX(",null,n)-2,x:ei(t,e)}):e&&i.push(s(i)+"skewX("+e+n)}(o.skewX,r.skewX,a,h),function(t,e,i,n,o,r){if(t!==i||e!==n){var a=o.push(s(o)+"scale(",null,",",null,")");r.push({i:a-4,x:ei(t,i)},{i:a-2,x:ei(e,n)})}else 1===i&&1===n||o.push(s(o)+"scale("+i+","+n+")")}(o.scaleX,o.scaleY,r.scaleX,r.scaleY,a,h),o=r=null,function(t){for(var e,i=-1,n=h.length;++i>8&15|e>>4&240,e>>4&15|240&e,(15&e)<<4|15&e,1):8===i?Ii(e>>24&255,e>>16&255,e>>8&255,(255&e)/255):4===i?Ii(e>>12&15|e>>8&240,e>>8&15|e>>4&240,e>>4&15|240&e,((15&e)<<4|15&e)/255):null):(e=bi.exec(t))?new Ri(e[1],e[2],e[3],1):(e=Si.exec(t))?new Ri(255*e[1]/100,255*e[2]/100,255*e[3]/100,1):(e=wi.exec(t))?Ii(e[1],e[2],e[3],e[4]):(e=Ti.exec(t))?Ii(255*e[1]/100,255*e[2]/100,255*e[3]/100,e[4]):(e=Ei.exec(t))?Fi(e[1],e[2]/100,e[3]/100,1):(e=Pi.exec(t))?Fi(e[1],e[2]/100,e[3]/100,e[4]):Ai.hasOwnProperty(t)?Di(Ai[t]):"transparent"===t?new Ri(NaN,NaN,NaN,0):null}function Di(t){return new Ri(t>>16&255,t>>8&255,255&t,1)}function Ii(t,e,i,n){return n<=0&&(t=e=i=NaN),new Ri(t,e,i,n)}function Li(t,e,i,n){return 1===arguments.length?((s=t)instanceof fi||(s=Ni(s)),s?new Ri((s=s.rgb()).r,s.g,s.b,s.opacity):new Ri):new Ri(t,e,i,n??1);var s}function Ri(t,e,i,n){this.r=+t,this.g=+e,this.b=+i,this.opacity=+n}function Oi(){return`#${Ui(this.r)}${Ui(this.g)}${Ui(this.b)}`}function ki(){const t=Bi(this.opacity);return`${1===t?"rgb(":"rgba("}${zi(this.r)}, ${zi(this.g)}, ${zi(this.b)}${1===t?")":`, ${t})`}`}function Bi(t){return isNaN(t)?1:Math.max(0,Math.min(1,t))}function zi(t){return Math.max(0,Math.min(255,Math.round(t)||0))}function Ui(t){return((t=zi(t))<16?"0":"")+t.toString(16)}function Fi(t,e,i,n){return n<=0?t=e=i=NaN:i<=0||i>=1?t=e=NaN:e<=0&&(t=NaN),new Wi(t,e,i,n)}function ji(t){if(t instanceof Wi)return new Wi(t.h,t.s,t.l,t.opacity);if(t instanceof fi||(t=Ni(t)),!t)return new Wi;if(t instanceof Wi)return t;var e=(t=t.rgb()).r/255,i=t.g/255,n=t.b/255,s=Math.min(e,i,n),o=Math.max(e,i,n),r=NaN,a=o-s,h=(o+s)/2;return a?(r=e===o?(i-n)/a+6*(i0&&h<1?0:r,new Wi(r,a,h,t.opacity)}function Wi(t,e,i,n){this.h=+t,this.s=+e,this.l=+i,this.opacity=+n}function Gi(t){return(t=(t||0)%360)<0?t+360:t}function Zi(t){return Math.max(0,Math.min(1,t||0))}function Hi(t,e,i){return 255*(t<60?e+(i-e)*t/60:t<180?i:t<240?e+(i-e)*(240-t)/60:e)}function Xi(t,e,i,n,s){var o=t*t,r=o*t;return((1-3*t+3*o-r)*e+(4-6*o+3*r)*i+(1+3*t+3*o-3*r)*n+r*s)/6}ci(fi,Ni,{copy(t){return Object.assign(new this.constructor,this,t)},displayable(){return this.rgb().displayable()},hex:Ci,formatHex:Ci,formatHex8:function(){return this.rgb().formatHex8()},formatHsl:function(){return ji(this).formatHsl()},formatRgb:Mi,toString:Mi}),ci(Ri,Li,_i(fi,{brighter(t){return t=null==t?pi:Math.pow(pi,t),new Ri(this.r*t,this.g*t,this.b*t,this.opacity)},darker(t){return t=null==t?gi:Math.pow(gi,t),new Ri(this.r*t,this.g*t,this.b*t,this.opacity)},rgb(){return this},clamp(){return new Ri(zi(this.r),zi(this.g),zi(this.b),Bi(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:Oi,formatHex:Oi,formatHex8:function(){return`#${Ui(this.r)}${Ui(this.g)}${Ui(this.b)}${Ui(255*(isNaN(this.opacity)?1:this.opacity))}`},formatRgb:ki,toString:ki})),ci(Wi,function(t,e,i,n){return 1===arguments.length?ji(t):new Wi(t,e,i,n??1)},_i(fi,{brighter(t){return t=null==t?pi:Math.pow(pi,t),new Wi(this.h,this.s,this.l*t,this.opacity)},darker(t){return t=null==t?gi:Math.pow(gi,t),new Wi(this.h,this.s,this.l*t,this.opacity)},rgb(){var t=this.h%360+360*(this.h<0),e=isNaN(t)||isNaN(this.s)?0:this.s,i=this.l,n=i+(i<.5?i:1-i)*e,s=2*i-n;return new Ri(Hi(t>=240?t-240:t+120,s,n),Hi(t,s,n),Hi(t<120?t+240:t-120,s,n),this.opacity)},clamp(){return new Wi(Gi(this.h),Zi(this.s),Zi(this.l),Bi(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){const t=Bi(this.opacity);return`${1===t?"hsl(":"hsla("}${Gi(this.h)}, ${100*Zi(this.s)}%, ${100*Zi(this.l)}%${1===t?")":`, ${t})`}`}}));const qi=t=>()=>t;function Vi(t,e){var i=e-t;return i?function(t,e){return function(i){return t+i*e}}(t,i):qi(isNaN(t)?e:t)}const Yi=function t(e){var i=function(t){return 1===(t=+t)?Vi:function(e,i){return i-e?function(t,e,i){return t=Math.pow(t,i),e=Math.pow(e,i)-t,i=1/i,function(n){return Math.pow(t+n*e,i)}}(e,i,t):qi(isNaN(e)?i:e)}}(e);function n(t,e){var n=i((t=Li(t)).r,(e=Li(e)).r),s=i(t.g,e.g),o=i(t.b,e.b),r=Vi(t.opacity,e.opacity);return function(e){return t.r=n(e),t.g=s(e),t.b=o(e),t.opacity=r(e),t+""}}return n.gamma=t,n}(1);function $i(t){return function(e){var i,n,s=e.length,o=new Array(s),r=new Array(s),a=new Array(s);for(i=0;i=1?(i=1,e-1):Math.floor(i*e),s=t[n],o=t[n+1],r=n>0?t[n-1]:2*s-o,a=no&&(s=e.slice(o,s),a[r]?a[r]+=s:a[++r]=s),(i=i[0])===(n=n[0])?a[r]?a[r]+=n:a[++r]=n:(a[++r]=null,h.push({i:r,x:ei(i,n)})),o=Qi.lastIndex;return o=0&&(t=t.slice(0,e)),!t||"start"===t})}(e)?Ke:Qe;return function(){var r=o(this,t),a=r.on;a!==n&&(s=(n=a).copy()).on(e,i),r.on=s}}(i,t,e))},attr:function(t,e){var i=xt(t),n="transform"===i?hi:tn;return this.attrTween(t,"function"==typeof e?(i.local?an:rn)(i,n,ui(this,"attr."+t,e)):null==e?(i.local?nn:en)(i):(i.local?on:sn)(i,n,e))},attrTween:function(t,e){var i="attr."+t;if(arguments.length<2)return(i=this.tween(i))&&i._value;if(null==e)return this.tween(i,null);if("function"!=typeof e)throw new Error;var n=xt(t);return this.tween(i,(n.local?hn:ln)(n,e))},style:function(t,e,i){var n="transform"==(t+="")?ai:tn;return null==e?this.styleTween(t,function(t,e){var i,n,s;return function(){var o=Dt(this,t),r=(this.style.removeProperty(t),Dt(this,t));return o===r?null:o===i&&r===n?s:s=e(i=o,n=r)}}(t,n)).on("end.style."+t,gn(t)):"function"==typeof e?this.styleTween(t,function(t,e,i){var n,s,o;return function(){var r=Dt(this,t),a=i(this),h=a+"";return null==a&&(this.style.removeProperty(t),h=a=Dt(this,t)),r===h?null:r===n&&h===s?o:(s=h,o=e(n=r,a))}}(t,n,ui(this,"style."+t,e))).each(function(t,e){var i,n,s,o,r="style."+e,a="end."+r;return function(){var h=Qe(this,t),l=h.on,d=null==h.value[r]?o||(o=gn(e)):void 0;l===i&&s===d||(n=(i=l).copy()).on(a,s=d),h.on=n}}(this._id,t)):this.styleTween(t,function(t,e,i){var n,s,o=i+"";return function(){var r=Dt(this,t);return r===o?null:r===n?s:s=e(n=r,i)}}(t,n,e),i).on("end.style."+t,null)},styleTween:function(t,e,i){var n="style."+(t+="");if(arguments.length<2)return(n=this.tween(n))&&n._value;if(null==e)return this.tween(n,null);if("function"!=typeof e)throw new Error;return this.tween(n,function(t,e,i){var n,s;function o(){var o=e.apply(this,arguments);return o!==s&&(n=(s=o)&&function(t,e,i){return function(n){this.style.setProperty(t,e.call(this,n),i)}}(t,o,i)),n}return o._value=e,o}(t,e,i??""))},text:function(t){return this.tween("text","function"==typeof t?function(t){return function(){var e=t(this);this.textContent=e??""}}(ui(this,"text",t)):function(t){return function(){this.textContent=t}}(null==t?"":t+""))},textTween:function(t){var e="text";if(arguments.length<1)return(e=this.tween(e))&&e._value;if(null==t)return this.tween(e,null);if("function"!=typeof t)throw new Error;return this.tween(e,function(t){var e,i;function n(){var n=t.apply(this,arguments);return n!==i&&(e=(i=n)&&function(t){return function(e){this.textContent=t.call(this,e)}}(n)),e}return n._value=t,n}(t))},remove:function(){return this.on("end.remove",function(t){return function(){var e=this.parentNode;for(var i in this.__transition)if(+i!==t)return;e&&e.removeChild(this)}}(this._id))},tween:function(t,e){var i=this._id;if(t+="",arguments.length<2){for(var n,s=Je(this.node(),i).tween,o=0,r=s.length;o()=>t;function wn(t,{sourceEvent:e,target:i,transform:n,dispatch:s}){Object.defineProperties(this,{type:{value:t,enumerable:!0,configurable:!0},sourceEvent:{value:e,enumerable:!0,configurable:!0},target:{value:i,enumerable:!0,configurable:!0},transform:{value:n,enumerable:!0,configurable:!0},_:{value:s}})}function Tn(t,e,i){this.k=t,this.x=e,this.y=i}Tn.prototype={constructor:Tn,scale:function(t){return 1===t?this:new Tn(this.k*t,this.x,this.y)},translate:function(t,e){return 0===t&0===e?this:new Tn(this.k,this.x+this.k*t,this.y+this.k*e)},apply:function(t){return[t[0]*this.k+this.x,t[1]*this.k+this.y]},applyX:function(t){return t*this.k+this.x},applyY:function(t){return t*this.k+this.y},invert:function(t){return[(t[0]-this.x)/this.k,(t[1]-this.y)/this.k]},invertX:function(t){return(t-this.x)/this.k},invertY:function(t){return(t-this.y)/this.k},rescaleX:function(t){return t.copy().domain(t.range().map(this.invertX,this).map(t.invert,t))},rescaleY:function(t){return t.copy().domain(t.range().map(this.invertY,this).map(t.invert,t))},toString:function(){return"translate("+this.x+","+this.y+") scale("+this.k+")"}};var En=new Tn(1,0,0);function Pn(t){t.stopImmediatePropagation()}function An(t){t.preventDefault(),t.stopImmediatePropagation()}function Cn(t){return!(t.ctrlKey&&"wheel"!==t.type||t.button)}function Mn(){var t=this;return t instanceof SVGElement?(t=t.ownerSVGElement||t).hasAttribute("viewBox")?[[(t=t.viewBox.baseVal).x,t.y],[t.x+t.width,t.y+t.height]]:[[0,0],[t.width.baseVal.value,t.height.baseVal.value]]:[[0,0],[t.clientWidth,t.clientHeight]]}function Nn(){return this.__zoom||En}function Dn(t){return-t.deltaY*(1===t.deltaMode?.05:t.deltaMode?1:.002)*(t.ctrlKey?10:1)}function In(){return navigator.maxTouchPoints||"ontouchstart"in this}function Ln(t,e,i){var n=t.invertX(e[0][0])-i[0][0],s=t.invertX(e[1][0])-i[1][0],o=t.invertY(e[0][1])-i[0][1],r=t.invertY(e[1][1])-i[1][1];return t.translate(s>n?(n+s)/2:Math.min(0,n)||Math.max(0,s),r>o?(o+r)/2:Math.min(0,o)||Math.max(0,r))}Tn.prototype;const Rn=(t,e)=>!!t&&!!e&&t.x===e.x&&t.y===e.y;var On;function kn(t,e,i){t.on(On.SIMULATION_START,()=>{e.emit(On.SIMULATION_START,void 0),i(!0)}),t.on(On.SIMULATION_PROGRESS,t=>{e.emit(On.SIMULATION_PROGRESS,t)}),t.on(On.SIMULATION_END,t=>{e.emit(On.SIMULATION_END,t),i(!1)}),t.on(On.SIMULATION_STEP,t=>{e.emit(On.SIMULATION_STEP,t)}),t.on(On.NODE_DRAG,t=>{e.emit(On.NODE_DRAG,t)}),t.on(On.SETTINGS_UPDATE,t=>{e.emit(On.SETTINGS_UPDATE,t)})}function Bn(t){return function(){return t}}function zn(t){return 1e-6*(t()-.5)}function Un(t){return t.index}function Fn(t,e){var i=t.get(e);if(!i)throw new Error("node not found: "+e);return i}!function(t){t.SIMULATION_START="simulation-start",t.SIMULATION_STEP="simulation-step",t.SIMULATION_PROGRESS="simulation-progress",t.SIMULATION_END="simulation-end",t.NODE_DRAG="node-drag",t.NODE_DRAG_END="node-drag-end",t.SETTINGS_UPDATE="settings-update"}(On||(On={}));const jn=4294967296;function Wn(t){return t.x}function Gn(t){return t.y}var Zn=Math.PI*(3-Math.sqrt(5));function Hn(t,e,i,n){if(isNaN(e)||isNaN(i))return t;var s,o,r,a,h,l,d,u,c,_=t._root,f={data:n},g=t._x0,p=t._y0,m=t._x1,v=t._y1;if(!_)return t._root=f,t;for(;_.length;)if((l=e>=(o=(g+m)/2))?g=o:m=o,(d=i>=(r=(p+v)/2))?p=r:v=r,s=_,!(_=_[u=d<<1|l]))return s[u]=f,t;if(a=+t._x.call(null,_.data),h=+t._y.call(null,_.data),e===a&&i===h)return f.next=_,s?s[u]=f:t._root=f,t;do{s=s?s[u]=new Array(4):t._root=new Array(4),(l=e>=(o=(g+m)/2))?g=o:m=o,(d=i>=(r=(p+v)/2))?p=r:v=r}while((u=d<<1|l)==(c=(h>=r)<<1|a>=o));return s[c]=_,s[u]=f,t}function Xn(t,e,i,n,s){this.node=t,this.x0=e,this.y0=i,this.x1=n,this.y1=s}function qn(t){return t[0]}function Vn(t){return t[1]}function Yn(t,e,i){var n=new $n(e??qn,i??Vn,NaN,NaN,NaN,NaN);return null==t?n:n.addAll(t)}function $n(t,e,i,n,s,o){this._x=t,this._y=e,this._x0=i,this._y0=n,this._x1=s,this._y1=o,this._root=void 0}function Kn(t){for(var e={data:t.data},i=e;t=t.next;)i=i.next={data:t.data};return e}var Qn=Yn.prototype=$n.prototype;function Jn(t){return t.x+t.vx}function ts(t){return t.y+t.vy}Qn.copy=function(){var t,e,i=new $n(this._x,this._y,this._x0,this._y0,this._x1,this._y1),n=this._root;if(!n)return i;if(!n.length)return i._root=Kn(n),i;for(t=[{source:n,target:i._root=new Array(4)}];n=t.pop();)for(var s=0;s<4;++s)(e=n.source[s])&&(e.length?t.push({source:e,target:n.target[s]=new Array(4)}):n.target[s]=Kn(e));return i},Qn.add=function(t){const e=+this._x.call(null,t),i=+this._y.call(null,t);return Hn(this.cover(e,i),e,i,t)},Qn.addAll=function(t){var e,i,n,s,o=t.length,r=new Array(o),a=new Array(o),h=1/0,l=1/0,d=-1/0,u=-1/0;for(i=0;id&&(d=n),su&&(u=s));if(h>d||l>u)return this;for(this.cover(h,l).cover(d,u),i=0;it||t>=s||n>e||e>=o;)switch(a=(ec||(o=h.y0)>_||(r=h.x1)=m)<<1|t>=p)&&(h=f[f.length-1],f[f.length-1]=f[f.length-1-l],f[f.length-1-l]=h)}else{var v=t-+this._x.call(null,g.data),y=e-+this._y.call(null,g.data),x=v*v+y*y;if(x=(a=(f+p)/2))?f=a:p=a,(d=r>=(h=(g+m)/2))?g=h:m=h,e=_,!(_=_[u=d<<1|l]))return this;if(!_.length)break;(e[u+1&3]||e[u+2&3]||e[u+3&3])&&(i=e,c=u)}for(;_.data!==t;)if(n=_,!(_=_.next))return this;return(s=_.next)&&delete _.next,n?(s?n.next=s:delete n.next,this):e?(s?e[u]=s:delete e[u],(_=e[0]||e[1]||e[2]||e[3])&&_===(e[3]||e[2]||e[1]||e[0])&&!_.length&&(i?i[c]=_:this._root=_),this):(this._root=s,this)},Qn.removeAll=function(t){for(var e=0,i=t.length;e100*(t>0?t:1),ns={useGPU:!1,isSimulatingOnDataUpdate:!0,isSimulatingOnSettingsUpdate:!0,isSimulatingOnUnstick:!0,isPhysicsEnabled:!1,alpha:{alpha:1,alphaMin:.05,alphaDecay:.028,alphaTarget:0},centering:{x:0,y:0,strength:1},collision:{radius:15,strength:1,iterations:1},links:{distance:50,strength:1,iterations:1},manyBody:{strength:-100,theta:.9,distanceMin:1,distanceMax:is(50)},positioning:{forceX:{x:0,strength:.1},forceY:{y:0,strength:.1}},anchorX:"center",anchorY:"center"},ss={rowGap:50,colGap:50},os={nodeGap:50,levelGap:50,treeGap:100,orientation:"vertical",reversed:!1};class rs extends t{constructor(){super(...arguments),this._nodes=[],this._edges=[],this._nodeIndexByNodeId={},this._cancelSimulation=!1,this._schedulerPort=null}terminate(){var t;this._cancelSimulation=!0,null===(t=this._schedulerPort)||void 0===t||t.close(),this._schedulerPort=null,this.removeAllListeners()}_scheduleNext(t){if("undefined"!=typeof MessageChannel){const e=new MessageChannel;this._schedulerPort=e.port2,e.port1.onmessage=()=>{this._schedulerPort=null,t()},e.port2.postMessage(null)}else setTimeout(t,0)}_rebuildNodeIndex(){this._nodeIndexByNodeId={};for(let t=0;t0&&this.activateSimulation())}setupData(t){this.clearData(),this._initializeNewData(t),this._settings.isSimulatingOnDataUpdate&&(this._updateSimulationData(),this._runSimulation())}mergeData(t){this._initializeNewData(t),this._settings.isPhysicsEnabled||this._pinNodes(),this._settings.isSimulatingOnDataUpdate&&(this._updateSimulationData(),this.activateSimulation())}updateData(t){const e=new Set(t.nodes.map(t=>t.id)),i=this._nodes.filter(t=>e.has(t.id)),n=t.nodes.filter(t=>void 0===this._nodeIndexByNodeId[t.id]);this._nodes=[...i,...n],this._rebuildNodeIndex(),this._edges=t.edges,this._settings.isSimulatingOnSettingsUpdate&&(this._updateSimulationData(),this.activateSimulation())}deleteData(t){if(t.nodeIds){const e=new Set(t.nodeIds);this._nodes=this._nodes.filter(t=>!e.has(t.id))}if(t.edgeIds){const e=new Set(t.edgeIds);this._edges=this._edges.filter(t=>!e.has(t.id))}this._rebuildNodeIndex(),this._settings.isSimulatingOnDataUpdate&&(this._updateSimulationData(),this.activateSimulation())}patchData(t){if(t.nodes){const e={};for(let t=0;t0&&this.activateSimulation()}terminate(){var t;super.terminate(),null===(t=this._simulation)||void 0===t||t.stop()}_resetSimulation(){this._simulation&&(this._simulation.stop(),this._simulation.on("tick",null).on("end",null)),this._linkForce=function(t){var e,i,n,s,o,r,a=Un,h=function(t){return 1/Math.min(s[t.source.index],s[t.target.index])},l=Bn(30),d=1;function u(n){for(var s=0,a=t.length;s[a(t,e,n),t]));for(r=0,s=new Array(l);rt.id),this._simulation=function(t){var e,i=1,n=.001,s=1-Math.pow(n,1/300),o=0,r=.6,a=new Map,h=Ge(u),l=tt("tick","end"),d=function(){let t=1;return()=>(t=(1664525*t+1013904223)%jn)/jn}();function u(){c(),l.call("tick",e),i1?(null==i?a.delete(t):a.set(t,f(i)),e):a.get(t)},find:function(e,i,n){var s,o,r,a,h,l=0,d=t.length;for(null==n?n=1/0:n*=n,l=0;l1?(l.on(t,i),e):l.on(t)}}}(this._nodes).force("link",this._linkForce).stop(),this._applySettingsToSimulation(this._settings),this._simulation.on("tick",()=>{this.emit(On.SIMULATION_STEP,{nodes:this._nodes,edges:this._edges})}),this._simulation.on("end",()=>{this._isDragging=!1,this._isStabilizing=!1,this.emit(On.SIMULATION_END,{nodes:this._nodes,edges:this._edges}),this._settings.isPhysicsEnabled||this._pinNodes()})}_runSimulation(t){if(this._isStabilizing||this._cancelSimulation)return;(this._settings.isPhysicsEnabled||(null==t?void 0:t.isUpdatingSettings))&&this._unpinNodes(),this.emit(On.SIMULATION_START,void 0),this._isStabilizing=!0,this._simulation.alpha(this._settings.alpha.alpha).alphaTarget(this._settings.alpha.alphaTarget).stop();const e=Math.min(500,Math.ceil(Math.log(this._settings.alpha.alphaMin)/Math.log(1-this._settings.alpha.alphaDecay)));let i=-1,n=0;const s=()=>{if(this._cancelSimulation)return this._isStabilizing=!1,void(this._cancelSimulation=!1);const t=Math.min(n+100,e);for(;ni&&(i=t,this.emit(On.SIMULATION_PROGRESS,{nodes:this._nodes,edges:this._edges,progress:t/100}))}nl+f||od+f||rh.index){var g=l-a.x-a.vx,p=d-a.y-a.vy,m=g*g+p*p;mt.r&&(t.r=t[e].r)}function h(){if(e){var n,s,o=e.length;for(i=new Array(o),n=0;n=a)){(t.data!==e||t.next)&&(0===u&&(f+=(u=zn(i))*u),0===c&&(f+=(c=zn(i))*c),f=s)continue;h<1&&(h=1);const u=-t*e/h;o.vx+=r*u,o.vy+=a*u}}}return o.initialize=t=>{n=t},o}(t.manyBody.strength,t.manyBody.distanceMax,()=>this._edges)):this._simulation.force("edgeMidpointRepulsion",null)}if(null===t.manyBody&&(this._simulation.force("charge",null),this._simulation.force("edgeMidpointRepulsion",null)),null===(e=t.positioning)||void 0===e?void 0:e.forceX){const e=function(t){var e,i,n,s=Bn(.1);function o(t){for(var s,o=0,r=e.length;o{const n=t.createShader(i===hs.VERTEX?t.VERTEX_SHADER:t.FRAGMENT_SHADER);if(!n)throw new o("Failed to create shader.");if(t.shaderSource(n,e),t.compileShader(n),!t.getShaderParameter(n,t.COMPILE_STATUS)){const e=t.getShaderInfoLog(n);throw t.deleteShader(n),new o(`Failed to compile shader: ${e}`)}return n};class ds extends rs{constructor(t){super(),this._isStabilizing=!1,this._isDragging=!1,this._dragLoopRunning=!1,this._pendingRestart=!1,this._simulationGeneration=0,this._currentAlpha=0,this._currentStep=0,this._totalSteps=0,this._dragAlpha=0,this._dragNeedsReheat=!1,this._dirtyNodes=new Set,this._forceProgram=null,this._quadBuffer=null,this._quadVAO=null,this._stateTexA=null,this._stateTexB=null,this._fixedTex=null,this._fboA=null,this._fboB=null,this._texWidth=0,this._treeDataTexture=null,this._treeChildrenTexture=null,this._treeGeometryTexture=null,this._adjOffsetsTexture=null,this._adjEdgesTexture=null,this._cachedAdjacency=null,this._treeTexWidth=1,this._treeNodeCount=0,this._pingPong=!0,this._uniforms={},this.type="force",this._settings=Object.assign(Object.assign({},ns),t);const e=document.createElement("canvas").getContext("webgl2");if(!e)throw new o("Failed to create WebGL2 context for GPU force layout engine.");this._gl=e,this._initGPU(),this.clearData()}setSettings(t){const e=t;this._initialSettings||(this._initialSettings=Object.assign(m(ns),e));const i=m(this._settings);Object.assign(this._settings,e),v(this._settings,i)||(this.emit(On.SETTINGS_UPDATE,{settings:{type:"force",options:this._settings}}),i.isPhysicsEnabled&&!e.isPhysicsEnabled?this.stopSimulation():this._settings.isSimulatingOnSettingsUpdate&&this._nodes.length>0&&this.activateSimulation())}setupData(t){this.clearData(),this._initializeNewData(t),this._settings.isSimulatingOnDataUpdate&&this._runSimulation()}mergeData(t){this._initializeNewData(t),this._settings.isPhysicsEnabled||this._pinNodes(),this._settings.isSimulatingOnDataUpdate&&this.activateSimulation()}updateData(t){const e=new Set(t.nodes.map(t=>t.id)),i=this._nodes.filter(t=>e.has(t.id)),n=t.nodes.filter(t=>void 0===this._nodeIndexByNodeId[t.id]);this._nodes=[...i,...n],this._rebuildNodeIndex(),this._edges=t.edges,this._cachedAdjacency=null,this._settings.isSimulatingOnSettingsUpdate&&this.activateSimulation()}deleteData(t){if(t.nodeIds){const e=new Set(t.nodeIds);this._nodes=this._nodes.filter(t=>!e.has(t.id))}if(t.edgeIds){const e=new Set(t.edgeIds);this._edges=this._edges.filter(t=>!e.has(t.id))}this._rebuildNodeIndex(),this._cachedAdjacency=null,this._settings.isSimulatingOnDataUpdate&&this.activateSimulation()}patchData(t){if(t.nodes){const e={};for(let t=0;t0&&this.activateSimulation()}terminate(){var t;super.terminate();const e=this._gl;e&&(e.deleteBuffer(this._quadBuffer),e.deleteVertexArray(this._quadVAO),e.deleteProgram(this._forceProgram),e.deleteTexture(this._stateTexA),e.deleteTexture(this._stateTexB),e.deleteTexture(this._fixedTex),e.deleteTexture(this._treeDataTexture),e.deleteTexture(this._treeChildrenTexture),e.deleteTexture(this._treeGeometryTexture),e.deleteTexture(this._adjOffsetsTexture),e.deleteTexture(this._adjEdgesTexture),e.deleteFramebuffer(this._fboA),e.deleteFramebuffer(this._fboB),null===(t=e.getExtension("WEBGL_lose_context"))||void 0===t||t.loseContext())}reheat(){const t=this._settings.alpha;this._currentAlpha=t.alpha,this._totalSteps=Math.min(500,Math.ceil(Math.log(t.alphaMin)/Math.log(1-t.alphaDecay))),this._currentStep=0,this._isStabilizing||(this._ensurePositions(),this._uploadDataToGPU(),this._cachedAdjacency||this._buildAndUploadAdjacency(),this._startSimulationLoop())}_runSimulation(){this._isStabilizing||this._cancelSimulation||(this._ensurePositions(),this._uploadDataToGPU(),this._buildAndUploadAdjacency(),this._startSimulationLoop())}_startDragLoop(){if(this._dragLoopRunning)return;this._dragLoopRunning=!0;const t=this._settings.alpha.alphaDecay,e=this._settings.alpha.alphaMin;this._dragAlpha=.3,this._dragNeedsReheat=!1;const i=()=>{this._isDragging?(this._dragNeedsReheat&&(this._dragAlpha=.3,this._dragNeedsReheat=!1),this._dragAlpha+=(0-this._dragAlpha)*t,this._dragAlpha{if(t!==this._simulationGeneration)return;if(this._cancelSimulation)return this._isStabilizing=!1,this._cancelSimulation=!1,void this.emit(On.SIMULATION_END,{nodes:this._nodes,edges:this._edges});if(this._readbackFromGPU(),this._pendingRestart)return this._isStabilizing=!1,this._pendingRestart=!1,this._ensurePositions(),this._uploadDataToGPU(),this._cachedAdjacency||this._buildAndUploadAdjacency(),void this._startSimulationLoop();this._flushDirtyNodes(),this._buildAndUploadQuadTree();const r=Math.min(this._currentStep+1,this._totalSteps);for(;this._currentSteps&&(s=a,this.emit(On.SIMULATION_PROGRESS,{nodes:this._nodes,edges:this._edges,progress:a/100})),this._currentStep0&&(s=s.concat(t))}const o=function(t,e){var i,n;const s=t.length;if(0===s)return{treeData:new Float32Array(0),treeChildren:new Float32Array(0),treeGeometry:new Float32Array(0),nodeCount:0,texWidth:1};let o=1/0,r=1/0,a=-1/0,h=-1/0;for(let e=0;ea&&(a=i),n>h&&(h=n)}let l=Math.max(a-o,h-r);l<1e-6&&(l=1),l*=1.01;const d=.5*l,u=.5*(o+a)-d,c=.5*(r+h)-d,_=[];function f(t){const e=_.length;return _.push({cx:0,cy:0,charge:0,size:t,bodyIndex:-1,children:[null,null,null,null]}),e}const g=f(l),p=[u],m=[c];function v(t,e,i,n,s){return 2*(e>=n+.5*s?1:0)+(t>=i+.5*s?1:0)}function y(t,e,i,n){const s=.5*n;return{cx0:1&t?e+s:e,cy0:2&t?i+s:i,csz:s}}function x(t,i,n){let s=g,o=u,r=c,a=l;for(let h=0;h<50;h++){const h=_[s];if(-1===h.bodyIndex&&null===h.children[0]&&null===h.children[1]&&null===h.children[2]&&null===h.children[3])return h.bodyIndex=t,h.cx=i,h.cy=n,void(h.charge=e);if(h.bodyIndex>=0){const t=h.bodyIndex,i=h.cx,n=h.cy;h.bodyIndex=-1;const s=v(i,n,o,r,a),{cx0:l,cy0:d,csz:u}=y(s,o,r,a),c=f(u);p[c]=l,m[c]=d,h.children[s]=c,_[c].bodyIndex=t,_[c].cx=i,_[c].cy=n,_[c].charge=e}const l=v(i,n,o,r,a);if(null===h.children[l]){const{cx0:s,cy0:d,csz:u}=y(l,o,r,a),c=f(u);return p[c]=s,m[c]=d,h.children[l]=c,_[c].bodyIndex=t,_[c].cx=i,_[c].cy=n,void(_[c].charge=e)}const{cx0:d,cy0:u,csz:c}=y(l,o,r,a);s=h.children[l],o=d,r=u,a=c}}for(let e=0;e=0)return;let n=0,s=0,o=0,r=0;for(let e=0;e<4;e++){const a=i.children[e];if(null===a)continue;t(a);const h=_[a],l=Math.abs(h.charge);n+=h.charge,s+=h.cx*l,o+=h.cy*l,r+=l}r>0&&(i.cx=s/r,i.cy=o/r),i.charge=n}(g);const b=_.length,S=Math.ceil(Math.sqrt(b)),w=S*S,T=new Float32Array(4*w),E=new Float32Array(4*w),P=new Float32Array(4*w);for(let t=0;t=0?T[s+3]=-(e.bodyIndex+1):T[s+3]=e.size,E[s]=null!==e.children[0]?e.children[0]:-1,E[s+1]=null!==e.children[1]?e.children[1]:-1,E[s+2]=null!==e.children[2]?e.children[2]:-1,E[s+3]=null!==e.children[3]?e.children[3]:-1,P[s]=null!==(i=p[t])&&void 0!==i?i:0,P[s+1]=null!==(n=m[t])&&void 0!==n?n:0,P[s+2]=e.size,P[s+3]=0}for(let t=b;t= uNodeCount) {\n fragColor = vec4(0.0);\n return;\n }\n\n vec4 fixedData = texelFetch(uFixed, fc, 0);\n if (fixedData.x > 0.5) {\n fragColor = vec4(fixedData.yz, 0.0, 0.0);\n return;\n }\n\n vec4 state = texelFetch(uState, fc, 0);\n vec2 pos = state.xy;\n vec2 vel = state.zw;\n\n if (uHasManyBody > 0.5 && uTreeNodeCount > 0) {\n int stack[128];\n int top = 0;\n stack[top++] = 0;\n\n while (top > 0) {\n int idx = stack[--top];\n vec4 data = texelFetch(uTreeData, texCoord(idx, uTreeTexWidth), 0);\n float w = data.w;\n\n if (w < -0.5) {\n int bodyIdx = int(-w - 0.5);\n if (bodyIdx != nodeId) {\n vec2 delta = data.xy - pos;\n float distSq = dot(delta, delta);\n\n if (distSq < 1e-8) {\n delta = vec2(float(nodeId) * 1e-4 - float(bodyIdx) * 1e-4 + 1e-4, 1e-4);\n distSq = dot(delta, delta);\n }\n\n if (distSq < uDistanceMax2) {\n float l = distSq;\n if (l < uDistanceMin2) l = sqrt(uDistanceMin2 * l);\n vel += delta * (data.z * uAlpha / max(l, 1e-6));\n }\n }\n } else {\n vec2 delta = data.xy - pos;\n float distSq = dot(delta, delta);\n\n if (distSq > 0.0 && w * w / distSq < uTheta2) {\n if (distSq < uDistanceMax2) {\n float l = distSq;\n if (l < uDistanceMin2) l = sqrt(uDistanceMin2 * l);\n vel += delta * (data.z * uAlpha / max(l, 1e-6));\n }\n } else {\n vec4 ch = texelFetch(uTreeChildren, texCoord(idx, uTreeTexWidth), 0);\n if (ch.w >= 0.0 && top < 64) stack[top++] = int(ch.w + 0.5);\n if (ch.z >= 0.0 && top < 64) stack[top++] = int(ch.z + 0.5);\n if (ch.y >= 0.0 && top < 64) stack[top++] = int(ch.y + 0.5);\n if (ch.x >= 0.0 && top < 64) stack[top++] = int(ch.x + 0.5);\n }\n }\n }\n }\n\n if (uHasCollision > 0.5 && uCollisionRadius > 0.0 && uTreeNodeCount > 0) {\n float collisionDiam = uCollisionRadius * 2.0;\n vec2 predictedPos = state.xy + state.zw;\n int stack[64];\n int top = 0;\n stack[top++] = 0;\n\n while (top > 0) {\n int idx = stack[--top];\n vec4 data = texelFetch(uTreeData, texCoord(idx, uTreeTexWidth), 0);\n float w = data.w;\n\n if (w < -0.5) {\n int bodyIdx = int(-w - 0.5);\n if (bodyIdx != nodeId && bodyIdx < uNodeCount) {\n vec2 delta = data.xy - predictedPos;\n float dist = length(delta);\n\n if (dist < collisionDiam && dist > 0.0) {\n float push = (collisionDiam - dist) * uCollisionStrength;\n vel -= (delta / dist) * push * 0.5;\n }\n }\n } else {\n vec4 geo = texelFetch(uTreeGeometry, texCoord(idx, uTreeTexWidth), 0);\n float cellSize = geo.z;\n vec2 nearest = clamp(predictedPos, geo.xy, geo.xy + cellSize);\n float distToCell = length(nearest - predictedPos);\n\n if (distToCell < collisionDiam) {\n vec4 ch = texelFetch(uTreeChildren, texCoord(idx, uTreeTexWidth), 0);\n if (ch.w >= 0.0 && top < 64) stack[top++] = int(ch.w + 0.5);\n if (ch.z >= 0.0 && top < 64) stack[top++] = int(ch.z + 0.5);\n if (ch.y >= 0.0 && top < 64) stack[top++] = int(ch.y + 0.5);\n if (ch.x >= 0.0 && top < 64) stack[top++] = int(ch.x + 0.5);\n }\n }\n }\n }\n\n if (uHasLinks > 0.5) {\n vec4 offData = texelFetch(uAdjOffsets, texCoord(nodeId, uAdjOffsetsTexWidth), 0);\n int start = int(offData.x + 0.5);\n int count = int(offData.y + 0.5);\n\n for (int e = 0; e < count; e++) {\n vec4 edgeData = texelFetch(uAdjEdges, texCoord(start + e, uAdjEdgesTexWidth), 0);\n int targetId = int(edgeData.x + 0.5);\n float restDist = edgeData.y;\n float strength = edgeData.z;\n float dirBias = edgeData.w;\n\n vec4 targetState = texelFetch(uState, texCoord(targetId, uTexWidth), 0);\n vec2 delta = (targetState.xy + targetState.zw) - (state.xy + state.zw);\n float d = length(delta);\n\n if (d < 1e-6) {\n delta = vec2(1e-3, 1e-3);\n d = length(delta);\n }\n\n float scale = (d - restDist) / d * uAlpha * strength;\n vel += delta * scale * dirBias;\n }\n }\n\n if (uHasCentering > 0.5) {\n vel += (uCenter - pos) * uCenterStrength * uAlpha;\n }\n\n if (uHasPositioning > 0.5) {\n vel.x += (uForceXTarget - pos.x) * uForceXStrength * uAlpha;\n vel.y += (uForceYTarget - pos.y) * uForceYStrength * uAlpha;\n }\n\n vel *= uDamping;\n pos += vel;\n\n fragColor = vec4(pos, vel);\n}\n",hs.FRAGMENT),n=t.createProgram();if(!n)throw new o("Failed to create program.");if(this._forceProgram=n,t.attachShader(n,e),t.attachShader(n,i),t.linkProgram(n),!t.getProgramParameter(n,t.LINK_STATUS)){const e=t.getProgramInfoLog(n);throw new o(`Failed to link force program: ${e}`)}this._cacheUniformLocations(n),this._quadBuffer=t.createBuffer();const s=new Float32Array([-1,-1,1,-1,-1,1,1,1]);t.bindBuffer(t.ARRAY_BUFFER,this._quadBuffer),t.bufferData(t.ARRAY_BUFFER,s,t.STATIC_DRAW),this._quadVAO=t.createVertexArray(),t.bindVertexArray(this._quadVAO);const r=t.getAttribLocation(n,"aPosition");t.enableVertexAttribArray(r),t.vertexAttribPointer(r,2,t.FLOAT,!1,0,0),t.bindVertexArray(null),this._stateTexA=t.createTexture(),this._stateTexB=t.createTexture(),this._fixedTex=t.createTexture(),this._treeDataTexture=t.createTexture(),this._treeChildrenTexture=t.createTexture(),this._treeGeometryTexture=t.createTexture(),this._adjOffsetsTexture=t.createTexture(),this._adjEdgesTexture=t.createTexture(),this._fboA=t.createFramebuffer(),this._fboB=t.createFramebuffer()}_cacheUniformLocations(t){const e=this._gl,i=["uState","uFixed","uTreeData","uTreeChildren","uTreeGeometry","uAdjOffsets","uAdjEdges","uNodeCount","uTexWidth","uAlpha","uDamping","uManyBodyStrength","uTheta2","uDistanceMin2","uDistanceMax2","uTreeNodeCount","uTreeTexWidth","uAdjOffsetsTexWidth","uAdjEdgesTexWidth","uCenter","uCenterStrength","uCollisionRadius","uCollisionStrength","uForceXTarget","uForceXStrength","uForceYTarget","uForceYStrength","uHasManyBody","uHasLinks","uHasCentering","uHasCollision","uHasPositioning"];for(const n of i)this._uniforms[n]=e.getUniformLocation(t,n)}_uploadDataToGPU(){var t,e,i,n,s,o,r,a;const h=this._gl,l=this._nodes.length;this._texWidth=Math.max(1,Math.ceil(Math.sqrt(l)));const d=this._texWidth*this._texWidth,u=new Float32Array(4*d),c=new Float32Array(4*d);for(let h=0;h0?t.distanceMax:is(null!==(i=null===(e=this._settings.links)||void 0===e?void 0:e.distance)&&void 0!==i?i:50);c.uniform1f(g.uDistanceMax2,s*s),c.uniform1i(g.uTreeNodeCount,this._treeNodeCount),c.uniform1i(g.uTreeTexWidth,this._treeTexWidth)}const m=null!==this._cachedAdjacency&&this._edges.length>0;c.uniform1f(g.uHasLinks,m?1:0),m&&(c.uniform1i(g.uAdjOffsetsTexWidth,this._cachedAdjacency.offsetsTexWidth),c.uniform1i(g.uAdjEdgesTexWidth,this._cachedAdjacency.edgesTexWidth)),c.uniform1f(g.uHasCentering,0);const v=null!==this._settings.collision&&void 0!==this._settings.collision;c.uniform1f(g.uHasCollision,v?1:0),v&&(c.uniform1f(g.uCollisionRadius,this._settings.collision.radius),c.uniform1f(g.uCollisionStrength,this._settings.collision.strength));const y=null!==this._settings.positioning&&void 0!==this._settings.positioning;if(c.uniform1f(g.uHasPositioning,y?1:0),y){const t=this._settings.positioning;c.uniform1f(g.uForceXTarget,null!==(s=null===(n=t.forceX)||void 0===n?void 0:n.x)&&void 0!==s?s:0),c.uniform1f(g.uForceXStrength,null!==(a=null===(r=t.forceX)||void 0===r?void 0:r.strength)&&void 0!==a?a:0),c.uniform1f(g.uForceYTarget,null!==(l=null===(h=t.forceY)||void 0===h?void 0:h.y)&&void 0!==l?l:0),c.uniform1f(g.uForceYStrength,null!==(u=null===(d=t.forceY)||void 0===d?void 0:d.strength)&&void 0!==u?u:0)}const x=this._pingPong?this._stateTexA:this._stateTexB,b=this._pingPong?this._fboB:this._fboA;c.activeTexture(c.TEXTURE0),c.bindTexture(c.TEXTURE_2D,x),c.uniform1i(g.uState,0),c.activeTexture(c.TEXTURE1),c.bindTexture(c.TEXTURE_2D,this._fixedTex),c.uniform1i(g.uFixed,1),c.activeTexture(c.TEXTURE2),c.bindTexture(c.TEXTURE_2D,this._treeDataTexture),c.uniform1i(g.uTreeData,2),c.activeTexture(c.TEXTURE3),c.bindTexture(c.TEXTURE_2D,this._treeChildrenTexture),c.uniform1i(g.uTreeChildren,3),c.activeTexture(c.TEXTURE4),c.bindTexture(c.TEXTURE_2D,this._adjOffsetsTexture),c.uniform1i(g.uAdjOffsets,4),c.activeTexture(c.TEXTURE5),c.bindTexture(c.TEXTURE_2D,this._adjEdgesTexture),c.uniform1i(g.uAdjEdges,5),c.activeTexture(c.TEXTURE6),c.bindTexture(c.TEXTURE_2D,this._treeGeometryTexture),c.uniform1i(g.uTreeGeometry,6),c.bindFramebuffer(c.FRAMEBUFFER,b),c.viewport(0,0,this._texWidth,this._texWidth),c.bindVertexArray(this._quadVAO),c.drawArrays(c.TRIANGLE_STRIP,0,4),c.bindVertexArray(null),c.bindFramebuffer(c.FRAMEBUFFER,null),this._pingPong=!this._pingPong}_readbackFromGPU(){const t=this._gl,e=this._nodes.length;if(0===e)return;const i=this._pingPong?this._fboA:this._fboB,n=this._texWidth*this._texWidth,s=new Float32Array(4*n);t.bindFramebuffer(t.FRAMEBUFFER,i),t.readPixels(0,0,this._texWidth,this._texWidth,t.RGBA,t.FLOAT,s),t.bindFramebuffer(t.FRAMEBUFFER,null);for(let t=0;tt.id)),i=this._nodes.filter(t=>e.has(t.id)),n=t.nodes.filter(t=>void 0===this._nodeIndexByNodeId[t.id]);this._nodes=[...i,...n],this._edges=t.edges,this._rebuildNodeIndex(),this._calculateAndEmit()}deleteData(t){if(t.nodeIds){const e=new Set(t.nodeIds);this._nodes=this._nodes.filter(t=>!e.has(t.id))}if(t.edgeIds){const e=new Set(t.edgeIds);this._edges=this._edges.filter(t=>!e.has(t.id))}this._rebuildNodeIndex(),this._calculateAndEmit()}patchData(t){if(t.nodes)for(let e=0;e0&&this._calculateAndEmit()}terminate(){this._pendingRecalculation=!1,super.terminate()}_calculateAndEmit(){0===this._nodes.length||this._cancelSimulation||(this._isCalculating?this._pendingRecalculation=!0:(this._isCalculating=!0,this.emit(On.SIMULATION_START,void 0),this.calculatePositions(this._nodes,this._edges,t=>{this.emit(On.SIMULATION_PROGRESS,{nodes:this._nodes,edges:this._edges,progress:t})},()=>this._cancelSimulation,()=>{this._isCalculating=!1,this._cancelSimulation||this.emit(On.SIMULATION_END,{nodes:this._nodes,edges:this._edges}),this._cancelSimulation=!1,this._pendingRecalculation&&(this._pendingRecalculation=!1,this._calculateAndEmit())})))}_emitProgress(t,e,i,n){const s=Math.round(100*t/e);return s>i?(n(s/100),s):i}}class cs extends us{constructor(t){super(),this.type="circular",this._config=Object.assign(Object.assign({},es),t)}calculatePositions(t,e,i,n,s){const o=2*Math.PI/t.length;let r=-1,a=0;const h=()=>{if(n())return void s();const e=Math.min(a+5e3,t.length);for(;a{if(n())return void s();const e=Math.min(h+5e3,t.length);for(;h{if(n()||c>=a.length)return!n()&&this._config.reversed&&this._applyReversal(t,h,l),void s();const e=this._assignLevels(a[c],o,r),f=Math.max(...Array.from(e.values()).map(t=>t.length));e.size*this._config.levelGap>l&&(l=e.size*this._config.levelGap);let g=0===c?0:this._config.treeGap+h;c>0&&(g+=(f-1)*this._config.nodeGap/2);for(let i=0;ih&&(h=a),void 0!==r&&(t[r].x="horizontal"===this._config.orientation?n:a,t[r].y="horizontal"===this._config.orientation?a:n),d++}}c++,c0;){const t=h.pop();if(void 0===t)continue;a.push(t);const s=null!==(i=e.get(t))&&void 0!==i?i:[];for(let t=0;t{var e;return 0===(null!==(e=i.get(t))&&void 0!==e?e:0)});void 0===a&&(a=t.reduce((t,e)=>{var n,s;return(null!==(n=i.get(e))&&void 0!==n?n:0)<(null!==(s=i.get(t))&&void 0!==s?s:0)?e:t}));const h=[[a,0]];for(const[t,i]of h){if(r.has(t))continue;r.add(t),o.has(i)?null===(n=o.get(i))||void 0===n||n.push(t):o.set(i,[t]);const a=null!==(s=e.get(t))&&void 0!==s?s:[];for(let t=0;t{this._isSimulationRunning=t})}}var ms,vs;!function(t){t.SetupData="Set Data",t.MergeData="Add Data",t.UpdateData="Update Data",t.DeleteData="Delete Data",t.PatchData="Patch Data",t.ClearData="Clear Data",t.ActivateSimulation="Activate Simulation",t.UpdateSimulation="Update Simulation",t.StopSimulation="Stop Simulation",t.StartDragNode="Start Drag Node",t.DragNode="Drag Node",t.EndDragNode="End Drag Node",t.FixNodes="Fix Nodes",t.ReleaseNodes="Release Nodes",t.SetSettings="Set Settings"}(ms||(ms={})),function(t){t.READY="ready",t.SIMULATION_START="simulation-start",t.SIMULATION_STEP="simulation-step",t.SIMULATION_PROGRESS="simulation-progress",t.SIMULATION_END="simulation-end",t.SIMULATION_TICK="simulation-tick",t.NODE_DRAG="node-drag",t.NODE_DRAG_END="node-drag-end",t.SETTINGS_UPDATE="settings-update"}(vs||(vs={}));class ys extends t{constructor(t){let e;super(),this._isSimulationRunning=!1,this._fallback=null,this._ready=!1,this._pending=[],this._hasWarned=!1,this._handleWorkerMessage=({data:t})=>{switch(t.type){case vs.READY:this._markReady();break;case vs.SIMULATION_START:this.emit(On.SIMULATION_START,void 0),this._isSimulationRunning=!0;break;case vs.SIMULATION_PROGRESS:this.emit(On.SIMULATION_PROGRESS,t.data);break;case vs.SIMULATION_END:this.emit(On.SIMULATION_END,t.data),this._isSimulationRunning=!1;break;case vs.SIMULATION_STEP:this.emit(On.SIMULATION_STEP,t.data);break;case vs.NODE_DRAG:this.emit(On.NODE_DRAG,t.data);break;case vs.NODE_DRAG_END:this.emit(On.NODE_DRAG_END,t.data);break;case vs.SETTINGS_UPDATE:this.emit(On.SETTINGS_UPDATE,t.data)}},this._settings=t;try{this._blobUrl=URL.createObjectURL(new Blob(['"use strict";(()=>{function Ee(n,r){var e,t=1;n==null&&(n=0),r==null&&(r=0);function i(){var o,s=e.length,a,u=0,l=0;for(o=0;o=(_=(a+l)/2))?a=_:l=_,(h=e>=(m=(u+c)/2))?u=m:c=m,i=o,!(o=o[p=h<<1|f]))return i[p]=s,n;if(d=+n._x.call(null,o.data),g=+n._y.call(null,o.data),r===d&&e===g)return s.next=o,i?i[p]=s:n._root=s,n;do i=i?i[p]=new Array(4):n._root=new Array(4),(f=r>=(_=(a+l)/2))?a=_:l=_,(h=e>=(m=(u+c)/2))?u=m:c=m;while((p=h<<1|f)===(y=(g>=m)<<1|d>=_));return i[y]=o,i[p]=s,n}function Be(n){var r,e,t=n.length,i,o,s=new Array(t),a=new Array(t),u=1/0,l=1/0,c=-1/0,_=-1/0;for(e=0;ec&&(c=i),o_&&(_=o));if(u>c||l>_)return this;for(this.cover(u,l).cover(c,_),e=0;en||n>=i||t>r||r>=o;)switch(l=(rc||(a=g.y0)>_||(u=g.x1)=p)<<1|n>=h)&&(g=m[m.length-1],m[m.length-1]=m[m.length-1-f],m[m.length-1-f]=g)}else{var y=n-+this._x.call(null,d.data),T=r-+this._y.call(null,d.data),x=y*y+T*T;if(x=(m=(s+u)/2))?s=m:u=m,(f=_>=(d=(a+l)/2))?a=d:l=d,r=e,!(e=e[h=f<<1|g]))return this;if(!e.length)break;(r[h+1&3]||r[h+2&3]||r[h+3&3])&&(t=r,p=h)}for(;e.data!==n;)if(i=e,!(e=e.next))return this;return(o=e.next)&&delete e.next,i?(o?i.next=o:delete i.next,this):r?(o?r[h]=o:delete r[h],(e=r[0]||r[1]||r[2]||r[3])&&e===(r[3]||r[2]||r[1]||r[0])&&!e.length&&(t?t[p]=e:this._root=e),this):(this._root=o,this)}function He(n){for(var r=0,e=n.length;rm.index){var M=d-D.x-D.vx,v=g-D.y-D.vy,S=M*M+v*v;Sd+b||Eg+b||Pl.r&&(l.r=l[c].r)}function u(){if(r){var l,c=r.length,_;for(e=new Array(c),l=0;l[r(I,E,s),I])),x;for(h=0,a=new Array(p);h{}};function rt(){for(var n=0,r=arguments.length,e={},t;n=0&&(t=e.slice(i+1),e=e.slice(0,i)),e&&!r.hasOwnProperty(e))throw new Error("unknown type: "+e);return{type:e,name:t}})}le.prototype=rt.prototype={constructor:le,on:function(n,r){var e=this._,t=Rt(n+"",e),i,o=-1,s=t.length;if(arguments.length<2){for(;++o0)for(var e=new Array(i),t=0,i,o;t=0&&n._call.call(void 0,r),n=n._next;--J}function st(){Z=(de=oe.now())+ce,J=ie=0;try{ut()}finally{J=0,Gt(),Z=0}}function Ft(){var n=oe.now(),r=n-de;r>at&&(ce-=r,de=n)}function Gt(){for(var n,r=ue,e,t=1/0;r;)r._call?(t>r._time&&(t=r._time),n=r,r=r._next):(e=r._next,r._next=null,r=n?n._next=e:ue=e);ne=n,Le(t)}function Le(n){if(!J){ie&&(ie=clearTimeout(ie));var r=n-Z;r>24?(n<1/0&&(ie=setTimeout(st,n-oe.now()-ce)),te&&(te=clearInterval(te))):(te||(de=oe.now(),te=setInterval(Ft,at)),J=1,lt(st))}}function dt(){let n=1;return()=>(n=(1664525*n+1013904223)%4294967296)/4294967296}function ct(n){return n.x}function ht(n){return n.y}var kt=10,Wt=Math.PI*(3-Math.sqrt(5));function Me(n){var r,e=1,t=.001,i=1-Math.pow(t,1/300),o=0,s=.6,a=new Map,u=he(_),l=Ae("tick","end"),c=dt();n==null&&(n=[]);function _(){m(),l.call("tick",r),e1?(h==null?a.delete(f):a.set(f,g(h)),r):a.get(f)},find:function(f,h,p){var y=0,T=n.length,x,I,E,P,D;for(p==null?p=1/0:p*=p,y=0;y1?(l.on(f,h),r):l.on(f)}}}function Re(){var n,r,e,t,i=O(-30),o,s=1,a=1/0,u=.81;function l(d){var g,f=n.length,h=Q(n,ct,ht).visitAfter(_);for(t=d,g=0;g=a)return;(d.data!==r||d.next)&&(p===0&&(p=k(e),x+=p*p),y===0&&(y=k(e),x+=y*y),xn instanceof Date,pe=n=>Array.isArray(n),me=n=>n!==null&&typeof n=="object"&&n.constructor.name==="Object";var C=n=>fe(n)?Ct(n):pe(n)?Bt(n):me(n)?Kt(n):n,j=(n,r)=>{let e=fe(n),t=fe(r);if(e&&!t||!e&&t)return!1;if(e&&t)return n.getTime()===r.getTime();let i=pe(n),o=pe(r);if(i&&!o||!i&&o)return!1;if(i&&o)return n.length!==r.length?!1:n.every((u,l)=>j(u,r[l]));let s=me(n),a=me(r);if(s&&!a||!s&&a)return!1;if(s&&a){let u=Object.keys(n),l=Object.keys(r);return j(u,l)?u.every(c=>j(n[c],r[c])):!1}return n===r},Ct=n=>new Date(n),Bt=n=>n.map(r=>C(r)),Kt=n=>{let r={};return Object.keys(n).forEach(e=>{r[e]=C(n[e])}),r};var pt={radius:100,centerX:0,centerY:0},zt=100,ft=50,Fe=n=>(n>0?n:1)*zt,ee={useGPU:!1,isSimulatingOnDataUpdate:!0,isSimulatingOnSettingsUpdate:!0,isSimulatingOnUnstick:!0,isPhysicsEnabled:!1,alpha:{alpha:1,alphaMin:.05,alphaDecay:.028,alphaTarget:0},centering:{x:0,y:0,strength:1},collision:{radius:15,strength:1,iterations:1},links:{distance:ft,strength:1,iterations:1},manyBody:{strength:-100,theta:.9,distanceMin:1,distanceMax:Fe(ft)},positioning:{forceX:{x:0,strength:.1},forceY:{y:0,strength:.1}},anchorX:"center",anchorY:"center"},mt={rowGap:50,colGap:50},gt={nodeGap:50,levelGap:50,treeGap:100,orientation:"vertical",reversed:!1};var ge=class{constructor(){this._listeners=new Map}once(r,e){let t={callable:e,isOnce:!0},i=this._listeners.get(r);return i?i.push(t):this._listeners.set(r,[t]),this}on(r,e){let t={callable:e},i=this._listeners.get(r);return i?i.push(t):this._listeners.set(r,[t]),this}off(r,e){let t=this._listeners.get(r);if(t){let i=t.filter(o=>o.callable!==e);this._listeners.set(r,i)}return this}emit(r,e){let t=this._listeners.get(r);if(!t||t.length===0)return!1;let i=!1;for(let o=0;o!s.isOnce);this._listeners.set(r,o)}return!0}eventNames(){return[...this._listeners.keys()]}listenerCount(r){let e=this._listeners.get(r);return e?e.length:0}listeners(r){let e=this._listeners.get(r);return e?e.map(t=>t.callable):[]}addListener(r,e){return this.on(r,e)}removeListener(r,e){return this.off(r,e)}removeAllListeners(r){return r?this._listeners.delete(r):this._listeners.clear(),this}};var Y=class extends ge{constructor(){super(...arguments);this._nodes=[];this._edges=[];this._nodeIndexByNodeId={};this._cancelSimulation=!1;this._schedulerPort=null}terminate(){this._cancelSimulation=!0,this._schedulerPort?.close(),this._schedulerPort=null,this.removeAllListeners()}_scheduleNext(e){if(typeof MessageChannel<"u"){let t=new MessageChannel;this._schedulerPort=t.port2,t.port1.onmessage=()=>{this._schedulerPort=null,e()},t.port2.postMessage(null)}else setTimeout(e,0)}_rebuildNodeIndex(){this._nodeIndexByNodeId={};for(let e=0;e=i)continue;p<1&&(p=1);let y=-n*s/p;g.vx+=f*y,g.vy+=h*y}}}return o.initialize=s=>{t=s},o}var re=class extends Y{constructor(e){super();this._isDragging=!1;this._isStabilizing=!1;this.type="force";this._settings={...ee,...e},this.clearData()}setSettings(e){let t=e;this._initialSettings||(this._initialSettings=Object.assign(C(ee),t));let i=C(this._settings);if(Object.assign(this._settings,t),j(this._settings,i))return;this._applySettingsToSimulation(t),this.emit("settings-update",{settings:{type:"force",options:this._settings}}),i.isPhysicsEnabled&&!t.isPhysicsEnabled?this._simulation.stop():this._settings.isSimulatingOnSettingsUpdate&&this._nodes.length>0&&this.activateSimulation()}setupData(e){this.clearData(),this._initializeNewData(e),this._settings.isSimulatingOnDataUpdate&&(this._updateSimulationData(),this._runSimulation())}mergeData(e){this._initializeNewData(e),this._settings.isPhysicsEnabled||this._pinNodes(),this._settings.isSimulatingOnDataUpdate&&(this._updateSimulationData(),this.activateSimulation())}updateData(e){let t=new Set(e.nodes.map(s=>s.id)),i=this._nodes.filter(s=>t.has(s.id)),o=e.nodes.filter(s=>this._nodeIndexByNodeId[s.id]===void 0);this._nodes=[...i,...o],this._rebuildNodeIndex(),this._edges=e.edges,this._settings.isSimulatingOnSettingsUpdate&&(this._updateSimulationData(),this.activateSimulation())}deleteData(e){if(e.nodeIds){let t=new Set(e.nodeIds);this._nodes=this._nodes.filter(i=>!t.has(i.id))}if(e.edgeIds){let t=new Set(e.edgeIds);this._edges=this._edges.filter(i=>!t.has(i.id))}this._rebuildNodeIndex(),this._settings.isSimulatingOnDataUpdate&&(this._updateSimulationData(),this.activateSimulation())}patchData(e){if(e.nodes){let t={};for(let i=0;i0&&this.activateSimulation()}terminate(){super.terminate(),this._simulation?.stop()}_resetSimulation(){this._simulation&&(this._simulation.stop(),this._simulation.on("tick",null).on("end",null)),this._linkForce=De(this._edges).id(e=>e.id),this._simulation=Me(this._nodes).force("link",this._linkForce).stop(),this._applySettingsToSimulation(this._settings),this._simulation.on("tick",()=>{this.emit("simulation-step",{nodes:this._nodes,edges:this._edges})}),this._simulation.on("end",()=>{this._isDragging=!1,this._isStabilizing=!1,this.emit("simulation-end",{nodes:this._nodes,edges:this._edges}),this._settings.isPhysicsEnabled||this._pinNodes()})}_runSimulation(e){if(this._isStabilizing||this._cancelSimulation)return;(this._settings.isPhysicsEnabled||e?.isUpdatingSettings)&&this._unpinNodes(),this.emit("simulation-start",void 0),this._isStabilizing=!0,this._simulation.alpha(this._settings.alpha.alpha).alphaTarget(this._settings.alpha.alphaTarget).stop();let t=Math.min(jt,Math.ceil(Math.log(this._settings.alpha.alphaMin)/Math.log(1-this._settings.alpha.alphaDecay))),i=-1,o=0,s=()=>{if(this._cancelSimulation){this._isStabilizing=!1,this._cancelSimulation=!1;return}let a=Math.min(o+Xt,t);for(;oi&&(i=u,this.emit("simulation-progress",{nodes:this._nodes,edges:this._edges,progress:u/100}))}othis._edges)):this._simulation.force("edgeMidpointRepulsion",null)}if(e.manyBody===null&&(this._simulation.force("charge",null),this._simulation.force("edgeMidpointRepulsion",null)),e.positioning?.forceX){let t=we(e.positioning.forceX.x).strength(e.positioning.forceX.strength);this._simulation.force("x",t)}if(e.positioning?.forceX===null&&this._simulation.force("x",null),e.positioning?.forceY){let t=Ue(e.positioning.forceY.y).strength(e.positioning.forceY.strength);this._simulation.force("y",t)}if(e.positioning?.forceY===null&&this._simulation.force("y",null),e.centering){let t=Ee(e.centering.x,e.centering.y).strength(e.centering.strength);this._simulation.force("center",t)}e.centering===null&&this._simulation.force("center",null)}};var B=class extends Error{constructor(r){super(r),this.message=r,Object.setPrototypeOf(this,new.target.prototype),this.name=this.constructor.name}};var ke=(n,r,e)=>{let t=n.createShader(e==="vertex"?n.VERTEX_SHADER:n.FRAGMENT_SHADER);if(!t)throw new B("Failed to create shader.");if(n.shaderSource(t,r),n.compileShader(t),!n.getShaderParameter(t,n.COMPILE_STATUS)){let i=n.getShaderInfoLog(t);throw n.deleteShader(t),new B(`Failed to compile shader: ${i}`)}return t};var _t=`#version 300 es\n\nin vec2 aPosition;\n\nvoid main() {\n gl_Position = vec4(aPosition, 0.0, 1.0);\n}\n`;var yt=`#version 300 es\n\nprecision highp float;\n\nuniform sampler2D uState;\nuniform sampler2D uFixed;\nuniform sampler2D uTreeData;\nuniform sampler2D uTreeChildren;\nuniform sampler2D uTreeGeometry;\nuniform sampler2D uAdjOffsets;\nuniform sampler2D uAdjEdges;\n\nuniform int uNodeCount;\nuniform int uTexWidth;\nuniform float uAlpha;\nuniform float uDamping;\n\nuniform float uManyBodyStrength;\nuniform float uTheta2;\nuniform float uDistanceMin2;\nuniform float uDistanceMax2;\nuniform int uTreeNodeCount;\nuniform int uTreeTexWidth;\n\nuniform int uAdjOffsetsTexWidth;\nuniform int uAdjEdgesTexWidth;\n\nuniform vec2 uCenter;\nuniform float uCenterStrength;\n\nuniform float uCollisionRadius;\nuniform float uCollisionStrength;\n\nuniform float uForceXTarget;\nuniform float uForceXStrength;\nuniform float uForceYTarget;\nuniform float uForceYStrength;\n\nuniform float uHasManyBody;\nuniform float uHasLinks;\nuniform float uHasCentering;\nuniform float uHasCollision;\nuniform float uHasPositioning;\n\nout vec4 fragColor;\n\nivec2 texCoord(int idx, int tw) {\n return ivec2(idx % tw, idx / tw);\n}\n\nvoid main() {\n ivec2 fc = ivec2(gl_FragCoord.xy);\n int nodeId = fc.y * uTexWidth + fc.x;\n\n if (nodeId >= uNodeCount) {\n fragColor = vec4(0.0);\n return;\n }\n\n vec4 fixedData = texelFetch(uFixed, fc, 0);\n if (fixedData.x > 0.5) {\n fragColor = vec4(fixedData.yz, 0.0, 0.0);\n return;\n }\n\n vec4 state = texelFetch(uState, fc, 0);\n vec2 pos = state.xy;\n vec2 vel = state.zw;\n\n if (uHasManyBody > 0.5 && uTreeNodeCount > 0) {\n int stack[128];\n int top = 0;\n stack[top++] = 0;\n\n while (top > 0) {\n int idx = stack[--top];\n vec4 data = texelFetch(uTreeData, texCoord(idx, uTreeTexWidth), 0);\n float w = data.w;\n\n if (w < -0.5) {\n int bodyIdx = int(-w - 0.5);\n if (bodyIdx != nodeId) {\n vec2 delta = data.xy - pos;\n float distSq = dot(delta, delta);\n\n if (distSq < 1e-8) {\n delta = vec2(float(nodeId) * 1e-4 - float(bodyIdx) * 1e-4 + 1e-4, 1e-4);\n distSq = dot(delta, delta);\n }\n\n if (distSq < uDistanceMax2) {\n float l = distSq;\n if (l < uDistanceMin2) l = sqrt(uDistanceMin2 * l);\n vel += delta * (data.z * uAlpha / max(l, 1e-6));\n }\n }\n } else {\n vec2 delta = data.xy - pos;\n float distSq = dot(delta, delta);\n\n if (distSq > 0.0 && w * w / distSq < uTheta2) {\n if (distSq < uDistanceMax2) {\n float l = distSq;\n if (l < uDistanceMin2) l = sqrt(uDistanceMin2 * l);\n vel += delta * (data.z * uAlpha / max(l, 1e-6));\n }\n } else {\n vec4 ch = texelFetch(uTreeChildren, texCoord(idx, uTreeTexWidth), 0);\n if (ch.w >= 0.0 && top < 64) stack[top++] = int(ch.w + 0.5);\n if (ch.z >= 0.0 && top < 64) stack[top++] = int(ch.z + 0.5);\n if (ch.y >= 0.0 && top < 64) stack[top++] = int(ch.y + 0.5);\n if (ch.x >= 0.0 && top < 64) stack[top++] = int(ch.x + 0.5);\n }\n }\n }\n }\n\n if (uHasCollision > 0.5 && uCollisionRadius > 0.0 && uTreeNodeCount > 0) {\n float collisionDiam = uCollisionRadius * 2.0;\n vec2 predictedPos = state.xy + state.zw;\n int stack[64];\n int top = 0;\n stack[top++] = 0;\n\n while (top > 0) {\n int idx = stack[--top];\n vec4 data = texelFetch(uTreeData, texCoord(idx, uTreeTexWidth), 0);\n float w = data.w;\n\n if (w < -0.5) {\n int bodyIdx = int(-w - 0.5);\n if (bodyIdx != nodeId && bodyIdx < uNodeCount) {\n vec2 delta = data.xy - predictedPos;\n float dist = length(delta);\n\n if (dist < collisionDiam && dist > 0.0) {\n float push = (collisionDiam - dist) * uCollisionStrength;\n vel -= (delta / dist) * push * 0.5;\n }\n }\n } else {\n vec4 geo = texelFetch(uTreeGeometry, texCoord(idx, uTreeTexWidth), 0);\n float cellSize = geo.z;\n vec2 nearest = clamp(predictedPos, geo.xy, geo.xy + cellSize);\n float distToCell = length(nearest - predictedPos);\n\n if (distToCell < collisionDiam) {\n vec4 ch = texelFetch(uTreeChildren, texCoord(idx, uTreeTexWidth), 0);\n if (ch.w >= 0.0 && top < 64) stack[top++] = int(ch.w + 0.5);\n if (ch.z >= 0.0 && top < 64) stack[top++] = int(ch.z + 0.5);\n if (ch.y >= 0.0 && top < 64) stack[top++] = int(ch.y + 0.5);\n if (ch.x >= 0.0 && top < 64) stack[top++] = int(ch.x + 0.5);\n }\n }\n }\n }\n\n if (uHasLinks > 0.5) {\n vec4 offData = texelFetch(uAdjOffsets, texCoord(nodeId, uAdjOffsetsTexWidth), 0);\n int start = int(offData.x + 0.5);\n int count = int(offData.y + 0.5);\n\n for (int e = 0; e < count; e++) {\n vec4 edgeData = texelFetch(uAdjEdges, texCoord(start + e, uAdjEdgesTexWidth), 0);\n int targetId = int(edgeData.x + 0.5);\n float restDist = edgeData.y;\n float strength = edgeData.z;\n float dirBias = edgeData.w;\n\n vec4 targetState = texelFetch(uState, texCoord(targetId, uTexWidth), 0);\n vec2 delta = (targetState.xy + targetState.zw) - (state.xy + state.zw);\n float d = length(delta);\n\n if (d < 1e-6) {\n delta = vec2(1e-3, 1e-3);\n d = length(delta);\n }\n\n float scale = (d - restDist) / d * uAlpha * strength;\n vel += delta * scale * dirBias;\n }\n }\n\n if (uHasCentering > 0.5) {\n vel += (uCenter - pos) * uCenterStrength * uAlpha;\n }\n\n if (uHasPositioning > 0.5) {\n vel.x += (uForceXTarget - pos.x) * uForceXStrength * uAlpha;\n vel.y += (uForceYTarget - pos.y) * uForceYStrength * uAlpha;\n }\n\n vel *= uDamping;\n pos += vel;\n\n fragColor = vec4(pos, vel);\n}\n`;function It(n,r){let e=n.length;if(e===0)return{treeData:new Float32Array(0),treeChildren:new Float32Array(0),treeGeometry:new Float32Array(0),nodeCount:0,texWidth:1};let t=1/0,i=1/0,o=-1/0,s=-1/0;for(let v=0;vo&&(o=S),A>s&&(s=A)}let a=Math.max(o-t,s-i);a<1e-6&&(a=1),a*=1.01;let u=(t+o)*.5,l=(i+s)*.5,c=a*.5,_=u-c,m=l-c,d=[];function g(v){let S=d.length;return d.push({cx:0,cy:0,charge:0,size:v,bodyIndex:-1,children:[null,null,null,null]}),S}let f=g(a),h=[_],p=[m];function y(v,S,A,K,w){let U=A+w*.5,G=K+w*.5,X=v>=U?1:0;return(S>=G?1:0)*2+X}function T(v,S,A,K){let w=K*.5,U=v&1?S+w:S,G=v&2?A+w:A;return{cx0:U,cy0:G,csz:w}}function x(v,S,A){let K=f,w=_,U=m,G=a;for(let X=0;X<50;X++){let L=d[K];if(L.bodyIndex===-1&&L.children[0]===null&&L.children[1]===null&&L.children[2]===null&&L.children[3]===null){L.bodyIndex=v,L.cx=S,L.cy=A,L.charge=r;return}if(L.bodyIndex>=0){let ve=L.bodyIndex,se=L.cx,ae=L.cy;L.bodyIndex=-1;let W=y(se,ae,w,U,G),{cx0:bt,cy0:Dt,csz:At}=T(W,w,U,G),V=g(At);h[V]=bt,p[V]=Dt,L.children[W]=V,d[V].bodyIndex=ve,d[V].cx=se,d[V].cy=ae,d[V].charge=r}let z=y(S,A,w,U,G);if(L.children[z]===null){let{cx0:ve,cy0:se,csz:ae}=T(z,w,U,G),W=g(ae);h[W]=ve,p[W]=se,L.children[z]=W,d[W].bodyIndex=v,d[W].cx=S,d[W].cy=A,d[W].charge=r;return}let{cx0:vt,cy0:Et,csz:Nt}=T(z,w,U,G);K=L.children[z],w=vt,U=Et,G=Nt}}for(let v=0;v=0)return;let A=0,K=0,w=0,U=0;for(let G=0;G<4;G++){let X=S.children[G];if(X===null)continue;I(X);let L=d[X],z=Math.abs(L.charge);A+=L.charge,K+=L.cx*z,w+=L.cy*z,U+=z}U>0&&(S.cx=K/U,S.cy=w/U),S.charge=A}I(f);let E=d.length,P=Math.ceil(Math.sqrt(E)),D=P*P,N=new Float32Array(D*4),b=new Float32Array(D*4),M=new Float32Array(D*4);for(let v=0;v=0?N[A+3]=-(S.bodyIndex+1):N[A+3]=S.size,b[A]=S.children[0]!==null?S.children[0]:-1,b[A+1]=S.children[1]!==null?S.children[1]:-1,b[A+2]=S.children[2]!==null?S.children[2]:-1,b[A+3]=S.children[3]!==null?S.children[3]:-1,M[A]=h[v]??0,M[A+1]=p[v]??0,M[A+2]=S.size,M[A+3]=0}for(let v=E;v0&&this.activateSimulation()}setupData(e){this.clearData(),this._initializeNewData(e),this._settings.isSimulatingOnDataUpdate&&this._runSimulation()}mergeData(e){this._initializeNewData(e),this._settings.isPhysicsEnabled||this._pinNodes(),this._settings.isSimulatingOnDataUpdate&&this.activateSimulation()}updateData(e){let t=new Set(e.nodes.map(s=>s.id)),i=this._nodes.filter(s=>t.has(s.id)),o=e.nodes.filter(s=>this._nodeIndexByNodeId[s.id]===void 0);this._nodes=[...i,...o],this._rebuildNodeIndex(),this._edges=e.edges,this._cachedAdjacency=null,this._settings.isSimulatingOnSettingsUpdate&&this.activateSimulation()}deleteData(e){if(e.nodeIds){let t=new Set(e.nodeIds);this._nodes=this._nodes.filter(i=>!t.has(i.id))}if(e.edgeIds){let t=new Set(e.edgeIds);this._edges=this._edges.filter(i=>!t.has(i.id))}this._rebuildNodeIndex(),this._cachedAdjacency=null,this._settings.isSimulatingOnDataUpdate&&this.activateSimulation()}patchData(e){if(e.nodes){let t={};for(let i=0;i0&&this.activateSimulation()}terminate(){super.terminate();let e=this._gl;e&&(e.deleteBuffer(this._quadBuffer),e.deleteVertexArray(this._quadVAO),e.deleteProgram(this._forceProgram),e.deleteTexture(this._stateTexA),e.deleteTexture(this._stateTexB),e.deleteTexture(this._fixedTex),e.deleteTexture(this._treeDataTexture),e.deleteTexture(this._treeChildrenTexture),e.deleteTexture(this._treeGeometryTexture),e.deleteTexture(this._adjOffsetsTexture),e.deleteTexture(this._adjEdgesTexture),e.deleteFramebuffer(this._fboA),e.deleteFramebuffer(this._fboB),e.getExtension("WEBGL_lose_context")?.loseContext())}reheat(){let e=this._settings.alpha;this._currentAlpha=e.alpha,this._totalSteps=Math.min(St,Math.ceil(Math.log(e.alphaMin)/Math.log(1-e.alphaDecay))),this._currentStep=0,!this._isStabilizing&&(this._ensurePositions(),this._uploadDataToGPU(),this._cachedAdjacency||this._buildAndUploadAdjacency(),this._startSimulationLoop())}_runSimulation(){this._isStabilizing||this._cancelSimulation||(this._ensurePositions(),this._uploadDataToGPU(),this._buildAndUploadAdjacency(),this._startSimulationLoop())}_startDragLoop(){if(this._dragLoopRunning)return;this._dragLoopRunning=!0;let e=this._settings.alpha.alphaDecay,t=this._settings.alpha.alphaMin;this._dragAlpha=.3,this._dragNeedsReheat=!1;let i=()=>{if(!this._isDragging){this._dragLoopRunning=!1;return}if(this._dragNeedsReheat&&(this._dragAlpha=.3,this._dragNeedsReheat=!1),this._dragAlpha+=(0-this._dragAlpha)*e,this._dragAlpha{if(e!==this._simulationGeneration)return;if(this._cancelSimulation){this._isStabilizing=!1,this._cancelSimulation=!1,this.emit("simulation-end",{nodes:this._nodes,edges:this._edges});return}if(this._readbackFromGPU(),this._pendingRestart){this._isStabilizing=!1,this._pendingRestart=!1,this._ensurePositions(),this._uploadDataToGPU(),this._cachedAdjacency||this._buildAndUploadAdjacency(),this._startSimulationLoop();return}this._flushDirtyNodes(),this._buildAndUploadQuadTree();let u=Math.min(this._currentStep+Ht,this._totalSteps);for(;this._currentSteps&&(s=l,this.emit("simulation-progress",{nodes:this._nodes,edges:this._edges,progress:l/100})),this._currentStep0&&(i=i.concat(s))}let o=It(i,t);this._uploadTexture(this._treeDataTexture,o.treeData,o.texWidth),this._uploadTexture(this._treeChildrenTexture,o.treeChildren,o.texWidth),this._uploadTexture(this._treeGeometryTexture,o.treeGeometry,o.texWidth),this._treeTexWidth=o.texWidth,this._treeNodeCount=o.nodeCount}_getEdgeMidpoints(){let e=[];for(let t=0;t0?d.distanceMax:Fe(this._settings.links?.distance??50);t.uniform1f(s.uDistanceMax2,f*f),t.uniform1i(s.uTreeNodeCount,this._treeNodeCount),t.uniform1i(s.uTreeTexWidth,this._treeTexWidth)}let u=this._cachedAdjacency!==null&&this._edges.length>0;t.uniform1f(s.uHasLinks,u?1:0),u&&(t.uniform1i(s.uAdjOffsetsTexWidth,this._cachedAdjacency.offsetsTexWidth),t.uniform1i(s.uAdjEdgesTexWidth,this._cachedAdjacency.edgesTexWidth)),t.uniform1f(s.uHasCentering,0);let l=this._settings.collision!==null&&this._settings.collision!==void 0;t.uniform1f(s.uHasCollision,l?1:0),l&&(t.uniform1f(s.uCollisionRadius,this._settings.collision.radius),t.uniform1f(s.uCollisionStrength,this._settings.collision.strength));let c=this._settings.positioning!==null&&this._settings.positioning!==void 0;if(t.uniform1f(s.uHasPositioning,c?1:0),c){let d=this._settings.positioning;t.uniform1f(s.uForceXTarget,d.forceX?.x??0),t.uniform1f(s.uForceXStrength,d.forceX?.strength??0),t.uniform1f(s.uForceYTarget,d.forceY?.y??0),t.uniform1f(s.uForceYStrength,d.forceY?.strength??0)}let _=this._pingPong?this._stateTexA:this._stateTexB,m=this._pingPong?this._fboB:this._fboA;t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,_),t.uniform1i(s.uState,0),t.activeTexture(t.TEXTURE1),t.bindTexture(t.TEXTURE_2D,this._fixedTex),t.uniform1i(s.uFixed,1),t.activeTexture(t.TEXTURE2),t.bindTexture(t.TEXTURE_2D,this._treeDataTexture),t.uniform1i(s.uTreeData,2),t.activeTexture(t.TEXTURE3),t.bindTexture(t.TEXTURE_2D,this._treeChildrenTexture),t.uniform1i(s.uTreeChildren,3),t.activeTexture(t.TEXTURE4),t.bindTexture(t.TEXTURE_2D,this._adjOffsetsTexture),t.uniform1i(s.uAdjOffsets,4),t.activeTexture(t.TEXTURE5),t.bindTexture(t.TEXTURE_2D,this._adjEdgesTexture),t.uniform1i(s.uAdjEdges,5),t.activeTexture(t.TEXTURE6),t.bindTexture(t.TEXTURE_2D,this._treeGeometryTexture),t.uniform1i(s.uTreeGeometry,6),t.bindFramebuffer(t.FRAMEBUFFER,m),t.viewport(0,0,this._texWidth,this._texWidth),t.bindVertexArray(this._quadVAO),t.drawArrays(t.TRIANGLE_STRIP,0,4),t.bindVertexArray(null),t.bindFramebuffer(t.FRAMEBUFFER,null),this._pingPong=!this._pingPong}_readbackFromGPU(){let e=this._gl,t=this._nodes.length;if(t===0)return;let i=this._pingPong?this._fboA:this._fboB,o=this._texWidth*this._texWidth,s=new Float32Array(o*4);e.bindFramebuffer(e.FRAMEBUFFER,i),e.readPixels(0,0,this._texWidth,this._texWidth,e.RGBA,e.FLOAT,s),e.bindFramebuffer(e.FRAMEBUFFER,null);for(let a=0;as.id)),i=this._nodes.filter(s=>t.has(s.id)),o=e.nodes.filter(s=>this._nodeIndexByNodeId[s.id]===void 0);this._nodes=[...i,...o],this._edges=e.edges,this._rebuildNodeIndex(),this._calculateAndEmit()}deleteData(e){if(e.nodeIds){let t=new Set(e.nodeIds);this._nodes=this._nodes.filter(i=>!t.has(i.id))}if(e.edgeIds){let t=new Set(e.edgeIds);this._edges=this._edges.filter(i=>!t.has(i.id))}this._rebuildNodeIndex(),this._calculateAndEmit()}patchData(e){if(e.nodes)for(let t=0;t0&&this._calculateAndEmit()}terminate(){this._pendingRecalculation=!1,super.terminate()}_calculateAndEmit(){if(!(this._nodes.length===0||this._cancelSimulation)){if(this._isCalculating){this._pendingRecalculation=!0;return}this._isCalculating=!0,this.emit("simulation-start",void 0),this.calculatePositions(this._nodes,this._edges,e=>{this.emit("simulation-progress",{nodes:this._nodes,edges:this._edges,progress:e})},()=>this._cancelSimulation,()=>{this._isCalculating=!1,this._cancelSimulation||this.emit("simulation-end",{nodes:this._nodes,edges:this._edges}),this._cancelSimulation=!1,this._pendingRecalculation&&(this._pendingRecalculation=!1,this._calculateAndEmit())})}}_emitProgress(e,t,i,o){let s=Math.round(e*100/t);return s>i?(o(s/100),s):i}};var Ie=class extends H{constructor(e){super();this.type="circular";this._config={...pt,...e}}calculatePositions(e,t,i,o,s){let a=2*Math.PI/e.length,u=-1,l=0,c=()=>{if(o()){s();return}let _=Math.min(l+ye,e.length);for(;l<_;l++)e[l].x=this._config.centerX+this._config.radius*Math.cos(a*l),e[l].y=this._config.centerY+this._config.radius*Math.sin(a*l);l{if(o()){s();return}let m=Math.min(c+ye,e.length);for(;c{if(o()||g>=l.length){!o()&&this._config.reversed&&this._applyReversal(e,c,_),s();return}let h=this._assignLevels(l[g],a,u),p=Math.max(...Array.from(h.values()).map(T=>T.length));h.size*this._config.levelGap>_&&(_=h.size*this._config.levelGap);let y=g===0?0:this._config.treeGap+c;g>0&&(y+=(p-1)*this._config.nodeGap/2);for(let T=0;Tc&&(c=b),N!==void 0&&(e[N].x=this._config.orientation==="horizontal"?x:b,e[N].y=this._config.orientation==="horizontal"?b:x),m++}}g++,g0;){let c=l.pop();if(c===void 0)continue;u.push(c);let _=t.get(c)??[];for(let m=0;m<_.length;m++)i.has(_[m])||(i.add(_[m]),l.push(_[m]))}o.push(u)}return o}_assignLevels(e,t,i){let o=new Map,s=new Set,a=e.find(l=>(i.get(l)??0)===0);a===void 0&&(a=e.reduce((l,c)=>(i.get(c)??0)<(i.get(l)??0)?c:l));let u=[[a,0]];for(let[l,c]of u){if(s.has(l))continue;s.add(l),o.has(c)?o.get(c)?.push(l):o.set(c,[l]);let _=t.get(l)??[];for(let m=0;m<_.length;m++)u.push([_[m],c+1])}return o}_getEdgeEndpointId(e){return typeof e=="object"?e.id:e}};var Te=class{static create(r){switch(r?.type){case"circular":return new Ie(r.options);case"grid":return new xe(r.options);case"hierarchical":return new Se(r.options);default:{let e=r?.options;if(e?.useGPU)try{return new _e(e)}catch{return console.warn("WebGL2 unavailable, falling back to CPU force layout engine."),new re(e)}return new re(e)}}}};function Tt(n,r){switch(r.type){case"Set Data":n.setupData(r.data);break;case"Add Data":n.mergeData(r.data);break;case"Update Data":n.updateData(r.data);break;case"Delete Data":n.deleteData(r.data);break;case"Patch Data":n.patchData(r.data);break;case"Clear Data":n.clearData();break;case"Activate Simulation":n.activateSimulation();break;case"Stop Simulation":n.stopSimulation();break;case"Start Drag Node":n.startDragNode();break;case"Drag Node":n.dragNode(r.data.id,{x:r.data.x,y:r.data.y});break;case"End Drag Node":n.endDragNode(r.data.id);break;case"Fix Nodes":n.fixNodes(r.data.nodes);break;case"Release Nodes":n.releaseNodes(r.data.nodes);break;default:break}}var q=null,$=n=>postMessage(n);function Vt(n){n.on("simulation-start",()=>$({type:"simulation-start"})),n.on("simulation-progress",r=>$({type:"simulation-progress",data:r})),n.on("simulation-end",r=>$({type:"simulation-end",data:r})),n.on("simulation-step",r=>$({type:"simulation-step",data:r})),n.on("node-drag",r=>$({type:"node-drag",data:r})),n.on("settings-update",r=>$({type:"settings-update",data:r}))}$({type:"ready"});addEventListener("message",({data:n})=>{if(n.type==="Set Settings"){let r=n.data;if(r.type===q?.type&&r.options){q?.setSettings(r.options);return}q?.removeAllListeners(),q?.terminate(),q=Te.create(r),Vt(q);return}q&&Tt(q,n)});})();\n'],{type:"text/javascript"})),e=new Worker(this._blobUrl)}catch(t){return void this._activateFallback(t)}this._worker=e,e.onerror=t=>{this._ready?this._warnWorkerError(t):this._activateFallback(t)},e.onmessage=this._handleWorkerMessage,this._readyTimer=setTimeout(()=>{this._ready||this._fallback||this._activateFallback(new Error("Web Worker readiness handshake timed out."))},3e3),this.emitToWorker({type:ms.SetSettings,data:t})}setupData(t){this.emitToWorker({type:ms.SetupData,data:t})}mergeData(t){this.emitToWorker({type:ms.MergeData,data:t})}updateData(t){this.emitToWorker({type:ms.UpdateData,data:t})}deleteData(t){this.emitToWorker({type:ms.DeleteData,data:t})}patchData(t){this.emitToWorker({type:ms.PatchData,data:t})}clearData(){this.emitToWorker({type:ms.ClearData})}activateSimulation(){this.emitToWorker({type:ms.ActivateSimulation})}stopSimulation(){this.emitToWorker({type:ms.StopSimulation})}updateSimulation(t,e){this.emitToWorker({type:ms.UpdateSimulation,data:{nodes:t,edges:e}})}startDragNode(){this.emitToWorker({type:ms.StartDragNode})}dragNode(t,e){this.emitToWorker({type:ms.DragNode,data:Object.assign({id:t},e)})}endDragNode(t){this.emitToWorker({type:ms.EndDragNode,data:{id:t}})}fixNodes(t){this.emitToWorker({type:ms.FixNodes,data:{nodes:t}})}releaseNodes(t){this.emitToWorker({type:ms.ReleaseNodes,data:{nodes:t}})}setSettings(t){this.emitToWorker({type:ms.SetSettings,data:t})}isSimulationRunning(){return this._fallback?this._fallback.isSimulationRunning():this._isSimulationRunning}terminate(){var t;void 0!==this._readyTimer&&(clearTimeout(this._readyTimer),this._readyTimer=void 0),this._revokeBlobUrl(),this._worker&&(this._worker.onmessage=null,this._worker.onerror=null,this._worker.terminate(),this._worker=void 0),null===(t=this._fallback)||void 0===t||t.terminate(),this.removeAllListeners()}emitToWorker(t){var e;this._fallback?this._applyToFallback(this._fallback,t):(this._ready||this._pending.push(t),null===(e=this._worker)||void 0===e||e.postMessage(t))}_markReady(){this._ready||(this._ready=!0,this._pending=[],void 0!==this._readyTimer&&(clearTimeout(this._readyTimer),this._readyTimer=void 0),this._revokeBlobUrl())}_activateFallback(t){if(this._fallback)return;if(this._warnFallback(t),void 0!==this._readyTimer&&(clearTimeout(this._readyTimer),this._readyTimer=void 0),this._worker){this._worker.onmessage=null,this._worker.onerror=null;try{this._worker.terminate()}catch(t){}this._worker=void 0}this._revokeBlobUrl();const e=new ps(this._settings);this._wireFallbackEvents(e),this._fallback=e;const i=this._pending;this._pending=[];for(const t of i)this._applyToFallback(e,t)}_wireFallbackEvents(t){kn(t,this,t=>{this._isSimulationRunning=t})}_applyToFallback(t,e){e.type!==ms.SetSettings?function(t,e){switch(e.type){case ms.SetupData:t.setupData(e.data);break;case ms.MergeData:t.mergeData(e.data);break;case ms.UpdateData:t.updateData(e.data);break;case ms.DeleteData:t.deleteData(e.data);break;case ms.PatchData:t.patchData(e.data);break;case ms.ClearData:t.clearData();break;case ms.ActivateSimulation:t.activateSimulation();break;case ms.StopSimulation:t.stopSimulation();break;case ms.StartDragNode:t.startDragNode();break;case ms.DragNode:t.dragNode(e.data.id,{x:e.data.x,y:e.data.y});break;case ms.EndDragNode:t.endDragNode(e.data.id);break;case ms.FixNodes:t.fixNodes(e.data.nodes);break;case ms.ReleaseNodes:t.releaseNodes(e.data.nodes)}}(t,e):t.setSettings(e.data)}_revokeBlobUrl(){this._blobUrl&&(URL.revokeObjectURL(this._blobUrl),this._blobUrl=void 0)}_warnWorkerError(t){this._hasWarned||(this._hasWarned=!0,console.warn("Orb: the layout Web Worker errored after it had started. The current layout is kept and no further updates will be simulated; reload the graph to recover.",t))}_warnFallback(t){this._hasWarned||(this._hasWarned=!0,console.warn("Orb: the layout Web Worker could not start; falling back to the main-thread simulator. Layout is still correct but runs on the main thread. Under a strict Content Security Policy, allow blob workers (e.g. `worker-src blob:` or `child-src blob:`) to re-enable off-main-thread layout.",t))}}class xs{static getSimulator(t){const e=Object.assign({type:"force"},t),i=e.options;if("force"===e.type&&(null==i?void 0:i.useGPU))return new ps(e);try{if("undefined"!=typeof Worker)return new ys(e);throw new Error("WebWorkers are unavailable in your environment.")}catch(t){return console.error("Could not create simulator in a WebWorker context. All calculations will be done in the main thread.",t),new ps(e)}}}const bs=t=>{const e=t.start,i=t.end;return e{if(!this.sortBy)return 0;const i=this.getOne(t),n=this.getOne(e);return void 0===i||void 0===n?0:this.sortBy(i,n)})}get size(){return this.entityById.size}}const ws=(...t)=>{const e=t.reduce((t,e)=>t.concat(e),[]);return Array.from(new Set(e))};class Ts extends d{constructor(t,e){var i,n;super(),this._nodes=new Ss({getId:t=>t.getId(),sortBy:(t,e)=>{var i,n;return(null!==(i=t.getStyle().zIndex)&&void 0!==i?i:0)-(null!==(n=e.getStyle().zIndex)&&void 0!==n?n:0)}}),this._edges=new Ss({getId:t=>t.getId(),sortBy:(t,e)=>{var i,n;return(null!==(i=t.getStyle().zIndex)&&void 0!==i?i:0)-(null!==(n=e.getStyle().zIndex)&&void 0!==n?n:0)}}),this._styleVersion=0,this._bumpStyleVersion=()=>{this._styleVersion++},this._update=t=>{if(t&&"type"in t&&"options"in t&&"isSingle"in t.options){if("node"===t.type&&t.options.isSingle){const e=this._nodes.getAll();for(let i=0;it.isSelected())}getSelectedEdges(){return this.getEdges(t=>t.isSelected())}getHoveredNodes(){return this.getNodes(t=>t.isHovered())}getHoveredEdges(){return this.getEdges(t=>t.isHovered())}getNodePositions(t){const e=this.getNodes(t),i=new Array(e.length);for(let t=0;tt.id),e=this._edges.getAll().map(t=>t.id);this.remove({nodeIds:t,edgeIds:e})}removeAllEdges(){const t=this._edges.getAll().map(t=>t.id);this.remove({edgeIds:t})}removeAllNodes(){this.removeAll()}isEqual(t){if(this.getNodeCount()!==t.getNodeCount())return!1;if(this.getEdgeCount()!==t.getEdgeCount())return!1;const e=this.getNodes();for(let i=0;ii.x&&(i.x=s+r),s-ri.y&&(i.y=o+r),o-r=0;i--)if(e[i].includesPoint(t))return e[i]}getNearestEdge(t,e=3){let i,n=e;const s=this.getEdges();for(let e=0;e{const n=i.getPosition();if(void 0===n.x||void 0===n.y)return!1;const s={x:n.x,y:n.y};return a(e,s)&&t.contains(s)})}getStyleVersion(){return this._styleVersion}_insertNodes(t){const e=new Array(t.length);for(let i=0;i{var t,e;return null===(e=null===(t=this._settings)||void 0===t?void 0:t.onLoadedImages)||void 0===e?void 0:e.call(t)},listeners:[this._update],onStateChange:this._bumpStyleVersion});this._nodes.setMany(e)}_insertEdges(t){const e=[];for(let i=0;i{var t,e;return null===(e=null===(t=this._settings)||void 0===t?void 0:t.onLoadedImages)||void 0===e?void 0:e.call(t)},listeners:[this._update],onStateChange:this._bumpStyleVersion}))}this._nodes.setMany(e)}_upsertEdges(t){const e=[],i=[];for(let n=0;n{var e;const i=new Array(t.length),n=(t=>{var e;const i={},n=new Set;for(let s=0;se+1);continue}if(r<=1)continue;const a=[];r%2!=0&&a.push(0);for(let t=2;t<=r;t+=2)a.push(t/2),a.push(t/2*-1);s[e]=a}return s})(t);for(let s=0;s{var t,e;null===(e=null===(t=this._settings)||void 0===t?void 0:t.onLoadedImages)||void 0===e||e.call(t)}),this._nodes.sort(),this._edges.sort()}}const Es=(t,e)=>{var i;null===(i=null==e?void 0:e.cascade)||void 0===i||i?Rs(t,r.SELECTED,{isStateOverride:!0}):t.setState(r.SELECTED,{isNotifySkipped:!0})},Ps=(t,e)=>{var i;null===(i=null==e?void 0:e.cascade)||void 0===i||i?Os(t,r.SELECTED,{isStateOverride:!0}):t.setState(r.SELECTED,{isNotifySkipped:!0})},As=(t,e)=>{var i;null===(i=null==e?void 0:e.cascade)||void 0===i||i?Rs(t,r.NONE,{isStateOverride:!0}):t.clearState()},Cs=(t,e)=>{var i;null===(i=null==e?void 0:e.cascade)||void 0===i||i?Os(t,r.NONE,{isStateOverride:!0}):t.clearState()},Ms=(t,e,i)=>{Ds(t),Es(e,i)},Ns=(t,e,i)=>{Ds(t),Ps(e,i)},Ds=t=>{const e=t.getNodes(t=>t.isSelected());for(let t=0;tt.isSelected());for(let t=0;t{Rs(t,r.HOVERED)},Ls=t=>{const e=t.getNodes(t=>t.isHovered());for(let t=0;tt.isHovered());for(let t=0;t{ks(t,i)&&t.setState(e,{isNotifySkipped:!0}),t.getInEdges().forEach(t=>{t&&ks(t,i)&&t.setState(e,{isNotifySkipped:!0}),t.startNode&&ks(t.startNode,i)&&t.startNode.setState(e,{isNotifySkipped:!0})}),t.getOutEdges().forEach(t=>{t&&ks(t,i)&&t.setState(e,{isNotifySkipped:!0}),t.endNode&&ks(t.endNode,i)&&t.endNode.setState(e,{isNotifySkipped:!0})})},Os=(t,e,i)=>{ks(t,i)&&t.setState(e,{isNotifySkipped:!0}),t.startNode&&ks(t.startNode,i)&&t.startNode.setState(e,{isNotifySkipped:!0}),t.endNode&&ks(t.endNode,i)&&t.endNode.setState(e,{isNotifySkipped:!0})},ks=(t,e)=>{const i=null==e?void 0:e.isStateOverride;return i||!i&&!t.getState()};class Bs{constructor(t){this.isSelectEnabled=t.isDefaultSelectEnabled,this.isHoverEnabled=t.isDefaultHoverEnabled,this.isMultiSelectEnabled=t.isDefaultMultiSelectEnabled,this.isSelectCascadeEnabled=t.isDefaultSelectCascadeEnabled}onMouseClick(t,e,i){var n;const s=this.isMultiSelectEnabled&&null!==(n=null==i?void 0:i.isAppend)&&void 0!==n&&n,o=t.getNearestNode(e);if(o)return this.isSelectEnabled&&(s?(t=>{t.isSelected()?As(t,{cascade:!1}):Es(t,{cascade:!1})})(o):Ms(t,o,{cascade:this.isSelectCascadeEnabled})),{isStateChanged:!0,changedSubject:o};const r=t.getNearestEdge(e);if(r)return this.isSelectEnabled&&(s?(t=>{t.isSelected()?Cs(t,{cascade:!1}):Ps(t,{cascade:!1})})(r):Ns(t,r,{cascade:this.isSelectCascadeEnabled})),{isStateChanged:!0,changedSubject:r};if(!this.isSelectEnabled||s)return{isStateChanged:!1};const{changedCount:a}=Ds(t);return{isStateChanged:a>0}}onMouseMove(t,e){const i=t.getNearestNode(e);if(i&&(!this.isSelectEnabled||this.isSelectEnabled&&!i.isSelected()))return i===this._lastHoveredNode?{changedSubject:i,isStateChanged:!1}:(this.isHoverEnabled&&((t,e)=>{Ls(t),Is(e)})(t,i),this._lastHoveredNode=i,{isStateChanged:!0,changedSubject:i});if(this._lastHoveredNode=void 0,!i&&this.isHoverEnabled){const{changedCount:e}=Ls(t);return{isStateChanged:e>0}}return{isStateChanged:!1}}onMouseRightClick(t,e){const i=t.getNearestNode(e);if(i)return this.isSelectEnabled&&Ms(t,i,{cascade:this.isSelectCascadeEnabled}),{isStateChanged:!0,changedSubject:i};const n=t.getNearestEdge(e);if(n)return this.isSelectEnabled&&Ns(t,n,{cascade:this.isSelectCascadeEnabled}),{isStateChanged:!0,changedSubject:n};if(!this.isSelectEnabled)return{isStateChanged:!1};const{changedCount:s}=Ds(t);return{isStateChanged:s>0}}onMouseDoubleClick(t,e){const i=t.getNearestNode(e);if(i)return this.isSelectEnabled&&Ms(t,i,{cascade:this.isSelectCascadeEnabled}),{isStateChanged:!0,changedSubject:i};const n=t.getNearestEdge(e);if(n)return this.isSelectEnabled&&Ns(t,n,{cascade:this.isSelectCascadeEnabled}),{isStateChanged:!0,changedSubject:n};if(!this.isSelectEnabled)return{isStateChanged:!1};const{changedCount:s}=Ds(t);return{isStateChanged:s>0}}}var zs,Us;!function(t){t.CANVAS="canvas",t.WEBGL="webgl"}(zs||(zs={})),function(t){t.RESIZE="resize",t.RENDER_START="render-start",t.RENDER_END="render-end"}(Us||(Us={}));const Fs={devicePixelRatio:null,fps:60,minZoom:.25,maxZoom:8,fitZoomMargin:.2,labelsIsEnabled:!0,labelsOnEventIsEnabled:!0,shadowIsEnabled:!0,shadowOnEventIsEnabled:!0,contextAlphaOnEvent:.3,contextAlphaOnEventIsEnabled:!0,backgroundColor:null,areCollapsedContainerDimensionsAllowed:!1},js="Roboto, sans-serif";var Ws;!function(t){t.TOP="top",t.MIDDLE="middle"}(Ws||(Ws={}));class Gs{constructor(t,e){var i,n;this.textLines=[],this.fontSize=4,this.fontFamily=qs(4,js),this.text=`${void 0===t?"":t}`,this.textLines=Vs(this.text),this.position=e.position,this.properties=e.properties,this.textBaseline=e.textBaseline,(void 0!==this.properties.fontSize||this.properties.fontFamily)&&(this.fontSize=Math.max(null!==(i=this.properties.fontSize)&&void 0!==i?i:0,0),this.fontFamily=qs(this.fontSize,null!==(n=this.properties.fontFamily)&&void 0!==n?n:js)),this._fixPosition()}_fixPosition(){if(this.textBaseline===Ws.MIDDLE&&this.textLines.length){const t=Math.floor(this.textLines.length/2),e=(this.textLines.length-1)/2;this.position.y-=e*this.fontSize-t*(1.2-1)}}}const Zs=(t,e)=>{e.textLines.length>0&&e.fontSize>0&&e.position&&(Hs(t,e),Xs(t,e))},Hs=(t,e)=>{if(!e.properties.fontBackgroundColor||!e.position)return;t.fillStyle=e.properties.fontBackgroundColor.toString();const i=.12*e.fontSize,n=e.fontSize+2*i,s=1.2*e.fontSize,o=e.textBaseline===Ws.MIDDLE?e.fontSize/2:0;for(let r=0;r{var i;if(!e.position)return;t.fillStyle=(null!==(i=e.properties.fontColor)&&void 0!==i?i:"#000000").toString(),t.font=e.fontFamily,t.textBaseline=e.textBaseline,t.textAlign="center";const n=1.2*e.fontSize;for(let i=0;i`${t}px ${e}`,Vs=t=>{const e=t.split("\n"),i=[];for(let t=0;t{var e,i;const n=null!==(e=t.getStyle().arrowSize)&&void 0!==e?e:1,s=null!==(i=t.getWidth())&&void 0!==i?i:1,o=t.endNode,r=t.getCurvedControlPoint(),a=Ks(t,o),h=$s(t,Math.max(0,Math.min(1,a.t+-.1)),r),l=Math.atan2(a.y-h.y,a.x-h.x),d=1.5*n+3*s;return{point:a,core:{x:a.x-.9*d*Math.cos(l),y:a.y-.9*d*Math.sin(l)},angle:l,length:d}},$s=(t,e,i)=>{const n=t.startNode.getCenter(),s=t.endNode.getCenter();if(!n||!s)return{x:0,y:0};const o=e;return{x:Math.pow(1-o,2)*n.x+2*o*(1-o)*i.x+Math.pow(o,2)*s.x,y:Math.pow(1-o,2)*n.y+2*o*(1-o)*i.y+Math.pow(o,2)*s.y}},Ks=(t,e)=>{let i,n,s,o=0,r=0,a=1,h={x:0,y:0,t:0};const l=t.getCurvedControlPoint();let d=t.endNode,u=!1;e.getId()===t.startNode.getId()&&(d=t.startNode,u=!0);const c=d.getCenter();let _;for(;r<=a&&o<10&&(_=.5*(r+a),h=Object.assign(Object.assign({},$s(t,_,l)),{t:0}),i=d.getDistanceToBorder(),n=Math.sqrt(Math.pow(h.x-c.x,2)+Math.pow(h.y-c.y,2)),s=i-n,!(Math.abs(s)<.2));)s<0?!1===u?r=_:a=_:!1===u?a=_:r=_,o++;return h.t=null!=_?_:0,h},Qs=t=>{var e,i;const n=null!==(e=t.getStyle().arrowSize)&&void 0!==e?e:1,s=null!==(i=t.getWidth())&&void 0!==i?i:1,o=t.startNode,r=to(t,o),a=-2*r.t*Math.PI+.45*Math.PI,h=1.5*n+3*s;return{point:r,core:{x:r.x-.9*h*Math.cos(a),y:r.y-.9*h*Math.sin(a)},angle:a,length:h}},Js=(t,e)=>{const i=2*e*Math.PI;return{x:t.x+t.radius*Math.cos(i),y:t.y-t.radius*Math.sin(i)}},to=(t,e)=>{const i=t.getCircularData();let n=.6,s=1;let o,r,a,h=0,l={x:0,y:0,t:0},d=.5*(n+s);const u=e.getCenter();for(;n<=s&&h<10&&(d=.5*(n+s),l=Object.assign(Object.assign({},Js(i,d)),{t:0}),o=e.getDistanceToBorder(),r=Math.sqrt(Math.pow(l.x-u.x,2)+Math.pow(l.y-u.y,2)),a=o-r,!(Math.abs(a)<.05));)a>0?n=d:s=d,h++;return l.t=null!=d?d:0,l},eo=t=>{var e,i;const n=null!==(e=t.getStyle().arrowSize)&&void 0!==e?e:1,s=null!==(i=t.getWidth())&&void 0!==i?i:1,o=t.startNode.getCenter(),r=t.endNode.getCenter(),a=Math.atan2(r.y-o.y,r.x-o.x),h=io(t,t.endNode),l=1.5*n+3*s;return{point:h,core:{x:h.x-.9*l*Math.cos(a),y:h.y-.9*l*Math.sin(a)},angle:a,length:l}},io=(t,e)=>{let i=t.endNode,n=t.startNode;e.getId()===t.startNode.getId()&&(i=t.startNode,n=t.endNode);const s=i.getCenter(),o=n.getCenter(),r=s.x-o.x,a=s.y-o.y,h=Math.sqrt(r*r+a*a),l=(h-e.getDistanceToBorder())/h;return{x:(1-l)*o.x+l*s.x,y:(1-l)*o.y+l*s.y,t:0}},no=t=>{if(t instanceof k)return eo(t);if(t instanceof B)return Ys(t);if(t instanceof z)return Qs(t);throw new Error("Failed to draw unsupported edge type")},so=(t,e)=>{const i=e.point.x,n=e.point.y,s=e.angle,o=e.length;for(let e=0;e{const i=e.getCenter(),n=e.getRadius();switch(e.getStyle().shape){case w.SQUARE:((t,e,i,n)=>{t.beginPath(),t.rect(e-n,i-n,2*n,2*n),t.closePath()})(t,i.x,i.y,n);break;case w.DIAMOND:((t,e,i,n)=>{t.beginPath(),t.lineTo(e,i+n),t.lineTo(e+n,i),t.lineTo(e,i-n),t.lineTo(e-n,i),t.closePath()})(t,i.x,i.y,n);break;case w.TRIANGLE:((t,e,i,n)=>{t.beginPath(),i+=.275*(n*=1.15);const s=2*n,o=Math.sqrt(3)*s/6,r=Math.sqrt(s*s-n*n);t.moveTo(e,i-(r-o)),t.lineTo(e+n,i+o),t.lineTo(e-n,i+o),t.lineTo(e,i-(r-o)),t.closePath()})(t,i.x,i.y,n);break;case w.TRIANGLE_DOWN:((t,e,i,n)=>{t.beginPath(),i-=.275*(n*=1.15);const s=2*n,o=Math.sqrt(3)*s/6,r=Math.sqrt(s*s-n*n);t.moveTo(e,i+(r-o)),t.lineTo(e+n,i-o),t.lineTo(e-n,i-o),t.lineTo(e,i+(r-o)),t.closePath()})(t,i.x,i.y,n);break;case w.STAR:((t,e,i,n)=>{t.beginPath(),i+=.1*(n*=.82);for(let s=0;s<10;s++){const o=n*(s%2==0?1.3:.5),r=e+o*Math.sin(2*s*Math.PI/10),a=i-o*Math.cos(2*s*Math.PI/10);t.lineTo(r,a)}t.closePath()})(t,i.x,i.y,n);break;case w.HEXAGON:((t,e,i,n)=>{((t,e,i,n,s)=>{t.beginPath(),t.moveTo(e+n,i);const o=2*Math.PI/s;for(let r=1;r{t.beginPath(),t.arc(e,i,n,0,2*Math.PI,!1),t.closePath()})(t,i.x,i.y,n)}},ro=(t,e=300)=>{let i=0,n=null;return function(){const s=arguments,o=Date.now(),r=e-(o-i);r<=0?(n&&(clearTimeout(n),n=null),i=o,t(...s)):n||(n=setTimeout(()=>{i=Date.now(),n=null,t(...s)},r))}},ao=t=>{const e=Math.max(t,1);return Math.round(1e3/e)},ho=(t,e=!1)=>{t.style.position="relative";const i=getComputedStyle(t);i.display||(t.style.display="block",console.warn("[Orb] Graph container doesn't have defined 'display' property. Setting 'display' to 'block'...")),!e&&uo(i.width)&&(t.style.width="100%",uo(getComputedStyle(t).width)?(t.style.width="400px",console.warn("[Orb] The graph container element and its parent don't have defined width properties.","If you are using percentage values,","please make sure that the parent element of the graph container has a defined position and width.","Setting the width of the graph container to an arbitrary value of '400px'...")):console.warn("[Orb] The graph container element doesn't have defined width. Setting width to 100%...")),!e&&uo(i.height)&&(t.style.height="100%",uo(getComputedStyle(t).height)?(t.style.height="400px",console.warn("[Orb] The graph container element and its parent don't have defined height properties.","If you are using percentage values,","please make sure that the parent element of the graph container has a defined position and height.","Setting the height of the graph container to an arbitrary value of '400px'...")):console.warn("[Orb] Graph container doesn't have defined height. Setting height to 100%..."))},lo=/^\s*0+\s*(?:px|rem|em|vh|vw)?\s*$/i,uo=t=>null==t||""===t||lo.test(t),co=t=>{const e=document.createElement("canvas");return e.style.position="absolute",e.style.top="0",e.style.left="0",t.appendChild(e),e},_o=t=>{let e=window.devicePixelRatio,i=()=>{};const n=()=>{i();const s=matchMedia(`(resolution: ${e}dppx)`);s.addEventListener("change",n),i=()=>s.removeEventListener("change",n),window.devicePixelRatio!==e&&(e=window.devicePixelRatio,t(e))};return n(),()=>i()};class fo extends t{constructor(t,e){super(),this._isOriginCentered=!1,this._isInitiallyRendered=!1,ho(t,null==e?void 0:e.areCollapsedContainerDimensionsAllowed),this._container=t,this._canvas=co(t);const i=this._canvas.getContext("2d");if(!i)throw new o("Failed to create Canvas context.");this._context=i,this._width=640,this._height=480,this.transform=En,this._settings=Object.assign(Object.assign({},Fs),e),this._resizeObs=new ResizeObserver(()=>this._resize()),this._resizeObs.observe(this._container),this._resize(),u(null==e?void 0:e.devicePixelRatio)||(this._dprObserveUnsubscribe=_o(()=>this._resize())),this._throttleRender=ro(t=>{this._render(t)},ao(this._settings.fps))}get width(){return this._width}get height(){return this._height}get container(){return this._container}get canvas(){return this._canvas}get isInitiallyRendered(){return this._isInitiallyRendered}getSettings(){return m(this._settings)}setSettings(t){var e;const i=t.fps&&t.fps!==this._settings.fps,n=this._settings.devicePixelRatio,s=t.devicePixelRatio;this._settings=Object.assign(Object.assign({},this._settings),t),i&&(this._throttleRender=ro(t=>{this._render(t)},ao(this._settings.fps))),!u(n)&&u(s)&&(null===(e=this._dprObserveUnsubscribe)||void 0===e||e.call(this),this._resize()),u(n)&&null===s&&(this._dprObserveUnsubscribe=_o(()=>this._resize()))}render(t){this._throttleRender(t)}_render(t){this.emit(Us.RENDER_START,void 0);const e=Date.now();this._context.clearRect(0,0,this._width,this._height),this._settings.backgroundColor&&(this._context.fillStyle=this._settings.backgroundColor.toString(),this._context.fillRect(0,0,this._width,this._height)),this._context.save(),this._context.translate(this.transform.x,this.transform.y),this._context.scale(this.transform.k,this.transform.k),this._isOriginCentered&&this._context.translate(this._width/2,this._height/2),this.drawObjects(t.getEdges()),this.drawObjects(t.getNodes()),this._context.restore(),this.emit(Us.RENDER_END,{durationMs:Date.now()-e}),this._isInitiallyRendered=!0}drawObjects(t){if(0===t.length)return;const e=[],i=[];for(let n=0;n{var n,s;const o=null===(n=null==i?void 0:i.isShadowEnabled)||void 0===n||n,r=null===(s=null==i?void 0:i.isLabelEnabled)||void 0===s||s,a=e.hasShadow();((t,e)=>{if(e.hasBorder()){t.lineWidth=e.getBorderWidth();const i=e.getBorderColor();i&&(t.strokeStyle=i.toString())}const i=e.getColor();i&&(t.fillStyle=i.toString())})(t,e),o&&a&&((t,e)=>{const i=e.getStyle();i.shadowColor&&(t.shadowColor=i.shadowColor.toString()),i.shadowSize&&(t.shadowBlur=i.shadowSize),i.shadowOffsetX&&(t.shadowOffsetX=i.shadowOffsetX),i.shadowOffsetY&&(t.shadowOffsetY=i.shadowOffsetY)})(t,e),oo(t,e),t.fill();const h=e.getBackgroundImage();h&&((t,e,i)=>{if(!i.width||!i.height)return;const n=e.getCenter(),s=e.getRadius(),o=Math.max(2*s/i.width,2*s/i.height),r=i.height*o,a=i.width*o;t.save(),t.clip(),t.drawImage(i,n.x-a/2,n.y-r/2,a,r),t.restore()})(t,e,h),o&&a&&((t,e)=>{const i=e.getStyle();i.shadowColor&&(t.shadowColor="rgba(0,0,0,0)"),i.shadowSize&&(t.shadowBlur=0),i.shadowOffsetX&&(t.shadowOffsetX=0),i.shadowOffsetY&&(t.shadowOffsetY=0)})(t,e),e.hasBorder()&&t.stroke(),r&&((t,e)=>{const i=e.getLabel();if(!i)return;const n=e.getCenter(),s=1.2*e.getBorderedRadius(),o=e.getStyle(),r=new Gs(i,{position:{x:n.x,y:n.y+s},textBaseline:Ws.TOP,properties:{fontBackgroundColor:o.fontBackgroundColor,fontColor:o.fontColor,fontFamily:o.fontFamily,fontSize:o.fontSize}});Zs(t,r)})(t,e)})(this._context,t,e):((t,e,i)=>{var n,s;if(!e.getWidth())return;const o=null===(n=null==i?void 0:i.isShadowEnabled)||void 0===n||n,r=null===(s=null==i?void 0:i.isLabelEnabled)||void 0===s||s,a=e.hasShadow();((t,e)=>{const i=e.getWidth();i>0&&(t.lineWidth=i);const n=e.getColor();n&&(t.strokeStyle=n.toString(),t.fillStyle=n.toString())})(t,e),o&&a&&((t,e)=>{const i=e.getStyle();i.shadowColor&&(t.shadowColor=i.shadowColor.toString()),i.shadowSize&&(t.shadowBlur=i.shadowSize),i.shadowOffsetX&&(t.shadowOffsetX=i.shadowOffsetX),i.shadowOffsetY&&(t.shadowOffsetY=i.shadowOffsetY)})(t,e),((t,e)=>{if(0===e.getStyle().arrowSize)return;const i=no(e),n=so([{x:0,y:0},{x:-1,y:.4},{x:-1,y:-.4}],i);t.beginPath();for(let e=0;e{if(e instanceof k)return((t,e)=>{const i=e.startNode.getCenter(),n=e.endNode.getCenter();if(!i||!n)return;t.beginPath(),t.moveTo(i.x,i.y),t.lineTo(n.x,n.y);const s=e.getLineDashPattern();t.setLineDash(null!=s?s:[]),t.stroke()})(t,e);if(e instanceof B)return((t,e)=>{const i=e.startNode.getCenter(),n=e.endNode.getCenter();if(!i||!n)return;const s=e.getCurvedControlPoint();t.beginPath(),t.moveTo(i.x,i.y),t.quadraticCurveTo(s.x,s.y,n.x,n.y);const o=e.getLineDashPattern();t.setLineDash(null!=o?o:[]),t.stroke()})(t,e);if(e instanceof z)return((t,e)=>{const{x:i,y:n,radius:s}=e.getCircularData();t.beginPath(),t.arc(i,n,s,0,2*Math.PI,!1),t.closePath();const o=e.getLineDashPattern();t.setLineDash(null!=o?o:[]),t.stroke()})(t,e);throw new Error("Failed to draw unsupported edge type")})(t,e),o&&a&&((t,e)=>{const i=e.getStyle();i.shadowColor&&(t.shadowColor="rgba(0,0,0,0)"),i.shadowSize&&(t.shadowBlur=0),i.shadowOffsetX&&(t.shadowOffsetX=0),i.shadowOffsetY&&(t.shadowOffsetY=0)})(t,e),r&&((t,e)=>{const i=e.getLabel();if(!i)return;const n=e.getStyle(),s=new Gs(i,{position:e.getCenter(),textBaseline:Ws.MIDDLE,properties:{fontBackgroundColor:n.fontBackgroundColor,fontColor:n.fontColor,fontFamily:n.fontFamily,fontSize:n.fontSize}});Zs(t,s)})(t,e)})(this._context,t,e)}reset(){this.transform=En,this._context.clearRect(0,0,this._width,this._height),this._context.save()}getFitZoomTransform(t,e){const i=t.getBoundingBox(),n="center"===(null==e?void 0:e.anchorX)?i.x+i.width/2:"end"===(null==e?void 0:e.anchorX)?i.x+i.width:0,s="center"===(null==e?void 0:e.anchorY)?i.y+i.height/2:"end"===(null==e?void 0:e.anchorY)?i.y+i.height:0,o=this.getSimulationViewRectangle(),r=o.height/(i.height*(1+this._settings.fitZoomMargin)),a=o.width/(i.width*(1+this._settings.fitZoomMargin)),h=Math.min(r,a),l=this.transform.k,d=Math.max(Math.min(h*l,this._settings.maxZoom),this._settings.minZoom),u=o.width/2*l*(1-d)-n*d,c=o.height/2*l*(1-d)-s*d;return En.translate(u,c).scale(d)}getSimulationPosition(t){const[e,i]=this.transform.invert([t.x,t.y]);return{x:e-this._width/2,y:i-this._height/2}}getCanvasPosition(t){const[e,i]=this.transform.apply([t.x+this._width/2,t.y+this._height/2]);return{x:e,y:i}}getSimulationViewRectangle(){const t=this.getSimulationPosition({x:0,y:0}),e=this.getSimulationPosition({x:this._width,y:this._height});return{x:t.x,y:t.y,width:e.x-t.x,height:e.y-t.y}}translateOriginToCenter(){this._isOriginCentered=!0}destroy(){var t;this._resizeObs.unobserve(this._container),null===(t=this._dprObserveUnsubscribe)||void 0===t||t.call(this),this.removeAllListeners(),this._canvas.remove()}}const go=(t,e,i)=>{const n=ls(t,e,hs.VERTEX),s=ls(t,i,hs.FRAGMENT),r=t.createProgram();if(!r)throw new o("Failed to create GL program.");if(t.attachShader(r,n),t.attachShader(r,s),t.linkProgram(r),!t.getProgramParameter(r,t.LINK_STATUS)){const e=t.getProgramInfoLog(r);throw t.deleteProgram(r),new o(`Failed to link GL program: ${e}`)}return t.deleteShader(n),t.deleteShader(s),r},po=2048,mo=2048;class vo{constructor(t){this._texture=null,this._cache=new Map,this._shelves=[],this._isDirty=!1,this._isTextureAllocated=!1,this._gl=t,this._canvas=document.createElement("canvas"),this._canvas.width=po,this._canvas.height=mo,this._ctx=this._canvas.getContext("2d",{willReadFrequently:!1}),this._texture=t.createTexture(),t.bindTexture(t.TEXTURE_2D,this._texture),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.bindTexture(t.TEXTURE_2D,null)}getOrCreate(t,e,i,n,s){const o=`${t}|${e}|${i}|${n}|${null!=s?s:""}`,r=this._cache.get(o);if(r)return r;const a=t.split("\n").map(t=>t.trim());if(0===a.length||1===a.length&&""===a[0])return null;const h=this._ctx,l=`48px ${i}`;h.font=l;let d=0;for(let t=0;td&&(d=e)}const u=48*1.2,c=48+(a.length-1)*u,_=Math.ceil(d+11.52)+4,f=Math.ceil(c+11.52)+4,g=this._allocate(_,f);if(!g)return null;const p=g.x+2,m=g.y+2;s&&(h.fillStyle=s,h.fillRect(p,m,_-4,f-4)),h.font=l,h.fillStyle=n,h.textBaseline="top",h.textAlign="center";const v=p+(_-4)/2;for(let t=0;tmo)return null;const n={y:i,height:e,x:t};return this._shelves.push(n),{x:0,y:i}}}const yo=2048,xo=2048;class bo{constructor(t){this._texture=null,this._cache=new Map,this._pending=new Map,this._shelves=[],this._isDirty=!1,this._isTextureAllocated=!1,this._gl=t,this._canvas=document.createElement("canvas"),this._canvas.width=yo,this._canvas.height=xo,this._ctx=this._canvas.getContext("2d",{willReadFrequently:!1}),this._texture=t.createTexture(),t.bindTexture(t.TEXTURE_2D,this._texture),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.bindTexture(t.TEXTURE_2D,null)}getOrCreate(t){const e=this._cache.get(t);if(e)return e;const i=this._pending.get(t);if(i)return i.loaded?this._packImage(t,i.image):null;const n=new Image;n.crossOrigin="anonymous";const s={image:n,loaded:!1};return this._pending.set(t,s),n.onload=()=>{s.loaded=!0},n.onerror=()=>{this._pending.delete(t)},n.src=t,null}bind(t){const e=this._gl;e.activeTexture(e.TEXTURE0+t),e.bindTexture(e.TEXTURE_2D,this._texture)}uploadIfDirty(){if(!this._isDirty)return;const t=this._gl;t.bindTexture(t.TEXTURE_2D,this._texture),this._isTextureAllocated||(t.texImage2D(t.TEXTURE_2D,0,t.RGBA,yo,xo,0,t.RGBA,t.UNSIGNED_BYTE,null),this._isTextureAllocated=!0),t.texSubImage2D(t.TEXTURE_2D,0,0,0,t.RGBA,t.UNSIGNED_BYTE,this._canvas),t.bindTexture(t.TEXTURE_2D,null),this._isDirty=!1}clear(){this._cache.clear(),this._pending.clear(),this._shelves=[],this._isDirty=!1,this._ctx.clearRect(0,0,yo,xo)}_packImage(t,e){if(!e.naturalWidth||!e.naturalHeight)return null;const i=e.naturalWidth/e.naturalHeight;let n,s;e.naturalWidth>=e.naturalHeight?(n=Math.min(e.naturalWidth,128),s=Math.round(n/i)):(s=Math.min(e.naturalHeight,128),n=Math.round(s*i));const o=n+4,r=s+4,a=this._allocate(o,r);if(!a)return null;this._ctx.drawImage(e,a.x+2,a.y+2,n,s);const h={u0:(a.x+2)/yo,v0:(a.y+2)/xo,u1:(a.x+2+n)/yo,v1:(a.y+2+s)/xo,aspect:i};return this._cache.set(t,h),this._pending.delete(t),this._isDirty=!0,h}_allocate(t,e){for(let i=0;ixo)return null;const n={y:i,height:e,x:t};return this._shelves.push(n),{x:0,y:i}}}const So=[0,0,0,0],wo=[.6,.6,.6,1],To=[1,0,0,1],Eo={[w.CIRCLE]:0,[w.DOT]:1,[w.SQUARE]:2,[w.DIAMOND]:3,[w.TRIANGLE]:4,[w.TRIANGLE_DOWN]:5,[w.STAR]:6,[w.HEXAGON]:7},Po="Roboto, sans-serif",Ao="#000000";class Co extends t{constructor(t,e){super(),this._isOriginCentered=!1,this._isInitiallyRendered=!1,this._nodeProgram=null,this._edgeProgram=null,this._labelProgram=null,this._nodeVao=null,this._edgeVao=null,this._labelVao=null,this._nodeInstanceBuffer=null,this._edgeInstanceBuffer=null,this._labelInstanceBuffer=null,this._labelCache=null,this._imageAtlas=null,this._isColorCacheDirty=!0,this._nodeColorCache=new Map,this._nodeBorderColorCache=new Map,this._nodeShadowColorCache=new Map,this._edgeColorCache=new Map,this._edgeShadowColorCache=new Map,this._lastNodeCount=0,this._lastEdgeCount=0,this._edgeInstanceData=null,this._nodeInstanceData=null,this._buffersAreCurrent=!1,this._bufferCacheStats={hits:0,misses:0},this._timerExt=null,this._timerEdgeQueries=[],this._timerNodeQueries=[],this._timerQueryIdx=0,this._lastEdgeGpuMs=null,this._lastNodeGpuMs=null,this._lastStyleVersion=-1,ho(t,null==e?void 0:e.areCollapsedContainerDimensionsAllowed),this._container=t,this._canvas=co(t);const i=this._canvas.getContext("webgl2",{antialias:!0});if(!i)throw new o("Failed to create WebGL context.");if(this._gl=i,this._width=640,this._height=480,this.transform=En,this._settings=Object.assign(Object.assign({},Fs),e),"number"!=typeof(null==e?void 0:e.devicePixelRatio)&&(this._dprObserveUnsubscribe=_o(()=>{this._isInitiallyRendered&&this.emit(Us.RESIZE,void 0)})),this._initShaders(),this._initNodeBuffers(),this._initEdgeBuffers(),this._initLabelBuffers(),this._labelCache=new vo(this._gl),this._imageAtlas=new bo(this._gl),this._timerExt=i.getExtension("EXT_disjoint_timer_query_webgl2"),this._timerExt)for(let t=0;t<4;t++){const t=i.createQuery(),e=i.createQuery();t&&this._timerEdgeQueries.push(t),e&&this._timerNodeQueries.push(e)}}_pollTimerQuery(t){if(!this._timerExt)return null;const e=this._gl;return e.getQueryParameter(t,e.QUERY_RESULT_AVAILABLE)?e.getParameter(this._timerExt.GPU_DISJOINT_EXT)?null:e.getQueryParameter(t,e.QUERY_RESULT)/1e6:null}getGpuTimeStats(){return{edgeMs:this._lastEdgeGpuMs,nodeMs:this._lastNodeGpuMs,supported:null!==this._timerExt}}_initShaders(){this._nodeProgram=go(this._gl,"#version 300 es\n\nprecision highp float;\n\nin vec2 aQuadPosition;\n\nin vec2 aCenter;\nin float aRadius;\nin vec4 aColor;\nin vec4 aBorderColor;\nin float aBorderWidth;\nin vec4 aShadowColor;\nin float aShadowSize;\nin float aShadowOffsetX;\nin float aShadowOffsetY;\nin float aShapeType;\nin vec2 aImageUV0;\nin vec2 aImageUV1;\nin float aImageAspect;\n\nuniform vec2 uResolution;\nuniform vec2 uTranslation;\nuniform float uScale;\nuniform vec2 uOriginOffset;\n\nout vec2 vUV;\nout vec4 vColor;\nout vec4 vBorderColor;\nout float vBorderThreshold;\nout vec4 vShadowColor;\nout float vNodeRadius;\nout vec2 vShadowOffset;\nout float vShadowBlur;\nflat out int vShapeType;\nout vec2 vImageUV0;\nout vec2 vImageUV1;\nout float vImageAspect;\n\nvoid main() {\n vShapeType = int(aShapeType + 0.5);\n vColor = aColor;\n vBorderColor = aBorderColor;\n vShadowColor = aShadowColor;\n vImageUV0 = aImageUV0;\n vImageUV1 = aImageUV1;\n vImageAspect = aImageAspect;\n\n float totalRadius = aRadius + aShadowSize + abs(aShadowOffsetX) + abs(aShadowOffsetY);\n\n vUV = aQuadPosition;\n vNodeRadius = aRadius / totalRadius;\n\n vBorderThreshold = vNodeRadius * (1.0 - aBorderWidth / aRadius);\n\n vShadowOffset = vec2(aShadowOffsetX, aShadowOffsetY) / totalRadius;\n\n vShadowBlur = aShadowSize / totalRadius;\n\n vec2 worldPos = aCenter + aQuadPosition * totalRadius;\n vec2 screenPos = (worldPos + uOriginOffset) * uScale + uTranslation;\n\n vec2 clip = (screenPos / uResolution) * 2.0 - 1.0;\n gl_Position = vec4(clip.x, -clip.y, 0.0, 1.0);\n}\n","#version 300 es\n\nprecision highp float;\n\nin vec2 vUV;\nin vec4 vColor;\nin vec4 vBorderColor;\nin float vBorderThreshold;\nin vec4 vShadowColor;\nin float vNodeRadius;\nin vec2 vShadowOffset;\nin float vShadowBlur;\nflat in int vShapeType;\nin vec2 vImageUV0;\nin vec2 vImageUV1;\nin float vImageAspect;\n\nuniform sampler2D uImageAtlas;\n\nout vec4 fragColor;\n\nconst int SHAPE_CIRCLE = 0;\nconst int SHAPE_DOT = 1;\nconst int SHAPE_SQUARE = 2;\nconst int SHAPE_DIAMOND = 3;\nconst int SHAPE_TRIANGLE = 4;\nconst int SHAPE_TRIANGLE_DOWN = 5;\nconst int SHAPE_STAR = 6;\nconst int SHAPE_HEXAGON = 7;\n\nfloat sdCircle(vec2 p, float r) {\n return length(p) - r;\n}\n\nfloat sdSquare(vec2 p, float r) {\n vec2 d = abs(p) - vec2(r);\n return max(d.x, d.y);\n}\n\nfloat sdDiamond(vec2 p, float r) {\n return (abs(p.x) + abs(p.y)) - r;\n}\n\nfloat sdTriangleDown(vec2 p, float r) {\n float sr = r * 1.15;\n vec2 q = vec2(p.x, p.y - 0.275 * sr);\n\n float k = sqrt(3.0);\n q.x = abs(q.x) - sr;\n q.y = q.y + sr / k;\n if (q.x + k * q.y > 0.0) {\n q = vec2(q.x - k * q.y, -k * q.x - q.y) / 2.0;\n }\n q.x -= clamp(q.x, -2.0 * sr, 0.0);\n return -length(q) * sign(q.y);\n}\n\nfloat sdTriangleUp(vec2 p, float r) {\n return sdTriangleDown(vec2(p.x, -p.y), r);\n}\n\nfloat sdStar(vec2 p, float r) {\n float sr = r * 0.82;\n vec2 q = vec2(p.x, p.y - 0.1 * sr);\n\n float outerR = sr * 1.3;\n float innerR = sr * 0.5;\n\n float angle = atan(q.x, -q.y);\n float sector = 6.2831853 / 5.0;\n float a = mod(angle + sector * 0.5, sector) - sector * 0.5;\n\n float cosA = cos(a);\n float sinA = abs(sin(a));\n\n float halfSector = sector * 0.5;\n vec2 outerPt = vec2(outerR, 0.0);\n vec2 innerPt = vec2(innerR * cos(halfSector), innerR * sin(halfSector));\n\n vec2 sp = vec2(cosA, sinA) * length(q);\n\n vec2 edge = innerPt - outerPt;\n vec2 toP = sp - outerPt;\n float t = clamp(dot(toP, edge) / dot(edge, edge), 0.0, 1.0);\n float dist = length(toP - edge * t);\n\n float cross2d = edge.x * toP.y - edge.y * toP.x;\n return cross2d > 0.0 ? -dist : dist;\n}\n\nfloat sdHexagon(vec2 p, float r) {\n vec2 q = abs(p);\n float k = sqrt(3.0);\n float d = max(q.x, (q.x * 0.5 + q.y * (k * 0.5)));\n return d - r;\n}\n\nfloat shapeSDF(vec2 p, float r, int shapeType) {\n if (shapeType == SHAPE_SQUARE) return sdSquare(p, r);\n if (shapeType == SHAPE_DIAMOND) return sdDiamond(p, r);\n if (shapeType == SHAPE_TRIANGLE) return sdTriangleUp(p, r);\n if (shapeType == SHAPE_TRIANGLE_DOWN) return sdTriangleDown(p, r);\n if (shapeType == SHAPE_STAR) return sdStar(p, r);\n if (shapeType == SHAPE_HEXAGON) return sdHexagon(p, r);\n\n return sdCircle(p, r);\n}\n\nvoid main() {\n // Body SDF - always needed.\n float dist = shapeSDF(vUV, vNodeRadius, vShapeType);\n\n float aa = 0.02 * vNodeRadius;\n float nodeAlpha = 1.0 - smoothstep(-aa, 0.0, dist);\n\n // Shadow SDF - skip entirely when no shadow. Avoids a second full shapeSDF() call\n // (which is a cascade of ifs) and the exp() per fragment.\n float shadowAlpha = 0.0;\n if (vShadowBlur > 0.0) {\n float shadowDist = shapeSDF(vUV - vShadowOffset, vNodeRadius, vShapeType);\n float t = max(shadowDist, 0.0) / vShadowBlur;\n shadowAlpha = exp(-t * t * 1.5) * 0.5 * vShadowColor.a;\n }\n\n vec4 fillColor = vColor;\n if (vImageAspect > 0.0 && dist < 0.0) {\n vec2 uv01 = (vUV / vNodeRadius) * 0.5 + 0.5;\n if (vImageAspect > 1.0) {\n uv01.x = (uv01.x - 0.5) / vImageAspect + 0.5;\n } else {\n uv01.y = (uv01.y - 0.5) * vImageAspect + 0.5;\n }\n if (uv01.x >= 0.0 && uv01.x <= 1.0 && uv01.y >= 0.0 && uv01.y <= 1.0) {\n vec2 atlasUV = mix(vImageUV0, vImageUV1, uv01);\n vec4 imgTexel = texture(uImageAtlas, atlasUV);\n fillColor = mix(fillColor, vec4(imgTexel.rgb, 1.0), imgTexel.a);\n }\n }\n\n vec4 nodeColor;\n if (vBorderThreshold < vNodeRadius) {\n float borderDist = shapeSDF(vUV, vBorderThreshold, vShapeType);\n float borderMix = smoothstep(-aa, aa, borderDist);\n nodeColor = mix(fillColor, vBorderColor, borderMix);\n } else {\n nodeColor = fillColor;\n }\n nodeColor.a *= nodeAlpha;\n\n float finalAlpha = nodeColor.a + shadowAlpha * (1.0 - nodeColor.a);\n\n if (finalAlpha < 0.001) {\n discard;\n }\n\n if (shadowAlpha > 0.0) {\n vec3 finalRGB = (nodeColor.rgb * nodeColor.a + vShadowColor.rgb * shadowAlpha * (1.0 - nodeColor.a)) / finalAlpha;\n fragColor = vec4(finalRGB, finalAlpha);\n } else {\n fragColor = nodeColor;\n }\n}\n"),this._edgeProgram=go(this._gl,"#version 300 es\n\nprecision highp float;\n\nin vec2 aQuadPosition;\n\nin vec2 aStart;\nin vec2 aEnd;\nin vec2 aControl;\nin float aWidth;\nin float aEdgeType;\nin float aLoopbackRadius;\nin float aArrowSize;\nin vec2 aArrowTip;\nin vec2 aArrowDir;\nin vec4 aColor;\nin vec4 aShadowColor;\nin float aShadowSize;\nin float aShadowOffsetX;\nin float aShadowOffsetY;\n\nuniform vec2 uResolution;\nuniform vec2 uTranslation;\nuniform float uScale;\nuniform vec2 uOriginOffset;\n\nout vec2 vWorldPos;\nout vec2 vStart;\nout vec2 vEnd;\nout vec2 vControl;\nout float vHalfWidth;\nout float vWidthFade;\nout float vHalfWidthPx;\nout float vPerpPx;\nout float vLoopbackRadius;\nout float vArrowSize;\nout vec2 vArrowTip;\nout vec2 vArrowDir;\nout vec4 vColor;\nout vec4 vShadowColor;\nout float vShadowSize;\nout vec2 vShadowOffset;\nflat out int vEdgeType;\n\nvoid main() {\n vEdgeType = int(aEdgeType + 0.5);\n vStart = aStart;\n vEnd = aEnd;\n vControl = aControl;\n float effectiveWidth = max(aWidth, 1.0 / uScale);\n vHalfWidth = effectiveWidth * 0.5;\n vWidthFade = clamp(aWidth * uScale, 0.0, 1.0);\n vHalfWidthPx = vHalfWidth * uScale;\n vPerpPx = 0.0;\n vLoopbackRadius = aLoopbackRadius;\n vArrowSize = aArrowSize;\n vArrowTip = aArrowTip;\n vArrowDir = aArrowDir;\n vColor = aColor;\n vShadowColor = aShadowColor;\n vShadowSize = aShadowSize;\n vShadowOffset = vec2(aShadowOffsetX, aShadowOffsetY);\n\n float pad = vHalfWidth + aShadowSize + abs(aShadowOffsetX) + abs(aShadowOffsetY);\n\n vec2 worldPos;\n\n if (vEdgeType == 0) {\n vec2 dir = aEnd - aStart;\n float len = length(dir);\n vec2 unitDir = dir / max(len, 0.0001);\n vec2 perp = vec2(-unitDir.y, unitDir.x);\n float totalHalf = pad + aArrowSize;\n vec2 midpoint = (aStart + aEnd) * 0.5;\n worldPos = midpoint\n + unitDir * (len * 0.5 + totalHalf) * aQuadPosition.x\n + perp * totalHalf * aQuadPosition.y;\n vPerpPx = totalHalf * aQuadPosition.y * uScale;\n } else if (vEdgeType == 1) {\n float margin = pad + aArrowSize;\n vec2 bboxMin = min(min(aStart, aEnd), aControl) - margin;\n vec2 bboxMax = max(max(aStart, aEnd), aControl) + margin;\n vec2 center = (bboxMin + bboxMax) * 0.5;\n vec2 halfSize = (bboxMax - bboxMin) * 0.5;\n worldPos = center + aQuadPosition * halfSize;\n } else {\n float margin = pad + aArrowSize;\n vec2 ctr = aControl;\n float r = aLoopbackRadius;\n vec2 bboxMin = min(ctr - (r + margin), aStart - margin);\n vec2 bboxMax = max(ctr + (r + margin), aStart + margin);\n vec2 center = (bboxMin + bboxMax) * 0.5;\n vec2 halfSize = (bboxMax - bboxMin) * 0.5;\n worldPos = center + aQuadPosition * halfSize;\n }\n\n vWorldPos = worldPos;\n vec2 screenPos = (worldPos + uOriginOffset) * uScale + uTranslation;\n vec2 clip = (screenPos / uResolution) * 2.0 - 1.0;\n gl_Position = vec4(clip.x, -clip.y, 0.0, 1.0);\n}\n","#version 300 es\n\nprecision highp float;\n\nin vec2 vWorldPos;\nin vec2 vStart;\nin vec2 vEnd;\nin vec2 vControl;\nin float vHalfWidth;\nin float vWidthFade;\nin float vHalfWidthPx;\nin float vPerpPx;\nin float vLoopbackRadius;\nin float vArrowSize;\nin vec2 vArrowTip;\nin vec2 vArrowDir;\nin vec4 vColor;\nin vec4 vShadowColor;\nin float vShadowSize;\nin vec2 vShadowOffset;\nflat in int vEdgeType;\n\nuniform bool uSimpleMode;\n\nout vec4 fragColor;\n\nfloat sdSegment(vec2 p, vec2 a, vec2 b) {\n vec2 pa = p - a;\n vec2 ba = b - a;\n float h = clamp(dot(pa, ba) / dot(ba, ba), 0.0, 1.0);\n return length(pa - ba * h);\n}\n\nfloat sdBezier(vec2 pos, vec2 A, vec2 B, vec2 C) {\n vec2 a = B - A;\n vec2 b = A - 2.0 * B + C;\n vec2 c = a * 2.0;\n vec2 d = A - pos;\n\n float kk = 1.0 / max(dot(b, b), 0.0001);\n float kx = kk * dot(a, b);\n float ky = kk * (2.0 * dot(a, a) + dot(d, b)) / 3.0;\n float kz = kk * dot(d, a);\n\n float p = ky - kx * kx;\n float q = kx * (2.0 * kx * kx - 3.0 * ky) + kz;\n float p3 = p * p * p;\n float q2 = q * q;\n float h = q2 + 4.0 * p3;\n\n float res;\n if (h >= 0.0) {\n h = sqrt(h);\n vec2 x = (vec2(h, -h) - q) / 2.0;\n vec2 uv = sign(x) * pow(abs(x), vec2(1.0 / 3.0));\n float t = clamp(uv.x + uv.y - kx, 0.0, 1.0);\n vec2 qo = d + (c + b * t) * t;\n res = dot(qo, qo);\n } else {\n float z = sqrt(-p);\n float v = acos(q / (p * z * 2.0)) / 3.0;\n float m = cos(v);\n float n = sin(v) * 1.732050808;\n vec3 t = clamp(vec3(m + m, -n - m, n - m) * z - kx, 0.0, 1.0);\n vec2 qx = d + (c + b * t.x) * t.x;\n float dx = dot(qx, qx);\n vec2 qy = d + (c + b * t.y) * t.y;\n float dy = dot(qy, qy);\n res = min(dx, dy);\n }\n\n return sqrt(res);\n}\n\nfloat sdArrow(vec2 p, vec2 tip, vec2 dir, float size) {\n if (size <= 0.0) return 1e6;\n\n vec2 perp = vec2(-dir.y, dir.x);\n vec2 rel = p - tip;\n float along = dot(rel, -dir);\n float across = dot(rel, perp);\n\n if (along < 0.0) return length(rel);\n if (along > size) {\n float hw = size * 0.4;\n float closest = clamp(across, -hw, hw);\n vec2 pt = tip - dir * size + perp * closest;\n return length(p - pt);\n }\n\n float halfW = (along / size) * size * 0.4;\n float d = abs(across) - halfW;\n return d;\n}\n\nvoid main() {\n if (uSimpleMode && vEdgeType == 0) {\n float cover = clamp(vHalfWidthPx - abs(vPerpPx) + 0.5, 0.0, 1.0);\n float a = cover * vWidthFade;\n if (a < 0.001) discard;\n fragColor = vec4(vColor.rgb, vColor.a * a);\n return;\n }\n\n float dist;\n if (vEdgeType == 0) {\n dist = sdSegment(vWorldPos, vStart, vEnd);\n } else if (vEdgeType == 1) {\n dist = sdBezier(vWorldPos, vStart, vControl, vEnd);\n } else {\n dist = abs(length(vWorldPos - vControl) - vLoopbackRadius);\n }\n\n float edgeSdf = dist - vHalfWidth;\n float combinedSdf = edgeSdf;\n\n if (vArrowSize > 0.0) {\n float arrowDist = sdArrow(vWorldPos, vArrowTip, vArrowDir, vArrowSize);\n combinedSdf = min(edgeSdf, arrowDist);\n }\n\n float shadowAlpha = 0.0;\n if (vShadowSize > 0.0) {\n vec2 shadowPos = vWorldPos - vShadowOffset;\n float shadowDist;\n if (vEdgeType == 0) {\n shadowDist = sdSegment(shadowPos, vStart, vEnd);\n } else if (vEdgeType == 1) {\n shadowDist = sdBezier(shadowPos, vStart, vControl, vEnd);\n } else {\n shadowDist = abs(length(shadowPos - vControl) - vLoopbackRadius);\n }\n float shadowArrowDist = vArrowSize > 0.0\n ? sdArrow(shadowPos, vArrowTip, vArrowDir, vArrowSize)\n : 1.0e6;\n float shadowCombined = min(shadowDist - vHalfWidth, shadowArrowDist);\n float t = max(shadowCombined, 0.0) / vShadowSize;\n shadowAlpha = exp(-t * t * 1.5) * 0.5 * vShadowColor.a;\n }\n\n float aa = fwidth(combinedSdf);\n float edgeAlpha = (1.0 - smoothstep(-aa, aa, combinedSdf)) * vWidthFade;\n vec4 edgeColor = vColor;\n edgeColor.a *= edgeAlpha;\n\n float finalAlpha = edgeColor.a + shadowAlpha * (1.0 - edgeColor.a);\n\n if (finalAlpha < 0.001) discard;\n\n if (shadowAlpha > 0.0) {\n vec3 finalRGB = (edgeColor.rgb * edgeColor.a + vShadowColor.rgb * shadowAlpha * (1.0 - edgeColor.a)) / finalAlpha;\n fragColor = vec4(finalRGB, finalAlpha);\n } else {\n fragColor = edgeColor;\n }\n}\n"),this._labelProgram=go(this._gl,"#version 300 es\n\nin vec2 aQuadPosition;\n\nin vec2 aLabelCenter;\nin vec2 aLabelSize;\nin vec2 aLabelUV0;\nin vec2 aLabelUV1;\n\nuniform vec2 uResolution;\nuniform vec2 uTranslation;\nuniform float uScale;\nuniform vec2 uOriginOffset;\n\nout vec2 vAtlasUV;\n\nvoid main() {\n vec2 worldPos = aLabelCenter + aQuadPosition * aLabelSize;\n vec2 screenPos = (worldPos + uOriginOffset) * uScale + uTranslation;\n vec2 clip = (screenPos / uResolution) * 2.0 - 1.0;\n gl_Position = vec4(clip.x, -clip.y, 0.0, 1.0);\n\n vec2 uv01 = aQuadPosition * 0.5 + 0.5;\n vAtlasUV = mix(aLabelUV0, aLabelUV1, uv01);\n}\n","#version 300 es\n\nprecision highp float;\n\nuniform sampler2D uAtlas;\n\nin vec2 vAtlasUV;\n\nout vec4 fragColor;\n\nvoid main() {\n vec4 texel = texture(uAtlas, vAtlasUV);\n if (texel.a < 0.01) discard;\n fragColor = texel;\n}\n")}_initNodeBuffers(){if(!this._nodeProgram)throw new o("Node program not initialized.");const t=this._gl;this._nodeVao=t.createVertexArray(),t.bindVertexArray(this._nodeVao);const e=new Float32Array([-1,-1,1,-1,-1,1,1,1]),i=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,i),t.bufferData(t.ARRAY_BUFFER,e,t.STATIC_DRAW);const n=t.getAttribLocation(this._nodeProgram,"aQuadPosition");t.enableVertexAttribArray(n),t.vertexAttribPointer(n,2,t.FLOAT,!1,0,0),this._nodeInstanceBuffer=t.createBuffer(),t.bindBuffer(t.ARRAY_BUFFER,this._nodeInstanceBuffer);const s=25*Float32Array.BYTES_PER_ELEMENT,r=(e,i,n)=>{const o=t.getAttribLocation(this._nodeProgram,e);t.enableVertexAttribArray(o),t.vertexAttribPointer(o,i,t.FLOAT,!1,s,4*n),t.vertexAttribDivisor(o,1)};r("aCenter",2,0),r("aRadius",1,2),r("aColor",4,3),r("aBorderColor",4,7),r("aBorderWidth",1,11),r("aShadowColor",4,12),r("aShadowSize",1,16),r("aShadowOffsetX",1,17),r("aShadowOffsetY",1,18),r("aShapeType",1,19),r("aImageUV0",2,20),r("aImageUV1",2,22),r("aImageAspect",1,24),t.bindVertexArray(null)}_initEdgeBuffers(){if(!this._edgeProgram)throw new o("Edge program not initialized.");const t=this._gl;this._edgeVao=t.createVertexArray(),t.bindVertexArray(this._edgeVao);const e=new Float32Array([-1,-1,1,-1,-1,1,1,1]),i=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,i),t.bufferData(t.ARRAY_BUFFER,e,t.STATIC_DRAW);const n=t.getAttribLocation(this._edgeProgram,"aQuadPosition");t.enableVertexAttribArray(n),t.vertexAttribPointer(n,2,t.FLOAT,!1,0,0),this._edgeInstanceBuffer=t.createBuffer(),t.bindBuffer(t.ARRAY_BUFFER,this._edgeInstanceBuffer);const s=(e,i,n)=>{const s=t.getAttribLocation(this._edgeProgram,e);t.enableVertexAttribArray(s),t.vertexAttribPointer(s,i,t.FLOAT,!1,100,4*n),t.vertexAttribDivisor(s,1)};s("aStart",2,0),s("aEnd",2,2),s("aControl",2,4),s("aWidth",1,6),s("aEdgeType",1,7),s("aLoopbackRadius",1,8),s("aArrowSize",1,9),s("aArrowTip",2,10),s("aArrowDir",2,12),s("aColor",4,14),s("aShadowColor",4,18),s("aShadowSize",1,22),s("aShadowOffsetX",1,23),s("aShadowOffsetY",1,24),t.bindVertexArray(null)}_initLabelBuffers(){if(!this._labelProgram)throw new o("Label program not initialized.");const t=this._gl;this._labelVao=t.createVertexArray(),t.bindVertexArray(this._labelVao);const e=new Float32Array([-1,-1,1,-1,-1,1,1,1]),i=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,i),t.bufferData(t.ARRAY_BUFFER,e,t.STATIC_DRAW);const n=t.getAttribLocation(this._labelProgram,"aQuadPosition");t.enableVertexAttribArray(n),t.vertexAttribPointer(n,2,t.FLOAT,!1,0,0),this._labelInstanceBuffer=t.createBuffer(),t.bindBuffer(t.ARRAY_BUFFER,this._labelInstanceBuffer);const s=(e,i,n)=>{const s=t.getAttribLocation(this._labelProgram,e);t.enableVertexAttribArray(s),t.vertexAttribPointer(s,i,t.FLOAT,!1,32,4*n),t.vertexAttribDivisor(s,1)};s("aLabelCenter",2,0),s("aLabelSize",2,2),s("aLabelUV0",2,4),s("aLabelUV1",2,6),t.bindVertexArray(null)}_resolveColor(t){if(!t)return[1,0,0,1];if(t instanceof F)return[t.rgb.r/255,t.rgb.g/255,t.rgb.b/255,1];const e=t.match(/^rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+))?\s*\)$/);if(e)return[parseInt(e[1])/255,parseInt(e[2])/255,parseInt(e[3])/255,void 0!==e[4]?parseFloat(e[4]):1];const i=new F(t);return[i.rgb.r/255,i.rgb.g/255,i.rgb.b/255,1]}_buildNodeColorCache(t){this._nodeColorCache.clear();for(let e=0;et.isSelected()||t.isHovered()),S=x&&t.getEdges().some(t=>t.isSelected()||t.isHovered());let T=null,E=null,P=null,A=null;if(!v){const e=t.getNodes();T=new Float64Array(e.length),E=new Float64Array(e.length),P=new Float64Array(e.length),A=new Map;for(let t=0;t0)if(I=1.5*B+3*(x||1),0===C){const t=a-o,e=h-r,i=Math.sqrt(t*t+e*e);i>0&&(O=t/i,k=e/i,L=a-O*l,R=h-k*l)}else if(1===C){let t=1,e=.5,i=1;for(let n=0;n<8;n++){const n=.5*(e+i),s=1-n,d=s*s*o+2*n*s*M+n*n*a,u=s*s*r+2*n*s*N+n*n*h,c=Math.sqrt(Math.pow(d-a,2)+Math.pow(u-h,2));if(Math.abs(c-l)<.1){t=n;break}c>l?e=n:i=n,t=n}const n=1-t;L=n*n*o+2*t*n*M+t*t*a,R=n*n*r+2*t*n*N+t*t*h;const s=2*n*(M-o)+2*t*(a-M),d=2*n*(N-r)+2*t*(h-N),u=Math.sqrt(s*s+d*d);u>0&&(O=s/u,k=d/u)}else{let t=.8,e=.6,i=1;for(let n=0;n<8;n++){const n=.5*(e+i),s=2*n*Math.PI,a=M+D*Math.cos(s),h=N-D*Math.sin(s),l=Math.sqrt(Math.pow(a-o,2)+Math.pow(h-r,2));if(Math.abs(l-d)<.1){t=n;break}l>d?i=n:e=n,t=n}const n=2*t*Math.PI;L=M+D*Math.cos(n),R=N-D*Math.sin(n);const s=-2*t*Math.PI+.45*Math.PI;O=Math.cos(s),k=Math.sin(s)}m[v]=o,m[v+1]=r,m[v+2]=a,m[v+3]=h,m[v+4]=M,m[v+5]=N,m[v+6]=x,m[v+7]=C,m[v+8]=D,m[v+9]=I,m[v+10]=L,m[v+11]=R,m[v+12]=O,m[v+13]=k,m[v+14]=b[0],m[v+15]=b[1],m[v+16]=b[2],m[v+17]=b[3]*w,m[v+18]=p[0],m[v+19]=p[1],m[v+20]=p[2],m[v+21]=p[3]*w,m[v+22]=c,m[v+23]=_,m[v+24]=g}l.useProgram(this._edgeProgram),this._setViewUniforms(this._edgeProgram),l.bindBuffer(l.ARRAY_BUFFER,this._edgeInstanceBuffer),v||(l.bufferData(l.ARRAY_BUFFER,m.byteLength,l.STREAM_DRAW),l.bufferSubData(l.ARRAY_BUFFER,0,m));const C=this.transform.k<=.2,M=l.getUniformLocation(this._edgeProgram,"uSimpleMode");if(l.uniform1i(M,C?1:0),l.bindVertexArray(this._edgeVao),this._timerExt&&this._timerEdgeQueries.length>0){const t=this._timerEdgeQueries[this._timerQueryIdx],e=this._pollTimerQuery(t);null!==e&&(this._lastEdgeGpuMs=e),l.beginQuery(this._timerExt.TIME_ELAPSED_EXT,t)}l.drawArraysInstanced(l.TRIANGLE_STRIP,0,4,f.length),this._timerExt&&this._timerEdgeQueries.length>0&&l.endQuery(this._timerExt.TIME_ELAPSED_EXT),l.bindVertexArray(null),C&&l.enable(l.BLEND),l.useProgram(this._nodeProgram),this._setViewUniforms(this._nodeProgram),this._imageAtlas&&(this._imageAtlas.uploadIfDirty(),this._imageAtlas.bind(0),l.uniform1i(l.getUniformLocation(this._nodeProgram,"uImageAtlas"),0));const N=t.getNodes(),D=this.transform.k,I=25*N.length,L=null===this._nodeInstanceData||this._nodeInstanceData.length!==I;L&&(this._nodeInstanceData=new Float32Array(I));const R=this._nodeInstanceData,O=v&&!L;if(O||N.length===this._lastNodeCount&&!this._isColorCacheDirty||(this._buildNodeColorCache(N),this._buildNodeBorderColorCache(N),this._buildNodeShadowColorCache(N),this._isColorCacheDirty=!1,this._lastNodeCount=N.length),!O)for(let t=0;t=4){const t=e.isSelected()&&r.imageUrlSelected||r.imageUrl;if(t&&this._imageAtlas){const e=this._imageAtlas.getOrCreate(t);e&&(p=e.u0,m=e.v0,v=e.u1,x=e.v1,S=e.aspect)}}R[u+20]=p,R[u+21]=m,R[u+22]=v,R[u+23]=x,R[u+24]=S}if(l.bindBuffer(l.ARRAY_BUFFER,this._nodeInstanceBuffer),O||(l.bufferData(l.ARRAY_BUFFER,R.byteLength,l.STREAM_DRAW),l.bufferSubData(l.ARRAY_BUFFER,0,R)),this._buffersAreCurrent=!0,l.bindVertexArray(this._nodeVao),this._timerExt&&this._timerNodeQueries.length>0){const t=this._timerNodeQueries[this._timerQueryIdx],e=this._pollTimerQuery(t);null!==e&&(this._lastNodeGpuMs=e),l.beginQuery(this._timerExt.TIME_ELAPSED_EXT,t)}if(l.drawArraysInstanced(l.TRIANGLE_STRIP,0,4,N.length),this._timerExt&&this._timerNodeQueries.length>0&&(l.endQuery(this._timerExt.TIME_ELAPSED_EXT),this._timerQueryIdx=(this._timerQueryIdx+1)%this._timerNodeQueries.length),l.bindVertexArray(null),this._labelProgram&&this._labelCache&&this._settings.labelsIsEnabled){const t=this._labelCache,e=t.rasterFontPx;let i=0;const n=N.length+f.length,o=new Float32Array(8*n);for(let n=0;n0&&(t.uploadIfDirty(),l.useProgram(this._labelProgram),this._setViewUniforms(this._labelProgram),t.bind(0),l.uniform1i(l.getUniformLocation(this._labelProgram,"uAtlas"),0),l.bindBuffer(l.ARRAY_BUFFER,this._labelInstanceBuffer),l.bufferData(l.ARRAY_BUFFER,o.subarray(0,8*i),l.DYNAMIC_DRAW),l.bindVertexArray(this._labelVao),l.drawArraysInstanced(l.TRIANGLE_STRIP,0,4,i),l.bindVertexArray(null))}this._isInitiallyRendered=!0,this.emit(Us.RENDER_END,{durationMs:performance.now()-a})}reset(){this.transform=En;const t=this._gl;t.clearColor(0,0,0,0),t.clear(t.COLOR_BUFFER_BIT)}getFitZoomTransform(t){const e=t.getBoundingBox(),i=e.x+e.width/2,n=e.y+e.height/2,s=this.getSimulationViewRectangle(),o=s.height/(e.height*(1+this._settings.fitZoomMargin)),r=s.width/(e.width*(1+this._settings.fitZoomMargin)),a=Math.min(o,r),h=this.transform.k,l=Math.max(Math.min(a*h,this._settings.maxZoom),this._settings.minZoom),d=s.width/2*h*(1-l)-i*l,u=s.height/2*h*(1-l)-n*l;return En.translate(d,u).scale(l)}getSimulationPosition(t){const[e,i]=this.transform.invert([t.x,t.y]);return{x:e-this._width/2,y:i-this._height/2}}getCanvasPosition(t){const[e,i]=this.transform.apply([t.x+this._width/2,t.y+this._height/2]);return{x:e,y:i}}getSimulationViewRectangle(){const t=this.getSimulationPosition({x:0,y:0}),e=this.getSimulationPosition({x:this._width,y:this._height});return{x:t.x,y:t.y,width:e.x-t.x,height:e.y-t.y}}translateOriginToCenter(){this._isOriginCentered=!0}destroy(){var t,e;null===(t=this._dprObserveUnsubscribe)||void 0===t||t.call(this),this.removeAllListeners(),null===(e=this._gl.getExtension("WEBGL_lose_context"))||void 0===e||e.loseContext(),this._canvas.remove()}_setViewUniforms(t){const e=this._gl,i=this._isOriginCentered?this._width/2:0,n=this._isOriginCentered?this._height/2:0;e.uniform2f(e.getUniformLocation(t,"uResolution"),this._width,this._height),e.uniform2f(e.getUniformLocation(t,"uTranslation"),this.transform.x,this.transform.y),e.uniform1f(e.getUniformLocation(t,"uScale"),this.transform.k),e.uniform2f(e.getUniformLocation(t,"uOriginOffset"),i,n)}}class Mo{static getRenderer(t,e=zs.CANVAS,i){return e===zs.WEBGL?new Co(t,i):new fo(t,i)}}const No=t=>isFinite(t)?""+Math.round(1e3*t)/1e3:"0",Do=t=>t.replace(/&/g,"&").replace(//g,">").replace(/"/g,""").replace(/'/g,"'"),Io=(t,e,i)=>{const n=Object.keys(e).filter(t=>{const i=e[t];return null!=i&&""!==i}).map(t=>{const i=e[t];return`${t}="${"number"==typeof i?No(i):Do(String(i))}"`}).join(" "),s=n?`${t} ${n}`:t;return void 0===i?`<${s}/>`:`<${s}>${i}`},Lo=t=>t.map(t=>`${No(t.x)},${No(t.y)}`).join(" "),Ro=t=>({tag:"polygon",attributes:{points:Lo(t)}}),Oo=(t,e)=>{var i,n;if(null==t||""==`${t}`)return"";const s=new Gs(t,{position:e.position,textBaseline:e.textBaseline,properties:e.properties});if(!s.textLines.length||s.fontSize<=0)return"";const o=null!==(i=e.properties.fontFamily)&&void 0!==i?i:"Roboto, sans-serif",r=(null!==(n=e.properties.fontColor)&&void 0!==n?n:"#000000").toString(),a=1.2*s.fontSize,h=e.textBaseline===Ws.MIDDLE?"middle":"text-before-edge",l=ko(s,a),d=s.textLines.map((t,e)=>Io("tspan",{x:s.position.x,dy:0===e?0:a},Do(t))).join("");return`${l}${Io("text",{x:s.position.x,y:s.position.y,"font-size":s.fontSize,"font-family":o,fill:r,"text-anchor":"middle","dominant-baseline":h},d)}`},ko=(t,e)=>{const i=t.properties.fontBackgroundColor;if(!i)return"";const n=.12*t.fontSize,s=t.fontSize+2*n,o=t.textBaseline===Ws.MIDDLE?t.fontSize/2:0,r=i.toString();return t.textLines.map((i,a)=>{const h=i.length*t.fontSize*.6+2*n;return Io("rect",{x:t.position.x-h/2,y:t.position.y-o-n+a*e,width:h,height:s,fill:r})}).join("")},Bo=t=>{if("undefined"!=typeof document)try{const e=document.createElement("canvas");e.width=t.naturalWidth||t.width,e.height=t.naturalHeight||t.height;const i=e.getContext("2d");if(!i)return;return i.drawImage(t,0,0),e.toDataURL()}catch(t){return}},zo=t=>{var e,i,n;return t.shadowColor?{color:t.shadowColor,size:null!==(e=t.shadowSize)&&void 0!==e?e:0,offsetX:null!==(i=t.shadowOffsetX)&&void 0!==i?i:0,offsetY:null!==(n=t.shadowOffsetY)&&void 0!==n?n:0}:null},Uo=(t,e)=>{const{color:i,opacity:n}=jo(e.color.toString()),s=Math.max(.5*e.size,0),o=`shadow:${i}:${n}:${s}:${e.offsetX}:${e.offsetY}`;return t.add(o,o=>Fo(o,i,n,s,e.offsetX,e.offsetY,t.filterRegion))},Fo=(t,e,i,n,s,o,r)=>{const a=r?`filterUnits="userSpaceOnUse" x="${No(r.x)}" y="${No(r.y)}" width="${No(r.width)}" height="${No(r.height)}"`:'filterUnits="objectBoundingBox" x="-50%" y="-50%" width="200%" height="200%"';return``},jo=t=>{const e=t.match(/^rgba\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)\s*\)$/i);if(e)return{color:`rgb(${e[1]}, ${e[2]}, ${e[3]})`,opacity:Wo(Number(e[4]))};const i=t.match(/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i);if(i)return{color:`#${i[1]}${i[2]}${i[3]}`,opacity:parseInt(i[4],16)/255};const n=t.match(/^#([0-9a-f])([0-9a-f])([0-9a-f])([0-9a-f])$/i);return n?{color:`#${n[1]}${n[2]}${n[3]}`,opacity:parseInt(n[4],16)/15}:{color:t,opacity:1}},Wo=t=>isFinite(t)?Math.min(Math.max(t,0),1):1,Go=(t,e,i)=>{var n,s,o,r,a,h;const l=null===(n=null==i?void 0:i.isLabelEnabled)||void 0===n||n,d=null===(s=null==i?void 0:i.isShadowEnabled)||void 0===s||s,u=null===(o=null==i?void 0:i.isImageEnabled)||void 0===o||o,c=t.getCenter(),_=t.getRadius();if(_<=0)return"";const f=((t,e,i,n)=>{switch(t){case w.SQUARE:return{tag:"rect",attributes:{x:e-n,y:i-n,width:2*n,height:2*n}};case w.DIAMOND:return Ro([{x:e,y:i+n},{x:e+n,y:i},{x:e,y:i-n},{x:e-n,y:i}]);case w.TRIANGLE:return Ro(((t,e,i)=>{e+=.275*(i*=1.15);const n=2*i,s=Math.sqrt(3)*n/6;return[{x:t,y:e-(Math.sqrt(n*n-i*i)-s)},{x:t+i,y:e+s},{x:t-i,y:e+s}]})(e,i,n));case w.TRIANGLE_DOWN:return Ro(((t,e,i)=>{e-=.275*(i*=1.15);const n=2*i,s=Math.sqrt(3)*n/6;return[{x:t,y:e+(Math.sqrt(n*n-i*i)-s)},{x:t+i,y:e-s},{x:t-i,y:e-s}]})(e,i,n));case w.STAR:return Ro(((t,e,i)=>{e+=.1*(i*=.82);const n=[];for(let s=0;s<10;s++){const o=i*(s%2==0?1.3:.5);n.push({x:t+o*Math.sin(2*s*Math.PI/10),y:e-o*Math.cos(2*s*Math.PI/10)})}return n})(e,i,n));case w.HEXAGON:return Ro(((t,e,i,n)=>{const s=[],o=2*Math.PI/n;for(let r=0;r{const n=t.getBackgroundImage();if(!n||!n.width||!n.height)return"";const s=((t,e)=>{var i,n;const s=Bo(e);if(s)return s;const o=t.getStyle();return t.isSelected()&&o.imageUrlSelected?o.imageUrlSelected:null!==(n=null!==(i=o.imageUrl)&&void 0!==i?i:e.src)&&void 0!==n?n:void 0})(t,n);if(!s)return"";const o=t.getCenter(),r=t.getRadius(),a=Object.keys(i.attributes).map(t=>`${t}=${i.attributes[t]}`).join(","),h=e.add(`clip:${i.tag}:${a}`,t=>Io("clipPath",{id:t},Io(i.tag,i.attributes)));return Io("image",{href:s,"xlink:href":s,x:o.x-r,y:o.y-r,width:2*r,height:2*r,preserveAspectRatio:"xMidYMid slice","clip-path":`url(#${h})`})})(t,e,f):"",y=d&&t.hasShadow()?zo(t.getStyle()):null;let x;if(v||y){let t=`${Io(f.tag,Object.assign(Object.assign({},f.attributes),{fill:g}))}${v}`;y&&(t=Io("g",{filter:`url(#${Uo(e,y)})`},t)),x=`${t}${p?Io(f.tag,Object.assign(Object.assign(Object.assign({},f.attributes),{fill:"none"}),m)):""}`}else x=Io(f.tag,Object.assign(Object.assign(Object.assign({},f.attributes),{fill:g}),m));const b=l?Zo(t):"";return Io("g",{},`${x}${b}`)},Zo=t=>{const e=t.getLabel();if(!e)return"";const i=t.getCenter(),n=1.2*t.getBorderedRadius(),s=t.getStyle();return Oo(e,{position:{x:i.x,y:i.y+n},textBaseline:Ws.TOP,properties:{fontBackgroundColor:s.fontBackgroundColor,fontColor:s.fontColor,fontFamily:s.fontFamily,fontSize:s.fontSize}})},Ho=[{x:0,y:0},{x:-1,y:.4},{x:-1,y:-.4}],Xo=(t,e,i)=>{var n,s,o;const r=t.getWidth();if(!r)return"";const a=null===(n=null==i?void 0:i.isLabelEnabled)||void 0===n||n,h=null===(s=null==i?void 0:i.isShadowEnabled)||void 0===s||s,l=(null!==(o=t.getColor())&&void 0!==o?o:"#000000").toString(),d=Vo(t,l),u=qo(t,r,l),c=h&&t.hasShadow()?zo(t.getStyle()):null;let _=`${d}${u}`;c&&(_=Io("g",{filter:`url(#${Uo(e,c)})`},_));const f=a?Ko(t):"";return Io("g",{},`${_}${f}`)},qo=(t,e,i)=>{const n=t.getLineDashPattern(),s={stroke:i,"stroke-width":e,fill:"none","stroke-dasharray":n?n.join(" "):void 0};if(t instanceof k){const e=t.startNode.getCenter(),i=t.endNode.getCenter(),n=`M ${No(e.x)} ${No(e.y)} L ${No(i.x)} ${No(i.y)}`;return Io("path",Object.assign({d:n},s))}if(t instanceof B){const e=t.startNode.getCenter(),i=t.endNode.getCenter(),n=t.getCurvedControlPoint(),o=`M ${No(e.x)} ${No(e.y)} Q ${No(n.x)} ${No(n.y)} ${No(i.x)} ${No(i.y)}`;return Io("path",Object.assign({d:o},s))}if(t instanceof z){const{x:e,y:i,radius:n}=t.getCircularData();return Io("circle",Object.assign({cx:e,cy:i,r:n},s))}return""},Vo=(t,e)=>{if(0===t.getStyle().arrowSize)return"";const i=Yo(t);if(!i)return"";const n=$o(Ho,i).map(t=>`${No(t.x)},${No(t.y)}`).join(" ");return Io("polygon",{points:n,fill:e})},Yo=t=>t instanceof k?eo(t):t instanceof B?Ys(t):t instanceof z?Qs(t):null,$o=(t,e)=>t.map(t=>{const i=t.x*Math.cos(e.angle)-t.y*Math.sin(e.angle),n=t.x*Math.sin(e.angle)+t.y*Math.cos(e.angle);return{x:e.point.x+e.length*i,y:e.point.y+e.length*n}}),Ko=t=>{const e=t.getLabel();if(!e)return"";const i=t.getStyle();return Oo(e,{position:t.getCenter(),textBaseline:Ws.MIDDLE,properties:{fontBackgroundColor:i.fontBackgroundColor,fontColor:i.fontColor,fontFamily:i.fontFamily,fontSize:i.fontSize}})};class Qo{constructor(t){this.filterRegion=t,this._idBySignature=new Map,this._entries=[],this._counter=0}add(t,e){const i=this._idBySignature.get(t);if(void 0!==i)return i;const n=`orb-def-${this._counter}`;return this._counter+=1,this._idBySignature.set(t,n),this._entries.push(e(n)),n}toSVG(){return this._entries.length?`${this._entries.join("")}`:""}}const Jo=(t,e={})=>{var i,n,s,o;const r=null!==(i=e.padding)&&void 0!==i?i:20,a=null===(n=e.isLabelEnabled)||void 0===n||n,h=null===(s=e.isShadowEnabled)||void 0===s||s,l=null===(o=e.isImageEnabled)||void 0===o||o,d=t.getNodes(),u=t.getEdges(),c=tr(d,u,a,h),_=c.x-r,f=c.y-r,g=Math.max(c.width+2*r,1),p=Math.max(c.height+2*r,1),m=new Qo({x:_,y:f,width:g,height:p}),v=[];e.backgroundColor&&v.push(Io("rect",{x:_,y:f,width:g,height:p,fill:e.backgroundColor.toString()}));for(let t=0;t{const s={minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0};for(let e=0;e{et.maxX&&(t.maxX=e),i>t.maxY&&(t.maxY=i)},ir=(t,e,i,n,s)=>{er(t,e-n,i-s),er(t,e+n,i+s)},nr=(t,e,i,n)=>{var s;if(e.getRadius()<=0)return;const o=e.getCenter(),r=e.getBorderedRadius(),a=n?rr(e.hasShadow(),e.getStyle()):0;if(ir(t,o.x,o.y,r+a,r+a),i&&e.getLabel()){const i=e.getStyle(),n=o.y+1.2*e.getBorderedRadius();or(t,e.getLabel(),o.x,n,null!==(s=i.fontSize)&&void 0!==s?s:4,!1)}},sr=(t,e,i,n)=>{var s;if(!e.getWidth())return;const o=e.getStyle(),r=n?rr(e.hasShadow(),o):0;if(e instanceof z){const i=e.getCircularData();ir(t,i.x,i.y,i.radius+r,i.radius+r)}else if(e instanceof B){const i=e.getCurvedControlPoint();ir(t,i.x,i.y,r,r)}if(i&&e.getLabel()){const i=e.getCenter();or(t,e.getLabel(),i.x,i.y,null!==(s=o.fontSize)&&void 0!==s?s:4,!0)}},or=(t,e,i,n,s,o)=>{if(s<=0)return;const r=`${e}`.split("\n"),a=.12*s,h=r.reduce((t,e)=>Math.max(t,e.trim().length),0)*s*.6+2*a,l=r.length*s*1.2+2*a,d=o?n-l/2:n;er(t,i-h/2,d),er(t,i+h/2,d+l)},rr=(t,e)=>{var i,n,s;return t&&e.shadowColor?(null!==(i=e.shadowSize)&&void 0!==i?i:0)+Math.max(Math.abs(null!==(n=e.shadowOffsetX)&&void 0!==n?n:0),Math.abs(null!==(s=e.shadowOffsetY)&&void 0!==s?s:0)):0};class ar{constructor(t){this._graph=t}selectNodeById(t,e){const i=this._graph.getNodeById(t);return!!i&&(Es(i,e),!0)}selectNodesByIds(t,e){const i=[];for(let e=0;e{let i=0;for(let n=0;n{let i=0;for(let n=0;n{let i=0;for(let n=0;n{let i=0;for(let n=0;n{Os(t,r.HOVERED)})(e),!0)}unhoverAll(){const{changedCount:t}=Ls(this._graph);return t}}const hr={isBackgroundDrag:!0},lr=t=>!!t&&!0===t.isBackgroundDrag;class dr{constructor(t,i){var n,o,r,a,h,l,d,u;this._simulatorUsesGPU=!1,this._simulationStartedAt=Date.now(),this._assignPositions=t=>{if(this._settings.getPosition)for(let e=0;e!(t.button||t.ctrlKey&&"wheel"!==t.type||"wheel"!==t.type&&this._isBackgroundDragModifierActive(t)),this._dragFilter=t=>!(t.button||!this._isBackgroundDragModifierActive(t)&&t.ctrlKey),this.dragSubject=t=>{var e;const i=this.getCanvasMousePosition(t.sourceEvent),n=null===(e=this._renderer)||void 0===e?void 0:e.getSimulationPosition(i);return this._graph.getNearestNode(n)||(this._isBackgroundDragModifierActive(t.sourceEvent)?hr:void 0)},this.dragStarted=t=>{if(lr(t.subject))return void this._emitBackgroundDrag(e.BACKGROUND_DRAG_START,t.sourceEvent);if(!this._settings.interaction.isDragEnabled)return;const i=this.getCanvasMousePosition(t.sourceEvent),n=this._renderer.getSimulationPosition(i);this._events.emit(e.NODE_DRAG_START,{node:t.subject,event:t.sourceEvent,localPoint:n,globalPoint:i}),this._dragStartPosition=i},this.dragged=t=>{if(lr(t.subject))return void this._emitBackgroundDrag(e.BACKGROUND_DRAG,t.sourceEvent);if(!this._settings.interaction.isDragEnabled)return;const i=this.getCanvasMousePosition(t.sourceEvent),n=this._renderer.getSimulationPosition(i);Rn(this._dragStartPosition,i)||(this._dragStartPosition=void 0),this._simulator.dragNode(t.subject.getId(),n),this._events.emit(e.NODE_DRAG,{node:t.subject,event:t.sourceEvent,localPoint:n,globalPoint:i})},this.dragEnded=t=>{if(lr(t.subject))return void this._emitBackgroundDrag(e.BACKGROUND_DRAG_END,t.sourceEvent);if(!this._settings.interaction.isDragEnabled)return;const i=this.getCanvasMousePosition(t.sourceEvent),n=this._renderer.getSimulationPosition(i);Rn(this._dragStartPosition,i)||this._simulator.endDragNode(t.subject.getId()),this._events.emit(e.NODE_DRAG_END,{node:t.subject,event:t.sourceEvent,localPoint:n,globalPoint:i})},this.zoomed=t=>{this._settings.interaction.isZoomEnabled&&(this._renderer.transform=t.transform,setTimeout(()=>{this.render(),this._events.emit(e.TRANSFORM,{transform:t.transform})},1))},this.mouseMoved=t=>{const i=this.getCanvasMousePosition(t),n=this._renderer.getSimulationPosition(i),s=this._strategy.onMouseMove(this._graph,n),o=s.changedSubject;o&&s.isStateChanged&&(E(o)&&this._events.emit(e.NODE_HOVER,{node:o,event:t,localPoint:n,globalPoint:i}),L(o)&&this._events.emit(e.EDGE_HOVER,{edge:o,event:t,localPoint:n,globalPoint:i})),this._events.emit(e.MOUSE_MOVE,{subject:o,event:t,localPoint:n,globalPoint:i}),s.isStateChanged&&(this._invalidateStyles(),this.render())},this.mouseClicked=t=>{const i=this.getCanvasMousePosition(t),n=this._renderer.getSimulationPosition(i),s=this._strategy.onMouseClick(this._graph,n,{isAppend:t.shiftKey}),o=s.changedSubject;o&&(E(o)&&this._events.emit(e.NODE_CLICK,{node:o,event:t,localPoint:n,globalPoint:i}),L(o)&&this._events.emit(e.EDGE_CLICK,{edge:o,event:t,localPoint:n,globalPoint:i})),this._events.emit(e.MOUSE_CLICK,{subject:o,event:t,localPoint:n,globalPoint:i}),(s.isStateChanged||s.changedSubject)&&(this._invalidateStyles(),this.render())},this.mouseRightClicked=t=>{const i=this.getCanvasMousePosition(t),n=this._renderer.getSimulationPosition(i),s=this._strategy.onMouseRightClick(this._graph,n),o=s.changedSubject;o&&(E(o)&&this._events.emit(e.NODE_RIGHT_CLICK,{node:o,event:t,localPoint:n,globalPoint:i}),L(o)&&this._events.emit(e.EDGE_RIGHT_CLICK,{edge:o,event:t,localPoint:n,globalPoint:i})),this._events.emit(e.MOUSE_RIGHT_CLICK,{subject:o,event:t,localPoint:n,globalPoint:i}),(s.isStateChanged||s.changedSubject)&&(this._invalidateStyles(),this.render())},this.mouseDoubleClicked=t=>{const i=this.getCanvasMousePosition(t),n=this._renderer.getSimulationPosition(i),s=this._strategy.onMouseDoubleClick(this._graph,n),o=s.changedSubject;o&&(E(o)&&this._events.emit(e.NODE_DOUBLE_CLICK,{node:o,event:t,localPoint:n,globalPoint:i}),L(o)&&this._events.emit(e.EDGE_DOUBLE_CLICK,{edge:o,event:t,localPoint:n,globalPoint:i})),this._events.emit(e.MOUSE_DOUBLE_CLICK,{subject:o,event:t,localPoint:n,globalPoint:i}),(s.isStateChanged||s.changedSubject)&&(this._invalidateStyles(),this.render())},this.zoomIn=t=>{_e(this._renderer.canvas).transition().duration(this._settings.zoomFitTransitionMs).ease(Ae).call(this._d3Zoom.scaleBy,1.2).on("end",()=>this.render(t))},this.zoomOut=t=>{_e(this._renderer.canvas).transition().duration(this._settings.zoomFitTransitionMs).ease(Ae).call(this._d3Zoom.scaleBy,.8).on("end",()=>this.render(t))},this._invalidateStyles=()=>{var t,e;null===(e=(t=this._renderer).invalidateStyles)||void 0===e||e.call(t)},this._update=t=>{t&&"x"in t&&"y"in t&&"id"in t&&this._simulator.patchData({nodes:[{x:t.x,y:t.y,sx:t.x,sy:t.y,fx:t.x,fy:t.y,id:t.id}],edges:[]}),this._invalidateStyles(),this.render()},this._initializeSimulationEvents=()=>{this._simulator.on(On.SIMULATION_START,()=>{this._simulationStartedAt=Date.now(),this._events.emit(e.SIMULATION_START,void 0)});const t=()=>{var t,e;return null===(e=(t=this._renderer).invalidateBuffers)||void 0===e?void 0:e.call(t)};this._simulator.on(On.SIMULATION_PROGRESS,i=>{this._graph.setNodePositions(i.nodes),t(),this._events.emit(e.SIMULATION_STEP,{progress:i.progress}),this.render()}),this._simulator.on(On.SIMULATION_END,i=>{this._graph.setNodePositions(i.nodes),t(),this.render(),this._events.emit(e.SIMULATION_END,{durationMs:Date.now()-this._simulationStartedAt})}),this._simulator.on(On.SIMULATION_STEP,e=>{this._graph.setNodePositions(e.nodes),t(),this.render()}),this._simulator.on(On.NODE_DRAG,e=>{this._graph.setNodePositions(e.nodes),t(),this.render()}),this._simulator.on(On.SETTINGS_UPDATE,t=>{var e;this._settings.layout.options=null===(e=t.settings)||void 0===e?void 0:e.options})},this._container=t,this._settings=Object.assign(Object.assign({getPosition:null==i?void 0:i.getPosition,zoomFitTransitionMs:200,isOutOfBoundsDragEnabled:!1,areCoordinatesRounded:!0},i),{layout:Object.assign({type:"force"},null!==(n=null==i?void 0:i.layout)&&void 0!==n?n:ns),render:Object.assign({},null==i?void 0:i.render),strategy:Object.assign({isDefaultHoverEnabled:!0,isDefaultSelectEnabled:!0,isDefaultMultiSelectEnabled:!1,isDefaultSelectCascadeEnabled:!0},null==i?void 0:i.strategy),interaction:Object.assign(Object.assign({isDragEnabled:!0,isZoomEnabled:!0},null==i?void 0:i.interaction),{backgroundDrag:Object.assign({isEnabled:!1,modifier:"shift"},null===(o=null==i?void 0:i.interaction)||void 0===o?void 0:o.backgroundDrag)})}),this._graph=new Ts(void 0,{onLoadedImages:()=>{this._renderer.isInitiallyRendered&&this.render()},listeners:[this._update]}),this._graph.setDefaultStyle(X()),this._events=new s,this._interaction=new ar(this._graph),this._strategy=new Bs({isDefaultSelectEnabled:null!==(r=this._settings.strategy.isDefaultSelectEnabled)&&void 0!==r&&r,isDefaultHoverEnabled:null!==(a=this._settings.strategy.isDefaultHoverEnabled)&&void 0!==a&&a,isDefaultMultiSelectEnabled:null===(h=this._settings.strategy.isDefaultMultiSelectEnabled)||void 0===h||h,isDefaultSelectCascadeEnabled:null===(l=this._settings.strategy.isDefaultSelectCascadeEnabled)||void 0===l||l}),this._rendererType=null!==(u=null===(d=null==i?void 0:i.render)||void 0===d?void 0:d.type)&&void 0!==u?u:zs.CANVAS,this._initRenderer(this._rendererType),this._simulator=xs.getSimulator(this._settings.layout),this._simulatorUsesGPU=dr._needsGPU(this._settings.layout),this._initializeSimulationEvents(),this._graph.setSettings({onSetupData:()=>{this._assignPositions(this._graph.getNodes());const t=this._graph.getNodePositions(),e=this._graph.getEdgePositions();this._simulator.setupData({nodes:t,edges:e})},onMergeData:t=>{var e,i;const n=new Set(null===(e=t.nodes)||void 0===e?void 0:e.map(t=>t.id)),s=t=>n.has(t.getId()),o=new Set(null===(i=t.edges)||void 0===i?void 0:i.map(t=>t.id));this._assignPositions(this._graph.getNodes(s));const r=this._graph.getNodePositions(s),a=this._graph.getEdgePositions(t=>o.has(t.getId()));this._simulator.mergeData({nodes:r,edges:a})},onRemoveData:t=>{this._simulator.deleteData(t)}})}_initRenderer(t){try{this._renderer=Mo.getRenderer(this._container,t,this._settings.render)}catch(t){throw this._container.textContent=t.message,t}this._renderer.on(Us.RENDER_START,()=>{this._events.emit(e.RENDER_START,void 0)}),this._renderer.on(Us.RENDER_END,t=>{this._events.emit(e.RENDER_END,t)}),this._renderer.on(Us.RESIZE,()=>{this._renderer.isInitiallyRendered&&this._renderer.render(this._graph)}),this._renderer.translateOriginToCenter(),this._settings.render=this._renderer.getSettings(),this._d3Zoom=function(){var t,e,i,n=Cn,s=Mn,o=Ln,r=Dn,a=In,h=[0,1/0],l=[[-1/0,-1/0],[1/0,1/0]],d=250,u=Me,c=tt("start","zoom","end"),_=0,f=10;function g(t){t.property("__zoom",Nn).on("wheel.zoom",S,{passive:!1}).on("mousedown.zoom",w).on("dblclick.zoom",T).filter(a).on("touchstart.zoom",E).on("touchmove.zoom",P).on("touchend.zoom touchcancel.zoom",A).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function p(t,e){return(e=Math.max(h[0],Math.min(h[1],e)))===t.k?t:new Tn(e,t.x,t.y)}function m(t,e,i){var n=e[0]-i[0]*t.k,s=e[1]-i[1]*t.k;return n===t.x&&s===t.y?t:new Tn(t.k,n,s)}function v(t){return[(+t[0][0]+ +t[1][0])/2,(+t[0][1]+ +t[1][1])/2]}function y(t,e,i,n){t.on("start.zoom",function(){x(this,arguments).event(n).start()}).on("interrupt.zoom end.zoom",function(){x(this,arguments).event(n).end()}).tween("zoom",function(){var t=this,o=arguments,r=x(t,o).event(n),a=s.apply(t,o),h=null==i?v(a):"function"==typeof i?i.apply(t,o):i,l=Math.max(a[1][0]-a[0][0],a[1][1]-a[0][1]),d=t.__zoom,c="function"==typeof e?e.apply(t,o):e,_=u(d.invert(h).concat(l/d.k),c.invert(h).concat(l/c.k));return function(t){if(1===t)t=c;else{var e=_(t),i=l/e[2];t=new Tn(i,h[0]-e[0]*i,h[1]-e[1]*i)}r.zoom(null,t)}})}function x(t,e,i){return!i&&t.__zooming||new b(t,e)}function b(t,e){this.that=t,this.args=e,this.active=0,this.sourceEvent=null,this.extent=s.apply(t,e),this.taps=0}function S(t,...e){if(n.apply(this,arguments)){var i=x(this,e).event(t),s=this.__zoom,a=Math.max(h[0],Math.min(h[1],s.k*Math.pow(2,r.apply(this,arguments)))),d=fe(t);if(i.wheel)i.mouse[0][0]===d[0]&&i.mouse[0][1]===d[1]||(i.mouse[1]=s.invert(i.mouse[0]=d)),clearTimeout(i.wheel);else{if(s.k===a)return;i.mouse=[d,s.invert(d)],ti(this),i.start()}An(t),i.wheel=setTimeout(function(){i.wheel=null,i.end()},150),i.zoom("mouse",o(m(p(s,a),i.mouse[0],i.mouse[1]),i.extent,l))}}function w(t,...e){if(!i&&n.apply(this,arguments)){var s=t.currentTarget,r=x(this,e,!0).event(t),a=_e(t.view).on("mousemove.zoom",function(t){if(An(t),!r.moved){var e=t.clientX-d,i=t.clientY-u;r.moved=e*e+i*i>_}r.event(t).zoom("mouse",o(m(r.that.__zoom,r.mouse[0]=fe(t,s),r.mouse[1]),r.extent,l))},!0).on("mouseup.zoom",function(t){a.on("mousemove.zoom mouseup.zoom",null),xe(t.view,r.moved),An(t),r.event(t).end()},!0),h=fe(t,s),d=t.clientX,u=t.clientY;ye(t.view),Pn(t),r.mouse=[h,this.__zoom.invert(h)],ti(this),r.start()}}function T(t,...e){if(n.apply(this,arguments)){var i=this.__zoom,r=fe(t.changedTouches?t.changedTouches[0]:t,this),a=i.invert(r),h=i.k*(t.shiftKey?.5:2),u=o(m(p(i,h),r,a),s.apply(this,e),l);An(t),d>0?_e(this).transition().duration(d).call(y,u,r,t):_e(this).call(g.transform,u,r,t)}}function E(i,...s){if(n.apply(this,arguments)){var o,r,a,h,l=i.touches,d=l.length,u=x(this,s,i.changedTouches.length===d).event(i);for(Pn(i),r=0;ru}h.mouse("drag",n)}function g(t){_e(t.view).on("mousemove.drag mouseup.drag",null),xe(t.view,i),ve(t),h.mouse("end",t)}function p(t,e){if(s.call(this,t,e)){var i,n,r=t.changedTouches,a=o.call(this,t,e),h=r.length;for(i=0;i{this.recenter()}),this._simulator.setupData({nodes:n,edges:s})}t.strategy&&(c(t.strategy.isDefaultHoverEnabled)&&(this._settings.strategy.isDefaultHoverEnabled=t.strategy.isDefaultHoverEnabled,this._strategy.isHoverEnabled=this._settings.strategy.isDefaultHoverEnabled),c(t.strategy.isDefaultSelectEnabled)&&(this._settings.strategy.isDefaultSelectEnabled=t.strategy.isDefaultSelectEnabled,this._strategy.isSelectEnabled=this._settings.strategy.isDefaultSelectEnabled),c(t.strategy.isDefaultMultiSelectEnabled)&&(this._settings.strategy.isDefaultMultiSelectEnabled=t.strategy.isDefaultMultiSelectEnabled,this._strategy.isMultiSelectEnabled=this._settings.strategy.isDefaultMultiSelectEnabled),c(t.strategy.isDefaultSelectCascadeEnabled)&&(this._settings.strategy.isDefaultSelectCascadeEnabled=t.strategy.isDefaultSelectCascadeEnabled,this._strategy.isSelectCascadeEnabled=this._settings.strategy.isDefaultSelectCascadeEnabled)),t.interaction&&(c(t.interaction.isDragEnabled)&&(this._settings.interaction.isDragEnabled=t.interaction.isDragEnabled),c(t.interaction.isZoomEnabled)&&(this._settings.interaction.isZoomEnabled=t.interaction.isZoomEnabled),t.interaction.backgroundDrag&&(this._settings.interaction.backgroundDrag=Object.assign(Object.assign({},this._settings.interaction.backgroundDrag),t.interaction.backgroundDrag)))}static _needsGPU(t){var e;return"force"===t.type&&!!(null===(e=t.options)||void 0===e?void 0:e.useGPU)}render(t){t&&(this._simulator.isSimulationRunning()?this._simulator.once(On.SIMULATION_END,()=>{this._renderer.once(Us.RENDER_END,()=>t())}):this._renderer.once(Us.RENDER_END,()=>t())),this._renderer.render(this._graph)}recenter(t,e){"function"==typeof t&&(e=t,t=void 0);const i=(t=>{var e,i,n,s,o,r;if("hierarchical"===t.type){const n=t.options;return{anchorX:null!==(e=n.anchorX)&&void 0!==e?e:"horizontal"===n.orientation?n.reversed?"end":"start":"center",anchorY:null!==(i=n.anchorY)&&void 0!==i?i:"vertical"===n.orientation?n.reversed?"end":"start":"center"}}return{anchorX:null!==(s=null===(n=t.options)||void 0===n?void 0:n.anchorX)&&void 0!==s?s:"center",anchorY:null!==(r=null===(o=t.options)||void 0===o?void 0:o.anchorY)&&void 0!==r?r:"center"}})(this._settings.layout),n=Object.assign(Object.assign({},i),t),s=this._renderer.getFitZoomTransform(this._graph,n);_e(this._renderer.canvas).transition().duration(this._settings.zoomFitTransitionMs).ease(Ae).call(this._d3Zoom.transform,s).on("end",()=>this.render(e))}getSVG(t){return Jo(this._graph,Object.assign({backgroundColor:this._settings.render.backgroundColor},t))}destroy(){this._renderer.destroy(),this._simulator.terminate()}_isBackgroundDragModifierActive(t){var e;const i=this._settings.interaction.backgroundDrag;if(!(null==i?void 0:i.isEnabled))return!1;switch(null!==(e=i.modifier)&&void 0!==e?e:"shift"){case"shift":return t.shiftKey;case"ctrl":return t.ctrlKey;case"alt":return t.altKey;case"meta":return t.metaKey;case null:return!0;default:return!1}}_emitBackgroundDrag(t,e){const i=this.getCanvasMousePosition(e),n=this._renderer.getSimulationPosition(i);this._events.emit(t,{event:e,localPoint:n,globalPoint:i})}getCanvasMousePosition(t){var e,i,n,s;const o=this._renderer.canvas.getBoundingClientRect();let r=null!==(i=null!==(e=t.clientX)&&void 0!==e?e:t.pageX)&&void 0!==i?i:t.x,a=null!==(s=null!==(n=t.clientY)&&void 0!==n?n:t.pageY)&&void 0!==s?s:t.y;return r-=o.left,a-=o.top,this._settings.areCoordinatesRounded&&(r=Math.floor(r),a=Math.floor(a)),this._settings.isOutOfBoundsDragEnabled||(r=Math.max(0,Math.min(this._renderer.width,r)),a=Math.max(0,Math.min(this._renderer.height,a))),{x:r,y:a}}fixNodes(){this._simulator.fixNodes()}releaseNodes(){this._simulator.releaseNodes()}}var ur=i(481);class cr{constructor(t,e){var i,n,o,r,a,h,l,d,u,c,_,f;this._invalidateStyles=()=>{var t,e;null===(e=(t=this._renderer).invalidateStyles)||void 0===e||e.call(t)},this._update=()=>{this._invalidateStyles(),this.render()},this._container=t,this._graph=new Ts(void 0,{onLoadedImages:()=>{this._renderer.isInitiallyRendered&&this.render()},listeners:[this._update]}),this._graph.setDefaultStyle(X()),this._events=new s,this._interaction=new ar(this._graph),this._settings=Object.assign(Object.assign({areCollapsedContainerDimensionsAllowed:!1},e),{map:{zoomLevel:null!==(n=null===(i=e.map)||void 0===i?void 0:i.zoomLevel)&&void 0!==n?n:2,tile:null!==(r=null===(o=e.map)||void 0===o?void 0:o.tile)&&void 0!==r?r:{instance:new ur.TileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"),attribution:'Leaflet | Map data © OpenStreetMap contributors'},nodeSizeMode:null!==(h=null===(a=e.map)||void 0===a?void 0:a.nodeSizeMode)&&void 0!==h?h:"geographic"},render:Object.assign({type:zs.CANVAS},e.render),strategy:Object.assign({isDefaultHoverEnabled:!0,isDefaultSelectEnabled:!0,isDefaultMultiSelectEnabled:!1,isDefaultSelectCascadeEnabled:!0},null==e?void 0:e.strategy)}),this._strategy=new Bs({isDefaultSelectEnabled:null!==(l=this._settings.strategy.isDefaultSelectEnabled)&&void 0!==l&&l,isDefaultHoverEnabled:null!==(d=this._settings.strategy.isDefaultHoverEnabled)&&void 0!==d&&d,isDefaultMultiSelectEnabled:null===(u=this._settings.strategy.isDefaultMultiSelectEnabled)||void 0===u||u,isDefaultSelectCascadeEnabled:null===(c=this._settings.strategy.isDefaultSelectCascadeEnabled)||void 0===c||c}),this._rendererType=null!==(f=null===(_=null==e?void 0:e.render)||void 0===_?void 0:_.type)&&void 0!==f?f:zs.CANVAS,this._initRenderer(this._rendererType),this._map=this._initMap(),this._leaflet=this._initLeaflet(),this._handleTileChange()}_initRenderer(t){try{this._renderer=Mo.getRenderer(this._container,t,this._settings.render)}catch(t){throw this._container.textContent=t.message,t}this._renderer.on(Us.RENDER_END,t=>{this._events.emit(e.RENDER_END,t)}),this._renderer.on(Us.RESIZE,()=>{this._renderer.isInitiallyRendered&&(this._leaflet.invalidateSize(!1),this._renderer.render(this._graph))}),this._settings.render=this._renderer.getSettings(),this._renderer.canvas.style.zIndex="2",this._renderer.canvas.style.pointerEvents="none"}setRenderer(t){if(t===this._rendererType)return;this._renderer.destroy(),this._initRenderer(t),this._rendererType=t;const e=this._leaflet._mapPane._leaflet_pos,i=this._getStyleScale();this._renderer.transform=Object.assign(Object.assign({},e),{k:i}),this.render()}get data(){return this._graph}get events(){return this._events}get interaction(){return this._interaction}get leaflet(){return this._leaflet}get canvas(){return this._renderer.canvas}getSimulationPosition(t){const e=this._leaflet.containerPointToLayerPoint([t.x,t.y]);return this._toSimulationPoint(e)}getCanvasPosition(t){const e=this._getStyleScale(),i=this._leaflet.layerPointToContainerPoint([t.x*e,t.y*e]);return{x:i.x,y:i.y}}getSimulationViewRectangle(){const t=this._leaflet.getSize(),e=this.getSimulationPosition({x:0,y:0}),i=this.getSimulationPosition({x:t.x,y:t.y});return{x:e.x,y:e.y,width:i.x-e.x,height:i.y-e.y}}getSettings(){return m(this._settings)}setSettings(t){if(t.getGeoPosition&&(this._settings.getGeoPosition=t.getGeoPosition,this._updateGraphPositions()),t.map&&("number"==typeof t.map.zoomLevel&&(this._settings.map.zoomLevel=t.map.zoomLevel,this._leaflet.setZoom(t.map.zoomLevel)),t.map.tile&&(this._settings.map.tile=t.map.tile,this._handleTileChange()),t.map.nodeSizeMode&&t.map.nodeSizeMode!==this._settings.map.nodeSizeMode)){this._settings.map.nodeSizeMode=t.map.nodeSizeMode,this._updateGraphPositions();const e=this._leaflet._mapPane._leaflet_pos,i=this._getStyleScale();this._renderer.transform=Object.assign(Object.assign({},e),{k:i}),this._renderer.render(this._graph)}t.render&&(t.render.type&&t.render.type!==this._rendererType&&this.setRenderer(t.render.type),this._renderer.setSettings(t.render),this._settings.render=this._renderer.getSettings()),t.strategy&&(c(t.strategy.isDefaultHoverEnabled)&&(this._settings.strategy.isDefaultHoverEnabled=t.strategy.isDefaultHoverEnabled,this._strategy.isHoverEnabled=this._settings.strategy.isDefaultHoverEnabled),c(t.strategy.isDefaultSelectEnabled)&&(this._settings.strategy.isDefaultSelectEnabled=t.strategy.isDefaultSelectEnabled,this._strategy.isSelectEnabled=this._settings.strategy.isDefaultSelectEnabled),c(t.strategy.isDefaultMultiSelectEnabled)&&(this._settings.strategy.isDefaultMultiSelectEnabled=t.strategy.isDefaultMultiSelectEnabled,this._strategy.isMultiSelectEnabled=this._settings.strategy.isDefaultMultiSelectEnabled),c(t.strategy.isDefaultSelectCascadeEnabled)&&(this._settings.strategy.isDefaultSelectCascadeEnabled=t.strategy.isDefaultSelectCascadeEnabled,this._strategy.isSelectCascadeEnabled=this._settings.strategy.isDefaultSelectCascadeEnabled))}render(t){t&&this._renderer.once(Us.RENDER_END,()=>t()),this._updateGraphPositions(),this._renderer.render(this._graph)}zoomIn(t){this._leaflet.zoomIn(),null==t||t()}recenter(t){const e=this._graph.getBoundingBox(),i=this._getStyleScale(),n=this._leaflet.layerPointToLatLng([e.x*i,e.y*i]),s=this._leaflet.layerPointToLatLng([(e.x+e.width)*i,(e.y+e.height)*i]);this._leaflet.fitBounds(ur.latLngBounds(n,s)),null==t||t()}zoomOut(t){this._leaflet.zoomOut(),null==t||t()}getSVG(){throw new Error("SVG export is not supported on OrbMapView.")}destroy(){this._renderer.destroy(),this._leaflet.off(),this._leaflet.remove(),this._leaflet.getContainer().outerHTML=""}_initMap(){const t=document.createElement("div");return t.style.position="absolute",t.style.width="100%",t.style.height="100%",t.style.zIndex="1",t.style.cursor="default",this._container.appendChild(t),t}_initLeaflet(){const t=ur.map(this._map,{doubleClickZoom:!1,zoomControl:!1}).setView([0,0],this._settings.map.zoomLevel);return t.on("zoomstart",()=>{this._renderer.reset()}),t.on("zoom",t=>{var i,n;this._updateGraphPositions(),null===(n=(i=this._renderer).invalidateBuffers)||void 0===n||n.call(i);const s=t.target._mapPane._leaflet_pos,o=this._getStyleScale();this._renderer.transform=Object.assign(Object.assign({},s),{k:o}),this._renderer.render(this._graph),this._events.emit(e.TRANSFORM,{transform:Object.assign(Object.assign({},s),{k:o})})}),t.on("mousemove",t=>{const i=this._toSimulationPoint(t.layerPoint),n={x:t.containerPoint.x,y:t.containerPoint.y},s=this._strategy.onMouseMove(this._graph,i),o=s.changedSubject;o&&s.isStateChanged&&(E(o)&&this._events.emit(e.NODE_HOVER,{node:o,event:t.originalEvent,localPoint:i,globalPoint:n}),L(o)&&this._events.emit(e.EDGE_HOVER,{edge:o,event:t.originalEvent,localPoint:i,globalPoint:n})),this._events.emit(e.MOUSE_MOVE,{subject:o,event:t.originalEvent,localPoint:i,globalPoint:n}),s.isStateChanged&&(this._invalidateStyles(),this._renderer.render(this._graph))}),t.on("click contextmenu dblclick",t=>{const i=this._toSimulationPoint(t.layerPoint),n={x:t.containerPoint.x,y:t.containerPoint.y};if("contextmenu"===t.type){const s=this._strategy.onMouseRightClick(this._graph,i),o=s.changedSubject;o&&(E(o)&&this._events.emit(e.NODE_RIGHT_CLICK,{node:o,event:t.originalEvent,localPoint:i,globalPoint:n}),L(o)&&this._events.emit(e.EDGE_RIGHT_CLICK,{edge:o,event:t.originalEvent,localPoint:i,globalPoint:n})),this._events.emit(e.MOUSE_RIGHT_CLICK,{subject:o,event:t.originalEvent,localPoint:i,globalPoint:n}),s.isStateChanged&&(this._invalidateStyles(),this._renderer.render(this._graph))}else if("click"===t.type){const s=this._strategy.onMouseClick(this._graph,i,{isAppend:t.originalEvent.shiftKey}),o=s.changedSubject;o&&(E(o)&&this._events.emit(e.NODE_CLICK,{node:o,event:t.originalEvent,localPoint:i,globalPoint:n}),L(o)&&this._events.emit(e.EDGE_CLICK,{edge:o,event:t.originalEvent,localPoint:i,globalPoint:n})),this._events.emit(e.MOUSE_CLICK,{subject:o,event:t.originalEvent,localPoint:i,globalPoint:n}),(s.isStateChanged||s.changedSubject)&&(this._invalidateStyles(),this._renderer.render(this._graph))}else if("dblclick"===t.type){const s=this._strategy.onMouseDoubleClick(this._graph,i),o=s.changedSubject;if(o&&(E(o)&&this._events.emit(e.NODE_DOUBLE_CLICK,{node:o,event:t.originalEvent,localPoint:i,globalPoint:n}),L(o)&&this._events.emit(e.EDGE_DOUBLE_CLICK,{edge:o,event:t.originalEvent,localPoint:i,globalPoint:n})),this._events.emit(e.MOUSE_DOUBLE_CLICK,{subject:o,event:t.originalEvent,localPoint:i,globalPoint:n}),!o){const e=t.target._zoom+1;t.target.setZoomAround(t.layerPoint,e)}(s.isStateChanged||s.changedSubject)&&(this._invalidateStyles(),this._renderer.render(this._graph))}}),t.on("moveend",t=>{const e=t.target._mapPane._leaflet_pos,i=this._getStyleScale();this._renderer.transform=Object.assign(Object.assign({},e),{k:i}),this._renderer.render(this._graph)}),t.on("drag",t=>{const i=t.target._mapPane._leaflet_pos,n=this._getStyleScale();this._renderer.transform=Object.assign(Object.assign({},i),{k:n}),this._renderer.render(this._graph),this._events.emit(e.TRANSFORM,{transform:Object.assign(Object.assign({},i),{k:n})})}),t}_updateGraphPositions(){const t=this._graph.getNodes(),e=this._getStyleScale();for(let i=0;i{this._leaflet.attributionControl.setPrefix(t.attribution),this._leaflet.eachLayer(t=>this._leaflet.removeLayer(t)),t.instance.addTo(this._leaflet)})}}})(),n})()); \ No newline at end of file diff --git a/src/interactions/index.ts b/src/interactions/index.ts index dad1d52..ea16b0d 100644 --- a/src/interactions/index.ts +++ b/src/interactions/index.ts @@ -4,7 +4,6 @@ export { IRectangleSelectionStyle, IRectangleSelectionSelectEvent, IRectangleSelectionMode, - IRectangleSelectionEdgeMode, RectangleSelectionEventType, DEFAULT_RECTANGLE_SELECTION_STYLE, } from './shared'; diff --git a/src/interactions/rectangle-selection.ts b/src/interactions/rectangle-selection.ts index 03faca8..9232e51 100644 --- a/src/interactions/rectangle-selection.ts +++ b/src/interactions/rectangle-selection.ts @@ -2,12 +2,11 @@ import { Emitter } from '../utils/emitter.utils'; import { IOrbView } from '../views/shared'; import { OrbEventType, IOrbEventBackgroundDrag } from '../events'; import { getRectangleFromPoints, IPosition, RectangleArea } from '../common'; -import { INode, INodeBase } from '../models/node'; -import { IEdge, IEdgeBase } from '../models/edge'; +import { INodeBase } from '../models/node'; +import { IEdgeBase } from '../models/edge'; import { CLASS_NAME, DEFAULT_RECTANGLE_SELECTION_STYLE, - IRectangleSelectionEdgeMode, IRectangleSelectionMode, IRectangleSelectionOptions, IRectangleSelectionStyle, @@ -15,8 +14,10 @@ import { RectangleSelectionEventType, } from './shared'; +// Shift already enables the gesture, so mirror Shift-click's additive behavior: +// a plain Shift-drag adds to the selection, holding Ctrl/Cmd replaces it. const DEFAULT_RESOLVE_MODE = (event: MouseEvent): IRectangleSelectionMode => - event.ctrlKey || event.metaKey ? 'add' : 'replace'; + event.ctrlKey || event.metaKey ? 'replace' : 'add'; // Marquee selection built on Orb's public API: it listens for the view's neutral // BACKGROUND_DRAG_* events, draws its own DOM overlay, and applies the selection @@ -27,7 +28,6 @@ export class RectangleSelection extend > { private readonly _view: IOrbView; private readonly _resolveMode: (event: MouseEvent) => IRectangleSelectionMode; - private readonly _includeEdges: IRectangleSelectionEdgeMode; private readonly _style: IRectangleSelectionStyle; private _overlay?: HTMLDivElement; @@ -38,7 +38,6 @@ export class RectangleSelection extend super(); this._view = view; this._resolveMode = options?.resolveMode ?? DEFAULT_RESOLVE_MODE; - this._includeEdges = options?.includeEdges ?? 'none'; this._style = { ...DEFAULT_RECTANGLE_SELECTION_STYLE, ...options?.style }; this._view.events.on(OrbEventType.BACKGROUND_DRAG_START, this._onDragStart); @@ -83,28 +82,13 @@ export class RectangleSelection extend } this._view.interaction.selectNodesByIds(nodes.map((node) => node.getId())); - const edges = this._selectEdges(nodes); - this._view.render(); this._removeOverlay(); this._start = undefined; - this.emit(RectangleSelectionEventType.SELECT, { nodes, edges, area, mode }); + this.emit(RectangleSelectionEventType.SELECT, { nodes, area, mode }); }; - private _selectEdges(nodes: INode[]): IEdge[] { - if (this._includeEdges !== 'endpointsInside') { - return []; - } - - const nodeIds = new Set(nodes.map((node) => node.getId())); - const edges = this._view.data.getEdges( - (edge) => nodeIds.has(edge.startNode?.getId()) && nodeIds.has(edge.endNode?.getId()), - ); - this._view.interaction.selectEdgesByIds(edges.map((edge) => edge.getId())); - return edges; - } - private _createOverlay(): void { const canvas = this._view.canvas; const container = canvas.parentElement; diff --git a/src/interactions/shared.ts b/src/interactions/shared.ts index bd7455e..e12ade7 100644 --- a/src/interactions/shared.ts +++ b/src/interactions/shared.ts @@ -1,11 +1,9 @@ import { INode, INodeBase } from '../models/node'; -import { IEdge, IEdgeBase } from '../models/edge'; +import { IEdgeBase } from '../models/edge'; import { RectangleArea } from '../common'; export type IRectangleSelectionMode = 'replace' | 'add'; -export type IRectangleSelectionEdgeMode = 'none' | 'endpointsInside'; - // Applied as inline styles on the overlay element, which also carries the // `orb-selection-rectangle` class for CSS overrides. export interface IRectangleSelectionStyle { @@ -17,16 +15,13 @@ export interface IRectangleSelectionStyle { } export interface IRectangleSelectionOptions { - // Defaults to: ctrl/meta held -> 'add', otherwise 'replace'. + // Defaults to: ctrl/meta held -> 'replace', otherwise 'add'. resolveMode?: (event: MouseEvent) => IRectangleSelectionMode; - // 'endpointsInside' also selects edges whose both endpoints fall in the area. - includeEdges?: IRectangleSelectionEdgeMode; style?: Partial; } export interface IRectangleSelectionSelectEvent { nodes: INode[]; - edges: IEdge[]; area: RectangleArea; mode: IRectangleSelectionMode; } diff --git a/src/utils/graph.utils.ts b/src/utils/graph.utils.ts index 4bad778..b6e56b0 100644 --- a/src/utils/graph.utils.ts +++ b/src/utils/graph.utils.ts @@ -67,40 +67,60 @@ export const selectNodes = ( nodes: INode[], options?: ISelectionOptions, ): { changedCount: number } => { + let changedCount = 0; for (let i = 0; i < nodes.length; i++) { + const previousState = nodes[i].getState(); selectNode(nodes[i], options); + if (nodes[i].getState() !== previousState) { + changedCount += 1; + } } - return { changedCount: nodes.length }; + return { changedCount }; }; export const unselectNodes = ( nodes: INode[], options?: ISelectionOptions, ): { changedCount: number } => { + let changedCount = 0; for (let i = 0; i < nodes.length; i++) { + const previousState = nodes[i].getState(); unselectNode(nodes[i], options); + if (nodes[i].getState() !== previousState) { + changedCount += 1; + } } - return { changedCount: nodes.length }; + return { changedCount }; }; export const selectEdges = ( edges: IEdge[], options?: ISelectionOptions, ): { changedCount: number } => { + let changedCount = 0; for (let i = 0; i < edges.length; i++) { + const previousState = edges[i].getState(); selectEdge(edges[i], options); + if (edges[i].getState() !== previousState) { + changedCount += 1; + } } - return { changedCount: edges.length }; + return { changedCount }; }; export const unselectEdges = ( edges: IEdge[], options?: ISelectionOptions, ): { changedCount: number } => { + let changedCount = 0; for (let i = 0; i < edges.length; i++) { + const previousState = edges[i].getState(); unselectEdge(edges[i], options); + if (edges[i].getState() !== previousState) { + changedCount += 1; + } } - return { changedCount: edges.length }; + return { changedCount }; }; export const selectOnlyEdge = ( diff --git a/test/models/selection.spec.ts b/test/models/selection.spec.ts index 6a16949..bb75380 100644 --- a/test/models/selection.spec.ts +++ b/test/models/selection.spec.ts @@ -101,6 +101,19 @@ describe('GraphInteraction batch selection', () => { expect(graph.getNodeById(0)!.isSelected()).toBe(true); }); + test('selectNodesByIds counts only nodes whose state actually changed', () => { + const graph = buildGraph(); + const interaction = new GraphInteraction(graph); + interaction.selectNodesByIds([0]); + + // 0 is already selected, so only 1 changes. + const count = interaction.selectNodesByIds([0, 1]); + + expect(count).toBe(1); + expect(graph.getNodeById(0)!.isSelected()).toBe(true); + expect(graph.getNodeById(1)!.isSelected()).toBe(true); + }); + test('unselectNodesByIds clears only the listed nodes', () => { const graph = buildGraph(); const interaction = new GraphInteraction(graph); From c949cb35494355022dae9fb436718e7392dedf45 Mon Sep 17 00:00:00 2001 From: AlexIchenskiy Date: Tue, 8 Sep 2026 12:23:22 +0200 Subject: [PATCH 3/3] Chore: Improve empty drag handling --- docs/site/concepts/interaction.md | 11 +++++---- .../public/demos/rectangle-selection.html | 16 ++++++++++--- src/interactions/rectangle-selection.ts | 23 ++++++++++++++++--- 3 files changed, 39 insertions(+), 11 deletions(-) diff --git a/docs/site/concepts/interaction.md b/docs/site/concepts/interaction.md index 0a071e3..57684d1 100644 --- a/docs/site/concepts/interaction.md +++ b/docs/site/concepts/interaction.md @@ -152,10 +152,11 @@ selection.on('select', ({ nodes, area, mode }) => { }); ``` -By default, **Shift-drag** over the empty background draws the box and adds the nodes to -the selection (mirroring Shift-click); holding **Ctrl/Cmd** as well replaces it instead. -Dragging a node still moves it, and a plain drag still pans. Call `selection.destroy()` to -detach it. +By default, **Shift-drag** over the empty background draws the box and replaces the +selection with the nodes inside (like a fresh marquee); holding **Ctrl/Cmd** as well adds +to the current selection instead. A too-small drag counts as a click and leaves the +selection untouched. Dragging a node still moves it, and a plain drag still pans. Call +`selection.destroy()` to detach it. ::: warning Requires background drag `RectangleSelection` only listens - it does not enable the gesture. If @@ -167,7 +168,7 @@ Shift-drag is a no-op. | Option | Type | Default | | --- | --- | --- | -| `resolveMode` | `(event: MouseEvent) => 'add' \| 'replace'` | ctrl/meta → `replace`, else `add` | +| `resolveMode` | `(event: MouseEvent) => 'add' \| 'replace'` | ctrl/meta → `add`, else `replace` | | `style` | `Partial` | dashed blue overlay | The overlay element carries the `orb-selection-rectangle` class, so you can also style it diff --git a/docs/site/public/demos/rectangle-selection.html b/docs/site/public/demos/rectangle-selection.html index 6180281..7385d25 100644 --- a/docs/site/public/demos/rectangle-selection.html +++ b/docs/site/public/demos/rectangle-selection.html @@ -24,7 +24,7 @@
- Shift+drag to add · Ctrl/Cmd to replace + Shift+drag to select · Ctrl/Cmd to add 0 nodes, 0 edges @@ -135,12 +135,22 @@ orb.events.on(OrbEventType.BACKGROUND_DRAG, (e) => { if (start) setOverlay(start.canvas, e.globalPoint); }); + // Below this canvas-pixel span in both axes, treat the gesture as a click, not a + // marquee: leave the selection alone so a stray Shift-click doesn't clear it. + const MIN_DRAG_PX = 3; + orb.events.on(OrbEventType.BACKGROUND_DRAG_END, (e) => { if (!start) return; + if (Math.abs(e.globalPoint.x - start.canvas.x) < MIN_DRAG_PX && + Math.abs(e.globalPoint.y - start.canvas.y) < MIN_DRAG_PX) { + clearOverlay(); + start = null; + return; + } const area = RectangleArea.fromPoints(start.sim, e.localPoint); const selected = orb.data.getNodesInArea(area); - // Shift-drag adds (like Shift-click); holding Ctrl/Cmd replaces instead. - if (e.event.ctrlKey || e.event.metaKey) orb.interaction.unselectAll(); + // Shift-drag replaces (fresh marquee); holding Ctrl/Cmd adds to the selection instead. + if (!(e.event.ctrlKey || e.event.metaKey)) orb.interaction.unselectAll(); orb.interaction.selectNodesByIds(selected.map((n) => n.getId())); if (includeEdgesEl.checked) { const set = new Set(selected.map((n) => n.getId())); diff --git a/src/interactions/rectangle-selection.ts b/src/interactions/rectangle-selection.ts index 9232e51..56b5ec3 100644 --- a/src/interactions/rectangle-selection.ts +++ b/src/interactions/rectangle-selection.ts @@ -14,10 +14,17 @@ import { RectangleSelectionEventType, } from './shared'; -// Shift already enables the gesture, so mirror Shift-click's additive behavior: -// a plain Shift-drag adds to the selection, holding Ctrl/Cmd replaces it. +// A drawn box reads as a fresh selection, matching desktop marquee convention: a plain +// Shift-drag replaces the selection, holding Ctrl/Cmd adds to it. Incremental additions +// are still one gesture away (Ctrl/Cmd + Shift-drag, or Shift-click a node when multiselect +// is enabled - both leave the existing selection intact). const DEFAULT_RESOLVE_MODE = (event: MouseEvent): IRectangleSelectionMode => - event.ctrlKey || event.metaKey ? 'replace' : 'add'; + event.ctrlKey || event.metaKey ? 'add' : 'replace'; + +// Below this canvas-pixel span in both axes the gesture is treated as a click, not a +// marquee: selection is left untouched and no `select` event fires. Guards against a +// stray Shift-click (a zero-area drag) wiping the selection in the default `replace` mode. +const MIN_DRAG_PX = 3; // Marquee selection built on Orb's public API: it listens for the view's neutral // BACKGROUND_DRAG_* events, draws its own DOM overlay, and applies the selection @@ -73,6 +80,16 @@ export class RectangleSelection extend return; } + // A gesture below the drag threshold (e.g. a Shift-click) is not a marquee: leave the + // selection alone and emit nothing, so it doesn't clear the selection in `replace` mode. + const dx = Math.abs(event.globalPoint.x - this._start.canvas.x); + const dy = Math.abs(event.globalPoint.y - this._start.canvas.y); + if (dx < MIN_DRAG_PX && dy < MIN_DRAG_PX) { + this._removeOverlay(); + this._start = undefined; + return; + } + const area = RectangleArea.fromPoints(this._start.simulation, event.localPoint); const nodes = this._view.data.getNodesInArea(area); const mode = this._resolveMode(event.event);