fuxi-topology 0.2.3 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3780,7 +3780,9 @@ class yn extends Xe {
3780
3780
  }));
3781
3781
  }
3782
3782
  clearSelectionSilent() {
3783
- this.selected && (this.selected.deselect(), this.selected = null, this.highlight.destroy());
3783
+ if (!this.selected) return;
3784
+ const t = this.selected;
3785
+ this.selected = null, this.highlight.destroy(), t.deselect();
3784
3786
  }
3785
3787
  getSelectedId() {
3786
3788
  return this.selected ? this.getItemId(this.selected) : null;
@@ -159,4 +159,4 @@ void main(void)
159
159
 
160
160
  finalColor = vec4(newRgb, original.a);
161
161
  }
162
- `;class ja extends w.Filter{_angle;constructor(t={}){const n=t.width??.35,i=t.intensity??.6,r=t.angle??Math.PI/6,o=w.GlProgram.from({vertex:Ja,fragment:Za,name:"shimmer-filter"});super({glProgram:o,resources:{shimmerUniforms:new w.UniformGroup({uPhase:{value:0,type:"f32"},uWidth:{value:n,type:"f32"},uIntensity:{value:i,type:"f32"},uCosA:{value:Math.cos(r),type:"f32"},uSinA:{value:Math.sin(r),type:"f32"}})}}),this._angle=r}get phase(){return this.resources.shimmerUniforms.uniforms.uPhase}set phase(t){this.resources.shimmerUniforms.uniforms.uPhase=t}get width(){return this.resources.shimmerUniforms.uniforms.uWidth}set width(t){this.resources.shimmerUniforms.uniforms.uWidth=t}get intensity(){return this.resources.shimmerUniforms.uniforms.uIntensity}set intensity(t){this.resources.shimmerUniforms.uniforms.uIntensity=t}get angle(){return this._angle}set angle(t){this._angle=t,this.resources.shimmerUniforms.uniforms.uCosA=Math.cos(t),this.resources.shimmerUniforms.uniforms.uSinA=Math.sin(t)}}const xt=new WeakMap;function Qa(e,t,n){const i=n?.frequency??.8,r=n?.width??.35,o=n?.intensity??.6,s=n?.angle??Math.PI/6;return{stateId:e,type:t,onEnter(a){const c=new ja({width:r,intensity:o,angle:s}),l=a.getGraphics();pt(a),l.filters=[...l.filters??[],c];const h=Math.abs(Math.cos(s))+Math.abs(Math.sin(s));xt.set(a,{elapsed:0,filter:c,maxProj:h})},onLeave(a){const c=xt.get(a);if(c){const l=a.getGraphics();l.filters=(l.filters??[]).filter(h=>h!==c.filter),gt(a),xt.delete(a)}},onUpdate(a,c){const l=xt.get(a);if(!l)return;l.elapsed+=c;const h=l.elapsed*i/1e3%1,u=r*.5,f=l.maxProj+r;l.filter.phase=h*f-u}}}const mn=new WeakMap;function ec(e,t,n){const i=n?.color??16711680;return{stateId:e,type:t,onEnter(r){const o=r.getGraphics();mn.set(r,o.tint),o.tint=i},onLeave(r){const o=mn.get(r);o!==void 0&&(r.getGraphics().tint=o,mn.delete(r))}}}class Qi extends w.EventEmitter{states=new Map;plugins=new Map;add(t){for(const n of Array.isArray(t)?t:[t]){const i=this.states.has(n.id);this.states.set(n.id,n),this.emit(i?"state:updated":"state:added",n)}return this}remove(t){return this.states.delete(t)?(this.plugins.delete(t),this.emit("state:removed",{id:t}),!0):!1}get(t){return this.states.get(t)}has(t){return this.states.has(t)}getAll(){return[...this.states.values()]}clear(){this.states.clear(),this.plugins.clear(),this.emit("states:cleared")}registerPlugin(t){const n=this.plugins.get(t.stateId)??[];return n.push(t),this.plugins.set(t.stateId,n),this}unregisterPlugin(t,n){const i=this.plugins.get(t);if(i){const r=i.filter(o=>o.type!==n);r.length?this.plugins.set(t,r):this.plugins.delete(t)}return this}getPlugins(t,n){return(this.plugins.get(t)??[]).filter(i=>i.type===n)}getWeight(t){return this.states.get(t)?.weight??0}sortByWeight(t){return[...t].sort((n,i)=>this.getWeight(n)-this.getWeight(i))}toJSON(){return this.getAll()}fromJSON(t){this.add(t)}toYAML(){return ae(this.toJSON())}fromYAML(t){this.fromJSON(ce(t))}destroy(){this.clear(),this.removeAllListeners()}}class yt extends w.EventEmitter{_app;icons=new ji;states=new Qi;scenes=new Map;activeSceneId=null;_isReady=!1;_isBatchLoading=!1;plugins=new Map;_cameraBoundScene=null;_onSceneCameraChange=t=>this.emit("camera:change",{...t,sceneId:this._cameraBoundScene.id});_onSceneCameraMove=t=>this.emit("camera:move",{...t,sceneId:this._cameraBoundScene.id});_onSceneCameraZoom=t=>this.emit("camera:zoom",{...t,sceneId:this._cameraBoundScene.id});bindCameraEvents(t){this._cameraBoundScene=t,t.on("camera:change",this._onSceneCameraChange),t.on("camera:move",this._onSceneCameraMove),t.on("camera:zoom",this._onSceneCameraZoom)}unbindCameraEvents(t){t.off("camera:change",this._onSceneCameraChange),t.off("camera:move",this._onSceneCameraMove),t.off("camera:zoom",this._onSceneCameraZoom),this._cameraBoundScene===t&&(this._cameraBoundScene=null)}get app(){return this._app}async init(t){if(this._isReady)return;const{container:n,width:i,height:r}=t;this._app=new w.Application,await this._app.init({resizeTo:!i&&!r?n:void 0,width:i??n.clientWidth,height:r??n.clientHeight,antialias:!0}),n.appendChild(this._app.canvas),this._app.stage.eventMode="static",this._app.stage.hitArea=this._app.screen,this._isReady=!0,this.use(new Zi),this.emit("ready")}static async create(t){const n=new yt;return await n.init(t),n}ensureReady(){if(!this._isReady)throw new Error("Topology not initialized. Call init() first.")}addScene(t,n){if(this.ensureReady(),this.scenes.has(t))throw new Error(`Scene "${t}" already exists`);const i=new he(t,this.app,this.icons,this.states);return this.scenes.set(t,i),n&&i.fromJSON(n),!this._isBatchLoading&&this.scenes.size===1?this.switchScene(t):i.setActive(!1),this.emit("scene:added",i),i}removeScene(t){this.ensureReady();const n=this.scenes.get(t);n&&(this.activeSceneId===t&&(this.unbindCameraEvents(n),n.setActive(!1),this.activeSceneId=null),this.emit("scene:removed",{id:t}),n.destroy(),this.scenes.delete(t))}switchScene(t){this.ensureReady();const n=this.scenes.get(t);if(!n)throw new Error(`Scene "${t}" not found`);const i=this.activeSceneId,r=i?this.scenes.get(i)??null:null;return i&&i!==t&&this.scenes.get(i)?.setActive(!1),r&&r!==n&&this.unbindCameraEvents(r),this.bindCameraEvents(n),n.setActive(!0),this.activeSceneId=t,this.emit("scene:switched",{from:r,to:n}),n}getScene(t){return this.scenes.get(t)}getSceneIds(){return[...this.scenes.keys()]}async fit(t,n){this.ensureReady();let i,r;Array.isArray(t)?r=t:(i=t,r=n??[0]);const o=r.length?r:[0],s=o[0]??0,a=o[1]??s,c=o[2]??s,l=o[3]??a,h=i?this.scenes.get(i):this.activeScene;if(!h)throw new Error(i?`Scene "${i}" not found`:"No active scene");const u=h.getContentBounds();if(!u)return;const f=this._app.screen.width,d=this._app.screen.height;if(f<=0||d<=0)return;const p=h.projectionContainer,m=[{x:u.x,y:u.y},{x:u.x+u.width,y:u.y},{x:u.x,y:u.y+u.height},{x:u.x+u.width,y:u.y+u.height}],y=p.skew.x,S=p.skew.y,x=Math.cos(S),I=Math.sin(S),A=Math.sin(y),O=Math.cos(y);let R=1/0,F=1/0,W=-1/0,j=-1/0;for(const{x:ve,y:xe}of m){const ye=x*ve+A*xe,_e=I*ve+O*xe;ye<R&&(R=ye),_e<F&&(F=_e),ye>W&&(W=ye),_e>j&&(j=_e)}const X=W-R,q=j-F,pe=(R+W)/2,ge=(F+j)/2,K=f-l-a,me=d-s-c;let $;if(X<=0&&q<=0)$=he.DEFAULT_ZOOM;else if(K<=0||me<=0)$=he.DEFAULT_ZOOM;else{const ve=X>0?K/X:1/0,xe=q>0?me/q:1/0;$=Math.min(ve,xe)}$=Math.max(.05,Math.min($,10));const P=l+(f-l-a)/2,Ln=s+(d-s-c)/2,T=P-$*pe,Q=Ln-$*ge;!Number.isFinite(T)||!Number.isFinite(Q)||!Number.isFinite($)||await h.setCamera({zoom:$,x:T,y:Q})}get activeScene(){return this.activeSceneId?this.scenes.get(this.activeSceneId):void 0}get isInitialized(){return this._isReady}get stage(){return this.app?.stage}toJSON(){const t={};for(const[n,i]of this.scenes)t[n]=i.toJSON();return{scenes:t,icons:this.icons.toJSON(),states:this.states.toJSON(),activeSceneId:this.activeSceneId??void 0}}fromJSON(t){for(const i of[...this.scenes.keys()])this.removeScene(i);t.icons&&this.icons.fromJSON(t.icons),t.states&&this.states.fromJSON(t.states),this._isBatchLoading=!0;for(const[i,r]of Object.entries(t.scenes))this.addScene(i,r);this._isBatchLoading=!1;const n=t.activeSceneId&&this.scenes.has(t.activeSceneId)?t.activeSceneId:this.getSceneIds()[0];n&&this.switchScene(n)}toYAML(){return ae(this.toJSON())}fromYAML(t){this.fromJSON(ce(t))}async exportPNG(t){this.ensureReady();const n=this.activeScene;if(!n)throw new Error("No active scene");return n.exportPNG(t)}async exportSVG(t){this.ensureReady();const n=this.activeScene;if(!n)throw new Error("No active scene");return n.exportSVG(t)}async downloadPNG(t,n){const i=await this.exportPNG(n);Ue(i,t??"topology.png")}async downloadSVG(t,n){const i=await this.exportSVG(n);Ue(i,t??"topology.svg")}use(t){if(this.plugins.has(t.name))throw new Error(`Plugin "${t.name}" is already installed`);return this.plugins.set(t.name,t),t.install(this),this.emit("plugin:installed",{name:t.name}),this}removePlugin(t){const n=typeof t=="string"?t:t.name,i=this.plugins.get(n);return i&&(i.uninstall(this),this.plugins.delete(n),this.emit("plugin:removed",{name:n})),this}hasPlugin(t){return this.plugins.has(t)}getPlugin(t){if(typeof t=="string")return this.plugins.get(t);for(const n of this.plugins.values())if(n instanceof t)return n}destroy(){for(const t of this.plugins.values())t.uninstall(this);this.plugins.clear();for(const t of[...this.scenes.keys()])this.removeScene(t);this.icons.clear(),this.states.clear(),wa(),this.emit("destroyed"),this.removeAllListeners(),this.app?.destroy(!0),this._isReady=!1}}class Ge extends Ce{activeItems=new Map;hookScene(t){const n=this.getCollection(t);for(const s of n.getAll())this.enableInteraction(s,t);const i=s=>this.enableInteraction(s,t),r=({id:s})=>this.disableInteraction(s),o=()=>{for(const[s,a]of this.activeItems)a.sceneId===t.id&&this.disableInteraction(s)};return n.on(`${this.targetType}:added`,i),n.on(`${this.targetType}:removed`,r),n.on(`${this.targetType}s:cleared`,o),()=>{n.off(`${this.targetType}:added`,i),n.off(`${this.targetType}:removed`,r),n.off(`${this.targetType}s:cleared`,o);for(const s of n.getAll())this.disableInteraction(this.getItemId(s))}}enableInteraction(t,n){const i=this.getItemId(t);if(this.activeItems.has(i))return;const r=t.getGraphics();r.eventMode="static",r.cursor="pointer",this.activeItems.set(i,{item:t,sceneId:n.id})}disableInteraction(t){const n=this.activeItems.get(t);if(!n)return;const i=n.item.getGraphics();i.eventMode="none",i.cursor="default",this.activeItems.delete(t)}}const tc={padding:6,radius:6,color:4886754,lineWidth:2,alpha:.8};class er{graphics;draw(t,n){this.destroy();const{padding:i,radius:r,color:o,lineWidth:s,alpha:a}={...tc,...n},c=t.getLocalBounds(),l=new w.Graphics;l.roundRect(c.x-i,c.y-i,c.width+i*2,c.height+i*2,r),l.stroke({color:o,width:s,alpha:a}),l.position.copyFrom(t.position),l.skew.copyFrom(t.skew),l.scale.copyFrom(t.scale),t.parent?.addChild(l),this.graphics=l}updatePosition(t){this.graphics&&this.graphics.position.copyFrom(t.position)}destroy(){this.graphics?.destroy(),this.graphics=void 0}get exists(){return this.graphics!==void 0}}class _t extends Ce{selected=null;highlight=new er;dragStates=new Map;snapDelta(t){return t}get highlightOptions(){return{}}hookScene(t){const n=this.getCollection(t),{projectionContainer:i}=t;for(const a of n.getAll())this.attachBehavior(a,i,t);const r=a=>this.attachBehavior(a,i,t),o=({id:a})=>this.detachBehavior(a),s=()=>{for(const[a,c]of this.dragStates)c.sceneId===t.id&&this.detachBehavior(a)};return n.on(`${this.targetType}:added`,r),n.on(`${this.targetType}:removed`,o),n.on(`${this.targetType}s:cleared`,s),()=>{n.off(`${this.targetType}:added`,r),n.off(`${this.targetType}:removed`,o),n.off(`${this.targetType}s:cleared`,s);for(const a of n.getAll())this.detachBehavior(this.getItemId(a))}}onItemPointerDown({itemType:t,itemId:n}){if(t!==this.targetType){t!==null?this.clearSelectionSilent():this.clearSelection();return}if(n){const i=this.dragStates.get(n);i&&this.selectItem(i.item)}}onSceneSwitched(){this.clearSelection()}attachBehavior(t,n,i){const r=this.getItemId(t);if(this.dragStates.has(r))return;const o=t.getGraphics();o.eventMode="static",o.cursor="pointer";const s={item:t,sceneId:i.id,isDragging:!1,startPointer:{x:0,y:0},startTile:{x:0,y:0},cleanup:()=>{}},a=h=>{s.isDragging=!0;const u=n.toLocal(h.global);s.startPointer={x:u.x,y:u.y},s.startTile={...this.getItemPosition(t)}},c=h=>{if(!s.isDragging)return;const u=n.toLocal(h.global),f=u.x-s.startPointer.x,d=u.y-s.startPointer.y,p=s.startTile.x+this.snapDelta(f),m=s.startTile.y+this.snapDelta(d);this.applyDrag(t,p,m,i),this.updateHighlight(t)},l=()=>{s.isDragging&&(s.isDragging=!1,this.onDragEnd(t,i))};o.on("pointerdown",a),o.on("globalpointermove",c),o.on("pointerup",l),o.on("pointerupoutside",l),s.cleanup=()=>{o.eventMode="none",o.cursor="default",o.off("pointerdown",a),o.off("globalpointermove",c),o.off("pointerup",l),o.off("pointerupoutside",l)},this.dragStates.set(r,s),s.extraCleanup=this.onAttachItem(t,i)??void 0}detachBehavior(t){const n=this.dragStates.get(t);n&&(this.selected&&this.getItemId(this.selected)===t&&this.clearSelection(),n.extraCleanup?.(),n.cleanup(),this.dragStates.delete(t))}onAttachItem(t,n){}onDragEnd(t,n){}selectItem(t){this.selected!==t&&(this.clearSelectionSilent(),this.selected=t,t.select(),this.highlight.draw(t.getGraphics(),this.highlightOptions),this.topology?.emit("selection:changed",{pluginName:this.name,itemType:this.targetType,itemId:this.getItemId(t)}))}clearSelection(){this.selected&&(this.clearSelectionSilent(),this.topology?.emit("selection:changed",{pluginName:this.name,itemType:this.targetType,itemId:null}))}clearSelectionSilent(){this.selected&&(this.selected.deselect(),this.selected=null,this.highlight.destroy())}getSelectedId(){return this.selected?this.getItemId(this.selected):null}getSelected(){return this.selected}updateHighlight(t){this.selected===t&&this.highlight.updatePosition(t.getGraphics())}}var vn="http://www.w3.org/1999/xhtml";const tr={svg:"http://www.w3.org/2000/svg",xhtml:vn,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function wt(e){var t=e+="",n=t.indexOf(":");return n>=0&&(t=e.slice(0,n))!=="xmlns"&&(e=e.slice(n+1)),tr.hasOwnProperty(t)?{space:tr[t],local:e}:e}function nc(e){return function(){var t=this.ownerDocument,n=this.namespaceURI;return n===vn&&t.documentElement.namespaceURI===vn?t.createElement(e):t.createElementNS(n,e)}}function ic(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function nr(e){var t=wt(e);return(t.local?ic:nc)(t)}function rc(){}function xn(e){return e==null?rc:function(){return this.querySelector(e)}}function oc(e){typeof e!="function"&&(e=xn(e));for(var t=this._groups,n=t.length,i=new Array(n),r=0;r<n;++r)for(var o=t[r],s=o.length,a=i[r]=new Array(s),c,l,h=0;h<s;++h)(c=o[h])&&(l=e.call(c,c.__data__,h,o))&&("__data__"in c&&(l.__data__=c.__data__),a[h]=l);return new D(i,this._parents)}function sc(e){return e==null?[]:Array.isArray(e)?e:Array.from(e)}function ac(){return[]}function ir(e){return e==null?ac:function(){return this.querySelectorAll(e)}}function cc(e){return function(){return sc(e.apply(this,arguments))}}function lc(e){typeof e=="function"?e=cc(e):e=ir(e);for(var t=this._groups,n=t.length,i=[],r=[],o=0;o<n;++o)for(var s=t[o],a=s.length,c,l=0;l<a;++l)(c=s[l])&&(i.push(e.call(c,c.__data__,l,s)),r.push(c));return new D(i,r)}function rr(e){return function(){return this.matches(e)}}function or(e){return function(t){return t.matches(e)}}var hc=Array.prototype.find;function uc(e){return function(){return hc.call(this.children,e)}}function fc(){return this.firstElementChild}function dc(e){return this.select(e==null?fc:uc(typeof e=="function"?e:or(e)))}var pc=Array.prototype.filter;function gc(){return Array.from(this.children)}function mc(e){return function(){return pc.call(this.children,e)}}function vc(e){return this.selectAll(e==null?gc:mc(typeof e=="function"?e:or(e)))}function xc(e){typeof e!="function"&&(e=rr(e));for(var t=this._groups,n=t.length,i=new Array(n),r=0;r<n;++r)for(var o=t[r],s=o.length,a=i[r]=[],c,l=0;l<s;++l)(c=o[l])&&e.call(c,c.__data__,l,o)&&a.push(c);return new D(i,this._parents)}function sr(e){return new Array(e.length)}function yc(){return new D(this._enter||this._groups.map(sr),this._parents)}function St(e,t){this.ownerDocument=e.ownerDocument,this.namespaceURI=e.namespaceURI,this._next=null,this._parent=e,this.__data__=t}St.prototype={constructor:St,appendChild:function(e){return this._parent.insertBefore(e,this._next)},insertBefore:function(e,t){return this._parent.insertBefore(e,t)},querySelector:function(e){return this._parent.querySelector(e)},querySelectorAll:function(e){return this._parent.querySelectorAll(e)}};function _c(e){return function(){return e}}function wc(e,t,n,i,r,o){for(var s=0,a,c=t.length,l=o.length;s<l;++s)(a=t[s])?(a.__data__=o[s],i[s]=a):n[s]=new St(e,o[s]);for(;s<c;++s)(a=t[s])&&(r[s]=a)}function Sc(e,t,n,i,r,o,s){var a,c,l=new Map,h=t.length,u=o.length,f=new Array(h),d;for(a=0;a<h;++a)(c=t[a])&&(f[a]=d=s.call(c,c.__data__,a,t)+"",l.has(d)?r[a]=c:l.set(d,c));for(a=0;a<u;++a)d=s.call(e,o[a],a,o)+"",(c=l.get(d))?(i[a]=c,c.__data__=o[a],l.delete(d)):n[a]=new St(e,o[a]);for(a=0;a<h;++a)(c=t[a])&&l.get(f[a])===c&&(r[a]=c)}function Ic(e){return e.__data__}function Ac(e,t){if(!arguments.length)return Array.from(this,Ic);var n=t?Sc:wc,i=this._parents,r=this._groups;typeof e!="function"&&(e=_c(e));for(var o=r.length,s=new Array(o),a=new Array(o),c=new Array(o),l=0;l<o;++l){var h=i[l],u=r[l],f=u.length,d=bc(e.call(h,h&&h.__data__,l,i)),p=d.length,m=a[l]=new Array(p),y=s[l]=new Array(p),S=c[l]=new Array(f);n(h,u,m,y,S,d,t);for(var x=0,I=0,A,O;x<p;++x)if(A=m[x]){for(x>=I&&(I=x+1);!(O=y[I])&&++I<p;);A._next=O||null}}return s=new D(s,i),s._enter=a,s._exit=c,s}function bc(e){return typeof e=="object"&&"length"in e?e:Array.from(e)}function Cc(){return new D(this._exit||this._groups.map(sr),this._parents)}function Tc(e,t,n){var i=this.enter(),r=this,o=this.exit();return typeof e=="function"?(i=e(i),i&&(i=i.selection())):i=i.append(e+""),t!=null&&(r=t(r),r&&(r=r.selection())),n==null?o.remove():n(o),i&&r?i.merge(r).order():r}function Ec(e){for(var t=e.selection?e.selection():e,n=this._groups,i=t._groups,r=n.length,o=i.length,s=Math.min(r,o),a=new Array(r),c=0;c<s;++c)for(var l=n[c],h=i[c],u=l.length,f=a[c]=new Array(u),d,p=0;p<u;++p)(d=l[p]||h[p])&&(f[p]=d);for(;c<r;++c)a[c]=n[c];return new D(a,this._parents)}function Mc(){for(var e=this._groups,t=-1,n=e.length;++t<n;)for(var i=e[t],r=i.length-1,o=i[r],s;--r>=0;)(s=i[r])&&(o&&s.compareDocumentPosition(o)^4&&o.parentNode.insertBefore(s,o),o=s);return this}function Oc(e){e||(e=Pc);function t(u,f){return u&&f?e(u.__data__,f.__data__):!u-!f}for(var n=this._groups,i=n.length,r=new Array(i),o=0;o<i;++o){for(var s=n[o],a=s.length,c=r[o]=new Array(a),l,h=0;h<a;++h)(l=s[h])&&(c[h]=l);c.sort(t)}return new D(r,this._parents).order()}function Pc(e,t){return e<t?-1:e>t?1:e>=t?0:NaN}function Lc(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function kc(){return Array.from(this)}function Nc(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var i=e[t],r=0,o=i.length;r<o;++r){var s=i[r];if(s)return s}return null}function Rc(){let e=0;for(const t of this)++e;return e}function Dc(){return!this.node()}function Fc(e){for(var t=this._groups,n=0,i=t.length;n<i;++n)for(var r=t[n],o=0,s=r.length,a;o<s;++o)(a=r[o])&&e.call(a,a.__data__,o,r);return this}function $c(e){return function(){this.removeAttribute(e)}}function zc(e){return function(){this.removeAttributeNS(e.space,e.local)}}function Bc(e,t){return function(){this.setAttribute(e,t)}}function Hc(e,t){return function(){this.setAttributeNS(e.space,e.local,t)}}function Uc(e,t){return function(){var n=t.apply(this,arguments);n==null?this.removeAttribute(e):this.setAttribute(e,n)}}function Yc(e,t){return function(){var n=t.apply(this,arguments);n==null?this.removeAttributeNS(e.space,e.local):this.setAttributeNS(e.space,e.local,n)}}function Gc(e,t){var n=wt(e);if(arguments.length<2){var i=this.node();return n.local?i.getAttributeNS(n.space,n.local):i.getAttribute(n)}return this.each((t==null?n.local?zc:$c:typeof t=="function"?n.local?Yc:Uc:n.local?Hc:Bc)(n,t))}function ar(e){return e.ownerDocument&&e.ownerDocument.defaultView||e.document&&e||e.defaultView}function Wc(e){return function(){this.style.removeProperty(e)}}function Xc(e,t,n){return function(){this.style.setProperty(e,t,n)}}function qc(e,t,n){return function(){var i=t.apply(this,arguments);i==null?this.style.removeProperty(e):this.style.setProperty(e,i,n)}}function Kc(e,t,n){return arguments.length>1?this.each((t==null?Wc:typeof t=="function"?qc:Xc)(e,t,n??"")):Te(this.node(),e)}function Te(e,t){return e.style.getPropertyValue(t)||ar(e).getComputedStyle(e,null).getPropertyValue(t)}function Vc(e){return function(){delete this[e]}}function Jc(e,t){return function(){this[e]=t}}function Zc(e,t){return function(){var n=t.apply(this,arguments);n==null?delete this[e]:this[e]=n}}function jc(e,t){return arguments.length>1?this.each((t==null?Vc:typeof t=="function"?Zc:Jc)(e,t)):this.node()[e]}function cr(e){return e.trim().split(/^|\s+/)}function yn(e){return e.classList||new lr(e)}function lr(e){this._node=e,this._names=cr(e.getAttribute("class")||"")}lr.prototype={add:function(e){var t=this._names.indexOf(e);t<0&&(this._names.push(e),this._node.setAttribute("class",this._names.join(" ")))},remove:function(e){var t=this._names.indexOf(e);t>=0&&(this._names.splice(t,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(e){return this._names.indexOf(e)>=0}};function hr(e,t){for(var n=yn(e),i=-1,r=t.length;++i<r;)n.add(t[i])}function ur(e,t){for(var n=yn(e),i=-1,r=t.length;++i<r;)n.remove(t[i])}function Qc(e){return function(){hr(this,e)}}function el(e){return function(){ur(this,e)}}function tl(e,t){return function(){(t.apply(this,arguments)?hr:ur)(this,e)}}function nl(e,t){var n=cr(e+"");if(arguments.length<2){for(var i=yn(this.node()),r=-1,o=n.length;++r<o;)if(!i.contains(n[r]))return!1;return!0}return this.each((typeof t=="function"?tl:t?Qc:el)(n,t))}function il(){this.textContent=""}function rl(e){return function(){this.textContent=e}}function ol(e){return function(){var t=e.apply(this,arguments);this.textContent=t??""}}function sl(e){return arguments.length?this.each(e==null?il:(typeof e=="function"?ol:rl)(e)):this.node().textContent}function al(){this.innerHTML=""}function cl(e){return function(){this.innerHTML=e}}function ll(e){return function(){var t=e.apply(this,arguments);this.innerHTML=t??""}}function hl(e){return arguments.length?this.each(e==null?al:(typeof e=="function"?ll:cl)(e)):this.node().innerHTML}function ul(){this.nextSibling&&this.parentNode.appendChild(this)}function fl(){return this.each(ul)}function dl(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function pl(){return this.each(dl)}function gl(e){var t=typeof e=="function"?e:nr(e);return this.select(function(){return this.appendChild(t.apply(this,arguments))})}function ml(){return null}function vl(e,t){var n=typeof e=="function"?e:nr(e),i=t==null?ml:typeof t=="function"?t:xn(t);return this.select(function(){return this.insertBefore(n.apply(this,arguments),i.apply(this,arguments)||null)})}function xl(){var e=this.parentNode;e&&e.removeChild(this)}function yl(){return this.each(xl)}function _l(){var e=this.cloneNode(!1),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function wl(){var e=this.cloneNode(!0),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function Sl(e){return this.select(e?wl:_l)}function Il(e){return arguments.length?this.property("__data__",e):this.node().__data__}function Al(e){return function(t){e.call(this,t,this.__data__)}}function bl(e){return e.trim().split(/^|\s+/).map(function(t){var n="",i=t.indexOf(".");return i>=0&&(n=t.slice(i+1),t=t.slice(0,i)),{type:t,name:n}})}function Cl(e){return function(){var t=this.__on;if(t){for(var n=0,i=-1,r=t.length,o;n<r;++n)o=t[n],(!e.type||o.type===e.type)&&o.name===e.name?this.removeEventListener(o.type,o.listener,o.options):t[++i]=o;++i?t.length=i:delete this.__on}}}function Tl(e,t,n){return function(){var i=this.__on,r,o=Al(t);if(i){for(var s=0,a=i.length;s<a;++s)if((r=i[s]).type===e.type&&r.name===e.name){this.removeEventListener(r.type,r.listener,r.options),this.addEventListener(r.type,r.listener=o,r.options=n),r.value=t;return}}this.addEventListener(e.type,o,n),r={type:e.type,name:e.name,value:t,listener:o,options:n},i?i.push(r):this.__on=[r]}}function El(e,t,n){var i=bl(e+""),r,o=i.length,s;if(arguments.length<2){var a=this.node().__on;if(a){for(var c=0,l=a.length,h;c<l;++c)for(r=0,h=a[c];r<o;++r)if((s=i[r]).type===h.type&&s.name===h.name)return h.value}return}for(a=t?Tl:Cl,r=0;r<o;++r)this.each(a(i[r],t,n));return this}function fr(e,t,n){var i=ar(e),r=i.CustomEvent;typeof r=="function"?r=new r(t,n):(r=i.document.createEvent("Event"),n?(r.initEvent(t,n.bubbles,n.cancelable),r.detail=n.detail):r.initEvent(t,!1,!1)),e.dispatchEvent(r)}function Ml(e,t){return function(){return fr(this,e,t)}}function Ol(e,t){return function(){return fr(this,e,t.apply(this,arguments))}}function Pl(e,t){return this.each((typeof t=="function"?Ol:Ml)(e,t))}function*Ll(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var i=e[t],r=0,o=i.length,s;r<o;++r)(s=i[r])&&(yield s)}var dr=[null];function D(e,t){this._groups=e,this._parents=t}function We(){return new D([[document.documentElement]],dr)}function kl(){return this}D.prototype=We.prototype={constructor:D,select:oc,selectAll:lc,selectChild:dc,selectChildren:vc,filter:xc,data:Ac,enter:yc,exit:Cc,join:Tc,merge:Ec,selection:kl,order:Mc,sort:Oc,call:Lc,nodes:kc,node:Nc,size:Rc,empty:Dc,each:Fc,attr:Gc,style:Kc,property:jc,classed:nl,text:sl,html:hl,raise:fl,lower:pl,append:gl,insert:vl,remove:yl,clone:Sl,datum:Il,on:El,dispatch:Pl,[Symbol.iterator]:Ll};function Nl(e){return typeof e=="string"?new D([[document.querySelector(e)]],[document.documentElement]):new D([[e]],dr)}var Rl={value:()=>{}};function pr(){for(var e=0,t=arguments.length,n={},i;e<t;++e){if(!(i=arguments[e]+"")||i in n||/[\s.]/.test(i))throw new Error("illegal type: "+i);n[i]=[]}return new It(n)}function It(e){this._=e}function Dl(e,t){return e.trim().split(/^|\s+/).map(function(n){var i="",r=n.indexOf(".");if(r>=0&&(i=n.slice(r+1),n=n.slice(0,r)),n&&!t.hasOwnProperty(n))throw new Error("unknown type: "+n);return{type:n,name:i}})}It.prototype=pr.prototype={constructor:It,on:function(e,t){var n=this._,i=Dl(e+"",n),r,o=-1,s=i.length;if(arguments.length<2){for(;++o<s;)if((r=(e=i[o]).type)&&(r=Fl(n[r],e.name)))return r;return}if(t!=null&&typeof t!="function")throw new Error("invalid callback: "+t);for(;++o<s;)if(r=(e=i[o]).type)n[r]=gr(n[r],e.name,t);else if(t==null)for(r in n)n[r]=gr(n[r],e.name,null);return this},copy:function(){var e={},t=this._;for(var n in t)e[n]=t[n].slice();return new It(e)},call:function(e,t){if((r=arguments.length-2)>0)for(var n=new Array(r),i=0,r,o;i<r;++i)n[i]=arguments[i+2];if(!this._.hasOwnProperty(e))throw new Error("unknown type: "+e);for(o=this._[e],i=0,r=o.length;i<r;++i)o[i].value.apply(t,n)},apply:function(e,t,n){if(!this._.hasOwnProperty(e))throw new Error("unknown type: "+e);for(var i=this._[e],r=0,o=i.length;r<o;++r)i[r].value.apply(t,n)}};function Fl(e,t){for(var n=0,i=e.length,r;n<i;++n)if((r=e[n]).name===t)return r.value}function gr(e,t,n){for(var i=0,r=e.length;i<r;++i)if(e[i].name===t){e[i]=Rl,e=e.slice(0,i).concat(e.slice(i+1));break}return n!=null&&e.push({name:t,value:n}),e}var Ee=0,Xe=0,qe=0,mr=1e3,At,Ke,bt=0,ue=0,Ct=0,Ve=typeof performance=="object"&&performance.now?performance:Date,vr=typeof window=="object"&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(e){setTimeout(e,17)};function _n(){return ue||(vr($l),ue=Ve.now()+Ct)}function $l(){ue=0}function Tt(){this._call=this._time=this._next=null}Tt.prototype=xr.prototype={constructor:Tt,restart:function(e,t,n){if(typeof e!="function")throw new TypeError("callback is not a function");n=(n==null?_n():+n)+(t==null?0:+t),!this._next&&Ke!==this&&(Ke?Ke._next=this:At=this,Ke=this),this._call=e,this._time=n,wn()},stop:function(){this._call&&(this._call=null,this._time=1/0,wn())}};function xr(e,t,n){var i=new Tt;return i.restart(e,t,n),i}function zl(){_n(),++Ee;for(var e=At,t;e;)(t=ue-e._time)>=0&&e._call.call(void 0,t),e=e._next;--Ee}function yr(){ue=(bt=Ve.now())+Ct,Ee=Xe=0;try{zl()}finally{Ee=0,Hl(),ue=0}}function Bl(){var e=Ve.now(),t=e-bt;t>mr&&(Ct-=t,bt=e)}function Hl(){for(var e,t=At,n,i=1/0;t;)t._call?(i>t._time&&(i=t._time),e=t,t=t._next):(n=t._next,t._next=null,t=e?e._next=n:At=n);Ke=e,wn(i)}function wn(e){if(!Ee){Xe&&(Xe=clearTimeout(Xe));var t=e-ue;t>24?(e<1/0&&(Xe=setTimeout(yr,e-Ve.now()-Ct)),qe&&(qe=clearInterval(qe))):(qe||(bt=Ve.now(),qe=setInterval(Bl,mr)),Ee=1,vr(yr))}}function _r(e,t,n){var i=new Tt;return t=t==null?0:+t,i.restart(r=>{i.stop(),e(r+t)},t,n),i}var Ul=pr("start","end","cancel","interrupt"),Yl=[],wr=0,Sr=1,Sn=2,Et=3,Ir=4,In=5,Mt=6;function Ot(e,t,n,i,r,o){var s=e.__transition;if(!s)e.__transition={};else if(n in s)return;Gl(e,n,{name:t,index:i,group:r,on:Ul,tween:Yl,time:o.time,delay:o.delay,duration:o.duration,ease:o.ease,timer:null,state:wr})}function An(e,t){var n=B(e,t);if(n.state>wr)throw new Error("too late; already scheduled");return n}function Y(e,t){var n=B(e,t);if(n.state>Et)throw new Error("too late; already running");return n}function B(e,t){var n=e.__transition;if(!n||!(n=n[t]))throw new Error("transition not found");return n}function Gl(e,t,n){var i=e.__transition,r;i[t]=n,n.timer=xr(o,0,n.time);function o(l){n.state=Sr,n.timer.restart(s,n.delay,n.time),n.delay<=l&&s(l-n.delay)}function s(l){var h,u,f,d;if(n.state!==Sr)return c();for(h in i)if(d=i[h],d.name===n.name){if(d.state===Et)return _r(s);d.state===Ir?(d.state=Mt,d.timer.stop(),d.on.call("interrupt",e,e.__data__,d.index,d.group),delete i[h]):+h<t&&(d.state=Mt,d.timer.stop(),d.on.call("cancel",e,e.__data__,d.index,d.group),delete i[h])}if(_r(function(){n.state===Et&&(n.state=Ir,n.timer.restart(a,n.delay,n.time),a(l))}),n.state=Sn,n.on.call("start",e,e.__data__,n.index,n.group),n.state===Sn){for(n.state=Et,r=new Array(f=n.tween.length),h=0,u=-1;h<f;++h)(d=n.tween[h].value.call(e,e.__data__,n.index,n.group))&&(r[++u]=d);r.length=u+1}}function a(l){for(var h=l<n.duration?n.ease.call(null,l/n.duration):(n.timer.restart(c),n.state=In,1),u=-1,f=r.length;++u<f;)r[u].call(e,h);n.state===In&&(n.on.call("end",e,e.__data__,n.index,n.group),c())}function c(){n.state=Mt,n.timer.stop(),delete i[t];for(var l in i)return;delete e.__transition}}function Wl(e,t){var n=e.__transition,i,r,o=!0,s;if(n){t=t==null?null:t+"";for(s in n){if((i=n[s]).name!==t){o=!1;continue}r=i.state>Sn&&i.state<In,i.state=Mt,i.timer.stop(),i.on.call(r?"interrupt":"cancel",e,e.__data__,i.index,i.group),delete n[s]}o&&delete e.__transition}}function Xl(e){return this.each(function(){Wl(this,e)})}function bn(e,t,n){e.prototype=t.prototype=n,n.constructor=e}function Ar(e,t){var n=Object.create(e.prototype);for(var i in t)n[i]=t[i];return n}function Je(){}var Ze=.7,Pt=1/Ze,Me="\\s*([+-]?\\d+)\\s*",je="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",G="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",ql=/^#([0-9a-f]{3,8})$/,Kl=new RegExp(`^rgb\\(${Me},${Me},${Me}\\)$`),Vl=new RegExp(`^rgb\\(${G},${G},${G}\\)$`),Jl=new RegExp(`^rgba\\(${Me},${Me},${Me},${je}\\)$`),Zl=new RegExp(`^rgba\\(${G},${G},${G},${je}\\)$`),jl=new RegExp(`^hsl\\(${je},${G},${G}\\)$`),Ql=new RegExp(`^hsla\\(${je},${G},${G},${je}\\)$`),br={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074};bn(Je,Qe,{copy(e){return Object.assign(new this.constructor,this,e)},displayable(){return this.rgb().displayable()},hex:Cr,formatHex:Cr,formatHex8:eh,formatHsl:th,formatRgb:Tr,toString:Tr});function Cr(){return this.rgb().formatHex()}function eh(){return this.rgb().formatHex8()}function th(){return Lr(this).formatHsl()}function Tr(){return this.rgb().formatRgb()}function Qe(e){var t,n;return e=(e+"").trim().toLowerCase(),(t=ql.exec(e))?(n=t[1].length,t=parseInt(t[1],16),n===6?Er(t):n===3?new N(t>>8&15|t>>4&240,t>>4&15|t&240,(t&15)<<4|t&15,1):n===8?Lt(t>>24&255,t>>16&255,t>>8&255,(t&255)/255):n===4?Lt(t>>12&15|t>>8&240,t>>8&15|t>>4&240,t>>4&15|t&240,((t&15)<<4|t&15)/255):null):(t=Kl.exec(e))?new N(t[1],t[2],t[3],1):(t=Vl.exec(e))?new N(t[1]*255/100,t[2]*255/100,t[3]*255/100,1):(t=Jl.exec(e))?Lt(t[1],t[2],t[3],t[4]):(t=Zl.exec(e))?Lt(t[1]*255/100,t[2]*255/100,t[3]*255/100,t[4]):(t=jl.exec(e))?Pr(t[1],t[2]/100,t[3]/100,1):(t=Ql.exec(e))?Pr(t[1],t[2]/100,t[3]/100,t[4]):br.hasOwnProperty(e)?Er(br[e]):e==="transparent"?new N(NaN,NaN,NaN,0):null}function Er(e){return new N(e>>16&255,e>>8&255,e&255,1)}function Lt(e,t,n,i){return i<=0&&(e=t=n=NaN),new N(e,t,n,i)}function nh(e){return e instanceof Je||(e=Qe(e)),e?(e=e.rgb(),new N(e.r,e.g,e.b,e.opacity)):new N}function Cn(e,t,n,i){return arguments.length===1?nh(e):new N(e,t,n,i??1)}function N(e,t,n,i){this.r=+e,this.g=+t,this.b=+n,this.opacity=+i}bn(N,Cn,Ar(Je,{brighter(e){return e=e==null?Pt:Math.pow(Pt,e),new N(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?Ze:Math.pow(Ze,e),new N(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new N(fe(this.r),fe(this.g),fe(this.b),kt(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:Mr,formatHex:Mr,formatHex8:ih,formatRgb:Or,toString:Or}));function Mr(){return`#${de(this.r)}${de(this.g)}${de(this.b)}`}function ih(){return`#${de(this.r)}${de(this.g)}${de(this.b)}${de((isNaN(this.opacity)?1:this.opacity)*255)}`}function Or(){const e=kt(this.opacity);return`${e===1?"rgb(":"rgba("}${fe(this.r)}, ${fe(this.g)}, ${fe(this.b)}${e===1?")":`, ${e})`}`}function kt(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function fe(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function de(e){return e=fe(e),(e<16?"0":"")+e.toString(16)}function Pr(e,t,n,i){return i<=0?e=t=n=NaN:n<=0||n>=1?e=t=NaN:t<=0&&(e=NaN),new H(e,t,n,i)}function Lr(e){if(e instanceof H)return new H(e.h,e.s,e.l,e.opacity);if(e instanceof Je||(e=Qe(e)),!e)return new H;if(e instanceof H)return e;e=e.rgb();var t=e.r/255,n=e.g/255,i=e.b/255,r=Math.min(t,n,i),o=Math.max(t,n,i),s=NaN,a=o-r,c=(o+r)/2;return a?(t===o?s=(n-i)/a+(n<i)*6:n===o?s=(i-t)/a+2:s=(t-n)/a+4,a/=c<.5?o+r:2-o-r,s*=60):a=c>0&&c<1?0:s,new H(s,a,c,e.opacity)}function rh(e,t,n,i){return arguments.length===1?Lr(e):new H(e,t,n,i??1)}function H(e,t,n,i){this.h=+e,this.s=+t,this.l=+n,this.opacity=+i}bn(H,rh,Ar(Je,{brighter(e){return e=e==null?Pt:Math.pow(Pt,e),new H(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?Ze:Math.pow(Ze,e),new H(this.h,this.s,this.l*e,this.opacity)},rgb(){var e=this.h%360+(this.h<0)*360,t=isNaN(e)||isNaN(this.s)?0:this.s,n=this.l,i=n+(n<.5?n:1-n)*t,r=2*n-i;return new N(Tn(e>=240?e-240:e+120,r,i),Tn(e,r,i),Tn(e<120?e+240:e-120,r,i),this.opacity)},clamp(){return new H(kr(this.h),Nt(this.s),Nt(this.l),kt(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 e=kt(this.opacity);return`${e===1?"hsl(":"hsla("}${kr(this.h)}, ${Nt(this.s)*100}%, ${Nt(this.l)*100}%${e===1?")":`, ${e})`}`}}));function kr(e){return e=(e||0)%360,e<0?e+360:e}function Nt(e){return Math.max(0,Math.min(1,e||0))}function Tn(e,t,n){return(e<60?t+(n-t)*e/60:e<180?n:e<240?t+(n-t)*(240-e)/60:t)*255}const Nr=e=>()=>e;function oh(e,t){return function(n){return e+n*t}}function sh(e,t,n){return e=Math.pow(e,n),t=Math.pow(t,n)-e,n=1/n,function(i){return Math.pow(e+i*t,n)}}function ah(e){return(e=+e)==1?Rr:function(t,n){return n-t?sh(t,n,e):Nr(isNaN(t)?n:t)}}function Rr(e,t){var n=t-e;return n?oh(e,n):Nr(isNaN(e)?t:e)}const Dr=(function e(t){var n=ah(t);function i(r,o){var s=n((r=Cn(r)).r,(o=Cn(o)).r),a=n(r.g,o.g),c=n(r.b,o.b),l=Rr(r.opacity,o.opacity);return function(h){return r.r=s(h),r.g=a(h),r.b=c(h),r.opacity=l(h),r+""}}return i.gamma=e,i})(1);function re(e,t){return e=+e,t=+t,function(n){return e*(1-n)+t*n}}var En=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,Mn=new RegExp(En.source,"g");function ch(e){return function(){return e}}function lh(e){return function(t){return e(t)+""}}function hh(e,t){var n=En.lastIndex=Mn.lastIndex=0,i,r,o,s=-1,a=[],c=[];for(e=e+"",t=t+"";(i=En.exec(e))&&(r=Mn.exec(t));)(o=r.index)>n&&(o=t.slice(n,o),a[s]?a[s]+=o:a[++s]=o),(i=i[0])===(r=r[0])?a[s]?a[s]+=r:a[++s]=r:(a[++s]=null,c.push({i:s,x:re(i,r)})),n=Mn.lastIndex;return n<t.length&&(o=t.slice(n),a[s]?a[s]+=o:a[++s]=o),a.length<2?c[0]?lh(c[0].x):ch(t):(t=c.length,function(l){for(var h=0,u;h<t;++h)a[(u=c[h]).i]=u.x(l);return a.join("")})}var Fr=180/Math.PI,On={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function $r(e,t,n,i,r,o){var s,a,c;return(s=Math.sqrt(e*e+t*t))&&(e/=s,t/=s),(c=e*n+t*i)&&(n-=e*c,i-=t*c),(a=Math.sqrt(n*n+i*i))&&(n/=a,i/=a,c/=a),e*i<t*n&&(e=-e,t=-t,c=-c,s=-s),{translateX:r,translateY:o,rotate:Math.atan2(t,e)*Fr,skewX:Math.atan(c)*Fr,scaleX:s,scaleY:a}}var Rt;function uh(e){const t=new(typeof DOMMatrix=="function"?DOMMatrix:WebKitCSSMatrix)(e+"");return t.isIdentity?On:$r(t.a,t.b,t.c,t.d,t.e,t.f)}function fh(e){return e==null||(Rt||(Rt=document.createElementNS("http://www.w3.org/2000/svg","g")),Rt.setAttribute("transform",e),!(e=Rt.transform.baseVal.consolidate()))?On:(e=e.matrix,$r(e.a,e.b,e.c,e.d,e.e,e.f))}function zr(e,t,n,i){function r(l){return l.length?l.pop()+" ":""}function o(l,h,u,f,d,p){if(l!==u||h!==f){var m=d.push("translate(",null,t,null,n);p.push({i:m-4,x:re(l,u)},{i:m-2,x:re(h,f)})}else(u||f)&&d.push("translate("+u+t+f+n)}function s(l,h,u,f){l!==h?(l-h>180?h+=360:h-l>180&&(l+=360),f.push({i:u.push(r(u)+"rotate(",null,i)-2,x:re(l,h)})):h&&u.push(r(u)+"rotate("+h+i)}function a(l,h,u,f){l!==h?f.push({i:u.push(r(u)+"skewX(",null,i)-2,x:re(l,h)}):h&&u.push(r(u)+"skewX("+h+i)}function c(l,h,u,f,d,p){if(l!==u||h!==f){var m=d.push(r(d)+"scale(",null,",",null,")");p.push({i:m-4,x:re(l,u)},{i:m-2,x:re(h,f)})}else(u!==1||f!==1)&&d.push(r(d)+"scale("+u+","+f+")")}return function(l,h){var u=[],f=[];return l=e(l),h=e(h),o(l.translateX,l.translateY,h.translateX,h.translateY,u,f),s(l.rotate,h.rotate,u,f),a(l.skewX,h.skewX,u,f),c(l.scaleX,l.scaleY,h.scaleX,h.scaleY,u,f),l=h=null,function(d){for(var p=-1,m=f.length,y;++p<m;)u[(y=f[p]).i]=y.x(d);return u.join("")}}}var dh=zr(uh,"px, ","px)","deg)"),ph=zr(fh,", ",")",")");function gh(e,t){var n,i;return function(){var r=Y(this,e),o=r.tween;if(o!==n){i=n=o;for(var s=0,a=i.length;s<a;++s)if(i[s].name===t){i=i.slice(),i.splice(s,1);break}}r.tween=i}}function mh(e,t,n){var i,r;if(typeof n!="function")throw new Error;return function(){var o=Y(this,e),s=o.tween;if(s!==i){r=(i=s).slice();for(var a={name:t,value:n},c=0,l=r.length;c<l;++c)if(r[c].name===t){r[c]=a;break}c===l&&r.push(a)}o.tween=r}}function vh(e,t){var n=this._id;if(e+="",arguments.length<2){for(var i=B(this.node(),n).tween,r=0,o=i.length,s;r<o;++r)if((s=i[r]).name===e)return s.value;return null}return this.each((t==null?gh:mh)(n,e,t))}function Pn(e,t,n){var i=e._id;return e.each(function(){var r=Y(this,i);(r.value||(r.value={}))[t]=n.apply(this,arguments)}),function(r){return B(r,i).value[t]}}function Br(e,t){var n;return(typeof t=="number"?re:t instanceof Qe?Dr:(n=Qe(t))?(t=n,Dr):hh)(e,t)}function xh(e){return function(){this.removeAttribute(e)}}function yh(e){return function(){this.removeAttributeNS(e.space,e.local)}}function _h(e,t,n){var i,r=n+"",o;return function(){var s=this.getAttribute(e);return s===r?null:s===i?o:o=t(i=s,n)}}function wh(e,t,n){var i,r=n+"",o;return function(){var s=this.getAttributeNS(e.space,e.local);return s===r?null:s===i?o:o=t(i=s,n)}}function Sh(e,t,n){var i,r,o;return function(){var s,a=n(this),c;return a==null?void this.removeAttribute(e):(s=this.getAttribute(e),c=a+"",s===c?null:s===i&&c===r?o:(r=c,o=t(i=s,a)))}}function Ih(e,t,n){var i,r,o;return function(){var s,a=n(this),c;return a==null?void this.removeAttributeNS(e.space,e.local):(s=this.getAttributeNS(e.space,e.local),c=a+"",s===c?null:s===i&&c===r?o:(r=c,o=t(i=s,a)))}}function Ah(e,t){var n=wt(e),i=n==="transform"?ph:Br;return this.attrTween(e,typeof t=="function"?(n.local?Ih:Sh)(n,i,Pn(this,"attr."+e,t)):t==null?(n.local?yh:xh)(n):(n.local?wh:_h)(n,i,t))}function bh(e,t){return function(n){this.setAttribute(e,t.call(this,n))}}function Ch(e,t){return function(n){this.setAttributeNS(e.space,e.local,t.call(this,n))}}function Th(e,t){var n,i;function r(){var o=t.apply(this,arguments);return o!==i&&(n=(i=o)&&Ch(e,o)),n}return r._value=t,r}function Eh(e,t){var n,i;function r(){var o=t.apply(this,arguments);return o!==i&&(n=(i=o)&&bh(e,o)),n}return r._value=t,r}function Mh(e,t){var n="attr."+e;if(arguments.length<2)return(n=this.tween(n))&&n._value;if(t==null)return this.tween(n,null);if(typeof t!="function")throw new Error;var i=wt(e);return this.tween(n,(i.local?Th:Eh)(i,t))}function Oh(e,t){return function(){An(this,e).delay=+t.apply(this,arguments)}}function Ph(e,t){return t=+t,function(){An(this,e).delay=t}}function Lh(e){var t=this._id;return arguments.length?this.each((typeof e=="function"?Oh:Ph)(t,e)):B(this.node(),t).delay}function kh(e,t){return function(){Y(this,e).duration=+t.apply(this,arguments)}}function Nh(e,t){return t=+t,function(){Y(this,e).duration=t}}function Rh(e){var t=this._id;return arguments.length?this.each((typeof e=="function"?kh:Nh)(t,e)):B(this.node(),t).duration}function Dh(e,t){if(typeof t!="function")throw new Error;return function(){Y(this,e).ease=t}}function Fh(e){var t=this._id;return arguments.length?this.each(Dh(t,e)):B(this.node(),t).ease}function $h(e,t){return function(){var n=t.apply(this,arguments);if(typeof n!="function")throw new Error;Y(this,e).ease=n}}function zh(e){if(typeof e!="function")throw new Error;return this.each($h(this._id,e))}function Bh(e){typeof e!="function"&&(e=rr(e));for(var t=this._groups,n=t.length,i=new Array(n),r=0;r<n;++r)for(var o=t[r],s=o.length,a=i[r]=[],c,l=0;l<s;++l)(c=o[l])&&e.call(c,c.__data__,l,o)&&a.push(c);return new J(i,this._parents,this._name,this._id)}function Hh(e){if(e._id!==this._id)throw new Error;for(var t=this._groups,n=e._groups,i=t.length,r=n.length,o=Math.min(i,r),s=new Array(i),a=0;a<o;++a)for(var c=t[a],l=n[a],h=c.length,u=s[a]=new Array(h),f,d=0;d<h;++d)(f=c[d]||l[d])&&(u[d]=f);for(;a<i;++a)s[a]=t[a];return new J(s,this._parents,this._name,this._id)}function Uh(e){return(e+"").trim().split(/^|\s+/).every(function(t){var n=t.indexOf(".");return n>=0&&(t=t.slice(0,n)),!t||t==="start"})}function Yh(e,t,n){var i,r,o=Uh(t)?An:Y;return function(){var s=o(this,e),a=s.on;a!==i&&(r=(i=a).copy()).on(t,n),s.on=r}}function Gh(e,t){var n=this._id;return arguments.length<2?B(this.node(),n).on.on(e):this.each(Yh(n,e,t))}function Wh(e){return function(){var t=this.parentNode;for(var n in this.__transition)if(+n!==e)return;t&&t.removeChild(this)}}function Xh(){return this.on("end.remove",Wh(this._id))}function qh(e){var t=this._name,n=this._id;typeof e!="function"&&(e=xn(e));for(var i=this._groups,r=i.length,o=new Array(r),s=0;s<r;++s)for(var a=i[s],c=a.length,l=o[s]=new Array(c),h,u,f=0;f<c;++f)(h=a[f])&&(u=e.call(h,h.__data__,f,a))&&("__data__"in h&&(u.__data__=h.__data__),l[f]=u,Ot(l[f],t,n,f,l,B(h,n)));return new J(o,this._parents,t,n)}function Kh(e){var t=this._name,n=this._id;typeof e!="function"&&(e=ir(e));for(var i=this._groups,r=i.length,o=[],s=[],a=0;a<r;++a)for(var c=i[a],l=c.length,h,u=0;u<l;++u)if(h=c[u]){for(var f=e.call(h,h.__data__,u,c),d,p=B(h,n),m=0,y=f.length;m<y;++m)(d=f[m])&&Ot(d,t,n,m,f,p);o.push(f),s.push(h)}return new J(o,s,t,n)}var Vh=We.prototype.constructor;function Jh(){return new Vh(this._groups,this._parents)}function Zh(e,t){var n,i,r;return function(){var o=Te(this,e),s=(this.style.removeProperty(e),Te(this,e));return o===s?null:o===n&&s===i?r:r=t(n=o,i=s)}}function Hr(e){return function(){this.style.removeProperty(e)}}function jh(e,t,n){var i,r=n+"",o;return function(){var s=Te(this,e);return s===r?null:s===i?o:o=t(i=s,n)}}function Qh(e,t,n){var i,r,o;return function(){var s=Te(this,e),a=n(this),c=a+"";return a==null&&(c=a=(this.style.removeProperty(e),Te(this,e))),s===c?null:s===i&&c===r?o:(r=c,o=t(i=s,a))}}function eu(e,t){var n,i,r,o="style."+t,s="end."+o,a;return function(){var c=Y(this,e),l=c.on,h=c.value[o]==null?a||(a=Hr(t)):void 0;(l!==n||r!==h)&&(i=(n=l).copy()).on(s,r=h),c.on=i}}function tu(e,t,n){var i=(e+="")=="transform"?dh:Br;return t==null?this.styleTween(e,Zh(e,i)).on("end.style."+e,Hr(e)):typeof t=="function"?this.styleTween(e,Qh(e,i,Pn(this,"style."+e,t))).each(eu(this._id,e)):this.styleTween(e,jh(e,i,t),n).on("end.style."+e,null)}function nu(e,t,n){return function(i){this.style.setProperty(e,t.call(this,i),n)}}function iu(e,t,n){var i,r;function o(){var s=t.apply(this,arguments);return s!==r&&(i=(r=s)&&nu(e,s,n)),i}return o._value=t,o}function ru(e,t,n){var i="style."+(e+="");if(arguments.length<2)return(i=this.tween(i))&&i._value;if(t==null)return this.tween(i,null);if(typeof t!="function")throw new Error;return this.tween(i,iu(e,t,n??""))}function ou(e){return function(){this.textContent=e}}function su(e){return function(){var t=e(this);this.textContent=t??""}}function au(e){return this.tween("text",typeof e=="function"?su(Pn(this,"text",e)):ou(e==null?"":e+""))}function cu(e){return function(t){this.textContent=e.call(this,t)}}function lu(e){var t,n;function i(){var r=e.apply(this,arguments);return r!==n&&(t=(n=r)&&cu(r)),t}return i._value=e,i}function hu(e){var t="text";if(arguments.length<1)return(t=this.tween(t))&&t._value;if(e==null)return this.tween(t,null);if(typeof e!="function")throw new Error;return this.tween(t,lu(e))}function uu(){for(var e=this._name,t=this._id,n=Ur(),i=this._groups,r=i.length,o=0;o<r;++o)for(var s=i[o],a=s.length,c,l=0;l<a;++l)if(c=s[l]){var h=B(c,t);Ot(c,e,n,l,s,{time:h.time+h.delay+h.duration,delay:0,duration:h.duration,ease:h.ease})}return new J(i,this._parents,e,n)}function fu(){var e,t,n=this,i=n._id,r=n.size();return new Promise(function(o,s){var a={value:s},c={value:function(){--r===0&&o()}};n.each(function(){var l=Y(this,i),h=l.on;h!==e&&(t=(e=h).copy(),t._.cancel.push(a),t._.interrupt.push(a),t._.end.push(c)),l.on=t}),r===0&&o()})}var du=0;function J(e,t,n,i){this._groups=e,this._parents=t,this._name=n,this._id=i}function Ur(){return++du}var Z=We.prototype;J.prototype={constructor:J,select:qh,selectAll:Kh,selectChild:Z.selectChild,selectChildren:Z.selectChildren,filter:Bh,merge:Hh,selection:Jh,transition:uu,call:Z.call,nodes:Z.nodes,node:Z.node,size:Z.size,empty:Z.empty,each:Z.each,on:Gh,attr:Ah,attrTween:Mh,style:tu,styleTween:ru,text:au,textTween:hu,remove:Xh,tween:vh,delay:Lh,duration:Rh,ease:Fh,easeVarying:zh,end:fu,[Symbol.iterator]:Z[Symbol.iterator]};function pu(e){return((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2}var gu={time:null,delay:0,duration:250,ease:pu};function mu(e,t){for(var n;!(n=e.__transition)||!(n=n[t]);)if(!(e=e.parentNode))throw new Error(`transition ${t} not found`);return n}function vu(e){var t,n;e instanceof J?(t=e._id,e=e._name):(t=Ur(),(n=gu).time=_n(),e=e==null?null:e+"");for(var i=this._groups,r=i.length,o=0;o<r;++o)for(var s=i[o],a=s.length,c,l=0;l<a;++l)(c=s[l])&&Ot(c,e,t,l,s,n||mu(c,t));return new J(i,this._parents,e,t)}We.prototype.interrupt=Xl,We.prototype.transition=vu;class xu extends ft{name="viewport";minScale;maxScale;_dragEnabled;transitionDuration;canvas;d3Sel;d3Zoom;_hitObject=!1;_stageDown;constructor(t){super(),this.minScale=t?.minScale??.1,this.maxScale=t?.maxScale??10,this._dragEnabled=t?.dragEnabled??!0,this.transitionDuration=t?.transitionDuration??300}get dragEnabled(){return this._dragEnabled}set dragEnabled(t){this._dragEnabled=t}install(t){super.install(t),this.canvas=t.app.canvas}onBindActiveScene(t){const n=this.topology;if(!n||!this.canvas)return;const i=this.canvas,r=n.app.stage,o=t.projectionContainer;this._stageDown=a=>{this._hitObject=a.target!==r},r.on("pointerdown",this._stageDown),this.d3Zoom=oe.zoom().scaleExtent([this.minScale,this.maxScale]).filter(a=>a.button||a.ctrlKey&&a.type!=="wheel"?!1:a.type==="wheel"||a.type==="dblclick"?!0:this._dragEnabled&&!this._hitObject).on("zoom",a=>{const{x:c,y:l,k:h}=a.transform;o.scale.set(h),o.position.set(c,l)}),this.d3Sel=Nl(i),this.d3Sel.call(this.d3Zoom);const s=new oe.ZoomTransform(o.scale.x,o.x,o.y);this.d3Sel.call(this.d3Zoom.transform,s),t.setCameraHandler(a=>{if(!this.d3Sel||!this.d3Zoom){t.applyCamera(a);return}const c=new oe.ZoomTransform(a.zoom,a.x,a.y),l=this.transitionDuration;if(l<=0){t.applyCamera(a),this.d3Sel.property("__zoom",c);return}return new Promise(h=>{this.d3Sel.transition().duration(l).call(this.d3Zoom.transform,c).on("end",()=>h()).on("interrupt",()=>{h()})})})}onUnbindActiveScene(){this.activeScene?.setCameraHandler(void 0);const t=this.topology?.app.stage;t&&this._stageDown&&t.off("pointerdown",this._stageDown),this._stageDown=void 0,this._hitObject=!1,this.d3Sel&&(this.d3Sel.on(".zoom",null),this.d3Sel=void 0),this.d3Zoom=void 0}uninstall(t){this.canvas=void 0,super.uninstall(t)}getTransform(){return this.d3Sel?oe.zoomTransform(this.d3Sel.node()):oe.zoomIdentity}zoomTo(t,n,i){if(!this.d3Sel||!this.d3Zoom||!this.canvas)return;const r=n??this.canvas.clientWidth/2,o=i??this.canvas.clientHeight/2;this.d3Sel.call(this.d3Zoom.scaleTo,t,[r,o])}panTo(t,n){if(!this.d3Sel||!this.d3Zoom)return;const i=this.getTransform().k;this.d3Sel.call(this.d3Zoom.transform,new oe.ZoomTransform(i,t,n))}}class yu extends _t{name="node-editor";targetType="node";get highlightOptions(){return{padding:4,lineWidth:3}}getCollection(t){return t.nodes}getItemId(t){return t.id}getItemPosition(t){return{x:t.x,y:t.y}}snapDelta(t){return ie(t)/v}applyDrag(t,n,i,r){t.setPosition(n,i),r.lines?.redrawLinesForNode(t.id)}onDragEnd(t,n){t.setOptions({x:t.x,y:t.y}),n.lines?.redrawLinesForNode(t.id)}}class _u extends Ce{name="line-editor";editStates=new Map;selectedLineId=null;dragCtx=null;RADIUS=12;COLOR_POSITION=4886754;COLOR_NODE=8947848;TEXT_COLOR=16777215;TEXT_SIZE=14;hookScene(t){const n=t.lines;for(const o of n.getAll())this.attachLine(o,t);const i=o=>this.attachLine(o,t),r=({id:o})=>this.detachLine(o);return n.on("line:added",i),n.on("line:removed",r),()=>{n.off("line:added",i),n.off("line:removed",r);for(const o of n.getAll())this.detachLine(o.id)}}onItemPointerDown({itemType:t,itemId:n}){if(t!=="line"){t!==null?this.clearSelectionSilent():this.clearSelection();return}n&&this.selectedLineId!==n&&this.select(n)}attachLine(t,n){const i=t.getContainer();i.eventMode="static",i.cursor="pointer";const r=new w.Container;r.visible=!1,r.zIndex=1e4,n.projectionContainer.addChild(r);const o=a=>{this.selectedLineId===t.id&&this.handlePathDrag(a,t,n)},s=()=>{this.selectedLineId===t.id&&this.renderMarkers(this.editStates.get(t.id))};i.on("pointerdown",o),t.on("points:changed",s),this.editStates.set(t.id,{line:t,scene:n,markersContainer:r,onLinePointerDown:o,onPointsChanged:s})}detachLine(t){const n=this.editStates.get(t);if(!n)return;const i=n.line.getContainer();i.off("pointerdown",n.onLinePointerDown),n.line.off("points:changed",n.onPointsChanged),i.eventMode="auto",i.cursor="default",n.markersContainer.destroy({children:!0}),this.editStates.delete(t),this.selectedLineId===t&&(this.selectedLineId=null)}savedZIndex=null;SELECTED_ZINDEX=9999;select(t){if(this.selectedLineId&&this.selectedLineId!==t&&this.clearSelectionSilent(),this.selectedLineId===t){this.deselect(t);return}const n=this.editStates.get(t);if(!n)return;this.selectedLineId=t;const i=n.line.getContainer();this.savedZIndex=i.zIndex,i.zIndex=this.SELECTED_ZINDEX,this.renderMarkers(n),this.topology?.emit("selection:changed",{pluginName:this.name,itemType:"line",itemId:t})}deselect(t){const n=this.editStates.get(t);n&&(this.savedZIndex!==null&&(n.line.getContainer().zIndex=this.savedZIndex,this.savedZIndex=null),this.selectedLineId=null,this.cancelDrag(),n.markersContainer.visible=!1,n.markersContainer.removeChildren(),this.topology?.emit("selection:changed",{pluginName:this.name,itemType:"line",itemId:null}))}getSelectedLineId(){return this.selectedLineId}clearSelection(){this.selectedLineId&&this.deselect(this.selectedLineId)}clearSelectionSilent(){if(!this.selectedLineId)return;const t=this.editStates.get(this.selectedLineId);t&&(this.savedZIndex!==null&&(t.line.getContainer().zIndex=this.savedZIndex,this.savedZIndex=null),this.selectedLineId=null,this.cancelDrag(),t.markersContainer.visible=!1,t.markersContainer.removeChildren())}renderMarkers(t){const{line:n,scene:i,markersContainer:r}=t,o=n.options.anchor;r.removeChildren(),o.forEach((s,a)=>{const c=n.resolveAnchorPosition(s);if(!c)return;const l=n.isAnchorNode(s),h=this.createMarker(a,l);h.position.set(c.x*v,c.y*v),l||(h.eventMode="static",h.cursor="grab",h.on("pointerdown",u=>{u.stopPropagation(),this.startAnchorDrag(n.id,a,i,!1)})),r.addChild(h)}),r.visible=!0}createMarker(t,n){const i=new w.Container,r=new w.Graphics;r.circle(0,0,this.RADIUS),r.fill({color:n?this.COLOR_NODE:this.COLOR_POSITION,alpha:n?.5:1}),r.stroke({color:16777215,width:2,alpha:n?.4:.8});const o=new w.Text({text:t.toString(),style:{fontSize:this.TEXT_SIZE,fill:this.TEXT_COLOR,fontWeight:"bold"}});return o.anchor.set(.5),i.addChild(r,o),i}startAnchorDrag(t,n,i,r){this.cancelDrag();const o=this.editStates.get(t);if(!o)return;const s=i.projectionContainer,a=i.stage,c=h=>{const u=s.toLocal(h.global),f=ie(u.x)/v,d=ie(u.y)/v;o.line.updateAnchorPosition(n,f,d),this.renderMarkers(o)},l=()=>{a.off("globalpointermove",c),a.off("pointerup",l),a.off("pointerupoutside",l),this.dragCtx=null,o.line.draw(),this.renderMarkers(o)};a.on("globalpointermove",c),a.on("pointerup",l),a.on("pointerupoutside",l),this.dragCtx={lineId:t,anchorIndex:n,isNewAnchor:r,onMove:c,onUp:l}}cancelDrag(){if(!this.dragCtx)return;const t=this.editStates.get(this.dragCtx.lineId);if(t){const n=t.scene.stage;n.off("globalpointermove",this.dragCtx.onMove),n.off("pointerup",this.dragCtx.onUp),n.off("pointerupoutside",this.dragCtx.onUp)}this.dragCtx=null}handlePathDrag(t,n,i){const r=i.projectionContainer,o=r.toLocal(t.global),s=ie(o.x)/v,a=ie(o.y)/v,c=n.options.anchor;for(const x of c){const I=n.resolveAnchorPosition(x);if(I&&I.x===s&&I.y===a)return}const l=n.getPoints();if(l.length<2)return;const h={x:s*v,y:a*v};let u=1/0,f=0;for(let x=0;x<l.length-1;x++){const I=Ui(h,l[x],l[x+1]);I<u&&(u=I,f=x)}const d=this.findAnchorInsertIndex(n,i,f),p=i.stage;let m=!1;const y=x=>{if(!m){m=!0;const I=r.toLocal(x.global),A=ie(I.x)/v,O=ie(I.y)/v,R={x:A,y:O};n.insertAnchor(d,R),this.renderMarkers(this.editStates.get(n.id)),p.off("globalpointermove",y),p.off("pointerup",S),p.off("pointerupoutside",S),this.startAnchorDrag(n.id,d,i,!0)}},S=()=>{p.off("globalpointermove",y),p.off("pointerup",S),p.off("pointerupoutside",S)};p.on("globalpointermove",y),p.on("pointerup",S),p.on("pointerupoutside",S)}findAnchorInsertIndex(t,n,i){const r=t.options.anchor,o=t.getPoints();if(r.length<=2)return 1;const s=[];for(let c=0;c<r.length;c++){const l=t.resolveAnchorPosition(r[c]);l&&s.push({px:l.x*v,py:l.y*v,anchorIdx:c})}const a=[];for(const c of s){let l=0,h=1/0;for(let u=0;u<o.length;u++){const f=o[u].x-c.px,d=o[u].y-c.py,p=f*f+d*d;p<h&&(h=p,l=u)}a.push(l)}for(let c=0;c<a.length-1;c++)if(i>=a[c]&&i<a[c+1])return s[c].anchorIdx+1;return r.length-1}}class wu extends _t{name="text-editor";targetType="text";step;constructor(t){super(),this.step=t?.step??1}get highlightOptions(){return{radius:4}}getCollection(t){return t.texts}getItemId(t){return t.id}getItemPosition(t){return{x:t.x,y:t.y}}snapDelta(t){const n=this.step*v;return Math.round(t/n)*this.step}applyDrag(t,n,i){t.setOptions({x:n,y:i})}}class Su extends _t{name="rect-drag";targetType="rect";step;constructor(t){super(),this.step=t?.step??1}getCollection(t){return t.rects}getItemId(t){return t.id}getItemPosition(t){return{x:t.x,y:t.y}}snapDelta(t){const n=this.step*v;return Math.round(t/n)*this.step}applyDrag(t,n,i){t.setOptions({x:n,y:i})}onAttachItem(t){const n=o=>this.selectItem(o),i=o=>{this.selected?.id===o.id&&this.clearSelection()},r=()=>{this.selected?.id===t.id&&this.highlight.draw(t.getGraphics())};return t.on("item:selected",n),t.on("item:deselected",i),t.on("options:changed",r),()=>{t.off("item:selected",n),t.off("item:deselected",i),t.off("options:changed",r)}}}class Iu extends Ce{name="rect-resize";resizeHandles;activeRect=null;resizeState={isResizing:!1,handle:null,startRect:{x:0,y:0,width:0,height:0},startMouse:{x:0,y:0}};resizeGlobalHandlers;step;rectListeners=new Map;constructor(t){super(),this.step=t?.step??1}hookScene(t){const{rects:n}=t;for(const s of n.getAll())this.attachListeners(s);const i=s=>this.attachListeners(s),r=({id:s})=>this.detachListeners(s),o=()=>{for(const s of n.getAll())this.detachListeners(s.id)};return n.on("rect:added",i),n.on("rect:removed",r),n.on("rects:cleared",o),()=>{n.off("rect:added",i),n.off("rect:removed",r),n.off("rects:cleared",o);for(const s of n.getAll())this.detachListeners(s.id)}}onSceneSwitched(){this.activeRect?.deselect()}attachListeners(t){if(this.rectListeners.has(t.id))return;const n={rect:t,onSelected:i=>{this.activeRect=i,this.drawResizeHandles(i)},onDeselected:i=>{this.activeRect=null,this.cleanupResizeHandles()},onOptionsChanged:()=>{this.activeRect?.id===t.id&&!this.resizeState.isResizing&&this.updateHandlesPosition(t)}};t.on("item:selected",n.onSelected),t.on("item:deselected",n.onDeselected),t.on("options:changed",n.onOptionsChanged),this.rectListeners.set(t.id,n)}detachListeners(t){const n=this.rectListeners.get(t);if(!n)return;this.activeRect?.id===t&&(this.activeRect=null,this.cleanupResizeHandles());const{rect:i}=n;i.off("item:selected",n.onSelected),i.off("item:deselected",n.onDeselected),i.off("options:changed",n.onOptionsChanged),this.rectListeners.delete(t)}drawResizeHandles(t){this.cleanupResizeHandles();const n=t.getGraphics(),i=n.getLocalBounds(),r=8,o=4886754,s=16777215,a=new w.Container;a.position.copyFrom(n.position);const c=[{type:"nw",x:i.x,y:i.y,cursor:"nw-resize"},{type:"n",x:i.x+i.width/2,y:i.y,cursor:"ns-resize"},{type:"ne",x:i.x+i.width,y:i.y,cursor:"ne-resize"},{type:"e",x:i.x+i.width,y:i.y+i.height/2,cursor:"ew-resize"},{type:"se",x:i.x+i.width,y:i.y+i.height,cursor:"se-resize"},{type:"s",x:i.x+i.width/2,y:i.y+i.height,cursor:"ns-resize"},{type:"sw",x:i.x,y:i.y+i.height,cursor:"sw-resize"},{type:"w",x:i.x,y:i.y+i.height/2,cursor:"ew-resize"}],l=this.topology;if(!l)return;const h=l.activeScene;if(!h)return;c.forEach(({type:p,x:m,y,cursor:S})=>{const x=new w.Graphics;x.rect(-r/2,-r/2,r,r),x.fill({color:o}),x.stroke({color:s,width:2}),x.position.set(m,y),x.eventMode="static",x.cursor=S,x.on("pointerdown",I=>{I.stopPropagation(),this.resizeState.isResizing=!0,this.resizeState.handle=p;const A=h.projectionContainer.toLocal(I.global);this.resizeState.startMouse={x:A.x,y:A.y},this.resizeState.startRect={x:t.x,y:t.y,width:t.options.width,height:t.options.height}}),a.addChild(x)});const u=p=>{if(!this.resizeState.isResizing||!this.resizeState.handle)return;const m=h.projectionContainer.toLocal(p.global),y=(m.x-this.resizeState.startMouse.x)/v,S=(m.y-this.resizeState.startMouse.y)/v;this.applyResize(t,this.resizeState.handle,y,S)},f=()=>{this.resizeState.isResizing&&(this.resizeState.isResizing=!1,this.resizeState.handle=null)};this.resizeGlobalHandlers={onMove:u,onUp:f};const d=this.topology?.stage;d&&(d.on("globalpointermove",u),d.on("pointerup",f),d.on("pointerupoutside",f)),n.parent?.addChild(a),this.resizeHandles=a}cleanupResizeHandles(){if(this.resizeGlobalHandlers){const t=this.topology?.stage;t&&(t.off("globalpointermove",this.resizeGlobalHandlers.onMove),t.off("pointerup",this.resizeGlobalHandlers.onUp),t.off("pointerupoutside",this.resizeGlobalHandlers.onUp)),this.resizeGlobalHandlers=void 0}this.resizeHandles?.destroy(),this.resizeHandles=void 0}updateHandlesPosition(t){if(!this.resizeHandles)return;const n=t.getGraphics();this.resizeHandles.position.copyFrom(n.position)}applyResize(t,n,i,r){const{startRect:o}=this.resizeState;let s=o.x,a=o.y,c=o.width,l=o.height;switch(n){case"nw":s=o.x+i,a=o.y+r,c=o.width-i,l=o.height-r;break;case"n":a=o.y+r,l=o.height-r;break;case"ne":a=o.y+r,c=o.width+i,l=o.height-r;break;case"e":c=o.width+i;break;case"se":c=o.width+i,l=o.height+r;break;case"s":l=o.height+r;break;case"sw":s=o.x+i,c=o.width-i,l=o.height+r;break;case"w":s=o.x+i,c=o.width-i;break}c<0&&(s+=c,c=-c),l<0&&(a+=l,l=-l),s=Math.round(s/this.step)*this.step,a=Math.round(a/this.step)*this.step,c=Math.round(c/this.step)*this.step,l=Math.round(l/this.step)*this.step;const h=this.step;c<h&&(c=h),l<h&&(l=h),t.setOptions({x:s,y:a,width:c,height:l}),this.drawResizeHandles(t)}}class Au extends Ge{name="node-runtime";targetType="node";getCollection(t){return t.nodes}getItemId(t){return t.id}}class bu extends Ge{name="line-runtime";targetType="line";getCollection(t){return t.lines}getItemId(t){return t.id}}class Cu extends Ge{name="text-runtime";targetType="text";getCollection(t){return t.texts}getItemId(t){return t.id}}class Tu extends Ge{name="rect-runtime";targetType="rect";getCollection(t){return t.rects}getItemId(t){return t.id}}class et extends ft{_isActive=!1;_opts;_prevDragEnabled=null;_panning=!1;_cleanupKeys;_pendingResolve;_pendingReject;constructor(t){super(),this._opts={rightClickToStop:t?.rightClickToStop??!0,panningKey:t?.panningKey??"Space",suppressSelection:t?.suppressSelection??!0}}get isActive(){return this._isActive}get isPanning(){return this._panning}stop(){if(!this._isActive)return;this._isActive=!1,this.onStop(),this._endPan(),this._unbindKeys(),this._setHitTest(!0),this._restoreViewportDrag();const t=this._pendingReject;this._pendingResolve=void 0,this._pendingReject=void 0,t?.()}activate(){this._isActive&&this.stop();const t=this.activeScene;return!t||!this.topology?null:(this._isActive=!0,this._disableViewportDrag(),this._setHitTest(!1),this._bindKeys(),t)}createPending(){return new Promise((t,n)=>{this._pendingResolve=t,this._pendingReject=n})}complete(t){const n=this._pendingResolve;this._pendingResolve=void 0,this._pendingReject=void 0,this.stop(),n?.(t)}onBindActiveScene(t){}onUnbindActiveScene(){this.stop()}uninstall(t){this.stop(),super.uninstall(t)}_disableViewportDrag(){const t=this.topology?.getPlugin("viewport");t&&(this._prevDragEnabled=t.dragEnabled,t.dragEnabled=!1)}_restoreViewportDrag(){if(this._prevDragEnabled===null)return;const t=this.topology?.getPlugin("viewport");t&&(t.dragEnabled=this._prevDragEnabled),this._prevDragEnabled=null}_setHitTest(t){if(!this._opts.suppressSelection)return;const n=this.topology?.getPlugin("hit-test");n&&(n.enabled=t),this.activeScene&&(this.activeScene.projectionContainer.interactiveChildren=t)}_bindKeys(){const t=this.topology?.app?.canvas;if(!t)return;const{panningKey:n,rightClickToStop:i}=this._opts,r=a=>{n&&a.code===n&&!this._panning&&(a.preventDefault(),this._beginPan())},o=a=>{n&&a.code===n&&this._panning&&this._endPan()},s=a=>{i&&(a.preventDefault(),this.stop())};window.addEventListener("keydown",r),window.addEventListener("keyup",o),t.addEventListener("contextmenu",s),this._cleanupKeys=()=>{window.removeEventListener("keydown",r),window.removeEventListener("keyup",o),t.removeEventListener("contextmenu",s)}}_unbindKeys(){this._cleanupKeys?.(),this._cleanupKeys=void 0}_beginPan(){this._panning=!0;const t=this.topology?.getPlugin("viewport");t&&(t.dragEnabled=!0),this.topology?.stage&&(this.topology.stage.cursor="grab")}_endPan(){if(!this._panning)return;this._panning=!1;const t=this.topology?.getPlugin("viewport");t&&(t.dragEnabled=!1),this.topology?.stage&&(this.topology.stage.cursor="crosshair")}toTile(t,n){const i=n.projectionContainer.toLocal(t.global);return{x:Math.round(i.x/v),y:Math.round(i.y/v)}}}class Eu extends et{name="text-creator";_defaults={};_previewId=null;_handlers=null;constructor(t){super(t)}start(t){this._defaults=t??{};const n=this.activate();return n?(this._createPreview(n),this._bindEvents(n),this.createPending()):Promise.reject()}onStop(){this._removePreview(),this._unbindEvents()}_createPreview(t){const n=$e();this._previewId=n;const i=t.texts.add({id:n,x:0,y:0,...this._defaults,text:this._defaults.text??"Text"});i.getGraphics().alpha=.5}_removePreview(){this._previewId&&this.activeScene?.texts.has(this._previewId)&&this.activeScene.texts.remove(this._previewId),this._previewId=null}_bindEvents(t){const n=this.topology.stage;if(!n)return;const i=o=>{if(this.isPanning||!this._previewId||!this.activeScene)return;const s=this.toTile(o,t);this.activeScene.texts.get(this._previewId)?.setOptions({x:s.x,y:s.y})},r=o=>{if(o.button!==0||this.isPanning||!this._previewId||!this.activeScene)return;const s=this.activeScene.texts.get(this._previewId);s&&(s.getGraphics().alpha=1);const a=this._previewId;this._previewId=null,this.complete(a)};n.on("globalpointermove",i),n.on("pointerdown",r),this._handlers={onMove:i,onDown:r},n.cursor="crosshair"}_unbindEvents(){const t=this.topology?.stage;!t||!this._handlers||(t.off("globalpointermove",this._handlers.onMove),t.off("pointerdown",this._handlers.onDown),t.cursor="default",this._handlers=null)}}class Mu extends et{name="rect-creator";_defaults={};_previewId=null;_isDragging=!1;_startTile={x:0,y:0};_handlers=null;constructor(t){super(t)}start(t){this._defaults=t??{};const n=this.activate();return n?(this._bindEvents(n),this.createPending()):Promise.reject()}onStop(){this._removePreview(),this._unbindEvents(),this._isDragging=!1}_removePreview(){this._previewId&&this.activeScene?.rects.has(this._previewId)&&this.activeScene.rects.remove(this._previewId),this._previewId=null}_bindEvents(t){const n=this.topology.stage;if(!n)return;const i=s=>{if(s.button!==0||this.isPanning||this._isDragging)return;this._isDragging=!0;const a=this.toTile(s,t);this._startTile=a;const c=$e();this._previewId=c;const l=t.rects.add({id:c,x:a.x,y:a.y,width:1,height:1,...this._defaults});l.getGraphics().alpha=.5},r=s=>{if(this.isPanning||!this._isDragging||!this._previewId||!this.activeScene)return;const a=this.toTile(s,t),c=Math.min(this._startTile.x,a.x),l=Math.min(this._startTile.y,a.y),h=Math.max(1,Math.abs(a.x-this._startTile.x)),u=Math.max(1,Math.abs(a.y-this._startTile.y));this.activeScene.rects.get(this._previewId)?.setOptions({x:c,y:l,width:h,height:u})},o=s=>{if(this.isPanning||!this._isDragging)return;this._isDragging=!1;const a=this.activeScene?.rects.get(this._previewId);a&&(a.getGraphics().alpha=1);const c=this._previewId;this._previewId=null,this.complete(c)};n.on("pointerdown",i),n.on("globalpointermove",r),n.on("pointerup",o),n.on("pointerupoutside",o),this._handlers={onDown:i,onMove:r,onUp:o},n.cursor="crosshair"}_unbindEvents(){const t=this.topology?.stage;!t||!this._handlers||(t.off("pointerdown",this._handlers.onDown),t.off("globalpointermove",this._handlers.onMove),t.off("pointerup",this._handlers.onUp),t.off("pointerupoutside",this._handlers.onUp),t.cursor="default",this._handlers=null)}}class Ou extends et{name="line-creator";_defaults={};_previewId=null;_isDragging=!1;_handlers=null;constructor(t){super(t)}start(t){this._defaults=t??{};const n=this.activate();return n?(this._bindEvents(n),this.createPending()):Promise.reject()}onStop(){this._removePreview(),this._unbindEvents(),this._isDragging=!1}_removePreview(){this._previewId&&this.activeScene?.lines.has(this._previewId)&&this.activeScene.lines.remove(this._previewId),this._previewId=null}_bindEvents(t){const n=this.topology.stage;if(!n)return;const i=s=>{if(s.button!==0||this.isPanning||this._isDragging)return;this._isDragging=!0;const a=this.toTile(s,t),c=$e();this._previewId=c;const l=t.lines.add({id:c,anchor:[{x:a.x,y:a.y},{x:a.x,y:a.y}],...this._defaults});l.getGraphics().alpha=.5,l.draw()},r=s=>{if(this.isPanning||!this._isDragging||!this._previewId||!this.activeScene)return;const a=this.toTile(s,t);this.activeScene.lines.get(this._previewId)?.updateAnchorPosition(1,a.x,a.y)},o=s=>{if(this.isPanning||!this._isDragging)return;this._isDragging=!1;const a=this.activeScene?.lines.get(this._previewId);a&&(a.getGraphics().alpha=1,a.draw());const c=this._previewId;this._previewId=null,this.complete(c)};n.on("pointerdown",i),n.on("globalpointermove",r),n.on("pointerup",o),n.on("pointerupoutside",o),this._handlers={onDown:i,onMove:r,onUp:o},n.cursor="crosshair"}_unbindEvents(){const t=this.topology?.stage;!t||!this._handlers||(t.off("pointerdown",this._handlers.onDown),t.off("globalpointermove",this._handlers.onMove),t.off("pointerup",this._handlers.onUp),t.off("pointerupoutside",this._handlers.onUp),t.cursor="default",this._handlers=null)}}class Pu extends et{name="node-creator";_defaults={};_previewId=null;_tempIconIds=new Set;_promotedIconIds=new Set;_handlers=null;constructor(t){super(t)}start(t,n){this._defaults=t??{};const i=this.activate();return i?(this._registerTempIcons(n),this._createPreview(i),this._bindEvents(i),this.createPending()):Promise.reject()}onStop(){this._removePreview(),this._unbindEvents(),this._removeTempIcons()}_registerTempIcons(t){if(!(!t?.length||!this.topology))for(const n of t)this.topology.icons.has(n.id)||(this.topology.icons.add(n),this._tempIconIds.add(n.id))}_removeTempIcons(){if(this.topology){for(const t of this._tempIconIds)this._promotedIconIds.has(t)||this.topology.icons.remove(t);this._tempIconIds.clear(),this._promotedIconIds.clear()}}_createPreview(t){const n=$e();this._previewId=n;const i=t.nodes.add({icon:"",...this._defaults,id:n,x:0,y:0});i.getGraphics().alpha=.5}_removePreview(){this._previewId&&this.activeScene?.nodes.has(this._previewId)&&this.activeScene.nodes.remove(this._previewId),this._previewId=null}_bindEvents(t){const n=this.topology.stage;if(!n)return;const i=o=>{if(this.isPanning||!this._previewId||!this.activeScene)return;const s=this.toTile(o,t);this.activeScene.nodes.get(this._previewId)?.setOptions({x:s.x,y:s.y})},r=o=>{if(o.button!==0||this.isPanning||!this._previewId||!this.activeScene)return;const s=this.activeScene.nodes.get(this._previewId);if(s){s.getGraphics().alpha=1;const c=s.options.icon;c&&this._tempIconIds.has(c)&&this._promotedIconIds.add(c)}const a=this._previewId;this._previewId=null,this.complete(a)};n.on("globalpointermove",i),n.on("pointerdown",r),this._handlers={onMove:i,onDown:r},n.cursor="crosshair"}_unbindEvents(){const t=this.topology?.stage;!t||!this._handlers||(t.off("globalpointermove",this._handlers.onMove),t.off("pointerdown",this._handlers.onDown),t.cursor="default",this._handlers=null)}}Object.defineProperty(g,"ZoomTransform",{enumerable:!0,get:()=>oe.ZoomTransform}),g.AZIMUTH=le,g.ActiveScenePlugin=ft,g.BILLBOARD_SCALE_X=cn,g.BILLBOARD_SCALE_Y=Fe,g.BILLBOARD_SKEW_X=sn,g.BILLBOARD_SKEW_Y=an,g.BaseCreatorPlugin=et,g.COS_ELEVATION=De,g.ELEVATION=Jt,g.HitTestPlugin=Zi,g.ISOMETRIC_SKEW_X=Qt,g.ISOMETRIC_SKEW_Y=en,g.IconManager=ji,g.InteractiveRuntimePlugin=Ge,g.LineCreatorPlugin=Ou,g.LineEditorPlugin=_u,g.LineRuntimePlugin=bu,g.NodeCreatorPlugin=Pu,g.NodeEditorPlugin=yu,g.NodeRuntimePlugin=Au,g.RectCreatorPlugin=Mu,g.RectDragPlugin=Su,g.RectResizePlugin=Iu,g.RectRuntimePlugin=Tu,g.SIN_ELEVATION=ne,g.Scene=he,g.SceneAwarePlugin=Ce,g.SelectableEditorPlugin=_t,g.SelectionHighlight=er,g.StateManager=Qi,g.TILE_HDIAGONAL=ua,g.TILE_HEIGHT=ha,g.TILE_SIZE=v,g.TILE_VDIAGONAL=Zt,g.TILE_WIDTH=la,g.TextCreatorPlugin=Eu,g.TextEditorPlugin=wu,g.TextRuntimePlugin=Cu,g.Topology=yt,g.ViewportPlugin=xu,g.calculateIsometricSkew=jt,g.calculateIsometricTileDiagonals=fa,g.createBlinkStatePlugin=Ba,g.createBounceStatePlugin=Ha,g.createBrightenStatePlugin=Ua,g.createDarkenStatePlugin=Ya,g.createGlowStatePlugin=Ka,g.createHeartbeatStatePlugin=Va,g.createShimmerStatePlugin=Qa,g.createTintStatePlugin=ec,g.default=yt,g.downloadFile=Ue,g.findPath=Yi,g.generateUUID=$e,g.getBoundingBox=Gi,g.getBoundingBoxSize=Wi,g.getItemMetadata=Ki,g.isometricToWorld=pa,g.normalizePositionFromOrigin=Xi,g.parseYaml=ce,g.pointToSegmentDist=Ui,g.projectToIsometric=da,g.setItemMetadata=ze,g.snapToTile=ie,g.sortByPosition=ln,g.toYaml=ae,Object.defineProperties(g,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
162
+ `;class ja extends w.Filter{_angle;constructor(t={}){const n=t.width??.35,i=t.intensity??.6,r=t.angle??Math.PI/6,o=w.GlProgram.from({vertex:Ja,fragment:Za,name:"shimmer-filter"});super({glProgram:o,resources:{shimmerUniforms:new w.UniformGroup({uPhase:{value:0,type:"f32"},uWidth:{value:n,type:"f32"},uIntensity:{value:i,type:"f32"},uCosA:{value:Math.cos(r),type:"f32"},uSinA:{value:Math.sin(r),type:"f32"}})}}),this._angle=r}get phase(){return this.resources.shimmerUniforms.uniforms.uPhase}set phase(t){this.resources.shimmerUniforms.uniforms.uPhase=t}get width(){return this.resources.shimmerUniforms.uniforms.uWidth}set width(t){this.resources.shimmerUniforms.uniforms.uWidth=t}get intensity(){return this.resources.shimmerUniforms.uniforms.uIntensity}set intensity(t){this.resources.shimmerUniforms.uniforms.uIntensity=t}get angle(){return this._angle}set angle(t){this._angle=t,this.resources.shimmerUniforms.uniforms.uCosA=Math.cos(t),this.resources.shimmerUniforms.uniforms.uSinA=Math.sin(t)}}const xt=new WeakMap;function Qa(e,t,n){const i=n?.frequency??.8,r=n?.width??.35,o=n?.intensity??.6,s=n?.angle??Math.PI/6;return{stateId:e,type:t,onEnter(a){const c=new ja({width:r,intensity:o,angle:s}),l=a.getGraphics();pt(a),l.filters=[...l.filters??[],c];const h=Math.abs(Math.cos(s))+Math.abs(Math.sin(s));xt.set(a,{elapsed:0,filter:c,maxProj:h})},onLeave(a){const c=xt.get(a);if(c){const l=a.getGraphics();l.filters=(l.filters??[]).filter(h=>h!==c.filter),gt(a),xt.delete(a)}},onUpdate(a,c){const l=xt.get(a);if(!l)return;l.elapsed+=c;const h=l.elapsed*i/1e3%1,u=r*.5,f=l.maxProj+r;l.filter.phase=h*f-u}}}const mn=new WeakMap;function ec(e,t,n){const i=n?.color??16711680;return{stateId:e,type:t,onEnter(r){const o=r.getGraphics();mn.set(r,o.tint),o.tint=i},onLeave(r){const o=mn.get(r);o!==void 0&&(r.getGraphics().tint=o,mn.delete(r))}}}class Qi extends w.EventEmitter{states=new Map;plugins=new Map;add(t){for(const n of Array.isArray(t)?t:[t]){const i=this.states.has(n.id);this.states.set(n.id,n),this.emit(i?"state:updated":"state:added",n)}return this}remove(t){return this.states.delete(t)?(this.plugins.delete(t),this.emit("state:removed",{id:t}),!0):!1}get(t){return this.states.get(t)}has(t){return this.states.has(t)}getAll(){return[...this.states.values()]}clear(){this.states.clear(),this.plugins.clear(),this.emit("states:cleared")}registerPlugin(t){const n=this.plugins.get(t.stateId)??[];return n.push(t),this.plugins.set(t.stateId,n),this}unregisterPlugin(t,n){const i=this.plugins.get(t);if(i){const r=i.filter(o=>o.type!==n);r.length?this.plugins.set(t,r):this.plugins.delete(t)}return this}getPlugins(t,n){return(this.plugins.get(t)??[]).filter(i=>i.type===n)}getWeight(t){return this.states.get(t)?.weight??0}sortByWeight(t){return[...t].sort((n,i)=>this.getWeight(n)-this.getWeight(i))}toJSON(){return this.getAll()}fromJSON(t){this.add(t)}toYAML(){return ae(this.toJSON())}fromYAML(t){this.fromJSON(ce(t))}destroy(){this.clear(),this.removeAllListeners()}}class yt extends w.EventEmitter{_app;icons=new ji;states=new Qi;scenes=new Map;activeSceneId=null;_isReady=!1;_isBatchLoading=!1;plugins=new Map;_cameraBoundScene=null;_onSceneCameraChange=t=>this.emit("camera:change",{...t,sceneId:this._cameraBoundScene.id});_onSceneCameraMove=t=>this.emit("camera:move",{...t,sceneId:this._cameraBoundScene.id});_onSceneCameraZoom=t=>this.emit("camera:zoom",{...t,sceneId:this._cameraBoundScene.id});bindCameraEvents(t){this._cameraBoundScene=t,t.on("camera:change",this._onSceneCameraChange),t.on("camera:move",this._onSceneCameraMove),t.on("camera:zoom",this._onSceneCameraZoom)}unbindCameraEvents(t){t.off("camera:change",this._onSceneCameraChange),t.off("camera:move",this._onSceneCameraMove),t.off("camera:zoom",this._onSceneCameraZoom),this._cameraBoundScene===t&&(this._cameraBoundScene=null)}get app(){return this._app}async init(t){if(this._isReady)return;const{container:n,width:i,height:r}=t;this._app=new w.Application,await this._app.init({resizeTo:!i&&!r?n:void 0,width:i??n.clientWidth,height:r??n.clientHeight,antialias:!0}),n.appendChild(this._app.canvas),this._app.stage.eventMode="static",this._app.stage.hitArea=this._app.screen,this._isReady=!0,this.use(new Zi),this.emit("ready")}static async create(t){const n=new yt;return await n.init(t),n}ensureReady(){if(!this._isReady)throw new Error("Topology not initialized. Call init() first.")}addScene(t,n){if(this.ensureReady(),this.scenes.has(t))throw new Error(`Scene "${t}" already exists`);const i=new he(t,this.app,this.icons,this.states);return this.scenes.set(t,i),n&&i.fromJSON(n),!this._isBatchLoading&&this.scenes.size===1?this.switchScene(t):i.setActive(!1),this.emit("scene:added",i),i}removeScene(t){this.ensureReady();const n=this.scenes.get(t);n&&(this.activeSceneId===t&&(this.unbindCameraEvents(n),n.setActive(!1),this.activeSceneId=null),this.emit("scene:removed",{id:t}),n.destroy(),this.scenes.delete(t))}switchScene(t){this.ensureReady();const n=this.scenes.get(t);if(!n)throw new Error(`Scene "${t}" not found`);const i=this.activeSceneId,r=i?this.scenes.get(i)??null:null;return i&&i!==t&&this.scenes.get(i)?.setActive(!1),r&&r!==n&&this.unbindCameraEvents(r),this.bindCameraEvents(n),n.setActive(!0),this.activeSceneId=t,this.emit("scene:switched",{from:r,to:n}),n}getScene(t){return this.scenes.get(t)}getSceneIds(){return[...this.scenes.keys()]}async fit(t,n){this.ensureReady();let i,r;Array.isArray(t)?r=t:(i=t,r=n??[0]);const o=r.length?r:[0],s=o[0]??0,a=o[1]??s,c=o[2]??s,l=o[3]??a,h=i?this.scenes.get(i):this.activeScene;if(!h)throw new Error(i?`Scene "${i}" not found`:"No active scene");const u=h.getContentBounds();if(!u)return;const f=this._app.screen.width,d=this._app.screen.height;if(f<=0||d<=0)return;const p=h.projectionContainer,m=[{x:u.x,y:u.y},{x:u.x+u.width,y:u.y},{x:u.x,y:u.y+u.height},{x:u.x+u.width,y:u.y+u.height}],y=p.skew.x,S=p.skew.y,x=Math.cos(S),I=Math.sin(S),A=Math.sin(y),O=Math.cos(y);let R=1/0,F=1/0,W=-1/0,j=-1/0;for(const{x:ve,y:xe}of m){const ye=x*ve+A*xe,_e=I*ve+O*xe;ye<R&&(R=ye),_e<F&&(F=_e),ye>W&&(W=ye),_e>j&&(j=_e)}const X=W-R,q=j-F,pe=(R+W)/2,ge=(F+j)/2,K=f-l-a,me=d-s-c;let $;if(X<=0&&q<=0)$=he.DEFAULT_ZOOM;else if(K<=0||me<=0)$=he.DEFAULT_ZOOM;else{const ve=X>0?K/X:1/0,xe=q>0?me/q:1/0;$=Math.min(ve,xe)}$=Math.max(.05,Math.min($,10));const P=l+(f-l-a)/2,Ln=s+(d-s-c)/2,T=P-$*pe,Q=Ln-$*ge;!Number.isFinite(T)||!Number.isFinite(Q)||!Number.isFinite($)||await h.setCamera({zoom:$,x:T,y:Q})}get activeScene(){return this.activeSceneId?this.scenes.get(this.activeSceneId):void 0}get isInitialized(){return this._isReady}get stage(){return this.app?.stage}toJSON(){const t={};for(const[n,i]of this.scenes)t[n]=i.toJSON();return{scenes:t,icons:this.icons.toJSON(),states:this.states.toJSON(),activeSceneId:this.activeSceneId??void 0}}fromJSON(t){for(const i of[...this.scenes.keys()])this.removeScene(i);t.icons&&this.icons.fromJSON(t.icons),t.states&&this.states.fromJSON(t.states),this._isBatchLoading=!0;for(const[i,r]of Object.entries(t.scenes))this.addScene(i,r);this._isBatchLoading=!1;const n=t.activeSceneId&&this.scenes.has(t.activeSceneId)?t.activeSceneId:this.getSceneIds()[0];n&&this.switchScene(n)}toYAML(){return ae(this.toJSON())}fromYAML(t){this.fromJSON(ce(t))}async exportPNG(t){this.ensureReady();const n=this.activeScene;if(!n)throw new Error("No active scene");return n.exportPNG(t)}async exportSVG(t){this.ensureReady();const n=this.activeScene;if(!n)throw new Error("No active scene");return n.exportSVG(t)}async downloadPNG(t,n){const i=await this.exportPNG(n);Ue(i,t??"topology.png")}async downloadSVG(t,n){const i=await this.exportSVG(n);Ue(i,t??"topology.svg")}use(t){if(this.plugins.has(t.name))throw new Error(`Plugin "${t.name}" is already installed`);return this.plugins.set(t.name,t),t.install(this),this.emit("plugin:installed",{name:t.name}),this}removePlugin(t){const n=typeof t=="string"?t:t.name,i=this.plugins.get(n);return i&&(i.uninstall(this),this.plugins.delete(n),this.emit("plugin:removed",{name:n})),this}hasPlugin(t){return this.plugins.has(t)}getPlugin(t){if(typeof t=="string")return this.plugins.get(t);for(const n of this.plugins.values())if(n instanceof t)return n}destroy(){for(const t of this.plugins.values())t.uninstall(this);this.plugins.clear();for(const t of[...this.scenes.keys()])this.removeScene(t);this.icons.clear(),this.states.clear(),wa(),this.emit("destroyed"),this.removeAllListeners(),this.app?.destroy(!0),this._isReady=!1}}class Ge extends Ce{activeItems=new Map;hookScene(t){const n=this.getCollection(t);for(const s of n.getAll())this.enableInteraction(s,t);const i=s=>this.enableInteraction(s,t),r=({id:s})=>this.disableInteraction(s),o=()=>{for(const[s,a]of this.activeItems)a.sceneId===t.id&&this.disableInteraction(s)};return n.on(`${this.targetType}:added`,i),n.on(`${this.targetType}:removed`,r),n.on(`${this.targetType}s:cleared`,o),()=>{n.off(`${this.targetType}:added`,i),n.off(`${this.targetType}:removed`,r),n.off(`${this.targetType}s:cleared`,o);for(const s of n.getAll())this.disableInteraction(this.getItemId(s))}}enableInteraction(t,n){const i=this.getItemId(t);if(this.activeItems.has(i))return;const r=t.getGraphics();r.eventMode="static",r.cursor="pointer",this.activeItems.set(i,{item:t,sceneId:n.id})}disableInteraction(t){const n=this.activeItems.get(t);if(!n)return;const i=n.item.getGraphics();i.eventMode="none",i.cursor="default",this.activeItems.delete(t)}}const tc={padding:6,radius:6,color:4886754,lineWidth:2,alpha:.8};class er{graphics;draw(t,n){this.destroy();const{padding:i,radius:r,color:o,lineWidth:s,alpha:a}={...tc,...n},c=t.getLocalBounds(),l=new w.Graphics;l.roundRect(c.x-i,c.y-i,c.width+i*2,c.height+i*2,r),l.stroke({color:o,width:s,alpha:a}),l.position.copyFrom(t.position),l.skew.copyFrom(t.skew),l.scale.copyFrom(t.scale),t.parent?.addChild(l),this.graphics=l}updatePosition(t){this.graphics&&this.graphics.position.copyFrom(t.position)}destroy(){this.graphics?.destroy(),this.graphics=void 0}get exists(){return this.graphics!==void 0}}class _t extends Ce{selected=null;highlight=new er;dragStates=new Map;snapDelta(t){return t}get highlightOptions(){return{}}hookScene(t){const n=this.getCollection(t),{projectionContainer:i}=t;for(const a of n.getAll())this.attachBehavior(a,i,t);const r=a=>this.attachBehavior(a,i,t),o=({id:a})=>this.detachBehavior(a),s=()=>{for(const[a,c]of this.dragStates)c.sceneId===t.id&&this.detachBehavior(a)};return n.on(`${this.targetType}:added`,r),n.on(`${this.targetType}:removed`,o),n.on(`${this.targetType}s:cleared`,s),()=>{n.off(`${this.targetType}:added`,r),n.off(`${this.targetType}:removed`,o),n.off(`${this.targetType}s:cleared`,s);for(const a of n.getAll())this.detachBehavior(this.getItemId(a))}}onItemPointerDown({itemType:t,itemId:n}){if(t!==this.targetType){t!==null?this.clearSelectionSilent():this.clearSelection();return}if(n){const i=this.dragStates.get(n);i&&this.selectItem(i.item)}}onSceneSwitched(){this.clearSelection()}attachBehavior(t,n,i){const r=this.getItemId(t);if(this.dragStates.has(r))return;const o=t.getGraphics();o.eventMode="static",o.cursor="pointer";const s={item:t,sceneId:i.id,isDragging:!1,startPointer:{x:0,y:0},startTile:{x:0,y:0},cleanup:()=>{}},a=h=>{s.isDragging=!0;const u=n.toLocal(h.global);s.startPointer={x:u.x,y:u.y},s.startTile={...this.getItemPosition(t)}},c=h=>{if(!s.isDragging)return;const u=n.toLocal(h.global),f=u.x-s.startPointer.x,d=u.y-s.startPointer.y,p=s.startTile.x+this.snapDelta(f),m=s.startTile.y+this.snapDelta(d);this.applyDrag(t,p,m,i),this.updateHighlight(t)},l=()=>{s.isDragging&&(s.isDragging=!1,this.onDragEnd(t,i))};o.on("pointerdown",a),o.on("globalpointermove",c),o.on("pointerup",l),o.on("pointerupoutside",l),s.cleanup=()=>{o.eventMode="none",o.cursor="default",o.off("pointerdown",a),o.off("globalpointermove",c),o.off("pointerup",l),o.off("pointerupoutside",l)},this.dragStates.set(r,s),s.extraCleanup=this.onAttachItem(t,i)??void 0}detachBehavior(t){const n=this.dragStates.get(t);n&&(this.selected&&this.getItemId(this.selected)===t&&this.clearSelection(),n.extraCleanup?.(),n.cleanup(),this.dragStates.delete(t))}onAttachItem(t,n){}onDragEnd(t,n){}selectItem(t){this.selected!==t&&(this.clearSelectionSilent(),this.selected=t,t.select(),this.highlight.draw(t.getGraphics(),this.highlightOptions),this.topology?.emit("selection:changed",{pluginName:this.name,itemType:this.targetType,itemId:this.getItemId(t)}))}clearSelection(){this.selected&&(this.clearSelectionSilent(),this.topology?.emit("selection:changed",{pluginName:this.name,itemType:this.targetType,itemId:null}))}clearSelectionSilent(){if(!this.selected)return;const t=this.selected;this.selected=null,this.highlight.destroy(),t.deselect()}getSelectedId(){return this.selected?this.getItemId(this.selected):null}getSelected(){return this.selected}updateHighlight(t){this.selected===t&&this.highlight.updatePosition(t.getGraphics())}}var vn="http://www.w3.org/1999/xhtml";const tr={svg:"http://www.w3.org/2000/svg",xhtml:vn,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function wt(e){var t=e+="",n=t.indexOf(":");return n>=0&&(t=e.slice(0,n))!=="xmlns"&&(e=e.slice(n+1)),tr.hasOwnProperty(t)?{space:tr[t],local:e}:e}function nc(e){return function(){var t=this.ownerDocument,n=this.namespaceURI;return n===vn&&t.documentElement.namespaceURI===vn?t.createElement(e):t.createElementNS(n,e)}}function ic(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function nr(e){var t=wt(e);return(t.local?ic:nc)(t)}function rc(){}function xn(e){return e==null?rc:function(){return this.querySelector(e)}}function oc(e){typeof e!="function"&&(e=xn(e));for(var t=this._groups,n=t.length,i=new Array(n),r=0;r<n;++r)for(var o=t[r],s=o.length,a=i[r]=new Array(s),c,l,h=0;h<s;++h)(c=o[h])&&(l=e.call(c,c.__data__,h,o))&&("__data__"in c&&(l.__data__=c.__data__),a[h]=l);return new D(i,this._parents)}function sc(e){return e==null?[]:Array.isArray(e)?e:Array.from(e)}function ac(){return[]}function ir(e){return e==null?ac:function(){return this.querySelectorAll(e)}}function cc(e){return function(){return sc(e.apply(this,arguments))}}function lc(e){typeof e=="function"?e=cc(e):e=ir(e);for(var t=this._groups,n=t.length,i=[],r=[],o=0;o<n;++o)for(var s=t[o],a=s.length,c,l=0;l<a;++l)(c=s[l])&&(i.push(e.call(c,c.__data__,l,s)),r.push(c));return new D(i,r)}function rr(e){return function(){return this.matches(e)}}function or(e){return function(t){return t.matches(e)}}var hc=Array.prototype.find;function uc(e){return function(){return hc.call(this.children,e)}}function fc(){return this.firstElementChild}function dc(e){return this.select(e==null?fc:uc(typeof e=="function"?e:or(e)))}var pc=Array.prototype.filter;function gc(){return Array.from(this.children)}function mc(e){return function(){return pc.call(this.children,e)}}function vc(e){return this.selectAll(e==null?gc:mc(typeof e=="function"?e:or(e)))}function xc(e){typeof e!="function"&&(e=rr(e));for(var t=this._groups,n=t.length,i=new Array(n),r=0;r<n;++r)for(var o=t[r],s=o.length,a=i[r]=[],c,l=0;l<s;++l)(c=o[l])&&e.call(c,c.__data__,l,o)&&a.push(c);return new D(i,this._parents)}function sr(e){return new Array(e.length)}function yc(){return new D(this._enter||this._groups.map(sr),this._parents)}function St(e,t){this.ownerDocument=e.ownerDocument,this.namespaceURI=e.namespaceURI,this._next=null,this._parent=e,this.__data__=t}St.prototype={constructor:St,appendChild:function(e){return this._parent.insertBefore(e,this._next)},insertBefore:function(e,t){return this._parent.insertBefore(e,t)},querySelector:function(e){return this._parent.querySelector(e)},querySelectorAll:function(e){return this._parent.querySelectorAll(e)}};function _c(e){return function(){return e}}function wc(e,t,n,i,r,o){for(var s=0,a,c=t.length,l=o.length;s<l;++s)(a=t[s])?(a.__data__=o[s],i[s]=a):n[s]=new St(e,o[s]);for(;s<c;++s)(a=t[s])&&(r[s]=a)}function Sc(e,t,n,i,r,o,s){var a,c,l=new Map,h=t.length,u=o.length,f=new Array(h),d;for(a=0;a<h;++a)(c=t[a])&&(f[a]=d=s.call(c,c.__data__,a,t)+"",l.has(d)?r[a]=c:l.set(d,c));for(a=0;a<u;++a)d=s.call(e,o[a],a,o)+"",(c=l.get(d))?(i[a]=c,c.__data__=o[a],l.delete(d)):n[a]=new St(e,o[a]);for(a=0;a<h;++a)(c=t[a])&&l.get(f[a])===c&&(r[a]=c)}function Ic(e){return e.__data__}function Ac(e,t){if(!arguments.length)return Array.from(this,Ic);var n=t?Sc:wc,i=this._parents,r=this._groups;typeof e!="function"&&(e=_c(e));for(var o=r.length,s=new Array(o),a=new Array(o),c=new Array(o),l=0;l<o;++l){var h=i[l],u=r[l],f=u.length,d=bc(e.call(h,h&&h.__data__,l,i)),p=d.length,m=a[l]=new Array(p),y=s[l]=new Array(p),S=c[l]=new Array(f);n(h,u,m,y,S,d,t);for(var x=0,I=0,A,O;x<p;++x)if(A=m[x]){for(x>=I&&(I=x+1);!(O=y[I])&&++I<p;);A._next=O||null}}return s=new D(s,i),s._enter=a,s._exit=c,s}function bc(e){return typeof e=="object"&&"length"in e?e:Array.from(e)}function Cc(){return new D(this._exit||this._groups.map(sr),this._parents)}function Tc(e,t,n){var i=this.enter(),r=this,o=this.exit();return typeof e=="function"?(i=e(i),i&&(i=i.selection())):i=i.append(e+""),t!=null&&(r=t(r),r&&(r=r.selection())),n==null?o.remove():n(o),i&&r?i.merge(r).order():r}function Ec(e){for(var t=e.selection?e.selection():e,n=this._groups,i=t._groups,r=n.length,o=i.length,s=Math.min(r,o),a=new Array(r),c=0;c<s;++c)for(var l=n[c],h=i[c],u=l.length,f=a[c]=new Array(u),d,p=0;p<u;++p)(d=l[p]||h[p])&&(f[p]=d);for(;c<r;++c)a[c]=n[c];return new D(a,this._parents)}function Mc(){for(var e=this._groups,t=-1,n=e.length;++t<n;)for(var i=e[t],r=i.length-1,o=i[r],s;--r>=0;)(s=i[r])&&(o&&s.compareDocumentPosition(o)^4&&o.parentNode.insertBefore(s,o),o=s);return this}function Oc(e){e||(e=Pc);function t(u,f){return u&&f?e(u.__data__,f.__data__):!u-!f}for(var n=this._groups,i=n.length,r=new Array(i),o=0;o<i;++o){for(var s=n[o],a=s.length,c=r[o]=new Array(a),l,h=0;h<a;++h)(l=s[h])&&(c[h]=l);c.sort(t)}return new D(r,this._parents).order()}function Pc(e,t){return e<t?-1:e>t?1:e>=t?0:NaN}function Lc(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function kc(){return Array.from(this)}function Nc(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var i=e[t],r=0,o=i.length;r<o;++r){var s=i[r];if(s)return s}return null}function Rc(){let e=0;for(const t of this)++e;return e}function Dc(){return!this.node()}function Fc(e){for(var t=this._groups,n=0,i=t.length;n<i;++n)for(var r=t[n],o=0,s=r.length,a;o<s;++o)(a=r[o])&&e.call(a,a.__data__,o,r);return this}function $c(e){return function(){this.removeAttribute(e)}}function zc(e){return function(){this.removeAttributeNS(e.space,e.local)}}function Bc(e,t){return function(){this.setAttribute(e,t)}}function Hc(e,t){return function(){this.setAttributeNS(e.space,e.local,t)}}function Uc(e,t){return function(){var n=t.apply(this,arguments);n==null?this.removeAttribute(e):this.setAttribute(e,n)}}function Yc(e,t){return function(){var n=t.apply(this,arguments);n==null?this.removeAttributeNS(e.space,e.local):this.setAttributeNS(e.space,e.local,n)}}function Gc(e,t){var n=wt(e);if(arguments.length<2){var i=this.node();return n.local?i.getAttributeNS(n.space,n.local):i.getAttribute(n)}return this.each((t==null?n.local?zc:$c:typeof t=="function"?n.local?Yc:Uc:n.local?Hc:Bc)(n,t))}function ar(e){return e.ownerDocument&&e.ownerDocument.defaultView||e.document&&e||e.defaultView}function Wc(e){return function(){this.style.removeProperty(e)}}function Xc(e,t,n){return function(){this.style.setProperty(e,t,n)}}function qc(e,t,n){return function(){var i=t.apply(this,arguments);i==null?this.style.removeProperty(e):this.style.setProperty(e,i,n)}}function Kc(e,t,n){return arguments.length>1?this.each((t==null?Wc:typeof t=="function"?qc:Xc)(e,t,n??"")):Te(this.node(),e)}function Te(e,t){return e.style.getPropertyValue(t)||ar(e).getComputedStyle(e,null).getPropertyValue(t)}function Vc(e){return function(){delete this[e]}}function Jc(e,t){return function(){this[e]=t}}function Zc(e,t){return function(){var n=t.apply(this,arguments);n==null?delete this[e]:this[e]=n}}function jc(e,t){return arguments.length>1?this.each((t==null?Vc:typeof t=="function"?Zc:Jc)(e,t)):this.node()[e]}function cr(e){return e.trim().split(/^|\s+/)}function yn(e){return e.classList||new lr(e)}function lr(e){this._node=e,this._names=cr(e.getAttribute("class")||"")}lr.prototype={add:function(e){var t=this._names.indexOf(e);t<0&&(this._names.push(e),this._node.setAttribute("class",this._names.join(" ")))},remove:function(e){var t=this._names.indexOf(e);t>=0&&(this._names.splice(t,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(e){return this._names.indexOf(e)>=0}};function hr(e,t){for(var n=yn(e),i=-1,r=t.length;++i<r;)n.add(t[i])}function ur(e,t){for(var n=yn(e),i=-1,r=t.length;++i<r;)n.remove(t[i])}function Qc(e){return function(){hr(this,e)}}function el(e){return function(){ur(this,e)}}function tl(e,t){return function(){(t.apply(this,arguments)?hr:ur)(this,e)}}function nl(e,t){var n=cr(e+"");if(arguments.length<2){for(var i=yn(this.node()),r=-1,o=n.length;++r<o;)if(!i.contains(n[r]))return!1;return!0}return this.each((typeof t=="function"?tl:t?Qc:el)(n,t))}function il(){this.textContent=""}function rl(e){return function(){this.textContent=e}}function ol(e){return function(){var t=e.apply(this,arguments);this.textContent=t??""}}function sl(e){return arguments.length?this.each(e==null?il:(typeof e=="function"?ol:rl)(e)):this.node().textContent}function al(){this.innerHTML=""}function cl(e){return function(){this.innerHTML=e}}function ll(e){return function(){var t=e.apply(this,arguments);this.innerHTML=t??""}}function hl(e){return arguments.length?this.each(e==null?al:(typeof e=="function"?ll:cl)(e)):this.node().innerHTML}function ul(){this.nextSibling&&this.parentNode.appendChild(this)}function fl(){return this.each(ul)}function dl(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function pl(){return this.each(dl)}function gl(e){var t=typeof e=="function"?e:nr(e);return this.select(function(){return this.appendChild(t.apply(this,arguments))})}function ml(){return null}function vl(e,t){var n=typeof e=="function"?e:nr(e),i=t==null?ml:typeof t=="function"?t:xn(t);return this.select(function(){return this.insertBefore(n.apply(this,arguments),i.apply(this,arguments)||null)})}function xl(){var e=this.parentNode;e&&e.removeChild(this)}function yl(){return this.each(xl)}function _l(){var e=this.cloneNode(!1),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function wl(){var e=this.cloneNode(!0),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function Sl(e){return this.select(e?wl:_l)}function Il(e){return arguments.length?this.property("__data__",e):this.node().__data__}function Al(e){return function(t){e.call(this,t,this.__data__)}}function bl(e){return e.trim().split(/^|\s+/).map(function(t){var n="",i=t.indexOf(".");return i>=0&&(n=t.slice(i+1),t=t.slice(0,i)),{type:t,name:n}})}function Cl(e){return function(){var t=this.__on;if(t){for(var n=0,i=-1,r=t.length,o;n<r;++n)o=t[n],(!e.type||o.type===e.type)&&o.name===e.name?this.removeEventListener(o.type,o.listener,o.options):t[++i]=o;++i?t.length=i:delete this.__on}}}function Tl(e,t,n){return function(){var i=this.__on,r,o=Al(t);if(i){for(var s=0,a=i.length;s<a;++s)if((r=i[s]).type===e.type&&r.name===e.name){this.removeEventListener(r.type,r.listener,r.options),this.addEventListener(r.type,r.listener=o,r.options=n),r.value=t;return}}this.addEventListener(e.type,o,n),r={type:e.type,name:e.name,value:t,listener:o,options:n},i?i.push(r):this.__on=[r]}}function El(e,t,n){var i=bl(e+""),r,o=i.length,s;if(arguments.length<2){var a=this.node().__on;if(a){for(var c=0,l=a.length,h;c<l;++c)for(r=0,h=a[c];r<o;++r)if((s=i[r]).type===h.type&&s.name===h.name)return h.value}return}for(a=t?Tl:Cl,r=0;r<o;++r)this.each(a(i[r],t,n));return this}function fr(e,t,n){var i=ar(e),r=i.CustomEvent;typeof r=="function"?r=new r(t,n):(r=i.document.createEvent("Event"),n?(r.initEvent(t,n.bubbles,n.cancelable),r.detail=n.detail):r.initEvent(t,!1,!1)),e.dispatchEvent(r)}function Ml(e,t){return function(){return fr(this,e,t)}}function Ol(e,t){return function(){return fr(this,e,t.apply(this,arguments))}}function Pl(e,t){return this.each((typeof t=="function"?Ol:Ml)(e,t))}function*Ll(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var i=e[t],r=0,o=i.length,s;r<o;++r)(s=i[r])&&(yield s)}var dr=[null];function D(e,t){this._groups=e,this._parents=t}function We(){return new D([[document.documentElement]],dr)}function kl(){return this}D.prototype=We.prototype={constructor:D,select:oc,selectAll:lc,selectChild:dc,selectChildren:vc,filter:xc,data:Ac,enter:yc,exit:Cc,join:Tc,merge:Ec,selection:kl,order:Mc,sort:Oc,call:Lc,nodes:kc,node:Nc,size:Rc,empty:Dc,each:Fc,attr:Gc,style:Kc,property:jc,classed:nl,text:sl,html:hl,raise:fl,lower:pl,append:gl,insert:vl,remove:yl,clone:Sl,datum:Il,on:El,dispatch:Pl,[Symbol.iterator]:Ll};function Nl(e){return typeof e=="string"?new D([[document.querySelector(e)]],[document.documentElement]):new D([[e]],dr)}var Rl={value:()=>{}};function pr(){for(var e=0,t=arguments.length,n={},i;e<t;++e){if(!(i=arguments[e]+"")||i in n||/[\s.]/.test(i))throw new Error("illegal type: "+i);n[i]=[]}return new It(n)}function It(e){this._=e}function Dl(e,t){return e.trim().split(/^|\s+/).map(function(n){var i="",r=n.indexOf(".");if(r>=0&&(i=n.slice(r+1),n=n.slice(0,r)),n&&!t.hasOwnProperty(n))throw new Error("unknown type: "+n);return{type:n,name:i}})}It.prototype=pr.prototype={constructor:It,on:function(e,t){var n=this._,i=Dl(e+"",n),r,o=-1,s=i.length;if(arguments.length<2){for(;++o<s;)if((r=(e=i[o]).type)&&(r=Fl(n[r],e.name)))return r;return}if(t!=null&&typeof t!="function")throw new Error("invalid callback: "+t);for(;++o<s;)if(r=(e=i[o]).type)n[r]=gr(n[r],e.name,t);else if(t==null)for(r in n)n[r]=gr(n[r],e.name,null);return this},copy:function(){var e={},t=this._;for(var n in t)e[n]=t[n].slice();return new It(e)},call:function(e,t){if((r=arguments.length-2)>0)for(var n=new Array(r),i=0,r,o;i<r;++i)n[i]=arguments[i+2];if(!this._.hasOwnProperty(e))throw new Error("unknown type: "+e);for(o=this._[e],i=0,r=o.length;i<r;++i)o[i].value.apply(t,n)},apply:function(e,t,n){if(!this._.hasOwnProperty(e))throw new Error("unknown type: "+e);for(var i=this._[e],r=0,o=i.length;r<o;++r)i[r].value.apply(t,n)}};function Fl(e,t){for(var n=0,i=e.length,r;n<i;++n)if((r=e[n]).name===t)return r.value}function gr(e,t,n){for(var i=0,r=e.length;i<r;++i)if(e[i].name===t){e[i]=Rl,e=e.slice(0,i).concat(e.slice(i+1));break}return n!=null&&e.push({name:t,value:n}),e}var Ee=0,Xe=0,qe=0,mr=1e3,At,Ke,bt=0,ue=0,Ct=0,Ve=typeof performance=="object"&&performance.now?performance:Date,vr=typeof window=="object"&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(e){setTimeout(e,17)};function _n(){return ue||(vr($l),ue=Ve.now()+Ct)}function $l(){ue=0}function Tt(){this._call=this._time=this._next=null}Tt.prototype=xr.prototype={constructor:Tt,restart:function(e,t,n){if(typeof e!="function")throw new TypeError("callback is not a function");n=(n==null?_n():+n)+(t==null?0:+t),!this._next&&Ke!==this&&(Ke?Ke._next=this:At=this,Ke=this),this._call=e,this._time=n,wn()},stop:function(){this._call&&(this._call=null,this._time=1/0,wn())}};function xr(e,t,n){var i=new Tt;return i.restart(e,t,n),i}function zl(){_n(),++Ee;for(var e=At,t;e;)(t=ue-e._time)>=0&&e._call.call(void 0,t),e=e._next;--Ee}function yr(){ue=(bt=Ve.now())+Ct,Ee=Xe=0;try{zl()}finally{Ee=0,Hl(),ue=0}}function Bl(){var e=Ve.now(),t=e-bt;t>mr&&(Ct-=t,bt=e)}function Hl(){for(var e,t=At,n,i=1/0;t;)t._call?(i>t._time&&(i=t._time),e=t,t=t._next):(n=t._next,t._next=null,t=e?e._next=n:At=n);Ke=e,wn(i)}function wn(e){if(!Ee){Xe&&(Xe=clearTimeout(Xe));var t=e-ue;t>24?(e<1/0&&(Xe=setTimeout(yr,e-Ve.now()-Ct)),qe&&(qe=clearInterval(qe))):(qe||(bt=Ve.now(),qe=setInterval(Bl,mr)),Ee=1,vr(yr))}}function _r(e,t,n){var i=new Tt;return t=t==null?0:+t,i.restart(r=>{i.stop(),e(r+t)},t,n),i}var Ul=pr("start","end","cancel","interrupt"),Yl=[],wr=0,Sr=1,Sn=2,Et=3,Ir=4,In=5,Mt=6;function Ot(e,t,n,i,r,o){var s=e.__transition;if(!s)e.__transition={};else if(n in s)return;Gl(e,n,{name:t,index:i,group:r,on:Ul,tween:Yl,time:o.time,delay:o.delay,duration:o.duration,ease:o.ease,timer:null,state:wr})}function An(e,t){var n=B(e,t);if(n.state>wr)throw new Error("too late; already scheduled");return n}function Y(e,t){var n=B(e,t);if(n.state>Et)throw new Error("too late; already running");return n}function B(e,t){var n=e.__transition;if(!n||!(n=n[t]))throw new Error("transition not found");return n}function Gl(e,t,n){var i=e.__transition,r;i[t]=n,n.timer=xr(o,0,n.time);function o(l){n.state=Sr,n.timer.restart(s,n.delay,n.time),n.delay<=l&&s(l-n.delay)}function s(l){var h,u,f,d;if(n.state!==Sr)return c();for(h in i)if(d=i[h],d.name===n.name){if(d.state===Et)return _r(s);d.state===Ir?(d.state=Mt,d.timer.stop(),d.on.call("interrupt",e,e.__data__,d.index,d.group),delete i[h]):+h<t&&(d.state=Mt,d.timer.stop(),d.on.call("cancel",e,e.__data__,d.index,d.group),delete i[h])}if(_r(function(){n.state===Et&&(n.state=Ir,n.timer.restart(a,n.delay,n.time),a(l))}),n.state=Sn,n.on.call("start",e,e.__data__,n.index,n.group),n.state===Sn){for(n.state=Et,r=new Array(f=n.tween.length),h=0,u=-1;h<f;++h)(d=n.tween[h].value.call(e,e.__data__,n.index,n.group))&&(r[++u]=d);r.length=u+1}}function a(l){for(var h=l<n.duration?n.ease.call(null,l/n.duration):(n.timer.restart(c),n.state=In,1),u=-1,f=r.length;++u<f;)r[u].call(e,h);n.state===In&&(n.on.call("end",e,e.__data__,n.index,n.group),c())}function c(){n.state=Mt,n.timer.stop(),delete i[t];for(var l in i)return;delete e.__transition}}function Wl(e,t){var n=e.__transition,i,r,o=!0,s;if(n){t=t==null?null:t+"";for(s in n){if((i=n[s]).name!==t){o=!1;continue}r=i.state>Sn&&i.state<In,i.state=Mt,i.timer.stop(),i.on.call(r?"interrupt":"cancel",e,e.__data__,i.index,i.group),delete n[s]}o&&delete e.__transition}}function Xl(e){return this.each(function(){Wl(this,e)})}function bn(e,t,n){e.prototype=t.prototype=n,n.constructor=e}function Ar(e,t){var n=Object.create(e.prototype);for(var i in t)n[i]=t[i];return n}function Je(){}var Ze=.7,Pt=1/Ze,Me="\\s*([+-]?\\d+)\\s*",je="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",G="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",ql=/^#([0-9a-f]{3,8})$/,Kl=new RegExp(`^rgb\\(${Me},${Me},${Me}\\)$`),Vl=new RegExp(`^rgb\\(${G},${G},${G}\\)$`),Jl=new RegExp(`^rgba\\(${Me},${Me},${Me},${je}\\)$`),Zl=new RegExp(`^rgba\\(${G},${G},${G},${je}\\)$`),jl=new RegExp(`^hsl\\(${je},${G},${G}\\)$`),Ql=new RegExp(`^hsla\\(${je},${G},${G},${je}\\)$`),br={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074};bn(Je,Qe,{copy(e){return Object.assign(new this.constructor,this,e)},displayable(){return this.rgb().displayable()},hex:Cr,formatHex:Cr,formatHex8:eh,formatHsl:th,formatRgb:Tr,toString:Tr});function Cr(){return this.rgb().formatHex()}function eh(){return this.rgb().formatHex8()}function th(){return Lr(this).formatHsl()}function Tr(){return this.rgb().formatRgb()}function Qe(e){var t,n;return e=(e+"").trim().toLowerCase(),(t=ql.exec(e))?(n=t[1].length,t=parseInt(t[1],16),n===6?Er(t):n===3?new N(t>>8&15|t>>4&240,t>>4&15|t&240,(t&15)<<4|t&15,1):n===8?Lt(t>>24&255,t>>16&255,t>>8&255,(t&255)/255):n===4?Lt(t>>12&15|t>>8&240,t>>8&15|t>>4&240,t>>4&15|t&240,((t&15)<<4|t&15)/255):null):(t=Kl.exec(e))?new N(t[1],t[2],t[3],1):(t=Vl.exec(e))?new N(t[1]*255/100,t[2]*255/100,t[3]*255/100,1):(t=Jl.exec(e))?Lt(t[1],t[2],t[3],t[4]):(t=Zl.exec(e))?Lt(t[1]*255/100,t[2]*255/100,t[3]*255/100,t[4]):(t=jl.exec(e))?Pr(t[1],t[2]/100,t[3]/100,1):(t=Ql.exec(e))?Pr(t[1],t[2]/100,t[3]/100,t[4]):br.hasOwnProperty(e)?Er(br[e]):e==="transparent"?new N(NaN,NaN,NaN,0):null}function Er(e){return new N(e>>16&255,e>>8&255,e&255,1)}function Lt(e,t,n,i){return i<=0&&(e=t=n=NaN),new N(e,t,n,i)}function nh(e){return e instanceof Je||(e=Qe(e)),e?(e=e.rgb(),new N(e.r,e.g,e.b,e.opacity)):new N}function Cn(e,t,n,i){return arguments.length===1?nh(e):new N(e,t,n,i??1)}function N(e,t,n,i){this.r=+e,this.g=+t,this.b=+n,this.opacity=+i}bn(N,Cn,Ar(Je,{brighter(e){return e=e==null?Pt:Math.pow(Pt,e),new N(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?Ze:Math.pow(Ze,e),new N(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new N(fe(this.r),fe(this.g),fe(this.b),kt(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:Mr,formatHex:Mr,formatHex8:ih,formatRgb:Or,toString:Or}));function Mr(){return`#${de(this.r)}${de(this.g)}${de(this.b)}`}function ih(){return`#${de(this.r)}${de(this.g)}${de(this.b)}${de((isNaN(this.opacity)?1:this.opacity)*255)}`}function Or(){const e=kt(this.opacity);return`${e===1?"rgb(":"rgba("}${fe(this.r)}, ${fe(this.g)}, ${fe(this.b)}${e===1?")":`, ${e})`}`}function kt(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function fe(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function de(e){return e=fe(e),(e<16?"0":"")+e.toString(16)}function Pr(e,t,n,i){return i<=0?e=t=n=NaN:n<=0||n>=1?e=t=NaN:t<=0&&(e=NaN),new H(e,t,n,i)}function Lr(e){if(e instanceof H)return new H(e.h,e.s,e.l,e.opacity);if(e instanceof Je||(e=Qe(e)),!e)return new H;if(e instanceof H)return e;e=e.rgb();var t=e.r/255,n=e.g/255,i=e.b/255,r=Math.min(t,n,i),o=Math.max(t,n,i),s=NaN,a=o-r,c=(o+r)/2;return a?(t===o?s=(n-i)/a+(n<i)*6:n===o?s=(i-t)/a+2:s=(t-n)/a+4,a/=c<.5?o+r:2-o-r,s*=60):a=c>0&&c<1?0:s,new H(s,a,c,e.opacity)}function rh(e,t,n,i){return arguments.length===1?Lr(e):new H(e,t,n,i??1)}function H(e,t,n,i){this.h=+e,this.s=+t,this.l=+n,this.opacity=+i}bn(H,rh,Ar(Je,{brighter(e){return e=e==null?Pt:Math.pow(Pt,e),new H(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?Ze:Math.pow(Ze,e),new H(this.h,this.s,this.l*e,this.opacity)},rgb(){var e=this.h%360+(this.h<0)*360,t=isNaN(e)||isNaN(this.s)?0:this.s,n=this.l,i=n+(n<.5?n:1-n)*t,r=2*n-i;return new N(Tn(e>=240?e-240:e+120,r,i),Tn(e,r,i),Tn(e<120?e+240:e-120,r,i),this.opacity)},clamp(){return new H(kr(this.h),Nt(this.s),Nt(this.l),kt(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 e=kt(this.opacity);return`${e===1?"hsl(":"hsla("}${kr(this.h)}, ${Nt(this.s)*100}%, ${Nt(this.l)*100}%${e===1?")":`, ${e})`}`}}));function kr(e){return e=(e||0)%360,e<0?e+360:e}function Nt(e){return Math.max(0,Math.min(1,e||0))}function Tn(e,t,n){return(e<60?t+(n-t)*e/60:e<180?n:e<240?t+(n-t)*(240-e)/60:t)*255}const Nr=e=>()=>e;function oh(e,t){return function(n){return e+n*t}}function sh(e,t,n){return e=Math.pow(e,n),t=Math.pow(t,n)-e,n=1/n,function(i){return Math.pow(e+i*t,n)}}function ah(e){return(e=+e)==1?Rr:function(t,n){return n-t?sh(t,n,e):Nr(isNaN(t)?n:t)}}function Rr(e,t){var n=t-e;return n?oh(e,n):Nr(isNaN(e)?t:e)}const Dr=(function e(t){var n=ah(t);function i(r,o){var s=n((r=Cn(r)).r,(o=Cn(o)).r),a=n(r.g,o.g),c=n(r.b,o.b),l=Rr(r.opacity,o.opacity);return function(h){return r.r=s(h),r.g=a(h),r.b=c(h),r.opacity=l(h),r+""}}return i.gamma=e,i})(1);function re(e,t){return e=+e,t=+t,function(n){return e*(1-n)+t*n}}var En=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,Mn=new RegExp(En.source,"g");function ch(e){return function(){return e}}function lh(e){return function(t){return e(t)+""}}function hh(e,t){var n=En.lastIndex=Mn.lastIndex=0,i,r,o,s=-1,a=[],c=[];for(e=e+"",t=t+"";(i=En.exec(e))&&(r=Mn.exec(t));)(o=r.index)>n&&(o=t.slice(n,o),a[s]?a[s]+=o:a[++s]=o),(i=i[0])===(r=r[0])?a[s]?a[s]+=r:a[++s]=r:(a[++s]=null,c.push({i:s,x:re(i,r)})),n=Mn.lastIndex;return n<t.length&&(o=t.slice(n),a[s]?a[s]+=o:a[++s]=o),a.length<2?c[0]?lh(c[0].x):ch(t):(t=c.length,function(l){for(var h=0,u;h<t;++h)a[(u=c[h]).i]=u.x(l);return a.join("")})}var Fr=180/Math.PI,On={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function $r(e,t,n,i,r,o){var s,a,c;return(s=Math.sqrt(e*e+t*t))&&(e/=s,t/=s),(c=e*n+t*i)&&(n-=e*c,i-=t*c),(a=Math.sqrt(n*n+i*i))&&(n/=a,i/=a,c/=a),e*i<t*n&&(e=-e,t=-t,c=-c,s=-s),{translateX:r,translateY:o,rotate:Math.atan2(t,e)*Fr,skewX:Math.atan(c)*Fr,scaleX:s,scaleY:a}}var Rt;function uh(e){const t=new(typeof DOMMatrix=="function"?DOMMatrix:WebKitCSSMatrix)(e+"");return t.isIdentity?On:$r(t.a,t.b,t.c,t.d,t.e,t.f)}function fh(e){return e==null||(Rt||(Rt=document.createElementNS("http://www.w3.org/2000/svg","g")),Rt.setAttribute("transform",e),!(e=Rt.transform.baseVal.consolidate()))?On:(e=e.matrix,$r(e.a,e.b,e.c,e.d,e.e,e.f))}function zr(e,t,n,i){function r(l){return l.length?l.pop()+" ":""}function o(l,h,u,f,d,p){if(l!==u||h!==f){var m=d.push("translate(",null,t,null,n);p.push({i:m-4,x:re(l,u)},{i:m-2,x:re(h,f)})}else(u||f)&&d.push("translate("+u+t+f+n)}function s(l,h,u,f){l!==h?(l-h>180?h+=360:h-l>180&&(l+=360),f.push({i:u.push(r(u)+"rotate(",null,i)-2,x:re(l,h)})):h&&u.push(r(u)+"rotate("+h+i)}function a(l,h,u,f){l!==h?f.push({i:u.push(r(u)+"skewX(",null,i)-2,x:re(l,h)}):h&&u.push(r(u)+"skewX("+h+i)}function c(l,h,u,f,d,p){if(l!==u||h!==f){var m=d.push(r(d)+"scale(",null,",",null,")");p.push({i:m-4,x:re(l,u)},{i:m-2,x:re(h,f)})}else(u!==1||f!==1)&&d.push(r(d)+"scale("+u+","+f+")")}return function(l,h){var u=[],f=[];return l=e(l),h=e(h),o(l.translateX,l.translateY,h.translateX,h.translateY,u,f),s(l.rotate,h.rotate,u,f),a(l.skewX,h.skewX,u,f),c(l.scaleX,l.scaleY,h.scaleX,h.scaleY,u,f),l=h=null,function(d){for(var p=-1,m=f.length,y;++p<m;)u[(y=f[p]).i]=y.x(d);return u.join("")}}}var dh=zr(uh,"px, ","px)","deg)"),ph=zr(fh,", ",")",")");function gh(e,t){var n,i;return function(){var r=Y(this,e),o=r.tween;if(o!==n){i=n=o;for(var s=0,a=i.length;s<a;++s)if(i[s].name===t){i=i.slice(),i.splice(s,1);break}}r.tween=i}}function mh(e,t,n){var i,r;if(typeof n!="function")throw new Error;return function(){var o=Y(this,e),s=o.tween;if(s!==i){r=(i=s).slice();for(var a={name:t,value:n},c=0,l=r.length;c<l;++c)if(r[c].name===t){r[c]=a;break}c===l&&r.push(a)}o.tween=r}}function vh(e,t){var n=this._id;if(e+="",arguments.length<2){for(var i=B(this.node(),n).tween,r=0,o=i.length,s;r<o;++r)if((s=i[r]).name===e)return s.value;return null}return this.each((t==null?gh:mh)(n,e,t))}function Pn(e,t,n){var i=e._id;return e.each(function(){var r=Y(this,i);(r.value||(r.value={}))[t]=n.apply(this,arguments)}),function(r){return B(r,i).value[t]}}function Br(e,t){var n;return(typeof t=="number"?re:t instanceof Qe?Dr:(n=Qe(t))?(t=n,Dr):hh)(e,t)}function xh(e){return function(){this.removeAttribute(e)}}function yh(e){return function(){this.removeAttributeNS(e.space,e.local)}}function _h(e,t,n){var i,r=n+"",o;return function(){var s=this.getAttribute(e);return s===r?null:s===i?o:o=t(i=s,n)}}function wh(e,t,n){var i,r=n+"",o;return function(){var s=this.getAttributeNS(e.space,e.local);return s===r?null:s===i?o:o=t(i=s,n)}}function Sh(e,t,n){var i,r,o;return function(){var s,a=n(this),c;return a==null?void this.removeAttribute(e):(s=this.getAttribute(e),c=a+"",s===c?null:s===i&&c===r?o:(r=c,o=t(i=s,a)))}}function Ih(e,t,n){var i,r,o;return function(){var s,a=n(this),c;return a==null?void this.removeAttributeNS(e.space,e.local):(s=this.getAttributeNS(e.space,e.local),c=a+"",s===c?null:s===i&&c===r?o:(r=c,o=t(i=s,a)))}}function Ah(e,t){var n=wt(e),i=n==="transform"?ph:Br;return this.attrTween(e,typeof t=="function"?(n.local?Ih:Sh)(n,i,Pn(this,"attr."+e,t)):t==null?(n.local?yh:xh)(n):(n.local?wh:_h)(n,i,t))}function bh(e,t){return function(n){this.setAttribute(e,t.call(this,n))}}function Ch(e,t){return function(n){this.setAttributeNS(e.space,e.local,t.call(this,n))}}function Th(e,t){var n,i;function r(){var o=t.apply(this,arguments);return o!==i&&(n=(i=o)&&Ch(e,o)),n}return r._value=t,r}function Eh(e,t){var n,i;function r(){var o=t.apply(this,arguments);return o!==i&&(n=(i=o)&&bh(e,o)),n}return r._value=t,r}function Mh(e,t){var n="attr."+e;if(arguments.length<2)return(n=this.tween(n))&&n._value;if(t==null)return this.tween(n,null);if(typeof t!="function")throw new Error;var i=wt(e);return this.tween(n,(i.local?Th:Eh)(i,t))}function Oh(e,t){return function(){An(this,e).delay=+t.apply(this,arguments)}}function Ph(e,t){return t=+t,function(){An(this,e).delay=t}}function Lh(e){var t=this._id;return arguments.length?this.each((typeof e=="function"?Oh:Ph)(t,e)):B(this.node(),t).delay}function kh(e,t){return function(){Y(this,e).duration=+t.apply(this,arguments)}}function Nh(e,t){return t=+t,function(){Y(this,e).duration=t}}function Rh(e){var t=this._id;return arguments.length?this.each((typeof e=="function"?kh:Nh)(t,e)):B(this.node(),t).duration}function Dh(e,t){if(typeof t!="function")throw new Error;return function(){Y(this,e).ease=t}}function Fh(e){var t=this._id;return arguments.length?this.each(Dh(t,e)):B(this.node(),t).ease}function $h(e,t){return function(){var n=t.apply(this,arguments);if(typeof n!="function")throw new Error;Y(this,e).ease=n}}function zh(e){if(typeof e!="function")throw new Error;return this.each($h(this._id,e))}function Bh(e){typeof e!="function"&&(e=rr(e));for(var t=this._groups,n=t.length,i=new Array(n),r=0;r<n;++r)for(var o=t[r],s=o.length,a=i[r]=[],c,l=0;l<s;++l)(c=o[l])&&e.call(c,c.__data__,l,o)&&a.push(c);return new J(i,this._parents,this._name,this._id)}function Hh(e){if(e._id!==this._id)throw new Error;for(var t=this._groups,n=e._groups,i=t.length,r=n.length,o=Math.min(i,r),s=new Array(i),a=0;a<o;++a)for(var c=t[a],l=n[a],h=c.length,u=s[a]=new Array(h),f,d=0;d<h;++d)(f=c[d]||l[d])&&(u[d]=f);for(;a<i;++a)s[a]=t[a];return new J(s,this._parents,this._name,this._id)}function Uh(e){return(e+"").trim().split(/^|\s+/).every(function(t){var n=t.indexOf(".");return n>=0&&(t=t.slice(0,n)),!t||t==="start"})}function Yh(e,t,n){var i,r,o=Uh(t)?An:Y;return function(){var s=o(this,e),a=s.on;a!==i&&(r=(i=a).copy()).on(t,n),s.on=r}}function Gh(e,t){var n=this._id;return arguments.length<2?B(this.node(),n).on.on(e):this.each(Yh(n,e,t))}function Wh(e){return function(){var t=this.parentNode;for(var n in this.__transition)if(+n!==e)return;t&&t.removeChild(this)}}function Xh(){return this.on("end.remove",Wh(this._id))}function qh(e){var t=this._name,n=this._id;typeof e!="function"&&(e=xn(e));for(var i=this._groups,r=i.length,o=new Array(r),s=0;s<r;++s)for(var a=i[s],c=a.length,l=o[s]=new Array(c),h,u,f=0;f<c;++f)(h=a[f])&&(u=e.call(h,h.__data__,f,a))&&("__data__"in h&&(u.__data__=h.__data__),l[f]=u,Ot(l[f],t,n,f,l,B(h,n)));return new J(o,this._parents,t,n)}function Kh(e){var t=this._name,n=this._id;typeof e!="function"&&(e=ir(e));for(var i=this._groups,r=i.length,o=[],s=[],a=0;a<r;++a)for(var c=i[a],l=c.length,h,u=0;u<l;++u)if(h=c[u]){for(var f=e.call(h,h.__data__,u,c),d,p=B(h,n),m=0,y=f.length;m<y;++m)(d=f[m])&&Ot(d,t,n,m,f,p);o.push(f),s.push(h)}return new J(o,s,t,n)}var Vh=We.prototype.constructor;function Jh(){return new Vh(this._groups,this._parents)}function Zh(e,t){var n,i,r;return function(){var o=Te(this,e),s=(this.style.removeProperty(e),Te(this,e));return o===s?null:o===n&&s===i?r:r=t(n=o,i=s)}}function Hr(e){return function(){this.style.removeProperty(e)}}function jh(e,t,n){var i,r=n+"",o;return function(){var s=Te(this,e);return s===r?null:s===i?o:o=t(i=s,n)}}function Qh(e,t,n){var i,r,o;return function(){var s=Te(this,e),a=n(this),c=a+"";return a==null&&(c=a=(this.style.removeProperty(e),Te(this,e))),s===c?null:s===i&&c===r?o:(r=c,o=t(i=s,a))}}function eu(e,t){var n,i,r,o="style."+t,s="end."+o,a;return function(){var c=Y(this,e),l=c.on,h=c.value[o]==null?a||(a=Hr(t)):void 0;(l!==n||r!==h)&&(i=(n=l).copy()).on(s,r=h),c.on=i}}function tu(e,t,n){var i=(e+="")=="transform"?dh:Br;return t==null?this.styleTween(e,Zh(e,i)).on("end.style."+e,Hr(e)):typeof t=="function"?this.styleTween(e,Qh(e,i,Pn(this,"style."+e,t))).each(eu(this._id,e)):this.styleTween(e,jh(e,i,t),n).on("end.style."+e,null)}function nu(e,t,n){return function(i){this.style.setProperty(e,t.call(this,i),n)}}function iu(e,t,n){var i,r;function o(){var s=t.apply(this,arguments);return s!==r&&(i=(r=s)&&nu(e,s,n)),i}return o._value=t,o}function ru(e,t,n){var i="style."+(e+="");if(arguments.length<2)return(i=this.tween(i))&&i._value;if(t==null)return this.tween(i,null);if(typeof t!="function")throw new Error;return this.tween(i,iu(e,t,n??""))}function ou(e){return function(){this.textContent=e}}function su(e){return function(){var t=e(this);this.textContent=t??""}}function au(e){return this.tween("text",typeof e=="function"?su(Pn(this,"text",e)):ou(e==null?"":e+""))}function cu(e){return function(t){this.textContent=e.call(this,t)}}function lu(e){var t,n;function i(){var r=e.apply(this,arguments);return r!==n&&(t=(n=r)&&cu(r)),t}return i._value=e,i}function hu(e){var t="text";if(arguments.length<1)return(t=this.tween(t))&&t._value;if(e==null)return this.tween(t,null);if(typeof e!="function")throw new Error;return this.tween(t,lu(e))}function uu(){for(var e=this._name,t=this._id,n=Ur(),i=this._groups,r=i.length,o=0;o<r;++o)for(var s=i[o],a=s.length,c,l=0;l<a;++l)if(c=s[l]){var h=B(c,t);Ot(c,e,n,l,s,{time:h.time+h.delay+h.duration,delay:0,duration:h.duration,ease:h.ease})}return new J(i,this._parents,e,n)}function fu(){var e,t,n=this,i=n._id,r=n.size();return new Promise(function(o,s){var a={value:s},c={value:function(){--r===0&&o()}};n.each(function(){var l=Y(this,i),h=l.on;h!==e&&(t=(e=h).copy(),t._.cancel.push(a),t._.interrupt.push(a),t._.end.push(c)),l.on=t}),r===0&&o()})}var du=0;function J(e,t,n,i){this._groups=e,this._parents=t,this._name=n,this._id=i}function Ur(){return++du}var Z=We.prototype;J.prototype={constructor:J,select:qh,selectAll:Kh,selectChild:Z.selectChild,selectChildren:Z.selectChildren,filter:Bh,merge:Hh,selection:Jh,transition:uu,call:Z.call,nodes:Z.nodes,node:Z.node,size:Z.size,empty:Z.empty,each:Z.each,on:Gh,attr:Ah,attrTween:Mh,style:tu,styleTween:ru,text:au,textTween:hu,remove:Xh,tween:vh,delay:Lh,duration:Rh,ease:Fh,easeVarying:zh,end:fu,[Symbol.iterator]:Z[Symbol.iterator]};function pu(e){return((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2}var gu={time:null,delay:0,duration:250,ease:pu};function mu(e,t){for(var n;!(n=e.__transition)||!(n=n[t]);)if(!(e=e.parentNode))throw new Error(`transition ${t} not found`);return n}function vu(e){var t,n;e instanceof J?(t=e._id,e=e._name):(t=Ur(),(n=gu).time=_n(),e=e==null?null:e+"");for(var i=this._groups,r=i.length,o=0;o<r;++o)for(var s=i[o],a=s.length,c,l=0;l<a;++l)(c=s[l])&&Ot(c,e,t,l,s,n||mu(c,t));return new J(i,this._parents,e,t)}We.prototype.interrupt=Xl,We.prototype.transition=vu;class xu extends ft{name="viewport";minScale;maxScale;_dragEnabled;transitionDuration;canvas;d3Sel;d3Zoom;_hitObject=!1;_stageDown;constructor(t){super(),this.minScale=t?.minScale??.1,this.maxScale=t?.maxScale??10,this._dragEnabled=t?.dragEnabled??!0,this.transitionDuration=t?.transitionDuration??300}get dragEnabled(){return this._dragEnabled}set dragEnabled(t){this._dragEnabled=t}install(t){super.install(t),this.canvas=t.app.canvas}onBindActiveScene(t){const n=this.topology;if(!n||!this.canvas)return;const i=this.canvas,r=n.app.stage,o=t.projectionContainer;this._stageDown=a=>{this._hitObject=a.target!==r},r.on("pointerdown",this._stageDown),this.d3Zoom=oe.zoom().scaleExtent([this.minScale,this.maxScale]).filter(a=>a.button||a.ctrlKey&&a.type!=="wheel"?!1:a.type==="wheel"||a.type==="dblclick"?!0:this._dragEnabled&&!this._hitObject).on("zoom",a=>{const{x:c,y:l,k:h}=a.transform;o.scale.set(h),o.position.set(c,l)}),this.d3Sel=Nl(i),this.d3Sel.call(this.d3Zoom);const s=new oe.ZoomTransform(o.scale.x,o.x,o.y);this.d3Sel.call(this.d3Zoom.transform,s),t.setCameraHandler(a=>{if(!this.d3Sel||!this.d3Zoom){t.applyCamera(a);return}const c=new oe.ZoomTransform(a.zoom,a.x,a.y),l=this.transitionDuration;if(l<=0){t.applyCamera(a),this.d3Sel.property("__zoom",c);return}return new Promise(h=>{this.d3Sel.transition().duration(l).call(this.d3Zoom.transform,c).on("end",()=>h()).on("interrupt",()=>{h()})})})}onUnbindActiveScene(){this.activeScene?.setCameraHandler(void 0);const t=this.topology?.app.stage;t&&this._stageDown&&t.off("pointerdown",this._stageDown),this._stageDown=void 0,this._hitObject=!1,this.d3Sel&&(this.d3Sel.on(".zoom",null),this.d3Sel=void 0),this.d3Zoom=void 0}uninstall(t){this.canvas=void 0,super.uninstall(t)}getTransform(){return this.d3Sel?oe.zoomTransform(this.d3Sel.node()):oe.zoomIdentity}zoomTo(t,n,i){if(!this.d3Sel||!this.d3Zoom||!this.canvas)return;const r=n??this.canvas.clientWidth/2,o=i??this.canvas.clientHeight/2;this.d3Sel.call(this.d3Zoom.scaleTo,t,[r,o])}panTo(t,n){if(!this.d3Sel||!this.d3Zoom)return;const i=this.getTransform().k;this.d3Sel.call(this.d3Zoom.transform,new oe.ZoomTransform(i,t,n))}}class yu extends _t{name="node-editor";targetType="node";get highlightOptions(){return{padding:4,lineWidth:3}}getCollection(t){return t.nodes}getItemId(t){return t.id}getItemPosition(t){return{x:t.x,y:t.y}}snapDelta(t){return ie(t)/v}applyDrag(t,n,i,r){t.setPosition(n,i),r.lines?.redrawLinesForNode(t.id)}onDragEnd(t,n){t.setOptions({x:t.x,y:t.y}),n.lines?.redrawLinesForNode(t.id)}}class _u extends Ce{name="line-editor";editStates=new Map;selectedLineId=null;dragCtx=null;RADIUS=12;COLOR_POSITION=4886754;COLOR_NODE=8947848;TEXT_COLOR=16777215;TEXT_SIZE=14;hookScene(t){const n=t.lines;for(const o of n.getAll())this.attachLine(o,t);const i=o=>this.attachLine(o,t),r=({id:o})=>this.detachLine(o);return n.on("line:added",i),n.on("line:removed",r),()=>{n.off("line:added",i),n.off("line:removed",r);for(const o of n.getAll())this.detachLine(o.id)}}onItemPointerDown({itemType:t,itemId:n}){if(t!=="line"){t!==null?this.clearSelectionSilent():this.clearSelection();return}n&&this.selectedLineId!==n&&this.select(n)}attachLine(t,n){const i=t.getContainer();i.eventMode="static",i.cursor="pointer";const r=new w.Container;r.visible=!1,r.zIndex=1e4,n.projectionContainer.addChild(r);const o=a=>{this.selectedLineId===t.id&&this.handlePathDrag(a,t,n)},s=()=>{this.selectedLineId===t.id&&this.renderMarkers(this.editStates.get(t.id))};i.on("pointerdown",o),t.on("points:changed",s),this.editStates.set(t.id,{line:t,scene:n,markersContainer:r,onLinePointerDown:o,onPointsChanged:s})}detachLine(t){const n=this.editStates.get(t);if(!n)return;const i=n.line.getContainer();i.off("pointerdown",n.onLinePointerDown),n.line.off("points:changed",n.onPointsChanged),i.eventMode="auto",i.cursor="default",n.markersContainer.destroy({children:!0}),this.editStates.delete(t),this.selectedLineId===t&&(this.selectedLineId=null)}savedZIndex=null;SELECTED_ZINDEX=9999;select(t){if(this.selectedLineId&&this.selectedLineId!==t&&this.clearSelectionSilent(),this.selectedLineId===t){this.deselect(t);return}const n=this.editStates.get(t);if(!n)return;this.selectedLineId=t;const i=n.line.getContainer();this.savedZIndex=i.zIndex,i.zIndex=this.SELECTED_ZINDEX,this.renderMarkers(n),this.topology?.emit("selection:changed",{pluginName:this.name,itemType:"line",itemId:t})}deselect(t){const n=this.editStates.get(t);n&&(this.savedZIndex!==null&&(n.line.getContainer().zIndex=this.savedZIndex,this.savedZIndex=null),this.selectedLineId=null,this.cancelDrag(),n.markersContainer.visible=!1,n.markersContainer.removeChildren(),this.topology?.emit("selection:changed",{pluginName:this.name,itemType:"line",itemId:null}))}getSelectedLineId(){return this.selectedLineId}clearSelection(){this.selectedLineId&&this.deselect(this.selectedLineId)}clearSelectionSilent(){if(!this.selectedLineId)return;const t=this.editStates.get(this.selectedLineId);t&&(this.savedZIndex!==null&&(t.line.getContainer().zIndex=this.savedZIndex,this.savedZIndex=null),this.selectedLineId=null,this.cancelDrag(),t.markersContainer.visible=!1,t.markersContainer.removeChildren())}renderMarkers(t){const{line:n,scene:i,markersContainer:r}=t,o=n.options.anchor;r.removeChildren(),o.forEach((s,a)=>{const c=n.resolveAnchorPosition(s);if(!c)return;const l=n.isAnchorNode(s),h=this.createMarker(a,l);h.position.set(c.x*v,c.y*v),l||(h.eventMode="static",h.cursor="grab",h.on("pointerdown",u=>{u.stopPropagation(),this.startAnchorDrag(n.id,a,i,!1)})),r.addChild(h)}),r.visible=!0}createMarker(t,n){const i=new w.Container,r=new w.Graphics;r.circle(0,0,this.RADIUS),r.fill({color:n?this.COLOR_NODE:this.COLOR_POSITION,alpha:n?.5:1}),r.stroke({color:16777215,width:2,alpha:n?.4:.8});const o=new w.Text({text:t.toString(),style:{fontSize:this.TEXT_SIZE,fill:this.TEXT_COLOR,fontWeight:"bold"}});return o.anchor.set(.5),i.addChild(r,o),i}startAnchorDrag(t,n,i,r){this.cancelDrag();const o=this.editStates.get(t);if(!o)return;const s=i.projectionContainer,a=i.stage,c=h=>{const u=s.toLocal(h.global),f=ie(u.x)/v,d=ie(u.y)/v;o.line.updateAnchorPosition(n,f,d),this.renderMarkers(o)},l=()=>{a.off("globalpointermove",c),a.off("pointerup",l),a.off("pointerupoutside",l),this.dragCtx=null,o.line.draw(),this.renderMarkers(o)};a.on("globalpointermove",c),a.on("pointerup",l),a.on("pointerupoutside",l),this.dragCtx={lineId:t,anchorIndex:n,isNewAnchor:r,onMove:c,onUp:l}}cancelDrag(){if(!this.dragCtx)return;const t=this.editStates.get(this.dragCtx.lineId);if(t){const n=t.scene.stage;n.off("globalpointermove",this.dragCtx.onMove),n.off("pointerup",this.dragCtx.onUp),n.off("pointerupoutside",this.dragCtx.onUp)}this.dragCtx=null}handlePathDrag(t,n,i){const r=i.projectionContainer,o=r.toLocal(t.global),s=ie(o.x)/v,a=ie(o.y)/v,c=n.options.anchor;for(const x of c){const I=n.resolveAnchorPosition(x);if(I&&I.x===s&&I.y===a)return}const l=n.getPoints();if(l.length<2)return;const h={x:s*v,y:a*v};let u=1/0,f=0;for(let x=0;x<l.length-1;x++){const I=Ui(h,l[x],l[x+1]);I<u&&(u=I,f=x)}const d=this.findAnchorInsertIndex(n,i,f),p=i.stage;let m=!1;const y=x=>{if(!m){m=!0;const I=r.toLocal(x.global),A=ie(I.x)/v,O=ie(I.y)/v,R={x:A,y:O};n.insertAnchor(d,R),this.renderMarkers(this.editStates.get(n.id)),p.off("globalpointermove",y),p.off("pointerup",S),p.off("pointerupoutside",S),this.startAnchorDrag(n.id,d,i,!0)}},S=()=>{p.off("globalpointermove",y),p.off("pointerup",S),p.off("pointerupoutside",S)};p.on("globalpointermove",y),p.on("pointerup",S),p.on("pointerupoutside",S)}findAnchorInsertIndex(t,n,i){const r=t.options.anchor,o=t.getPoints();if(r.length<=2)return 1;const s=[];for(let c=0;c<r.length;c++){const l=t.resolveAnchorPosition(r[c]);l&&s.push({px:l.x*v,py:l.y*v,anchorIdx:c})}const a=[];for(const c of s){let l=0,h=1/0;for(let u=0;u<o.length;u++){const f=o[u].x-c.px,d=o[u].y-c.py,p=f*f+d*d;p<h&&(h=p,l=u)}a.push(l)}for(let c=0;c<a.length-1;c++)if(i>=a[c]&&i<a[c+1])return s[c].anchorIdx+1;return r.length-1}}class wu extends _t{name="text-editor";targetType="text";step;constructor(t){super(),this.step=t?.step??1}get highlightOptions(){return{radius:4}}getCollection(t){return t.texts}getItemId(t){return t.id}getItemPosition(t){return{x:t.x,y:t.y}}snapDelta(t){const n=this.step*v;return Math.round(t/n)*this.step}applyDrag(t,n,i){t.setOptions({x:n,y:i})}}class Su extends _t{name="rect-drag";targetType="rect";step;constructor(t){super(),this.step=t?.step??1}getCollection(t){return t.rects}getItemId(t){return t.id}getItemPosition(t){return{x:t.x,y:t.y}}snapDelta(t){const n=this.step*v;return Math.round(t/n)*this.step}applyDrag(t,n,i){t.setOptions({x:n,y:i})}onAttachItem(t){const n=o=>this.selectItem(o),i=o=>{this.selected?.id===o.id&&this.clearSelection()},r=()=>{this.selected?.id===t.id&&this.highlight.draw(t.getGraphics())};return t.on("item:selected",n),t.on("item:deselected",i),t.on("options:changed",r),()=>{t.off("item:selected",n),t.off("item:deselected",i),t.off("options:changed",r)}}}class Iu extends Ce{name="rect-resize";resizeHandles;activeRect=null;resizeState={isResizing:!1,handle:null,startRect:{x:0,y:0,width:0,height:0},startMouse:{x:0,y:0}};resizeGlobalHandlers;step;rectListeners=new Map;constructor(t){super(),this.step=t?.step??1}hookScene(t){const{rects:n}=t;for(const s of n.getAll())this.attachListeners(s);const i=s=>this.attachListeners(s),r=({id:s})=>this.detachListeners(s),o=()=>{for(const s of n.getAll())this.detachListeners(s.id)};return n.on("rect:added",i),n.on("rect:removed",r),n.on("rects:cleared",o),()=>{n.off("rect:added",i),n.off("rect:removed",r),n.off("rects:cleared",o);for(const s of n.getAll())this.detachListeners(s.id)}}onSceneSwitched(){this.activeRect?.deselect()}attachListeners(t){if(this.rectListeners.has(t.id))return;const n={rect:t,onSelected:i=>{this.activeRect=i,this.drawResizeHandles(i)},onDeselected:i=>{this.activeRect=null,this.cleanupResizeHandles()},onOptionsChanged:()=>{this.activeRect?.id===t.id&&!this.resizeState.isResizing&&this.updateHandlesPosition(t)}};t.on("item:selected",n.onSelected),t.on("item:deselected",n.onDeselected),t.on("options:changed",n.onOptionsChanged),this.rectListeners.set(t.id,n)}detachListeners(t){const n=this.rectListeners.get(t);if(!n)return;this.activeRect?.id===t&&(this.activeRect=null,this.cleanupResizeHandles());const{rect:i}=n;i.off("item:selected",n.onSelected),i.off("item:deselected",n.onDeselected),i.off("options:changed",n.onOptionsChanged),this.rectListeners.delete(t)}drawResizeHandles(t){this.cleanupResizeHandles();const n=t.getGraphics(),i=n.getLocalBounds(),r=8,o=4886754,s=16777215,a=new w.Container;a.position.copyFrom(n.position);const c=[{type:"nw",x:i.x,y:i.y,cursor:"nw-resize"},{type:"n",x:i.x+i.width/2,y:i.y,cursor:"ns-resize"},{type:"ne",x:i.x+i.width,y:i.y,cursor:"ne-resize"},{type:"e",x:i.x+i.width,y:i.y+i.height/2,cursor:"ew-resize"},{type:"se",x:i.x+i.width,y:i.y+i.height,cursor:"se-resize"},{type:"s",x:i.x+i.width/2,y:i.y+i.height,cursor:"ns-resize"},{type:"sw",x:i.x,y:i.y+i.height,cursor:"sw-resize"},{type:"w",x:i.x,y:i.y+i.height/2,cursor:"ew-resize"}],l=this.topology;if(!l)return;const h=l.activeScene;if(!h)return;c.forEach(({type:p,x:m,y,cursor:S})=>{const x=new w.Graphics;x.rect(-r/2,-r/2,r,r),x.fill({color:o}),x.stroke({color:s,width:2}),x.position.set(m,y),x.eventMode="static",x.cursor=S,x.on("pointerdown",I=>{I.stopPropagation(),this.resizeState.isResizing=!0,this.resizeState.handle=p;const A=h.projectionContainer.toLocal(I.global);this.resizeState.startMouse={x:A.x,y:A.y},this.resizeState.startRect={x:t.x,y:t.y,width:t.options.width,height:t.options.height}}),a.addChild(x)});const u=p=>{if(!this.resizeState.isResizing||!this.resizeState.handle)return;const m=h.projectionContainer.toLocal(p.global),y=(m.x-this.resizeState.startMouse.x)/v,S=(m.y-this.resizeState.startMouse.y)/v;this.applyResize(t,this.resizeState.handle,y,S)},f=()=>{this.resizeState.isResizing&&(this.resizeState.isResizing=!1,this.resizeState.handle=null)};this.resizeGlobalHandlers={onMove:u,onUp:f};const d=this.topology?.stage;d&&(d.on("globalpointermove",u),d.on("pointerup",f),d.on("pointerupoutside",f)),n.parent?.addChild(a),this.resizeHandles=a}cleanupResizeHandles(){if(this.resizeGlobalHandlers){const t=this.topology?.stage;t&&(t.off("globalpointermove",this.resizeGlobalHandlers.onMove),t.off("pointerup",this.resizeGlobalHandlers.onUp),t.off("pointerupoutside",this.resizeGlobalHandlers.onUp)),this.resizeGlobalHandlers=void 0}this.resizeHandles?.destroy(),this.resizeHandles=void 0}updateHandlesPosition(t){if(!this.resizeHandles)return;const n=t.getGraphics();this.resizeHandles.position.copyFrom(n.position)}applyResize(t,n,i,r){const{startRect:o}=this.resizeState;let s=o.x,a=o.y,c=o.width,l=o.height;switch(n){case"nw":s=o.x+i,a=o.y+r,c=o.width-i,l=o.height-r;break;case"n":a=o.y+r,l=o.height-r;break;case"ne":a=o.y+r,c=o.width+i,l=o.height-r;break;case"e":c=o.width+i;break;case"se":c=o.width+i,l=o.height+r;break;case"s":l=o.height+r;break;case"sw":s=o.x+i,c=o.width-i,l=o.height+r;break;case"w":s=o.x+i,c=o.width-i;break}c<0&&(s+=c,c=-c),l<0&&(a+=l,l=-l),s=Math.round(s/this.step)*this.step,a=Math.round(a/this.step)*this.step,c=Math.round(c/this.step)*this.step,l=Math.round(l/this.step)*this.step;const h=this.step;c<h&&(c=h),l<h&&(l=h),t.setOptions({x:s,y:a,width:c,height:l}),this.drawResizeHandles(t)}}class Au extends Ge{name="node-runtime";targetType="node";getCollection(t){return t.nodes}getItemId(t){return t.id}}class bu extends Ge{name="line-runtime";targetType="line";getCollection(t){return t.lines}getItemId(t){return t.id}}class Cu extends Ge{name="text-runtime";targetType="text";getCollection(t){return t.texts}getItemId(t){return t.id}}class Tu extends Ge{name="rect-runtime";targetType="rect";getCollection(t){return t.rects}getItemId(t){return t.id}}class et extends ft{_isActive=!1;_opts;_prevDragEnabled=null;_panning=!1;_cleanupKeys;_pendingResolve;_pendingReject;constructor(t){super(),this._opts={rightClickToStop:t?.rightClickToStop??!0,panningKey:t?.panningKey??"Space",suppressSelection:t?.suppressSelection??!0}}get isActive(){return this._isActive}get isPanning(){return this._panning}stop(){if(!this._isActive)return;this._isActive=!1,this.onStop(),this._endPan(),this._unbindKeys(),this._setHitTest(!0),this._restoreViewportDrag();const t=this._pendingReject;this._pendingResolve=void 0,this._pendingReject=void 0,t?.()}activate(){this._isActive&&this.stop();const t=this.activeScene;return!t||!this.topology?null:(this._isActive=!0,this._disableViewportDrag(),this._setHitTest(!1),this._bindKeys(),t)}createPending(){return new Promise((t,n)=>{this._pendingResolve=t,this._pendingReject=n})}complete(t){const n=this._pendingResolve;this._pendingResolve=void 0,this._pendingReject=void 0,this.stop(),n?.(t)}onBindActiveScene(t){}onUnbindActiveScene(){this.stop()}uninstall(t){this.stop(),super.uninstall(t)}_disableViewportDrag(){const t=this.topology?.getPlugin("viewport");t&&(this._prevDragEnabled=t.dragEnabled,t.dragEnabled=!1)}_restoreViewportDrag(){if(this._prevDragEnabled===null)return;const t=this.topology?.getPlugin("viewport");t&&(t.dragEnabled=this._prevDragEnabled),this._prevDragEnabled=null}_setHitTest(t){if(!this._opts.suppressSelection)return;const n=this.topology?.getPlugin("hit-test");n&&(n.enabled=t),this.activeScene&&(this.activeScene.projectionContainer.interactiveChildren=t)}_bindKeys(){const t=this.topology?.app?.canvas;if(!t)return;const{panningKey:n,rightClickToStop:i}=this._opts,r=a=>{n&&a.code===n&&!this._panning&&(a.preventDefault(),this._beginPan())},o=a=>{n&&a.code===n&&this._panning&&this._endPan()},s=a=>{i&&(a.preventDefault(),this.stop())};window.addEventListener("keydown",r),window.addEventListener("keyup",o),t.addEventListener("contextmenu",s),this._cleanupKeys=()=>{window.removeEventListener("keydown",r),window.removeEventListener("keyup",o),t.removeEventListener("contextmenu",s)}}_unbindKeys(){this._cleanupKeys?.(),this._cleanupKeys=void 0}_beginPan(){this._panning=!0;const t=this.topology?.getPlugin("viewport");t&&(t.dragEnabled=!0),this.topology?.stage&&(this.topology.stage.cursor="grab")}_endPan(){if(!this._panning)return;this._panning=!1;const t=this.topology?.getPlugin("viewport");t&&(t.dragEnabled=!1),this.topology?.stage&&(this.topology.stage.cursor="crosshair")}toTile(t,n){const i=n.projectionContainer.toLocal(t.global);return{x:Math.round(i.x/v),y:Math.round(i.y/v)}}}class Eu extends et{name="text-creator";_defaults={};_previewId=null;_handlers=null;constructor(t){super(t)}start(t){this._defaults=t??{};const n=this.activate();return n?(this._createPreview(n),this._bindEvents(n),this.createPending()):Promise.reject()}onStop(){this._removePreview(),this._unbindEvents()}_createPreview(t){const n=$e();this._previewId=n;const i=t.texts.add({id:n,x:0,y:0,...this._defaults,text:this._defaults.text??"Text"});i.getGraphics().alpha=.5}_removePreview(){this._previewId&&this.activeScene?.texts.has(this._previewId)&&this.activeScene.texts.remove(this._previewId),this._previewId=null}_bindEvents(t){const n=this.topology.stage;if(!n)return;const i=o=>{if(this.isPanning||!this._previewId||!this.activeScene)return;const s=this.toTile(o,t);this.activeScene.texts.get(this._previewId)?.setOptions({x:s.x,y:s.y})},r=o=>{if(o.button!==0||this.isPanning||!this._previewId||!this.activeScene)return;const s=this.activeScene.texts.get(this._previewId);s&&(s.getGraphics().alpha=1);const a=this._previewId;this._previewId=null,this.complete(a)};n.on("globalpointermove",i),n.on("pointerdown",r),this._handlers={onMove:i,onDown:r},n.cursor="crosshair"}_unbindEvents(){const t=this.topology?.stage;!t||!this._handlers||(t.off("globalpointermove",this._handlers.onMove),t.off("pointerdown",this._handlers.onDown),t.cursor="default",this._handlers=null)}}class Mu extends et{name="rect-creator";_defaults={};_previewId=null;_isDragging=!1;_startTile={x:0,y:0};_handlers=null;constructor(t){super(t)}start(t){this._defaults=t??{};const n=this.activate();return n?(this._bindEvents(n),this.createPending()):Promise.reject()}onStop(){this._removePreview(),this._unbindEvents(),this._isDragging=!1}_removePreview(){this._previewId&&this.activeScene?.rects.has(this._previewId)&&this.activeScene.rects.remove(this._previewId),this._previewId=null}_bindEvents(t){const n=this.topology.stage;if(!n)return;const i=s=>{if(s.button!==0||this.isPanning||this._isDragging)return;this._isDragging=!0;const a=this.toTile(s,t);this._startTile=a;const c=$e();this._previewId=c;const l=t.rects.add({id:c,x:a.x,y:a.y,width:1,height:1,...this._defaults});l.getGraphics().alpha=.5},r=s=>{if(this.isPanning||!this._isDragging||!this._previewId||!this.activeScene)return;const a=this.toTile(s,t),c=Math.min(this._startTile.x,a.x),l=Math.min(this._startTile.y,a.y),h=Math.max(1,Math.abs(a.x-this._startTile.x)),u=Math.max(1,Math.abs(a.y-this._startTile.y));this.activeScene.rects.get(this._previewId)?.setOptions({x:c,y:l,width:h,height:u})},o=s=>{if(this.isPanning||!this._isDragging)return;this._isDragging=!1;const a=this.activeScene?.rects.get(this._previewId);a&&(a.getGraphics().alpha=1);const c=this._previewId;this._previewId=null,this.complete(c)};n.on("pointerdown",i),n.on("globalpointermove",r),n.on("pointerup",o),n.on("pointerupoutside",o),this._handlers={onDown:i,onMove:r,onUp:o},n.cursor="crosshair"}_unbindEvents(){const t=this.topology?.stage;!t||!this._handlers||(t.off("pointerdown",this._handlers.onDown),t.off("globalpointermove",this._handlers.onMove),t.off("pointerup",this._handlers.onUp),t.off("pointerupoutside",this._handlers.onUp),t.cursor="default",this._handlers=null)}}class Ou extends et{name="line-creator";_defaults={};_previewId=null;_isDragging=!1;_handlers=null;constructor(t){super(t)}start(t){this._defaults=t??{};const n=this.activate();return n?(this._bindEvents(n),this.createPending()):Promise.reject()}onStop(){this._removePreview(),this._unbindEvents(),this._isDragging=!1}_removePreview(){this._previewId&&this.activeScene?.lines.has(this._previewId)&&this.activeScene.lines.remove(this._previewId),this._previewId=null}_bindEvents(t){const n=this.topology.stage;if(!n)return;const i=s=>{if(s.button!==0||this.isPanning||this._isDragging)return;this._isDragging=!0;const a=this.toTile(s,t),c=$e();this._previewId=c;const l=t.lines.add({id:c,anchor:[{x:a.x,y:a.y},{x:a.x,y:a.y}],...this._defaults});l.getGraphics().alpha=.5,l.draw()},r=s=>{if(this.isPanning||!this._isDragging||!this._previewId||!this.activeScene)return;const a=this.toTile(s,t);this.activeScene.lines.get(this._previewId)?.updateAnchorPosition(1,a.x,a.y)},o=s=>{if(this.isPanning||!this._isDragging)return;this._isDragging=!1;const a=this.activeScene?.lines.get(this._previewId);a&&(a.getGraphics().alpha=1,a.draw());const c=this._previewId;this._previewId=null,this.complete(c)};n.on("pointerdown",i),n.on("globalpointermove",r),n.on("pointerup",o),n.on("pointerupoutside",o),this._handlers={onDown:i,onMove:r,onUp:o},n.cursor="crosshair"}_unbindEvents(){const t=this.topology?.stage;!t||!this._handlers||(t.off("pointerdown",this._handlers.onDown),t.off("globalpointermove",this._handlers.onMove),t.off("pointerup",this._handlers.onUp),t.off("pointerupoutside",this._handlers.onUp),t.cursor="default",this._handlers=null)}}class Pu extends et{name="node-creator";_defaults={};_previewId=null;_tempIconIds=new Set;_promotedIconIds=new Set;_handlers=null;constructor(t){super(t)}start(t,n){this._defaults=t??{};const i=this.activate();return i?(this._registerTempIcons(n),this._createPreview(i),this._bindEvents(i),this.createPending()):Promise.reject()}onStop(){this._removePreview(),this._unbindEvents(),this._removeTempIcons()}_registerTempIcons(t){if(!(!t?.length||!this.topology))for(const n of t)this.topology.icons.has(n.id)||(this.topology.icons.add(n),this._tempIconIds.add(n.id))}_removeTempIcons(){if(this.topology){for(const t of this._tempIconIds)this._promotedIconIds.has(t)||this.topology.icons.remove(t);this._tempIconIds.clear(),this._promotedIconIds.clear()}}_createPreview(t){const n=$e();this._previewId=n;const i=t.nodes.add({icon:"",...this._defaults,id:n,x:0,y:0});i.getGraphics().alpha=.5}_removePreview(){this._previewId&&this.activeScene?.nodes.has(this._previewId)&&this.activeScene.nodes.remove(this._previewId),this._previewId=null}_bindEvents(t){const n=this.topology.stage;if(!n)return;const i=o=>{if(this.isPanning||!this._previewId||!this.activeScene)return;const s=this.toTile(o,t);this.activeScene.nodes.get(this._previewId)?.setOptions({x:s.x,y:s.y})},r=o=>{if(o.button!==0||this.isPanning||!this._previewId||!this.activeScene)return;const s=this.activeScene.nodes.get(this._previewId);if(s){s.getGraphics().alpha=1;const c=s.options.icon;c&&this._tempIconIds.has(c)&&this._promotedIconIds.add(c)}const a=this._previewId;this._previewId=null,this.complete(a)};n.on("globalpointermove",i),n.on("pointerdown",r),this._handlers={onMove:i,onDown:r},n.cursor="crosshair"}_unbindEvents(){const t=this.topology?.stage;!t||!this._handlers||(t.off("globalpointermove",this._handlers.onMove),t.off("pointerdown",this._handlers.onDown),t.cursor="default",this._handlers=null)}}Object.defineProperty(g,"ZoomTransform",{enumerable:!0,get:()=>oe.ZoomTransform}),g.AZIMUTH=le,g.ActiveScenePlugin=ft,g.BILLBOARD_SCALE_X=cn,g.BILLBOARD_SCALE_Y=Fe,g.BILLBOARD_SKEW_X=sn,g.BILLBOARD_SKEW_Y=an,g.BaseCreatorPlugin=et,g.COS_ELEVATION=De,g.ELEVATION=Jt,g.HitTestPlugin=Zi,g.ISOMETRIC_SKEW_X=Qt,g.ISOMETRIC_SKEW_Y=en,g.IconManager=ji,g.InteractiveRuntimePlugin=Ge,g.LineCreatorPlugin=Ou,g.LineEditorPlugin=_u,g.LineRuntimePlugin=bu,g.NodeCreatorPlugin=Pu,g.NodeEditorPlugin=yu,g.NodeRuntimePlugin=Au,g.RectCreatorPlugin=Mu,g.RectDragPlugin=Su,g.RectResizePlugin=Iu,g.RectRuntimePlugin=Tu,g.SIN_ELEVATION=ne,g.Scene=he,g.SceneAwarePlugin=Ce,g.SelectableEditorPlugin=_t,g.SelectionHighlight=er,g.StateManager=Qi,g.TILE_HDIAGONAL=ua,g.TILE_HEIGHT=ha,g.TILE_SIZE=v,g.TILE_VDIAGONAL=Zt,g.TILE_WIDTH=la,g.TextCreatorPlugin=Eu,g.TextEditorPlugin=wu,g.TextRuntimePlugin=Cu,g.Topology=yt,g.ViewportPlugin=xu,g.calculateIsometricSkew=jt,g.calculateIsometricTileDiagonals=fa,g.createBlinkStatePlugin=Ba,g.createBounceStatePlugin=Ha,g.createBrightenStatePlugin=Ua,g.createDarkenStatePlugin=Ya,g.createGlowStatePlugin=Ka,g.createHeartbeatStatePlugin=Va,g.createShimmerStatePlugin=Qa,g.createTintStatePlugin=ec,g.default=yt,g.downloadFile=Ue,g.findPath=Yi,g.generateUUID=$e,g.getBoundingBox=Gi,g.getBoundingBoxSize=Wi,g.getItemMetadata=Ki,g.isometricToWorld=pa,g.normalizePositionFromOrigin=Xi,g.parseYaml=ce,g.pointToSegmentDist=Ui,g.projectToIsometric=da,g.setItemMetadata=ze,g.snapToTile=ie,g.sortByPosition=ln,g.toYaml=ae,Object.defineProperties(g,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fuxi-topology",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "description": "A topology visualization library based on PixiJS",
5
5
  "type": "module",
6
6
  "main": "./dist/fuxi-topology.umd.cjs",