@elicdavis/node-flow 0.2.4 → 0.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@elicdavis/node-flow",
3
3
  "description": "build node graphs",
4
4
  "author": "Eli C Davis",
5
- "version": "0.2.4",
5
+ "version": "0.2.5",
6
6
  "license": "MIT",
7
7
  "keywords": [
8
8
  "nodes",
@@ -1,8 +0,0 @@
1
- var ft=new Set,ct=!1,mt=0,mn=()=>typeof requestAnimationFrame=="function";function Lt(r){return ft.add(r),()=>{ft.delete(r)}}function b(){ct||!mn()||(ct=!0,requestAnimationFrame(()=>{ct=!1,ft.forEach(r=>r()),mt>0&&b()}))}function pt(){mt++,b();let r=!1;return()=>{r||(r=!0,mt--)}}var yt={FontFamily:"Courier New",Graph:{BackgroundColor:"#07212a",DotColor:"rgb(41, 54, 57)"},Node:{FontColor:"#afb9bb",BackgroundColor:"#0c2b35",Title:{Color:"#154050",FontColor:"#afb9bb",Padding:5},BorderRadius:15,Border:{Idle:"#1c1c1c",MouseOver:"#8e8e8e",Grabbed:"white",Selected:"#6e6e6e",Highlighted:"#ffc95c"},Bevel:null,Port:{FontColor:"#afb9bb"},Message:{InfoColor:"#afb9bb",WarnColor:"#f1f663ff",ErrorColor:"#FF0000"}},BoxSelect:{Color:"white",Size:1,Radius:2,LineDashLength:5},Widget:{FontColor:"#afb9bb",LabelColor:"#7f9497",FontSize:14,Padding:6,Gap:4,BackgroundColor:"#0f313c",Border:{Color:"#154050",Size:2,Radius:2},Bevel:null,Hover:{BackgroundColor:"#195366"},Input:{BackgroundColor:"#0f313c",HoverBackgroundColor:"#195366",FontColor:"#afb9bb"},Slider:{FillColor:"#07212A"},Button:{Click:{BackgroundColor:"#1f637a"}}},ContextMenu:{BackgroundColor:"#07212A",HighlightColor:"#205A6D",HighlightFontColor:"#afb9bb",FontColor:"#afb9bb",DisabledFontColor:"#4a585c",BorderRadius:5},Minimap:{BackgroundColor:"rgba(10, 16, 18, 0.85)",BorderColor:"#1c1c1c",BorderRadius:4,Padding:6,NodeColor:"#6b7f85",ViewportColor:"rgba(175, 185, 187, 0.25)"},Popup:{BackgroundColor:"#000000",FontColor:"#ffffff",FontFamily:"Verdana",BorderRadius:8,Backdrop:"#00000070"},Note:{FontColor:"#afb9bb",FontSize:16,EntrySpacing:20,LineSpacing:5,DotSize:3,HeaderLineWidth:2,H1:{FontSize:32},H2:{FontSize:16},H3:{FontSize:16},CodeFontFamily:null,CodeBlock:{BackgroundColor:"#0c2b35",FontColor:"#afb9bb",Padding:16,BorderRadius:4}}};function Ct(r){return JSON.parse(JSON.stringify(r))}function Ht(r,e){if(e===void 0)return r;if(e===null||typeof e!="object"||r===null||typeof r!="object")return e;for(let t of Object.keys(e))r[t]=Ht(r[t],e[t]);return r}var pn=Object.freeze(Ct(yt)),c=Ct(yt),Ot=0,gt=new Set;function gn(r){let e=Ht(Ct(yt),r);for(let t of Object.keys(e))c[t]=e[t];Ot++,gt.forEach(t=>t()),b()}function D(){return Ot}function yn(r){return gt.add(r),()=>gt.delete(r)}var Cn=16,bn="black";function te(r,e){return{color:r?.color===void 0?e?.color:r?.color,size:r?.size===void 0?e?.size:r?.size,font:r?.font===void 0?e?.font:r?.font,style:r?.style===void 0?e?.style:r?.style,weight:r?.weight===void 0?e?.weight:r?.weight}}var j=class{#e;#t;#n;#o;#i;constructor(e){this.#e=e?.size===void 0?Cn:e.size,this.#t=e?.color===void 0?bn:e.color,this.#n=e?.font,this.#o=e?.weight===void 0?"":e.weight,this.#i=e?.style===void 0?"":e.style}setupStyle(e,t){e.fillStyle=this.#t,e.font=this.#i+" "+this.#o+" "+this.#e*t+"px "+this.getFont()}getSize(){return this.#e}getFont(){return this.#n??c.FontFamily}getWeight(){return this.#o}getStyle(){return this.#i}measure(e,t,n,i){this.setupStyle(e,t);let o=e.measureText(n);i.x=o.width,i.y=o.actualBoundingBoxAscent+o.actualBoundingBoxDescent}setColor(e){this.#t=e}getColor(){return this.#t}setSize(e){this.#e=e}setWeight(e){this.#o=e}};var bt=class{#e;#t;#n;#o;#i;constructor(e,t){this.#e=new Array,this.#t=0,this.#n=e,this.#o=t,this.#i=0}runIf(e,t){e&&this.run(t)}#s(){return this.#i>0}run(e){let t=this.#t;this.#i+=1,e(),this.#i-=1,this.#t=t}get(){if(!this.#s())throw new Error("can't use pool outside of running context");let e;return this.#e.length===this.#t?(e=this.#n(),this.#e.push(this.#n())):(e=this.#e[this.#t],this.#o(e)),this.#t++,e}},A=new bt(()=>({x:0,y:0}),r=>{r.x=0,r.y=0});function z(r,e){r.x=e.x,r.y=e.y}function He(r,e,t){r.x=e.x-t.x,r.y=e.y-t.y}function Ne(r,e,t){r.x=e.x+t.x,r.y=e.y+t.y}function Y(r,e){r.x*=e,r.y*=e}function P(){return{x:0,y:0}}function ge(r,e){let t=e.x-r.x,n=e.y-r.y;return Math.sqrt(t*t+n*n)}function Gt(r,e){if(r.x>e.x){let t=e.x;e.x=r.x,r.x=t}if(r.y>e.y){let t=e.y;e.y=r.y,r.y=t}}function xt(r,e){let t=!1;return A.run(()=>{let n=A.get(),i=A.get();z(n,r.Position),Ne(i,n,r.Size),Gt(n,i);let o=A.get(),s=A.get();z(o,e.Position),Ne(s,o,e.Size),Gt(o,s),t=n.x<=s.x&&i.x>=o.x&&n.y<=s.y&&i.y>=o.y}),t}function wt(r,e){return e.x=r.Position.x+r.Size.x/2,e.y=r.Position.y+r.Size.y/2,e}function T(r,e){let t=r.Position;return!(e.x<t.x||e.y<t.y||e.x>t.x+r.Size.x||e.y>t.y+r.Size.y)}var W=class{#e;#t;constructor(){this.#e=new Array,this.#t=0}Count(){return this.#t}Clear(){this.#t=0}At(e){return this.#e[e]}Push(e){this.#e.length===this.#t?this.#e.push(e):this.#e[this.#t]=e,this.#t++}ToArray(){let e=new Array(this.Count());for(let t=0;t<this.#t;t++)e[t]=this.#e[t];return e}};var _t=30;var qt=(n=>(n[n.Enabled=0]="Enabled",n[n.Disabled=1]="Disabled",n[n.Hidden=2]="Hidden",n))(qt||{}),vt=class{#e;#t;#n;#o;group;constructor(e){this.#e=e?.name===void 0?"item":e.name,this.#t=e?.callback,this.#n=new j(e?.textStyle),this.group=e?.group,this.#o=e?.enabled===void 0?0:e.enabled()}getName(){return this.#e}state(){return this.#o}execute(){this.#o!==0||this.#t===void 0||this.#t()}},St=class{constructor(e){this.entries=e;this.#e=e.length*_t}#e;height(){return this.#e}},Oe=class{constructor(e,t,n){this.text=e;this.subMenu=t;this.item=n}click(){this.item?.execute()}};function Z(...r){let e={items:new Array,subMenus:new Array};for(let t=0;t<r.length;t++){let n=r[t];n!==void 0&&(n.items!==void 0&&(e.items=e.items?.concat(n.items)),n.subMenus!==void 0&&(e.subMenus=e.subMenus?.concat(n.subMenus)))}return e}var ne=class{#e;#t;#n;#o;#i;#s;#r;constructor(e){if(this.#r=P(),this.#i=new W,this.#e=e?.name===void 0?"menu":e?.name,this.#t=new Array,this.#n=new Array,this.#o=new j(te(e?.textStyle,{color:c.ContextMenu.FontColor})),this.#s=e?.group,e?.subMenus!==void 0)for(let t=0;t<e?.subMenus.length;t++)this.#n.push(new ne(e?.subMenus[t]));if(e?.items!==void 0)for(let t=0;t<e?.items.length;t++){let n=new vt(e?.items[t]);n.state()!==2&&this.#t.push(n)}this.#l()}#l(){let e=new Map,t=new Array;t.push(new Array);for(let n=0;n<this.#t.length;n++){let i=0,o=this.#t[n];if(o.group!==void 0){let s=e.get(o.group);s!==void 0?i=s:(i=t.length,e.set(o.group,i),t.push(new Array))}t[i].push(new Oe(this.#t[n].getName(),void 0,this.#t[n]))}for(let n=0;n<this.#n.length;n++){let i=0,o=this.#n[n];if(o.#s!==void 0){let s=e.get(o.#s);s!==void 0?i=s:(i=t.length,e.set(o.#s,i),t.push(new Array))}t[i].push(new Oe(this.#n[n].getName(),this.#n[n],void 0))}this.#i.Clear();for(let n=0;n<t.length;n++){let i=t[n];i.length!==0&&this.#i.Push(new St(i))}}#d=0;#h(e,t){if(this.#d>0)return this.#d;let n=P();for(let i=0;i<this.#i.Count();i++){let o=this.#i.At(i);for(let s=0;s<o.entries.length;s++)this.#o.measure(e,t,o.entries[s].text,n),this.#d=Math.max(n.x,this.#d)}return this.#d}getName(){return this.#e}#u={Position:P(),Size:P()};#c;#a=null;contains(e){return this.#a!==null&&T(this.#a,e)?!0:this.#c!==void 0&&this.#c.contains(e)}render(e,t,n,i,o,s=0){let h=1.25*_t,d=1.25*40+this.#h(e,1.25),a=0;for(let m=0;m<this.#i.Count();m++)a+=this.#i.At(m).height();a*=1.25;let u=e.canvas.clientWidth,f={x:t.x,y:t.y},g=o;if(s===0)o||(f.x-=d),o&&f.x+d>u&&(f.x=u-d,g=!1);else{let m=t.x+s,C=t.x-d,x=m+d<=u,w=C>=0;g=o?x||!w:!w&&x,f.x=g?m:C,f.x=Math.max(0,Math.min(f.x,u-d))}f.y+a>e.canvas.clientHeight&&(f.y=e.canvas.clientHeight-a),f.y=Math.max(0,f.y),this.#a={Position:{x:f.x,y:f.y},Size:{x:d,y:a}};let v=i!==void 0&&this.#c!==void 0&&this.#c.contains(i)?void 0:i;this.#u.Size.x=d,this.#u.Size.y=h,z(this.#u.Position,f),e.textAlign="left",e.fillStyle=c.ContextMenu.BackgroundColor,e.shadowColor="#000000",e.shadowBlur=5*1.25,e.beginPath(),e.roundRect(f.x,this.#u.Position.y,d,a,c.ContextMenu.BorderRadius*1.25),e.fill(),e.shadowBlur=0;let p=null;if(v!==void 0){let m=0;for(let C=0;C<this.#i.Count();C++)for(let x of this.#i.At(C).entries)this.#u.Position.y=f.y+h*m,T(this.#u,v)&&(p=x,this.#c=x.subMenu,this.#r.x=f.x,this.#r.y=this.#u.Position.y),m++}let y=0;for(let m=0;m<this.#i.Count();m++){let C=this.#i.At(m);for(let x=0;x<C.entries.length;x++){let w=C.entries[x];this.#u.Position.y=f.y+h*y;let M=w===p,F=w.item!==void 0&&w.item.state()===1,B=!F&&(M||this.#c!==void 0&&w.subMenu===this.#c);B&&(e.fillStyle=c.ContextMenu.HighlightColor,e.beginPath(),e.roundRect(f.x+h/10,this.#u.Position.y+h/10,d-h/5,h-h/5,c.ContextMenu.BorderRadius*1.25),e.fill()),this.#o.setupStyle(e,1.25),F?e.fillStyle=c.ContextMenu.DisabledFontColor:B&&(e.fillStyle=c.ContextMenu.HighlightFontColor),e.fillText(w.text,f.x+h/5,this.#u.Position.y+h/2),w.subMenu!==void 0&&(e.beginPath(),e.strokeStyle=B?c.ContextMenu.HighlightFontColor:c.ContextMenu.FontColor,e.lineWidth=1*1.25,e.lineTo(f.x+d-h/2.5,this.#u.Position.y+h/3),e.lineTo(f.x+d-h/4,this.#u.Position.y+h/2),e.lineTo(f.x+d-h/2.5,this.#u.Position.y+h-h/3),e.stroke()),y++}if(m!==this.#i.Count()-1){e.strokeStyle=c.ContextMenu.FontColor,e.lineWidth=.5*1.25,e.beginPath();let x=f.x+h/10,w=this.#u.Position.y+h;e.lineTo(x,w),e.lineTo(x+d-h/5,w),e.stroke()}}if(this.#c!==void 0){let m=this.#c.render(e,this.#r,1.25,i,g,d);m!==null&&(p=m)}return p}};var xn=500,wn=12,vn=5e-4,$t=600,Ge=class{#e;#t;#n;#o;#i;#s;#r;#l;#d;#h;#u;#c=!1;#a=null;#f=P();#y=!1;#m=0;#p=0;constructor(e,t,n,i,o,s,l,h,d){this.#n=e,this.#i=t,this.#s=n,this.#r=i,this.#l=o,this.#d=s,this.#h=h,this.#u=d,this.#e=!1,this.#t=P(),this.#o=P(),e.style.touchAction="none";let a=u=>f=>{u(f),b()};e.addEventListener("mousedown",a(this.#T.bind(this)),!1),e.addEventListener("touchstart",a(this.#P.bind(this)),{passive:!1}),document.addEventListener("mouseup",a(this.#z.bind(this)),!1),document.addEventListener("touchend",a(this.#k.bind(this)),!1),document.addEventListener("touchcancel",a(this.#k.bind(this)),!1),e.addEventListener("mousemove",a(this.#A.bind(this)),!1),e.addEventListener("mouseleave",a(()=>{this.#c=!1,this.#e||this.#u?.()}),!1),e.addEventListener("touchmove",a(this.#D.bind(this)),{passive:!1}),e.addEventListener("wheel",a(this.#x.bind(this)),{passive:!1}),e.addEventListener("drop",a(u=>{u.preventDefault(),u.dataTransfer?.items&&[...u.dataTransfer.items].forEach((f,g)=>{if(f.kind==="file"){let v=f.getAsFile();v&&l(v)}})})),e.addEventListener("dragover",a(u=>{u.preventDefault(),this.#s(this.#g(u))})),e.addEventListener("contextmenu",a(u=>{u.preventDefault(),!(Date.now()-this.#p<$t)&&this.#d(this.#g(u))}),!1)}#g(e){let t=this.#n.getBoundingClientRect();return{x:e.clientX-t.left,y:e.clientY-t.top}}#C(e){let t=this.#n.getBoundingClientRect();return{x:e.clientX-t.left,y:e.clientY-t.top}}#b(){return Date.now()-this.#p<$t}#w(){this.#a!==null&&(clearTimeout(this.#a),this.#a=null)}#x(e){e.preventDefault();let t=e.deltaY;if(e.deltaMode===WheelEvent.DOM_DELTA_LINE?t*=16:e.deltaMode===WheelEvent.DOM_DELTA_PAGE&&(t*=this.#n.clientHeight),t===0)return;let n=this.#g(e);this.#s(n),this.#h(Math.exp(-t*vn),n)}#A(e){if(this.#b())return;this.#c=!0;let t=this.#g(e);if(this.#e){let n=P();He(n,t,this.#o),this.#i(n)}this.#s(t),z(this.#o,t)}#T(e){e.button!==0||this.#b()||(this.#c=!0,this.#e=!0,this.#r(this.#g(e),e.ctrlKey||e.shiftKey))}#z(e){if(e.button!==0||this.#b())return;let t=this.#e;this.#e=!1,this.#l(),t&&!this.#c&&this.#u?.()}#P(e){if(this.#p=Date.now(),e.preventDefault(),e.touches.length>=2){this.#w(),this.#e=!1,this.#m=ge(this.#C(e.touches[0]),this.#C(e.touches[1]));return}if(e.touches.length!==1)return;let t=this.#C(e.touches[0]);z(this.#f,t),z(this.#t,t),this.#y=!1,this.#m=0,this.#w();let n=t.x,i=t.y;this.#a=setTimeout(()=>{this.#a=null,this.#y=!0,this.#e=!1,this.#l(),this.#d({x:n,y:i}),b()},xn),this.#e=!0,this.#s(t),this.#r(t,!1)}#D(e){if(this.#p=Date.now(),e.preventDefault(),e.touches.length>=2){this.#w(),this.#e=!1;let n=this.#C(e.touches[0]),i=this.#C(e.touches[1]),o=ge(n,i),s={x:(n.x+i.x)/2,y:(n.y+i.y)/2};this.#m>0&&(this.#s(s),this.#h(o/this.#m,s)),this.#m=o;return}if(e.touches.length!==1)return;let t=this.#C(e.touches[0]);this.#a!==null&&ge(t,this.#f)>wn&&this.#w(),this.#s(t),this.#e&&!this.#y&&this.#i({x:t.x-this.#t.x,y:t.y-this.#t.y}),z(this.#t,t)}#k(e){if(this.#p=Date.now(),this.#w(),e.touches.length>=1){this.#m=0;return}this.#m=0,this.#e=!1,this.#y||this.#l(),this.#y=!1}};function Pt(r){return typeof r=="number"?{Bottom:r,Right:r,Top:r,Left:r}:{Bottom:r?.Bottom===void 0?0:r?.Bottom,Right:r?.Right===void 0?0:r?.Right,Left:r?.Left===void 0?0:r?.Left,Top:r?.Top===void 0?0:r?.Top}}var ye=class{#e;#t;#n;#o;#i;#s;#r;#l;#d;#h;constructor(e){this.#e=Pt(e?.Margin),this.#t=Pt(e?.Padding),this.#o=e?.BackgroundColor,this.#n={Color:e?.Border?.Color??"black",Thickness:e?.Border?.Thickness??0,Radius:e?.Border?.Radius??0},this.#i=e?.MinWidth,this.#s=e?.MaxWidth,this.#r=e?.MinHeight,this.#l=e?.MaxHeight,this.#d=e?.Grow,this.#h=e?.Display??"flex"}setBackgroundColor(e){this.#o=e}render(e,t,n,i){if(this.#h==="none")return;let o={x:0,y:0};this.size(e,o),o.x=o.x*n,o.y=o.y*n,o.x=Math.max(o.x,i.x),o.y=Math.max(o.y,i.y),this.#o&&(e.fillStyle=this.#o,e.beginPath(),e.roundRect(t.x+this.#e.Left*n,t.y+this.#e.Right*n,o.x-(this.#e.Left+this.#e.Right)*n,o.y-(this.#e.Top+this.#e.Bottom)*n,this.#n.Radius*n),e.fill()),this.#n.Thickness>0&&(e.lineWidth=this.#n.Thickness*n,e.strokeStyle=this.#n.Color,e.stroke());let s={x:t.x+this.#f()*n,y:t.y+this.#a()*n},l={x:o.x-this.#u()*n,y:o.y-this.#c()*n};this.doRender(e,s,n,l)}maxLimitations(e){e.x=-1,e.y=-1,this.#s&&(e.x=this.#s),this.#l&&(e.y=this.#l)}setDisplay(e){this.#h=e}getDisplay(){return this.#h}size(e,t){if(t.x=0,t.y=0,this.#h==="none")return;let n={x:-1,y:-1};this.maxLimitations(n),this.calcSize(e,t,n),t.x+=this.#u(),t.y+=this.#c(),this.#i&&(t.x=Math.max(t.x,this.#i)),this.#s&&(t.x=Math.min(this.#s,t.x)),this.#l&&(t.y=Math.min(this.#l,t.y)),this.#r&&(t.y=Math.max(this.#r,t.y))}#u(){return this.#n.Thickness+this.#e.Left+this.#e.Right+this.#t.Left+this.#t.Right}#c(){return this.#n.Thickness+this.#e.Top+this.#e.Bottom+this.#t.Top+this.#t.Bottom}#a(){return this.#n.Thickness/2+this.#e.Top+this.#t.Top}#f(){return this.#n.Thickness/2+this.#e.Left+this.#t.Left}};var ie=class extends ye{#e;#t;#n;constructor(e,t){super(t),this.#e=e,this.#t="column",this.#n="stretch"}calcSize(e,t,n){t.x=0,t.y=0;let i={x:0,y:0};switch(this.#t){case"column":for(let o=0;o<this.#e.length;o++)this.#e[o].size(e,i),t.x=Math.max(t.x,i.x),t.y+=i.y;break;case"row":for(let o=0;o<this.#e.length;o++)this.#e[o].size(e,i),t.y=Math.max(t.y,i.y),t.x+=i.x;break;default:throw new Error("unknown layout: "+this.#t)}}doRender(e,t,n,i){switch(this.#t){case"column":this.#o(e,t,n,i);break;default:throw new Error("unimplemented layout direction: "+this.#t)}}#o(e,t,n,i){let o={x:t.x,y:t.y},s={x:0,y:0};for(let l=0;l<this.#e.length;l++){let h=this.#e[l];switch(h.size(e,s),Y(s,n),this.#n){case"stretch":o.x=t.x,s.x=i.x;break;case"start":o.x=t.x;break;case"end":o.x=i.x-s.x;break;case"center":o.x=i.x-s.x/2;break;default:throw new Error("unimplmeneted alignment: "+this.#n)}h.render(e,o,n,s),o.y+=s.y}}};var _=class extends ye{#e;#t;#n;#o;constructor(e,t){super(t),this.#e=e,this.#t=t?.Align??"left",this.#n=t?.VerticalAlign??"top",this.#o=t?.LineHeight??1}doRender(e,t,n,i){let o=P();this.calcSize(e,o,i),Y(o,n);let s=P();switch(z(s,t),e.textAlign="left",e.textBaseline="top",this.#t){case"left":break;case"right":s.x+=i.x-o.x;break;case"center":s.x+=(i.x-o.x)/2;break;default:throw new Error("unimplemented justification: "+this.#t)}switch(this.#n){case"top":break;case"bottom":s.y+=i.y-o.y;break;case"center":s.y+=(i.y-o.y)/2;break;default:throw new Error("unimplemented justification: "+this.#t)}if(i.x<=0)this.#e.render(e,n,s);else{let l=this.#e.breakIntoLines(e,i.x),h={x:0,y:0};for(let d=0;d<l.length;d++)l[d].render(e,n,s),l[d].size(e,1,h),s.y+=this.#e.style().getSize()*this.#o}}calcSize(e,t,n){if(n.x<=0){this.#e.size(e,1,t);return}let i=this.#e.breakIntoLines(e,n.x),o={x:0,y:0};t.x=0,t.y=this.#e.style().getSize()*i.length*this.#o;for(let s=0;s<i.length;s++)i[s].size(e,1,o),t.x=Math.max(o.x,t.x)}};var Nt=({max:r,getValue:e,match:t})=>{let n=0;for(;n<=r;){let i=Math.floor((n+r)/2),o=e(i);if(o===t)return i;o<t?n=i+1:r=i-1}return r};function Ce(r,e,t){let n=r.measureText(e).width,i="\u2026",o=r.measureText(i).width;if(n<=t||n<=o)return e;let s=Nt({max:e.length,getValue:l=>r.measureText(e.substring(0,l)).width,match:t-o});return e.substring(0,s)+i}function jt(r,e,t){if(r.measureText(e).width<=t)return[e];let i=Nt({max:e.length,getValue:o=>r.measureText(e.substring(0,o)).width,match:t});for(let o=i-1;o>=1;o--)if(e.charAt(o)===" "){i=o+1;break}return[e.substring(0,i),e.substring(i)]}function ke(r,e,t){if(r.measureText(e).width<=t)return[e];let i=new Array,o=e;for(;o!=="";){let s=Nt({max:o.length,getValue:l=>r.measureText(o.substring(0,l)).width,match:t});if(s===o.length){i.push(o.substring(0,s));break}for(let l=s-1;l>=1;l--)if(o.charAt(l)===" "){s=l+1;break}i.push(o.substring(0,s)),o=o.substring(s)}return i}var k=class{#e;#t=-1;#n;#o;#i;#s;#r;#l;constructor(e,t,n){this.#i=e,this.#e=!1,this.#n=P(),this.#o=new j(t),this.#s=n?.MaxWidth?n?.MaxWidth:-1,this.#r=n?.LineSpacing?n?.LineSpacing:5,this.#l=[e],typeof document<"u"&&document.fonts!==void 0&&(document.fonts.check(`16px "${this.#o.getFont()}"`)||document.fonts.addEventListener("loadingdone",()=>{this.#e=!1,b()}))}set(e){this.#i=e,this.#e=!1}get(){return this.#i}breakIntoLines(e,t){let n=new Array;this.#o.setupStyle(e,1);let i=ke(e,this.#i,t);if(i.length===1)return[this];for(let o=0;o<i.length;o++){let s=new k(i[o]);s.#o=this.#o,n.push(s)}return n}split(e){let t=this.#i.split(e),n=new Array;for(let i=0;i<t.length;i++){let o=new k(t[i]);o.#o=this.#o,n.push(o)}return n}splitAtIndex(e){let t=[new k(this.#i.substring(0,e)),new k(this.#i.substring(e,0))];for(let n=0;n<t.length;n++)t[n].#o=this.#o;return t}splitAtWidth(e,t){this.#o.setupStyle(e,1);let n=jt(e,this.#i,t);if(n.length===1)return[this];let i=new Array;for(let o=0;o<n.length;o++){let s=new k(n[o]);s.#o=this.#o,i.push(s)}return i}#d(e){if(!(this.#e&&this.#t===D())){if(this.#t=D(),this.#o.setupStyle(e,1),this.#s==-1){let t=e.measureText(this.#i);this.#n.x=t.width,this.#n.y=t.actualBoundingBoxAscent+t.actualBoundingBoxDescent,this.#l=[this.#i],this.#e=!0;return}this.#l=ke(e,this.#i,this.#s),this.#n.x=0,this.#n.y=0;for(let t=0;t<this.#l.length;t++){let n=e.measureText(this.#l[t]);this.#n.x=Math.max(this.#n.x,n.width)}this.#n.y+=(this.#l.length-1)*this.#r+this.#o.getSize()*this.#l.length,this.#e=!0}}size(e,t,n){this.#d(e),z(n,this.#n),Y(n,t)}height(e){return this.#d(e),this.#n.y}setColor(e){this.#o.setColor(e)}getColor(){return this.#o.getColor()}setSize(e){this.#o.setSize(e)}setWeight(e){this.#o.setWeight(e)}render(e,t,n){this.#d(e),this.#o.setupStyle(e,t);let i=0;for(let o=0;o<this.#l.length;o++)e.fillText(this.#l[o],n.x,n.y+i),i+=(this.#o.getSize()+this.#r)*t}style(){return this.#o}};function Te(r,e,t){return Math.min(Math.max(r,e),t)}function G(r){return Te(r,0,1)}function kt(r){var e=r.toString(16);return e.length==1?"0"+e:e}function Kt(r){return"#"+kt(Math.round(r.r*255))+kt(Math.round(r.g*255))+kt(Math.round(r.b*255))}function Xt(r){var e=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})(?:[a-f\d]{2})?$/i.exec(r);return e?{r:parseInt(e[1],16)/255,g:parseInt(e[2],16)/255,b:parseInt(e[3],16)/255}:null}function Yt(r,e){if(r.s<=0){e.r=r.v,e.g=r.v,e.b=r.v;return}let t=r.h;t>=360&&(t=0),t/=60;let n=Math.round(t),i=t-n,o=r.v*(1-r.s),s=r.v*(1-r.s*i),l=r.v*(1-r.s*(1-i));switch(n){case 0:e.r=r.v,e.g=l,e.b=o;break;case 1:e.r=s,e.g=r.v,e.b=o;break;case 2:e.r=o,e.g=r.v,e.b=l;break;case 3:e.r=o,e.g=s,e.b=r.v;break;case 4:e.r=l,e.g=o,e.b=r.v;break;default:e.r=r.v,e.g=o,e.b=s;break}e.r=G(e.r),e.g=G(e.g),e.b=G(e.b)}var Be=(n=>(n.Input="INPUT",n.Output="OUTPUT",n.InputArray="INPUTARRAY",n))(Be||{});function Nn(r,e){return!r||!e?!1:Tt(r.acceptedTypes(),e.acceptedTypes())}function Tt(r,e){return r.length===0||e.length===0?!0:r.some(t=>e.includes(t))}function oe(r,e,t){return!r||!e?!1:Ae(r.acceptedTypes(),e.acceptedTypes(),t)}function Ae(r,e,t){return Tt(r,e)?!0:(t??[]).some(n=>r.includes(n.from)&&e.includes(n.to))}function Ue(r){return r.anyType===!0?[]:r.acceptedTypes!==void 0&&r.acceptedTypes.length>0?r.acceptedTypes:[r.type===void 0?"":r.type]}var Mt=12;function Zt(r,e,t){if(e===0)return 0;let n=Math.round((t-r.Position.y)/(r.Size.y/e));return Math.min(e,Math.max(0,n))}function kn(r,e,t){let n=Math.max(1,e);return{x:r.Position.x+r.Size.x/2,y:r.Position.y+(t+.5)*r.Size.y/n}}function Me(r,e){let t=0;for(var n=0;n<r.length;n++)t+=r.charCodeAt(n)*(n+1);let i=24;t=Math.round(t)%i;let o={h:t/(i-1)*360,s:e,v:1},s={r:0,g:0,b:0};return Yt(o,s),Kt(s)}function Tn(r){return Me(r,1)}var be=class{#e;#t;#n;#o;#i;#s;#r;#l;#d;#h;#u;#c;#a;#f;#y;#m;#p;#g=null;constructor(e,t,n){this.#e=e,this.#i=new Array,this.#s=t,this.#t=n?.name===void 0?"Port":n?.name,this.#r=n?.type===void 0?"":n?.type,this.#l=n?.anyType===!0,this.#d=n?.acceptedTypes===void 0?[]:n.acceptedTypes,this.#h=n?.description===void 0?"":n.description,this.#u=n?.array===!0,this.#c=n?.hidden===!0,this.#a=n?.emptyStyle?.fillColor,this.#f=n?.filledStyle?.fillColor,this.#n={borderColor:n?.emptyStyle?.borderColor===void 0?"#1c1c1c":n.emptyStyle?.borderColor,fillColor:this.#a===void 0?Me(this.#r,.3):this.#a,borderSize:n?.emptyStyle?.borderSize===void 0?1:n.emptyStyle?.borderSize,size:n?.emptyStyle?.size===void 0?4:n.emptyStyle?.size},this.#o={borderColor:n?.filledStyle?.borderColor===void 0?"#1c1c1c":n.filledStyle?.borderColor,fillColor:this.#f===void 0?Me(this.#r,1):this.#f,borderSize:n?.filledStyle?.borderSize===void 0?1:n.filledStyle?.borderSize,size:n?.filledStyle?.size===void 0?5:n.filledStyle?.size},this.#m=new Array,n?.onConnectionAdded&&this.#m.push(n?.onConnectionAdded),this.#p=new Array,n?.onConnectionRemoved&&this.#p.push(n?.onConnectionRemoved),this.#y=this.#C()}#C(){let e=new Array,t=this.#r;return this.#d.length>1&&(t=this.#d.join(" or ")),t===""&&this.#l&&(t="any"),this.#u&&(t="Array<"+t+">"),e.push(new _(new k(t,{color:"white"}),{Align:"center"})),this.#h!==""&&e.push(new _(new k(this.#h,{color:"white",style:"italic"}),{Align:"center",Padding:{Top:16},MaxWidth:400,LineHeight:1.5})),new ie(e,{BackgroundColor:"rgba(0, 0, 0, 0.85)",Border:{Radius:6},Padding:13})}#b(){this.#a===void 0&&(this.#n.fillColor=Me(this.#r,.3)),this.#f===void 0&&(this.#o.fillColor=Me(this.#r,1)),this.#y=this.#C(),b()}setDataType(e){this.#r!==e&&(this.#r=e,this.#b())}setAnyType(e){this.#l!==e&&(this.#l=e,this.#b())}settleOn(e){this.#d=[e],this.setDataType(e),this.#b()}addConnection(e,t){let n=t===void 0?this.#i.length:Math.min(Math.max(t,0),this.#i.length),i=this.hidden();this.#i.splice(n,0,e),this.#w(i);for(let o=0;o<this.#m.length;o++)this.#m[o](e,n,this,this.#s,this.#e)}replaceConnection(e,t){let n=this.#i.length;this.#i[t]=e;for(let i=0;i<this.#m.length;i++)this.#m[i](e,n,this,this.#s,this.#e)}addConnectionAddedListener(e){e!==void 0&&this.#m.push(e)}connections(){return this.#i}slots(){return this.#s!=="INPUTARRAY"?1:Math.max(1,this.#i.length)}setHidden(e){let t=this.hidden();this.#c=e,this.#w(t)}#w(e){(e!==this.hidden()||this.#s==="INPUTARRAY"||this.#g!==null)&&this.#e?.invalidateLayout()}setWidget(e){this.#g=e,this.#e?.invalidateLayout()}widget(){return this.#g}widgetShown(){return this.#g!==null&&this.#s!=="OUTPUT"&&this.#i.length===0&&!this.hidden()&&!(this.#g.Hidden?.()??!1)}hidden(){return this.tucked()&&!(this.#e?.hiddenPortsShown()??!1)}tucked(){return this.#c&&this.#i.length===0}addConnectionRemovedListener(e){e!==void 0&&this.#p.push(e)}clearConnection(e){let t=this.#i.indexOf(e);if(t>-1){let n=this.hidden();this.#i.splice(t,1),this.#w(n);for(let i=0;i<this.#p.length;i++)this.#p[i](e,t,this,this.#s,this.#e)}else console.error("no connection found to remove")}getDataType(){return this.#r}acceptsAnyType(){return this.#l}acceptedTypes(){return this.#l?[]:this.#d.length>0?this.#d:[this.#r]}setAcceptedTypes(e){this.#d=e}getPortType(){return this.#s}getDisplayName(){return this.#t}filledStyleColor(){return this.#o.fillColor===void 0?(console.error("There's no fill color!!!!!!!!!"),"black"):this.#o.fillColor}#x={Position:{x:0,y:0},Size:{x:0,y:0}};render(e,t,n,i,o){let s=this.#n;this.#i.length>0&&(s=this.#o);let l=s.size*n.zoom;if(i&&T(this.#x,i)){l*=1.25;let a=t.x,u=t.y;o.queue(()=>{let f={x:0,y:0};this.#y.calcSize(e,f,{x:-1,y:-1}),this.#y.render(e,{x:a-f.x/2,y:u},1,f)})}let h=this.slots(),d=h===1?l*2:h*Mt*n.zoom;if(this.#x.Position.x=t.x-l,this.#x.Position.y=t.y-d/2,this.#x.Size.x=l*2,this.#x.Size.y=d,e.strokeStyle=s.borderColor,e.fillStyle=s.fillColor,e.beginPath(),this.#s==="INPUTARRAY"?e.roundRect(this.#x.Position.x,this.#x.Position.y,this.#x.Size.x,this.#x.Size.y,h===1?0:l):e.arc(t.x,t.y,l,0,2*Math.PI),e.fill(),e.stroke(),h>1){e.fillStyle=s.borderColor;for(let a=0;a<h;a++){let u=kn(this.#x,h,a);e.beginPath(),e.arc(u.x,u.y,l*.4,0,2*Math.PI),e.fill()}}return this.#x}};var U=(y=>(y.Default="default",y.Pointer="pointer",y.Grab="grab",y.Grabbing="grabbing",y.Wait="wait",y.Help="help",y.Crosshair="crosshair",y.Cell="cell",y.Text="text",y.Move="move",y.NotAllowed="not-allowed",y.ZoomIn="zoom-in",y.ZoomOut="zoom-out",y.None="none",y.ContextMenu="context-menu",y.EWResize="ew-resize",y))(U||{});var _e=new Set;function Qt(r,e){_e.forEach(t=>{t.canvas===r&&(t.placed=!1)}),e(),_e.forEach(t=>{t.canvas===r&&!t.placed&&(t.input.style.opacity="0",t.input.style.pointerEvents="none")})}function Bt(r){let e=r.canvas;if(e===null)return null;let t=document.createElement("input");t.type="text",t.value=r.value;let n={canvas:e,input:t,placed:!0},i=(l,h)=>{let d=e.getBoundingClientRect(),a=e.width>0?d.width/e.width:1,u=e.height>0?d.height/e.height:1,f=d.left+l.Position.x*a,g=d.top+l.Position.y*u,v=l.Size.x*a,p=l.Size.y*u,y=[Math.max(0,d.top-g),Math.max(0,f+v-(d.left+d.width)),Math.max(0,g+p-(d.top+d.height)),Math.max(0,d.left-f)];n.placed=!0,t.style.cssText=["position: fixed",`left: ${f}px`,`top: ${g}px`,`width: ${v}px`,`height: ${p}px`,`clip-path: inset(${y.map(m=>`${m}px`).join(" ")})`,"box-sizing: border-box","margin: 0",`padding: 0 ${c.Widget.Padding*h}px`,`font: ${c.Widget.FontSize*h*u}px ${c.FontFamily}`,`color: ${c.Widget.FontColor}`,`background: ${c.Widget.Hover.BackgroundColor}`,`border: ${c.Widget.Border.Size*h}px solid ${c.Widget.Border.Color}`,`border-radius: ${c.Widget.Border.Radius*h}px`,"outline: none","z-index: 1000"].join(";")};i(r.box,r.scale);let o=!1,s=l=>{o||(o=!0,_e.delete(n),t.remove(),l&&r.onCommit(t.value),b())};return t.addEventListener("keydown",l=>{l.stopPropagation(),l.key==="Enter"?(l.preventDefault(),s(!0)):l.key==="Escape"&&(l.preventDefault(),s(!1))}),t.addEventListener("blur",()=>s(!0)),_e.add(n),document.body.appendChild(t),t.focus(),t.select(),{input:t,place:i}}var qe=150,$e=25,I=class{#e=!1;#t=!1;#n=!1;#o=!1;#i={Position:{x:0,y:0},Size:{x:0,y:0}};#s=null;#r=1;#l=null;Draw(e,t,n,i){this.#i={Position:{x:t.Position.x,y:t.Position.y},Size:{x:t.Size.x,y:t.Size.y}},this.#s=e.canvas??null,this.#r=n,this.#n=!this.#t&&i!==void 0&&T(t,i),this.#l!==null&&(this.#l.input.isConnected?this.#l.place(this.#i,n):this.#l=null),e.save(),this.#t&&(e.globalAlpha*=.4),this.render(e,t,n),e.restore()}PointerDown(e){this.#t||(this.#o=!0,this.onPointerDown(e),b())}PointerMove(e){!this.#o||(this.onPointerMove(e),b())}PointerUp(e){!this.#o||(this.#o=!1,this.onPointerUp(e),e.inside&&this.onClick(e),b())}Cursor(){return"pointer"}Hidden(){return this.#e}setHidden(e){this.#e=e,b()}Disabled(){return this.#t}setDisabled(e){this.#t=e,e&&(this.#o=!1),b()}hovered(){return this.#n}pressed(){return this.#o}box(){return this.#i}canvas(){return this.#s}scale(){return this.#r}editText(e,t){this.#l=Bt({canvas:this.#s,box:this.#i,scale:this.#r,value:e,onCommit:t})}onPointerDown(e){}onPointerMove(e){}onPointerUp(e){}onClick(e){}};function Jt(r,e,t,n){if(t!==void 0)return t;if(e!=null){let i=r.getProperty(e);if(i!=null)return i}return n}var je=class extends I{constructor(t){super();this.owner=t}Size(){return{x:150,y:16}}render(t,n,i){let o=this.owner.hiddenPortsShown()?"\u25B4 less":`\u25BE ${this.owner.hiddenPortCount()} more`,s=n.Position.y+n.Size.y/2,l=n.Position.x+n.Size.x/2;t.font=`${11*i}px ${c.FontFamily}`;let h=t.measureText(o).width/2+6*i;t.globalAlpha=this.hovered()?1:.5,t.strokeStyle=c.Widget.FontColor,t.fillStyle=c.Widget.FontColor,t.lineWidth=Math.max(1,i),t.beginPath(),t.moveTo(n.Position.x,s),t.lineTo(l-h,s),t.moveTo(l+h,s),t.lineTo(n.Position.x+n.Size.x,s),t.stroke(),t.textAlign="center",t.textBaseline="middle",t.fillText(o,l,s)}onClick(){this.owner.setHiddenPortsShown(!this.owner.hiddenPortsShown())}};function en(r,e){return{color:r?.color===void 0?e?.color:r?.color,size:r?.size===void 0?e?.size:r?.size}}var ze=class{#e;#t;constructor(e){this.#e=e?.size===void 0?.5:e.size,this.#t=e?.color===void 0?"black":e.color}setupStyle(e,t){e.strokeStyle=this.#t,e.lineWidth=t*this.#e}setColor(e){this.#t=e}setSize(e){this.#e=e}size(){return this.#e}};function tn(r,e){return{radius:r?.radius===void 0?e?.radius:r?.radius,color:r?.color===void 0?e?.color:r?.color,border:en(r?.border,e?.border)}}var Q=class{#e;#t;#n;constructor(e){this.#t=e?.color===void 0?"#CCCCCC":e.color,this.#e=e?.border===void 0?null:new ze(e.border),this.#n=e?.radius===void 0?2:e.radius}#o(e,t,n,i){e.fillStyle=this.#t,this.#e?.setupStyle(e,n),e.beginPath(),e.roundRect(t.Position.x,t.Position.y,t.Size.x,t.Size.y,i),e.fill()}#i(e,t,n,i){this.#o(e,t,n,i),e.stroke()}Outline(e,t,n,i){this.#e?.setupStyle(e,n),e.beginPath(),e.roundRect(t.Position.x,t.Position.y,t.Size.x,t.Size.y,i),e.stroke()}Draw(e,t,n){this.#i(e,t,n,this.#n*n)}DrawRoundedTopOnly(e,t,n){this.#i(e,t,n,[this.#n*n*2,this.#n*n*2,0,0])}DrawUnderline(e,t,n){this.#o(e,t,n,[this.#n*n*2,this.#n*n*2,0,0]),e.beginPath(),e.moveTo(t.Position.x,t.Position.y+t.Size.y),e.lineTo(t.Position.x+t.Size.x,t.Position.y+t.Size.y),e.stroke()}borderSize(){return this.#e===null?0:this.#e.size()}radius(){return this.#n}setColor(e){this.#t=e}setBorderColor(e){this.#e===null?this.#e=new ze({color:e}):this.#e.setColor(e)}};function Ke(r,e,t,n,i){let o=Math.max(1,2*t),s=o/2,l=e.Position.x+s,h=e.Position.y+s,d=e.Position.x+e.Size.x-s,a=e.Position.y+e.Size.y-s;r.save(),r.lineWidth=o,r.lineCap="square",r.strokeStyle=i?n.Dark:n.Light,r.beginPath(),r.moveTo(l,a),r.lineTo(l,h),r.lineTo(d,h),r.stroke(),r.strokeStyle=i?n.Light:n.Dark,r.beginPath(),r.moveTo(d,h),r.lineTo(d,a),r.lineTo(l,a),r.stroke(),r.restore()}function Xe(r){return`${c.Widget.FontSize*r}px ${c.FontFamily}`}function Mn(r){return r.background!==void 0?r.background:r.input?r.hovered?c.Widget.Input.HoverBackgroundColor:c.Widget.Input.BackgroundColor:r.pressed?c.Widget.Button.Click.BackgroundColor:r.hovered?c.Widget.Hover.BackgroundColor:c.Widget.BackgroundColor}function xe(r,e,t,n){r.fillStyle=Mn(n),r.beginPath(),r.roundRect(e.Position.x,e.Position.y,e.Size.x,e.Size.y,c.Widget.Border.Radius*t),r.fill(),c.Widget.Border.Size>0&&(r.strokeStyle=n.border??c.Widget.Border.Color,r.lineWidth=c.Widget.Border.Size*t,r.stroke()),c.Widget.Bevel!==null&&Ke(r,e,t,c.Widget.Bevel,n.input===!0||n.pressed===!0)}function K(r,e,t,n){xe(r,e,t,n),Ye(r,e,t,n)}function Ye(r,e,t,n){let i=c.Widget.Padding*t,o=e.Position.y+e.Size.y/2,s=n.textColor??(n.input?c.Widget.Input.FontColor:c.Widget.FontColor);if(r.font=Xe(t),r.textBaseline="middle",n.label===void 0||n.label===""){r.textAlign="center",r.fillStyle=s,r.fillText(Ce(r,n.value,e.Size.x-i*2),e.Position.x+e.Size.x/2,o);return}let l=e.Size.x-i*2,h=Ce(r,n.label,l/2),d=r.measureText(h).width;r.textAlign="left",r.fillStyle=n.textColor??c.Widget.LabelColor,r.fillText(h,e.Position.x+i,o),r.textAlign="right",r.fillStyle=s,r.fillText(Ce(r,n.value,l-d-i),e.Position.x+e.Size.x-i,o)}var H=class extends I{#e;#t;#n;#o;#i;#s;#r;constructor(e,t,n){super(),this.#e=e,this.#t=t?.property,this.#o=t?.label??"",this.#i=t?.width??qe,this.#n=Jt(e,this.#t,t?.value,n),this.#s=t?.callback,this.#r=t?.onInput,this.#t!==void 0&&(e.setProperty(this.#t,this.#n),e.addPropertyChangeListener(this.#t,(i,o)=>this.setValue(o)))}Size(){return{x:this.#i,y:$e}}value(){return this.#n}setValue(e){this.equal(e,this.#n)||(this.#n=e,this.valueChanged(),this.#t!==void 0&&this.#e.setProperty(this.#t,e),b())}label(){return this.#o}setLabel(e){this.#o=e,b()}node(){return this.#e}input(e){this.setValue(e),this.#r?.(e)}commit(e,t){this.setValue(e),!this.equal(e,t)&&(this.#t!==void 0&&this.#e.editProperty(this.#t,e),this.#s?.(e))}valueChanged(){}equal(e,t){return Object.is(e,t)}};var Bn=3,re=class extends H{#e;#t;#n;#o;#i=0;#s=0;#r=!1;#l=!1;constructor(e,t){super(e,t,0),this.#e=t?.step,this.#t=t?.integer===!0,this.#n=t?.min??-1/0,this.#o=t?.max??1/0}Cursor(){return"ew-resize"}render(e,t,n){K(e,t,n,{input:!0,hovered:this.hovered()||this.pressed(),label:this.label(),value:Ze(this.value())})}onPointerDown(e){this.#i=e.position.x,this.#s=this.value(),this.#r=!1,this.#l=!1}onPointerMove(e){let t=e.position.x-this.#i;!this.#r&&Math.abs(t)<Bn||(this.#r=!0,this.input(this.#h(this.#s+t*this.#d(this.#s))))}onPointerUp(){this.#l=this.#r,this.#r&&(this.#r=!1,this.commit(this.value(),this.#s))}onClick(){if(this.#l)return;let e=this.value();this.editText(String(e),t=>{let n=Number.parseFloat(t);Number.isFinite(n)&&this.commit(this.#h(n),e)})}#d(e){return this.#e!==void 0?this.#e:Math.max(Math.abs(e)*.01,this.#t?.1:.01)}#h(e){let t=this.#t?Math.round(e):e;return Math.min(this.#o,Math.max(this.#n,t))}};function Ze(r){return""+parseFloat(r.toPrecision(6))}var se=class extends I{#e;#t;#n;constructor(e){super(),this.#e=e?.text??"Button",this.#t=e?.callback,this.#n=e?.width??qe}Size(){return{x:this.#n,y:$e}}text(){return this.#e}setText(e){this.#e=e,b()}render(e,t,n){K(e,t,n,{hovered:this.hovered(),pressed:this.pressed(),value:this.#e})}onClick(){this.#t?.()}};function nn(r){let e=Xt(r);return e===null||(e.r+e.g+e.b)/3>.5?"black":"white"}var we=null;function An(){return(we===null||!we.isConnected)&&(we=document.createElement("input"),we.type="color",document.body.appendChild(we)),we}var le=class extends H{#e;constructor(e,t){super(e,t,"#000000"),this.#e=nn(this.value())}valueChanged(){this.#e=nn(this.value())}render(e,t,n){K(e,t,n,{input:!0,hovered:this.hovered(),label:this.label(),value:this.value(),background:this.value(),border:this.#e,textColor:this.#e})}onClick(){let e=this.canvas();if(e===null)return;let t=this.value(),n=t.slice(7),i=this.box(),o=e.getBoundingClientRect(),s=e.width>0?o.width/e.width:1,l=e.height>0?o.height/e.height:1,h=An();h.style.cssText=["position: fixed",`left: ${o.left+i.Position.x*s}px`,`top: ${o.top+i.Position.y*l}px`,`width: ${i.Size.x*s}px`,`height: ${i.Size.y*l}px`,"opacity: 0","pointer-events: none","border: 0","padding: 0"].join(";"),h.value=t.slice(0,7),h.oninput=()=>this.input(h.value+n),h.onchange=()=>this.commit(h.value+n,t),h.getBoundingClientRect(),h.click()}};var de=class extends H{#e;#t;#n;#o;#i=0;constructor(e,t){let n=t?.min??0,i=t?.max??1;super(e,{...t,value:t?.value===void 0?void 0:Te(t.value,n,i)},n),this.#e=n,this.#t=i,this.#n=t?.snapIncrement,this.#o=t?.fillColor}Cursor(){return"ew-resize"}setValue(e){super.setValue(Te(e,this.#e,this.#t))}render(e,t,n){xe(e,t,n,{input:!0,hovered:this.hovered()||this.pressed(),value:""});let i=c.Widget.Border.Size*n,o=G((this.value()-this.#e)/(this.#t-this.#e));e.fillStyle=this.#o??c.Widget.Slider.FillColor,e.beginPath(),e.roundRect(t.Position.x+i/2,t.Position.y+i/2,Math.max(0,t.Size.x*o-i),t.Size.y-i,c.Widget.Border.Radius*n),e.fill(),Ye(e,t,n,{input:!0,hovered:!1,label:this.label(),value:Ze(Number(this.value().toFixed(3)))})}onPointerDown(e){this.#i=this.value(),this.input(this.#s(e.position.x))}onPointerMove(e){this.input(this.#s(e.position.x))}onPointerUp(){this.commit(this.value(),this.#i)}#s(e){let t=this.box(),n=c.Widget.Border.Size*this.scale(),i=t.Position.x+n/2,o=i+t.Size.x-n,l=G((e-i)/(o-i))*(this.#t-this.#e)+this.#e;return this.#n!==void 0&&(l=Math.round(l/this.#n)*this.#n),Te(l,this.#e,this.#t)}};var he=class extends H{constructor(e,t){super(e,t,"")}Cursor(){return"text"}render(e,t,n){K(e,t,n,{input:!0,hovered:this.hovered(),label:this.label(),value:this.value()})}onClick(){let e=this.value();this.editText(e,t=>this.commit(t,e))}};var ae=class extends H{#e;#t;constructor(e,t){super(e,{...t,label:t?.label??"Toggle"},!1),this.#e=t?.onColor??"#00FF00",this.#t=t?.offColor??"#004400"}Toggle(){let e=this.value();this.commit(!e,e)}render(e,t,n){xe(e,t,n,{hovered:this.hovered(),value:""});let i=Math.min(t.Size.x,t.Size.y)*.6,o=(t.Size.y-i)/2,s=this.value();e.fillStyle=s?this.#e:this.#t,e.beginPath(),e.roundRect(t.Position.x+o,t.Position.y+o,i,i,c.Widget.Border.Radius*n),s&&(e.shadowBlur=15*n,e.shadowColor=this.#e),e.fill(),e.shadowBlur=0;let l=t.Position.x+o*2+i;e.font=Xe(n),e.textAlign="center",e.textBaseline="middle",e.fillStyle=c.Widget.FontColor;let h=t.Position.x+t.Size.x-l-o;e.fillText(Ce(e,this.label(),h),l+h/2,t.Position.y+t.Size.y/2)}onClick(){this.Toggle()}};var ue=class extends I{#e;#t;#n;#o;#i;constructor(e){super(),this.#o=e?.maxWidth===void 0?150:e?.maxWidth,this.#i=e?.maxHeight===void 0?150:e?.maxHeight,e?.image?this.SetUrl(e?.image):e?.blob&&this.SetBlob(e?.blob)}SetBlob(e){let t=URL.createObjectURL(e);this.SetUrl(t),this.#t=t}SetUrl(e){this.#t!==void 0&&(URL.revokeObjectURL(this.#t),this.#t=void 0),this.#n=void 0,this.#e=e;let t=document.createElement("img");t.src=e,t.onload=()=>{this.#e===e&&(this.#n=t,b())},t.onerror=n=>{console.log("error loading image:",e,n)}}Cursor(){return"default"}Size(){if(this.#n===void 0)return{x:0,y:0};let e=1;if(this.#n.width>this.#o&&(e=this.#o/this.#n.width),this.#n.height>this.#i){let t=this.#i/this.#n.height;t<e&&(e=t)}return{x:e*this.#n.width,y:e*this.#n.height}}render(e,t,n){if(!this.#n)return;let i=this.Size(),o=i.x*n,s=i.y*n;e.drawImage(this.#n,t.Position.x+(t.Size.x-o)/2,t.Position.y,o,s)}};var Re=class extends I{#e;#t;#n;#o=-1;#i(){if(this.#o===D())return;this.#o=D();let e=this.#e.style();e.setColor(this.#n?.color??c.Widget.FontColor),e.setSize(this.#n?.size??c.Note.FontSize)}constructor(e,t){super(),this.#t=P(),this.#n=t?.textBoxStyle,this.#e=new k("",te(t?.textBoxStyle,{})),this.#i(),this.setText(t?.value??"");let n=t?.property;if(n!==void 0){let i=e.getProperty(n);i!=null&&this.setText(String(i)),e.addPropertyChangeListener(n,(o,s)=>this.setText(String(s)))}}Cursor(){return"default"}Size(){return this.#t}text(){return this.#e.get()}setText(e){this.#e.get()!==e&&(this.#e.set(e),b())}render(e,t,n){this.#i(),this.#e.size(e,1,this.#t),e.textAlign="left",this.#e.render(e,n,t.Position)}};var We=class extends I{#e;#t;#n;#o=[];#i=null;#s=null;#r;constructor(e,t){super(),this.#e=e,this.#t=t?.grow??e.map(()=>1),this.#n=t?.gap??c.Widget.Gap}children(){return this.#e}Size(){let e=this.#h(),t=0,n=0;for(let i of e){let o=i.Size();t+=o.x,n=Math.max(n,o.y)}return t+=Math.max(0,e.length-1)*this.#n,{x:t,y:n}}Cursor(){return(this.#i??this.#d(this.#r))?.Cursor?.()??"default"}Draw(e,t,n,i){this.#r=i,super.Draw(e,t,n,i)}render(e,t,n){let i=this.#h(),o=this.#n*n,s=i.reduce((a,u)=>a+u.Size().x*n,0),l=Math.max(0,t.Size.x-s-o*Math.max(0,i.length-1)),h=i.reduce((a,u)=>a+this.#u(u),0);this.#o=this.#e.map(()=>null);let d=t.Position.x;for(let a of i){let u=a.Size(),f=h>0?l*(this.#u(a)/h):0,g={Position:{x:d,y:t.Position.y+(t.Size.y-u.y*n)/2},Size:{x:u.x*n+f,y:u.y*n}};this.#o[this.#e.indexOf(a)]=g,a.Draw(e,g,n,this.#i===null||this.#i===a?this.#r:void 0),d+=g.Size.x+o}}onPointerDown(e){let t=this.#d(e.position);t===null||t.Disabled?.()||(this.#i=t,this.#s=this.#o[this.#e.indexOf(t)],t.PointerDown?.(this.#l(e)))}onPointerMove(e){this.#i?.PointerMove?.(this.#l(e))}onPointerUp(e){let t=this.#i,n=this.#l(e);this.#i=null,this.#s=null,t?.PointerUp?.(n)}#l(e){return{position:e.position,inside:this.#s!==null&&T(this.#s,e.position)}}#d(e){if(e===void 0)return null;for(let t=0;t<this.#e.length;t++){let n=this.#o[t];if(n&&T(n,e))return this.#e[t]}return null}#h(){return this.#e.filter(e=>!e.Hidden?.())}#u(e){return this.#t[this.#e.indexOf(e)]??1}};var Qe=class{#e;constructor(){this.#e=new Map}register(e,t){this.#e.set(e,t)}create(e,t,n){let i=this.#e.get(t);if(i===void 0)throw new Error("no builder registered for widget: "+t);return i(e,n)}createFromConfig(e,t){return this.create(e,t.type,t.config)}},L=new Qe;L.register("button",(r,e)=>new se(e));L.register("number",(r,e)=>new re(r,e));L.register("color",(r,e)=>new le(r,e));L.register("slider",(r,e)=>new de(r,e));L.register("string",(r,e)=>new he(r,e));L.register("toggle",(r,e)=>new ae(r,e));L.register("image",(r,e)=>new ue(e));L.register("text",(r,e)=>new Re(r,e));L.register("row",(r,e)=>new We((e?.widgets??[]).map(t=>L.createFromConfig(r,t)),e));var zn=30,Rn=80;function Wn(r){let e=G(r);return e*e*(3-2*e)}function At(r,e,t,n){return i=>{let o="#00FF00";i.outPort!==null?o=i.outPort.filledStyleColor():i.inPort!==null&&(o=i.inPort.filledStyleColor());let s=r*i.graphScale;e!==void 0&&(o=e),(i.mouseOver||i.inNode?.selected()||i.outNode?.selected())&&(s=t*i.graphScale,i.ctx.shadowBlur=25*i.graphScale,n!==void 0&&(o=n),i.ctx.shadowColor=o),i.ctx.strokeStyle=o,i.ctx.lineWidth=s;let l=i.start.x,h=i.start.y,d=i.end.x,a=i.end.y,u=d-l,f=zn*i.graphScale,g=Rn*i.graphScale,v=u<=0?0:f*Wn(u/g),p=l-v,y=d+v;i.ctx.beginPath(),i.ctx.moveTo(l,h),v>0&&i.ctx.lineTo(p,h);let m=(p+y)/2;i.ctx.bezierCurveTo(m,h,m,a,y,a),v>0&&i.ctx.lineTo(d,a),i.ctx.stroke(),i.ctx.shadowBlur=0}}var ve=class{#e;#t;#n;#o;#i;#s;#r;constructor(e,t,n,i,o){this.#n=e,this.#o=t,this.#i=n,this.#s=i,this.#r=o,this.#e=P(),this.#t=P(),e!==null&&e.inputPort(this.#o).addConnection(this),n!==null&&n.outputPort(this.#s).addConnection(this)}render(e,t,n,i){if(!(this.#n===null&&this.#i===null)){if(this.#n!==null){let o=this.#l();if(o===void 0)return;wt(o,this.#e)}else if(i!==void 0)this.#e.x=i.x,this.#e.y=i.y;else return;if(this.#i!==null){let o=this.#i.outputPortPosition(this.#s);if(o===void 0)return;wt(o,this.#t)}else if(i!==void 0)this.#t.x=i.x,this.#t.y=i.y;else return;this.#r({ctx:e,start:this.#e,end:this.#t,graphScale:t,mouseOver:n,inPort:this.inPort(),inNode:this.#n,outPort:this.outPort(),outNode:this.#i})}}inNode(){return this.#n}outNode(){return this.#i}clearPort(e){if(this.#n!==null){let t=this.#n.inputPortPosition(this.#o);t!==void 0&&T(t,e)&&this.clearInput()}if(this.#i!==null){let t=this.#i.outputPortPosition(this.#s);t!==void 0&&T(t,e)&&this.clearOutput()}}clearPorts(){this.clearInput(),this.clearOutput()}setInput(e,t,n,i){this.#n=e,this.#o=t;let o=this.#n.inputPort(t);!!n&&o.connections().length>0?o.replaceConnection(this,0):o.addConnection(this,i)}setOutput(e,t){this.#i=e,this.#s=t,this.#i.outputPort(t).addConnection(this)}clearInput(){this.#n?.inputPort(this.#o).clearConnection(this),this.#n=null,this.#o=-1}clearOutput(){this.#i?.outputPort(this.#s).clearConnection(this),this.#i=null,this.#s=-1}#l(){if(this.#n===null)return;let e=this.#n.inputPortPosition(this.#o),t=this.#n.inputPort(this.#o),n=t.slots();if(e===void 0||n===1)return e;let i=t.connections().indexOf(this);if(i===-1)return e;let o=e.Size.y/n;return{Position:{x:e.Position.x,y:e.Position.y+i*o},Size:{x:e.Size.x,y:o}}}mouseOverPort(e){if(this.#n!==null){let t=this.#l();if(t!==void 0&&T(t,e))return this.#n.inputPort(this.#o)}if(this.#i!==null){let t=this.#i.outputPortPosition(this.#s);if(t!==void 0&&T(t,e))return this.#i.outputPort(this.#s)}return null}outPort(){return this.#i===null?null:this.#i.outputPort(this.#s)}inPort(){return this.#n===null?null:this.#n.inputPort(this.#o)}referencesNode(e){return this.#n===e||this.#i===e}};var X=class{zoom;position;constructor(){this.zoom=1,this.position=P()}screenSpaceToGraphSpace(e,t){let n=this.zoom;t.x=e.x/n-this.position.x/n,t.y=e.y/n-this.position.y/n}graphSpaceToScreenSpace(e,t){t.x=this.position.x+e.x*this.zoom,t.y=this.position.y+e.y*this.zoom}getOrientation(){return{position:{x:this.position.x,y:this.position.y},zoom:this.zoom}}setOrientation(e){this.position.x=e.position.x,this.position.y=e.position.y,this.zoom=e.zoom}reset(){this.zoom=1,this.position.x=0,this.position.y=0}};var Vn=100,Ve=50,Fn=25,Je=150,En=8,In=8;function Dn(r,e){let t=new Set,n=new Array;for(let i of r){if(t.has(i))continue;let o=[{node:i,expanded:!1}];for(;o.length>0;){let s=o[o.length-1];if(s.expanded){o.pop(),n.push(s.node);continue}if(s.expanded=!0,t.has(s.node)){o.pop();continue}t.add(s.node);for(let l of e.get(s.node)??[])t.has(l)||o.push({node:l,expanded:!1})}}return n}function sn(r,e){let t=new Map;for(let n of r)t.set(n,[]);for(let n of r)for(let i of e.get(n)??[]){let o=t.get(i);o!==void 0&&!o.includes(n)&&o.push(n)}return t}function Ln(r,e){let t=sn(r,e),n=Dn(r,t),i=new Set,o=new Map;for(let u of n){let f=0;for(let g of t.get(u)??[])i.has(g)&&(f=Math.max(f,o.get(g)+1));o.set(u,f),i.add(u)}let s=0;for(let u of o.values())s=Math.max(s,u);let l=new Map;for(let u of r)l.set(u,s-o.get(u));for(let u of r){let f=l.get(u);if((t.get(u)??[]).some(v=>l.get(v)>f))continue;let g=-1;for(let v of e.get(u)??[]){let p=l.get(v);p!==void 0&&p<f&&(g=Math.max(g,p+1))}g>=0&&l.set(u,g)}let h=[...new Set(l.values())].sort((u,f)=>u-f),d=new Map;h.forEach((u,f)=>d.set(u,f));let a=h.map(()=>new Array);for(let u of r){let f=d.get(l.get(u));l.set(u,f),a[f].push(u)}return{layers:a,layerOf:l}}function on(r,e){let t=new Map;for(let i of r.layers)i.forEach((o,s)=>t.set(o,s));let n=0;for(let i=0;i+1<r.layers.length;i++){let o=new Array;for(let s of r.layers[i])for(let l of e.get(s)??[])r.layerOf.get(l)===i+1&&o.push([t.get(s),t.get(l)]);for(let s=0;s<o.length;s++)for(let l=s+1;l<o.length;l++)(o[s][0]-o[l][0])*(o[s][1]-o[l][1])<0&&n++}return n}function Hn(r,e,t){let n=new Map;for(let h of r.layers)for(let d=0;d<h.length;d++)n.set(h[d],d);let i=(h,d,a)=>{let u=0,f=0;for(let g of d.get(h)??[])r.layerOf.get(g)===a&&(u+=n.get(g),f++);return f===0?-1:u/f},o=(h,d)=>{for(let a=0;a<r.layers.length;a++){let u=d>0?a:r.layers.length-1-a,f=u+d;if(f<0||f>=r.layers.length)continue;let g=r.layers[u],v=new Map;for(let p of g){let y=i(p,h,f);v.set(p,y===-1?n.get(p):y)}g.sort((p,y)=>v.get(p)-v.get(y));for(let p=0;p<g.length;p++)n.set(g[p],p)}},s=r.layers.map(h=>h.slice()),l=on(r,t);for(let h=0;h<En&&l>0;h++){o(e,-1),o(t,1);let d=on(r,t);d<l&&(l=d,s=r.layers.map(a=>a.slice()))}for(let h=0;h<s.length;h++)r.layers[h]=s[h]}function On(r,e,t){let n=new Map;r.forEach((s,l)=>n.set(s,l));let i=new Set,o=new Array;for(let s of r){if(i.has(s))continue;i.add(s);let l=new Array,h=[s];for(;h.length>0;){let d=h.pop();l.push(d);for(let a of[...e.get(d)??[],...t.get(d)??[]])n.has(a)&&!i.has(a)&&(i.add(a),h.push(a))}l.sort((d,a)=>n.get(d)-n.get(a)),o.push(l)}return o}function Gn(r,e){let t;for(let n of r){let i=e.get(n)??[];if(i.length>1)return;if(i.length===0){if(t!==void 0)return;t=n}}return t}function ln(r){let e=new Array,t=0;for(let n of r)e.push(t),t+=n+Vn;return e}function Un(r,e,t){let n=p=>[...new Set(e.get(p)??[])],i=new Map([[r,0]]),o=new Array,s=[r],l=0;for(;s.length>0;){let p=s.pop();o.push(p);let y=n(p);for(let m=y.length-1;m>=0;m--){let C=i.get(p)+1;i.set(y[m],C),l=Math.max(l,C),s.push(y[m])}}let h=new Array(l+1).fill(0);for(let[p,y]of i)h[l-y]=Math.max(h[l-y],t.get(p).x);let d=ln(h),a=new Map,u=new Map,f=new Map;for(let p=o.length-1;p>=0;p--){let y=o[p],m=t.get(y).y,C=n(y);if(C.length===0){a.set(y,m),u.set(y,0);continue}let x=0;for(let B of C)f.set(B,x),x+=a.get(B)+Ve;let w=B=>f.get(B)+u.get(B)+t.get(B).y/2,M=(w(C[0])+w(C[C.length-1]))/2-m/2,F=0;if(M<0){F=-M,M=0;for(let B of C)f.set(B,f.get(B)+F)}a.set(y,Math.max(x-Ve+F,M+m)),u.set(y,M)}let g=new Map,v=new Map([[r,0]]);for(let p of o){let y=l-i.get(p),m=t.get(p);g.set(p,{x:d[y]+(h[y]-m.x)/2,y:v.get(p)+u.get(p)});for(let C of n(p))v.set(C,v.get(p)+f.get(C))}return g}function _n(r){let e=new Array;for(let n of r)for(e.push({sum:n,count:1});e.length>1;){let i=e[e.length-1],o=e[e.length-2];if(o.sum/o.count<=i.sum/i.count)break;o.sum+=i.sum,o.count+=i.count,e.pop()}let t=new Array;for(let n of e)for(let i=0;i<n.count;i++)t.push(n.sum/n.count);return t}function qn(r){let e=r.slice().sort((n,i)=>n-i),t=Math.floor(e.length/2);return e.length%2===1?e[t]:(e[t-1]+e[t])/2}function $n(r,e,t,n){let i=Ln(r,e),o=new Map,s=new Map,l=new Map;for(let m of r)o.set(m,[...new Set(e.get(m)??[])]),s.set(m,[...new Set(t.get(m)??[])]),l.set(m,n.get(m).y);let h=-1;for(let m of r){let C=i.layerOf.get(m),x=s.get(m);for(let w=0;w<x.length;w++){let M=x[w],F=i.layerOf.get(M);if(F-C<2)continue;let B=m;for(let N=C+1;N<F;N++){let R=h--;i.layerOf.set(R,N),i.layers[N].push(R),l.set(R,0),o.set(R,[B]),s.set(R,[]),B===m?x[w]=R:s.get(B).push(R),B=R}s.get(B).push(M);let S=o.get(M);S[S.indexOf(m)]=B}}let d=new Map;for(let m of r){if(s.get(m).length>0)continue;let C=[m];for(;C.length>0;){let x=C.pop();if(d.has(x))continue;d.set(x,d.size);let w=o.get(x)??[];for(let M=w.length-1;M>=0;M--)C.push(w[M])}}for(let m of i.layers)m.sort((C,x)=>(d.get(C)??1/0)-(d.get(x)??1/0));Hn(i,o,s);let a=(m,C)=>m<0||C<0?Fn:Ve,u=new Map;for(let m of i.layers){let C=0;for(let x=0;x<m.length;x++)u.set(m[x],C),C+=l.get(m[x])+(x+1<m.length?a(m[x],m[x+1]):0);for(let x of m)u.set(x,u.get(x)-C/2)}let f=m=>u.get(m)+l.get(m)/2,g=(m,C,x)=>{let w=new Array,M=new Array,F=0;for(let S=0;S<m.length;S++){let N=m[S],R=(C.get(N)??[]).filter(ee=>i.layerOf.get(ee)===x).map(f),V=R.length>0?qn(R)-l.get(N)/2:u.get(N);w.push(F),M.push(V-F),S+1<m.length&&(F+=l.get(N)+a(N,m[S+1]))}let B=_n(M);for(let S=0;S<m.length;S++)u.set(m[S],B[S]+w[S])};for(let m=0;m<In;m++)if(m%2===0)for(let C=1;C<i.layers.length;C++)g(i.layers[C],o,C-1);else for(let C=i.layers.length-2;C>=0;C--)g(i.layers[C],s,C+1);let v=i.layers.map(m=>m.reduce((C,x)=>x<0?C:Math.max(C,n.get(x).x),0)),p=ln(v),y=new Map;for(let m of r){let C=i.layerOf.get(m);y.set(m,{x:p[C]+(v[C]-n.get(m).x)/2,y:u.get(m)})}return y}function jn(r,e){let t=Math.ceil(Math.sqrt(r.length)),n=new Array(t).fill(0),i=new Array(Math.ceil(r.length/t)).fill(0);r.forEach((a,u)=>{let f=e.get(a);n[u%t]=Math.max(n[u%t],f.x),i[Math.floor(u/t)]=Math.max(i[Math.floor(u/t)],f.y)});let o=new Array,s=0;for(let a of n)o.push(s),s+=a+Ve;let l=new Array,h=0;for(let a of i)l.push(h),h+=a+Ve;let d=new Map;return r.forEach((a,u)=>d.set(a,{x:o[u%t],y:l[Math.floor(u/t)]})),d}function rn(r,e){let t=1/0,n=1/0,i=-1/0,o=-1/0;for(let[l,h]of r){let d=e.get(l);t=Math.min(t,h.x),n=Math.min(n,h.y),i=Math.max(i,h.x+d.x),o=Math.max(o,h.y+d.y)}let s=new Map;for(let[l,h]of r)s.set(l,{x:h.x-t,y:h.y-n});return{positions:s,size:{x:i-t,y:o-n}}}function Kn(r,e,t,n){let i=new Array,o=new Array;for(let g of On(r,e,t)){if(g.length===1){o.push(g[0]);continue}let v=Gn(g,t),p=v!==void 0?Un(v,e,n):$n(g,e,t,n);i.push(rn(p,n))}i.sort((g,v)=>v.size.y-g.size.y||v.size.x-g.size.x),o.length>0&&i.push(rn(jn(o,n),n));let s=0,l=0;for(let g of i)s+=(g.size.x+Je)*(g.size.y+Je),l=Math.max(l,g.size.x);let h=Math.max(l,Math.sqrt(s)),d=new Map,a=0,u=0,f=0;for(let g of i){a>0&&a+g.size.x>h&&(a=0,u+=f+Je,f=0);for(let[v,p]of g.positions)d.set(v,{x:p.x+a,y:p.y+u});a+=g.size.x+Je,f=Math.max(f,g.size.y)}return d}function zt(r,e,t){let n=e.getNodes();if(n.length===0)return;let i=new Array;if(t)for(let p of t)p>=0&&p<n.length&&i.push(p);else for(let p=0;p<n.length;p++)i.push(p);if(i.length<2)return;let o=new Set(i),s=new Map;for(let p=0;p<n.length;p++)s.set(n[p],p);let l=new X,h=new Map;for(let p of i)h.set(p,n[p].calculateBounds(r,l).Size);let d=new Map;for(let p of i){let y=n[p],m=new Array;for(let C=0;C<y.inputs();C++)for(let x of y.inputPort(C).connections()){let w=x.outNode(),M=w===null?void 0:s.get(w);M!==void 0&&o.has(M)&&M!==p&&!m.includes(M)&&m.push(M)}d.set(p,m)}let a=sn(i,d),u=Kn(i,d,a,h),f={x:0,y:0};for(let p of i){let y=n[p].getPosition();f.x+=y.x,f.y+=y.y}f.x/=i.length,f.y/=i.length;let g=0,v=0;for(let[p,y]of u)g=Math.max(g,y.x+h.get(p).x),v=Math.max(v,y.y+h.get(p).y);for(let[p,y]of u)n[p].setPosition({x:f.x-g/2+y.x,y:f.y-v/2+y.y})}function q(r,e){let t=r+"_Start",n=r+"_End";performance.mark(t),e(),performance.mark(n),performance.measure(r,t,n)}function Xn(r,e){return e.needs==="INPUT"?(r.inputs??[]).some(t=>Ae(e.types,Ue(t),e.casts)):(r.outputs??[]).some(t=>Ae(Ue(t),e.types,e.casts))}var Fe=class{#e;#t;#n;#o;constructor(e){if(this.#e=e?.name===void 0?"Unknown":e.name,this.#t=e?.description===void 0?"":e.description,this.#n=e?.version===void 0?"v0.0.0":e.version,this.#o=new Map,e?.nodes!==void 0)for(let t in e.nodes)this.register(t,e.nodes[t])}nodes(){return this.#o}register(e,t){this.#o.set(e,t)}unregister(e){return this.#o.delete(e)}#i(e,t,n,i,o){let s=[],l=new Map;for(let[d,a]of n){let u=d.indexOf("/"),f=d.indexOf("[");if(u===-1||f!==-1&&f<u){if(o!==void 0&&!Xn(a,o))continue;s.push({name:d,callback:()=>{let g=new ce(a);g.setPosition(i),e.addNode(g),o?.onCreated?.(g)}})}else{let g=d.split("/");l.has(g[0])||l.set(g[0],new Map);let v=l.get(g[0]);g.shift(),v?.set(g.join("/"),a)}}let h=[];for(let[d,a]of l){let u=this.#i(e,d,a,i,o);o!==void 0&&u.items?.length===0&&u.subMenus?.length===0||h.push(u)}return{name:t,items:s,subMenus:h}}contextMenu(e,t,n){return this.#i(e,this.#e,this.#o,t,n)}create(e){let t=this.#o.get(e);if(t===void 0)throw new Error("no builder registered for node: "+e);return new ce(t)}};var Ee=class{#e;#t;constructor(e){if(this.#e=new Map,this.#t=new Array,e?.onNodeCreated&&this.#t.push(e?.onNodeCreated),e?.publishers!==void 0)for(let t in e.publishers)this.addPublisher(t,new Fe(e.publishers[t]))}addOnNodeCreatedListener(e){this.#t.push(e)}addPublisher(e,t){this.#e.set(e,t)}create(e,t){let n=this.#e.get(e);if(n===void 0)throw new Error("no publisher registered with identifier: "+e);let i=n.create(t);for(let o=0;o<this.#t.length;o++){let s=this.#t[o];s(e,t,i)}return i}newNodeSubmenus(e,t,n){let i=[];for(let[o,s]of this.#e){let l=s.contextMenu(e,t,n);n!==void 0&&l.items?.length===0&&l.subMenus?.length===0||i.push(l)}return i}openMenu(e,t,n){return{name:"New Node",group:E,subMenus:this.newNodeSubmenus(e,t,n)}}};var E="node-flow-graph-node-menu";function Yn(r){return r?.renderer!==void 0?r.renderer:At(r?.size===void 0?2:r.size,void 0,r?.mouseOverSize===void 0?4:r.mouseOverSize,void 0)}var et=class{#e;#t;#n;#o;#i;#s;#r;#l;#d;#h;#u=null;#c=null;#a=P();#f;#y;#m;#p;#g;#C;#b;#w;#x;#A;#T;#z=new Array;#P=null;constructor(e,t){this.#e=e,this.#t=[],this.#o=-1,this.#i=new W,this.#s=null,this.#l=null,this.#d=null,this.#h=null,this.#n=new Array,this.#y=new Ee(t?.nodes),this.#r=Yn(t?.idleConnection),this.#T=new Array,this.#A=new Array,this.#f="default",this.#m=!1,this.#p=P(),this.#g=P(),this.#C=new W,this.#w=null,this.#b=t?.casts??[]}setCasts(e){this.#b=e}casts(){return this.#b}addPublisher(e,t){this.#y.addPublisher(e,t)}addOnNodeCreatedListener(e){this.#y.addOnNodeCreatedListener(e)}nodeFactory(){return this.#y}addOnNodeAddedListener(e){e!=null&&this.#T.push(e)}addOnNodeRemovedListener(e){e!=null&&this.#A.push(e)}addNodeHoverListener(e){this.#z.push(e)}#D(e){if(this.#P!==e){this.#P=e;for(let t=0;t<this.#z.length;t++)this.#z[t](e)}}clickStart(e,t,n){if(this.#m=!1,this.#i.Clear(),this.#w!==null){this.#l=null,this.#d=null,this.#o=-1;for(let o=0;o<this.#t.length;o++){let s=this.#t[o].inBounds(this.#w,t,e);s.Node!==void 0&&s.PortIndex===void 0&&s.Widget===void 0&&(this.#o=o),s.Widget!==void 0&&(this.#d=s.Widget,this.#u=s.WidgetBox??null),s.Port!==void 0&&s.Node!==void 0&&s.PortIndex!==void 0&&s.PortIsInput!==void 0&&(this.#l={Index:s.PortIndex,Node:s.Node,Port:s.Port,InputPort:s.PortIsInput})}}let i=!1;if(this.#o>-1){this.#q(this.#o,!n);for(let o=0;o<this.#t.length;o++)this.#t[o].selected()&&this.#i.Push(o);i=!0}if(this.#d!==null&&(this.#d.Disabled?.()||(this.#h=this.#d,this.#c=this.#u===null?null:{Position:{x:this.#u.Position.x,y:this.#u.Position.y},Size:{x:this.#u.Size.x,y:this.#u.Size.y}},z(this.#a,e),this.#h.PointerDown?.(this.#k())),i=!0),this.#l===null)return n&&!i&&(t.screenSpaceToGraphSpace(e,this.#p),z(this.#g,this.#p),this.#m=!0),!i&&!n&&this.unselectAllNodes(),i||n;if(this.#l.InputPort){let o=this.#l.Port,s=o.connections(),l=s.find(h=>h.mouseOverPort(e)===o)??s[0];l!==void 0&&(l.clearInput(),this.#s=l)}else{let o=this.#l.Node,s=this.#l.Index,l=this.#l.Node,h=this.#l.Index;this.#l.InputPort?(l=null,h=-1):(o=null,s=-1);let d=new ve(o,s,l,h,this.#r);this.#s=d,this.#n.push(d)}return!0}#k(){return{position:{x:this.#a.x,y:this.#a.y},inside:this.#c!==null&&T(this.#c,this.#a)}}mouseDragEvent(e,t){if(this.#h!==null)return this.#a.x+=e.x,this.#a.y+=e.y,this.#h.PointerMove?.(this.#k()),!0;let n=!1;return A.run(()=>{let i=A.get();if(i.x=e.x/t,i.y=e.y/t,Ne(this.#g,this.#g,i),this.#M())for(let o=0;o<this.#i.Count();o++){let s=this.#t[this.#i.At(o)];s.locked()||(s.translate(i),n=!0)}}),n?!0:this.#F()||this.#H()||this.#m}clearNodeInputConnection(e,t){let n=e.inputPort(t);for(let i=this.#n.length-1;i>=0;i--)this.#n[i].inPort()===n&&this.#O(this.#n[i],!0)}connectionsWithin(e){let t=[];for(let n of this.#n){let i=n.outNode(),o=n.inNode();if(i===null||o===null)continue;let s=e.indexOf(i),l=e.indexOf(o);if(s===-1||l===-1)continue;let h=n.outPort(),d=n.inPort();h===null||d===null||t.push({fromNode:s,fromPort:this.#V(i,h),toNode:l,toPort:this.#v(o,d)})}return t}#R=null;setConnectionReleasedHandler(e){this.#R=e}#W(e){let t=e.outNode(),n=e.inNode();if(t!==null&&n===null){let i=e.outPort();if(i===null)return null;let o=this.#V(t,i);return{needs:"INPUT",types:i.acceptedTypes(),connectTo:s=>{let l=this.#S(s,"INPUT",i);l!==-1&&o!==-1&&this.connectNodes(t,o,s,l)}}}if(n!==null&&t===null){let i=e.inPort();if(i===null)return null;let o=this.#v(n,i);return{needs:"OUTPUT",types:i.acceptedTypes(),connectTo:s=>{let l=this.#S(s,"OUTPUT",i);l!==-1&&o!==-1&&this.connectNodes(s,l,n,o)}}}return null}#V(e,t){for(let n=0;n<e.outputs();n++)if(e.outputPort(n)===t)return n;return-1}#v(e,t){for(let n=0;n<e.inputs();n++)if(e.inputPort(n)===t)return n;return-1}#S(e,t,n){let i=t==="INPUT"?e.inputs():e.outputs(),o=-1;for(let s=0;s<i;s++){let l=t==="INPUT"?e.inputPort(s):e.outputPort(s);if(!!(t==="INPUT"?oe(n,l,this.#b):oe(l,n,this.#b))){if(!l.hidden())return s;o===-1&&(o=s)}}return o}clickEnd(){for(let n=0;n<this.#i.Count();n++)this.#t[this.#i.At(n)].raiseDragStoppedEvent();if(this.#i.Clear(),this.#m){for(let n=0;n<this.#C.Count();n++)this.#B(this.#t[this.#C.At(n)],!1);this.#C.Clear(),this.#m=!1}if(this.#h!==null){let n=this.#h,i=this.#k();this.#h=null,this.#c=null,n.PointerUp?.(i)}if(this.#s===null)return;if(this.#l===null){let n=this.#W(this.#s);this.#L(),n!==null&&this.#R?.(n);return}let e=this.#l.Port,t=this.#s;if(e===t.inPort()||e===t.outPort()){this.#L();return}if(this.#l.InputPort&&t.inPort()!==null){this.#L();return}if(!this.#l.InputPort&&t.outPort()!==null){this.#L();return}if(this.#l.InputPort&&!oe(t.outPort(),this.#l.Port,this.#b)){this.#L();return}if(!this.#l.InputPort&&!oe(this.#l.Port,t.inPort(),this.#b)){this.#L();return}if(this.#l.InputPort){let n=!1,i=this.#l.Node.inputPort(this.#l.Index);this.#l.Port.getPortType()!=="INPUTARRAY"&&i.connections().length>0&&(n=!0),n&&(i.connections()[0].clearOutput(),this.#O(i.connections()[0],!1)),t.setInput(this.#l.Node,this.#l.Index,n,this.#K())}else t.setOutput(this.#l.Node,this.#l.Index);this.#s=null}connectNodes(e,t,n,i){let o=e.outputPort(t),s=n.inputPort(i);if(!oe(o,s,this.#b)){console.error("can't connect nodes of different types",o.getDataType(),s.getDataType());return}let l=n.inputPort(i).connections();for(let d=0;d<l.length;d++){let a=l[d];if(a.outNode()===e&&a.outPort()===e.outputPort(t))return}let h=new ve(n,i,e,t,this.#r);return this.#n.push(h),b(),h}getNodes(){return this.#t}getSelectedNodes(){let e=new Array;for(let t=0;t<this.#t.length;t++)this.#t[t].selected()&&e.push(this.#t[t]);return e}connectedInputsNodeReferencesByIndex(e){return this.connectedInputsNodeReferences(this.#t[e])}connectedInputsNodeReferences(e){let t=new Array;for(let n=0;n<this.#n.length;n++){let i=this.#n[n];if(e!==i.inNode())continue;let o=i.outNode();o!==null&&t.push(o)}return t}connectedOutputsNodeReferences(e){let t=this.#t[e],n=new Array;for(let i=0;i<this.#n.length;i++){let o=this.#n[i];if(t!==o.outNode())continue;let s=o.inNode();s!==null&&n.push(s)}return n}addNode(e){this.#t.push(e),b();for(let t=0;t<this.#T.length;t++){let n=this.#T[t];!n||n(e)}}fileDrop(e){return this.#o===-1?!1:(this.#t[this.#o].dropFile(e),!0)}#N(e){if(e>=this.#t.length||e<0){console.error("invalid node connection");return}for(let t=this.#n.length-1;t>=0;t--)this.#n[t].referencesNode(this.#t[e])&&this.#I(t,!0)}#M(){return this.#i.Count()>0}#F(){return this.#s!==null}#H(){return this.#h!==null}removeNode(e){for(let t=0;t<this.#t.length;t++)this.#t[t]===e&&this.#E(t)}#E(e){this.#N(e);let t=this.#t[e];this.#t.splice(e,1),this.#o===e?this.#o=-1:this.#o>e&&this.#o--,this.#l?.Node===t&&(this.#l=null),b();for(let n=0;n<this.#A.length;n++)this.#A[n](t)}#I(e,t){t&&this.#n[e].clearPorts(),this.#n.splice(e,1),b()}#O(e,t){let n=this.#n.indexOf(e);n>-1?this.#I(n,t):console.error("no connection found to remove")}organize(e){zt(e,this)}#U(){let e=new Array;for(let t=0;t<this.#t.length;t++)this.#t[t].selected()&&e.push(t);return e}#$(e){zt(e,this,this.#U())}openContextMenu(e,t){let n={name:"Organize",group:E,items:[{name:"All Nodes",group:E,callback:()=>{this.organize(e)}}]},i={items:[],subMenus:[n,this.#y.openMenu(this,t)]},o=this.#U().length;if(o>0&&(n.items?.push({name:"Selected Nodes",group:E,callback:()=>{this.#$(e)}}),i.items?.push({name:o===1?"Delete Selected Node":`Delete ${o} Selected Nodes`,group:E,callback:()=>{this.removeSelectedNodes()}})),this.#o>-1){let s=this.#o,l=this.#t[s];i.subMenus?.push({group:E,name:"Select",items:[{name:"Direct Connected Nodes",group:E,callback:()=>{this.#j(s)}},{name:"Input Nodes + Descendents",group:E,callback:()=>{this.#_(l)}}]}),i.subMenus?.push({group:E,name:"Delete",items:[{name:"Node",group:E,callback:()=>{this.#E(s)}},{name:"Connections",group:E,callback:()=>{this.#N(s)}}]}),i=Z(i,l.contextMenu())}return i}#_(e){if(e===void 0)return;this.#B(e,!1);let t=this.connectedInputsNodeReferences(e);for(let n=0;n<t.length;n++)this.#_(t[n])}#j(e){let t=this.#t[e];if(t===void 0)return;this.#B(t,!1);let n=this.connectedOutputsNodeReferences(e);for(let o=0;o<n.length;o++)this.#B(n[o],!1);let i=this.connectedInputsNodeReferencesByIndex(e);for(let o=0;o<i.length;o++)this.#B(i[o],!1)}unselectAllNodes(){let e=!1;for(let t=0;t<this.#t.length;t++)this.#t[t].selected()&&(this.#t[t].unselect(),e=!0);e&&b()}removeSelectedNodes(){let e=this.getSelectedNodes();for(let t of e)this.removeNode(t);return e}#q(e,t){this.#B(this.#t[e],t)}#B(e,t){if(e.select(),!!t)for(let n=0;n<this.#t.length;n++)e!==this.#t[n]&&this.#t[n].unselect()}#L(){this.#s!==null&&(this.#O(this.#s,!0),this.#s=null)}#X(e,t,n){for(let i=0;i<this.#n.length;i++){let o=!1;n!==void 0&&(o=this.#n[i].mouseOverPort(n)!==null),this.#n[i].render(e,t.zoom,o,n)}}#Z(e,t,n){this.#l=null,this.#d=null,this.#o=-1,this.#C.Clear();let i=null,o=this.#Y(t),s={Position:{x:0,y:0},Size:{x:e.canvas.width,y:e.canvas.height}};for(let l=0;l<this.#t.length;l++){let h=0,d=this.#t[l].calculateBounds(e,t);if(!(!xt(d,s)&&this.#t[l].layoutPortsWithoutDrawing(d,t.zoom))){if(n!==void 0&&!this.#m){let a=this.#t[l].inBounds(e,t,n);a.Node!==void 0&&(i=a.Node),a.Node!==void 0&&a.PortIndex===void 0&&a.Widget===void 0&&(h=1,this.#o=l,this.#f="grab"),a.Widget!==void 0&&(this.#d=a.Widget,this.#u=a.WidgetBox??null,this.#f=a.Widget.Disabled?.()?"default":a.Widget.Cursor?.()??"pointer"),a.Port!==void 0&&a.Node!==void 0&&a.PortIndex!==void 0&&a.PortIsInput!==void 0&&(this.#l={Index:a.PortIndex,Node:a.Node,Port:a.Port,InputPort:a.PortIsInput})}else if(this.#m){let a=this.#t[l].calculateBounds(e,t);xt(o,a)&&(h=1,this.#C.Push(l))}this.#t[l].selected()&&this.#i.Count()>0&&(h=2,this.#f="grabbing"),this.#t[l].render(e,t,h,n,this.#e)}}this.#D(i),this.#h!==null&&(this.#f=this.#h.Cursor?.()??"pointer")}#Y(e){let t={Position:P(),Size:P()};return e.graphSpaceToScreenSpace(this.#p,t.Position),e.graphSpaceToScreenSpace(this.#g,t.Size),He(t.Size,t.Size,t.Position),t}#K(){let e=this.#l;if(e===null||!e.InputPort||this.#x===void 0||e.Port.getPortType()!=="INPUTARRAY")return;let t=e.Node.inputPortPosition(e.Index);return Zt(t,e.Port.connections().length,this.#x.y)}#Q(e,t){let n=this.#l;if(this.#s===null||this.#s.inPort()!==null||n===null)return;let i=this.#K(),o=n.Port.connections().length;if(i===void 0||o===0)return;let s=n.Node.inputPortPosition(n.Index),l=s.Position.y+i*s.Size.y/o,h=6*t.zoom;e.save(),e.strokeStyle="#ffffff",e.lineWidth=Math.max(1,2*t.zoom),e.beginPath(),e.moveTo(s.Position.x-h,l),e.lineTo(s.Position.x+s.Size.x+h,l),e.stroke(),e.restore()}render(e,t,n){this.#w=e,this.#x=n,this.#f="default";let i=this.#t.some(o=>!o.hasBeenLaidOut());for(let o of this.#t)o.hasBeenLaidOut()&&o.placePorts(o.calculateBounds(e,t),t.zoom);if(q("Render_Connections",()=>{this.#X(e,t,n)}),q("Render_Nodes",()=>{this.#Z(e,t,n)}),this.#Q(e,t),i&&b(),this.#m){let o=this.#Y(t);e.setLineDash([c.BoxSelect.LineDashLength]),new Q({border:{color:c.BoxSelect.Color,size:c.BoxSelect.Size},color:"rgba(0,0,0,0)",radius:c.BoxSelect.Radius}).Draw(e,o,1),e.setLineDash([])}return{cursorStyle:this.#f}}};var J=class{#e;#t;#n;#o;#i;#s;#r;constructor(e){this.#e=e.title,this.#t=e.options,this.#n=e.content,this.#o=e.onClose,this.#i=e.buttonCSS===void 0?"flex-grow: 1; margin-right: 8px;":e.buttonCSS,this.#s=null,this.#r=null}Hide(){this.#s!==null&&(this.#r!==null&&(document.removeEventListener("keydown",this.#r,!0),this.#r=null),document.body.removeChild(this.#s),this.#s=null)}#l(e){this.Hide(),this.#o!==void 0&&this.#o(e)}Show(){this.#s=document.createElement("div"),this.#s.style.cssText=`position:absolute;top:0;width:100%;display:flex;height:100%;justify-content:center;align-items:center;background-color:${c.Popup.Backdrop};`,document.body.appendChild(this.#s);let e=document.createElement("div");e.style.cssText=`background-color:${c.Popup.BackgroundColor};color:${c.Popup.FontColor};font-family:${c.Popup.FontFamily};border-radius:${c.Popup.BorderRadius}px;padding:16px;`,this.#s.appendChild(e);let t=document.createElement("h2");t.textContent=this.#e,t.style.cssText="margin-top:0;margin-bottom:16px;",e.appendChild(t),this.#n!==void 0&&e.appendChild(this.#n());let n=document.createElement("div");n.style.cssText="margin-top:16px;justify-content:space-around;align-items:center;flex-direction:row;display:flex;",e.appendChild(n);for(let i=0;i<this.#t.length;i++){let o=document.createElement("button");o.style.cssText=this.#i,o.textContent=this.#t[i],o.onclick=()=>this.#l(this.#t[i]),n.appendChild(o)}this.#r=i=>{i.key==="Enter"?(i.preventDefault(),this.#l(this.#t.length>0?this.#t[0]:null)):i.key==="Escape"&&(i.preventDefault(),this.#l(null)),i.stopPropagation()},document.addEventListener("keydown",this.#r,!0)}};function tt(r){let e=null;return new J({title:r.title,options:["Set","Cancel"],content:()=>{let t=document.createElement("div");return e=document.createElement("input"),e.value=r.startingValue,t.append(e),t},onClose:t=>{if(t!=="Set"||e===null){r.onCancel&&r.onCancel();return}r.onUpdate(e.value)}})}function Ie(r){let e=new Array,t="Set",n="Cancel";return new J({title:r.title,options:[t,n],content:()=>{let i=document.createElement("div");i.style.flexDirection="column",i.style.display="flex";for(let o=0;o<r.form.length;o++){let s=document.createElement("h4");s.innerText=r.form[o].name,i.append(s);let l=document.createElement("input");l.value=r.form[o].startingValue,l.type=r.form[o].type,i.append(l),e.push(l),i.append(document.createElement("br"))}return i},onClose:i=>{if(i!==t||e===null){r.onCancel&&r.onCancel();return}let o=new Array;for(let s=0;s<r.form.length;s++)o[s]=e[s]?.value;r.onUpdate(o)}})}var Rt=150,Qn=(n=>(n.Info="info",n.Warning="warning",n.Error="error",n))(Qn||{});function Jn(r){switch(r){case"info":return c.Node.Message.InfoColor;case"warning":return c.Node.Message.WarnColor;case"error":return c.Node.Message.ErrorColor;default:throw new Error(`unrecognized message type ${r}`)}}var dn=(n=>(n[n.Idle=0]="Idle",n[n.MouseOver=1]="MouseOver",n[n.Grabbed=2]="Grabbed",n))(dn||{}),nt=class{#e;#t;constructor(e){this.#t=e.alwaysShow?e.alwaysShow:!1,this.#e=new k(e.message,{color:e.color?e.color:Jn(e.type?e.type:"info")},{LineSpacing:2.5,MaxWidth:200})}render(e,t,n,i){return!this.#t&&!i?0:(e.textAlign="center",this.#e.render(e,t,n),this.#e.height(e)*t)}},ce=class{#e;#t;#n;#o;#i;#s;#r;#l;#d;#h;#u;#c;#a;#f;#y;#m;#p;#g;#C;#b;#w;#x;#A=-1;#T;#z;#P=new Map;#D;#k;#R;#W;#V=!1;#v;#S;#N;#M=new W;#F;#H;#E;#I=new Map;constructor(e){if(this.#r=new Array,this.#l=new Array,this.#d=new Array,this.#v=new W,this.#S=new W,this.#N=new W,this.#R=15,this.#h=e?.locked===void 0?!1:e.locked,this.#F=e?.data===void 0?{}:e?.data,this.#E=new Map,this.#H=new Array,this.#a=e?.canEditPorts===void 0?!1:e.canEditPorts,this.#u=e?.canEditTitle===void 0?!1:e.canEditTitle,this.#c=e?.canEditInfo===void 0?!1:e.canEditInfo,this.#f=e?.contextMenu===void 0?null:e.contextMenu,this.#y=e?.metadata,this.#s=[],e?.messages)for(let t=0;t<e.messages.length;t++){let n=e.messages[t];this.#s.push(new nt(n))}if(this.#W=!1,this.#m=new Array,this.#p=new Array,this.#g=new Array,this.#C=new Array,this.#b=new Array,this.#w=new Array,e?.onSelect&&this.#m.push(e?.onSelect),e?.onUnselect&&this.#p.push(e?.onUnselect),e?.onFileDrop&&this.#g.push(e?.onFileDrop),e?.onDragStop&&this.#C.push(e.onDragStop),e?.onTitleChange&&this.#b.push(e.onTitleChange),e?.onInfoChange&&this.#w.push(e.onInfoChange),this.#e=e?.position===void 0?{x:0,y:0}:e.position,this.#t=new k(e?.title===void 0?"":e.title,te(e?.style?.title?.textStyle,{size:16,weight:"bold"})),this.#n=new k(e?.subTitle===void 0?"":e.subTitle,te(e?.style?.title?.textStyle,{size:10,weight:"bold"})),this.#o=new k("i",{size:13,weight:"bold"}),this.#i=e?.info?e?.info:"",this.#D=e?.style?.title?.padding===void 0?15:e?.style?.title?.padding,this.#x=e?.style,this.#X(),e?.inputs!==void 0)for(let t=0;t<e.inputs.length;t++)this.addInput(e.inputs[t]);if(e?.outputs!==void 0)for(let t=0;t<e.outputs.length;t++)this.addOutput(e.outputs[t]);if(e?.widgets!==void 0)for(let t of e.widgets)this.addWidget(L.createFromConfig(this,t))}metadata(){return this.#y}selected(){return this.#W}select(){if(!this.#W){this.#W=!0,b();for(let e=0;e<this.#m.length;e++)this.#m[e]()}}highlighted(){return this.#V}setHighlighted(e){this.#V!==e&&(this.#V=e,b())}raiseDragStoppedEvent(){for(let e=0;e<this.#C.length;e++)this.#C[e](this)}addTitleChangeListener(e){e==null,this.#b.push(e)}addInfoChangeListener(e){e==null,this.#w.push(e)}addDragStoppedListener(e){e==null,this.#C.push(e)}addAnyPropertyChangeListener(e){e==null,this.#H.push(e)}addPropertyChangeListener(e,t){this.#E.has(e)||this.#E.set(e,[]);let n=this.#E.get(e);n!==void 0&&n.push(t)}setProperty(e,t){let n=this.#F[e];if(Object.is(n,t))return;this.#F[e]=t,b();for(let o=0;o<this.#H.length;o++)this.#H[o](e,n,t);let i=this.#E.get(e);if(i!==void 0)for(let o=0;o<i.length;o++)i[o](n,t)}addPropertyEditListener(e,t){let n=this.#I.get(e);n===void 0&&(n=[],this.#I.set(e,n)),n.push(t)}editProperty(e,t){this.setProperty(e,t);let n=this.#I.get(e);if(n!==void 0)for(let i of[...n])i(t)}getProperty(e){return this.#F[e]}#O(){tt({title:"Set Node Title",startingValue:this.title(),onUpdate:e=>{this.setTitle(e)}}).Show()}#U(){tt({title:"Set Node Info",startingValue:this.#i,onUpdate:e=>{this.setInfo(e)}}).Show()}#$(){tt({title:"New Button Widget Text",startingValue:"My Button",onUpdate:e=>{this.addWidget(new se({text:e}))}}).Show()}#_(){return{name:"Widget",items:[{name:"Button",callback:this.#$.bind(this)},{name:"Number",callback:()=>{this.addWidget(new re(this))}},{name:"Color",callback:()=>{this.addWidget(new le(this))}},{name:"Slider",callback:()=>{Ie({title:"New Slider",form:[{name:"min",type:"number",startingValue:0},{name:"max",type:"number",startingValue:100}],onUpdate:e=>{this.addWidget(new de(this,{min:e[0],max:e[1]}))}}).Show()}},{name:"String",callback:()=>{this.addWidget(new he(this))}},{name:"Toggle",callback:()=>{this.addWidget(new ae(this))}},{name:"Image",callback:()=>{Ie({title:"New Image",form:[{name:"URL",type:"text",startingValue:"https://pbs.twimg.com/media/GYabtu6bsAA7m99?format=jpg&name=medium"},{name:"Max Width",type:"number",startingValue:Rt},{name:"Max Height",type:"number",startingValue:Rt}],onUpdate:e=>{this.addWidget(new ue({image:e[0],maxWidth:e[1],maxHeight:e[2]}))}}).Show()}}]}}contextMenu(){let e={group:E,items:[],subMenus:[]};if(this.canEditPorts()||this.canEditTitle()||this.#c){let t=new Array;this.canEditTitle()&&t.push({name:"Title",callback:()=>{this.#O()}}),this.#c&&t.push({name:"Info",callback:()=>{this.#U()}});let n=new Array;this.canEditPorts()&&n.push({name:"Add",items:[{name:"Input",callback:()=>{Ie({title:"New Input",form:[{name:"name",type:"text",startingValue:"input"},{name:"type",type:"text",startingValue:"string"}],onUpdate:i=>{this.addInput({name:i[0],type:i[1]})}}).Show()}},{name:"Output",callback:()=>{Ie({title:"New Output",form:[{name:"name",type:"text",startingValue:"output"},{name:"type",type:"text",startingValue:"string"}],onUpdate:i=>{this.addOutput({name:i[0],type:i[1]})}}).Show()}}],subMenus:[this.#_()]}),e.subMenus?.push({group:E,name:"Edit",items:t,subMenus:n})}return this.locked()?e.items?.push({name:"Unlock Node Position",group:E,callback:this.unlock.bind(this)}):e.items?.push({name:"Lock Node Position",group:E,callback:this.lock.bind(this)}),this.#f!==null&&(e=Z(e,this.#f)),e}unselect(){if(!!this.#W){this.#W=!1,b();for(let e=0;e<this.#p.length;e++)this.#p[e]()}}addUnselectListener(e){this.#p.push(e)}addSelectListener(e){this.#m.push(e)}dropFile(e){for(let t=0;t<this.#g.length;t++)this.#g[t](e)}addFileDropListener(e){this.#g.push(e)}locked(){return this.#h}lock(){this.#h=!0}unlock(){this.#h=!1}setPosition(e){z(this.#e,e),b()}getPosition(){return this.#e}calculateBounds(e,t){this.#Z();let n=P(),i=this.#D*2,o=P();t.graphSpaceToScreenSpace(this.#e,o);let s=P();this.#t.size(e,1,s);let l=P();this.#n.size(e,1,l),s.x=Math.max(s.x,l.x),this.#i!==""&&(s.x+=s.y*4),s.x+=i,s.y+=i;for(let d of[...this.#r,...this.#l])d.hidden()||(this.#k.measure(e,1,d.getDisplayName(),n),s.y+=this.#K(d,n.y)+this.#R,s.x=Math.max(s.x,this.#Q(d,n.x)+i));let h=this.#L()?[this.#q,...this.#d]:this.#d;for(let d of h){if(d.Hidden?.())continue;let a=d.Size();s.y+=a.y+this.#R,s.x=Math.max(s.x,a.x+i)}return s.y+=this.#R,s.x=Math.max(s.x,Rt),Y(s,t.zoom),{Position:o,Size:s}}addInput(e){let t=new be(this,e.array?"INPUTARRAY":"INPUT",e);return e.widget!==void 0&&t.setWidget(L.createFromConfig(this,e.widget)),this.#r.push(t),t}addOutput(e){let t=new be(this,"OUTPUT",e);return this.#l.push(t),t}#j=!1;#q=new je(this);#B=null;hiddenPortsShown(){return this.#j}setHiddenPortsShown(e){e!==this.#j&&(this.#j=e,this.invalidateLayout())}hiddenPortCount(){let e=0;for(let t of[...this.#r,...this.#l])t.tucked()&&e++;return e}#L(){return this.hiddenPortCount()>0}addWidget(e){this.#d.push(e),b()}insertWidget(e,t){let n=Math.max(0,Math.min(e,this.#d.length));this.#d.splice(n,0,t),b()}removeWidget(e){let t=this.#d.indexOf(e,0);if(t===-1)throw new Error("node does not contain widget");this.#d.splice(t,1),b()}removeWidgetAt(e){if(e<0||e>=this.#d.length)return;let t=this.#d.splice(e,1)[0];return b(),t}moveWidget(e,t){if(e<0||e>=this.#d.length||t<0||t>=this.#d.length||e===t)return;let[n]=this.#d.splice(e,1);this.#d.splice(t,0,n),b()}clearWidgets(){this.#d.length=0,b()}getWidget(e){return this.#d[e]}widgets(){return this.#d}indexOfWidget(e){return this.#d.indexOf(e,0)}widgetCount(){return this.#d.length}translate(e){this.#e.x+=e.x,this.#e.y+=e.y}inBounds(e,t,n){var i={};let o=this.calculateBounds(e,t);T(o,n)&&(i.Node=this);for(let s=0;s<this.#v.Count();s++)!this.#r[s].hidden()&&T(this.#v.At(s),n)&&(i.Node=this,i.PortIndex=s,i.PortIsInput=!0,i.Port=this.#r[s]);for(let s=0;s<this.#S.Count();s++)!this.#l[s].hidden()&&T(this.#S.At(s),n)&&(i.Node=this,i.PortIndex=s,i.PortIsInput=!1,i.Port=this.#l[s]);this.#B!==null&&T(this.#B,n)&&(i.Node=this,i.Widget=this.#q,i.WidgetBox=this.#B);for(let s=0;s<this.#N.Count();s++){let l=this.#d[s];l!==void 0&&!l.Hidden?.()&&T(this.#N.At(s),n)&&(i.Node=this,i.WidgetIndex=s,i.Widget=l,i.WidgetBox=this.#N.At(s))}for(let s=0;s<this.#M.Count();s++){let l=this.#r[s];l!==void 0&&l.widgetShown()&&T(this.#M.At(s),n)&&(i.Node=this,i.Widget=l.widget(),i.WidgetBox=this.#M.At(s),i.Port=void 0,i.PortIndex=void 0,i.PortIsInput=void 0)}return i}canEditTitle(){return this.#u}canEditPorts(){return this.#a}title(){return this.#t.get()}setTitle(e){let t=e;t==null&&(t="");let n=this.title();if(t!==n){this.#t.set(t),b();for(let i=0;i<this.#b.length;i++){let o=this.#b[i];o(this,n,t)}}}setInfo(e){let t=e;if(t==null&&(t=""),t===this.#i)return;let n=this.#i;this.#i=t,b();for(let i=0;i<this.#w.length;i++){let o=this.#w[i];o(this,n,t)}}inputPortPosition(e){return this.#v.At(e)}widgetPosition(e){if(!(e<0||e>=this.#N.Count()))return this.#N.At(e)}inputPort(e){return this.#r[e]}inputs(){return this.#r.length}outputPortPosition(e){return this.#S.At(e)}outputPort(e){return this.#l[e]}outputs(){return this.#l.length}#X(){let e=this.#x,t=e?.title?.textStyle?.color??c.Node.Title.FontColor;this.#t.style().setColor(t),this.#n.style().setColor(t),this.#o.style().setColor(t),this.#T=e?.title?.color??c.Node.Title.Color;let n=(i,o,s)=>new Q(tn(i,{border:{color:o,size:s},radius:c.Node.BorderRadius,color:c.Node.BackgroundColor}));this.#P.set(0,n(e?.idle,c.Node.Border.Idle,1)),this.#P.set(1,n(e?.mouseOver,c.Node.Border.MouseOver,1.1)),this.#P.set(2,n(e?.grabbed,c.Node.Border.Grabbed,2)),this.#z=n(e?.selected,c.Node.Border.Selected,1),this.#k=new j({size:e?.portText?.size??14,color:e?.portText?.color??c.Node.Port.FontColor,font:e?.portText?.font,weight:e?.portText?.weight}),this.#A=D()}#Z(){this.#A!==D()&&this.#X()}#Y(e){if(this.#W&&e===0)return this.#z;let t=this.#P.get(e);if(t===void 0)throw new Error("no registered border style for state: "+e);return t}addMessage(e){this.#s.push(new nt(e))}clearMessages(){this.#s=[]}#K(e,t){let n=e.slots(),i=e.widgetShown()?e.widget().Size().y:0;return Math.max(n>1?n*Mt:0,t,i)}#Q(e,t){return e.widgetShown()?t+this.#R+e.widget().Size().x:t}hasBeenLaidOut(){return this.#J}invalidateLayout(){this.#J=!1,this.#G={input:[],output:[]},b()}#J=!1;render(e,t,n,i,o){this.#J=!0,A.run(()=>{let s=A.get();this.#v.Clear(),this.#S.Clear(),this.#N.Clear(),this.#M.Clear();let l=this.#D*t.zoom,h=this.#R*t.zoom,d=this.calculateBounds(e,t),a=this.#Y(n);a.Draw(e,d,t.zoom),this.#V&&(e.save(),e.strokeStyle=c.Node.Border.Highlighted,e.lineWidth=2,e.beginPath(),e.roundRect(d.Position.x-3,d.Position.y-3,d.Size.x+3*2,d.Size.y+3*2,a.radius()*t.zoom+3),e.stroke(),e.restore());let u=a.borderSize();e.textAlign="center",e.textBaseline="middle";let f=A.get();this.#t.size(e,t.zoom,f);let g=A.get();this.#n.size(e,t.zoom,g);let v=A.get();v.x=d.Size.x,v.y=f.y+l*2,e.fillStyle=this.#T,e.beginPath();let p=d.Position.x+u*t.zoom*.5,y=d.Position.y+u*t.zoom*.5,m=v.x-u*t.zoom,C=v.y-u*t.zoom*.5;e.roundRect(p,y,m,C,[a.radius()*t.zoom,a.radius()*t.zoom,0,0]),e.fill(),c.Node.Bevel!==null&&Ke(e,d,t.zoom,c.Node.Bevel,!1);let x=A.get();if(x.x=d.Position.x+d.Size.x/2,x.y=d.Position.y+l+f.y/2,this.#n.get()!==""){let S=A.get();z(S,x),S.y-=f.y/1.5,x.y+=l/2,this.#n.render(e,t.zoom,S)}if(this.#t.render(e,t.zoom,x),this.#i!==""){let S=C*.25,N=p+m-C*.25-S,R=y+C*.25+S,V=A.get();V.x=N,V.y=R+C*.025;let ee=1.5*t.zoom;i&&ge(V,i)<=S&&(ee*=1.5,o.queue(()=>{this.#o.style().setupStyle(e,t.zoom),e.textAlign="center";let fe=m*1.5,me=ke(e,this.#i,fe),pe=this.#o.style().getSize()+2,It=pe*me.length*t.zoom,Pe=pe*t.zoom,Dt=y-It-Pe/2;e.fillStyle=this.#T,e.beginPath(),e.roundRect(N-fe/2-Pe/2,Dt-Pe,fe+Pe,It+Pe,a.radius()*t.zoom),e.fill(),this.#o.style().setupStyle(e,t.zoom);for(let Le=0;Le<me.length;Le++){let fn=me[Le];e.fillText(fn,N,Dt+Le*pe*t.zoom)}})),e.beginPath(),e.arc(N,R,S,0,2*Math.PI,!1),e.lineWidth=ee,e.strokeStyle=this.#o.getColor(),e.stroke(),e.textAlign="center",this.#o.render(e,t.zoom,V)}let w=d.Position.y+l*2+f.y+h,M=d.Position.x+l;for(let S=0;S<this.#r.length;S++){e.textAlign="left";let N=this.#r[S];if(N.hidden()){this.#v.Push({Position:{x:d.Position.x,y:w},Size:{x:0,y:0}}),this.#M.Push({Position:{x:d.Position.x,y:w},Size:{x:0,y:0}});continue}this.#k.measure(e,1,N.getDisplayName(),s);let R=this.#K(N,s.y)*t.zoom,V=A.get();if(V.x=d.Position.x,V.y=w+R/2,this.#k.setupStyle(e,t.zoom),e.fillText(N.getDisplayName(),M,V.y),N.widgetShown()){let ee=N.widget(),fe=ee.Size().y*t.zoom,me=M+s.x*t.zoom+h,pe={Position:{x:me,y:w+(R-fe)/2},Size:{x:d.Position.x+d.Size.x-l-me,y:fe}};ee.Draw(e,pe,t.zoom,i),this.#M.Push(pe)}else this.#M.Push({Position:{x:d.Position.x,y:w},Size:{x:0,y:0}});this.#v.Push(N.render(e,V,t,i,o)),w+=R+h}let F=d.Position.x+d.Size.x;e.textAlign="right";for(let S=0;S<this.#l.length;S++){let N=this.#l[S];if(N.hidden()){this.#S.Push({Position:{x:F,y:w},Size:{x:0,y:0}});continue}this.#k.measure(e,1,N.getDisplayName(),s);let R=s.y*t.zoom,V=A.get();V.x=F,V.y=w+R/2,this.#k.setupStyle(e,t.zoom),e.fillText(N.getDisplayName(),F-l,V.y),this.#S.Push(N.render(e,V,t,i,o)),w+=R+h}if(this.#B=null,this.#L()){let S={Position:{x:d.Position.x+l,y:w},Size:{x:d.Size.x-l*2,y:this.#q.Size().y*t.zoom}};this.#q.Draw(e,S,t.zoom,i),this.#B=S,w+=S.Size.y+h}for(let S=0;S<this.#d.length;S++){let N=this.#d[S];if(N.Hidden?.()){this.#N.Push({Position:{x:d.Position.x,y:w},Size:{x:0,y:0}});continue}let R=N.Size(),V={Position:{x:d.Position.x+l,y:w},Size:{x:d.Size.x-l*2,y:R.y*t.zoom}};N.Draw(e,V,t.zoom,i),this.#N.Push(V),w+=V.Size.y+h}let B=A.get();B.x=d.Position.x+d.Size.x/2,B.y=d.Position.y+d.Size.y+15*t.zoom;for(let S=0;S<this.#s.length;S++){let N=this.#s[S];B.y+=N.render(e,t.zoom,B,n!==0)+10*t.zoom}this.#ee(d,t.zoom)})}#G={input:[],output:[]};#ee(e,t){if(t<=0)return;let n=(i,o)=>{o.length=0;for(let s=0;s<i.Count();s++){let l=i.At(s);o.push({Position:{x:(l.Position.x-e.Position.x)/t,y:(l.Position.y-e.Position.y)/t},Size:{x:l.Size.x/t,y:l.Size.y/t}})}};n(this.#v,this.#G.input),n(this.#S,this.#G.output)}layoutPortsWithoutDrawing(e,t){return this.placePorts(e,t)?(this.#N.Clear(),this.#M.Clear(),this.#B=null,!0):!1}placePorts(e,t){if(this.#G.input.length===0&&this.#G.output.length===0)return!1;let n=(i,o)=>{o.Clear();for(let s=0;s<i.length;s++){let l=i[s];o.Push({Position:{x:e.Position.x+l.Position.x*t,y:e.Position.y+l.Position.y*t},Size:{x:l.Size.x*t,y:l.Size.y*t}})}};return n(this.#G.input,this.#v),n(this.#G.output,this.#S),!0}};var it=class{#e;#t;#n;#o;constructor(e,t,n,i){this.#e=e,this.#t=t,this.#n=n,this.#o=i}type(){return this.#e}lexeme(){return this.#t}tokenStart(){return this.#n}tokenEnd(){return this.#o}};var ot=class{#e;#t;#n;constructor(e){this.#t=0,this.#e=e,this.#n=new Array}tokens(){return this.#n}#o(){return this.#t>this.#e.length-1?"":this.#e.charAt(this.#t)}#i(){this.#t++}#s(){return this.#t++,this.#t>this.#e.length-1?"":this.#e.charAt(this.#t)}#r=0;#l(e,t,n){this.#n.push(new it(e,t,n??this.#r,this.#t))}#d(){let e=0;for(;this.#o()==="#";)e++,this.#i();let t="H3";e===1?t="H1":e===2&&(t="H2"),this.#l(t,"#".repeat(e))}#h(){let e=this.#o();for(;e!==""&&!(e!==" "&&e!==" ");)e=this.#s();this.#l("Space"," ")}#u(){let e=this.#o(),t=-1;for(;e!=="";){if((e===" "||e===" ")&&t===-1){this.#i();continue}if(e===`
2
- `||e==="*"||e==="`"){t!=-1&&this.#l("Text",this.#e.substring(t,this.#t));return}t===-1&&(t=this.#t),e=this.#s()}t!=-1&&this.#l("Text",this.#e.substring(t,this.#t),t)}parse(){let e=this.#o();for(;e!=="";)this.#r=this.#t,e===" "||e===" "?this.#h():e==="#"?this.#d():e===`
3
- `?(this.#i(),this.#l("New Line",`
4
- `)):e==="*"?(this.#i(),this.#l("Star","*")):e==="`"?(this.#i(),this.#l("`","`")):this.#u(),e=this.#o()}};function an(r){typeof document>"u"||document.fonts===void 0||document.fonts.addEventListener("loadingdone",()=>{r(),b()})}var rt=class{#e;#t;#n;#o;text(){return this.#e}constructor(e){this.#e=e,this.#o=-1,this.#n=new W,this.#t=new W,an(()=>{this.#o=-1})}#i(e,t){if(this.#o===t)return;let n=t;n-=c.Note.CodeBlock.Padding*2,this.#n.Clear(),this.#t.Clear();let i=0,o=this.#e.style().getSize()+c.Note.LineSpacing,s=this.#e.split(`
5
- `);for(let l=0;l<s.length;l++){let d=s[l].breakIntoLines(e,n);for(let a=0;a<d.length;a++)this.#n.Push(d[a]),this.#t.Push({x:0,y:i}),i+=o}this.#o=t}render(e,t,n,i){this.#i(e,i);let o=c.Note.CodeBlock.Padding*n,s=this.#n.Count(),l=s===0?0:this.#t.At(s-1).y,d=(s===0?0:(l+this.#e.style().getSize())*n)+o*2;e.fillStyle=c.Note.CodeBlock.BackgroundColor,e.beginPath(),e.roundRect(t.x,t.y,i*n,d,c.Note.CodeBlock.BorderRadius*n),e.fill();let a=e.textBaseline;e.textBaseline="top";for(let u=0;u<s;u++){let f=this.#n.At(u),g=this.#t.At(u);f.render(e,n,{x:g.x*n+t.x+o,y:g.y*n+t.y+o})}return e.textBaseline=a,d}},st=class{#e;constructor(e){this.#e=e}entries(){return this.#e}render(e,t,n,i){let o=0,s=20,l={x:t.x+s*n,y:t.y},h=c.Note.DotSize*n;for(let d=0;d<this.#e.length;d++)e.beginPath(),e.arc(t.x+h,l.y+h*3,h,0,2*Math.PI),e.fill(),o+=this.#e[d].render(e,l,n,i-s)+n*c.Note.LineSpacing*2,l.y=t.y+o;return o}},$=class{#e;#t;#n;#o;#i;#s;lines(){return this.#n}constructor(e,t,n){this.#n=e,this.#e=t,this.#t=n,this.#s=-1,this.#i=new W,this.#o=new W,an(()=>{this.#s=-1})}#r(e,t){if(this.#s===t)return;let n=t;this.#t&&(n-=c.Note.CodeBlock.Padding*2),this.#i.Clear(),this.#o.Clear();let i=P(),o=P(),s=0,l=new W,h=new W;for(let d=0;d<this.#n.length;d++){let u=this.#n[d].splitAtWidth(e,n-i.x),f=0;for(;u.length>1&&f<100;){if(f++,u[0].get()===""&&l.Count()===0)if(u[1].get().length===1){u[0]=u[1];break}else u=u[1].splitAtIndex(1);u[0].get()!==""&&(u[0].size(e,1,o),s=Math.max(s,o.y),l.Push(u[0]),h.Push(i.x)),i.y+=s;for(let g=0;g<l.Count();g++)this.#i.Push(l.At(g)),this.#o.Push({x:h.At(g),y:i.y});l.Clear(),h.Clear(),i.y+=c.Note.LineSpacing,s=0,i.x=0,u=u[1].splitAtWidth(e,n)}f===100&&console.log(u),u[0].size(e,1,o),s=Math.max(s,o.y),l.Push(u[0]),h.Push(i.x),i.x+=o.x}i.y+=s;for(let d=0;d<l.Count();d++)this.#i.Push(l.At(d)),this.#o.Push({x:h.At(d),y:i.y});this.#s=t}render(e,t,n,i){this.#r(e,i);let o=0;if(this.#t&&(o+=c.Note.CodeBlock.Padding*n),this.#t){let l=0;for(let d=0;d<this.#i.Count();d++){let a=this.#o.At(d);l=Math.max(l,a.y*n)}let h=t.y+l+n*5;e.fillStyle=c.Note.CodeBlock.BackgroundColor,e.beginPath(),e.roundRect(t.x,t.y,i*n,l+o*2,c.Note.CodeBlock.BorderRadius*n),e.fill()}let s=0;for(let l=0;l<this.#i.Count();l++){let h=this.#i.At(l),d=this.#o.At(l);h.render(e,n,{x:d.x*n+t.x+o,y:d.y*n+t.y+o}),s=Math.max(s,d.y*n)}if(this.#e){let l=t.y+s+n*5;e.strokeStyle=c.Note.FontColor,e.lineWidth=c.Note.HeaderLineWidth*n,e.beginPath(),e.moveTo(t.x,l),e.lineTo(t.x+i*n,l),e.stroke()}return s+o*2}};var lt=class{#e;#t;#n;constructor(e,t){this.#n=e,this.#t=0,this.#e=t}#o(){return this.#t>this.#e.length-1?null:this.#e[this.#t]}#i(){this.#t++}#s(){return this.#t++,this.#t>=this.#e.length?null:this.#e[this.#t]}#r(){return this.#l(1)}#l(e){return this.#t+e>=this.#e.length?null:this.#e[this.#t+e]}#d(){if(this.#r()?.type()==="Space")return[new k("*")];let e=this.#h(),t="",n=0;for(;;){let h=this.#o();if(h===null||h.type()==="New Line")break;if(h.type()==="Star"){n=this.#h();break}t+=h.lexeme(),this.#i()}this.#t--;let o=t!==""&&t.trimStart()===t&&t.trimEnd()===t?Math.min(e,n):0;if(o===0)return[new k("*".repeat(e)+t+"*".repeat(n))];let s={};o>=2?s.weight="bold":s.style="italic";let l=new Array;return e>o&&l.push(new k("*".repeat(e-o))),l.push(new k(t,s)),n>o&&l.push(new k("*".repeat(n-o))),l}#h(){let e=0;for(;this.#o()?.type()==="Star";)e++,this.#i();return e}#u(){let e=this.#t;this.#i();let t="";for(;;){let n=this.#o();if(n===null||n.type()==="New Line")return this.#t=e,[new k("`")];if(n.type()==="`")break;t+=n.lexeme(),this.#i()}return[new k(t,{font:c.Note.CodeFontFamily??"monospace"})]}#c(){let e=new Array,t="",n=this.#o();for(;n!==null&&n.type()==="Space";)n=this.#s();for(;n!==null&&n.type()!=="New Line";){switch(n.type()){case"Text":case"H1":case"H2":case"H3":case"Space":t+=n.lexeme();break;case"Star":case"`":t!==""&&(e.push(new k(t)),t="");let i=n.type()==="Star"?this.#d():this.#u();for(let o=0;o<i.length;o++)e.push(i[o]);break}n=this.#s()}return t!==""&&e.push(new k(t)),e}#a(){this.#i();let e=this.#c();for(let t=0;t<e.length;t++)e[t].setColor(c.Note.FontColor),e[t].setSize(c.Note.H1.FontSize),e[t].setWeight("bold");return new $(e,!0,!1)}#f(){this.#i();let e=this.#c();for(let t=0;t<e.length;t++)e[t].setColor(c.Note.FontColor),e[t].setSize(c.Note.H2.FontSize),e[t].setWeight("bold");return new $(e,!0,!1)}#y(){this.#i();let e=this.#c();for(let t=0;t<e.length;t++)e[t].setColor(c.Note.FontColor),e[t].setSize(c.Note.H3.FontSize),e[t].setWeight("bold");return new $(e,!1,!1)}#m(){if(this.#r()?.type()!=="Space"){let t=this.#c();return this.#p(t),new $(t,!1,!1)}let e=new Array;for(;this.#o()?.type()==="Star"&&this.#r()?.type()==="Space";){this.#i();let t=this.#c();this.#p(t),e.push(new $(t,!1,!1)),this.#i()}return new st(e)}#p(e){for(let t=0;t<e.length;t++)e[t].setColor(c.Note.FontColor),e[t].setSize(c.Note.FontSize)}#g(){if(this.#r()?.type()!=="`"||this.#l(2)?.type()!=="`"){let s=this.#c();return this.#p(s),new $(s,!1,!1)}this.#i(),this.#i();let e=this.#s();e?.type()==="New Line"&&(e=this.#s());let t=e?.tokenStart(),n=t;for(;e!==null;){if(e.type()==="`"&&this.#r()?.type()==="`"&&this.#l(2)?.type()==="`"){n=e.tokenEnd()-1;break}e=this.#s()}this.#i(),this.#i(),this.#i();let i=this.#n.substring(t,n).replace(/\r?\n$/,""),o=new k(i,{font:c.Note.CodeFontFamily??void 0});return this.#p([o]),o.setColor(c.Note.CodeBlock.FontColor),new rt(o)}parse(){let e=this.#o(),t=new Array;for(;e!==null;){switch(e.type()){case"H1":t.push(this.#a());break;case"H2":t.push(this.#f());break;case"H3":t.push(this.#y());break;case"Text":let n=this.#c();this.#p(n),t.push(new $(n,!1,!1));break;case"Star":t.push(this.#m());break;case"New Line":this.#i();break;case"`":t.push(this.#g());break;default:this.#i()}e=this.#o()}return t}};function Wt(r){let e=new ot(r);return e.parse(),new lt(r,e.tokens()).parse()}var dt=20,O=10,Se=class{#e;#t;#n=-1;#o;#i;#s;#r;#l;#d;#h;#u;#c;#a;constructor(e){this.#c=new Array,this.#a=new Array,this.#s=e?.metadata===void 0?{}:e?.metadata,this.#t=[],this.#e="",this.#u=!1,this.#d=e?.locked===void 0?!0:!e?.locked,this.#o=e?.width===void 0?500:e.width,this.#r=e?.position===void 0?{x:0,y:0}:e.position,this.setText(e?.text===void 0?"":e?.text),this.#h={Position:{x:0,y:0},Size:{x:0,y:0}},this.#l=0,this.#i=new Q({border:{color:"white",size:1}}),e?.onWidthChange&&this.#c.push(e.onWidthChange),e?.onContentChange&&this.#a.push(e.onContentChange)}setText(e){this.#e=e,this.#t=Wt(this.#e),this.#n=D();for(let t=0;t<this.#a.length;t++)this.#a[t](this,e)}setMetadataProperty(e,t){this.#s[e]=t}getMetadataProperty(e){return this.#s[e]}text(){return this.#e}width(){return this.#o}position(){return this.#r}translate(e){this.#r.x+=e.x,this.#r.y+=e.y}setPosition(e){z(this.#r,e)}handleSelected(){return this.#l}selectHandle(e){this.#l=e}#f=P();setWidth(e){e===void 0&&console.error("Attempted to set note's width to undefined"),this.#o=e;for(let t=0;t<this.#c.length;t++)this.#c[t](this,e)}addWidthChangeListener(e){e!=null&&this.#c.push(e)}addContentChangeListener(e){e!=null&&this.#a.push(e)}render(e,t,n){if(this.#d&&(this.#u||this.#l!==0)){if(n){if(this.#l===2){let a=this.#r.x*t.zoom+t.position.x;this.setWidth(Math.max((n.x-a)/t.zoom,1))}else if(this.#l===1){let a=this.#o*t.zoom,u=this.#r.x*t.zoom+t.position.x+a;this.setWidth(Math.max((u-n.x)/t.zoom,1)),this.#r.x=u-this.#o*t.zoom-t.position.x,this.#r.x/=t.zoom}}this.#i.Outline(e,this.leftResizeHandleBox(),t.zoom,2),this.#i.Outline(e,this.rightResizeHandleBox(),t.zoom,2),e.beginPath();let s=this.#h.Position.x,l=this.#h.Position.x+this.#h.Size.x,h=this.#h.Position.y,d=this.#h.Position.y+this.#h.Size.y;e.moveTo(s,h+this.#h.Size.y/2-O),e.lineTo(s,h),e.lineTo(l,h),e.lineTo(l,h+this.#h.Size.y/2-O),e.moveTo(s,d-this.#h.Size.y/2+O),e.lineTo(s,d),e.lineTo(l,d),e.lineTo(l,d-this.#h.Size.y/2+O),e.stroke()}t.graphSpaceToScreenSpace(this.#r,this.#f),z(this.#h.Position,this.#f),this.#n!==D()&&(this.#t=Wt(this.#e),this.#n=D());let i=this.#f.y,o=c.Note.EntrySpacing*t.zoom;e.textAlign="left",e.textBaseline="alphabetic";for(let s=0;s<this.#t.length;s++){let l=this.#t[s];this.#f.y+=l.render(e,this.#f,t.zoom,this.#o)+o}this.#h.Position.x-=dt,this.#h.Position.y-=dt,this.#h.Size.x=t.zoom*this.#o+dt*2,this.#h.Size.y=this.#f.y-i+dt*2}leftResizeHandleBox(){return{Position:{x:this.#h.Position.x-O/2,y:this.#h.Position.y+this.#h.Size.y/2-O/2},Size:{x:O,y:O}}}rightResizeHandleBox(){return{Position:{x:this.#h.Position.x-O/2+this.#h.Size.x,y:this.#h.Position.y+this.#h.Size.y/2-O/2},Size:{x:O,y:O}}}edittingLayout(){return this.#d}setHovering(e){this.#u=e}editContent(){let e=null,t="Save";new J({title:"Edit Note",options:[t,"Cancel"],content:()=>{let i=document.createElement("div");return e=document.createElement("textarea"),e.rows=8,e.cols=50,e.value=this.#e,i.append(e),i},onClose:i=>{i!==t||e===null||this.setText(e.value)}}).Show()}lock(){this.#d=!1}unlock(){this.#d=!0}bounds(){return this.#h}};var ht=class{#e;#t;#n;#o;#i;#s;#r;#l;constructor(e){if(this.#o=0,this.#e=[],this.#t=null,this.#n=null,this.#i=new Array,this.#s=new Array,this.#r=new Array,this.#l=new Array,e?.notes!==void 0)for(let t=0;t<e?.notes.length;t++)this.addNote(new Se(e?.notes[t]));e?.onNoteAdded!==void 0&&this.#i.push(e?.onNoteAdded),e?.onNoteDragStop!==void 0&&this.#l.push(e?.onNoteDragStop),e?.onNoteDragStart!==void 0&&this.#r.push(e?.onNoteDragStart),e?.onNoteRemoved!==void 0&&this.#s.push(e?.onNoteRemoved)}addNote(e){if(e!=null){this.#e.push(e),b();for(let t=0;t<this.#i.length;t++)this.#i[t](e)}}getNotes(){return this.#e}addNoteAddedListener(e){e!=null&&this.#i.push(e)}addNoteRemovedListener(e){e!=null&&this.#s.push(e)}addNoteDragStartListener(e){e!=null&&this.#r.push(e)}addNoteDragStopListener(e){e!=null&&this.#l.push(e)}openContextMenu(e,t){let n="node-flow-graph-note-menu",i={items:[{name:"New Note",group:n,callback:()=>{this.addNote(new Se({text:`#Note
6
-
7
- Right-click this note and select "edit note" to put what you want here.`,width:300,position:t}))}}],subMenus:[]};if(this.#t!==null){let o=this.#t;i.items?.push({name:"Delete Note",group:n,callback:()=>{this.removeNote(o)}},{name:"Edit Note",group:n,callback:o.editContent.bind(o)}),o.edittingLayout()?i.items?.push({name:"Lock Note",group:n,callback:o.lock.bind(o)}):i.items?.push({name:"Unlock Note",group:n,callback:o.unlock.bind(o)})}return i}clickStart(e,t,n){if(this.#t!==null&&this.#t.edittingLayout()){this.#n=this.#t,this.#n.selectHandle(this.#o);for(let i=0;i<this.#r.length;i++)this.#r[i](this.#n);return!0}return!1}clickEnd(){if(this.#n!==null){this.#n.selectHandle(0);for(let e=0;e<this.#l.length;e++)this.#l[e](this.#n)}this.#n=null}mouseDragEvent(e,t){return this.#n===null?!1:(this.#n.handleSelected()||this.#n.translate({x:e.x*(1/t),y:e.y*(1/t)}),!0)}fileDrop(e){return!1}removeNote(e){let t=this.#e.indexOf(e);if(t>-1){let n=this.#e[t];this.#e.splice(t,1),b();for(let i=0;i<this.#s.length;i++)this.#s[i](n)}else console.error("no note found to remove")}removeAllNotes(){let e=this.#e;this.#e=[],this.#t=null,this.#n=null;for(let t=0;t<e.length;t++)for(let n=0;n<this.#s.length;n++)this.#s[n](e[t])}render(e,t,n){if(this.#t=null,this.#o=0,n)for(let i=0;i<this.#e.length;i++)this.#e[i].setHovering(!1),T(this.#e[i].bounds(),n)&&(this.#t=this.#e[i]);this.#t!=null&&(this.#t.setHovering(!0),n&&(T(this.#t.leftResizeHandleBox(),n)?this.#o=1:T(this.#t.rightResizeHandleBox(),n)&&(this.#o=2)));for(let i=0;i<this.#e.length;i++)this.#e[i].render(e,t,n)}};var at=class{#e;constructor(){this.#e=new W}queue(e){!e||this.#e.Push(e)}render(e,t,n){for(let i=0;i<this.#e.Count();i++)this.#e.At(i)();this.#e.Clear()}openContextMenu(e,t){return null}clickStart(e,t,n){return!1}mouseDragEvent(e,t){return!1}fileDrop(e){return!1}clickEnd(){}};var Vt=class{#e;items;constructor(e,t){this.#e=e,this.items=t}updateRendering(e){let t=!1;for(let n=0;n<this.items.length;n++){let i=this.items[n].filter(e);this.items[n].render(i),i&&(t=!0)}this.#e.setDisplay(t?"flex":"none")}},Ft=class{#e;#t;#n;constructor(e,t,n){this.#e=e.toLowerCase(),this.#t=t,this.#n=n}filter(e){if(e.length===0)return!0;for(let t=0;t<e.length;t++)if(e[t]!==""&&this.#e.indexOf(e[t])===-1)return!1;return!0}render(e){this.#t.setDisplay(e?"flex":"none")}rendering(){return this.#t.getDisplay()==="flex"}highlight(e){this.#t.setBackgroundColor(e?c.ContextMenu.HighlightColor:"")}select(){this.#n.callback&&this.#n.callback()}};function un(r,e,t,n){let i=e?.name??"";if(r!==""&&(i=r+" / "+i),e?.items&&e.items.length>0){let o=new _(new k(i,{color:c.ContextMenu.FontColor,weight:"bold",size:12}),{Align:"center",VerticalAlign:"center",Padding:16});t.push(o);let s=new Array;for(let l=0;l<e.items.length;l++){let h=e.items[l],d=new _(new k(h.name??"Item",{color:c.ContextMenu.FontColor}),{Padding:8});s.push(new Ft(i+(h.name??""),d,h)),t.push(d)}n.push(new Vt(o,s))}if(e?.subMenus)for(let o=0;o<e?.subMenus.length;o++){let s=e?.subMenus[o];un(i,s,t,n)}}var ut=class{#e;#t;#n;#o;constructor(e){this.#e=[],this.#o=0,this.#n=new k("",{color:c.ContextMenu.FontColor});let t=[new _(new k("Search",{color:c.ContextMenu.FontColor}),{Padding:{Bottom:0,Left:8,Right:8,Top:8}}),new ie([new _(this.#n,void 0)],{Border:{Radius:2},BackgroundColor:"#003847",Padding:8,Margin:8,MinHeight:46})];e&&un("",e,t,this.#e),this.#t=new ie(t,{BackgroundColor:c.ContextMenu.BackgroundColor,Border:{Thickness:1,Radius:4}}),this.#i()}execute(){let e=this.#o;for(let t=0;t<this.#e.length;t++){let n=this.#e[t];for(let i=0;i<n.items.length;i++)if(n.items[i].rendering()){if(e===0){n.items[i].select();return}e--}}}#i(){let e=this.#n.get().trim().toLowerCase(),t=new Array;if(e!==""){var n=e.split(" ");for(let o=0;o<n.length;o++){let s=n[o].trim();s!==""&&t.push(s)}}let i=this.#o;for(let o=0;o<this.#e.length;o++){let s=this.#e[o];s.updateRendering(t);for(let l=0;l<s.items.length;l++)s.items[l].rendering()&&(s.items[l].highlight(i===0),i--)}}keyboardEvent(e){let t=!0;if(e.code==="Backspace"){this.#o=0;let n=this.#n.get();this.#n.set(n.slice(0,n.length-1))}else/^[a-zA-Z0-9]$/.test(e.key)||e.key===" "?(this.#o=0,this.#n.set(this.#n.get()+e.key)):e.key==="ArrowUp"?this.#o=Math.max(0,this.#o-1):e.key==="ArrowDown"?this.#o++:t=!1;t&&(this.#i(),e.preventDefault())}renderSize={x:0,y:0};render(e,t,n,i){return this.#t.calcSize(e,this.renderSize,{x:-1,y:-1}),t.y+Math.min(this.renderSize.y,400)>e.canvas.clientHeight&&(t.y=e.canvas.clientHeight-Math.min(this.renderSize.y,400)),t.x+this.renderSize.x>e.canvas.clientWidth&&(t.x=e.canvas.clientWidth-this.renderSize.x),t.y<0&&(t.y=0),t.x<0&&(t.x=0),this.#t.render(e,t,1,this.renderSize),this.#s={Position:{x:t.x,y:t.y},Size:{x:this.renderSize.x,y:this.renderSize.y}},null}#s=null;contains(e){return this.#s!==null&&T(this.#s,e)}};var De=class{#e;#t;#n;#o;#i;#s;#r;#l;#d={Position:{x:0,y:0},Size:{x:0,y:0}};#h=1;#u=0;#c=0;#a=c.Minimap.Padding;#f=!1;constructor(e){this.#e=e?.enabled===!0,this.#t=e?.width===void 0?200:e.width,this.#n=e?.height===void 0?150:e.height,this.#o=e?.margin===void 0?16:e.margin,this.#i=e?.backgroundColor,this.#s=e?.borderColor,this.#r=e?.nodeColor,this.#l=e?.viewportColor}enabled(){return this.#e}setEnabled(e){this.#e=e,this.#f=!1}contains(e){return this.#e&&this.#f&&T(this.#d,e)}graphPositionOf(e,t){t.x=(e.x-this.#d.Position.x-this.#a)/this.#h+this.#u,t.y=(e.y-this.#d.Position.y-this.#a)/this.#h+this.#c}render(e,t,n,i){if(!this.#e){this.#f=!1;return}let o=new X,s=1/0,l=1/0,h=-1/0,d=-1/0,a=[];for(let x=0;x<i.length;x++){let w=i[x].calculateBounds(e,o);a.push(w),s=Math.min(s,w.Position.x),l=Math.min(l,w.Position.y),h=Math.max(h,w.Position.x+w.Size.x),d=Math.max(d,w.Position.y+w.Size.y)}let u={x:0,y:0},f={x:0,y:0};if(n.screenSpaceToGraphSpace({x:0,y:0},u),n.screenSpaceToGraphSpace({x:t.width,y:t.height},f),s=Math.min(s,u.x),l=Math.min(l,u.y),h=Math.max(h,f.x),d=Math.max(d,f.y),!isFinite(s)||h<=s||d<=l){this.#f=!1;return}this.#d.Size.x=this.#t,this.#d.Size.y=this.#n,this.#d.Position.x=t.width-this.#t-this.#o,this.#d.Position.y=t.height-this.#n-this.#o,this.#a=c.Minimap.Padding;let g=this.#t-this.#a*2,v=this.#n-this.#a*2;this.#h=Math.min(g/(h-s),v/(d-l)),this.#u=s,this.#c=l;let p=this.#d.Position.x+this.#a,y=this.#d.Position.y+this.#a,m=x=>p+(x-s)*this.#h,C=x=>y+(x-l)*this.#h;e.fillStyle=this.#i??c.Minimap.BackgroundColor,e.strokeStyle=this.#s??c.Minimap.BorderColor,e.lineWidth=1,e.beginPath(),e.roundRect(this.#d.Position.x,this.#d.Position.y,this.#t,this.#n,c.Minimap.BorderRadius),e.fill(),e.stroke(),e.fillStyle=this.#r??c.Minimap.NodeColor;for(let x=0;x<a.length;x++){let w=a[x];e.fillRect(m(w.Position.x),C(w.Position.y),Math.max(1,w.Size.x*this.#h),Math.max(1,w.Size.y*this.#h))}e.fillStyle=this.#l??c.Minimap.ViewportColor,e.fillRect(m(u.x),C(u.y),Math.max(1,(f.x-u.x)*this.#h),Math.max(1,(f.y-u.y)*this.#h)),this.#f=!0}};function ti(r){return(e,t,n,i)=>{t.fillStyle=r??c.Graph.BackgroundColor,t.fillRect(0,0,e.width,e.height);let o=G(i-.3);if(o<=0)return;t.save(),t.globalAlpha=o,t.fillStyle=c.Graph.DotColor;let s=100,l=2*Math.PI,h=2*i;for(let d=-50;d<50;d++){let a=d*s*i+n.x;for(let u=-50;u<50;u++){let f=u*s*i+n.y;t.beginPath(),t.arc(a,f,h,0,l),t.fill()}}t.restore()}}var ni="graph-context-menu",Et=class{#e;constructor(e){this.#e=e}clickStart(e,t,n){for(let i=this.#e.length-1;i>=0;i--)if(this.#e[i].clickStart(e,t,n))return}fileDrop(e){for(let t=this.#e.length-1;t>=0;t--)if(this.#e[t].fileDrop(e))return!0;return!1}openContextMenu(e,t){let n={};for(let i=0;i<this.#e.length;i++){let o=this.#e[i].openContextMenu(e,t);o!==null&&(n=Z(n,o))}return n}clickEnd(){for(let e=0;e<this.#e.length;e++)this.#e[e].clickEnd()}mouseDragEvent(e,t){for(let n=0;n<this.#e.length;n++)if(this.#e[n].mouseDragEvent(e,t))return!0;return!1}render(e,t,n){let i={};for(let o=0;o<this.#e.length;o++)q("Render_Subsystem_"+o,()=>{let s=this.#e[o].render(e,t,n);s?.cursorStyle&&(i.cursorStyle=s.cursorStyle)});return i}},cn=class{#e;#t;#n;#o;#i;#s=!1;#r;#l;#d;#h;#u;#c;#a;#f;constructor(e,t){let n=new at;this.#a=new et(n,{nodes:t?.nodes,idleConnection:t?.idleConnection,casts:t?.casts}),this.#V="default",this.#v="default",this.#f=new ht(t?.board),this.#u=[new Et([this.#f,this.#a,n])],this.#c=0,this.#r=new X,this.#o=Z({items:[{name:"Center on Graph",group:ni,callback:this.centerOnGraph.bind(this)}]},t?.contextMenu),this.#l=null,this.#d=null,this.#h=null,this.#t=e;let i=e.getContext("2d");if(i===null)throw new Error("could not create canvas context");this.#e=i,t?.backgroundRenderer!==void 0?this.#n=t?.backgroundRenderer:this.#n=ti(t?.backgroundColor),this.#S=new De(t?.minimap),this.#a.setConnectionReleasedHandler(o=>{this.#k(o)}),this.#H(),this.#N=Lt(this.#E.bind(this)),b(),new Ge(this.#t,this.#W.bind(this),o=>{this.#i=o,this.#s=!0},this.#A.bind(this),this.#R.bind(this),this.#D.bind(this),this.#w.bind(this),(o,s)=>{this.#x(o,s)},()=>{this.#s=!1}),document.addEventListener("keydown",o=>{this.#b(o),b()})}#y=[];#m=[];addCopyListener(e){this.#y.push(e)}addPasteListener(e){this.#m.push(e)}#p(){let e=this.#a.getSelectedNodes();if(e.length===0)return;let t=this.#a.connectionsWithin(e);this.#y.forEach(n=>n(e,t))}#g(){let e=this.#i===void 0?{x:0,y:0}:this.#P(this.#i);this.#m.forEach(t=>t(e))}#C(e){return e.code==="Delete"||e.key==="Delete"}#b(e){if(document.activeElement&&["INPUT","TEXTAREA"].includes(document.activeElement.tagName))return;if(this.#d){if(e.code==="Escape"){this.#d=null;return}if(e.code==="Enter"){this.#d.Menu.execute(),this.#d=null;return}this.#d.Menu.keyboardEvent(e);return}if(this.#C(e)&&this.#a.getSelectedNodes().length>0){e.preventDefault(),this.#a.removeSelectedNodes();return}if(e.ctrlKey||e.metaKey)switch(e.code.startsWith("Key")?e.code.substring(3).toLowerCase():(e.key??"").toLowerCase()){case"c":this.#p();return;case"v":this.#g();return;case"d":e.preventDefault(),this.#p(),this.#g();return}if(!(e.key==" "||e.code=="Space")||!this.#i)return;let n=this.#P(this.#i),i=this.#a.nodeFactory().newNodeSubmenus(this.#a,n);this.#d={Menu:new ut({subMenus:i}),Position:n}}#w(e){if(this.currentView().fileDrop(e))return;let t=e.name.split("."),n=t[t.length-1];if(n!=="jpg"&&n!=="jpeg"&&n!=="png")return;let i=P();this.#i&&z(i,this.#P(this.#i)),this.#a.addNode(new ce({title:t[0],position:i,widgets:[{type:"image",config:{blob:e}}]}))}addNoteAddedListener(e){this.#f.addNoteAddedListener(e)}addNoteRemovedListener(e){this.#f.addNoteRemovedListener(e)}addNoteDragStartListener(e){this.#f.addNoteDragStartListener(e)}addNoteDragStopListener(e){this.#f.addNoteDragStopListener(e)}zoom(e,t){this.#x(1+e*.05,t)}#x(e,t){let n=t??this.#i,i;if(n!==void 0&&(i=this.#P(n)),this.#r.zoom*=e,!i||n===void 0)return;t!==void 0&&(this.#i=t);let o=this.#P(n);this.#r.position.x+=(o.x-i.x)*this.#r.zoom,this.#r.position.y+=(o.y-i.y)*this.#r.zoom}#A(e,t){if(this.#h!==null){this.#h.click(),this.#l=null,this.#h=null;return}if(this.#l=null,this.#d=null,this.#h=null,this.#i=e,this.#s=!0,this.#S.contains(e)){this.#z(e),this.#T=!0;return}this.currentView().clickStart(e,this.#r,t)}#T=!1;#z(e){let t={x:0,y:0};this.#S.graphPositionOf(e,t),this.#r.position.x=-(t.x*this.#r.zoom)+this.#t.width/2,this.#r.position.y=-(t.y*this.#r.zoom)+this.#t.height/2,b()}minimap(){return this.#S}currentView(){return this.#u[this.#c]}organize(){this.#a.organize(this.#e)}addPublisher(e,t){this.#a.addPublisher(e,t)}setCasts(e){this.#a.setCasts(e)}getNodes(){return this.#a.getNodes()}getSelectedNodes(){return this.#a.getSelectedNodes()}unselectAllNodes(){this.#a.unselectAllNodes()}removeSelectedNodes(){return this.#a.removeSelectedNodes()}getCamera(){return this.#r.getOrientation()}setCamera(e){this.#r.setOrientation(e)}resetCamera(){this.#r.reset()}centerOnGraph(){let e=this.getNodes();if(e.length===0){this.#r.reset();return}let t=new X,n=1/0,i=1/0,o=-1/0,s=-1/0;for(let y=0;y<e.length;y++){let m=e[y].calculateBounds(this.#e,t);n=Math.min(n,m.Position.x),i=Math.min(i,m.Position.y),o=Math.max(o,m.Position.x+m.Size.x),s=Math.max(s,m.Position.y+m.Size.y)}let l=o-n,h=s-i;if(l<=0||h<=0){this.#r.reset();return}let d=l*.05,a=h*.05;n-=d,i-=a,l+=d*2,h+=a*2;let u=this.#t.clientWidth,f=this.#t.clientHeight;if(u<=0||f<=0){this.#r.reset();return}let g=Math.min(u/l,f/h),v=n+l/2,p=i+h/2;this.#r.zoom=g,this.#r.position.x=u/2-v*g,this.#r.position.y=f/2-p*g}connectedInputsNodeReferences(e){return this.#a.connectedInputsNodeReferencesByIndex(e)}connectedOutputsNodeReferences(e){return this.#a.connectedOutputsNodeReferences(e)}connectNodes(e,t,n,i){return this.#a.connectNodes(e,t,n,i)}clearNodeInputConnection(e,t){this.#a.clearNodeInputConnection(e,t)}addNode(e){this.#a.addNode(e)}removeNode(e){this.#a.removeNode(e)}addNote(e){this.#f.addNote(e)}removeNote(e){this.#f.removeNote(e)}removeAllNotes(){this.#f.removeAllNotes()}getNotes(){return this.#f.getNotes()}addOnNodeCreatedListener(e){this.#a.addOnNodeCreatedListener(e)}addOnNodeAddedListener(e){this.#a.addOnNodeAddedListener(e)}addOnNodeRemovedListener(e){this.#a.addOnNodeRemovedListener(e)}addNodeHoverListener(e){this.#a.addNodeHoverListener(e)}#P(e){let t=P();return this.#r.screenSpaceToGraphSpace(e,t),t}#D(e){let t=this.#o,n=this.#P(e);t=Z(t,this.currentView().openContextMenu(this.#e,n)),this.#l={Menu:new ne(t),Position:n}}#k(e){if(this.#i===void 0)return;let t=this.#P(this.#i),n=this.#a.nodeFactory().openMenu(this.#a,t,{needs:e.needs,types:e.types,casts:this.#a.casts(),onCreated:e.connectTo});this.#l={Menu:new ne(n),Position:t},b()}#R(){this.#T=!1,this.currentView().clickEnd()}#W(e){if(this.#T){this.#i!==void 0&&this.#z(this.#i);return}this.currentView().mouseDragEvent(e,this.#r.zoom)||(this.#r.position.x+=e.x,this.#r.position.y+=e.y)}#V;#v;#S;#N;#M;#F(){let e=this.#t.parentNode;if(e===null)return;let t=e.getBoundingClientRect();this.#t.width===t.width&&this.#t.height===t.height||(this.#t.width=t.width,this.#t.height=t.height)}#H(){this.#F();let e=this.#t.parentNode;e===null||typeof ResizeObserver>"u"||(this.#M=new ResizeObserver(()=>{this.#F(),b()}),this.#M.observe(e))}requestRender(){b()}renderContinuously(){return pt()}dispose(){this.#N(),this.#M?.disconnect()}#E(){this.#F(),this.#v="default",q("Render_Background",this.#U.bind(this)),q("Render_View_"+this.#c,()=>{Qt(this.#t,()=>{let e=this.currentView().render(this.#e,this.#r,this.#O());e?.cursorStyle&&(this.#v=e?.cursorStyle)})}),q("Render_Minimap",()=>{this.#S.render(this.#e,this.#t,this.#r,this.#a.getNodes())}),q("Render_Context",this.#$.bind(this)),q("Render_QuickMenu",this.#_.bind(this)),this.#V!==this.#v&&(this.#t.style.cursor=this.#v),this.#V=this.#v}#I(){return this.#s?this.#i:void 0}#O(){let e=this.#I();if(e!==void 0&&!(this.#l?.Menu.contains(e)||this.#d?.Menu.contains(e)))return e}#U(){this.#n(this.#t,this.#e,this.#r.position,this.#r.zoom)}#$(){A.run(()=>{if(this.#l!==null){let e=A.get();this.#r.graphSpaceToScreenSpace(this.#l.Position,e),this.#h=this.#l.Menu.render(this.#e,e,this.#r.zoom,this.#I(),!0),this.#h!==null&&(this.#v="pointer")}})}#_(){A.run(()=>{if(this.#d!==null){let e=A.get();this.#r.graphSpaceToScreenSpace(this.#d.Position,e),this.#h=this.#d.Menu.render(this.#e,e,this.#r.zoom,this.#I()),this.#h!==null&&(this.#v="pointer")}})}};export{se as ButtonWidget,le as ColorWidget,ve as Connection,qt as ContextMenuItemState,U as CursorStyle,At as DefaultConnectionRenderer,pn as DefaultTheme,ce as FlowNode,Se as FlowNote,L as GlobalWidgetFactory,Et as GraphView,ue as ImageWidget,T as InBox,Qn as MessageType,De as Minimap,Ee as NodeFactory,cn as NodeFlowGraph,dn as NodeState,re as NumberWidget,be as Port,Be as PortType,Fe as Publisher,We as RowWidget,de as SliderWidget,he as StringWidget,Re as TextWidget,c as Theme,ae as ToggleWidget,H as ValueWidget,I as WidgetBase,Qe as WidgetFactory,K as drawField,xe as drawFieldBox,Ye as drawFieldText,Bt as editInPlace,Ze as formatNumber,yn as onThemeChange,Ue as portConfigTypes,Tn as portTypeColor,Nn as portsCompatible,oe as portsConnect,pt as renderContinuously,b as requestRender,gn as setTheme,D as themeVersion,Tt as typeSetsCompatible,Ae as typeSetsConnect,Xe as widgetFont};
8
- //# sourceMappingURL=NodeFlow.js.map