@metadev/daga-react 5.0.3 → 5.0.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/index.js CHANGED
@@ -1,2 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("react/jsx-runtime"),io=require("d3"),kt=require("rxjs"),I=require("react");function so(s){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const e in s)if(e!=="default"){const a=Object.getOwnPropertyDescriptor(s,e);Object.defineProperty(t,e,a.get?a:{enumerable:!0,get:()=>s[e]})}}return t.default=s,Object.freeze(t)}const A=so(io);var f=(s=>(s.Bottom="bottom",s.Left="left",s.Right="right",s.Top="top",s))(f||{}),Bt=(s=>(s.BottomLeft="bottom-left",s.BottomRight="bottom-right",s.TopLeft="top-left",s.TopRight="top-right",s))(Bt||{}),Lt=(s=>(s.Left="left",s.Center="center",s.Right="right",s))(Lt||{}),Xt=(s=>(s.Top="top",s.Center="center",s.Bottom="bottom",s))(Xt||{});const It=s=>[Math.round(s[0]),Math.round(s[1])],ft=(s,t,e)=>t<e?t<=s&&s<=e:e<=s&&s<=t,Se=(s,t,e)=>(s-t[0])/(t[1]-t[0])*(e[1]-e[0])+e[0],Wt=(s,t,e,a,l,r,i)=>{const n=(()=>{switch(r){case"start":return a[0]+(s[0]-t[0]);case"end":return a[1]-(t[1]-s[0]);case"middle":{const d=(t[0]+t[1])/2,c=(a[0]+a[1])/2,h=t[1]-t[0],u=a[1]-a[0],b=(s[0]-d)/h;return c+b*u}default:return Se(s[0],t,a)}})(),o=(()=>{switch(i){case"start":return l[0]+(s[1]-e[0]);case"end":return l[1]-(e[1]-s[1]);case"middle":{const d=(e[0]+e[1])/2,c=(l[0]+l[1])/2,h=e[1]-e[0],u=l[1]-l[0],b=(s[1]-d)/h;return c+b*u}default:return Se(s[1],e,l)}})();return[n,o]},Re=(s,t)=>((s[0]-t[0])**2+(s[1]-t[1])**2)**.5,no=(s,t)=>(ft(s[0][0],t[0][0],t[1][0])||ft(s[1][0],t[1][0],t[0][0])||ft(t[0][0],s[0][0],s[1][0])||ft(t[1][0],s[1][0],s[0][0]))&&(ft(s[0][1],t[0][1],t[1][1])||ft(s[1][1],t[1][1],t[0][1])||ft(t[0][1],s[0][1],s[1][1])||ft(t[1][1],s[1][1],s[0][1]));var S=(s=>(s.Blur="blur",s.Change="change",s.Click="click",s.ContextMenu="contextmenu",s.DoubleClick="dblclick",s.Focus="focus",s.FocusIn="focusin",s.FocusOut="focusout",s.Input="input",s.KeyDown="keydown",s.KeyUp="keyup",s.MouseDown="mousedown",s.MouseEnter="mouseenter",s.MouseLeave="mouseleave",s.MouseMove="mousemove",s.MouseOut="mouseout",s.MouseOver="mouseover",s.MouseUp="mouseup",s.TouchStart="touchstart",s.TouchEnd="touchend",s.Wheel="wheel",s))(S||{}),K=(s=>(s.Alt="Alt",s.AltGraph="AltGraph",s.ArrowDown="ArrowDown",s.ArrowLeft="ArrowLeft",s.ArrowRight="ArrowRight",s.ArrowUp="ArrowUp",s.Backspace="Backspace",s.Control="Control",s.Delete="Delete",s.End="End",s.Enter="Enter",s.Escape="Escape",s.Home="Home",s.OS="OS",s.PageDown="PageDown",s.PageUp="PageUp",s.Shift="Shift",s.Tab="Tab",s))(K||{}),$=(s=>(s.Drag="drag",s.Start="start",s.End="end",s))($||{}),de=(s=>(s.Zoom="zoom",s.Start="start",s.End="end",s))(de||{});const ce=s=>s.replace(/([!"#$%&'()*+,\-./:;<=>?@[\\\]^`{|}])/g,"\\$1");var Ve=(s=>(s.Straight="straight",s.Bezier="bezier",s.Square="square",s))(Ve||{}),pe=(s=>(s.Solid="solid",s.Dashed="dashed",s.GappedDashes="gapped-dashes",s.Dotted="dotted",s))(pe||{});const ro=20,ao=(s,t,e,a,l)=>{if(typeof s=="function")return s(t,e,a,l);if(t.length===0)return"";if(t.length===1)return`M ${t[0][0]} ${t[0][1]}`;{l=l||ro;let r="",i,n;switch(s){case"straight":r+=`M ${t[0][0]} ${t[0][1]}`;for(let o=1;o<t.length;++o)r+=` L ${t[o][0]} ${t[o][1]}`;break;case"bezier":i=e,r+=`M ${t[0][0]} ${t[0][1]}`;for(let o=1;o<t.length;++o){if(o+1>=t.length)switch(a){case f.Bottom:n=f.Top;break;case f.Top:n=f.Bottom;break;case f.Right:n=f.Left;break;case f.Left:n=f.Right;break}else Math.abs(t[o][0]-t[o-1][0])<Math.abs(t[o][1]-t[o-1][1])?t[o][1]>t[o-1][1]?n=f.Bottom:n=f.Top:t[o][0]>t[o-1][0]?n=f.Right:n=f.Left;if(i!==void 0){let d="",c="";const h=(Math.abs(t[o][0]-t[o-1][0])+Math.abs(t[o][1]-t[o-1][1]))/2;switch(i){case f.Bottom:d=`${t[o-1][0]} ${t[o-1][1]+h}`;break;case f.Top:d=`${t[o-1][0]} ${t[o-1][1]-h}`;break;case f.Right:d=`${t[o-1][0]+h} ${t[o-1][1]}`;break;case f.Left:d=`${t[o-1][0]-h} ${t[o-1][1]}`;break}if(n!==void 0){switch(n){case f.Top:c=`${t[o][0]} ${t[o][1]+h}`;break;case f.Bottom:c=`${t[o][0]} ${t[o][1]-h}`;break;case f.Left:c=`${t[o][0]+h} ${t[o][1]}`;break;case f.Right:c=`${t[o][0]-h} ${t[o][1]}`;break}r+=` C ${d} ${c} ${t[o][0]} ${t[o][1]}`}else r+=` Q ${d} ${t[o][0]} ${t[o][1]}`}else if(n!==void 0){let d="";const c=(Math.abs(t[o][0]-t[o-1][0])+Math.abs(t[o][1]-t[o-1][1]))/2;switch(n){case f.Top:d=`${t[o][0]} ${t[o][1]+c}`;break;case f.Bottom:d=`${t[o][0]} ${t[o][1]-c}`;break;case f.Left:d=`${t[o][0]+c} ${t[o][1]}`;break;case f.Right:d=`${t[o][0]-c} ${t[o][1]}`;break}r+=` Q ${d} ${t[o][0]} ${t[o][1]}`}else r+=` L ${t[o][0]} ${t[o][1]}`;i=n}break;case"square":i=e,r+=`M ${t[0][0]} ${t[0][1]}`;for(let o=1;o<t.length;++o){if(o+1>=t.length)switch(a){case f.Bottom:n=f.Top;break;case f.Top:n=f.Bottom;break;case f.Right:n=f.Left;break;case f.Left:n=f.Right;break}switch(i){case f.Bottom:switch(n){case f.Bottom:t[o][1]>t[o-1][1]?(t[o][0]!==t[o-1][0]?(r+=` V ${(t[o][1]+t[o-1][1])/2}`,r+=` H ${t[o][0]}`,r+=` V ${t[o][1]}`):r+=` V ${t[o][1]}`,i=n):t[o][0]>t[o-1][0]?(r+=` V ${t[o-1][1]+l}`,r+=` H ${Math.max(t[o-1][0],t[o][0])+l}`,r+=` V ${t[o][1]-l}`,r+=` H ${t[o][0]}`,r+=` V ${t[o][1]}`):(r+=` V ${t[o-1][1]+l}`,r+=` H ${Math.min(t[o-1][0],t[o][0])-l}`,r+=` V ${t[o][1]-l}`,r+=` H ${t[o][0]}`,r+=` V ${t[o][1]}`);break;case f.Top:r+=` V ${Math.max(t[o-1][1],t[o][1])+l}`,r+=` H ${t[o][0]}`,r+=` V ${t[o][1]}`;break;case f.Left:t[o][1]>t[o-1][1]+l?t[o][0]<t[o-1][0]-l?(r+=` V ${t[o][1]}`,r+=` H ${t[o][0]}`):(r+=` V ${(t[o-1][1]+t[o][1])/2}`,r+=` H ${t[o][0]+l}`,r+=` V ${t[o][1]}`,r+=` H ${t[o][0]}`):t[o][0]<t[o-1][0]-l?(r+=` V ${t[o-1][1]+l}`,r+=` H ${(t[o-1][0]+t[o][0])/2}`,r+=` V ${t[o][1]}`,r+=` H ${t[o][0]}`):(r+=` V ${t[o-1][1]+l}`,r+=` H ${t[o][0]+l}`,r+=` V ${t[o][1]}`,r+=` H ${t[o][0]}`);break;case f.Right:t[o][1]>t[o-1][1]+l?t[o][0]>t[o-1][0]+l?(r+=` V ${t[o][1]}`,r+=` H ${t[o][0]}`):(r+=` V ${(t[o-1][1]+t[o][1])/2}`,r+=` H ${t[o][0]-l}`,r+=` V ${t[o][1]}`,r+=` H ${t[o][0]}`):t[o][0]>t[o-1][0]+l?(r+=` V ${t[o-1][1]+l}`,r+=` H ${(t[o-1][0]+t[o][0])/2}`,r+=` V ${t[o][1]}`,r+=` H ${t[o][0]}`):(r+=` V ${t[o-1][1]+l}`,r+=` H ${t[o][0]-l}`,r+=` V ${t[o][1]}`,r+=` H ${t[o][0]}`);break;default:t[o][1]<t[o-1][1]+l?(r+=` V ${t[o-1][1]+l}`,t[o][0]!==t[o-1][0]&&(r+=` H ${t[o][0]}`),r+=` V ${t[o][1]}`,i=f.Top):(r+=` V ${t[o][1]}`,i=f.Bottom,t[o][0]!==t[o-1][0]&&(r+=` H ${t[o][0]}`,i=t[o][0]>t[o-1][0]?f.Right:f.Left));break}break;case f.Top:switch(n){case f.Top:t[o][1]<t[o-1][1]?(t[o][0]!==t[o-1][0]?(r+=` V ${(t[o][1]+t[o-1][1])/2}`,r+=` H ${t[o][0]}`,r+=` V ${t[o][1]}`):r+=` V ${t[o][1]}`,i=n):t[o][0]<t[o-1][0]?(r+=` V ${t[o-1][1]-l}`,r+=` H ${Math.min(t[o-1][0],t[o][0])-l}`,r+=` V ${t[o][1]+l}`,r+=` H ${t[o][0]}`,r+=` V ${t[o][1]}`):(r+=` V ${t[o-1][1]-l}`,r+=` H ${Math.max(t[o-1][0],t[o][0])+l}`,r+=` V ${t[o][1]+l}`,r+=` H ${t[o][0]}`,r+=` V ${t[o][1]}`);break;case f.Bottom:r+=` V ${Math.min(t[o-1][1],t[o][1])-l}`,r+=` H ${t[o][0]}`,r+=` V ${t[o][1]}`;break;case f.Right:t[o][1]<t[o-1][1]-l?t[o][0]>t[o-1][0]+l?(r+=` V ${t[o][1]}`,r+=` H ${t[o][0]}`):(r+=` V ${(t[o-1][1]+t[o][1])/2}`,r+=` H ${t[o][0]-l}`,r+=` V ${t[o][1]}`,r+=` H ${t[o][0]}`):t[o][0]>t[o-1][0]+l?(r+=` V ${t[o-1][1]-l}`,r+=` H ${(t[o-1][0]+t[o][0])/2}`,r+=` V ${t[o][1]}`,r+=` H ${t[o][0]}`):(r+=` V ${t[o-1][1]-l}`,r+=` H ${t[o][0]-l}`,r+=` V ${t[o][1]}`,r+=` H ${t[o][0]}`);break;case f.Left:t[o][1]<t[o-1][1]-l?t[o][0]<t[o-1][0]-l?(r+=` V ${t[o][1]}`,r+=` H ${t[o][0]}`):(r+=` V ${(t[o-1][1]+t[o][1])/2}`,r+=` H ${t[o][0]+l}`,r+=` V ${t[o][1]}`,r+=` H ${t[o][0]}`):t[o][0]<t[o-1][0]-l?(r+=` V ${t[o-1][1]-l}`,r+=` H ${(t[o-1][0]+t[o][0])/2}`,r+=` V ${t[o][1]}`,r+=` H ${t[o][0]}`):(r+=` V ${t[o-1][1]-l}`,r+=` H ${t[o][0]+l}`,r+=` V ${t[o][1]}`,r+=` H ${t[o][0]}`);break;default:t[o][1]>t[o-1][1]-l?(r+=` V ${t[o-1][1]-l}`,t[o][0]!==t[o-1][0]&&(r+=` H ${t[o][0]}`),r+=` V ${t[o][1]}`,i=f.Bottom):(r+=` V ${t[o][1]}`,i=f.Top,t[o][0]!==t[o-1][0]&&(r+=` H ${t[o][0]}`,i=t[o][0]>t[o-1][0]?f.Right:f.Left));break}break;case f.Left:switch(n){case f.Left:t[o][0]<t[o-1][0]?(t[o][1]!==t[o-1][1]?(r+=` H ${(t[o][0]+t[o-1][0])/2}`,r+=` V ${t[o][1]}`,r+=` H ${t[o][0]}`):r+=` H ${t[o][0]}`,i=n):t[o][1]<t[o-1][1]?(r+=` H ${t[o-1][0]-l}`,r+=` V ${Math.min(t[o-1][1],t[o][1])-l}`,r+=` H ${t[o][0]+l}`,r+=` V ${t[o][1]}`,r+=` H ${t[o][0]}`):(r+=` H ${t[o-1][0]-l}`,r+=` V ${Math.max(t[o-1][1],t[o][1])+l}`,r+=` H ${t[o][0]+l}`,r+=` V ${t[o][1]}`,r+=` H ${t[o][0]}`);break;case f.Right:r+=` H ${Math.min(t[o-1][0],t[o][0])-l}`,r+=` V ${t[o][1]}`,r+=` H ${t[o][0]}`;break;case f.Bottom:t[o][0]<t[o-1][0]-l?t[o][1]>t[o-1][1]+l?(r+=` H ${t[o][0]}`,r+=` V ${t[o][1]}`):(r+=` H ${(t[o-1][0]+t[o][0])/2}`,r+=` V ${t[o][1]-l}`,r+=` H ${t[o][0]}`,r+=` V ${t[o][1]}`):t[o][1]>t[o-1][1]+l?(r+=` H ${t[o-1][0]-l}`,r+=` V ${(t[o-1][1]+t[o][1])/2}`,r+=` H ${t[o][0]}`,r+=` V ${t[o][1]}`):(r+=` H ${t[o-1][0]-l}`,r+=` V ${t[o][1]-l}`,r+=` H ${t[o][0]}`,r+=` V ${t[o][1]}`);break;case f.Top:t[o][0]<t[o-1][0]-l?t[o][1]<t[o-1][1]-l?(r+=` H ${t[o][0]}`,r+=` V ${t[o][1]}`):(r+=` H ${(t[o-1][0]+t[o][0])/2}`,r+=` V ${t[o][1]+l}`,r+=` H ${t[o][0]}`,r+=` V ${t[o][1]}`):t[o][1]<t[o-1][1]-l?(r+=` H ${t[o-1][0]-l}`,r+=` V ${(t[o-1][1]+t[o][1])/2}`,r+=` H ${t[o][0]}`,r+=` V ${t[o][1]}`):(r+=` H ${t[o-1][0]-l}`,r+=` V ${t[o][1]+l}`,r+=` H ${t[o][0]}`,r+=` V ${t[o][1]}`);break;default:t[o][0]>t[o-1][0]-l?(r+=` H ${t[o-1][0]-l}`,t[o][1]!==t[o-1][1]&&(r+=` V ${t[o][1]}`),r+=` H ${t[o][0]}`,i=f.Right):(r+=` H ${t[o][0]}`,i=f.Left,t[o][1]!==t[o-1][1]&&(r+=` V ${t[o][1]}`,i=t[o][1]>t[o-1][1]?f.Bottom:f.Top));break}break;case f.Right:switch(n){case f.Right:t[o][0]>t[o-1][0]?(t[o][1]!==t[o-1][1]?(r+=` H ${(t[o][0]+t[o-1][0])/2}`,r+=` V ${t[o][1]}`,r+=` H ${t[o][0]}`):r+=` H ${t[o][0]}`,i=n):t[o][1]>t[o-1][1]?(r+=` H ${t[o-1][0]+l}`,r+=` V ${Math.max(t[o-1][1],t[o][1])+l}`,r+=` H ${t[o][0]-l}`,r+=` V ${t[o][1]}`,r+=` H ${t[o][0]}`):(r+=` H ${t[o-1][0]+l}`,r+=` V ${Math.min(t[o-1][1],t[o][1])-l}`,r+=` H ${t[o][0]-l}`,r+=` V ${t[o][1]}`,r+=` H ${t[o][0]}`);break;case f.Left:r+=` H ${Math.max(t[o-1][0],t[o][0])+l}`,r+=` V ${t[o][1]}`,r+=` H ${t[o][0]}`;break;case f.Top:t[o][0]>t[o-1][0]+l?t[o][1]<t[o-1][1]-l?(r+=` H ${t[o][0]}`,r+=` V ${t[o][1]}`):(r+=` H ${(t[o-1][0]+t[o][0])/2}`,r+=` V ${t[o][1]+l}`,r+=` H ${t[o][0]}`,r+=` V ${t[o][1]}`):t[o][1]<t[o-1][1]-l?(r+=` H ${t[o-1][0]+l}`,r+=` V ${(t[o-1][1]+t[o][1])/2}`,r+=` H ${t[o][0]}`,r+=` V ${t[o][1]}`):(r+=` H ${t[o-1][0]+l}`,r+=` V ${t[o][1]+l}`,r+=` H ${t[o][0]}`,r+=` V ${t[o][1]}`);break;case f.Bottom:t[o][0]>t[o-1][0]+l?t[o][1]>t[o-1][1]+l?(r+=` H ${t[o][0]}`,r+=` V ${t[o][1]}`):(r+=` H ${(t[o-1][0]+t[o][0])/2}`,r+=` V ${t[o][1]-l}`,r+=` H ${t[o][0]}`,r+=` V ${t[o][1]}`):t[o][1]>t[o-1][1]+l?(r+=` H ${t[o-1][0]+l}`,r+=` V ${(t[o-1][1]+t[o][1])/2}`,r+=` H ${t[o][0]}`,r+=` V ${t[o][1]}`):(r+=` H ${t[o-1][0]+l}`,r+=` V ${t[o][1]-l}`,r+=` H ${t[o][0]}`,r+=` V ${t[o][1]}`);break;default:t[o][0]<t[o-1][0]+l?(r+=` H ${t[o-1][0]+l}`,t[o][1]!==t[o-1][1]&&(r+=` V ${t[o][1]}`),r+=` H ${t[o][0]}`,i=f.Left):(r+=` H ${t[o][0]}`,i=f.Right,t[o][1]!==t[o-1][1]&&(r+=` V ${t[o][1]}`,i=t[o][1]>t[o-1][1]?f.Bottom:f.Top));break}break;default:t[o][0]!==t[o-1][0]&&(r+=` H ${t[o][0]}`,i=t[o][0]>t[o-1][0]?f.Right:f.Left),t[o][1]!==t[o-1][1]&&(r+=` V ${t[o][1]}`,i=t[o][1]>t[o-1][1]?f.Bottom:f.Top)}}break}return r}},he=(s,t)=>{switch(s){case"dotted":return`${t}`;case"dashed":return`${4*t} ${t}`;case"gapped-dashes":return`${4*t} ${4*t}`;default:return"none"}},B=(s,t)=>{const e=s.indexOf(t);return e>=0&&s.splice(e,1),s};var Tt=(s=>(s.Ellipse="ellipse",s.Empty="empty",s.Folder="folder",s.Hexagon="hexagon",s.Octagon="octagon",s.Pill="pill",s.Rectangle="rectangle",s.Rhombus="rhombus",s.RoundedRectangle="rounded-rectangle",s.StickyNote="sticky-note",s))(Tt||{});const ge=(s,t,e,a,l)=>{if(typeof s=="function")return s(t,e,a,l);switch(s){case"ellipse":return Oe(t,e,a,l);case"empty":return lo();case"folder":return co(t,e,a,l);case"hexagon":return ho(t,e,a,l);case"octagon":return go(t,e,a,l);case"pill":return Yt(t,e,a,l);case"rectangle":return xe(t,e,a,l);case"rhombus":return fo(t,e,a,l);case"rounded-rectangle":return uo(t,e,a,l);case"sticky-note":return po(t,e,a,l);default:return xe(t,e,a,l)}},Oe=(s,t,e,a)=>`M ${s+e/2} ${t} A ${e/2} ${a/2} 0 0 0 ${s+e/2} ${t+a} A ${e/2} ${a/2} 0 1 0 ${s+e/2} ${t} Z`,lo=()=>"Z",co=(s,t,e,a)=>`M ${s} ${t} L ${s+e/3} ${t} L ${s+e/2} ${t+a/6} L ${s+e} ${t+a/6} L ${s+e} ${t+a} L ${s} ${t+a} Z`,ho=(s,t,e,a)=>`M ${s+e/4} ${t} L ${s+3*e/4} ${t} L ${s+e} ${t+a/2} L ${s+3*e/4} ${t+a} L ${s+e/4} ${t+a} L ${s} ${t+a/2} Z`,go=(s,t,e,a)=>`M ${s+e/4} ${t} L ${s+3*e/4} ${t} L ${s+e} ${t+a/4} L ${s+e} ${t+3*a/4} L ${s+3*e/4} ${t+a} L ${s+e/4} ${t+a} L ${s} ${t+3*a/4} L ${s} ${t+a/4} L ${s+e/4} ${t} Z`,Yt=(s,t,e,a)=>a<e?`M ${s+a/2} ${t} L ${s+e-a/2} ${t} A ${a/2} ${a/2} 0 0 1 ${s+e} ${t+a/2} A ${a/2} ${a/2} 0 0 1 ${s+e-a/2} ${t+a} L ${s+a/2} ${t+a} A ${a/2} ${a/2} 0 0 1 ${s} ${t+a/2} A ${a/2} ${a/2} 0 0 1 ${s+a/2} ${t} Z`:a>e?`M ${s} ${t+e/2} L ${s} ${t+a-e/2} A ${e/2} ${e/2} 0 0 0 ${s+e/2} ${t+a} A ${e/2} ${e/2} 0 0 0 ${s+e} ${t+a-e/2} L ${s+e} ${t+e/2} A ${e/2} ${e/2} 0 0 0 ${s+e/2} ${t} A ${e/2} ${e/2} 0 0 0 ${s} ${t+e/2} Z`:Oe(s,t,e,a),xe=(s,t,e,a)=>`M ${s} ${t} L ${s+e} ${t} L ${s+e} ${t+a} L ${s} ${t+a} Z`,fo=(s,t,e,a)=>`M ${s+e/2} ${t} L ${s+e} ${t+a/2} L ${s+e/2} ${t+a} L ${s} ${t+a/2} Z`,uo=(s,t,e,a)=>`M ${s+e/4} ${t} L ${s+3*e/4} ${t} A ${e/4} ${a/4} 0 0 1 ${s+e} ${t+a/4} L ${s+e} ${t+3*a/4} A ${e/4} ${a/4} 0 0 1 ${s+3*e/4} ${t+a} L ${s+e/4} ${t+a} A ${e/4} ${a/4} 0 0 1 ${s} ${t+3*a/4} L ${s} ${t+a/4} A ${e/4} ${a/4} 0 0 1 ${s+e/4} ${t} Z`,po=(s,t,e,a)=>`M ${s} ${t} L ${s+3*e/4} ${t} L ${s+3*e/4} ${t+a/4} L ${s+3*e/4} ${t} L ${s+e} ${t+a/4} L ${s+3*e/4} ${t+a/4} L ${s+e} ${t+a/4} L ${s+e} ${t+a} L ${s} ${t+a} Z`;var L=(s=>(s.AllScroll="all-scroll",s.Auto="auto",s.Crosshair="crosshair",s.EWResize="ew-resize",s.Grab="grab",s.Grabbing="grabbing",s.Move="move",s.NoDrop="no-drop",s.NSResize="ns-resize",s.NotAllowed="not-allowed",s.ZoomIn="zoom-in",s.ZoomOut="zoom-out",s))(L||{});const mo=s=>Math.max(...s.split(`
2
- `).map(t=>t.length)),vo=s=>s.match(/\n/g)?.length||0,Z=[];for(let s=0;s<256;++s)Z.push((s+256).toString(16).slice(1));function yo(s,t=0){return(Z[s[t+0]]+Z[s[t+1]]+Z[s[t+2]]+Z[s[t+3]]+"-"+Z[s[t+4]]+Z[s[t+5]]+"-"+Z[s[t+6]]+Z[s[t+7]]+"-"+Z[s[t+8]]+Z[s[t+9]]+"-"+Z[s[t+10]]+Z[s[t+11]]+Z[s[t+12]]+Z[s[t+13]]+Z[s[t+14]]+Z[s[t+15]]).toLowerCase()}let oe;const bo=new Uint8Array(16);function ko(){if(!oe){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");oe=crypto.getRandomValues.bind(crypto)}return oe(bo)}const wo=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),Ce={randomUUID:wo};function So(s,t,e){s=s||{};const a=s.random??s.rng?.()??ko();if(a.length<16)throw new Error("Random bytes length must be >= 16");return a[6]=a[6]&15|64,a[8]=a[8]&63|128,yo(a)}function $e(s,t,e){return Ce.randomUUID&&!s?Ce.randomUUID():So(s)}const St=s=>{if(typeof s!="object")return s;if(Array.isArray(s))return s.map(St);const t={};for(const e of Object.entries(s))t[e[0]]=St(e[1]);return t},nt=s=>{const{selected:t,highlighted:e,selectedAndHighlighted:a,...l}=s,r=l,i={...r,...t},n={...r,...e},o={...r,...e,...t,...a};return{defaultLook:r,selectedLook:i,highlightedLook:n,selectedAndHighlightedLook:o}};class Kt{constructor(){this.entities=[],this.entityMap={}}get length(){return this.size()}all(){return[...this.entities]}add(t){this.entityMap[t.id]===void 0&&(this.entityMap[t.id]=t,this.entities.push(t))}clear(){for(;this.entities.length>0;)this.remove(this.entities[0].id)}contains(t){return this.entityMap[t]!==void 0}count(t){return this.entities.filter(t).length}filter(t){return this.entities.filter(t)}find(t){return this.entities.find(t)}get(t){return this.entityMap[t]}map(t){return this.entities.map(t)}remove(t){const e=this.get(t);e!==void 0&&(delete this.entityMap[t],B(this.entities,e))}size(){return this.entities.length}*[Symbol.iterator](){for(const t of this.entities)yield t}}const Nt=0;class Ct{constructor(t,e){this.selfRemoved=!1,this.selfRemovedTimestamp=null,this.model=t,this._id=e}get id(){return this._id}get highlighted(){return this.model.canvas?.userHighlight?.contains(this.id)||!1}get selected(){return this.model.canvas?.userSelection?.contains(this.id)||!1}select(){return this.model.canvas?.selectCanvasView()?.select(`[id='${ce(this.id)}']`)}}class gt extends Kt{all(t=!1){return t?super.all():super.filter(e=>!e.removed)}contains(t,e=!1){return e?super.contains(t):super.contains(t)&&!this.entityMap[t].removed}count(t,e=!1){return e?super.count(t):super.count((a,l,r)=>t(a,l,r)&&!a.removed)}filter(t,e=!1){return e?super.filter(t):super.filter((a,l,r)=>t(a,l,r)&&!a.removed)}find(t,e=!1){return e?super.find(t):super.find((a,l,r)=>t(a,l,r)&&!a.removed)}get(t,e=!1){return e?super.get(t):this.contains(t)?super.get(t):void 0}map(t,e=!1){return e?super.map(t):super.filter(a=>!a.removed).map(t)}remove(t){const e=this.get(t,!0);e!==void 0&&(delete this.entityMap[t],B(this.entities,e))}size(t=!1){return t?super.size():super.filter(e=>!e.removed).length}*[Symbol.iterator](t=!1){if(t)for(const e of this.entities)yield e;else for(const e of this.entities.filter(a=>!a.removed))yield e}}class xo{constructor(t,e,a,l,r,i,n){this.name=t,this.label=e,this.type=a,this.defaultValue=l,this.basic=r,this.editable=i,this.rootAttribute=n,this.options=void 0,this.properties=void 0}}var N=(s=>(s.Boolean="boolean",s.Color="color",s.Date="date",s.Datetime="datetime",s.Number="number",s.Object="object",s.Option="option",s.OptionList="option-list",s.OptionSet="option-set",s.Text="text",s.TextArea="text-area",s.TextList="text-list",s.TextSet="text-set",s.TextMap="text-map",s.Time="time",s.Url="url",s))(N||{});class qt{constructor(t=[]){this.propertyList=t,this.propertyMap={};for(const e of this.propertyList)this.propertyMap[e.name]=e}getProperty(t){return this.propertyMap[t]}hasProperty(t){return this.propertyMap[t]!==void 0}hasProperties(){return this.propertyList.length>0}}function bt(s,t){return!t||s[0]>t[0]?!0:s[0]===t[0]?s[1]>=t[1]:!1}const Ie=s=>s==null||s===""||s instanceof Array&&s.length===0||s instanceof Object&&Object.keys(s).length===0,wt=(s,t)=>s===t||JSON.stringify(s)===JSON.stringify(t),_e=(s,t,e)=>{const a={},l={};for(const r in e.propertySet.propertyMap)if(e.propertySet.propertyMap[r].type===N.Object){const i=_e(s[r],t[r],e.getSubValueSet(r));Object.keys(i[0]).length>0&&Object.keys(i[1]).length>0&&(a[r]=i[0],l[r]=i[1])}else wt(s[r],t[r])||(a[r]=s[r],l[r]=t[r]);return[a,l]},Co=s=>s!=null&&s.constructor===Object;class vt{constructor(t,e){this.displayedProperties=[],this.hiddenProperties=[],this.values={},this.valueSets={},this.ownTimestamps={},this.propertySet=t,this.rootElement=e,this.resetValues()}getRootElementValue(t){if(this.rootElement){if(typeof t=="string")return this.rootElement[t];if(Array.isArray(t)&&t.length>0){let e=this.rootElement;for(const a of t){if(e==null)return;e=e[a]}return e}}}setRootElementValue(t,e){if(this.rootElement){if(typeof t=="string"&&(this.rootElement[t]=e),Array.isArray(t)&&t.length>0){let a=this.rootElement;for(let l=0;l<t.length-1;++l){const r=t[l];if(a==null)return;a=a[r]}if(a==null)return;a[t[t.length-1]]=e}typeof this.rootElement.updateInView=="function"&&this.rootElement.updateInView()}}getValue(t){const e=this.propertySet.getProperty(t)?.rootAttribute;return e!=null&&(this.values[t]=this.getRootElementValue(e)),this.propertySet.getProperty(t).type===N.Object?this.valueSets[t].getValues():this.values[t]}getValues(){const t={};for(const e in this.propertySet.propertyMap)this.propertySet.getProperty(e).type===N.Object?t[e]=this.valueSets[e].getValues():t[e]=this.getValue(e);return t}getValuesForKeys(t){const e={};for(const a in t)this.propertySet.getProperty(a).type===N.Object?e[a]=this.valueSets[a].getValuesForKeys(t[a]):e[a]=this.getValue(a);return e}getTimestamps(){const t={};for(const e in this.propertySet.propertyMap)if(this.propertySet.getProperty(e).type===N.Object)t[e]=this.valueSets[e].getTimestamps();else{const l=this.ownTimestamps[e];l&&(t[e]=l)}return t}hasValue(t){const e=this.getValue(t);return!Ie(e)}hasSetValue(t){const e=this.getValue(t),a=this.propertySet.getProperty(t);return a&&a.type===N.Object?this.getSubValueSet(t).hasAnySetValue():!Ie(e)&&!wt(e,a?.defaultValue)}hasAnySetValue(){for(const t of this.propertySet.propertyList)if(this.hasSetValue(t.name))return!0;return!1}setValue(t,e){const a=this.propertySet.getProperty(t);if(a){a.type===N.Object?this.valueSets[t].setValues(e):(this.values[t]=e,wt(e,a.defaultValue)||this.displayProperty(a));const l=a.rootAttribute;l!=null&&this.setRootElementValue(l,e)}}setValues(t){this.resetValues();for(const e in t)this.propertySet.getProperty(e).type===N.Object?this.valueSets[e].setValues(t[e]):this.setValue(e,t[e])}setTimestamps(t){this.ownTimestamps={};for(const e in t)this.propertySet.getProperty(e).type===N.Object?this.valueSets[e].setTimestamps(t[e]):this.ownTimestamps[e]=t[e]}overwriteValues(t){for(const e in t)this.propertySet.getProperty(e).type===N.Object?this.valueSets[e].overwriteValues(t[e]):this.setValue(e,t[e])}overwriteValuesLww(t,e){for(const a in t)this.propertySet.getProperty(a).type===N.Object?this.valueSets[a].overwriteValuesLww(t[a],e):bt(e,this.ownTimestamps[a])&&(this.setValue(a,t[a]),this.ownTimestamps[a]=e)}resetValues(){this.displayedProperties=[],this.hiddenProperties=[],this.ownTimestamps={};for(const t in this.propertySet.propertyMap){const e=this.propertySet.getProperty(t),a=e.rootAttribute;e.type===N.Object?this.valueSets[t]=this.constructSubValueSet(t):this.values[t]=St(e.defaultValue),a!=null&&e.defaultValue!==void 0&&!wt(this.getRootElementValue(a),e.defaultValue)&&this.setRootElementValue(a,this.values[t]),e.basic!==!1?this.displayedProperties.push(e):this.hiddenProperties.push(e)}}constructSubValueSet(t){const e=this.propertySet.getProperty(t),a=new qt(e.properties),l=new vt(a,this.rootElement);return l.overwriteValues(St(e.defaultValue)),l}getSubValueSet(t){return this.valueSets[t]}displayProperty(t){this.displayedProperties.includes(t)||(this.displayedProperties.push(t),B(this.hiddenProperties,t))}hideProperty(t){this.hiddenProperties.includes(t)||(this.hiddenProperties.push(t),B(this.displayedProperties,t))}}const ot={name:"",label:null,look:{lookType:"connection-look",color:"#000000",thickness:1,shape:Ve.Straight,style:pe.Solid,selected:{color:"#AA00AA"},highlighted:{thickness:2}},startMarkerLook:void 0,endMarkerLook:void 0,startTypes:[],endTypes:[],properties:[]};class He{constructor(t){const e={...ot,...t};this.id=e.id,this.name=e.name,this.label=e.label;const a=nt(e.look);if(this.defaultLook=a.defaultLook,this.selectedLook=a.selectedLook,this.highlightedLook=a.highlightedLook,this.selectedAndHighlightedLook=a.selectedAndHighlightedLook,e.startMarkerLook!==void 0){const l=nt(e.startMarkerLook);this.defaultStartMarkerLook=l.defaultLook,this.selectedStartMarkerLook=l.selectedLook,this.highlightedStartMarkerLook=l.highlightedLook,this.selectedAndHighlightedStartMarkerLook=l.selectedAndHighlightedLook}else this.defaultStartMarkerLook=null,this.selectedStartMarkerLook=null,this.highlightedStartMarkerLook=null,this.selectedAndHighlightedStartMarkerLook=null;if(e.endMarkerLook!==void 0){const l=nt(e.endMarkerLook);this.defaultEndMarkerLook=l.defaultLook,this.selectedEndMarkerLook=l.selectedLook,this.highlightedEndMarkerLook=l.highlightedLook,this.selectedAndHighlightedEndMarkerLook=l.selectedAndHighlightedLook}else this.defaultEndMarkerLook=null,this.selectedEndMarkerLook=null,this.highlightedEndMarkerLook=null,this.selectedAndHighlightedEndMarkerLook=null;this.startTypes=e.startTypes,this.endTypes=e.endTypes,this.propertySet=new qt(e.properties)}canStartFromType(t){return this.startTypes.indexOf(t)>=0}canFinishOnType(t){return this.endTypes.indexOf(t)>=0}}class lt extends Ct{constructor(t,e,a,l,r){if(t.connections.get(r)!==void 0)throw new Error(`DiagramConnection with id "${r}" already exists`);if(!r)throw new Error("DiagramConnection cannot have an empty or null id");super(t,r),this.startCoords=[0,0],this.endCoords=[0,0],this.startLabel="",this.middleLabel="",this.endLabel="",this.points=[],this._type=e,this.valueSet=new vt(e.propertySet,this),this.originalData={},this.setStart(a),this.setEnd(l)}get type(){return this._type}set type(t){t!==this._type&&(this._type=t,this.valueSet&&(this.valueSet=new vt(t.propertySet,this)),this.model.canvas?.userSelection?.openInPropertyEditor(this,!1),this.updateInView())}get typeString(){return this.type.id}set typeString(t){if(t!==this.type.id){const e=this.model.connections.types.get(t);e&&(this.type=e)}}get name(){return this.middleLabel}set name(t){this.middleLabel=t}get look(){return this.selected?this.highlighted?this._selectedAndHighlightedLook!==void 0?this._selectedAndHighlightedLook:this.type.selectedAndHighlightedLook:this._selectedLook!==void 0?this._selectedLook:this.type.selectedLook:this.highlighted?this._highlightedLook!==void 0?this._highlightedLook:this.type.highlightedLook:this._defaultLook!==void 0?this._defaultLook:this.type.defaultLook}set look(t){this.lookConfig=t}get lookConfig(){return this._lookConfig}set lookConfig(t){if(this._lookConfig=t,t){const e=nt(t);this._defaultLook={...this._defaultLook,...e.defaultLook},this._selectedLook={...this._selectedLook,...e.selectedLook},this._highlightedLook={...this._highlightedLook,...e.highlightedLook},this._selectedAndHighlightedLook={...this._selectedAndHighlightedLook,...e.selectedAndHighlightedLook}}else this._defaultLook=t,this._selectedLook=t,this._highlightedLook=t,this._selectedAndHighlightedLook=t}get startMarkerLook(){return this.selected?this.highlighted?this._selectedAndHighlightedStartMarkerLook!==void 0?this._selectedAndHighlightedStartMarkerLook:this.type.selectedAndHighlightedStartMarkerLook:this._selectedStartMarkerLook!==void 0?this._selectedStartMarkerLook:this.type.selectedStartMarkerLook:this.highlighted?this._highlightedStartMarkerLook!==void 0?this._highlightedStartMarkerLook:this.type.highlightedStartMarkerLook:this._defaultStartMarkerLook!==void 0?this._defaultStartMarkerLook:this.type.defaultStartMarkerLook}set startMarkerLook(t){this.startMarkerLookConfig=t}get startMarkerLookConfig(){return this._startMarkerLookConfig}set startMarkerLookConfig(t){if(this._startMarkerLookConfig=t,t){const e=nt(t);this._defaultStartMarkerLook={...this._defaultStartMarkerLook,...e.defaultLook},this._selectedStartMarkerLook={...this._selectedStartMarkerLook,...e.selectedLook},this._highlightedStartMarkerLook={...this._highlightedStartMarkerLook,...e.highlightedLook},this._selectedAndHighlightedStartMarkerLook={...this._selectedAndHighlightedStartMarkerLook,...e.selectedAndHighlightedLook}}else this._defaultStartMarkerLook=t,this._selectedStartMarkerLook=t,this._highlightedStartMarkerLook=t,this._selectedAndHighlightedStartMarkerLook=t}get endMarkerLook(){return this.selected?this.highlighted?this._selectedAndHighlightedEndMarkerLook!==void 0?this._selectedAndHighlightedEndMarkerLook:this.type.selectedAndHighlightedEndMarkerLook:this._selectedEndMarkerLook!==void 0?this._selectedEndMarkerLook:this.type.selectedEndMarkerLook:this.highlighted?this._highlightedEndMarkerLook!==void 0?this._highlightedEndMarkerLook:this.type.highlightedEndMarkerLook:this._defaultEndMarkerLook!==void 0?this._defaultEndMarkerLook:this.type.defaultEndMarkerLook}set endMarkerLook(t){this.endMarkerLookConfig=t}get endMarkerLookConfig(){return this._endMarkerLookConfig}set endMarkerLookConfig(t){if(this._endMarkerLookConfig=t,t){const e=nt(t);this._defaultEndMarkerLook={...this._defaultEndMarkerLook,...e.defaultLook},this._selectedEndMarkerLook={...this._selectedEndMarkerLook,...e.selectedLook},this._highlightedEndMarkerLook={...this._highlightedEndMarkerLook,...e.highlightedLook},this._selectedAndHighlightedEndMarkerLook={...this._selectedAndHighlightedEndMarkerLook,...e.selectedAndHighlightedLook}}else this._defaultEndMarkerLook=t,this._selectedEndMarkerLook=t,this._highlightedEndMarkerLook=t,this._selectedAndHighlightedEndMarkerLook=t}get removed(){return this.selfRemoved||this.start!==void 0&&this.start.removed||this.end!==void 0&&this.end.removed}updateInView(){this.model.canvas?.updateConnectionsInView(this.id)}raise(){this.select()?.raise()}setStart(t){this.start!==t?(this.start!==void 0&&B(this.start.outgoingConnections,this),this.start=t,t!==void 0&&(t.outgoingConnections.push(this),this.startDirection=t?.direction,this.startCoords=t?.connectionPoint||[0,0])):(this.startDirection=t?.direction,this.startCoords=t?.connectionPoint||[0,0]),this.updateInView()}setEnd(t){this.end!==t?(this.end!==void 0&&B(this.end.incomingConnections,this),this.end=t,t!==void 0&&(t.incomingConnections.push(this),this.endDirection=t?.direction,this.endCoords=t?.connectionPoint||[0,0])):(this.endDirection=t?.direction,this.endCoords=t?.connectionPoint||[0,0]),this.updateInView()}tighten(){const t=this.model.canvas?.allowConnectionLoops||!1,e=this.model.canvas?.allowSharingPorts!==!1,a=this.model.canvas?.allowSharingBothPorts||!1;if(this.start?.rootElement&&this.end){const l=this.start.rootElement.ports.map(r=>[r,r.distanceTo(this.end.coords)]).sort((r,i)=>r[1]-i[1]).map(r=>r[0]);t:for(const r of l){if(!t&&r===this.end||!r.allowsOutgoing||!e&&(r.incomingConnections.filter(i=>!i.removed&&i!==this).length>0||r.outgoingConnections.filter(i=>!i.removed&&i!==this).length>0))continue t;if(!a){for(const i of r.outgoingConnections.filter(n=>!n.removed))if(i!==this&&i.end===this.end)continue t;for(const i of r.incomingConnections.filter(n=>!n.removed))if(i!==this&&i.start===this.end)continue t}if(r===this.start)break t;this.setStart(r);break t}}if(this.end?.rootElement&&this.start){const l=this.end.rootElement.ports.map(r=>[r,r.distanceTo(this.start.coords)]).sort((r,i)=>r[1]-i[1]).map(r=>r[0]);t:for(const r of l){if(!t&&r===this.start||!r.allowsIncoming||!e&&(r.incomingConnections.filter(i=>!i.removed&&i!==this).length>0||r.outgoingConnections.filter(i=>!i.removed&&i!==this).length>0))continue t;if(!a){for(const i of r.incomingConnections.filter(n=>!n.removed))if(i!==this&&i.start===this.start)continue t;for(const i of r.outgoingConnections.filter(n=>!n.removed))if(i!==this&&i.end===this.start)continue t}if(r===this.end)break t;this.setEnd(r);break t}}}getPriority(){return this.start?this.end?Math.min(this.start.getPriority(),this.end.getPriority()):this.start.getPriority():this.end?this.end.getPriority():Nt}}class $o extends gt{constructor(t){super(),this.types=new Kt,this.model=t}new(t,e,a,l){let r;if(t instanceof He)r=t;else{const n=this.types.get(t);if(n===void 0)throw new TypeError(`Connection type with id '${t}' could not be found.`);r=n}const i=new lt(this.model,r,e,a,l);return super.add(i),i.updateInView(),i.valueSet.resetValues(),i}remove(t){const e=this.get(t,!0);e&&(B(e.start?.outgoingConnections||[],e),B(e.end?.incomingConnections||[],e),super.remove(t),e.updateInView())}}const O={editable:!0,fontSize:0,margin:0,padding:0,fontFamily:"'Wonder Unit Sans', sans-serif",color:"#000000",selectedColor:"#000000",backgroundColor:"#00000000",horizontalAlign:Lt.Center,verticalAlign:Xt.Center,orientation:f.Top,fit:!1,shrink:!0};class ct extends Ct{constructor(t,e,a,l,r,i,n,o,d,c,h,u,b,m,x,g){const v=`${e?.id}_field`;if(t.fields.get(v)!==void 0)throw new Error("DiagramField for rootElement already exists");if(super(t,v),this.textTimestamp=null,this.rootElement=e,this.coords=a,this.width=l,this.height=r,this.fontSize=i,this.fontFamily=n,this.color=o,this.selectedColor=d,this.horizontalAlign=c,this.verticalAlign=h,!isNaN(Number(u)))this.orientation=Number(u);else switch(u){case f.Top:this.orientation=0;break;case f.Right:this.orientation=90;break;case f.Bottom:this.orientation=180;break;case f.Left:this.orientation=270;break;default:this.orientation=0}this.defaultText=b,this._text=b,this.editable=m,this.fit=x,this.shrink=g}get text(){return this._text}set text(t){(t==null||t?.trim()==="")&&(t=this.defaultText),this._text=t,this.updateInView(),this.fit&&this.model.canvas?.fitFieldRootInView(this.id,this.shrink)}get removed(){return this.selfRemoved||this.rootElement!==void 0&&this.rootElement.removed}updateInView(){this.model.canvas?.updateFieldsInView(this.id)}raise(){this.select()?.raise()}move(t){this.coords=t,this.updateInView()}getPriority(){return this.rootElement?.getPriority()||Nt}}class Io extends gt{constructor(t){super(),this.model=t}new(t,e,a,l,r,i,n,o,d,c,h,u,b,m,x){const g=new ct(this.model,t,e,n,o,a,l,r,i,d,c,h,u,b,m,x);return super.add(g),g.updateInView(),t!==void 0&&(t.label=g),g}remove(t){const e=this.get(t,!0);e&&(e.rootElement?.label!==void 0&&e.rootElement.label===e&&(e.rootElement.label=void 0),super.remove(t),e.updateInView())}}const q=s=>s?.margin===null||s?.margin===void 0?O.margin:typeof s.margin=="number"?s.margin:s.margin.length===0?O.margin:s.margin.length===1||s.margin.length===2?s.margin[0]:(s.margin.length===3,s.margin[2]),D=s=>s?.margin===null||s?.margin===void 0?O.margin:typeof s.margin=="number"?s.margin:s.margin.length===0?O.margin:s.margin.length===1?s.margin[0]:s.margin.length===2||s.margin.length===3?s.margin[1]:s.margin[3],it=s=>s?.margin===null||s?.margin===void 0?O.margin:typeof s.margin=="number"?s.margin:s.margin.length===0?O.margin:s.margin.length===1?s.margin[0]:(s.margin.length===2||s.margin.length===3,s.margin[1]),G=s=>s?.margin===null||s?.margin===void 0?O.margin:typeof s.margin=="number"?s.margin:s.margin.length===0?O.margin:(s.margin.length===1||s.margin.length===2||s.margin.length===3,s.margin[0]),Vt=s=>s?.padding===null||s?.padding===void 0?O.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?O.padding:s.padding.length===1||s.padding.length===2?s.padding[0]:(s.padding.length===3,s.padding[2]),Ot=s=>s?.padding===null||s?.padding===void 0?O.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?O.padding:s.padding.length===1?s.padding[0]:s.padding.length===2||s.padding.length===3?s.padding[1]:s.padding[3],_t=s=>s?.padding===null||s?.padding===void 0?O.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?O.padding:s.padding.length===1?s.padding[0]:(s.padding.length===2||s.padding.length===3,s.padding[1]),Ht=s=>s?.padding===null||s?.padding===void 0?O.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?O.padding:(s.padding.length===1||s.padding.length===2||s.padding.length===3,s.padding[0]),Ae=1,Le=1,Ao=1,Lo=1;class Eo{constructor(t){this.margin=t.margin||0,this.defaultWidths=t.defaultWidths||null,this.defaultHeights=t.defaultHeights||null,this.minWidths=t.minWidths||null,this.minHeights=t.minHeights||null,this.sections=[];for(const e of t.sections){const a=[];this.sections.push(a);for(const l of e)a.push(new Mo(l))}}}class Mo{constructor(t){this.label=t.label||null,this.ports=t.ports||[],this.priority=t.priority||Nt,this.resizableX=t.resizableX,this.resizableY=t.resizableY;const e=nt(t.look||je);this.defaultLook=e.defaultLook,this.selectedLook=e.selectedLook,this.highlightedLook=e.highlightedLook,this.selectedAndHighlightedLook=e.selectedAndHighlightedLook}}class U extends Ct{constructor(t,e,a,l,r,i,n,o){if(t.sections.get(o)!==void 0)throw new Error(`DiagramSection with id "${o}" already exists`);if(!o)throw new Error("DiagramSection cannot have an empty or null id");super(t,o),this.ports=[],this.decorators=[],this.node=e,this.indexXInNode=a,this.indexYInNode=l,this.coords=r,this.width=i,this.height=n}get name(){return this.label?.text||""}set name(t){this.label&&(this.label.text=t)}get look(){return this.selected?this.highlighted?this._selectedAndHighlightedLook!==void 0?this._selectedAndHighlightedLook:this.type?.selectedAndHighlightedLook||this.node?.look:this._selectedLook!==void 0?this._selectedLook:this.type?.selectedLook||this.node?.look:this.highlighted?this._highlightedLook!==void 0?this._highlightedLook:this.type?.highlightedLook||this.node?.look:this._defaultLook!==void 0?this._defaultLook:this.type?.defaultLook||this.node?.look}set look(t){this.lookConfig=t}get lookConfig(){return this._lookConfig}set lookConfig(t){if(this._lookConfig=t,t){const e=nt(t);this._defaultLook={...this._defaultLook,...e.defaultLook},this._selectedLook={...this._selectedLook,...e.selectedLook},this._highlightedLook={...this._highlightedLook,...e.highlightedLook},this._selectedAndHighlightedLook={...this._selectedAndHighlightedLook,...e.selectedAndHighlightedLook}}else this._defaultLook=t,this._selectedLook=t,this._highlightedLook=t,this._selectedAndHighlightedLook=t}get removed(){return this.selfRemoved||this.node!==void 0&&this.node.removed}updateInView(){this.model.canvas?.updateSectionsInView(this.id)}raise(){this.select()?.raise(),this.label&&this.label.raise();for(const t of this.ports)t.raise();for(const t of this.decorators)t.raise()}get type(){return this.node?.type?.sectionGrid?.sections?.[this.indexYInNode]?.[this.indexXInNode]}getMinWidth(){return this.node?.type?.sectionGrid?.minWidths?.[this.indexXInNode]||Ao}getMinHeight(){return this.node?.type?.sectionGrid?.minHeights?.[this.indexYInNode]||Lo}getPriority(){return this.node?.type?.sectionGrid?.sections?.[this.indexYInNode]?.[this.indexXInNode]?.priority||Nt}getResizableX(){const t=this.type;return t?.resizableX!==void 0?t.resizableX:this.node?.type?.resizableX||!1}getResizableY(){const t=this.type;return t?.resizableY!==void 0?t.resizableY:this.node?.type?.resizableY||!1}getClosestPortToPoint(t){if(this.ports.length!==0){if(this.ports.length===1)return this.ports[1];{const e=this.ports.map(r=>r.distanceTo(t)),a=e.indexOf(Math.min(...e));return this.ports[a]}}}getIncomingConnections(t=!1){const e=[];for(const a of this.ports)for(const l of a.incomingConnections)!t&&l.removed||e.push(l);return e}getOutgoingConnections(t=!1){const e=[];for(const a of this.ports)for(const l of a.outgoingConnections)!t&&l.removed||e.push(l);return e}getConnections(t=!1){const e=[];for(const a of this.ports){for(const l of a.incomingConnections)!t&&l.removed||e.push(l);for(const l of a.outgoingConnections)!t&&l.removed||e.push(l)}return e}move(t){this.setGeometry({coords:t,width:this.width,height:this.height})}stretch(t,e){const a=[this.coords[0],this.coords[0]+this.width],l=[this.coords[1],this.coords[1]+this.height];let r,i;switch(t){case f.Left:r=[a[0]-e,a[1]],i=[l[0],l[1]],r[1]-r[0]<this.getMinWidth()&&(r[0]=r[1]-this.getMinWidth());break;case f.Top:r=[a[0],a[1]],i=[l[0]-e,l[1]],i[1]-i[0]<this.getMinHeight()&&(i[0]=i[1]-this.getMinHeight());break;case f.Right:r=[a[0],a[1]+e],i=[l[0],l[1]],r[1]-r[0]<this.getMinWidth()&&(r[1]=r[0]+this.getMinWidth());break;case f.Bottom:r=[a[0],a[1]],i=[l[0],l[1]+e],i[1]-i[0]<this.getMinHeight()&&(i[1]=i[0]+this.getMinHeight());break}this.setGeometry({coords:[r[0],i[0]],width:r[1]-r[0],height:i[1]-i[0]})}getGeometry(){return{coords:[...this.coords],width:this.width,height:this.height}}setGeometry(t){const e=[this.coords[0],this.coords[0]+this.width],a=[this.coords[1],this.coords[1]+this.height];this.coords=[...t.coords],this.width=t.width,this.height=t.height;const l=[this.coords[0],this.coords[0]+this.width],r=[this.coords[1],this.coords[1]+this.height];for(const n of this.ports)n.move(Wt(n.coords,e,a,l,r,n.anchorPointX,n.anchorPointY));const i=this.type;this.label&&(this.label.coords=[this.coords[0]+D(i?.label),this.coords[1]+G(i?.label)],this.label.width=this.width-D(i?.label)-it(i?.label),this.label.height=this.height-G(i?.label)-q(i?.label),this.label.updateInView());for(const n of this.decorators)n.move(Wt(n.coords,e,a,l,r,n.anchorPointX,n.anchorPointY));this.model.canvas?.autoTightenConnections!==!1&&this.getConnections().forEach(n=>n.tighten()),this.updateInView()}}class To extends gt{constructor(t){super(),this.model=t}new(t,e,a,l,r,i,n){const o=new U(this.model,t,e,a,l,r,i,n);super.add(o),o.updateInView(),t.sections.push(o),t.updateInView();const d=t.type.sectionGrid?.sections?.[a]?.[e]?.ports;if(d&&d.length>0)for(let h=0;h<d.length;++h){const u=d[h],b=this.model.ports.new(u.type!==void 0?this.model.ports.types.get(u.type):void 0,o,[o.coords[0]+(u.coords[0]||0),o.coords[1]+(u.coords[1]||0)],u.connectionPoint!==void 0?[o.coords[0]+(u.connectionPoint[0]||0),o.coords[1]+(u.connectionPoint[1]||0)]:void 0,u?.direction,`${o.id}_${h}`,u.anchorPointX||"floating",u.anchorPointY||"floating");if(b.type?.label){const m={...O,...b.type?.label},x=6*m.fontSize+Ot(m)+_t(m),g=m.fontSize+Ht(m)+Vt(m);let v;switch(b.direction){case f.Bottom:case f.Left:case f.Right:v=[b.coords[0]-x/2,b.coords[1]-g-q(m)];break;case f.Top:v=[b.coords[0]-x/2,b.coords[1]+G(m)];break;default:v=b.coords}this.model.fields.new(b,v,m.fontSize,m.fontFamily,m.color,m.selectedColor,x,g,m.horizontalAlign,m.verticalAlign,m.orientation,"",m.editable,m.fit,m.shrink)}}const c=t.type.sectionGrid?.sections?.[a]?.[e]?.label;if(c){const h={...O,...c};this.model.fields.new(o,[o.coords[0]+D(h),o.coords[1]+G(h)],h.fontSize,h.fontFamily,h.color,h.selectedColor,o.width-D(h)-it(h),o.height-G(h)-q(h),h.horizontalAlign,h.verticalAlign,h.orientation,"",h.editable,h.fit,h.shrink)}return o}remove(t){const e=this.get(t,!0);if(e){for(;e.ports.length>0;)this.model.ports.remove(e.ports[0].id);e.label&&this.model.fields.remove(e.label.id),e.node&&B(e.node.sections,e),super.remove(t),e.updateInView()}}}const je={lookType:"shaped-look",shape:Tt.Rectangle,fillColor:"#FFFFFF",borderColor:"#000000",borderThickness:1,selected:{fillColor:"#FFAAFF",borderColor:"#AA00AA"},highlighted:{borderThickness:3}},ht={name:"",defaultWidth:1,defaultHeight:1,minWidth:1,minHeight:1,resizableX:!1,resizableY:!1,snapToGridOffset:[0,0,0,0],padding:0,label:null,ports:[],decorators:[],sectionGrid:null,look:je,isUnique:!1,canBeParentless:!0,childrenTypes:[],priority:Nt,properties:[]};class Ge{constructor(t){const e={...ht,...t};this.id=e.id,this.name=e.name,this.defaultWidth=e.defaultWidth,this.defaultHeight=e.defaultHeight,this.minWidth=e.minWidth,this.minHeight=e.minHeight,this.resizableX=e.resizableX,this.resizableY=e.resizableY,this.snapToGridOffset=e.snapToGridOffset,this.bottomPadding=Po(e),this.leftPadding=zo(e),this.rightPadding=Ro(e),this.topPadding=Vo(e),this.label=e.label,this.ports=e.ports,this.decorators=e.decorators,this.sectionGrid=e.sectionGrid?new Eo(e.sectionGrid):null;const a=nt(e.look);this.defaultLook=a.defaultLook,this.selectedLook=a.selectedLook,this.highlightedLook=a.highlightedLook,this.selectedAndHighlightedLook=a.selectedAndHighlightedLook,this.isUnique=e.isUnique,this.canBeParentless=e.canBeParentless,this.childrenTypes=e.childrenTypes,this.priority=e.priority,this.propertySet=new qt(t?.properties||[])}}class z extends Ct{constructor(t,e,a=[0,0],l){if(t.nodes.get(l)!==void 0)throw new Error(`DiagramNode with id "${l}" already exists`);if(!l)throw new Error("DiagramNode cannot have an empty or null id");super(t,l),this.children=[],this.sections=[],this.ports=[],this.decorators=[],this.geometryTimestamp=null,this._type=e,this.valueSet=new vt(e.propertySet,this),this.originalData={},this.coords=a,this.width=e.defaultWidth,this.height=e.defaultHeight}get type(){return this._type}set type(t){t!==this._type&&(this._type=t,this.valueSet&&(this.valueSet=new vt(t.propertySet,this)),this.model.canvas?.userSelection?.openInPropertyEditor(this,!1),this.updateInView())}get typeString(){return this.type.id}set typeString(t){if(t!==this.type.id){const e=this.model.nodes.types.get(t);e&&(this.type=e)}}get name(){return this.label?.text||""}set name(t){this.label&&(this.label.text=t)}get look(){return this.selected?this.highlighted?this._selectedAndHighlightedLook!==void 0?this._selectedAndHighlightedLook:this.type.selectedAndHighlightedLook:this._selectedLook!==void 0?this._selectedLook:this.type.selectedLook:this.highlighted?this._highlightedLook!==void 0?this._highlightedLook:this.type.highlightedLook:this._defaultLook!==void 0?this._defaultLook:this.type.defaultLook}set look(t){this.lookConfig=t}get lookConfig(){return this._lookConfig}set lookConfig(t){if(this._lookConfig=t,t){const e=nt(t);this._defaultLook={...this._defaultLook,...e.defaultLook},this._selectedLook={...this._selectedLook,...e.selectedLook},this._highlightedLook={...this._highlightedLook,...e.highlightedLook},this._selectedAndHighlightedLook={...this._selectedAndHighlightedLook,...e.selectedAndHighlightedLook}}else this._defaultLook=t,this._selectedLook=t,this._highlightedLook=t,this._selectedAndHighlightedLook=t}get removed(){return this.selfRemoved}updateInView(){this.model.canvas?.updateNodesInView(this.id)}raise(){this.select()?.raise();for(const t of this.sections)t.raise();this.label&&this.label.raise();for(const t of this.ports)t.raise();for(const t of this.decorators)t.raise();for(const t of this.children)t.raise()}getPriority(){return this.type.priority}getClosestPortToPoint(t){if(this.ports.length!==0){if(this.ports.length===1)return this.ports[1];{const e=this.ports.map(r=>r.distanceTo(t)),a=e.indexOf(Math.min(...e));return this.ports[a]}}}getIncomingConnections(t=!1){const e=[];for(const a of this.ports)for(const l of a.incomingConnections)!t&&l.removed||e.push(l);return e}getOutgoingConnections(t=!1){const e=[];for(const a of this.ports)for(const l of a.outgoingConnections)!t&&l.removed||e.push(l);return e}getConnections(t=!1){const e=[];for(const a of this.ports){for(const l of a.incomingConnections)!t&&l.removed||e.push(l);for(const l of a.outgoingConnections)!t&&l.removed||e.push(l)}return e}getAdjacentNodes(t=!1){const e=[];for(const a of this.ports){for(const l of a.incomingConnections){if(!t&&l.removed)continue;const r=l.start?.getNode();if(r){if(!t&&r.removed)continue;e.push(r)}}for(const l of a.outgoingConnections){if(!t&&l.removed)continue;const r=l.end?.getNode();if(r){if(!t&&r.removed)continue;e.push(r)}}}return e}getLastAncestor(){let t=this;for(;t.parent!==void 0;)t=t?.parent;return t}isAncestorOf(t){let e=t;for(;e!==void 0;){if(this.id===e.id)return!0;e=e.parent}return!1}isDescendantOf(t){return t.isAncestorOf(this)}addChild(t){if(t.id===this.id)return;let e=this.parent,a=!1;for(;e!==void 0;){if(e.id===t.id){a=!0;break}e=e.parent}a||this.children.indexOf(t)>=0||(this.fitToChild(t),this.children.push(t),t.parent=this,t.raise())}removeChild(t){B(this.children,t),t.parent=void 0}fitToChild(t){const e=Math.max(...this.sections.map(o=>o.indexXInNode)),a=Math.max(...this.sections.map(o=>o.indexYInNode)),l=this.coords[0]-t.coords[0]+this.type.leftPadding;l>=0&&(this.sections.length>0?this.stretchSections(f.Left,l,e,a):this.stretch(f.Left,l));const r=this.coords[1]-t.coords[1]+this.type.topPadding;r>=0&&(this.sections.length>0?this.stretchSections(f.Top,r,e,a):this.stretch(f.Top,r));const i=t.coords[0]+t.width-(this.coords[0]+this.width)+this.type.rightPadding;i>=0&&(this.sections.length>0?this.stretchSections(f.Right,i,e,a):this.stretch(f.Right,i));const n=t.coords[1]+t.height-(this.coords[1]+this.height)+this.type.bottomPadding;n>=0&&(this.sections.length>0?this.stretchSections(f.Bottom,n,e,a):this.stretch(f.Bottom,n)),this.parent&&this.parent.fitToChild(this)}move(t){const e=[t[0]-this.coords[0],t[1]-this.coords[1]];for(const a of this.children)a.move([a.coords[0]+e[0],a.coords[1]+e[1]]);for(const a of this.sections)a.move([a.coords[0]+e[0],a.coords[1]+e[1]]);this.setGeometry({coords:t,width:this.width,height:this.height,sections:{},children:{}})}stretch(t,e){const a=[this.coords[0],this.coords[0]+this.width],l=[this.coords[1],this.coords[1]+this.height];let r,i;switch(t){case f.Left:r=[a[0]-e,a[1]],i=[l[0],l[1]],r[1]-r[0]<this.type.minWidth&&(r[0]=r[1]-this.type.minWidth);break;case f.Top:r=[a[0],a[1]],i=[l[0]-e,l[1]],i[1]-i[0]<this.type.minHeight&&(i[0]=i[1]-this.type.minHeight);break;case f.Right:r=[a[0],a[1]+e],i=[l[0],l[1]],r[1]-r[0]<this.type.minWidth&&(r[1]=r[0]+this.type.minWidth);break;case f.Bottom:r=[a[0],a[1]],i=[l[0],l[1]+e],i[1]-i[0]<this.type.minHeight&&(i[1]=i[0]+this.type.minHeight);break}this.setGeometry({coords:[r[0],i[0]],width:r[1]-r[0],height:i[1]-i[0],sections:{},children:{}})}stretchSections(t,e,a,l){let r=Number.NEGATIVE_INFINITY;switch(t){case f.Bottom:for(const i of this.sections)i.indexYInNode===l&&(r=Math.max(r,i.getMinHeight()-i.height));e<r&&(e=r);for(const i of this.sections)i.indexYInNode===l?i.stretch(t,e):i.indexYInNode>l&&i.move([i.coords[0],i.coords[1]+e]);break;case f.Right:for(const i of this.sections)i.indexXInNode===a&&(r=Math.max(r,i.getMinWidth()-i.width));e<r&&(e=r);for(const i of this.sections)i.indexXInNode===a?i.stretch(t,e):i.indexXInNode>a&&i.move([i.coords[0]+e,i.coords[1]]);break;case f.Top:for(const i of this.sections)i.indexYInNode===l&&(r=Math.max(r,i.getMinHeight()-i.height));e<r&&(e=r);for(const i of this.sections)i.indexYInNode===l?i.stretch(t,e):i.indexYInNode<l&&i.move([i.coords[0],i.coords[1]-e]);break;case f.Left:for(const i of this.sections)i.indexXInNode===a&&(r=Math.max(r,i.getMinWidth()-i.width));e<r&&(e=r);for(const i of this.sections)i.indexXInNode===a?i.stretch(t,e):i.indexXInNode<a&&i.move([i.coords[0]-e,i.coords[1]]);break}this.stretch(t,e)}getGeometry(t){const e={};for(const l of this.sections)e[l.id]=l.getGeometry();const a={};for(const l of this.children)l.id!==t&&(a[l.id]=l.getGeometry(t));return{coords:[...this.coords],width:this.width,height:this.height,sections:e,children:a}}setGeometry(t){this.raise();const e=[this.coords[0],this.coords[0]+this.width],a=[this.coords[1],this.coords[1]+this.height];this.coords=[...t.coords],this.width=t.width,this.height=t.height;const l=[this.coords[0],this.coords[0]+this.width],r=[this.coords[1],this.coords[1]+this.height];for(const i of this.children){const n=t.children[i.id];n&&i.setGeometry(n)}for(const i of this.sections){const n=t.sections[i.id];n&&i.setGeometry(n)}for(const i of this.ports)i.move(Wt(i.coords,e,a,l,r,i.anchorPointX,i.anchorPointY));this.label&&(this.label.coords=[this.coords[0]+D(this.type.label),this.coords[1]+G(this.type.label)],this.label.width=this.width-D(this.type.label)-it(this.type.label),this.label.height=this.height-G(this.type.label)-q(this.type.label),this.label.updateInView());for(const i of this.decorators)i.move(Wt(i.coords,e,a,l,r,i.anchorPointX,i.anchorPointY));this.model.canvas?.autoTightenConnections!==!1&&this.getConnections().forEach(i=>i.tighten()),this.updateInView()}removeSectionColumn(t){const e=this.type.sectionGrid?.margin||0;let a=0;const l=[...this.sections];for(const r of l)r.indexYInNode===t&&(a=Math.max(a,r.width),this.model.sections.remove(r.id));for(const r of l)r.indexYInNode>t&&(--r.indexYInNode,r.move([r.coords[0]-a-e,r.coords[1]]));this.stretch(f.Right,-e-a)}removeSectionRow(t){const e=this.type.sectionGrid?.margin||0;let a=0;const l=[...this.sections];for(const r of l)r.indexXInNode===t&&(a=Math.max(a,r.height),this.model.sections.remove(r.id));for(const r of l)r.indexYInNode>t&&(--r.indexXInNode,r.move([r.coords[0],r.coords[1]-a-e]));this.stretch(f.Bottom,-e-a)}copySectionColumn(t){const e=this.type.sectionGrid?.margin||0;let a=0;const l=[...this.sections];for(const r of l)if(r.indexXInNode===t){a=Math.max(a,r.width);let i=r.indexXInNode+1;for(;this.model.sections.get(`${r.id}_copy_${i}_${r.indexYInNode}`,!0)!==void 0;)++i;this.model.sections.new(this,r.indexXInNode+1,r.indexYInNode,[r.coords[0]+r.width+e,r.coords[1]],r.width,r.height,`${r.id}_copy_${i}_${r.indexYInNode}`)}for(const r of l)r.indexXInNode>t&&(++r.indexXInNode,r.move([r.coords[0]+a+e,r.coords[1]]));this.stretch(f.Right,e+a)}copySectionRow(t){const e=this.type.sectionGrid?.margin||0;let a=0;const l=[...this.sections];for(const r of l)if(r.indexYInNode===t){a=Math.max(a,r.height);let i=r.indexYInNode+1;for(;this.model.sections.get(`${r.id}_copy_${r.indexXInNode}_${i}`,!0)!==void 0;)++i;this.model.sections.new(this,r.indexXInNode,r.indexYInNode+1,[r.coords[0],r.coords[1]+r.height+e],r.width,r.height,`${r.id}_copy_${r.indexXInNode}_${i}`)}for(const r of l)r.indexYInNode>t&&(++r.indexYInNode,r.move([r.coords[0],r.coords[1]+a+e]));this.stretch(f.Bottom,e+a)}}class No extends gt{constructor(t){super(),this.types=new Kt,this.model=t}new(t,e,a){let l;if(t instanceof Ge)l=t;else{const i=this.types.get(t);if(i===void 0)throw new TypeError(`Node type with id '${t}' could not be found.`);l=i}const r=new z(this.model,l,e,a);if(super.add(r),r.updateInView(),l.sectionGrid!==null){let i=r.coords[1]+(l.sectionGrid.margin||0);for(let n=0;n<l.sectionGrid.sections.length;++n){let o=r.coords[0]+(l.sectionGrid.margin||0);for(let d=0;d<l.sectionGrid.sections[n].length;++d)this.model.sections.new(r,d,n,[o,i],l.sectionGrid.defaultWidths?.[d]||Ae,l.sectionGrid.defaultHeights?.[n]||Le,`${r.id}_${n}_${d}`),o+=(l.sectionGrid.defaultWidths?.[d]||Ae)+(l.sectionGrid.margin||0);i+=(l.sectionGrid.defaultHeights?.[n]||Le)+(l.sectionGrid.margin||0)}}if(l.ports.length>0)for(let i=0;i<l.ports.length;++i){const n=l.ports[i],o=n.type!==void 0?this.model.ports.types.get(n.type):void 0,d=this.model.ports.new(o,r,[r.coords[0]+n.coords[0],r.coords[1]+n.coords[1]],n.connectionPoint!==void 0?[r.coords[0]+(n.connectionPoint[0]||0),r.coords[1]+(n.connectionPoint[1]||0)]:void 0,n.direction,`${r.id}_port_${i}`,n.anchorPointX||"floating",n.anchorPointY||"floating");if(d.type?.label){const c={...O,...d.type?.label},h=6*c.fontSize+Ot(c)+_t(c),u=c.fontSize+Ht(c)+Vt(c);let b;switch(d.direction){case f.Bottom:case f.Left:case f.Right:b=[d.coords[0]-h/2,d.coords[1]-u-q(c)];break;case f.Top:b=[d.coords[0]-h/2,d.coords[1]+G(c)];break;default:b=d.coords}this.model.fields.new(d,b,c.fontSize,c.fontFamily,c.color,c.selectedColor,h,u,c.horizontalAlign,c.verticalAlign,c.orientation,"",c.editable,c.fit,c.shrink)}}if(l.label){const i={...O,...l.label};this.model.fields.new(r,[r.coords[0]+D(i),r.coords[1]+G(i)],i.fontSize,i.fontFamily,i.color,i.selectedColor,r.width-D(i)-it(i),r.height-G(i)-q(i),i.horizontalAlign,i.verticalAlign,i.orientation,"",i.editable,i.fit,i.shrink)}if(l.decorators.length>0)for(let i=0;i<l.decorators.length;++i){const n=l.decorators[i];this.model.decorators.new(r,[r.coords[0]+n.coords[0],r.coords[1]+n.coords[1]],n.width,n.height,r.getPriority(),n.html,`${r.id}_decorator_${i}`,n.anchorPointX||"floating",n.anchorPointY||"floating")}return r.valueSet.resetValues(),r.model.canvas?.fitNodeInView(r.id),r}remove(t){const e=this.get(t,!0);if(e){for(e.parent&&B(e.parent.children,e);e.children.length>0;)this.model.nodes.remove(e.children[0].id);for(;e.sections.length>0;)this.model.sections.remove(e.sections[0].id);for(;e.ports.length>0;)this.model.ports.remove(e.ports[0].id);for(;e.decorators.length>0;)this.model.decorators.remove(e.decorators[0].id);e.label&&this.model.fields.remove(e.label.id),super.remove(t),e.updateInView()}}getAtCoordinates(t,e){const a=[];for(const l of this)l.coords[0]<t&&t<l.coords[0]+l.width&&l.coords[1]<e&&e<l.coords[1]+l.height&&a.push(l);return a}}const Fe=s=>{for(let t=0;t<s.length;++t)for(let e=0;e<s.length;++e)e!==t&&s[e].isAncestorOf(s[t])&&(s.splice(e,1),--e,t>e&&--t);return s},Po=s=>s?.padding===null||s?.padding===void 0?ht.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?ht.padding:s.padding.length===1||s.padding.length===2?s.padding[0]:(s.padding.length===3,s.padding[2]),zo=s=>s?.padding===null||s?.padding===void 0?ht.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?ht.padding:s.padding.length===1?s.padding[0]:s.padding.length===2||s.padding.length===3?s.padding[1]:s.padding[3],Ro=s=>s?.padding===null||s?.padding===void 0?ht.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?ht.padding:s.padding.length===1?s.padding[0]:(s.padding.length===2||s.padding.length===3,s.padding[1]),Vo=s=>s?.padding===null||s?.padding===void 0?ht.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?ht.padding:(s.padding.length===1||s.padding.length===2||s.padding.length===3,s.padding[0]),Ue={lookType:"shaped-look",shape:Tt.Ellipse,fillColor:"transparent",borderColor:"transparent",borderThickness:0,selected:{fillColor:"rgba(255, 0, 255, 0.5)"},highlighted:{fillColor:"rgba(0, 255, 255, 0.5)"}},Dt=nt(Ue),De={name:"",label:null,allowsOutgoing:!0,allowsIncoming:!0,width:24,look:Ue};class Oo{constructor(t){const e={...De,...t};this.id=e.id,this.name=e.name,this.label=e.label,this.allowsOutgoing=e.allowsOutgoing,this.allowsIncoming=e.allowsIncoming,this.width=e.width;const a=nt(e.look);this.defaultLook=a.defaultLook,this.selectedLook=a.selectedLook,this.highlightedLook=a.highlightedLook,this.selectedAndHighlightedLook=a.selectedAndHighlightedLook}}class yt extends Ct{constructor(t,e,a,l,r,i,n,o="floating",d="floating"){if(t.ports.get(n)!==void 0)throw new Error(`DiagramPort with id "${n}" already exists`);if(!n)throw new Error("DiagramPort cannot have an empty or null id");super(t,n),this.outgoingConnections=[],this.incomingConnections=[],this._type=e,this.rootElement=a,this.coords=l,this.connectionPoint=r||l,this.direction=i,this.anchorPointX=o,this.anchorPointY=d}get type(){return this._type}set type(t){t!==this._type&&(this._type=t,this.updateInView())}get typeString(){return this.type?.id}set typeString(t){if(t!==this.type?.id)if(t===void 0)this.type=void 0;else{const e=this.model.ports.types.get(t);e&&(this.type=e)}}get allowsOutgoing(){return this.type?.allowsOutgoing!==void 0?this.type?.allowsOutgoing:!0}get allowsIncoming(){return this.type?.allowsIncoming!==void 0?this.type?.allowsIncoming:!0}get name(){return this.label?.text||""}set name(t){this.label&&(this.label.text=t)}get look(){return this.selected?this.highlighted?this._selectedAndHighlightedLook!==void 0?this._selectedAndHighlightedLook:(this.type||Dt)?.selectedAndHighlightedLook:this._selectedLook!==void 0?this._selectedLook:(this.type||Dt)?.selectedLook:this.highlighted?this._highlightedLook!==void 0?this._highlightedLook:(this.type||Dt)?.highlightedLook:this._defaultLook!==void 0?this._defaultLook:(this.type||Dt)?.defaultLook}set look(t){this.lookConfig=t}get lookConfig(){return this._lookConfig}set lookConfig(t){if(this._lookConfig=t,t){const e=nt(t);this._defaultLook={...this._defaultLook,...e.defaultLook},this._selectedLook={...this._selectedLook,...e.selectedLook},this._highlightedLook={...this._highlightedLook,...e.highlightedLook},this._selectedAndHighlightedLook={...this._selectedAndHighlightedLook,...e.selectedAndHighlightedLook}}else this._defaultLook=t,this._selectedLook=t,this._highlightedLook=t,this._selectedAndHighlightedLook=t}get width(){return this.type?.width||De.width}get height(){return this.width}get removed(){return this.selfRemoved||this.rootElement!==void 0&&this.rootElement.removed}updateInView(){this.model.canvas?.updatePortsInView(this.id)}raise(){this.select()?.raise(),this.label&&this.label.raise();for(const t of this.incomingConnections)t.raise();for(const t of this.outgoingConnections)t.raise()}startConnection(t){this.outgoingConnections.push(t)}finishConnection(t){this.incomingConnections.push(t)}getNode(){if(this.rootElement instanceof z)return this.rootElement;if(this.rootElement instanceof U)return this.rootElement.node}getPriority(){return this.rootElement?.getPriority()||Nt}move(t){const e=[t[0]-this.coords[0],t[1]-this.coords[1]];this.coords=t,this.connectionPoint[0]=this.connectionPoint[0]+e[0],this.connectionPoint[1]=this.connectionPoint[1]+e[1];for(const a of this.outgoingConnections)a.setStart(this);for(const a of this.incomingConnections)a.setEnd(this);this.label&&this.label.move([this.label.coords[0]+e[0],this.label.coords[1]+e[1]]),this.updateInView()}distanceTo(t){return Re(this.coords,t)}}class _o extends gt{constructor(t){super(),this.types=new Kt,this.model=t}new(t,e,a,l,r,i,n="floating",o="floating"){const d=new yt(this.model,t,e,a,l,r,i,n,o);return super.add(d),d.updateInView(),e!==void 0&&e.ports.push(d),d}remove(t){const e=this.get(t,!0);if(e){for(;e.outgoingConnections.length>0;)this.model.connections.remove(e.outgoingConnections[0].id);for(;e.incomingConnections.length>0;)this.model.connections.remove(e.incomingConnections[0].id);e.label&&this.model.fields.remove(e.label.id),(e.rootElement instanceof z||e.rootElement instanceof U)&&B(e.rootElement.ports,e),super.remove(t),e.updateInView()}}}class Be{import(t,e){t.clear(),e.id&&(t.id=e.id),t.name=e.name,t.description=e.description,t.type=e.type,t.createdAt=new Date(e.createdAt),t.updatedAt=new Date(e.updatedAt);for(const a of e.nodes||[])this.importNode(t,a);for(const a of e.connections||[])this.importConnection(t,a);return e.data&&t.valueSet.setValues(e.data),e.collabMeta&&(t.logicalClock=e.collabMeta.logicalClock,t.valueSet.setTimestamps(e.collabMeta.dataTimestamps)),t}importNode(t,e){const a=t.nodes.types.get(e.type);if(a){const l=new z(t,a,e.coords,e.id);if(t.nodes.add(l),l.width=e.width,l.height=e.height,e.label){if(a.decorators)for(let i=0;i<a.decorators.length;++i){const n=a.decorators[i];t.decorators.new(l,[l.coords[0]+n.coords[0],l.coords[1]+n.coords[1]],n.width,n.height,l.getPriority(),n.html,`${l.id}_decorator_${i}`)}if(a.label){const i={...O,...a.label},n=new ct(t,l,[l.coords[0]+D(i),l.coords[1]+G(i)],l.width-D(i)-it(i),l.height-G(i)-q(i),i.fontSize,i.fontFamily,i.color,i.selectedColor,i.horizontalAlign,i.verticalAlign,i.orientation,"",i.editable,i.fit,i.shrink);n.text=e.label,l.label=n,t.fields.add(n),n.updateInView()}}for(const i of e.children||[]){const n=this.importNode(t,i);n!==void 0&&(l.children?.push(n),n.parent=l)}for(const i of e.sections||[]){const n=new U(t,l,i.indexXInNode,i.indexYInNode,i.coords,i.width,i.height,i.id);if(l.sections?.push(n),t.sections.add(n),i.label&&a.sectionGrid?.sections?.[i.indexYInNode]?.[i.indexXInNode]?.label){const d={...O,...a.sectionGrid?.sections?.[i.indexYInNode]?.[i.indexXInNode]?.label},c=new ct(t,n,[n.coords[0]+D(d),n.coords[1]+G(d)],n.width-D(d)-it(d),n.height-G(d)-q(d),d.fontSize,d.fontFamily,d.color,d.selectedColor,d.horizontalAlign,d.verticalAlign,d.orientation,"",d.editable,d.fit,d.shrink);c.text=i.label,n.label=c,t.fields.add(c),c.updateInView()}let o=0;for(const d of i.ports||[]){const c=d.type!==void 0?t.ports.types.get(d.type):void 0,h=new yt(t,c,n,d.coords,d.connectionPoint||d.coords,d.direction,d.id);if(n.ports.push(h),t.ports.add(h),d.label){if(a.ports.length>o&&c?.label){const u={...O,...c?.label};let b;switch(h.direction){case f.Top:case f.Left:b=[h.coords[0]-u.fontSize,h.coords[1]-u.fontSize];break;case f.Bottom:b=[h.coords[0]-u.fontSize,h.coords[1]+u.fontSize];break;case f.Right:b=[h.coords[0]+u.fontSize,h.coords[1]-u.fontSize];break;default:b=h.coords}const m=new ct(t,h,b,u.fontSize,u.fontSize,u.fontSize,u.fontFamily,u.color,u.selectedColor,u.horizontalAlign,u.verticalAlign,u.orientation,"",u.editable,u.fit,u.shrink);m.text=d.label,h.label=m,t.fields.add(m),m.updateInView()}++o}d.collabMeta&&(h.selfRemoved=d.collabMeta.selfRemoved,h.selfRemovedTimestamp=d.collabMeta.selfRemovedTimestamp,this.importLabelCollabMeta(h.label,d.collabMeta.label)),h.updateInView()}i.collabMeta&&(n.selfRemoved=i.collabMeta.selfRemoved,n.selfRemovedTimestamp=i.collabMeta.selfRemovedTimestamp,this.importLabelCollabMeta(n.label,i.collabMeta.label)),n.updateInView()}let r=0;for(const i of e.ports||[]){const n=i.type!==void 0?t.ports.types.get(i.type):void 0,o=new yt(t,n,l,i.coords,i.connectionPoint||i.coords,i.direction,i.id);if(l.ports.push(o),t.ports.add(o),i.label){if(a.ports.length>r&&n?.label){const d={...O,...n?.label};let c;switch(o.direction){case f.Top:case f.Left:c=[o.coords[0]-d.fontSize,o.coords[1]-d.fontSize];break;case f.Bottom:c=[o.coords[0]-d.fontSize,o.coords[1]+d.fontSize];break;case f.Right:c=[o.coords[0]+d.fontSize,o.coords[1]-d.fontSize];break;default:c=o.coords}const h=new ct(t,o,c,d.fontSize,d.fontSize,d.fontSize,d.fontFamily,d.color,d.selectedColor,d.horizontalAlign,d.verticalAlign,d.orientation,"",d.editable,d.fit,d.shrink);h.text=i.label,o.label=h,t.fields.add(h),h.updateInView()}++r}i.collabMeta&&(o.selfRemoved=i.collabMeta.selfRemoved,o.selfRemovedTimestamp=i.collabMeta.selfRemovedTimestamp,this.importLabelCollabMeta(o.label,i.collabMeta.label)),o.updateInView()}return e.data&&l.valueSet.setValues(e.data),e.collabMeta&&(l.selfRemoved=e.collabMeta.selfRemoved,l.selfRemovedTimestamp=e.collabMeta.selfRemovedTimestamp,l.geometryTimestamp=e.collabMeta.geometryTimestamp,this.importLabelCollabMeta(l.label,e.collabMeta.label),l.valueSet.setTimestamps(e.collabMeta.dataTimestamps)),l.updateInView(),l.raise(),l}}importConnection(t,e){const a=t.connections.types.get(e.type);if(a){const l=new lt(t,a,e.start?t.ports.get(e.start):void 0,e.end?t.ports.get(e.end):void 0,e.id);return t.connections.add(l),l.startLabel=e.startLabel,l.middleLabel=e.middleLabel,l.endLabel=e.endLabel,l.points=e.points,e.data&&l.valueSet.setValues(e.data),e.collabMeta&&(l.selfRemoved=e.collabMeta.selfRemoved,l.selfRemovedTimestamp=e.collabMeta.selfRemovedTimestamp,l.valueSet.setTimestamps(e.collabMeta.dataTimestamps)),l.updateInView(),l.raise(),l}}importLabelCollabMeta(t,e){t&&e&&(t.selfRemoved=e.selfRemoved,t.selfRemovedTimestamp=e.selfRemovedTimestamp,t.textTimestamp=e.textTimestamp)}}class Jt{constructor(t,e,a,l,r,i,n){this.canvas=t,this.id=e,this.typeId=a,this.coords=l,this.parentId=r,this.label=i,this.values=n}do(){const t=this.canvas.model.nodes.new(this.typeId,this.coords,this.id);this.parentId!==void 0&&this.canvas.model.nodes.get(this.parentId)?.addChild(t),t.label&&(t.label.text=this.label||""),this.values!==void 0?t.valueSet.setValues(St({...t.valueSet.getValues(),...this.values})):t.valueSet.resetValues()}serialize(){return{type:"addNode",id:this.id,typeId:this.typeId,coords:this.coords,parentId:this.parentId,label:this.label,values:this.values}}static deserialize(t,e){return new Jt(t,e.id,e.typeId,e.coords,e.parentId,e.label,e.values)}}class me{constructor(t,e,a,l,r,i,n){this.canvas=t,this.nodeId=e,this.copyColumnIndex=a,this.copyRowIndex=l,this.removeColumnIndex=r,this.removeRowIndex=i,this.timestamp=n}do(){const t=this.canvas.model.nodes.get(this.nodeId);t&&bt(this.timestamp,t.geometryTimestamp)&&(this.copyColumnIndex!==void 0&&t.copySectionColumn(this.copyColumnIndex),this.copyRowIndex!==void 0&&t.copySectionRow(this.copyRowIndex),this.removeColumnIndex!==void 0&&t.removeSectionColumn(this.removeColumnIndex),this.removeRowIndex!==void 0&&t.removeSectionRow(this.removeRowIndex),t.geometryTimestamp=this.timestamp)}serialize(){return{type:"addSection",nodeId:this.nodeId,copyColumnIndex:this.copyColumnIndex,copyRowIndex:this.copyRowIndex,removeColumnIndex:this.removeColumnIndex,removeRowIndex:this.removeRowIndex,timestamp:this.timestamp}}static deserialize(t,e){return new me(t,e.nodeId,e.copyColumnIndex,e.copyRowIndex,e.removeColumnIndex,e.removeRowIndex,e.timestamp)}}class ve{constructor(t,e,a){this.canvas=t,this.to=e,this.timestamp=a}do(){for(const t in this.to){const e=this.canvas.model.nodes.get(t,!0);if(e&&bt(this.timestamp,e.geometryTimestamp)){const a=this.to[t];e.move([a[0],a[1]]),e.geometryTimestamp=this.timestamp}}}serialize(){return{type:"applyLayout",to:this.to,timestamp:this.timestamp}}static deserialize(t,e){return new ve(t,e.to,e.timestamp)}}class jt{constructor(t,e,a,l){this.canvas=t,this.nodeIds=e,this.delta=a,this.timestamp=l}do(){for(const t of this.nodeIds){const e=this.canvas.model.nodes.get(t,!0);e&&bt(this.timestamp,e.geometryTimestamp)&&(e.move([e.coords[0]+this.delta[0],e.coords[1]+this.delta[1]]),e.parent?.fitToChild(e),e.geometryTimestamp=this.timestamp)}}serialize(){return{type:"move",nodeIds:this.nodeIds,delta:this.delta,timestamp:this.timestamp}}static deserialize(t,e){return new jt(t,e.nodeIds,e.delta,e.timestamp)}}class st{constructor(t,e,a,l){this.canvas=t,this.nodeId=e,this.to=a,this.timestamp=l}do(){const t=this.canvas.model.nodes.get(this.nodeId,!0);if(t&&bt(this.timestamp,t.geometryTimestamp)){t.setGeometry(this.to),t.label?.fit&&this.canvas.fitFieldRootInView(t.label.id,t.label.shrink);for(const e of t.sections)e.label?.fit&&this.canvas.fitFieldRootInView(e.label.id,e.label.shrink);t.parent?.fitToChild(t),t.geometryTimestamp=this.timestamp}}serialize(){return{type:"setGeometry",nodeId:this.nodeId,to:this.to,timestamp:this.timestamp}}static deserialize(t,e){return new st(t,e.nodeId,e.to,e.timestamp)}}class Gt{constructor(t,e,a,l,r){this.canvas=t,this.childId=e,this.parentId=a,this.childGeometry=l,this.timestamp=r}do(){const t=this.canvas.model.nodes.get(this.childId,!0),e=this.parentId!==void 0?this.canvas.model.nodes.get(this.parentId,!0):void 0;t&&(this.parentId===void 0||e)&&bt(this.timestamp,t.geometryTimestamp)&&(t.parent?.removeChild(t),t.setGeometry(this.childGeometry),e?.addChild(t))}serialize(){return{type:"setParent",childId:this.childId,parentId:this.parentId,childGeometry:this.childGeometry,timestamp:this.timestamp}}static deserialize(t,e){return new Gt(t,e.childId,e.parentId,e.childGeometry,e.timestamp)}}class Qt{constructor(t,e,a,l,r){this.canvas=t,this.id=e,this.typeId=a,this.startId=l,this.endId=r}do(){const t=this.canvas.model.ports.get(this.startId,!0),e=this.canvas.model.ports.get(this.endId,!0);t&&e&&this.canvas.model.connections.new(this.typeId,t,e,this.id)}serialize(){return{type:"addConnection",id:this.id,typeId:this.typeId,startId:this.startId,endId:this.endId}}static deserialize(t,e){return new Qt(t,e.id,e.typeId,e.startId,e.endId)}}class Et{constructor(t,e,a,l){this.canvas=t,this.fieldId=e,this.to=a,this.timestamp=l}do(){const t=this.canvas.model.fields.get(this.fieldId,!0);t&&bt(this.timestamp,t.textTimestamp)&&(t.text=this.to,t.textTimestamp=this.timestamp)}serialize(){return{type:"editField",fieldId:this.fieldId,to:this.to,timestamp:this.timestamp}}static deserialize(t,e){return new Et(t,e.fieldId,e.to,e.timestamp)}}class Mt{constructor(t,e,a,l){this.canvas=t,this.id=e,this.to=a,this.timestamp=l}getValueSet(){return this.id===void 0?this.canvas.model.valueSet:(this.canvas.model.nodes.get(this.id,!0)||this.canvas.model.connections.get(this.id,!0))?.valueSet}do(){this.getValueSet()?.overwriteValuesLww(this.to,this.timestamp)}serialize(){return{type:"updateValues",id:this.id,to:this.to,timestamp:this.timestamp}}static deserialize(t,e){return new Mt(t,e.id,e.to,e.timestamp)}}class rt{constructor(t,e,a,l,r,i,n,o){this.canvas=t,this.nodeIds=e,this.sectionIds=a,this.portIds=l,this.connectionIds=r,this.fieldIds=i,this.selfRemoved=n,this.timestamp=o}doOne(t){t&&bt(this.timestamp,t.selfRemovedTimestamp)&&(t.selfRemoved=this.selfRemoved,t.selfRemovedTimestamp=this.timestamp)}do(){for(const t of this.nodeIds)this.doOne(this.canvas.model.nodes.get(t,!0));for(const t of this.sectionIds)this.doOne(this.canvas.model.sections.get(t,!0));for(const t of this.portIds)this.doOne(this.canvas.model.ports.get(t,!0));for(const t of this.connectionIds)this.doOne(this.canvas.model.connections.get(t,!0));for(const t of this.fieldIds)this.doOne(this.canvas.model.fields.get(t,!0));this.canvas.updateNodesInView(...this.nodeIds),this.canvas.updateSectionsInView(...this.sectionIds),this.canvas.updatePortsInView(...this.portIds),this.canvas.updateConnectionsInView(...this.connectionIds),this.canvas.updateFieldsInView(...this.fieldIds),this.canvas.updateDecoratorsInView()}serialize(){return{type:"setSelfRemoved",nodeIds:this.nodeIds,sectionIds:this.sectionIds,portIds:this.portIds,connectionIds:this.connectionIds,fieldIds:this.fieldIds,removed:this.selfRemoved,timestamp:this.timestamp}}static deserialize(t,e){return new rt(t,e.nodeIds,e.sectionIds,e.portIds,e.connectionIds,e.fieldIds,e.removed,e.timestamp)}}class te{constructor(t,e,a){this.canvas=t,this.nodes=e,this.connections=a}do(){const t=new Be;this.canvas.userSelection.clear();for(const e of this.nodes){const a=t.importNode(this.canvas.model,e);a&&this.canvas.userSelection.add(a)}for(const e of this.connections){const a=t.importConnection(this.canvas.model,e);a&&this.canvas.userSelection.add(a)}}serialize(){return{type:"paste",nodes:this.nodes,connections:this.connections}}static deserialize(t,e){return new te(t,e.nodes,e.connections)}}class Ho{constructor(t){this.isInRoom=!1,this.canvas=t,this.replicaId=$e()}freshTimestamp(){return this.canvas.model.logicalClock++,[this.canvas.model.logicalClock,this.replicaId]}freshId(){return"id"+$e()}doCollaboratively(t){if(t.do(),this.onSend){const e=t.serialize();this.onSend(e)}}receive(t){switch("timestamp"in t&&(this.canvas.model.logicalClock=Math.max(this.canvas.model.logicalClock,t.timestamp[0])),t.type){case"addNode":{Jt.deserialize(this.canvas,t).do();break}case"addSection":{me.deserialize(this.canvas,t).do();break}case"applyLayout":{ve.deserialize(this.canvas,t).do();break}case"move":{jt.deserialize(this.canvas,t).do();break}case"setGeometry":{st.deserialize(this.canvas,t).do();break}case"setParent":{Gt.deserialize(this.canvas,t).do();break}case"addConnection":{Qt.deserialize(this.canvas,t).do();break}case"editField":{Et.deserialize(this.canvas,t).do();break}case"updateValues":{Mt.deserialize(this.canvas,t).do();break}case"setSelfRemoved":{rt.deserialize(this.canvas,t).do();break}case"paste":{te.deserialize(this.canvas,t).do();break}default:console.error("Unknown CollabAction type, skipping:",t)}}}class jo{constructor(t,e){this.canvas=t,this.maximum=e,this.history=[],this.index=0}add(t){this.index<this.history.length&&(this.history=this.history.slice(0,this.index)),this.history.length>=this.maximum?(this.history=this.history.slice(1,this.history.length),this.history.push(t)):(this.history.push(t),++this.index),this.canvas.diagramChange$.next({action:t,method:0})}undo(){let t;if(this.index>0){let e;do--this.index,t=this.history[this.index],e=t.undo();while(!e&&this.index>0)}this.canvas.diagramChange$.next({action:t,method:1})}redo(){let t;if(this.index<this.history.length){let e;do t=this.history[this.index],e=t.redo(),++this.index;while(!e&&this.index<this.history.length)}this.canvas.diagramChange$.next({action:t,method:2})}}var k=(s=>(s.AddConnection="add-connection",s.AddNode="add-node",s.AddSectionAction="add-section",s.ApplyLayout="apply-layout",s.Clipboard="clipboard",s.ContextMenu="context-menu",s.EditField="edit-field",s.MoveNode="move-node",s.Paste="paste",s.Remove="remove",s.StretchNode="stretch-node",s.StretchSection="stretch-section",s.UpdateValues="update-values",s.Zoom="zoom",s))(k||{});class Go{constructor(t,e,a,l,r,i,n,o,d){this.canvas=t,this.type=e,this.coords=a,this.parentId=l,this.ancestorId=r,this.fromAncestorGeometry=i,this.toAncestorGeometry=n,this.label=o,this.values=d,this.id=this.canvas.collabEngine.freshId()}do(){const t=new Jt(this.canvas,this.id,this.type.id,this.coords,this.parentId,this.label,this.values);if(this.canvas.collabEngine.doCollaboratively(t),this.ancestorId!==void 0&&this.toAncestorGeometry!==void 0){const e=new st(this.canvas,this.ancestorId,this.toAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(e)}return!0}undo(){const t=this.canvas.model.nodes.get(this.id),e=new rt(this.canvas,[this.id],[],[],[],[],!0,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(e),this.ancestorId!==void 0&&this.fromAncestorGeometry!==void 0){const a=new st(this.canvas,this.ancestorId,this.fromAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(a)}return t!==void 0}redo(){const t=this.canvas.model.nodes.get(this.id),e=new rt(this.canvas,[this.id],[],[],[],[],!1,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(e),this.ancestorId!==void 0&&this.toAncestorGeometry!==void 0){const a=new st(this.canvas,this.ancestorId,this.toAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(a)}return t===void 0}}class ie{constructor(t,e,a){this.canvas=t,this.nodeIds=e,this.delta=a}do(){const t=new jt(this.canvas,this.nodeIds,this.delta,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(t),this.nodeIds.map(e=>this.canvas.model.nodes.get(e)!==void 0).includes(!0)&&(this.delta[0]!==0||this.delta[1]!==0)}undo(){const t=new jt(this.canvas,this.nodeIds,[-this.delta[0],-this.delta[1]],this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(t),this.nodeIds.map(e=>this.canvas.model.nodes.get(e)!==void 0).includes(!0)&&(this.delta[0]!==0||this.delta[1]!==0)}redo(){return this.do()}}class X{constructor(t,e,a,l,r,i,n,o){this.canvas=t,this.intent=e,this.nodeId=a,this.from=l,this.to=r,this.ancestorId=i,this.fromAncestorGeometry=n,this.toAncestorGeometry=o}do(){const t=this.canvas.model.nodes.get(this.nodeId);if(t){const e=new st(this.canvas,this.nodeId,this.to,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(e),this.ancestorId!==void 0&&this.toAncestorGeometry!==void 0){const a=new st(this.canvas,this.ancestorId,this.toAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(a)}}return t!==void 0}undo(){const t=this.canvas.model.nodes.get(this.nodeId);if(t){this.to=t.getGeometry();const e=new st(this.canvas,this.nodeId,this.from,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(e),this.ancestorId!==void 0&&this.fromAncestorGeometry!==void 0){const a=new st(this.canvas,this.ancestorId,this.fromAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(a)}}return t!==void 0}redo(){const t=this.canvas.model.nodes.get(this.nodeId);if(t){this.from=t.getGeometry();const e=new st(this.canvas,this.nodeId,this.to,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(e)}return t!==void 0}}class Fo{constructor(t,e,a,l,r,i,n,o,d){this.canvas=t,this.childId=e,this.fromParentId=a,this.toParentId=l,this.fromChildGeometry=r,this.toChildGeometry=i,this.ancestorId=n,this.fromAncestorGeometry=o,this.toAncestorGeometry=d}do(){const t=this.canvas.model.nodes.get(this.childId),e=new Gt(this.canvas,this.childId,this.toParentId,this.toChildGeometry,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(e),this.ancestorId!==void 0&&this.toAncestorGeometry!==void 0){const a=new st(this.canvas,this.ancestorId,this.toAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(a)}return t!==void 0}undo(){const t=this.canvas.model.nodes.get(this.childId),e=new Gt(this.canvas,this.childId,this.fromParentId,this.fromChildGeometry,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(e),this.ancestorId!==void 0&&this.fromAncestorGeometry!==void 0){const a=new st(this.canvas,this.ancestorId,this.fromAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(a)}return t!==void 0}redo(){return this.do()}}class se{constructor(t,e,a,l){this.canvas=t,this.type=e,this.startId=a,this.endId=l,this.id=this.canvas.collabEngine.freshId()}do(){const t=new Qt(this.canvas,this.id,this.type.id,this.startId,this.endId);return this.canvas.collabEngine.doCollaboratively(t),!0}undo(){const t=this.canvas.model.connections.get(this.id),e=new rt(this.canvas,[],[],[],[this.id],[],!0,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),t!==void 0}redo(){const t=this.canvas.model.connections.get(this.id),e=new rt(this.canvas,[],[],[],[this.id],[],!1,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),t===void 0}}class Ee{constructor(t,e,a,l){this.canvas=t,this.fieldId=e,this.from=a,this.to=l}do(){const t=this.canvas.model.fields.get(this.fieldId),e=new Et(this.canvas,this.fieldId,this.to,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),t!==void 0}undo(){const t=this.canvas.model.fields.get(this.fieldId);if(t){this.to=t.text;const e=new Et(this.canvas,this.fieldId,this.from,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(e)}return t!==void 0}redo(){const t=this.canvas.model.fields.get(this.fieldId);if(t){this.from=t.text;const e=new Et(this.canvas,this.fieldId,this.to,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(e)}return t!==void 0}}class Uo{constructor(t,e,a,l){this.canvas=t,this.id=e,this.from=a,this.to=l}do(){const t=new Mt(this.canvas,this.id,this.to,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(t),!0}undo(){const t=new Mt(this.canvas,this.id,this.from,this.canvas.collabEngine.freshTimestamp()),e=t.getValueSet();if(e)this.to=e.getValuesForKeys(this.to),this.canvas.collabEngine.doCollaboratively(t);else return!1;return!e.rootElement.removed}redo(){const t=new Mt(this.canvas,this.id,this.to,this.canvas.collabEngine.freshTimestamp()),e=t.getValueSet();if(e)this.from=e.getValuesForKeys(this.from),this.canvas.collabEngine.doCollaboratively(t);else return!1;return!e.rootElement.removed}}class Do{constructor(t,e,a,l,r,i){this.canvas=t,this.nodeIds=e,this.sectionIds=a,this.portIds=l,this.connectionIds=r,this.fieldIds=i}do(){const t=this.nodeIds.map(a=>this.canvas.model.nodes.get(a)!==void 0).includes(!0)||this.sectionIds.map(a=>this.canvas.model.sections.get(a)!==void 0).includes(!0)||this.portIds.map(a=>this.canvas.model.ports.get(a)!==void 0).includes(!0)||this.connectionIds.map(a=>this.canvas.model.connections.get(a)!==void 0).includes(!0)||this.fieldIds.map(a=>this.canvas.model.fields.get(a)!==void 0).includes(!0),e=new rt(this.canvas,this.nodeIds,this.sectionIds,this.portIds,this.connectionIds,this.fieldIds,!0,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),t}undo(){const t=this.nodeIds.map(a=>this.canvas.model.nodes.get(a)===void 0).includes(!0)||this.sectionIds.map(a=>this.canvas.model.sections.get(a)===void 0).includes(!0)||this.portIds.map(a=>this.canvas.model.ports.get(a)===void 0).includes(!0)||this.connectionIds.map(a=>this.canvas.model.connections.get(a)===void 0).includes(!0)||this.fieldIds.map(a=>this.canvas.model.fields.get(a)===void 0).includes(!0),e=new rt(this.canvas,this.nodeIds,this.sectionIds,this.portIds,this.connectionIds,this.fieldIds,!1,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),t}redo(){return this.do()}}class Bo{constructor(t,e,a,l){this.canvas=t,this.nodes=e,this.connections=a,this.coords=l}do(){const t=[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY];for(const r of this.nodes)r.coords[0]<t[0]&&(t[0]=r.coords[0]),r.coords[1]<t[1]&&(t[1]=r.coords[1]);const e=this.coords!==void 0?[this.coords[0]-t[0],this.coords[1]-t[1]]:void 0,a={};for(const r of this.nodes){const i=r.id,n=this.canvas.collabEngine.freshId();if(a[i]=n,r.id=n,e&&(r.coords=[r.coords[0]+e[0],r.coords[1]+e[1]]),r.sections)for(const o of r.sections){const d=o.id;if(o.id.includes(r.id)?o.id=o.id.replace(r.id,n):o.id=this.canvas.collabEngine.freshId(),a[d]=o.id,e&&(o.coords=[o.coords[0]+e[0],o.coords[1]+e[1]]),o.ports)for(const c of o.ports){const h=c.id;c.id.includes(r.id)?c.id=c.id.replace(r.id,n):c.id=this.canvas.collabEngine.freshId(),a[h]=c.id,e&&(c.coords=[c.coords[0]+e[0],c.coords[1]+e[1]],c.connectionPoint&&(c.connectionPoint=[c.connectionPoint[0]+e[0],c.connectionPoint[1]+e[1]]))}}if(r.ports)for(const o of r.ports){const d=o.id;o.id.includes(r.id)?o.id=o.id.replace(r.id,n):o.id=this.canvas.collabEngine.freshId(),a[d]=o.id,e&&(o.coords=[o.coords[0]+e[0],o.coords[1]+e[1]],o.connectionPoint&&(o.connectionPoint=[o.connectionPoint[0]+e[0],o.connectionPoint[1]+e[1]]))}}for(const r of this.connections){const i=this.canvas.collabEngine.freshId();if(a[r.id]=i,r.id=i,r.start=a[r.start]||r.start,r.end=a[r.end]||r.end,e)for(let n=0;n<r.points.length;++n)r.points[n]=[r.points[n][0]+e[0],r.points[n][1]+e[1]]}const l=new te(this.canvas,this.nodes,this.connections);return this.canvas.collabEngine.doCollaboratively(l),!0}undo(){const t=this.nodes.map(a=>this.canvas.model.nodes.get(a.id)!==void 0).includes(!0)||this.connections.map(a=>this.canvas.model.connections.get(a.id)!==void 0).includes(!0),e=new rt(this.canvas,this.nodes.map(a=>a.id),[],[],this.connections.map(a=>a.id),[],!0,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),t}redo(){const t=this.nodes.map(a=>this.canvas.model.nodes.get(a.id)===void 0).includes(!0)||this.connections.map(a=>this.canvas.model.connections.get(a.id)===void 0).includes(!0),e=new rt(this.canvas,this.nodes.map(a=>a.id),[],[],this.connections.map(a=>a.id),[],!1,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),t}}class Ft{constructor(t){this.type=t,this.defaultPrevented=!1}preventDefault(){this.defaultPrevented=!0}}var Ye=(s=>(s[s.Zoom=0]="Zoom",s[s.DoubleClick=1]="DoubleClick",s[s.SecondaryClick=2]="SecondaryClick",s[s.Selection=3]="Selection",s[s.Highlight=4]="Highlight",s))(Ye||{});class Yo extends Ft{constructor(t,e){super(0),this.coords=t,this.zoom=e}}class ut extends Ft{constructor(t,e,a){super(1),this.cause=t,this.target=e,this.coords=a}}class pt extends Ft{constructor(t,e,a){super(2),this.cause=t,this.target=e,this.coords=a}}class H extends Ft{constructor(t,e){super(3),this.targets=t,this.selected=e}}class Q extends Ft{constructor(t){super(4),this.target=t}}class Xe extends Ct{constructor(t,e,a,l,r,i,n,o,d="floating",c="floating"){if(t.objects.get(o)!==void 0)throw new Error(`DiagramDecorator with id "${o}" already exists`);if(!o)throw new Error("DiagramDecorator cannot have an empty or null id");super(t,o),this.rootElement=e,this.coords=a,this.width=l,this.height=r,this.priority=i,this.html=n,this.anchorPointX=d,this.anchorPointY=c}get removed(){return this.selfRemoved||this.rootElement!==void 0&&this.rootElement.removed}updateInView(){this.model.canvas?.updateDecoratorsInView(this.id)}raise(){this.select()?.raise()}move(t){this.coords=t,this.updateInView()}getPriority(){return this.priority}}class Xo extends gt{constructor(t){super(),this.model=t}new(t,e,a,l,r,i,n,o="floating",d="floating"){const c=new Xe(this.model,t,e,a,l,r,i,n,o,d);return super.add(c),c.updateInView(),t!==void 0&&t.decorators.push(c),c}remove(t){const e=this.get(t,!0);e&&((e.rootElement instanceof z||e.rootElement instanceof U)&&B(e.rootElement.decorators,e),super.remove(t),e.updateInView())}}class Wo extends Ct{constructor(t,e,a,l,r,i,n){if(t.objects.get(n)!==void 0)throw new Error(`DiagramObject with id "${n}" already exists`);if(!n)throw new Error("DiagramObject cannot have an empty or null id");super(t,n),this.coords=e,this.width=a,this.height=l,this.priority=r,this.html=i}get removed(){return this.selfRemoved}updateInView(){this.model.canvas?.updateObjectsInView(this.id)}raise(){this.select()?.raise()}move(t){this.coords=t,this.updateInView()}getPriority(){return this.priority}}class Zo extends gt{constructor(t){super(),this.model=t}new(t,e,a,l,r,i){const n=new Wo(this.model,t,e,a,l,r,i);return super.add(n),n.updateInView(),n}remove(t){const e=this.get(t,!0);e&&(super.remove(t),e.updateInView())}}class We{constructor(t,e,a,l,r,i=[]){this.nodes=new No(this),this.sections=new To(this),this.ports=new _o(this),this.connections=new $o(this),this.fields=new Io(this),this.objects=new Zo(this),this.decorators=new Xo(this),this.canvas=t,this.id=e,this.name=a,this.description=l,this.type=r,this.createdAt=new Date,this.updatedAt=new Date,this.logicalClock=0,this.valueSet=new vt(new qt(i),this)}clear(){this.canvas?.cancelAllUserActions(),this.id=void 0,this.name="",this.description=void 0,this.createdAt=new Date,this.updatedAt=new Date,this.logicalClock=0,this.nodes.clear(),this.sections.clear(),this.ports.clear(),this.connections.clear(),this.fields.clear(),this.objects.clear(),this.decorators.clear(),this.valueSet.resetValues(),this.canvas?.updateModelInView()}}const mt=s=>!!s.button,ne=(s,t,e,a,l,r,i,n)=>ao(s,[t,e],a,l,Math.max(10,i||0,n||0)*r),w=s=>{s?A.select("body").style("cursor",s):A.select("body").style("cursor",L.Auto)},dt=s=>s instanceof z?s:s instanceof U?s.node||s:s.rootElement instanceof z||s.rootElement instanceof U||s.rootElement instanceof yt?dt(s.rootElement):s,re=s=>{s.filter(".shaped-look").append("path"),s.filter(".image-look").append("image").attr("preserveAspectRatio","none"),s.filter(".stretchable-image-look").append("image").attr("class","top-left-image").attr("preserveAspectRatio","none"),s.filter(".stretchable-image-look").append("image").attr("class","top-image").attr("preserveAspectRatio","none"),s.filter(".stretchable-image-look").append("image").attr("class","top-right-image").attr("preserveAspectRatio","none"),s.filter(".stretchable-image-look").append("image").attr("class","left-image").attr("preserveAspectRatio","none"),s.filter(".stretchable-image-look").append("image").attr("class","center-image").attr("preserveAspectRatio","none"),s.filter(".stretchable-image-look").append("image").attr("class","right-image").attr("preserveAspectRatio","none"),s.filter(".stretchable-image-look").append("image").attr("class","bottom-left-image").attr("preserveAspectRatio","none"),s.filter(".stretchable-image-look").append("image").attr("class","bottom-image").attr("preserveAspectRatio","none"),s.filter(".stretchable-image-look").append("image").attr("class","bottom-right-image").attr("preserveAspectRatio","none")},zt={fillColor:"#FFFFFF",borderColor:"#000000",borderThickness:1,borderStyle:pe.Solid},ae=s=>{s.filter(".shaped-look").select("path").attr("d",t=>ge(t.look.shape||Tt.Rectangle,0,0,t.width,t.height)).attr("fill",t=>t.look.fillColor||zt.fillColor).attr("stroke",t=>t.look.borderColor||zt.borderColor).attr("stroke-width",t=>`${t.look.borderThickness||zt.borderThickness}px`).attr("stroke-dasharray",t=>he(t.look.borderStyle||zt.borderStyle,t.type?.defaultLook?.borderThickness||t.look?.borderThickness||zt.borderThickness)),s.filter(".image-look").select("image").attr("x",0).attr("y",0).attr("width",t=>t.width).attr("height",t=>t.height).attr("href",t=>t.look.backgroundImage),s.filter(".stretchable-image-look").select("image.top-left-image").attr("x",0).attr("y",0).attr("width",t=>t.look.leftMargin).attr("height",t=>t.look.topMargin).attr("href",t=>t.look.backgroundImageTopLeft),s.filter(".stretchable-image-look").select("image.top-image").attr("x",t=>t.look.leftMargin).attr("y",0).attr("width",t=>t.width-t.look.rightMargin-t.look.leftMargin).attr("height",t=>t.look.topMargin).attr("href",t=>t.look.backgroundImageTop),s.filter(".stretchable-image-look").select("image.top-right-image").attr("x",t=>t.width-t.look.rightMargin).attr("y",0).attr("width",t=>t.look.rightMargin).attr("height",t=>t.look.topMargin).attr("href",t=>t.look.backgroundImageTopRight),s.filter(".stretchable-image-look").select("image.left-image").attr("x",0).attr("y",t=>t.look.topMargin).attr("width",t=>t.look.leftMargin).attr("height",t=>t.height-t.look.bottomMargin-t.look.topMargin).attr("href",t=>t.look.backgroundImageLeft),s.filter(".stretchable-image-look").select("image.center-image").attr("x",t=>t.look.leftMargin).attr("y",t=>t.look.topMargin).attr("width",t=>t.width-t.look.rightMargin-t.look.leftMargin).attr("height",t=>t.height-t.look.bottomMargin-t.look.topMargin).attr("href",t=>t.look.backgroundImageCenter),s.filter(".stretchable-image-look").select("image.right-image").attr("x",t=>t.width-t.look.rightMargin).attr("y",t=>t.look.topMargin).attr("width",t=>t.look.rightMargin).attr("height",t=>t.height-t.look.bottomMargin-t.look.topMargin).attr("href",t=>t.look.backgroundImageRight),s.filter(".stretchable-image-look").select("image.bottom-left-image").attr("x",0).attr("y",t=>t.height-t.look.bottomMargin).attr("width",t=>t.look.leftMargin).attr("height",t=>t.look.bottomMargin).attr("href",t=>t.look.backgroundImageBottomLeft),s.filter(".stretchable-image-look").select("image.bottom-image").attr("x",t=>t.look.leftMargin).attr("y",t=>t.height-t.look.bottomMargin).attr("width",t=>t.width-t.look.rightMargin-t.look.leftMargin).attr("height",t=>t.look.bottomMargin).attr("href",t=>t.look.backgroundImageBottom),s.filter(".stretchable-image-look").select("image.bottom-right-image").attr("x",t=>t.width-t.look.rightMargin).attr("y",t=>t.height-t.look.bottomMargin).attr("width",t=>t.look.rightMargin).attr("height",t=>t.look.bottomMargin).attr("href",t=>t.look.backgroundImageBottomRight)},Rt={style:"dots",color:"rgba(0, 0, 0, 0.1)",snap:!1,spacing:10,thickness:.05},Ko=(s,t,e)=>{const a=t.append("defs");if(s.gridSize>0&&isFinite(s.gridSize)){const l=a.append("pattern").attr("id",e).attr("x",-s.gridSize/2).attr("y",-s.gridSize/2).attr("width",s.gridSize).attr("height",s.gridSize).attr("patternUnits","userSpaceOnUse");switch(l.append("rect").attr("x",0).attr("y",0).attr("width",s.gridSize).attr("height",s.gridSize).attr("fill",s.backgroundColor),s.gridStyle){case"dots":l.append("circle").attr("cx",s.gridSize/2).attr("cy",s.gridSize/2).attr("r",s.gridSize*s.gridThickness).attr("fill",s.gridColor);break;case"lines":l.append("line").attr("x1",s.gridSize/2).attr("x2",s.gridSize/2).attr("y1",0).attr("y2",s.gridSize).attr("stroke-width",s.gridSize*s.gridThickness).attr("stroke",s.gridColor),l.append("line").attr("x1",0).attr("x2",(s.gridSize-s.gridSize*s.gridThickness)/2).attr("y1",s.gridSize/2).attr("y2",s.gridSize/2).attr("stroke-width",s.gridSize*s.gridThickness).attr("stroke",s.gridColor),l.append("line").attr("x1",(s.gridSize+s.gridSize*s.gridThickness)/2).attr("x2",s.gridSize).attr("y1",s.gridSize/2).attr("y2",s.gridSize/2).attr("stroke-width",s.gridSize*s.gridThickness).attr("stroke",s.gridColor);break}t.select("rect").attr("fill",`url(#${e})`)}},fe=96,W=32,At=fe+W,qo=Math.PI/4,Jo=100,Me={customButtons:[]};class Qo{constructor(t,e){this.canvas=t,this.config=e||Me}open(t){this.close();const e=this.canvas.getPointerLocationRelativeToRoot(t),a=this.canvas.getPointerLocationRelativeToCanvas(t),l=this.canvas.selectSVGElement().append("foreignObject").attr("class","daga-context-menu").attr("x",`${e[0]-At}px`).attr("y",`${e[1]-At}px`).attr("width",`${2*At}px`).attr("height",`${2*At}px`).style("pointer-events","none").on(S.ContextMenu,i=>{this.canvas.canUserPerformAction(k.ContextMenu)&&(t.preventDefault(),this.open(i))}).on(S.Click,i=>{i.preventDefault(),this.close()});this.contextMenuContainer=l;const r=[];this.canvas.userSelection.length!==0&&this.canvas.canUserPerformAction(k.Clipboard)&&this.canvas.canUserPerformAction(k.Remove)&&r.push({name:"CUT",imageClass:"daga-cut",onPress:i=>{i.userSelection.cutToClipboard(),i.cancelAllUserActions()}}),this.canvas.userSelection.length!==0&&this.canvas.canUserPerformAction(k.Clipboard)&&r.push({name:"COPY",imageClass:"daga-copy",onPress:i=>{i.userSelection.copyToClipboard(),i.cancelAllUserActions()}}),this.canvas.canUserPerformAction(k.Paste)&&r.push({name:"PASTE",imageClass:"daga-paste",onPress:i=>{i.userSelection.pasteFromClipboard(i.getClosestGridPoint(a)),i.cancelAllUserActions()}}),this.canvas.userSelection.length!==0&&this.canvas.canUserPerformAction(k.Remove)&&r.push({name:"DELETE",imageClass:"daga-delete",onPress:i=>{i.userSelection.removeFromModel(),i.cancelAllUserActions()}});for(const i of this.config.customButtons||Me.customButtons)(i.condition===void 0||i.condition(this.canvas))&&r.push(i);r.length===0&&r.push({name:"NONE",imageClass:"daga-cross",onPress:void 0});for(let i=0;i<r.length;++i){const n=r[i],o=n.onPress,d=(i+.5-r.length/2)*qo,c=l.append("xhtml:div").attr("class",`daga-context-menu-button ${n.onPress!==void 0?" daga-clickable":""}`).attr("tabindex",0).style("position","absolute").style("box-sizing","border-box").style("width",`${2*W}px`).style("height",`${2*W}px`).style("border-radius",`${W}px`).style("pointer-events","auto").on(S.Click,h=>{o&&(h.preventDefault(),o(this.canvas))}).on(S.KeyDown,h=>{o&&h.key===K.Enter&&(h.preventDefault(),o(this.canvas))});n.imageClass!==void 0?c.append("xhtml:div").style("position","absolute").style("left",`${.75*W}px`).style("top",`${.5*W}px`).style("width",`${.5*W}px`).style("height",`${.5*W}px`).style("background-size","contain").style("background-repeat","no-repeat").attr("class",n.imageClass):n.image!==void 0&&c.append("xhtml:img").style("position","absolute").style("left",`${.75*W}px`).style("top",`${.5*W}px`).style("width",`${.5*W}px`).style("height",`${.5*W}px`).attr("src",n.image),c.append("xhtml:span").style("position","absolute").style("left",`${.2*W}px`).style("top",`${1.1*W}px`).style("text-align","center").style("width",`${1.6*W}px`).style("height",`${.35*W}px`).style("margin","0").style("font-size",`${.35*W}px`).style("font-weight","700").style("user-select","none").text(n.name),c.transition().ease(A.easeLinear).duration(Jo).tween("progress",()=>h=>{const u=d*h;return c.style("left",`${Math.sin(u)*fe-W+At}px`).style("top",`${-Math.cos(u)*fe-W+At}px`)})}}close(){this.contextMenuContainer?.remove(),this.contextMenuContainer=void 0}}class ti extends gt{constructor(t,e=!0){super(),this.focus=void 0,this.canvas=t,this.highlightSections=e}getFocus(){return this.focus}focusOn(t){this.clear(),this.focus=t,(t instanceof ct||t instanceof Xe)&&t.rootElement?this.focusOn(t.rootElement):this.add(t)}add(t){if(super.add(t),t instanceof z){if(!this.highlightSections)for(const e of t.sections){super.add(e);for(const a of e.ports)super.add(a),this.canvas.updatePortsInView(a.id);e.label&&(super.add(e.label),this.canvas.updateFieldsInView(e.label.id)),this.canvas.updateSectionsInView(e.id)}for(const e of t.ports)super.add(e),this.canvas.updatePortsInView(e.id);t.label&&(super.add(t.label),this.canvas.updateFieldsInView(t.label.id)),this.canvas.updateNodesInView(t.id)}else if(t instanceof U)if(!this.highlightSections&&t.node)this.add(t.node);else{for(const e of t.ports)super.add(e),this.canvas.updatePortsInView(e.id);t.label&&(super.add(t.label),this.canvas.updateFieldsInView(t.label.id)),this.canvas.updateSectionsInView(t.id)}else t instanceof yt?(t.label&&(super.add(t.label),this.canvas.updateFieldsInView(t.label.id)),this.canvas.updatePortsInView(t.id)):t instanceof lt&&this.canvas.updateConnectionsInView(t.id)}clear(){for(;this.entities.length>0;){const t=this.entities[0];this.remove(t.id),t.updateInView()}this.focus=void 0}}const ei=1;class Ze{export(t,e=!1){const a={name:t.name,type:t.type,typeVersion:ei,createdAt:t.createdAt,updatedAt:t.updatedAt,nodes:[],connections:[],data:t.valueSet.getValues(),...e?{collabMeta:{logicalClock:t.logicalClock,dataTimestamps:t.valueSet.getTimestamps()}}:{}};t.id&&(a.id=t.id),t.description&&(a.description=t.description);for(const l of t.nodes.all(!0))!e&&l.removed||l.parent===void 0&&a.nodes.push(this.exportNode(l,e));for(const l of t.connections.all(!0))!e&&l.removed||a.connections.push(this.exportConnection(l,e));return a}exportNode(t,e=!1){const a=[];for(const i of t.children)a.push(this.exportNode(i,e));const l=[];for(const i of t.sections){const n=[];for(const o of i.ports)n.push({id:o.id,type:o.type?.id,coords:It(o.coords),connectionPoint:It(o.connectionPoint||o.coords),direction:o.direction,label:o.label?.text||"",...e?{collabMeta:{removed:o.removed,selfRemoved:o.selfRemoved,selfRemovedTimestamp:o.selfRemovedTimestamp,...this.exportLabelCollabMeta(o)}}:{}});l.push({id:i.id,ports:n,label:i.label?.text||"",indexXInNode:i.indexXInNode,indexYInNode:i.indexYInNode,coords:It(i.coords),width:i.width,height:i.height,...e?{collabMeta:{removed:i.removed,selfRemoved:i.selfRemoved,selfRemovedTimestamp:i.selfRemovedTimestamp,...this.exportLabelCollabMeta(i)}}:{}})}const r=[];for(const i of t.ports)r.push({id:i.id,type:i.type?.id,coords:It(i.coords),connectionPoint:It(i.connectionPoint||i.coords),direction:i.direction,label:i.label?.text||"",...e?{collabMeta:{removed:i.removed,selfRemoved:i.selfRemoved,selfRemovedTimestamp:i.selfRemovedTimestamp,...this.exportLabelCollabMeta(i)}}:{}});return{id:t.id,type:t.type.id,children:a,sections:l,ports:r,label:t.label?.text||"",coords:It(t.coords),width:t.width,height:t.height,data:t.valueSet.getValues(),...e?{collabMeta:{removed:t.removed,selfRemoved:t.selfRemoved,selfRemovedTimestamp:t.selfRemovedTimestamp,geometryTimestamp:t.geometryTimestamp,dataTimestamps:t.valueSet.getTimestamps(),...this.exportLabelCollabMeta(t)}}:{}}}exportConnection(t,e=!1){return{id:t.id,type:t.type.id,start:t.start?.id||"",end:t.end?.id||"",startLabel:t.startLabel,middleLabel:t.middleLabel,endLabel:t.endLabel,points:t.points,data:t.valueSet.getValues(),...e?{collabMeta:{removed:t.removed,selfRemoved:t.selfRemoved,selfRemovedTimestamp:t.selfRemovedTimestamp,dataTimestamps:t.valueSet.getTimestamps()}}:{}}}exportLabelCollabMeta({label:t}){return t?{label:{removed:t.removed,selfRemoved:t.selfRemoved,selfRemovedTimestamp:t.selfRemovedTimestamp,textTimestamp:t.textTimestamp}}:{}}}const oi="Diagram properties";class ii extends gt{constructor(t,e){super(),this.canvas=t,this.canvas.propertyEditorChanges$.pipe(kt.debounceTime(2e3)).subscribe(()=>{this.makeUpdateValuesAction()}),this.diagramPropertiesText=e!==void 0?e:oi}add(t){if(!this.contains(t.id)&&(this.length===0?this.propertyEditorSelection===void 0&&(t instanceof z||t instanceof lt)?this.openInPropertyEditor(t):this.propertyEditorSelection===void 0&&t instanceof U?this.openInPropertyEditor(t.node):this.openInPropertyEditor(void 0):this.openInPropertyEditor(void 0),super.add(t),t.updateInView(),t instanceof z&&t.sections))for(const e of t.sections)super.add(e),e.updateInView()}remove(t){const e=this.get(t);if(e&&(this.propertyEditorSelection===e&&this.openInPropertyEditor(void 0),super.remove(t),e.updateInView(),e instanceof z&&e.sections))for(const a of e.sections)super.remove(a.id),a.updateInView()}toggle(t){this.contains(t.id)?this.remove(t.id):this.add(t)}clear(){for(this.openInPropertyEditor(void 0);this.entities.length>0;){const t=this.entities[0];super.remove(t.id),t.updateInView()}}move(t){for(const e of this.all())e instanceof z&&e.move([e.coords[0]+t[0],e.coords[1]+t[1]])}removeFromModel(){if(this.length>0){const t=[],e=[],a=[],l=[],r=[];for(const n of this.all())n instanceof z?t.push(n.id):n instanceof U?e.push(n.id):n instanceof yt?a.push(n.id):n instanceof lt?l.push(n.id):n instanceof ct&&r.push(n.id);const i=new Do(this.canvas,t,e,a,l,r);i.do(),this.canvas.actionStack.add(i)}}copyToClipboard(){const t={type:"daga-user-selection",nodes:[],connections:[]},e=new Ze;for(const a of this.all())a instanceof z&&t.nodes.push(e.exportNode(a,!1)),a instanceof lt&&t.connections.push(e.exportConnection(a,!1));navigator.clipboard.writeText(JSON.stringify(t))}cutToClipboard(){this.copyToClipboard(),this.removeFromModel()}pasteFromClipboard(t){navigator.clipboard.readText().then(e=>{try{const a=JSON.parse(e);if(a.type!=="daga-user-selection")return;const l=new Bo(this.canvas,a.nodes,a.connections,t);this.canvas.actionStack.add(l),l.do()}catch{return}})}openInPropertyEditor(t,e=!0){e&&this.makeUpdateValuesAction();const a=this.canvas.parentComponent?.propertyEditor;if(a===void 0)return;const l=t?.valueSet;l?(this.propertyEditorSelection=t,e&&(this.propertyEditorValues=St(l.getValues())),a&&(t instanceof z||t instanceof lt?(t instanceof z?t.name?a.title=`${t.type.name}: ${t.name}`:a.title=t.type.name:t instanceof lt&&(a.title=t.type.name),a.valueSet=void 0,a.valueSet=l):(a.title=this.diagramPropertiesText,a.valueSet=void 0,a.valueSet=l))):(this.propertyEditorSelection=void 0,this.propertyEditorValues=void 0,a&&(a.title="",a.valueSet=void 0))}makeUpdateValuesAction(){if(this.propertyEditorSelection===void 0||this.propertyEditorValues===void 0)return;const t=this.propertyEditorSelection instanceof We?void 0:this.propertyEditorSelection.id;if(wt(this.propertyEditorValues,this.propertyEditorSelection?.valueSet.getValues()))return;const e=this.propertyEditorValues,a=St(this.propertyEditorSelection?.valueSet.getValues()),[l,r]=_e(e,a,this.propertyEditorSelection?.valueSet),i=new Uo(this.canvas,t,l,r);i.do(),this.canvas.actionStack.add(i),this.propertyEditorValues=a}}const si=s=>s*Math.PI/180,Te=(s,t,e)=>{const a=si(e),l=Math.sin(a),r=Math.cos(a),i=(Math.abs(s*r)-Math.abs(t*l))/(r*r-l*l),n=(Math.abs(s*l)-Math.abs(t*r))/(l*l-r*r);return[i,n]},Ne=navigator?.userAgent?.indexOf("AppleWebKit")>=0,ni=12,_=6,ri=25,le="diagram-connection-unfinished",Zt=class Zt{constructor(t,e){if(this.backgroundPatternId=`daga-background-pattern-id-${Zt.canvasCount++}`,this.zoomTransform=A.zoomIdentity,this.draggingFrom=[0,0],this.dragging=!1,this.secondaryButton=!1,this.validatorChange$=new kt.Subject,this.diagramChange$=new kt.Subject,this.diagramEvent$=new kt.Subject,this.propertyEditorChanges$=new kt.Subject,this.parentComponent=t,this.model=new We(this,void 0,e.name||"unnamed","",e.type||"",e.properties||[]),this.userSelection=new ii(this,e.components?.propertyEditor?.title),this.userHighlight=new ti(this,e.canvas?.highlightSections!==!1),this.contextMenu=new Qo(this,e.canvas?.contextMenu),this.backgroundColor=e.canvas?.backgroundColor||"#FFFFFF",this.gridStyle=e.canvas?.grid?.style??Rt.style,this.gridSize=e.canvas?.grid?.enabled===!1||e.canvas?.grid===void 0?0:Math.abs(e.canvas?.grid?.spacing||Rt.spacing),this.gridThickness=Math.abs(e.canvas?.grid?.thickness||Rt.thickness),this.gridColor=e.canvas?.grid?.color||Rt.color,this.snapToGrid=e.canvas?.grid?.enabled===!1||e.canvas?.grid===void 0?!1:e.canvas?.grid?.snap||Rt.snap,this.zoomFactor=e.canvas?.zoomFactor||2,this.panRate=e.canvas?.panRate||100,this.inferConnectionType=e.connectionSettings?.inferConnectionType||!1,this.autoTightenConnections=e.connectionSettings?.autoTighten!==!1,this.allowConnectionLoops=e.connectionSettings?.allowLoops||!1,this.allowSharingPorts=e.connectionSettings?.sharePorts!==!1,this.allowSharingBothPorts=e.connectionSettings?.shareBothPorts||!1,this.portHighlightRadius=e.connectionSettings?.portHighlightRadius||100,this.multipleSelectionOn=!1,this.priorityThresholds=e.canvas?.priorityThresholds||[],this.priorityThreshold=this.priorityThresholds?this.priorityThresholds[0]:void 0,this.layoutFormat=e.layoutFormat,this.userActions=e.userActions||{},this.validators=[],this.actionStack=new jo(this,ri),this.collabEngine=new Ho(this),e.nodeTypes)for(const a of e.nodeTypes){const l=new Ge({...e.nodeTypeDefaults,...a});this.model.nodes.types.add(l)}if(e.portTypes)for(const a of e.portTypes){const l=new Oo({...e.portTypeDefaults,...a});this.model.ports.types.add(l)}if(e.connectionTypes){for(const a of e.connectionTypes){const l=new He({...e.connectionTypeDefaults,...a});this.model.connections.types.add(l)}this._connectionType=e?.connectionSettings?.defaultConnection!==void 0?this.model.connections.types.get(e.connectionSettings.defaultConnection):void 0}}get connectionType(){return this._connectionType}set connectionType(t){this._connectionType=t,this.parentComponent?.palette?.refreshPalette()}addValidator(t){this.validators.push(t),this.validatorChange$.next()}removeValidator(t){B(this.validators,t),this.validatorChange$.next()}getPriorityThresholdOptions(){return this.priorityThresholds}getPriorityThreshold(){return this.priorityThreshold}setPriorityThreshold(t){this.priorityThreshold=t,this.updateModelInView();for(const e of this.model.nodes)this.fitNodeInView(e.id);this.parentComponent?.palette?.refreshPalette()}initView(t){const e=A.select(t);e.html(""),this.diagramRoot=e.append("div").node(),A.select(this.diagramRoot).attr("tabindex",0).style("width","100%").style("height","100%").append("svg").style("width","100%").style("height","100%"),A.select(this.diagramRoot).on(S.Click,()=>{A.select(this.diagramRoot).node()?.focus()}).on(S.ContextMenu,l=>{if(this.dragging){l.preventDefault(),l.stopPropagation(),this.dragging=!1;return}const r=new pt(l,null);this.diagramEvent$.next(r),!r.defaultPrevented&&this.canUserPerformAction(k.ContextMenu)&&(l.preventDefault(),this.contextMenu.open(l))}).on(S.DoubleClick,l=>{const r=new ut(l,null);this.diagramEvent$.next(r)}).on(S.KeyDown,l=>{if(!l.ctrlKey&&(l.key===K.Delete||l.key===K.Backspace)&&this.canUserPerformAction(k.Remove)&&(this.userSelection.removeFromModel(),this.cancelAllUserActions()),l.ctrlKey&&l.key==="a"){l.preventDefault();for(const r of this.model.nodes)this.userSelection.add(r);for(const r of this.model.connections)this.userSelection.add(r);this.diagramEvent$.next(new H(this.userSelection.all(),!0))}if(l.ctrlKey&&l.key==="i"){l.preventDefault();const r=[],i=[];for(const n of this.model.nodes)this.userSelection.toggle(n),n.selected?r.push(n):i.push(n);for(const n of this.model.connections)this.userSelection.toggle(n),n.selected?r.push(n):i.push(n);r.length>0&&this.diagramEvent$.next(new H(r,!0)),i.length>0&&this.diagramEvent$.next(new H(i,!1))}if(l.ctrlKey&&l.key==="c"&&this.canUserPerformAction(k.Clipboard)&&(l.preventDefault(),this.userSelection.copyToClipboard(),this.cancelAllUserActions()),l.ctrlKey&&l.key==="x"&&this.canUserPerformAction(k.Clipboard)&&this.canUserPerformAction(k.Remove)&&(l.preventDefault(),this.userSelection.cutToClipboard(),this.cancelAllUserActions()),l.ctrlKey&&l.key==="v"&&this.canUserPerformAction(k.Paste)){l.preventDefault();const r=this.getCoordinatesOnScreen();this.userSelection.pasteFromClipboard(this.getClosestGridPoint([(r[0][0]+r[1][0])/2,(r[0][1]+r[1][1])/2])),this.cancelAllUserActions()}l.ctrlKey&&l.key==="y"&&(l.preventDefault(),this.actionStack.redo()),l.ctrlKey&&l.key==="z"&&(l.preventDefault(),this.actionStack.undo()),l.key==="+"&&this.canUserPerformAction(k.Zoom)&&(l.preventDefault(),this.zoomBy(this.zoomFactor)),l.key==="-"&&this.canUserPerformAction(k.Zoom)&&(l.preventDefault(),this.zoomBy(1/this.zoomFactor)),l.key===K.ArrowLeft&&this.canUserPerformAction(k.Zoom)&&(l.preventDefault(),this.translateBy(this.panRate/this.zoomTransform.k,0)),l.key===K.ArrowRight&&this.canUserPerformAction(k.Zoom)&&(l.preventDefault(),this.translateBy(-this.panRate/this.zoomTransform.k,0)),l.key===K.ArrowDown&&this.canUserPerformAction(k.Zoom)&&(l.preventDefault(),this.translateBy(0,-this.panRate/this.zoomTransform.k)),l.key===K.ArrowUp&&this.canUserPerformAction(k.Zoom)&&(l.preventDefault(),this.translateBy(0,this.panRate/this.zoomTransform.k))});const a=this.selectSVGElement().append("g").attr("class","daga-canvas-view").attr("width","100%").attr("height","100%");a.call(this.zoomBehavior=A.zoom().filter(l=>l.type!==S.DoubleClick).on(de.Zoom,l=>{if(l.sourceEvent){if(!this.canUserPerformAction(k.Zoom)){w(L.NotAllowed);return}l.sourceEvent.type===S.Wheel&&l.sourceEvent.wheelDelta!==void 0?(l.sourceEvent.wheelDelta>0&&w(L.ZoomIn),l.sourceEvent.wheelDelta<0&&w(L.ZoomOut)):l.sourceEvent.type===S.MouseMove&&w(L.AllScroll)}this.zoomTransform=l.transform;const r=l.transform.toString();this.selectCanvasElements().attr("transform",r),A.select(`#${this.backgroundPatternId}`).attr("patternTransform",r),Ne&&this.updateFieldsInView(),this.contextMenu.close(),this.diagramEvent$.next(new Yo([this.zoomTransform.x,this.zoomTransform.y],this.zoomTransform.k))}).on(de.End,()=>{w()})),a.append("rect").attr("x",0).attr("y",0).attr("width","100%").attr("height","100%").attr("fill",this.backgroundColor).attr("stroke-width","0").on(S.MouseMove,l=>{if(this.unfinishedConnection!==void 0){const r=this.getPointerLocationRelativeToCanvas(l);this.unfinishedConnection.endCoords=r}}).on(S.MouseOver,()=>{this.userHighlight.size()>0&&(this.userHighlight.clear(),this.diagramEvent$.next(new Q(null)))}).on(S.Click,()=>{if(this.userHighlight.size()>0&&(this.userHighlight.clear(),this.diagramEvent$.next(new Q(null))),this.contextMenu.close(),this.userSelection.size()>0){const l=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new H(l,!1))}this.userSelection.openInPropertyEditor(this.model)}).call(A.drag().filter(l=>this.multipleSelectionOn||mt(l)).on($.Start,l=>{this.startMultipleSelection(l)}).on($.Drag,l=>{this.continueMultipleSelection(l)}).on($.End,l=>{this.finishMultipleSelection(l)})),Ko(this,a,this.backgroundPatternId),a.append("g").attr("class","daga-canvas-elements")}getZoomLevel(){return this.zoomTransform.k}zoomBy(t){isNaN(t)||this.zoomBehavior.scaleBy(this.selectCanvasView(),t)}zoomTo(t){isNaN(t)||this.zoomBehavior.scaleTo(this.selectCanvasView(),t)}getViewCoordinates(){return[this.zoomTransform.x,this.zoomTransform.y]}translateBy(t,e){!isNaN(t)&&!isNaN(e)&&this.zoomBehavior.translateBy(this.selectCanvasView(),t,e)}translateTo(t,e){!isNaN(t)&&!isNaN(e)&&this.zoomBehavior.translateTo(this.selectCanvasView(),t,e)}center(){if(this.model.nodes.length>0){const t=this.selectCanvasView().select("rect").node()?.getBBox(),e=this.model.nodes.all(),a=Math.min(...e.map(m=>m.coords[0])),l=Math.max(...e.map(m=>m.coords[0]+m.width)),r=(a+l)/2,i=l-a,n=t.width,o=Math.min(...e.map(m=>m.coords[1])),d=Math.max(...e.map(m=>m.coords[1]+m.height)),c=(o+d)/2,h=d-o,u=t.height,b=Math.min(n/i,u/h,1);this.translateTo(r,c),this.zoomTo(b)}}getClosestGridPoint(t){return this.gridSize===0||!isFinite(this.gridSize)?t:[Math.round(t[0]/this.gridSize)*this.gridSize,Math.round(t[1]/this.gridSize)*this.gridSize]}getCoordinatesOnScreen(){const t=this.selectSVGElement().node()?.getBoundingClientRect(),e=[t?.width||0,t?.height||0];return[[-this.zoomTransform.x/this.zoomTransform.k,-this.zoomTransform.y/this.zoomTransform.k],[(e[0]-this.zoomTransform.x)/this.zoomTransform.k,(e[1]-this.zoomTransform.y)/this.zoomTransform.k]]}getEventHoldingCoordinates(t){if(t.type==="drag"||t.type==="start"||t.type==="end"){const e=t.sourceEvent;if(e&&(e.type==="touchmove"||e.type==="touchstart"||e.type==="touchend"))return t.sourceEvent.touches[0]||t.sourceEvent.changedTouches[0]}return t}getPointerLocationRelativeToCanvas(t){return A.pointer(this.getEventHoldingCoordinates(t),this.selectCanvasElements().node())}getPointerLocationRelativeToRoot(t){return A.pointer(this.getEventHoldingCoordinates(t),this.selectSVGElement().node())}getPointerLocationRelativeToBody(t){return A.pointer(this.getEventHoldingCoordinates(t),A.select("body").node())}getPointerLocationRelativeToScreen(t){const e=this.getPointerLocationRelativeToBody(t);return[e[0]-window.scrollX,e[1]-window.scrollY]}updateModelInView(){this.updateNodesInView(),this.updateSectionsInView(),this.updatePortsInView(),this.updateConnectionsInView(),this.updateFieldsInView(),this.updateObjectsInView(),this.updateDecoratorsInView()}updateNodesInView(...t){let e=this.selectCanvasElements().selectAll("g.diagram-node").data(this.model.nodes.filter(i=>this.priorityThreshold!==void 0?i.getPriority()>=this.priorityThreshold:!0),i=>i.id);const a=e.exit(),l=e.enter().append("g").attr("id",i=>i.id).attr("class",i=>`diagram-node${i.type.resizableX?" resizable-x":""}${i.type.resizableY?" resizable-y":""} ${i.type.defaultLook.lookType}`);t&&t.length>0&&(e=e.filter(i=>t.includes(i.id)));const r=l.merge(e);a.remove(),l.on(S.MouseOver,(i,n)=>{this.dragging||(this.userHighlight.focusOn(n),this.diagramEvent$.next(new Q(n)))}).on(S.Click,(i,n)=>{if(!i.ctrlKey&&!i.shiftKey){const o=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new H(o,!1))}this.userSelection.toggle(n),this.diagramEvent$.next(new H([n],n.selected))}).on(S.ContextMenu,(i,n)=>{if(this.dragging){i.preventDefault(),i.stopPropagation(),this.dragging=!1;return}const o=new pt(i,n);this.diagramEvent$.next(o),!o.defaultPrevented&&this.canUserPerformAction(k.ContextMenu)&&(i.preventDefault(),this.userHighlight.focusOn(n),this.diagramEvent$.next(new Q(n)),this.userSelection.add(n),this.diagramEvent$.next(new H([n],!0)),this.contextMenu.open(i))}).on(S.DoubleClick,(i,n)=>{const o=new ut(i,n);this.diagramEvent$.next(o)}).call(A.drag().filter(i=>(this.secondaryButton=mt(i),!0)).on($.Start,(i,n)=>{this.multipleSelectionOn||this.secondaryButton?this.startMultipleSelection(i):this.startMovingNode(i,n)}).on($.Drag,(i,n)=>{this.multipleSelectionOn||this.secondaryButton?this.continueMultipleSelection(i):this.continueMovingNode(i,n)}).on($.End,(i,n)=>{this.multipleSelectionOn||this.secondaryButton?this.finishMultipleSelection(i):this.finishMovingNode(i,n),this.secondaryButton=!1})),re(l),l.filter(".resizable-x").append("line").attr("class","left-resizer").attr("stroke","transparent").attr("stroke-width",`${_}px`).on(S.MouseOver,(i,n)=>{this.canUserPerformAction(k.StretchNode)&&n.type.resizableX&&!n.removed&&w(L.EWResize)}).on(S.MouseOut,(i,n)=>{this.canUserPerformAction(k.StretchNode)&&n.type.resizableX&&!n.removed&&w()}).call(A.drag().on($.Start,(i,n)=>{this.canUserPerformAction(k.StretchNode)&&n.type.resizableX&&!n.removed?(w(L.EWResize),this.currentAction=new X(this,k.StretchNode,n.id,n.getGeometry(),n.getGeometry())):w(L.NotAllowed)}).on($.Drag,(i,n)=>{if(this.canUserPerformAction(k.StretchNode)&&n.type.resizableX&&!n.removed){const o=this.getPointerLocationRelativeToCanvas(i);n.stretch(f.Left,n.coords[0]-o[0])}}).on($.End,(i,n)=>{if(this.canUserPerformAction(k.StretchNode)&&n.type.resizableX&&!n.removed&&this.currentAction instanceof X&&this.currentAction.intent===k.StretchNode){let o=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(o=this.getClosestGridPoint([o[0]-n.type.snapToGridOffset[0],o[1]-n.type.snapToGridOffset[1]]),o[0]+=n.type.snapToGridOffset[0],o[1]+=n.type.snapToGridOffset[1]),n.stretch(f.Left,n.coords[0]-o[0]),this.currentAction.to=n.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}w()})),l.filter(".resizable-y").append("line").attr("class","top-resizer").attr("stroke","transparent").attr("stroke-width",`${_}px`).on(S.MouseOver,(i,n)=>{this.canUserPerformAction(k.StretchNode)&&n.type.resizableY&&!n.removed&&w(L.NSResize)}).on(S.MouseOut,(i,n)=>{this.canUserPerformAction(k.StretchNode)&&n.type.resizableY&&!n.removed&&w()}).call(A.drag().on($.Start,(i,n)=>{this.canUserPerformAction(k.StretchNode)&&n.type.resizableY&&!n.removed?(w(L.NSResize),this.currentAction=new X(this,k.StretchNode,n.id,n.getGeometry(),n.getGeometry())):w(L.NotAllowed)}).on($.Drag,(i,n)=>{if(this.canUserPerformAction(k.StretchNode)&&n.type.resizableY&&!n.removed){const o=this.getPointerLocationRelativeToCanvas(i);n.stretch(f.Top,n.coords[1]-o[1])}}).on($.End,(i,n)=>{if(this.canUserPerformAction(k.StretchNode)&&n.type.resizableY&&!n.removed&&this.currentAction instanceof X&&this.currentAction.intent===k.StretchNode){let o=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(o=this.getClosestGridPoint([o[0]-n.type.snapToGridOffset[0],o[1]-n.type.snapToGridOffset[1]]),o[0]+=n.type.snapToGridOffset[0],o[1]+=n.type.snapToGridOffset[1]),n.stretch(f.Top,n.coords[1]-o[1]),this.currentAction.to=n.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}w()})),l.filter(".resizable-x").append("line").attr("class","right-resizer").attr("stroke","transparent").attr("stroke-width",`${_}px`).on(S.MouseOver,(i,n)=>{this.canUserPerformAction(k.StretchNode)&&n.type.resizableX&&!n.removed&&w(L.EWResize)}).on(S.MouseOut,(i,n)=>{this.canUserPerformAction(k.StretchNode)&&n.type.resizableX&&!n.removed&&w()}).call(A.drag().on($.Start,(i,n)=>{this.canUserPerformAction(k.StretchNode)&&n.type.resizableX&&!n.removed?(w(L.EWResize),this.currentAction=new X(this,k.StretchNode,n.id,n.getGeometry(),n.getGeometry())):w(L.NotAllowed)}).on($.Drag,(i,n)=>{if(this.canUserPerformAction(k.StretchNode)&&n.type.resizableX&&!n.removed){const o=this.getPointerLocationRelativeToCanvas(i);n.stretch(f.Right,o[0]-(n.coords[0]+n.width))}}).on($.End,(i,n)=>{if(this.canUserPerformAction(k.StretchNode)&&n.type.resizableX&&!n.removed&&this.currentAction instanceof X&&this.currentAction.intent===k.StretchNode){let o=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(o=this.getClosestGridPoint([o[0]-n.type.snapToGridOffset[2],o[1]-n.type.snapToGridOffset[3]]),o[0]+=n.type.snapToGridOffset[2],o[1]+=n.type.snapToGridOffset[3]),n.stretch(f.Right,o[0]-(n.coords[0]+n.width)),this.currentAction.to=n.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}w()})),l.filter(".resizable-y").append("line").attr("class","bottom-resizer").attr("stroke","transparent").attr("stroke-width",`${_}px`).on(S.MouseOver,(i,n)=>{this.canUserPerformAction(k.StretchNode)&&n.type.resizableY&&!n.removed&&w(L.NSResize)}).on(S.MouseOut,(i,n)=>{this.canUserPerformAction(k.StretchNode)&&n.type.resizableY&&!n.removed&&w()}).call(A.drag().on($.Start,(i,n)=>{this.canUserPerformAction(k.StretchNode)&&n.type.resizableY&&!n.removed?(w(L.NSResize),this.currentAction=new X(this,k.StretchNode,n.id,n.getGeometry(),n.getGeometry())):w(L.NotAllowed)}).on($.Drag,(i,n)=>{if(this.canUserPerformAction(k.StretchNode)&&n.type.resizableY&&!n.removed){const o=this.getPointerLocationRelativeToCanvas(i);n.stretch(f.Bottom,o[1]-(n.coords[1]+n.height))}}).on($.End,(i,n)=>{if(this.canUserPerformAction(k.StretchNode)&&n.type.resizableY&&!n.removed&&this.currentAction instanceof X&&this.currentAction.intent===k.StretchNode){let o=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&this.snapToGrid&&(o=this.getClosestGridPoint([o[0]-n.type.snapToGridOffset[2],o[1]-n.type.snapToGridOffset[3]]),o[0]+=n.type.snapToGridOffset[2],o[1]+=n.type.snapToGridOffset[3]),n.stretch(f.Bottom,o[1]-(n.coords[1]+n.height)),this.currentAction.to=n.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}w()})),r.attr("transform",i=>`translate(${i.coords[0]},${i.coords[1]})`).attr("opacity",i=>i.removed?.5:1),ae(r),r.filter(".resizable-x").select("line.left-resizer").attr("x1",_/2).attr("x2",_/2).attr("y1",0).attr("y2",i=>i.height),r.filter(".resizable-y").select("line.top-resizer").attr("x1",0).attr("x2",i=>i.width).attr("y1",_/2).attr("y2",_/2),r.filter(".resizable-x").select("line.right-resizer").attr("x1",i=>i.width-_/2).attr("x2",i=>i.width-_/2).attr("y1",0).attr("y2",i=>i.height),r.filter(".resizable-y").select("line.bottom-resizer").attr("x1",0).attr("x2",i=>i.width).attr("y1",i=>i.height-_/2).attr("y2",i=>i.height-_/2)}updateSectionsInView(...t){let e=this.selectCanvasElements().selectAll("g.diagram-section").data(this.model.sections.filter(i=>this.priorityThreshold!==void 0?i.getPriority()>=this.priorityThreshold:!0),i=>i.id);const a=e.exit(),l=e.enter().append("g").attr("id",i=>i.id).attr("class",i=>`diagram-section${i.getResizableX()?" resizable-x":""}${i.getResizableY()?" resizable-y":""} ${i.look?.lookType}`);t&&t.length>0&&(e=e.filter(i=>t.includes(i.id)));const r=l.merge(e);a.remove(),l.on(S.MouseOver,(i,n)=>{this.dragging||(this.userHighlight.focusOn(n),this.diagramEvent$.next(new Q(n)))}).on(S.Click,(i,n)=>{if(!i.ctrlKey&&!i.shiftKey){const d=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new H(d,!1))}const o=dt(n);this.userSelection.toggle(o),this.diagramEvent$.next(new H([o],o.selected))}).on(S.ContextMenu,(i,n)=>{if(this.dragging){i.preventDefault(),i.stopPropagation(),this.dragging=!1;return}const o=new pt(i,n);if(this.diagramEvent$.next(o),!o.defaultPrevented&&this.canUserPerformAction(k.ContextMenu)){i.preventDefault();const d=dt(n);this.userHighlight.focusOn(d),this.diagramEvent$.next(new Q(d)),this.userSelection.add(d),this.diagramEvent$.next(new H([d],!0)),this.contextMenu.open(i)}}).on(S.DoubleClick,(i,n)=>{const o=new ut(i,n);this.diagramEvent$.next(o)}).call(A.drag().filter(i=>(this.secondaryButton=mt(i),!0)).on($.Start,(i,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.startMultipleSelection(i);else{const o=n?.node;o?this.startMovingNode(i,o):w(L.NotAllowed)}}).on($.Drag,(i,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(i);else{const o=n?.node;o?this.continueMovingNode(i,o):w(L.NotAllowed)}}).on($.End,(i,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(i);else{const o=n?.node;o?this.finishMovingNode(i,o):w()}this.secondaryButton=!1})),re(l),l.filter(".resizable-x").append("line").attr("class","left-resizer").attr("stroke","transparent").attr("stroke-width",`${_}px`).on(S.MouseOver,(i,n)=>{this.canUserPerformAction(k.StretchSection)&&n.getResizableX()&&!n.removed&&w(L.EWResize)}).on(S.MouseOut,(i,n)=>{this.canUserPerformAction(k.StretchSection)&&n.getResizableX()&&!n.removed&&w()}).call(A.drag().on($.Start,(i,n)=>{this.canUserPerformAction(k.StretchSection)&&n.getResizableX()&&!n.removed&&n.node?(w(L.EWResize),this.currentAction=new X(this,k.StretchSection,n.node.id,n.node.getGeometry(),n.node.getGeometry())):w(L.NotAllowed)}).on($.Drag,(i,n)=>{if(this.canUserPerformAction(k.StretchSection)&&n.getResizableX()&&!n.removed&&n.node){const o=this.getPointerLocationRelativeToCanvas(i);n.node.stretchSections(f.Left,n.coords[0]-o[0],n.indexXInNode,n.indexYInNode)}}).on($.End,(i,n)=>{if(this.canUserPerformAction(k.StretchSection)&&n.getResizableX()&&!n.removed&&this.currentAction instanceof X&&this.currentAction.intent===k.StretchSection&&n.node){let o=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(o=this.getClosestGridPoint(o)),n.node.stretchSections(f.Left,n.coords[0]-o[0],n.indexXInNode,n.indexYInNode),this.currentAction.to=n.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}w()})),l.filter(".resizable-y").append("line").attr("class","top-resizer").attr("stroke","transparent").attr("stroke-width",`${_}px`).on(S.MouseOver,(i,n)=>{this.canUserPerformAction(k.StretchSection)&&n.getResizableY()&&!n.removed&&w(L.NSResize)}).on(S.MouseOut,(i,n)=>{this.canUserPerformAction(k.StretchSection)&&n.getResizableY()&&!n.removed&&w()}).call(A.drag().on($.Start,(i,n)=>{this.canUserPerformAction(k.StretchSection)&&n.getResizableY()&&!n.removed&&n.node?(w(L.NSResize),this.currentAction=new X(this,k.StretchSection,n.node.id,n.node.getGeometry(),n.node.getGeometry())):w(L.NotAllowed)}).on($.Drag,(i,n)=>{if(this.canUserPerformAction(k.StretchSection)&&n.getResizableY()&&!n.removed&&n.node){const o=this.getPointerLocationRelativeToCanvas(i);n.node.stretchSections(f.Top,n.coords[1]-o[1],n.indexXInNode,n.indexYInNode)}}).on($.End,(i,n)=>{if(this.canUserPerformAction(k.StretchSection)&&n.getResizableY()&&!n.removed&&this.currentAction instanceof X&&this.currentAction.intent===k.StretchSection&&n.node){let o=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(o=this.getClosestGridPoint(o)),n.node.stretchSections(f.Top,n.coords[1]-o[1],n.indexXInNode,n.indexYInNode),this.currentAction.to=n.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}w()})),l.filter(".resizable-x").append("line").attr("class","right-resizer").attr("stroke","transparent").attr("stroke-width",`${_}px`).on(S.MouseOver,(i,n)=>{this.canUserPerformAction(k.StretchSection)&&n.getResizableX()&&!n.removed&&w(L.EWResize)}).on(S.MouseOut,(i,n)=>{this.canUserPerformAction(k.StretchSection)&&n.getResizableX()&&!n.removed&&w()}).call(A.drag().on($.Start,(i,n)=>{this.canUserPerformAction(k.StretchSection)&&n.getResizableX()&&!n.removed&&n.node?(w(L.EWResize),this.currentAction=new X(this,k.StretchSection,n.node.id,n.node.getGeometry(),n.node.getGeometry())):w(L.NotAllowed)}).on($.Drag,(i,n)=>{if(this.canUserPerformAction(k.StretchSection)&&n.getResizableX()&&!n.removed&&n.node){const o=this.getPointerLocationRelativeToCanvas(i);n.node.stretchSections(f.Right,o[0]-(n.coords[0]+n.width),n.indexXInNode,n.indexYInNode)}}).on($.End,(i,n)=>{if(this.canUserPerformAction(k.StretchSection)&&n.getResizableX()&&!n.removed&&this.currentAction instanceof X&&this.currentAction.intent===k.StretchSection&&n.node){let o=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(o=this.getClosestGridPoint(o)),n.node.stretchSections(f.Right,o[0]-(n.coords[0]+n.width),n.indexXInNode,n.indexYInNode),this.currentAction.to=n.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}w()})),l.filter(".resizable-y").append("line").attr("class","bottom-resizer").attr("stroke","transparent").attr("stroke-width",`${_}px`).on(S.MouseOver,(i,n)=>{this.canUserPerformAction(k.StretchSection)&&n.getResizableY()&&!n.removed&&w(L.NSResize)}).on(S.MouseOut,(i,n)=>{this.canUserPerformAction(k.StretchSection)&&n.getResizableY()&&!n.removed&&w()}).call(A.drag().on($.Start,(i,n)=>{this.canUserPerformAction(k.StretchSection)&&n.getResizableY()&&!n.removed&&n.node?(w(L.NSResize),this.currentAction=new X(this,k.StretchSection,n.node.id,n.node.getGeometry(),n.node.getGeometry())):w(L.NotAllowed)}).on($.Drag,(i,n)=>{if(this.canUserPerformAction(k.StretchSection)&&n.getResizableY()&&!n.removed&&n.node){const o=this.getPointerLocationRelativeToCanvas(i);n.node.stretchSections(f.Bottom,o[1]-(n.coords[1]+n.height),n.indexXInNode,n.indexYInNode)}}).on($.End,(i,n)=>{if(this.canUserPerformAction(k.StretchSection)&&n.getResizableY()&&!n.removed&&this.currentAction instanceof X&&this.currentAction.intent===k.StretchSection&&n.node){let o=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(o=this.getClosestGridPoint(o)),n.node.stretchSections(f.Bottom,o[1]-(n.coords[1]+n.height),n.indexXInNode,n.indexYInNode),this.currentAction.to=n.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}w()})),r.attr("transform",i=>`translate(${i.coords[0]},${i.coords[1]})`).attr("opacity",i=>i.removed?.5:1),ae(r),r.filter(".resizable-x").select("line.left-resizer").attr("x1",_/2).attr("x2",_/2).attr("y1",0).attr("y2",i=>i.height),r.filter(".resizable-y").select("line.top-resizer").attr("x1",0).attr("x2",i=>i.width).attr("y1",_/2).attr("y2",_/2),r.filter(".resizable-x").select("line.right-resizer").attr("x1",i=>i.width-_/2).attr("x2",i=>i.width-_/2).attr("y1",0).attr("y2",i=>i.height),r.filter(".resizable-y").select("line.bottom-resizer").attr("x1",0).attr("x2",i=>i.width).attr("y1",i=>i.height-_/2).attr("y2",i=>i.height-_/2)}updatePortsInView(...t){let e=this.selectCanvasElements().selectAll("g.diagram-port").data(this.model.ports.filter(i=>this.priorityThreshold!==void 0?i.getPriority()>=this.priorityThreshold:!0),i=>i.id);const a=e.exit(),l=e.enter().append("g").attr("id",i=>i.id).attr("class",i=>`diagram-port ${i.look.lookType}`);t&&t.length>0&&(e=e.filter(i=>t.includes(i.id)));const r=l.merge(e);a.remove(),l.on(S.MouseOver,(i,n)=>{!this.unfinishedConnection&&!this.dragging&&(this.userHighlight.focusOn(n),this.diagramEvent$.next(new Q(n))),this.unfinishedConnection&&(this.unfinishedConnection.type.canStartFromType(this.unfinishedConnection.start?.getNode()?.type?.id||"")&&this.unfinishedConnection.start?.allowsOutgoing&&this.unfinishedConnection.type.canFinishOnType(n.getNode()?.type?.id||"")&&n.allowsIncoming||this.unfinishedConnection.type.canStartFromType(n.getNode()?.type?.id||"")&&n.allowsOutgoing&&this.unfinishedConnection.type.canFinishOnType(this.unfinishedConnection.start?.getNode()?.type?.id||"")&&this.unfinishedConnection.start?.allowsIncoming||w(L.NoDrop))}).on(S.MouseOut,()=>{this.unfinishedConnection&&w(L.Grabbing)}).on(S.Click,(i,n)=>{if(!i.ctrlKey&&!i.shiftKey){const d=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new H(d,!1))}const o=dt(n);this.userSelection.toggle(o),this.diagramEvent$.next(new H([o],o.selected))}).on(S.ContextMenu,(i,n)=>{if(this.dragging){i.preventDefault(),i.stopPropagation(),this.dragging=!1;return}const o=new pt(i,n);if(this.diagramEvent$.next(o),!o.defaultPrevented&&this.canUserPerformAction(k.ContextMenu)){i.preventDefault();const d=dt(n);this.userHighlight.focusOn(d),this.diagramEvent$.next(new Q(d)),this.userSelection.add(d),this.diagramEvent$.next(new H([d],!0)),this.contextMenu.open(i)}}).on(S.DoubleClick,(i,n)=>{const o=new ut(i,n);this.diagramEvent$.next(o)}).call(A.drag().filter(i=>(this.secondaryButton=mt(i),!0)).on($.Start,(i,n)=>{this.multipleSelectionOn||this.secondaryButton?this.startMultipleSelection(i):this.canUserPerformAction(k.AddConnection)&&(this.allowSharingPorts||n.incomingConnections.filter(o=>!o.removed).length===0&&n.outgoingConnections.filter(o=>!o.removed).length===0)&&!n.removed?(w(L.Grabbing),this.startConnection(n),this.unfinishedConnection&&(this.unfinishedConnectionTracer=this.selectCanvasElements().append("path").attr("stroke","none").attr("fill","none"))):w(L.NotAllowed)}).on($.Drag,(i,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(i);else if(this.canUserPerformAction(k.AddConnection)&&!n.removed&&this.unfinishedConnection!==void 0){const o=[i.x,i.y];this.unfinishedConnectionTracer?.attr("d",ne(this.unfinishedConnection.look.shape||ot.look.shape,this.unfinishedConnection.startCoords,o,this.unfinishedConnection.startDirection,this.unfinishedConnection.endDirection,this.unfinishedConnection.type.defaultLook.thickness||ot.look.thickness,this.unfinishedConnection.type.defaultStartMarkerLook?.width,this.unfinishedConnection.type.defaultEndMarkerLook?.width));const d=this.unfinishedConnectionTracer?.node();if(d){let c=2;const h=d.getTotalLength();h<c&&(c=0);const u=d.getPointAtLength(h-c);this.unfinishedConnection.endCoords=[u.x,u.y]}else this.unfinishedConnection.endCoords=o;if(this.updateConnectionsInView(le),this.model.ports.length>0){const c=this.getPointerLocationRelativeToCanvas(i);let h=Number.POSITIVE_INFINITY,u;for(const b of this.model.ports){const m=b.distanceTo(c);m<h&&(h=m,u=b)}u&&h<this.portHighlightRadius?this.userHighlight.focusOn(u):this.userHighlight.clear()}}}).on($.End,(i,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(i);else{if(this.canUserPerformAction(k.AddConnection)&&!n.removed){this.unfinishedConnectionTracer?.remove();const o=this.userHighlight.getFocus();if(o instanceof yt)this.finishConnection(o);else if(o instanceof ct&&o.rootElement instanceof yt)this.finishConnection(o.rootElement);else if(o instanceof z||o instanceof U||o instanceof ct){let d;if(o instanceof z||o instanceof U)d=o;else if(o.rootElement instanceof z||o.rootElement instanceof U)d=o.rootElement;else{this.dropConnection();return}const c=d.getClosestPortToPoint([i.x,i.y]);c!==void 0?this.finishConnection(c):this.dropConnection()}else this.dropConnection()}w()}this.secondaryButton=!1})),l.filter(".image-look").append("image"),re(l),r.attr("transform",i=>`translate(${i.coords[0]-i.width/2},${i.coords[1]-i.width/2})`).attr("opacity",i=>i.removed?.5:1),ae(r)}updateConnectionsInView(...t){const e=this.model.connections.filter(n=>this.priorityThreshold!==void 0?n.getPriority()>=this.priorityThreshold:!0);this.unfinishedConnection&&e.push(this.unfinishedConnection);let a=this.selectCanvasElements().selectAll("g.diagram-connection").data(e,n=>n.id);const l=a.exit(),r=a.enter().append("g").attr("id",n=>n.id).attr("class","diagram-connection");t&&t.length>0&&(a=a.filter(n=>t.includes(n.id)));const i=r.merge(a);l.remove(),r.on(S.MouseOver,(n,o)=>{o.end!==void 0&&!this.dragging&&(this.userHighlight.focusOn(o),this.diagramEvent$.next(new Q(o)))}).on(S.Click,(n,o)=>{if(!n.ctrlKey&&!n.shiftKey){const d=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new H(d,!1))}this.userSelection.toggle(o),this.diagramEvent$.next(new H([o],o.selected))}).on(S.ContextMenu,(n,o)=>{if(this.dragging){n.preventDefault(),n.stopPropagation(),this.dragging=!1;return}const d=new pt(n,o);this.diagramEvent$.next(d),!d.defaultPrevented&&this.canUserPerformAction(k.ContextMenu)&&(n.preventDefault(),this.userHighlight.focusOn(o),this.diagramEvent$.next(new Q(o)),this.userSelection.add(o),this.diagramEvent$.next(new H([o],!0)),this.contextMenu.open(n))}).on(S.DoubleClick,(n,o)=>{const d=new ut(n,o);this.diagramEvent$.next(d)}).call(A.drag().filter(n=>(this.secondaryButton=mt(n),!0)).on($.Start,n=>{this.startMultipleSelection(n)}).on($.Drag,n=>{this.continueMultipleSelection(n)}).on($.End,n=>{this.finishMultipleSelection(n)})),r.append("path").attr("class","diagram-connection-path"),r.append("path").attr("class","diagram-connection-path-box"),r.append("marker").attr("id",n=>`${n.id}-start-marker`).attr("class","diagram-connection-start-marker").append("image").attr("preserveAspectRatio","none"),r.append("marker").attr("id",n=>`${n.id}-end-marker`).attr("class","diagram-connection-end-marker").append("image").attr("preserveAspectRatio","none"),r.append("g").attr("class","diagram-connection-start-label"),r.select("g.diagram-connection-start-label").append("path"),r.select("g.diagram-connection-start-label").append("text").style("user-select","none"),r.append("g").attr("class","diagram-connection-middle-label"),r.select("g.diagram-connection-middle-label").append("path"),r.select("g.diagram-connection-middle-label").append("text").style("user-select","none"),r.append("g").attr("class","diagram-connection-end-label"),r.select("g.diagram-connection-end-label").append("path"),r.select("g.diagram-connection-end-label").append("text").style("user-select","none"),i.attr("opacity",n=>n.removed?.5:1).select("path.diagram-connection-path").attr("d",n=>ne(n.look.shape||ot.look.shape,n.startCoords,n.endCoords,n.startDirection,n.endDirection,n.type.defaultLook.thickness||ot.look.thickness,n.type.defaultStartMarkerLook?.width,n.type.defaultEndMarkerLook?.width)).attr("marker-start",n=>`url(#${n.id}-start-marker)`).attr("marker-end",n=>`url(#${n.id}-end-marker)`).attr("stroke",n=>n.look.color||ot.look.color).attr("stroke-width",n=>`${n.look.thickness}px`).attr("stroke-dasharray",n=>he(n.look.style||ot.look.style,n.type.defaultLook.thickness||ot.look.thickness)).attr("fill","none"),i.select("path.diagram-connection-path-box").attr("d",n=>ne(n.look.shape||ot.look.shape,n.startCoords,n.endCoords,n.startDirection,n.endDirection,n.type.defaultLook.thickness||ot.look.thickness,n.type.defaultStartMarkerLook?.width,n.type.defaultEndMarkerLook?.width)).attr("stroke","transparent").attr("pointer-events","stroke").attr("stroke-width",n=>`${(n.look.thickness||ot.look.thickness)+ni}px`).attr("stroke-dasharray",n=>he(n.look.style||ot.look.style,n.type.defaultLook.thickness||ot.look.thickness)).attr("fill","none"),i.data().forEach(n=>{this.updateConnectionLabelsInView(n),this.updateConnectionMarkersInView(n)})}updateFieldsInView(...t){let e=this.selectCanvasElements().selectAll("foreignObject.diagram-field").data(this.model.fields.filter(i=>this.priorityThreshold!==void 0?i.getPriority()>=this.priorityThreshold:!0),i=>i.id);const a=e.exit(),l=e.enter().append("foreignObject").attr("id",i=>i.id).attr("class","diagram-field");t&&t.length>0&&(e=e.filter(i=>t.includes(i.id)));const r=l.merge(e);if(a.remove(),l.style("box-sizing","border-box").on(S.MouseOver,(i,n)=>{this.dragging||(this.userHighlight.focusOn(n),this.diagramEvent$.next(new Q(n)))}).on(S.Click,(i,n)=>{if(!i.ctrlKey&&!i.shiftKey){const d=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new H(d,!1))}const o=dt(n);this.userSelection.toggle(o),this.diagramEvent$.next(new H([o],o.selected))}).on(S.ContextMenu,(i,n)=>{if(this.dragging){i.preventDefault(),i.stopPropagation(),this.dragging=!1;return}const o=new pt(i,n);if(this.diagramEvent$.next(o),!o.defaultPrevented&&this.canUserPerformAction(k.ContextMenu)){i.preventDefault();const d=dt(n);this.userHighlight.focusOn(d),this.diagramEvent$.next(new Q(d)),this.userSelection.add(d),this.diagramEvent$.next(new H([d],!0)),this.contextMenu.open(i)}}).on(S.DoubleClick,(i,n)=>{const o=new ut(i,n);this.diagramEvent$.next(o),!o.defaultPrevented&&this.canUserPerformAction(k.EditField)&&n.editable&&!n.removed&&(this.currentAction=new Ee(this,n.id,n.text,""),this.createInputField(n.text,n.coords,n.width,n.height,n.fontSize,n.fontFamily||O.fontFamily,n.orientation,()=>{},d=>{n.text=d,this.currentAction instanceof Ee&&(this.currentAction.to=d,this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0)}))}).call(A.drag().filter(i=>(this.secondaryButton=mt(i),!0)).on($.Start,(i,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.startMultipleSelection(i);else{let o;n.rootElement instanceof z?o=n.rootElement:n.rootElement instanceof U&&(o=n.rootElement.node),o?this.startMovingNode(i,o):w(L.NotAllowed)}}).on($.Drag,(i,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(i);else{let o;n.rootElement instanceof z?o=n.rootElement:n.rootElement instanceof U&&(o=n.rootElement.node),o?this.continueMovingNode(i,o):w(L.NotAllowed)}}).on($.End,(i,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(i);else{let o;n.rootElement instanceof z?o=n.rootElement:n.rootElement instanceof U&&(o=n.rootElement.node),o?this.finishMovingNode(i,o):w()}this.secondaryButton=!1})).append("xhtml:div").style("width","100%").style("height","100%").style("display","flex").append("xhtml:p").style("box-sizing","border-box").style("outline",0).style("margin",0).style("border",0).style("padding",0).style("user-select","none").style("font-kerning","none").style("white-space","nowrap"),r.attr("x",0).attr("y",0).attr("width",i=>`${i.width}px`).attr("height",i=>`${i.height}px`).attr("transform",i=>`translate(${i.coords[0]},${i.coords[1]})`).attr("opacity",i=>i.removed?.5:1).select("div").style("justify-content",i=>i.horizontalAlign===Lt.Center?"center":i.horizontalAlign===Lt.Right?"flex-end":"flex-start").style("align-items",i=>i.verticalAlign===Xt.Center?"center":i.verticalAlign===Xt.Bottom?"end":"start").select("p").style("max-width",i=>i.fit?"default":`${Te(i.width,i.height,i.orientation)[0]}px`).style("max-height",i=>i.fit?"default":`${Te(i.width,i.height,i.orientation)[1]}px`).style("overflow",i=>i.fit?"default":"clip").style("text-overflow",i=>i.fit?"default":"ellipsis").style("text-align",i=>i.horizontalAlign===Lt.Center?"center":i.horizontalAlign===Lt.Right?"end":"start").style("transform",i=>`rotate(${i.orientation}deg)`).style("font-size",i=>`${i.fontSize}px`).style("font-family",i=>i.fontFamily||"'Wonder Unit Sans', sans-serif").style("font-weight",i=>i.highlighted?600:400).style("color",i=>i.selected?i.selectedColor||"#000000":i.color||"#000000").html(i=>i.text.replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/\n/g,"<br/>")),Ne){const i=this.zoomTransform.k;r.attr("width",n=>`${n.width*i}px`).attr("height",n=>`${n.height*i}px`).select("div").style("position","absolute").style("left",n=>`${n.coords[0]*i+this.zoomTransform.x}px`).style("top",n=>`${n.coords[1]*i+this.zoomTransform.y}px`).select("p").style("font-size",n=>`${n.fontSize*i}px`)}}updateObjectsInView(...t){let e=this.selectCanvasElements().selectAll("g.diagram-object").data(this.model.objects.filter(i=>this.priorityThreshold!==void 0?i.getPriority()>=this.priorityThreshold:!0),i=>i.id);const a=e.exit(),l=e.enter().append("g").attr("id",i=>i.id).attr("class","diagram-object");t&&t.length>0&&(e=e.filter(i=>t.includes(i.id))),l.merge(e).attr("width",i=>`${i.width}px`).attr("height",i=>`${i.height}px`).attr("transform",i=>`translate(${i.coords[0]},${i.coords[1]})`).html(i=>i.html),a.remove(),l.on(S.ContextMenu,(i,n)=>{if(this.dragging){i.preventDefault(),i.stopPropagation(),this.dragging=!1;return}const o=new pt(i,n);this.diagramEvent$.next(o),!o.defaultPrevented&&this.canUserPerformAction(k.ContextMenu)&&(i.preventDefault(),this.contextMenu.open(i))}).on(S.DoubleClick,(i,n)=>{const o=new ut(i,n);this.diagramEvent$.next(o)}).call(A.drag().filter(i=>(this.secondaryButton=mt(i),!0)).on($.Start,i=>{(this.multipleSelectionOn||this.secondaryButton)&&this.startMultipleSelection(i)}).on($.Drag,i=>{(this.multipleSelectionOn||this.secondaryButton)&&this.continueMultipleSelection(i)}).on($.End,i=>{(this.multipleSelectionOn||this.secondaryButton)&&this.finishMultipleSelection(i)}))}updateDecoratorsInView(...t){let e=this.selectCanvasElements().selectAll("g.diagram-decorator").data(this.model.decorators.filter(i=>this.priorityThreshold!==void 0?i.getPriority()>=this.priorityThreshold:!0),i=>i.id);const a=e.exit(),l=e.enter().append("g").attr("id",i=>i.id).attr("class","diagram-decorator");t&&t.length>0&&(e=e.filter(i=>t.includes(i.id))),l.merge(e).attr("width",i=>`${i.width}px`).attr("height",i=>`${i.height}px`).attr("transform",i=>`translate(${i.coords[0]},${i.coords[1]})`).html(i=>i.html),a.remove(),l.on(S.MouseOver,(i,n)=>{this.dragging||(this.userHighlight.focusOn(n),this.diagramEvent$.next(new Q(n)))}).on(S.Click,(i,n)=>{if(!i.ctrlKey&&!i.shiftKey){const o=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new H(o,!1))}if(n.rootElement){const o=dt(n.rootElement);this.userSelection.toggle(o),this.diagramEvent$.next(new H([o],o.selected))}}).on(S.ContextMenu,(i,n)=>{if(this.dragging){i.preventDefault(),i.stopPropagation(),this.dragging=!1;return}const o=new pt(i,n);if(this.diagramEvent$.next(o),!o.defaultPrevented&&this.canUserPerformAction(k.ContextMenu)&&n.rootElement){i.preventDefault();const d=dt(n.rootElement);this.userHighlight.focusOn(d),this.diagramEvent$.next(new Q(d)),this.userSelection.add(d),this.diagramEvent$.next(new H([d],!0)),this.contextMenu.open(i)}}).on(S.DoubleClick,(i,n)=>{const o=new ut(i,n);this.diagramEvent$.next(o)}).call(A.drag().filter(i=>(this.secondaryButton=mt(i),!0)).on($.Start,(i,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.startMultipleSelection(i);else{let o;n.rootElement instanceof z?o=n.rootElement:n.rootElement instanceof U&&(o=n.rootElement.node),o?this.startMovingNode(i,o):w(L.NotAllowed)}}).on($.Drag,(i,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(i);else{let o;n.rootElement instanceof z?o=n.rootElement:n.rootElement instanceof U&&(o=n.rootElement.node),o?this.continueMovingNode(i,o):w(L.NotAllowed)}}).on($.End,(i,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(i);else{let o;n.rootElement instanceof z?o=n.rootElement:n.rootElement instanceof U&&(o=n.rootElement.node),o?this.finishMovingNode(i,o):w()}this.secondaryButton=!1}))}updateConnectionLabelsInView(t){const e=this.selectCanvasView().select(`[id='${ce(t.id)}']`),l=e.select("path").node(),r={...O,...t.type.label};if(l){const i=l.getTotalLength();let n=0,o=0,d=0,c=0,h=0,u=0;if(r.backgroundColor==="#00000000"){const g=t.endCoords[0]-t.startCoords[0],v=t.endCoords[1]-t.startCoords[1];switch(t.startDirection){case f.Top:n=g>=0?-.5:.5,h=n;break;case f.Bottom:n=g>=0?-.5:.5,h=n;break;case f.Left:o=v>0?-.5:.5,u=o;break;case f.Right:o=v>0?-.5:.5,u=o;break;default:n=.5,h=n,o=-.5,u=o}switch(t.endDirection){case f.Top:h=g>=0?.5:-.5;break;case f.Bottom:h=g>=0?.5:-.5;break;case f.Left:u=v>0?.5:-.5;break;case f.Right:u=v>0?.5:-.5;break;default:h=.5,u=-.5}Math.abs(g)>=Math.abs(v)?(d=g>0?-.5:.5,c=v>0?.5:-.5):(d=g>0?.5:-.5,c=v>0?-.5:.5)}e.select("g.diagram-connection-start-label text").attr("x",0).attr("y",r.fontSize/3).attr("text-anchor","middle").attr("font-family",r.fontFamily).attr("font-size",r.fontSize).attr("fill",t.selected?r.selectedColor:r.color).style("font-kerning","none").text(t.startLabel);const b=e.select("g.diagram-connection-start-label text").node()?.getBoundingClientRect();if(b){const g=t.startLabel?b.width/this.zoomTransform.k+Ot(r)+_t(r):0,v=t.startLabel?b.height/this.zoomTransform.k+Ht(r)+Vt(r):0;let y;switch(t.startDirection){case f.Left:y=l.getPointAtLength(it(r)+g/2);break;case f.Right:y=l.getPointAtLength(D(r)+g/2);break;case f.Top:y=l.getPointAtLength(q(r)+g/2);break;case f.Bottom:y=l.getPointAtLength(G(r)+g/2);break;default:y=l.getPointAtLength(Math.max(D(r)+g/2,it(r)+g/2,G(r)+v/2,q(r)+v/2))}e.select("g.diagram-connection-start-label path").attr("d",Yt(-g/2,-v/2,g,v)).attr("fill",r.backgroundColor).attr("stroke","none"),e.select("g.diagram-connection-start-label").attr("transform",`translate(${y.x+n*g},${y.y+o*v})`)}e.select("g.diagram-connection-middle-label text").attr("x",0).attr("y",r.fontSize/3).attr("text-anchor","middle").attr("font-family",r.fontFamily).attr("font-size",r.fontSize).attr("fill",t.selected?r.selectedColor:r.color).style("font-kerning","none").text(t.middleLabel);const m=e.select("g.diagram-connection-middle-label text").node()?.getBoundingClientRect();if(m){const g=t.middleLabel?m.width/this.zoomTransform.k+Ot(r)+_t(r):0,v=t.middleLabel?m.height/this.zoomTransform.k+Ht(r)+Vt(r):0,y=l.getPointAtLength(i/2);e.select("g.diagram-connection-middle-label path").attr("d",Yt(-g/2,-v/2,g,v)).attr("fill",r.backgroundColor).attr("stroke","none"),e.select("g.diagram-connection-middle-label").attr("transform",`translate(${y.x+d*g},${y.y+c*v})`)}e.select("g.diagram-connection-end-label text").attr("x",0).attr("y",r.fontSize/3).attr("text-anchor","middle").attr("font-family",r.fontFamily).attr("font-size",r.fontSize).attr("fill",t.selected?r.selectedColor:r.color).style("font-kerning","none").text(t.endLabel);const x=e.select("g.diagram-connection-end-label text").node()?.getBoundingClientRect();if(x){const g=t.endLabel?x.width/this.zoomTransform.k+Ot(r)+_t(r):0,v=t.endLabel?x.height/this.zoomTransform.k+Ht(r)+Vt(r):0;let y;switch(t.endDirection){case f.Left:y=l.getPointAtLength(i-(it(r)+g/2));break;case f.Right:y=l.getPointAtLength(i-(D(r)+g/2));break;case f.Top:y=l.getPointAtLength(i-(q(r)+g/2));break;case f.Bottom:y=l.getPointAtLength(i-(G(r)+g/2));break;default:y=l.getPointAtLength(i-Math.max(D(r)+g/2,it(r)+g/2,G(r)+v/2,q(r)+v/2))}e.select("g.diagram-connection-end-label path").attr("d",Yt(-g/2,-v/2,g,v)).attr("fill",r.backgroundColor).attr("stroke","none"),e.select("g.diagram-connection-end-label").attr("transform",`translate(${y.x+h*g},${y.y+u*v})`)}}}updateConnectionMarkersInView(t){const e=this.selectCanvasView().select(`[id='${ce(t.id)}']`),a=e.select("marker.diagram-connection-start-marker"),l=e.select("marker.diagram-connection-end-marker");t.startMarkerLook!==null?a.attr("orient","auto-start-reverse").attr("markerWidth",t.startMarkerLook.width).attr("markerHeight",t.startMarkerLook.height).attr("refX",t.startMarkerLook.refX).attr("refY",t.startMarkerLook.refY).select("image").attr("href",t.startMarkerLook.image).attr("width",t.startMarkerLook.width).attr("height",t.startMarkerLook.height):a.attr("orient","auto-start-reverse").attr("markerWidth",0).attr("markerHeight",0),t.endMarkerLook!==null?l.attr("orient","auto-start-reverse").attr("markerWidth",t.endMarkerLook.width).attr("markerHeight",t.endMarkerLook.height).attr("refX",t.endMarkerLook.refX).attr("refY",t.endMarkerLook.refY).select("image").attr("href",t.endMarkerLook.image).attr("width",t.endMarkerLook.width).attr("height",t.endMarkerLook.height):l.attr("orient","auto-start-reverse").attr("markerWidth",0).attr("markerHeight",0)}fieldRootFitsInView(t){const e=this.model.fields.get(t);if(!e)return!1;if(e.rootElement instanceof z||e.rootElement instanceof U){const a=this.minimumSizeOfField(e),l=a[0]+D(e.rootElement.type?.label)+it(e.rootElement.type?.label)-e.rootElement.width,r=a[1]+G(e.rootElement.type?.label)+q(e.rootElement.type?.label)-e.rootElement.height;return l<=0&&r<=0}return!0}fitFieldRootInView(t,e=!0){const a=this.model.fields.get(t);if(a){if(a.rootElement instanceof z){const l=this.minimumSizeOfField(a);let r=l[0]+D(a.rootElement.type.label)+it(a.rootElement.type.label)-a.rootElement.width,i=l[1]+G(a.rootElement.type.label)+q(a.rootElement.type.label)-a.rootElement.height;this.snapToGrid&&(r=Math.ceil(r/this.gridSize)*this.gridSize,i=Math.ceil(i/this.gridSize)*this.gridSize),a.rootElement.width+r<a.rootElement.type.minWidth&&(r=a.rootElement.type.minWidth-a.rootElement.width),a.rootElement.height+i<a.rootElement.type.minHeight&&(i=a.rootElement.type.minHeight-a.rootElement.height),(e!==!1||r>0)&&a.rootElement.stretch(f.Right,r),(e!==!1||i>0)&&a.rootElement.stretch(f.Bottom,i)}if(a.rootElement instanceof U){const l=this.minimumSizeOfField(a);let r=l[0],i=l[1];for(const c of a.rootElement.node?.sections||[])c.label&&(c.indexXInNode===a.rootElement.indexXInNode&&c.indexYInNode!==a.rootElement.indexYInNode?r=Math.max(r,this.minimumSizeOfField(c.label)[0]):c.indexXInNode!==a.rootElement.indexXInNode&&c.indexYInNode===a.rootElement.indexYInNode&&(i=Math.max(i,this.minimumSizeOfField(c.label)[1])));l[0]<r&&(l[0]=r),l[1]<i&&(l[1]=i);const n=a.rootElement.type;let o=l[0]+D(n?.label)+it(n?.label)-a.rootElement.width,d=l[1]+G(n?.label)+q(n?.label)-a.rootElement.height;this.snapToGrid&&(o=Math.ceil(o/this.gridSize)*this.gridSize,d=Math.ceil(d/this.gridSize)*this.gridSize),a.rootElement.width+o<(a.rootElement.getMinWidth()||0)&&(o=(a.rootElement.getMinWidth()||0)-a.rootElement.width),a.rootElement.height+d<(a.rootElement.getMinHeight()||0)&&(d=(a.rootElement.getMinHeight()||0)-a.rootElement.height),(e||o>0)&&a.rootElement.node?.stretchSections(f.Right,o,a.rootElement.indexXInNode,a.rootElement.indexYInNode),(e||d>0)&&a.rootElement.node?.stretchSections(f.Bottom,d,a.rootElement.indexXInNode,a.rootElement.indexYInNode)}}}fitNodeInView(t,e=!0){const a=this.model.nodes.get(t);if(a&&a.sections.length>0&&this.priorityThreshold){let l=0,r=0;for(const i of a.sections)if(i.getPriority()>=this.priorityThreshold){const n=i.coords[0]+i.width-a.coords[0],o=i.coords[1]+i.height-a.coords[1];l=Math.max(l,n),r=Math.max(r,o)}l+=a.type.sectionGrid?.margin||0,r+=a.type.sectionGrid?.margin||0,(e||l>a.width)&&a.stretch(f.Right,l-a.width),(e||r>a.height)&&a.stretch(f.Bottom,r-a.height)}}selectRoot(){return A.select(this.diagramRoot)}selectSVGElement(){return A.select(this.diagramRoot).select("svg")}selectCanvasView(){return this.selectSVGElement().select(".daga-canvas-view")}selectCanvasElements(){return this.selectSVGElement().select(".daga-canvas-elements")}startConnection(t){if(t.allowsOutgoing||t.allowsIncoming){if(this.connectionType&&(this.connectionType.canStartFromType(t.getNode()?.type?.id||"")&&t.allowsOutgoing||this.connectionType.canFinishOnType(t.getNode()?.type?.id||"")&&t.allowsIncoming))this.unfinishedConnection=new lt(this.model,this.connectionType,t,void 0,le);else if(this.inferConnectionType){let e=this.model.connections.types.all().find(a=>t.allowsOutgoing&&a.canStartFromType(t.getNode()?.type?.id||""));e===void 0&&(e=this.model.connections.types.all().find(a=>t.allowsIncoming&&a.canFinishOnType(t.getNode()?.type?.id||""))),e!==void 0&&(this.unfinishedConnection=new lt(this.model,e,t,void 0,le))}}}finishConnection(t){if(this.userHighlight.clear(),this.unfinishedConnection!==void 0){if(!this.allowConnectionLoops&&this.unfinishedConnection.start===t){this.dropConnection();return}if(!this.allowSharingPorts&&(t.incomingConnections.filter(e=>!e.removed).length>0||t.outgoingConnections.filter(e=>!e.removed).length>0)){this.dropConnection();return}if(!this.allowSharingBothPorts&&this.model.connections.find(e=>!e.removed&&(e.start===this.unfinishedConnection?.start&&e.end===t||e.end===this.unfinishedConnection?.start&&e.start===t))!==void 0){this.dropConnection();return}if(this.unfinishedConnection.type.canStartFromType(this.unfinishedConnection?.start?.getNode()?.type?.id||"")&&this.unfinishedConnection?.start?.allowsOutgoing&&this.unfinishedConnection.type.canFinishOnType(t.getNode()?.type?.id||"")&&t.allowsIncoming){const e=new se(this,this.unfinishedConnection.type,this.unfinishedConnection.start?.id,t.id);this.dropConnection(),e.do(),this.actionStack.add(e)}else if(this.unfinishedConnection.type.canFinishOnType(this.unfinishedConnection?.start?.getNode()?.type?.id||"")&&this.unfinishedConnection?.start?.allowsIncoming&&this.unfinishedConnection.type.canStartFromType(t.getNode()?.type?.id||"")&&t.allowsOutgoing){const e=new se(this,this.unfinishedConnection.type,t.id,this.unfinishedConnection.start?.id);this.dropConnection(),e.do(),this.actionStack.add(e)}else if(this.inferConnectionType){let e=this.model.connections.types.all().find(l=>l.canStartFromType(this.unfinishedConnection?.start?.getNode()?.type?.id||"")&&this.unfinishedConnection?.start?.allowsOutgoing&&l.canFinishOnType(t.getNode()?.type?.id||"")&&t.allowsIncoming),a=!1;if(e===void 0&&(e=this.model.connections.types.all().find(l=>l.canFinishOnType(this.unfinishedConnection?.start?.getNode()?.type?.id||"")&&this.unfinishedConnection?.start?.allowsIncoming&&l.canStartFromType(t.getNode()?.type?.id||"")&&t.allowsOutgoing),a=!0),e!==void 0){const l=new se(this,e,a?t.id:this.unfinishedConnection.start?.id,a?this.unfinishedConnection.start?.id:t.id);this.dropConnection(),l.do(),this.actionStack.add(l)}else this.dropConnection()}else this.dropConnection()}}dropConnection(){this.unfinishedConnection?.setStart(void 0),this.unfinishedConnection?.setEnd(void 0),this.unfinishedConnection?.select()?.remove(),this.unfinishedConnection=void 0}cancelAllUserActions(){this.currentAction=void 0,this.dropConnection(),this.removeInputField(),this.contextMenu.close(),this.userSelection.clear()}canUserPerformAction(t){return this.userActions[t]!==!1}createInputField(t,e,a,l,r,i,n,o,d){this.removeInputField();const c=this.selectCanvasElements().append("foreignObject").attr("x",`${e[0]}px`).attr("y",`${e[1]}px`).attr("width",`${a}px`).attr("height",`${l}px`).style("box-sizing","border-box").style("border","1px solid");this.inputFieldContainer=c;const h=c.append("xhtml:textarea");let u,b;h.text(t).style("box-sizing","border-box").style("width",`${a}px`).style("height",`${l}px`).style("font-size",`${r}px`).style("font-family",i).style("resize","none").style("outline",0).style("border",0).style("margin",0).style("padding",0).on(S.KeyDown,x=>{x.stopPropagation()}).on(S.KeyUp,x=>{if(x.stopPropagation(),x.key===K.Escape){const g=h.property("value");this.removeInputField(),d&&d(g)}}).on(S.Input,()=>{const x=h.property("value");h.attr("cols",mo(x)+1),h.attr("rows",vo(x)+1),h.style("width",""),h.style("height",""),u=h.property("scrollWidth")+1,b=h.property("scrollHeight")+1;const g=Math.max(u,a),v=Math.max(b,l);c?.attr("width",`${g}px`),h.style("width",`${g}px`),c?.attr("height",`${v}px`),h.style("height",`${v}px`),o&&o(x)}).on(S.Click,x=>{x.stopPropagation()}).on(S.FocusOut,()=>{const x=h.property("value");this.removeInputField(),d&&d(x)});const m=h.node();m.focus(),m.select()}removeInputField(){this.inputFieldContainer?.select("input")?.on(S.Blur,null),this.inputFieldContainer?.remove(),this.inputFieldContainer=void 0}minimumSizeOfField(t){const e=t.select()?.select("p")?.node();if(!e)return[0,0];const a=e.getBoundingClientRect();return[a.width/this.zoomTransform.k,a.height/this.zoomTransform.k]}startMovingNode(t,e){if(this.canUserPerformAction(k.MoveNode)&&!e.removed)if(w(L.Grabbing),this.draggingFrom=[t.x,t.y],e.selected&&this.userSelection.count(a=>a instanceof z)>1)this.currentAction=new ie(this,this.userSelection.filter(a=>a instanceof z).map(a=>a.id),e.coords);else{const a=e.getLastAncestor();this.currentAction=new X(this,k.MoveNode,e.id,e.getGeometry(),e.getGeometry(),a?.id,a?.getGeometry(e.id),a?.getGeometry(e.id))}else w(L.NotAllowed)}continueMovingNode(t,e){if(this.canUserPerformAction(k.MoveNode)&&(this.currentAction instanceof ie||this.currentAction instanceof X)&&!e.removed){const a=[t.x-e.width/2,t.y-e.height/2];e.selected?this.userSelection.move([a[0]-e.coords[0],a[1]-e.coords[1]]):e.move(a),this.userHighlight.clear(),this.dragging=!0}}finishMovingNode(t,e){if(this.canUserPerformAction(k.MoveNode)&&!e.removed&&(this.draggingFrom[0]!==t.x||this.draggingFrom[1]!==t.y)){let a=[t.x-e.width/2,t.y-e.height/2];if(this.snapToGrid&&(a=this.getClosestGridPoint([a[0]-e.type.snapToGridOffset[0],a[1]-e.type.snapToGridOffset[1]]),a[0]+=e.type.snapToGridOffset[0],a[1]+=e.type.snapToGridOffset[1]),this.currentAction instanceof ie){const l=this.currentAction.delta;this.currentAction.delta=[a[0]-l[0],a[1]-l[1]],e.selected?this.userSelection.move([l[0]-e.coords[0],l[1]-e.coords[1]]):e.move(l)}else if(this.currentAction instanceof X){e.move(a);const r=this.model.nodes.getAtCoordinates(t.x,t.y).filter(o=>o.id!==e.id&&!o.isDescendantOf(e)).filter(o=>o.type.childrenTypes.includes(e.type.id)),i=Fe(r),n=i[i.length-1];if(n!==e.parent&&(e.type.canBeParentless||n!==void 0)){const o=n?.getLastAncestor(),d=this.currentAction.from,c=new Fo(this,e.id,e.parent?.id,n?.id,d,e.getGeometry(),o?.id,o?.getGeometry(e.id),o?.getGeometry(e.id));e.parent?.removeChild(e),n!==void 0&&n.addChild(e),c.toChildGeometry=e.getGeometry(e.id),c.toAncestorGeometry=o?.getGeometry(e.id),this.currentAction=c}else{const o=e?.getLastAncestor();this.currentAction.ancestorId=o?.id,this.currentAction.fromAncestorGeometry=o?.getGeometry(e.id),e.parent?.fitToChild(e),this.currentAction.to=e.getGeometry(e.id),this.currentAction.toAncestorGeometry=o?.getGeometry(e.id)}}this.currentAction!==void 0&&(this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0)}w(),this.dragging=!1}startMultipleSelection(t){this.draggingFrom=this.getPointerLocationRelativeToCanvas(t),this.multipleSelectionContainer=this.selectSVGElement().append("rect").attr("stroke","#0E74B6").attr("fill","rgba(14, 116, 182, 0.06)")}continueMultipleSelection(t){const e=this.getPointerLocationRelativeToCanvas(t);(this.draggingFrom[0]!==e[0]||this.draggingFrom[1]!==e[1])&&(w(L.Crosshair),this.multipleSelectionContainer?.attr("x",Math.min(this.draggingFrom[0],e[0])*this.zoomTransform.k+this.zoomTransform.x)?.attr("y",Math.min(this.draggingFrom[1],e[1])*this.zoomTransform.k+this.zoomTransform.y)?.attr("width",Math.abs(this.draggingFrom[0]-e[0])*this.zoomTransform.k)?.attr("height",Math.abs(this.draggingFrom[1]-e[1])*this.zoomTransform.k),this.dragging=!0)}finishMultipleSelection(t){const e=this.getPointerLocationRelativeToCanvas(t);this.multipleSelectionContainer?.remove(),this.multipleSelectionContainer=void 0,this.userSelection.clear();for(const a of this.model.nodes)no([a.coords,[a.coords[0]+a.width,a.coords[1]+a.height]],[this.draggingFrom,e])&&this.userSelection.add(a);this.multipleSelectionOn=!1,this.diagramEvent$.next(new H(this.userSelection.all(),!0)),w()}};Zt.canvasCount=0;let ue=Zt;class Ke{constructor(){this.grid=[[void 0]],this.offsetX=0,this.offsetY=0}minX(){return-this.offsetX}maxX(){return this.width()-1-this.offsetX}minY(){return-this.offsetY}maxY(){return this.height()-1-this.offsetY}width(){return this.grid[0].length}height(){return this.grid.length}addColumnLeft(){for(const t of this.grid)t.splice(0,0,void 0);this.offsetX=this.offsetX+1}addColumnRight(){for(const t of this.grid)t.push(void 0)}addRowTop(){const t=[];for(let e=0;e<this.grid[0].length;++e)t.push(void 0);this.grid.splice(0,0,t),this.offsetY=this.offsetY+1}addRowBottom(){const t=[];for(let e=0;e<this.grid[0].length;++e)t.push(void 0);this.grid.push(t)}get(t){if(this.grid[t[1]+this.offsetY])return this.grid[t[1]+this.offsetY][t[0]+this.offsetX]}set(t,e){for(;t[0]<-this.offsetX;)this.addColumnLeft();for(;t[0]>=this.width()-this.offsetX;)this.addColumnRight();for(;t[1]<-this.offsetY;)this.addRowTop();for(;t[1]>=this.height()-this.offsetY;)this.addRowBottom();this.grid[t[1]+this.offsetY][t[0]+this.offsetX]=e}getClosestEmptyCoordinate(t){if(this.get(t)===void 0)return t;const e=[...t];for(let a=1;;++a){const l=a%2>0?a:-a,r=l>0?1:-1,i=[e[0]+l,e[1]+l];for(let n=e[0];n!==i[0]+r;n+=r)if(e[0]=n,this.get(e)===void 0)return e;for(let n=e[1];n!==i[1]+r;n+=r)if(e[1]=n,this.get(e)===void 0)return e}}}class ai{constructor(t){this.gapSize=t}apply(t){if(t.nodes.length===0)return t;const e=new Ke,a=t.nodes.filter(n=>!n.parent);for(;a.length>0;)qe(a[0],e,[0,0],a);const l=Math.max(...t.nodes.map(n=>n.width)),r=Math.max(...t.nodes.map(n=>n.height)),i=this.gapSize!==void 0?this.gapSize:(t.canvas?.gridSize||0)*2;for(let n=e.minY();n<=e.maxY();++n)for(let o=e.minX();o<=e.maxX();++o){const d=e.get([o,n]);d!==void 0&&d.move([o*(l+i),n*(r+i)])}return t}}const qe=(s,t,e,a)=>{const l=t.getClosestEmptyCoordinate(e);t.set(l,s),B(a,s);for(const r of s.getAdjacentNodes())a.includes(r)&&qe(r,t,l,a)};class li{constructor(t){this.gapSize=t}apply(t){if(t.nodes.length===0)return t;const e=new Ke,a=t.nodes.filter(c=>!c.parent),l={},r=a[0];let i=[r];for(l[r.id]=[0,0];a.length>0;){const c=[];for(const h of i){e.set(e.getClosestEmptyCoordinate(l[h.id]),h),B(a,h);const u=h.getAdjacentNodes();for(const b of u)a.includes(b)&&(c.push(b),l[b.id]=l[h.id])}if(c.length>0)i=c;else if(a.length>0){const h=a[0];i=[h],l[h.id]=e.getClosestEmptyCoordinate([0,0])}}const n=Math.max(...t.nodes.map(c=>c.width)),o=Math.max(...t.nodes.map(c=>c.height)),d=this.gapSize!==void 0?this.gapSize:(t.canvas?.gridSize||0)*2;for(let c=e.minY();c<=e.maxY();++c)for(let h=e.minX();h<=e.maxX();++h){const u=e.get([h,c]);u!==void 0&&u.move([h*(n+d),c*(o+d)])}return t}}class ee{constructor(t){this.gapSize=t}apply(t){if(t.nodes.length===0)return t;const e=this.gapSize!==void 0?this.gapSize:(t.canvas?.gridSize||0)*2;let a=t.nodes.filter(n=>!n.parent);const l=a[0];B(a,l);const r=[[l]];for(;a.length>0;){const n=r[r.length-1],o=[];for(const d of n){const c=d.getAdjacentNodes();for(const h of c)a.includes(h)&&(B(a,h),o.push(h))}o.length>0?r.push(o):(r.push(a),a=[])}let i=0;for(const n of r){let o=0;for(const c of n)c.move([i,o]),o+=e+c.height;const d=Math.max(...n.map(c=>c.width));i+=e+d}for(const n of t.connections)n.tighten();return t}}class di{constructor(t){this.gapSize=t}apply(t){if(t.nodes.length===0)return t;new ee(this.gapSize).apply(t);const e=this.gapSize!==void 0?this.gapSize:(t.canvas?.gridSize||0)*2,a=.99,l=1,r=.1,i=2e5,n=.5,o=1,d=.002;let c=100;for(;c>l;){c=c*a;const h=[0,0];{for(const u of t.nodes)h[0]=h[0]+u.coords[0]+u.width/2,h[1]=h[1]+u.coords[1]+u.width/2;h[0]=h[0]/t.nodes.length,h[1]=h[1]/t.nodes.length}for(const u of t.nodes){const b=u.getAdjacentNodes();for(const m of t.nodes){const x=[u.coords[0]+u.width/2,u.coords[1]+u.height/2],g=[m.coords[0]+m.width/2,m.coords[1]+m.height/2],v=Re(u.coords,m.coords),y=[m.coords[0],m.coords[1]];if(b.includes(m)&&v>0&&(v>e+(Math.max(u.width,u.height)+Math.max(m.width,m.height))/2?(y[0]=y[0]-(g[0]-x[0])*r,y[1]=y[1]-(g[1]-x[1])*r):(y[0]=y[0]+(g[0]-x[0])*n,y[1]=y[1]+(g[1]-x[1])*n)),v>0){const T=i/(v*v);y[0]=y[0]+T*(g[0]-x[0])/v,y[1]=y[1]+T*(g[1]-x[1])/v}else y[0]=y[0]+o*(Math.random()*2-1),y[1]=y[1]+o*(Math.random()*2-1);y[0]=y[0]-(g[0]-h[0])*d,y[1]=y[1]-(g[1]-h[1])*d,y[0]-m.coords[0]>c?y[0]=m.coords[0]+c:y[0]-m.coords[0]<-c&&(y[0]=m.coords[0]-c),y[1]-m.coords[1]>c?y[1]=m.coords[1]+c:y[1]-m.coords[1]<-c&&(y[1]=m.coords[1]-c),m.move(y)}}}if(t.canvas&&t.canvas.snapToGrid)for(const h of t.nodes){const u=t.canvas.getClosestGridPoint([h.coords[0]-h.type.snapToGridOffset[0],h.coords[1]-h.type.snapToGridOffset[1]]);u[0]+=h.type.snapToGridOffset[0],u[1]+=h.type.snapToGridOffset[1],h.move(u)}for(const h of t.connections)h.tighten();return t}}class ci{constructor(t){this.gapSize=t}apply(t){if(t.nodes.length===0)return t;const e=this.gapSize!==void 0?this.gapSize:(t.canvas?.gridSize||0)*2,a=t.nodes.filter(r=>!r.parent);a.sort((r,i)=>i.type.priority-r.type.priority);let l=0;for(const r of a)r.move([l,0]),l+=r.width+e;return t}}class hi{constructor(t){this.gapSize=t}apply(t){if(t.nodes.length===0)return t;const e=Math.max(...t.nodes.map(c=>c.getPriority())),a=Math.min(...t.nodes.map(c=>c.getPriority()));if(e===a)return new ee(this.gapSize).apply(t),t;const l=this.gapSize!==void 0?this.gapSize:(t.canvas?.gridSize||0)*2,r=t.nodes.filter(c=>!c.parent),i=[],n=t.nodes.filter(c=>!c.parent).filter(c=>c.getPriority()>=e),o=[];if(n.length>1){const c=n[0];n.splice(0,1),o.push(c);const h=[c],u=[c];for(;h.length>0;){const b=h[0];h.splice(0,1),n.includes(b)&&(o.push(b),B(n,b));const m=b.getAdjacentNodes();for(const x of m)u.includes(x)||(h.push(x),u.push(x))}for(const b of n)o.push(b)}else o.push(n[0]);for(const c of o)B(r,c),i.push([c]);for(i.push([]),r.sort((c,h)=>h.type.priority-c.type.priority);r.length>0;){const c=r[0];r.splice(0,1);const h=[c],u=[c];let b=!1;for(;h.length>0;){const m=h[0];h.splice(0,1);const x=o.indexOf(m);if(x>=0){i[x].push(c),b=!0;break}else{const g=m.getAdjacentNodes();for(const v of g)u.includes(v)||(h.push(v),u.push(v))}}b||i[i.length-1].push(c)}let d=0;for(let c=0;c<i.length;++c){let h=0;for(let b=0;b<i[c].length;++b){const m=i[c][b];m.move([d,h]),h+=l+m.height}const u=Math.max(...i[c].map(b=>b.width));d+=l+u}for(const c of t.connections)c.tighten();return t}}class gi{constructor(t){this.gapSize=t}apply(t){if(t.nodes.length===0)return t;const e=Math.max(...t.nodes.map(c=>c.getPriority())),a=Math.min(...t.nodes.map(c=>c.getPriority()));if(e===a)return new ee(this.gapSize).apply(t),t;const l=this.gapSize!==void 0?this.gapSize:(t.canvas?.gridSize||0)*2,r=t.nodes.filter(c=>!c.parent).sort((c,h)=>h.getPriority()-c.getPriority()),i=[];for(;r.length>0;){const c=r[0];r.splice(0,1);const h=new ye(void 0,c);Je(h,r),i.push(h)}const n=[];for(const c of i)n.push([c]),Qe(c,n,n.length);const o=Math.max(...t.nodes.map(c=>c.height));let d=0;for(let c=0;c<n.length;++c){let h=0;for(let b=0;b<n[c].length;++b){const m=n[c][b];m.node.move([d,h]),h+=(l+o)*m.countBranchHeight()}const u=Math.max(...n[c].map(b=>b.node.width));d+=l+u}for(const c of t.connections)c.tighten();return t}}const Je=(s,t)=>{for(const e of s.node.getAdjacentNodes().sort((a,l)=>l.getPriority()-a.getPriority())){const a=t.indexOf(e);if(a>=0){t.splice(a,1);const l=s.addBranch(e);Je(l,t)}}},Qe=(s,t,e)=>{if(s.branches.length>0){for(;e>=t.length;)t.push([]);for(const a of s.branches)t[e].push(a),Qe(a,t,e+1)}};class ye{constructor(t,e){this.parent=t,this.branches=[],this.depth=0,this.node=e}addBranch(t){const e=new ye(this,t);return e.depth=this.depth+1,this.branches.push(e),e}countBranchHeight(){if(this.branches.length<=0)return 1;{let t=0;for(const e of this.branches)t+=e.countBranchHeight();return t}}}class fi{constructor(t){this.gapSize=t}apply(t){if(t.nodes.length===0)return t;const e=this.gapSize!==void 0?this.gapSize:(t.canvas?.gridSize||0)*2,a=t.nodes.filter(r=>!r.parent);a.sort((r,i)=>i.type.priority-r.type.priority);let l=0;for(const r of a)r.move([0,l]),l+=r.height+e;return t}}const Pe={adjacency:new ai,breadth:new ee,"breadth-adjacency":new li,force:new di,horizontal:new ci,priority:new hi,tree:new gi,vertical:new fi},ui=I.createContext({}),xt=I.createContext({});class pi{constructor(t,e){this.onTitleChange=t,this.onValueSetChange=e}get title(){return this._title}set title(t){this._title=t,this.onTitleChange(t)}get valueSet(){return this._valueSet}set valueSet(t){this._valueSet=t,this.onValueSetChange(t)}highlightProperty(...t){}}const be=({direction:s,collapsableSelector:t,collapsableAdditionalSelector:e,collapsed:a,disabled:l,rule:r,collapsedValue:i,visibleValue:n,onCollapse:o})=>{const[d,c]=I.useState(a),h=()=>{if(!l){const b=!d;c(b),o?.(b);let m;if(typeof t=="string")m=A.select(t),e&&(m=m.select(e));else{const x=t;if(!x)throw new Error("collapsableSelector is not a valid ref");m=A.select(x.current),e&&(m=m.select(e))}m.style(r,b?i:n)}},u=()=>{switch(s){case f.Right:return l?"daga-horizontal-none":d?"daga-horizontal-right":"daga-horizontal-left";case f.Bottom:return l?"daga-vertical-none":d?"daga-vertical-down":"daga-vertical-up";case f.Left:return l?"daga-horizontal-none":d?"daga-horizontal-left":"daga-horizontal-right";case f.Top:return l?"daga-vertical-none":d?"daga-vertical-up":"daga-vertical-down"}};return p.jsx("daga-collapse-button",{children:p.jsx("button",{className:`daga-collapse-button daga-${s}`,onClick:h,children:p.jsx("div",{className:u()})})})},mi=()=>{const s=I.useContext(xt),t=I.useRef(null),[e,a]=I.useState([]);kt.merge(s.validatorChange$,s.diagramChange$).pipe(kt.map(()=>l())).subscribe();const l=()=>{a([]);for(const i of s.validators){const n=i.validate(s.model);a(n)}},r=i=>{if(i.elementId&&(i.propertyNames===void 0||i.propertyNames.length===0)){const n=s.model.nodes.get(i.elementId)||s.model.connections.get(i.elementId);n&&s.userHighlight.add(n)}else if(i.elementId&&i.propertyNames!==void 0&&i.propertyNames.length>0){s.userSelection.openInPropertyEditor(s.model.nodes.get(i.elementId)||s.model.connections.get(i.elementId));const n=s.model.nodes.get(i.elementId)||s.model.connections.get(i.elementId);n&&s.userHighlight.add(n),s.parentComponent?.propertyEditor?.highlightProperty(...i.propertyNames)}else!i.elementId&&i.propertyNames!==void 0&&i.propertyNames.length>0&&(s.userSelection.openInPropertyEditor(),s.parentComponent?.propertyEditor?.highlightProperty(...i.propertyNames))};return p.jsx("daga-errors",{children:p.jsxs("div",{ref:t,className:"daga-errors",children:[e.length===0&&p.jsx("div",{className:"daga-errors-summary daga-no-errors daga-prevent-user-select",children:p.jsx("span",{children:"No errors found"})}),e.length>0&&p.jsxs("div",{className:"daga-errors-summary daga-with-errors daga-prevent-user-select",children:[p.jsxs("span",{children:[e.length," errors found"]}),p.jsx("div",{className:"daga-collapse-button-container",children:p.jsx(be,{collapsableSelector:t,collapsableAdditionalSelector:".daga-error-panel",direction:f.Top,rule:"display",collapsedValue:"none",visibleValue:"block",collapsed:!1,disabled:!1})})]}),e.length>0&&p.jsx("div",{className:"daga-error-panel",children:p.jsx("ol",{children:e.map((i,n)=>p.jsx("li",{onClick:()=>r(i),dangerouslySetInnerHTML:{__html:i.message}},n))})})]})})},vi=200,ze=s=>(s||"").toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g,""),to=({disabled:s,options:t,value:e,onChange:a})=>{const l=I.useRef(null),[r,i]=I.useState(""),[n,o]=I.useState(void 0),[d,c]=I.useState([]),[h,u]=I.useState([]),[b,m]=I.useState([]),[x,g]=I.useState([]),[v,y]=I.useState(!1);I.useEffect(()=>{i(t.find(E=>wt(E.key,e))?.label||"")},[e,t]);const T=E=>{if(!s)switch(E.key){case K.PageDown:n===void 0?(F(0),M(0)):(F(n+5),M(n)),E.preventDefault();break;case K.ArrowDown:n===void 0?(F(0),M(0)):(F(n+1),M(n)),E.preventDefault();break;case K.PageUp:n===void 0?(F(t.length-1),M(t.length-1)):(F(n-5),M(n)),E.preventDefault();break;case K.ArrowUp:n===void 0?(F(t.length-1),M(t.length-1)):(F(n-1),M(n)),E.preventDefault();break;case K.Escape:j(),E.preventDefault();break;case K.Enter:R(t[n||0]),E.preventDefault();break;default:P()}},P=()=>{if(!s){const E=ze(r.trim());c([]),u([]),m([]),g([]);for(const V of t){const J=ze(V.label).indexOf(E);if(J>=0){const tt=V.label.substring(0,J),$t=V.label.substring(J,J+E.length),Pt=V.label.substring(J+E.length);c(et=>[...et,V]),u(et=>[...et,tt]),m(et=>[...et,$t]),g(et=>[...et,Pt])}}y(!0)}},j=()=>{y(!1)},F=E=>{if(!s){let V=E;if(E===void 0){o(void 0);return}E<0&&(V=0),E>=t.length&&(V=t.length-1),o(V)}},Y=()=>{setTimeout(()=>{j()},vi)},M=E=>{const V=l.current?.querySelectorAll("li")[E];V&&V.scrollIntoView({block:"center"})},C=()=>{s||(i(""),y(!1),o(void 0))},R=E=>{s||(i(E.label),y(!1),o(void 0),a(E.key))};return p.jsxs("div",{ref:l,className:`daga-autocomplete ${v?"daga-showing-options":""}`,children:[p.jsxs("div",{className:"daga-autocomplete-input",children:[p.jsx("input",{value:r,disabled:s,onKeyUp:T,onFocus:P,onBlur:Y,onChange:E=>i(E.target.value)}),r!==""&&p.jsx("button",{className:"daga-clear",onClick:C})]}),p.jsx("div",{className:"daga-autocomplete-options",children:p.jsxs("ul",{className:"daga-autocomplete-option-list",children:[d.length===0&&p.jsx("li",{className:"daga-autocomplete-option no-options",children:"(No options)"}),d.map((E,V)=>p.jsxs("li",{className:`daga-autocomplete-option ${V===n?"daga-focused":""}`,onMouseMove:()=>F(V),onClick:()=>R(E),children:[p.jsx("span",{children:h[V]}),p.jsx("span",{className:"daga-match",children:b[V]}),p.jsx("span",{children:x[V]})]},V))]})})]})},yi=(s,t)=>s.find(e=>e.key===t)?.label||`${t}`,bi=({disabled:s,allowRepeats:t,options:e,value:a,onChange:l})=>{const[r,i]=I.useState(),[n,o]=I.useState([]),[d,c]=I.useState([]),h=g=>{for(const v of a)if(v===g)return!0;return!1},u=()=>{if(!t){const g=[];for(const v of e)h(v.key)||g.push(v);c(g)}};I.useEffect(()=>{const g=a.length===0,v=a.map(y=>yi(e,y));o(v),g&&l(a),u()},[a,e]);const b=g=>{a.length>g&&(a.splice(g,1),o(n.filter((v,y)=>y!==g)),l(a),u())},m=()=>{r!==void 0&&(t||!h(r))&&(l(a.concat(r)),x())},x=()=>{i("")};return p.jsxs("div",{children:[a.map((g,v)=>p.jsxs("div",{className:"daga-value-item-element",children:[p.jsx("span",{className:"daga-input",children:n[v]}),!s&&p.jsx("button",{className:"daga-property-button",onClick:()=>b(v),children:p.jsx("div",{className:"daga-icon daga-close-icon"})})]},v)),!s&&p.jsxs("div",{className:"daga-value-item-input",children:[p.jsx("div",{className:"daga-input daga-relatively-positioned",children:p.jsx(to,{disabled:s,options:t?e||[]:d||[],value:r,onChange:i})}),p.jsx("button",{className:"daga-property-button",onClick:m,children:p.jsx("div",{className:"daga-icon daga-add-icon"})})]})]})},ki=({disabled:s,allowRepeats:t,value:e,onChange:a})=>{const[l,r]=I.useState(""),i=u=>{for(const b of u||[])if(b===u)return!0;return!1},n=u=>{e.length>u&&a(e.filter((b,m)=>m!==u))},o=(u,b,m)=>{const x=e.map((g,v)=>v===b?m==="blur"?u.trim():u:g);a(x)},d=()=>{const u=l.trim();u!==""&&(t||!i(u))&&(a(e.concat(u)),c())},c=()=>{r("")},h=u=>{u.key==="Enter"&&d()};return p.jsxs(p.Fragment,{children:[e.map((u,b)=>p.jsxs("div",{className:"daga-value-item-element",children:[p.jsx("input",{className:"daga-input",disabled:s,value:u,onChange:m=>o(m.target.value,b,"change"),onBlur:m=>o(m.target.value,b,"blur")}),p.jsx("button",{className:"daga-property-button",onClick:()=>n(b),children:p.jsx("div",{className:"daga-icon daga-close-icon"})})]},b)),!s&&p.jsxs("div",{className:"daga-value-item-input",children:[p.jsxs("div",{className:"daga-input daga-relatively-positioned",children:[p.jsx("input",{type:"text",onKeyUp:h,value:l,onChange:u=>r(u.target.value)}),p.jsx("button",{className:"daga-clear",onClick:c})]}),p.jsx("button",{className:"daga-property-button",onClick:d,children:p.jsx("div",{className:"daga-icon daga-add-icon"})})]})]})},wi=({disabled:s,value:t,onChange:e})=>{const[a,l]=I.useState(""),[r,i]=I.useState(""),[n,o]=I.useState({}),d=g=>{const v={};Object.keys(t).forEach(y=>{y!==g&&(v[y]=t[y])}),e(v)},c=(g,v,y)=>{const T=y==="blur"?v.trim():v;if(y==="blur"){if(g!==T){const P={};Object.keys(t).forEach(j=>{j===g?P[T]=t[j]:P[j]=t[j]}),e(P),o(j=>{const F={...j};return delete F[g],F})}}else o(P=>({...P,[g]:v}))},h=(g,v,y)=>{const T=y==="blur"?v.trim():v;if(T!==""){const P={};Object.keys(t).forEach(j=>{j===g?P[j]=T:P[j]=t[j]}),e(P)}},u=()=>{const g=a.trim(),v=r.trim();if(g!==""&&v!==""){const y={};Object.keys(t).forEach(T=>{y[T]=t[T]}),y[g]=v,e(y),l(""),i("")}},b=()=>{l("")},m=()=>{i("")},x=g=>{g.key==="Enter"&&u()};return p.jsxs("div",{children:[Object.entries(t).map(([g,v],y)=>p.jsxs("div",{className:"daga-value-item-element",children:[p.jsx("input",{id:`key-${y}`,className:"daga-input",type:"text",disabled:s,value:n[g]??g,onChange:T=>c(g,T.target.value,"change"),onBlur:T=>c(g,T.target.value,"blur")}),p.jsx("input",{id:`value-${y}`,className:"daga-input",type:"text",disabled:s,value:v,onChange:T=>h(g,T.target.value,"change"),onBlur:T=>h(g,T.target.value,"blur")}),p.jsx("button",{className:"daga-property-button",onClick:()=>d(g),children:p.jsx("div",{className:"daga-icon daga-close-icon"})})]},g)),!s&&p.jsxs("div",{className:"daga-value-item-input",children:[p.jsxs("div",{className:"daga-input daga-relatively-positioned",children:[p.jsx("input",{type:"text",value:a,onKeyUp:x,onChange:g=>l(g.target.value),onBlur:g=>c(a,g.target.value,"blur")}),p.jsx("button",{className:"daga-clear",onClick:b})]}),p.jsxs("div",{className:"daga-input daga-relatively-positioned",children:[p.jsx("input",{type:"text",value:r,onKeyUp:x,onChange:g=>i(g.target.value),onBlur:g=>h(a,g.target.value,"blur")}),p.jsx("button",{className:"daga-clear",onClick:m})]}),p.jsx("button",{className:"daga-property-button",onClick:u,children:p.jsx("div",{className:"daga-icon daga-add-icon"})})]})]})},eo=({valueSet:s,onValueChange:t,depth:e})=>{const l=I.useContext(xt).canUserPerformAction(k.UpdateValues)&&s?.rootElement?.removed!==!0,r=o=>"daga-property-name-"+o.replace(/\s/g,""),i=o=>{if(typeof o=="string")return o;if(o==null||isNaN(o.valueOf()))return"";const d=new Date(o),c=d.getTimezoneOffset();return d.setMinutes(d.getMinutes()-c),d.toISOString().substring(0,19)},n=o=>new Date(o);return p.jsx("daga-object-editor",{children:s.displayedProperties.map(o=>p.jsxs("div",{className:`daga-property ${r(o.name)}`,children:[p.jsx("p",{className:"daga-property-name",children:o.label||o.name}),o.type===N.Text&&p.jsx("input",{type:"daga-text",disabled:o.editable===!1||!l,value:s?.getValue(o.name),onChange:d=>t(s,o,d.target.value)}),o.type===N.TextArea&&p.jsx("textarea",{disabled:o.editable===!1||!l,value:s?.getValue(o.name),onChange:d=>t(s,o,d.target.value)}),o.type===N.Number&&p.jsx("input",{type:"number",disabled:o.editable===!1||!l,value:s?.getValue(o.name),onChange:d=>t(s,o,d.target.value)}),o.type===N.Color&&p.jsx("input",{type:"text",pattern:"#[0-9a-fA-F]{6}",disabled:o.editable===!1||!l,value:s?.getValue(o.name),onChange:d=>t(s,o,d.target.value)}),o.type===N.Datetime&&p.jsx("input",{type:"datetime-local",disabled:o.editable===!1||!l,value:i(s?.getValue(o.name)),onChange:d=>t(s,o,n(d.target.value))}),o.type===N.Date&&p.jsx("input",{type:"date",disabled:o.editable===!1||!l,value:s?.getValue(o.name),onChange:d=>t(s,o,d.target.value)}),o.type===N.Time&&p.jsx("input",{type:"time",disabled:o.editable===!1||!l,value:s?.getValue(o.name),onChange:d=>t(s,o,d.target.value)}),o.type===N.Url&&p.jsx("input",{type:"url",disabled:o.editable===!1||!l,value:s?.getValue(o.name),onChange:d=>t(s,o,d.target.value)}),o.type===N.Boolean&&p.jsxs("div",{className:"daga-radio",children:[p.jsxs("label",{className:"daga-radio-item daga-radio-start"+(s?.getValue(o.name)===!1?" daga-checked":""),children:[p.jsx("input",{type:"radio",disabled:o.editable===!1||!l,name:o.name,value:"false",checked:s?.getValue(o.name)===!1,onChange:()=>t(s,o,!1)}),"No"]}),p.jsxs("label",{className:"daga-radio-item daga-radio-end"+(s?.getValue(o.name)===!0?" daga-checked":""),children:[p.jsx("input",{type:"radio",disabled:o.editable===!1||!l,name:o.name,value:"true",checked:s?.getValue(o.name)===!0,onChange:()=>t(s,o,!0)}),"Yes"]})]}),o.type===N.Option&&p.jsx("div",{className:"daga-relatively-positioned",children:p.jsx(to,{disabled:o.editable===!1||!l,options:o.options||[],value:s?.getValue(o.name),onChange:d=>t(s,o,d)})}),(o.type===N.OptionList||o.type===N.OptionSet)&&p.jsx(bi,{disabled:o.editable===!1||!l,allowRepeats:o.type===N.OptionList,options:o.options||[],value:s?.getValue(o.name),onChange:d=>t(s,o,d)}),(o.type===N.TextList||o.type===N.TextSet)&&p.jsx(ki,{disabled:o.editable===!1||!l,allowRepeats:o.type===N.TextList,value:s?.getValue(o.name),onChange:d=>t(s,o,d)}),o.type===N.TextMap&&p.jsx(wi,{disabled:o.editable===!1||!l,value:s?.getValue(o.name),onChange:d=>t(s,o,d)}),o.type===N.Object&&p.jsx("div",{className:"daga-left-bar",children:p.jsx(eo,{valueSet:s.getSubValueSet(o.name),onValueChange:t,depth:e+1})})]},o.name))})},oo=({valueSet:s,depth:t})=>{const e=I.useContext(xt),a=I.useRef(null),l=o=>"daga-property-name-"+o.replace(/\s/g,""),r=()=>{for(const o of s?.displayedProperties||[]){let d=0,c=0,h=0;const u=A.select(a.current).select(`.daga-property.${l(o.name)}.daga-depth-${t}`);u.select("button.daga-move-button").call(A.drag().on($.Start,b=>{w(L.Grabbing);const m=e.getPointerLocationRelativeToScreen(b);if(m.length<2||isNaN(m[0])||isNaN(m[1]))return;const x=u.node()?.getBoundingClientRect();d=x?.width||0,c=x?.height||0,u.style("position","fixed").style("left",`${m[0]-d/2}px`).style("top",`${m[1]-c/2}px`).style("width",`${d}px`).style("height",`${c}px`).style("z-index",1)}).on($.Drag,b=>{w(L.Grabbing);const m=e.getPointerLocationRelativeToScreen(b);m.length<2||isNaN(m[0])||isNaN(m[1])||(u.style("position","fixed").style("left",`${m[0]-d/2}px`).style("top",`${m[1]-c/2}px`).style("width",`${d}px`).style("height",`${c}px`).style("z-index",1),A.select(a.current).select(`.daga-dropbar.daga-index-${h}.daga-depth-${t}`).style("visibility","hidden").style("height",0),h=i(m),A.select(a.current).select(`.daga-dropbar.daga-index-${h}.daga-depth-${t}`).style("visibility","visible").style("height","0.25rem"))}).on($.End,b=>{w(L.Auto),u.style("position","relative").style("left",0).style("top",0).style("z-index",0).style("width","unset").style("height","unset"),A.select(a.current).select(`.daga-dropbar.daga-index-${h}.daga-depth-${t}`).style("visibility","hidden").style("height",0);const m=e.getPointerLocationRelativeToScreen(b);m.length<2||isNaN(m[0])||isNaN(m[1])||(h=i(m),s?.displayedProperties?.splice(s.displayedProperties.indexOf(o),1),s?.displayedProperties?.splice(h,0,o))}))}},i=o=>{const d=s?.propertySet.propertyList||[],c=[];for(let h=0;h<=d.length;++h){const u=A.select(a.current).select(`.daga-dropbar.daga-index-${h}.daga-depth-${t}`).node()?.getBoundingClientRect();u&&c.push([u.x+u.width/2,u.y+u.height/2])}if(c.length>0){const h=c.map(b=>((o[0]-b[0])**2+(o[1]-b[1])**2)**.5);return h.indexOf(Math.min(...h))}return 0},n=o=>{if(s===void 0)return;let d;o instanceof xo?d=o:o instanceof Event?d=s?.propertySet.getProperty(o.target?.value||""):d=s?.propertySet.getProperty(o||""),d&&s?.hideProperty(d),r()};return p.jsxs("daga-property-settings",{ref:a,children:[p.jsx("div",{className:`daga-dropbar daga-index-0 daga-depth-${t}`}),s?.displayedProperties.map((o,d)=>p.jsxs("div",{className:`daga-property-and-dropbar ${l(o.name)} daga-depth-${t}`,children:[p.jsxs("div",{className:`daga-property ${l(o.name)} daga-depth-${t}`,children:[p.jsxs("div",{className:"daga-property-name",children:[p.jsx("span",{children:o.label||o.name}),p.jsxs("div",{className:"daga-buttons",children:[p.jsx("button",{className:"daga-property-button daga-move-button",children:p.jsx("div",{className:"daga-icon daga-move-icon"})}),p.jsx("button",{className:"daga-property-button daga-hide-button",onClick:()=>n(o.name),children:p.jsx("div",{className:"daga-icon daga-hide-icon"})})]})]}),o.type!==N.Object&&p.jsx("div",{className:"daga-property-value",children:Si(s?.getValue(o.name))}),o.type===N.Object&&p.jsx(oo,{valueSet:s?.getSubValueSet(o.name),depth:t+1})]}),p.jsx("div",{className:`daga-dropbar daga-index-${d+1} daga-depth-${t}`})]},o.name))]})},Si=s=>Array.isArray(s)?s.join(", "):Co(s)?Object.entries(s).map(t=>t.map(e=>JSON.stringify(e)).join(": ")).join(", "):s instanceof Date?s.toLocaleString():s==null?"":""+s,xi=({location:s,direction:t,width:e,height:a,title:l,valueSet:r,onValueChange:i})=>{const n=I.useRef(null),[o,d]=I.useState(!1),[c,h]=I.useState(!1),u=()=>A.select(n.current);return I.useEffect(()=>{if(n.current)switch(t){case f.Bottom:case f.Top:u().style("width",e),a&&u().select(".daga-panel-content").style("height",a);break;case f.Left:case f.Right:u().style("height",e),a&&u().select(".daga-panel-content").style("width",a);break}},[e,a,t]),p.jsx("daga-property-editor",{children:p.jsxs("div",{ref:n,className:`daga-panel daga-bottom daga-${s} daga-${t}`,children:[p.jsx(be,{disabled:!r||!r.propertySet||!r.propertySet.hasProperties(),collapsed:o,direction:t,collapsableSelector:n,collapsableAdditionalSelector:".daga-panel-content",rule:"display",collapsedValue:"none",visibleValue:"block",onCollapse:d}),p.jsx("div",{className:"daga-panel-content",children:r&&r.propertySet&&r.propertySet.hasProperties()&&!o&&p.jsxs("div",{children:[l&&p.jsxs("p",{className:"daga-title",children:[l,p.jsx("button",{className:"daga-property-button",onClick:()=>h(!c),children:p.jsx("div",{className:`daga-icon daga-settings-icon ${c?"daga-unrotate":"daga-rotate"}`})})]}),!c&&p.jsx(eo,{valueSet:r,onValueChange:i,depth:0}),c&&p.jsx(oo,{valueSet:r,depth:0})]})})]})})},Ci=6,$i=s=>{const t=I.useContext(xt),[e,a]=I.useState(s.currentPalette||s.palettes[0]),[l,r]=I.useState(0),[i,n]=I.useState(void 0),o=I.useRef(null),d=I.useRef(!1),c=g=>{if(a(g),h().selectAll("*").remove(),r(t.getPriorityThreshold()||0),g.categories&&u(g.categories),g.templates)for(const v of g.templates)b(v)},h=()=>A.select(o.current).select(".daga-palette-view"),u=g=>{const v=h().append("select").style("width","100%").style("height","2rem").style("padding","0.5rem").style("border-radius","0.25rem").style("background-color","#f7f8fc").style("border","1px solid #e6e6e6");v.append("option").attr("value","").text("(None selected)");for(const y in g)v.append("option").attr("value",y).text(y);v.on(S.Change,()=>{i&&h().selectAll(".daga-template-container.daga-in-category").remove();const y=v.property("value");n(y);const T=g[y]||[];for(const P of T)b(P,"daga-in-category")}),i&&(v.property("value",i),v.dispatch(S.Change))},b=(g,v)=>{if(g.templateType==="node"){const y=t.model.nodes.types.get(g.type);y?m(y,g,v):console.error(`Could not find a node type called '${g.type}'`)}else if(g.templateType==="connection"){const y=t.model.connections.types.get(g.type);y?x(y,g,v):console.error(`Could not find a connection type called '${g.type}'`)}},m=(g,v,y)=>{if(l!==void 0&&g.priority<l)return;const T=g.defaultLook.lookType==="shaped-look"?g.defaultLook.borderThickness||1:0,P=g.defaultHeight+T,j=g.defaultWidth+T,F=v.height||P,Y=v.width||j,M=h().append("div").attr("class",`daga-template-container ${y!==void 0?y:""}`).style("width",`${Y}px`).style("height",`${F}px`).call(A.drag().on($.Drag,R=>{if(t.canUserPerformAction(k.AddNode)){const E=t.getPointerLocationRelativeToScreen(R);if(E.length<2||isNaN(E[0])||isNaN(E[1]))return;M.style("position","fixed").style("left",`${E[0]-Y/2}px`).style("top",`${E[1]-F/2}px`).style("z-index",1)}}).on($.Start,R=>{if(t.canUserPerformAction(k.AddNode)){w(L.Grabbing);const E=t.getPointerLocationRelativeToScreen(R);if(E.length<2||isNaN(E[0])||isNaN(E[1]))return;M.style("position","fixed").style("left",`${E[0]-Y/2}px`).style("top",`${E[1]-F/2}px`).style("z-index",1),g.isUnique&&t.model.nodes.find(V=>!V.removed&&V.type.id===g.id)!==void 0&&w(L.NotAllowed)}}).on($.End,R=>{if(t.canUserPerformAction(k.AddNode)){if(w(L.Auto),M.style("position","relative").style("left",0).style("top",0).style("z-index","auto"),g.isUnique&&t.model.nodes.find(Ut=>!Ut.removed&&Ut.type.id===g.id)!==void 0)return;const E=t.getPointerLocationRelativeToScreen(R);if(E.length<2||isNaN(E[0])||isNaN(E[1]))return;const V=document.elementFromPoint(E[0],E[1]);if(V&&!t.selectCanvasView().node()?.contains(V))return;const at=t.getPointerLocationRelativeToCanvas(R);if(at.length<2||isNaN(at[0])||isNaN(at[1]))return;let J=[at[0]-g.defaultWidth/2,at[1]-g.defaultHeight/2];t.snapToGrid&&(J=t.getClosestGridPoint([J[0]-g.snapToGridOffset[0],J[1]-g.snapToGridOffset[1]]),J[0]+=g.snapToGridOffset[0],J[1]+=g.snapToGridOffset[1]);const $t=t.model.nodes.getAtCoordinates(at[0],at[1]).filter(Ut=>Ut.type.childrenTypes.includes(g.id)),Pt=Fe($t),et=Pt[Pt.length-1];if(!g.canBeParentless&&et===void 0)return;const ke=et?.getLastAncestor(),we=new Go(t,g,J,et?.id,ke?.id,ke?.getGeometry(),void 0,v.label,v.values);we.do(),t?.actionStack.add(we),w()}})).append("svg").attr("class",`palette-node ${g.id}`).attr("viewBox",`0 0 ${j} ${P}`).attr("preserveAspectRatio","none").style("position","relative").style("left",0).style("top",0).style("width",`${Y}px`).style("height",`${F}px`),C=v.look||g.defaultLook;switch(C.lookType){case"shaped-look":M.append("path").attr("d",ge(C.shape||Tt.Rectangle,(C.borderThickness||1)/2,(C.borderThickness||1)/2,g.defaultWidth,g.defaultHeight)).attr("fill",C.fillColor||"#FFFFFF").attr("stroke",C.borderColor||"#000000").attr("stroke-width",`${C.borderThickness}px`);break;case"image-look":M.append("image").attr("x",0).attr("y",0).attr("width",g.defaultWidth).attr("height",g.defaultHeight).attr("href",C.backgroundImage).attr("preserveAspectRatio","none");break;case"stretchable-image-look":M.append("image").attr("x",0).attr("y",0).attr("width",C.leftMargin).attr("height",C.topMargin).attr("href",C.backgroundImageTopLeft).attr("preserveAspectRatio","none"),M.append("image").attr("x",C.leftMargin).attr("y",0).attr("width",g.defaultWidth-C.rightMargin-C.leftMargin).attr("height",C.topMargin).attr("href",C.backgroundImageTop).attr("preserveAspectRatio","none"),M.append("image").attr("x",g.defaultWidth-C.rightMargin).attr("y",0).attr("width",C.rightMargin).attr("height",C.topMargin).attr("href",C.backgroundImageTopRight).attr("preserveAspectRatio","none"),M.append("image").attr("x",0).attr("y",C.topMargin).attr("width",C.leftMargin).attr("height",g.defaultHeight-C.bottomMargin-C.topMargin).attr("href",C.backgroundImageLeft).attr("preserveAspectRatio","none"),M.append("image").attr("x",C.leftMargin).attr("y",C.topMargin).attr("width",g.defaultWidth-C.rightMargin-C.leftMargin).attr("height",g.defaultHeight-C.bottomMargin-C.topMargin).attr("href",C.backgroundImageCenter).attr("preserveAspectRatio","none"),M.append("image").attr("x",g.defaultWidth-C.rightMargin).attr("y",C.topMargin).attr("width",C.rightMargin).attr("height",g.defaultHeight-C.bottomMargin-C.topMargin).attr("href",C.backgroundImageRight).attr("preserveAspectRatio","none"),M.append("image").attr("x",0).attr("y",g.defaultHeight-C.bottomMargin).attr("width",C.leftMargin).attr("height",C.bottomMargin).attr("href",C.backgroundImageBottomLeft).attr("preserveAspectRatio","none"),M.append("image").attr("x",C.leftMargin).attr("y",g.defaultHeight-C.bottomMargin).attr("width",g.defaultWidth-C.rightMargin-C.leftMargin).attr("height",C.bottomMargin).attr("href",C.backgroundImageBottom).attr("preserveAspectRatio","none"),M.append("image").attr("x",g.defaultWidth-C.rightMargin).attr("y",g.defaultHeight-C.bottomMargin).attr("width",C.rightMargin).attr("height",C.bottomMargin).attr("href",C.backgroundImageBottomRight).attr("preserveAspectRatio","none")}if(v.look===void 0){if(g.decorators)for(const R of g.decorators)M.append("foreignObject").attr("width",`${R.width}px`).attr("height",`${R.height}px`).attr("transform",`translate(${R.coords[0]},${R.coords[1]})`).html(R.html);if(v.label){const R={...O,...g.label,...v.labelLook};M.append("text").attr("transform",`translate(${(D(R)+g.defaultWidth)/2},${(G(R)+g.defaultHeight)/2})`).attr("x",0).attr("y",0).attr("font-size",`${R.fontSize}px`).attr("text-anchor","middle").attr("font-family",R.fontFamily).attr("font-weight",400).attr("fill",R.color).attr("stroke","none").style("font-kerning","none").style("user-select","none").text(v.label)}}},x=(g,v,y)=>{const T=h().append("div").attr("class",`daga-template-container ${y!==void 0?y:""}`).style("width",`${v.width}px`).style("height",`${v.height}px`).append("svg").attr("class",`palette-button ${g.id}`).style("position","relative").style("left",0).style("top",0).style("width","100%").style("height","100%").on("click",()=>{t.connectionType=g});T.append("path").attr("d",ge(Tt.Rectangle,0,0,v.width,v.height)).attr("fill",v.backgroundColor).attr("stroke","black").attr("stroke-width","1px"),v.icon!==""&&T.append("image").attr("x",0).attr("y",0).attr("width",v.width).attr("height",v.height).attr("href",v.icon),v.label!==""&&T.append("text").attr("transform",`translate(${v.width/2},${v.height/2+Ci})`).attr("x",0).attr("y",0).attr("font-size","20px").attr("text-anchor","middle").attr("font-family","'Wonder Unit Sans', sans-serif").attr("font-weight",400).attr("fill","#000000").attr("stroke","none").style("font-kerning","none").style("user-select","none").text(v.label)};return I.useEffect(()=>{s.palettes.length>0&&!d.current&&(d.current=!0,c(s.palettes[0]))},[s.palettes]),I.useEffect(()=>{if(o.current)switch(s.direction){case f.Bottom:case f.Top:o.current.style.width=s.width,s.height&&(o.current.style.height=s.height);break;case f.Left:case f.Right:o.current.style.height=s.width,s.height&&(o.current.style.width=s.height);break}},[s.direction,s.width,s.height]),p.jsx("daga-palette",{children:p.jsxs("div",{ref:o,className:`daga-panel daga-${s.location} daga-${s.direction}`,children:[p.jsx(be,{direction:s.direction,collapsableSelector:o,collapsableAdditionalSelector:".daga-panel-content",rule:"display",collapsedValue:"none",visibleValue:"block",collapsed:!1,disabled:!1}),p.jsxs("div",{className:"daga-panel-content",children:[s.palettes.length>1&&p.jsx("div",{className:"daga-panel-tabs",children:s.palettes.map(g=>p.jsx("div",{className:`daga-panel-tab ${g===e?"daga-current-tab":""}`,onClick:()=>c(g),children:g.name}))}),p.jsx("div",{className:"daga-palette-view"})]})]})})},Ii=({location:s,direction:t,enableAction:e,enableFilter:a,enableLayout:l,enableSelection:r,enableZoom:i})=>{let n=!1,o=!0,d=!1,c,h,u,b;switch(t){case f.Bottom:c="height",h="scaleY",u="top",b="bottom";break;case f.Top:c="height",h="scaleY",u="bottom",b="top";break;case f.Left:c="width",h="scaleX",u="right",b="left";break;case f.Right:c="width",h="scaleX",u="left",b="right";break}const m=I.useRef(null),x=I.useRef(null),g=I.useRef(null);I.useEffect(()=>{A.select(m.current).style(`margin-${b}`,"-1rem").style(c,"0rem").style("transform",`${h}(0)`).style("transform-origin",u)});const v=async()=>{const tt=A.select(m.current);if(!d)if(o){o=!1;const et=`${4*tt.selectChildren().size()}rem`;tt.transition().duration(500).ease(A.easeLinear).style(c,et).style("transform",`${h}(1)`),setTimeout(()=>{d=!1},500)}else o=!0,tt.transition().duration(500).ease(A.easeLinear).style(c,"0rem").style("transform",`${h}(0)`),setTimeout(()=>{d=!1},500)},y=I.useContext(xt),T=()=>{y.zoomBy(y.zoomFactor)},P=()=>{y.zoomBy(1/y.zoomFactor)},j=()=>{y.center()},F=()=>{y.layoutFormat&&y.layoutFormat in Pe&&Pe[y.layoutFormat].apply(y.model)},Y=()=>{n=!n,A.select(g.current).classed("daga-on",n).classed("daga-off",!n);const tt=y.getPriorityThresholdOptions();tt&&tt.length>=2&&y.setPriorityThreshold(tt[n?1:0])},M=()=>{y.actionStack.undo()},C=()=>{y.actionStack.redo()},R=()=>{y.userSelection.copyToClipboard()},E=()=>{y.userSelection.cutToClipboard()},V=()=>{y.userSelection.pasteFromClipboard()},at=()=>{y.userSelection.removeFromModel()},J=()=>{y.multipleSelectionOn=!0,A.select(x.current).classed("daga-on",!0).classed("daga-off",!1);const tt=y.diagramEvent$.subscribe($t=>{$t.type===Ye.Selection&&(A.select(x.current).classed("daga-on",!1).classed("daga-off",!0),tt.unsubscribe())})};return p.jsx("daga-diagram-buttons",{children:p.jsxs("div",{className:`daga-diagram-buttons daga-${s} daga-${t}`,children:[i&&y.canUserPerformAction(k.Zoom)&&p.jsx("button",{className:"daga-zoom-in",onClick:T,children:p.jsx("span",{className:"daga-tooltip",children:"Zoom in"})}),i&&y.canUserPerformAction(k.Zoom)&&p.jsx("button",{className:"daga-zoom-out",onClick:P,children:p.jsx("span",{className:"daga-tooltip",children:"Zoom out"})}),p.jsxs("div",{className:"daga-collapsable-buttons daga-collapsed",ref:m,children:[i&&y.canUserPerformAction(k.Zoom)&&p.jsx("button",{className:"daga-center",onClick:j,children:p.jsx("span",{className:"daga-tooltip",children:"Fit diagram to screen"})}),e&&p.jsx("button",{className:"daga-undo",onClick:M,children:p.jsx("span",{className:"daga-tooltip",children:"Undo"})}),e&&p.jsx("button",{className:"daga-redo",onClick:C,children:p.jsx("span",{className:"daga-tooltip",children:"Redo"})}),r&&p.jsx("button",{className:"daga-copy",onClick:R,children:p.jsx("span",{className:"daga-tooltip",children:"Copy"})}),r&&p.jsx("button",{className:"daga-cut",onClick:E,children:p.jsx("span",{className:"daga-tooltip",children:"Cut"})}),r&&p.jsx("button",{className:`daga-multiple-selection ${n?"daga-on":"daga-off"}`,onClick:J,ref:x,children:p.jsx("span",{className:"daga-tooltip",children:"Multiple selection"})}),r&&p.jsx("button",{className:"daga-paste",onClick:V,children:p.jsx("span",{className:"daga-tooltip",children:"Paste"})}),r&&p.jsx("button",{className:"daga-delete",onClick:at,children:p.jsx("span",{className:"daga-tooltip",children:"Delete"})}),l&&y.layoutFormat&&p.jsx("button",{className:"daga-layout",onClick:F,children:p.jsx("span",{className:"daga-tooltip",children:"Apply layout"})}),a&&p.jsx("button",{className:`daga-filter ${n?"daga-on":"daga-off"}`,onClick:Y,ref:g,children:p.jsx("span",{className:"daga-tooltip",children:"Apply filter"})})]}),p.jsx("button",{className:"daga-more-options",onClick:v,children:o?p.jsx("span",{className:"daga-tooltip",children:"More options"}):p.jsx("span",{className:"daga-tooltip",children:"Less options"})})]})})},Ai=({config:s,model:t,onCanvasCreated:e,onDiagramEvent:a,onModelChange:l})=>{const r=new Be,i=new Ze,n=I.useRef(null),o=I.useRef(void 0),d=I.useRef(!1),c=[],[h,u]=I.useState(void 0),[b,m]=I.useState(void 0),x={zoomIn:()=>{},zoomOut:()=>{},center:()=>{},layout:()=>{},filter:()=>{},undo:()=>{},redo:()=>{}},g={refreshPalette:()=>{}},v=new pi(Y=>u(Y),Y=>m(Y)),y={diagramButtons:x,palette:g,propertyEditor:v},T=(Y=!1)=>{if((!o.current||Y)&&(c.forEach(M=>M.unsubscribe()),o.current=new ue(y,s)),!o.current)throw new Error("Canvas could not be created");return o.current},P=T(),j=Y=>{P.initView(Y),c.push(P.diagramEvent$.subscribe(M=>{a?.(M)})),c.push(P.diagramChange$.subscribe(()=>{const M=i.export(P.model);l?.(M)}))};I.useEffect(()=>{n.current&&(d.current||(j(n.current),d.current=!0,e?.(P)))},[n.current]),I.useEffect(()=>{n.current&&(T(!0),j(n.current),e?.(P))},[s]),I.useEffect(()=>{t&&r.import(P.model,t)},[t]);const F=(Y,M,C)=>{if(b!==void 0&&M.editable!==!1&&!wt(Y.getValue(M.name),C)){Y.setValue(M.name,C);const R=new vt(b.propertySet,void 0);R.setValues(b.getValues()),R.rootElement=b.rootElement,v.valueSet=R,b.rootElement.valueSet=R,P.propertyEditorChanges$?.next()}};return p.jsx("daga-diagram",{children:p.jsx(ui.Provider,{value:s,children:p.jsx(xt.Provider,{value:P,children:p.jsxs("daga-diagram-editor",{children:[p.jsx("div",{className:"daga-append-to",ref:n}),p.jsxs(xt.Provider,{value:P,children:[s.components?.buttons!==void 0&&s.components?.buttons?.enabled!==!1&&p.jsx(Ii,{location:s.components?.buttons?.location||Bt.BottomRight,direction:s.components?.buttons?.direction||f.Top,enableAction:s.components?.buttons?.enableAction!==!1,enableFilter:s.components?.buttons?.enableFilter===!0,enableLayout:s.components?.buttons?.enableLayout===!0,enableSelection:s.components?.buttons?.enableSelection!==!1,enableZoom:s.components?.buttons?.enableZoom!==!1}),s.components?.palette!==void 0&&s.components?.palette?.enabled!==!1&&s.components?.palette?.sections&&(s.components?.palette?.sections?.length||0)>0&&p.jsx($i,{location:s.components?.palette?.location||Bt.TopLeft,direction:s.components?.palette?.direction||f.Bottom,width:s.components?.palette?.width||"12rem",height:s.components?.palette?.height,palettes:s.components?.palette?.sections||[]}),s.components?.propertyEditor!==void 0&&s.components?.propertyEditor?.enabled!==!1&&p.jsx(xi,{location:s.components?.propertyEditor?.location||Bt.TopRight,direction:s.components?.propertyEditor?.direction||f.Bottom,width:s.components?.propertyEditor?.width||"24rem",height:s.components?.propertyEditor?.height,title:h,valueSet:b,onValueChange:F}),s.components?.errors!==void 0&&s.components?.errors?.enabled!==!1&&p.jsx(mi,{})]})]})})})})};exports.DagaDiagram=Ai;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require(`d3`);c=s(c);let l=require(`rxjs`),u=require(`react`);u=s(u);let d=require(`react/jsx-runtime`);var f=function(e){return e.Bottom=`bottom`,e.Left=`left`,e.Right=`right`,e.Top=`top`,e}({}),p=function(e){return e.BottomLeft=`bottom-left`,e.BottomRight=`bottom-right`,e.TopLeft=`top-left`,e.TopRight=`top-right`,e}({}),m=function(e){return e.Left=`left`,e.Center=`center`,e.Right=`right`,e}({}),h=function(e){return e.Top=`top`,e.Center=`center`,e.Bottom=`bottom`,e}({}),g=e=>[Math.round(e[0]),Math.round(e[1])],_=(e,t,n)=>t<n?t<=e&&e<=n:n<=e&&e<=t,v=(e,t,n)=>(e-t[0])/(t[1]-t[0])*(n[1]-n[0])+n[0],y=(e,t,n,r,i,a,o)=>[(()=>{switch(a){case`start`:return r[0]+(e[0]-t[0]);case`end`:return r[1]-(t[1]-e[0]);case`middle`:{let n=(t[0]+t[1])/2,i=(r[0]+r[1])/2,a=t[1]-t[0],o=r[1]-r[0];return i+(e[0]-n)/a*o}default:return v(e[0],t,r)}})(),(()=>{switch(o){case`start`:return i[0]+(e[1]-n[0]);case`end`:return i[1]-(n[1]-e[1]);case`middle`:{let t=(n[0]+n[1])/2,r=(i[0]+i[1])/2,a=n[1]-n[0],o=i[1]-i[0];return r+(e[1]-t)/a*o}default:return v(e[1],n,i)}})()],b=(e,t)=>((e[0]-t[0])**2+(e[1]-t[1])**2)**.5,ee=(e,t)=>(_(e[0][0],t[0][0],t[1][0])||_(e[1][0],t[1][0],t[0][0])||_(t[0][0],e[0][0],e[1][0])||_(t[1][0],e[1][0],e[0][0]))&&(_(e[0][1],t[0][1],t[1][1])||_(e[1][1],t[1][1],t[0][1])||_(t[0][1],e[0][1],e[1][1])||_(t[1][1],e[1][1],e[0][1])),x=function(e){return e.Blur=`blur`,e.Change=`change`,e.Click=`click`,e.ContextMenu=`contextmenu`,e.DoubleClick=`dblclick`,e.Focus=`focus`,e.FocusIn=`focusin`,e.FocusOut=`focusout`,e.Input=`input`,e.KeyDown=`keydown`,e.KeyUp=`keyup`,e.MouseDown=`mousedown`,e.MouseEnter=`mouseenter`,e.MouseLeave=`mouseleave`,e.MouseMove=`mousemove`,e.MouseOut=`mouseout`,e.MouseOver=`mouseover`,e.MouseUp=`mouseup`,e.TouchStart=`touchstart`,e.TouchEnd=`touchend`,e.Wheel=`wheel`,e}({}),S=function(e){return e.Alt=`Alt`,e.AltGraph=`AltGraph`,e.ArrowDown=`ArrowDown`,e.ArrowLeft=`ArrowLeft`,e.ArrowRight=`ArrowRight`,e.ArrowUp=`ArrowUp`,e.Backspace=`Backspace`,e.Control=`Control`,e.Delete=`Delete`,e.End=`End`,e.Enter=`Enter`,e.Escape=`Escape`,e.Home=`Home`,e.OS=`OS`,e.PageDown=`PageDown`,e.PageUp=`PageUp`,e.Shift=`Shift`,e.Tab=`Tab`,e}({}),C=function(e){return e.Drag=`drag`,e.Start=`start`,e.End=`end`,e}({}),w=function(e){return e.Zoom=`zoom`,e.Start=`start`,e.End=`end`,e}({}),te=e=>e.replace(/([!"#$%&'()*+,\-./:;<=>?@[\\\]^`{|}])/g,`\\$1`),T=function(e){return e.Straight=`straight`,e.Bezier=`bezier`,e.Square=`square`,e}({}),ne=function(e){return e.Solid=`solid`,e.Dashed=`dashed`,e.GappedDashes=`gapped-dashes`,e.Dotted=`dotted`,e}({}),re=20,ie=(e,t,n,r,i)=>{if(typeof e==`function`)return e(t,n,r,i);if(t.length===0)return``;if(t.length===1)return`M ${t[0][0]} ${t[0][1]}`;{i||=re;let a=``,o,s;switch(e){case T.Straight:a+=`M ${t[0][0]} ${t[0][1]}`;for(let e=1;e<t.length;++e)a+=` L ${t[e][0]} ${t[e][1]}`;break;case T.Bezier:o=n,a+=`M ${t[0][0]} ${t[0][1]}`;for(let e=1;e<t.length;++e){if(e+1>=t.length)switch(r){case f.Bottom:s=f.Top;break;case f.Top:s=f.Bottom;break;case f.Right:s=f.Left;break;case f.Left:s=f.Right;break}else s=Math.abs(t[e][0]-t[e-1][0])<Math.abs(t[e][1]-t[e-1][1])?t[e][1]>t[e-1][1]?f.Bottom:f.Top:t[e][0]>t[e-1][0]?f.Right:f.Left;if(o!==void 0){let n=``,r=``,i=(Math.abs(t[e][0]-t[e-1][0])+Math.abs(t[e][1]-t[e-1][1]))/2;switch(o){case f.Bottom:n=`${t[e-1][0]} ${t[e-1][1]+i}`;break;case f.Top:n=`${t[e-1][0]} ${t[e-1][1]-i}`;break;case f.Right:n=`${t[e-1][0]+i} ${t[e-1][1]}`;break;case f.Left:n=`${t[e-1][0]-i} ${t[e-1][1]}`;break}if(s!==void 0){switch(s){case f.Top:r=`${t[e][0]} ${t[e][1]+i}`;break;case f.Bottom:r=`${t[e][0]} ${t[e][1]-i}`;break;case f.Left:r=`${t[e][0]+i} ${t[e][1]}`;break;case f.Right:r=`${t[e][0]-i} ${t[e][1]}`;break}a+=` C ${n} ${r} ${t[e][0]} ${t[e][1]}`}else a+=` Q ${n} ${t[e][0]} ${t[e][1]}`}else if(s!==void 0){let n=``,r=(Math.abs(t[e][0]-t[e-1][0])+Math.abs(t[e][1]-t[e-1][1]))/2;switch(s){case f.Top:n=`${t[e][0]} ${t[e][1]+r}`;break;case f.Bottom:n=`${t[e][0]} ${t[e][1]-r}`;break;case f.Left:n=`${t[e][0]+r} ${t[e][1]}`;break;case f.Right:n=`${t[e][0]-r} ${t[e][1]}`;break}a+=` Q ${n} ${t[e][0]} ${t[e][1]}`}else a+=` L ${t[e][0]} ${t[e][1]}`;o=s}break;case T.Square:o=n,a+=`M ${t[0][0]} ${t[0][1]}`;for(let e=1;e<t.length;++e){if(e+1>=t.length)switch(r){case f.Bottom:s=f.Top;break;case f.Top:s=f.Bottom;break;case f.Right:s=f.Left;break;case f.Left:s=f.Right;break}switch(o){case f.Bottom:switch(s){case f.Bottom:t[e][1]>t[e-1][1]?(t[e][0]===t[e-1][0]?a+=` V ${t[e][1]}`:(a+=` V ${(t[e][1]+t[e-1][1])/2}`,a+=` H ${t[e][0]}`,a+=` V ${t[e][1]}`),o=s):t[e][0]>t[e-1][0]?(a+=` V ${t[e-1][1]+i}`,a+=` H ${Math.max(t[e-1][0],t[e][0])+i}`,a+=` V ${t[e][1]-i}`,a+=` H ${t[e][0]}`,a+=` V ${t[e][1]}`):(a+=` V ${t[e-1][1]+i}`,a+=` H ${Math.min(t[e-1][0],t[e][0])-i}`,a+=` V ${t[e][1]-i}`,a+=` H ${t[e][0]}`,a+=` V ${t[e][1]}`);break;case f.Top:a+=` V ${Math.max(t[e-1][1],t[e][1])+i}`,a+=` H ${t[e][0]}`,a+=` V ${t[e][1]}`;break;case f.Left:t[e][1]>t[e-1][1]+i?t[e][0]<t[e-1][0]-i?(a+=` V ${t[e][1]}`,a+=` H ${t[e][0]}`):(a+=` V ${(t[e-1][1]+t[e][1])/2}`,a+=` H ${t[e][0]+i}`,a+=` V ${t[e][1]}`,a+=` H ${t[e][0]}`):t[e][0]<t[e-1][0]-i?(a+=` V ${t[e-1][1]+i}`,a+=` H ${(t[e-1][0]+t[e][0])/2}`,a+=` V ${t[e][1]}`,a+=` H ${t[e][0]}`):(a+=` V ${t[e-1][1]+i}`,a+=` H ${t[e][0]+i}`,a+=` V ${t[e][1]}`,a+=` H ${t[e][0]}`);break;case f.Right:t[e][1]>t[e-1][1]+i?t[e][0]>t[e-1][0]+i?(a+=` V ${t[e][1]}`,a+=` H ${t[e][0]}`):(a+=` V ${(t[e-1][1]+t[e][1])/2}`,a+=` H ${t[e][0]-i}`,a+=` V ${t[e][1]}`,a+=` H ${t[e][0]}`):t[e][0]>t[e-1][0]+i?(a+=` V ${t[e-1][1]+i}`,a+=` H ${(t[e-1][0]+t[e][0])/2}`,a+=` V ${t[e][1]}`,a+=` H ${t[e][0]}`):(a+=` V ${t[e-1][1]+i}`,a+=` H ${t[e][0]-i}`,a+=` V ${t[e][1]}`,a+=` H ${t[e][0]}`);break;default:t[e][1]<t[e-1][1]+i?(a+=` V ${t[e-1][1]+i}`,t[e][0]!==t[e-1][0]&&(a+=` H ${t[e][0]}`),a+=` V ${t[e][1]}`,o=f.Top):(a+=` V ${t[e][1]}`,o=f.Bottom,t[e][0]!==t[e-1][0]&&(a+=` H ${t[e][0]}`,o=t[e][0]>t[e-1][0]?f.Right:f.Left));break}break;case f.Top:switch(s){case f.Top:t[e][1]<t[e-1][1]?(t[e][0]===t[e-1][0]?a+=` V ${t[e][1]}`:(a+=` V ${(t[e][1]+t[e-1][1])/2}`,a+=` H ${t[e][0]}`,a+=` V ${t[e][1]}`),o=s):t[e][0]<t[e-1][0]?(a+=` V ${t[e-1][1]-i}`,a+=` H ${Math.min(t[e-1][0],t[e][0])-i}`,a+=` V ${t[e][1]+i}`,a+=` H ${t[e][0]}`,a+=` V ${t[e][1]}`):(a+=` V ${t[e-1][1]-i}`,a+=` H ${Math.max(t[e-1][0],t[e][0])+i}`,a+=` V ${t[e][1]+i}`,a+=` H ${t[e][0]}`,a+=` V ${t[e][1]}`);break;case f.Bottom:a+=` V ${Math.min(t[e-1][1],t[e][1])-i}`,a+=` H ${t[e][0]}`,a+=` V ${t[e][1]}`;break;case f.Right:t[e][1]<t[e-1][1]-i?t[e][0]>t[e-1][0]+i?(a+=` V ${t[e][1]}`,a+=` H ${t[e][0]}`):(a+=` V ${(t[e-1][1]+t[e][1])/2}`,a+=` H ${t[e][0]-i}`,a+=` V ${t[e][1]}`,a+=` H ${t[e][0]}`):t[e][0]>t[e-1][0]+i?(a+=` V ${t[e-1][1]-i}`,a+=` H ${(t[e-1][0]+t[e][0])/2}`,a+=` V ${t[e][1]}`,a+=` H ${t[e][0]}`):(a+=` V ${t[e-1][1]-i}`,a+=` H ${t[e][0]-i}`,a+=` V ${t[e][1]}`,a+=` H ${t[e][0]}`);break;case f.Left:t[e][1]<t[e-1][1]-i?t[e][0]<t[e-1][0]-i?(a+=` V ${t[e][1]}`,a+=` H ${t[e][0]}`):(a+=` V ${(t[e-1][1]+t[e][1])/2}`,a+=` H ${t[e][0]+i}`,a+=` V ${t[e][1]}`,a+=` H ${t[e][0]}`):t[e][0]<t[e-1][0]-i?(a+=` V ${t[e-1][1]-i}`,a+=` H ${(t[e-1][0]+t[e][0])/2}`,a+=` V ${t[e][1]}`,a+=` H ${t[e][0]}`):(a+=` V ${t[e-1][1]-i}`,a+=` H ${t[e][0]+i}`,a+=` V ${t[e][1]}`,a+=` H ${t[e][0]}`);break;default:t[e][1]>t[e-1][1]-i?(a+=` V ${t[e-1][1]-i}`,t[e][0]!==t[e-1][0]&&(a+=` H ${t[e][0]}`),a+=` V ${t[e][1]}`,o=f.Bottom):(a+=` V ${t[e][1]}`,o=f.Top,t[e][0]!==t[e-1][0]&&(a+=` H ${t[e][0]}`,o=t[e][0]>t[e-1][0]?f.Right:f.Left));break}break;case f.Left:switch(s){case f.Left:t[e][0]<t[e-1][0]?(t[e][1]===t[e-1][1]?a+=` H ${t[e][0]}`:(a+=` H ${(t[e][0]+t[e-1][0])/2}`,a+=` V ${t[e][1]}`,a+=` H ${t[e][0]}`),o=s):t[e][1]<t[e-1][1]?(a+=` H ${t[e-1][0]-i}`,a+=` V ${Math.min(t[e-1][1],t[e][1])-i}`,a+=` H ${t[e][0]+i}`,a+=` V ${t[e][1]}`,a+=` H ${t[e][0]}`):(a+=` H ${t[e-1][0]-i}`,a+=` V ${Math.max(t[e-1][1],t[e][1])+i}`,a+=` H ${t[e][0]+i}`,a+=` V ${t[e][1]}`,a+=` H ${t[e][0]}`);break;case f.Right:a+=` H ${Math.min(t[e-1][0],t[e][0])-i}`,a+=` V ${t[e][1]}`,a+=` H ${t[e][0]}`;break;case f.Bottom:t[e][0]<t[e-1][0]-i?t[e][1]>t[e-1][1]+i?(a+=` H ${t[e][0]}`,a+=` V ${t[e][1]}`):(a+=` H ${(t[e-1][0]+t[e][0])/2}`,a+=` V ${t[e][1]-i}`,a+=` H ${t[e][0]}`,a+=` V ${t[e][1]}`):t[e][1]>t[e-1][1]+i?(a+=` H ${t[e-1][0]-i}`,a+=` V ${(t[e-1][1]+t[e][1])/2}`,a+=` H ${t[e][0]}`,a+=` V ${t[e][1]}`):(a+=` H ${t[e-1][0]-i}`,a+=` V ${t[e][1]-i}`,a+=` H ${t[e][0]}`,a+=` V ${t[e][1]}`);break;case f.Top:t[e][0]<t[e-1][0]-i?t[e][1]<t[e-1][1]-i?(a+=` H ${t[e][0]}`,a+=` V ${t[e][1]}`):(a+=` H ${(t[e-1][0]+t[e][0])/2}`,a+=` V ${t[e][1]+i}`,a+=` H ${t[e][0]}`,a+=` V ${t[e][1]}`):t[e][1]<t[e-1][1]-i?(a+=` H ${t[e-1][0]-i}`,a+=` V ${(t[e-1][1]+t[e][1])/2}`,a+=` H ${t[e][0]}`,a+=` V ${t[e][1]}`):(a+=` H ${t[e-1][0]-i}`,a+=` V ${t[e][1]+i}`,a+=` H ${t[e][0]}`,a+=` V ${t[e][1]}`);break;default:t[e][0]>t[e-1][0]-i?(a+=` H ${t[e-1][0]-i}`,t[e][1]!==t[e-1][1]&&(a+=` V ${t[e][1]}`),a+=` H ${t[e][0]}`,o=f.Right):(a+=` H ${t[e][0]}`,o=f.Left,t[e][1]!==t[e-1][1]&&(a+=` V ${t[e][1]}`,o=t[e][1]>t[e-1][1]?f.Bottom:f.Top));break}break;case f.Right:switch(s){case f.Right:t[e][0]>t[e-1][0]?(t[e][1]===t[e-1][1]?a+=` H ${t[e][0]}`:(a+=` H ${(t[e][0]+t[e-1][0])/2}`,a+=` V ${t[e][1]}`,a+=` H ${t[e][0]}`),o=s):t[e][1]>t[e-1][1]?(a+=` H ${t[e-1][0]+i}`,a+=` V ${Math.max(t[e-1][1],t[e][1])+i}`,a+=` H ${t[e][0]-i}`,a+=` V ${t[e][1]}`,a+=` H ${t[e][0]}`):(a+=` H ${t[e-1][0]+i}`,a+=` V ${Math.min(t[e-1][1],t[e][1])-i}`,a+=` H ${t[e][0]-i}`,a+=` V ${t[e][1]}`,a+=` H ${t[e][0]}`);break;case f.Left:a+=` H ${Math.max(t[e-1][0],t[e][0])+i}`,a+=` V ${t[e][1]}`,a+=` H ${t[e][0]}`;break;case f.Top:t[e][0]>t[e-1][0]+i?t[e][1]<t[e-1][1]-i?(a+=` H ${t[e][0]}`,a+=` V ${t[e][1]}`):(a+=` H ${(t[e-1][0]+t[e][0])/2}`,a+=` V ${t[e][1]+i}`,a+=` H ${t[e][0]}`,a+=` V ${t[e][1]}`):t[e][1]<t[e-1][1]-i?(a+=` H ${t[e-1][0]+i}`,a+=` V ${(t[e-1][1]+t[e][1])/2}`,a+=` H ${t[e][0]}`,a+=` V ${t[e][1]}`):(a+=` H ${t[e-1][0]+i}`,a+=` V ${t[e][1]+i}`,a+=` H ${t[e][0]}`,a+=` V ${t[e][1]}`);break;case f.Bottom:t[e][0]>t[e-1][0]+i?t[e][1]>t[e-1][1]+i?(a+=` H ${t[e][0]}`,a+=` V ${t[e][1]}`):(a+=` H ${(t[e-1][0]+t[e][0])/2}`,a+=` V ${t[e][1]-i}`,a+=` H ${t[e][0]}`,a+=` V ${t[e][1]}`):t[e][1]>t[e-1][1]+i?(a+=` H ${t[e-1][0]+i}`,a+=` V ${(t[e-1][1]+t[e][1])/2}`,a+=` H ${t[e][0]}`,a+=` V ${t[e][1]}`):(a+=` H ${t[e-1][0]+i}`,a+=` V ${t[e][1]-i}`,a+=` H ${t[e][0]}`,a+=` V ${t[e][1]}`);break;default:t[e][0]<t[e-1][0]+i?(a+=` H ${t[e-1][0]+i}`,t[e][1]!==t[e-1][1]&&(a+=` V ${t[e][1]}`),a+=` H ${t[e][0]}`,o=f.Left):(a+=` H ${t[e][0]}`,o=f.Right,t[e][1]!==t[e-1][1]&&(a+=` V ${t[e][1]}`,o=t[e][1]>t[e-1][1]?f.Bottom:f.Top));break}break;default:t[e][0]!==t[e-1][0]&&(a+=` H ${t[e][0]}`,o=t[e][0]>t[e-1][0]?f.Right:f.Left),t[e][1]!==t[e-1][1]&&(a+=` V ${t[e][1]}`,o=t[e][1]>t[e-1][1]?f.Bottom:f.Top)}}break}return a}},ae=(e,t)=>{switch(e){case ne.Dotted:return`${t}`;case ne.Dashed:return`${4*t} ${t}`;case ne.GappedDashes:return`${4*t} ${4*t}`;case ne.Solid:default:return`none`}},E=(e,t)=>{let n=e.indexOf(t);return n>=0&&e.splice(n,1),e},D=function(e){return e.Ellipse=`ellipse`,e.Empty=`empty`,e.Folder=`folder`,e.Hexagon=`hexagon`,e.Octagon=`octagon`,e.Pill=`pill`,e.Rectangle=`rectangle`,e.Rhombus=`rhombus`,e.RoundedRectangle=`rounded-rectangle`,e.StickyNote=`sticky-note`,e}({}),oe=(e,t,n,r,i)=>{if(typeof e==`function`)return e(t,n,r,i);switch(e){case D.Ellipse:return se(t,n,r,i);case D.Empty:return ce();case D.Folder:return le(t,n,r,i);case D.Hexagon:return ue(t,n,r,i);case D.Octagon:return de(t,n,r,i);case D.Pill:return fe(t,n,r,i);case D.Rectangle:return pe(t,n,r,i);case D.Rhombus:return me(t,n,r,i);case D.RoundedRectangle:return he(t,n,r,i);case D.StickyNote:return ge(t,n,r,i);default:return pe(t,n,r,i)}},se=(e,t,n,r)=>`M ${e+n/2} ${t} A ${n/2} ${r/2} 0 0 0 ${e+n/2} ${t+r} A ${n/2} ${r/2} 0 1 0 ${e+n/2} ${t} Z`,ce=()=>`Z`,le=(e,t,n,r)=>`M ${e} ${t} L ${e+n/3} ${t} L ${e+n/2} ${t+r/6} L ${e+n} ${t+r/6} L ${e+n} ${t+r} L ${e} ${t+r} Z`,ue=(e,t,n,r)=>`M ${e+n/4} ${t} L ${e+3*n/4} ${t} L ${e+n} ${t+r/2} L ${e+3*n/4} ${t+r} L ${e+n/4} ${t+r} L ${e} ${t+r/2} Z`,de=(e,t,n,r)=>`M ${e+n/4} ${t} L ${e+3*n/4} ${t} L ${e+n} ${t+r/4} L ${e+n} ${t+3*r/4} L ${e+3*n/4} ${t+r} L ${e+n/4} ${t+r} L ${e} ${t+3*r/4} L ${e} ${t+r/4} L ${e+n/4} ${t} Z`,fe=(e,t,n,r)=>r<n?`M ${e+r/2} ${t} L ${e+n-r/2} ${t} A ${r/2} ${r/2} 0 0 1 ${e+n} ${t+r/2} A ${r/2} ${r/2} 0 0 1 ${e+n-r/2} ${t+r} L ${e+r/2} ${t+r} A ${r/2} ${r/2} 0 0 1 ${e} ${t+r/2} A ${r/2} ${r/2} 0 0 1 ${e+r/2} ${t} Z`:r>n?`M ${e} ${t+n/2} L ${e} ${t+r-n/2} A ${n/2} ${n/2} 0 0 0 ${e+n/2} ${t+r} A ${n/2} ${n/2} 0 0 0 ${e+n} ${t+r-n/2} L ${e+n} ${t+n/2} A ${n/2} ${n/2} 0 0 0 ${e+n/2} ${t} A ${n/2} ${n/2} 0 0 0 ${e} ${t+n/2} Z`:se(e,t,n,r),pe=(e,t,n,r)=>`M ${e} ${t} L ${e+n} ${t} L ${e+n} ${t+r} L ${e} ${t+r} Z`,me=(e,t,n,r)=>`M ${e+n/2} ${t} L ${e+n} ${t+r/2} L ${e+n/2} ${t+r} L ${e} ${t+r/2} Z`,he=(e,t,n,r)=>`M ${e+n/4} ${t} L ${e+3*n/4} ${t} A ${n/4} ${r/4} 0 0 1 ${e+n} ${t+r/4} L ${e+n} ${t+3*r/4} A ${n/4} ${r/4} 0 0 1 ${e+3*n/4} ${t+r} L ${e+n/4} ${t+r} A ${n/4} ${r/4} 0 0 1 ${e} ${t+3*r/4} L ${e} ${t+r/4} A ${n/4} ${r/4} 0 0 1 ${e+n/4} ${t} Z`,ge=(e,t,n,r)=>`M ${e} ${t} L ${e+3*n/4} ${t} L ${e+3*n/4} ${t+r/4} L ${e+3*n/4} ${t} L ${e+n} ${t+r/4} L ${e+3*n/4} ${t+r/4} L ${e+n} ${t+r/4} L ${e+n} ${t+r} L ${e} ${t+r} Z`,O=function(e){return e.AllScroll=`all-scroll`,e.Auto=`auto`,e.Crosshair=`crosshair`,e.EWResize=`ew-resize`,e.Grab=`grab`,e.Grabbing=`grabbing`,e.Move=`move`,e.NoDrop=`no-drop`,e.NSResize=`ns-resize`,e.NotAllowed=`not-allowed`,e.ZoomIn=`zoom-in`,e.ZoomOut=`zoom-out`,e}({}),_e=e=>Math.max(...e.split(`
2
+ `).map(e=>e.length)),ve=e=>e.match(/\n/g)?.length||0,k=[];for(let e=0;e<256;++e)k.push((e+256).toString(16).slice(1));function ye(e,t=0){return(k[e[t+0]]+k[e[t+1]]+k[e[t+2]]+k[e[t+3]]+`-`+k[e[t+4]]+k[e[t+5]]+`-`+k[e[t+6]]+k[e[t+7]]+`-`+k[e[t+8]]+k[e[t+9]]+`-`+k[e[t+10]]+k[e[t+11]]+k[e[t+12]]+k[e[t+13]]+k[e[t+14]]+k[e[t+15]]).toLowerCase()}var be=new Uint8Array(16);function xe(){return crypto.getRandomValues(be)}function Se(e,t,n){return!t&&!e&&crypto.randomUUID?crypto.randomUUID():Ce(e,t,n)}function Ce(e,t,n){e||={};let r=e.random??e.rng?.()??xe();if(r.length<16)throw Error(`Random bytes length must be >= 16`);if(r[6]=r[6]&15|64,r[8]=r[8]&63|128,t){if(n||=0,n<0||n+16>t.length)throw RangeError(`UUID byte range ${n}:${n+15} is out of buffer bounds`);for(let e=0;e<16;++e)t[n+e]=r[e];return t}return ye(r)}var we=e=>{if(typeof e!=`object`||!e)return e;if(Array.isArray(e))return e.map(we);let t={};for(let n of Object.entries(e))t[n[0]]=we(n[1]);return t},A=e=>{let{selected:t,highlighted:n,selectedAndHighlighted:r,...i}=e,a=i;return{defaultLook:a,selectedLook:{...a,...t},highlightedLook:{...a,...n},selectedAndHighlightedLook:{...a,...n,...t,...r}}},Te=class{constructor(){this.entities=[],this.entityMap={}}get length(){return this.size()}all(){return[...this.entities]}add(e){this.entityMap[e.id]===void 0&&(this.entityMap[e.id]=e,this.entities.push(e))}clear(){for(;this.entities.length>0;)this.remove(this.entities[0].id)}contains(e){return this.entityMap[e]!==void 0}count(e){return this.entities.filter(e).length}filter(e){return this.entities.filter(e)}find(e){return this.entities.find(e)}get(e){return this.entityMap[e]}map(e){return this.entities.map(e)}remove(e){let t=this.get(e);t!==void 0&&(delete this.entityMap[e],E(this.entities,t))}size(){return this.entities.length}*[Symbol.iterator](){for(let e of this.entities)yield e}},Ee=class{get id(){return this._id}get highlighted(){return this.model.canvas?.userHighlight?.contains(this.id)||!1}get selected(){return this.model.canvas?.userSelection?.contains(this.id)||!1}constructor(e,t){this.selfRemoved=!1,this.selfRemovedTimestamp=null,this.model=e,this._id=t}select(){return this.model.canvas?.selectCanvasView()?.select(`[id='${te(this.id)}']`)}},j=class extends Te{all(e=!1){return e?super.all():super.filter(e=>!e.removed)}contains(e,t=!1){return t?super.contains(e):super.contains(e)&&!this.entityMap[e].removed}count(e,t=!1){return t?super.count(e):super.count((t,n,r)=>e(t,n,r)&&!t.removed)}filter(e,t=!1){return t?super.filter(e):super.filter((t,n,r)=>e(t,n,r)&&!t.removed)}find(e,t=!1){return t?super.find(e):super.find((t,n,r)=>e(t,n,r)&&!t.removed)}get(e,t=!1){return t||this.contains(e)?super.get(e):void 0}map(e,t=!1){return t?super.map(e):super.filter(e=>!e.removed).map(e)}remove(e){let t=this.get(e,!0);t!==void 0&&(delete this.entityMap[e],E(this.entities,t))}size(e=!1){return e?super.size():super.filter(e=>!e.removed).length}*[Symbol.iterator](e=!1){if(e)for(let e of this.entities)yield e;else for(let e of this.entities.filter(e=>!e.removed))yield e}},De=class{constructor(e,t,n,r,i,a,o){this.name=e,this.label=t,this.type=n,this.defaultValue=r,this.basic=i,this.editable=a,this.rootAttribute=o,this.options=void 0,this.properties=void 0}},M=function(e){return e.Boolean=`boolean`,e.Color=`color`,e.Date=`date`,e.Datetime=`datetime`,e.Number=`number`,e.Object=`object`,e.Option=`option`,e.OptionList=`option-list`,e.OptionSet=`option-set`,e.Text=`text`,e.TextArea=`text-area`,e.TextList=`text-list`,e.TextSet=`text-set`,e.TextMap=`text-map`,e.Time=`time`,e.Url=`url`,e}({}),Oe=class{constructor(e=[]){this.propertyList=e,this.propertyMap={};for(let e of this.propertyList)this.propertyMap[e.name]=e}getProperty(e){return this.propertyMap[e]}hasProperty(e){return this.propertyMap[e]!==void 0}hasProperties(){return this.propertyList.length>0}};function ke(e,t){return!t||e[0]>t[0]?!0:e[0]===t[0]?e[1]>=t[1]:!1}var Ae=e=>e==null||e===``||e instanceof Array&&e.length===0||e instanceof Object&&Object.keys(e).length===0,je=(e,t)=>e===t||JSON.stringify(e)===JSON.stringify(t),Me=(e,t,n)=>{let r={},i={};for(let a in n.propertySet.propertyMap)if(n.propertySet.propertyMap[a].type===M.Object){let o=Me(e[a],t[a],n.getSubValueSet(a));Object.keys(o[0]).length>0&&Object.keys(o[1]).length>0&&(r[a]=o[0],i[a]=o[1])}else je(e[a],t[a])||(r[a]=e[a],i[a]=t[a]);return[r,i]},Ne=e=>e!=null&&e.constructor===Object,Pe=class e{constructor(e,t){this.displayedProperties=[],this.hiddenProperties=[],this.values={},this.valueSets={},this.ownTimestamps={},this.propertySet=e,this.rootElement=t,this.resetValues()}getRootElementValue(e){if(this.rootElement){if(typeof e==`string`)return this.rootElement[e];if(Array.isArray(e)&&e.length>0){let t=this.rootElement;for(let n of e){if(t==null)return;t=t[n]}return t}}}setRootElementValue(e,t){if(this.rootElement){if(typeof e==`string`&&(this.rootElement[e]=t),Array.isArray(e)&&e.length>0){let n=this.rootElement;for(let t=0;t<e.length-1;++t){let r=e[t];if(n==null)return;n=n[r]}if(n==null)return;n[e[e.length-1]]=t}typeof this.rootElement.updateInView==`function`&&this.rootElement.updateInView()}}getValue(e){let t=this.propertySet.getProperty(e)?.rootAttribute;return t!=null&&(this.values[e]=this.getRootElementValue(t)),this.propertySet.getProperty(e).type===M.Object?this.valueSets[e].getValues():this.values[e]}getValues(){let e={};for(let t in this.propertySet.propertyMap)this.propertySet.getProperty(t).type===M.Object?e[t]=this.valueSets[t].getValues():e[t]=this.getValue(t);return e}getValuesForKeys(e){let t={};for(let n in e)this.propertySet.getProperty(n).type===M.Object?t[n]=this.valueSets[n].getValuesForKeys(e[n]):t[n]=this.getValue(n);return t}getTimestamps(){let e={};for(let t in this.propertySet.propertyMap)if(this.propertySet.getProperty(t).type===M.Object)e[t]=this.valueSets[t].getTimestamps();else{let n=this.ownTimestamps[t];n&&(e[t]=n)}return e}hasValue(e){return!Ae(this.getValue(e))}hasSetValue(e){let t=this.getValue(e),n=this.propertySet.getProperty(e);return n&&n.type===M.Object?this.getSubValueSet(e).hasAnySetValue():!Ae(t)&&!je(t,n?.defaultValue)}hasAnySetValue(){for(let e of this.propertySet.propertyList)if(this.hasSetValue(e.name))return!0;return!1}setValue(e,t){let n=this.propertySet.getProperty(e);if(n){n.type===M.Object?this.valueSets[e].setValues(t):(this.values[e]=t,je(t,n.defaultValue)||this.displayProperty(n));let r=n.rootAttribute;r!=null&&this.setRootElementValue(r,t)}}setValues(e){this.resetValues();for(let t in e)this.propertySet.getProperty(t).type===M.Object?this.valueSets[t].setValues(e[t]):this.setValue(t,e[t])}setTimestamps(e){this.ownTimestamps={};for(let t in e)this.propertySet.getProperty(t).type===M.Object?this.valueSets[t].setTimestamps(e[t]):this.ownTimestamps[t]=e[t]}overwriteValues(e){for(let t in e)this.propertySet.getProperty(t).type===M.Object?this.valueSets[t].overwriteValues(e[t]):this.setValue(t,e[t])}overwriteValuesLww(e,t){for(let n in e)this.propertySet.getProperty(n).type===M.Object?this.valueSets[n].overwriteValuesLww(e[n],t):ke(t,this.ownTimestamps[n])&&(this.setValue(n,e[n]),this.ownTimestamps[n]=t)}resetValues(){this.displayedProperties=[],this.hiddenProperties=[],this.ownTimestamps={};for(let e in this.propertySet.propertyMap){let t=this.propertySet.getProperty(e),n=t.rootAttribute;t.type===M.Object?this.valueSets[e]=this.constructSubValueSet(e):this.values[e]=we(t.defaultValue),n!=null&&t.defaultValue!==void 0&&!je(this.getRootElementValue(n),t.defaultValue)&&this.setRootElementValue(n,this.values[e]),t.basic===!1?this.hiddenProperties.push(t):this.displayedProperties.push(t)}}constructSubValueSet(t){let n=this.propertySet.getProperty(t),r=new e(new Oe(n.properties),this.rootElement);return r.overwriteValues(we(n.defaultValue)),r}getSubValueSet(e){return this.valueSets[e]}displayProperty(e){this.displayedProperties.includes(e)||(this.displayedProperties.push(e),E(this.hiddenProperties,e))}hideProperty(e){this.hiddenProperties.includes(e)||(this.hiddenProperties.push(e),E(this.displayedProperties,e))}},N={name:``,label:null,look:{lookType:`connection-look`,color:`#000000`,thickness:1,shape:T.Straight,style:ne.Solid,selected:{color:`#AA00AA`},highlighted:{thickness:2}},startMarkerLook:void 0,endMarkerLook:void 0,startTypes:[],endTypes:[],properties:[]},Fe=class{constructor(e){let t={...N,...e};this.id=t.id,this.name=t.name,this.label=t.label;let n=A(t.look);if(this.defaultLook=n.defaultLook,this.selectedLook=n.selectedLook,this.highlightedLook=n.highlightedLook,this.selectedAndHighlightedLook=n.selectedAndHighlightedLook,t.startMarkerLook!==void 0){let e=A(t.startMarkerLook);this.defaultStartMarkerLook=e.defaultLook,this.selectedStartMarkerLook=e.selectedLook,this.highlightedStartMarkerLook=e.highlightedLook,this.selectedAndHighlightedStartMarkerLook=e.selectedAndHighlightedLook}else this.defaultStartMarkerLook=null,this.selectedStartMarkerLook=null,this.highlightedStartMarkerLook=null,this.selectedAndHighlightedStartMarkerLook=null;if(t.endMarkerLook!==void 0){let e=A(t.endMarkerLook);this.defaultEndMarkerLook=e.defaultLook,this.selectedEndMarkerLook=e.selectedLook,this.highlightedEndMarkerLook=e.highlightedLook,this.selectedAndHighlightedEndMarkerLook=e.selectedAndHighlightedLook}else this.defaultEndMarkerLook=null,this.selectedEndMarkerLook=null,this.highlightedEndMarkerLook=null,this.selectedAndHighlightedEndMarkerLook=null;this.startTypes=t.startTypes,this.endTypes=t.endTypes,this.propertySet=new Oe(t.properties)}canStartFromType(e){return this.startTypes.indexOf(e)>=0}canFinishOnType(e){return this.endTypes.indexOf(e)>=0}},P=class extends Ee{get type(){return this._type}set type(e){e!==this._type&&(this._type=e,this.valueSet&&=new Pe(e.propertySet,this),this.model.canvas?.userSelection?.openInPropertyEditor(this,!1),this.updateInView())}get typeString(){return this.type.id}set typeString(e){if(e!==this.type.id){let t=this.model.connections.types.get(e);t&&(this.type=t)}}get name(){return this.middleLabel}set name(e){this.middleLabel=e}get look(){return this.selected?this.highlighted?this._selectedAndHighlightedLook===void 0?this.type.selectedAndHighlightedLook:this._selectedAndHighlightedLook:this._selectedLook===void 0?this.type.selectedLook:this._selectedLook:this.highlighted?this._highlightedLook===void 0?this.type.highlightedLook:this._highlightedLook:this._defaultLook===void 0?this.type.defaultLook:this._defaultLook}set look(e){this.lookConfig=e}get lookConfig(){return this._lookConfig}set lookConfig(e){if(this._lookConfig=e,e){let t=A(e);this._defaultLook={...this._defaultLook,...t.defaultLook},this._selectedLook={...this._selectedLook,...t.selectedLook},this._highlightedLook={...this._highlightedLook,...t.highlightedLook},this._selectedAndHighlightedLook={...this._selectedAndHighlightedLook,...t.selectedAndHighlightedLook}}else this._defaultLook=e,this._selectedLook=e,this._highlightedLook=e,this._selectedAndHighlightedLook=e}get startMarkerLook(){return this.selected?this.highlighted?this._selectedAndHighlightedStartMarkerLook===void 0?this.type.selectedAndHighlightedStartMarkerLook:this._selectedAndHighlightedStartMarkerLook:this._selectedStartMarkerLook===void 0?this.type.selectedStartMarkerLook:this._selectedStartMarkerLook:this.highlighted?this._highlightedStartMarkerLook===void 0?this.type.highlightedStartMarkerLook:this._highlightedStartMarkerLook:this._defaultStartMarkerLook===void 0?this.type.defaultStartMarkerLook:this._defaultStartMarkerLook}set startMarkerLook(e){this.startMarkerLookConfig=e}get startMarkerLookConfig(){return this._startMarkerLookConfig}set startMarkerLookConfig(e){if(this._startMarkerLookConfig=e,e){let t=A(e);this._defaultStartMarkerLook={...this._defaultStartMarkerLook,...t.defaultLook},this._selectedStartMarkerLook={...this._selectedStartMarkerLook,...t.selectedLook},this._highlightedStartMarkerLook={...this._highlightedStartMarkerLook,...t.highlightedLook},this._selectedAndHighlightedStartMarkerLook={...this._selectedAndHighlightedStartMarkerLook,...t.selectedAndHighlightedLook}}else this._defaultStartMarkerLook=e,this._selectedStartMarkerLook=e,this._highlightedStartMarkerLook=e,this._selectedAndHighlightedStartMarkerLook=e}get endMarkerLook(){return this.selected?this.highlighted?this._selectedAndHighlightedEndMarkerLook===void 0?this.type.selectedAndHighlightedEndMarkerLook:this._selectedAndHighlightedEndMarkerLook:this._selectedEndMarkerLook===void 0?this.type.selectedEndMarkerLook:this._selectedEndMarkerLook:this.highlighted?this._highlightedEndMarkerLook===void 0?this.type.highlightedEndMarkerLook:this._highlightedEndMarkerLook:this._defaultEndMarkerLook===void 0?this.type.defaultEndMarkerLook:this._defaultEndMarkerLook}set endMarkerLook(e){this.endMarkerLookConfig=e}get endMarkerLookConfig(){return this._endMarkerLookConfig}set endMarkerLookConfig(e){if(this._endMarkerLookConfig=e,e){let t=A(e);this._defaultEndMarkerLook={...this._defaultEndMarkerLook,...t.defaultLook},this._selectedEndMarkerLook={...this._selectedEndMarkerLook,...t.selectedLook},this._highlightedEndMarkerLook={...this._highlightedEndMarkerLook,...t.highlightedLook},this._selectedAndHighlightedEndMarkerLook={...this._selectedAndHighlightedEndMarkerLook,...t.selectedAndHighlightedLook}}else this._defaultEndMarkerLook=e,this._selectedEndMarkerLook=e,this._highlightedEndMarkerLook=e,this._selectedAndHighlightedEndMarkerLook=e}constructor(e,t,n,r,i){if(e.connections.get(i)!==void 0)throw Error(`DiagramConnection with id "${i}" already exists`);if(!i)throw Error(`DiagramConnection cannot have an empty or null id`);super(e,i),this.startCoords=[0,0],this.endCoords=[0,0],this.startLabel=``,this.middleLabel=``,this.endLabel=``,this.points=[],this._type=t,this.valueSet=new Pe(t.propertySet,this),this.originalData={},this.setStart(n),this.setEnd(r)}get removed(){return this.selfRemoved||this.start!==void 0&&this.start.removed||this.end!==void 0&&this.end.removed}updateInView(){this.model.canvas?.updateConnectionsInView(this.id)}raise(){this.select()?.raise(),this.start?.raise(!1),this.end?.raise(!1)}setStart(e){this.start===e?(this.startDirection=e?.direction,this.startCoords=e?.connectionPoint||[0,0]):(this.start!==void 0&&E(this.start.outgoingConnections,this),this.start=e,e!==void 0&&(e.outgoingConnections.push(this),this.startDirection=e?.direction,this.startCoords=e?.connectionPoint||[0,0])),this.updateInView()}setEnd(e){this.end===e?(this.endDirection=e?.direction,this.endCoords=e?.connectionPoint||[0,0]):(this.end!==void 0&&E(this.end.incomingConnections,this),this.end=e,e!==void 0&&(e.incomingConnections.push(this),this.endDirection=e?.direction,this.endCoords=e?.connectionPoint||[0,0])),this.updateInView()}tighten(){let e=this.model.canvas?.allowConnectionLoops||!1,t=this.model.canvas?.allowSharingPorts!==!1,n=this.model.canvas?.allowSharingBothPorts||!1,r=this.model.canvas?.tightenConnectionsAcrossPortTypes||!1;if(this.start?.rootElement&&this.end){let i=this.start.rootElement.ports.map(e=>[e,e.distanceTo(this.end.coords)]).sort((e,t)=>e[1]-t[1]).map(e=>e[0]);checkAlternativeStartPorts:for(let a of i){if(!e&&a===this.end||!a.allowsOutgoing||!r&&a.type!==this.start.type||!t&&(a.incomingConnections.filter(e=>!e.removed&&e!==this).length>0||a.outgoingConnections.filter(e=>!e.removed&&e!==this).length>0))continue checkAlternativeStartPorts;if(!n){for(let e of a.outgoingConnections.filter(e=>!e.removed))if(e!==this&&e.end===this.end)continue checkAlternativeStartPorts;for(let e of a.incomingConnections.filter(e=>!e.removed))if(e!==this&&e.start===this.end)continue checkAlternativeStartPorts}if(a===this.start)break checkAlternativeStartPorts;this.setStart(a);break checkAlternativeStartPorts}}if(this.end?.rootElement&&this.start){let i=this.end.rootElement.ports.map(e=>[e,e.distanceTo(this.start.coords)]).sort((e,t)=>e[1]-t[1]).map(e=>e[0]);checkAlternativeEndPorts:for(let a of i){if(!e&&a===this.start||!a.allowsIncoming||!r&&a.type!==this.end.type||!t&&(a.incomingConnections.filter(e=>!e.removed&&e!==this).length>0||a.outgoingConnections.filter(e=>!e.removed&&e!==this).length>0))continue checkAlternativeEndPorts;if(!n){for(let e of a.incomingConnections.filter(e=>!e.removed))if(e!==this&&e.start===this.start)continue checkAlternativeEndPorts;for(let e of a.outgoingConnections.filter(e=>!e.removed))if(e!==this&&e.end===this.start)continue checkAlternativeEndPorts}if(a===this.end)break checkAlternativeEndPorts;this.setEnd(a);break checkAlternativeEndPorts}}}getPriority(){return this.start?this.end?Math.min(this.start.getPriority(),this.end.getPriority()):this.start.getPriority():this.end?this.end.getPriority():0}},Ie=class extends j{constructor(e){super(),this.types=new Te,this.model=e}new(e,t,n,r){let i;if(e instanceof Fe)i=e;else{let t=this.types.get(e);if(t===void 0)throw TypeError(`Connection type with id '${e}' could not be found.`);i=t}let a=new P(this.model,i,t,n,r);return super.add(a),a.updateInView(),a.valueSet.resetValues(),a.start?.raise(!1),a.end?.raise(!1),a}remove(e){let t=this.get(e,!0);t&&(E(t.start?.outgoingConnections||[],t),E(t.end?.incomingConnections||[],t),super.remove(e),t.updateInView())}},F={editable:!0,fontSize:0,margin:0,padding:0,fontFamily:`'Wonder Unit Sans', sans-serif`,color:`#000000`,selectedColor:`#000000`,backgroundColor:`transparent`,horizontalAlign:m.Center,verticalAlign:h.Center,orientation:f.Top,multiline:!1,fit:!1,shrink:!0},I=class extends Ee{get text(){return this._text}set text(e){(e==null||e?.trim()===``)&&(e=this.defaultText),this._text=e,this.updateInView(),this.fit&&this.model.canvas?.fitFieldRootInView(this.id,this.shrink)}constructor(e,t,n,r,i,a,o,s,c,l,u,d,p,m,h,g,_){let v=`${t?.id}_field`;if(e.fields.get(v)!==void 0)throw Error(`DiagramField for rootElement already exists`);if(super(e,v),this.textTimestamp=null,this.rootElement=t,this.coords=n,this.width=r,this.height=i,this.fontSize=a,this.fontFamily=o,this.color=s,this.selectedColor=c,this.horizontalAlign=l,this.verticalAlign=u,!isNaN(Number(d)))this.orientation=Number(d);else switch(d){case f.Top:this.orientation=0;break;case f.Right:this.orientation=90;break;case f.Bottom:this.orientation=180;break;case f.Left:this.orientation=270;break;default:this.orientation=0}this.multiline=p,this.defaultText=m,this._text=m,this.editable=h,this.fit=g,this.shrink=_}get removed(){return this.selfRemoved||this.rootElement!==void 0&&this.rootElement.removed}updateInView(){this.model.canvas?.updateFieldsInView(this.id)}raise(){this.select()?.raise()}move(e){this.coords=e,this.updateInView()}getPriority(){return this.rootElement?.getPriority()||0}},Le=class extends j{constructor(e){super(),this.model=e}new(e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h){let g=new I(this.model,e,t,o,s,n,r,i,a,c,l,u,d,f,p,m,h);return super.add(g),g.updateInView(),e!==void 0&&(e.label=g),g}remove(e){let t=this.get(e,!0);t&&(t.rootElement?.label!==void 0&&t.rootElement.label===t&&(t.rootElement.label=void 0),super.remove(e),t.updateInView())}},L=e=>e?.margin===null||e?.margin===void 0?F.margin:typeof e.margin==`number`?e.margin:e.margin.length===0?F.margin:e.margin.length===1||e.margin.length===2?e.margin[0]:(e.margin.length,e.margin[2]),R=e=>e?.margin===null||e?.margin===void 0?F.margin:typeof e.margin==`number`?e.margin:e.margin.length===0?F.margin:e.margin.length===1?e.margin[0]:e.margin.length===2||e.margin.length===3?e.margin[1]:e.margin[3],z=e=>e?.margin===null||e?.margin===void 0?F.margin:typeof e.margin==`number`?e.margin:e.margin.length===0?F.margin:e.margin.length===1?e.margin[0]:(e.margin.length===2||e.margin.length,e.margin[1]),B=e=>e?.margin===null||e?.margin===void 0?F.margin:typeof e.margin==`number`?e.margin:e.margin.length===0?F.margin:(e.margin.length===1||e.margin.length===2||e.margin.length,e.margin[0]),Re=e=>e?.padding===null||e?.padding===void 0?F.padding:typeof e.padding==`number`?e.padding:e.padding.length===0?F.padding:e.padding.length===1||e.padding.length===2?e.padding[0]:(e.padding.length,e.padding[2]),ze=e=>e?.padding===null||e?.padding===void 0?F.padding:typeof e.padding==`number`?e.padding:e.padding.length===0?F.padding:e.padding.length===1?e.padding[0]:e.padding.length===2||e.padding.length===3?e.padding[1]:e.padding[3],Be=e=>e?.padding===null||e?.padding===void 0?F.padding:typeof e.padding==`number`?e.padding:e.padding.length===0?F.padding:e.padding.length===1?e.padding[0]:(e.padding.length===2||e.padding.length,e.padding[1]),Ve=e=>e?.padding===null||e?.padding===void 0?F.padding:typeof e.padding==`number`?e.padding:e.padding.length===0?F.padding:(e.padding.length===1||e.padding.length===2||e.padding.length,e.padding[0]),He=function(e){return e[e.OnlyWhenSelected=0]=`OnlyWhenSelected`,e}({}),Ue=class{constructor(e){this.margin=e.margin||0,this.defaultWidths=e.defaultWidths||null,this.defaultHeights=e.defaultHeights||null,this.minWidths=e.minWidths||null,this.minHeights=e.minHeights||null,this.sections=[];for(let t of e.sections){let e=[];this.sections.push(e);for(let n of t)e.push(new We(n))}}},We=class{constructor(e){this.label=e.label||null,this.ports=e.ports||[],this.priority=e.priority||0,this.resizableX=e.resizableX,this.resizableY=e.resizableY;let t=A(e.look||Ke);this.defaultLook=t.defaultLook,this.selectedLook=t.selectedLook,this.highlightedLook=t.highlightedLook,this.selectedAndHighlightedLook=t.selectedAndHighlightedLook}},V=class extends Ee{get name(){return this.label?.text||``}set name(e){this.label&&(this.label.text=e)}get look(){return this.selected?this.highlighted?this._selectedAndHighlightedLook===void 0?this.type?.selectedAndHighlightedLook||this.node?.look:this._selectedAndHighlightedLook:this._selectedLook===void 0?this.type?.selectedLook||this.node?.look:this._selectedLook:this.highlighted?this._highlightedLook===void 0?this.type?.highlightedLook||this.node?.look:this._highlightedLook:this._defaultLook===void 0?this.type?.defaultLook||this.node?.look:this._defaultLook}set look(e){this.lookConfig=e}get lookConfig(){return this._lookConfig}set lookConfig(e){if(this._lookConfig=e,e){let t=A(e);this._defaultLook={...this._defaultLook,...t.defaultLook},this._selectedLook={...this._selectedLook,...t.selectedLook},this._highlightedLook={...this._highlightedLook,...t.highlightedLook},this._selectedAndHighlightedLook={...this._selectedAndHighlightedLook,...t.selectedAndHighlightedLook}}else this._defaultLook=e,this._selectedLook=e,this._highlightedLook=e,this._selectedAndHighlightedLook=e}constructor(e,t,n,r,i,a,o,s){if(e.sections.get(s)!==void 0)throw Error(`DiagramSection with id "${s}" already exists`);if(!s)throw Error(`DiagramSection cannot have an empty or null id`);super(e,s),this.ports=[],this.decorators=[],this.node=t,this.indexXInNode=n,this.indexYInNode=r,this.coords=i,this.width=a,this.height=o}get removed(){return this.selfRemoved||this.node!==void 0&&this.node.removed}updateInView(){this.model.canvas?.updateSectionsInView(this.id)}raise(){this.select()?.raise(),this.label&&this.label.raise();for(let e of this.ports)e.raise();for(let e of this.decorators)e.raise()}get type(){return this.node?.type?.sectionGrid?.sections?.[this.indexYInNode]?.[this.indexXInNode]}getMinWidth(){return this.node?.type?.sectionGrid?.minWidths?.[this.indexXInNode]||1}getMinHeight(){return this.node?.type?.sectionGrid?.minHeights?.[this.indexYInNode]||1}getPriority(){return this.node?.type?.sectionGrid?.sections?.[this.indexYInNode]?.[this.indexXInNode]?.priority||0}getResizableX(){let e=this.type;return e?.resizableX===void 0?this.node?.getResizableX()||!1:e.resizableX===He.OnlyWhenSelected?this.selected:e.resizableX}getResizableY(){let e=this.type;return e?.resizableY===void 0?this.node?.getResizableY()||!1:e.resizableY===He.OnlyWhenSelected?this.selected:e.resizableY}getClosestPortToPoint(e){if(this.ports.length!==0){if(this.ports.length===1)return this.ports[1];{let t=this.ports.map(t=>t.distanceTo(e)),n=t.indexOf(Math.min(...t));return this.ports[n]}}}getIncomingConnections(e=!1){let t=[];for(let n of this.ports)for(let r of n.incomingConnections)!e&&r.removed||t.push(r);return t}getOutgoingConnections(e=!1){let t=[];for(let n of this.ports)for(let r of n.outgoingConnections)!e&&r.removed||t.push(r);return t}getConnections(e=!1){let t=[];for(let n of this.ports){for(let r of n.incomingConnections)!e&&r.removed||t.push(r);for(let r of n.outgoingConnections)!e&&r.removed||t.push(r)}return t}move(e){this.setGeometry({coords:e,width:this.width,height:this.height})}stretch(e,t){let n=[this.coords[0],this.coords[0]+this.width],r=[this.coords[1],this.coords[1]+this.height],i,a;switch(e){case f.Left:i=[n[0]-t,n[1]],a=[r[0],r[1]],i[1]-i[0]<this.getMinWidth()&&(i[0]=i[1]-this.getMinWidth());break;case f.Top:i=[n[0],n[1]],a=[r[0]-t,r[1]],a[1]-a[0]<this.getMinHeight()&&(a[0]=a[1]-this.getMinHeight());break;case f.Right:i=[n[0],n[1]+t],a=[r[0],r[1]],i[1]-i[0]<this.getMinWidth()&&(i[1]=i[0]+this.getMinWidth());break;case f.Bottom:i=[n[0],n[1]],a=[r[0],r[1]+t],a[1]-a[0]<this.getMinHeight()&&(a[1]=a[0]+this.getMinHeight());break}this.setGeometry({coords:[i[0],a[0]],width:i[1]-i[0],height:a[1]-a[0]})}getGeometry(){return{coords:[...this.coords],width:this.width,height:this.height}}setGeometry(e){let t=[this.coords[0],this.coords[0]+this.width],n=[this.coords[1],this.coords[1]+this.height];this.coords=[...e.coords],this.width=e.width,this.height=e.height;let r=[this.coords[0],this.coords[0]+this.width],i=[this.coords[1],this.coords[1]+this.height];for(let e of this.ports)e.move(y(e.coords,t,n,r,i,e.anchorPointX,e.anchorPointY));let a=this.type;this.label&&(this.label.coords=[this.coords[0]+R(a?.label),this.coords[1]+B(a?.label)],this.label.width=this.width-R(a?.label)-z(a?.label),this.label.height=this.height-B(a?.label)-L(a?.label),this.label.updateInView());for(let e of this.decorators)e.move(y(e.coords,t,n,r,i,e.anchorPointX,e.anchorPointY));this.model.canvas?.autoTightenConnections!==!1&&this.getConnections().forEach(e=>e.tighten()),this.updateInView()}},Ge=class extends j{constructor(e){super(),this.model=e}new(e,t,n,r,i,a,o){let s=new V(this.model,e,t,n,r,i,a,o);super.add(s),s.updateInView(),e.sections.push(s),e.updateInView();let c=e.type.sectionGrid?.sections?.[n]?.[t]?.ports;if(c&&c.length>0)for(let e=0;e<c.length;++e){let t=c[e],n=this.model.ports.new(t.type===void 0?void 0:this.model.ports.types.get(t.type),s,[s.coords[0]+(t.coords[0]||0),s.coords[1]+(t.coords[1]||0)],t.connectionPoint===void 0?void 0:[s.coords[0]+(t.connectionPoint[0]||0),s.coords[1]+(t.connectionPoint[1]||0)],t?.direction,`${s.id}_${e}`,t.anchorPointX||`floating`,t.anchorPointY||`floating`);if(n.type?.label){let e={...F,...n.type?.label},t=6*e.fontSize+ze(e)+Be(e),r=e.fontSize+Ve(e)+Re(e),i;switch(n.direction){case f.Bottom:case f.Left:case f.Right:i=[n.coords[0]-t/2,n.coords[1]-r-L(e)];break;case f.Top:i=[n.coords[0]-t/2,n.coords[1]+B(e)];break;default:i=n.coords}this.model.fields.new(n,i,e.fontSize,e.fontFamily,e.color,e.selectedColor,t,r,e.horizontalAlign,e.verticalAlign,e.orientation,e.multiline,``,e.editable,e.fit,e.shrink)}}let l=e.type.sectionGrid?.sections?.[n]?.[t]?.label;if(l){let e={...F,...l};this.model.fields.new(s,[s.coords[0]+R(e),s.coords[1]+B(e)],e.fontSize,e.fontFamily,e.color,e.selectedColor,s.width-R(e)-z(e),s.height-B(e)-L(e),e.horizontalAlign,e.verticalAlign,e.orientation,e.multiline,``,e.editable,e.fit,e.shrink)}return s}remove(e){let t=this.get(e,!0);if(t){for(;t.ports.length>0;)this.model.ports.remove(t.ports[0].id);t.label&&this.model.fields.remove(t.label.id),t.node&&E(t.node.sections,t),super.remove(e),t.updateInView()}}},Ke={lookType:`shaped-look`,shape:D.Rectangle,fillColor:`#FFFFFF`,borderColor:`#000000`,borderThickness:1,selected:{fillColor:`#FFAAFF`,borderColor:`#AA00AA`},highlighted:{borderThickness:3}},H={name:``,defaultWidth:1,defaultHeight:1,minWidth:1,minHeight:1,resizableX:!1,resizableY:!1,snapToGridOffset:[0,0,0,0],padding:0,label:null,ports:[],decorators:[],sectionGrid:null,look:Ke,isUnique:!1,canBeParentless:!0,childrenTypes:[],priority:0,properties:[]},qe=class{constructor(e){let t={...H,...e};this.id=t.id,this.name=t.name,this.defaultWidth=t.defaultWidth,this.defaultHeight=t.defaultHeight,this.minWidth=t.minWidth,this.minHeight=t.minHeight,this.resizableX=t.resizableX,this.resizableY=t.resizableY,this.snapToGridOffset=t.snapToGridOffset,this.bottomPadding=Xe(t),this.leftPadding=Ze(t),this.rightPadding=Qe(t),this.topPadding=$e(t),this.label=t.label,this.ports=t.ports,this.decorators=t.decorators,this.sectionGrid=t.sectionGrid?new Ue(t.sectionGrid):null;let n=A(t.look);this.defaultLook=n.defaultLook,this.selectedLook=n.selectedLook,this.highlightedLook=n.highlightedLook,this.selectedAndHighlightedLook=n.selectedAndHighlightedLook,this.isUnique=t.isUnique,this.canBeParentless=t.canBeParentless,this.childrenTypes=t.childrenTypes,this.priority=t.priority,this.propertySet=new Oe(e?.properties||[])}},U=class extends Ee{get type(){return this._type}set type(e){e!==this._type&&(this._type=e,this.valueSet&&=new Pe(e.propertySet,this),this.model.canvas?.userSelection?.openInPropertyEditor(this,!1),this.updateInView())}get typeString(){return this.type.id}set typeString(e){if(e!==this.type.id){let t=this.model.nodes.types.get(e);t&&(this.type=t)}}get name(){return this.label?.text||``}set name(e){this.label&&(this.label.text=e)}get look(){return this.selected?this.highlighted?this._selectedAndHighlightedLook===void 0?this.type.selectedAndHighlightedLook:this._selectedAndHighlightedLook:this._selectedLook===void 0?this.type.selectedLook:this._selectedLook:this.highlighted?this._highlightedLook===void 0?this.type.highlightedLook:this._highlightedLook:this._defaultLook===void 0?this.type.defaultLook:this._defaultLook}set look(e){this.lookConfig=e}get lookConfig(){return this._lookConfig}set lookConfig(e){if(this._lookConfig=e,e){let t=A(e);this._defaultLook={...this._defaultLook,...t.defaultLook},this._selectedLook={...this._selectedLook,...t.selectedLook},this._highlightedLook={...this._highlightedLook,...t.highlightedLook},this._selectedAndHighlightedLook={...this._selectedAndHighlightedLook,...t.selectedAndHighlightedLook}}else this._defaultLook=e,this._selectedLook=e,this._highlightedLook=e,this._selectedAndHighlightedLook=e}constructor(e,t,n=[0,0],r){if(e.nodes.get(r)!==void 0)throw Error(`DiagramNode with id "${r}" already exists`);if(!r)throw Error(`DiagramNode cannot have an empty or null id`);super(e,r),this.children=[],this.sections=[],this.ports=[],this.decorators=[],this.geometryTimestamp=null,this._type=t,this.valueSet=new Pe(t.propertySet,this),this.originalData={},this.coords=n,this.width=t.defaultWidth,this.height=t.defaultHeight}get removed(){return this.selfRemoved}updateInView(){this.model.canvas?.updateNodesInView(this.id)}raise(){this.select()?.raise();for(let e of this.sections)e.raise();this.label&&this.label.raise();for(let e of this.ports)e.raise();for(let e of this.decorators)e.raise();for(let e of this.children)e.raise()}getPriority(){return this.type.priority}getResizableX(){let e=this.type.resizableX;return e===He.OnlyWhenSelected?this.selected:e}getResizableY(){let e=this.type.resizableY;return e===He.OnlyWhenSelected?this.selected:e}getClosestPortToPoint(e){if(this.ports.length!==0){if(this.ports.length===1)return this.ports[1];{let t=this.ports.map(t=>t.distanceTo(e)),n=t.indexOf(Math.min(...t));return this.ports[n]}}}getIncomingConnections(e=!1){let t=[];for(let n of this.ports)for(let r of n.incomingConnections)!e&&r.removed||t.push(r);return t}getOutgoingConnections(e=!1){let t=[];for(let n of this.ports)for(let r of n.outgoingConnections)!e&&r.removed||t.push(r);return t}getConnections(e=!1){let t=[];for(let n of this.ports){for(let r of n.incomingConnections)!e&&r.removed||t.push(r);for(let r of n.outgoingConnections)!e&&r.removed||t.push(r)}return t}getAdjacentNodes(e=!1){let t=[];for(let n of this.ports){for(let r of n.incomingConnections){if(!e&&r.removed)continue;let n=r.start?.getNode();if(n){if(!e&&n.removed)continue;t.push(n)}}for(let r of n.outgoingConnections){if(!e&&r.removed)continue;let n=r.end?.getNode();if(n){if(!e&&n.removed)continue;t.push(n)}}}return t}getLastAncestor(){let e=this;for(;e.parent!==void 0;)e=e?.parent;return e}isAncestorOf(e){let t=e;for(;t!==void 0;){if(this.id===t.id)return!0;t=t.parent}return!1}isDescendantOf(e){return e.isAncestorOf(this)}addChild(e){if(e.id===this.id)return;let t=this.parent,n=!1;for(;t!==void 0;){if(t.id===e.id){n=!0;break}t=t.parent}n||this.children.indexOf(e)>=0||(this.fitToChild(e),this.children.push(e),e.parent=this,e.raise())}removeChild(e){E(this.children,e),e.parent=void 0}fitToChild(e){let t=Math.max(...this.sections.map(e=>e.indexXInNode)),n=Math.max(...this.sections.map(e=>e.indexYInNode)),r=this.coords[0]-e.coords[0]+this.type.leftPadding;r>=0&&(this.sections.length>0?this.stretchSections(f.Left,r,t,n):this.stretch(f.Left,r));let i=this.coords[1]-e.coords[1]+this.type.topPadding;i>=0&&(this.sections.length>0?this.stretchSections(f.Top,i,t,n):this.stretch(f.Top,i));let a=e.coords[0]+e.width-(this.coords[0]+this.width)+this.type.rightPadding;a>=0&&(this.sections.length>0?this.stretchSections(f.Right,a,t,n):this.stretch(f.Right,a));let o=e.coords[1]+e.height-(this.coords[1]+this.height)+this.type.bottomPadding;o>=0&&(this.sections.length>0?this.stretchSections(f.Bottom,o,t,n):this.stretch(f.Bottom,o)),this.parent&&this.parent.fitToChild(this)}move(e){let t=[e[0]-this.coords[0],e[1]-this.coords[1]];for(let e of this.children)e.move([e.coords[0]+t[0],e.coords[1]+t[1]]);for(let e of this.sections)e.move([e.coords[0]+t[0],e.coords[1]+t[1]]);this.setGeometry({coords:e,width:this.width,height:this.height,sections:{},children:{}})}stretch(e,t){let n=[this.coords[0],this.coords[0]+this.width],r=[this.coords[1],this.coords[1]+this.height],i,a;switch(e){case f.Left:i=[n[0]-t,n[1]],a=[r[0],r[1]],i[1]-i[0]<this.type.minWidth&&(i[0]=i[1]-this.type.minWidth);break;case f.Top:i=[n[0],n[1]],a=[r[0]-t,r[1]],a[1]-a[0]<this.type.minHeight&&(a[0]=a[1]-this.type.minHeight);break;case f.Right:i=[n[0],n[1]+t],a=[r[0],r[1]],i[1]-i[0]<this.type.minWidth&&(i[1]=i[0]+this.type.minWidth);break;case f.Bottom:i=[n[0],n[1]],a=[r[0],r[1]+t],a[1]-a[0]<this.type.minHeight&&(a[1]=a[0]+this.type.minHeight);break}this.setGeometry({coords:[i[0],a[0]],width:i[1]-i[0],height:a[1]-a[0],sections:{},children:{}})}stretchSections(e,t,n,r){let i=-1/0;switch(e){case f.Bottom:for(let e of this.sections)e.indexYInNode===r&&(i=Math.max(i,e.getMinHeight()-e.height));t<i&&(t=i);for(let n of this.sections)n.indexYInNode===r?n.stretch(e,t):n.indexYInNode>r&&n.move([n.coords[0],n.coords[1]+t]);break;case f.Right:for(let e of this.sections)e.indexXInNode===n&&(i=Math.max(i,e.getMinWidth()-e.width));t<i&&(t=i);for(let r of this.sections)r.indexXInNode===n?r.stretch(e,t):r.indexXInNode>n&&r.move([r.coords[0]+t,r.coords[1]]);break;case f.Top:for(let e of this.sections)e.indexYInNode===r&&(i=Math.max(i,e.getMinHeight()-e.height));t<i&&(t=i);for(let n of this.sections)n.indexYInNode===r?n.stretch(e,t):n.indexYInNode<r&&n.move([n.coords[0],n.coords[1]-t]);break;case f.Left:for(let e of this.sections)e.indexXInNode===n&&(i=Math.max(i,e.getMinWidth()-e.width));t<i&&(t=i);for(let r of this.sections)r.indexXInNode===n?r.stretch(e,t):r.indexXInNode<n&&r.move([r.coords[0]-t,r.coords[1]]);break}this.stretch(e,t)}getGeometry(e){let t={};for(let e of this.sections)t[e.id]=e.getGeometry();let n={};for(let t of this.children)t.id!==e&&(n[t.id]=t.getGeometry(e));return{coords:[...this.coords],width:this.width,height:this.height,sections:t,children:n}}setGeometry(e){this.raise();let t=[this.coords[0],this.coords[0]+this.width],n=[this.coords[1],this.coords[1]+this.height];this.coords=[...e.coords],this.width=e.width,this.height=e.height;let r=[this.coords[0],this.coords[0]+this.width],i=[this.coords[1],this.coords[1]+this.height];for(let t of this.children){let n=e.children[t.id];n&&t.setGeometry(n)}for(let t of this.sections){let n=e.sections[t.id];n&&t.setGeometry(n)}for(let e of this.ports)e.move(y(e.coords,t,n,r,i,e.anchorPointX,e.anchorPointY));this.label&&(this.label.coords=[this.coords[0]+R(this.type.label),this.coords[1]+B(this.type.label)],this.label.width=this.width-R(this.type.label)-z(this.type.label),this.label.height=this.height-B(this.type.label)-L(this.type.label),this.label.updateInView());for(let e of this.decorators)e.move(y(e.coords,t,n,r,i,e.anchorPointX,e.anchorPointY));this.model.canvas?.autoTightenConnections!==!1&&this.getConnections().forEach(e=>e.tighten()),this.updateInView()}removeSectionColumn(e){let t=this.type.sectionGrid?.margin||0,n=0,r=[...this.sections];for(let t of r)t.indexYInNode===e&&(n=Math.max(n,t.width),this.model.sections.remove(t.id));for(let i of r)i.indexYInNode>e&&(--i.indexYInNode,i.move([i.coords[0]-n-t,i.coords[1]]));this.stretch(f.Right,-t-n)}removeSectionRow(e){let t=this.type.sectionGrid?.margin||0,n=0,r=[...this.sections];for(let t of r)t.indexXInNode===e&&(n=Math.max(n,t.height),this.model.sections.remove(t.id));for(let i of r)i.indexYInNode>e&&(--i.indexXInNode,i.move([i.coords[0],i.coords[1]-n-t]));this.stretch(f.Bottom,-t-n)}copySectionColumn(e){let t=this.type.sectionGrid?.margin||0,n=0,r=[...this.sections];for(let i of r)if(i.indexXInNode===e){n=Math.max(n,i.width);let e=i.indexXInNode+1;for(;this.model.sections.get(`${i.id}_copy_${e}_${i.indexYInNode}`,!0)!==void 0;)++e;this.model.sections.new(this,i.indexXInNode+1,i.indexYInNode,[i.coords[0]+i.width+t,i.coords[1]],i.width,i.height,`${i.id}_copy_${e}_${i.indexYInNode}`)}for(let i of r)i.indexXInNode>e&&(++i.indexXInNode,i.move([i.coords[0]+n+t,i.coords[1]]));this.stretch(f.Right,t+n)}copySectionRow(e){let t=this.type.sectionGrid?.margin||0,n=0,r=[...this.sections];for(let i of r)if(i.indexYInNode===e){n=Math.max(n,i.height);let e=i.indexYInNode+1;for(;this.model.sections.get(`${i.id}_copy_${i.indexXInNode}_${e}`,!0)!==void 0;)++e;this.model.sections.new(this,i.indexXInNode,i.indexYInNode+1,[i.coords[0],i.coords[1]+i.height+t],i.width,i.height,`${i.id}_copy_${i.indexXInNode}_${e}`)}for(let i of r)i.indexYInNode>e&&(++i.indexYInNode,i.move([i.coords[0],i.coords[1]+n+t]));this.stretch(f.Bottom,t+n)}},Je=class extends j{constructor(e){super(),this.types=new Te,this.model=e}new(e,t,n){let r;if(e instanceof qe)r=e;else{let t=this.types.get(e);if(t===void 0)throw TypeError(`Node type with id '${e}' could not be found.`);r=t}let i=new U(this.model,r,t,n);if(super.add(i),i.updateInView(),r.sectionGrid!==null){let e=i.coords[1]+(r.sectionGrid.margin||0);for(let t=0;t<r.sectionGrid.sections.length;++t){let n=i.coords[0]+(r.sectionGrid.margin||0);for(let a=0;a<r.sectionGrid.sections[t].length;++a)this.model.sections.new(i,a,t,[n,e],r.sectionGrid.defaultWidths?.[a]||1,r.sectionGrid.defaultHeights?.[t]||1,`${i.id}_${t}_${a}`),n+=(r.sectionGrid.defaultWidths?.[a]||1)+(r.sectionGrid.margin||0);e+=(r.sectionGrid.defaultHeights?.[t]||1)+(r.sectionGrid.margin||0)}}if(r.ports.length>0)for(let e=0;e<r.ports.length;++e){let t=r.ports[e],n=t.type===void 0?void 0:this.model.ports.types.get(t.type),a=this.model.ports.new(n,i,[i.coords[0]+t.coords[0],i.coords[1]+t.coords[1]],t.connectionPoint===void 0?void 0:[i.coords[0]+(t.connectionPoint[0]||0),i.coords[1]+(t.connectionPoint[1]||0)],t.direction,`${i.id}_port_${e}`,t.anchorPointX||`floating`,t.anchorPointY||`floating`);if(a.type?.label){let e={...F,...a.type?.label},t=6*e.fontSize+ze(e)+Be(e),n=e.fontSize+Ve(e)+Re(e),r;switch(a.direction){case f.Bottom:case f.Left:case f.Right:r=[a.coords[0]-t/2,a.coords[1]-n-L(e)];break;case f.Top:r=[a.coords[0]-t/2,a.coords[1]+B(e)];break;default:r=a.coords}this.model.fields.new(a,r,e.fontSize,e.fontFamily,e.color,e.selectedColor,t,n,e.horizontalAlign,e.verticalAlign,e.orientation,e.multiline,``,e.editable,e.fit,e.shrink)}}if(r.label){let e={...F,...r.label};this.model.fields.new(i,[i.coords[0]+R(e),i.coords[1]+B(e)],e.fontSize,e.fontFamily,e.color,e.selectedColor,i.width-R(e)-z(e),i.height-B(e)-L(e),e.horizontalAlign,e.verticalAlign,e.orientation,e.multiline,``,e.editable,e.fit,e.shrink)}if(r.decorators.length>0)for(let e=0;e<r.decorators.length;++e){let t=r.decorators[e];this.model.decorators.new(i,[i.coords[0]+t.coords[0],i.coords[1]+t.coords[1]],t.width,t.height,i.getPriority(),t.html,`${i.id}_decorator_${e}`,t.anchorPointX||`floating`,t.anchorPointY||`floating`)}return i.valueSet.resetValues(),i.model.canvas?.fitNodeInView(i.id),i}remove(e){let t=this.get(e,!0);if(t){for(t.parent&&E(t.parent.children,t);t.children.length>0;)this.model.nodes.remove(t.children[0].id);for(;t.sections.length>0;)this.model.sections.remove(t.sections[0].id);for(;t.ports.length>0;)this.model.ports.remove(t.ports[0].id);for(;t.decorators.length>0;)this.model.decorators.remove(t.decorators[0].id);t.label&&this.model.fields.remove(t.label.id),super.remove(e),t.updateInView()}}getAtCoordinates(e,t){let n=[];for(let r of this)r.coords[0]<e&&e<r.coords[0]+r.width&&r.coords[1]<t&&t<r.coords[1]+r.height&&n.push(r);return n}},Ye=e=>{for(let t=0;t<e.length;++t)for(let n=0;n<e.length;++n)n!==t&&e[n].isAncestorOf(e[t])&&(e.splice(n,1),--n,t>n&&--t);return e},Xe=e=>e?.padding===null||e?.padding===void 0?H.padding:typeof e.padding==`number`?e.padding:e.padding.length===0?H.padding:e.padding.length===1||e.padding.length===2?e.padding[0]:(e.padding.length,e.padding[2]),Ze=e=>e?.padding===null||e?.padding===void 0?H.padding:typeof e.padding==`number`?e.padding:e.padding.length===0?H.padding:e.padding.length===1?e.padding[0]:e.padding.length===2||e.padding.length===3?e.padding[1]:e.padding[3],Qe=e=>e?.padding===null||e?.padding===void 0?H.padding:typeof e.padding==`number`?e.padding:e.padding.length===0?H.padding:e.padding.length===1?e.padding[0]:(e.padding.length===2||e.padding.length,e.padding[1]),$e=e=>e?.padding===null||e?.padding===void 0?H.padding:typeof e.padding==`number`?e.padding:e.padding.length===0?H.padding:(e.padding.length===1||e.padding.length===2||e.padding.length,e.padding[0]),et={lookType:`shaped-look`,shape:D.Ellipse,fillColor:`transparent`,borderColor:`transparent`,borderThickness:0,selected:{fillColor:`rgba(255, 0, 255, 0.5)`},highlighted:{fillColor:`rgba(0, 255, 255, 0.5)`}},tt=A(et),nt={name:``,label:null,allowsOutgoing:!0,allowsIncoming:!0,width:24,look:et},rt=class{constructor(e){let t={...nt,...e};this.id=t.id,this.name=t.name,this.label=t.label,this.allowsOutgoing=t.allowsOutgoing,this.allowsIncoming=t.allowsIncoming,this.width=t.width;let n=A(t.look);this.defaultLook=n.defaultLook,this.selectedLook=n.selectedLook,this.highlightedLook=n.highlightedLook,this.selectedAndHighlightedLook=n.selectedAndHighlightedLook}},it=class extends Ee{get type(){return this._type}set type(e){e!==this._type&&(this._type=e,this.updateInView())}get typeString(){return this.type?.id}set typeString(e){if(e!==this.type?.id)if(e===void 0)this.type=void 0;else{let t=this.model.ports.types.get(e);t&&(this.type=t)}}get allowsOutgoing(){return this.type?.allowsOutgoing===void 0?!0:this.type?.allowsOutgoing}get allowsIncoming(){return this.type?.allowsIncoming===void 0?!0:this.type?.allowsIncoming}get name(){return this.label?.text||``}set name(e){this.label&&(this.label.text=e)}get look(){return this.selected?this.highlighted?this._selectedAndHighlightedLook===void 0?(this.type||tt)?.selectedAndHighlightedLook:this._selectedAndHighlightedLook:this._selectedLook===void 0?(this.type||tt)?.selectedLook:this._selectedLook:this.highlighted?this._highlightedLook===void 0?(this.type||tt)?.highlightedLook:this._highlightedLook:this._defaultLook===void 0?(this.type||tt)?.defaultLook:this._defaultLook}set look(e){this.lookConfig=e}get lookConfig(){return this._lookConfig}set lookConfig(e){if(this._lookConfig=e,e){let t=A(e);this._defaultLook={...this._defaultLook,...t.defaultLook},this._selectedLook={...this._selectedLook,...t.selectedLook},this._highlightedLook={...this._highlightedLook,...t.highlightedLook},this._selectedAndHighlightedLook={...this._selectedAndHighlightedLook,...t.selectedAndHighlightedLook}}else this._defaultLook=e,this._selectedLook=e,this._highlightedLook=e,this._selectedAndHighlightedLook=e}get width(){return this.type?.width||nt.width}get height(){return this.width}constructor(e,t,n,r,i,a,o,s=`floating`,c=`floating`){if(e.ports.get(o)!==void 0)throw Error(`DiagramPort with id "${o}" already exists`);if(!o)throw Error(`DiagramPort cannot have an empty or null id`);super(e,o),this.outgoingConnections=[],this.incomingConnections=[],this._type=t,this.rootElement=n,this.coords=r,this.connectionPoint=i||r,this.direction=a,this.anchorPointX=s,this.anchorPointY=c}get removed(){return this.selfRemoved||this.rootElement!==void 0&&this.rootElement.removed}updateInView(){this.model.canvas?.updatePortsInView(this.id)}raise(e=!0){if(this.select()?.raise(),this.label&&this.label.raise(),e){for(let e of this.incomingConnections)e.raise();for(let e of this.outgoingConnections)e.raise()}}startConnection(e){this.outgoingConnections.push(e)}finishConnection(e){this.incomingConnections.push(e)}getNode(){if(this.rootElement instanceof U)return this.rootElement;if(this.rootElement instanceof V)return this.rootElement.node}getPriority(){return this.rootElement?.getPriority()||0}move(e){let t=[e[0]-this.coords[0],e[1]-this.coords[1]];this.coords=e,this.connectionPoint[0]=this.connectionPoint[0]+t[0],this.connectionPoint[1]=this.connectionPoint[1]+t[1];for(let e of this.outgoingConnections)e.setStart(this);for(let e of this.incomingConnections)e.setEnd(this);this.label&&this.label.move([this.label.coords[0]+t[0],this.label.coords[1]+t[1]]),this.updateInView()}distanceTo(e){return b(this.coords,e)}},at=class extends j{constructor(e){super(),this.types=new Te,this.model=e}new(e,t,n,r,i,a,o=`floating`,s=`floating`){let c=new it(this.model,e,t,n,r,i,a,o,s);return super.add(c),c.updateInView(),t!==void 0&&t.ports.push(c),c}remove(e){let t=this.get(e,!0);if(t){for(;t.outgoingConnections.length>0;)this.model.connections.remove(t.outgoingConnections[0].id);for(;t.incomingConnections.length>0;)this.model.connections.remove(t.incomingConnections[0].id);t.label&&this.model.fields.remove(t.label.id),(t.rootElement instanceof U||t.rootElement instanceof V)&&E(t.rootElement.ports,t),super.remove(e),t.updateInView()}}},ot=class{import(e,t){e.clear(),t.id&&(e.id=t.id),e.name=t.name,e.description=t.description,e.type=t.type,e.createdAt=new Date(t.createdAt),e.updatedAt=new Date(t.updatedAt);for(let n of t.nodes||[])this.importNode(e,n);for(let n of t.connections||[])this.importConnection(e,n);return t.data&&e.valueSet.setValues(t.data),t.collabMeta&&(e.logicalClock=t.collabMeta.logicalClock,e.valueSet.setTimestamps(t.collabMeta.dataTimestamps)),e}importNode(e,t){let n=e.nodes.types.get(t.type);if(n){let r=new U(e,n,t.coords,t.id);if(e.nodes.add(r),r.width=t.width,r.height=t.height,n.decorators)for(let t=0;t<n.decorators.length;++t){let i=n.decorators[t];e.decorators.new(r,[r.coords[0]+i.coords[0],r.coords[1]+i.coords[1]],i.width,i.height,r.getPriority(),i.html,`${r.id}_decorator_${t}`)}if(n.label){let i={...F,...n.label},a=new I(e,r,[r.coords[0]+R(i),r.coords[1]+B(i)],r.width-R(i)-z(i),r.height-B(i)-L(i),i.fontSize,i.fontFamily,i.color,i.selectedColor,i.horizontalAlign,i.verticalAlign,i.orientation,i.multiline,``,i.editable,i.fit,i.shrink);a.text=t.label,r.label=a,e.fields.add(a),a.updateInView()}for(let n of t.children||[]){let t=this.importNode(e,n);t!==void 0&&(r.children?.push(t),t.parent=r)}for(let i of t.sections||[]){let t=new V(e,r,i.indexXInNode,i.indexYInNode,i.coords,i.width,i.height,i.id);if(r.sections?.push(t),e.sections.add(t),n.sectionGrid?.sections?.[i.indexYInNode]?.[i.indexXInNode]?.label){let r={...F,...n.sectionGrid?.sections?.[i.indexYInNode]?.[i.indexXInNode]?.label},a=new I(e,t,[t.coords[0]+R(r),t.coords[1]+B(r)],t.width-R(r)-z(r),t.height-B(r)-L(r),r.fontSize,r.fontFamily,r.color,r.selectedColor,r.horizontalAlign,r.verticalAlign,r.orientation,r.multiline,``,r.editable,r.fit,r.shrink);a.text=i.label,t.label=a,e.fields.add(a),a.updateInView()}let a=0;for(let r of i.ports||[]){let i=r.type===void 0?void 0:e.ports.types.get(r.type),o=new it(e,i,t,r.coords,r.connectionPoint||r.coords,r.direction,r.id);if(t.ports.push(o),e.ports.add(o),r.label){if(n.ports.length>a&&i?.label){let t={...F,...i?.label},n;switch(o.direction){case f.Top:case f.Left:n=[o.coords[0]-t.fontSize,o.coords[1]-t.fontSize];break;case f.Bottom:n=[o.coords[0]-t.fontSize,o.coords[1]+t.fontSize];break;case f.Right:n=[o.coords[0]+t.fontSize,o.coords[1]-t.fontSize];break;default:n=o.coords}let a=new I(e,o,n,t.fontSize,t.fontSize,t.fontSize,t.fontFamily,t.color,t.selectedColor,t.horizontalAlign,t.verticalAlign,t.orientation,t.multiline,``,t.editable,t.fit,t.shrink);a.text=r.label,o.label=a,e.fields.add(a),a.updateInView()}++a}r.collabMeta&&(o.selfRemoved=r.collabMeta.selfRemoved,o.selfRemovedTimestamp=r.collabMeta.selfRemovedTimestamp,this.importLabelCollabMeta(o.label,r.collabMeta.label)),o.updateInView()}i.collabMeta&&(t.selfRemoved=i.collabMeta.selfRemoved,t.selfRemovedTimestamp=i.collabMeta.selfRemovedTimestamp,this.importLabelCollabMeta(t.label,i.collabMeta.label)),t.updateInView()}let i=0;for(let a of t.ports||[]){let t=a.type===void 0?void 0:e.ports.types.get(a.type),o=new it(e,t,r,a.coords,a.connectionPoint||a.coords,a.direction,a.id);if(r.ports.push(o),e.ports.add(o),a.label){if(n.ports.length>i&&t?.label){let n={...F,...t?.label},r;switch(o.direction){case f.Top:case f.Left:r=[o.coords[0]-n.fontSize,o.coords[1]-n.fontSize];break;case f.Bottom:r=[o.coords[0]-n.fontSize,o.coords[1]+n.fontSize];break;case f.Right:r=[o.coords[0]+n.fontSize,o.coords[1]-n.fontSize];break;default:r=o.coords}let i=new I(e,o,r,n.fontSize,n.fontSize,n.fontSize,n.fontFamily,n.color,n.selectedColor,n.horizontalAlign,n.verticalAlign,n.orientation,n.multiline,``,n.editable,n.fit,n.shrink);i.text=a.label,o.label=i,e.fields.add(i),i.updateInView()}++i}a.collabMeta&&(o.selfRemoved=a.collabMeta.selfRemoved,o.selfRemovedTimestamp=a.collabMeta.selfRemovedTimestamp,this.importLabelCollabMeta(o.label,a.collabMeta.label)),o.updateInView()}return t.data&&r.valueSet.setValues(t.data),t.collabMeta&&(r.selfRemoved=t.collabMeta.selfRemoved,r.selfRemovedTimestamp=t.collabMeta.selfRemovedTimestamp,r.geometryTimestamp=t.collabMeta.geometryTimestamp,this.importLabelCollabMeta(r.label,t.collabMeta.label),r.valueSet.setTimestamps(t.collabMeta.dataTimestamps)),r.updateInView(),r.raise(),r}}importConnection(e,t){let n=e.connections.types.get(t.type);if(n){let r=new P(e,n,t.start?e.ports.get(t.start):void 0,t.end?e.ports.get(t.end):void 0,t.id);return e.connections.add(r),r.startLabel=t.startLabel,r.middleLabel=t.middleLabel,r.endLabel=t.endLabel,r.points=t.points,t.data&&r.valueSet.setValues(t.data),t.collabMeta&&(r.selfRemoved=t.collabMeta.selfRemoved,r.selfRemovedTimestamp=t.collabMeta.selfRemovedTimestamp,r.valueSet.setTimestamps(t.collabMeta.dataTimestamps)),r.updateInView(),r.raise(),r}}importLabelCollabMeta(e,t){e&&t&&(e.selfRemoved=t.selfRemoved,e.selfRemovedTimestamp=t.selfRemovedTimestamp,e.textTimestamp=t.textTimestamp)}},st=class e{constructor(e,t,n,r,i,a,o){this.canvas=e,this.id=t,this.typeId=n,this.coords=r,this.parentId=i,this.label=a,this.values=o}do(){let e=this.canvas.model.nodes.new(this.typeId,this.coords,this.id);this.parentId!==void 0&&this.canvas.model.nodes.get(this.parentId)?.addChild(e),e.label&&(e.label.text=this.label||``),this.values===void 0?e.valueSet.resetValues():e.valueSet.setValues(we({...e.valueSet.getValues(),...this.values}))}serialize(){return{type:`addNode`,id:this.id,typeId:this.typeId,coords:this.coords,parentId:this.parentId,label:this.label,values:this.values}}static deserialize(t,n){return new e(t,n.id,n.typeId,n.coords,n.parentId,n.label,n.values)}},ct=class e{constructor(e,t,n,r,i,a,o){this.canvas=e,this.nodeId=t,this.copyColumnIndex=n,this.copyRowIndex=r,this.removeColumnIndex=i,this.removeRowIndex=a,this.timestamp=o}do(){let e=this.canvas.model.nodes.get(this.nodeId);e&&ke(this.timestamp,e.geometryTimestamp)&&(this.copyColumnIndex!==void 0&&e.copySectionColumn(this.copyColumnIndex),this.copyRowIndex!==void 0&&e.copySectionRow(this.copyRowIndex),this.removeColumnIndex!==void 0&&e.removeSectionColumn(this.removeColumnIndex),this.removeRowIndex!==void 0&&e.removeSectionRow(this.removeRowIndex),e.geometryTimestamp=this.timestamp)}serialize(){return{type:`addSection`,nodeId:this.nodeId,copyColumnIndex:this.copyColumnIndex,copyRowIndex:this.copyRowIndex,removeColumnIndex:this.removeColumnIndex,removeRowIndex:this.removeRowIndex,timestamp:this.timestamp}}static deserialize(t,n){return new e(t,n.nodeId,n.copyColumnIndex,n.copyRowIndex,n.removeColumnIndex,n.removeRowIndex,n.timestamp)}},lt=class e{constructor(e,t,n){this.canvas=e,this.to=t,this.timestamp=n}do(){for(let e in this.to){let t=this.canvas.model.nodes.get(e,!0);if(t&&ke(this.timestamp,t.geometryTimestamp)){let n=this.to[e];t.move([n[0],n[1]]),t.geometryTimestamp=this.timestamp}}}serialize(){return{type:`applyLayout`,to:this.to,timestamp:this.timestamp}}static deserialize(t,n){return new e(t,n.to,n.timestamp)}},ut=class e{constructor(e,t,n,r){this.canvas=e,this.nodeIds=t,this.delta=n,this.timestamp=r}do(){for(let e of this.nodeIds){let t=this.canvas.model.nodes.get(e,!0);t&&ke(this.timestamp,t.geometryTimestamp)&&(t.move([t.coords[0]+this.delta[0],t.coords[1]+this.delta[1]]),t.parent?.fitToChild(t),t.geometryTimestamp=this.timestamp)}}serialize(){return{type:`move`,nodeIds:this.nodeIds,delta:this.delta,timestamp:this.timestamp}}static deserialize(t,n){return new e(t,n.nodeIds,n.delta,n.timestamp)}},W=class e{constructor(e,t,n,r){this.canvas=e,this.nodeId=t,this.to=n,this.timestamp=r}do(){let e=this.canvas.model.nodes.get(this.nodeId,!0);if(e&&ke(this.timestamp,e.geometryTimestamp)){e.setGeometry(this.to),e.label?.fit&&this.canvas.fitFieldRootInView(e.label.id,e.label.shrink);for(let t of e.sections)t.label?.fit&&this.canvas.fitFieldRootInView(t.label.id,t.label.shrink);e.parent?.fitToChild(e),e.geometryTimestamp=this.timestamp}}serialize(){return{type:`setGeometry`,nodeId:this.nodeId,to:this.to,timestamp:this.timestamp}}static deserialize(t,n){return new e(t,n.nodeId,n.to,n.timestamp)}},dt=class e{constructor(e,t,n,r,i){this.canvas=e,this.childId=t,this.parentId=n,this.childGeometry=r,this.timestamp=i}do(){let e=this.canvas.model.nodes.get(this.childId,!0),t=this.parentId===void 0?void 0:this.canvas.model.nodes.get(this.parentId,!0);e&&(this.parentId===void 0||t)&&ke(this.timestamp,e.geometryTimestamp)&&(e.parent?.removeChild(e),e.setGeometry(this.childGeometry),t?.addChild(e))}serialize(){return{type:`setParent`,childId:this.childId,parentId:this.parentId,childGeometry:this.childGeometry,timestamp:this.timestamp}}static deserialize(t,n){return new e(t,n.childId,n.parentId,n.childGeometry,n.timestamp)}},ft=class e{constructor(e,t,n,r,i){this.canvas=e,this.id=t,this.typeId=n,this.startId=r,this.endId=i}do(){let e=this.canvas.model.ports.get(this.startId,!0),t=this.canvas.model.ports.get(this.endId,!0);e&&t&&this.canvas.model.connections.new(this.typeId,e,t,this.id)}serialize(){return{type:`addConnection`,id:this.id,typeId:this.typeId,startId:this.startId,endId:this.endId}}static deserialize(t,n){return new e(t,n.id,n.typeId,n.startId,n.endId)}},pt=class e{constructor(e,t,n,r){this.canvas=e,this.fieldId=t,this.to=n,this.timestamp=r}do(){let e=this.canvas.model.fields.get(this.fieldId,!0);e&&ke(this.timestamp,e.textTimestamp)&&(e.text=this.to,e.textTimestamp=this.timestamp)}serialize(){return{type:`editField`,fieldId:this.fieldId,to:this.to,timestamp:this.timestamp}}static deserialize(t,n){return new e(t,n.fieldId,n.to,n.timestamp)}},mt=class e{constructor(e,t,n,r){this.canvas=e,this.id=t,this.to=n,this.timestamp=r}getValueSet(){return this.id===void 0?this.canvas.model.valueSet:(this.canvas.model.nodes.get(this.id,!0)||this.canvas.model.connections.get(this.id,!0))?.valueSet}do(){this.getValueSet()?.overwriteValuesLww(this.to,this.timestamp)}serialize(){return{type:`updateValues`,id:this.id,to:this.to,timestamp:this.timestamp}}static deserialize(t,n){return new e(t,n.id,n.to,n.timestamp)}},G=class e{constructor(e,t,n,r,i,a,o,s){this.canvas=e,this.nodeIds=t,this.sectionIds=n,this.portIds=r,this.connectionIds=i,this.fieldIds=a,this.selfRemoved=o,this.timestamp=s}doOne(e){e&&ke(this.timestamp,e.selfRemovedTimestamp)&&(e.selfRemoved=this.selfRemoved,e.selfRemovedTimestamp=this.timestamp)}do(){for(let e of this.nodeIds)this.doOne(this.canvas.model.nodes.get(e,!0));for(let e of this.sectionIds)this.doOne(this.canvas.model.sections.get(e,!0));for(let e of this.portIds)this.doOne(this.canvas.model.ports.get(e,!0));for(let e of this.connectionIds)this.doOne(this.canvas.model.connections.get(e,!0));for(let e of this.fieldIds)this.doOne(this.canvas.model.fields.get(e,!0));this.canvas.updateNodesInView(...this.nodeIds),this.canvas.updateSectionsInView(...this.sectionIds),this.canvas.updatePortsInView(...this.portIds),this.canvas.updateConnectionsInView(...this.connectionIds),this.canvas.updateFieldsInView(...this.fieldIds),this.canvas.updateDecoratorsInView()}serialize(){return{type:`setSelfRemoved`,nodeIds:this.nodeIds,sectionIds:this.sectionIds,portIds:this.portIds,connectionIds:this.connectionIds,fieldIds:this.fieldIds,removed:this.selfRemoved,timestamp:this.timestamp}}static deserialize(t,n){return new e(t,n.nodeIds,n.sectionIds,n.portIds,n.connectionIds,n.fieldIds,n.removed,n.timestamp)}},ht=class e{constructor(e,t,n){this.canvas=e,this.nodes=t,this.connections=n}do(){let e=new ot;this.canvas.userSelection.clear();for(let t of this.nodes){let n=e.importNode(this.canvas.model,t);n&&this.canvas.userSelection.add(n)}for(let t of this.connections){let n=e.importConnection(this.canvas.model,t);n&&this.canvas.userSelection.add(n)}}serialize(){return{type:`paste`,nodes:this.nodes,connections:this.connections}}static deserialize(t,n){return new e(t,n.nodes,n.connections)}},gt=class{constructor(e){this.isInRoom=!1,this.canvas=e,this.replicaId=Se()}freshTimestamp(){return this.canvas.model.logicalClock++,[this.canvas.model.logicalClock,this.replicaId]}freshId(){return`id`+Se()}doCollaboratively(e){if(e.do(),this.onSend){let t=e.serialize();this.onSend(t)}}receive(e){switch(`timestamp`in e&&(this.canvas.model.logicalClock=Math.max(this.canvas.model.logicalClock,e.timestamp[0])),e.type){case`addNode`:st.deserialize(this.canvas,e).do();break;case`addSection`:ct.deserialize(this.canvas,e).do();break;case`applyLayout`:lt.deserialize(this.canvas,e).do();break;case`move`:ut.deserialize(this.canvas,e).do();break;case`setGeometry`:W.deserialize(this.canvas,e).do();break;case`setParent`:dt.deserialize(this.canvas,e).do();break;case`addConnection`:ft.deserialize(this.canvas,e).do();break;case`editField`:pt.deserialize(this.canvas,e).do();break;case`updateValues`:mt.deserialize(this.canvas,e).do();break;case`setSelfRemoved`:G.deserialize(this.canvas,e).do();break;case`paste`:ht.deserialize(this.canvas,e).do();break;default:console.error(`Unknown CollabAction type, skipping:`,e)}}},_t=class{constructor(e,t){this.canvas=e,this.maximum=t,this.history=[],this.index=0}add(e){this.index<this.history.length&&(this.history=this.history.slice(0,this.index)),this.history.length>=this.maximum?(this.history=this.history.slice(1,this.history.length),this.history.push(e)):(this.history.push(e),++this.index),this.canvas.diagramChange$.next({action:e,method:vt.Do})}undo(){let e;if(this.index>0){let t;do--this.index,e=this.history[this.index],t=e.undo();while(!t&&this.index>0)}this.canvas.diagramChange$.next({action:e,method:vt.Undo})}redo(){let e;if(this.index<this.history.length){let t;do e=this.history[this.index],t=e.redo(),++this.index;while(!t&&this.index<this.history.length)}this.canvas.diagramChange$.next({action:e,method:vt.Redo})}},vt=function(e){return e[e.Do=0]=`Do`,e[e.Undo=1]=`Undo`,e[e.Redo=2]=`Redo`,e}({}),K=function(e){return e.AddConnection=`add-connection`,e.AddNode=`add-node`,e.AddSectionAction=`add-section`,e.ApplyLayout=`apply-layout`,e.Clipboard=`clipboard`,e.ContextMenu=`context-menu`,e.EditField=`edit-field`,e.MoveNode=`move-node`,e.Paste=`paste`,e.Remove=`remove`,e.StretchNode=`stretch-node`,e.StretchSection=`stretch-section`,e.UpdateValues=`update-values`,e.Zoom=`zoom`,e}({}),yt=class{constructor(e,t,n,r,i,a,o,s,c){this.canvas=e,this.type=t,this.coords=n,this.parentId=r,this.ancestorId=i,this.fromAncestorGeometry=a,this.toAncestorGeometry=o,this.label=s,this.values=c,this.id=this.canvas.collabEngine.freshId()}do(){let e=new st(this.canvas,this.id,this.type.id,this.coords,this.parentId,this.label,this.values);if(this.canvas.collabEngine.doCollaboratively(e),this.ancestorId!==void 0&&this.toAncestorGeometry!==void 0){let e=new W(this.canvas,this.ancestorId,this.toAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(e)}return!0}undo(){let e=this.canvas.model.nodes.get(this.id),t=new G(this.canvas,[this.id],[],[],[],[],!0,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(t),this.ancestorId!==void 0&&this.fromAncestorGeometry!==void 0){let e=new W(this.canvas,this.ancestorId,this.fromAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(e)}return e!==void 0}redo(){let e=this.canvas.model.nodes.get(this.id),t=new G(this.canvas,[this.id],[],[],[],[],!1,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(t),this.ancestorId!==void 0&&this.toAncestorGeometry!==void 0){let e=new W(this.canvas,this.ancestorId,this.toAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(e)}return e===void 0}},bt=class{constructor(e,t,n){this.canvas=e,this.nodeIds=t,this.delta=n}do(){let e=new ut(this.canvas,this.nodeIds,this.delta,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),this.nodeIds.map(e=>this.canvas.model.nodes.get(e)!==void 0).includes(!0)&&(this.delta[0]!==0||this.delta[1]!==0)}undo(){let e=new ut(this.canvas,this.nodeIds,[-this.delta[0],-this.delta[1]],this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),this.nodeIds.map(e=>this.canvas.model.nodes.get(e)!==void 0).includes(!0)&&(this.delta[0]!==0||this.delta[1]!==0)}redo(){return this.do()}},q=class{constructor(e,t,n,r,i,a,o,s){this.canvas=e,this.intent=t,this.nodeId=n,this.from=r,this.to=i,this.ancestorId=a,this.fromAncestorGeometry=o,this.toAncestorGeometry=s}do(){let e=this.canvas.model.nodes.get(this.nodeId);if(e){let e=new W(this.canvas,this.nodeId,this.to,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(e),this.ancestorId!==void 0&&this.toAncestorGeometry!==void 0){let e=new W(this.canvas,this.ancestorId,this.toAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(e)}}return e!==void 0}undo(){let e=this.canvas.model.nodes.get(this.nodeId);if(e){this.to=e.getGeometry();let t=new W(this.canvas,this.nodeId,this.from,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(t),this.ancestorId!==void 0&&this.fromAncestorGeometry!==void 0){let e=new W(this.canvas,this.ancestorId,this.fromAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(e)}}return e!==void 0}redo(){let e=this.canvas.model.nodes.get(this.nodeId);if(e){this.from=e.getGeometry();let t=new W(this.canvas,this.nodeId,this.to,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(t)}return e!==void 0}},xt=class{constructor(e,t,n,r,i,a,o,s,c){this.canvas=e,this.childId=t,this.fromParentId=n,this.toParentId=r,this.fromChildGeometry=i,this.toChildGeometry=a,this.ancestorId=o,this.fromAncestorGeometry=s,this.toAncestorGeometry=c}do(){let e=this.canvas.model.nodes.get(this.childId),t=new dt(this.canvas,this.childId,this.toParentId,this.toChildGeometry,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(t),this.ancestorId!==void 0&&this.toAncestorGeometry!==void 0){let e=new W(this.canvas,this.ancestorId,this.toAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(e)}return e!==void 0}undo(){let e=this.canvas.model.nodes.get(this.childId),t=new dt(this.canvas,this.childId,this.fromParentId,this.fromChildGeometry,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(t),this.ancestorId!==void 0&&this.fromAncestorGeometry!==void 0){let e=new W(this.canvas,this.ancestorId,this.fromAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(e)}return e!==void 0}redo(){return this.do()}},St=class{constructor(e,t,n,r){this.canvas=e,this.type=t,this.startId=n,this.endId=r,this.id=this.canvas.collabEngine.freshId()}do(){let e=new ft(this.canvas,this.id,this.type.id,this.startId,this.endId);return this.canvas.collabEngine.doCollaboratively(e),!0}undo(){let e=this.canvas.model.connections.get(this.id),t=new G(this.canvas,[],[],[],[this.id],[],!0,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(t),e!==void 0}redo(){let e=this.canvas.model.connections.get(this.id),t=new G(this.canvas,[],[],[],[this.id],[],!1,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(t),e===void 0}},Ct=class{constructor(e,t,n,r){this.canvas=e,this.fieldId=t,this.from=n,this.to=r}do(){let e=this.canvas.model.fields.get(this.fieldId),t=new pt(this.canvas,this.fieldId,this.to,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(t),e!==void 0}undo(){let e=this.canvas.model.fields.get(this.fieldId);if(e){this.to=e.text;let t=new pt(this.canvas,this.fieldId,this.from,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(t)}return e!==void 0}redo(){let e=this.canvas.model.fields.get(this.fieldId);if(e){this.from=e.text;let t=new pt(this.canvas,this.fieldId,this.to,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(t)}return e!==void 0}},wt=class{constructor(e,t,n,r){this.canvas=e,this.id=t,this.from=n,this.to=r}do(){let e=new mt(this.canvas,this.id,this.to,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),!0}undo(){let e=new mt(this.canvas,this.id,this.from,this.canvas.collabEngine.freshTimestamp()),t=e.getValueSet();if(t)this.to=t.getValuesForKeys(this.to),this.canvas.collabEngine.doCollaboratively(e);else return!1;return!t.rootElement.removed}redo(){let e=new mt(this.canvas,this.id,this.to,this.canvas.collabEngine.freshTimestamp()),t=e.getValueSet();if(t)this.from=t.getValuesForKeys(this.from),this.canvas.collabEngine.doCollaboratively(e);else return!1;return!t.rootElement.removed}},Tt=class{constructor(e,t,n,r,i,a){this.canvas=e,this.nodeIds=t,this.sectionIds=n,this.portIds=r,this.connectionIds=i,this.fieldIds=a}do(){let e=this.nodeIds.map(e=>this.canvas.model.nodes.get(e)!==void 0).includes(!0)||this.sectionIds.map(e=>this.canvas.model.sections.get(e)!==void 0).includes(!0)||this.portIds.map(e=>this.canvas.model.ports.get(e)!==void 0).includes(!0)||this.connectionIds.map(e=>this.canvas.model.connections.get(e)!==void 0).includes(!0)||this.fieldIds.map(e=>this.canvas.model.fields.get(e)!==void 0).includes(!0),t=new G(this.canvas,this.nodeIds,this.sectionIds,this.portIds,this.connectionIds,this.fieldIds,!0,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(t),e}undo(){let e=this.nodeIds.map(e=>this.canvas.model.nodes.get(e)===void 0).includes(!0)||this.sectionIds.map(e=>this.canvas.model.sections.get(e)===void 0).includes(!0)||this.portIds.map(e=>this.canvas.model.ports.get(e)===void 0).includes(!0)||this.connectionIds.map(e=>this.canvas.model.connections.get(e)===void 0).includes(!0)||this.fieldIds.map(e=>this.canvas.model.fields.get(e)===void 0).includes(!0),t=new G(this.canvas,this.nodeIds,this.sectionIds,this.portIds,this.connectionIds,this.fieldIds,!1,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(t),e}redo(){return this.do()}},Et=class{constructor(e,t,n,r){this.canvas=e,this.nodes=t,this.connections=n,this.coords=r}do(){let e=[1/0,1/0];for(let t of this.nodes)t.coords[0]<e[0]&&(e[0]=t.coords[0]),t.coords[1]<e[1]&&(e[1]=t.coords[1]);let t=this.coords===void 0?void 0:[this.coords[0]-e[0],this.coords[1]-e[1]],n={};for(let e of this.nodes){let r=e.id,i=this.canvas.collabEngine.freshId();if(n[r]=i,e.id=i,t&&(e.coords=[e.coords[0]+t[0],e.coords[1]+t[1]]),e.sections)for(let r of e.sections){let a=r.id;if(r.id.includes(e.id)?r.id=r.id.replace(e.id,i):r.id=this.canvas.collabEngine.freshId(),n[a]=r.id,t&&(r.coords=[r.coords[0]+t[0],r.coords[1]+t[1]]),r.ports)for(let a of r.ports){let r=a.id;a.id.includes(e.id)?a.id=a.id.replace(e.id,i):a.id=this.canvas.collabEngine.freshId(),n[r]=a.id,t&&(a.coords=[a.coords[0]+t[0],a.coords[1]+t[1]],a.connectionPoint&&=[a.connectionPoint[0]+t[0],a.connectionPoint[1]+t[1]])}}if(e.ports)for(let r of e.ports){let a=r.id;r.id.includes(e.id)?r.id=r.id.replace(e.id,i):r.id=this.canvas.collabEngine.freshId(),n[a]=r.id,t&&(r.coords=[r.coords[0]+t[0],r.coords[1]+t[1]],r.connectionPoint&&=[r.connectionPoint[0]+t[0],r.connectionPoint[1]+t[1]])}}for(let e of this.connections){let r=this.canvas.collabEngine.freshId();if(n[e.id]=r,e.id=r,e.start=n[e.start]||e.start,e.end=n[e.end]||e.end,t)for(let n=0;n<e.points.length;++n)e.points[n]=[e.points[n][0]+t[0],e.points[n][1]+t[1]]}let r=new ht(this.canvas,this.nodes,this.connections);return this.canvas.collabEngine.doCollaboratively(r),!0}undo(){let e=this.nodes.map(e=>this.canvas.model.nodes.get(e.id)!==void 0).includes(!0)||this.connections.map(e=>this.canvas.model.connections.get(e.id)!==void 0).includes(!0),t=new G(this.canvas,this.nodes.map(e=>e.id),[],[],this.connections.map(e=>e.id),[],!0,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(t),e}redo(){let e=this.nodes.map(e=>this.canvas.model.nodes.get(e.id)===void 0).includes(!0)||this.connections.map(e=>this.canvas.model.connections.get(e.id)===void 0).includes(!0),t=new G(this.canvas,this.nodes.map(e=>e.id),[],[],this.connections.map(e=>e.id),[],!1,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(t),e}},Dt=class{constructor(e){this.type=e,this.defaultPrevented=!1}preventDefault(){this.defaultPrevented=!0}},Ot=function(e){return e[e.Zoom=0]=`Zoom`,e[e.DoubleClick=1]=`DoubleClick`,e[e.SecondaryClick=2]=`SecondaryClick`,e[e.Selection=3]=`Selection`,e[e.Highlight=4]=`Highlight`,e[e.DraggingNode=5]=`DraggingNode`,e}({}),kt=class extends Dt{constructor(e,t){super(Ot.Zoom),this.coords=e,this.zoom=t}},At=class extends Dt{constructor(e,t,n){super(Ot.DoubleClick),this.cause=e,this.target=t,this.coords=n}},jt=class extends Dt{constructor(e,t,n){super(Ot.SecondaryClick),this.cause=e,this.target=t,this.coords=n}},J=class extends Dt{constructor(e,t){super(Ot.Selection),this.targets=e,this.selected=t}},Y=class extends Dt{constructor(e){super(Ot.Highlight),this.target=e}},Mt=class extends Dt{constructor(e){super(Ot.DraggingNode),this.target=e}},Nt=class extends Ee{constructor(e,t,n,r,i,a,o,s,c=`floating`,l=`floating`){if(e.objects.get(s)!==void 0)throw Error(`DiagramDecorator with id "${s}" already exists`);if(!s)throw Error(`DiagramDecorator cannot have an empty or null id`);super(e,s),this.rootElement=t,this.coords=n,this.width=r,this.height=i,this.priority=a,this.html=o,this.anchorPointX=c,this.anchorPointY=l}get removed(){return this.selfRemoved||this.rootElement!==void 0&&this.rootElement.removed}updateInView(){this.model.canvas?.updateDecoratorsInView(this.id)}raise(){this.select()?.raise()}move(e){this.coords=e,this.updateInView()}getPriority(){return this.priority}},Pt=class extends j{constructor(e){super(),this.model=e}new(e,t,n,r,i,a,o,s=`floating`,c=`floating`){let l=new Nt(this.model,e,t,n,r,i,a,o,s,c);return super.add(l),l.updateInView(),e!==void 0&&e.decorators.push(l),l}remove(e){let t=this.get(e,!0);t&&((t.rootElement instanceof U||t.rootElement instanceof V)&&E(t.rootElement.decorators,t),super.remove(e),t.updateInView())}},Ft=class extends Ee{constructor(e,t,n,r,i,a,o){if(e.objects.get(o)!==void 0)throw Error(`DiagramObject with id "${o}" already exists`);if(!o)throw Error(`DiagramObject cannot have an empty or null id`);super(e,o),this.coords=t,this.width=n,this.height=r,this.priority=i,this.html=a}get removed(){return this.selfRemoved}updateInView(){this.model.canvas?.updateObjectsInView(this.id)}raise(){this.select()?.raise()}move(e){this.coords=e,this.updateInView()}getPriority(){return this.priority}},It=class extends j{constructor(e){super(),this.model=e}new(e,t,n,r,i,a){let o=new Ft(this.model,e,t,n,r,i,a);return super.add(o),o.updateInView(),o}remove(e){let t=this.get(e,!0);t&&(super.remove(e),t.updateInView())}},Lt=class{constructor(e,t,n,r,i,a=[]){this.nodes=new Je(this),this.sections=new Ge(this),this.ports=new at(this),this.connections=new Ie(this),this.fields=new Le(this),this.objects=new It(this),this.decorators=new Pt(this),this.canvas=e,this.id=t,this.name=n,this.description=r,this.type=i,this.createdAt=new Date,this.updatedAt=new Date,this.logicalClock=0,this.valueSet=new Pe(new Oe(a),this)}clear(){this.canvas?.cancelAllUserActions(),this.id=void 0,this.name=``,this.description=void 0,this.createdAt=new Date,this.updatedAt=new Date,this.logicalClock=0,this.nodes.clear(),this.sections.clear(),this.ports.clear(),this.connections.clear(),this.fields.clear(),this.objects.clear(),this.decorators.clear(),this.valueSet.resetValues(),this.canvas?.updateModelInView()}},X=e=>!!e.button,Rt=(e,t,n,r,i,a,o,s,c)=>ie(e,[t,...a,n],r,i,Math.max(10,s||0,c||0)*o),Z=e=>{e?c.select(`body`).style(`cursor`,e):c.select(`body`).style(`cursor`,O.Auto)},Q=e=>e instanceof U?e:e instanceof V?e.node||e:e.rootElement instanceof U||e.rootElement instanceof V||e.rootElement instanceof it?Q(e.rootElement):e,zt=e=>{if(e instanceof U)return e.type.resizableX!==!1;if(e instanceof V){if(e.type!==void 0)return e.type.resizableX!==!1;if(e.node!==void 0)return zt(e.node)}return!1},Bt=e=>{if(e instanceof U)return e.type.resizableY!==!1;if(e instanceof V){if(e.type!==void 0)return e.type.resizableY!==!1;if(e.node!==void 0)return Bt(e.node)}return!1},Vt=e=>{e.filter(`.shaped-look`).append(`path`),e.filter(`.image-look`).append(`image`).attr(`preserveAspectRatio`,`none`),e.filter(`.stretchable-image-look`).append(`image`).attr(`class`,`top-left-image`).attr(`preserveAspectRatio`,`none`),e.filter(`.stretchable-image-look`).append(`image`).attr(`class`,`top-image`).attr(`preserveAspectRatio`,`none`),e.filter(`.stretchable-image-look`).append(`image`).attr(`class`,`top-right-image`).attr(`preserveAspectRatio`,`none`),e.filter(`.stretchable-image-look`).append(`image`).attr(`class`,`left-image`).attr(`preserveAspectRatio`,`none`),e.filter(`.stretchable-image-look`).append(`image`).attr(`class`,`center-image`).attr(`preserveAspectRatio`,`none`),e.filter(`.stretchable-image-look`).append(`image`).attr(`class`,`right-image`).attr(`preserveAspectRatio`,`none`),e.filter(`.stretchable-image-look`).append(`image`).attr(`class`,`bottom-left-image`).attr(`preserveAspectRatio`,`none`),e.filter(`.stretchable-image-look`).append(`image`).attr(`class`,`bottom-image`).attr(`preserveAspectRatio`,`none`),e.filter(`.stretchable-image-look`).append(`image`).attr(`class`,`bottom-right-image`).attr(`preserveAspectRatio`,`none`)},Ht={fillColor:`#FFFFFF`,borderColor:`#000000`,borderThickness:1,borderStyle:ne.Solid},Ut=e=>{e.filter(`.shaped-look`).select(`path`).attr(`d`,e=>oe(e.look.shape||D.Rectangle,0,0,e.width,e.height)).attr(`fill`,e=>e.look.fillColor||Ht.fillColor).attr(`stroke`,e=>e.look.borderColor||Ht.borderColor).attr(`stroke-width`,e=>`${e.look.borderThickness||Ht.borderThickness}px`).attr(`stroke-dasharray`,e=>ae(e.look.borderStyle||Ht.borderStyle,e.type?.defaultLook?.borderThickness||e.look?.borderThickness||Ht.borderThickness)),e.filter(`.image-look`).select(`image`).attr(`x`,0).attr(`y`,0).attr(`width`,e=>e.width).attr(`height`,e=>e.height).attr(`href`,e=>e.look.backgroundImage),e.filter(`.stretchable-image-look`).select(`image.top-left-image`).attr(`x`,0).attr(`y`,0).attr(`width`,e=>e.look.leftMargin).attr(`height`,e=>e.look.topMargin).attr(`href`,e=>e.look.backgroundImageTopLeft),e.filter(`.stretchable-image-look`).select(`image.top-image`).attr(`x`,e=>e.look.leftMargin).attr(`y`,0).attr(`width`,e=>e.width-e.look.rightMargin-e.look.leftMargin).attr(`height`,e=>e.look.topMargin).attr(`href`,e=>e.look.backgroundImageTop),e.filter(`.stretchable-image-look`).select(`image.top-right-image`).attr(`x`,e=>e.width-e.look.rightMargin).attr(`y`,0).attr(`width`,e=>e.look.rightMargin).attr(`height`,e=>e.look.topMargin).attr(`href`,e=>e.look.backgroundImageTopRight),e.filter(`.stretchable-image-look`).select(`image.left-image`).attr(`x`,0).attr(`y`,e=>e.look.topMargin).attr(`width`,e=>e.look.leftMargin).attr(`height`,e=>e.height-e.look.bottomMargin-e.look.topMargin).attr(`href`,e=>e.look.backgroundImageLeft),e.filter(`.stretchable-image-look`).select(`image.center-image`).attr(`x`,e=>e.look.leftMargin).attr(`y`,e=>e.look.topMargin).attr(`width`,e=>e.width-e.look.rightMargin-e.look.leftMargin).attr(`height`,e=>e.height-e.look.bottomMargin-e.look.topMargin).attr(`href`,e=>e.look.backgroundImageCenter),e.filter(`.stretchable-image-look`).select(`image.right-image`).attr(`x`,e=>e.width-e.look.rightMargin).attr(`y`,e=>e.look.topMargin).attr(`width`,e=>e.look.rightMargin).attr(`height`,e=>e.height-e.look.bottomMargin-e.look.topMargin).attr(`href`,e=>e.look.backgroundImageRight),e.filter(`.stretchable-image-look`).select(`image.bottom-left-image`).attr(`x`,0).attr(`y`,e=>e.height-e.look.bottomMargin).attr(`width`,e=>e.look.leftMargin).attr(`height`,e=>e.look.bottomMargin).attr(`href`,e=>e.look.backgroundImageBottomLeft),e.filter(`.stretchable-image-look`).select(`image.bottom-image`).attr(`x`,e=>e.look.leftMargin).attr(`y`,e=>e.height-e.look.bottomMargin).attr(`width`,e=>e.width-e.look.rightMargin-e.look.leftMargin).attr(`height`,e=>e.look.bottomMargin).attr(`href`,e=>e.look.backgroundImageBottom),e.filter(`.stretchable-image-look`).select(`image.bottom-right-image`).attr(`x`,e=>e.width-e.look.rightMargin).attr(`y`,e=>e.height-e.look.bottomMargin).attr(`width`,e=>e.look.rightMargin).attr(`height`,e=>e.look.bottomMargin).attr(`href`,e=>e.look.backgroundImageBottomRight)},Wt={enabled:!0,style:`dots`,color:`rgba(0, 0, 0, 0.1)`,snap:!1,spacing:10,thickness:.05},Gt=(e,t,n)=>{let r=t.append(`defs`);if(e.gridSize>0&&isFinite(e.gridSize)){let i=r.append(`pattern`).attr(`id`,n).attr(`x`,-e.gridSize/2).attr(`y`,-e.gridSize/2).attr(`width`,e.gridSize).attr(`height`,e.gridSize).attr(`patternUnits`,`userSpaceOnUse`);switch(i.append(`rect`).attr(`x`,0).attr(`y`,0).attr(`width`,e.gridSize).attr(`height`,e.gridSize).attr(`fill`,e.backgroundColor),e.gridStyle){case`dots`:i.append(`circle`).attr(`cx`,e.gridSize/2).attr(`cy`,e.gridSize/2).attr(`r`,e.gridSize*e.gridThickness).attr(`fill`,e.gridColor);break;case`lines`:i.append(`line`).attr(`x1`,e.gridSize/2).attr(`x2`,e.gridSize/2).attr(`y1`,0).attr(`y2`,e.gridSize).attr(`stroke-width`,e.gridSize*e.gridThickness).attr(`stroke`,e.gridColor),i.append(`line`).attr(`x1`,0).attr(`x2`,(e.gridSize-e.gridSize*e.gridThickness)/2).attr(`y1`,e.gridSize/2).attr(`y2`,e.gridSize/2).attr(`stroke-width`,e.gridSize*e.gridThickness).attr(`stroke`,e.gridColor),i.append(`line`).attr(`x1`,(e.gridSize+e.gridSize*e.gridThickness)/2).attr(`x2`,e.gridSize).attr(`y1`,e.gridSize/2).attr(`y2`,e.gridSize/2).attr(`stroke-width`,e.gridSize*e.gridThickness).attr(`stroke`,e.gridColor);break}t.select(`rect`).attr(`fill`,`url(#${n})`)}},Kt=96,$=32,qt=Kt+$,Jt=Math.PI/4,Yt=100,Xt={customButtons:[]},Zt=class{constructor(e,t){this.canvas=e,this.config=t||Xt}open(e){this.close();let t=this.canvas.getPointerLocationRelativeToRoot(e),n=this.canvas.getPointerLocationRelativeToCanvas(e),r=this.canvas.selectSVGElement().append(`foreignObject`).attr(`class`,`daga-context-menu`).attr(`x`,`${t[0]-qt}px`).attr(`y`,`${t[1]-qt}px`).attr(`width`,`${2*qt}px`).attr(`height`,`${2*qt}px`).style(`pointer-events`,`none`).on(x.ContextMenu,t=>{this.canvas.canUserPerformAction(K.ContextMenu)&&(e.preventDefault(),this.open(t))}).on(x.Click,e=>{e.preventDefault(),this.close()});this.contextMenuContainer=r;let i=[];this.canvas.userSelection.length!==0&&this.canvas.canUserPerformAction(K.Clipboard)&&this.canvas.canUserPerformAction(K.Remove)&&i.push({name:`CUT`,imageClass:`daga-cut`,onPress:e=>{e.userSelection.cutToClipboard(),e.cancelAllUserActions()}}),this.canvas.userSelection.length!==0&&this.canvas.canUserPerformAction(K.Clipboard)&&i.push({name:`COPY`,imageClass:`daga-copy`,onPress:e=>{e.userSelection.copyToClipboard(),e.cancelAllUserActions()}}),this.canvas.canUserPerformAction(K.Paste)&&i.push({name:`PASTE`,imageClass:`daga-paste`,onPress:e=>{e.userSelection.pasteFromClipboard(e.getClosestGridPoint(n)),e.cancelAllUserActions()}}),this.canvas.userSelection.length!==0&&this.canvas.canUserPerformAction(K.Remove)&&i.push({name:`DELETE`,imageClass:`daga-delete`,onPress:e=>{e.userSelection.removeFromModel(),e.cancelAllUserActions()}});for(let e of this.config.customButtons||Xt.customButtons)(e.condition===void 0||e.condition(this.canvas))&&i.push(e);i.length===0&&i.push({name:`NONE`,imageClass:`daga-cross`,onPress:void 0});for(let e=0;e<i.length;++e){let t=i[e],n=t.onPress,a=(e+.5-i.length/2)*Jt,o=r.append(`xhtml:div`).attr(`class`,`daga-context-menu-button ${t.onPress===void 0?``:` daga-clickable`}`).attr(`tabindex`,0).style(`position`,`absolute`).style(`box-sizing`,`border-box`).style(`width`,`${2*$}px`).style(`height`,`${2*$}px`).style(`border-radius`,`${$}px`).style(`pointer-events`,`auto`).on(x.Click,e=>{n&&(e.preventDefault(),n(this.canvas))}).on(x.KeyDown,e=>{n&&e.key===S.Enter&&(e.preventDefault(),n(this.canvas))});t.imageClass===void 0?t.image!==void 0&&o.append(`xhtml:img`).style(`position`,`absolute`).style(`left`,`${.75*$}px`).style(`top`,`${.5*$}px`).style(`width`,`${.5*$}px`).style(`height`,`${.5*$}px`).attr(`src`,t.image):o.append(`xhtml:div`).style(`position`,`absolute`).style(`left`,`${.75*$}px`).style(`top`,`${.5*$}px`).style(`width`,`${.5*$}px`).style(`height`,`${.5*$}px`).style(`background-size`,`contain`).style(`background-repeat`,`no-repeat`).attr(`class`,t.imageClass),o.append(`xhtml:span`).style(`position`,`absolute`).style(`left`,`${.2*$}px`).style(`top`,`${1.1*$}px`).style(`text-align`,`center`).style(`width`,`${1.6*$}px`).style(`height`,`${.35*$}px`).style(`margin`,`0`).style(`font-size`,`${.35*$}px`).style(`font-weight`,`700`).style(`user-select`,`none`).text(t.name),o.transition().ease(c.easeLinear).duration(Yt).tween(`progress`,()=>e=>{let t=a*e;return o.style(`left`,`${Math.sin(t)*Kt-$+qt}px`).style(`top`,`${-Math.cos(t)*Kt-$+qt}px`)})}}close(){this.contextMenuContainer?.remove(),this.contextMenuContainer=void 0}},Qt=class extends j{constructor(e,t=!0){super(),this.focus=void 0,this.canvas=e,this.highlightSections=t}getFocus(){return this.focus}focusOn(e){this.clear(),this.focus=e,(e instanceof I||e instanceof Nt)&&e.rootElement?this.focusOn(e.rootElement):this.add(e)}add(e){if(super.add(e),e instanceof U){if(!this.highlightSections)for(let t of e.sections){super.add(t);for(let e of t.ports)super.add(e),this.canvas.updatePortsInView(e.id);t.label&&(super.add(t.label),this.canvas.updateFieldsInView(t.label.id)),this.canvas.updateSectionsInView(t.id)}for(let t of e.ports)super.add(t),this.canvas.updatePortsInView(t.id);e.label&&(super.add(e.label),this.canvas.updateFieldsInView(e.label.id)),this.canvas.updateNodesInView(e.id)}else if(e instanceof V)if(!this.highlightSections&&e.node)this.add(e.node);else{for(let t of e.ports)super.add(t),this.canvas.updatePortsInView(t.id);e.label&&(super.add(e.label),this.canvas.updateFieldsInView(e.label.id)),this.canvas.updateSectionsInView(e.id)}else e instanceof it?(e.label&&(super.add(e.label),this.canvas.updateFieldsInView(e.label.id)),this.canvas.updatePortsInView(e.id)):e instanceof P&&this.canvas.updateConnectionsInView(e.id)}clear(){for(;this.entities.length>0;){let e=this.entities[0];this.remove(e.id),e.updateInView()}this.focus=void 0}},$t=class{export(e,t=!1){let n={name:e.name,type:e.type,typeVersion:1,createdAt:e.createdAt,updatedAt:e.updatedAt,nodes:[],connections:[],data:e.valueSet.getValues(),...t?{collabMeta:{logicalClock:e.logicalClock,dataTimestamps:e.valueSet.getTimestamps()}}:{}};e.id&&(n.id=e.id),e.description&&(n.description=e.description);for(let r of e.nodes.all(!0))!t&&r.removed||r.parent===void 0&&n.nodes.push(this.exportNode(r,t));for(let r of e.connections.all(!0))!t&&r.removed||n.connections.push(this.exportConnection(r,t));return n}exportNode(e,t=!1){let n=[];for(let r of e.children)n.push(this.exportNode(r,t));let r=[];for(let n of e.sections){let e=[];for(let r of n.ports)e.push({id:r.id,type:r.type?.id,coords:g(r.coords),connectionPoint:g(r.connectionPoint||r.coords),direction:r.direction,label:r.label?.text||``,...t?{collabMeta:{removed:r.removed,selfRemoved:r.selfRemoved,selfRemovedTimestamp:r.selfRemovedTimestamp,...this.exportLabelCollabMeta(r)}}:{}});r.push({id:n.id,ports:e,label:n.label?.text||``,indexXInNode:n.indexXInNode,indexYInNode:n.indexYInNode,coords:g(n.coords),width:n.width,height:n.height,...t?{collabMeta:{removed:n.removed,selfRemoved:n.selfRemoved,selfRemovedTimestamp:n.selfRemovedTimestamp,...this.exportLabelCollabMeta(n)}}:{}})}let i=[];for(let n of e.ports)i.push({id:n.id,type:n.type?.id,coords:g(n.coords),connectionPoint:g(n.connectionPoint||n.coords),direction:n.direction,label:n.label?.text||``,...t?{collabMeta:{removed:n.removed,selfRemoved:n.selfRemoved,selfRemovedTimestamp:n.selfRemovedTimestamp,...this.exportLabelCollabMeta(n)}}:{}});return{id:e.id,type:e.type.id,children:n,sections:r,ports:i,label:e.label?.text||``,coords:g(e.coords),width:e.width,height:e.height,data:e.valueSet.getValues(),...t?{collabMeta:{removed:e.removed,selfRemoved:e.selfRemoved,selfRemovedTimestamp:e.selfRemovedTimestamp,geometryTimestamp:e.geometryTimestamp,dataTimestamps:e.valueSet.getTimestamps(),...this.exportLabelCollabMeta(e)}}:{}}}exportConnection(e,t=!1){return{id:e.id,type:e.type.id,start:e.start?.id||``,end:e.end?.id||``,startLabel:e.startLabel,middleLabel:e.middleLabel,endLabel:e.endLabel,points:e.points,data:e.valueSet.getValues(),...t?{collabMeta:{removed:e.removed,selfRemoved:e.selfRemoved,selfRemovedTimestamp:e.selfRemovedTimestamp,dataTimestamps:e.valueSet.getTimestamps()}}:{}}}exportLabelCollabMeta({label:e}){return e?{label:{removed:e.removed,selfRemoved:e.selfRemoved,selfRemovedTimestamp:e.selfRemovedTimestamp,textTimestamp:e.textTimestamp}}:{}}},en=`Diagram properties`,tn=class extends j{constructor(e,t){super(),this.canvas=e,this.canvas.propertyEditorChanges$.pipe((0,l.debounceTime)(2e3)).subscribe(()=>{this.makeUpdateValuesAction()}),this.diagramPropertiesText=t===void 0?en:t}add(e){if(!this.contains(e.id)&&(this.length===0?this.propertyEditorSelection===void 0&&(e instanceof U||e instanceof P)?this.openInPropertyEditor(e):this.propertyEditorSelection===void 0&&e instanceof V?this.openInPropertyEditor(e.node):this.openInPropertyEditor(void 0):this.openInPropertyEditor(void 0),super.add(e),e.updateInView(),e instanceof U&&e.sections))for(let t of e.sections)super.add(t),t.updateInView()}remove(e){let t=this.get(e);if(t&&(this.propertyEditorSelection===t&&this.openInPropertyEditor(void 0),super.remove(e),t.updateInView(),t instanceof U&&t.sections))for(let e of t.sections)super.remove(e.id),e.updateInView()}toggle(e){this.contains(e.id)?this.remove(e.id):this.add(e)}clear(){for(this.openInPropertyEditor(void 0);this.entities.length>0;){let e=this.entities[0];super.remove(e.id),e.updateInView()}}move(e){for(let t of this.all())t instanceof U&&t.move([t.coords[0]+e[0],t.coords[1]+e[1]])}removeFromModel(){if(this.length>0){let e=[],t=[],n=[],r=[],i=[];for(let a of this.all())a instanceof U?e.push(a.id):a instanceof V?t.push(a.id):a instanceof it?n.push(a.id):a instanceof P?r.push(a.id):a instanceof I&&i.push(a.id);let a=new Tt(this.canvas,e,t,n,r,i);a.do(),this.canvas.actionStack.add(a)}}copyToClipboard(){let e={type:`daga-user-selection`,nodes:[],connections:[]},t=new $t;for(let n of this.all())n instanceof U&&e.nodes.push(t.exportNode(n,!1)),n instanceof P&&e.connections.push(t.exportConnection(n,!1));navigator.clipboard.writeText(JSON.stringify(e))}cutToClipboard(){this.copyToClipboard(),this.removeFromModel()}pasteFromClipboard(e){navigator.clipboard.readText().then(t=>{try{let n=JSON.parse(t);if(n.type!==`daga-user-selection`)return;let r=new Et(this.canvas,n.nodes,n.connections,e);this.canvas.actionStack.add(r),r.do()}catch{return}})}openInPropertyEditor(e,t=!0){t&&this.makeUpdateValuesAction();let n=this.canvas.parentComponent?.propertyEditor;if(n===void 0)return;let r=e?.valueSet;r?(this.propertyEditorSelection=e,t&&(this.propertyEditorValues=we(r.getValues())),n&&(e instanceof U||e instanceof P?(e instanceof U?e.name?n.title=`${e.type.name}: ${e.name}`:n.title=e.type.name:e instanceof P&&(n.title=e.type.name),n.valueSet=void 0,n.valueSet=r):(n.title=this.diagramPropertiesText,n.valueSet=void 0,n.valueSet=r))):(this.propertyEditorSelection=void 0,this.propertyEditorValues=void 0,n&&(n.title=``,n.valueSet=void 0))}makeUpdateValuesAction(){if(this.propertyEditorSelection===void 0||this.propertyEditorValues===void 0)return;let e=this.propertyEditorSelection instanceof Lt?void 0:this.propertyEditorSelection.id;if(je(this.propertyEditorValues,this.propertyEditorSelection?.valueSet.getValues()))return;let t=this.propertyEditorValues,n=we(this.propertyEditorSelection?.valueSet.getValues()),[r,i]=Me(t,n,this.propertyEditorSelection?.valueSet),a=new wt(this.canvas,e,r,i);a.do(),this.canvas.actionStack.add(a),this.propertyEditorValues=n}},nn=`diagram-connection-unfinished`,rn=class e{static{this.canvasCount=0}get connectionType(){return this._connectionType}set connectionType(e){this._connectionType=e,this.parentComponent?.palette?.refreshPalette()}constructor(t,n){if(this.backgroundPatternId=`daga-background-pattern-id-${e.canvasCount++}`,this.zoomTransform=c.zoomIdentity,this.draggingFrom=[0,0],this.dragging=!1,this.secondaryButton=!1,this.validatorChange$=new l.Subject,this.diagramChange$=new l.Subject,this.diagramEvent$=new l.Subject,this.propertyEditorChanges$=new l.Subject,this.parentComponent=t,this.model=new Lt(this,void 0,n.name||`unnamed`,``,n.type||``,n.properties||[]),this.userSelection=new tn(this,n.components?.propertyEditor?.title),this.userHighlight=new Qt(this,n.canvas?.highlightSections!==!1),this.contextMenu=new Zt(this,n.canvas?.contextMenu),this.backgroundColor=n.canvas?.backgroundColor||`#FFFFFF`,this.gridStyle=n.canvas?.grid?.style??Wt.style,this.gridSize=n.canvas?.grid?.enabled===!1||n.canvas?.grid===void 0?0:Math.abs(n.canvas?.grid?.spacing||Wt.spacing),this.gridThickness=Math.abs(n.canvas?.grid?.thickness||Wt.thickness),this.gridColor=n.canvas?.grid?.color||Wt.color,this.snapToGrid=n.canvas?.grid?.enabled===!1||n.canvas?.grid===void 0?!1:n.canvas?.grid?.snap||Wt.snap,this.zoomFactor=n.canvas?.zoomFactor||2,this.panRate=n.canvas?.panRate||100,this.inferConnectionType=n.connectionSettings?.inferConnectionType||!1,this.autoTightenConnections=n.connectionSettings?.autoTighten!==!1,this.tightenConnectionsAcrossPortTypes=n.connectionSettings?.tightenAcrossPortTypes||!1,this.allowConnectionLoops=n.connectionSettings?.allowLoops||!1,this.allowSharingPorts=n.connectionSettings?.sharePorts!==!1,this.allowSharingBothPorts=n.connectionSettings?.shareBothPorts||!1,this.portHighlightRadius=n.connectionSettings?.portHighlightRadius||100,this.multipleSelectionOn=!1,this.priorityThresholds=n.canvas?.priorityThresholds||[],this.priorityThreshold=this.priorityThresholds?this.priorityThresholds[0]:void 0,this.layoutFormat=n.layoutFormat,this.userActions=n.userActions||{},this.validators=[],this.actionStack=new _t(this,25),this.collabEngine=new gt(this),n.nodeTypes)for(let e of n.nodeTypes){let t=new qe({...n.nodeTypeDefaults,...e});this.model.nodes.types.add(t)}if(n.portTypes)for(let e of n.portTypes){let t=new rt({...n.portTypeDefaults,...e});this.model.ports.types.add(t)}if(n.connectionTypes){for(let e of n.connectionTypes){let t=new Fe({...n.connectionTypeDefaults,...e});this.model.connections.types.add(t)}this._connectionType=n?.connectionSettings?.defaultConnection===void 0?void 0:this.model.connections.types.get(n.connectionSettings.defaultConnection)}}addValidator(e){this.validators.push(e),this.validatorChange$.next()}removeValidator(e){E(this.validators,e),this.validatorChange$.next()}getPriorityThresholdOptions(){return this.priorityThresholds}getPriorityThreshold(){return this.priorityThreshold}setPriorityThreshold(e){this.priorityThreshold=e,this.updateModelInView();for(let e of this.model.nodes)this.fitNodeInView(e.id);this.parentComponent?.palette?.refreshPalette()}initView(e){let t=c.select(e);t.html(``),this.diagramRoot=t.append(`div`).node(),c.select(this.diagramRoot).attr(`tabindex`,0).style(`width`,`100%`).style(`height`,`100%`).append(`svg`).style(`width`,`100%`).style(`height`,`100%`),c.select(this.diagramRoot).on(x.Click,()=>{c.select(this.diagramRoot).node()?.focus()}).on(x.ContextMenu,e=>{if(this.dragging){e.preventDefault(),e.stopPropagation(),this.dragging=!1;return}let t=new jt(e,null);this.diagramEvent$.next(t),!t.defaultPrevented&&this.canUserPerformAction(K.ContextMenu)&&(e.preventDefault(),this.contextMenu.open(e))}).on(x.DoubleClick,e=>{let t=new At(e,null);this.diagramEvent$.next(t)}).on(x.KeyDown,e=>{if(!e.ctrlKey&&(e.key===S.Delete||e.key===S.Backspace)&&this.canUserPerformAction(K.Remove)&&(this.userSelection.removeFromModel(),this.cancelAllUserActions()),e.ctrlKey&&e.key===`a`){e.preventDefault();for(let e of this.model.nodes)this.userSelection.add(e);for(let e of this.model.connections)this.userSelection.add(e);this.diagramEvent$.next(new J(this.userSelection.all(),!0))}if(e.ctrlKey&&e.key===`i`){e.preventDefault();let t=[],n=[];for(let e of this.model.nodes)this.userSelection.toggle(e),e.selected?t.push(e):n.push(e);for(let e of this.model.connections)this.userSelection.toggle(e),e.selected?t.push(e):n.push(e);t.length>0&&this.diagramEvent$.next(new J(t,!0)),n.length>0&&this.diagramEvent$.next(new J(n,!1))}if(e.ctrlKey&&e.key===`c`&&this.canUserPerformAction(K.Clipboard)&&(e.preventDefault(),this.userSelection.copyToClipboard(),this.cancelAllUserActions()),e.ctrlKey&&e.key===`x`&&this.canUserPerformAction(K.Clipboard)&&this.canUserPerformAction(K.Remove)&&(e.preventDefault(),this.userSelection.cutToClipboard(),this.cancelAllUserActions()),e.ctrlKey&&e.key===`v`&&this.canUserPerformAction(K.Paste)){e.preventDefault();let t=this.getCoordinatesOnScreen();this.userSelection.pasteFromClipboard(this.getClosestGridPoint([(t[0][0]+t[1][0])/2,(t[0][1]+t[1][1])/2])),this.cancelAllUserActions()}e.ctrlKey&&e.key===`y`&&(e.preventDefault(),this.actionStack.redo()),e.ctrlKey&&e.key===`z`&&(e.preventDefault(),this.actionStack.undo()),e.key===`+`&&this.canUserPerformAction(K.Zoom)&&(e.preventDefault(),this.zoomBy(this.zoomFactor)),e.key===`-`&&this.canUserPerformAction(K.Zoom)&&(e.preventDefault(),this.zoomBy(1/this.zoomFactor)),e.key===S.ArrowLeft&&this.canUserPerformAction(K.Zoom)&&(e.preventDefault(),this.translateBy(this.panRate/this.zoomTransform.k,0)),e.key===S.ArrowRight&&this.canUserPerformAction(K.Zoom)&&(e.preventDefault(),this.translateBy(-this.panRate/this.zoomTransform.k,0)),e.key===S.ArrowDown&&this.canUserPerformAction(K.Zoom)&&(e.preventDefault(),this.translateBy(0,-this.panRate/this.zoomTransform.k)),e.key===S.ArrowUp&&this.canUserPerformAction(K.Zoom)&&(e.preventDefault(),this.translateBy(0,this.panRate/this.zoomTransform.k))});let n=this.selectSVGElement().append(`g`).attr(`class`,`daga-canvas-view`).attr(`width`,`100%`).attr(`height`,`100%`);n.call(this.zoomBehavior=c.zoom().filter(e=>e.type!==x.DoubleClick).on(w.Zoom,e=>{if(e.sourceEvent){if(!this.canUserPerformAction(K.Zoom)){Z(O.NotAllowed);return}e.sourceEvent.type===x.Wheel&&e.sourceEvent.wheelDelta!==void 0?(e.sourceEvent.wheelDelta>0&&Z(O.ZoomIn),e.sourceEvent.wheelDelta<0&&Z(O.ZoomOut)):e.sourceEvent.type===x.MouseMove&&Z(O.AllScroll)}this.zoomTransform=e.transform;let t=e.transform.toString();this.selectCanvasElements().attr(`transform`,t),c.select(`#${this.backgroundPatternId}`).attr(`patternTransform`,t),this.contextMenu.close(),this.diagramEvent$.next(new kt([this.zoomTransform.x,this.zoomTransform.y],this.zoomTransform.k))}).on(w.End,()=>{Z()})),n.append(`rect`).attr(`x`,0).attr(`y`,0).attr(`width`,`100%`).attr(`height`,`100%`).attr(`fill`,this.backgroundColor).attr(`stroke-width`,`0`).on(x.MouseMove,e=>{if(this.unfinishedConnection!==void 0){let t=this.getPointerLocationRelativeToCanvas(e);this.unfinishedConnection.endCoords=t}}).on(x.MouseOver,()=>{this.userHighlight.size()>0&&(this.userHighlight.clear(),this.diagramEvent$.next(new Y(null)))}).on(x.Click,()=>{if(this.userHighlight.size()>0&&(this.userHighlight.clear(),this.diagramEvent$.next(new Y(null))),this.contextMenu.close(),this.userSelection.size()>0){let e=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new J(e,!1))}this.userSelection.openInPropertyEditor(this.model)}).call(c.drag().filter(e=>this.multipleSelectionOn||X(e)).on(C.Start,e=>{this.startMultipleSelection(e)}).on(C.Drag,e=>{this.continueMultipleSelection(e)}).on(C.End,e=>{this.finishMultipleSelection(e)})),Gt(this,n,this.backgroundPatternId),n.append(`g`).attr(`class`,`daga-canvas-elements`)}getZoomLevel(){return this.zoomTransform.k}zoomBy(e){isNaN(e)||this.zoomBehavior.scaleBy(this.selectCanvasView(),e)}zoomTo(e){isNaN(e)||this.zoomBehavior.scaleTo(this.selectCanvasView(),e)}getViewCoordinates(){let e=this.selectCanvasView()?.select(`rect`)?.node()?.getBBox();return[((e.width+e.x)/2-this.zoomTransform.x)/this.zoomTransform.k,((e.height+e.y)/2-this.zoomTransform.y)/this.zoomTransform.k]}translateBy(e,t){!isNaN(e)&&!isNaN(t)&&this.zoomBehavior.translateBy(this.selectCanvasView(),e,t)}translateTo(e,t){!isNaN(e)&&!isNaN(t)&&this.zoomBehavior.translateTo(this.selectCanvasView(),e,t)}zoomAndPanTo(e,t,n,r){if(!r||r<=0){this.zoomBehavior.scaleTo(this.selectCanvasView(),n),this.zoomBehavior.translateTo(this.selectCanvasView(),e,t);return}this.zoomBehavior.interpolate(c.interpolate);let[i,a]=this.getViewCoordinates(),o=this.getZoomLevel(),s=e,l=t,u=n;this.selectCanvasElements().transition().duration(r).ease(c.easeCubicInOut).tween(`progress`,()=>{let e=!1;return t=>{try{if(!e){let e=t*(s-i)+i,n=t*(l-a)+a,r=t*(u-o)+o;this.zoomBehavior.scaleTo(this.selectCanvasView(),r),this.zoomBehavior.translateTo(this.selectCanvasView(),e,n)}}catch(t){console.warn(`Animation has been interrupted.`,t),e=!0}}})}center(e,t,n){if(this.model.nodes.length>0){let r=this.selectCanvasView().select(`rect`).node()?.getBBox(),i=e?.map(e=>this.model.nodes.get(e)).filter(e=>!!e)||this.model.nodes.all(),a=Math.min(...i.map(e=>e.coords[0])),o=Math.max(...i.map(e=>e.coords[0]+e.width)),s=(a+o)/2,c=o-a,l=r.width,u=Math.min(...i.map(e=>e.coords[1])),d=Math.max(...i.map(e=>e.coords[1]+e.height)),f=(u+d)/2,p=d-u,m=r.height,h=Math.min(l/c,m/p,t===void 0?1:t);this.zoomAndPanTo(s,f,h,n)}}getClosestGridPoint(e){return this.gridSize===0||!isFinite(this.gridSize)?e:[Math.round(e[0]/this.gridSize)*this.gridSize,Math.round(e[1]/this.gridSize)*this.gridSize]}getCoordinatesOnScreen(){let e=this.selectSVGElement().node()?.getBoundingClientRect(),t=[e?.width||0,e?.height||0];return[[-this.zoomTransform.x/this.zoomTransform.k,-this.zoomTransform.y/this.zoomTransform.k],[(t[0]-this.zoomTransform.x)/this.zoomTransform.k,(t[1]-this.zoomTransform.y)/this.zoomTransform.k]]}getEventHoldingCoordinates(e){if(e.type===`drag`||e.type===`start`||e.type===`end`){let t=e.sourceEvent;if(t&&(t.type===`touchmove`||t.type===`touchstart`||t.type===`touchend`))return e.sourceEvent.touches[0]||e.sourceEvent.changedTouches[0]}return e}getPointerLocationRelativeToCanvas(e){return c.pointer(this.getEventHoldingCoordinates(e),this.selectCanvasElements().node())}getPointerLocationRelativeToRoot(e){return c.pointer(this.getEventHoldingCoordinates(e),this.selectSVGElement().node())}getPointerLocationRelativeToBody(e){return c.pointer(this.getEventHoldingCoordinates(e),c.select(`body`).node())}getPointerLocationRelativeToScreen(e){let t=this.getPointerLocationRelativeToBody(e);return[t[0]-window.scrollX,t[1]-window.scrollY]}updateModelInView(){this.updateNodesInView(),this.updateSectionsInView(),this.updatePortsInView(),this.updateConnectionsInView(),this.updateFieldsInView(),this.updateObjectsInView(),this.updateDecoratorsInView()}updateNodesInView(...e){let t=this.selectCanvasElements().selectAll(`g.diagram-node`).data(this.model.nodes.filter(e=>this.priorityThreshold===void 0?!0:e.getPriority()>=this.priorityThreshold),e=>e.id),n=t.exit(),r=t.enter().append(`g`).attr(`id`,e=>e.id).attr(`class`,e=>`diagram-node${zt(e)?` resizable-x`:``}${Bt(e)?` resizable-y`:``} ${e.type.defaultLook.lookType}`);e&&e.length>0&&(t=t.filter(t=>e.includes(t.id)));let i=r.merge(t);n.remove(),r.on(x.MouseOver,(e,t)=>{this.dragging||(this.userHighlight.focusOn(t),this.diagramEvent$.next(new Y(t)))}).on(x.Click,(e,t)=>{if(!e.ctrlKey&&!e.shiftKey){let e=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new J(e,!1))}this.userSelection.toggle(t),this.diagramEvent$.next(new J([t],t.selected))}).on(x.ContextMenu,(e,t)=>{if(this.dragging){e.preventDefault(),e.stopPropagation(),this.dragging=!1;return}let n=new jt(e,t);this.diagramEvent$.next(n),!n.defaultPrevented&&this.canUserPerformAction(K.ContextMenu)&&(e.preventDefault(),this.userHighlight.focusOn(t),this.diagramEvent$.next(new Y(t)),this.userSelection.add(t),this.diagramEvent$.next(new J([t],!0)),this.contextMenu.open(e))}).on(x.DoubleClick,(e,t)=>{let n=new At(e,t);this.diagramEvent$.next(n)}).call(c.drag().filter(e=>(this.secondaryButton=X(e),!0)).on(C.Start,(e,t)=>{this.multipleSelectionOn||this.secondaryButton?this.startMultipleSelection(e):this.startMovingNode(e,t)}).on(C.Drag,(e,t)=>{this.multipleSelectionOn||this.secondaryButton?this.continueMultipleSelection(e):this.continueMovingNode(e,t)}).on(C.End,(e,t)=>{this.multipleSelectionOn||this.secondaryButton?this.finishMultipleSelection(e):this.finishMovingNode(e,t),this.secondaryButton=!1})),Vt(r),r.filter(`.resizable-x`).append(`line`).attr(`class`,`left-resizer`).attr(`stroke`,`transparent`).attr(`stroke-width`,6).on(x.MouseOver,(e,t)=>{this.canUserPerformAction(K.StretchNode)&&t.getResizableX()&&!t.removed&&Z(O.EWResize)}).on(x.MouseOut,(e,t)=>{this.canUserPerformAction(K.StretchNode)&&t.getResizableX()&&!t.removed&&Z()}).call(c.drag().on(C.Start,(e,t)=>{this.canUserPerformAction(K.StretchNode)&&t.getResizableX()&&!t.removed?(Z(O.EWResize),this.currentAction=new q(this,K.StretchNode,t.id,t.getGeometry(),t.getGeometry())):Z(O.NotAllowed)}).on(C.Drag,(e,t)=>{if(this.canUserPerformAction(K.StretchNode)&&t.getResizableX()&&!t.removed){let n=this.getPointerLocationRelativeToCanvas(e);t.stretch(f.Left,t.coords[0]-n[0])}}).on(C.End,(e,t)=>{if(this.canUserPerformAction(K.StretchNode)&&t.getResizableX()&&!t.removed&&this.currentAction instanceof q&&this.currentAction.intent===K.StretchNode){let n=this.getPointerLocationRelativeToCanvas(e);this.snapToGrid&&(n=this.getClosestGridPoint([n[0]-t.type.snapToGridOffset[0],n[1]-t.type.snapToGridOffset[1]]),n[0]+=t.type.snapToGridOffset[0],n[1]+=t.type.snapToGridOffset[1]),t.stretch(f.Left,t.coords[0]-n[0]),this.currentAction.to=t.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}Z()})),r.filter(`.resizable-y`).append(`line`).attr(`class`,`top-resizer`).attr(`stroke`,`transparent`).attr(`stroke-width`,6).on(x.MouseOver,(e,t)=>{this.canUserPerformAction(K.StretchNode)&&t.getResizableY()&&!t.removed&&Z(O.NSResize)}).on(x.MouseOut,(e,t)=>{this.canUserPerformAction(K.StretchNode)&&t.getResizableY()&&!t.removed&&Z()}).call(c.drag().on(C.Start,(e,t)=>{this.canUserPerformAction(K.StretchNode)&&t.getResizableY()&&!t.removed?(Z(O.NSResize),this.currentAction=new q(this,K.StretchNode,t.id,t.getGeometry(),t.getGeometry())):Z(O.NotAllowed)}).on(C.Drag,(e,t)=>{if(this.canUserPerformAction(K.StretchNode)&&t.getResizableY()&&!t.removed){let n=this.getPointerLocationRelativeToCanvas(e);t.stretch(f.Top,t.coords[1]-n[1])}}).on(C.End,(e,t)=>{if(this.canUserPerformAction(K.StretchNode)&&t.getResizableY()&&!t.removed&&this.currentAction instanceof q&&this.currentAction.intent===K.StretchNode){let n=this.getPointerLocationRelativeToCanvas(e);this.snapToGrid&&(n=this.getClosestGridPoint([n[0]-t.type.snapToGridOffset[0],n[1]-t.type.snapToGridOffset[1]]),n[0]+=t.type.snapToGridOffset[0],n[1]+=t.type.snapToGridOffset[1]),t.stretch(f.Top,t.coords[1]-n[1]),this.currentAction.to=t.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}Z()})),r.filter(`.resizable-x`).append(`line`).attr(`class`,`right-resizer`).attr(`stroke`,`transparent`).attr(`stroke-width`,6).on(x.MouseOver,(e,t)=>{this.canUserPerformAction(K.StretchNode)&&t.getResizableX()&&!t.removed&&Z(O.EWResize)}).on(x.MouseOut,(e,t)=>{this.canUserPerformAction(K.StretchNode)&&t.getResizableX()&&!t.removed&&Z()}).call(c.drag().on(C.Start,(e,t)=>{this.canUserPerformAction(K.StretchNode)&&t.getResizableX()&&!t.removed?(Z(O.EWResize),this.currentAction=new q(this,K.StretchNode,t.id,t.getGeometry(),t.getGeometry())):Z(O.NotAllowed)}).on(C.Drag,(e,t)=>{if(this.canUserPerformAction(K.StretchNode)&&t.getResizableX()&&!t.removed){let n=this.getPointerLocationRelativeToCanvas(e);t.stretch(f.Right,n[0]-(t.coords[0]+t.width))}}).on(C.End,(e,t)=>{if(this.canUserPerformAction(K.StretchNode)&&t.getResizableX()&&!t.removed&&this.currentAction instanceof q&&this.currentAction.intent===K.StretchNode){let n=this.getPointerLocationRelativeToCanvas(e);this.snapToGrid&&(n=this.getClosestGridPoint([n[0]-t.type.snapToGridOffset[2],n[1]-t.type.snapToGridOffset[3]]),n[0]+=t.type.snapToGridOffset[2],n[1]+=t.type.snapToGridOffset[3]),t.stretch(f.Right,n[0]-(t.coords[0]+t.width)),this.currentAction.to=t.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}Z()})),r.filter(`.resizable-y`).append(`line`).attr(`class`,`bottom-resizer`).attr(`stroke`,`transparent`).attr(`stroke-width`,6).on(x.MouseOver,(e,t)=>{this.canUserPerformAction(K.StretchNode)&&t.getResizableY()&&!t.removed&&Z(O.NSResize)}).on(x.MouseOut,(e,t)=>{this.canUserPerformAction(K.StretchNode)&&t.getResizableY()&&!t.removed&&Z()}).call(c.drag().on(C.Start,(e,t)=>{this.canUserPerformAction(K.StretchNode)&&t.getResizableY()&&!t.removed?(Z(O.NSResize),this.currentAction=new q(this,K.StretchNode,t.id,t.getGeometry(),t.getGeometry())):Z(O.NotAllowed)}).on(C.Drag,(e,t)=>{if(this.canUserPerformAction(K.StretchNode)&&t.getResizableY()&&!t.removed){let n=this.getPointerLocationRelativeToCanvas(e);t.stretch(f.Bottom,n[1]-(t.coords[1]+t.height))}}).on(C.End,(e,t)=>{if(this.canUserPerformAction(K.StretchNode)&&t.getResizableY()&&!t.removed&&this.currentAction instanceof q&&this.currentAction.intent===K.StretchNode){let n=this.getPointerLocationRelativeToCanvas(e);this.snapToGrid&&this.snapToGrid&&(n=this.getClosestGridPoint([n[0]-t.type.snapToGridOffset[2],n[1]-t.type.snapToGridOffset[3]]),n[0]+=t.type.snapToGridOffset[2],n[1]+=t.type.snapToGridOffset[3]),t.stretch(f.Bottom,n[1]-(t.coords[1]+t.height)),this.currentAction.to=t.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}Z()})),i.attr(`transform`,e=>`translate(${e.coords[0]},${e.coords[1]})`).attr(`opacity`,e=>e.removed?.5:1),Ut(i),i.filter(`.resizable-x`).select(`line.left-resizer`).style(`pointer-events`,e=>e.getResizableX()?`initial`:`none`).attr(`x1`,6/2).attr(`x2`,6/2).attr(`y1`,0).attr(`y2`,e=>e.height),i.filter(`.resizable-y`).select(`line.top-resizer`).style(`pointer-events`,e=>e.getResizableY()?`initial`:`none`).attr(`x1`,0).attr(`x2`,e=>e.width).attr(`y1`,6/2).attr(`y2`,6/2),i.filter(`.resizable-x`).select(`line.right-resizer`).style(`pointer-events`,e=>e.getResizableX()?`initial`:`none`).attr(`x1`,e=>e.width-6/2).attr(`x2`,e=>e.width-6/2).attr(`y1`,0).attr(`y2`,e=>e.height),i.filter(`.resizable-y`).select(`line.bottom-resizer`).style(`pointer-events`,e=>e.getResizableY()?`initial`:`none`).attr(`x1`,0).attr(`x2`,e=>e.width).attr(`y1`,e=>e.height-6/2).attr(`y2`,e=>e.height-6/2)}updateSectionsInView(...e){let t=this.selectCanvasElements().selectAll(`g.diagram-section`).data(this.model.sections.filter(e=>this.priorityThreshold===void 0?!0:e.getPriority()>=this.priorityThreshold),e=>e.id),n=t.exit(),r=t.enter().append(`g`).attr(`id`,e=>e.id).attr(`class`,e=>`diagram-section${zt(e)?` resizable-x`:``}${Bt(e)?` resizable-y`:``} ${e.look?.lookType}`);e&&e.length>0&&(t=t.filter(t=>e.includes(t.id)));let i=r.merge(t);n.remove(),r.on(x.MouseOver,(e,t)=>{this.dragging||(this.userHighlight.focusOn(t),this.diagramEvent$.next(new Y(t)))}).on(x.Click,(e,t)=>{if(!e.ctrlKey&&!e.shiftKey){let e=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new J(e,!1))}let n=Q(t);this.userSelection.toggle(n),this.diagramEvent$.next(new J([n],n.selected))}).on(x.ContextMenu,(e,t)=>{if(this.dragging){e.preventDefault(),e.stopPropagation(),this.dragging=!1;return}let n=new jt(e,t);if(this.diagramEvent$.next(n),!n.defaultPrevented&&this.canUserPerformAction(K.ContextMenu)){e.preventDefault();let n=Q(t);this.userHighlight.focusOn(n),this.diagramEvent$.next(new Y(n)),this.userSelection.add(n),this.diagramEvent$.next(new J([n],!0)),this.contextMenu.open(e)}}).on(x.DoubleClick,(e,t)=>{let n=new At(e,t);this.diagramEvent$.next(n)}).call(c.drag().filter(e=>(this.secondaryButton=X(e),!0)).on(C.Start,(e,t)=>{if(this.multipleSelectionOn||this.secondaryButton)this.startMultipleSelection(e);else{let n=t?.node;n?this.startMovingNode(e,n):Z(O.NotAllowed)}}).on(C.Drag,(e,t)=>{if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(e);else{let n=t?.node;n?this.continueMovingNode(e,n):Z(O.NotAllowed)}}).on(C.End,(e,t)=>{if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(e);else{let n=t?.node;n?this.finishMovingNode(e,n):Z()}this.secondaryButton=!1})),Vt(r),r.filter(`.resizable-x`).append(`line`).attr(`class`,`left-resizer`).attr(`stroke`,`transparent`).attr(`stroke-width`,6).on(x.MouseOver,(e,t)=>{this.canUserPerformAction(K.StretchSection)&&t.getResizableX()&&!t.removed&&Z(O.EWResize)}).on(x.MouseOut,(e,t)=>{this.canUserPerformAction(K.StretchSection)&&t.getResizableX()&&!t.removed&&Z()}).call(c.drag().on(C.Start,(e,t)=>{this.canUserPerformAction(K.StretchSection)&&t.getResizableX()&&!t.removed&&t.node?(Z(O.EWResize),this.currentAction=new q(this,K.StretchSection,t.node.id,t.node.getGeometry(),t.node.getGeometry())):Z(O.NotAllowed)}).on(C.Drag,(e,t)=>{if(this.canUserPerformAction(K.StretchSection)&&t.getResizableX()&&!t.removed&&t.node){let n=this.getPointerLocationRelativeToCanvas(e);t.node.stretchSections(f.Left,t.coords[0]-n[0],t.indexXInNode,t.indexYInNode)}}).on(C.End,(e,t)=>{if(this.canUserPerformAction(K.StretchSection)&&t.getResizableX()&&!t.removed&&this.currentAction instanceof q&&this.currentAction.intent===K.StretchSection&&t.node){let n=this.getPointerLocationRelativeToCanvas(e);this.snapToGrid&&(n=this.getClosestGridPoint(n)),t.node.stretchSections(f.Left,t.coords[0]-n[0],t.indexXInNode,t.indexYInNode),this.currentAction.to=t.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}Z()})),r.filter(`.resizable-y`).append(`line`).attr(`class`,`top-resizer`).attr(`stroke`,`transparent`).attr(`stroke-width`,6).on(x.MouseOver,(e,t)=>{this.canUserPerformAction(K.StretchSection)&&t.getResizableY()&&!t.removed&&Z(O.NSResize)}).on(x.MouseOut,(e,t)=>{this.canUserPerformAction(K.StretchSection)&&t.getResizableY()&&!t.removed&&Z()}).call(c.drag().on(C.Start,(e,t)=>{this.canUserPerformAction(K.StretchSection)&&t.getResizableY()&&!t.removed&&t.node?(Z(O.NSResize),this.currentAction=new q(this,K.StretchSection,t.node.id,t.node.getGeometry(),t.node.getGeometry())):Z(O.NotAllowed)}).on(C.Drag,(e,t)=>{if(this.canUserPerformAction(K.StretchSection)&&t.getResizableY()&&!t.removed&&t.node){let n=this.getPointerLocationRelativeToCanvas(e);t.node.stretchSections(f.Top,t.coords[1]-n[1],t.indexXInNode,t.indexYInNode)}}).on(C.End,(e,t)=>{if(this.canUserPerformAction(K.StretchSection)&&t.getResizableY()&&!t.removed&&this.currentAction instanceof q&&this.currentAction.intent===K.StretchSection&&t.node){let n=this.getPointerLocationRelativeToCanvas(e);this.snapToGrid&&(n=this.getClosestGridPoint(n)),t.node.stretchSections(f.Top,t.coords[1]-n[1],t.indexXInNode,t.indexYInNode),this.currentAction.to=t.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}Z()})),r.filter(`.resizable-x`).append(`line`).attr(`class`,`right-resizer`).attr(`stroke`,`transparent`).attr(`stroke-width`,6).on(x.MouseOver,(e,t)=>{this.canUserPerformAction(K.StretchSection)&&t.getResizableX()&&!t.removed&&Z(O.EWResize)}).on(x.MouseOut,(e,t)=>{this.canUserPerformAction(K.StretchSection)&&t.getResizableX()&&!t.removed&&Z()}).call(c.drag().on(C.Start,(e,t)=>{this.canUserPerformAction(K.StretchSection)&&t.getResizableX()&&!t.removed&&t.node?(Z(O.EWResize),this.currentAction=new q(this,K.StretchSection,t.node.id,t.node.getGeometry(),t.node.getGeometry())):Z(O.NotAllowed)}).on(C.Drag,(e,t)=>{if(this.canUserPerformAction(K.StretchSection)&&t.getResizableX()&&!t.removed&&t.node){let n=this.getPointerLocationRelativeToCanvas(e);t.node.stretchSections(f.Right,n[0]-(t.coords[0]+t.width),t.indexXInNode,t.indexYInNode)}}).on(C.End,(e,t)=>{if(this.canUserPerformAction(K.StretchSection)&&t.getResizableX()&&!t.removed&&this.currentAction instanceof q&&this.currentAction.intent===K.StretchSection&&t.node){let n=this.getPointerLocationRelativeToCanvas(e);this.snapToGrid&&(n=this.getClosestGridPoint(n)),t.node.stretchSections(f.Right,n[0]-(t.coords[0]+t.width),t.indexXInNode,t.indexYInNode),this.currentAction.to=t.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}Z()})),r.filter(`.resizable-y`).append(`line`).attr(`class`,`bottom-resizer`).attr(`stroke`,`transparent`).attr(`stroke-width`,6).on(x.MouseOver,(e,t)=>{this.canUserPerformAction(K.StretchSection)&&t.getResizableY()&&!t.removed&&Z(O.NSResize)}).on(x.MouseOut,(e,t)=>{this.canUserPerformAction(K.StretchSection)&&t.getResizableY()&&!t.removed&&Z()}).call(c.drag().on(C.Start,(e,t)=>{this.canUserPerformAction(K.StretchSection)&&t.getResizableY()&&!t.removed&&t.node?(Z(O.NSResize),this.currentAction=new q(this,K.StretchSection,t.node.id,t.node.getGeometry(),t.node.getGeometry())):Z(O.NotAllowed)}).on(C.Drag,(e,t)=>{if(this.canUserPerformAction(K.StretchSection)&&t.getResizableY()&&!t.removed&&t.node){let n=this.getPointerLocationRelativeToCanvas(e);t.node.stretchSections(f.Bottom,n[1]-(t.coords[1]+t.height),t.indexXInNode,t.indexYInNode)}}).on(C.End,(e,t)=>{if(this.canUserPerformAction(K.StretchSection)&&t.getResizableY()&&!t.removed&&this.currentAction instanceof q&&this.currentAction.intent===K.StretchSection&&t.node){let n=this.getPointerLocationRelativeToCanvas(e);this.snapToGrid&&(n=this.getClosestGridPoint(n)),t.node.stretchSections(f.Bottom,n[1]-(t.coords[1]+t.height),t.indexXInNode,t.indexYInNode),this.currentAction.to=t.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}Z()})),i.attr(`transform`,e=>`translate(${e.coords[0]},${e.coords[1]})`).attr(`opacity`,e=>e.removed?.5:1),Ut(i),i.filter(`.resizable-x`).select(`line.left-resizer`).style(`pointer-events`,e=>e.getResizableX()?`initial`:`none`).attr(`x1`,6/2).attr(`x2`,6/2).attr(`y1`,0).attr(`y2`,e=>e.height),i.filter(`.resizable-y`).select(`line.top-resizer`).style(`pointer-events`,e=>e.getResizableY()?`initial`:`none`).attr(`x1`,0).attr(`x2`,e=>e.width).attr(`y1`,6/2).attr(`y2`,6/2),i.filter(`.resizable-x`).select(`line.right-resizer`).style(`pointer-events`,e=>e.getResizableX()?`initial`:`none`).attr(`x1`,e=>e.width-6/2).attr(`x2`,e=>e.width-6/2).attr(`y1`,0).attr(`y2`,e=>e.height),i.filter(`.resizable-y`).select(`line.bottom-resizer`).style(`pointer-events`,e=>e.getResizableY()?`initial`:`none`).attr(`x1`,0).attr(`x2`,e=>e.width).attr(`y1`,e=>e.height-6/2).attr(`y2`,e=>e.height-6/2)}updatePortsInView(...e){let t=this.selectCanvasElements().selectAll(`g.diagram-port`).data(this.model.ports.filter(e=>this.priorityThreshold===void 0?!0:e.getPriority()>=this.priorityThreshold),e=>e.id),n=t.exit(),r=t.enter().append(`g`).attr(`id`,e=>e.id).attr(`class`,e=>`diagram-port ${e.look.lookType}`);e&&e.length>0&&(t=t.filter(t=>e.includes(t.id)));let i=r.merge(t);n.remove(),r.on(x.MouseOver,(e,t)=>{!this.unfinishedConnection&&!this.dragging&&(this.userHighlight.focusOn(t),this.diagramEvent$.next(new Y(t))),this.unfinishedConnection&&(this.unfinishedConnection.type.canStartFromType(this.unfinishedConnection.start?.getNode()?.type?.id||``)&&this.unfinishedConnection.start?.allowsOutgoing&&this.unfinishedConnection.type.canFinishOnType(t.getNode()?.type?.id||``)&&t.allowsIncoming||this.unfinishedConnection.type.canStartFromType(t.getNode()?.type?.id||``)&&t.allowsOutgoing&&this.unfinishedConnection.type.canFinishOnType(this.unfinishedConnection.start?.getNode()?.type?.id||``)&&this.unfinishedConnection.start?.allowsIncoming||Z(O.NoDrop))}).on(x.MouseOut,()=>{this.unfinishedConnection&&Z(O.Grabbing)}).on(x.Click,(e,t)=>{if(!e.ctrlKey&&!e.shiftKey){let e=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new J(e,!1))}let n=Q(t);this.userSelection.toggle(n),this.diagramEvent$.next(new J([n],n.selected))}).on(x.ContextMenu,(e,t)=>{if(this.dragging){e.preventDefault(),e.stopPropagation(),this.dragging=!1;return}let n=new jt(e,t);if(this.diagramEvent$.next(n),!n.defaultPrevented&&this.canUserPerformAction(K.ContextMenu)){e.preventDefault();let n=Q(t);this.userHighlight.focusOn(n),this.diagramEvent$.next(new Y(n)),this.userSelection.add(n),this.diagramEvent$.next(new J([n],!0)),this.contextMenu.open(e)}}).on(x.DoubleClick,(e,t)=>{let n=new At(e,t);this.diagramEvent$.next(n)}).call(c.drag().filter(e=>(this.secondaryButton=X(e),!0)).on(C.Start,(e,t)=>{this.multipleSelectionOn||this.secondaryButton?this.startMultipleSelection(e):this.canUserPerformAction(K.AddConnection)&&(this.allowSharingPorts||t.incomingConnections.filter(e=>!e.removed).length===0&&t.outgoingConnections.filter(e=>!e.removed).length===0)&&!t.removed?(Z(O.Grabbing),this.startConnection(t),this.unfinishedConnection&&(this.unfinishedConnectionTracer=this.selectCanvasElements().append(`path`).attr(`stroke`,`none`).attr(`fill`,`none`))):Z(O.NotAllowed)}).on(C.Drag,(e,t)=>{if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(e);else if(this.canUserPerformAction(K.AddConnection)&&!t.removed&&this.unfinishedConnection!==void 0){let t=[e.x,e.y];this.unfinishedConnectionTracer?.attr(`d`,Rt(this.unfinishedConnection.look.shape||N.look.shape,this.unfinishedConnection.startCoords,t,this.unfinishedConnection.startDirection,this.unfinishedConnection.endDirection,this.unfinishedConnection.points,this.unfinishedConnection.type.defaultLook.thickness||N.look.thickness,this.unfinishedConnection.type.defaultStartMarkerLook?.width,this.unfinishedConnection.type.defaultEndMarkerLook?.width));let n=this.unfinishedConnectionTracer?.node();if(n){let e=2,t=n.getTotalLength();t<e&&(e=0);let r=n.getPointAtLength(t-e);this.unfinishedConnection.endCoords=[r.x,r.y]}else this.unfinishedConnection.endCoords=t;if(this.updateConnectionsInView(nn),this.unfinishedConnectionPort?.raise(!1),this.model.ports.length>0){let t=this.getPointerLocationRelativeToCanvas(e),n=1/0,r;for(let e of this.model.ports){let i=e.distanceTo(t);i<n&&(n=i,r=e)}r&&n<this.portHighlightRadius?this.userHighlight.focusOn(r):this.userHighlight.clear()}}}).on(C.End,(e,t)=>{if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(e);else{if(this.canUserPerformAction(K.AddConnection)&&!t.removed){this.unfinishedConnectionTracer?.remove();let t=this.userHighlight.getFocus();if(t instanceof it)this.finishConnection(t);else if(t instanceof I&&t.rootElement instanceof it)this.finishConnection(t.rootElement);else if(t instanceof U||t instanceof V||t instanceof I){let n;if(t instanceof U||t instanceof V)n=t;else if(t.rootElement instanceof U||t.rootElement instanceof V)n=t.rootElement;else{this.dropConnection();return}let r=n.getClosestPortToPoint([e.x,e.y]);r===void 0?this.dropConnection():this.finishConnection(r)}else this.dropConnection()}Z()}this.secondaryButton=!1})),r.filter(`.image-look`).append(`image`),Vt(r),i.attr(`transform`,e=>`translate(${e.coords[0]-e.width/2},${e.coords[1]-e.width/2})`).attr(`opacity`,e=>e.removed?.5:1),Ut(i)}updateConnectionsInView(...e){let t=this.model.connections.filter(e=>this.priorityThreshold===void 0?!0:e.getPriority()>=this.priorityThreshold);this.unfinishedConnection&&t.push(this.unfinishedConnection);let n=this.selectCanvasElements().selectAll(`g.diagram-connection`).data(t,e=>e.id),r=n.exit(),i=n.enter().append(`g`).attr(`id`,e=>e.id).attr(`class`,`diagram-connection`);e&&e.length>0&&(n=n.filter(t=>e.includes(t.id)));let a=i.merge(n);r.remove(),i.on(x.MouseOver,(e,t)=>{t.end!==void 0&&!this.dragging&&(this.userHighlight.focusOn(t),this.diagramEvent$.next(new Y(t)))}).on(x.Click,(e,t)=>{if(!e.ctrlKey&&!e.shiftKey){let e=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new J(e,!1))}this.userSelection.toggle(t),this.diagramEvent$.next(new J([t],t.selected))}).on(x.ContextMenu,(e,t)=>{if(this.dragging){e.preventDefault(),e.stopPropagation(),this.dragging=!1;return}let n=new jt(e,t);this.diagramEvent$.next(n),!n.defaultPrevented&&this.canUserPerformAction(K.ContextMenu)&&(e.preventDefault(),this.userHighlight.focusOn(t),this.diagramEvent$.next(new Y(t)),this.userSelection.add(t),this.diagramEvent$.next(new J([t],!0)),this.contextMenu.open(e))}).on(x.DoubleClick,(e,t)=>{let n=new At(e,t);this.diagramEvent$.next(n)}).call(c.drag().filter(e=>(this.secondaryButton=X(e),!0)).on(C.Start,e=>{this.startMultipleSelection(e)}).on(C.Drag,e=>{this.continueMultipleSelection(e)}).on(C.End,e=>{this.finishMultipleSelection(e)})),i.append(`path`).attr(`class`,`diagram-connection-path`),i.append(`path`).attr(`class`,`diagram-connection-path-box`),i.append(`marker`).attr(`id`,e=>`${e.id}-start-marker`).attr(`class`,`diagram-connection-start-marker`).append(`image`).attr(`preserveAspectRatio`,`none`),i.append(`marker`).attr(`id`,e=>`${e.id}-end-marker`).attr(`class`,`diagram-connection-end-marker`).append(`image`).attr(`preserveAspectRatio`,`none`),i.append(`g`).attr(`class`,`diagram-connection-start-label`),i.select(`g.diagram-connection-start-label`).append(`path`),i.select(`g.diagram-connection-start-label`).append(`text`).style(`user-select`,`none`),i.append(`g`).attr(`class`,`diagram-connection-middle-label`),i.select(`g.diagram-connection-middle-label`).append(`path`),i.select(`g.diagram-connection-middle-label`).append(`text`).style(`user-select`,`none`),i.append(`g`).attr(`class`,`diagram-connection-end-label`),i.select(`g.diagram-connection-end-label`).append(`path`),i.select(`g.diagram-connection-end-label`).append(`text`).style(`user-select`,`none`),a.attr(`opacity`,e=>e.removed?.5:1).select(`path.diagram-connection-path`).attr(`d`,e=>Rt(e.look.shape||N.look.shape,e.startCoords,e.endCoords,e.startDirection,e.endDirection,e.points,e.type.defaultLook.thickness||N.look.thickness,e.type.defaultStartMarkerLook?.width,e.type.defaultEndMarkerLook?.width)).attr(`marker-start`,e=>`url(#${e.id}-start-marker)`).attr(`marker-end`,e=>`url(#${e.id}-end-marker)`).attr(`stroke`,e=>e.look.color||N.look.color).attr(`stroke-width`,e=>e.look.thickness||N.look.thickness).attr(`stroke-dasharray`,e=>ae(e.look.style||N.look.style,e.type.defaultLook.thickness||N.look.thickness)).attr(`fill`,`none`),a.select(`path.diagram-connection-path-box`).attr(`d`,e=>Rt(e.look.shape||N.look.shape,e.startCoords,e.endCoords,e.startDirection,e.endDirection,e.points,e.type.defaultLook.thickness||N.look.thickness,e.type.defaultStartMarkerLook?.width,e.type.defaultEndMarkerLook?.width)).attr(`stroke`,`transparent`).attr(`pointer-events`,`stroke`).attr(`stroke-width`,e=>(e.look.thickness||N.look.thickness)+12).attr(`stroke-dasharray`,e=>ae(e.look.style||N.look.style,e.type.defaultLook.thickness||N.look.thickness)).attr(`fill`,`none`),a.data().forEach(e=>{this.updateConnectionLabelsInView(e),this.updateConnectionMarkersInView(e)})}updateFieldsInView(...e){let t=this.selectCanvasElements().selectAll(`g.diagram-field`).data(this.model.fields.filter(e=>this.priorityThreshold===void 0?!0:e.getPriority()>=this.priorityThreshold),e=>e.id),n=t.exit(),r=t.enter().append(`g`).attr(`id`,e=>e.id).attr(`class`,`diagram-field`);e&&e.length>0&&(t=t.filter(t=>e.includes(t.id)));let i=r.merge(t);n.remove(),r.on(x.MouseOver,(e,t)=>{this.dragging||(this.userHighlight.focusOn(t),this.diagramEvent$.next(new Y(t)))}).on(x.Click,(e,t)=>{if(!e.ctrlKey&&!e.shiftKey){let e=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new J(e,!1))}let n=Q(t);this.userSelection.toggle(n),this.diagramEvent$.next(new J([n],n.selected))}).on(x.ContextMenu,(e,t)=>{if(this.dragging){e.preventDefault(),e.stopPropagation(),this.dragging=!1;return}let n=new jt(e,t);if(this.diagramEvent$.next(n),!n.defaultPrevented&&this.canUserPerformAction(K.ContextMenu)){e.preventDefault();let n=Q(t);this.userHighlight.focusOn(n),this.diagramEvent$.next(new Y(n)),this.userSelection.add(n),this.diagramEvent$.next(new J([n],!0)),this.contextMenu.open(e)}}).on(x.DoubleClick,(e,t)=>{let n=new At(e,t);this.diagramEvent$.next(n),!n.defaultPrevented&&this.canUserPerformAction(K.EditField)&&t.editable&&!t.removed&&(this.currentAction=new Ct(this,t.id,t.text,``),this.openTextInput(t.id))}).call(c.drag().filter(e=>(this.secondaryButton=X(e),!0)).on(C.Start,(e,t)=>{if(this.multipleSelectionOn||this.secondaryButton)this.startMultipleSelection(e);else{let n;t.rootElement instanceof U?n=t.rootElement:t.rootElement instanceof V&&(n=t.rootElement.node),n?this.startMovingNode(e,n):Z(O.NotAllowed)}}).on(C.Drag,(e,t)=>{if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(e);else{let n;t.rootElement instanceof U?n=t.rootElement:t.rootElement instanceof V&&(n=t.rootElement.node),n?this.continueMovingNode(e,n):Z(O.NotAllowed)}}).on(C.End,(e,t)=>{if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(e);else{let n;t.rootElement instanceof U?n=t.rootElement:t.rootElement instanceof V&&(n=t.rootElement.node),n?this.finishMovingNode(e,n):Z()}this.secondaryButton=!1})),r.append(`text`),r.append(`rect`),i.attr(`x`,0).attr(`y`,0).attr(`width`,e=>e.width).attr(`height`,e=>e.height).attr(`transform`,e=>`translate(${e.coords[0]},${e.coords[1]}) rotate(${e.orientation} ${e.width/2} ${e.height/2})`).attr(`opacity`,e=>e.removed?.5:1).select(`text`).attr(`x`,e=>e.horizontalAlign===m.Center?e.width/2:e.horizontalAlign===m.Right?e.width:0).attr(`text-anchor`,e=>e.horizontalAlign===m.Center?`middle`:e.horizontalAlign===m.Right?`end`:`start`).attr(`y`,e=>e.verticalAlign===h.Center?e.height/2:e.verticalAlign===h.Bottom?e.height:0).attr(`dominant-baseline`,e=>e.verticalAlign===h.Center?`middle`:e.verticalAlign===h.Bottom?`auto`:`hanging`).attr(`font-size`,e=>e.fontSize).attr(`font-family`,e=>e.fontFamily||`'Wonder Unit Sans', sans-serif`).attr(`font-weight`,e=>e.highlighted?600:400).attr(`fill`,e=>e.selected?e.selectedColor||`#000000`:e.color||`#000000`).each(e=>{this.setFieldTextAndWrap(e)}),i.select(`rect`).attr(`x`,0).attr(`y`,0).attr(`width`,e=>e.width).attr(`height`,e=>e.height).attr(`fill`,`transparent`)}updateObjectsInView(...e){let t=this.selectCanvasElements().selectAll(`g.diagram-object`).data(this.model.objects.filter(e=>this.priorityThreshold===void 0?!0:e.getPriority()>=this.priorityThreshold),e=>e.id),n=t.exit(),r=t.enter().append(`g`).attr(`id`,e=>e.id).attr(`class`,`diagram-object`);e&&e.length>0&&(t=t.filter(t=>e.includes(t.id))),r.merge(t).attr(`width`,e=>e.width).attr(`height`,e=>e.height).attr(`transform`,e=>`translate(${e.coords[0]},${e.coords[1]})`).html(e=>e.html),n.remove(),r.on(x.ContextMenu,(e,t)=>{if(this.dragging){e.preventDefault(),e.stopPropagation(),this.dragging=!1;return}let n=new jt(e,t);this.diagramEvent$.next(n),!n.defaultPrevented&&this.canUserPerformAction(K.ContextMenu)&&(e.preventDefault(),this.contextMenu.open(e))}).on(x.DoubleClick,(e,t)=>{let n=new At(e,t);this.diagramEvent$.next(n)}).call(c.drag().filter(e=>(this.secondaryButton=X(e),!0)).on(C.Start,e=>{(this.multipleSelectionOn||this.secondaryButton)&&this.startMultipleSelection(e)}).on(C.Drag,e=>{(this.multipleSelectionOn||this.secondaryButton)&&this.continueMultipleSelection(e)}).on(C.End,e=>{(this.multipleSelectionOn||this.secondaryButton)&&this.finishMultipleSelection(e)}))}updateDecoratorsInView(...e){let t=this.selectCanvasElements().selectAll(`g.diagram-decorator`).data(this.model.decorators.filter(e=>this.priorityThreshold===void 0?!0:e.getPriority()>=this.priorityThreshold),e=>e.id),n=t.exit(),r=t.enter().append(`g`).attr(`id`,e=>e.id).attr(`class`,`diagram-decorator`);e&&e.length>0&&(t=t.filter(t=>e.includes(t.id))),r.merge(t).attr(`width`,e=>e.width).attr(`height`,e=>e.height).attr(`transform`,e=>`translate(${e.coords[0]},${e.coords[1]})`).html(e=>e.html),n.remove(),r.on(x.MouseOver,(e,t)=>{this.dragging||(this.userHighlight.focusOn(t),this.diagramEvent$.next(new Y(t)))}).on(x.Click,(e,t)=>{if(!e.ctrlKey&&!e.shiftKey){let e=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new J(e,!1))}if(t.rootElement){let e=Q(t.rootElement);this.userSelection.toggle(e),this.diagramEvent$.next(new J([e],e.selected))}}).on(x.ContextMenu,(e,t)=>{if(this.dragging){e.preventDefault(),e.stopPropagation(),this.dragging=!1;return}let n=new jt(e,t);if(this.diagramEvent$.next(n),!n.defaultPrevented&&this.canUserPerformAction(K.ContextMenu)&&t.rootElement){e.preventDefault();let n=Q(t.rootElement);this.userHighlight.focusOn(n),this.diagramEvent$.next(new Y(n)),this.userSelection.add(n),this.diagramEvent$.next(new J([n],!0)),this.contextMenu.open(e)}}).on(x.DoubleClick,(e,t)=>{let n=new At(e,t);this.diagramEvent$.next(n)}).call(c.drag().filter(e=>(this.secondaryButton=X(e),!0)).on(C.Start,(e,t)=>{if(this.multipleSelectionOn||this.secondaryButton)this.startMultipleSelection(e);else{let n;t.rootElement instanceof U?n=t.rootElement:t.rootElement instanceof V&&(n=t.rootElement.node),n?this.startMovingNode(e,n):Z(O.NotAllowed)}}).on(C.Drag,(e,t)=>{if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(e);else{let n;t.rootElement instanceof U?n=t.rootElement:t.rootElement instanceof V&&(n=t.rootElement.node),n?this.continueMovingNode(e,n):Z(O.NotAllowed)}}).on(C.End,(e,t)=>{if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(e);else{let n;t.rootElement instanceof U?n=t.rootElement:t.rootElement instanceof V&&(n=t.rootElement.node),n?this.finishMovingNode(e,n):Z()}this.secondaryButton=!1}))}updateConnectionLabelsInView(e){let t=this.selectCanvasView().select(`[id='${te(e.id)}']`),n=t.select(`path`).node(),r={...F,...e.type.label};if(n){let i=n.getTotalLength(),a=0,o=0,s=0,c=0,l=0,u=0;if(r.backgroundColor===`transparent`){let t=e.endCoords[0]-e.startCoords[0],n=e.endCoords[1]-e.startCoords[1];switch(e.startDirection){case f.Top:a=t>=0?-.5:.5,l=a;break;case f.Bottom:a=t>=0?-.5:.5,l=a;break;case f.Left:o=n>0?-.5:.5,u=o;break;case f.Right:o=n>0?-.5:.5,u=o;break;default:a=.5,l=a,o=-.5,u=o}switch(e.endDirection){case f.Top:l=t>=0?.5:-.5;break;case f.Bottom:l=t>=0?.5:-.5;break;case f.Left:u=n>0?.5:-.5;break;case f.Right:u=n>0?.5:-.5;break;default:l=.5,u=-.5}Math.abs(t)>=Math.abs(n)?(s=t>0?-.5:.5,c=n>0?.5:-.5):(s=t>0?.5:-.5,c=n>0?-.5:.5)}t.select(`g.diagram-connection-start-label text`).attr(`x`,0).attr(`y`,r.fontSize/3).attr(`text-anchor`,`middle`).attr(`font-family`,r.fontFamily).attr(`font-size`,r.fontSize).attr(`fill`,e.selected?r.selectedColor:r.color).style(`font-kerning`,`none`).text(e.startLabel);let d=t.select(`g.diagram-connection-start-label text`).node()?.getBoundingClientRect();if(d){let i=e.startLabel?d.width/this.zoomTransform.k+ze(r)+Be(r):0,s=e.startLabel?d.height/this.zoomTransform.k+Ve(r)+Re(r):0,c;switch(e.startDirection){case f.Left:c=n.getPointAtLength(z(r)+i/2);break;case f.Right:c=n.getPointAtLength(R(r)+i/2);break;case f.Top:c=n.getPointAtLength(L(r)+s/2);break;case f.Bottom:c=n.getPointAtLength(B(r)+s/2);break;default:c=n.getPointAtLength(Math.max(R(r)+i/2,z(r)+i/2,B(r)+s/2,L(r)+s/2))}t.select(`g.diagram-connection-start-label path`).attr(`d`,fe(-i/2,-s/2,i,s)).attr(`fill`,r.backgroundColor).attr(`stroke`,`none`),t.select(`g.diagram-connection-start-label`).attr(`transform`,`translate(${c.x+a*i},${c.y+o*s})`)}t.select(`g.diagram-connection-middle-label text`).attr(`x`,0).attr(`y`,r.fontSize/3).attr(`text-anchor`,`middle`).attr(`font-family`,r.fontFamily).attr(`font-size`,r.fontSize).attr(`fill`,e.selected?r.selectedColor:r.color).style(`font-kerning`,`none`).text(e.middleLabel);let p=t.select(`g.diagram-connection-middle-label text`).node()?.getBoundingClientRect();if(p){let a=e.middleLabel?p.width/this.zoomTransform.k+ze(r)+Be(r):0,o=e.middleLabel?p.height/this.zoomTransform.k+Ve(r)+Re(r):0,l=n.getPointAtLength(i/2);t.select(`g.diagram-connection-middle-label path`).attr(`d`,fe(-a/2,-o/2,a,o)).attr(`fill`,r.backgroundColor).attr(`stroke`,`none`),t.select(`g.diagram-connection-middle-label`).attr(`transform`,`translate(${l.x+s*a},${l.y+c*o})`)}t.select(`g.diagram-connection-end-label text`).attr(`x`,0).attr(`y`,r.fontSize/3).attr(`text-anchor`,`middle`).attr(`font-family`,r.fontFamily).attr(`font-size`,r.fontSize).attr(`fill`,e.selected?r.selectedColor:r.color).style(`font-kerning`,`none`).text(e.endLabel);let m=t.select(`g.diagram-connection-end-label text`).node()?.getBoundingClientRect();if(m){let a=e.endLabel?m.width/this.zoomTransform.k+ze(r)+Be(r):0,o=e.endLabel?m.height/this.zoomTransform.k+Ve(r)+Re(r):0,s;switch(e.endDirection){case f.Left:s=n.getPointAtLength(i-(z(r)+a/2));break;case f.Right:s=n.getPointAtLength(i-(R(r)+a/2));break;case f.Top:s=n.getPointAtLength(i-(L(r)+o/2));break;case f.Bottom:s=n.getPointAtLength(i-(B(r)+o/2));break;default:s=n.getPointAtLength(i-Math.max(R(r)+a/2,z(r)+a/2,B(r)+o/2,L(r)+o/2))}t.select(`g.diagram-connection-end-label path`).attr(`d`,fe(-a/2,-o/2,a,o)).attr(`fill`,r.backgroundColor).attr(`stroke`,`none`),t.select(`g.diagram-connection-end-label`).attr(`transform`,`translate(${s.x+l*a},${s.y+u*o})`)}}}updateConnectionMarkersInView(e){let t=this.selectCanvasView().select(`[id='${te(e.id)}']`),n=t.select(`marker.diagram-connection-start-marker`),r=t.select(`marker.diagram-connection-end-marker`);e.startMarkerLook===null?n.attr(`orient`,`auto-start-reverse`).attr(`markerWidth`,0).attr(`markerHeight`,0):n.attr(`orient`,`auto-start-reverse`).attr(`markerWidth`,e.startMarkerLook.width).attr(`markerHeight`,e.startMarkerLook.height).attr(`refX`,e.startMarkerLook.refX).attr(`refY`,e.startMarkerLook.refY).select(`image`).attr(`href`,e.startMarkerLook.image).attr(`width`,e.startMarkerLook.width).attr(`height`,e.startMarkerLook.height),e.endMarkerLook===null?r.attr(`orient`,`auto-start-reverse`).attr(`markerWidth`,0).attr(`markerHeight`,0):r.attr(`orient`,`auto-start-reverse`).attr(`markerWidth`,e.endMarkerLook.width).attr(`markerHeight`,e.endMarkerLook.height).attr(`refX`,e.endMarkerLook.refX).attr(`refY`,e.endMarkerLook.refY).select(`image`).attr(`href`,e.endMarkerLook.image).attr(`width`,e.endMarkerLook.width).attr(`height`,e.endMarkerLook.height)}fieldRootFitsInView(e){let t=this.model.fields.get(e);if(!t)return!1;if(t.rootElement instanceof U||t.rootElement instanceof V){let e=this.minimumSizeOfField(t),n=e[0]+R(t.rootElement.type?.label)+z(t.rootElement.type?.label)-t.rootElement.width,r=e[1]+B(t.rootElement.type?.label)+L(t.rootElement.type?.label)-t.rootElement.height;return n<=0&&r<=0}return!0}fitFieldRootInView(e,t=!0){let n=this.model.fields.get(e);if(n){if(n.rootElement instanceof U){let e=this.minimumSizeOfField(n),r=e[0]+R(n.rootElement.type.label)+z(n.rootElement.type.label)-n.rootElement.width,i=e[1]+B(n.rootElement.type.label)+L(n.rootElement.type.label)-n.rootElement.height;this.snapToGrid&&(r=Math.ceil(r/this.gridSize)*this.gridSize,i=Math.ceil(i/this.gridSize)*this.gridSize),n.rootElement.width+r<n.rootElement.type.minWidth&&(r=n.rootElement.type.minWidth-n.rootElement.width),n.rootElement.height+i<n.rootElement.type.minHeight&&(i=n.rootElement.type.minHeight-n.rootElement.height),(t!==!1||r>0)&&n.rootElement.stretch(f.Right,r),(t!==!1||i>0)&&n.rootElement.stretch(f.Bottom,i)}if(n.rootElement instanceof V){let e=this.minimumSizeOfField(n),r=e[0],i=e[1];for(let e of n.rootElement.node?.sections||[])e.label&&(e.indexXInNode===n.rootElement.indexXInNode&&e.indexYInNode!==n.rootElement.indexYInNode?r=Math.max(r,this.minimumSizeOfField(e.label)[0]):e.indexXInNode!==n.rootElement.indexXInNode&&e.indexYInNode===n.rootElement.indexYInNode&&(i=Math.max(i,this.minimumSizeOfField(e.label)[1])));e[0]<r&&(e[0]=r),e[1]<i&&(e[1]=i);let a=n.rootElement.type,o=e[0]+R(a?.label)+z(a?.label)-n.rootElement.width,s=e[1]+B(a?.label)+L(a?.label)-n.rootElement.height;this.snapToGrid&&(o=Math.ceil(o/this.gridSize)*this.gridSize,s=Math.ceil(s/this.gridSize)*this.gridSize),n.rootElement.width+o<(n.rootElement.getMinWidth()||0)&&(o=(n.rootElement.getMinWidth()||0)-n.rootElement.width),n.rootElement.height+s<(n.rootElement.getMinHeight()||0)&&(s=(n.rootElement.getMinHeight()||0)-n.rootElement.height),(t||o>0)&&n.rootElement.node?.stretchSections(f.Right,o,n.rootElement.indexXInNode,n.rootElement.indexYInNode),(t||s>0)&&n.rootElement.node?.stretchSections(f.Bottom,s,n.rootElement.indexXInNode,n.rootElement.indexYInNode)}}}fitNodeInView(e,t=!0){let n=this.model.nodes.get(e);if(n&&n.sections.length>0&&this.priorityThreshold){let e=0,r=0;for(let t of n.sections)if(t.getPriority()>=this.priorityThreshold){let i=t.coords[0]+t.width-n.coords[0],a=t.coords[1]+t.height-n.coords[1];e=Math.max(e,i),r=Math.max(r,a)}e+=n.type.sectionGrid?.margin||0,r+=n.type.sectionGrid?.margin||0,(t||e>n.width)&&n.stretch(f.Right,e-n.width),(t||r>n.height)&&n.stretch(f.Bottom,r-n.height)}}selectRoot(){return c.select(this.diagramRoot)}selectSVGElement(){return c.select(this.diagramRoot).select(`svg`)}selectCanvasView(){return this.selectSVGElement().select(`.daga-canvas-view`)}selectCanvasElements(){return this.selectSVGElement().select(`.daga-canvas-elements`)}startConnection(e){if(e.allowsOutgoing||e.allowsIncoming){if(this.connectionType&&(this.connectionType.canStartFromType(e.getNode()?.type?.id||``)&&e.allowsOutgoing||this.connectionType.canFinishOnType(e.getNode()?.type?.id||``)&&e.allowsIncoming))this.unfinishedConnection=new P(this.model,this.connectionType,e,void 0,nn),this.unfinishedConnectionPort=e;else if(this.inferConnectionType){let t=this.model.connections.types.all().find(t=>e.allowsOutgoing&&t.canStartFromType(e.getNode()?.type?.id||``));t===void 0&&(t=this.model.connections.types.all().find(t=>e.allowsIncoming&&t.canFinishOnType(e.getNode()?.type?.id||``))),t!==void 0&&(this.unfinishedConnection=new P(this.model,t,e,void 0,nn),this.unfinishedConnectionPort=e)}}}finishConnection(e){if(this.userHighlight.clear(),this.unfinishedConnection!==void 0){if(!this.allowConnectionLoops&&this.unfinishedConnection.start===e){this.dropConnection();return}if(!this.allowSharingPorts&&(e.incomingConnections.filter(e=>!e.removed).length>0||e.outgoingConnections.filter(e=>!e.removed).length>0)){this.dropConnection();return}if(!this.allowSharingBothPorts&&this.model.connections.find(t=>!t.removed&&(t.start===this.unfinishedConnection?.start&&t.end===e||t.end===this.unfinishedConnection?.start&&t.start===e))!==void 0){this.dropConnection();return}if(this.unfinishedConnection.type.canStartFromType(this.unfinishedConnection?.start?.getNode()?.type?.id||``)&&this.unfinishedConnection?.start?.allowsOutgoing&&this.unfinishedConnection.type.canFinishOnType(e.getNode()?.type?.id||``)&&e.allowsIncoming){let t=new St(this,this.unfinishedConnection.type,this.unfinishedConnection.start?.id,e.id);this.dropConnection(),t.do(),this.actionStack.add(t)}else if(this.unfinishedConnection.type.canFinishOnType(this.unfinishedConnection?.start?.getNode()?.type?.id||``)&&this.unfinishedConnection?.start?.allowsIncoming&&this.unfinishedConnection.type.canStartFromType(e.getNode()?.type?.id||``)&&e.allowsOutgoing){let t=new St(this,this.unfinishedConnection.type,e.id,this.unfinishedConnection.start?.id);this.dropConnection(),t.do(),this.actionStack.add(t)}else if(this.inferConnectionType){let t=this.model.connections.types.all().find(t=>t.canStartFromType(this.unfinishedConnection?.start?.getNode()?.type?.id||``)&&this.unfinishedConnection?.start?.allowsOutgoing&&t.canFinishOnType(e.getNode()?.type?.id||``)&&e.allowsIncoming),n=!1;if(t===void 0&&(t=this.model.connections.types.all().find(t=>t.canFinishOnType(this.unfinishedConnection?.start?.getNode()?.type?.id||``)&&this.unfinishedConnection?.start?.allowsIncoming&&t.canStartFromType(e.getNode()?.type?.id||``)&&e.allowsOutgoing),n=!0),t!==void 0){let r=new St(this,t,n?e.id:this.unfinishedConnection.start?.id,n?this.unfinishedConnection.start?.id:e.id);this.dropConnection(),r.do(),this.actionStack.add(r)}else this.dropConnection()}else this.dropConnection()}}dropConnection(){this.unfinishedConnection?.setStart(void 0),this.unfinishedConnection?.setEnd(void 0),this.unfinishedConnection?.select()?.remove(),this.unfinishedConnection=void 0,this.unfinishedConnectionPort=void 0}cancelAllUserActions(){this.currentAction=void 0,this.dropConnection(),this.removeInputField(),this.contextMenu.close(),this.userSelection.clear()}canUserPerformAction(e){return this.userActions[e]!==!1}openTextInput(e){let t=this.model.fields.get(e);t&&this.createInputField(t.text,t.coords,t.width,t.height,t.fontSize,t.fontFamily||F.fontFamily,t.orientation,t.multiline,()=>{},e=>{t.text=e,this.currentAction instanceof Ct&&(this.currentAction.to=e,this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0)})}createInputField(e,t,n,r,i,a,o,s,c,l){this.removeInputField();let u=this.selectCanvasElements().append(`foreignObject`).attr(`x`,`${t[0]}px`).attr(`y`,`${t[1]}px`).attr(`width`,`${n}px`).attr(`height`,`${r}px`).style(`box-sizing`,`border-box`).style(`border`,`1px solid`);this.inputFieldContainer=u;let d=u.append(`xhtml:textarea`),f,p;d.text(e).style(`box-sizing`,`border-box`).style(`width`,`${n}px`).style(`height`,`${r}px`).style(`font-size`,`${i}px`).style(`font-family`,a).style(`resize`,`none`).style(`outline`,0).style(`border`,0).style(`margin`,0).style(`padding`,0).on(x.KeyDown,e=>{if(e.stopPropagation(),e.key===S.Escape||e.key===S.Enter&&!s){let e=d.property(`value`)||``;this.removeInputField(),l&&l(e)}}).on(x.KeyUp,e=>{e.stopPropagation()}).on(x.Input,e=>{let t=d.property(`value`);d.attr(`cols`,_e(t)+1),d.attr(`rows`,ve(t)+1),d.style(`width`,``),d.style(`height`,``),f=d.property(`scrollWidth`)+1,p=d.property(`scrollHeight`)+1;let i=Math.max(f,n),a=Math.max(p,r);u?.attr(`width`,`${i}px`),d.style(`width`,`${i}px`),u?.attr(`height`,`${a}px`),d.style(`height`,`${a}px`),c&&c(t)}).on(x.Click,e=>{e.stopPropagation()}).on(x.FocusOut,()=>{let e=d.property(`value`);this.removeInputField(),l&&l(e)});let m=d.node();m.focus(),m.select()}removeInputField(){this.inputFieldContainer?.select(`input`)?.on(x.Blur,null),this.inputFieldContainer?.remove(),this.inputFieldContainer=void 0}minimumSizeOfField(e){let t=e.select()?.select(`text`)?.node();if(!t)return[0,0];let n=t.getBoundingClientRect();return[n.width/this.zoomTransform.k,n.height/this.zoomTransform.k]}setFieldTextAndWrap(e){let t=e.select()?.select(`text`),n=t?.node();if(t&&n)this.setFieldText(e,t,e.text);else return;if(e.fit)return;let r=this.minimumSizeOfField(e);for(;r[0]>e.width||r[1]>e.height;){let n=t?.html()?.replace(/<\/tspan>/g,`
3
+ `)?.replace(/<tspan[^>]*>/g,``)?.slice(0,-1)||``,i=`...`;if(i=n.endsWith(`...`)?n.slice(0,-4)+`...`:n.slice(0,-1)+`...`,t&&this.setFieldText(e,t,i),i===`...`)return;r=this.minimumSizeOfField(e)}}setFieldText(e,t,n){let r=n.split(`
4
+ `);t.html(``);for(let n=0;n<r.length;++n)t.append(`tspan`).attr(`x`,e.horizontalAlign===m.Center?e.width/2:e.horizontalAlign===m.Right?e.width:0).attr(`y`,e.verticalAlign===h.Center?(n+.5-r.length/2)*e.fontSize+e.height/2:e.verticalAlign===h.Bottom?e.height-(r.length-n-1)*e.fontSize:n*e.fontSize).text(r[n])}startMovingNode(e,t){if(this.canUserPerformAction(K.MoveNode)&&!t.removed)if(Z(O.Grabbing),this.draggingFrom=[e.x,e.y],t.selected&&this.userSelection.count(e=>e instanceof U)>1)this.currentAction=new bt(this,this.userSelection.filter(e=>e instanceof U).map(e=>e.id),t.coords);else{let e=t.getLastAncestor();this.currentAction=new q(this,K.MoveNode,t.id,t.getGeometry(),t.getGeometry(),e?.id,e?.getGeometry(t.id),e?.getGeometry(t.id))}else Z(O.NotAllowed)}continueMovingNode(e,t){if(this.canUserPerformAction(K.MoveNode)&&(this.currentAction instanceof bt||this.currentAction instanceof q)&&!t.removed){let n=[e.x-t.width/2,e.y-t.height/2];t.selected?this.userSelection.move([n[0]-t.coords[0],n[1]-t.coords[1]]):t.move(n),this.userHighlight.clear(),this.dragging=!0,this.diagramEvent$.next(new Mt(t))}}finishMovingNode(e,t){if(this.canUserPerformAction(K.MoveNode)&&!t.removed&&(this.draggingFrom[0]!==e.x||this.draggingFrom[1]!==e.y)){let n=[e.x-t.width/2,e.y-t.height/2];if(this.snapToGrid&&(n=this.getClosestGridPoint([n[0]-t.type.snapToGridOffset[0],n[1]-t.type.snapToGridOffset[1]]),n[0]+=t.type.snapToGridOffset[0],n[1]+=t.type.snapToGridOffset[1]),this.currentAction instanceof bt){let e=this.currentAction.delta;this.currentAction.delta=[n[0]-e[0],n[1]-e[1]],t.selected?this.userSelection.move([e[0]-t.coords[0],e[1]-t.coords[1]]):t.move(e)}else if(this.currentAction instanceof q){t.move(n);let r=Ye(this.model.nodes.getAtCoordinates(e.x,e.y).filter(e=>e.id!==t.id&&!e.isDescendantOf(t)).filter(e=>e.type.childrenTypes.includes(t.type.id))),i=r[r.length-1];if(i!==t.parent&&(t.type.canBeParentless||i!==void 0)){let e=i?.getLastAncestor(),n=this.currentAction.from,r=new xt(this,t.id,t.parent?.id,i?.id,n,t.getGeometry(),e?.id,e?.getGeometry(t.id),e?.getGeometry(t.id));t.parent?.removeChild(t),i!==void 0&&i.addChild(t),r.toChildGeometry=t.getGeometry(t.id),r.toAncestorGeometry=e?.getGeometry(t.id),this.currentAction=r}else{let e=t?.getLastAncestor();this.currentAction.ancestorId=e?.id,this.currentAction.fromAncestorGeometry=e?.getGeometry(t.id),t.parent?.fitToChild(t),this.currentAction.to=t.getGeometry(t.id),this.currentAction.toAncestorGeometry=e?.getGeometry(t.id)}}this.currentAction!==void 0&&(this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0)}Z(),this.dragging=!1}startMultipleSelection(e){this.draggingFrom=this.getPointerLocationRelativeToCanvas(e),this.multipleSelectionContainer=this.selectSVGElement().append(`rect`).attr(`stroke`,`#0E74B6`).attr(`fill`,`rgba(14, 116, 182, 0.06)`)}continueMultipleSelection(e){let t=this.getPointerLocationRelativeToCanvas(e);(this.draggingFrom[0]!==t[0]||this.draggingFrom[1]!==t[1])&&(Z(O.Crosshair),this.multipleSelectionContainer?.attr(`x`,Math.min(this.draggingFrom[0],t[0])*this.zoomTransform.k+this.zoomTransform.x)?.attr(`y`,Math.min(this.draggingFrom[1],t[1])*this.zoomTransform.k+this.zoomTransform.y)?.attr(`width`,Math.abs(this.draggingFrom[0]-t[0])*this.zoomTransform.k)?.attr(`height`,Math.abs(this.draggingFrom[1]-t[1])*this.zoomTransform.k),this.dragging=!0)}finishMultipleSelection(e){let t=this.getPointerLocationRelativeToCanvas(e);this.multipleSelectionContainer?.remove(),this.multipleSelectionContainer=void 0,this.userSelection.clear();for(let e of this.model.nodes)ee([e.coords,[e.coords[0]+e.width,e.coords[1]+e.height]],[this.draggingFrom,t])&&this.userSelection.add(e);this.multipleSelectionOn=!1,this.diagramEvent$.next(new J(this.userSelection.all(),!0)),Z()}},an=class{constructor(){this.grid=[[void 0]],this.offsetX=0,this.offsetY=0}minX(){return-this.offsetX}maxX(){return this.width()-1-this.offsetX}minY(){return-this.offsetY}maxY(){return this.height()-1-this.offsetY}width(){return this.grid[0].length}height(){return this.grid.length}addColumnLeft(){for(let e of this.grid)e.splice(0,0,void 0);this.offsetX+=1}addColumnRight(){for(let e of this.grid)e.push(void 0)}addRowTop(){let e=[];for(let t=0;t<this.grid[0].length;++t)e.push(void 0);this.grid.splice(0,0,e),this.offsetY+=1}addRowBottom(){let e=[];for(let t=0;t<this.grid[0].length;++t)e.push(void 0);this.grid.push(e)}get(e){if(this.grid[e[1]+this.offsetY])return this.grid[e[1]+this.offsetY][e[0]+this.offsetX]}set(e,t){for(;e[0]<-this.offsetX;)this.addColumnLeft();for(;e[0]>=this.width()-this.offsetX;)this.addColumnRight();for(;e[1]<-this.offsetY;)this.addRowTop();for(;e[1]>=this.height()-this.offsetY;)this.addRowBottom();this.grid[e[1]+this.offsetY][e[0]+this.offsetX]=t}getClosestEmptyCoordinate(e){if(this.get(e)===void 0)return e;let t=[...e];for(let e=1;;++e){let n=e%2>0?e:-e,r=n>0?1:-1,i=[t[0]+n,t[1]+n];for(let e=t[0];e!==i[0]+r;e+=r)if(t[0]=e,this.get(t)===void 0)return t;for(let e=t[1];e!==i[1]+r;e+=r)if(t[1]=e,this.get(t)===void 0)return t}}},on=class{constructor(e){this.gapSize=e}apply(e){if(e.nodes.length===0)return e;let t=new an,n=e.nodes.filter(e=>!e.parent);for(;n.length>0;)sn(n[0],t,[0,0],n);let r=Math.max(...e.nodes.map(e=>e.width)),i=Math.max(...e.nodes.map(e=>e.height)),a=this.gapSize===void 0?(e.canvas?.gridSize||0)*2:this.gapSize;for(let e=t.minY();e<=t.maxY();++e)for(let n=t.minX();n<=t.maxX();++n){let o=t.get([n,e]);o!==void 0&&o.move([n*(r+a),e*(i+a)])}return e}},sn=(e,t,n,r)=>{let i=t.getClosestEmptyCoordinate(n);t.set(i,e),E(r,e);for(let n of e.getAdjacentNodes())r.includes(n)&&sn(n,t,i,r)},cn=class{constructor(e){this.gapSize=e}apply(e){if(e.nodes.length===0)return e;let t=new an,n=e.nodes.filter(e=>!e.parent),r={},i=n[0],a=[i];for(r[i.id]=[0,0];n.length>0;){let e=[];for(let i of a){t.set(t.getClosestEmptyCoordinate(r[i.id]),i),E(n,i);let a=i.getAdjacentNodes();for(let t of a)n.includes(t)&&(e.push(t),r[t.id]=r[i.id])}if(e.length>0)a=e;else if(n.length>0){let e=n[0];a=[e],r[e.id]=t.getClosestEmptyCoordinate([0,0])}}let o=Math.max(...e.nodes.map(e=>e.width)),s=Math.max(...e.nodes.map(e=>e.height)),c=this.gapSize===void 0?(e.canvas?.gridSize||0)*2:this.gapSize;for(let e=t.minY();e<=t.maxY();++e)for(let n=t.minX();n<=t.maxX();++n){let r=t.get([n,e]);r!==void 0&&r.move([n*(o+c),e*(s+c)])}return e}},ln=class{constructor(e){this.gapSize=e}apply(e){if(e.nodes.length===0)return e;let t=this.gapSize===void 0?(e.canvas?.gridSize||0)*2:this.gapSize,n=e.nodes.filter(e=>!e.parent),r=n[0];E(n,r);let i=[[r]];for(;n.length>0;){let e=i[i.length-1],t=[];for(let r of e){let e=r.getAdjacentNodes();for(let r of e)n.includes(r)&&(E(n,r),t.push(r))}t.length>0?i.push(t):(i.push(n),n=[])}let a=0;for(let e of i){let n=0;for(let r of e)r.move([a,n]),n+=t+r.height;let r=Math.max(...e.map(e=>e.width));a+=t+r}for(let t of e.connections)t.tighten();return e}},un=class{constructor(e){this.gapSize=e}apply(e){if(e.nodes.length===0)return e;new ln(this.gapSize).apply(e);let t=this.gapSize===void 0?(e.canvas?.gridSize||0)*2:this.gapSize,n=.1,r=.5,i=.002,a=100;for(;a>1;){a*=.99;let o=[0,0];if(i>0){for(let t of e.nodes)o[0]=o[0]+t.coords[0]+t.width/2,o[1]=o[1]+t.coords[1]+t.width/2;o[0]/=e.nodes.length,o[1]/=e.nodes.length}for(let s of e.nodes){let c=s.getAdjacentNodes();for(let l of e.nodes){let e=[s.coords[0]+s.width/2,s.coords[1]+s.height/2],u=[l.coords[0]+l.width/2,l.coords[1]+l.height/2],d=b(s.coords,l.coords),f=[l.coords[0],l.coords[1]];if(c.includes(l)&&d>0&&(d>t+(Math.max(s.width,s.height)+Math.max(l.width,l.height))/2?(f[0]-=(u[0]-e[0])*n,f[1]-=(u[1]-e[1])*n):(f[0]+=(u[0]-e[0])*r,f[1]+=(u[1]-e[1])*r)),d>0){let t=2e5/(d*d);f[0]+=t*(u[0]-e[0])/d,f[1]+=t*(u[1]-e[1])/d}else f[0]+=1*(Math.random()*2-1),f[1]+=1*(Math.random()*2-1);i>0&&(f[0]-=(u[0]-o[0])*i,f[1]-=(u[1]-o[1])*i),f[0]-l.coords[0]>a?f[0]=l.coords[0]+a:f[0]-l.coords[0]<-a&&(f[0]=l.coords[0]-a),f[1]-l.coords[1]>a?f[1]=l.coords[1]+a:f[1]-l.coords[1]<-a&&(f[1]=l.coords[1]-a),l.move(f)}}}if(e.canvas&&e.canvas.snapToGrid)for(let t of e.nodes){let n=e.canvas.getClosestGridPoint([t.coords[0]-t.type.snapToGridOffset[0],t.coords[1]-t.type.snapToGridOffset[1]]);n[0]+=t.type.snapToGridOffset[0],n[1]+=t.type.snapToGridOffset[1],t.move(n)}for(let t of e.connections)t.tighten();return e}},dn=class{constructor(e){this.gapSize=e}apply(e){if(e.nodes.length===0)return e;let t=this.gapSize===void 0?(e.canvas?.gridSize||0)*2:this.gapSize,n=e.nodes.filter(e=>!e.parent);n.sort((e,t)=>t.type.priority-e.type.priority);let r=0;for(let e of n)e.move([r,0]),r+=e.width+t;return e}},fn=class{constructor(e){this.gapSize=e}apply(e){if(e.nodes.length===0)return e;let t=Math.max(...e.nodes.map(e=>e.getPriority()));if(t===Math.min(...e.nodes.map(e=>e.getPriority())))return new ln(this.gapSize).apply(e),e;let n=this.gapSize===void 0?(e.canvas?.gridSize||0)*2:this.gapSize,r=e.nodes.filter(e=>!e.parent),i=[],a=e.nodes.filter(e=>!e.parent).filter(e=>e.getPriority()>=t),o=[];if(a.length>1){let e=a[0];a.splice(0,1),o.push(e);let t=[e],n=[e];for(;t.length>0;){let e=t[0];t.splice(0,1),a.includes(e)&&(o.push(e),E(a,e));let r=e.getAdjacentNodes();for(let e of r)n.includes(e)||(t.push(e),n.push(e))}for(let e of a)o.push(e)}else o.push(a[0]);for(let e of o)E(r,e),i.push([e]);for(i.push([]),r.sort((e,t)=>t.type.priority-e.type.priority);r.length>0;){let e=r[0];r.splice(0,1);let t=[e],n=[e],a=!1;for(;t.length>0;){let r=t[0];t.splice(0,1);let s=o.indexOf(r);if(s>=0){i[s].push(e),a=!0;break}else{let e=r.getAdjacentNodes();for(let r of e)n.includes(r)||(t.push(r),n.push(r))}}a||i[i.length-1].push(e)}let s=0;for(let e=0;e<i.length;++e){let t=0;for(let r=0;r<i[e].length;++r){let a=i[e][r];a.move([s,t]),t+=n+a.height}let r=Math.max(...i[e].map(e=>e.width));s+=n+r}for(let t of e.connections)t.tighten();return e}},pn=class{constructor(e){this.gapSize=e}apply(e){if(e.nodes.length===0)return e;if(Math.max(...e.nodes.map(e=>e.getPriority()))===Math.min(...e.nodes.map(e=>e.getPriority())))return new ln(this.gapSize).apply(e),e;let t=this.gapSize===void 0?(e.canvas?.gridSize||0)*2:this.gapSize,n=e.nodes.filter(e=>!e.parent).sort((e,t)=>t.getPriority()-e.getPriority()),r=[];for(;n.length>0;){let e=n[0];n.splice(0,1);let t=new gn(void 0,e);mn(t,n),r.push(t)}let i=[];for(let e of r)i.push([e]),hn(e,i,i.length);let a=Math.max(...e.nodes.map(e=>e.height)),o=0;for(let e=0;e<i.length;++e){let n=0;for(let r=0;r<i[e].length;++r){let s=i[e][r];s.node.move([o,n]),n+=(t+a)*s.countBranchHeight()}let r=Math.max(...i[e].map(e=>e.node.width));o+=t+r}for(let t of e.connections)t.tighten();return e}},mn=(e,t)=>{for(let n of e.node.getAdjacentNodes().sort((e,t)=>t.getPriority()-e.getPriority())){let r=t.indexOf(n);r>=0&&(t.splice(r,1),mn(e.addBranch(n),t))}},hn=(e,t,n)=>{if(e.branches.length>0){for(;n>=t.length;)t.push([]);for(let r of e.branches)t[n].push(r),hn(r,t,n+1)}},gn=class e{constructor(e,t){this.parent=e,this.branches=[],this.depth=0,this.node=t}addBranch(t){let n=new e(this,t);return n.depth=this.depth+1,this.branches.push(n),n}countBranchHeight(){if(this.branches.length<=0)return 1;{let e=0;for(let t of this.branches)e+=t.countBranchHeight();return e}}},_n=class{constructor(e){this.gapSize=e}apply(e){if(e.nodes.length===0)return e;let t=this.gapSize===void 0?(e.canvas?.gridSize||0)*2:this.gapSize,n=e.nodes.filter(e=>!e.parent);n.sort((e,t)=>t.type.priority-e.type.priority);let r=0;for(let e of n)e.move([0,r]),r+=e.height+t;return e}},vn={adjacency:new on,breadth:new ln,"breadth-adjacency":new cn,force:new un,horizontal:new dn,priority:new fn,tree:new pn,vertical:new _n},yn=(0,u.createContext)({}),bn=(0,u.createContext)({}),xn=class{constructor(e,t){this.onTitleChange=e,this.onValueSetChange=t}get title(){return this._title}set title(e){this._title=e,this.onTitleChange(e)}get valueSet(){return this._valueSet}set valueSet(e){this._valueSet=e,this.onValueSetChange(e)}highlightProperty(...e){}},Sn=({direction:e,collapsableSelector:t,collapsableAdditionalSelector:n,collapsed:r,disabled:i,rule:a,collapsedValue:o,visibleValue:s,onCollapse:l})=>{let[p,m]=(0,u.useState)(r);return(0,d.jsx)(`daga-collapse-button`,{children:(0,d.jsx)(`button`,{className:`daga-collapse-button daga-${e}`,onClick:()=>{if(!i){let e=!p;m(e),l?.(e);let r;if(typeof t==`string`)r=c.select(t),n&&(r=r.select(n));else{let e=t;if(!e)throw Error(`collapsableSelector is not a valid ref`);r=c.select(e.current),n&&(r=r.select(n))}r.style(a,e?o:s)}},children:(0,d.jsx)(`div`,{className:(()=>{switch(e){case f.Right:return i?`daga-horizontal-none`:p?`daga-horizontal-right`:`daga-horizontal-left`;case f.Bottom:return i?`daga-vertical-none`:p?`daga-vertical-down`:`daga-vertical-up`;case f.Left:return i?`daga-horizontal-none`:p?`daga-horizontal-left`:`daga-horizontal-right`;case f.Top:return i?`daga-vertical-none`:p?`daga-vertical-up`:`daga-vertical-down`}})()})})})},Cn=()=>{let e=(0,u.useContext)(bn),t=(0,u.useRef)(null),[n,r]=(0,u.useState)([]);(0,l.merge)(e.validatorChange$,e.diagramChange$).pipe((0,l.map)(()=>i())).subscribe();let i=()=>{r([]);for(let t of e.validators)r(t.validate(e.model))},a=t=>{if(t.elementId&&(t.propertyNames===void 0||t.propertyNames.length===0)){let n=e.model.nodes.get(t.elementId)||e.model.connections.get(t.elementId);n&&e.userHighlight.add(n)}else if(t.elementId&&t.propertyNames!==void 0&&t.propertyNames.length>0){e.userSelection.openInPropertyEditor(e.model.nodes.get(t.elementId)||e.model.connections.get(t.elementId));let n=e.model.nodes.get(t.elementId)||e.model.connections.get(t.elementId);n&&e.userHighlight.add(n),e.parentComponent?.propertyEditor?.highlightProperty(...t.propertyNames)}else !t.elementId&&t.propertyNames!==void 0&&t.propertyNames.length>0&&(e.userSelection.openInPropertyEditor(),e.parentComponent?.propertyEditor?.highlightProperty(...t.propertyNames))};return(0,d.jsx)(`daga-errors`,{children:(0,d.jsxs)(`div`,{ref:t,className:`daga-errors`,children:[n.length===0&&(0,d.jsx)(`div`,{className:`daga-errors-summary daga-no-errors daga-prevent-user-select`,children:(0,d.jsx)(`span`,{children:`No errors found`})}),n.length>0&&(0,d.jsxs)(`div`,{className:`daga-errors-summary daga-with-errors daga-prevent-user-select`,children:[(0,d.jsxs)(`span`,{children:[n.length,` errors found`]}),(0,d.jsx)(`div`,{className:`daga-collapse-button-container`,children:(0,d.jsx)(Sn,{collapsableSelector:t,collapsableAdditionalSelector:`.daga-error-panel`,direction:f.Top,rule:`display`,collapsedValue:`none`,visibleValue:`block`,collapsed:!1,disabled:!1})})]}),n.length>0&&(0,d.jsx)(`div`,{className:`daga-error-panel`,children:(0,d.jsx)(`ol`,{children:n.map((e,t)=>(0,d.jsx)(`li`,{onClick:()=>a(e),dangerouslySetInnerHTML:{__html:e.message}},t))})})]})})},wn=200,Tn=e=>(e||``).toLowerCase().normalize(`NFD`).replace(/[\u0300-\u036f]/g,``),En=({disabled:e,options:t,value:n,onChange:r})=>{let i=(0,u.useRef)(null),[a,o]=(0,u.useState)(``),[s,c]=(0,u.useState)(void 0),[l,f]=(0,u.useState)([]),[p,m]=(0,u.useState)([]),[h,g]=(0,u.useState)([]),[_,v]=(0,u.useState)([]),[y,b]=(0,u.useState)(!1);(0,u.useEffect)(()=>{o(t.find(e=>je(e.key,n))?.label||``)},[n,t]);let ee=n=>{if(!e)switch(n.key){case S.PageDown:s===void 0?(w(0),T(0)):(w(s+5),T(s)),n.preventDefault();break;case S.ArrowDown:s===void 0?(w(0),T(0)):(w(s+1),T(s)),n.preventDefault();break;case S.PageUp:s===void 0?(w(t.length-1),T(t.length-1)):(w(s-5),T(s)),n.preventDefault();break;case S.ArrowUp:s===void 0?(w(t.length-1),T(t.length-1)):(w(s-1),T(s)),n.preventDefault();break;case S.Escape:C(),n.preventDefault();break;case S.Enter:re(t[s||0]),n.preventDefault();break;default:x()}},x=()=>{if(!e){let e=Tn(a.trim());f([]),m([]),g([]),v([]);for(let n of t){let t=Tn(n.label).indexOf(e);if(t>=0){let r=n.label.substring(0,t),i=n.label.substring(t,t+e.length),a=n.label.substring(t+e.length);f(e=>[...e,n]),m(e=>[...e,r]),g(e=>[...e,i]),v(e=>[...e,a])}}b(!0)}},C=()=>{b(!1)},w=n=>{if(!e){let e=n;if(n===void 0){c(void 0);return}n<0&&(e=0),n>=t.length&&(e=t.length-1),c(e)}},te=()=>{setTimeout(()=>{C()},wn)},T=e=>{let t=i.current?.querySelectorAll(`li`)[e];t&&t.scrollIntoView({block:`center`})},ne=()=>{e||(o(``),b(!1),c(void 0))},re=t=>{e||(o(t.label),b(!1),c(void 0),r(t.key))};return(0,d.jsxs)(`div`,{ref:i,className:`daga-autocomplete ${y?`daga-showing-options`:``}`,children:[(0,d.jsxs)(`div`,{className:`daga-autocomplete-input`,children:[(0,d.jsx)(`input`,{value:a,disabled:e,onKeyUp:ee,onFocus:x,onBlur:te,onChange:e=>o(e.target.value)}),a!==``&&(0,d.jsx)(`button`,{className:`daga-clear`,onClick:ne})]}),(0,d.jsx)(`div`,{className:`daga-autocomplete-options`,children:(0,d.jsxs)(`ul`,{className:`daga-autocomplete-option-list`,children:[l.length===0&&(0,d.jsx)(`li`,{className:`daga-autocomplete-option no-options`,children:`(No options)`}),l.map((e,t)=>(0,d.jsxs)(`li`,{className:`daga-autocomplete-option ${t===s?`daga-focused`:``}`,onMouseMove:()=>w(t),onClick:()=>re(e),children:[(0,d.jsx)(`span`,{children:p[t]}),(0,d.jsx)(`span`,{className:`daga-match`,children:h[t]}),(0,d.jsx)(`span`,{children:_[t]})]},t))]})})]})},Dn=(e,t)=>e.find(e=>e.key===t)?.label||`${t}`,On=({disabled:e,allowRepeats:t,options:n,value:r,onChange:i})=>{let[a,o]=(0,u.useState)(),[s,c]=(0,u.useState)([]),[l,f]=(0,u.useState)([]),p=e=>{for(let t of r)if(t===e)return!0;return!1},m=()=>{if(!t){let e=[];for(let t of n)p(t.key)||e.push(t);f(e)}};(0,u.useEffect)(()=>{let e=r.length===0;c(r.map(e=>Dn(n,e))),e&&i(r),m()},[r,n]);let h=e=>{r.length>e&&(r.splice(e,1),c(s.filter((t,n)=>n!==e)),i(r),m())},g=()=>{a!==void 0&&(t||!p(a))&&(i(r.concat(a)),_())},_=()=>{o(``)};return(0,d.jsxs)(`div`,{children:[r.map((t,n)=>(0,d.jsxs)(`div`,{className:`daga-value-item-element`,children:[(0,d.jsx)(`span`,{className:`daga-input`,children:s[n]}),!e&&(0,d.jsx)(`button`,{className:`daga-property-button`,onClick:()=>h(n),children:(0,d.jsx)(`div`,{className:`daga-icon daga-close-icon`})})]},n)),!e&&(0,d.jsxs)(`div`,{className:`daga-value-item-input`,children:[(0,d.jsx)(`div`,{className:`daga-input daga-relatively-positioned`,children:(0,d.jsx)(En,{disabled:e,options:t?n||[]:l||[],value:a,onChange:o})}),(0,d.jsx)(`button`,{className:`daga-property-button`,onClick:g,children:(0,d.jsx)(`div`,{className:`daga-icon daga-add-icon`})})]})]})},kn=({disabled:e,allowRepeats:t,value:n,onChange:r})=>{let[i,a]=(0,u.useState)(``),o=e=>{for(let t of e||[])if(t===e)return!0;return!1},s=e=>{n.length>e&&r(n.filter((t,n)=>n!==e))},c=(e,t,i)=>{r(n.map((n,r)=>r===t?i===`blur`?e.trim():e:n))},l=()=>{let e=i.trim();e!==``&&(t||!o(e))&&(r(n.concat(e)),f())},f=()=>{a(``)};return(0,d.jsxs)(d.Fragment,{children:[n.map((t,n)=>(0,d.jsxs)(`div`,{className:`daga-value-item-element`,children:[(0,d.jsx)(`input`,{className:`daga-input`,disabled:e,value:t,onChange:e=>c(e.target.value,n,`change`),onBlur:e=>c(e.target.value,n,`blur`)}),(0,d.jsx)(`button`,{className:`daga-property-button`,onClick:()=>s(n),children:(0,d.jsx)(`div`,{className:`daga-icon daga-close-icon`})})]},n)),!e&&(0,d.jsxs)(`div`,{className:`daga-value-item-input`,children:[(0,d.jsxs)(`div`,{className:`daga-input daga-relatively-positioned`,children:[(0,d.jsx)(`input`,{type:`text`,onKeyUp:e=>{e.key===`Enter`&&l()},value:i,onChange:e=>a(e.target.value)}),(0,d.jsx)(`button`,{className:`daga-clear`,onClick:f})]}),(0,d.jsx)(`button`,{className:`daga-property-button`,onClick:l,children:(0,d.jsx)(`div`,{className:`daga-icon daga-add-icon`})})]})]})},An=({disabled:e,value:t,onChange:n})=>{let[r,i]=(0,u.useState)(``),[a,o]=(0,u.useState)(``),[s,c]=(0,u.useState)({}),l=e=>{let r={};Object.keys(t).forEach(n=>{n!==e&&(r[n]=t[n])}),n(r)},f=(e,r,i)=>{let a=i===`blur`?r.trim():r;if(i===`blur`){if(e!==a){let r={};Object.keys(t).forEach(n=>{n===e?r[a]=t[n]:r[n]=t[n]}),n(r),c(t=>{let n={...t};return delete n[e],n})}}else c(t=>({...t,[e]:r}))},p=(e,r,i)=>{let a=i===`blur`?r.trim():r;if(a!==``){let r={};Object.keys(t).forEach(n=>{n===e?r[n]=a:r[n]=t[n]}),n(r)}},m=()=>{let e=r.trim(),s=a.trim();if(e!==``&&s!==``){let r={};Object.keys(t).forEach(e=>{r[e]=t[e]}),r[e]=s,n(r),i(``),o(``)}},h=()=>{i(``)},g=()=>{o(``)},_=e=>{e.key===`Enter`&&m()};return(0,d.jsxs)(`div`,{children:[Object.entries(t).map(([t,n],r)=>(0,d.jsxs)(`div`,{className:`daga-value-item-element`,children:[(0,d.jsx)(`input`,{id:`key-${r}`,className:`daga-input`,type:`text`,disabled:e,value:s[t]??t,onChange:e=>f(t,e.target.value,`change`),onBlur:e=>f(t,e.target.value,`blur`)}),(0,d.jsx)(`input`,{id:`value-${r}`,className:`daga-input`,type:`text`,disabled:e,value:n,onChange:e=>p(t,e.target.value,`change`),onBlur:e=>p(t,e.target.value,`blur`)}),(0,d.jsx)(`button`,{className:`daga-property-button`,onClick:()=>l(t),children:(0,d.jsx)(`div`,{className:`daga-icon daga-close-icon`})})]},t)),!e&&(0,d.jsxs)(`div`,{className:`daga-value-item-input`,children:[(0,d.jsxs)(`div`,{className:`daga-input daga-relatively-positioned`,children:[(0,d.jsx)(`input`,{type:`text`,value:r,onKeyUp:_,onChange:e=>i(e.target.value),onBlur:e=>f(r,e.target.value,`blur`)}),(0,d.jsx)(`button`,{className:`daga-clear`,onClick:h})]}),(0,d.jsxs)(`div`,{className:`daga-input daga-relatively-positioned`,children:[(0,d.jsx)(`input`,{type:`text`,value:a,onKeyUp:_,onChange:e=>o(e.target.value),onBlur:e=>p(r,e.target.value,`blur`)}),(0,d.jsx)(`button`,{className:`daga-clear`,onClick:g})]}),(0,d.jsx)(`button`,{className:`daga-property-button`,onClick:m,children:(0,d.jsx)(`div`,{className:`daga-icon daga-add-icon`})})]})]})},jn=({valueSet:e,onValueChange:t,depth:n})=>{let r=(0,u.useContext)(bn).canUserPerformAction(K.UpdateValues)&&e?.rootElement?.removed!==!0,i=e=>`daga-property-name-`+e.replace(/\s/g,``),a=e=>{if(typeof e==`string`)return e;if(e==null||isNaN(e.valueOf()))return``;let t=new Date(e),n=t.getTimezoneOffset();return t.setMinutes(t.getMinutes()-n),t.toISOString().substring(0,19)},o=e=>new Date(e);return(0,d.jsx)(`daga-object-editor`,{children:e.displayedProperties.map(s=>(0,d.jsxs)(`div`,{className:`daga-property ${i(s.name)}`,children:[(0,d.jsx)(`p`,{className:`daga-property-name`,children:s.label||s.name}),s.type===M.Text&&(0,d.jsx)(`input`,{type:`daga-text`,disabled:s.editable===!1||!r,value:e?.getValue(s.name),onChange:n=>t(e,s,n.target.value)}),s.type===M.TextArea&&(0,d.jsx)(`textarea`,{disabled:s.editable===!1||!r,value:e?.getValue(s.name),onChange:n=>t(e,s,n.target.value)}),s.type===M.Number&&(0,d.jsx)(`input`,{type:`number`,disabled:s.editable===!1||!r,value:e?.getValue(s.name),onChange:n=>t(e,s,n.target.value)}),s.type===M.Color&&(0,d.jsx)(`input`,{type:`text`,pattern:`#[0-9a-fA-F]{6}`,disabled:s.editable===!1||!r,value:e?.getValue(s.name),onChange:n=>t(e,s,n.target.value)}),s.type===M.Datetime&&(0,d.jsx)(`input`,{type:`datetime-local`,disabled:s.editable===!1||!r,value:a(e?.getValue(s.name)),onChange:n=>t(e,s,o(n.target.value))}),s.type===M.Date&&(0,d.jsx)(`input`,{type:`date`,disabled:s.editable===!1||!r,value:e?.getValue(s.name),onChange:n=>t(e,s,n.target.value)}),s.type===M.Time&&(0,d.jsx)(`input`,{type:`time`,disabled:s.editable===!1||!r,value:e?.getValue(s.name),onChange:n=>t(e,s,n.target.value)}),s.type===M.Url&&(0,d.jsx)(`input`,{type:`url`,disabled:s.editable===!1||!r,value:e?.getValue(s.name),onChange:n=>t(e,s,n.target.value)}),s.type===M.Boolean&&(0,d.jsxs)(`div`,{className:`daga-radio`,children:[(0,d.jsxs)(`label`,{className:`daga-radio-item daga-radio-start`+(e?.getValue(s.name)===!1?` daga-checked`:``),children:[(0,d.jsx)(`input`,{type:`radio`,disabled:s.editable===!1||!r,name:s.name,value:`false`,checked:e?.getValue(s.name)===!1,onChange:()=>t(e,s,!1)}),`No`]}),(0,d.jsxs)(`label`,{className:`daga-radio-item daga-radio-end`+(e?.getValue(s.name)===!0?` daga-checked`:``),children:[(0,d.jsx)(`input`,{type:`radio`,disabled:s.editable===!1||!r,name:s.name,value:`true`,checked:e?.getValue(s.name)===!0,onChange:()=>t(e,s,!0)}),`Yes`]})]}),s.type===M.Option&&(0,d.jsx)(`div`,{className:`daga-relatively-positioned`,children:(0,d.jsx)(En,{disabled:s.editable===!1||!r,options:s.options||[],value:e?.getValue(s.name),onChange:n=>t(e,s,n)})}),(s.type===M.OptionList||s.type===M.OptionSet)&&(0,d.jsx)(On,{disabled:s.editable===!1||!r,allowRepeats:s.type===M.OptionList,options:s.options||[],value:e?.getValue(s.name),onChange:n=>t(e,s,n)}),(s.type===M.TextList||s.type===M.TextSet)&&(0,d.jsx)(kn,{disabled:s.editable===!1||!r,allowRepeats:s.type===M.TextList,value:e?.getValue(s.name),onChange:n=>t(e,s,n)}),s.type===M.TextMap&&(0,d.jsx)(An,{disabled:s.editable===!1||!r,value:e?.getValue(s.name),onChange:n=>t(e,s,n)}),s.type===M.Object&&(0,d.jsx)(`div`,{className:`daga-left-bar`,children:(0,d.jsx)(jn,{valueSet:e.getSubValueSet(s.name),onValueChange:t,depth:n+1})})]},s.name))})},Mn=({valueSet:e,depth:t})=>{let n=(0,u.useContext)(bn),r=(0,u.useRef)(null),i=e=>`daga-property-name-`+e.replace(/\s/g,``),a=()=>{for(let a of e?.displayedProperties||[]){let s=0,l=0,u=0,d=c.select(r.current).select(`.daga-property.${i(a.name)}.daga-depth-${t}`);d.select(`button.daga-move-button`).call(c.drag().on(C.Start,e=>{Z(O.Grabbing);let t=n.getPointerLocationRelativeToScreen(e);if(t.length<2||isNaN(t[0])||isNaN(t[1]))return;let r=d.node()?.getBoundingClientRect();s=r?.width||0,l=r?.height||0,d.style(`position`,`fixed`).style(`left`,`${t[0]-s/2}px`).style(`top`,`${t[1]-l/2}px`).style(`width`,`${s}px`).style(`height`,`${l}px`).style(`z-index`,1)}).on(C.Drag,e=>{Z(O.Grabbing);let i=n.getPointerLocationRelativeToScreen(e);i.length<2||isNaN(i[0])||isNaN(i[1])||(d.style(`position`,`fixed`).style(`left`,`${i[0]-s/2}px`).style(`top`,`${i[1]-l/2}px`).style(`width`,`${s}px`).style(`height`,`${l}px`).style(`z-index`,1),c.select(r.current).select(`.daga-dropbar.daga-index-${u}.daga-depth-${t}`).style(`visibility`,`hidden`).style(`height`,0),u=o(i),c.select(r.current).select(`.daga-dropbar.daga-index-${u}.daga-depth-${t}`).style(`visibility`,`visible`).style(`height`,`0.25rem`))}).on(C.End,i=>{Z(O.Auto),d.style(`position`,`relative`).style(`left`,0).style(`top`,0).style(`z-index`,0).style(`width`,`unset`).style(`height`,`unset`),c.select(r.current).select(`.daga-dropbar.daga-index-${u}.daga-depth-${t}`).style(`visibility`,`hidden`).style(`height`,0);let s=n.getPointerLocationRelativeToScreen(i);s.length<2||isNaN(s[0])||isNaN(s[1])||(u=o(s),e?.displayedProperties?.splice(e.displayedProperties.indexOf(a),1),e?.displayedProperties?.splice(u,0,a))}))}},o=n=>{let i=e?.propertySet.propertyList||[],a=[];for(let e=0;e<=i.length;++e){let n=c.select(r.current).select(`.daga-dropbar.daga-index-${e}.daga-depth-${t}`).node()?.getBoundingClientRect();n&&a.push([n.x+n.width/2,n.y+n.height/2])}if(a.length>0){let e=a.map(e=>((n[0]-e[0])**2+(n[1]-e[1])**2)**.5);return e.indexOf(Math.min(...e))}return 0},s=t=>{if(e===void 0)return;let n;n=t instanceof De?t:t instanceof Event?e?.propertySet.getProperty(t.target?.value||``):e?.propertySet.getProperty(t||``),n&&e?.hideProperty(n),a()};return(0,d.jsxs)(`daga-property-settings`,{ref:r,children:[(0,d.jsx)(`div`,{className:`daga-dropbar daga-index-0 daga-depth-${t}`}),e?.displayedProperties.map((n,r)=>(0,d.jsxs)(`div`,{className:`daga-property-and-dropbar ${i(n.name)} daga-depth-${t}`,children:[(0,d.jsxs)(`div`,{className:`daga-property ${i(n.name)} daga-depth-${t}`,children:[(0,d.jsxs)(`div`,{className:`daga-property-name`,children:[(0,d.jsx)(`span`,{children:n.label||n.name}),(0,d.jsxs)(`div`,{className:`daga-buttons`,children:[(0,d.jsx)(`button`,{className:`daga-property-button daga-move-button`,children:(0,d.jsx)(`div`,{className:`daga-icon daga-move-icon`})}),(0,d.jsx)(`button`,{className:`daga-property-button daga-hide-button`,onClick:()=>s(n.name),children:(0,d.jsx)(`div`,{className:`daga-icon daga-hide-icon`})})]})]}),n.type!==M.Object&&(0,d.jsx)(`div`,{className:`daga-property-value`,children:Nn(e?.getValue(n.name))}),n.type===M.Object&&(0,d.jsx)(Mn,{valueSet:e?.getSubValueSet(n.name),depth:t+1})]}),(0,d.jsx)(`div`,{className:`daga-dropbar daga-index-${r+1} daga-depth-${t}`})]},n.name))]})},Nn=e=>Array.isArray(e)?e.join(`, `):Ne(e)?Object.entries(e).map(e=>e.map(e=>JSON.stringify(e)).join(`: `)).join(`, `):e instanceof Date?e.toLocaleString():e==null?``:``+e,Pn=({location:e,direction:t,width:n,height:r,title:i,valueSet:a,onValueChange:o})=>{let s=(0,u.useRef)(null),[l,p]=(0,u.useState)(!1),[m,h]=(0,u.useState)(!1),g=()=>c.select(s.current);return(0,u.useEffect)(()=>{if(s.current)switch(t){case f.Bottom:case f.Top:g().style(`width`,n),r&&g().select(`.daga-panel-content`).style(`height`,r);break;case f.Left:case f.Right:g().style(`height`,n),r&&g().select(`.daga-panel-content`).style(`width`,r);break}},[n,r,t]),(0,d.jsx)(`daga-property-editor`,{children:(0,d.jsxs)(`div`,{ref:s,className:`daga-panel daga-bottom daga-${e} daga-${t}`,children:[(0,d.jsx)(Sn,{disabled:!a||!a.propertySet||!a.propertySet.hasProperties(),collapsed:l,direction:t,collapsableSelector:s,collapsableAdditionalSelector:`.daga-panel-content`,rule:`display`,collapsedValue:`none`,visibleValue:`block`,onCollapse:p}),(0,d.jsx)(`div`,{className:`daga-panel-content`,children:a&&a.propertySet&&a.propertySet.hasProperties()&&!l&&(0,d.jsxs)(`div`,{children:[i&&(0,d.jsxs)(`p`,{className:`daga-title`,children:[i,(0,d.jsx)(`button`,{className:`daga-property-button`,onClick:()=>h(!m),children:(0,d.jsx)(`div`,{className:`daga-icon daga-settings-icon ${m?`daga-unrotate`:`daga-rotate`}`})})]}),!m&&(0,d.jsx)(jn,{valueSet:a,onValueChange:o,depth:0}),m&&(0,d.jsx)(Mn,{valueSet:a,depth:0})]})})]})})},Fn=6,In=e=>{let t=(0,u.useContext)(bn),[n,r]=(0,u.useState)(e.currentPalette||e.palettes[0]),[i,a]=(0,u.useState)(0),[o,s]=(0,u.useState)(void 0),l=(0,u.useRef)(null),p=(0,u.useRef)(!1),m=e=>{if(r(e),h().selectAll(`*`).remove(),a(t.getPriorityThreshold()||0),e.categories&&g(e.categories),e.templates)for(let t of e.templates)_(t)},h=()=>c.select(l.current).select(`.daga-palette-view`),g=e=>{let t=h().append(`select`).style(`width`,`100%`).style(`height`,`2rem`).style(`padding`,`0.5rem`).style(`border-radius`,`0.25rem`).style(`background-color`,`#f7f8fc`).style(`border`,`1px solid #e6e6e6`);t.append(`option`).attr(`value`,``).text(`(None selected)`);for(let n in e)t.append(`option`).attr(`value`,n).text(n);t.on(x.Change,()=>{o&&h().selectAll(`.daga-template-container.daga-in-category`).remove();let n=t.property(`value`);s(n);let r=e[n]||[];for(let e of r)_(e,`daga-in-category`)}),o&&(t.property(`value`,o),t.dispatch(x.Change))},_=(e,n)=>{if(e.templateType===`node`){let r=t.model.nodes.types.get(e.type);r?v(r,e,n):console.error(`Could not find a node type called '${e.type}'`)}else if(e.templateType===`connection`){let r=t.model.connections.types.get(e.type);r?y(r,e,n):console.error(`Could not find a connection type called '${e.type}'`)}},v=(e,n,r)=>{if(i!==void 0&&e.priority<i)return;let a=e.defaultLook.lookType===`shaped-look`?e.defaultLook.borderThickness||1:0,o=e.defaultHeight+a,s=e.defaultWidth+a,l=n.height||o,u=n.width||s,d=h().append(`div`).attr(`class`,`daga-template-container ${r===void 0?``:r}`).style(`width`,`${u}px`).style(`height`,`${l}px`).call(c.drag().on(C.Drag,e=>{if(t.canUserPerformAction(K.AddNode)){let n=t.getPointerLocationRelativeToScreen(e);if(n.length<2||isNaN(n[0])||isNaN(n[1]))return;d.style(`position`,`fixed`).style(`left`,`${n[0]-u/2}px`).style(`top`,`${n[1]-l/2}px`).style(`z-index`,1)}}).on(C.Start,n=>{if(t.canUserPerformAction(K.AddNode)){Z(O.Grabbing);let r=t.getPointerLocationRelativeToScreen(n);if(r.length<2||isNaN(r[0])||isNaN(r[1]))return;d.style(`position`,`fixed`).style(`left`,`${r[0]-u/2}px`).style(`top`,`${r[1]-l/2}px`).style(`z-index`,1),e.isUnique&&t.model.nodes.find(t=>!t.removed&&t.type.id===e.id)!==void 0&&Z(O.NotAllowed)}}).on(C.End,r=>{if(t.canUserPerformAction(K.AddNode)){if(Z(O.Auto),d.style(`position`,`relative`).style(`left`,0).style(`top`,0).style(`z-index`,`auto`),e.isUnique&&t.model.nodes.find(t=>!t.removed&&t.type.id===e.id)!==void 0)return;let i=t.getPointerLocationRelativeToScreen(r);if(i.length<2||isNaN(i[0])||isNaN(i[1]))return;let a=document.elementFromPoint(i[0],i[1]);if(a&&!t.selectCanvasView().node()?.contains(a))return;let o=t.getPointerLocationRelativeToCanvas(r);if(o.length<2||isNaN(o[0])||isNaN(o[1]))return;let s=[o[0]-e.defaultWidth/2,o[1]-e.defaultHeight/2];t.snapToGrid&&(s=t.getClosestGridPoint([s[0]-e.snapToGridOffset[0],s[1]-e.snapToGridOffset[1]]),s[0]+=e.snapToGridOffset[0],s[1]+=e.snapToGridOffset[1]);let c=Ye(t.model.nodes.getAtCoordinates(o[0],o[1]).filter(t=>t.type.childrenTypes.includes(e.id))),l=c[c.length-1];if(!e.canBeParentless&&l===void 0)return;let u=l?.getLastAncestor(),f=new yt(t,e,s,l?.id,u?.id,u?.getGeometry(),void 0,n.label,n.values);f.do(),t?.actionStack.add(f),Z()}})).append(`svg`).attr(`class`,`palette-node ${e.id}`).attr(`viewBox`,`0 0 ${s} ${o}`).attr(`preserveAspectRatio`,`none`).style(`position`,`relative`).style(`left`,0).style(`top`,0).style(`width`,`${u}px`).style(`height`,`${l}px`),f=n.look||e.defaultLook;switch(f.lookType){case`shaped-look`:d.append(`path`).attr(`d`,oe(f.shape||D.Rectangle,(f.borderThickness||1)/2,(f.borderThickness||1)/2,e.defaultWidth,e.defaultHeight)).attr(`fill`,f.fillColor||`#FFFFFF`).attr(`stroke`,f.borderColor||`#000000`).attr(`stroke-width`,`${f.borderThickness}px`);break;case`image-look`:d.append(`image`).attr(`x`,0).attr(`y`,0).attr(`width`,e.defaultWidth).attr(`height`,e.defaultHeight).attr(`href`,f.backgroundImage).attr(`preserveAspectRatio`,`none`);break;case`stretchable-image-look`:d.append(`image`).attr(`x`,0).attr(`y`,0).attr(`width`,f.leftMargin).attr(`height`,f.topMargin).attr(`href`,f.backgroundImageTopLeft).attr(`preserveAspectRatio`,`none`),d.append(`image`).attr(`x`,f.leftMargin).attr(`y`,0).attr(`width`,e.defaultWidth-f.rightMargin-f.leftMargin).attr(`height`,f.topMargin).attr(`href`,f.backgroundImageTop).attr(`preserveAspectRatio`,`none`),d.append(`image`).attr(`x`,e.defaultWidth-f.rightMargin).attr(`y`,0).attr(`width`,f.rightMargin).attr(`height`,f.topMargin).attr(`href`,f.backgroundImageTopRight).attr(`preserveAspectRatio`,`none`),d.append(`image`).attr(`x`,0).attr(`y`,f.topMargin).attr(`width`,f.leftMargin).attr(`height`,e.defaultHeight-f.bottomMargin-f.topMargin).attr(`href`,f.backgroundImageLeft).attr(`preserveAspectRatio`,`none`),d.append(`image`).attr(`x`,f.leftMargin).attr(`y`,f.topMargin).attr(`width`,e.defaultWidth-f.rightMargin-f.leftMargin).attr(`height`,e.defaultHeight-f.bottomMargin-f.topMargin).attr(`href`,f.backgroundImageCenter).attr(`preserveAspectRatio`,`none`),d.append(`image`).attr(`x`,e.defaultWidth-f.rightMargin).attr(`y`,f.topMargin).attr(`width`,f.rightMargin).attr(`height`,e.defaultHeight-f.bottomMargin-f.topMargin).attr(`href`,f.backgroundImageRight).attr(`preserveAspectRatio`,`none`),d.append(`image`).attr(`x`,0).attr(`y`,e.defaultHeight-f.bottomMargin).attr(`width`,f.leftMargin).attr(`height`,f.bottomMargin).attr(`href`,f.backgroundImageBottomLeft).attr(`preserveAspectRatio`,`none`),d.append(`image`).attr(`x`,f.leftMargin).attr(`y`,e.defaultHeight-f.bottomMargin).attr(`width`,e.defaultWidth-f.rightMargin-f.leftMargin).attr(`height`,f.bottomMargin).attr(`href`,f.backgroundImageBottom).attr(`preserveAspectRatio`,`none`),d.append(`image`).attr(`x`,e.defaultWidth-f.rightMargin).attr(`y`,e.defaultHeight-f.bottomMargin).attr(`width`,f.rightMargin).attr(`height`,f.bottomMargin).attr(`href`,f.backgroundImageBottomRight).attr(`preserveAspectRatio`,`none`)}if(n.look===void 0){if(e.decorators)for(let t of e.decorators)d.append(`foreignObject`).attr(`width`,`${t.width}px`).attr(`height`,`${t.height}px`).attr(`transform`,`translate(${t.coords[0]},${t.coords[1]})`).html(t.html);if(n.label){let t={...F,...e.label,...n.labelLook};d.append(`text`).attr(`transform`,`translate(${(R(t)+e.defaultWidth)/2},${(B(t)+e.defaultHeight)/2})`).attr(`x`,0).attr(`y`,0).attr(`font-size`,`${t.fontSize}px`).attr(`text-anchor`,`middle`).attr(`font-family`,t.fontFamily).attr(`font-weight`,400).attr(`fill`,t.color).attr(`stroke`,`none`).style(`font-kerning`,`none`).style(`user-select`,`none`).text(n.label)}}},y=(e,n,r)=>{let i=h().append(`div`).attr(`class`,`daga-template-container ${r===void 0?``:r}`).style(`width`,`${n.width}px`).style(`height`,`${n.height}px`).append(`svg`).attr(`class`,`palette-button ${e.id}`).style(`position`,`relative`).style(`left`,0).style(`top`,0).style(`width`,`100%`).style(`height`,`100%`).on(`click`,()=>{t.connectionType=e});i.append(`path`).attr(`d`,oe(D.Rectangle,0,0,n.width,n.height)).attr(`fill`,n.backgroundColor).attr(`stroke`,`black`).attr(`stroke-width`,`1px`),n.icon!==``&&i.append(`image`).attr(`x`,0).attr(`y`,0).attr(`width`,n.width).attr(`height`,n.height).attr(`href`,n.icon),n.label!==``&&i.append(`text`).attr(`transform`,`translate(${n.width/2},${n.height/2+Fn})`).attr(`x`,0).attr(`y`,0).attr(`font-size`,`20px`).attr(`text-anchor`,`middle`).attr(`font-family`,`'Wonder Unit Sans', sans-serif`).attr(`font-weight`,400).attr(`fill`,`#000000`).attr(`stroke`,`none`).style(`font-kerning`,`none`).style(`user-select`,`none`).text(n.label)};return(0,u.useEffect)(()=>{e.palettes.length>0&&!p.current&&(p.current=!0,m(e.palettes[0]))},[e.palettes]),(0,u.useEffect)(()=>{if(l.current)switch(e.direction){case f.Bottom:case f.Top:l.current.style.width=e.width,e.height&&(l.current.style.height=e.height);break;case f.Left:case f.Right:l.current.style.height=e.width,e.height&&(l.current.style.width=e.height);break}},[e.direction,e.width,e.height]),(0,d.jsx)(`daga-palette`,{children:(0,d.jsxs)(`div`,{ref:l,className:`daga-panel daga-${e.location} daga-${e.direction}`,children:[(0,d.jsx)(Sn,{direction:e.direction,collapsableSelector:l,collapsableAdditionalSelector:`.daga-panel-content`,rule:`display`,collapsedValue:`none`,visibleValue:`block`,collapsed:!1,disabled:!1}),(0,d.jsxs)(`div`,{className:`daga-panel-content`,children:[e.palettes.length>1&&(0,d.jsx)(`div`,{className:`daga-panel-tabs`,children:e.palettes.map(e=>(0,d.jsx)(`div`,{className:`daga-panel-tab ${e===n?`daga-current-tab`:``}`,onClick:()=>m(e),children:e.name}))}),(0,d.jsx)(`div`,{className:`daga-palette-view`})]})]})})},Ln=({location:e,direction:t,centerAnimationDuration:n,enableAction:r,enableFilter:i,enableLayout:a,enableSelection:o,enableZoom:s})=>{let l=!1,p=!0,m=!1,h,g,_,v;switch(t){case f.Bottom:h=`height`,g=`scaleY`,_=`top`,v=`bottom`;break;case f.Top:h=`height`,g=`scaleY`,_=`bottom`,v=`top`;break;case f.Left:h=`width`,g=`scaleX`,_=`right`,v=`left`;break;case f.Right:h=`width`,g=`scaleX`,_=`left`,v=`right`;break}let y=(0,u.useRef)(null),b=(0,u.useRef)(null),ee=(0,u.useRef)(null);(0,u.useEffect)(()=>{c.select(y.current).style(`margin-${v}`,`-1rem`).style(h,`0rem`).style(`transform`,`${g}(0)`).style(`transform-origin`,_)});let x=async()=>{let e=c.select(y.current);if(!m)if(p){p=!1;let t=`${4*e.selectChildren().size()}rem`;e.transition().duration(500).ease(c.easeLinear).style(h,t).style(`transform`,`${g}(1)`),setTimeout(()=>{m=!1},500)}else p=!0,e.transition().duration(500).ease(c.easeLinear).style(h,`0rem`).style(`transform`,`${g}(0)`),setTimeout(()=>{m=!1},500)},S=(0,u.useContext)(bn);return(0,d.jsx)(`daga-diagram-buttons`,{children:(0,d.jsxs)(`div`,{className:`daga-diagram-buttons daga-${e} daga-${t}`,children:[s&&S.canUserPerformAction(K.Zoom)&&(0,d.jsx)(`button`,{className:`daga-zoom-in`,onClick:()=>{S.zoomBy(S.zoomFactor)},children:(0,d.jsx)(`span`,{className:`daga-tooltip`,children:`Zoom in`})}),s&&S.canUserPerformAction(K.Zoom)&&(0,d.jsx)(`button`,{className:`daga-zoom-out`,onClick:()=>{S.zoomBy(1/S.zoomFactor)},children:(0,d.jsx)(`span`,{className:`daga-tooltip`,children:`Zoom out`})}),(0,d.jsxs)(`div`,{className:`daga-collapsable-buttons daga-collapsed`,ref:y,children:[s&&S.canUserPerformAction(K.Zoom)&&(0,d.jsx)(`button`,{className:`daga-center`,onClick:()=>{S.center(void 0,1,n)},children:(0,d.jsx)(`span`,{className:`daga-tooltip`,children:`Fit diagram to screen`})}),r&&(0,d.jsx)(`button`,{className:`daga-undo`,onClick:()=>{S.actionStack.undo()},children:(0,d.jsx)(`span`,{className:`daga-tooltip`,children:`Undo`})}),r&&(0,d.jsx)(`button`,{className:`daga-redo`,onClick:()=>{S.actionStack.redo()},children:(0,d.jsx)(`span`,{className:`daga-tooltip`,children:`Redo`})}),o&&(0,d.jsx)(`button`,{className:`daga-copy`,onClick:()=>{S.userSelection.copyToClipboard()},children:(0,d.jsx)(`span`,{className:`daga-tooltip`,children:`Copy`})}),o&&(0,d.jsx)(`button`,{className:`daga-cut`,onClick:()=>{S.userSelection.cutToClipboard()},children:(0,d.jsx)(`span`,{className:`daga-tooltip`,children:`Cut`})}),o&&(0,d.jsx)(`button`,{className:`daga-multiple-selection ${l?`daga-on`:`daga-off`}`,onClick:()=>{S.multipleSelectionOn=!0,c.select(b.current).classed(`daga-on`,!0).classed(`daga-off`,!1);let e=S.diagramEvent$.subscribe(t=>{t.type===Ot.Selection&&(c.select(b.current).classed(`daga-on`,!1).classed(`daga-off`,!0),e.unsubscribe())})},ref:b,children:(0,d.jsx)(`span`,{className:`daga-tooltip`,children:`Multiple selection`})}),o&&(0,d.jsx)(`button`,{className:`daga-paste`,onClick:()=>{S.userSelection.pasteFromClipboard()},children:(0,d.jsx)(`span`,{className:`daga-tooltip`,children:`Paste`})}),o&&(0,d.jsx)(`button`,{className:`daga-delete`,onClick:()=>{S.userSelection.removeFromModel()},children:(0,d.jsx)(`span`,{className:`daga-tooltip`,children:`Delete`})}),a&&S.layoutFormat&&(0,d.jsx)(`button`,{className:`daga-layout`,onClick:()=>{S.layoutFormat&&S.layoutFormat in vn&&vn[S.layoutFormat].apply(S.model)},children:(0,d.jsx)(`span`,{className:`daga-tooltip`,children:`Apply layout`})}),i&&(0,d.jsx)(`button`,{className:`daga-filter ${l?`daga-on`:`daga-off`}`,onClick:()=>{l=!l,c.select(ee.current).classed(`daga-on`,l).classed(`daga-off`,!l);let e=S.getPriorityThresholdOptions();e&&e.length>=2&&S.setPriorityThreshold(e[+!!l])},ref:ee,children:(0,d.jsx)(`span`,{className:`daga-tooltip`,children:`Apply filter`})})]}),(0,d.jsx)(`button`,{className:`daga-more-options`,onClick:x,children:p?(0,d.jsx)(`span`,{className:`daga-tooltip`,children:`More options`}):(0,d.jsx)(`span`,{className:`daga-tooltip`,children:`Less options`})})]})})},Rn=({config:e,model:t,onCanvasCreated:n,onDiagramEvent:r,onModelChange:i})=>{let a=new ot,o=new $t,s=(0,u.useRef)(null),c=(0,u.useRef)(void 0),l=(0,u.useRef)(!1),m=[],[h,g]=(0,u.useState)(void 0),[_,v]=(0,u.useState)(void 0),y={zoomIn:()=>{},zoomOut:()=>{},center:()=>{},layout:()=>{},filter:()=>{},undo:()=>{},redo:()=>{}},b={refreshPalette:()=>{}},ee=new xn(e=>g(e),e=>v(e)),x={diagramButtons:y,palette:b,propertyEditor:ee},S=(t=!1)=>{if((!c.current||t)&&(m.forEach(e=>e.unsubscribe()),c.current=new rn(x,e)),!c.current)throw Error(`Canvas could not be created`);return c.current},C=S(),w=e=>{C.initView(e),m.push(C.diagramEvent$.subscribe(e=>{r?.(e)})),m.push(C.diagramChange$.subscribe(()=>{let e=o.export(C.model);i?.(e)}))};return(0,u.useEffect)(()=>{s.current&&(l.current||(w(s.current),l.current=!0,n?.(C)))},[s.current]),(0,u.useEffect)(()=>{s.current&&(S(!0),w(s.current),n?.(C))},[e]),(0,u.useEffect)(()=>{t&&a.import(C.model,t)},[t]),(0,d.jsx)(`daga-diagram`,{children:(0,d.jsx)(yn.Provider,{value:e,children:(0,d.jsx)(bn.Provider,{value:C,children:(0,d.jsxs)(`daga-diagram-editor`,{children:[(0,d.jsx)(`div`,{className:`daga-append-to`,ref:s}),(0,d.jsxs)(bn.Provider,{value:C,children:[e.components?.buttons!==void 0&&e.components?.buttons?.enabled!==!1&&(0,d.jsx)(Ln,{location:e.components?.buttons?.location||p.BottomRight,direction:e.components?.buttons?.direction||f.Top,centerAnimationDuration:e.components?.buttons?.centerAnimationDuration,enableAction:e.components?.buttons?.enableAction!==!1,enableFilter:e.components?.buttons?.enableFilter===!0,enableLayout:e.components?.buttons?.enableLayout===!0,enableSelection:e.components?.buttons?.enableSelection!==!1,enableZoom:e.components?.buttons?.enableZoom!==!1}),e.components?.palette!==void 0&&e.components?.palette?.enabled!==!1&&e.components?.palette?.sections&&(e.components?.palette?.sections?.length||0)>0&&(0,d.jsx)(In,{location:e.components?.palette?.location||p.TopLeft,direction:e.components?.palette?.direction||f.Bottom,width:e.components?.palette?.width||`12rem`,height:e.components?.palette?.height,palettes:e.components?.palette?.sections||[]}),e.components?.propertyEditor!==void 0&&e.components?.propertyEditor?.enabled!==!1&&(0,d.jsx)(Pn,{location:e.components?.propertyEditor?.location||p.TopRight,direction:e.components?.propertyEditor?.direction||f.Bottom,width:e.components?.propertyEditor?.width||`24rem`,height:e.components?.propertyEditor?.height,title:h,valueSet:_,onValueChange:(e,t,n)=>{if(_!==void 0&&t.editable!==!1&&!je(e.getValue(t.name),n)){e.setValue(t.name,n);let r=new Pe(_.propertySet,void 0);r.setValues(_.getValues()),r.rootElement=_.rootElement,ee.valueSet=r,_.rootElement.valueSet=r,C.propertyEditorChanges$?.next()}}}),e.components?.errors!==void 0&&e.components?.errors?.enabled!==!1&&(0,d.jsx)(Cn,{})]})]})})})})};exports.DagaDiagram=Rn;