@metadev/daga-react 4.2.8 → 4.2.10
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/Changelog.md +10 -0
- package/index.js +2 -2
- package/index.mjs +477 -384
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("react/jsx-runtime"),to=require("d3"),kt=require("rxjs"),E=require("react");function eo(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=eo(to);var g=(s=>(s.Bottom="bottom",s.Left="left",s.Right="right",s.Top="top",s))(g||{}),Ut=(s=>(s.BottomLeft="bottom-left",s.BottomRight="bottom-right",s.TopLeft="top-left",s.TopRight="top-right",s))(Ut||{}),It=(s=>(s.Left="left",s.Center="center",s.Right="right",s))(It||{}),Bt=(s=>(s.Top="top",s.Center="center",s.Bottom="bottom",s))(Bt||{});const Ct=s=>[Math.round(s[0]),Math.round(s[1])],gt=(s,t,e)=>t<e?t<=s&&s<=e:e<=s&&s<=t,ke=(s,t,e)=>(s-t[0])/(t[1]-t[0])*(e[1]-e[0])+e[0],Yt=(s,t,e,a,l,n,i)=>{const r=(()=>{switch(n){case"start":return a[0]+(s[0]-t[0]);case"end":return a[1]-(t[1]-s[0]);case"middle":{const c=(t[0]+t[1])/2,d=(a[0]+a[1])/2,h=t[1]-t[0],u=a[1]-a[0],y=(s[0]-c)/h;return d+y*u}case"floating":default:return ke(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 c=(e[0]+e[1])/2,d=(l[0]+l[1])/2,h=e[1]-e[0],u=l[1]-l[0],y=(s[1]-c)/h;return d+y*u}case"floating":default:return ke(s[1],e,l)}})();return[r,o]},Ne=(s,t)=>((s[0]-t[0])**2+(s[1]-t[1])**2)**.5,oo=(s,t)=>(gt(s[0][0],t[0][0],t[1][0])||gt(s[1][0],t[1][0],t[0][0])||gt(t[0][0],s[0][0],s[1][0])||gt(t[1][0],s[1][0],s[0][0]))&&(gt(s[0][1],t[0][1],t[1][1])||gt(s[1][1],t[1][1],t[0][1])||gt(t[0][1],s[0][1],s[1][1])||gt(t[1][1],s[1][1],s[0][1]));var C=(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))(C||{}),W=(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))(W||{}),$=(s=>(s.Drag="drag",s.Start="start",s.End="end",s))($||{}),le=(s=>(s.Zoom="zoom",s.Start="start",s.End="end",s))(le||{});const ce=s=>s.replace(/([!"#$%&'()*+,\-./:;<=>?@[\\\]^`{|}])/g,"\\$1");var Pe=(s=>(s.Straight="straight",s.Bezier="bezier",s.Square="square",s))(Pe||{}),ue=(s=>(s.Solid="solid",s.Dashed="dashed",s.GappedDashes="gapped-dashes",s.Dotted="dotted",s))(ue||{});const io=20,so=(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||io;let n="",i,r;switch(s){case"straight":n+=`M ${t[0][0]} ${t[0][1]}`;for(let o=1;o<t.length;++o)n+=` L ${t[o][0]} ${t[o][1]}`;break;case"bezier":i=e,n+=`M ${t[0][0]} ${t[0][1]}`;for(let o=1;o<t.length;++o){if(o+1>=t.length)switch(a){case g.Bottom:r=g.Top;break;case g.Top:r=g.Bottom;break;case g.Right:r=g.Left;break;case g.Left:r=g.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]?r=g.Bottom:r=g.Top:t[o][0]>t[o-1][0]?r=g.Right:r=g.Left;if(i!==void 0){let c="",d="";const h=(Math.abs(t[o][0]-t[o-1][0])+Math.abs(t[o][1]-t[o-1][1]))/2;switch(i){case g.Bottom:c=`${t[o-1][0]} ${t[o-1][1]+h}`;break;case g.Top:c=`${t[o-1][0]} ${t[o-1][1]-h}`;break;case g.Right:c=`${t[o-1][0]+h} ${t[o-1][1]}`;break;case g.Left:c=`${t[o-1][0]-h} ${t[o-1][1]}`;break}if(r!==void 0){switch(r){case g.Top:d=`${t[o][0]} ${t[o][1]+h}`;break;case g.Bottom:d=`${t[o][0]} ${t[o][1]-h}`;break;case g.Left:d=`${t[o][0]+h} ${t[o][1]}`;break;case g.Right:d=`${t[o][0]-h} ${t[o][1]}`;break}n+=` C ${c} ${d} ${t[o][0]} ${t[o][1]}`}else n+=` Q ${c} ${t[o][0]} ${t[o][1]}`}else if(r!==void 0){let c="";const d=(Math.abs(t[o][0]-t[o-1][0])+Math.abs(t[o][1]-t[o-1][1]))/2;switch(r){case g.Top:c=`${t[o][0]} ${t[o][1]+d}`;break;case g.Bottom:c=`${t[o][0]} ${t[o][1]-d}`;break;case g.Left:c=`${t[o][0]+d} ${t[o][1]}`;break;case g.Right:c=`${t[o][0]-d} ${t[o][1]}`;break}n+=` Q ${c} ${t[o][0]} ${t[o][1]}`}else n+=` L ${t[o][0]} ${t[o][1]}`;i=r}break;case"square":i=e,n+=`M ${t[0][0]} ${t[0][1]}`;for(let o=1;o<t.length;++o){if(o+1>=t.length)switch(a){case g.Bottom:r=g.Top;break;case g.Top:r=g.Bottom;break;case g.Right:r=g.Left;break;case g.Left:r=g.Right;break}switch(i){case g.Bottom:switch(r){case g.Bottom:t[o][1]>t[o-1][1]?(t[o][0]!==t[o-1][0]?(n+=` V ${(t[o][1]+t[o-1][1])/2}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`):n+=` V ${t[o][1]}`,i=r):t[o][0]>t[o-1][0]?(n+=` V ${t[o-1][1]+l}`,n+=` H ${Math.max(t[o-1][0],t[o][0])+l}`,n+=` V ${t[o][1]-l}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`):(n+=` V ${t[o-1][1]+l}`,n+=` H ${Math.min(t[o-1][0],t[o][0])-l}`,n+=` V ${t[o][1]-l}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`);break;case g.Top:n+=` V ${Math.max(t[o-1][1],t[o][1])+l}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`;break;case g.Left:t[o][1]>t[o-1][1]+l?t[o][0]<t[o-1][0]-l?(n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`):(n+=` V ${(t[o-1][1]+t[o][1])/2}`,n+=` H ${t[o][0]+l}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`):t[o][0]<t[o-1][0]-l?(n+=` V ${t[o-1][1]+l}`,n+=` H ${(t[o-1][0]+t[o][0])/2}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`):(n+=` V ${t[o-1][1]+l}`,n+=` H ${t[o][0]+l}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`);break;case g.Right:t[o][1]>t[o-1][1]+l?t[o][0]>t[o-1][0]+l?(n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`):(n+=` V ${(t[o-1][1]+t[o][1])/2}`,n+=` H ${t[o][0]-l}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`):t[o][0]>t[o-1][0]+l?(n+=` V ${t[o-1][1]+l}`,n+=` H ${(t[o-1][0]+t[o][0])/2}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`):(n+=` V ${t[o-1][1]+l}`,n+=` H ${t[o][0]-l}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`);break;default:t[o][1]<t[o-1][1]+l?(n+=` V ${t[o-1][1]+l}`,t[o][0]!==t[o-1][0]&&(n+=` H ${t[o][0]}`),n+=` V ${t[o][1]}`,i=g.Top):(n+=` V ${t[o][1]}`,i=g.Bottom,t[o][0]!==t[o-1][0]&&(n+=` H ${t[o][0]}`,i=t[o][0]>t[o-1][0]?g.Right:g.Left));break}break;case g.Top:switch(r){case g.Top:t[o][1]<t[o-1][1]?(t[o][0]!==t[o-1][0]?(n+=` V ${(t[o][1]+t[o-1][1])/2}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`):n+=` V ${t[o][1]}`,i=r):t[o][0]<t[o-1][0]?(n+=` V ${t[o-1][1]-l}`,n+=` H ${Math.min(t[o-1][0],t[o][0])-l}`,n+=` V ${t[o][1]+l}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`):(n+=` V ${t[o-1][1]-l}`,n+=` H ${Math.max(t[o-1][0],t[o][0])+l}`,n+=` V ${t[o][1]+l}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`);break;case g.Bottom:n+=` V ${Math.min(t[o-1][1],t[o][1])-l}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`;break;case g.Right:t[o][1]<t[o-1][1]-l?t[o][0]>t[o-1][0]+l?(n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`):(n+=` V ${(t[o-1][1]+t[o][1])/2}`,n+=` H ${t[o][0]-l}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`):t[o][0]>t[o-1][0]+l?(n+=` V ${t[o-1][1]-l}`,n+=` H ${(t[o-1][0]+t[o][0])/2}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`):(n+=` V ${t[o-1][1]-l}`,n+=` H ${t[o][0]-l}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`);break;case g.Left:t[o][1]<t[o-1][1]-l?t[o][0]<t[o-1][0]-l?(n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`):(n+=` V ${(t[o-1][1]+t[o][1])/2}`,n+=` H ${t[o][0]+l}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`):t[o][0]<t[o-1][0]-l?(n+=` V ${t[o-1][1]-l}`,n+=` H ${(t[o-1][0]+t[o][0])/2}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`):(n+=` V ${t[o-1][1]-l}`,n+=` H ${t[o][0]+l}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`);break;default:t[o][1]>t[o-1][1]-l?(n+=` V ${t[o-1][1]-l}`,t[o][0]!==t[o-1][0]&&(n+=` H ${t[o][0]}`),n+=` V ${t[o][1]}`,i=g.Bottom):(n+=` V ${t[o][1]}`,i=g.Top,t[o][0]!==t[o-1][0]&&(n+=` H ${t[o][0]}`,i=t[o][0]>t[o-1][0]?g.Right:g.Left));break}break;case g.Left:switch(r){case g.Left:t[o][0]<t[o-1][0]?(t[o][1]!==t[o-1][1]?(n+=` H ${(t[o][0]+t[o-1][0])/2}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`):n+=` H ${t[o][0]}`,i=r):t[o][1]<t[o-1][1]?(n+=` H ${t[o-1][0]-l}`,n+=` V ${Math.min(t[o-1][1],t[o][1])-l}`,n+=` H ${t[o][0]+l}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`):(n+=` H ${t[o-1][0]-l}`,n+=` V ${Math.max(t[o-1][1],t[o][1])+l}`,n+=` H ${t[o][0]+l}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`);break;case g.Right:n+=` H ${Math.min(t[o-1][0],t[o][0])-l}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`;break;case g.Bottom:t[o][0]<t[o-1][0]-l?t[o][1]>t[o-1][1]+l?(n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`):(n+=` H ${(t[o-1][0]+t[o][0])/2}`,n+=` V ${t[o][1]-l}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`):t[o][1]>t[o-1][1]+l?(n+=` H ${t[o-1][0]-l}`,n+=` V ${(t[o-1][1]+t[o][1])/2}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`):(n+=` H ${t[o-1][0]-l}`,n+=` V ${t[o][1]-l}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`);break;case g.Top:t[o][0]<t[o-1][0]-l?t[o][1]<t[o-1][1]-l?(n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`):(n+=` H ${(t[o-1][0]+t[o][0])/2}`,n+=` V ${t[o][1]+l}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`):t[o][1]<t[o-1][1]-l?(n+=` H ${t[o-1][0]-l}`,n+=` V ${(t[o-1][1]+t[o][1])/2}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`):(n+=` H ${t[o-1][0]-l}`,n+=` V ${t[o][1]+l}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`);break;default:t[o][0]>t[o-1][0]-l?(n+=` H ${t[o-1][0]-l}`,t[o][1]!==t[o-1][1]&&(n+=` V ${t[o][1]}`),n+=` H ${t[o][0]}`,i=g.Right):(n+=` H ${t[o][0]}`,i=g.Left,t[o][1]!==t[o-1][1]&&(n+=` V ${t[o][1]}`,i=t[o][1]>t[o-1][1]?g.Bottom:g.Top));break}break;case g.Right:switch(r){case g.Right:t[o][0]>t[o-1][0]?(t[o][1]!==t[o-1][1]?(n+=` H ${(t[o][0]+t[o-1][0])/2}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`):n+=` H ${t[o][0]}`,i=r):t[o][1]>t[o-1][1]?(n+=` H ${t[o-1][0]+l}`,n+=` V ${Math.max(t[o-1][1],t[o][1])+l}`,n+=` H ${t[o][0]-l}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`):(n+=` H ${t[o-1][0]+l}`,n+=` V ${Math.min(t[o-1][1],t[o][1])-l}`,n+=` H ${t[o][0]-l}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`);break;case g.Left:n+=` H ${Math.max(t[o-1][0],t[o][0])+l}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`;break;case g.Top:t[o][0]>t[o-1][0]+l?t[o][1]<t[o-1][1]-l?(n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`):(n+=` H ${(t[o-1][0]+t[o][0])/2}`,n+=` V ${t[o][1]+l}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`):t[o][1]<t[o-1][1]-l?(n+=` H ${t[o-1][0]+l}`,n+=` V ${(t[o-1][1]+t[o][1])/2}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`):(n+=` H ${t[o-1][0]+l}`,n+=` V ${t[o][1]+l}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`);break;case g.Bottom:t[o][0]>t[o-1][0]+l?t[o][1]>t[o-1][1]+l?(n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`):(n+=` H ${(t[o-1][0]+t[o][0])/2}`,n+=` V ${t[o][1]-l}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`):t[o][1]>t[o-1][1]+l?(n+=` H ${t[o-1][0]+l}`,n+=` V ${(t[o-1][1]+t[o][1])/2}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`):(n+=` H ${t[o-1][0]+l}`,n+=` V ${t[o][1]-l}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`);break;default:t[o][0]<t[o-1][0]+l?(n+=` H ${t[o-1][0]+l}`,t[o][1]!==t[o-1][1]&&(n+=` V ${t[o][1]}`),n+=` H ${t[o][0]}`,i=g.Left):(n+=` H ${t[o][0]}`,i=g.Right,t[o][1]!==t[o-1][1]&&(n+=` V ${t[o][1]}`,i=t[o][1]>t[o-1][1]?g.Bottom:g.Top));break}break;default:t[o][0]!==t[o-1][0]&&(n+=` H ${t[o][0]}`,i=t[o][0]>t[o-1][0]?g.Right:g.Left),t[o][1]!==t[o-1][1]&&(n+=` V ${t[o][1]}`,i=t[o][1]>t[o-1][1]?g.Bottom:g.Top)}}break}return n}},de=(s,t)=>{switch(s){case"dotted":return`${t}`;case"dashed":return`${4*t} ${t}`;case"gapped-dashes":return`${4*t} ${4*t}`;case"solid":default:return"none"}},D=(s,t)=>{const e=s.indexOf(t);return e>=0&&s.splice(e,1),s};var Et=(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))(Et||{});const he=(s,t,e,a,l)=>{if(typeof s=="function")return s(t,e,a,l);switch(s){case"ellipse":return Re(t,e,a,l);case"empty":return no();case"folder":return ro(t,e,a,l);case"hexagon":return ao(t,e,a,l);case"octagon":return lo(t,e,a,l);case"pill":return Dt(t,e,a,l);case"rectangle":return we(t,e,a,l);case"rhombus":return co(t,e,a,l);case"rounded-rectangle":return ho(t,e,a,l);case"sticky-note":return go(t,e,a,l);default:return we(t,e,a,l)}},Re=(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`,no=()=>"Z",ro=(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`,ao=(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`,lo=(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`,Dt=(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`:Re(s,t,e,a),we=(s,t,e,a)=>`M ${s} ${t} L ${s+e} ${t} L ${s+e} ${t+a} L ${s} ${t+a} Z`,co=(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`,ho=(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`,go=(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 fo=s=>Math.max(...s.split(`
|
|
2
|
-
`).map(t=>t.length)),uo=s=>s.match(/\n/g)?.length||0,X=[];for(let s=0;s<256;++s)X.push((s+256).toString(16).slice(1));function po(s,t=0){return(X[s[t+0]]+X[s[t+1]]+X[s[t+2]]+X[s[t+3]]+"-"+X[s[t+4]]+X[s[t+5]]+"-"+X[s[t+6]]+X[s[t+7]]+"-"+X[s[t+8]]+X[s[t+9]]+"-"+X[s[t+10]]+X[s[t+11]]+X[s[t+12]]+X[s[t+13]]+X[s[t+14]]+X[s[t+15]]).toLowerCase()}let ee;const mo=new Uint8Array(16);function vo(){if(!ee){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");ee=crypto.getRandomValues.bind(crypto)}return ee(mo)}const yo=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),Se={randomUUID:yo};function xe(s,t,e){if(Se.randomUUID&&!s)return Se.randomUUID();s=s||{};const a=s.random??s.rng?.()??vo();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,po(a)}const it=s=>{const{selected:t,highlighted:e,selectedAndHighlighted:a,...l}=s,n=l,i={...n,...t},r={...n,...e},o={...n,...e,...t,...a};return{defaultLook:n,selectedLook:i,highlightedLook:r,selectedAndHighlightedLook:o}};class Wt{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],D(this.entities,e))}size(){return this.entities.length}*[Symbol.iterator](){for(const t of this.entities)yield t}}const Mt=0;class xt{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 ht extends Wt{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,n)=>t(a,l,n)&&!a.removed)}filter(t,e=!1){return e?super.filter(t):super.filter((a,l,n)=>t(a,l,n)&&!a.removed)}find(t,e=!1){return e?super.find(t):super.find((a,l,n)=>t(a,l,n)&&!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],D(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 bo{constructor(t,e,a,l,n,i,r){this.name=t,this.label=e,this.type=a,this.defaultValue=l,this.basic=n,this.editable=i,this.rootAttribute=r,this.options=void 0,this.properties=void 0}}var T=(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))(T||{});class Zt{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 yt(s,t){return!t||s[0]>t[0]?!0:s[0]===t[0]?s[1]>=t[1]:!1}const Ce=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),ze=(s,t,e)=>{const a={},l={};for(const n in e.propertySet.propertyMap)if(e.propertySet.propertyMap[n].type===T.Object){const i=ze(s[n],t[n],e.getSubValueSet(n));Object.keys(i[0]).length>0&&Object.keys(i[1]).length>0&&(a[n]=i[0],l[n]=i[1])}else wt(s[n],t[n])||(a[n]=s[n],l[n]=t[n]);return[a,l]},ko=s=>s!=null&&s.constructor===Object;class mt{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 n=t[l];if(a==null)return;a=a[n]}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===T.Object?this.valueSets[t].getValues():this.values[t]}getValues(){const t={};for(const e in this.propertySet.propertyMap)this.propertySet.getProperty(e).type===T.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===T.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===T.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!Ce(e)}hasSetValue(t){const e=this.getValue(t),a=this.propertySet.getProperty(t);return a&&a.type===T.Object?this.getSubValueSet(t).hasAnySetValue():!Ce(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===T.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===T.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===T.Object?this.valueSets[e].setTimestamps(t[e]):this.ownTimestamps[e]=t[e]}overwriteValues(t){for(const e in t)this.propertySet.getProperty(e).type===T.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===T.Object?this.valueSets[a].overwriteValuesLww(t[a],e):yt(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===T.Object?this.valueSets[t]=this.constructSubValueSet(t):this.values[t]=structuredClone(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 Zt(e.properties),l=new mt(a,this.rootElement);return l.overwriteValues(structuredClone(e.defaultValue)),l}getSubValueSet(t){return this.valueSets[t]}displayProperty(t){this.displayedProperties.includes(t)||(this.displayedProperties.push(t),D(this.hiddenProperties,t))}hideProperty(t){this.hiddenProperties.includes(t)||(this.hiddenProperties.push(t),D(this.displayedProperties,t))}}const tt={name:"",label:null,look:{lookType:"connection-look",color:"#000000",thickness:1,shape:Pe.Straight,style:ue.Solid,selected:{color:"#AA00AA"},highlighted:{thickness:2}},startMarkerLook:void 0,endMarkerLook:void 0,startTypes:[],endTypes:[],properties:[]};class Ve{constructor(t){const e={...tt,...t};this.id=e.id,this.name=e.name,this.label=e.label;const a=it(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=it(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=it(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 Zt(e.properties)}canStartFromType(t){return this.startTypes.indexOf(t)>=0}canFinishOnType(t){return this.endTypes.indexOf(t)>=0}}class at extends xt{constructor(t,e,a,l,n){if(t.connections.get(n)!==void 0)throw new Error(`DiagramConnection with id "${n}" already exists`);if(!n)throw new Error("DiagramConnection cannot have an empty or null id");super(t,n),this.startCoords=[0,0],this.endCoords=[0,0],this.startLabel="",this.middleLabel="",this.endLabel="",this.points=[],this._type=e,this.valueSet=new mt(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 mt(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){if(t){const e=it(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){if(t){const e=it(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){if(t){const e=it(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&&D(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&&D(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(n=>[n,n.distanceTo(this.end.coords)]).sort((n,i)=>n[1]-i[1]).map(n=>n[0]);t:for(const n of l){if(!t&&n===this.end||!n.allowsOutgoing||!e&&(n.incomingConnections.length===1&&n.incomingConnections[0]!==this||n.incomingConnections.length>1||n.outgoingConnections.length===1&&n.outgoingConnections[0]!==this||n.outgoingConnections.length>1))continue t;if(!a){for(const i of n.outgoingConnections)if(i!==this&&i.end===this.end)continue t;for(const i of n.incomingConnections)if(i!==this&&i.start===this.end)continue t}if(n===this.start)break t;this.setStart(n);break t}}if(this.end?.rootElement&&this.start){const l=this.end.rootElement.ports.map(n=>[n,n.distanceTo(this.start.coords)]).sort((n,i)=>n[1]-i[1]).map(n=>n[0]);t:for(const n of l){if(!t&&n===this.start||!n.allowsIncoming||!e&&(n.outgoingConnections.length===1&&n.outgoingConnections[0]!==this||n.outgoingConnections.length>1||n.incomingConnections.length===1&&n.incomingConnections[0]!==this||n.incomingConnections.length>1))continue t;if(!a){for(const i of n.incomingConnections)if(i!==this&&i.start===this.start)continue t;for(const i of n.outgoingConnections)if(i!==this&&i.end===this.start)continue t}if(n===this.end)break t;this.setEnd(n);break t}}}getPriority(){return this.start?this.end?Math.min(this.start.getPriority(),this.end.getPriority()):this.start.getPriority():this.end?this.end.getPriority():Mt}}class wo extends ht{constructor(t){super(),this.types=new Wt,this.model=t}new(t,e,a,l){let n;if(t instanceof Ve)n=t;else{const r=this.types.get(t);if(r===void 0)throw new TypeError(`Connection type with id '${t}' could not be found.`);n=r}const i=new at(this.model,n,e,a,l);return super.add(i),i.updateInView(),i.valueSet.resetValues(),i}remove(t){const e=this.get(t,!0);e&&(D(e.start?.outgoingConnections||[],e),D(e.end?.incomingConnections||[],e),super.remove(t),e.updateInView())}}const V={editable:!0,fontSize:0,margin:0,padding:0,fontFamily:"'Wonder Unit Sans', sans-serif",color:"#000000",selectedColor:"#000000",backgroundColor:"#00000000",horizontalAlign:It.Center,verticalAlign:Bt.Center,orientation:g.Top,fit:!1,shrink:!0};class ct extends xt{constructor(t,e,a,l,n,i,r,o,c,d,h,u,y,v,m,p){const k=`${e?.id}_field`;if(t.fields.get(k)!==void 0)throw new Error("DiagramField for rootElement already exists");if(super(t,k),this.textTimestamp=null,this.rootElement=e,this.coords=a,this.width=l,this.height=n,this.fontSize=i,this.fontFamily=r,this.color=o,this.selectedColor=c,this.horizontalAlign=d,this.verticalAlign=h,!isNaN(Number(u)))this.orientation=Number(u);else switch(u){case g.Top:this.orientation=0;break;case g.Right:this.orientation=90;break;case g.Bottom:this.orientation=180;break;case g.Left:this.orientation=270;break;default:this.orientation=0}this.defaultText=y,this._text=y,this.editable=v,this.fit=m,this.shrink=p}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()||Mt}}class So extends ht{constructor(t){super(),this.model=t}new(t,e,a,l,n,i,r,o,c,d,h,u,y,v,m){const p=new ct(this.model,t,e,r,o,a,l,n,i,c,d,h,u,y,v,m);return super.add(p),p.updateInView(),t!==void 0&&(t.label=p),p}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 Z=s=>s?.margin===null||s?.margin===void 0?V.margin:typeof s.margin=="number"?s.margin:s.margin.length===0?V.margin:s.margin.length===1||s.margin.length===2?s.margin[0]:(s.margin.length===3,s.margin[2]),U=s=>s?.margin===null||s?.margin===void 0?V.margin:typeof s.margin=="number"?s.margin:s.margin.length===0?V.margin:s.margin.length===1?s.margin[0]:s.margin.length===2||s.margin.length===3?s.margin[1]:s.margin[3],et=s=>s?.margin===null||s?.margin===void 0?V.margin:typeof s.margin=="number"?s.margin:s.margin.length===0?V.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?V.margin:typeof s.margin=="number"?s.margin:s.margin.length===0?V.margin:(s.margin.length===1||s.margin.length===2||s.margin.length===3,s.margin[0]),Pt=s=>s?.padding===null||s?.padding===void 0?V.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?V.padding:s.padding.length===1||s.padding.length===2?s.padding[0]:(s.padding.length===3,s.padding[2]),Rt=s=>s?.padding===null||s?.padding===void 0?V.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?V.padding:s.padding.length===1?s.padding[0]:s.padding.length===2||s.padding.length===3?s.padding[1]:s.padding[3],zt=s=>s?.padding===null||s?.padding===void 0?V.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?V.padding:s.padding.length===1?s.padding[0]:(s.padding.length===2||s.padding.length===3,s.padding[1]),Vt=s=>s?.padding===null||s?.padding===void 0?V.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?V.padding:(s.padding.length===1||s.padding.length===2||s.padding.length===3,s.padding[0]),$e=1,Ie=1,xo=1,Co=1;class $o{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 Io(l))}}}class Io{constructor(t){this.label=t.label||null,this.ports=t.ports||[],this.priority=t.priority||Mt,this.resizableX=t.resizableX,this.resizableY=t.resizableY;const e=it(t.look||Oe);this.defaultLook=e.defaultLook,this.selectedLook=e.selectedLook,this.highlightedLook=e.highlightedLook,this.selectedAndHighlightedLook=e.selectedAndHighlightedLook}}class F extends xt{constructor(t,e,a,l,n,i,r,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=n,this.width=i,this.height=r}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){if(t){const e=it(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]||xo}getMinHeight(){return this.node?.type?.sectionGrid?.minHeights?.[this.indexYInNode]||Co}getPriority(){return this.node?.type?.sectionGrid?.sections?.[this.indexYInNode]?.[this.indexXInNode]?.priority||Mt}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(n=>n.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 n,i;switch(t){case g.Left:n=[a[0]-e,a[1]],i=[l[0],l[1]],n[1]-n[0]<this.getMinWidth()&&(n[0]=n[1]-this.getMinWidth());break;case g.Top:n=[a[0],a[1]],i=[l[0]-e,l[1]],i[1]-i[0]<this.getMinHeight()&&(i[0]=i[1]-this.getMinHeight());break;case g.Right:n=[a[0],a[1]+e],i=[l[0],l[1]],n[1]-n[0]<this.getMinWidth()&&(n[1]=n[0]+this.getMinWidth());break;case g.Bottom:n=[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:[n[0],i[0]],width:n[1]-n[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],n=[this.coords[1],this.coords[1]+this.height];for(const r of this.ports)r.move(Yt(r.coords,e,a,l,n,r.anchorPointX,r.anchorPointY));const i=this.type;this.label&&(this.label.coords=[this.coords[0]+U(i?.label),this.coords[1]+G(i?.label)],this.label.width=this.width-U(i?.label)-et(i?.label),this.label.height=this.height-G(i?.label)-Z(i?.label),this.label.updateInView());for(const r of this.decorators)r.move(Yt(r.coords,e,a,l,n,r.anchorPointX,r.anchorPointY));this.model.canvas?.autoTightenConnections!==!1&&this.getConnections().forEach(r=>r.tighten()),this.updateInView()}}class Ao extends ht{constructor(t){super(),this.model=t}new(t,e,a,l,n,i,r){const o=new F(this.model,t,e,a,l,n,i,r);super.add(o),o.updateInView(),t.sections.push(o),t.updateInView();const c=t.type.sectionGrid?.sections?.[a]?.[e]?.ports;if(c&&c.length>0)for(let h=0;h<c.length;++h){const u=c[h],y=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(y.type?.label){const v={...V,...y.type?.label},m=6*v.fontSize+Rt(v)+zt(v),p=v.fontSize+Vt(v)+Pt(v);let k;switch(y.direction){case g.Bottom:case g.Left:case g.Right:k=[y.coords[0]-m/2,y.coords[1]-p-Z(v)];break;case g.Top:k=[y.coords[0]-m/2,y.coords[1]+G(v)];break;default:k=y.coords}this.model.fields.new(y,k,v.fontSize,v.fontFamily,v.color,v.selectedColor,m,p,v.horizontalAlign,v.verticalAlign,v.orientation,"",v.editable,v.fit,v.shrink)}}const d=t.type.sectionGrid?.sections?.[a]?.[e]?.label;if(d){const h={...V,...d};this.model.fields.new(o,[o.coords[0]+U(h),o.coords[1]+G(h)],h.fontSize,h.fontFamily,h.color,h.selectedColor,o.width-U(h)-et(h),o.height-G(h)-Z(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&&D(e.node.sections,e),super.remove(t),e.updateInView()}}}const Oe={lookType:"shaped-look",shape:Et.Rectangle,fillColor:"#FFFFFF",borderColor:"#000000",borderThickness:1,selected:{fillColor:"#FFAAFF",borderColor:"#AA00AA"},highlighted:{borderThickness:3}},dt={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:Oe,isUnique:!1,canBeParentless:!0,childrenTypes:[],priority:Mt,properties:[]};class He{constructor(t){const e={...dt,...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=Eo(e),this.leftPadding=Mo(e),this.rightPadding=To(e),this.topPadding=No(e),this.label=e.label,this.ports=e.ports,this.decorators=e.decorators,this.sectionGrid=e.sectionGrid?new $o(e.sectionGrid):null;const a=it(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 Zt(t?.properties||[])}}class R extends xt{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 mt(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 mt(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){if(t){const e=it(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(n=>n.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 n=l.start?.getNode();if(n){if(!t&&n.removed)continue;e.push(n)}}for(const l of a.outgoingConnections){if(!t&&l.removed)continue;const n=l.end?.getNode();if(n){if(!t&&n.removed)continue;e.push(n)}}}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){D(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(g.Left,l,e,a):this.stretch(g.Left,l));const n=this.coords[1]-t.coords[1]+this.type.topPadding;n>=0&&(this.sections.length>0?this.stretchSections(g.Top,n,e,a):this.stretch(g.Top,n));const i=t.coords[0]+t.width-(this.coords[0]+this.width)+this.type.rightPadding;i>=0&&(this.sections.length>0?this.stretchSections(g.Right,i,e,a):this.stretch(g.Right,i));const r=t.coords[1]+t.height-(this.coords[1]+this.height)+this.type.bottomPadding;r>=0&&(this.sections.length>0?this.stretchSections(g.Bottom,r,e,a):this.stretch(g.Bottom,r)),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 n,i;switch(t){case g.Left:n=[a[0]-e,a[1]],i=[l[0],l[1]],n[1]-n[0]<this.type.minWidth&&(n[0]=n[1]-this.type.minWidth);break;case g.Top:n=[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 g.Right:n=[a[0],a[1]+e],i=[l[0],l[1]],n[1]-n[0]<this.type.minWidth&&(n[1]=n[0]+this.type.minWidth);break;case g.Bottom:n=[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:[n[0],i[0]],width:n[1]-n[0],height:i[1]-i[0],sections:{},children:{}})}stretchSections(t,e,a,l){let n=Number.NEGATIVE_INFINITY;switch(t){case g.Bottom:for(const i of this.sections)i.indexYInNode===l&&(n=Math.max(n,i.getMinHeight()-i.height));e<n&&(e=n);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 g.Right:for(const i of this.sections)i.indexXInNode===a&&(n=Math.max(n,i.getMinWidth()-i.width));e<n&&(e=n);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 g.Top:for(const i of this.sections)i.indexYInNode===l&&(n=Math.max(n,i.getMinHeight()-i.height));e<n&&(e=n);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 g.Left:for(const i of this.sections)i.indexXInNode===a&&(n=Math.max(n,i.getMinWidth()-i.width));e<n&&(e=n);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],n=[this.coords[1],this.coords[1]+this.height];for(const i of this.children){const r=t.children[i.id];r&&i.setGeometry(r)}for(const i of this.sections){const r=t.sections[i.id];r&&i.setGeometry(r)}for(const i of this.ports)i.move(Yt(i.coords,e,a,l,n,i.anchorPointX,i.anchorPointY));this.label&&(this.label.coords=[this.coords[0]+U(this.type.label),this.coords[1]+G(this.type.label)],this.label.width=this.width-U(this.type.label)-et(this.type.label),this.label.height=this.height-G(this.type.label)-Z(this.type.label),this.label.updateInView());for(const i of this.decorators)i.move(Yt(i.coords,e,a,l,n,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 n of l)n.indexYInNode===t&&(a=Math.max(a,n.width),this.model.sections.remove(n.id));for(const n of l)n.indexYInNode>t&&(--n.indexYInNode,n.move([n.coords[0]-a-e,n.coords[1]]));this.stretch(g.Right,-e-a)}removeSectionRow(t){const e=this.type.sectionGrid?.margin||0;let a=0;const l=[...this.sections];for(const n of l)n.indexXInNode===t&&(a=Math.max(a,n.height),this.model.sections.remove(n.id));for(const n of l)n.indexYInNode>t&&(--n.indexXInNode,n.move([n.coords[0],n.coords[1]-a-e]));this.stretch(g.Bottom,-e-a)}copySectionColumn(t){const e=this.type.sectionGrid?.margin||0;let a=0;const l=[...this.sections];for(const n of l)if(n.indexXInNode===t){a=Math.max(a,n.width);let i=n.indexXInNode+1;for(;this.model.sections.get(`${n.id}_copy_${i}_${n.indexYInNode}`,!0)!==void 0;)++i;this.model.sections.new(this,n.indexXInNode+1,n.indexYInNode,[n.coords[0]+n.width+e,n.coords[1]],n.width,n.height,`${n.id}_copy_${i}_${n.indexYInNode}`)}for(const n of l)n.indexXInNode>t&&(++n.indexXInNode,n.move([n.coords[0]+a+e,n.coords[1]]));this.stretch(g.Right,e+a)}copySectionRow(t){const e=this.type.sectionGrid?.margin||0;let a=0;const l=[...this.sections];for(const n of l)if(n.indexYInNode===t){a=Math.max(a,n.height);let i=n.indexYInNode+1;for(;this.model.sections.get(`${n.id}_copy_${n.indexXInNode}_${i}`,!0)!==void 0;)++i;this.model.sections.new(this,n.indexXInNode,n.indexYInNode+1,[n.coords[0],n.coords[1]+n.height+e],n.width,n.height,`${n.id}_copy_${n.indexXInNode}_${i}`)}for(const n of l)n.indexYInNode>t&&(++n.indexYInNode,n.move([n.coords[0],n.coords[1]+a+e]));this.stretch(g.Bottom,e+a)}}class Lo extends ht{constructor(t){super(),this.types=new Wt,this.model=t}new(t,e,a){let l;if(t instanceof He)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 n=new R(this.model,l,e,a);if(super.add(n),n.updateInView(),l.sectionGrid!==null){let i=n.coords[1]+(l.sectionGrid.margin||0);for(let r=0;r<l.sectionGrid.sections.length;++r){let o=n.coords[0]+(l.sectionGrid.margin||0);for(let c=0;c<l.sectionGrid.sections[r].length;++c)this.model.sections.new(n,c,r,[o,i],l.sectionGrid.defaultWidths?.[c]||$e,l.sectionGrid.defaultHeights?.[r]||Ie,`${n.id}_${r}_${c}`),o+=(l.sectionGrid.defaultWidths?.[c]||$e)+(l.sectionGrid.margin||0);i+=(l.sectionGrid.defaultHeights?.[r]||Ie)+(l.sectionGrid.margin||0)}}if(l.ports.length>0)for(let i=0;i<l.ports.length;++i){const r=l.ports[i],o=r.type!==void 0?this.model.ports.types.get(r.type):void 0,c=this.model.ports.new(o,n,[n.coords[0]+r.coords[0],n.coords[1]+r.coords[1]],r.connectionPoint!==void 0?[n.coords[0]+(r.connectionPoint[0]||0),n.coords[1]+(r.connectionPoint[1]||0)]:void 0,r.direction,`${n.id}_port_${i}`,r.anchorPointX||"floating",r.anchorPointY||"floating");if(c.type?.label){const d={...V,...c.type?.label},h=6*d.fontSize+Rt(d)+zt(d),u=d.fontSize+Vt(d)+Pt(d);let y;switch(c.direction){case g.Bottom:case g.Left:case g.Right:y=[c.coords[0]-h/2,c.coords[1]-u-Z(d)];break;case g.Top:y=[c.coords[0]-h/2,c.coords[1]+G(d)];break;default:y=c.coords}this.model.fields.new(c,y,d.fontSize,d.fontFamily,d.color,d.selectedColor,h,u,d.horizontalAlign,d.verticalAlign,d.orientation,"",d.editable,d.fit,d.shrink)}}if(l.label){const i={...V,...l.label};this.model.fields.new(n,[n.coords[0]+U(i),n.coords[1]+G(i)],i.fontSize,i.fontFamily,i.color,i.selectedColor,n.width-U(i)-et(i),n.height-G(i)-Z(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 r=l.decorators[i];this.model.decorators.new(n,[n.coords[0]+r.coords[0],n.coords[1]+r.coords[1]],r.width,r.height,n.getPriority(),r.html,`${n.id}_decorator_${i}`,r.anchorPointX||"floating",r.anchorPointY||"floating")}return n.valueSet.resetValues(),n.model.canvas?.fitNodeInView(n.id),n}remove(t){const e=this.get(t,!0);if(e){for(e.parent&&D(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 _e=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},Eo=s=>s?.padding===null||s?.padding===void 0?dt.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?dt.padding:s.padding.length===1||s.padding.length===2?s.padding[0]:(s.padding.length===3,s.padding[2]),Mo=s=>s?.padding===null||s?.padding===void 0?dt.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?dt.padding:s.padding.length===1?s.padding[0]:s.padding.length===2||s.padding.length===3?s.padding[1]:s.padding[3],To=s=>s?.padding===null||s?.padding===void 0?dt.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?dt.padding:s.padding.length===1?s.padding[0]:(s.padding.length===2||s.padding.length===3,s.padding[1]),No=s=>s?.padding===null||s?.padding===void 0?dt.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?dt.padding:(s.padding.length===1||s.padding.length===2||s.padding.length===3,s.padding[0]),je={lookType:"shaped-look",shape:Et.Ellipse,fillColor:"transparent",borderColor:"transparent",borderThickness:0,selected:{fillColor:"rgba(255, 0, 255, 0.5)"},highlighted:{fillColor:"rgba(0, 255, 255, 0.5)"}},Ft=it(je),Ge={name:"",label:null,allowsOutgoing:!0,allowsIncoming:!0,width:24,look:je};class Po{constructor(t){const e={...Ge,...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=it(e.look);this.defaultLook=a.defaultLook,this.selectedLook=a.selectedLook,this.highlightedLook=a.highlightedLook,this.selectedAndHighlightedLook=a.selectedAndHighlightedLook}}class vt extends xt{constructor(t,e,a,l,n,i,r,o="floating",c="floating"){if(t.ports.get(r)!==void 0)throw new Error(`DiagramPort with id "${r}" already exists`);if(!r)throw new Error("DiagramPort cannot have an empty or null id");super(t,r),this.outgoingConnections=[],this.incomingConnections=[],this._type=e,this.rootElement=a,this.coords=l,this.connectionPoint=n||l,this.direction=i,this.anchorPointX=o,this.anchorPointY=c}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||Ft)?.selectedAndHighlightedLook:this._selectedLook!==void 0?this._selectedLook:(this.type||Ft)?.selectedLook:this.highlighted?this._highlightedLook!==void 0?this._highlightedLook:(this.type||Ft)?.highlightedLook:this._defaultLook!==void 0?this._defaultLook:(this.type||Ft)?.defaultLook}set look(t){if(t){const e=it(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||Ge.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 R)return this.rootElement;if(this.rootElement instanceof F)return this.rootElement.node}getPriority(){return this.rootElement?.getPriority()||Mt}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 Ne(this.coords,t)}}class Ro extends ht{constructor(t){super(),this.types=new Wt,this.model=t}new(t,e,a,l,n,i,r="floating",o="floating"){const c=new vt(this.model,t,e,a,l,n,i,r,o);return super.add(c),c.updateInView(),e!==void 0&&e.ports.push(c),c}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 R||e.rootElement instanceof F)&&D(e.rootElement.ports,e),super.remove(t),e.updateInView()}}}class Fe{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 R(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 r=a.decorators[i];t.decorators.new(l,[l.coords[0]+r.coords[0],l.coords[1]+r.coords[1]],r.width,r.height,l.getPriority(),r.html,`${l.id}_decorator_${i}`)}if(a.label){const i={...V,...a.label},r=new ct(t,l,[l.coords[0]+U(i),l.coords[1]+G(i)],l.width-U(i)-et(i),l.height-G(i)-Z(i),i.fontSize,i.fontFamily,i.color,i.selectedColor,i.horizontalAlign,i.verticalAlign,i.orientation,"",i.editable,i.fit,i.shrink);r.text=e.label,l.label=r,t.fields.add(r),r.updateInView()}}for(const i of e.children||[]){const r=this.importNode(t,i);r!==void 0&&(l.children?.push(r),r.parent=l)}for(const i of e.sections||[]){const r=new F(t,l,i.indexXInNode,i.indexYInNode,i.coords,i.width,i.height,i.id);if(l.sections?.push(r),t.sections.add(r),i.label&&a.sectionGrid?.sections?.[i.indexYInNode]?.[i.indexXInNode]?.label){const c={...V,...a.sectionGrid?.sections?.[i.indexYInNode]?.[i.indexXInNode]?.label},d=new ct(t,r,[r.coords[0]+U(c),r.coords[1]+G(c)],r.width-U(c)-et(c),r.height-G(c)-Z(c),c.fontSize,c.fontFamily,c.color,c.selectedColor,c.horizontalAlign,c.verticalAlign,c.orientation,"",c.editable,c.fit,c.shrink);d.text=i.label,r.label=d,t.fields.add(d),d.updateInView()}let o=0;for(const c of i.ports||[]){const d=c.type!==void 0?t.ports.types.get(c.type):void 0,h=new vt(t,d,r,c.coords,c.connectionPoint||c.coords,c.direction,c.id);if(r.ports.push(h),t.ports.add(h),c.label){if(a.ports.length>o&&d?.label){const u={...V,...d?.label};let y;switch(h.direction){case g.Top:case g.Left:y=[h.coords[0]-u.fontSize,h.coords[1]-u.fontSize];break;case g.Bottom:y=[h.coords[0]-u.fontSize,h.coords[1]+u.fontSize];break;case g.Right:y=[h.coords[0]+u.fontSize,h.coords[1]-u.fontSize];break;default:y=h.coords}const v=new ct(t,h,y,u.fontSize,u.fontSize,u.fontSize,u.fontFamily,u.color,u.selectedColor,u.horizontalAlign,u.verticalAlign,u.orientation,"",u.editable,u.fit,u.shrink);v.text=c.label,h.label=v,t.fields.add(v),v.updateInView()}++o}c.collabMeta&&(h.selfRemoved=c.collabMeta.selfRemoved,h.selfRemovedTimestamp=c.collabMeta.selfRemovedTimestamp,this.importLabelCollabMeta(h.label,c.collabMeta.label)),h.updateInView()}i.collabMeta&&(r.selfRemoved=i.collabMeta.selfRemoved,r.selfRemovedTimestamp=i.collabMeta.selfRemovedTimestamp,this.importLabelCollabMeta(r.label,i.collabMeta.label)),r.updateInView()}let n=0;for(const i of e.ports||[]){const r=i.type!==void 0?t.ports.types.get(i.type):void 0,o=new vt(t,r,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>n&&r?.label){const c={...V,...r?.label};let d;switch(o.direction){case g.Top:case g.Left:d=[o.coords[0]-c.fontSize,o.coords[1]-c.fontSize];break;case g.Bottom:d=[o.coords[0]-c.fontSize,o.coords[1]+c.fontSize];break;case g.Right:d=[o.coords[0]+c.fontSize,o.coords[1]-c.fontSize];break;default:d=o.coords}const h=new ct(t,o,d,c.fontSize,c.fontSize,c.fontSize,c.fontFamily,c.color,c.selectedColor,c.horizontalAlign,c.verticalAlign,c.orientation,"",c.editable,c.fit,c.shrink);h.text=i.label,o.label=h,t.fields.add(h),h.updateInView()}++n}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 at(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 Kt{constructor(t,e,a,l,n,i,r){this.canvas=t,this.id=e,this.typeId=a,this.coords=l,this.parentId=n,this.label=i,this.values=r}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(structuredClone({...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 Kt(t,e.id,e.typeId,e.coords,e.parentId,e.label,e.values)}}class pe{constructor(t,e,a,l,n,i,r){this.canvas=t,this.nodeId=e,this.copyColumnIndex=a,this.copyRowIndex=l,this.removeColumnIndex=n,this.removeRowIndex=i,this.timestamp=r}do(){const t=this.canvas.model.nodes.get(this.nodeId);t&&yt(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 pe(t,e.nodeId,e.copyColumnIndex,e.copyRowIndex,e.removeColumnIndex,e.removeRowIndex,e.timestamp)}}class me{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&&yt(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 me(t,e.to,e.timestamp)}}class Ot{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&&yt(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 Ot(t,e.nodeIds,e.delta,e.timestamp)}}class ot{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&&yt(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 ot(t,e.nodeId,e.to,e.timestamp)}}class Ht{constructor(t,e,a,l,n){this.canvas=t,this.childId=e,this.parentId=a,this.childGeometry=l,this.timestamp=n}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)&&yt(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 Ht(t,e.childId,e.parentId,e.childGeometry,e.timestamp)}}class qt{constructor(t,e,a,l,n){this.canvas=t,this.id=e,this.typeId=a,this.startId=l,this.endId=n}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 At{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&&yt(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 At(t,e.fieldId,e.to,e.timestamp)}}class Lt{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 Lt(t,e.id,e.to,e.timestamp)}}class nt{constructor(t,e,a,l,n,i,r,o){this.canvas=t,this.nodeIds=e,this.sectionIds=a,this.portIds=l,this.connectionIds=n,this.fieldIds=i,this.selfRemoved=r,this.timestamp=o}doOne(t){t&&yt(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 nt(t,e.nodeIds,e.sectionIds,e.portIds,e.connectionIds,e.fieldIds,e.removed,e.timestamp)}}class Jt{constructor(t,e,a){this.canvas=t,this.nodes=e,this.connections=a}do(){const t=new Fe;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 Jt(t,e.nodes,e.connections)}}class zo{constructor(t){this.isInRoom=!1,this.canvas=t,this.replicaId=xe()}freshTimestamp(){return this.canvas.model.logicalClock++,[this.canvas.model.logicalClock,this.replicaId]}freshId(){return"id"+xe()}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":{Kt.deserialize(this.canvas,t).do();break}case"addSection":{pe.deserialize(this.canvas,t).do();break}case"applyLayout":{me.deserialize(this.canvas,t).do();break}case"move":{Ot.deserialize(this.canvas,t).do();break}case"setGeometry":{ot.deserialize(this.canvas,t).do();break}case"setParent":{Ht.deserialize(this.canvas,t).do();break}case"addConnection":{qt.deserialize(this.canvas,t).do();break}case"editField":{At.deserialize(this.canvas,t).do();break}case"updateValues":{Lt.deserialize(this.canvas,t).do();break}case"setSelfRemoved":{nt.deserialize(this.canvas,t).do();break}case"paste":{Jt.deserialize(this.canvas,t).do();break}default:console.error("Unknown CollabAction type, skipping:",t)}}}class Vo{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 w=(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))(w||{});class Oo{constructor(t,e,a,l,n,i,r,o,c){this.canvas=t,this.type=e,this.coords=a,this.parentId=l,this.ancestorId=n,this.fromAncestorGeometry=i,this.toAncestorGeometry=r,this.label=o,this.values=c,this.id=this.canvas.collabEngine.freshId()}do(){const t=new Kt(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 ot(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 nt(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 ot(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 nt(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 ot(this.canvas,this.ancestorId,this.toAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(a)}return t===void 0}}class oe{constructor(t,e,a){this.canvas=t,this.nodeIds=e,this.delta=a}do(){const t=new Ot(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 Ot(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 B{constructor(t,e,a,l,n,i,r,o){this.canvas=t,this.intent=e,this.nodeId=a,this.from=l,this.to=n,this.ancestorId=i,this.fromAncestorGeometry=r,this.toAncestorGeometry=o}do(){const t=this.canvas.model.nodes.get(this.nodeId);if(t){const e=new ot(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 ot(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 ot(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 ot(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 ot(this.canvas,this.nodeId,this.to,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(e)}return t!==void 0}}class Ho{constructor(t,e,a,l,n,i,r,o,c){this.canvas=t,this.childId=e,this.fromParentId=a,this.toParentId=l,this.fromChildGeometry=n,this.toChildGeometry=i,this.ancestorId=r,this.fromAncestorGeometry=o,this.toAncestorGeometry=c}do(){const t=this.canvas.model.nodes.get(this.childId),e=new Ht(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 ot(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 Ht(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 ot(this.canvas,this.ancestorId,this.fromAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(a)}return t!==void 0}redo(){return this.do()}}class ie{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 nt(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 nt(this.canvas,[],[],[],[this.id],[],!1,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),t===void 0}}class Ae{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 At(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 At(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 At(this.canvas,this.fieldId,this.to,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(e)}return t!==void 0}}class _o{constructor(t,e,a,l){this.canvas=t,this.id=e,this.from=a,this.to=l}do(){const t=new Lt(this.canvas,this.id,this.to,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(t),!0}undo(){const t=new Lt(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 Lt(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 jo{constructor(t,e,a,l,n,i){this.canvas=t,this.nodeIds=e,this.sectionIds=a,this.portIds=l,this.connectionIds=n,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 nt(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 nt(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 Go{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 n of this.nodes)n.coords[0]<t[0]&&(t[0]=n.coords[0]),n.coords[1]<t[1]&&(t[1]=n.coords[1]);const e=this.coords!==void 0?[this.coords[0]-t[0],this.coords[1]-t[1]]:void 0,a={};for(const n of this.nodes){const i=n.id,r=this.canvas.collabEngine.freshId();if(a[i]=r,n.id=r,e&&(n.coords=[n.coords[0]+e[0],n.coords[1]+e[1]]),n.sections)for(const o of n.sections){const c=o.id;if(o.id.includes(n.id)?o.id=o.id.replace(n.id,r):o.id=this.canvas.collabEngine.freshId(),a[c]=o.id,e&&(o.coords=[o.coords[0]+e[0],o.coords[1]+e[1]]),o.ports)for(const d of o.ports){const h=d.id;d.id.includes(n.id)?d.id=d.id.replace(n.id,r):d.id=this.canvas.collabEngine.freshId(),a[h]=d.id,e&&(d.coords=[d.coords[0]+e[0],d.coords[1]+e[1]],d.connectionPoint&&(d.connectionPoint=[d.connectionPoint[0]+e[0],d.connectionPoint[1]+e[1]]))}}if(n.ports)for(const o of n.ports){const c=o.id;o.id.includes(n.id)?o.id=o.id.replace(n.id,r):o.id=this.canvas.collabEngine.freshId(),a[c]=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 n of this.connections){const i=this.canvas.collabEngine.freshId();if(a[n.id]=i,n.id=i,n.start=a[n.start]||n.start,n.end=a[n.end]||n.end,e)for(let r=0;r<n.points.length;++r)n.points[r]=[n.points[r][0]+e[0],n.points[r][1]+e[1]]}const l=new Jt(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 nt(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 nt(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 Qt{constructor(t){this.type=t,this.defaultPrevented=!1}preventDefault(){this.defaultPrevented=!0}}var Ue=(s=>(s[s.DoubleClick=0]="DoubleClick",s[s.SecondaryClick=1]="SecondaryClick",s[s.Selection=2]="Selection",s[s.Highlight=3]="Highlight",s))(Ue||{});class ft extends Qt{constructor(t,e,a){super(0),this.cause=t,this.target=e,this.coords=a}}class ut extends Qt{constructor(t,e,a){super(1),this.cause=t,this.target=e,this.coords=a}}class j extends Qt{constructor(t,e){super(2),this.targets=t,this.selected=e}}class J extends Qt{constructor(t){super(3),this.target=t}}class De extends xt{constructor(t,e,a,l,n,i,r,o,c="floating",d="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=n,this.priority=i,this.html=r,this.anchorPointX=c,this.anchorPointY=d}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 Fo extends ht{constructor(t){super(),this.model=t}new(t,e,a,l,n,i,r,o="floating",c="floating"){const d=new De(this.model,t,e,a,l,n,i,r,o,c);return super.add(d),d.updateInView(),t!==void 0&&t.decorators.push(d),d}remove(t){const e=this.get(t,!0);e&&((e.rootElement instanceof R||e.rootElement instanceof F)&&D(e.rootElement.decorators,e),super.remove(t),e.updateInView())}}class Uo extends xt{constructor(t,e,a,l,n,i,r){if(t.objects.get(r)!==void 0)throw new Error(`DiagramObject with id "${r}" already exists`);if(!r)throw new Error("DiagramObject cannot have an empty or null id");super(t,r),this.coords=e,this.width=a,this.height=l,this.priority=n,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 Do extends ht{constructor(t){super(),this.model=t}new(t,e,a,l,n,i){const r=new Uo(this.model,t,e,a,l,n,i);return super.add(r),r.updateInView(),r}remove(t){const e=this.get(t,!0);e&&(super.remove(t),e.updateInView())}}class Be{constructor(t,e,a,l,n,i=[]){this.nodes=new Lo(this),this.sections=new Ao(this),this.ports=new Ro(this),this.connections=new wo(this),this.fields=new So(this),this.objects=new Do(this),this.decorators=new Fo(this),this.canvas=t,this.id=e,this.name=a,this.description=l,this.type=n,this.createdAt=new Date,this.updatedAt=new Date,this.logicalClock=0,this.valueSet=new mt(new Zt(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 pt=s=>!!s.button,se=(s,t,e,a,l,n,i,r)=>so(s,[t,e],a,l,Math.max(10,i||0,r||0)*n),S=s=>{s?A.select("body").style("cursor",s):A.select("body").style("cursor",L.Auto)},lt=s=>s instanceof R?s:s instanceof F?s.node||s:s.rootElement instanceof R||s.rootElement instanceof F||s.rootElement instanceof vt?lt(s.rootElement):s,ne=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")},Tt={fillColor:"#FFFFFF",borderColor:"#000000",borderThickness:1,borderStyle:ue.Solid},re=s=>{s.filter(".shaped-look").select("path").attr("d",t=>he(t.look.shape||Et.Rectangle,0,0,t.width,t.height)).attr("fill",t=>t.look.fillColor||Tt.fillColor).attr("stroke",t=>t.look.borderColor||Tt.borderColor).attr("stroke-width",t=>`${t.look.borderThickness||Tt.borderThickness}px`).attr("stroke-dasharray",t=>de(t.look.borderStyle||Tt.borderStyle,t.type?.defaultLook?.borderThickness||t.look?.borderThickness||Tt.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)},Nt={style:"dots",color:"rgba(0, 0, 0, 0.1)",snap:!1,spacing:10,thickness:.05},Bo=(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})`)}},ge=96,Y=32,$t=ge+Y,Yo=Math.PI/4,Xo=100,Le={customButtons:[]};class Wo{constructor(t,e){this.canvas=t,this.config=e||Le}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]-$t}px`).attr("y",`${e[1]-$t}px`).attr("width",`${2*$t}px`).attr("height",`${2*$t}px`).style("pointer-events","none").on(C.ContextMenu,i=>{this.canvas.canUserPerformAction(w.ContextMenu)&&(t.preventDefault(),this.open(i))}).on(C.Click,i=>{i.preventDefault(),this.close()});this.contextMenuContainer=l;const n=[];this.canvas.userSelection.length!==0&&this.canvas.canUserPerformAction(w.Clipboard)&&this.canvas.canUserPerformAction(w.Remove)&&n.push({name:"CUT",imageClass:"daga-cut",onPress:i=>{i.userSelection.cutToClipboard(),i.cancelAllUserActions()}}),this.canvas.userSelection.length!==0&&this.canvas.canUserPerformAction(w.Clipboard)&&n.push({name:"COPY",imageClass:"daga-copy",onPress:i=>{i.userSelection.copyToClipboard(),i.cancelAllUserActions()}}),this.canvas.canUserPerformAction(w.Paste)&&n.push({name:"PASTE",imageClass:"daga-paste",onPress:i=>{i.userSelection.pasteFromClipboard(i.getClosestGridPoint(a)),i.cancelAllUserActions()}}),this.canvas.userSelection.length!==0&&this.canvas.canUserPerformAction(w.Remove)&&n.push({name:"DELETE",imageClass:"daga-delete",onPress:i=>{i.userSelection.removeFromModel(),i.cancelAllUserActions()}});for(const i of this.config.customButtons||Le.customButtons)(i.condition===void 0||i.condition(this.canvas))&&n.push(i);n.length===0&&n.push({name:"NONE",imageClass:"daga-cross",onPress:void 0});for(let i=0;i<n.length;++i){const r=n[i],o=r.onPress,c=(i+.5-n.length/2)*Yo,d=l.append("xhtml:div").attr("class",`daga-context-menu-button ${r.onPress!==void 0?" daga-clickable":""}`).attr("tabindex",0).style("position","absolute").style("box-sizing","border-box").style("width",`${2*Y}px`).style("height",`${2*Y}px`).style("border-radius",`${Y}px`).style("pointer-events","auto").on(C.Click,h=>{o&&(h.preventDefault(),o(this.canvas))}).on(C.KeyDown,h=>{o&&h.key===W.Enter&&(h.preventDefault(),o(this.canvas))});r.imageClass!==void 0?d.append("xhtml:div").style("position","absolute").style("left",`${.75*Y}px`).style("top",`${.5*Y}px`).style("width",`${.5*Y}px`).style("height",`${.5*Y}px`).style("background-size","contain").style("background-repeat","no-repeat").attr("class",r.imageClass):r.image!==void 0&&d.append("xhtml:img").style("position","absolute").style("left",`${.75*Y}px`).style("top",`${.5*Y}px`).style("width",`${.5*Y}px`).style("height",`${.5*Y}px`).attr("src",r.image),d.append("xhtml:span").style("position","absolute").style("left",`${.2*Y}px`).style("top",`${1.1*Y}px`).style("text-align","center").style("width",`${1.6*Y}px`).style("height",`${.35*Y}px`).style("margin","0").style("font-size",`${.35*Y}px`).style("font-weight","700").style("user-select","none").text(r.name),d.transition().ease(A.easeLinear).duration(Xo).tween("progress",()=>h=>{const u=c*h;return d.style("left",`${Math.sin(u)*ge-Y+$t}px`).style("top",`${-Math.cos(u)*ge-Y+$t}px`)})}}close(){this.contextMenuContainer?.remove(),this.contextMenuContainer=void 0}}class Zo extends ht{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 De)&&t.rootElement?this.focusOn(t.rootElement):this.add(t)}add(t){if(super.add(t),t instanceof R){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 F)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 vt?(t.label&&(super.add(t.label),this.canvas.updateFieldsInView(t.label.id)),this.canvas.updatePortsInView(t.id)):t instanceof at&&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 Ko=1;class Ye{export(t,e=!1){const a={name:t.name,type:t.type,typeVersion:Ko,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 r=[];for(const o of i.ports)r.push({id:o.id,type:o.type?.id,coords:Ct(o.coords),connectionPoint:Ct(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:r,label:i.label?.text||"",indexXInNode:i.indexXInNode,indexYInNode:i.indexYInNode,coords:Ct(i.coords),width:i.width,height:i.height,...e?{collabMeta:{removed:i.removed,selfRemoved:i.selfRemoved,selfRemovedTimestamp:i.selfRemovedTimestamp,...this.exportLabelCollabMeta(i)}}:{}})}const n=[];for(const i of t.ports)n.push({id:i.id,type:i.type?.id,coords:Ct(i.coords),connectionPoint:Ct(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:n,label:t.label?.text||"",coords:Ct(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 qo="Diagram properties";class Jo extends ht{constructor(t){super(),this.canvas=t,this.canvas.propertyEditorChanges$.pipe(kt.debounceTime(2e3)).subscribe(()=>{this.makeUpdateValuesAction()})}add(t){if(!this.contains(t.id)&&(this.length===0?this.propertyEditorSelection===void 0&&(t instanceof R||t instanceof at)?this.openInPropertyEditor(t):this.propertyEditorSelection===void 0&&t instanceof F?this.openInPropertyEditor(t.node):this.openInPropertyEditor(void 0):this.openInPropertyEditor(void 0),super.add(t),t.updateInView(),t instanceof R&&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 R&&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 R&&e.move([e.coords[0]+t[0],e.coords[1]+t[1]])}removeFromModel(){if(this.length>0){const t=[],e=[],a=[],l=[],n=[];for(const r of this.all())r instanceof R?t.push(r.id):r instanceof F?e.push(r.id):r instanceof vt?a.push(r.id):r instanceof at?l.push(r.id):r instanceof ct&&n.push(r.id);const i=new jo(this.canvas,t,e,a,l,n);i.do(),this.canvas.actionStack.add(i)}}copyToClipboard(){const t={type:"daga-user-selection",nodes:[],connections:[]},e=new Ye;for(const a of this.all())a instanceof R&&t.nodes.push(e.exportNode(a,!1)),a instanceof at&&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 Go(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=structuredClone(l.getValues())),a&&(t instanceof R||t instanceof at?(t instanceof R?t.name?a.title=`${t.type.name}: ${t.name}`:a.title=t.type.name:t instanceof at&&(a.title=t.type.name),a.valueSet=void 0,a.valueSet=l):(a.title=qo,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 Be?void 0:this.propertyEditorSelection.id;if(wt(this.propertyEditorValues,this.propertyEditorSelection?.valueSet.getValues()))return;const e=this.propertyEditorValues,a=structuredClone(this.propertyEditorSelection?.valueSet.getValues()),[l,n]=ze(e,a,this.propertyEditorSelection?.valueSet),i=new _o(this.canvas,t,l,n);i.do(),this.canvas.actionStack.add(i),this.propertyEditorValues=a}}const Qo=s=>s*Math.PI/180,Ee=(s,t,e)=>{const a=Qo(e),l=Math.sin(a),n=Math.cos(a),i=(Math.abs(s*n)-Math.abs(t*l))/(n*n-l*l),r=(Math.abs(s*l)-Math.abs(t*n))/(l*l-n*n);return[i,r]},ti=12,H=6,ei=25,ae="diagram-connection-unfinished",Xt=class Xt{constructor(t,e){if(this.backgroundPatternId=`daga-background-pattern-id-${Xt.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 Be(this,void 0,e.name||"unnamed","",e.type||"",e.properties||[]),this.userSelection=new Jo(this),this.userHighlight=new Zo(this,e.canvas?.highlightSections!==!1),this.contextMenu=new Wo(this,e.canvas?.contextMenu),this.backgroundColor=e.canvas?.backgroundColor||"#FFFFFF",this.gridStyle=e.canvas?.grid?.style??Nt.style,this.gridSize=e.canvas?.grid?.enabled===!1||e.canvas?.grid===void 0?0:Math.abs(e.canvas?.grid?.spacing||Nt.spacing),this.gridThickness=Math.abs(e.canvas?.grid?.thickness||Nt.thickness),this.gridColor=e.canvas?.grid?.color||Nt.color,this.snapToGrid=e.canvas?.grid?.enabled===!1||e.canvas?.grid===void 0?!1:e.canvas?.grid?.snap||Nt.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 Vo(this,ei),this.collabEngine=new zo(this),e.nodeTypes)for(const a of e.nodeTypes){const l=new He({...e.nodeTypeDefaults,...a});this.model.nodes.types.add(l)}if(e.portTypes)for(const a of e.portTypes){const l=new Po({...e.portTypeDefaults,...a});this.model.ports.types.add(l)}if(e.connectionTypes){for(const a of e.connectionTypes){const l=new Ve({...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){D(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(C.Click,()=>{A.select(this.diagramRoot).node()?.focus()}).on(C.ContextMenu,l=>{if(this.dragging){l.preventDefault(),l.stopPropagation(),this.dragging=!1;return}const n=new ut(l,null);this.diagramEvent$.next(n),!n.defaultPrevented&&this.canUserPerformAction(w.ContextMenu)&&(l.preventDefault(),this.contextMenu.open(l))}).on(C.DoubleClick,l=>{const n=new ft(l,null);this.diagramEvent$.next(n)}).on(C.KeyDown,l=>{if(!l.ctrlKey&&(l.key===W.Delete||l.key===W.Backspace)&&this.canUserPerformAction(w.Remove)&&(this.userSelection.removeFromModel(),this.cancelAllUserActions()),l.ctrlKey&&l.key==="a"){l.preventDefault();for(const n of this.model.nodes)this.userSelection.add(n);for(const n of this.model.connections)this.userSelection.add(n);this.diagramEvent$.next(new j(this.userSelection.all(),!0))}if(l.ctrlKey&&l.key==="i"){l.preventDefault();const n=[],i=[];for(const r of this.model.nodes)this.userSelection.toggle(r),r.selected?n.push(r):i.push(r);for(const r of this.model.connections)this.userSelection.toggle(r),r.selected?n.push(r):i.push(r);n.length>0&&this.diagramEvent$.next(new j(n,!0)),i.length>0&&this.diagramEvent$.next(new j(i,!1))}if(l.ctrlKey&&l.key==="c"&&this.canUserPerformAction(w.Clipboard)&&(l.preventDefault(),this.userSelection.copyToClipboard(),this.cancelAllUserActions()),l.ctrlKey&&l.key==="x"&&this.canUserPerformAction(w.Clipboard)&&this.canUserPerformAction(w.Remove)&&(l.preventDefault(),this.userSelection.cutToClipboard(),this.cancelAllUserActions()),l.ctrlKey&&l.key==="v"&&this.canUserPerformAction(w.Paste)){l.preventDefault();const n=this.getCoordinatesOnScreen();this.userSelection.pasteFromClipboard(this.getClosestGridPoint([(n[0][0]+n[1][0])/2,(n[0][1]+n[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(w.Zoom)&&(l.preventDefault(),this.zoomBy(this.zoomFactor)),l.key==="-"&&this.canUserPerformAction(w.Zoom)&&(l.preventDefault(),this.zoomBy(1/this.zoomFactor)),l.key===W.ArrowLeft&&this.canUserPerformAction(w.Zoom)&&(l.preventDefault(),this.translateBy(this.panRate/this.zoomTransform.k,0)),l.key===W.ArrowRight&&this.canUserPerformAction(w.Zoom)&&(l.preventDefault(),this.translateBy(-this.panRate/this.zoomTransform.k,0)),l.key===W.ArrowDown&&this.canUserPerformAction(w.Zoom)&&(l.preventDefault(),this.translateBy(0,-this.panRate/this.zoomTransform.k)),l.key===W.ArrowUp&&this.canUserPerformAction(w.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!==C.DoubleClick).on(le.Zoom,l=>{if(l.sourceEvent){if(!this.canUserPerformAction(w.Zoom)){S(L.NotAllowed);return}l.sourceEvent.type===C.Wheel&&l.sourceEvent.wheelDelta!==void 0?(l.sourceEvent.wheelDelta>0&&S(L.ZoomIn),l.sourceEvent.wheelDelta<0&&S(L.ZoomOut)):l.sourceEvent.type===C.MouseMove&&S(L.AllScroll)}this.zoomTransform=l.transform;const n=l.transform.toString();this.selectCanvasElements().attr("transform",n),A.select(`#${this.backgroundPatternId}`).attr("patternTransform",n),this.contextMenu.close()}).on(le.End,()=>{S()})),a.append("rect").attr("x",0).attr("y",0).attr("width","100%").attr("height","100%").attr("fill",this.backgroundColor).attr("stroke-width","0").on(C.MouseMove,l=>{if(this.unfinishedConnection!==void 0){const n=this.getPointerLocationRelativeToCanvas(l);this.unfinishedConnection.endCoords=n}}).on(C.MouseOver,()=>{this.userHighlight.size()>0&&(this.userHighlight.clear(),this.diagramEvent$.next(new J(null)))}).on(C.Click,()=>{if(this.userHighlight.size()>0&&(this.userHighlight.clear(),this.diagramEvent$.next(new J(null))),this.contextMenu.close(),this.userSelection.size()>0){const l=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new j(l,!1)),this.userSelection.openInPropertyEditor(this.model)}}).call(A.drag().filter(l=>this.multipleSelectionOn||pt(l)).on($.Start,l=>{this.startMultipleSelection(l)}).on($.Drag,l=>{this.continueMultipleSelection(l)}).on($.End,l=>{this.finishMultipleSelection(l)})),Bo(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(v=>v.coords[0])),l=Math.max(...e.map(v=>v.coords[0]+v.width)),n=(a+l)/2,i=l-a,r=t.width,o=Math.min(...e.map(v=>v.coords[1])),c=Math.max(...e.map(v=>v.coords[1]+v.height)),d=(o+c)/2,h=c-o,u=t.height,y=Math.min(r/i,u/h,1);this.translateTo(n,d),this.zoomTo(y)}}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 n=l.merge(e);a.remove(),l.on(C.MouseOver,(i,r)=>{this.dragging||(this.userHighlight.focusOn(r),this.diagramEvent$.next(new J(r)))}).on(C.Click,(i,r)=>{if(!i.ctrlKey&&!i.shiftKey){const o=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new j(o,!1))}this.userSelection.toggle(r),this.diagramEvent$.next(new j([r],r.selected))}).on(C.ContextMenu,(i,r)=>{if(this.dragging){i.preventDefault(),i.stopPropagation(),this.dragging=!1;return}const o=new ut(i,r);this.diagramEvent$.next(o),!o.defaultPrevented&&this.canUserPerformAction(w.ContextMenu)&&(i.preventDefault(),this.userHighlight.focusOn(r),this.diagramEvent$.next(new J(r)),this.userSelection.add(r),this.diagramEvent$.next(new j([r],!0)),this.contextMenu.open(i))}).on(C.DoubleClick,(i,r)=>{const o=new ft(i,r);this.diagramEvent$.next(o)}).call(A.drag().filter(i=>(this.secondaryButton=pt(i),!0)).on($.Start,(i,r)=>{this.multipleSelectionOn||this.secondaryButton?this.startMultipleSelection(i):this.startMovingNode(i,r)}).on($.Drag,(i,r)=>{this.multipleSelectionOn||this.secondaryButton?this.continueMultipleSelection(i):this.continueMovingNode(i,r)}).on($.End,(i,r)=>{this.multipleSelectionOn||this.secondaryButton?this.finishMultipleSelection(i):this.finishMovingNode(i,r),this.secondaryButton=!1})),ne(l),l.filter(".resizable-x").append("line").attr("class","left-resizer").attr("stroke","transparent").attr("stroke-width",`${H}px`).on(C.MouseOver,(i,r)=>{this.canUserPerformAction(w.StretchNode)&&r.type.resizableX&&!r.removed&&S(L.EWResize)}).on(C.MouseOut,(i,r)=>{this.canUserPerformAction(w.StretchNode)&&r.type.resizableX&&!r.removed&&S()}).call(A.drag().on($.Start,(i,r)=>{this.canUserPerformAction(w.StretchNode)&&r.type.resizableX&&!r.removed?(S(L.EWResize),this.currentAction=new B(this,w.StretchNode,r.id,r.getGeometry(),r.getGeometry())):S(L.NotAllowed)}).on($.Drag,(i,r)=>{if(this.canUserPerformAction(w.StretchNode)&&r.type.resizableX&&!r.removed){const o=this.getPointerLocationRelativeToCanvas(i);r.stretch(g.Left,r.coords[0]-o[0])}}).on($.End,(i,r)=>{if(this.canUserPerformAction(w.StretchNode)&&r.type.resizableX&&!r.removed&&this.currentAction instanceof B&&this.currentAction.intent===w.StretchNode){let o=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(o=this.getClosestGridPoint([o[0]-r.type.snapToGridOffset[0],o[1]-r.type.snapToGridOffset[1]]),o[0]+=r.type.snapToGridOffset[0],o[1]+=r.type.snapToGridOffset[1]),r.stretch(g.Left,r.coords[0]-o[0]),this.currentAction.to=r.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}S()})),l.filter(".resizable-y").append("line").attr("class","top-resizer").attr("stroke","transparent").attr("stroke-width",`${H}px`).on(C.MouseOver,(i,r)=>{this.canUserPerformAction(w.StretchNode)&&r.type.resizableY&&!r.removed&&S(L.NSResize)}).on(C.MouseOut,(i,r)=>{this.canUserPerformAction(w.StretchNode)&&r.type.resizableY&&!r.removed&&S()}).call(A.drag().on($.Start,(i,r)=>{this.canUserPerformAction(w.StretchNode)&&r.type.resizableY&&!r.removed?(S(L.NSResize),this.currentAction=new B(this,w.StretchNode,r.id,r.getGeometry(),r.getGeometry())):S(L.NotAllowed)}).on($.Drag,(i,r)=>{if(this.canUserPerformAction(w.StretchNode)&&r.type.resizableY&&!r.removed){const o=this.getPointerLocationRelativeToCanvas(i);r.stretch(g.Top,r.coords[1]-o[1])}}).on($.End,(i,r)=>{if(this.canUserPerformAction(w.StretchNode)&&r.type.resizableY&&!r.removed&&this.currentAction instanceof B&&this.currentAction.intent===w.StretchNode){let o=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(o=this.getClosestGridPoint([o[0]-r.type.snapToGridOffset[0],o[1]-r.type.snapToGridOffset[1]]),o[0]+=r.type.snapToGridOffset[0],o[1]+=r.type.snapToGridOffset[1]),r.stretch(g.Top,r.coords[1]-o[1]),this.currentAction.to=r.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}S()})),l.filter(".resizable-x").append("line").attr("class","right-resizer").attr("stroke","transparent").attr("stroke-width",`${H}px`).on(C.MouseOver,(i,r)=>{this.canUserPerformAction(w.StretchNode)&&r.type.resizableX&&!r.removed&&S(L.EWResize)}).on(C.MouseOut,(i,r)=>{this.canUserPerformAction(w.StretchNode)&&r.type.resizableX&&!r.removed&&S()}).call(A.drag().on($.Start,(i,r)=>{this.canUserPerformAction(w.StretchNode)&&r.type.resizableX&&!r.removed?(S(L.EWResize),this.currentAction=new B(this,w.StretchNode,r.id,r.getGeometry(),r.getGeometry())):S(L.NotAllowed)}).on($.Drag,(i,r)=>{if(this.canUserPerformAction(w.StretchNode)&&r.type.resizableX&&!r.removed){const o=this.getPointerLocationRelativeToCanvas(i);r.stretch(g.Right,o[0]-(r.coords[0]+r.width))}}).on($.End,(i,r)=>{if(this.canUserPerformAction(w.StretchNode)&&r.type.resizableX&&!r.removed&&this.currentAction instanceof B&&this.currentAction.intent===w.StretchNode){let o=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(o=this.getClosestGridPoint([o[0]-r.type.snapToGridOffset[2],o[1]-r.type.snapToGridOffset[3]]),o[0]+=r.type.snapToGridOffset[2],o[1]+=r.type.snapToGridOffset[3]),r.stretch(g.Right,o[0]-(r.coords[0]+r.width)),this.currentAction.to=r.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}S()})),l.filter(".resizable-y").append("line").attr("class","bottom-resizer").attr("stroke","transparent").attr("stroke-width",`${H}px`).on(C.MouseOver,(i,r)=>{this.canUserPerformAction(w.StretchNode)&&r.type.resizableY&&!r.removed&&S(L.NSResize)}).on(C.MouseOut,(i,r)=>{this.canUserPerformAction(w.StretchNode)&&r.type.resizableY&&!r.removed&&S()}).call(A.drag().on($.Start,(i,r)=>{this.canUserPerformAction(w.StretchNode)&&r.type.resizableY&&!r.removed?(S(L.NSResize),this.currentAction=new B(this,w.StretchNode,r.id,r.getGeometry(),r.getGeometry())):S(L.NotAllowed)}).on($.Drag,(i,r)=>{if(this.canUserPerformAction(w.StretchNode)&&r.type.resizableY&&!r.removed){const o=this.getPointerLocationRelativeToCanvas(i);r.stretch(g.Bottom,o[1]-(r.coords[1]+r.height))}}).on($.End,(i,r)=>{if(this.canUserPerformAction(w.StretchNode)&&r.type.resizableY&&!r.removed&&this.currentAction instanceof B&&this.currentAction.intent===w.StretchNode){let o=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&this.snapToGrid&&(o=this.getClosestGridPoint([o[0]-r.type.snapToGridOffset[2],o[1]-r.type.snapToGridOffset[3]]),o[0]+=r.type.snapToGridOffset[2],o[1]+=r.type.snapToGridOffset[3]),r.stretch(g.Bottom,o[1]-(r.coords[1]+r.height)),this.currentAction.to=r.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}S()})),n.attr("transform",i=>`translate(${i.coords[0]},${i.coords[1]})`).attr("opacity",i=>i.removed?.5:1),re(n),n.filter(".resizable-x").select("line.left-resizer").attr("x1",H/2).attr("x2",H/2).attr("y1",0).attr("y2",i=>i.height),n.filter(".resizable-y").select("line.top-resizer").attr("x1",0).attr("x2",i=>i.width).attr("y1",H/2).attr("y2",H/2),n.filter(".resizable-x").select("line.right-resizer").attr("x1",i=>i.width-H/2).attr("x2",i=>i.width-H/2).attr("y1",0).attr("y2",i=>i.height),n.filter(".resizable-y").select("line.bottom-resizer").attr("x1",0).attr("x2",i=>i.width).attr("y1",i=>i.height-H/2).attr("y2",i=>i.height-H/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 n=l.merge(e);a.remove(),l.on(C.MouseOver,(i,r)=>{this.dragging||(this.userHighlight.focusOn(r),this.diagramEvent$.next(new J(r)))}).on(C.Click,(i,r)=>{if(!i.ctrlKey&&!i.shiftKey){const c=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new j(c,!1))}const o=lt(r);this.userSelection.toggle(o),this.diagramEvent$.next(new j([o],o.selected))}).on(C.ContextMenu,(i,r)=>{if(this.dragging){i.preventDefault(),i.stopPropagation(),this.dragging=!1;return}const o=new ut(i,r);if(this.diagramEvent$.next(o),!o.defaultPrevented&&this.canUserPerformAction(w.ContextMenu)){i.preventDefault();const c=lt(r);this.userHighlight.focusOn(c),this.diagramEvent$.next(new J(c)),this.userSelection.add(c),this.diagramEvent$.next(new j([c],!0)),this.contextMenu.open(i)}}).on(C.DoubleClick,(i,r)=>{const o=new ft(i,r);this.diagramEvent$.next(o)}).call(A.drag().filter(i=>(this.secondaryButton=pt(i),!0)).on($.Start,(i,r)=>{if(this.multipleSelectionOn||this.secondaryButton)this.startMultipleSelection(i);else{const o=r?.node;o?this.startMovingNode(i,o):S(L.NotAllowed)}}).on($.Drag,(i,r)=>{if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(i);else{const o=r?.node;o?this.continueMovingNode(i,o):S(L.NotAllowed)}}).on($.End,(i,r)=>{if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(i);else{const o=r?.node;o?this.finishMovingNode(i,o):S()}this.secondaryButton=!1})),ne(l),l.filter(".resizable-x").append("line").attr("class","left-resizer").attr("stroke","transparent").attr("stroke-width",`${H}px`).on(C.MouseOver,(i,r)=>{this.canUserPerformAction(w.StretchSection)&&r.getResizableX()&&!r.removed&&S(L.EWResize)}).on(C.MouseOut,(i,r)=>{this.canUserPerformAction(w.StretchSection)&&r.getResizableX()&&!r.removed&&S()}).call(A.drag().on($.Start,(i,r)=>{this.canUserPerformAction(w.StretchSection)&&r.getResizableX()&&!r.removed&&r.node?(S(L.EWResize),this.currentAction=new B(this,w.StretchSection,r.node.id,r.node.getGeometry(),r.node.getGeometry())):S(L.NotAllowed)}).on($.Drag,(i,r)=>{if(this.canUserPerformAction(w.StretchSection)&&r.getResizableX()&&!r.removed&&r.node){const o=this.getPointerLocationRelativeToCanvas(i);r.node.stretchSections(g.Left,r.coords[0]-o[0],r.indexXInNode,r.indexYInNode)}}).on($.End,(i,r)=>{if(this.canUserPerformAction(w.StretchSection)&&r.getResizableX()&&!r.removed&&this.currentAction instanceof B&&this.currentAction.intent===w.StretchSection&&r.node){let o=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(o=this.getClosestGridPoint(o)),r.node.stretchSections(g.Left,r.coords[0]-o[0],r.indexXInNode,r.indexYInNode),this.currentAction.to=r.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}S()})),l.filter(".resizable-y").append("line").attr("class","top-resizer").attr("stroke","transparent").attr("stroke-width",`${H}px`).on(C.MouseOver,(i,r)=>{this.canUserPerformAction(w.StretchSection)&&r.getResizableY()&&!r.removed&&S(L.NSResize)}).on(C.MouseOut,(i,r)=>{this.canUserPerformAction(w.StretchSection)&&r.getResizableY()&&!r.removed&&S()}).call(A.drag().on($.Start,(i,r)=>{this.canUserPerformAction(w.StretchSection)&&r.getResizableY()&&!r.removed&&r.node?(S(L.NSResize),this.currentAction=new B(this,w.StretchSection,r.node.id,r.node.getGeometry(),r.node.getGeometry())):S(L.NotAllowed)}).on($.Drag,(i,r)=>{if(this.canUserPerformAction(w.StretchSection)&&r.getResizableY()&&!r.removed&&r.node){const o=this.getPointerLocationRelativeToCanvas(i);r.node.stretchSections(g.Top,r.coords[1]-o[1],r.indexXInNode,r.indexYInNode)}}).on($.End,(i,r)=>{if(this.canUserPerformAction(w.StretchSection)&&r.getResizableY()&&!r.removed&&this.currentAction instanceof B&&this.currentAction.intent===w.StretchSection&&r.node){let o=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(o=this.getClosestGridPoint(o)),r.node.stretchSections(g.Top,r.coords[1]-o[1],r.indexXInNode,r.indexYInNode),this.currentAction.to=r.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}S()})),l.filter(".resizable-x").append("line").attr("class","right-resizer").attr("stroke","transparent").attr("stroke-width",`${H}px`).on(C.MouseOver,(i,r)=>{this.canUserPerformAction(w.StretchSection)&&r.getResizableX()&&!r.removed&&S(L.EWResize)}).on(C.MouseOut,(i,r)=>{this.canUserPerformAction(w.StretchSection)&&r.getResizableX()&&!r.removed&&S()}).call(A.drag().on($.Start,(i,r)=>{this.canUserPerformAction(w.StretchSection)&&r.getResizableX()&&!r.removed&&r.node?(S(L.EWResize),this.currentAction=new B(this,w.StretchSection,r.node.id,r.node.getGeometry(),r.node.getGeometry())):S(L.NotAllowed)}).on($.Drag,(i,r)=>{if(this.canUserPerformAction(w.StretchSection)&&r.getResizableX()&&!r.removed&&r.node){const o=this.getPointerLocationRelativeToCanvas(i);r.node.stretchSections(g.Right,o[0]-(r.coords[0]+r.width),r.indexXInNode,r.indexYInNode)}}).on($.End,(i,r)=>{if(this.canUserPerformAction(w.StretchSection)&&r.getResizableX()&&!r.removed&&this.currentAction instanceof B&&this.currentAction.intent===w.StretchSection&&r.node){let o=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(o=this.getClosestGridPoint(o)),r.node.stretchSections(g.Right,o[0]-(r.coords[0]+r.width),r.indexXInNode,r.indexYInNode),this.currentAction.to=r.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}S()})),l.filter(".resizable-y").append("line").attr("class","bottom-resizer").attr("stroke","transparent").attr("stroke-width",`${H}px`).on(C.MouseOver,(i,r)=>{this.canUserPerformAction(w.StretchSection)&&r.getResizableY()&&!r.removed&&S(L.NSResize)}).on(C.MouseOut,(i,r)=>{this.canUserPerformAction(w.StretchSection)&&r.getResizableY()&&!r.removed&&S()}).call(A.drag().on($.Start,(i,r)=>{this.canUserPerformAction(w.StretchSection)&&r.getResizableY()&&!r.removed&&r.node?(S(L.NSResize),this.currentAction=new B(this,w.StretchSection,r.node.id,r.node.getGeometry(),r.node.getGeometry())):S(L.NotAllowed)}).on($.Drag,(i,r)=>{if(this.canUserPerformAction(w.StretchSection)&&r.getResizableY()&&!r.removed&&r.node){const o=this.getPointerLocationRelativeToCanvas(i);r.node.stretchSections(g.Bottom,o[1]-(r.coords[1]+r.height),r.indexXInNode,r.indexYInNode)}}).on($.End,(i,r)=>{if(this.canUserPerformAction(w.StretchSection)&&r.getResizableY()&&!r.removed&&this.currentAction instanceof B&&this.currentAction.intent===w.StretchSection&&r.node){let o=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(o=this.getClosestGridPoint(o)),r.node.stretchSections(g.Bottom,o[1]-(r.coords[1]+r.height),r.indexXInNode,r.indexYInNode),this.currentAction.to=r.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}S()})),n.attr("transform",i=>`translate(${i.coords[0]},${i.coords[1]})`).attr("opacity",i=>i.removed?.5:1),re(n),n.filter(".resizable-x").select("line.left-resizer").attr("x1",H/2).attr("x2",H/2).attr("y1",0).attr("y2",i=>i.height),n.filter(".resizable-y").select("line.top-resizer").attr("x1",0).attr("x2",i=>i.width).attr("y1",H/2).attr("y2",H/2),n.filter(".resizable-x").select("line.right-resizer").attr("x1",i=>i.width-H/2).attr("x2",i=>i.width-H/2).attr("y1",0).attr("y2",i=>i.height),n.filter(".resizable-y").select("line.bottom-resizer").attr("x1",0).attr("x2",i=>i.width).attr("y1",i=>i.height-H/2).attr("y2",i=>i.height-H/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 n=l.merge(e);a.remove(),l.on(C.MouseOver,(i,r)=>{!this.unfinishedConnection&&!this.dragging&&(this.userHighlight.focusOn(r),this.diagramEvent$.next(new J(r))),this.unfinishedConnection&&(this.unfinishedConnection.type.canStartFromType(this.unfinishedConnection.start?.getNode()?.type?.id||"")&&this.unfinishedConnection.start?.allowsOutgoing&&this.unfinishedConnection.type.canFinishOnType(r.getNode()?.type?.id||"")&&r.allowsIncoming||this.unfinishedConnection.type.canStartFromType(r.getNode()?.type?.id||"")&&r.allowsOutgoing&&this.unfinishedConnection.type.canFinishOnType(this.unfinishedConnection.start?.getNode()?.type?.id||"")&&this.unfinishedConnection.start?.allowsIncoming||S(L.NoDrop))}).on(C.MouseOut,()=>{this.unfinishedConnection&&S(L.Grabbing)}).on(C.Click,(i,r)=>{if(!i.ctrlKey&&!i.shiftKey){const c=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new j(c,!1))}const o=lt(r);this.userSelection.toggle(o),this.diagramEvent$.next(new j([o],o.selected))}).on(C.ContextMenu,(i,r)=>{if(this.dragging){i.preventDefault(),i.stopPropagation(),this.dragging=!1;return}const o=new ut(i,r);if(this.diagramEvent$.next(o),!o.defaultPrevented&&this.canUserPerformAction(w.ContextMenu)){i.preventDefault();const c=lt(r);this.userHighlight.focusOn(c),this.diagramEvent$.next(new J(c)),this.userSelection.add(c),this.diagramEvent$.next(new j([c],!0)),this.contextMenu.open(i)}}).on(C.DoubleClick,(i,r)=>{const o=new ft(i,r);this.diagramEvent$.next(o)}).call(A.drag().filter(i=>(this.secondaryButton=pt(i),!0)).on($.Start,(i,r)=>{this.multipleSelectionOn||this.secondaryButton?this.startMultipleSelection(i):this.canUserPerformAction(w.AddConnection)&&(this.allowSharingPorts||r.incomingConnections.length===0&&r.outgoingConnections.length===0)&&!r.removed?(S(L.Grabbing),this.startConnection(r),this.unfinishedConnection&&(this.unfinishedConnectionTracer=this.selectCanvasElements().append("path").attr("stroke","none").attr("fill","none"))):S(L.NotAllowed)}).on($.Drag,(i,r)=>{if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(i);else if(this.canUserPerformAction(w.AddConnection)&&!r.removed&&this.unfinishedConnection!==void 0){const o=[i.x,i.y];this.unfinishedConnectionTracer?.attr("d",se(this.unfinishedConnection.look.shape||tt.look.shape,this.unfinishedConnection.startCoords,o,this.unfinishedConnection.startDirection,this.unfinishedConnection.endDirection,this.unfinishedConnection.type.defaultLook.thickness||tt.look.thickness,this.unfinishedConnection.type.defaultStartMarkerLook?.width,this.unfinishedConnection.type.defaultEndMarkerLook?.width));const c=this.unfinishedConnectionTracer?.node();if(c){let d=2;const h=c.getTotalLength();h<d&&(d=0);const u=c.getPointAtLength(h-d);this.unfinishedConnection.endCoords=[u.x,u.y]}else this.unfinishedConnection.endCoords=o;if(this.updateConnectionsInView(ae),this.model.ports.length>0){const d=this.getPointerLocationRelativeToCanvas(i);let h=Number.POSITIVE_INFINITY,u;for(const y of this.model.ports){const v=y.distanceTo(d);v<h&&(h=v,u=y)}u&&h<this.portHighlightRadius?this.userHighlight.focusOn(u):this.userHighlight.clear()}}}).on($.End,(i,r)=>{if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(i);else{if(this.canUserPerformAction(w.AddConnection)&&!r.removed){this.unfinishedConnectionTracer?.remove();const o=this.userHighlight.getFocus();if(o instanceof vt)this.finishConnection(o);else if(o instanceof ct&&o.rootElement instanceof vt)this.finishConnection(o.rootElement);else if(o instanceof R||o instanceof F||o instanceof ct){let c;if(o instanceof R||o instanceof F)c=o;else if(o.rootElement instanceof R||o.rootElement instanceof F)c=o.rootElement;else{this.dropConnection();return}const d=c.getClosestPortToPoint([i.x,i.y]);d!==void 0?this.finishConnection(d):this.dropConnection()}else this.dropConnection()}S()}this.secondaryButton=!1})),l.filter(".image-look").append("image"),ne(l),n.attr("transform",i=>`translate(${i.coords[0]-i.width/2},${i.coords[1]-i.width/2})`).attr("opacity",i=>i.removed?.5:1),re(n)}updateConnectionsInView(...t){const e=this.model.connections.filter(r=>this.priorityThreshold!==void 0?r.getPriority()>=this.priorityThreshold:!0);this.unfinishedConnection&&e.push(this.unfinishedConnection);let a=this.selectCanvasElements().selectAll("g.diagram-connection").data(e,r=>r.id);const l=a.exit(),n=a.enter().append("g").attr("id",r=>r.id).attr("class","diagram-connection");t&&t.length>0&&(a=a.filter(r=>t.includes(r.id)));const i=n.merge(a);l.remove(),n.on(C.MouseOver,(r,o)=>{o.end!==void 0&&!this.dragging&&(this.userHighlight.focusOn(o),this.diagramEvent$.next(new J(o)))}).on(C.Click,(r,o)=>{if(!r.ctrlKey&&!r.shiftKey){const c=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new j(c,!1))}this.userSelection.toggle(o),this.diagramEvent$.next(new j([o],o.selected))}).on(C.ContextMenu,(r,o)=>{if(this.dragging){r.preventDefault(),r.stopPropagation(),this.dragging=!1;return}const c=new ut(r,o);this.diagramEvent$.next(c),!c.defaultPrevented&&this.canUserPerformAction(w.ContextMenu)&&(r.preventDefault(),this.userHighlight.focusOn(o),this.diagramEvent$.next(new J(o)),this.userSelection.add(o),this.diagramEvent$.next(new j([o],!0)),this.contextMenu.open(r))}).on(C.DoubleClick,(r,o)=>{const c=new ft(r,o);this.diagramEvent$.next(c)}).call(A.drag().filter(r=>(this.secondaryButton=pt(r),!0)).on($.Start,r=>{this.startMultipleSelection(r)}).on($.Drag,r=>{this.continueMultipleSelection(r)}).on($.End,r=>{this.finishMultipleSelection(r)})),n.append("path").attr("class","diagram-connection-path"),n.append("path").attr("class","diagram-connection-path-box"),n.append("marker").attr("id",r=>`${r.id}-start-marker`).attr("class","diagram-connection-start-marker").append("image").attr("preserveAspectRatio","none"),n.append("marker").attr("id",r=>`${r.id}-end-marker`).attr("class","diagram-connection-end-marker").append("image").attr("preserveAspectRatio","none"),n.append("g").attr("class","diagram-connection-start-label"),n.select("g.diagram-connection-start-label").append("path"),n.select("g.diagram-connection-start-label").append("text").style("user-select","none"),n.append("g").attr("class","diagram-connection-middle-label"),n.select("g.diagram-connection-middle-label").append("path"),n.select("g.diagram-connection-middle-label").append("text").style("user-select","none"),n.append("g").attr("class","diagram-connection-end-label"),n.select("g.diagram-connection-end-label").append("path"),n.select("g.diagram-connection-end-label").append("text").style("user-select","none"),i.attr("opacity",r=>r.removed?.5:1).select("path.diagram-connection-path").attr("d",r=>se(r.look.shape||tt.look.shape,r.startCoords,r.endCoords,r.startDirection,r.endDirection,r.type.defaultLook.thickness||tt.look.thickness,r.type.defaultStartMarkerLook?.width,r.type.defaultEndMarkerLook?.width)).attr("marker-start",r=>`url(#${r.id}-start-marker)`).attr("marker-end",r=>`url(#${r.id}-end-marker)`).attr("stroke",r=>r.look.color||tt.look.color).attr("stroke-width",r=>`${r.look.thickness}px`).attr("stroke-dasharray",r=>de(r.look.style||tt.look.style,r.type.defaultLook.thickness||tt.look.thickness)).attr("fill","none"),i.select("path.diagram-connection-path-box").attr("d",r=>se(r.look.shape||tt.look.shape,r.startCoords,r.endCoords,r.startDirection,r.endDirection,r.type.defaultLook.thickness||tt.look.thickness,r.type.defaultStartMarkerLook?.width,r.type.defaultEndMarkerLook?.width)).attr("stroke","transparent").attr("pointer-events","stroke").attr("stroke-width",r=>`${(r.look.thickness||tt.look.thickness)+ti}px`).attr("stroke-dasharray",r=>de(r.look.style||tt.look.style,r.type.defaultLook.thickness||tt.look.thickness)).attr("fill","none"),i.data().forEach(r=>{this.updateConnectionLabelsInView(r),this.updateConnectionMarkersInView(r)})}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 n=l.merge(e);a.remove(),l.style("box-sizing","border-box").on(C.MouseOver,(i,r)=>{this.dragging||(this.userHighlight.focusOn(r),this.diagramEvent$.next(new J(r)))}).on(C.Click,(i,r)=>{if(!i.ctrlKey&&!i.shiftKey){const c=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new j(c,!1))}const o=lt(r);this.userSelection.toggle(o),this.diagramEvent$.next(new j([o],o.selected))}).on(C.ContextMenu,(i,r)=>{if(this.dragging){i.preventDefault(),i.stopPropagation(),this.dragging=!1;return}const o=new ut(i,r);if(this.diagramEvent$.next(o),!o.defaultPrevented&&this.canUserPerformAction(w.ContextMenu)){i.preventDefault();const c=lt(r);this.userHighlight.focusOn(c),this.diagramEvent$.next(new J(c)),this.userSelection.add(c),this.diagramEvent$.next(new j([c],!0)),this.contextMenu.open(i)}}).on(C.DoubleClick,(i,r)=>{const o=new ft(i,r);this.diagramEvent$.next(o),!o.defaultPrevented&&this.canUserPerformAction(w.EditField)&&r.editable&&!r.removed&&(this.currentAction=new Ae(this,r.id,r.text,""),this.createInputField(r.text,r.coords,r.width,r.height,r.fontSize,r.fontFamily||V.fontFamily,r.orientation,c=>{},c=>{r.text=c,this.currentAction instanceof Ae&&(this.currentAction.to=c,this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0)}))}).call(A.drag().filter(i=>(this.secondaryButton=pt(i),!0)).on($.Start,(i,r)=>{if(this.multipleSelectionOn||this.secondaryButton)this.startMultipleSelection(i);else{let o;r.rootElement instanceof R?o=r.rootElement:r.rootElement instanceof F&&(o=r.rootElement.node),o?this.startMovingNode(i,o):S(L.NotAllowed)}}).on($.Drag,(i,r)=>{if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(i);else{let o;r.rootElement instanceof R?o=r.rootElement:r.rootElement instanceof F&&(o=r.rootElement.node),o?this.continueMovingNode(i,o):S(L.NotAllowed)}}).on($.End,(i,r)=>{if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(i);else{let o;r.rootElement instanceof R?o=r.rootElement:r.rootElement instanceof F&&(o=r.rootElement.node),o?this.finishMovingNode(i,o):S()}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"),n.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===It.Center?"center":i.horizontalAlign===It.Right?"flex-end":"flex-start").style("align-items",i=>i.verticalAlign===Bt.Center?"center":i.verticalAlign===Bt.Bottom?"end":"start").select("p").style("max-width",i=>i.fit?"default":`${Ee(i.width,i.height,i.orientation)[0]}px`).style("max-height",i=>i.fit?"default":`${Ee(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===It.Center?"center":i.horizontalAlign===It.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,"<").replace(/>/g,">").replace(/\n/g,"<br/>"))}updateObjectsInView(...t){let e=this.selectCanvasElements().selectAll("foreignObject.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("foreignObject").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(C.ContextMenu,(i,r)=>{if(this.dragging){i.preventDefault(),i.stopPropagation(),this.dragging=!1;return}const o=new ut(i,r);this.diagramEvent$.next(o),!o.defaultPrevented&&this.canUserPerformAction(w.ContextMenu)&&(i.preventDefault(),this.contextMenu.open(i))}).on(C.DoubleClick,(i,r)=>{const o=new ft(i,r);this.diagramEvent$.next(o)}).call(A.drag().filter(i=>(this.secondaryButton=pt(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("foreignObject.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("foreignObject").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(C.MouseOver,(i,r)=>{this.dragging||(this.userHighlight.focusOn(r),this.diagramEvent$.next(new J(r)))}).on(C.Click,(i,r)=>{if(!i.ctrlKey&&!i.shiftKey){const o=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new j(o,!1))}if(r.rootElement){const o=lt(r.rootElement);this.userSelection.toggle(o),this.diagramEvent$.next(new j([o],o.selected))}}).on(C.ContextMenu,(i,r)=>{if(this.dragging){i.preventDefault(),i.stopPropagation(),this.dragging=!1;return}const o=new ut(i,r);if(this.diagramEvent$.next(o),!o.defaultPrevented&&this.canUserPerformAction(w.ContextMenu)&&r.rootElement){i.preventDefault();const c=lt(r.rootElement);this.userHighlight.focusOn(c),this.diagramEvent$.next(new J(c)),this.userSelection.add(c),this.diagramEvent$.next(new j([c],!0)),this.contextMenu.open(i)}}).on(C.DoubleClick,(i,r)=>{const o=new ft(i,r);this.diagramEvent$.next(o)}).call(A.drag().filter(i=>(this.secondaryButton=pt(i),!0)).on($.Start,(i,r)=>{if(this.multipleSelectionOn||this.secondaryButton)this.startMultipleSelection(i);else{let o;r.rootElement instanceof R?o=r.rootElement:r.rootElement instanceof F&&(o=r.rootElement.node),o?this.startMovingNode(i,o):S(L.NotAllowed)}}).on($.Drag,(i,r)=>{if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(i);else{let o;r.rootElement instanceof R?o=r.rootElement:r.rootElement instanceof F&&(o=r.rootElement.node),o?this.continueMovingNode(i,o):S(L.NotAllowed)}}).on($.End,(i,r)=>{if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(i);else{let o;r.rootElement instanceof R?o=r.rootElement:r.rootElement instanceof F&&(o=r.rootElement.node),o?this.finishMovingNode(i,o):S()}this.secondaryButton=!1}))}updateConnectionLabelsInView(t){const e=this.selectCanvasView().select(`[id='${ce(t.id)}']`),l=e.select("path").node(),n={...V,...t.type.label};if(l){const i=l.getTotalLength();let r=0,o=0,c=0,d=0,h=0,u=0;if(n.backgroundColor==="#00000000"){const p=t.endCoords[0]-t.startCoords[0],k=t.endCoords[1]-t.startCoords[1];switch(t.startDirection){case g.Top:r=p>=0?-.5:.5,h=r;break;case g.Bottom:r=p>=0?-.5:.5,h=r;break;case g.Left:o=k>0?-.5:.5,u=o;break;case g.Right:o=k>0?-.5:.5,u=o;break;default:r=.5,h=r,o=-.5,u=o}switch(t.endDirection){case g.Top:h=p>=0?.5:-.5;break;case g.Bottom:h=p>=0?.5:-.5;break;case g.Left:u=k>0?.5:-.5;break;case g.Right:u=k>0?.5:-.5;break;default:h=.5,u=-.5}Math.abs(p)>=Math.abs(k)?(c=p>0?-.5:.5,d=k>0?.5:-.5):(c=p>0?.5:-.5,d=k>0?-.5:.5)}e.select("g.diagram-connection-start-label text").attr("x",0).attr("y",n.fontSize/3).attr("text-anchor","middle").attr("font-family",n.fontFamily).attr("font-size",n.fontSize).attr("fill",t.selected?n.selectedColor:n.color).style("font-kerning","none").text(t.startLabel);const y=e.select("g.diagram-connection-start-label text").node()?.getBoundingClientRect();if(y){const p=t.startLabel?y.width/this.zoomTransform.k+Rt(n)+zt(n):0,k=t.startLabel?y.height/this.zoomTransform.k+Vt(n)+Pt(n):0;let b;switch(t.startDirection){case g.Left:b=l.getPointAtLength(et(n)+p/2);break;case g.Right:b=l.getPointAtLength(U(n)+p/2);break;case g.Top:b=l.getPointAtLength(Z(n)+p/2);break;case g.Bottom:b=l.getPointAtLength(G(n)+p/2);break;default:b=l.getPointAtLength(Math.max(U(n)+p/2,et(n)+p/2,G(n)+k/2,Z(n)+k/2))}e.select("g.diagram-connection-start-label path").attr("d",Dt(-p/2,-k/2,p,k)).attr("fill",n.backgroundColor).attr("stroke","none"),e.select("g.diagram-connection-start-label").attr("transform",`translate(${b.x+r*p},${b.y+o*k})`)}e.select("g.diagram-connection-middle-label text").attr("x",0).attr("y",n.fontSize/3).attr("text-anchor","middle").attr("font-family",n.fontFamily).attr("font-size",n.fontSize).attr("fill",t.selected?n.selectedColor:n.color).style("font-kerning","none").text(t.middleLabel);const v=e.select("g.diagram-connection-middle-label text").node()?.getBoundingClientRect();if(v){const p=t.middleLabel?v.width/this.zoomTransform.k+Rt(n)+zt(n):0,k=t.middleLabel?v.height/this.zoomTransform.k+Vt(n)+Pt(n):0,b=l.getPointAtLength(i/2);e.select("g.diagram-connection-middle-label path").attr("d",Dt(-p/2,-k/2,p,k)).attr("fill",n.backgroundColor).attr("stroke","none"),e.select("g.diagram-connection-middle-label").attr("transform",`translate(${b.x+c*p},${b.y+d*k})`)}e.select("g.diagram-connection-end-label text").attr("x",0).attr("y",n.fontSize/3).attr("text-anchor","middle").attr("font-family",n.fontFamily).attr("font-size",n.fontSize).attr("fill",t.selected?n.selectedColor:n.color).style("font-kerning","none").text(t.endLabel);const m=e.select("g.diagram-connection-end-label text").node()?.getBoundingClientRect();if(m){const p=t.endLabel?m.width/this.zoomTransform.k+Rt(n)+zt(n):0,k=t.endLabel?m.height/this.zoomTransform.k+Vt(n)+Pt(n):0;let b;switch(t.endDirection){case g.Left:b=l.getPointAtLength(i-(et(n)+p/2));break;case g.Right:b=l.getPointAtLength(i-(U(n)+p/2));break;case g.Top:b=l.getPointAtLength(i-(Z(n)+p/2));break;case g.Bottom:b=l.getPointAtLength(i-(G(n)+p/2));break;default:b=l.getPointAtLength(i-Math.max(U(n)+p/2,et(n)+p/2,G(n)+k/2,Z(n)+k/2))}e.select("g.diagram-connection-end-label path").attr("d",Dt(-p/2,-k/2,p,k)).attr("fill",n.backgroundColor).attr("stroke","none"),e.select("g.diagram-connection-end-label").attr("transform",`translate(${b.x+h*p},${b.y+u*k})`)}}}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 R||e.rootElement instanceof F){const a=this.minimumSizeOfField(e),l=a[0]+U(e.rootElement.type?.label)+et(e.rootElement.type?.label)-e.rootElement.width,n=a[1]+G(e.rootElement.type?.label)+Z(e.rootElement.type?.label)-e.rootElement.height;return l<=0&&n<=0}return!0}fitFieldRootInView(t,e=!0){const a=this.model.fields.get(t);if(a){if(a.rootElement instanceof R){const l=this.minimumSizeOfField(a);let n=l[0]+U(a.rootElement.type.label)+et(a.rootElement.type.label)-a.rootElement.width,i=l[1]+G(a.rootElement.type.label)+Z(a.rootElement.type.label)-a.rootElement.height;this.snapToGrid&&(n=Math.ceil(n/this.gridSize)*this.gridSize,i=Math.ceil(i/this.gridSize)*this.gridSize),a.rootElement.width+n<a.rootElement.type.minWidth&&(n=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||n>0)&&a.rootElement.stretch(g.Right,n),(e!==!1||i>0)&&a.rootElement.stretch(g.Bottom,i)}if(a.rootElement instanceof F){const l=this.minimumSizeOfField(a);let n=l[0],i=l[1];for(const d of a.rootElement.node?.sections||[])d.label&&(d.indexXInNode===a.rootElement.indexXInNode&&d.indexYInNode!==a.rootElement.indexYInNode?n=Math.max(n,this.minimumSizeOfField(d.label)[0]):d.indexXInNode!==a.rootElement.indexXInNode&&d.indexYInNode===a.rootElement.indexYInNode&&(i=Math.max(i,this.minimumSizeOfField(d.label)[1])));l[0]<n&&(l[0]=n),l[1]<i&&(l[1]=i);const r=a.rootElement.type;let o=l[0]+U(r?.label)+et(r?.label)-a.rootElement.width,c=l[1]+G(r?.label)+Z(r?.label)-a.rootElement.height;this.snapToGrid&&(o=Math.ceil(o/this.gridSize)*this.gridSize,c=Math.ceil(c/this.gridSize)*this.gridSize),a.rootElement.width+o<(a.rootElement.getMinWidth()||0)&&(o=(a.rootElement.getMinWidth()||0)-a.rootElement.width),a.rootElement.height+c<(a.rootElement.getMinHeight()||0)&&(c=(a.rootElement.getMinHeight()||0)-a.rootElement.height),(e||o>0)&&a.rootElement.node?.stretchSections(g.Right,o,a.rootElement.indexXInNode,a.rootElement.indexYInNode),(e||c>0)&&a.rootElement.node?.stretchSections(g.Bottom,c,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,n=0;for(const i of a.sections)if(i.getPriority()>=this.priorityThreshold){const r=i.coords[0]+i.width-a.coords[0],o=i.coords[1]+i.height-a.coords[1];l=Math.max(l,r),n=Math.max(n,o)}l+=a.type.sectionGrid?.margin||0,n+=a.type.sectionGrid?.margin||0,(e||l>a.width)&&a.stretch(g.Right,l-a.width),(e||n>a.height)&&a.stretch(g.Bottom,n-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 at(this.model,this.connectionType,t,void 0,ae);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 at(this.model,e,t,void 0,ae))}}}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.length>0||t.outgoingConnections.length>0)){this.dropConnection();return}if(!this.allowSharingBothPorts&&this.model.connections.find(e=>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 ie(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 ie(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 ie(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,n,i,r,o,c){this.removeInputField();const d=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=d;const h=d.append("xhtml:textarea");let u,y;h.text(t).style("box-sizing","border-box").style("width",`${a}px`).style("height",`${l}px`).style("font-size",`${n}px`).style("font-family",i).style("resize","none").style("outline",0).style("border",0).style("margin",0).style("padding",0).on(C.KeyDown,m=>{m.stopPropagation()}).on(C.KeyUp,m=>{if(m.stopPropagation(),m.key===W.Escape){const p=h.property("value");this.removeInputField(),c&&c(p)}}).on(C.Input,()=>{const m=h.property("value");h.attr("cols",fo(m)+1),h.attr("rows",uo(m)+1),h.style("width",""),h.style("height",""),u=h.property("scrollWidth")+1,y=h.property("scrollHeight")+1;const p=Math.max(u,a),k=Math.max(y,l);d?.attr("width",`${p}px`),h.style("width",`${p}px`),d?.attr("height",`${k}px`),h.style("height",`${k}px`),o&&o(m)}).on(C.Click,m=>{m.stopPropagation()}).on(C.FocusOut,()=>{const m=h.property("value");this.removeInputField(),c&&c(m)});const v=h.node();v.focus(),v.select()}removeInputField(){this.inputFieldContainer?.select("input")?.on(C.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(w.MoveNode)&&!e.removed)if(S(L.Grabbing),this.draggingFrom=[t.x,t.y],e.selected&&this.userSelection.count(a=>a instanceof R)>1)this.currentAction=new oe(this,this.userSelection.filter(a=>a instanceof R).map(a=>a.id),e.coords);else{const a=e.getLastAncestor();this.currentAction=new B(this,w.MoveNode,e.id,e.getGeometry(),e.getGeometry(),a?.id,a?.getGeometry(e.id),a?.getGeometry(e.id))}else S(L.NotAllowed)}continueMovingNode(t,e){if(this.canUserPerformAction(w.MoveNode)&&(this.currentAction instanceof oe||this.currentAction instanceof B)&&!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(w.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 oe){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 B){e.move(a);const n=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=_e(n),r=i[i.length-1];if(r!==e.parent&&(e.type.canBeParentless||r!==void 0)){const o=r?.getLastAncestor(),c=this.currentAction.from,d=new Ho(this,e.id,e.parent?.id,r?.id,c,e.getGeometry(),o?.id,o?.getGeometry(e.id),o?.getGeometry(e.id));e.parent?.removeChild(e),r!==void 0&&r.addChild(e),d.toChildGeometry=e.getGeometry(e.id),d.toAncestorGeometry=o?.getGeometry(e.id),this.currentAction=d}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)}S(),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])&&(S(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)oo([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 j(this.userSelection.all(),!0)),S()}};Xt.canvasCount=0;let fe=Xt;class Xe{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,n=l>0?1:-1,i=[e[0]+l,e[1]+l];for(let r=e[0];r!==i[0]+n;r+=n)if(e[0]=r,this.get(e)===void 0)return e;for(let r=e[1];r!==i[1]+n;r+=n)if(e[1]=r,this.get(e)===void 0)return e}}}class oi{constructor(t){this.gapSize=t}apply(t){if(t.nodes.length===0)return t;const e=new Xe,a=t.nodes.filter(r=>!r.parent);for(;a.length>0;)We(a[0],e,[0,0],a);const l=Math.max(...t.nodes.map(r=>r.width)),n=Math.max(...t.nodes.map(r=>r.height)),i=this.gapSize!==void 0?this.gapSize:(t.canvas?.gridSize||0)*2;for(let r=e.minY();r<=e.maxY();++r)for(let o=e.minX();o<=e.maxX();++o){const c=e.get([o,r]);c!==void 0&&c.move([o*(l+i),r*(n+i)])}return t}}const We=(s,t,e,a)=>{const l=t.getClosestEmptyCoordinate(e);t.set(l,s),D(a,s);for(const n of s.getAdjacentNodes())a.includes(n)&&We(n,t,l,a)};class ii{constructor(t){this.gapSize=t}apply(t){if(t.nodes.length===0)return t;const e=new Xe,a=t.nodes.filter(d=>!d.parent),l={},n=a[0];let i=[n];for(l[n.id]=[0,0];a.length>0;){const d=[];for(const h of i){e.set(e.getClosestEmptyCoordinate(l[h.id]),h),D(a,h);const u=h.getAdjacentNodes();for(const y of u)a.includes(y)&&(d.push(y),l[y.id]=l[h.id])}if(d.length>0)i=d;else if(a.length>0){const h=a[0];i=[h],l[h.id]=e.getClosestEmptyCoordinate([0,0])}}const r=Math.max(...t.nodes.map(d=>d.width)),o=Math.max(...t.nodes.map(d=>d.height)),c=this.gapSize!==void 0?this.gapSize:(t.canvas?.gridSize||0)*2;for(let d=e.minY();d<=e.maxY();++d)for(let h=e.minX();h<=e.maxX();++h){const u=e.get([h,d]);u!==void 0&&u.move([h*(r+c),d*(o+c)])}return t}}class te{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(r=>!r.parent);const l=a[0];D(a,l);const n=[[l]];for(;a.length>0;){const r=n[n.length-1],o=[];for(const c of r){const d=c.getAdjacentNodes();for(const h of d)a.includes(h)&&(D(a,h),o.push(h))}o.length>0?n.push(o):(n.push(a),a=[])}let i=0;for(const r of n){let o=0;for(const d of r)d.move([i,o]),o+=e+d.height;const c=Math.max(...r.map(d=>d.width));i+=e+c}for(const r of t.connections)r.tighten();return t}}class si{constructor(t){this.gapSize=t}apply(t){if(t.nodes.length===0)return t;new te(this.gapSize).apply(t);const e=this.gapSize!==void 0?this.gapSize:(t.canvas?.gridSize||0)*2,a=.99,l=1,n=.1,i=2e5,r=.5,o=1,c=.002;let d=100;for(;d>l;){d=d*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 y=u.getAdjacentNodes();for(const v of t.nodes){const m=[u.coords[0]+u.width/2,u.coords[1]+u.height/2],p=[v.coords[0]+v.width/2,v.coords[1]+v.height/2],k=Ne(u.coords,v.coords),b=[v.coords[0],v.coords[1]];if(y.includes(v)&&k>0&&(k>e+(Math.max(u.width,u.height)+Math.max(v.width,v.height))/2?(b[0]=b[0]-(p[0]-m[0])*n,b[1]=b[1]-(p[1]-m[1])*n):(b[0]=b[0]+(p[0]-m[0])*r,b[1]=b[1]+(p[1]-m[1])*r)),k>0){const N=i/(k*k);b[0]=b[0]+N*(p[0]-m[0])/k,b[1]=b[1]+N*(p[1]-m[1])/k}else b[0]=b[0]+o*(Math.random()*2-1),b[1]=b[1]+o*(Math.random()*2-1);b[0]=b[0]-(p[0]-h[0])*c,b[1]=b[1]-(p[1]-h[1])*c,b[0]-v.coords[0]>d?b[0]=v.coords[0]+d:b[0]-v.coords[0]<-d&&(b[0]=v.coords[0]-d),b[1]-v.coords[1]>d?b[1]=v.coords[1]+d:b[1]-v.coords[1]<-d&&(b[1]=v.coords[1]-d),v.move(b)}}}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 ni{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(n=>!n.parent);a.sort((n,i)=>i.type.priority-n.type.priority);let l=0;for(const n of a)n.move([l,0]),l+=n.width+e;return t}}class ri{constructor(t){this.gapSize=t}apply(t){if(t.nodes.length===0)return t;const e=Math.max(...t.nodes.map(d=>d.getPriority())),a=Math.min(...t.nodes.map(d=>d.getPriority()));if(e===a)return new te(this.gapSize).apply(t),t;const l=this.gapSize!==void 0?this.gapSize:(t.canvas?.gridSize||0)*2,n=t.nodes.filter(d=>!d.parent),i=[],r=t.nodes.filter(d=>!d.parent).filter(d=>d.getPriority()>=e),o=[];if(r.length>1){const d=r[0];r.splice(0,1),o.push(d);const h=[d],u=[d];for(;h.length>0;){const y=h[0];h.splice(0,1),r.includes(y)&&(o.push(y),D(r,y));const v=y.getAdjacentNodes();for(const m of v)u.includes(m)||(h.push(m),u.push(m))}for(const y of r)o.push(y)}else o.push(r[0]);for(const d of o)D(n,d),i.push([d]);for(i.push([]),n.sort((d,h)=>h.type.priority-d.type.priority);n.length>0;){const d=n[0];n.splice(0,1);const h=[d],u=[d];let y=!1;for(;h.length>0;){const v=h[0];h.splice(0,1);const m=o.indexOf(v);if(m>=0){i[m].push(d),y=!0;break}else{const p=v.getAdjacentNodes();for(const k of p)u.includes(k)||(h.push(k),u.push(k))}}y||i[i.length-1].push(d)}let c=0;for(let d=0;d<i.length;++d){let h=0;for(let y=0;y<i[d].length;++y){const v=i[d][y];v.move([c,h]),h+=l+v.height}const u=Math.max(...i[d].map(y=>y.width));c+=l+u}for(const d of t.connections)d.tighten();return t}}class ai{constructor(t){this.gapSize=t}apply(t){if(t.nodes.length===0)return t;const e=Math.max(...t.nodes.map(d=>d.getPriority())),a=Math.min(...t.nodes.map(d=>d.getPriority()));if(e===a)return new te(this.gapSize).apply(t),t;const l=this.gapSize!==void 0?this.gapSize:(t.canvas?.gridSize||0)*2,n=t.nodes.filter(d=>!d.parent).sort((d,h)=>h.getPriority()-d.getPriority()),i=[];for(;n.length>0;){const d=n[0];n.splice(0,1);const h=new ve(void 0,d);Ze(h,n),i.push(h)}const r=[];for(const d of i)r.push([d]),Ke(d,r,r.length);const o=Math.max(...t.nodes.map(d=>d.height));let c=0;for(let d=0;d<r.length;++d){let h=0;for(let y=0;y<r[d].length;++y){const v=r[d][y];v.node.move([c,h]),h+=(l+o)*v.countBranchHeight()}const u=Math.max(...r[d].map(y=>y.node.width));c+=l+u}for(const d of t.connections)d.tighten();return t}}const Ze=(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);Ze(l,t)}}},Ke=(s,t,e)=>{if(s.branches.length>0){for(;e>=t.length;)t.push([]);for(const a of s.branches)t[e].push(a),Ke(a,t,e+1)}};class ve{constructor(t,e){this.parent=t,this.branches=[],this.depth=0,this.node=e}addBranch(t){const e=new ve(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 li{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(n=>!n.parent);a.sort((n,i)=>i.type.priority-n.type.priority);let l=0;for(const n of a)n.move([0,l]),l+=n.height+e;return t}}const Me={adjacency:new oi,breadth:new te,"breadth-adjacency":new ii,force:new si,horizontal:new ni,priority:new ri,tree:new ai,vertical:new li},ci=E.createContext({}),St=E.createContext({});class di{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 ye=({direction:s,collapsableSelector:t,collapsableAdditionalSelector:e,collapsed:a,disabled:l,rule:n,collapsedValue:i,visibleValue:r,onCollapse:o})=>{const[c,d]=E.useState(a),h=()=>{if(!l){const y=!c;d(y),o?.(y);let v;if(typeof t=="string")v=A.select(t),e&&(v=v.select(e));else{const m=t;if(!m)throw new Error("collapsableSelector is not a valid ref");v=A.select(m.current),e&&(v=v.select(e))}v.style(n,y?i:r)}},u=()=>{switch(s){case g.Right:return l?"daga-horizontal-none":c?"daga-horizontal-right":"daga-horizontal-left";case g.Bottom:return l?"daga-vertical-none":c?"daga-vertical-down":"daga-vertical-up";case g.Left:return l?"daga-horizontal-none":c?"daga-horizontal-left":"daga-horizontal-right";case g.Top:return l?"daga-vertical-none":c?"daga-vertical-up":"daga-vertical-down"}};return f.jsx("daga-collapse-button",{children:f.jsx("button",{className:`daga-collapse-button daga-${s}`,onClick:h,children:f.jsx("div",{className:u()})})})},hi=()=>{const s=E.useContext(St),t=E.useRef(null),[e,a]=E.useState([]);kt.merge(s.validatorChange$,s.diagramChange$).pipe(kt.map(()=>l())).subscribe();const l=()=>{a([]);for(const i of s.validators){const r=i.validate(s.model);a(r)}},n=i=>{if(i.elementId&&(i.propertyNames===void 0||i.propertyNames.length===0)){const r=s.model.nodes.get(i.elementId)||s.model.connections.get(i.elementId);r&&s.userHighlight.add(r)}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 r=s.model.nodes.get(i.elementId)||s.model.connections.get(i.elementId);r&&s.userHighlight.add(r),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 f.jsx("daga-errors",{children:f.jsxs("div",{ref:t,className:"daga-errors",children:[e.length===0&&f.jsx("div",{className:"daga-errors-summary daga-no-errors daga-prevent-user-select",children:f.jsx("span",{children:"No errors found"})}),e.length>0&&f.jsxs("div",{className:"daga-errors-summary daga-with-errors daga-prevent-user-select",children:[f.jsxs("span",{children:[e.length," errors found"]}),f.jsx("div",{className:"daga-collapse-button-container",children:f.jsx(ye,{collapsableSelector:t,collapsableAdditionalSelector:".daga-error-panel",direction:g.Top,rule:"display",collapsedValue:"none",visibleValue:"block",collapsed:!1,disabled:!1})})]}),e.length>0&&f.jsx("div",{className:"daga-error-panel",children:f.jsx("ol",{children:e.map((i,r)=>f.jsx("li",{onClick:()=>n(i),dangerouslySetInnerHTML:{__html:i.message}},r))})})]})})},gi=200,Te=s=>(s||"").toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g,""),qe=({disabled:s,options:t,value:e,onChange:a})=>{const l=E.useRef(null),[n,i]=E.useState("");let r;const[o,c]=E.useState([]),[d,h]=E.useState([]),[u,y]=E.useState([]),[v,m]=E.useState([]),[p,k]=E.useState(!1);E.useEffect(()=>{i(t.find(I=>wt(I.key,e))?.label||"")},[e,t]);const b=I=>{if(!s)switch(I.key){case W.PageDown:r===void 0?(P(0),M(0)):(P(r+5),M(r)),I.preventDefault();break;case W.ArrowDown:r===void 0?(P(0),M(0)):(P(r+1),M(r)),I.preventDefault();break;case W.PageUp:r===void 0?(P(t.length-1),M(t.length-1)):(P(r-5),M(r)),I.preventDefault();break;case W.ArrowUp:r===void 0?(P(t.length-1),M(t.length-1)):(P(r-1),M(r)),I.preventDefault();break;case W.Escape:z(),I.preventDefault();break;case W.Enter:O(t[r||0]),I.preventDefault();break;default:N()}},N=()=>{if(!s){const I=Te(n.trim());c([]),h([]),y([]),m([]);for(const _ of t){const K=Te(_.label).indexOf(I);if(K>=0){const _t=_.label.substring(0,K),q=_.label.substring(K,K+I.length),bt=_.label.substring(K+I.length);c(st=>[...st,_]),h(st=>[...st,_t]),y(st=>[...st,q]),m(st=>[...st,bt])}}k(!0)}},z=()=>{k(!1)},P=I=>{if(!s){if(r=I,I===void 0)return;I<0&&(r=0),I>=t.length&&(r=t.length-1)}},Q=()=>{setTimeout(()=>{z()},gi)},M=I=>{const _=l.current?.querySelectorAll("li")[I];_&&_.scrollIntoView({block:"center"})},x=()=>{s||(i(""),k(!1),r=void 0)},O=I=>{s||(i(I.label),k(!1),r=void 0,a(I.key))};return f.jsxs("div",{ref:l,className:`daga-autocomplete ${p?"daga-showing-options":""}`,children:[f.jsxs("div",{className:"daga-autocomplete-input",children:[f.jsx("input",{value:n,disabled:s,onKeyUp:b,onFocus:N,onBlur:Q,onChange:I=>i(I.target.value)}),n!==""&&f.jsx("button",{className:"daga-clear",onClick:x})]}),f.jsx("div",{className:"daga-autocomplete-options",children:f.jsxs("ul",{className:"daga-autocomplete-option-list",children:[o.length===0&&f.jsx("li",{className:"daga-autocomplete-option no-options",children:"(No options)"}),o.map((I,_)=>f.jsxs("li",{className:`daga-autocomplete-option ${_===r?"daga-focused":""}`,onMouseMove:()=>P(_),onClick:()=>O(I),children:[f.jsx("span",{children:d[_]}),f.jsx("span",{className:"daga-match",children:u[_]}),f.jsx("span",{children:v[_]})]},_))]})})]})},fi=(s,t)=>s.find(e=>e.key===t)?.label||`${t}`,ui=({disabled:s,allowRepeats:t,options:e,value:a,onChange:l})=>{const[n,i]=E.useState(),[r,o]=E.useState([]),[c,d]=E.useState([]);E.useEffect(()=>{const p=a.length===0,k=a.map(b=>fi(e,b));o(k),p&&l(a),m()},[a,e]);const h=p=>{for(const k of a)if(k===p)return!0;return!1},u=p=>{a.length>p&&(a.splice(p,1),o(r.filter((k,b)=>b!==p)),l(a),m())},y=()=>{n!==void 0&&(t||!h(n))&&(l(a.concat(n)),v())},v=()=>{i("")},m=()=>{if(!t){const p=[];for(const k of e)h(k.key)||p.push(k);d(p)}};return f.jsxs("div",{children:[a.map((p,k)=>f.jsxs("div",{className:"daga-value-item-element",children:[f.jsx("span",{className:"daga-input",children:r[k]}),!s&&f.jsx("button",{className:"daga-property-button",onClick:()=>u(k),children:f.jsx("div",{className:"daga-icon daga-close-icon"})})]},k)),!s&&f.jsxs("div",{className:"daga-value-item-input",children:[f.jsx("div",{className:"daga-input daga-relatively-positioned",children:f.jsx(qe,{disabled:s,options:t?e||[]:c||[],value:n,onChange:i})}),f.jsx("button",{className:"daga-property-button",onClick:y,children:f.jsx("div",{className:"daga-icon daga-add-icon"})})]})]})},pi=({disabled:s,allowRepeats:t,value:e,onChange:a})=>{const[l,n]=E.useState(""),i=u=>{for(const y of u||[])if(y===u)return!0;return!1},r=u=>{e.length>u&&a(e.filter((y,v)=>v!==u))},o=(u,y,v)=>{const m=e.map((p,k)=>k===y?v==="blur"?u.trim():u:p);a(m)},c=()=>{const u=l.trim();u!==""&&(t||!i(u))&&(a(e.concat(u)),d())},d=()=>{n("")},h=u=>{u.key==="Enter"&&c()};return f.jsxs(f.Fragment,{children:[e.map((u,y)=>f.jsxs("div",{className:"daga-value-item-element",children:[f.jsx("input",{className:"daga-input",disabled:s,value:u,onChange:v=>o(v.target.value,y,"change"),onBlur:v=>o(v.target.value,y,"blur")}),f.jsx("button",{className:"daga-property-button",onClick:()=>r(y),children:f.jsx("div",{className:"daga-icon daga-close-icon"})})]},y)),!s&&f.jsxs("div",{className:"daga-value-item-input",children:[f.jsxs("div",{className:"daga-input daga-relatively-positioned",children:[f.jsx("input",{type:"text",onKeyUp:h,value:l,onChange:u=>n(u.target.value)}),f.jsx("button",{className:"daga-clear",onClick:d})]}),f.jsx("button",{className:"daga-property-button",onClick:c,children:f.jsx("div",{className:"daga-icon daga-add-icon"})})]})]})},mi=({disabled:s,value:t,onChange:e})=>{const[a,l]=E.useState(""),[n,i]=E.useState(""),[r,o]=E.useState({}),c=p=>{const k={};Object.keys(t).forEach(b=>{b!==p&&(k[b]=t[b])}),e(k)},d=(p,k,b)=>{const N=b==="blur"?k.trim():k;if(b==="blur"){if(p!==N){const z={};Object.keys(t).forEach(P=>{P===p?z[N]=t[P]:z[P]=t[P]}),e(z),o(P=>{const Q={...P};return delete Q[p],Q})}}else o(z=>({...z,[p]:k}))},h=(p,k,b)=>{const N=b==="blur"?k.trim():k;if(N!==""){const z={};Object.keys(t).forEach(P=>{P===p?z[P]=N:z[P]=t[P]}),e(z)}},u=()=>{const p=a.trim(),k=n.trim();if(p!==""&&k!==""){const b={};Object.keys(t).forEach(N=>{b[N]=t[N]}),b[p]=k,e(b),l(""),i("")}},y=()=>{l("")},v=()=>{i("")},m=p=>{p.key==="Enter"&&u()};return f.jsxs("div",{children:[Object.entries(t).map(([p,k],b)=>f.jsxs("div",{className:"daga-value-item-element",children:[f.jsx("input",{id:`key-${b}`,className:"daga-input",type:"text",disabled:s,value:r[p]??p,onChange:N=>d(p,N.target.value,"change"),onBlur:N=>d(p,N.target.value,"blur")}),f.jsx("input",{id:`value-${b}`,className:"daga-input",type:"text",disabled:s,value:k,onChange:N=>h(p,N.target.value,"change"),onBlur:N=>h(p,N.target.value,"blur")}),f.jsx("button",{className:"daga-property-button",onClick:()=>c(p),children:f.jsx("div",{className:"daga-icon daga-close-icon"})})]},p)),!s&&f.jsxs("div",{className:"daga-value-item-input",children:[f.jsxs("div",{className:"daga-input daga-relatively-positioned",children:[f.jsx("input",{type:"text",value:a,onKeyUp:m,onChange:p=>l(p.target.value),onBlur:p=>d(a,p.target.value,"blur")}),f.jsx("button",{className:"daga-clear",onClick:y})]}),f.jsxs("div",{className:"daga-input daga-relatively-positioned",children:[f.jsx("input",{type:"text",value:n,onKeyUp:m,onChange:p=>i(p.target.value),onBlur:p=>h(a,p.target.value,"blur")}),f.jsx("button",{className:"daga-clear",onClick:v})]}),f.jsx("button",{className:"daga-property-button",onClick:u,children:f.jsx("div",{className:"daga-icon daga-add-icon"})})]})]})},Je=({valueSet:s,onValueChange:t,depth:e})=>{const l=E.useContext(St).canUserPerformAction(w.UpdateValues)&&s?.rootElement?.removed!==!0,n=o=>"daga-property-name-"+o.replace(/\s/g,""),i=o=>{if(typeof o=="string")return o;if(o==null||isNaN(o.valueOf()))return"";const c=new Date(o),d=c.getTimezoneOffset();return c.setMinutes(c.getMinutes()-d),c.toISOString().substring(0,19)},r=o=>new Date(o);return f.jsx("daga-object-editor",{children:s.displayedProperties.map(o=>f.jsxs("div",{className:`daga-property ${n(o.name)}`,children:[f.jsx("p",{className:"daga-property-name",children:o.label||o.name}),o.type===T.Text&&f.jsx("input",{type:"daga-text",disabled:o.editable===!1||!l,value:s?.getValue(o.name),onChange:c=>t(s,o,c.target.value)}),o.type===T.TextArea&&f.jsx("textarea",{disabled:o.editable===!1||!l,value:s?.getValue(o.name),onChange:c=>t(s,o,c.target.value)}),o.type===T.Number&&f.jsx("input",{type:"number",disabled:o.editable===!1||!l,value:s?.getValue(o.name),onChange:c=>t(s,o,c.target.value)}),o.type===T.Color&&f.jsx("input",{type:"text",pattern:"#[0-9a-fA-F]{6}",disabled:o.editable===!1||!l,value:s?.getValue(o.name),onChange:c=>t(s,o,c.target.value)}),o.type===T.Datetime&&f.jsx("input",{type:"datetime-local",disabled:o.editable===!1||!l,value:i(s?.getValue(o.name)),onChange:c=>t(s,o,r(c.target.value))}),o.type===T.Date&&f.jsx("input",{type:"date",disabled:o.editable===!1||!l,value:s?.getValue(o.name),onChange:c=>t(s,o,c.target.value)}),o.type===T.Time&&f.jsx("input",{type:"time",disabled:o.editable===!1||!l,value:s?.getValue(o.name),onChange:c=>t(s,o,c.target.value)}),o.type===T.Url&&f.jsx("input",{type:"url",disabled:o.editable===!1||!l,value:s?.getValue(o.name),onChange:c=>t(s,o,c.target.value)}),o.type===T.Boolean&&f.jsxs("div",{className:"daga-radio",children:[f.jsxs("label",{className:"daga-radio-item daga-radio-start"+(s?.getValue(o.name)===!1?" daga-checked":""),children:[f.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"]}),f.jsxs("label",{className:"daga-radio-item daga-radio-end"+(s?.getValue(o.name)===!0?" daga-checked":""),children:[f.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===T.Option&&f.jsx("div",{className:"daga-relatively-positioned",children:f.jsx(qe,{disabled:o.editable===!1||!l,options:o.options||[],value:s?.getValue(o.name),onChange:c=>t(s,o,c)})}),(o.type===T.OptionList||o.type===T.OptionSet)&&f.jsx(ui,{disabled:o.editable===!1||!l,allowRepeats:o.type===T.OptionList,options:o.options||[],value:s?.getValue(o.name),onChange:c=>t(s,o,c)}),(o.type===T.TextList||o.type===T.TextSet)&&f.jsx(pi,{disabled:o.editable===!1||!l,allowRepeats:o.type===T.TextList,value:s?.getValue(o.name),onChange:c=>t(s,o,c)}),o.type===T.TextMap&&f.jsx(mi,{disabled:o.editable===!1||!l,value:s?.getValue(o.name),onChange:c=>t(s,o,c)}),o.type===T.Object&&f.jsx("div",{className:"daga-left-bar",children:f.jsx(Je,{valueSet:s.getSubValueSet(o.name),onValueChange:t,depth:e+1})})]},o.name))})},Qe=({valueSet:s,depth:t})=>{const e=E.useContext(St),a=E.useRef(null),l=o=>"daga-property-name-"+o.replace(/\s/g,""),n=()=>{for(const o of s?.displayedProperties||[]){let c=0,d=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,y=>{S(L.Grabbing);const v=e.getPointerLocationRelativeToScreen(y);if(v.length<2||isNaN(v[0])||isNaN(v[1]))return;const m=u.node()?.getBoundingClientRect();c=m?.width||0,d=m?.height||0,u.style("position","fixed").style("left",`${v[0]-c/2}px`).style("top",`${v[1]-d/2}px`).style("width",`${c}px`).style("height",`${d}px`).style("z-index",1)}).on($.Drag,y=>{S(L.Grabbing);const v=e.getPointerLocationRelativeToScreen(y);v.length<2||isNaN(v[0])||isNaN(v[1])||(u.style("position","fixed").style("left",`${v[0]-c/2}px`).style("top",`${v[1]-d/2}px`).style("width",`${c}px`).style("height",`${d}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(v),A.select(a.current).select(`.daga-dropbar.daga-index-${h}.daga-depth-${t}`).style("visibility","visible").style("height","0.25rem"))}).on($.End,y=>{S(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 v=e.getPointerLocationRelativeToScreen(y);v.length<2||isNaN(v[0])||isNaN(v[1])||(h=i(v),s?.displayedProperties?.splice(s.displayedProperties.indexOf(o),1),s?.displayedProperties?.splice(h,0,o))}))}},i=o=>{const c=s?.propertySet.propertyList||[],d=[];for(let h=0;h<=c.length;++h){const u=A.select(a.current).select(`.daga-dropbar.daga-index-${h}.daga-depth-${t}`).node()?.getBoundingClientRect();u&&d.push([u.x+u.width/2,u.y+u.height/2])}if(d.length>0){const h=d.map(y=>((o[0]-y[0])**2+(o[1]-y[1])**2)**.5);return h.indexOf(Math.min(...h))}return 0},r=o=>{if(s===void 0)return;let c;o instanceof bo?c=o:o instanceof Event?c=s?.propertySet.getProperty(o.target?.value||""):c=s?.propertySet.getProperty(o||""),c&&s?.hideProperty(c),n()};return f.jsxs("daga-property-settings",{ref:a,children:[f.jsx("div",{className:`daga-dropbar daga-index-0 daga-depth-${t}`}),s?.displayedProperties.map((o,c)=>f.jsxs("div",{className:`daga-property-and-dropbar ${l(o.name)} daga-depth-${t}`,children:[f.jsxs("div",{className:`daga-property ${l(o.name)} daga-depth-${t}`,children:[f.jsxs("div",{className:"daga-property-name",children:[f.jsx("span",{children:o.label||o.name}),f.jsxs("div",{className:"daga-buttons",children:[f.jsx("button",{className:"daga-property-button daga-move-button",children:f.jsx("div",{className:"daga-icon daga-move-icon"})}),f.jsx("button",{className:"daga-property-button daga-hide-button",onClick:()=>r(o.name),children:f.jsx("div",{className:"daga-icon daga-hide-icon"})})]})]}),o.type!==T.Object&&f.jsx("div",{className:"daga-property-value",children:vi(s?.getValue(o.name))}),o.type===T.Object&&f.jsx(Qe,{valueSet:s?.getSubValueSet(o.name),depth:t+1})]}),f.jsx("div",{className:`daga-dropbar daga-index-${c+1} daga-depth-${t}`})]},o.name))]})},vi=s=>Array.isArray(s)?s.join(", "):ko(s)?Object.entries(s).map(t=>t.map(e=>JSON.stringify(e)).join(": ")).join(", "):s instanceof Date?s.toLocaleString():s==null?"":""+s,yi=({location:s,direction:t,width:e,height:a,title:l,valueSet:n,onValueChange:i})=>{const r=E.useRef(null),[o,c]=E.useState(!1),[d,h]=E.useState(!1),u=()=>A.select(r.current);return E.useEffect(()=>{if(r.current)switch(t){case g.Bottom:case g.Top:u().style("width",e),a&&u().select(".daga-panel-content").style("height",a);break;case g.Left:case g.Right:u().style("height",e),a&&u().select(".daga-panel-content").style("width",a);break}},[e,t]),f.jsx("daga-property-editor",{children:f.jsxs("div",{ref:r,className:`daga-panel daga-bottom daga-${s} daga-${t}`,children:[f.jsx(ye,{disabled:!n||!n.propertySet||!n.propertySet.hasProperties(),collapsed:o,direction:t,collapsableSelector:r,collapsableAdditionalSelector:".daga-panel-content",rule:"display",collapsedValue:"none",visibleValue:"block",onCollapse:c}),f.jsx("div",{className:"daga-panel-content",children:n&&n.propertySet&&n.propertySet.hasProperties()&&!o&&f.jsxs("div",{children:[l&&f.jsxs("p",{className:"daga-title",children:[l,f.jsx("button",{className:"daga-property-button",onClick:()=>h(!d),children:f.jsx("div",{className:`daga-icon daga-settings-icon ${d?"daga-unrotate":"daga-rotate"}`})})]}),!d&&f.jsx(Je,{valueSet:n,onValueChange:i,depth:0}),d&&f.jsx(Qe,{valueSet:n,depth:0})]})})]})})},bi=6,ki=s=>{const t=E.useContext(St),[e,a]=E.useState(s.currentPalette||s.palettes[0]),[l,n]=E.useState(0),[i,r]=E.useState(void 0),o=E.useRef(null),c=m=>{if(a(m),d().selectAll("*").remove(),n(t.getPriorityThreshold()||0),m.categories&&h(m.categories),m.templates)for(const p of m.templates)u(p)},d=()=>A.select(o.current).select(".daga-palette-view"),h=m=>{const p=d().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");p.append("option").attr("value","").text("(None selected)");for(const k in m)p.append("option").attr("value",k).text(k);p.on(C.Change,()=>{i&&d().selectAll(".daga-template-container.daga-in-category").remove();const k=p.property("value");r(k);const b=m[k]||[];for(const N of b)u(N,"daga-in-category")}),i&&(p.property("value",i),p.dispatch(C.Change))},u=(m,p)=>{if(m.templateType==="node"){const k=t.model.nodes.types.get(m.type);k?y(k,m,p):console.error(`Could not find a node type called '${m.type}'`)}else if(m.templateType==="connection"){const k=t.model.connections.types.get(m.type);k?v(k,m,p):console.error(`Could not find a connection type called '${m.type}'`)}},y=(m,p,k)=>{if(l!==void 0&&m.priority<l)return;const b=m.defaultLook.lookType==="shaped-look"?m.defaultLook.borderThickness||1:0,N=m.defaultHeight+b,z=m.defaultWidth+b,P=p.height||N,Q=p.width||z,M=d().append("div").attr("class",`daga-template-container ${k!==void 0?k:""}`).style("width",`${Q}px`).style("height",`${P}px`).call(A.drag().on($.Drag,O=>{if(t.canUserPerformAction(w.AddNode)){const I=t.getPointerLocationRelativeToScreen(O);if(I.length<2||isNaN(I[0])||isNaN(I[1]))return;M.style("position","fixed").style("left",`${I[0]-Q/2}px`).style("top",`${I[1]-P/2}px`).style("z-index",1)}}).on($.Start,O=>{if(t.canUserPerformAction(w.AddNode)){S(L.Grabbing);const I=t.getPointerLocationRelativeToScreen(O);if(I.length<2||isNaN(I[0])||isNaN(I[1]))return;M.style("position","fixed").style("left",`${I[0]-Q/2}px`).style("top",`${I[1]-P/2}px`).style("z-index",1),m.isUnique&&t.model.nodes.find(_=>!_.removed&&_.type.id===m.id)!==void 0&&S(L.NotAllowed)}}).on($.End,O=>{if(t.canUserPerformAction(w.AddNode)){if(S(L.Auto),M.style("position","relative").style("left",0).style("top",0).style("z-index","auto"),m.isUnique&&t.model.nodes.find(Gt=>!Gt.removed&&Gt.type.id===m.id)!==void 0)return;const I=t.getPointerLocationRelativeToScreen(O);if(I.length<2||isNaN(I[0])||isNaN(I[1]))return;const _=document.elementFromPoint(I[0],I[1]);if(_&&!t.selectCanvasView().node()?.contains(_))return;const rt=t.getPointerLocationRelativeToCanvas(O);if(rt.length<2||isNaN(rt[0])||isNaN(rt[1]))return;let K=[rt[0]-m.defaultWidth/2,rt[1]-m.defaultHeight/2];t.snapToGrid&&(K=t.getClosestGridPoint([K[0]-m.snapToGridOffset[0],K[1]-m.snapToGridOffset[1]]),K[0]+=m.snapToGridOffset[0],K[1]+=m.snapToGridOffset[1]);const q=t.model.nodes.getAtCoordinates(rt[0],rt[1]).filter(Gt=>Gt.type.childrenTypes.includes(m.id)),bt=_e(q),st=bt[bt.length-1];if(!m.canBeParentless&&st===void 0)return;const jt=st?.getLastAncestor(),be=new Oo(t,m,K,st?.id,jt?.id,jt?.getGeometry(),void 0,p.label,p.values);be.do(),t?.actionStack.add(be),S()}})).append("svg").attr("class",`palette-node ${m.id}`).attr("viewBox",`0 0 ${z} ${N}`).attr("preserveAspectRatio","none").style("position","relative").style("left",0).style("top",0).style("width",`${Q}px`).style("height",`${P}px`),x=p.look||m.defaultLook;switch(x.lookType){case"shaped-look":M.append("path").attr("d",he(x.shape||Et.Rectangle,(x.borderThickness||1)/2,(x.borderThickness||1)/2,m.defaultWidth,m.defaultHeight)).attr("fill",x.fillColor||"#FFFFFF").attr("stroke",x.borderColor||"#000000").attr("stroke-width",`${x.borderThickness}px`);break;case"image-look":M.append("image").attr("x",0).attr("y",0).attr("width",m.defaultWidth).attr("height",m.defaultHeight).attr("href",x.backgroundImage).attr("preserveAspectRatio","none");break;case"stretchable-image-look":M.append("image").attr("x",0).attr("y",0).attr("width",x.leftMargin).attr("height",x.topMargin).attr("href",x.backgroundImageTopLeft).attr("preserveAspectRatio","none"),M.append("image").attr("x",x.leftMargin).attr("y",0).attr("width",m.defaultWidth-x.rightMargin-x.leftMargin).attr("height",x.topMargin).attr("href",x.backgroundImageTop).attr("preserveAspectRatio","none"),M.append("image").attr("x",m.defaultWidth-x.rightMargin).attr("y",0).attr("width",x.rightMargin).attr("height",x.topMargin).attr("href",x.backgroundImageTopRight).attr("preserveAspectRatio","none"),M.append("image").attr("x",0).attr("y",x.topMargin).attr("width",x.leftMargin).attr("height",m.defaultHeight-x.bottomMargin-x.topMargin).attr("href",x.backgroundImageLeft).attr("preserveAspectRatio","none"),M.append("image").attr("x",x.leftMargin).attr("y",x.topMargin).attr("width",m.defaultWidth-x.rightMargin-x.leftMargin).attr("height",m.defaultHeight-x.bottomMargin-x.topMargin).attr("href",x.backgroundImageCenter).attr("preserveAspectRatio","none"),M.append("image").attr("x",m.defaultWidth-x.rightMargin).attr("y",x.topMargin).attr("width",x.rightMargin).attr("height",m.defaultHeight-x.bottomMargin-x.topMargin).attr("href",x.backgroundImageRight).attr("preserveAspectRatio","none"),M.append("image").attr("x",0).attr("y",m.defaultHeight-x.bottomMargin).attr("width",x.leftMargin).attr("height",x.bottomMargin).attr("href",x.backgroundImageBottomLeft).attr("preserveAspectRatio","none"),M.append("image").attr("x",x.leftMargin).attr("y",m.defaultHeight-x.bottomMargin).attr("width",m.defaultWidth-x.rightMargin-x.leftMargin).attr("height",x.bottomMargin).attr("href",x.backgroundImageBottom).attr("preserveAspectRatio","none"),M.append("image").attr("x",m.defaultWidth-x.rightMargin).attr("y",m.defaultHeight-x.bottomMargin).attr("width",x.rightMargin).attr("height",x.bottomMargin).attr("href",x.backgroundImageBottomRight).attr("preserveAspectRatio","none")}if(p.look===void 0){if(m.decorators)for(const O of m.decorators)M.append("foreignObject").attr("width",`${O.width}px`).attr("height",`${O.height}px`).attr("transform",`translate(${O.coords[0]},${O.coords[1]})`).html(O.html);if(p.label){const O={...V,...m.label,...p.labelLook};M.append("text").attr("transform",`translate(${(U(O)+m.defaultWidth)/2},${(G(O)+m.defaultHeight)/2})`).attr("x",0).attr("y",0).attr("font-size",`${O.fontSize}px`).attr("text-anchor","middle").attr("font-family",O.fontFamily).attr("font-weight",400).attr("fill",O.color).attr("stroke","none").style("font-kerning","none").style("user-select","none").text(p.label)}}},v=(m,p,k)=>{const b=d().append("div").attr("class",`daga-template-container ${k!==void 0?k:""}`).style("width",`${p.width}px`).style("height",`${p.height}px`).append("svg").attr("class",`palette-button ${m.id}`).style("position","relative").style("left",0).style("top",0).style("width","100%").style("height","100%").on("click",()=>{t.connectionType=m});b.append("path").attr("d",he(Et.Rectangle,0,0,p.width,p.height)).attr("fill",p.backgroundColor).attr("stroke","black").attr("stroke-width","1px"),p.icon!==""&&b.append("image").attr("x",0).attr("y",0).attr("width",p.width).attr("height",p.height).attr("href",p.icon),p.label!==""&&b.append("text").attr("transform",`translate(${p.width/2},${p.height/2+bi})`).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(p.label)};return E.useEffect(()=>{if(c(s.palettes[0]),o.current)switch(s.direction){case g.Bottom:case g.Top:o.current.style.width=s.width,s.height&&(o.current.style.height=s.height);break;case g.Left:case g.Right:o.current.style.height=s.width,s.height&&(o.current.style.width=s.height);break}},[e,s.palettes]),f.jsx("daga-palette",{children:f.jsxs("div",{ref:o,className:`daga-panel daga-${s.location} daga-${s.direction}`,children:[f.jsx(ye,{direction:s.direction,collapsableSelector:o,collapsableAdditionalSelector:".daga-panel-content",rule:"display",collapsedValue:"none",visibleValue:"block",collapsed:!1,disabled:!1}),f.jsxs("div",{className:"daga-panel-content",children:[s.palettes.length>1&&f.jsx("div",{className:"daga-panel-tabs",children:s.palettes.map(m=>f.jsx("div",{className:`daga-panel-tab ${m===e?"daga-current-tab":""}`,onClick:()=>c(m),children:m.name}))}),f.jsx("div",{className:"daga-palette-view"})]})]})})},wi=({location:s,direction:t,enableAction:e,enableFilter:a,enableLayout:l,enableSelection:n,enableZoom:i})=>{let r=!1,o=!0,c=!1,d,h,u,y;switch(t){case g.Bottom:d="height",h="scaleY",u="top",y="bottom";break;case g.Top:d="height",h="scaleY",u="bottom",y="top";break;case g.Left:d="width",h="scaleX",u="right",y="left";break;case g.Right:d="width",h="scaleX",u="left",y="right";break}const v=E.useRef(null),m=E.useRef(null),p=E.useRef(null);E.useEffect(()=>{A.select(v.current).style(`margin-${y}`,"-1rem").style(d,"0rem").style("transform",`${h}(0)`).style("transform-origin",u)});const k=async()=>{const q=A.select(v.current);if(!c)if(o){o=!1;const jt=`${4*q.selectChildren().size()}rem`;q.transition().duration(500).ease(A.easeLinear).style(d,jt).style("transform",`${h}(1)`),setTimeout(()=>{c=!1},500)}else o=!0,q.transition().duration(500).ease(A.easeLinear).style(d,"0rem").style("transform",`${h}(0)`),setTimeout(()=>{c=!1},500)},b=E.useContext(St),N=()=>{b.zoomBy(b.zoomFactor)},z=()=>{b.zoomBy(1/b.zoomFactor)},P=()=>{b.center()},Q=()=>{b.layoutFormat&&b.layoutFormat in Me&&Me[b.layoutFormat].apply(b.model)},M=()=>{r=!r,A.select(p.current).classed("daga-on",r).classed("daga-off",!r);const q=b.getPriorityThresholdOptions();q&&q.length>=2&&b.setPriorityThreshold(q[r?1:0])},x=()=>{b.actionStack.undo()},O=()=>{b.actionStack.redo()},I=()=>{b.userSelection.copyToClipboard()},_=()=>{b.userSelection.cutToClipboard()},rt=()=>{b.userSelection.pasteFromClipboard()},K=()=>{b.userSelection.removeFromModel()},_t=()=>{b.multipleSelectionOn=!0,A.select(m.current).classed("daga-on",!0).classed("daga-off",!1);const q=b.diagramEvent$.subscribe(bt=>{bt.type===Ue.Selection&&(A.select(m.current).classed("daga-on",!1).classed("daga-off",!0),q.unsubscribe())})};return f.jsx("daga-diagram-buttons",{children:f.jsxs("div",{className:`daga-diagram-buttons daga-${s} daga-${t}`,children:[i&&b.canUserPerformAction(w.Zoom)&&f.jsx("button",{className:"daga-zoom-in",onClick:N,children:f.jsx("span",{className:"daga-tooltip",children:"Zoom in"})}),i&&b.canUserPerformAction(w.Zoom)&&f.jsx("button",{className:"daga-zoom-out",onClick:z,children:f.jsx("span",{className:"daga-tooltip",children:"Zoom out"})}),f.jsxs("div",{className:"daga-collapsable-buttons daga-collapsed",ref:v,children:[i&&b.canUserPerformAction(w.Zoom)&&f.jsx("button",{className:"daga-center",onClick:P,children:f.jsx("span",{className:"daga-tooltip",children:"Fit diagram to screen"})}),e&&f.jsx("button",{className:"daga-undo",onClick:x,children:f.jsx("span",{className:"daga-tooltip",children:"Undo"})}),e&&f.jsx("button",{className:"daga-redo",onClick:O,children:f.jsx("span",{className:"daga-tooltip",children:"Redo"})}),n&&f.jsx("button",{className:"daga-copy",onClick:I,children:f.jsx("span",{className:"daga-tooltip",children:"Copy"})}),n&&f.jsx("button",{className:"daga-cut",onClick:_,children:f.jsx("span",{className:"daga-tooltip",children:"Cut"})}),n&&f.jsx("button",{className:`daga-multiple-selection ${r?"daga-on":"daga-off"}`,onClick:_t,ref:m,children:f.jsx("span",{className:"daga-tooltip",children:"Multiple selection"})}),n&&f.jsx("button",{className:"daga-paste",onClick:rt,children:f.jsx("span",{className:"daga-tooltip",children:"Paste"})}),n&&f.jsx("button",{className:"daga-delete",onClick:K,children:f.jsx("span",{className:"daga-tooltip",children:"Delete"})}),l&&b.layoutFormat&&f.jsx("button",{className:"daga-layout",onClick:Q,children:f.jsx("span",{className:"daga-tooltip",children:"Apply layout"})}),a&&f.jsx("button",{className:`daga-filter ${r?"daga-on":"daga-off"}`,onClick:M,ref:p,children:f.jsx("span",{className:"daga-tooltip",children:"Apply filter"})})]}),f.jsx("button",{className:"daga-more-options",onClick:k,children:o?f.jsx("span",{className:"daga-tooltip",children:"More options"}):f.jsx("span",{className:"daga-tooltip",children:"Less options"})})]})})},Si=({config:s,model:t,onCanvasCreated:e,onDiagramEvent:a,onModelChange:l})=>{const n=new Fe,i=new Ye,r=E.useRef(null),o=E.useRef(void 0),c=E.useRef(!1),d=[],[h,u]=E.useState(void 0),[y,v]=E.useState(void 0),m={zoomIn:()=>{},zoomOut:()=>{},center:()=>{},layout:()=>{},filter:()=>{},undo:()=>{},redo:()=>{}},p={refreshPalette:()=>{}},k=new di(M=>u(M),M=>v(M)),b={diagramButtons:m,palette:p,propertyEditor:k},N=(M=!1)=>((!o.current||M)&&(d.forEach(x=>x.unsubscribe()),o.current=new fe(b,s)),o.current),z=N(),P=M=>{z.initView(M),d.push(z.diagramEvent$.subscribe(x=>{a?.(x)})),d.push(z.diagramChange$.subscribe(()=>{const x=i.export(z.model);l?.(x)}))};E.useEffect(()=>{r.current&&(c.current||(P(r.current),c.current=!0,e?.(z)))},[r.current]),E.useMemo(()=>{r.current&&(N(!0),P(r.current),e?.(z))},[s]),E.useEffect(()=>{t&&n.import(z.model,t)},[t]);const Q=(M,x,O)=>{if(y!==void 0&&x.editable!==!1&&!wt(M.getValue(x.name),O)){M.setValue(x.name,O);const I=new mt(y.propertySet,void 0);I.setValues(y.getValues()),I.rootElement=y.rootElement,k.valueSet=I,y.rootElement.valueSet=I,z.propertyEditorChanges$?.next()}};return f.jsx("daga-diagram",{children:f.jsx(ci.Provider,{value:s,children:f.jsx(St.Provider,{value:z,children:f.jsxs("daga-diagram-editor",{children:[f.jsx("div",{className:"daga-append-to",ref:r}),f.jsxs(St.Provider,{value:z,children:[s.components?.buttons!==void 0&&s.components?.buttons?.enabled!==!1&&f.jsx(wi,{location:s.components?.buttons?.location||Ut.BottomRight,direction:s.components?.buttons?.direction||g.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&&f.jsx(ki,{location:s.components?.palette?.location||Ut.TopLeft,direction:s.components?.palette?.direction||g.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&&f.jsx(yi,{location:s.components?.propertyEditor?.location||Ut.TopRight,direction:s.components?.propertyEditor?.direction||g.Bottom,width:s.components?.propertyEditor?.width||"24rem",height:s.components?.propertyEditor?.height,title:h,valueSet:y,onValueChange:Q}),s.components?.errors!==void 0&&s.components?.errors?.enabled!==!1&&f.jsx(hi,{})]})]})})})})};exports.DagaDiagram=Si;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("react/jsx-runtime"),eo=require("d3"),kt=require("rxjs"),E=require("react");function oo(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=oo(eo);var g=(s=>(s.Bottom="bottom",s.Left="left",s.Right="right",s.Top="top",s))(g||{}),Dt=(s=>(s.BottomLeft="bottom-left",s.BottomRight="bottom-right",s.TopLeft="top-left",s.TopRight="top-right",s))(Dt||{}),It=(s=>(s.Left="left",s.Center="center",s.Right="right",s))(It||{}),Yt=(s=>(s.Top="top",s.Center="center",s.Bottom="bottom",s))(Yt||{});const Ct=s=>[Math.round(s[0]),Math.round(s[1])],gt=(s,t,e)=>t<e?t<=s&&s<=e:e<=s&&s<=t,we=(s,t,e)=>(s-t[0])/(t[1]-t[0])*(e[1]-e[0])+e[0],Xt=(s,t,e,a,l,n,i)=>{const r=(()=>{switch(n){case"start":return a[0]+(s[0]-t[0]);case"end":return a[1]-(t[1]-s[0]);case"middle":{const c=(t[0]+t[1])/2,d=(a[0]+a[1])/2,h=t[1]-t[0],u=a[1]-a[0],y=(s[0]-c)/h;return d+y*u}case"floating":default:return we(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 c=(e[0]+e[1])/2,d=(l[0]+l[1])/2,h=e[1]-e[0],u=l[1]-l[0],y=(s[1]-c)/h;return d+y*u}case"floating":default:return we(s[1],e,l)}})();return[r,o]},Pe=(s,t)=>((s[0]-t[0])**2+(s[1]-t[1])**2)**.5,io=(s,t)=>(gt(s[0][0],t[0][0],t[1][0])||gt(s[1][0],t[1][0],t[0][0])||gt(t[0][0],s[0][0],s[1][0])||gt(t[1][0],s[1][0],s[0][0]))&&(gt(s[0][1],t[0][1],t[1][1])||gt(s[1][1],t[1][1],t[0][1])||gt(t[0][1],s[0][1],s[1][1])||gt(t[1][1],s[1][1],s[0][1]));var C=(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))(C||{}),W=(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))(W||{}),$=(s=>(s.Drag="drag",s.Start="start",s.End="end",s))($||{}),ce=(s=>(s.Zoom="zoom",s.Start="start",s.End="end",s))(ce||{});const de=s=>s.replace(/([!"#$%&'()*+,\-./:;<=>?@[\\\]^`{|}])/g,"\\$1");var Re=(s=>(s.Straight="straight",s.Bezier="bezier",s.Square="square",s))(Re||{}),pe=(s=>(s.Solid="solid",s.Dashed="dashed",s.GappedDashes="gapped-dashes",s.Dotted="dotted",s))(pe||{});const so=20,no=(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||so;let n="",i,r;switch(s){case"straight":n+=`M ${t[0][0]} ${t[0][1]}`;for(let o=1;o<t.length;++o)n+=` L ${t[o][0]} ${t[o][1]}`;break;case"bezier":i=e,n+=`M ${t[0][0]} ${t[0][1]}`;for(let o=1;o<t.length;++o){if(o+1>=t.length)switch(a){case g.Bottom:r=g.Top;break;case g.Top:r=g.Bottom;break;case g.Right:r=g.Left;break;case g.Left:r=g.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]?r=g.Bottom:r=g.Top:t[o][0]>t[o-1][0]?r=g.Right:r=g.Left;if(i!==void 0){let c="",d="";const h=(Math.abs(t[o][0]-t[o-1][0])+Math.abs(t[o][1]-t[o-1][1]))/2;switch(i){case g.Bottom:c=`${t[o-1][0]} ${t[o-1][1]+h}`;break;case g.Top:c=`${t[o-1][0]} ${t[o-1][1]-h}`;break;case g.Right:c=`${t[o-1][0]+h} ${t[o-1][1]}`;break;case g.Left:c=`${t[o-1][0]-h} ${t[o-1][1]}`;break}if(r!==void 0){switch(r){case g.Top:d=`${t[o][0]} ${t[o][1]+h}`;break;case g.Bottom:d=`${t[o][0]} ${t[o][1]-h}`;break;case g.Left:d=`${t[o][0]+h} ${t[o][1]}`;break;case g.Right:d=`${t[o][0]-h} ${t[o][1]}`;break}n+=` C ${c} ${d} ${t[o][0]} ${t[o][1]}`}else n+=` Q ${c} ${t[o][0]} ${t[o][1]}`}else if(r!==void 0){let c="";const d=(Math.abs(t[o][0]-t[o-1][0])+Math.abs(t[o][1]-t[o-1][1]))/2;switch(r){case g.Top:c=`${t[o][0]} ${t[o][1]+d}`;break;case g.Bottom:c=`${t[o][0]} ${t[o][1]-d}`;break;case g.Left:c=`${t[o][0]+d} ${t[o][1]}`;break;case g.Right:c=`${t[o][0]-d} ${t[o][1]}`;break}n+=` Q ${c} ${t[o][0]} ${t[o][1]}`}else n+=` L ${t[o][0]} ${t[o][1]}`;i=r}break;case"square":i=e,n+=`M ${t[0][0]} ${t[0][1]}`;for(let o=1;o<t.length;++o){if(o+1>=t.length)switch(a){case g.Bottom:r=g.Top;break;case g.Top:r=g.Bottom;break;case g.Right:r=g.Left;break;case g.Left:r=g.Right;break}switch(i){case g.Bottom:switch(r){case g.Bottom:t[o][1]>t[o-1][1]?(t[o][0]!==t[o-1][0]?(n+=` V ${(t[o][1]+t[o-1][1])/2}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`):n+=` V ${t[o][1]}`,i=r):t[o][0]>t[o-1][0]?(n+=` V ${t[o-1][1]+l}`,n+=` H ${Math.max(t[o-1][0],t[o][0])+l}`,n+=` V ${t[o][1]-l}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`):(n+=` V ${t[o-1][1]+l}`,n+=` H ${Math.min(t[o-1][0],t[o][0])-l}`,n+=` V ${t[o][1]-l}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`);break;case g.Top:n+=` V ${Math.max(t[o-1][1],t[o][1])+l}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`;break;case g.Left:t[o][1]>t[o-1][1]+l?t[o][0]<t[o-1][0]-l?(n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`):(n+=` V ${(t[o-1][1]+t[o][1])/2}`,n+=` H ${t[o][0]+l}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`):t[o][0]<t[o-1][0]-l?(n+=` V ${t[o-1][1]+l}`,n+=` H ${(t[o-1][0]+t[o][0])/2}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`):(n+=` V ${t[o-1][1]+l}`,n+=` H ${t[o][0]+l}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`);break;case g.Right:t[o][1]>t[o-1][1]+l?t[o][0]>t[o-1][0]+l?(n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`):(n+=` V ${(t[o-1][1]+t[o][1])/2}`,n+=` H ${t[o][0]-l}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`):t[o][0]>t[o-1][0]+l?(n+=` V ${t[o-1][1]+l}`,n+=` H ${(t[o-1][0]+t[o][0])/2}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`):(n+=` V ${t[o-1][1]+l}`,n+=` H ${t[o][0]-l}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`);break;default:t[o][1]<t[o-1][1]+l?(n+=` V ${t[o-1][1]+l}`,t[o][0]!==t[o-1][0]&&(n+=` H ${t[o][0]}`),n+=` V ${t[o][1]}`,i=g.Top):(n+=` V ${t[o][1]}`,i=g.Bottom,t[o][0]!==t[o-1][0]&&(n+=` H ${t[o][0]}`,i=t[o][0]>t[o-1][0]?g.Right:g.Left));break}break;case g.Top:switch(r){case g.Top:t[o][1]<t[o-1][1]?(t[o][0]!==t[o-1][0]?(n+=` V ${(t[o][1]+t[o-1][1])/2}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`):n+=` V ${t[o][1]}`,i=r):t[o][0]<t[o-1][0]?(n+=` V ${t[o-1][1]-l}`,n+=` H ${Math.min(t[o-1][0],t[o][0])-l}`,n+=` V ${t[o][1]+l}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`):(n+=` V ${t[o-1][1]-l}`,n+=` H ${Math.max(t[o-1][0],t[o][0])+l}`,n+=` V ${t[o][1]+l}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`);break;case g.Bottom:n+=` V ${Math.min(t[o-1][1],t[o][1])-l}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`;break;case g.Right:t[o][1]<t[o-1][1]-l?t[o][0]>t[o-1][0]+l?(n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`):(n+=` V ${(t[o-1][1]+t[o][1])/2}`,n+=` H ${t[o][0]-l}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`):t[o][0]>t[o-1][0]+l?(n+=` V ${t[o-1][1]-l}`,n+=` H ${(t[o-1][0]+t[o][0])/2}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`):(n+=` V ${t[o-1][1]-l}`,n+=` H ${t[o][0]-l}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`);break;case g.Left:t[o][1]<t[o-1][1]-l?t[o][0]<t[o-1][0]-l?(n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`):(n+=` V ${(t[o-1][1]+t[o][1])/2}`,n+=` H ${t[o][0]+l}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`):t[o][0]<t[o-1][0]-l?(n+=` V ${t[o-1][1]-l}`,n+=` H ${(t[o-1][0]+t[o][0])/2}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`):(n+=` V ${t[o-1][1]-l}`,n+=` H ${t[o][0]+l}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`);break;default:t[o][1]>t[o-1][1]-l?(n+=` V ${t[o-1][1]-l}`,t[o][0]!==t[o-1][0]&&(n+=` H ${t[o][0]}`),n+=` V ${t[o][1]}`,i=g.Bottom):(n+=` V ${t[o][1]}`,i=g.Top,t[o][0]!==t[o-1][0]&&(n+=` H ${t[o][0]}`,i=t[o][0]>t[o-1][0]?g.Right:g.Left));break}break;case g.Left:switch(r){case g.Left:t[o][0]<t[o-1][0]?(t[o][1]!==t[o-1][1]?(n+=` H ${(t[o][0]+t[o-1][0])/2}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`):n+=` H ${t[o][0]}`,i=r):t[o][1]<t[o-1][1]?(n+=` H ${t[o-1][0]-l}`,n+=` V ${Math.min(t[o-1][1],t[o][1])-l}`,n+=` H ${t[o][0]+l}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`):(n+=` H ${t[o-1][0]-l}`,n+=` V ${Math.max(t[o-1][1],t[o][1])+l}`,n+=` H ${t[o][0]+l}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`);break;case g.Right:n+=` H ${Math.min(t[o-1][0],t[o][0])-l}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`;break;case g.Bottom:t[o][0]<t[o-1][0]-l?t[o][1]>t[o-1][1]+l?(n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`):(n+=` H ${(t[o-1][0]+t[o][0])/2}`,n+=` V ${t[o][1]-l}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`):t[o][1]>t[o-1][1]+l?(n+=` H ${t[o-1][0]-l}`,n+=` V ${(t[o-1][1]+t[o][1])/2}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`):(n+=` H ${t[o-1][0]-l}`,n+=` V ${t[o][1]-l}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`);break;case g.Top:t[o][0]<t[o-1][0]-l?t[o][1]<t[o-1][1]-l?(n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`):(n+=` H ${(t[o-1][0]+t[o][0])/2}`,n+=` V ${t[o][1]+l}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`):t[o][1]<t[o-1][1]-l?(n+=` H ${t[o-1][0]-l}`,n+=` V ${(t[o-1][1]+t[o][1])/2}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`):(n+=` H ${t[o-1][0]-l}`,n+=` V ${t[o][1]+l}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`);break;default:t[o][0]>t[o-1][0]-l?(n+=` H ${t[o-1][0]-l}`,t[o][1]!==t[o-1][1]&&(n+=` V ${t[o][1]}`),n+=` H ${t[o][0]}`,i=g.Right):(n+=` H ${t[o][0]}`,i=g.Left,t[o][1]!==t[o-1][1]&&(n+=` V ${t[o][1]}`,i=t[o][1]>t[o-1][1]?g.Bottom:g.Top));break}break;case g.Right:switch(r){case g.Right:t[o][0]>t[o-1][0]?(t[o][1]!==t[o-1][1]?(n+=` H ${(t[o][0]+t[o-1][0])/2}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`):n+=` H ${t[o][0]}`,i=r):t[o][1]>t[o-1][1]?(n+=` H ${t[o-1][0]+l}`,n+=` V ${Math.max(t[o-1][1],t[o][1])+l}`,n+=` H ${t[o][0]-l}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`):(n+=` H ${t[o-1][0]+l}`,n+=` V ${Math.min(t[o-1][1],t[o][1])-l}`,n+=` H ${t[o][0]-l}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`);break;case g.Left:n+=` H ${Math.max(t[o-1][0],t[o][0])+l}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`;break;case g.Top:t[o][0]>t[o-1][0]+l?t[o][1]<t[o-1][1]-l?(n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`):(n+=` H ${(t[o-1][0]+t[o][0])/2}`,n+=` V ${t[o][1]+l}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`):t[o][1]<t[o-1][1]-l?(n+=` H ${t[o-1][0]+l}`,n+=` V ${(t[o-1][1]+t[o][1])/2}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`):(n+=` H ${t[o-1][0]+l}`,n+=` V ${t[o][1]+l}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`);break;case g.Bottom:t[o][0]>t[o-1][0]+l?t[o][1]>t[o-1][1]+l?(n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`):(n+=` H ${(t[o-1][0]+t[o][0])/2}`,n+=` V ${t[o][1]-l}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`):t[o][1]>t[o-1][1]+l?(n+=` H ${t[o-1][0]+l}`,n+=` V ${(t[o-1][1]+t[o][1])/2}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`):(n+=` H ${t[o-1][0]+l}`,n+=` V ${t[o][1]-l}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`);break;default:t[o][0]<t[o-1][0]+l?(n+=` H ${t[o-1][0]+l}`,t[o][1]!==t[o-1][1]&&(n+=` V ${t[o][1]}`),n+=` H ${t[o][0]}`,i=g.Left):(n+=` H ${t[o][0]}`,i=g.Right,t[o][1]!==t[o-1][1]&&(n+=` V ${t[o][1]}`,i=t[o][1]>t[o-1][1]?g.Bottom:g.Top));break}break;default:t[o][0]!==t[o-1][0]&&(n+=` H ${t[o][0]}`,i=t[o][0]>t[o-1][0]?g.Right:g.Left),t[o][1]!==t[o-1][1]&&(n+=` V ${t[o][1]}`,i=t[o][1]>t[o-1][1]?g.Bottom:g.Top)}}break}return n}},he=(s,t)=>{switch(s){case"dotted":return`${t}`;case"dashed":return`${4*t} ${t}`;case"gapped-dashes":return`${4*t} ${4*t}`;case"solid":default:return"none"}},D=(s,t)=>{const e=s.indexOf(t);return e>=0&&s.splice(e,1),s};var Et=(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))(Et||{});const ge=(s,t,e,a,l)=>{if(typeof s=="function")return s(t,e,a,l);switch(s){case"ellipse":return ze(t,e,a,l);case"empty":return ro();case"folder":return ao(t,e,a,l);case"hexagon":return lo(t,e,a,l);case"octagon":return co(t,e,a,l);case"pill":return Bt(t,e,a,l);case"rectangle":return Se(t,e,a,l);case"rhombus":return ho(t,e,a,l);case"rounded-rectangle":return go(t,e,a,l);case"sticky-note":return fo(t,e,a,l);default:return Se(t,e,a,l)}},ze=(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`,ro=()=>"Z",ao=(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`,lo=(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`,co=(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`,Bt=(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`:ze(s,t,e,a),Se=(s,t,e,a)=>`M ${s} ${t} L ${s+e} ${t} L ${s+e} ${t+a} L ${s} ${t+a} Z`,ho=(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`,go=(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`,fo=(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 uo=s=>Math.max(...s.split(`
|
|
2
|
+
`).map(t=>t.length)),po=s=>s.match(/\n/g)?.length||0,X=[];for(let s=0;s<256;++s)X.push((s+256).toString(16).slice(1));function mo(s,t=0){return(X[s[t+0]]+X[s[t+1]]+X[s[t+2]]+X[s[t+3]]+"-"+X[s[t+4]]+X[s[t+5]]+"-"+X[s[t+6]]+X[s[t+7]]+"-"+X[s[t+8]]+X[s[t+9]]+"-"+X[s[t+10]]+X[s[t+11]]+X[s[t+12]]+X[s[t+13]]+X[s[t+14]]+X[s[t+15]]).toLowerCase()}let oe;const vo=new Uint8Array(16);function yo(){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(vo)}const bo=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),xe={randomUUID:bo};function Ce(s,t,e){if(xe.randomUUID&&!s)return xe.randomUUID();s=s||{};const a=s.random??s.rng?.()??yo();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,mo(a)}const Mt=s=>{if(typeof s!="object")return s;const t={};for(const e of Object.entries(s))typeof e[1]=="object"?t[e[0]]=Mt(e[1]):t[e[0]]=e[1];return t},it=s=>{const{selected:t,highlighted:e,selectedAndHighlighted:a,...l}=s,n=l,i={...n,...t},r={...n,...e},o={...n,...e,...t,...a};return{defaultLook:n,selectedLook:i,highlightedLook:r,selectedAndHighlightedLook:o}};class Zt{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],D(this.entities,e))}size(){return this.entities.length}*[Symbol.iterator](){for(const t of this.entities)yield t}}const Tt=0;class xt{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='${de(this.id)}']`)}}class ht extends Zt{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,n)=>t(a,l,n)&&!a.removed)}filter(t,e=!1){return e?super.filter(t):super.filter((a,l,n)=>t(a,l,n)&&!a.removed)}find(t,e=!1){return e?super.find(t):super.find((a,l,n)=>t(a,l,n)&&!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],D(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 ko{constructor(t,e,a,l,n,i,r){this.name=t,this.label=e,this.type=a,this.defaultValue=l,this.basic=n,this.editable=i,this.rootAttribute=r,this.options=void 0,this.properties=void 0}}var T=(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))(T||{});class Kt{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 yt(s,t){return!t||s[0]>t[0]?!0:s[0]===t[0]?s[1]>=t[1]:!1}const $e=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),Ve=(s,t,e)=>{const a={},l={};for(const n in e.propertySet.propertyMap)if(e.propertySet.propertyMap[n].type===T.Object){const i=Ve(s[n],t[n],e.getSubValueSet(n));Object.keys(i[0]).length>0&&Object.keys(i[1]).length>0&&(a[n]=i[0],l[n]=i[1])}else wt(s[n],t[n])||(a[n]=s[n],l[n]=t[n]);return[a,l]},wo=s=>s!=null&&s.constructor===Object;class mt{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 n=t[l];if(a==null)return;a=a[n]}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===T.Object?this.valueSets[t].getValues():this.values[t]}getValues(){const t={};for(const e in this.propertySet.propertyMap)this.propertySet.getProperty(e).type===T.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===T.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===T.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!$e(e)}hasSetValue(t){const e=this.getValue(t),a=this.propertySet.getProperty(t);return a&&a.type===T.Object?this.getSubValueSet(t).hasAnySetValue():!$e(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===T.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===T.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===T.Object?this.valueSets[e].setTimestamps(t[e]):this.ownTimestamps[e]=t[e]}overwriteValues(t){for(const e in t)this.propertySet.getProperty(e).type===T.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===T.Object?this.valueSets[a].overwriteValuesLww(t[a],e):yt(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===T.Object?this.valueSets[t]=this.constructSubValueSet(t):this.values[t]=Mt(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 Kt(e.properties),l=new mt(a,this.rootElement);return l.overwriteValues(Mt(e.defaultValue)),l}getSubValueSet(t){return this.valueSets[t]}displayProperty(t){this.displayedProperties.includes(t)||(this.displayedProperties.push(t),D(this.hiddenProperties,t))}hideProperty(t){this.hiddenProperties.includes(t)||(this.hiddenProperties.push(t),D(this.displayedProperties,t))}}const tt={name:"",label:null,look:{lookType:"connection-look",color:"#000000",thickness:1,shape:Re.Straight,style:pe.Solid,selected:{color:"#AA00AA"},highlighted:{thickness:2}},startMarkerLook:void 0,endMarkerLook:void 0,startTypes:[],endTypes:[],properties:[]};class Oe{constructor(t){const e={...tt,...t};this.id=e.id,this.name=e.name,this.label=e.label;const a=it(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=it(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=it(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 Kt(e.properties)}canStartFromType(t){return this.startTypes.indexOf(t)>=0}canFinishOnType(t){return this.endTypes.indexOf(t)>=0}}class at extends xt{constructor(t,e,a,l,n){if(t.connections.get(n)!==void 0)throw new Error(`DiagramConnection with id "${n}" already exists`);if(!n)throw new Error("DiagramConnection cannot have an empty or null id");super(t,n),this.startCoords=[0,0],this.endCoords=[0,0],this.startLabel="",this.middleLabel="",this.endLabel="",this.points=[],this._type=e,this.valueSet=new mt(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 mt(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=it(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=it(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=it(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&&D(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&&D(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(n=>[n,n.distanceTo(this.end.coords)]).sort((n,i)=>n[1]-i[1]).map(n=>n[0]);t:for(const n of l){if(!t&&n===this.end||!n.allowsOutgoing||!e&&(n.incomingConnections.length===1&&n.incomingConnections[0]!==this||n.incomingConnections.length>1||n.outgoingConnections.length===1&&n.outgoingConnections[0]!==this||n.outgoingConnections.length>1))continue t;if(!a){for(const i of n.outgoingConnections)if(i!==this&&i.end===this.end)continue t;for(const i of n.incomingConnections)if(i!==this&&i.start===this.end)continue t}if(n===this.start)break t;this.setStart(n);break t}}if(this.end?.rootElement&&this.start){const l=this.end.rootElement.ports.map(n=>[n,n.distanceTo(this.start.coords)]).sort((n,i)=>n[1]-i[1]).map(n=>n[0]);t:for(const n of l){if(!t&&n===this.start||!n.allowsIncoming||!e&&(n.outgoingConnections.length===1&&n.outgoingConnections[0]!==this||n.outgoingConnections.length>1||n.incomingConnections.length===1&&n.incomingConnections[0]!==this||n.incomingConnections.length>1))continue t;if(!a){for(const i of n.incomingConnections)if(i!==this&&i.start===this.start)continue t;for(const i of n.outgoingConnections)if(i!==this&&i.end===this.start)continue t}if(n===this.end)break t;this.setEnd(n);break t}}}getPriority(){return this.start?this.end?Math.min(this.start.getPriority(),this.end.getPriority()):this.start.getPriority():this.end?this.end.getPriority():Tt}}class So extends ht{constructor(t){super(),this.types=new Zt,this.model=t}new(t,e,a,l){let n;if(t instanceof Oe)n=t;else{const r=this.types.get(t);if(r===void 0)throw new TypeError(`Connection type with id '${t}' could not be found.`);n=r}const i=new at(this.model,n,e,a,l);return super.add(i),i.updateInView(),i.valueSet.resetValues(),i}remove(t){const e=this.get(t,!0);e&&(D(e.start?.outgoingConnections||[],e),D(e.end?.incomingConnections||[],e),super.remove(t),e.updateInView())}}const V={editable:!0,fontSize:0,margin:0,padding:0,fontFamily:"'Wonder Unit Sans', sans-serif",color:"#000000",selectedColor:"#000000",backgroundColor:"#00000000",horizontalAlign:It.Center,verticalAlign:Yt.Center,orientation:g.Top,fit:!1,shrink:!0};class ct extends xt{constructor(t,e,a,l,n,i,r,o,c,d,h,u,y,v,m,p){const k=`${e?.id}_field`;if(t.fields.get(k)!==void 0)throw new Error("DiagramField for rootElement already exists");if(super(t,k),this.textTimestamp=null,this.rootElement=e,this.coords=a,this.width=l,this.height=n,this.fontSize=i,this.fontFamily=r,this.color=o,this.selectedColor=c,this.horizontalAlign=d,this.verticalAlign=h,!isNaN(Number(u)))this.orientation=Number(u);else switch(u){case g.Top:this.orientation=0;break;case g.Right:this.orientation=90;break;case g.Bottom:this.orientation=180;break;case g.Left:this.orientation=270;break;default:this.orientation=0}this.defaultText=y,this._text=y,this.editable=v,this.fit=m,this.shrink=p}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()||Tt}}class xo extends ht{constructor(t){super(),this.model=t}new(t,e,a,l,n,i,r,o,c,d,h,u,y,v,m){const p=new ct(this.model,t,e,r,o,a,l,n,i,c,d,h,u,y,v,m);return super.add(p),p.updateInView(),t!==void 0&&(t.label=p),p}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 Z=s=>s?.margin===null||s?.margin===void 0?V.margin:typeof s.margin=="number"?s.margin:s.margin.length===0?V.margin:s.margin.length===1||s.margin.length===2?s.margin[0]:(s.margin.length===3,s.margin[2]),U=s=>s?.margin===null||s?.margin===void 0?V.margin:typeof s.margin=="number"?s.margin:s.margin.length===0?V.margin:s.margin.length===1?s.margin[0]:s.margin.length===2||s.margin.length===3?s.margin[1]:s.margin[3],et=s=>s?.margin===null||s?.margin===void 0?V.margin:typeof s.margin=="number"?s.margin:s.margin.length===0?V.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?V.margin:typeof s.margin=="number"?s.margin:s.margin.length===0?V.margin:(s.margin.length===1||s.margin.length===2||s.margin.length===3,s.margin[0]),Rt=s=>s?.padding===null||s?.padding===void 0?V.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?V.padding:s.padding.length===1||s.padding.length===2?s.padding[0]:(s.padding.length===3,s.padding[2]),zt=s=>s?.padding===null||s?.padding===void 0?V.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?V.padding:s.padding.length===1?s.padding[0]:s.padding.length===2||s.padding.length===3?s.padding[1]:s.padding[3],Vt=s=>s?.padding===null||s?.padding===void 0?V.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?V.padding:s.padding.length===1?s.padding[0]:(s.padding.length===2||s.padding.length===3,s.padding[1]),Ot=s=>s?.padding===null||s?.padding===void 0?V.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?V.padding:(s.padding.length===1||s.padding.length===2||s.padding.length===3,s.padding[0]),Ie=1,Ae=1,Co=1,$o=1;class Io{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 Ao(l))}}}class Ao{constructor(t){this.label=t.label||null,this.ports=t.ports||[],this.priority=t.priority||Tt,this.resizableX=t.resizableX,this.resizableY=t.resizableY;const e=it(t.look||_e);this.defaultLook=e.defaultLook,this.selectedLook=e.selectedLook,this.highlightedLook=e.highlightedLook,this.selectedAndHighlightedLook=e.selectedAndHighlightedLook}}class F extends xt{constructor(t,e,a,l,n,i,r,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=n,this.width=i,this.height=r}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=it(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]||Co}getMinHeight(){return this.node?.type?.sectionGrid?.minHeights?.[this.indexYInNode]||$o}getPriority(){return this.node?.type?.sectionGrid?.sections?.[this.indexYInNode]?.[this.indexXInNode]?.priority||Tt}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(n=>n.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 n,i;switch(t){case g.Left:n=[a[0]-e,a[1]],i=[l[0],l[1]],n[1]-n[0]<this.getMinWidth()&&(n[0]=n[1]-this.getMinWidth());break;case g.Top:n=[a[0],a[1]],i=[l[0]-e,l[1]],i[1]-i[0]<this.getMinHeight()&&(i[0]=i[1]-this.getMinHeight());break;case g.Right:n=[a[0],a[1]+e],i=[l[0],l[1]],n[1]-n[0]<this.getMinWidth()&&(n[1]=n[0]+this.getMinWidth());break;case g.Bottom:n=[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:[n[0],i[0]],width:n[1]-n[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],n=[this.coords[1],this.coords[1]+this.height];for(const r of this.ports)r.move(Xt(r.coords,e,a,l,n,r.anchorPointX,r.anchorPointY));const i=this.type;this.label&&(this.label.coords=[this.coords[0]+U(i?.label),this.coords[1]+G(i?.label)],this.label.width=this.width-U(i?.label)-et(i?.label),this.label.height=this.height-G(i?.label)-Z(i?.label),this.label.updateInView());for(const r of this.decorators)r.move(Xt(r.coords,e,a,l,n,r.anchorPointX,r.anchorPointY));this.model.canvas?.autoTightenConnections!==!1&&this.getConnections().forEach(r=>r.tighten()),this.updateInView()}}class Lo extends ht{constructor(t){super(),this.model=t}new(t,e,a,l,n,i,r){const o=new F(this.model,t,e,a,l,n,i,r);super.add(o),o.updateInView(),t.sections.push(o),t.updateInView();const c=t.type.sectionGrid?.sections?.[a]?.[e]?.ports;if(c&&c.length>0)for(let h=0;h<c.length;++h){const u=c[h],y=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(y.type?.label){const v={...V,...y.type?.label},m=6*v.fontSize+zt(v)+Vt(v),p=v.fontSize+Ot(v)+Rt(v);let k;switch(y.direction){case g.Bottom:case g.Left:case g.Right:k=[y.coords[0]-m/2,y.coords[1]-p-Z(v)];break;case g.Top:k=[y.coords[0]-m/2,y.coords[1]+G(v)];break;default:k=y.coords}this.model.fields.new(y,k,v.fontSize,v.fontFamily,v.color,v.selectedColor,m,p,v.horizontalAlign,v.verticalAlign,v.orientation,"",v.editable,v.fit,v.shrink)}}const d=t.type.sectionGrid?.sections?.[a]?.[e]?.label;if(d){const h={...V,...d};this.model.fields.new(o,[o.coords[0]+U(h),o.coords[1]+G(h)],h.fontSize,h.fontFamily,h.color,h.selectedColor,o.width-U(h)-et(h),o.height-G(h)-Z(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&&D(e.node.sections,e),super.remove(t),e.updateInView()}}}const _e={lookType:"shaped-look",shape:Et.Rectangle,fillColor:"#FFFFFF",borderColor:"#000000",borderThickness:1,selected:{fillColor:"#FFAAFF",borderColor:"#AA00AA"},highlighted:{borderThickness:3}},dt={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:_e,isUnique:!1,canBeParentless:!0,childrenTypes:[],priority:Tt,properties:[]};class He{constructor(t){const e={...dt,...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=Mo(e),this.leftPadding=To(e),this.rightPadding=No(e),this.topPadding=Po(e),this.label=e.label,this.ports=e.ports,this.decorators=e.decorators,this.sectionGrid=e.sectionGrid?new Io(e.sectionGrid):null;const a=it(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 Kt(t?.properties||[])}}class R extends xt{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 mt(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 mt(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=it(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(n=>n.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 n=l.start?.getNode();if(n){if(!t&&n.removed)continue;e.push(n)}}for(const l of a.outgoingConnections){if(!t&&l.removed)continue;const n=l.end?.getNode();if(n){if(!t&&n.removed)continue;e.push(n)}}}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){D(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(g.Left,l,e,a):this.stretch(g.Left,l));const n=this.coords[1]-t.coords[1]+this.type.topPadding;n>=0&&(this.sections.length>0?this.stretchSections(g.Top,n,e,a):this.stretch(g.Top,n));const i=t.coords[0]+t.width-(this.coords[0]+this.width)+this.type.rightPadding;i>=0&&(this.sections.length>0?this.stretchSections(g.Right,i,e,a):this.stretch(g.Right,i));const r=t.coords[1]+t.height-(this.coords[1]+this.height)+this.type.bottomPadding;r>=0&&(this.sections.length>0?this.stretchSections(g.Bottom,r,e,a):this.stretch(g.Bottom,r)),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 n,i;switch(t){case g.Left:n=[a[0]-e,a[1]],i=[l[0],l[1]],n[1]-n[0]<this.type.minWidth&&(n[0]=n[1]-this.type.minWidth);break;case g.Top:n=[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 g.Right:n=[a[0],a[1]+e],i=[l[0],l[1]],n[1]-n[0]<this.type.minWidth&&(n[1]=n[0]+this.type.minWidth);break;case g.Bottom:n=[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:[n[0],i[0]],width:n[1]-n[0],height:i[1]-i[0],sections:{},children:{}})}stretchSections(t,e,a,l){let n=Number.NEGATIVE_INFINITY;switch(t){case g.Bottom:for(const i of this.sections)i.indexYInNode===l&&(n=Math.max(n,i.getMinHeight()-i.height));e<n&&(e=n);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 g.Right:for(const i of this.sections)i.indexXInNode===a&&(n=Math.max(n,i.getMinWidth()-i.width));e<n&&(e=n);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 g.Top:for(const i of this.sections)i.indexYInNode===l&&(n=Math.max(n,i.getMinHeight()-i.height));e<n&&(e=n);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 g.Left:for(const i of this.sections)i.indexXInNode===a&&(n=Math.max(n,i.getMinWidth()-i.width));e<n&&(e=n);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],n=[this.coords[1],this.coords[1]+this.height];for(const i of this.children){const r=t.children[i.id];r&&i.setGeometry(r)}for(const i of this.sections){const r=t.sections[i.id];r&&i.setGeometry(r)}for(const i of this.ports)i.move(Xt(i.coords,e,a,l,n,i.anchorPointX,i.anchorPointY));this.label&&(this.label.coords=[this.coords[0]+U(this.type.label),this.coords[1]+G(this.type.label)],this.label.width=this.width-U(this.type.label)-et(this.type.label),this.label.height=this.height-G(this.type.label)-Z(this.type.label),this.label.updateInView());for(const i of this.decorators)i.move(Xt(i.coords,e,a,l,n,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 n of l)n.indexYInNode===t&&(a=Math.max(a,n.width),this.model.sections.remove(n.id));for(const n of l)n.indexYInNode>t&&(--n.indexYInNode,n.move([n.coords[0]-a-e,n.coords[1]]));this.stretch(g.Right,-e-a)}removeSectionRow(t){const e=this.type.sectionGrid?.margin||0;let a=0;const l=[...this.sections];for(const n of l)n.indexXInNode===t&&(a=Math.max(a,n.height),this.model.sections.remove(n.id));for(const n of l)n.indexYInNode>t&&(--n.indexXInNode,n.move([n.coords[0],n.coords[1]-a-e]));this.stretch(g.Bottom,-e-a)}copySectionColumn(t){const e=this.type.sectionGrid?.margin||0;let a=0;const l=[...this.sections];for(const n of l)if(n.indexXInNode===t){a=Math.max(a,n.width);let i=n.indexXInNode+1;for(;this.model.sections.get(`${n.id}_copy_${i}_${n.indexYInNode}`,!0)!==void 0;)++i;this.model.sections.new(this,n.indexXInNode+1,n.indexYInNode,[n.coords[0]+n.width+e,n.coords[1]],n.width,n.height,`${n.id}_copy_${i}_${n.indexYInNode}`)}for(const n of l)n.indexXInNode>t&&(++n.indexXInNode,n.move([n.coords[0]+a+e,n.coords[1]]));this.stretch(g.Right,e+a)}copySectionRow(t){const e=this.type.sectionGrid?.margin||0;let a=0;const l=[...this.sections];for(const n of l)if(n.indexYInNode===t){a=Math.max(a,n.height);let i=n.indexYInNode+1;for(;this.model.sections.get(`${n.id}_copy_${n.indexXInNode}_${i}`,!0)!==void 0;)++i;this.model.sections.new(this,n.indexXInNode,n.indexYInNode+1,[n.coords[0],n.coords[1]+n.height+e],n.width,n.height,`${n.id}_copy_${n.indexXInNode}_${i}`)}for(const n of l)n.indexYInNode>t&&(++n.indexYInNode,n.move([n.coords[0],n.coords[1]+a+e]));this.stretch(g.Bottom,e+a)}}class Eo extends ht{constructor(t){super(),this.types=new Zt,this.model=t}new(t,e,a){let l;if(t instanceof He)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 n=new R(this.model,l,e,a);if(super.add(n),n.updateInView(),l.sectionGrid!==null){let i=n.coords[1]+(l.sectionGrid.margin||0);for(let r=0;r<l.sectionGrid.sections.length;++r){let o=n.coords[0]+(l.sectionGrid.margin||0);for(let c=0;c<l.sectionGrid.sections[r].length;++c)this.model.sections.new(n,c,r,[o,i],l.sectionGrid.defaultWidths?.[c]||Ie,l.sectionGrid.defaultHeights?.[r]||Ae,`${n.id}_${r}_${c}`),o+=(l.sectionGrid.defaultWidths?.[c]||Ie)+(l.sectionGrid.margin||0);i+=(l.sectionGrid.defaultHeights?.[r]||Ae)+(l.sectionGrid.margin||0)}}if(l.ports.length>0)for(let i=0;i<l.ports.length;++i){const r=l.ports[i],o=r.type!==void 0?this.model.ports.types.get(r.type):void 0,c=this.model.ports.new(o,n,[n.coords[0]+r.coords[0],n.coords[1]+r.coords[1]],r.connectionPoint!==void 0?[n.coords[0]+(r.connectionPoint[0]||0),n.coords[1]+(r.connectionPoint[1]||0)]:void 0,r.direction,`${n.id}_port_${i}`,r.anchorPointX||"floating",r.anchorPointY||"floating");if(c.type?.label){const d={...V,...c.type?.label},h=6*d.fontSize+zt(d)+Vt(d),u=d.fontSize+Ot(d)+Rt(d);let y;switch(c.direction){case g.Bottom:case g.Left:case g.Right:y=[c.coords[0]-h/2,c.coords[1]-u-Z(d)];break;case g.Top:y=[c.coords[0]-h/2,c.coords[1]+G(d)];break;default:y=c.coords}this.model.fields.new(c,y,d.fontSize,d.fontFamily,d.color,d.selectedColor,h,u,d.horizontalAlign,d.verticalAlign,d.orientation,"",d.editable,d.fit,d.shrink)}}if(l.label){const i={...V,...l.label};this.model.fields.new(n,[n.coords[0]+U(i),n.coords[1]+G(i)],i.fontSize,i.fontFamily,i.color,i.selectedColor,n.width-U(i)-et(i),n.height-G(i)-Z(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 r=l.decorators[i];this.model.decorators.new(n,[n.coords[0]+r.coords[0],n.coords[1]+r.coords[1]],r.width,r.height,n.getPriority(),r.html,`${n.id}_decorator_${i}`,r.anchorPointX||"floating",r.anchorPointY||"floating")}return n.valueSet.resetValues(),n.model.canvas?.fitNodeInView(n.id),n}remove(t){const e=this.get(t,!0);if(e){for(e.parent&&D(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 je=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},Mo=s=>s?.padding===null||s?.padding===void 0?dt.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?dt.padding:s.padding.length===1||s.padding.length===2?s.padding[0]:(s.padding.length===3,s.padding[2]),To=s=>s?.padding===null||s?.padding===void 0?dt.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?dt.padding:s.padding.length===1?s.padding[0]:s.padding.length===2||s.padding.length===3?s.padding[1]:s.padding[3],No=s=>s?.padding===null||s?.padding===void 0?dt.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?dt.padding:s.padding.length===1?s.padding[0]:(s.padding.length===2||s.padding.length===3,s.padding[1]),Po=s=>s?.padding===null||s?.padding===void 0?dt.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?dt.padding:(s.padding.length===1||s.padding.length===2||s.padding.length===3,s.padding[0]),Ge={lookType:"shaped-look",shape:Et.Ellipse,fillColor:"transparent",borderColor:"transparent",borderThickness:0,selected:{fillColor:"rgba(255, 0, 255, 0.5)"},highlighted:{fillColor:"rgba(0, 255, 255, 0.5)"}},Ut=it(Ge),Fe={name:"",label:null,allowsOutgoing:!0,allowsIncoming:!0,width:24,look:Ge};class Ro{constructor(t){const e={...Fe,...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=it(e.look);this.defaultLook=a.defaultLook,this.selectedLook=a.selectedLook,this.highlightedLook=a.highlightedLook,this.selectedAndHighlightedLook=a.selectedAndHighlightedLook}}class vt extends xt{constructor(t,e,a,l,n,i,r,o="floating",c="floating"){if(t.ports.get(r)!==void 0)throw new Error(`DiagramPort with id "${r}" already exists`);if(!r)throw new Error("DiagramPort cannot have an empty or null id");super(t,r),this.outgoingConnections=[],this.incomingConnections=[],this._type=e,this.rootElement=a,this.coords=l,this.connectionPoint=n||l,this.direction=i,this.anchorPointX=o,this.anchorPointY=c}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||Ut)?.selectedAndHighlightedLook:this._selectedLook!==void 0?this._selectedLook:(this.type||Ut)?.selectedLook:this.highlighted?this._highlightedLook!==void 0?this._highlightedLook:(this.type||Ut)?.highlightedLook:this._defaultLook!==void 0?this._defaultLook:(this.type||Ut)?.defaultLook}set look(t){this.lookConfig=t}get lookConfig(){return this._lookConfig}set lookConfig(t){if(this._lookConfig=t,t){const e=it(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||Fe.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 R)return this.rootElement;if(this.rootElement instanceof F)return this.rootElement.node}getPriority(){return this.rootElement?.getPriority()||Tt}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 Pe(this.coords,t)}}class zo extends ht{constructor(t){super(),this.types=new Zt,this.model=t}new(t,e,a,l,n,i,r="floating",o="floating"){const c=new vt(this.model,t,e,a,l,n,i,r,o);return super.add(c),c.updateInView(),e!==void 0&&e.ports.push(c),c}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 R||e.rootElement instanceof F)&&D(e.rootElement.ports,e),super.remove(t),e.updateInView()}}}class Ue{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 R(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 r=a.decorators[i];t.decorators.new(l,[l.coords[0]+r.coords[0],l.coords[1]+r.coords[1]],r.width,r.height,l.getPriority(),r.html,`${l.id}_decorator_${i}`)}if(a.label){const i={...V,...a.label},r=new ct(t,l,[l.coords[0]+U(i),l.coords[1]+G(i)],l.width-U(i)-et(i),l.height-G(i)-Z(i),i.fontSize,i.fontFamily,i.color,i.selectedColor,i.horizontalAlign,i.verticalAlign,i.orientation,"",i.editable,i.fit,i.shrink);r.text=e.label,l.label=r,t.fields.add(r),r.updateInView()}}for(const i of e.children||[]){const r=this.importNode(t,i);r!==void 0&&(l.children?.push(r),r.parent=l)}for(const i of e.sections||[]){const r=new F(t,l,i.indexXInNode,i.indexYInNode,i.coords,i.width,i.height,i.id);if(l.sections?.push(r),t.sections.add(r),i.label&&a.sectionGrid?.sections?.[i.indexYInNode]?.[i.indexXInNode]?.label){const c={...V,...a.sectionGrid?.sections?.[i.indexYInNode]?.[i.indexXInNode]?.label},d=new ct(t,r,[r.coords[0]+U(c),r.coords[1]+G(c)],r.width-U(c)-et(c),r.height-G(c)-Z(c),c.fontSize,c.fontFamily,c.color,c.selectedColor,c.horizontalAlign,c.verticalAlign,c.orientation,"",c.editable,c.fit,c.shrink);d.text=i.label,r.label=d,t.fields.add(d),d.updateInView()}let o=0;for(const c of i.ports||[]){const d=c.type!==void 0?t.ports.types.get(c.type):void 0,h=new vt(t,d,r,c.coords,c.connectionPoint||c.coords,c.direction,c.id);if(r.ports.push(h),t.ports.add(h),c.label){if(a.ports.length>o&&d?.label){const u={...V,...d?.label};let y;switch(h.direction){case g.Top:case g.Left:y=[h.coords[0]-u.fontSize,h.coords[1]-u.fontSize];break;case g.Bottom:y=[h.coords[0]-u.fontSize,h.coords[1]+u.fontSize];break;case g.Right:y=[h.coords[0]+u.fontSize,h.coords[1]-u.fontSize];break;default:y=h.coords}const v=new ct(t,h,y,u.fontSize,u.fontSize,u.fontSize,u.fontFamily,u.color,u.selectedColor,u.horizontalAlign,u.verticalAlign,u.orientation,"",u.editable,u.fit,u.shrink);v.text=c.label,h.label=v,t.fields.add(v),v.updateInView()}++o}c.collabMeta&&(h.selfRemoved=c.collabMeta.selfRemoved,h.selfRemovedTimestamp=c.collabMeta.selfRemovedTimestamp,this.importLabelCollabMeta(h.label,c.collabMeta.label)),h.updateInView()}i.collabMeta&&(r.selfRemoved=i.collabMeta.selfRemoved,r.selfRemovedTimestamp=i.collabMeta.selfRemovedTimestamp,this.importLabelCollabMeta(r.label,i.collabMeta.label)),r.updateInView()}let n=0;for(const i of e.ports||[]){const r=i.type!==void 0?t.ports.types.get(i.type):void 0,o=new vt(t,r,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>n&&r?.label){const c={...V,...r?.label};let d;switch(o.direction){case g.Top:case g.Left:d=[o.coords[0]-c.fontSize,o.coords[1]-c.fontSize];break;case g.Bottom:d=[o.coords[0]-c.fontSize,o.coords[1]+c.fontSize];break;case g.Right:d=[o.coords[0]+c.fontSize,o.coords[1]-c.fontSize];break;default:d=o.coords}const h=new ct(t,o,d,c.fontSize,c.fontSize,c.fontSize,c.fontFamily,c.color,c.selectedColor,c.horizontalAlign,c.verticalAlign,c.orientation,"",c.editable,c.fit,c.shrink);h.text=i.label,o.label=h,t.fields.add(h),h.updateInView()}++n}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 at(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 qt{constructor(t,e,a,l,n,i,r){this.canvas=t,this.id=e,this.typeId=a,this.coords=l,this.parentId=n,this.label=i,this.values=r}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(Mt({...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 qt(t,e.id,e.typeId,e.coords,e.parentId,e.label,e.values)}}class me{constructor(t,e,a,l,n,i,r){this.canvas=t,this.nodeId=e,this.copyColumnIndex=a,this.copyRowIndex=l,this.removeColumnIndex=n,this.removeRowIndex=i,this.timestamp=r}do(){const t=this.canvas.model.nodes.get(this.nodeId);t&&yt(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&&yt(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 _t{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&&yt(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 _t(t,e.nodeIds,e.delta,e.timestamp)}}class ot{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&&yt(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 ot(t,e.nodeId,e.to,e.timestamp)}}class Ht{constructor(t,e,a,l,n){this.canvas=t,this.childId=e,this.parentId=a,this.childGeometry=l,this.timestamp=n}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)&&yt(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 Ht(t,e.childId,e.parentId,e.childGeometry,e.timestamp)}}class Jt{constructor(t,e,a,l,n){this.canvas=t,this.id=e,this.typeId=a,this.startId=l,this.endId=n}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 Jt(t,e.id,e.typeId,e.startId,e.endId)}}class At{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&&yt(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 At(t,e.fieldId,e.to,e.timestamp)}}class Lt{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 Lt(t,e.id,e.to,e.timestamp)}}class nt{constructor(t,e,a,l,n,i,r,o){this.canvas=t,this.nodeIds=e,this.sectionIds=a,this.portIds=l,this.connectionIds=n,this.fieldIds=i,this.selfRemoved=r,this.timestamp=o}doOne(t){t&&yt(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 nt(t,e.nodeIds,e.sectionIds,e.portIds,e.connectionIds,e.fieldIds,e.removed,e.timestamp)}}class Qt{constructor(t,e,a){this.canvas=t,this.nodes=e,this.connections=a}do(){const t=new Ue;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 Qt(t,e.nodes,e.connections)}}class Vo{constructor(t){this.isInRoom=!1,this.canvas=t,this.replicaId=Ce()}freshTimestamp(){return this.canvas.model.logicalClock++,[this.canvas.model.logicalClock,this.replicaId]}freshId(){return"id"+Ce()}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":{qt.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":{_t.deserialize(this.canvas,t).do();break}case"setGeometry":{ot.deserialize(this.canvas,t).do();break}case"setParent":{Ht.deserialize(this.canvas,t).do();break}case"addConnection":{Jt.deserialize(this.canvas,t).do();break}case"editField":{At.deserialize(this.canvas,t).do();break}case"updateValues":{Lt.deserialize(this.canvas,t).do();break}case"setSelfRemoved":{nt.deserialize(this.canvas,t).do();break}case"paste":{Qt.deserialize(this.canvas,t).do();break}default:console.error("Unknown CollabAction type, skipping:",t)}}}class Oo{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 w=(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))(w||{});class _o{constructor(t,e,a,l,n,i,r,o,c){this.canvas=t,this.type=e,this.coords=a,this.parentId=l,this.ancestorId=n,this.fromAncestorGeometry=i,this.toAncestorGeometry=r,this.label=o,this.values=c,this.id=this.canvas.collabEngine.freshId()}do(){const t=new qt(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 ot(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 nt(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 ot(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 nt(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 ot(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 _t(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 _t(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 B{constructor(t,e,a,l,n,i,r,o){this.canvas=t,this.intent=e,this.nodeId=a,this.from=l,this.to=n,this.ancestorId=i,this.fromAncestorGeometry=r,this.toAncestorGeometry=o}do(){const t=this.canvas.model.nodes.get(this.nodeId);if(t){const e=new ot(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 ot(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 ot(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 ot(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 ot(this.canvas,this.nodeId,this.to,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(e)}return t!==void 0}}class Ho{constructor(t,e,a,l,n,i,r,o,c){this.canvas=t,this.childId=e,this.fromParentId=a,this.toParentId=l,this.fromChildGeometry=n,this.toChildGeometry=i,this.ancestorId=r,this.fromAncestorGeometry=o,this.toAncestorGeometry=c}do(){const t=this.canvas.model.nodes.get(this.childId),e=new Ht(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 ot(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 Ht(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 ot(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 Jt(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 nt(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 nt(this.canvas,[],[],[],[this.id],[],!1,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),t===void 0}}class Le{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 At(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 At(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 At(this.canvas,this.fieldId,this.to,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(e)}return t!==void 0}}class jo{constructor(t,e,a,l){this.canvas=t,this.id=e,this.from=a,this.to=l}do(){const t=new Lt(this.canvas,this.id,this.to,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(t),!0}undo(){const t=new Lt(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 Lt(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 Go{constructor(t,e,a,l,n,i){this.canvas=t,this.nodeIds=e,this.sectionIds=a,this.portIds=l,this.connectionIds=n,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 nt(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 nt(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 Fo{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 n of this.nodes)n.coords[0]<t[0]&&(t[0]=n.coords[0]),n.coords[1]<t[1]&&(t[1]=n.coords[1]);const e=this.coords!==void 0?[this.coords[0]-t[0],this.coords[1]-t[1]]:void 0,a={};for(const n of this.nodes){const i=n.id,r=this.canvas.collabEngine.freshId();if(a[i]=r,n.id=r,e&&(n.coords=[n.coords[0]+e[0],n.coords[1]+e[1]]),n.sections)for(const o of n.sections){const c=o.id;if(o.id.includes(n.id)?o.id=o.id.replace(n.id,r):o.id=this.canvas.collabEngine.freshId(),a[c]=o.id,e&&(o.coords=[o.coords[0]+e[0],o.coords[1]+e[1]]),o.ports)for(const d of o.ports){const h=d.id;d.id.includes(n.id)?d.id=d.id.replace(n.id,r):d.id=this.canvas.collabEngine.freshId(),a[h]=d.id,e&&(d.coords=[d.coords[0]+e[0],d.coords[1]+e[1]],d.connectionPoint&&(d.connectionPoint=[d.connectionPoint[0]+e[0],d.connectionPoint[1]+e[1]]))}}if(n.ports)for(const o of n.ports){const c=o.id;o.id.includes(n.id)?o.id=o.id.replace(n.id,r):o.id=this.canvas.collabEngine.freshId(),a[c]=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 n of this.connections){const i=this.canvas.collabEngine.freshId();if(a[n.id]=i,n.id=i,n.start=a[n.start]||n.start,n.end=a[n.end]||n.end,e)for(let r=0;r<n.points.length;++r)n.points[r]=[n.points[r][0]+e[0],n.points[r][1]+e[1]]}const l=new Qt(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 nt(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 nt(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 te{constructor(t){this.type=t,this.defaultPrevented=!1}preventDefault(){this.defaultPrevented=!0}}var De=(s=>(s[s.DoubleClick=0]="DoubleClick",s[s.SecondaryClick=1]="SecondaryClick",s[s.Selection=2]="Selection",s[s.Highlight=3]="Highlight",s))(De||{});class ft extends te{constructor(t,e,a){super(0),this.cause=t,this.target=e,this.coords=a}}class ut extends te{constructor(t,e,a){super(1),this.cause=t,this.target=e,this.coords=a}}class j extends te{constructor(t,e){super(2),this.targets=t,this.selected=e}}class J extends te{constructor(t){super(3),this.target=t}}class Be extends xt{constructor(t,e,a,l,n,i,r,o,c="floating",d="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=n,this.priority=i,this.html=r,this.anchorPointX=c,this.anchorPointY=d}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 Uo extends ht{constructor(t){super(),this.model=t}new(t,e,a,l,n,i,r,o="floating",c="floating"){const d=new Be(this.model,t,e,a,l,n,i,r,o,c);return super.add(d),d.updateInView(),t!==void 0&&t.decorators.push(d),d}remove(t){const e=this.get(t,!0);e&&((e.rootElement instanceof R||e.rootElement instanceof F)&&D(e.rootElement.decorators,e),super.remove(t),e.updateInView())}}class Do extends xt{constructor(t,e,a,l,n,i,r){if(t.objects.get(r)!==void 0)throw new Error(`DiagramObject with id "${r}" already exists`);if(!r)throw new Error("DiagramObject cannot have an empty or null id");super(t,r),this.coords=e,this.width=a,this.height=l,this.priority=n,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 Bo extends ht{constructor(t){super(),this.model=t}new(t,e,a,l,n,i){const r=new Do(this.model,t,e,a,l,n,i);return super.add(r),r.updateInView(),r}remove(t){const e=this.get(t,!0);e&&(super.remove(t),e.updateInView())}}class Ye{constructor(t,e,a,l,n,i=[]){this.nodes=new Eo(this),this.sections=new Lo(this),this.ports=new zo(this),this.connections=new So(this),this.fields=new xo(this),this.objects=new Bo(this),this.decorators=new Uo(this),this.canvas=t,this.id=e,this.name=a,this.description=l,this.type=n,this.createdAt=new Date,this.updatedAt=new Date,this.logicalClock=0,this.valueSet=new mt(new Kt(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 pt=s=>!!s.button,ne=(s,t,e,a,l,n,i,r)=>no(s,[t,e],a,l,Math.max(10,i||0,r||0)*n),S=s=>{s?A.select("body").style("cursor",s):A.select("body").style("cursor",L.Auto)},lt=s=>s instanceof R?s:s instanceof F?s.node||s:s.rootElement instanceof R||s.rootElement instanceof F||s.rootElement instanceof vt?lt(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")},Nt={fillColor:"#FFFFFF",borderColor:"#000000",borderThickness:1,borderStyle:pe.Solid},ae=s=>{s.filter(".shaped-look").select("path").attr("d",t=>ge(t.look.shape||Et.Rectangle,0,0,t.width,t.height)).attr("fill",t=>t.look.fillColor||Nt.fillColor).attr("stroke",t=>t.look.borderColor||Nt.borderColor).attr("stroke-width",t=>`${t.look.borderThickness||Nt.borderThickness}px`).attr("stroke-dasharray",t=>he(t.look.borderStyle||Nt.borderStyle,t.type?.defaultLook?.borderThickness||t.look?.borderThickness||Nt.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)},Pt={style:"dots",color:"rgba(0, 0, 0, 0.1)",snap:!1,spacing:10,thickness:.05},Yo=(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,Y=32,$t=fe+Y,Xo=Math.PI/4,Wo=100,Ee={customButtons:[]};class Zo{constructor(t,e){this.canvas=t,this.config=e||Ee}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]-$t}px`).attr("y",`${e[1]-$t}px`).attr("width",`${2*$t}px`).attr("height",`${2*$t}px`).style("pointer-events","none").on(C.ContextMenu,i=>{this.canvas.canUserPerformAction(w.ContextMenu)&&(t.preventDefault(),this.open(i))}).on(C.Click,i=>{i.preventDefault(),this.close()});this.contextMenuContainer=l;const n=[];this.canvas.userSelection.length!==0&&this.canvas.canUserPerformAction(w.Clipboard)&&this.canvas.canUserPerformAction(w.Remove)&&n.push({name:"CUT",imageClass:"daga-cut",onPress:i=>{i.userSelection.cutToClipboard(),i.cancelAllUserActions()}}),this.canvas.userSelection.length!==0&&this.canvas.canUserPerformAction(w.Clipboard)&&n.push({name:"COPY",imageClass:"daga-copy",onPress:i=>{i.userSelection.copyToClipboard(),i.cancelAllUserActions()}}),this.canvas.canUserPerformAction(w.Paste)&&n.push({name:"PASTE",imageClass:"daga-paste",onPress:i=>{i.userSelection.pasteFromClipboard(i.getClosestGridPoint(a)),i.cancelAllUserActions()}}),this.canvas.userSelection.length!==0&&this.canvas.canUserPerformAction(w.Remove)&&n.push({name:"DELETE",imageClass:"daga-delete",onPress:i=>{i.userSelection.removeFromModel(),i.cancelAllUserActions()}});for(const i of this.config.customButtons||Ee.customButtons)(i.condition===void 0||i.condition(this.canvas))&&n.push(i);n.length===0&&n.push({name:"NONE",imageClass:"daga-cross",onPress:void 0});for(let i=0;i<n.length;++i){const r=n[i],o=r.onPress,c=(i+.5-n.length/2)*Xo,d=l.append("xhtml:div").attr("class",`daga-context-menu-button ${r.onPress!==void 0?" daga-clickable":""}`).attr("tabindex",0).style("position","absolute").style("box-sizing","border-box").style("width",`${2*Y}px`).style("height",`${2*Y}px`).style("border-radius",`${Y}px`).style("pointer-events","auto").on(C.Click,h=>{o&&(h.preventDefault(),o(this.canvas))}).on(C.KeyDown,h=>{o&&h.key===W.Enter&&(h.preventDefault(),o(this.canvas))});r.imageClass!==void 0?d.append("xhtml:div").style("position","absolute").style("left",`${.75*Y}px`).style("top",`${.5*Y}px`).style("width",`${.5*Y}px`).style("height",`${.5*Y}px`).style("background-size","contain").style("background-repeat","no-repeat").attr("class",r.imageClass):r.image!==void 0&&d.append("xhtml:img").style("position","absolute").style("left",`${.75*Y}px`).style("top",`${.5*Y}px`).style("width",`${.5*Y}px`).style("height",`${.5*Y}px`).attr("src",r.image),d.append("xhtml:span").style("position","absolute").style("left",`${.2*Y}px`).style("top",`${1.1*Y}px`).style("text-align","center").style("width",`${1.6*Y}px`).style("height",`${.35*Y}px`).style("margin","0").style("font-size",`${.35*Y}px`).style("font-weight","700").style("user-select","none").text(r.name),d.transition().ease(A.easeLinear).duration(Wo).tween("progress",()=>h=>{const u=c*h;return d.style("left",`${Math.sin(u)*fe-Y+$t}px`).style("top",`${-Math.cos(u)*fe-Y+$t}px`)})}}close(){this.contextMenuContainer?.remove(),this.contextMenuContainer=void 0}}class Ko extends ht{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 Be)&&t.rootElement?this.focusOn(t.rootElement):this.add(t)}add(t){if(super.add(t),t instanceof R){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 F)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 vt?(t.label&&(super.add(t.label),this.canvas.updateFieldsInView(t.label.id)),this.canvas.updatePortsInView(t.id)):t instanceof at&&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 qo=1;class Xe{export(t,e=!1){const a={name:t.name,type:t.type,typeVersion:qo,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 r=[];for(const o of i.ports)r.push({id:o.id,type:o.type?.id,coords:Ct(o.coords),connectionPoint:Ct(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:r,label:i.label?.text||"",indexXInNode:i.indexXInNode,indexYInNode:i.indexYInNode,coords:Ct(i.coords),width:i.width,height:i.height,...e?{collabMeta:{removed:i.removed,selfRemoved:i.selfRemoved,selfRemovedTimestamp:i.selfRemovedTimestamp,...this.exportLabelCollabMeta(i)}}:{}})}const n=[];for(const i of t.ports)n.push({id:i.id,type:i.type?.id,coords:Ct(i.coords),connectionPoint:Ct(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:n,label:t.label?.text||"",coords:Ct(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 Jo="Diagram properties";class Qo extends ht{constructor(t,e){super(),this.canvas=t,this.canvas.propertyEditorChanges$.pipe(kt.debounceTime(2e3)).subscribe(()=>{this.makeUpdateValuesAction()}),console.log(e),this.diagramPropertiesText=e!==void 0?e:Jo}add(t){if(!this.contains(t.id)&&(this.length===0?this.propertyEditorSelection===void 0&&(t instanceof R||t instanceof at)?this.openInPropertyEditor(t):this.propertyEditorSelection===void 0&&t instanceof F?this.openInPropertyEditor(t.node):this.openInPropertyEditor(void 0):this.openInPropertyEditor(void 0),super.add(t),t.updateInView(),t instanceof R&&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 R&&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 R&&e.move([e.coords[0]+t[0],e.coords[1]+t[1]])}removeFromModel(){if(this.length>0){const t=[],e=[],a=[],l=[],n=[];for(const r of this.all())r instanceof R?t.push(r.id):r instanceof F?e.push(r.id):r instanceof vt?a.push(r.id):r instanceof at?l.push(r.id):r instanceof ct&&n.push(r.id);const i=new Go(this.canvas,t,e,a,l,n);i.do(),this.canvas.actionStack.add(i)}}copyToClipboard(){const t={type:"daga-user-selection",nodes:[],connections:[]},e=new Xe;for(const a of this.all())a instanceof R&&t.nodes.push(e.exportNode(a,!1)),a instanceof at&&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 Fo(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=Mt(l.getValues())),a&&(t instanceof R||t instanceof at?(t instanceof R?t.name?a.title=`${t.type.name}: ${t.name}`:a.title=t.type.name:t instanceof at&&(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 Ye?void 0:this.propertyEditorSelection.id;if(wt(this.propertyEditorValues,this.propertyEditorSelection?.valueSet.getValues()))return;const e=this.propertyEditorValues,a=Mt(this.propertyEditorSelection?.valueSet.getValues()),[l,n]=Ve(e,a,this.propertyEditorSelection?.valueSet),i=new jo(this.canvas,t,l,n);i.do(),this.canvas.actionStack.add(i),this.propertyEditorValues=a}}const ti=s=>s*Math.PI/180,Me=(s,t,e)=>{const a=ti(e),l=Math.sin(a),n=Math.cos(a),i=(Math.abs(s*n)-Math.abs(t*l))/(n*n-l*l),r=(Math.abs(s*l)-Math.abs(t*n))/(l*l-n*n);return[i,r]},ei=12,_=6,oi=25,le="diagram-connection-unfinished",Wt=class Wt{constructor(t,e){if(this.backgroundPatternId=`daga-background-pattern-id-${Wt.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 Ye(this,void 0,e.name||"unnamed","",e.type||"",e.properties||[]),this.userSelection=new Qo(this,e.components?.propertyEditor?.title),this.userHighlight=new Ko(this,e.canvas?.highlightSections!==!1),this.contextMenu=new Zo(this,e.canvas?.contextMenu),this.backgroundColor=e.canvas?.backgroundColor||"#FFFFFF",this.gridStyle=e.canvas?.grid?.style??Pt.style,this.gridSize=e.canvas?.grid?.enabled===!1||e.canvas?.grid===void 0?0:Math.abs(e.canvas?.grid?.spacing||Pt.spacing),this.gridThickness=Math.abs(e.canvas?.grid?.thickness||Pt.thickness),this.gridColor=e.canvas?.grid?.color||Pt.color,this.snapToGrid=e.canvas?.grid?.enabled===!1||e.canvas?.grid===void 0?!1:e.canvas?.grid?.snap||Pt.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 Oo(this,oi),this.collabEngine=new Vo(this),e.nodeTypes)for(const a of e.nodeTypes){const l=new He({...e.nodeTypeDefaults,...a});this.model.nodes.types.add(l)}if(e.portTypes)for(const a of e.portTypes){const l=new Ro({...e.portTypeDefaults,...a});this.model.ports.types.add(l)}if(e.connectionTypes){for(const a of e.connectionTypes){const l=new Oe({...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){D(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(C.Click,()=>{A.select(this.diagramRoot).node()?.focus()}).on(C.ContextMenu,l=>{if(this.dragging){l.preventDefault(),l.stopPropagation(),this.dragging=!1;return}const n=new ut(l,null);this.diagramEvent$.next(n),!n.defaultPrevented&&this.canUserPerformAction(w.ContextMenu)&&(l.preventDefault(),this.contextMenu.open(l))}).on(C.DoubleClick,l=>{const n=new ft(l,null);this.diagramEvent$.next(n)}).on(C.KeyDown,l=>{if(!l.ctrlKey&&(l.key===W.Delete||l.key===W.Backspace)&&this.canUserPerformAction(w.Remove)&&(this.userSelection.removeFromModel(),this.cancelAllUserActions()),l.ctrlKey&&l.key==="a"){l.preventDefault();for(const n of this.model.nodes)this.userSelection.add(n);for(const n of this.model.connections)this.userSelection.add(n);this.diagramEvent$.next(new j(this.userSelection.all(),!0))}if(l.ctrlKey&&l.key==="i"){l.preventDefault();const n=[],i=[];for(const r of this.model.nodes)this.userSelection.toggle(r),r.selected?n.push(r):i.push(r);for(const r of this.model.connections)this.userSelection.toggle(r),r.selected?n.push(r):i.push(r);n.length>0&&this.diagramEvent$.next(new j(n,!0)),i.length>0&&this.diagramEvent$.next(new j(i,!1))}if(l.ctrlKey&&l.key==="c"&&this.canUserPerformAction(w.Clipboard)&&(l.preventDefault(),this.userSelection.copyToClipboard(),this.cancelAllUserActions()),l.ctrlKey&&l.key==="x"&&this.canUserPerformAction(w.Clipboard)&&this.canUserPerformAction(w.Remove)&&(l.preventDefault(),this.userSelection.cutToClipboard(),this.cancelAllUserActions()),l.ctrlKey&&l.key==="v"&&this.canUserPerformAction(w.Paste)){l.preventDefault();const n=this.getCoordinatesOnScreen();this.userSelection.pasteFromClipboard(this.getClosestGridPoint([(n[0][0]+n[1][0])/2,(n[0][1]+n[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(w.Zoom)&&(l.preventDefault(),this.zoomBy(this.zoomFactor)),l.key==="-"&&this.canUserPerformAction(w.Zoom)&&(l.preventDefault(),this.zoomBy(1/this.zoomFactor)),l.key===W.ArrowLeft&&this.canUserPerformAction(w.Zoom)&&(l.preventDefault(),this.translateBy(this.panRate/this.zoomTransform.k,0)),l.key===W.ArrowRight&&this.canUserPerformAction(w.Zoom)&&(l.preventDefault(),this.translateBy(-this.panRate/this.zoomTransform.k,0)),l.key===W.ArrowDown&&this.canUserPerformAction(w.Zoom)&&(l.preventDefault(),this.translateBy(0,-this.panRate/this.zoomTransform.k)),l.key===W.ArrowUp&&this.canUserPerformAction(w.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!==C.DoubleClick).on(ce.Zoom,l=>{if(l.sourceEvent){if(!this.canUserPerformAction(w.Zoom)){S(L.NotAllowed);return}l.sourceEvent.type===C.Wheel&&l.sourceEvent.wheelDelta!==void 0?(l.sourceEvent.wheelDelta>0&&S(L.ZoomIn),l.sourceEvent.wheelDelta<0&&S(L.ZoomOut)):l.sourceEvent.type===C.MouseMove&&S(L.AllScroll)}this.zoomTransform=l.transform;const n=l.transform.toString();this.selectCanvasElements().attr("transform",n),A.select(`#${this.backgroundPatternId}`).attr("patternTransform",n),this.contextMenu.close()}).on(ce.End,()=>{S()})),a.append("rect").attr("x",0).attr("y",0).attr("width","100%").attr("height","100%").attr("fill",this.backgroundColor).attr("stroke-width","0").on(C.MouseMove,l=>{if(this.unfinishedConnection!==void 0){const n=this.getPointerLocationRelativeToCanvas(l);this.unfinishedConnection.endCoords=n}}).on(C.MouseOver,()=>{this.userHighlight.size()>0&&(this.userHighlight.clear(),this.diagramEvent$.next(new J(null)))}).on(C.Click,()=>{if(this.userHighlight.size()>0&&(this.userHighlight.clear(),this.diagramEvent$.next(new J(null))),this.contextMenu.close(),this.userSelection.size()>0){const l=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new j(l,!1))}this.userSelection.openInPropertyEditor(this.model)}).call(A.drag().filter(l=>this.multipleSelectionOn||pt(l)).on($.Start,l=>{this.startMultipleSelection(l)}).on($.Drag,l=>{this.continueMultipleSelection(l)}).on($.End,l=>{this.finishMultipleSelection(l)})),Yo(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(v=>v.coords[0])),l=Math.max(...e.map(v=>v.coords[0]+v.width)),n=(a+l)/2,i=l-a,r=t.width,o=Math.min(...e.map(v=>v.coords[1])),c=Math.max(...e.map(v=>v.coords[1]+v.height)),d=(o+c)/2,h=c-o,u=t.height,y=Math.min(r/i,u/h,1);this.translateTo(n,d),this.zoomTo(y)}}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 n=l.merge(e);a.remove(),l.on(C.MouseOver,(i,r)=>{this.dragging||(this.userHighlight.focusOn(r),this.diagramEvent$.next(new J(r)))}).on(C.Click,(i,r)=>{if(!i.ctrlKey&&!i.shiftKey){const o=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new j(o,!1))}this.userSelection.toggle(r),this.diagramEvent$.next(new j([r],r.selected))}).on(C.ContextMenu,(i,r)=>{if(this.dragging){i.preventDefault(),i.stopPropagation(),this.dragging=!1;return}const o=new ut(i,r);this.diagramEvent$.next(o),!o.defaultPrevented&&this.canUserPerformAction(w.ContextMenu)&&(i.preventDefault(),this.userHighlight.focusOn(r),this.diagramEvent$.next(new J(r)),this.userSelection.add(r),this.diagramEvent$.next(new j([r],!0)),this.contextMenu.open(i))}).on(C.DoubleClick,(i,r)=>{const o=new ft(i,r);this.diagramEvent$.next(o)}).call(A.drag().filter(i=>(this.secondaryButton=pt(i),!0)).on($.Start,(i,r)=>{this.multipleSelectionOn||this.secondaryButton?this.startMultipleSelection(i):this.startMovingNode(i,r)}).on($.Drag,(i,r)=>{this.multipleSelectionOn||this.secondaryButton?this.continueMultipleSelection(i):this.continueMovingNode(i,r)}).on($.End,(i,r)=>{this.multipleSelectionOn||this.secondaryButton?this.finishMultipleSelection(i):this.finishMovingNode(i,r),this.secondaryButton=!1})),re(l),l.filter(".resizable-x").append("line").attr("class","left-resizer").attr("stroke","transparent").attr("stroke-width",`${_}px`).on(C.MouseOver,(i,r)=>{this.canUserPerformAction(w.StretchNode)&&r.type.resizableX&&!r.removed&&S(L.EWResize)}).on(C.MouseOut,(i,r)=>{this.canUserPerformAction(w.StretchNode)&&r.type.resizableX&&!r.removed&&S()}).call(A.drag().on($.Start,(i,r)=>{this.canUserPerformAction(w.StretchNode)&&r.type.resizableX&&!r.removed?(S(L.EWResize),this.currentAction=new B(this,w.StretchNode,r.id,r.getGeometry(),r.getGeometry())):S(L.NotAllowed)}).on($.Drag,(i,r)=>{if(this.canUserPerformAction(w.StretchNode)&&r.type.resizableX&&!r.removed){const o=this.getPointerLocationRelativeToCanvas(i);r.stretch(g.Left,r.coords[0]-o[0])}}).on($.End,(i,r)=>{if(this.canUserPerformAction(w.StretchNode)&&r.type.resizableX&&!r.removed&&this.currentAction instanceof B&&this.currentAction.intent===w.StretchNode){let o=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(o=this.getClosestGridPoint([o[0]-r.type.snapToGridOffset[0],o[1]-r.type.snapToGridOffset[1]]),o[0]+=r.type.snapToGridOffset[0],o[1]+=r.type.snapToGridOffset[1]),r.stretch(g.Left,r.coords[0]-o[0]),this.currentAction.to=r.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}S()})),l.filter(".resizable-y").append("line").attr("class","top-resizer").attr("stroke","transparent").attr("stroke-width",`${_}px`).on(C.MouseOver,(i,r)=>{this.canUserPerformAction(w.StretchNode)&&r.type.resizableY&&!r.removed&&S(L.NSResize)}).on(C.MouseOut,(i,r)=>{this.canUserPerformAction(w.StretchNode)&&r.type.resizableY&&!r.removed&&S()}).call(A.drag().on($.Start,(i,r)=>{this.canUserPerformAction(w.StretchNode)&&r.type.resizableY&&!r.removed?(S(L.NSResize),this.currentAction=new B(this,w.StretchNode,r.id,r.getGeometry(),r.getGeometry())):S(L.NotAllowed)}).on($.Drag,(i,r)=>{if(this.canUserPerformAction(w.StretchNode)&&r.type.resizableY&&!r.removed){const o=this.getPointerLocationRelativeToCanvas(i);r.stretch(g.Top,r.coords[1]-o[1])}}).on($.End,(i,r)=>{if(this.canUserPerformAction(w.StretchNode)&&r.type.resizableY&&!r.removed&&this.currentAction instanceof B&&this.currentAction.intent===w.StretchNode){let o=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(o=this.getClosestGridPoint([o[0]-r.type.snapToGridOffset[0],o[1]-r.type.snapToGridOffset[1]]),o[0]+=r.type.snapToGridOffset[0],o[1]+=r.type.snapToGridOffset[1]),r.stretch(g.Top,r.coords[1]-o[1]),this.currentAction.to=r.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}S()})),l.filter(".resizable-x").append("line").attr("class","right-resizer").attr("stroke","transparent").attr("stroke-width",`${_}px`).on(C.MouseOver,(i,r)=>{this.canUserPerformAction(w.StretchNode)&&r.type.resizableX&&!r.removed&&S(L.EWResize)}).on(C.MouseOut,(i,r)=>{this.canUserPerformAction(w.StretchNode)&&r.type.resizableX&&!r.removed&&S()}).call(A.drag().on($.Start,(i,r)=>{this.canUserPerformAction(w.StretchNode)&&r.type.resizableX&&!r.removed?(S(L.EWResize),this.currentAction=new B(this,w.StretchNode,r.id,r.getGeometry(),r.getGeometry())):S(L.NotAllowed)}).on($.Drag,(i,r)=>{if(this.canUserPerformAction(w.StretchNode)&&r.type.resizableX&&!r.removed){const o=this.getPointerLocationRelativeToCanvas(i);r.stretch(g.Right,o[0]-(r.coords[0]+r.width))}}).on($.End,(i,r)=>{if(this.canUserPerformAction(w.StretchNode)&&r.type.resizableX&&!r.removed&&this.currentAction instanceof B&&this.currentAction.intent===w.StretchNode){let o=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(o=this.getClosestGridPoint([o[0]-r.type.snapToGridOffset[2],o[1]-r.type.snapToGridOffset[3]]),o[0]+=r.type.snapToGridOffset[2],o[1]+=r.type.snapToGridOffset[3]),r.stretch(g.Right,o[0]-(r.coords[0]+r.width)),this.currentAction.to=r.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}S()})),l.filter(".resizable-y").append("line").attr("class","bottom-resizer").attr("stroke","transparent").attr("stroke-width",`${_}px`).on(C.MouseOver,(i,r)=>{this.canUserPerformAction(w.StretchNode)&&r.type.resizableY&&!r.removed&&S(L.NSResize)}).on(C.MouseOut,(i,r)=>{this.canUserPerformAction(w.StretchNode)&&r.type.resizableY&&!r.removed&&S()}).call(A.drag().on($.Start,(i,r)=>{this.canUserPerformAction(w.StretchNode)&&r.type.resizableY&&!r.removed?(S(L.NSResize),this.currentAction=new B(this,w.StretchNode,r.id,r.getGeometry(),r.getGeometry())):S(L.NotAllowed)}).on($.Drag,(i,r)=>{if(this.canUserPerformAction(w.StretchNode)&&r.type.resizableY&&!r.removed){const o=this.getPointerLocationRelativeToCanvas(i);r.stretch(g.Bottom,o[1]-(r.coords[1]+r.height))}}).on($.End,(i,r)=>{if(this.canUserPerformAction(w.StretchNode)&&r.type.resizableY&&!r.removed&&this.currentAction instanceof B&&this.currentAction.intent===w.StretchNode){let o=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&this.snapToGrid&&(o=this.getClosestGridPoint([o[0]-r.type.snapToGridOffset[2],o[1]-r.type.snapToGridOffset[3]]),o[0]+=r.type.snapToGridOffset[2],o[1]+=r.type.snapToGridOffset[3]),r.stretch(g.Bottom,o[1]-(r.coords[1]+r.height)),this.currentAction.to=r.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}S()})),n.attr("transform",i=>`translate(${i.coords[0]},${i.coords[1]})`).attr("opacity",i=>i.removed?.5:1),ae(n),n.filter(".resizable-x").select("line.left-resizer").attr("x1",_/2).attr("x2",_/2).attr("y1",0).attr("y2",i=>i.height),n.filter(".resizable-y").select("line.top-resizer").attr("x1",0).attr("x2",i=>i.width).attr("y1",_/2).attr("y2",_/2),n.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),n.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 n=l.merge(e);a.remove(),l.on(C.MouseOver,(i,r)=>{this.dragging||(this.userHighlight.focusOn(r),this.diagramEvent$.next(new J(r)))}).on(C.Click,(i,r)=>{if(!i.ctrlKey&&!i.shiftKey){const c=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new j(c,!1))}const o=lt(r);this.userSelection.toggle(o),this.diagramEvent$.next(new j([o],o.selected))}).on(C.ContextMenu,(i,r)=>{if(this.dragging){i.preventDefault(),i.stopPropagation(),this.dragging=!1;return}const o=new ut(i,r);if(this.diagramEvent$.next(o),!o.defaultPrevented&&this.canUserPerformAction(w.ContextMenu)){i.preventDefault();const c=lt(r);this.userHighlight.focusOn(c),this.diagramEvent$.next(new J(c)),this.userSelection.add(c),this.diagramEvent$.next(new j([c],!0)),this.contextMenu.open(i)}}).on(C.DoubleClick,(i,r)=>{const o=new ft(i,r);this.diagramEvent$.next(o)}).call(A.drag().filter(i=>(this.secondaryButton=pt(i),!0)).on($.Start,(i,r)=>{if(this.multipleSelectionOn||this.secondaryButton)this.startMultipleSelection(i);else{const o=r?.node;o?this.startMovingNode(i,o):S(L.NotAllowed)}}).on($.Drag,(i,r)=>{if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(i);else{const o=r?.node;o?this.continueMovingNode(i,o):S(L.NotAllowed)}}).on($.End,(i,r)=>{if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(i);else{const o=r?.node;o?this.finishMovingNode(i,o):S()}this.secondaryButton=!1})),re(l),l.filter(".resizable-x").append("line").attr("class","left-resizer").attr("stroke","transparent").attr("stroke-width",`${_}px`).on(C.MouseOver,(i,r)=>{this.canUserPerformAction(w.StretchSection)&&r.getResizableX()&&!r.removed&&S(L.EWResize)}).on(C.MouseOut,(i,r)=>{this.canUserPerformAction(w.StretchSection)&&r.getResizableX()&&!r.removed&&S()}).call(A.drag().on($.Start,(i,r)=>{this.canUserPerformAction(w.StretchSection)&&r.getResizableX()&&!r.removed&&r.node?(S(L.EWResize),this.currentAction=new B(this,w.StretchSection,r.node.id,r.node.getGeometry(),r.node.getGeometry())):S(L.NotAllowed)}).on($.Drag,(i,r)=>{if(this.canUserPerformAction(w.StretchSection)&&r.getResizableX()&&!r.removed&&r.node){const o=this.getPointerLocationRelativeToCanvas(i);r.node.stretchSections(g.Left,r.coords[0]-o[0],r.indexXInNode,r.indexYInNode)}}).on($.End,(i,r)=>{if(this.canUserPerformAction(w.StretchSection)&&r.getResizableX()&&!r.removed&&this.currentAction instanceof B&&this.currentAction.intent===w.StretchSection&&r.node){let o=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(o=this.getClosestGridPoint(o)),r.node.stretchSections(g.Left,r.coords[0]-o[0],r.indexXInNode,r.indexYInNode),this.currentAction.to=r.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}S()})),l.filter(".resizable-y").append("line").attr("class","top-resizer").attr("stroke","transparent").attr("stroke-width",`${_}px`).on(C.MouseOver,(i,r)=>{this.canUserPerformAction(w.StretchSection)&&r.getResizableY()&&!r.removed&&S(L.NSResize)}).on(C.MouseOut,(i,r)=>{this.canUserPerformAction(w.StretchSection)&&r.getResizableY()&&!r.removed&&S()}).call(A.drag().on($.Start,(i,r)=>{this.canUserPerformAction(w.StretchSection)&&r.getResizableY()&&!r.removed&&r.node?(S(L.NSResize),this.currentAction=new B(this,w.StretchSection,r.node.id,r.node.getGeometry(),r.node.getGeometry())):S(L.NotAllowed)}).on($.Drag,(i,r)=>{if(this.canUserPerformAction(w.StretchSection)&&r.getResizableY()&&!r.removed&&r.node){const o=this.getPointerLocationRelativeToCanvas(i);r.node.stretchSections(g.Top,r.coords[1]-o[1],r.indexXInNode,r.indexYInNode)}}).on($.End,(i,r)=>{if(this.canUserPerformAction(w.StretchSection)&&r.getResizableY()&&!r.removed&&this.currentAction instanceof B&&this.currentAction.intent===w.StretchSection&&r.node){let o=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(o=this.getClosestGridPoint(o)),r.node.stretchSections(g.Top,r.coords[1]-o[1],r.indexXInNode,r.indexYInNode),this.currentAction.to=r.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}S()})),l.filter(".resizable-x").append("line").attr("class","right-resizer").attr("stroke","transparent").attr("stroke-width",`${_}px`).on(C.MouseOver,(i,r)=>{this.canUserPerformAction(w.StretchSection)&&r.getResizableX()&&!r.removed&&S(L.EWResize)}).on(C.MouseOut,(i,r)=>{this.canUserPerformAction(w.StretchSection)&&r.getResizableX()&&!r.removed&&S()}).call(A.drag().on($.Start,(i,r)=>{this.canUserPerformAction(w.StretchSection)&&r.getResizableX()&&!r.removed&&r.node?(S(L.EWResize),this.currentAction=new B(this,w.StretchSection,r.node.id,r.node.getGeometry(),r.node.getGeometry())):S(L.NotAllowed)}).on($.Drag,(i,r)=>{if(this.canUserPerformAction(w.StretchSection)&&r.getResizableX()&&!r.removed&&r.node){const o=this.getPointerLocationRelativeToCanvas(i);r.node.stretchSections(g.Right,o[0]-(r.coords[0]+r.width),r.indexXInNode,r.indexYInNode)}}).on($.End,(i,r)=>{if(this.canUserPerformAction(w.StretchSection)&&r.getResizableX()&&!r.removed&&this.currentAction instanceof B&&this.currentAction.intent===w.StretchSection&&r.node){let o=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(o=this.getClosestGridPoint(o)),r.node.stretchSections(g.Right,o[0]-(r.coords[0]+r.width),r.indexXInNode,r.indexYInNode),this.currentAction.to=r.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}S()})),l.filter(".resizable-y").append("line").attr("class","bottom-resizer").attr("stroke","transparent").attr("stroke-width",`${_}px`).on(C.MouseOver,(i,r)=>{this.canUserPerformAction(w.StretchSection)&&r.getResizableY()&&!r.removed&&S(L.NSResize)}).on(C.MouseOut,(i,r)=>{this.canUserPerformAction(w.StretchSection)&&r.getResizableY()&&!r.removed&&S()}).call(A.drag().on($.Start,(i,r)=>{this.canUserPerformAction(w.StretchSection)&&r.getResizableY()&&!r.removed&&r.node?(S(L.NSResize),this.currentAction=new B(this,w.StretchSection,r.node.id,r.node.getGeometry(),r.node.getGeometry())):S(L.NotAllowed)}).on($.Drag,(i,r)=>{if(this.canUserPerformAction(w.StretchSection)&&r.getResizableY()&&!r.removed&&r.node){const o=this.getPointerLocationRelativeToCanvas(i);r.node.stretchSections(g.Bottom,o[1]-(r.coords[1]+r.height),r.indexXInNode,r.indexYInNode)}}).on($.End,(i,r)=>{if(this.canUserPerformAction(w.StretchSection)&&r.getResizableY()&&!r.removed&&this.currentAction instanceof B&&this.currentAction.intent===w.StretchSection&&r.node){let o=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(o=this.getClosestGridPoint(o)),r.node.stretchSections(g.Bottom,o[1]-(r.coords[1]+r.height),r.indexXInNode,r.indexYInNode),this.currentAction.to=r.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}S()})),n.attr("transform",i=>`translate(${i.coords[0]},${i.coords[1]})`).attr("opacity",i=>i.removed?.5:1),ae(n),n.filter(".resizable-x").select("line.left-resizer").attr("x1",_/2).attr("x2",_/2).attr("y1",0).attr("y2",i=>i.height),n.filter(".resizable-y").select("line.top-resizer").attr("x1",0).attr("x2",i=>i.width).attr("y1",_/2).attr("y2",_/2),n.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),n.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 n=l.merge(e);a.remove(),l.on(C.MouseOver,(i,r)=>{!this.unfinishedConnection&&!this.dragging&&(this.userHighlight.focusOn(r),this.diagramEvent$.next(new J(r))),this.unfinishedConnection&&(this.unfinishedConnection.type.canStartFromType(this.unfinishedConnection.start?.getNode()?.type?.id||"")&&this.unfinishedConnection.start?.allowsOutgoing&&this.unfinishedConnection.type.canFinishOnType(r.getNode()?.type?.id||"")&&r.allowsIncoming||this.unfinishedConnection.type.canStartFromType(r.getNode()?.type?.id||"")&&r.allowsOutgoing&&this.unfinishedConnection.type.canFinishOnType(this.unfinishedConnection.start?.getNode()?.type?.id||"")&&this.unfinishedConnection.start?.allowsIncoming||S(L.NoDrop))}).on(C.MouseOut,()=>{this.unfinishedConnection&&S(L.Grabbing)}).on(C.Click,(i,r)=>{if(!i.ctrlKey&&!i.shiftKey){const c=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new j(c,!1))}const o=lt(r);this.userSelection.toggle(o),this.diagramEvent$.next(new j([o],o.selected))}).on(C.ContextMenu,(i,r)=>{if(this.dragging){i.preventDefault(),i.stopPropagation(),this.dragging=!1;return}const o=new ut(i,r);if(this.diagramEvent$.next(o),!o.defaultPrevented&&this.canUserPerformAction(w.ContextMenu)){i.preventDefault();const c=lt(r);this.userHighlight.focusOn(c),this.diagramEvent$.next(new J(c)),this.userSelection.add(c),this.diagramEvent$.next(new j([c],!0)),this.contextMenu.open(i)}}).on(C.DoubleClick,(i,r)=>{const o=new ft(i,r);this.diagramEvent$.next(o)}).call(A.drag().filter(i=>(this.secondaryButton=pt(i),!0)).on($.Start,(i,r)=>{this.multipleSelectionOn||this.secondaryButton?this.startMultipleSelection(i):this.canUserPerformAction(w.AddConnection)&&(this.allowSharingPorts||r.incomingConnections.length===0&&r.outgoingConnections.length===0)&&!r.removed?(S(L.Grabbing),this.startConnection(r),this.unfinishedConnection&&(this.unfinishedConnectionTracer=this.selectCanvasElements().append("path").attr("stroke","none").attr("fill","none"))):S(L.NotAllowed)}).on($.Drag,(i,r)=>{if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(i);else if(this.canUserPerformAction(w.AddConnection)&&!r.removed&&this.unfinishedConnection!==void 0){const o=[i.x,i.y];this.unfinishedConnectionTracer?.attr("d",ne(this.unfinishedConnection.look.shape||tt.look.shape,this.unfinishedConnection.startCoords,o,this.unfinishedConnection.startDirection,this.unfinishedConnection.endDirection,this.unfinishedConnection.type.defaultLook.thickness||tt.look.thickness,this.unfinishedConnection.type.defaultStartMarkerLook?.width,this.unfinishedConnection.type.defaultEndMarkerLook?.width));const c=this.unfinishedConnectionTracer?.node();if(c){let d=2;const h=c.getTotalLength();h<d&&(d=0);const u=c.getPointAtLength(h-d);this.unfinishedConnection.endCoords=[u.x,u.y]}else this.unfinishedConnection.endCoords=o;if(this.updateConnectionsInView(le),this.model.ports.length>0){const d=this.getPointerLocationRelativeToCanvas(i);let h=Number.POSITIVE_INFINITY,u;for(const y of this.model.ports){const v=y.distanceTo(d);v<h&&(h=v,u=y)}u&&h<this.portHighlightRadius?this.userHighlight.focusOn(u):this.userHighlight.clear()}}}).on($.End,(i,r)=>{if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(i);else{if(this.canUserPerformAction(w.AddConnection)&&!r.removed){this.unfinishedConnectionTracer?.remove();const o=this.userHighlight.getFocus();if(o instanceof vt)this.finishConnection(o);else if(o instanceof ct&&o.rootElement instanceof vt)this.finishConnection(o.rootElement);else if(o instanceof R||o instanceof F||o instanceof ct){let c;if(o instanceof R||o instanceof F)c=o;else if(o.rootElement instanceof R||o.rootElement instanceof F)c=o.rootElement;else{this.dropConnection();return}const d=c.getClosestPortToPoint([i.x,i.y]);d!==void 0?this.finishConnection(d):this.dropConnection()}else this.dropConnection()}S()}this.secondaryButton=!1})),l.filter(".image-look").append("image"),re(l),n.attr("transform",i=>`translate(${i.coords[0]-i.width/2},${i.coords[1]-i.width/2})`).attr("opacity",i=>i.removed?.5:1),ae(n)}updateConnectionsInView(...t){const e=this.model.connections.filter(r=>this.priorityThreshold!==void 0?r.getPriority()>=this.priorityThreshold:!0);this.unfinishedConnection&&e.push(this.unfinishedConnection);let a=this.selectCanvasElements().selectAll("g.diagram-connection").data(e,r=>r.id);const l=a.exit(),n=a.enter().append("g").attr("id",r=>r.id).attr("class","diagram-connection");t&&t.length>0&&(a=a.filter(r=>t.includes(r.id)));const i=n.merge(a);l.remove(),n.on(C.MouseOver,(r,o)=>{o.end!==void 0&&!this.dragging&&(this.userHighlight.focusOn(o),this.diagramEvent$.next(new J(o)))}).on(C.Click,(r,o)=>{if(!r.ctrlKey&&!r.shiftKey){const c=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new j(c,!1))}this.userSelection.toggle(o),this.diagramEvent$.next(new j([o],o.selected))}).on(C.ContextMenu,(r,o)=>{if(this.dragging){r.preventDefault(),r.stopPropagation(),this.dragging=!1;return}const c=new ut(r,o);this.diagramEvent$.next(c),!c.defaultPrevented&&this.canUserPerformAction(w.ContextMenu)&&(r.preventDefault(),this.userHighlight.focusOn(o),this.diagramEvent$.next(new J(o)),this.userSelection.add(o),this.diagramEvent$.next(new j([o],!0)),this.contextMenu.open(r))}).on(C.DoubleClick,(r,o)=>{const c=new ft(r,o);this.diagramEvent$.next(c)}).call(A.drag().filter(r=>(this.secondaryButton=pt(r),!0)).on($.Start,r=>{this.startMultipleSelection(r)}).on($.Drag,r=>{this.continueMultipleSelection(r)}).on($.End,r=>{this.finishMultipleSelection(r)})),n.append("path").attr("class","diagram-connection-path"),n.append("path").attr("class","diagram-connection-path-box"),n.append("marker").attr("id",r=>`${r.id}-start-marker`).attr("class","diagram-connection-start-marker").append("image").attr("preserveAspectRatio","none"),n.append("marker").attr("id",r=>`${r.id}-end-marker`).attr("class","diagram-connection-end-marker").append("image").attr("preserveAspectRatio","none"),n.append("g").attr("class","diagram-connection-start-label"),n.select("g.diagram-connection-start-label").append("path"),n.select("g.diagram-connection-start-label").append("text").style("user-select","none"),n.append("g").attr("class","diagram-connection-middle-label"),n.select("g.diagram-connection-middle-label").append("path"),n.select("g.diagram-connection-middle-label").append("text").style("user-select","none"),n.append("g").attr("class","diagram-connection-end-label"),n.select("g.diagram-connection-end-label").append("path"),n.select("g.diagram-connection-end-label").append("text").style("user-select","none"),i.attr("opacity",r=>r.removed?.5:1).select("path.diagram-connection-path").attr("d",r=>ne(r.look.shape||tt.look.shape,r.startCoords,r.endCoords,r.startDirection,r.endDirection,r.type.defaultLook.thickness||tt.look.thickness,r.type.defaultStartMarkerLook?.width,r.type.defaultEndMarkerLook?.width)).attr("marker-start",r=>`url(#${r.id}-start-marker)`).attr("marker-end",r=>`url(#${r.id}-end-marker)`).attr("stroke",r=>r.look.color||tt.look.color).attr("stroke-width",r=>`${r.look.thickness}px`).attr("stroke-dasharray",r=>he(r.look.style||tt.look.style,r.type.defaultLook.thickness||tt.look.thickness)).attr("fill","none"),i.select("path.diagram-connection-path-box").attr("d",r=>ne(r.look.shape||tt.look.shape,r.startCoords,r.endCoords,r.startDirection,r.endDirection,r.type.defaultLook.thickness||tt.look.thickness,r.type.defaultStartMarkerLook?.width,r.type.defaultEndMarkerLook?.width)).attr("stroke","transparent").attr("pointer-events","stroke").attr("stroke-width",r=>`${(r.look.thickness||tt.look.thickness)+ei}px`).attr("stroke-dasharray",r=>he(r.look.style||tt.look.style,r.type.defaultLook.thickness||tt.look.thickness)).attr("fill","none"),i.data().forEach(r=>{this.updateConnectionLabelsInView(r),this.updateConnectionMarkersInView(r)})}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 n=l.merge(e);a.remove(),l.style("box-sizing","border-box").on(C.MouseOver,(i,r)=>{this.dragging||(this.userHighlight.focusOn(r),this.diagramEvent$.next(new J(r)))}).on(C.Click,(i,r)=>{if(!i.ctrlKey&&!i.shiftKey){const c=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new j(c,!1))}const o=lt(r);this.userSelection.toggle(o),this.diagramEvent$.next(new j([o],o.selected))}).on(C.ContextMenu,(i,r)=>{if(this.dragging){i.preventDefault(),i.stopPropagation(),this.dragging=!1;return}const o=new ut(i,r);if(this.diagramEvent$.next(o),!o.defaultPrevented&&this.canUserPerformAction(w.ContextMenu)){i.preventDefault();const c=lt(r);this.userHighlight.focusOn(c),this.diagramEvent$.next(new J(c)),this.userSelection.add(c),this.diagramEvent$.next(new j([c],!0)),this.contextMenu.open(i)}}).on(C.DoubleClick,(i,r)=>{const o=new ft(i,r);this.diagramEvent$.next(o),!o.defaultPrevented&&this.canUserPerformAction(w.EditField)&&r.editable&&!r.removed&&(this.currentAction=new Le(this,r.id,r.text,""),this.createInputField(r.text,r.coords,r.width,r.height,r.fontSize,r.fontFamily||V.fontFamily,r.orientation,c=>{},c=>{r.text=c,this.currentAction instanceof Le&&(this.currentAction.to=c,this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0)}))}).call(A.drag().filter(i=>(this.secondaryButton=pt(i),!0)).on($.Start,(i,r)=>{if(this.multipleSelectionOn||this.secondaryButton)this.startMultipleSelection(i);else{let o;r.rootElement instanceof R?o=r.rootElement:r.rootElement instanceof F&&(o=r.rootElement.node),o?this.startMovingNode(i,o):S(L.NotAllowed)}}).on($.Drag,(i,r)=>{if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(i);else{let o;r.rootElement instanceof R?o=r.rootElement:r.rootElement instanceof F&&(o=r.rootElement.node),o?this.continueMovingNode(i,o):S(L.NotAllowed)}}).on($.End,(i,r)=>{if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(i);else{let o;r.rootElement instanceof R?o=r.rootElement:r.rootElement instanceof F&&(o=r.rootElement.node),o?this.finishMovingNode(i,o):S()}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"),n.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===It.Center?"center":i.horizontalAlign===It.Right?"flex-end":"flex-start").style("align-items",i=>i.verticalAlign===Yt.Center?"center":i.verticalAlign===Yt.Bottom?"end":"start").select("p").style("max-width",i=>i.fit?"default":`${Me(i.width,i.height,i.orientation)[0]}px`).style("max-height",i=>i.fit?"default":`${Me(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===It.Center?"center":i.horizontalAlign===It.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,"<").replace(/>/g,">").replace(/\n/g,"<br/>"))}updateObjectsInView(...t){let e=this.selectCanvasElements().selectAll("foreignObject.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("foreignObject").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(C.ContextMenu,(i,r)=>{if(this.dragging){i.preventDefault(),i.stopPropagation(),this.dragging=!1;return}const o=new ut(i,r);this.diagramEvent$.next(o),!o.defaultPrevented&&this.canUserPerformAction(w.ContextMenu)&&(i.preventDefault(),this.contextMenu.open(i))}).on(C.DoubleClick,(i,r)=>{const o=new ft(i,r);this.diagramEvent$.next(o)}).call(A.drag().filter(i=>(this.secondaryButton=pt(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("foreignObject.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("foreignObject").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(C.MouseOver,(i,r)=>{this.dragging||(this.userHighlight.focusOn(r),this.diagramEvent$.next(new J(r)))}).on(C.Click,(i,r)=>{if(!i.ctrlKey&&!i.shiftKey){const o=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new j(o,!1))}if(r.rootElement){const o=lt(r.rootElement);this.userSelection.toggle(o),this.diagramEvent$.next(new j([o],o.selected))}}).on(C.ContextMenu,(i,r)=>{if(this.dragging){i.preventDefault(),i.stopPropagation(),this.dragging=!1;return}const o=new ut(i,r);if(this.diagramEvent$.next(o),!o.defaultPrevented&&this.canUserPerformAction(w.ContextMenu)&&r.rootElement){i.preventDefault();const c=lt(r.rootElement);this.userHighlight.focusOn(c),this.diagramEvent$.next(new J(c)),this.userSelection.add(c),this.diagramEvent$.next(new j([c],!0)),this.contextMenu.open(i)}}).on(C.DoubleClick,(i,r)=>{const o=new ft(i,r);this.diagramEvent$.next(o)}).call(A.drag().filter(i=>(this.secondaryButton=pt(i),!0)).on($.Start,(i,r)=>{if(this.multipleSelectionOn||this.secondaryButton)this.startMultipleSelection(i);else{let o;r.rootElement instanceof R?o=r.rootElement:r.rootElement instanceof F&&(o=r.rootElement.node),o?this.startMovingNode(i,o):S(L.NotAllowed)}}).on($.Drag,(i,r)=>{if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(i);else{let o;r.rootElement instanceof R?o=r.rootElement:r.rootElement instanceof F&&(o=r.rootElement.node),o?this.continueMovingNode(i,o):S(L.NotAllowed)}}).on($.End,(i,r)=>{if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(i);else{let o;r.rootElement instanceof R?o=r.rootElement:r.rootElement instanceof F&&(o=r.rootElement.node),o?this.finishMovingNode(i,o):S()}this.secondaryButton=!1}))}updateConnectionLabelsInView(t){const e=this.selectCanvasView().select(`[id='${de(t.id)}']`),l=e.select("path").node(),n={...V,...t.type.label};if(l){const i=l.getTotalLength();let r=0,o=0,c=0,d=0,h=0,u=0;if(n.backgroundColor==="#00000000"){const p=t.endCoords[0]-t.startCoords[0],k=t.endCoords[1]-t.startCoords[1];switch(t.startDirection){case g.Top:r=p>=0?-.5:.5,h=r;break;case g.Bottom:r=p>=0?-.5:.5,h=r;break;case g.Left:o=k>0?-.5:.5,u=o;break;case g.Right:o=k>0?-.5:.5,u=o;break;default:r=.5,h=r,o=-.5,u=o}switch(t.endDirection){case g.Top:h=p>=0?.5:-.5;break;case g.Bottom:h=p>=0?.5:-.5;break;case g.Left:u=k>0?.5:-.5;break;case g.Right:u=k>0?.5:-.5;break;default:h=.5,u=-.5}Math.abs(p)>=Math.abs(k)?(c=p>0?-.5:.5,d=k>0?.5:-.5):(c=p>0?.5:-.5,d=k>0?-.5:.5)}e.select("g.diagram-connection-start-label text").attr("x",0).attr("y",n.fontSize/3).attr("text-anchor","middle").attr("font-family",n.fontFamily).attr("font-size",n.fontSize).attr("fill",t.selected?n.selectedColor:n.color).style("font-kerning","none").text(t.startLabel);const y=e.select("g.diagram-connection-start-label text").node()?.getBoundingClientRect();if(y){const p=t.startLabel?y.width/this.zoomTransform.k+zt(n)+Vt(n):0,k=t.startLabel?y.height/this.zoomTransform.k+Ot(n)+Rt(n):0;let b;switch(t.startDirection){case g.Left:b=l.getPointAtLength(et(n)+p/2);break;case g.Right:b=l.getPointAtLength(U(n)+p/2);break;case g.Top:b=l.getPointAtLength(Z(n)+p/2);break;case g.Bottom:b=l.getPointAtLength(G(n)+p/2);break;default:b=l.getPointAtLength(Math.max(U(n)+p/2,et(n)+p/2,G(n)+k/2,Z(n)+k/2))}e.select("g.diagram-connection-start-label path").attr("d",Bt(-p/2,-k/2,p,k)).attr("fill",n.backgroundColor).attr("stroke","none"),e.select("g.diagram-connection-start-label").attr("transform",`translate(${b.x+r*p},${b.y+o*k})`)}e.select("g.diagram-connection-middle-label text").attr("x",0).attr("y",n.fontSize/3).attr("text-anchor","middle").attr("font-family",n.fontFamily).attr("font-size",n.fontSize).attr("fill",t.selected?n.selectedColor:n.color).style("font-kerning","none").text(t.middleLabel);const v=e.select("g.diagram-connection-middle-label text").node()?.getBoundingClientRect();if(v){const p=t.middleLabel?v.width/this.zoomTransform.k+zt(n)+Vt(n):0,k=t.middleLabel?v.height/this.zoomTransform.k+Ot(n)+Rt(n):0,b=l.getPointAtLength(i/2);e.select("g.diagram-connection-middle-label path").attr("d",Bt(-p/2,-k/2,p,k)).attr("fill",n.backgroundColor).attr("stroke","none"),e.select("g.diagram-connection-middle-label").attr("transform",`translate(${b.x+c*p},${b.y+d*k})`)}e.select("g.diagram-connection-end-label text").attr("x",0).attr("y",n.fontSize/3).attr("text-anchor","middle").attr("font-family",n.fontFamily).attr("font-size",n.fontSize).attr("fill",t.selected?n.selectedColor:n.color).style("font-kerning","none").text(t.endLabel);const m=e.select("g.diagram-connection-end-label text").node()?.getBoundingClientRect();if(m){const p=t.endLabel?m.width/this.zoomTransform.k+zt(n)+Vt(n):0,k=t.endLabel?m.height/this.zoomTransform.k+Ot(n)+Rt(n):0;let b;switch(t.endDirection){case g.Left:b=l.getPointAtLength(i-(et(n)+p/2));break;case g.Right:b=l.getPointAtLength(i-(U(n)+p/2));break;case g.Top:b=l.getPointAtLength(i-(Z(n)+p/2));break;case g.Bottom:b=l.getPointAtLength(i-(G(n)+p/2));break;default:b=l.getPointAtLength(i-Math.max(U(n)+p/2,et(n)+p/2,G(n)+k/2,Z(n)+k/2))}e.select("g.diagram-connection-end-label path").attr("d",Bt(-p/2,-k/2,p,k)).attr("fill",n.backgroundColor).attr("stroke","none"),e.select("g.diagram-connection-end-label").attr("transform",`translate(${b.x+h*p},${b.y+u*k})`)}}}updateConnectionMarkersInView(t){const e=this.selectCanvasView().select(`[id='${de(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 R||e.rootElement instanceof F){const a=this.minimumSizeOfField(e),l=a[0]+U(e.rootElement.type?.label)+et(e.rootElement.type?.label)-e.rootElement.width,n=a[1]+G(e.rootElement.type?.label)+Z(e.rootElement.type?.label)-e.rootElement.height;return l<=0&&n<=0}return!0}fitFieldRootInView(t,e=!0){const a=this.model.fields.get(t);if(a){if(a.rootElement instanceof R){const l=this.minimumSizeOfField(a);let n=l[0]+U(a.rootElement.type.label)+et(a.rootElement.type.label)-a.rootElement.width,i=l[1]+G(a.rootElement.type.label)+Z(a.rootElement.type.label)-a.rootElement.height;this.snapToGrid&&(n=Math.ceil(n/this.gridSize)*this.gridSize,i=Math.ceil(i/this.gridSize)*this.gridSize),a.rootElement.width+n<a.rootElement.type.minWidth&&(n=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||n>0)&&a.rootElement.stretch(g.Right,n),(e!==!1||i>0)&&a.rootElement.stretch(g.Bottom,i)}if(a.rootElement instanceof F){const l=this.minimumSizeOfField(a);let n=l[0],i=l[1];for(const d of a.rootElement.node?.sections||[])d.label&&(d.indexXInNode===a.rootElement.indexXInNode&&d.indexYInNode!==a.rootElement.indexYInNode?n=Math.max(n,this.minimumSizeOfField(d.label)[0]):d.indexXInNode!==a.rootElement.indexXInNode&&d.indexYInNode===a.rootElement.indexYInNode&&(i=Math.max(i,this.minimumSizeOfField(d.label)[1])));l[0]<n&&(l[0]=n),l[1]<i&&(l[1]=i);const r=a.rootElement.type;let o=l[0]+U(r?.label)+et(r?.label)-a.rootElement.width,c=l[1]+G(r?.label)+Z(r?.label)-a.rootElement.height;this.snapToGrid&&(o=Math.ceil(o/this.gridSize)*this.gridSize,c=Math.ceil(c/this.gridSize)*this.gridSize),a.rootElement.width+o<(a.rootElement.getMinWidth()||0)&&(o=(a.rootElement.getMinWidth()||0)-a.rootElement.width),a.rootElement.height+c<(a.rootElement.getMinHeight()||0)&&(c=(a.rootElement.getMinHeight()||0)-a.rootElement.height),(e||o>0)&&a.rootElement.node?.stretchSections(g.Right,o,a.rootElement.indexXInNode,a.rootElement.indexYInNode),(e||c>0)&&a.rootElement.node?.stretchSections(g.Bottom,c,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,n=0;for(const i of a.sections)if(i.getPriority()>=this.priorityThreshold){const r=i.coords[0]+i.width-a.coords[0],o=i.coords[1]+i.height-a.coords[1];l=Math.max(l,r),n=Math.max(n,o)}l+=a.type.sectionGrid?.margin||0,n+=a.type.sectionGrid?.margin||0,(e||l>a.width)&&a.stretch(g.Right,l-a.width),(e||n>a.height)&&a.stretch(g.Bottom,n-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 at(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 at(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.length>0||t.outgoingConnections.length>0)){this.dropConnection();return}if(!this.allowSharingBothPorts&&this.model.connections.find(e=>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,n,i,r,o,c){this.removeInputField();const d=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=d;const h=d.append("xhtml:textarea");let u,y;h.text(t).style("box-sizing","border-box").style("width",`${a}px`).style("height",`${l}px`).style("font-size",`${n}px`).style("font-family",i).style("resize","none").style("outline",0).style("border",0).style("margin",0).style("padding",0).on(C.KeyDown,m=>{m.stopPropagation()}).on(C.KeyUp,m=>{if(m.stopPropagation(),m.key===W.Escape){const p=h.property("value");this.removeInputField(),c&&c(p)}}).on(C.Input,()=>{const m=h.property("value");h.attr("cols",uo(m)+1),h.attr("rows",po(m)+1),h.style("width",""),h.style("height",""),u=h.property("scrollWidth")+1,y=h.property("scrollHeight")+1;const p=Math.max(u,a),k=Math.max(y,l);d?.attr("width",`${p}px`),h.style("width",`${p}px`),d?.attr("height",`${k}px`),h.style("height",`${k}px`),o&&o(m)}).on(C.Click,m=>{m.stopPropagation()}).on(C.FocusOut,()=>{const m=h.property("value");this.removeInputField(),c&&c(m)});const v=h.node();v.focus(),v.select()}removeInputField(){this.inputFieldContainer?.select("input")?.on(C.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(w.MoveNode)&&!e.removed)if(S(L.Grabbing),this.draggingFrom=[t.x,t.y],e.selected&&this.userSelection.count(a=>a instanceof R)>1)this.currentAction=new ie(this,this.userSelection.filter(a=>a instanceof R).map(a=>a.id),e.coords);else{const a=e.getLastAncestor();this.currentAction=new B(this,w.MoveNode,e.id,e.getGeometry(),e.getGeometry(),a?.id,a?.getGeometry(e.id),a?.getGeometry(e.id))}else S(L.NotAllowed)}continueMovingNode(t,e){if(this.canUserPerformAction(w.MoveNode)&&(this.currentAction instanceof ie||this.currentAction instanceof B)&&!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(w.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 B){e.move(a);const n=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=je(n),r=i[i.length-1];if(r!==e.parent&&(e.type.canBeParentless||r!==void 0)){const o=r?.getLastAncestor(),c=this.currentAction.from,d=new Ho(this,e.id,e.parent?.id,r?.id,c,e.getGeometry(),o?.id,o?.getGeometry(e.id),o?.getGeometry(e.id));e.parent?.removeChild(e),r!==void 0&&r.addChild(e),d.toChildGeometry=e.getGeometry(e.id),d.toAncestorGeometry=o?.getGeometry(e.id),this.currentAction=d}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)}S(),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])&&(S(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)io([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 j(this.userSelection.all(),!0)),S()}};Wt.canvasCount=0;let ue=Wt;class We{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,n=l>0?1:-1,i=[e[0]+l,e[1]+l];for(let r=e[0];r!==i[0]+n;r+=n)if(e[0]=r,this.get(e)===void 0)return e;for(let r=e[1];r!==i[1]+n;r+=n)if(e[1]=r,this.get(e)===void 0)return e}}}class ii{constructor(t){this.gapSize=t}apply(t){if(t.nodes.length===0)return t;const e=new We,a=t.nodes.filter(r=>!r.parent);for(;a.length>0;)Ze(a[0],e,[0,0],a);const l=Math.max(...t.nodes.map(r=>r.width)),n=Math.max(...t.nodes.map(r=>r.height)),i=this.gapSize!==void 0?this.gapSize:(t.canvas?.gridSize||0)*2;for(let r=e.minY();r<=e.maxY();++r)for(let o=e.minX();o<=e.maxX();++o){const c=e.get([o,r]);c!==void 0&&c.move([o*(l+i),r*(n+i)])}return t}}const Ze=(s,t,e,a)=>{const l=t.getClosestEmptyCoordinate(e);t.set(l,s),D(a,s);for(const n of s.getAdjacentNodes())a.includes(n)&&Ze(n,t,l,a)};class si{constructor(t){this.gapSize=t}apply(t){if(t.nodes.length===0)return t;const e=new We,a=t.nodes.filter(d=>!d.parent),l={},n=a[0];let i=[n];for(l[n.id]=[0,0];a.length>0;){const d=[];for(const h of i){e.set(e.getClosestEmptyCoordinate(l[h.id]),h),D(a,h);const u=h.getAdjacentNodes();for(const y of u)a.includes(y)&&(d.push(y),l[y.id]=l[h.id])}if(d.length>0)i=d;else if(a.length>0){const h=a[0];i=[h],l[h.id]=e.getClosestEmptyCoordinate([0,0])}}const r=Math.max(...t.nodes.map(d=>d.width)),o=Math.max(...t.nodes.map(d=>d.height)),c=this.gapSize!==void 0?this.gapSize:(t.canvas?.gridSize||0)*2;for(let d=e.minY();d<=e.maxY();++d)for(let h=e.minX();h<=e.maxX();++h){const u=e.get([h,d]);u!==void 0&&u.move([h*(r+c),d*(o+c)])}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(r=>!r.parent);const l=a[0];D(a,l);const n=[[l]];for(;a.length>0;){const r=n[n.length-1],o=[];for(const c of r){const d=c.getAdjacentNodes();for(const h of d)a.includes(h)&&(D(a,h),o.push(h))}o.length>0?n.push(o):(n.push(a),a=[])}let i=0;for(const r of n){let o=0;for(const d of r)d.move([i,o]),o+=e+d.height;const c=Math.max(...r.map(d=>d.width));i+=e+c}for(const r of t.connections)r.tighten();return t}}class ni{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,n=.1,i=2e5,r=.5,o=1,c=.002;let d=100;for(;d>l;){d=d*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 y=u.getAdjacentNodes();for(const v of t.nodes){const m=[u.coords[0]+u.width/2,u.coords[1]+u.height/2],p=[v.coords[0]+v.width/2,v.coords[1]+v.height/2],k=Pe(u.coords,v.coords),b=[v.coords[0],v.coords[1]];if(y.includes(v)&&k>0&&(k>e+(Math.max(u.width,u.height)+Math.max(v.width,v.height))/2?(b[0]=b[0]-(p[0]-m[0])*n,b[1]=b[1]-(p[1]-m[1])*n):(b[0]=b[0]+(p[0]-m[0])*r,b[1]=b[1]+(p[1]-m[1])*r)),k>0){const N=i/(k*k);b[0]=b[0]+N*(p[0]-m[0])/k,b[1]=b[1]+N*(p[1]-m[1])/k}else b[0]=b[0]+o*(Math.random()*2-1),b[1]=b[1]+o*(Math.random()*2-1);b[0]=b[0]-(p[0]-h[0])*c,b[1]=b[1]-(p[1]-h[1])*c,b[0]-v.coords[0]>d?b[0]=v.coords[0]+d:b[0]-v.coords[0]<-d&&(b[0]=v.coords[0]-d),b[1]-v.coords[1]>d?b[1]=v.coords[1]+d:b[1]-v.coords[1]<-d&&(b[1]=v.coords[1]-d),v.move(b)}}}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 ri{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(n=>!n.parent);a.sort((n,i)=>i.type.priority-n.type.priority);let l=0;for(const n of a)n.move([l,0]),l+=n.width+e;return t}}class ai{constructor(t){this.gapSize=t}apply(t){if(t.nodes.length===0)return t;const e=Math.max(...t.nodes.map(d=>d.getPriority())),a=Math.min(...t.nodes.map(d=>d.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,n=t.nodes.filter(d=>!d.parent),i=[],r=t.nodes.filter(d=>!d.parent).filter(d=>d.getPriority()>=e),o=[];if(r.length>1){const d=r[0];r.splice(0,1),o.push(d);const h=[d],u=[d];for(;h.length>0;){const y=h[0];h.splice(0,1),r.includes(y)&&(o.push(y),D(r,y));const v=y.getAdjacentNodes();for(const m of v)u.includes(m)||(h.push(m),u.push(m))}for(const y of r)o.push(y)}else o.push(r[0]);for(const d of o)D(n,d),i.push([d]);for(i.push([]),n.sort((d,h)=>h.type.priority-d.type.priority);n.length>0;){const d=n[0];n.splice(0,1);const h=[d],u=[d];let y=!1;for(;h.length>0;){const v=h[0];h.splice(0,1);const m=o.indexOf(v);if(m>=0){i[m].push(d),y=!0;break}else{const p=v.getAdjacentNodes();for(const k of p)u.includes(k)||(h.push(k),u.push(k))}}y||i[i.length-1].push(d)}let c=0;for(let d=0;d<i.length;++d){let h=0;for(let y=0;y<i[d].length;++y){const v=i[d][y];v.move([c,h]),h+=l+v.height}const u=Math.max(...i[d].map(y=>y.width));c+=l+u}for(const d of t.connections)d.tighten();return t}}class li{constructor(t){this.gapSize=t}apply(t){if(t.nodes.length===0)return t;const e=Math.max(...t.nodes.map(d=>d.getPriority())),a=Math.min(...t.nodes.map(d=>d.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,n=t.nodes.filter(d=>!d.parent).sort((d,h)=>h.getPriority()-d.getPriority()),i=[];for(;n.length>0;){const d=n[0];n.splice(0,1);const h=new ye(void 0,d);Ke(h,n),i.push(h)}const r=[];for(const d of i)r.push([d]),qe(d,r,r.length);const o=Math.max(...t.nodes.map(d=>d.height));let c=0;for(let d=0;d<r.length;++d){let h=0;for(let y=0;y<r[d].length;++y){const v=r[d][y];v.node.move([c,h]),h+=(l+o)*v.countBranchHeight()}const u=Math.max(...r[d].map(y=>y.node.width));c+=l+u}for(const d of t.connections)d.tighten();return t}}const Ke=(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);Ke(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 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(n=>!n.parent);a.sort((n,i)=>i.type.priority-n.type.priority);let l=0;for(const n of a)n.move([0,l]),l+=n.height+e;return t}}const Te={adjacency:new ii,breadth:new ee,"breadth-adjacency":new si,force:new ni,horizontal:new ri,priority:new ai,tree:new li,vertical:new ci},di=E.createContext({}),St=E.createContext({});class hi{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:n,collapsedValue:i,visibleValue:r,onCollapse:o})=>{const[c,d]=E.useState(a),h=()=>{if(!l){const y=!c;d(y),o?.(y);let v;if(typeof t=="string")v=A.select(t),e&&(v=v.select(e));else{const m=t;if(!m)throw new Error("collapsableSelector is not a valid ref");v=A.select(m.current),e&&(v=v.select(e))}v.style(n,y?i:r)}},u=()=>{switch(s){case g.Right:return l?"daga-horizontal-none":c?"daga-horizontal-right":"daga-horizontal-left";case g.Bottom:return l?"daga-vertical-none":c?"daga-vertical-down":"daga-vertical-up";case g.Left:return l?"daga-horizontal-none":c?"daga-horizontal-left":"daga-horizontal-right";case g.Top:return l?"daga-vertical-none":c?"daga-vertical-up":"daga-vertical-down"}};return f.jsx("daga-collapse-button",{children:f.jsx("button",{className:`daga-collapse-button daga-${s}`,onClick:h,children:f.jsx("div",{className:u()})})})},gi=()=>{const s=E.useContext(St),t=E.useRef(null),[e,a]=E.useState([]);kt.merge(s.validatorChange$,s.diagramChange$).pipe(kt.map(()=>l())).subscribe();const l=()=>{a([]);for(const i of s.validators){const r=i.validate(s.model);a(r)}},n=i=>{if(i.elementId&&(i.propertyNames===void 0||i.propertyNames.length===0)){const r=s.model.nodes.get(i.elementId)||s.model.connections.get(i.elementId);r&&s.userHighlight.add(r)}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 r=s.model.nodes.get(i.elementId)||s.model.connections.get(i.elementId);r&&s.userHighlight.add(r),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 f.jsx("daga-errors",{children:f.jsxs("div",{ref:t,className:"daga-errors",children:[e.length===0&&f.jsx("div",{className:"daga-errors-summary daga-no-errors daga-prevent-user-select",children:f.jsx("span",{children:"No errors found"})}),e.length>0&&f.jsxs("div",{className:"daga-errors-summary daga-with-errors daga-prevent-user-select",children:[f.jsxs("span",{children:[e.length," errors found"]}),f.jsx("div",{className:"daga-collapse-button-container",children:f.jsx(be,{collapsableSelector:t,collapsableAdditionalSelector:".daga-error-panel",direction:g.Top,rule:"display",collapsedValue:"none",visibleValue:"block",collapsed:!1,disabled:!1})})]}),e.length>0&&f.jsx("div",{className:"daga-error-panel",children:f.jsx("ol",{children:e.map((i,r)=>f.jsx("li",{onClick:()=>n(i),dangerouslySetInnerHTML:{__html:i.message}},r))})})]})})},fi=200,Ne=s=>(s||"").toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g,""),Je=({disabled:s,options:t,value:e,onChange:a})=>{const l=E.useRef(null),[n,i]=E.useState("");let r;const[o,c]=E.useState([]),[d,h]=E.useState([]),[u,y]=E.useState([]),[v,m]=E.useState([]),[p,k]=E.useState(!1);E.useEffect(()=>{i(t.find(I=>wt(I.key,e))?.label||"")},[e,t]);const b=I=>{if(!s)switch(I.key){case W.PageDown:r===void 0?(P(0),M(0)):(P(r+5),M(r)),I.preventDefault();break;case W.ArrowDown:r===void 0?(P(0),M(0)):(P(r+1),M(r)),I.preventDefault();break;case W.PageUp:r===void 0?(P(t.length-1),M(t.length-1)):(P(r-5),M(r)),I.preventDefault();break;case W.ArrowUp:r===void 0?(P(t.length-1),M(t.length-1)):(P(r-1),M(r)),I.preventDefault();break;case W.Escape:z(),I.preventDefault();break;case W.Enter:O(t[r||0]),I.preventDefault();break;default:N()}},N=()=>{if(!s){const I=Ne(n.trim());c([]),h([]),y([]),m([]);for(const H of t){const K=Ne(H.label).indexOf(I);if(K>=0){const jt=H.label.substring(0,K),q=H.label.substring(K,K+I.length),bt=H.label.substring(K+I.length);c(st=>[...st,H]),h(st=>[...st,jt]),y(st=>[...st,q]),m(st=>[...st,bt])}}k(!0)}},z=()=>{k(!1)},P=I=>{if(!s){if(r=I,I===void 0)return;I<0&&(r=0),I>=t.length&&(r=t.length-1)}},Q=()=>{setTimeout(()=>{z()},fi)},M=I=>{const H=l.current?.querySelectorAll("li")[I];H&&H.scrollIntoView({block:"center"})},x=()=>{s||(i(""),k(!1),r=void 0)},O=I=>{s||(i(I.label),k(!1),r=void 0,a(I.key))};return f.jsxs("div",{ref:l,className:`daga-autocomplete ${p?"daga-showing-options":""}`,children:[f.jsxs("div",{className:"daga-autocomplete-input",children:[f.jsx("input",{value:n,disabled:s,onKeyUp:b,onFocus:N,onBlur:Q,onChange:I=>i(I.target.value)}),n!==""&&f.jsx("button",{className:"daga-clear",onClick:x})]}),f.jsx("div",{className:"daga-autocomplete-options",children:f.jsxs("ul",{className:"daga-autocomplete-option-list",children:[o.length===0&&f.jsx("li",{className:"daga-autocomplete-option no-options",children:"(No options)"}),o.map((I,H)=>f.jsxs("li",{className:`daga-autocomplete-option ${H===r?"daga-focused":""}`,onMouseMove:()=>P(H),onClick:()=>O(I),children:[f.jsx("span",{children:d[H]}),f.jsx("span",{className:"daga-match",children:u[H]}),f.jsx("span",{children:v[H]})]},H))]})})]})},ui=(s,t)=>s.find(e=>e.key===t)?.label||`${t}`,pi=({disabled:s,allowRepeats:t,options:e,value:a,onChange:l})=>{const[n,i]=E.useState(),[r,o]=E.useState([]),[c,d]=E.useState([]);E.useEffect(()=>{const p=a.length===0,k=a.map(b=>ui(e,b));o(k),p&&l(a),m()},[a,e]);const h=p=>{for(const k of a)if(k===p)return!0;return!1},u=p=>{a.length>p&&(a.splice(p,1),o(r.filter((k,b)=>b!==p)),l(a),m())},y=()=>{n!==void 0&&(t||!h(n))&&(l(a.concat(n)),v())},v=()=>{i("")},m=()=>{if(!t){const p=[];for(const k of e)h(k.key)||p.push(k);d(p)}};return f.jsxs("div",{children:[a.map((p,k)=>f.jsxs("div",{className:"daga-value-item-element",children:[f.jsx("span",{className:"daga-input",children:r[k]}),!s&&f.jsx("button",{className:"daga-property-button",onClick:()=>u(k),children:f.jsx("div",{className:"daga-icon daga-close-icon"})})]},k)),!s&&f.jsxs("div",{className:"daga-value-item-input",children:[f.jsx("div",{className:"daga-input daga-relatively-positioned",children:f.jsx(Je,{disabled:s,options:t?e||[]:c||[],value:n,onChange:i})}),f.jsx("button",{className:"daga-property-button",onClick:y,children:f.jsx("div",{className:"daga-icon daga-add-icon"})})]})]})},mi=({disabled:s,allowRepeats:t,value:e,onChange:a})=>{const[l,n]=E.useState(""),i=u=>{for(const y of u||[])if(y===u)return!0;return!1},r=u=>{e.length>u&&a(e.filter((y,v)=>v!==u))},o=(u,y,v)=>{const m=e.map((p,k)=>k===y?v==="blur"?u.trim():u:p);a(m)},c=()=>{const u=l.trim();u!==""&&(t||!i(u))&&(a(e.concat(u)),d())},d=()=>{n("")},h=u=>{u.key==="Enter"&&c()};return f.jsxs(f.Fragment,{children:[e.map((u,y)=>f.jsxs("div",{className:"daga-value-item-element",children:[f.jsx("input",{className:"daga-input",disabled:s,value:u,onChange:v=>o(v.target.value,y,"change"),onBlur:v=>o(v.target.value,y,"blur")}),f.jsx("button",{className:"daga-property-button",onClick:()=>r(y),children:f.jsx("div",{className:"daga-icon daga-close-icon"})})]},y)),!s&&f.jsxs("div",{className:"daga-value-item-input",children:[f.jsxs("div",{className:"daga-input daga-relatively-positioned",children:[f.jsx("input",{type:"text",onKeyUp:h,value:l,onChange:u=>n(u.target.value)}),f.jsx("button",{className:"daga-clear",onClick:d})]}),f.jsx("button",{className:"daga-property-button",onClick:c,children:f.jsx("div",{className:"daga-icon daga-add-icon"})})]})]})},vi=({disabled:s,value:t,onChange:e})=>{const[a,l]=E.useState(""),[n,i]=E.useState(""),[r,o]=E.useState({}),c=p=>{const k={};Object.keys(t).forEach(b=>{b!==p&&(k[b]=t[b])}),e(k)},d=(p,k,b)=>{const N=b==="blur"?k.trim():k;if(b==="blur"){if(p!==N){const z={};Object.keys(t).forEach(P=>{P===p?z[N]=t[P]:z[P]=t[P]}),e(z),o(P=>{const Q={...P};return delete Q[p],Q})}}else o(z=>({...z,[p]:k}))},h=(p,k,b)=>{const N=b==="blur"?k.trim():k;if(N!==""){const z={};Object.keys(t).forEach(P=>{P===p?z[P]=N:z[P]=t[P]}),e(z)}},u=()=>{const p=a.trim(),k=n.trim();if(p!==""&&k!==""){const b={};Object.keys(t).forEach(N=>{b[N]=t[N]}),b[p]=k,e(b),l(""),i("")}},y=()=>{l("")},v=()=>{i("")},m=p=>{p.key==="Enter"&&u()};return f.jsxs("div",{children:[Object.entries(t).map(([p,k],b)=>f.jsxs("div",{className:"daga-value-item-element",children:[f.jsx("input",{id:`key-${b}`,className:"daga-input",type:"text",disabled:s,value:r[p]??p,onChange:N=>d(p,N.target.value,"change"),onBlur:N=>d(p,N.target.value,"blur")}),f.jsx("input",{id:`value-${b}`,className:"daga-input",type:"text",disabled:s,value:k,onChange:N=>h(p,N.target.value,"change"),onBlur:N=>h(p,N.target.value,"blur")}),f.jsx("button",{className:"daga-property-button",onClick:()=>c(p),children:f.jsx("div",{className:"daga-icon daga-close-icon"})})]},p)),!s&&f.jsxs("div",{className:"daga-value-item-input",children:[f.jsxs("div",{className:"daga-input daga-relatively-positioned",children:[f.jsx("input",{type:"text",value:a,onKeyUp:m,onChange:p=>l(p.target.value),onBlur:p=>d(a,p.target.value,"blur")}),f.jsx("button",{className:"daga-clear",onClick:y})]}),f.jsxs("div",{className:"daga-input daga-relatively-positioned",children:[f.jsx("input",{type:"text",value:n,onKeyUp:m,onChange:p=>i(p.target.value),onBlur:p=>h(a,p.target.value,"blur")}),f.jsx("button",{className:"daga-clear",onClick:v})]}),f.jsx("button",{className:"daga-property-button",onClick:u,children:f.jsx("div",{className:"daga-icon daga-add-icon"})})]})]})},Qe=({valueSet:s,onValueChange:t,depth:e})=>{const l=E.useContext(St).canUserPerformAction(w.UpdateValues)&&s?.rootElement?.removed!==!0,n=o=>"daga-property-name-"+o.replace(/\s/g,""),i=o=>{if(typeof o=="string")return o;if(o==null||isNaN(o.valueOf()))return"";const c=new Date(o),d=c.getTimezoneOffset();return c.setMinutes(c.getMinutes()-d),c.toISOString().substring(0,19)},r=o=>new Date(o);return f.jsx("daga-object-editor",{children:s.displayedProperties.map(o=>f.jsxs("div",{className:`daga-property ${n(o.name)}`,children:[f.jsx("p",{className:"daga-property-name",children:o.label||o.name}),o.type===T.Text&&f.jsx("input",{type:"daga-text",disabled:o.editable===!1||!l,value:s?.getValue(o.name),onChange:c=>t(s,o,c.target.value)}),o.type===T.TextArea&&f.jsx("textarea",{disabled:o.editable===!1||!l,value:s?.getValue(o.name),onChange:c=>t(s,o,c.target.value)}),o.type===T.Number&&f.jsx("input",{type:"number",disabled:o.editable===!1||!l,value:s?.getValue(o.name),onChange:c=>t(s,o,c.target.value)}),o.type===T.Color&&f.jsx("input",{type:"text",pattern:"#[0-9a-fA-F]{6}",disabled:o.editable===!1||!l,value:s?.getValue(o.name),onChange:c=>t(s,o,c.target.value)}),o.type===T.Datetime&&f.jsx("input",{type:"datetime-local",disabled:o.editable===!1||!l,value:i(s?.getValue(o.name)),onChange:c=>t(s,o,r(c.target.value))}),o.type===T.Date&&f.jsx("input",{type:"date",disabled:o.editable===!1||!l,value:s?.getValue(o.name),onChange:c=>t(s,o,c.target.value)}),o.type===T.Time&&f.jsx("input",{type:"time",disabled:o.editable===!1||!l,value:s?.getValue(o.name),onChange:c=>t(s,o,c.target.value)}),o.type===T.Url&&f.jsx("input",{type:"url",disabled:o.editable===!1||!l,value:s?.getValue(o.name),onChange:c=>t(s,o,c.target.value)}),o.type===T.Boolean&&f.jsxs("div",{className:"daga-radio",children:[f.jsxs("label",{className:"daga-radio-item daga-radio-start"+(s?.getValue(o.name)===!1?" daga-checked":""),children:[f.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"]}),f.jsxs("label",{className:"daga-radio-item daga-radio-end"+(s?.getValue(o.name)===!0?" daga-checked":""),children:[f.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===T.Option&&f.jsx("div",{className:"daga-relatively-positioned",children:f.jsx(Je,{disabled:o.editable===!1||!l,options:o.options||[],value:s?.getValue(o.name),onChange:c=>t(s,o,c)})}),(o.type===T.OptionList||o.type===T.OptionSet)&&f.jsx(pi,{disabled:o.editable===!1||!l,allowRepeats:o.type===T.OptionList,options:o.options||[],value:s?.getValue(o.name),onChange:c=>t(s,o,c)}),(o.type===T.TextList||o.type===T.TextSet)&&f.jsx(mi,{disabled:o.editable===!1||!l,allowRepeats:o.type===T.TextList,value:s?.getValue(o.name),onChange:c=>t(s,o,c)}),o.type===T.TextMap&&f.jsx(vi,{disabled:o.editable===!1||!l,value:s?.getValue(o.name),onChange:c=>t(s,o,c)}),o.type===T.Object&&f.jsx("div",{className:"daga-left-bar",children:f.jsx(Qe,{valueSet:s.getSubValueSet(o.name),onValueChange:t,depth:e+1})})]},o.name))})},to=({valueSet:s,depth:t})=>{const e=E.useContext(St),a=E.useRef(null),l=o=>"daga-property-name-"+o.replace(/\s/g,""),n=()=>{for(const o of s?.displayedProperties||[]){let c=0,d=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,y=>{S(L.Grabbing);const v=e.getPointerLocationRelativeToScreen(y);if(v.length<2||isNaN(v[0])||isNaN(v[1]))return;const m=u.node()?.getBoundingClientRect();c=m?.width||0,d=m?.height||0,u.style("position","fixed").style("left",`${v[0]-c/2}px`).style("top",`${v[1]-d/2}px`).style("width",`${c}px`).style("height",`${d}px`).style("z-index",1)}).on($.Drag,y=>{S(L.Grabbing);const v=e.getPointerLocationRelativeToScreen(y);v.length<2||isNaN(v[0])||isNaN(v[1])||(u.style("position","fixed").style("left",`${v[0]-c/2}px`).style("top",`${v[1]-d/2}px`).style("width",`${c}px`).style("height",`${d}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(v),A.select(a.current).select(`.daga-dropbar.daga-index-${h}.daga-depth-${t}`).style("visibility","visible").style("height","0.25rem"))}).on($.End,y=>{S(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 v=e.getPointerLocationRelativeToScreen(y);v.length<2||isNaN(v[0])||isNaN(v[1])||(h=i(v),s?.displayedProperties?.splice(s.displayedProperties.indexOf(o),1),s?.displayedProperties?.splice(h,0,o))}))}},i=o=>{const c=s?.propertySet.propertyList||[],d=[];for(let h=0;h<=c.length;++h){const u=A.select(a.current).select(`.daga-dropbar.daga-index-${h}.daga-depth-${t}`).node()?.getBoundingClientRect();u&&d.push([u.x+u.width/2,u.y+u.height/2])}if(d.length>0){const h=d.map(y=>((o[0]-y[0])**2+(o[1]-y[1])**2)**.5);return h.indexOf(Math.min(...h))}return 0},r=o=>{if(s===void 0)return;let c;o instanceof ko?c=o:o instanceof Event?c=s?.propertySet.getProperty(o.target?.value||""):c=s?.propertySet.getProperty(o||""),c&&s?.hideProperty(c),n()};return f.jsxs("daga-property-settings",{ref:a,children:[f.jsx("div",{className:`daga-dropbar daga-index-0 daga-depth-${t}`}),s?.displayedProperties.map((o,c)=>f.jsxs("div",{className:`daga-property-and-dropbar ${l(o.name)} daga-depth-${t}`,children:[f.jsxs("div",{className:`daga-property ${l(o.name)} daga-depth-${t}`,children:[f.jsxs("div",{className:"daga-property-name",children:[f.jsx("span",{children:o.label||o.name}),f.jsxs("div",{className:"daga-buttons",children:[f.jsx("button",{className:"daga-property-button daga-move-button",children:f.jsx("div",{className:"daga-icon daga-move-icon"})}),f.jsx("button",{className:"daga-property-button daga-hide-button",onClick:()=>r(o.name),children:f.jsx("div",{className:"daga-icon daga-hide-icon"})})]})]}),o.type!==T.Object&&f.jsx("div",{className:"daga-property-value",children:yi(s?.getValue(o.name))}),o.type===T.Object&&f.jsx(to,{valueSet:s?.getSubValueSet(o.name),depth:t+1})]}),f.jsx("div",{className:`daga-dropbar daga-index-${c+1} daga-depth-${t}`})]},o.name))]})},yi=s=>Array.isArray(s)?s.join(", "):wo(s)?Object.entries(s).map(t=>t.map(e=>JSON.stringify(e)).join(": ")).join(", "):s instanceof Date?s.toLocaleString():s==null?"":""+s,bi=({location:s,direction:t,width:e,height:a,title:l,valueSet:n,onValueChange:i})=>{const r=E.useRef(null),[o,c]=E.useState(!1),[d,h]=E.useState(!1),u=()=>A.select(r.current);return E.useEffect(()=>{if(r.current)switch(t){case g.Bottom:case g.Top:u().style("width",e),a&&u().select(".daga-panel-content").style("height",a);break;case g.Left:case g.Right:u().style("height",e),a&&u().select(".daga-panel-content").style("width",a);break}},[e,t]),f.jsx("daga-property-editor",{children:f.jsxs("div",{ref:r,className:`daga-panel daga-bottom daga-${s} daga-${t}`,children:[f.jsx(be,{disabled:!n||!n.propertySet||!n.propertySet.hasProperties(),collapsed:o,direction:t,collapsableSelector:r,collapsableAdditionalSelector:".daga-panel-content",rule:"display",collapsedValue:"none",visibleValue:"block",onCollapse:c}),f.jsx("div",{className:"daga-panel-content",children:n&&n.propertySet&&n.propertySet.hasProperties()&&!o&&f.jsxs("div",{children:[l&&f.jsxs("p",{className:"daga-title",children:[l,f.jsx("button",{className:"daga-property-button",onClick:()=>h(!d),children:f.jsx("div",{className:`daga-icon daga-settings-icon ${d?"daga-unrotate":"daga-rotate"}`})})]}),!d&&f.jsx(Qe,{valueSet:n,onValueChange:i,depth:0}),d&&f.jsx(to,{valueSet:n,depth:0})]})})]})})},ki=6,wi=s=>{const t=E.useContext(St),[e,a]=E.useState(s.currentPalette||s.palettes[0]),[l,n]=E.useState(0),[i,r]=E.useState(void 0),o=E.useRef(null),c=m=>{if(a(m),d().selectAll("*").remove(),n(t.getPriorityThreshold()||0),m.categories&&h(m.categories),m.templates)for(const p of m.templates)u(p)},d=()=>A.select(o.current).select(".daga-palette-view"),h=m=>{const p=d().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");p.append("option").attr("value","").text("(None selected)");for(const k in m)p.append("option").attr("value",k).text(k);p.on(C.Change,()=>{i&&d().selectAll(".daga-template-container.daga-in-category").remove();const k=p.property("value");r(k);const b=m[k]||[];for(const N of b)u(N,"daga-in-category")}),i&&(p.property("value",i),p.dispatch(C.Change))},u=(m,p)=>{if(m.templateType==="node"){const k=t.model.nodes.types.get(m.type);k?y(k,m,p):console.error(`Could not find a node type called '${m.type}'`)}else if(m.templateType==="connection"){const k=t.model.connections.types.get(m.type);k?v(k,m,p):console.error(`Could not find a connection type called '${m.type}'`)}},y=(m,p,k)=>{if(l!==void 0&&m.priority<l)return;const b=m.defaultLook.lookType==="shaped-look"?m.defaultLook.borderThickness||1:0,N=m.defaultHeight+b,z=m.defaultWidth+b,P=p.height||N,Q=p.width||z,M=d().append("div").attr("class",`daga-template-container ${k!==void 0?k:""}`).style("width",`${Q}px`).style("height",`${P}px`).call(A.drag().on($.Drag,O=>{if(t.canUserPerformAction(w.AddNode)){const I=t.getPointerLocationRelativeToScreen(O);if(I.length<2||isNaN(I[0])||isNaN(I[1]))return;M.style("position","fixed").style("left",`${I[0]-Q/2}px`).style("top",`${I[1]-P/2}px`).style("z-index",1)}}).on($.Start,O=>{if(t.canUserPerformAction(w.AddNode)){S(L.Grabbing);const I=t.getPointerLocationRelativeToScreen(O);if(I.length<2||isNaN(I[0])||isNaN(I[1]))return;M.style("position","fixed").style("left",`${I[0]-Q/2}px`).style("top",`${I[1]-P/2}px`).style("z-index",1),m.isUnique&&t.model.nodes.find(H=>!H.removed&&H.type.id===m.id)!==void 0&&S(L.NotAllowed)}}).on($.End,O=>{if(t.canUserPerformAction(w.AddNode)){if(S(L.Auto),M.style("position","relative").style("left",0).style("top",0).style("z-index","auto"),m.isUnique&&t.model.nodes.find(Ft=>!Ft.removed&&Ft.type.id===m.id)!==void 0)return;const I=t.getPointerLocationRelativeToScreen(O);if(I.length<2||isNaN(I[0])||isNaN(I[1]))return;const H=document.elementFromPoint(I[0],I[1]);if(H&&!t.selectCanvasView().node()?.contains(H))return;const rt=t.getPointerLocationRelativeToCanvas(O);if(rt.length<2||isNaN(rt[0])||isNaN(rt[1]))return;let K=[rt[0]-m.defaultWidth/2,rt[1]-m.defaultHeight/2];t.snapToGrid&&(K=t.getClosestGridPoint([K[0]-m.snapToGridOffset[0],K[1]-m.snapToGridOffset[1]]),K[0]+=m.snapToGridOffset[0],K[1]+=m.snapToGridOffset[1]);const q=t.model.nodes.getAtCoordinates(rt[0],rt[1]).filter(Ft=>Ft.type.childrenTypes.includes(m.id)),bt=je(q),st=bt[bt.length-1];if(!m.canBeParentless&&st===void 0)return;const Gt=st?.getLastAncestor(),ke=new _o(t,m,K,st?.id,Gt?.id,Gt?.getGeometry(),void 0,p.label,p.values);ke.do(),t?.actionStack.add(ke),S()}})).append("svg").attr("class",`palette-node ${m.id}`).attr("viewBox",`0 0 ${z} ${N}`).attr("preserveAspectRatio","none").style("position","relative").style("left",0).style("top",0).style("width",`${Q}px`).style("height",`${P}px`),x=p.look||m.defaultLook;switch(x.lookType){case"shaped-look":M.append("path").attr("d",ge(x.shape||Et.Rectangle,(x.borderThickness||1)/2,(x.borderThickness||1)/2,m.defaultWidth,m.defaultHeight)).attr("fill",x.fillColor||"#FFFFFF").attr("stroke",x.borderColor||"#000000").attr("stroke-width",`${x.borderThickness}px`);break;case"image-look":M.append("image").attr("x",0).attr("y",0).attr("width",m.defaultWidth).attr("height",m.defaultHeight).attr("href",x.backgroundImage).attr("preserveAspectRatio","none");break;case"stretchable-image-look":M.append("image").attr("x",0).attr("y",0).attr("width",x.leftMargin).attr("height",x.topMargin).attr("href",x.backgroundImageTopLeft).attr("preserveAspectRatio","none"),M.append("image").attr("x",x.leftMargin).attr("y",0).attr("width",m.defaultWidth-x.rightMargin-x.leftMargin).attr("height",x.topMargin).attr("href",x.backgroundImageTop).attr("preserveAspectRatio","none"),M.append("image").attr("x",m.defaultWidth-x.rightMargin).attr("y",0).attr("width",x.rightMargin).attr("height",x.topMargin).attr("href",x.backgroundImageTopRight).attr("preserveAspectRatio","none"),M.append("image").attr("x",0).attr("y",x.topMargin).attr("width",x.leftMargin).attr("height",m.defaultHeight-x.bottomMargin-x.topMargin).attr("href",x.backgroundImageLeft).attr("preserveAspectRatio","none"),M.append("image").attr("x",x.leftMargin).attr("y",x.topMargin).attr("width",m.defaultWidth-x.rightMargin-x.leftMargin).attr("height",m.defaultHeight-x.bottomMargin-x.topMargin).attr("href",x.backgroundImageCenter).attr("preserveAspectRatio","none"),M.append("image").attr("x",m.defaultWidth-x.rightMargin).attr("y",x.topMargin).attr("width",x.rightMargin).attr("height",m.defaultHeight-x.bottomMargin-x.topMargin).attr("href",x.backgroundImageRight).attr("preserveAspectRatio","none"),M.append("image").attr("x",0).attr("y",m.defaultHeight-x.bottomMargin).attr("width",x.leftMargin).attr("height",x.bottomMargin).attr("href",x.backgroundImageBottomLeft).attr("preserveAspectRatio","none"),M.append("image").attr("x",x.leftMargin).attr("y",m.defaultHeight-x.bottomMargin).attr("width",m.defaultWidth-x.rightMargin-x.leftMargin).attr("height",x.bottomMargin).attr("href",x.backgroundImageBottom).attr("preserveAspectRatio","none"),M.append("image").attr("x",m.defaultWidth-x.rightMargin).attr("y",m.defaultHeight-x.bottomMargin).attr("width",x.rightMargin).attr("height",x.bottomMargin).attr("href",x.backgroundImageBottomRight).attr("preserveAspectRatio","none")}if(p.look===void 0){if(m.decorators)for(const O of m.decorators)M.append("foreignObject").attr("width",`${O.width}px`).attr("height",`${O.height}px`).attr("transform",`translate(${O.coords[0]},${O.coords[1]})`).html(O.html);if(p.label){const O={...V,...m.label,...p.labelLook};M.append("text").attr("transform",`translate(${(U(O)+m.defaultWidth)/2},${(G(O)+m.defaultHeight)/2})`).attr("x",0).attr("y",0).attr("font-size",`${O.fontSize}px`).attr("text-anchor","middle").attr("font-family",O.fontFamily).attr("font-weight",400).attr("fill",O.color).attr("stroke","none").style("font-kerning","none").style("user-select","none").text(p.label)}}},v=(m,p,k)=>{const b=d().append("div").attr("class",`daga-template-container ${k!==void 0?k:""}`).style("width",`${p.width}px`).style("height",`${p.height}px`).append("svg").attr("class",`palette-button ${m.id}`).style("position","relative").style("left",0).style("top",0).style("width","100%").style("height","100%").on("click",()=>{t.connectionType=m});b.append("path").attr("d",ge(Et.Rectangle,0,0,p.width,p.height)).attr("fill",p.backgroundColor).attr("stroke","black").attr("stroke-width","1px"),p.icon!==""&&b.append("image").attr("x",0).attr("y",0).attr("width",p.width).attr("height",p.height).attr("href",p.icon),p.label!==""&&b.append("text").attr("transform",`translate(${p.width/2},${p.height/2+ki})`).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(p.label)};return E.useEffect(()=>{if(c(s.palettes[0]),o.current)switch(s.direction){case g.Bottom:case g.Top:o.current.style.width=s.width,s.height&&(o.current.style.height=s.height);break;case g.Left:case g.Right:o.current.style.height=s.width,s.height&&(o.current.style.width=s.height);break}},[e,s.palettes]),f.jsx("daga-palette",{children:f.jsxs("div",{ref:o,className:`daga-panel daga-${s.location} daga-${s.direction}`,children:[f.jsx(be,{direction:s.direction,collapsableSelector:o,collapsableAdditionalSelector:".daga-panel-content",rule:"display",collapsedValue:"none",visibleValue:"block",collapsed:!1,disabled:!1}),f.jsxs("div",{className:"daga-panel-content",children:[s.palettes.length>1&&f.jsx("div",{className:"daga-panel-tabs",children:s.palettes.map(m=>f.jsx("div",{className:`daga-panel-tab ${m===e?"daga-current-tab":""}`,onClick:()=>c(m),children:m.name}))}),f.jsx("div",{className:"daga-palette-view"})]})]})})},Si=({location:s,direction:t,enableAction:e,enableFilter:a,enableLayout:l,enableSelection:n,enableZoom:i})=>{let r=!1,o=!0,c=!1,d,h,u,y;switch(t){case g.Bottom:d="height",h="scaleY",u="top",y="bottom";break;case g.Top:d="height",h="scaleY",u="bottom",y="top";break;case g.Left:d="width",h="scaleX",u="right",y="left";break;case g.Right:d="width",h="scaleX",u="left",y="right";break}const v=E.useRef(null),m=E.useRef(null),p=E.useRef(null);E.useEffect(()=>{A.select(v.current).style(`margin-${y}`,"-1rem").style(d,"0rem").style("transform",`${h}(0)`).style("transform-origin",u)});const k=async()=>{const q=A.select(v.current);if(!c)if(o){o=!1;const Gt=`${4*q.selectChildren().size()}rem`;q.transition().duration(500).ease(A.easeLinear).style(d,Gt).style("transform",`${h}(1)`),setTimeout(()=>{c=!1},500)}else o=!0,q.transition().duration(500).ease(A.easeLinear).style(d,"0rem").style("transform",`${h}(0)`),setTimeout(()=>{c=!1},500)},b=E.useContext(St),N=()=>{b.zoomBy(b.zoomFactor)},z=()=>{b.zoomBy(1/b.zoomFactor)},P=()=>{b.center()},Q=()=>{b.layoutFormat&&b.layoutFormat in Te&&Te[b.layoutFormat].apply(b.model)},M=()=>{r=!r,A.select(p.current).classed("daga-on",r).classed("daga-off",!r);const q=b.getPriorityThresholdOptions();q&&q.length>=2&&b.setPriorityThreshold(q[r?1:0])},x=()=>{b.actionStack.undo()},O=()=>{b.actionStack.redo()},I=()=>{b.userSelection.copyToClipboard()},H=()=>{b.userSelection.cutToClipboard()},rt=()=>{b.userSelection.pasteFromClipboard()},K=()=>{b.userSelection.removeFromModel()},jt=()=>{b.multipleSelectionOn=!0,A.select(m.current).classed("daga-on",!0).classed("daga-off",!1);const q=b.diagramEvent$.subscribe(bt=>{bt.type===De.Selection&&(A.select(m.current).classed("daga-on",!1).classed("daga-off",!0),q.unsubscribe())})};return f.jsx("daga-diagram-buttons",{children:f.jsxs("div",{className:`daga-diagram-buttons daga-${s} daga-${t}`,children:[i&&b.canUserPerformAction(w.Zoom)&&f.jsx("button",{className:"daga-zoom-in",onClick:N,children:f.jsx("span",{className:"daga-tooltip",children:"Zoom in"})}),i&&b.canUserPerformAction(w.Zoom)&&f.jsx("button",{className:"daga-zoom-out",onClick:z,children:f.jsx("span",{className:"daga-tooltip",children:"Zoom out"})}),f.jsxs("div",{className:"daga-collapsable-buttons daga-collapsed",ref:v,children:[i&&b.canUserPerformAction(w.Zoom)&&f.jsx("button",{className:"daga-center",onClick:P,children:f.jsx("span",{className:"daga-tooltip",children:"Fit diagram to screen"})}),e&&f.jsx("button",{className:"daga-undo",onClick:x,children:f.jsx("span",{className:"daga-tooltip",children:"Undo"})}),e&&f.jsx("button",{className:"daga-redo",onClick:O,children:f.jsx("span",{className:"daga-tooltip",children:"Redo"})}),n&&f.jsx("button",{className:"daga-copy",onClick:I,children:f.jsx("span",{className:"daga-tooltip",children:"Copy"})}),n&&f.jsx("button",{className:"daga-cut",onClick:H,children:f.jsx("span",{className:"daga-tooltip",children:"Cut"})}),n&&f.jsx("button",{className:`daga-multiple-selection ${r?"daga-on":"daga-off"}`,onClick:jt,ref:m,children:f.jsx("span",{className:"daga-tooltip",children:"Multiple selection"})}),n&&f.jsx("button",{className:"daga-paste",onClick:rt,children:f.jsx("span",{className:"daga-tooltip",children:"Paste"})}),n&&f.jsx("button",{className:"daga-delete",onClick:K,children:f.jsx("span",{className:"daga-tooltip",children:"Delete"})}),l&&b.layoutFormat&&f.jsx("button",{className:"daga-layout",onClick:Q,children:f.jsx("span",{className:"daga-tooltip",children:"Apply layout"})}),a&&f.jsx("button",{className:`daga-filter ${r?"daga-on":"daga-off"}`,onClick:M,ref:p,children:f.jsx("span",{className:"daga-tooltip",children:"Apply filter"})})]}),f.jsx("button",{className:"daga-more-options",onClick:k,children:o?f.jsx("span",{className:"daga-tooltip",children:"More options"}):f.jsx("span",{className:"daga-tooltip",children:"Less options"})})]})})},xi=({config:s,model:t,onCanvasCreated:e,onDiagramEvent:a,onModelChange:l})=>{const n=new Ue,i=new Xe,r=E.useRef(null),o=E.useRef(void 0),c=E.useRef(!1),d=[],[h,u]=E.useState(void 0),[y,v]=E.useState(void 0),m={zoomIn:()=>{},zoomOut:()=>{},center:()=>{},layout:()=>{},filter:()=>{},undo:()=>{},redo:()=>{}},p={refreshPalette:()=>{}},k=new hi(M=>u(M),M=>v(M)),b={diagramButtons:m,palette:p,propertyEditor:k},N=(M=!1)=>((!o.current||M)&&(d.forEach(x=>x.unsubscribe()),o.current=new ue(b,s)),o.current),z=N(),P=M=>{z.initView(M),d.push(z.diagramEvent$.subscribe(x=>{a?.(x)})),d.push(z.diagramChange$.subscribe(()=>{const x=i.export(z.model);l?.(x)}))};E.useEffect(()=>{r.current&&(c.current||(P(r.current),c.current=!0,e?.(z)))},[r.current]),E.useMemo(()=>{r.current&&(N(!0),P(r.current),e?.(z))},[s]),E.useEffect(()=>{t&&n.import(z.model,t)},[t]);const Q=(M,x,O)=>{if(y!==void 0&&x.editable!==!1&&!wt(M.getValue(x.name),O)){M.setValue(x.name,O);const I=new mt(y.propertySet,void 0);I.setValues(y.getValues()),I.rootElement=y.rootElement,k.valueSet=I,y.rootElement.valueSet=I,z.propertyEditorChanges$?.next()}};return f.jsx("daga-diagram",{children:f.jsx(di.Provider,{value:s,children:f.jsx(St.Provider,{value:z,children:f.jsxs("daga-diagram-editor",{children:[f.jsx("div",{className:"daga-append-to",ref:r}),f.jsxs(St.Provider,{value:z,children:[s.components?.buttons!==void 0&&s.components?.buttons?.enabled!==!1&&f.jsx(Si,{location:s.components?.buttons?.location||Dt.BottomRight,direction:s.components?.buttons?.direction||g.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&&f.jsx(wi,{location:s.components?.palette?.location||Dt.TopLeft,direction:s.components?.palette?.direction||g.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&&f.jsx(bi,{location:s.components?.propertyEditor?.location||Dt.TopRight,direction:s.components?.propertyEditor?.direction||g.Bottom,width:s.components?.propertyEditor?.width||"24rem",height:s.components?.propertyEditor?.height,title:h,valueSet:y,onValueChange:Q}),s.components?.errors!==void 0&&s.components?.errors?.enabled!==!1&&f.jsx(gi,{})]})]})})})})};exports.DagaDiagram=xi;
|