@metadev/daga-react 5.0.2 → 5.0.3
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 +5 -0
- package/index.js +2 -2
- package/index.mjs +255 -250
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("react/jsx-runtime"),oo=require("d3"),kt=require("rxjs"),I=require("react");function io(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=io(oo);var f=(s=>(s.Bottom="bottom",s.Left="left",s.Right="right",s.Top="top",s))(f||{}),Bt=(s=>(s.BottomLeft="bottom-left",s.BottomRight="bottom-right",s.TopLeft="top-left",s.TopRight="top-right",s))(Bt||{}),Lt=(s=>(s.Left="left",s.Center="center",s.Right="right",s))(Lt||{}),Xt=(s=>(s.Top="top",s.Center="center",s.Bottom="bottom",s))(Xt||{});const It=s=>[Math.round(s[0]),Math.round(s[1])],ft=(s,t,e)=>t<e?t<=s&&s<=e:e<=s&&s<=t,Se=(s,t,e)=>(s-t[0])/(t[1]-t[0])*(e[1]-e[0])+e[0],Wt=(s,t,e,a,l,r,i)=>{const n=(()=>{switch(r){case"start":return a[0]+(s[0]-t[0]);case"end":return a[1]-(t[1]-s[0]);case"middle":{const d=(t[0]+t[1])/2,c=(a[0]+a[1])/2,h=t[1]-t[0],u=a[1]-a[0],b=(s[0]-d)/h;return c+b*u}default:return Se(s[0],t,a)}})(),o=(()=>{switch(i){case"start":return l[0]+(s[1]-e[0]);case"end":return l[1]-(e[1]-s[1]);case"middle":{const d=(e[0]+e[1])/2,c=(l[0]+l[1])/2,h=e[1]-e[0],u=l[1]-l[0],b=(s[1]-d)/h;return c+b*u}default:return Se(s[1],e,l)}})();return[n,o]},Re=(s,t)=>((s[0]-t[0])**2+(s[1]-t[1])**2)**.5,so=(s,t)=>(ft(s[0][0],t[0][0],t[1][0])||ft(s[1][0],t[1][0],t[0][0])||ft(t[0][0],s[0][0],s[1][0])||ft(t[1][0],s[1][0],s[0][0]))&&(ft(s[0][1],t[0][1],t[1][1])||ft(s[1][1],t[1][1],t[0][1])||ft(t[0][1],s[0][1],s[1][1])||ft(t[1][1],s[1][1],s[0][1]));var S=(s=>(s.Blur="blur",s.Change="change",s.Click="click",s.ContextMenu="contextmenu",s.DoubleClick="dblclick",s.Focus="focus",s.FocusIn="focusin",s.FocusOut="focusout",s.Input="input",s.KeyDown="keydown",s.KeyUp="keyup",s.MouseDown="mousedown",s.MouseEnter="mouseenter",s.MouseLeave="mouseleave",s.MouseMove="mousemove",s.MouseOut="mouseout",s.MouseOver="mouseover",s.MouseUp="mouseup",s.TouchStart="touchstart",s.TouchEnd="touchend",s.Wheel="wheel",s))(S||{}),K=(s=>(s.Alt="Alt",s.AltGraph="AltGraph",s.ArrowDown="ArrowDown",s.ArrowLeft="ArrowLeft",s.ArrowRight="ArrowRight",s.ArrowUp="ArrowUp",s.Backspace="Backspace",s.Control="Control",s.Delete="Delete",s.End="End",s.Enter="Enter",s.Escape="Escape",s.Home="Home",s.OS="OS",s.PageDown="PageDown",s.PageUp="PageUp",s.Shift="Shift",s.Tab="Tab",s))(K||{}),$=(s=>(s.Drag="drag",s.Start="start",s.End="end",s))($||{}),de=(s=>(s.Zoom="zoom",s.Start="start",s.End="end",s))(de||{});const ce=s=>s.replace(/([!"#$%&'()*+,\-./:;<=>?@[\\\]^`{|}])/g,"\\$1");var ze=(s=>(s.Straight="straight",s.Bezier="bezier",s.Square="square",s))(ze||{}),pe=(s=>(s.Solid="solid",s.Dashed="dashed",s.GappedDashes="gapped-dashes",s.Dotted="dotted",s))(pe||{});const no=20,ro=(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||no;let r="",i,n;switch(s){case"straight":r+=`M ${t[0][0]} ${t[0][1]}`;for(let o=1;o<t.length;++o)r+=` L ${t[o][0]} ${t[o][1]}`;break;case"bezier":i=e,r+=`M ${t[0][0]} ${t[0][1]}`;for(let o=1;o<t.length;++o){if(o+1>=t.length)switch(a){case f.Bottom:n=f.Top;break;case f.Top:n=f.Bottom;break;case f.Right:n=f.Left;break;case f.Left:n=f.Right;break}else Math.abs(t[o][0]-t[o-1][0])<Math.abs(t[o][1]-t[o-1][1])?t[o][1]>t[o-1][1]?n=f.Bottom:n=f.Top:t[o][0]>t[o-1][0]?n=f.Right:n=f.Left;if(i!==void 0){let d="",c="";const h=(Math.abs(t[o][0]-t[o-1][0])+Math.abs(t[o][1]-t[o-1][1]))/2;switch(i){case f.Bottom:d=`${t[o-1][0]} ${t[o-1][1]+h}`;break;case f.Top:d=`${t[o-1][0]} ${t[o-1][1]-h}`;break;case f.Right:d=`${t[o-1][0]+h} ${t[o-1][1]}`;break;case f.Left:d=`${t[o-1][0]-h} ${t[o-1][1]}`;break}if(n!==void 0){switch(n){case f.Top:c=`${t[o][0]} ${t[o][1]+h}`;break;case f.Bottom:c=`${t[o][0]} ${t[o][1]-h}`;break;case f.Left:c=`${t[o][0]+h} ${t[o][1]}`;break;case f.Right:c=`${t[o][0]-h} ${t[o][1]}`;break}r+=` C ${d} ${c} ${t[o][0]} ${t[o][1]}`}else r+=` Q ${d} ${t[o][0]} ${t[o][1]}`}else if(n!==void 0){let d="";const c=(Math.abs(t[o][0]-t[o-1][0])+Math.abs(t[o][1]-t[o-1][1]))/2;switch(n){case f.Top:d=`${t[o][0]} ${t[o][1]+c}`;break;case f.Bottom:d=`${t[o][0]} ${t[o][1]-c}`;break;case f.Left:d=`${t[o][0]+c} ${t[o][1]}`;break;case f.Right:d=`${t[o][0]-c} ${t[o][1]}`;break}r+=` Q ${d} ${t[o][0]} ${t[o][1]}`}else r+=` L ${t[o][0]} ${t[o][1]}`;i=n}break;case"square":i=e,r+=`M ${t[0][0]} ${t[0][1]}`;for(let o=1;o<t.length;++o){if(o+1>=t.length)switch(a){case f.Bottom:n=f.Top;break;case f.Top:n=f.Bottom;break;case f.Right:n=f.Left;break;case f.Left:n=f.Right;break}switch(i){case f.Bottom:switch(n){case f.Bottom:t[o][1]>t[o-1][1]?(t[o][0]!==t[o-1][0]?(r+=` V ${(t[o][1]+t[o-1][1])/2}`,r+=` H ${t[o][0]}`,r+=` V ${t[o][1]}`):r+=` V ${t[o][1]}`,i=n):t[o][0]>t[o-1][0]?(r+=` V ${t[o-1][1]+l}`,r+=` H ${Math.max(t[o-1][0],t[o][0])+l}`,r+=` V ${t[o][1]-l}`,r+=` H ${t[o][0]}`,r+=` V ${t[o][1]}`):(r+=` V ${t[o-1][1]+l}`,r+=` H ${Math.min(t[o-1][0],t[o][0])-l}`,r+=` V ${t[o][1]-l}`,r+=` H ${t[o][0]}`,r+=` V ${t[o][1]}`);break;case f.Top:r+=` V ${Math.max(t[o-1][1],t[o][1])+l}`,r+=` H ${t[o][0]}`,r+=` V ${t[o][1]}`;break;case f.Left:t[o][1]>t[o-1][1]+l?t[o][0]<t[o-1][0]-l?(r+=` V ${t[o][1]}`,r+=` H ${t[o][0]}`):(r+=` V ${(t[o-1][1]+t[o][1])/2}`,r+=` H ${t[o][0]+l}`,r+=` V ${t[o][1]}`,r+=` H ${t[o][0]}`):t[o][0]<t[o-1][0]-l?(r+=` V ${t[o-1][1]+l}`,r+=` H ${(t[o-1][0]+t[o][0])/2}`,r+=` V ${t[o][1]}`,r+=` H ${t[o][0]}`):(r+=` V ${t[o-1][1]+l}`,r+=` H ${t[o][0]+l}`,r+=` V ${t[o][1]}`,r+=` H ${t[o][0]}`);break;case f.Right:t[o][1]>t[o-1][1]+l?t[o][0]>t[o-1][0]+l?(r+=` V ${t[o][1]}`,r+=` H ${t[o][0]}`):(r+=` V ${(t[o-1][1]+t[o][1])/2}`,r+=` H ${t[o][0]-l}`,r+=` V ${t[o][1]}`,r+=` H ${t[o][0]}`):t[o][0]>t[o-1][0]+l?(r+=` V ${t[o-1][1]+l}`,r+=` H ${(t[o-1][0]+t[o][0])/2}`,r+=` V ${t[o][1]}`,r+=` H ${t[o][0]}`):(r+=` V ${t[o-1][1]+l}`,r+=` H ${t[o][0]-l}`,r+=` V ${t[o][1]}`,r+=` H ${t[o][0]}`);break;default:t[o][1]<t[o-1][1]+l?(r+=` V ${t[o-1][1]+l}`,t[o][0]!==t[o-1][0]&&(r+=` H ${t[o][0]}`),r+=` V ${t[o][1]}`,i=f.Top):(r+=` V ${t[o][1]}`,i=f.Bottom,t[o][0]!==t[o-1][0]&&(r+=` H ${t[o][0]}`,i=t[o][0]>t[o-1][0]?f.Right:f.Left));break}break;case f.Top:switch(n){case f.Top:t[o][1]<t[o-1][1]?(t[o][0]!==t[o-1][0]?(r+=` V ${(t[o][1]+t[o-1][1])/2}`,r+=` H ${t[o][0]}`,r+=` V ${t[o][1]}`):r+=` V ${t[o][1]}`,i=n):t[o][0]<t[o-1][0]?(r+=` V ${t[o-1][1]-l}`,r+=` H ${Math.min(t[o-1][0],t[o][0])-l}`,r+=` V ${t[o][1]+l}`,r+=` H ${t[o][0]}`,r+=` V ${t[o][1]}`):(r+=` V ${t[o-1][1]-l}`,r+=` H ${Math.max(t[o-1][0],t[o][0])+l}`,r+=` V ${t[o][1]+l}`,r+=` H ${t[o][0]}`,r+=` V ${t[o][1]}`);break;case f.Bottom:r+=` V ${Math.min(t[o-1][1],t[o][1])-l}`,r+=` H ${t[o][0]}`,r+=` V ${t[o][1]}`;break;case f.Right:t[o][1]<t[o-1][1]-l?t[o][0]>t[o-1][0]+l?(r+=` V ${t[o][1]}`,r+=` H ${t[o][0]}`):(r+=` V ${(t[o-1][1]+t[o][1])/2}`,r+=` H ${t[o][0]-l}`,r+=` V ${t[o][1]}`,r+=` H ${t[o][0]}`):t[o][0]>t[o-1][0]+l?(r+=` V ${t[o-1][1]-l}`,r+=` H ${(t[o-1][0]+t[o][0])/2}`,r+=` V ${t[o][1]}`,r+=` H ${t[o][0]}`):(r+=` V ${t[o-1][1]-l}`,r+=` H ${t[o][0]-l}`,r+=` V ${t[o][1]}`,r+=` H ${t[o][0]}`);break;case f.Left:t[o][1]<t[o-1][1]-l?t[o][0]<t[o-1][0]-l?(r+=` V ${t[o][1]}`,r+=` H ${t[o][0]}`):(r+=` V ${(t[o-1][1]+t[o][1])/2}`,r+=` H ${t[o][0]+l}`,r+=` V ${t[o][1]}`,r+=` H ${t[o][0]}`):t[o][0]<t[o-1][0]-l?(r+=` V ${t[o-1][1]-l}`,r+=` H ${(t[o-1][0]+t[o][0])/2}`,r+=` V ${t[o][1]}`,r+=` H ${t[o][0]}`):(r+=` V ${t[o-1][1]-l}`,r+=` H ${t[o][0]+l}`,r+=` V ${t[o][1]}`,r+=` H ${t[o][0]}`);break;default:t[o][1]>t[o-1][1]-l?(r+=` V ${t[o-1][1]-l}`,t[o][0]!==t[o-1][0]&&(r+=` H ${t[o][0]}`),r+=` V ${t[o][1]}`,i=f.Bottom):(r+=` V ${t[o][1]}`,i=f.Top,t[o][0]!==t[o-1][0]&&(r+=` H ${t[o][0]}`,i=t[o][0]>t[o-1][0]?f.Right:f.Left));break}break;case f.Left:switch(n){case f.Left:t[o][0]<t[o-1][0]?(t[o][1]!==t[o-1][1]?(r+=` H ${(t[o][0]+t[o-1][0])/2}`,r+=` V ${t[o][1]}`,r+=` H ${t[o][0]}`):r+=` H ${t[o][0]}`,i=n):t[o][1]<t[o-1][1]?(r+=` H ${t[o-1][0]-l}`,r+=` V ${Math.min(t[o-1][1],t[o][1])-l}`,r+=` H ${t[o][0]+l}`,r+=` V ${t[o][1]}`,r+=` H ${t[o][0]}`):(r+=` H ${t[o-1][0]-l}`,r+=` V ${Math.max(t[o-1][1],t[o][1])+l}`,r+=` H ${t[o][0]+l}`,r+=` V ${t[o][1]}`,r+=` H ${t[o][0]}`);break;case f.Right:r+=` H ${Math.min(t[o-1][0],t[o][0])-l}`,r+=` V ${t[o][1]}`,r+=` H ${t[o][0]}`;break;case f.Bottom:t[o][0]<t[o-1][0]-l?t[o][1]>t[o-1][1]+l?(r+=` H ${t[o][0]}`,r+=` V ${t[o][1]}`):(r+=` H ${(t[o-1][0]+t[o][0])/2}`,r+=` V ${t[o][1]-l}`,r+=` H ${t[o][0]}`,r+=` V ${t[o][1]}`):t[o][1]>t[o-1][1]+l?(r+=` H ${t[o-1][0]-l}`,r+=` V ${(t[o-1][1]+t[o][1])/2}`,r+=` H ${t[o][0]}`,r+=` V ${t[o][1]}`):(r+=` H ${t[o-1][0]-l}`,r+=` V ${t[o][1]-l}`,r+=` H ${t[o][0]}`,r+=` V ${t[o][1]}`);break;case f.Top:t[o][0]<t[o-1][0]-l?t[o][1]<t[o-1][1]-l?(r+=` H ${t[o][0]}`,r+=` V ${t[o][1]}`):(r+=` H ${(t[o-1][0]+t[o][0])/2}`,r+=` V ${t[o][1]+l}`,r+=` H ${t[o][0]}`,r+=` V ${t[o][1]}`):t[o][1]<t[o-1][1]-l?(r+=` H ${t[o-1][0]-l}`,r+=` V ${(t[o-1][1]+t[o][1])/2}`,r+=` H ${t[o][0]}`,r+=` V ${t[o][1]}`):(r+=` H ${t[o-1][0]-l}`,r+=` V ${t[o][1]+l}`,r+=` H ${t[o][0]}`,r+=` V ${t[o][1]}`);break;default:t[o][0]>t[o-1][0]-l?(r+=` H ${t[o-1][0]-l}`,t[o][1]!==t[o-1][1]&&(r+=` V ${t[o][1]}`),r+=` H ${t[o][0]}`,i=f.Right):(r+=` H ${t[o][0]}`,i=f.Left,t[o][1]!==t[o-1][1]&&(r+=` V ${t[o][1]}`,i=t[o][1]>t[o-1][1]?f.Bottom:f.Top));break}break;case f.Right:switch(n){case f.Right:t[o][0]>t[o-1][0]?(t[o][1]!==t[o-1][1]?(r+=` H ${(t[o][0]+t[o-1][0])/2}`,r+=` V ${t[o][1]}`,r+=` H ${t[o][0]}`):r+=` H ${t[o][0]}`,i=n):t[o][1]>t[o-1][1]?(r+=` H ${t[o-1][0]+l}`,r+=` V ${Math.max(t[o-1][1],t[o][1])+l}`,r+=` H ${t[o][0]-l}`,r+=` V ${t[o][1]}`,r+=` H ${t[o][0]}`):(r+=` H ${t[o-1][0]+l}`,r+=` V ${Math.min(t[o-1][1],t[o][1])-l}`,r+=` H ${t[o][0]-l}`,r+=` V ${t[o][1]}`,r+=` H ${t[o][0]}`);break;case f.Left:r+=` H ${Math.max(t[o-1][0],t[o][0])+l}`,r+=` V ${t[o][1]}`,r+=` H ${t[o][0]}`;break;case f.Top:t[o][0]>t[o-1][0]+l?t[o][1]<t[o-1][1]-l?(r+=` H ${t[o][0]}`,r+=` V ${t[o][1]}`):(r+=` H ${(t[o-1][0]+t[o][0])/2}`,r+=` V ${t[o][1]+l}`,r+=` H ${t[o][0]}`,r+=` V ${t[o][1]}`):t[o][1]<t[o-1][1]-l?(r+=` H ${t[o-1][0]+l}`,r+=` V ${(t[o-1][1]+t[o][1])/2}`,r+=` H ${t[o][0]}`,r+=` V ${t[o][1]}`):(r+=` H ${t[o-1][0]+l}`,r+=` V ${t[o][1]+l}`,r+=` H ${t[o][0]}`,r+=` V ${t[o][1]}`);break;case f.Bottom:t[o][0]>t[o-1][0]+l?t[o][1]>t[o-1][1]+l?(r+=` H ${t[o][0]}`,r+=` V ${t[o][1]}`):(r+=` H ${(t[o-1][0]+t[o][0])/2}`,r+=` V ${t[o][1]-l}`,r+=` H ${t[o][0]}`,r+=` V ${t[o][1]}`):t[o][1]>t[o-1][1]+l?(r+=` H ${t[o-1][0]+l}`,r+=` V ${(t[o-1][1]+t[o][1])/2}`,r+=` H ${t[o][0]}`,r+=` V ${t[o][1]}`):(r+=` H ${t[o-1][0]+l}`,r+=` V ${t[o][1]-l}`,r+=` H ${t[o][0]}`,r+=` V ${t[o][1]}`);break;default:t[o][0]<t[o-1][0]+l?(r+=` H ${t[o-1][0]+l}`,t[o][1]!==t[o-1][1]&&(r+=` V ${t[o][1]}`),r+=` H ${t[o][0]}`,i=f.Left):(r+=` H ${t[o][0]}`,i=f.Right,t[o][1]!==t[o-1][1]&&(r+=` V ${t[o][1]}`,i=t[o][1]>t[o-1][1]?f.Bottom:f.Top));break}break;default:t[o][0]!==t[o-1][0]&&(r+=` H ${t[o][0]}`,i=t[o][0]>t[o-1][0]?f.Right:f.Left),t[o][1]!==t[o-1][1]&&(r+=` V ${t[o][1]}`,i=t[o][1]>t[o-1][1]?f.Bottom:f.Top)}}break}return r}},he=(s,t)=>{switch(s){case"dotted":return`${t}`;case"dashed":return`${4*t} ${t}`;case"gapped-dashes":return`${4*t} ${4*t}`;default:return"none"}},B=(s,t)=>{const e=s.indexOf(t);return e>=0&&s.splice(e,1),s};var Tt=(s=>(s.Ellipse="ellipse",s.Empty="empty",s.Folder="folder",s.Hexagon="hexagon",s.Octagon="octagon",s.Pill="pill",s.Rectangle="rectangle",s.Rhombus="rhombus",s.RoundedRectangle="rounded-rectangle",s.StickyNote="sticky-note",s))(Tt||{});const ge=(s,t,e,a,l)=>{if(typeof s=="function")return s(t,e,a,l);switch(s){case"ellipse":return Ve(t,e,a,l);case"empty":return ao();case"folder":return lo(t,e,a,l);case"hexagon":return co(t,e,a,l);case"octagon":return ho(t,e,a,l);case"pill":return Yt(t,e,a,l);case"rectangle":return xe(t,e,a,l);case"rhombus":return go(t,e,a,l);case"rounded-rectangle":return fo(t,e,a,l);case"sticky-note":return uo(t,e,a,l);default:return xe(t,e,a,l)}},Ve=(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`,ao=()=>"Z",lo=(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`,co=(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`,ho=(s,t,e,a)=>`M ${s+e/4} ${t} L ${s+3*e/4} ${t} L ${s+e} ${t+a/4} L ${s+e} ${t+3*a/4} L ${s+3*e/4} ${t+a} L ${s+e/4} ${t+a} L ${s} ${t+3*a/4} L ${s} ${t+a/4} L ${s+e/4} ${t} Z`,Yt=(s,t,e,a)=>a<e?`M ${s+a/2} ${t} L ${s+e-a/2} ${t} A ${a/2} ${a/2} 0 0 1 ${s+e} ${t+a/2} A ${a/2} ${a/2} 0 0 1 ${s+e-a/2} ${t+a} L ${s+a/2} ${t+a} A ${a/2} ${a/2} 0 0 1 ${s} ${t+a/2} A ${a/2} ${a/2} 0 0 1 ${s+a/2} ${t} Z`:a>e?`M ${s} ${t+e/2} L ${s} ${t+a-e/2} A ${e/2} ${e/2} 0 0 0 ${s+e/2} ${t+a} A ${e/2} ${e/2} 0 0 0 ${s+e} ${t+a-e/2} L ${s+e} ${t+e/2} A ${e/2} ${e/2} 0 0 0 ${s+e/2} ${t} A ${e/2} ${e/2} 0 0 0 ${s} ${t+e/2} Z`:Ve(s,t,e,a),xe=(s,t,e,a)=>`M ${s} ${t} L ${s+e} ${t} L ${s+e} ${t+a} L ${s} ${t+a} Z`,go=(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`,fo=(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`,uo=(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 po=s=>Math.max(...s.split(`
|
|
2
|
-
`).map(t=>t.length)),mo=s=>s.match(/\n/g)?.length||0,Z=[];for(let s=0;s<256;++s)Z.push((s+256).toString(16).slice(1));function vo(s,t=0){return(Z[s[t+0]]+Z[s[t+1]]+Z[s[t+2]]+Z[s[t+3]]+"-"+Z[s[t+4]]+Z[s[t+5]]+"-"+Z[s[t+6]]+Z[s[t+7]]+"-"+Z[s[t+8]]+Z[s[t+9]]+"-"+Z[s[t+10]]+Z[s[t+11]]+Z[s[t+12]]+Z[s[t+13]]+Z[s[t+14]]+Z[s[t+15]]).toLowerCase()}let oe;const yo=new Uint8Array(16);function bo(){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(yo)}const ko=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),Ce={randomUUID:ko};function wo(s,t,e){s=s||{};const a=s.random??s.rng?.()??bo();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,vo(a)}function $e(s,t,e){return Ce.randomUUID&&!s?Ce.randomUUID():wo(s)}const St=s=>{if(typeof s!="object")return s;if(Array.isArray(s))return s.map(St);const t={};for(const e of Object.entries(s))t[e[0]]=St(e[1]);return t},nt=s=>{const{selected:t,highlighted:e,selectedAndHighlighted:a,...l}=s,r=l,i={...r,...t},n={...r,...e},o={...r,...e,...t,...a};return{defaultLook:r,selectedLook:i,highlightedLook:n,selectedAndHighlightedLook:o}};class Kt{constructor(){this.entities=[],this.entityMap={}}get length(){return this.size()}all(){return[...this.entities]}add(t){this.entityMap[t.id]===void 0&&(this.entityMap[t.id]=t,this.entities.push(t))}clear(){for(;this.entities.length>0;)this.remove(this.entities[0].id)}contains(t){return this.entityMap[t]!==void 0}count(t){return this.entities.filter(t).length}filter(t){return this.entities.filter(t)}find(t){return this.entities.find(t)}get(t){return this.entityMap[t]}map(t){return this.entities.map(t)}remove(t){const e=this.get(t);e!==void 0&&(delete this.entityMap[t],B(this.entities,e))}size(){return this.entities.length}*[Symbol.iterator](){for(const t of this.entities)yield t}}const Nt=0;class Ct{constructor(t,e){this.selfRemoved=!1,this.selfRemovedTimestamp=null,this.model=t,this._id=e}get id(){return this._id}get highlighted(){return this.model.canvas?.userHighlight?.contains(this.id)||!1}get selected(){return this.model.canvas?.userSelection?.contains(this.id)||!1}select(){return this.model.canvas?.selectCanvasView()?.select(`[id='${ce(this.id)}']`)}}class gt extends Kt{all(t=!1){return t?super.all():super.filter(e=>!e.removed)}contains(t,e=!1){return e?super.contains(t):super.contains(t)&&!this.entityMap[t].removed}count(t,e=!1){return e?super.count(t):super.count((a,l,r)=>t(a,l,r)&&!a.removed)}filter(t,e=!1){return e?super.filter(t):super.filter((a,l,r)=>t(a,l,r)&&!a.removed)}find(t,e=!1){return e?super.find(t):super.find((a,l,r)=>t(a,l,r)&&!a.removed)}get(t,e=!1){return e?super.get(t):this.contains(t)?super.get(t):void 0}map(t,e=!1){return e?super.map(t):super.filter(a=>!a.removed).map(t)}remove(t){const e=this.get(t,!0);e!==void 0&&(delete this.entityMap[t],B(this.entities,e))}size(t=!1){return t?super.size():super.filter(e=>!e.removed).length}*[Symbol.iterator](t=!1){if(t)for(const e of this.entities)yield e;else for(const e of this.entities.filter(a=>!a.removed))yield e}}class So{constructor(t,e,a,l,r,i,n){this.name=t,this.label=e,this.type=a,this.defaultValue=l,this.basic=r,this.editable=i,this.rootAttribute=n,this.options=void 0,this.properties=void 0}}var N=(s=>(s.Boolean="boolean",s.Color="color",s.Date="date",s.Datetime="datetime",s.Number="number",s.Object="object",s.Option="option",s.OptionList="option-list",s.OptionSet="option-set",s.Text="text",s.TextArea="text-area",s.TextList="text-list",s.TextSet="text-set",s.TextMap="text-map",s.Time="time",s.Url="url",s))(N||{});class qt{constructor(t=[]){this.propertyList=t,this.propertyMap={};for(const e of this.propertyList)this.propertyMap[e.name]=e}getProperty(t){return this.propertyMap[t]}hasProperty(t){return this.propertyMap[t]!==void 0}hasProperties(){return this.propertyList.length>0}}function bt(s,t){return!t||s[0]>t[0]?!0:s[0]===t[0]?s[1]>=t[1]:!1}const Ie=s=>s==null||s===""||s instanceof Array&&s.length===0||s instanceof Object&&Object.keys(s).length===0,wt=(s,t)=>s===t||JSON.stringify(s)===JSON.stringify(t),Oe=(s,t,e)=>{const a={},l={};for(const r in e.propertySet.propertyMap)if(e.propertySet.propertyMap[r].type===N.Object){const i=Oe(s[r],t[r],e.getSubValueSet(r));Object.keys(i[0]).length>0&&Object.keys(i[1]).length>0&&(a[r]=i[0],l[r]=i[1])}else wt(s[r],t[r])||(a[r]=s[r],l[r]=t[r]);return[a,l]},xo=s=>s!=null&&s.constructor===Object;class vt{constructor(t,e){this.displayedProperties=[],this.hiddenProperties=[],this.values={},this.valueSets={},this.ownTimestamps={},this.propertySet=t,this.rootElement=e,this.resetValues()}getRootElementValue(t){if(this.rootElement){if(typeof t=="string")return this.rootElement[t];if(Array.isArray(t)&&t.length>0){let e=this.rootElement;for(const a of t){if(e==null)return;e=e[a]}return e}}}setRootElementValue(t,e){if(this.rootElement){if(typeof t=="string"&&(this.rootElement[t]=e),Array.isArray(t)&&t.length>0){let a=this.rootElement;for(let l=0;l<t.length-1;++l){const r=t[l];if(a==null)return;a=a[r]}if(a==null)return;a[t[t.length-1]]=e}typeof this.rootElement.updateInView=="function"&&this.rootElement.updateInView()}}getValue(t){const e=this.propertySet.getProperty(t)?.rootAttribute;return e!=null&&(this.values[t]=this.getRootElementValue(e)),this.propertySet.getProperty(t).type===N.Object?this.valueSets[t].getValues():this.values[t]}getValues(){const t={};for(const e in this.propertySet.propertyMap)this.propertySet.getProperty(e).type===N.Object?t[e]=this.valueSets[e].getValues():t[e]=this.getValue(e);return t}getValuesForKeys(t){const e={};for(const a in t)this.propertySet.getProperty(a).type===N.Object?e[a]=this.valueSets[a].getValuesForKeys(t[a]):e[a]=this.getValue(a);return e}getTimestamps(){const t={};for(const e in this.propertySet.propertyMap)if(this.propertySet.getProperty(e).type===N.Object)t[e]=this.valueSets[e].getTimestamps();else{const l=this.ownTimestamps[e];l&&(t[e]=l)}return t}hasValue(t){const e=this.getValue(t);return!Ie(e)}hasSetValue(t){const e=this.getValue(t),a=this.propertySet.getProperty(t);return a&&a.type===N.Object?this.getSubValueSet(t).hasAnySetValue():!Ie(e)&&!wt(e,a?.defaultValue)}hasAnySetValue(){for(const t of this.propertySet.propertyList)if(this.hasSetValue(t.name))return!0;return!1}setValue(t,e){const a=this.propertySet.getProperty(t);if(a){a.type===N.Object?this.valueSets[t].setValues(e):(this.values[t]=e,wt(e,a.defaultValue)||this.displayProperty(a));const l=a.rootAttribute;l!=null&&this.setRootElementValue(l,e)}}setValues(t){this.resetValues();for(const e in t)this.propertySet.getProperty(e).type===N.Object?this.valueSets[e].setValues(t[e]):this.setValue(e,t[e])}setTimestamps(t){this.ownTimestamps={};for(const e in t)this.propertySet.getProperty(e).type===N.Object?this.valueSets[e].setTimestamps(t[e]):this.ownTimestamps[e]=t[e]}overwriteValues(t){for(const e in t)this.propertySet.getProperty(e).type===N.Object?this.valueSets[e].overwriteValues(t[e]):this.setValue(e,t[e])}overwriteValuesLww(t,e){for(const a in t)this.propertySet.getProperty(a).type===N.Object?this.valueSets[a].overwriteValuesLww(t[a],e):bt(e,this.ownTimestamps[a])&&(this.setValue(a,t[a]),this.ownTimestamps[a]=e)}resetValues(){this.displayedProperties=[],this.hiddenProperties=[],this.ownTimestamps={};for(const t in this.propertySet.propertyMap){const e=this.propertySet.getProperty(t),a=e.rootAttribute;e.type===N.Object?this.valueSets[t]=this.constructSubValueSet(t):this.values[t]=St(e.defaultValue),a!=null&&e.defaultValue!==void 0&&!wt(this.getRootElementValue(a),e.defaultValue)&&this.setRootElementValue(a,this.values[t]),e.basic!==!1?this.displayedProperties.push(e):this.hiddenProperties.push(e)}}constructSubValueSet(t){const e=this.propertySet.getProperty(t),a=new qt(e.properties),l=new vt(a,this.rootElement);return l.overwriteValues(St(e.defaultValue)),l}getSubValueSet(t){return this.valueSets[t]}displayProperty(t){this.displayedProperties.includes(t)||(this.displayedProperties.push(t),B(this.hiddenProperties,t))}hideProperty(t){this.hiddenProperties.includes(t)||(this.hiddenProperties.push(t),B(this.displayedProperties,t))}}const ot={name:"",label:null,look:{lookType:"connection-look",color:"#000000",thickness:1,shape:ze.Straight,style:pe.Solid,selected:{color:"#AA00AA"},highlighted:{thickness:2}},startMarkerLook:void 0,endMarkerLook:void 0,startTypes:[],endTypes:[],properties:[]};class _e{constructor(t){const e={...ot,...t};this.id=e.id,this.name=e.name,this.label=e.label;const a=nt(e.look);if(this.defaultLook=a.defaultLook,this.selectedLook=a.selectedLook,this.highlightedLook=a.highlightedLook,this.selectedAndHighlightedLook=a.selectedAndHighlightedLook,e.startMarkerLook!==void 0){const l=nt(e.startMarkerLook);this.defaultStartMarkerLook=l.defaultLook,this.selectedStartMarkerLook=l.selectedLook,this.highlightedStartMarkerLook=l.highlightedLook,this.selectedAndHighlightedStartMarkerLook=l.selectedAndHighlightedLook}else this.defaultStartMarkerLook=null,this.selectedStartMarkerLook=null,this.highlightedStartMarkerLook=null,this.selectedAndHighlightedStartMarkerLook=null;if(e.endMarkerLook!==void 0){const l=nt(e.endMarkerLook);this.defaultEndMarkerLook=l.defaultLook,this.selectedEndMarkerLook=l.selectedLook,this.highlightedEndMarkerLook=l.highlightedLook,this.selectedAndHighlightedEndMarkerLook=l.selectedAndHighlightedLook}else this.defaultEndMarkerLook=null,this.selectedEndMarkerLook=null,this.highlightedEndMarkerLook=null,this.selectedAndHighlightedEndMarkerLook=null;this.startTypes=e.startTypes,this.endTypes=e.endTypes,this.propertySet=new qt(e.properties)}canStartFromType(t){return this.startTypes.indexOf(t)>=0}canFinishOnType(t){return this.endTypes.indexOf(t)>=0}}class lt extends Ct{constructor(t,e,a,l,r){if(t.connections.get(r)!==void 0)throw new Error(`DiagramConnection with id "${r}" already exists`);if(!r)throw new Error("DiagramConnection cannot have an empty or null id");super(t,r),this.startCoords=[0,0],this.endCoords=[0,0],this.startLabel="",this.middleLabel="",this.endLabel="",this.points=[],this._type=e,this.valueSet=new vt(e.propertySet,this),this.originalData={},this.setStart(a),this.setEnd(l)}get type(){return this._type}set type(t){t!==this._type&&(this._type=t,this.valueSet&&(this.valueSet=new vt(t.propertySet,this)),this.model.canvas?.userSelection?.openInPropertyEditor(this,!1),this.updateInView())}get typeString(){return this.type.id}set typeString(t){if(t!==this.type.id){const e=this.model.connections.types.get(t);e&&(this.type=e)}}get name(){return this.middleLabel}set name(t){this.middleLabel=t}get look(){return this.selected?this.highlighted?this._selectedAndHighlightedLook!==void 0?this._selectedAndHighlightedLook:this.type.selectedAndHighlightedLook:this._selectedLook!==void 0?this._selectedLook:this.type.selectedLook:this.highlighted?this._highlightedLook!==void 0?this._highlightedLook:this.type.highlightedLook:this._defaultLook!==void 0?this._defaultLook:this.type.defaultLook}set look(t){this.lookConfig=t}get lookConfig(){return this._lookConfig}set lookConfig(t){if(this._lookConfig=t,t){const e=nt(t);this._defaultLook={...this._defaultLook,...e.defaultLook},this._selectedLook={...this._selectedLook,...e.selectedLook},this._highlightedLook={...this._highlightedLook,...e.highlightedLook},this._selectedAndHighlightedLook={...this._selectedAndHighlightedLook,...e.selectedAndHighlightedLook}}else this._defaultLook=t,this._selectedLook=t,this._highlightedLook=t,this._selectedAndHighlightedLook=t}get startMarkerLook(){return this.selected?this.highlighted?this._selectedAndHighlightedStartMarkerLook!==void 0?this._selectedAndHighlightedStartMarkerLook:this.type.selectedAndHighlightedStartMarkerLook:this._selectedStartMarkerLook!==void 0?this._selectedStartMarkerLook:this.type.selectedStartMarkerLook:this.highlighted?this._highlightedStartMarkerLook!==void 0?this._highlightedStartMarkerLook:this.type.highlightedStartMarkerLook:this._defaultStartMarkerLook!==void 0?this._defaultStartMarkerLook:this.type.defaultStartMarkerLook}set startMarkerLook(t){this.startMarkerLookConfig=t}get startMarkerLookConfig(){return this._startMarkerLookConfig}set startMarkerLookConfig(t){if(this._startMarkerLookConfig=t,t){const e=nt(t);this._defaultStartMarkerLook={...this._defaultStartMarkerLook,...e.defaultLook},this._selectedStartMarkerLook={...this._selectedStartMarkerLook,...e.selectedLook},this._highlightedStartMarkerLook={...this._highlightedStartMarkerLook,...e.highlightedLook},this._selectedAndHighlightedStartMarkerLook={...this._selectedAndHighlightedStartMarkerLook,...e.selectedAndHighlightedLook}}else this._defaultStartMarkerLook=t,this._selectedStartMarkerLook=t,this._highlightedStartMarkerLook=t,this._selectedAndHighlightedStartMarkerLook=t}get endMarkerLook(){return this.selected?this.highlighted?this._selectedAndHighlightedEndMarkerLook!==void 0?this._selectedAndHighlightedEndMarkerLook:this.type.selectedAndHighlightedEndMarkerLook:this._selectedEndMarkerLook!==void 0?this._selectedEndMarkerLook:this.type.selectedEndMarkerLook:this.highlighted?this._highlightedEndMarkerLook!==void 0?this._highlightedEndMarkerLook:this.type.highlightedEndMarkerLook:this._defaultEndMarkerLook!==void 0?this._defaultEndMarkerLook:this.type.defaultEndMarkerLook}set endMarkerLook(t){this.endMarkerLookConfig=t}get endMarkerLookConfig(){return this._endMarkerLookConfig}set endMarkerLookConfig(t){if(this._endMarkerLookConfig=t,t){const e=nt(t);this._defaultEndMarkerLook={...this._defaultEndMarkerLook,...e.defaultLook},this._selectedEndMarkerLook={...this._selectedEndMarkerLook,...e.selectedLook},this._highlightedEndMarkerLook={...this._highlightedEndMarkerLook,...e.highlightedLook},this._selectedAndHighlightedEndMarkerLook={...this._selectedAndHighlightedEndMarkerLook,...e.selectedAndHighlightedLook}}else this._defaultEndMarkerLook=t,this._selectedEndMarkerLook=t,this._highlightedEndMarkerLook=t,this._selectedAndHighlightedEndMarkerLook=t}get removed(){return this.selfRemoved||this.start!==void 0&&this.start.removed||this.end!==void 0&&this.end.removed}updateInView(){this.model.canvas?.updateConnectionsInView(this.id)}raise(){this.select()?.raise()}setStart(t){this.start!==t?(this.start!==void 0&&B(this.start.outgoingConnections,this),this.start=t,t!==void 0&&(t.outgoingConnections.push(this),this.startDirection=t?.direction,this.startCoords=t?.connectionPoint||[0,0])):(this.startDirection=t?.direction,this.startCoords=t?.connectionPoint||[0,0]),this.updateInView()}setEnd(t){this.end!==t?(this.end!==void 0&&B(this.end.incomingConnections,this),this.end=t,t!==void 0&&(t.incomingConnections.push(this),this.endDirection=t?.direction,this.endCoords=t?.connectionPoint||[0,0])):(this.endDirection=t?.direction,this.endCoords=t?.connectionPoint||[0,0]),this.updateInView()}tighten(){const t=this.model.canvas?.allowConnectionLoops||!1,e=this.model.canvas?.allowSharingPorts!==!1,a=this.model.canvas?.allowSharingBothPorts||!1;if(this.start?.rootElement&&this.end){const l=this.start.rootElement.ports.map(r=>[r,r.distanceTo(this.end.coords)]).sort((r,i)=>r[1]-i[1]).map(r=>r[0]);t:for(const r of l){if(!t&&r===this.end||!r.allowsOutgoing||!e&&(r.incomingConnections.filter(i=>!i.removed&&i!==this).length>0||r.outgoingConnections.filter(i=>!i.removed&&i!==this).length>0))continue t;if(!a){for(const i of r.outgoingConnections.filter(n=>!n.removed))if(i!==this&&i.end===this.end)continue t;for(const i of r.incomingConnections.filter(n=>!n.removed))if(i!==this&&i.start===this.end)continue t}if(r===this.start)break t;this.setStart(r);break t}}if(this.end?.rootElement&&this.start){const l=this.end.rootElement.ports.map(r=>[r,r.distanceTo(this.start.coords)]).sort((r,i)=>r[1]-i[1]).map(r=>r[0]);t:for(const r of l){if(!t&&r===this.start||!r.allowsIncoming||!e&&(r.incomingConnections.filter(i=>!i.removed&&i!==this).length>0||r.outgoingConnections.filter(i=>!i.removed&&i!==this).length>0))continue t;if(!a){for(const i of r.incomingConnections.filter(n=>!n.removed))if(i!==this&&i.start===this.start)continue t;for(const i of r.outgoingConnections.filter(n=>!n.removed))if(i!==this&&i.end===this.start)continue t}if(r===this.end)break t;this.setEnd(r);break t}}}getPriority(){return this.start?this.end?Math.min(this.start.getPriority(),this.end.getPriority()):this.start.getPriority():this.end?this.end.getPriority():Nt}}class Co extends gt{constructor(t){super(),this.types=new Kt,this.model=t}new(t,e,a,l){let r;if(t instanceof _e)r=t;else{const n=this.types.get(t);if(n===void 0)throw new TypeError(`Connection type with id '${t}' could not be found.`);r=n}const i=new lt(this.model,r,e,a,l);return super.add(i),i.updateInView(),i.valueSet.resetValues(),i}remove(t){const e=this.get(t,!0);e&&(B(e.start?.outgoingConnections||[],e),B(e.end?.incomingConnections||[],e),super.remove(t),e.updateInView())}}const O={editable:!0,fontSize:0,margin:0,padding:0,fontFamily:"'Wonder Unit Sans', sans-serif",color:"#000000",selectedColor:"#000000",backgroundColor:"#00000000",horizontalAlign:Lt.Center,verticalAlign:Xt.Center,orientation:f.Top,fit:!1,shrink:!0};class ct extends Ct{constructor(t,e,a,l,r,i,n,o,d,c,h,u,b,m,x,g){const v=`${e?.id}_field`;if(t.fields.get(v)!==void 0)throw new Error("DiagramField for rootElement already exists");if(super(t,v),this.textTimestamp=null,this.rootElement=e,this.coords=a,this.width=l,this.height=r,this.fontSize=i,this.fontFamily=n,this.color=o,this.selectedColor=d,this.horizontalAlign=c,this.verticalAlign=h,!isNaN(Number(u)))this.orientation=Number(u);else switch(u){case f.Top:this.orientation=0;break;case f.Right:this.orientation=90;break;case f.Bottom:this.orientation=180;break;case f.Left:this.orientation=270;break;default:this.orientation=0}this.defaultText=b,this._text=b,this.editable=m,this.fit=x,this.shrink=g}get text(){return this._text}set text(t){(t==null||t?.trim()==="")&&(t=this.defaultText),this._text=t,this.updateInView(),this.fit&&this.model.canvas?.fitFieldRootInView(this.id,this.shrink)}get removed(){return this.selfRemoved||this.rootElement!==void 0&&this.rootElement.removed}updateInView(){this.model.canvas?.updateFieldsInView(this.id)}raise(){this.select()?.raise()}move(t){this.coords=t,this.updateInView()}getPriority(){return this.rootElement?.getPriority()||Nt}}class $o extends gt{constructor(t){super(),this.model=t}new(t,e,a,l,r,i,n,o,d,c,h,u,b,m,x){const g=new ct(this.model,t,e,n,o,a,l,r,i,d,c,h,u,b,m,x);return super.add(g),g.updateInView(),t!==void 0&&(t.label=g),g}remove(t){const e=this.get(t,!0);e&&(e.rootElement?.label!==void 0&&e.rootElement.label===e&&(e.rootElement.label=void 0),super.remove(t),e.updateInView())}}const q=s=>s?.margin===null||s?.margin===void 0?O.margin:typeof s.margin=="number"?s.margin:s.margin.length===0?O.margin:s.margin.length===1||s.margin.length===2?s.margin[0]:(s.margin.length===3,s.margin[2]),D=s=>s?.margin===null||s?.margin===void 0?O.margin:typeof s.margin=="number"?s.margin:s.margin.length===0?O.margin:s.margin.length===1?s.margin[0]:s.margin.length===2||s.margin.length===3?s.margin[1]:s.margin[3],it=s=>s?.margin===null||s?.margin===void 0?O.margin:typeof s.margin=="number"?s.margin:s.margin.length===0?O.margin:s.margin.length===1?s.margin[0]:(s.margin.length===2||s.margin.length===3,s.margin[1]),G=s=>s?.margin===null||s?.margin===void 0?O.margin:typeof s.margin=="number"?s.margin:s.margin.length===0?O.margin:(s.margin.length===1||s.margin.length===2||s.margin.length===3,s.margin[0]),Vt=s=>s?.padding===null||s?.padding===void 0?O.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?O.padding:s.padding.length===1||s.padding.length===2?s.padding[0]:(s.padding.length===3,s.padding[2]),Ot=s=>s?.padding===null||s?.padding===void 0?O.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?O.padding:s.padding.length===1?s.padding[0]:s.padding.length===2||s.padding.length===3?s.padding[1]:s.padding[3],_t=s=>s?.padding===null||s?.padding===void 0?O.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?O.padding:s.padding.length===1?s.padding[0]:(s.padding.length===2||s.padding.length===3,s.padding[1]),Ht=s=>s?.padding===null||s?.padding===void 0?O.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?O.padding:(s.padding.length===1||s.padding.length===2||s.padding.length===3,s.padding[0]),Ae=1,Le=1,Io=1,Ao=1;class Lo{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 Eo(l))}}}class Eo{constructor(t){this.label=t.label||null,this.ports=t.ports||[],this.priority=t.priority||Nt,this.resizableX=t.resizableX,this.resizableY=t.resizableY;const e=nt(t.look||He);this.defaultLook=e.defaultLook,this.selectedLook=e.selectedLook,this.highlightedLook=e.highlightedLook,this.selectedAndHighlightedLook=e.selectedAndHighlightedLook}}class U extends Ct{constructor(t,e,a,l,r,i,n,o){if(t.sections.get(o)!==void 0)throw new Error(`DiagramSection with id "${o}" already exists`);if(!o)throw new Error("DiagramSection cannot have an empty or null id");super(t,o),this.ports=[],this.decorators=[],this.node=e,this.indexXInNode=a,this.indexYInNode=l,this.coords=r,this.width=i,this.height=n}get name(){return this.label?.text||""}set name(t){this.label&&(this.label.text=t)}get look(){return this.selected?this.highlighted?this._selectedAndHighlightedLook!==void 0?this._selectedAndHighlightedLook:this.type?.selectedAndHighlightedLook||this.node?.look:this._selectedLook!==void 0?this._selectedLook:this.type?.selectedLook||this.node?.look:this.highlighted?this._highlightedLook!==void 0?this._highlightedLook:this.type?.highlightedLook||this.node?.look:this._defaultLook!==void 0?this._defaultLook:this.type?.defaultLook||this.node?.look}set look(t){this.lookConfig=t}get lookConfig(){return this._lookConfig}set lookConfig(t){if(this._lookConfig=t,t){const e=nt(t);this._defaultLook={...this._defaultLook,...e.defaultLook},this._selectedLook={...this._selectedLook,...e.selectedLook},this._highlightedLook={...this._highlightedLook,...e.highlightedLook},this._selectedAndHighlightedLook={...this._selectedAndHighlightedLook,...e.selectedAndHighlightedLook}}else this._defaultLook=t,this._selectedLook=t,this._highlightedLook=t,this._selectedAndHighlightedLook=t}get removed(){return this.selfRemoved||this.node!==void 0&&this.node.removed}updateInView(){this.model.canvas?.updateSectionsInView(this.id)}raise(){this.select()?.raise(),this.label&&this.label.raise();for(const t of this.ports)t.raise();for(const t of this.decorators)t.raise()}get type(){return this.node?.type?.sectionGrid?.sections?.[this.indexYInNode]?.[this.indexXInNode]}getMinWidth(){return this.node?.type?.sectionGrid?.minWidths?.[this.indexXInNode]||Io}getMinHeight(){return this.node?.type?.sectionGrid?.minHeights?.[this.indexYInNode]||Ao}getPriority(){return this.node?.type?.sectionGrid?.sections?.[this.indexYInNode]?.[this.indexXInNode]?.priority||Nt}getResizableX(){const t=this.type;return t?.resizableX!==void 0?t.resizableX:this.node?.type?.resizableX||!1}getResizableY(){const t=this.type;return t?.resizableY!==void 0?t.resizableY:this.node?.type?.resizableY||!1}getClosestPortToPoint(t){if(this.ports.length!==0){if(this.ports.length===1)return this.ports[1];{const e=this.ports.map(r=>r.distanceTo(t)),a=e.indexOf(Math.min(...e));return this.ports[a]}}}getIncomingConnections(t=!1){const e=[];for(const a of this.ports)for(const l of a.incomingConnections)!t&&l.removed||e.push(l);return e}getOutgoingConnections(t=!1){const e=[];for(const a of this.ports)for(const l of a.outgoingConnections)!t&&l.removed||e.push(l);return e}getConnections(t=!1){const e=[];for(const a of this.ports){for(const l of a.incomingConnections)!t&&l.removed||e.push(l);for(const l of a.outgoingConnections)!t&&l.removed||e.push(l)}return e}move(t){this.setGeometry({coords:t,width:this.width,height:this.height})}stretch(t,e){const a=[this.coords[0],this.coords[0]+this.width],l=[this.coords[1],this.coords[1]+this.height];let r,i;switch(t){case f.Left:r=[a[0]-e,a[1]],i=[l[0],l[1]],r[1]-r[0]<this.getMinWidth()&&(r[0]=r[1]-this.getMinWidth());break;case f.Top:r=[a[0],a[1]],i=[l[0]-e,l[1]],i[1]-i[0]<this.getMinHeight()&&(i[0]=i[1]-this.getMinHeight());break;case f.Right:r=[a[0],a[1]+e],i=[l[0],l[1]],r[1]-r[0]<this.getMinWidth()&&(r[1]=r[0]+this.getMinWidth());break;case f.Bottom:r=[a[0],a[1]],i=[l[0],l[1]+e],i[1]-i[0]<this.getMinHeight()&&(i[1]=i[0]+this.getMinHeight());break}this.setGeometry({coords:[r[0],i[0]],width:r[1]-r[0],height:i[1]-i[0]})}getGeometry(){return{coords:[...this.coords],width:this.width,height:this.height}}setGeometry(t){const e=[this.coords[0],this.coords[0]+this.width],a=[this.coords[1],this.coords[1]+this.height];this.coords=[...t.coords],this.width=t.width,this.height=t.height;const l=[this.coords[0],this.coords[0]+this.width],r=[this.coords[1],this.coords[1]+this.height];for(const n of this.ports)n.move(Wt(n.coords,e,a,l,r,n.anchorPointX,n.anchorPointY));const i=this.type;this.label&&(this.label.coords=[this.coords[0]+D(i?.label),this.coords[1]+G(i?.label)],this.label.width=this.width-D(i?.label)-it(i?.label),this.label.height=this.height-G(i?.label)-q(i?.label),this.label.updateInView());for(const n of this.decorators)n.move(Wt(n.coords,e,a,l,r,n.anchorPointX,n.anchorPointY));this.model.canvas?.autoTightenConnections!==!1&&this.getConnections().forEach(n=>n.tighten()),this.updateInView()}}class Mo extends gt{constructor(t){super(),this.model=t}new(t,e,a,l,r,i,n){const o=new U(this.model,t,e,a,l,r,i,n);super.add(o),o.updateInView(),t.sections.push(o),t.updateInView();const d=t.type.sectionGrid?.sections?.[a]?.[e]?.ports;if(d&&d.length>0)for(let h=0;h<d.length;++h){const u=d[h],b=this.model.ports.new(u.type!==void 0?this.model.ports.types.get(u.type):void 0,o,[o.coords[0]+(u.coords[0]||0),o.coords[1]+(u.coords[1]||0)],u.connectionPoint!==void 0?[o.coords[0]+(u.connectionPoint[0]||0),o.coords[1]+(u.connectionPoint[1]||0)]:void 0,u?.direction,`${o.id}_${h}`,u.anchorPointX||"floating",u.anchorPointY||"floating");if(b.type?.label){const m={...O,...b.type?.label},x=6*m.fontSize+Ot(m)+_t(m),g=m.fontSize+Ht(m)+Vt(m);let v;switch(b.direction){case f.Bottom:case f.Left:case f.Right:v=[b.coords[0]-x/2,b.coords[1]-g-q(m)];break;case f.Top:v=[b.coords[0]-x/2,b.coords[1]+G(m)];break;default:v=b.coords}this.model.fields.new(b,v,m.fontSize,m.fontFamily,m.color,m.selectedColor,x,g,m.horizontalAlign,m.verticalAlign,m.orientation,"",m.editable,m.fit,m.shrink)}}const c=t.type.sectionGrid?.sections?.[a]?.[e]?.label;if(c){const h={...O,...c};this.model.fields.new(o,[o.coords[0]+D(h),o.coords[1]+G(h)],h.fontSize,h.fontFamily,h.color,h.selectedColor,o.width-D(h)-it(h),o.height-G(h)-q(h),h.horizontalAlign,h.verticalAlign,h.orientation,"",h.editable,h.fit,h.shrink)}return o}remove(t){const e=this.get(t,!0);if(e){for(;e.ports.length>0;)this.model.ports.remove(e.ports[0].id);e.label&&this.model.fields.remove(e.label.id),e.node&&B(e.node.sections,e),super.remove(t),e.updateInView()}}}const He={lookType:"shaped-look",shape:Tt.Rectangle,fillColor:"#FFFFFF",borderColor:"#000000",borderThickness:1,selected:{fillColor:"#FFAAFF",borderColor:"#AA00AA"},highlighted:{borderThickness:3}},ht={name:"",defaultWidth:1,defaultHeight:1,minWidth:1,minHeight:1,resizableX:!1,resizableY:!1,snapToGridOffset:[0,0,0,0],padding:0,label:null,ports:[],decorators:[],sectionGrid:null,look:He,isUnique:!1,canBeParentless:!0,childrenTypes:[],priority:Nt,properties:[]};class je{constructor(t){const e={...ht,...t};this.id=e.id,this.name=e.name,this.defaultWidth=e.defaultWidth,this.defaultHeight=e.defaultHeight,this.minWidth=e.minWidth,this.minHeight=e.minHeight,this.resizableX=e.resizableX,this.resizableY=e.resizableY,this.snapToGridOffset=e.snapToGridOffset,this.bottomPadding=No(e),this.leftPadding=Po(e),this.rightPadding=Ro(e),this.topPadding=zo(e),this.label=e.label,this.ports=e.ports,this.decorators=e.decorators,this.sectionGrid=e.sectionGrid?new Lo(e.sectionGrid):null;const a=nt(e.look);this.defaultLook=a.defaultLook,this.selectedLook=a.selectedLook,this.highlightedLook=a.highlightedLook,this.selectedAndHighlightedLook=a.selectedAndHighlightedLook,this.isUnique=e.isUnique,this.canBeParentless=e.canBeParentless,this.childrenTypes=e.childrenTypes,this.priority=e.priority,this.propertySet=new qt(t?.properties||[])}}class R extends Ct{constructor(t,e,a=[0,0],l){if(t.nodes.get(l)!==void 0)throw new Error(`DiagramNode with id "${l}" already exists`);if(!l)throw new Error("DiagramNode cannot have an empty or null id");super(t,l),this.children=[],this.sections=[],this.ports=[],this.decorators=[],this.geometryTimestamp=null,this._type=e,this.valueSet=new vt(e.propertySet,this),this.originalData={},this.coords=a,this.width=e.defaultWidth,this.height=e.defaultHeight}get type(){return this._type}set type(t){t!==this._type&&(this._type=t,this.valueSet&&(this.valueSet=new vt(t.propertySet,this)),this.model.canvas?.userSelection?.openInPropertyEditor(this,!1),this.updateInView())}get typeString(){return this.type.id}set typeString(t){if(t!==this.type.id){const e=this.model.nodes.types.get(t);e&&(this.type=e)}}get name(){return this.label?.text||""}set name(t){this.label&&(this.label.text=t)}get look(){return this.selected?this.highlighted?this._selectedAndHighlightedLook!==void 0?this._selectedAndHighlightedLook:this.type.selectedAndHighlightedLook:this._selectedLook!==void 0?this._selectedLook:this.type.selectedLook:this.highlighted?this._highlightedLook!==void 0?this._highlightedLook:this.type.highlightedLook:this._defaultLook!==void 0?this._defaultLook:this.type.defaultLook}set look(t){this.lookConfig=t}get lookConfig(){return this._lookConfig}set lookConfig(t){if(this._lookConfig=t,t){const e=nt(t);this._defaultLook={...this._defaultLook,...e.defaultLook},this._selectedLook={...this._selectedLook,...e.selectedLook},this._highlightedLook={...this._highlightedLook,...e.highlightedLook},this._selectedAndHighlightedLook={...this._selectedAndHighlightedLook,...e.selectedAndHighlightedLook}}else this._defaultLook=t,this._selectedLook=t,this._highlightedLook=t,this._selectedAndHighlightedLook=t}get removed(){return this.selfRemoved}updateInView(){this.model.canvas?.updateNodesInView(this.id)}raise(){this.select()?.raise();for(const t of this.sections)t.raise();this.label&&this.label.raise();for(const t of this.ports)t.raise();for(const t of this.decorators)t.raise();for(const t of this.children)t.raise()}getPriority(){return this.type.priority}getClosestPortToPoint(t){if(this.ports.length!==0){if(this.ports.length===1)return this.ports[1];{const e=this.ports.map(r=>r.distanceTo(t)),a=e.indexOf(Math.min(...e));return this.ports[a]}}}getIncomingConnections(t=!1){const e=[];for(const a of this.ports)for(const l of a.incomingConnections)!t&&l.removed||e.push(l);return e}getOutgoingConnections(t=!1){const e=[];for(const a of this.ports)for(const l of a.outgoingConnections)!t&&l.removed||e.push(l);return e}getConnections(t=!1){const e=[];for(const a of this.ports){for(const l of a.incomingConnections)!t&&l.removed||e.push(l);for(const l of a.outgoingConnections)!t&&l.removed||e.push(l)}return e}getAdjacentNodes(t=!1){const e=[];for(const a of this.ports){for(const l of a.incomingConnections){if(!t&&l.removed)continue;const r=l.start?.getNode();if(r){if(!t&&r.removed)continue;e.push(r)}}for(const l of a.outgoingConnections){if(!t&&l.removed)continue;const r=l.end?.getNode();if(r){if(!t&&r.removed)continue;e.push(r)}}}return e}getLastAncestor(){let t=this;for(;t.parent!==void 0;)t=t?.parent;return t}isAncestorOf(t){let e=t;for(;e!==void 0;){if(this.id===e.id)return!0;e=e.parent}return!1}isDescendantOf(t){return t.isAncestorOf(this)}addChild(t){if(t.id===this.id)return;let e=this.parent,a=!1;for(;e!==void 0;){if(e.id===t.id){a=!0;break}e=e.parent}a||this.children.indexOf(t)>=0||(this.fitToChild(t),this.children.push(t),t.parent=this,t.raise())}removeChild(t){B(this.children,t),t.parent=void 0}fitToChild(t){const e=Math.max(...this.sections.map(o=>o.indexXInNode)),a=Math.max(...this.sections.map(o=>o.indexYInNode)),l=this.coords[0]-t.coords[0]+this.type.leftPadding;l>=0&&(this.sections.length>0?this.stretchSections(f.Left,l,e,a):this.stretch(f.Left,l));const r=this.coords[1]-t.coords[1]+this.type.topPadding;r>=0&&(this.sections.length>0?this.stretchSections(f.Top,r,e,a):this.stretch(f.Top,r));const i=t.coords[0]+t.width-(this.coords[0]+this.width)+this.type.rightPadding;i>=0&&(this.sections.length>0?this.stretchSections(f.Right,i,e,a):this.stretch(f.Right,i));const n=t.coords[1]+t.height-(this.coords[1]+this.height)+this.type.bottomPadding;n>=0&&(this.sections.length>0?this.stretchSections(f.Bottom,n,e,a):this.stretch(f.Bottom,n)),this.parent&&this.parent.fitToChild(this)}move(t){const e=[t[0]-this.coords[0],t[1]-this.coords[1]];for(const a of this.children)a.move([a.coords[0]+e[0],a.coords[1]+e[1]]);for(const a of this.sections)a.move([a.coords[0]+e[0],a.coords[1]+e[1]]);this.setGeometry({coords:t,width:this.width,height:this.height,sections:{},children:{}})}stretch(t,e){const a=[this.coords[0],this.coords[0]+this.width],l=[this.coords[1],this.coords[1]+this.height];let r,i;switch(t){case f.Left:r=[a[0]-e,a[1]],i=[l[0],l[1]],r[1]-r[0]<this.type.minWidth&&(r[0]=r[1]-this.type.minWidth);break;case f.Top:r=[a[0],a[1]],i=[l[0]-e,l[1]],i[1]-i[0]<this.type.minHeight&&(i[0]=i[1]-this.type.minHeight);break;case f.Right:r=[a[0],a[1]+e],i=[l[0],l[1]],r[1]-r[0]<this.type.minWidth&&(r[1]=r[0]+this.type.minWidth);break;case f.Bottom:r=[a[0],a[1]],i=[l[0],l[1]+e],i[1]-i[0]<this.type.minHeight&&(i[1]=i[0]+this.type.minHeight);break}this.setGeometry({coords:[r[0],i[0]],width:r[1]-r[0],height:i[1]-i[0],sections:{},children:{}})}stretchSections(t,e,a,l){let r=Number.NEGATIVE_INFINITY;switch(t){case f.Bottom:for(const i of this.sections)i.indexYInNode===l&&(r=Math.max(r,i.getMinHeight()-i.height));e<r&&(e=r);for(const i of this.sections)i.indexYInNode===l?i.stretch(t,e):i.indexYInNode>l&&i.move([i.coords[0],i.coords[1]+e]);break;case f.Right:for(const i of this.sections)i.indexXInNode===a&&(r=Math.max(r,i.getMinWidth()-i.width));e<r&&(e=r);for(const i of this.sections)i.indexXInNode===a?i.stretch(t,e):i.indexXInNode>a&&i.move([i.coords[0]+e,i.coords[1]]);break;case f.Top:for(const i of this.sections)i.indexYInNode===l&&(r=Math.max(r,i.getMinHeight()-i.height));e<r&&(e=r);for(const i of this.sections)i.indexYInNode===l?i.stretch(t,e):i.indexYInNode<l&&i.move([i.coords[0],i.coords[1]-e]);break;case f.Left:for(const i of this.sections)i.indexXInNode===a&&(r=Math.max(r,i.getMinWidth()-i.width));e<r&&(e=r);for(const i of this.sections)i.indexXInNode===a?i.stretch(t,e):i.indexXInNode<a&&i.move([i.coords[0]-e,i.coords[1]]);break}this.stretch(t,e)}getGeometry(t){const e={};for(const l of this.sections)e[l.id]=l.getGeometry();const a={};for(const l of this.children)l.id!==t&&(a[l.id]=l.getGeometry(t));return{coords:[...this.coords],width:this.width,height:this.height,sections:e,children:a}}setGeometry(t){this.raise();const e=[this.coords[0],this.coords[0]+this.width],a=[this.coords[1],this.coords[1]+this.height];this.coords=[...t.coords],this.width=t.width,this.height=t.height;const l=[this.coords[0],this.coords[0]+this.width],r=[this.coords[1],this.coords[1]+this.height];for(const i of this.children){const n=t.children[i.id];n&&i.setGeometry(n)}for(const i of this.sections){const n=t.sections[i.id];n&&i.setGeometry(n)}for(const i of this.ports)i.move(Wt(i.coords,e,a,l,r,i.anchorPointX,i.anchorPointY));this.label&&(this.label.coords=[this.coords[0]+D(this.type.label),this.coords[1]+G(this.type.label)],this.label.width=this.width-D(this.type.label)-it(this.type.label),this.label.height=this.height-G(this.type.label)-q(this.type.label),this.label.updateInView());for(const i of this.decorators)i.move(Wt(i.coords,e,a,l,r,i.anchorPointX,i.anchorPointY));this.model.canvas?.autoTightenConnections!==!1&&this.getConnections().forEach(i=>i.tighten()),this.updateInView()}removeSectionColumn(t){const e=this.type.sectionGrid?.margin||0;let a=0;const l=[...this.sections];for(const r of l)r.indexYInNode===t&&(a=Math.max(a,r.width),this.model.sections.remove(r.id));for(const r of l)r.indexYInNode>t&&(--r.indexYInNode,r.move([r.coords[0]-a-e,r.coords[1]]));this.stretch(f.Right,-e-a)}removeSectionRow(t){const e=this.type.sectionGrid?.margin||0;let a=0;const l=[...this.sections];for(const r of l)r.indexXInNode===t&&(a=Math.max(a,r.height),this.model.sections.remove(r.id));for(const r of l)r.indexYInNode>t&&(--r.indexXInNode,r.move([r.coords[0],r.coords[1]-a-e]));this.stretch(f.Bottom,-e-a)}copySectionColumn(t){const e=this.type.sectionGrid?.margin||0;let a=0;const l=[...this.sections];for(const r of l)if(r.indexXInNode===t){a=Math.max(a,r.width);let i=r.indexXInNode+1;for(;this.model.sections.get(`${r.id}_copy_${i}_${r.indexYInNode}`,!0)!==void 0;)++i;this.model.sections.new(this,r.indexXInNode+1,r.indexYInNode,[r.coords[0]+r.width+e,r.coords[1]],r.width,r.height,`${r.id}_copy_${i}_${r.indexYInNode}`)}for(const r of l)r.indexXInNode>t&&(++r.indexXInNode,r.move([r.coords[0]+a+e,r.coords[1]]));this.stretch(f.Right,e+a)}copySectionRow(t){const e=this.type.sectionGrid?.margin||0;let a=0;const l=[...this.sections];for(const r of l)if(r.indexYInNode===t){a=Math.max(a,r.height);let i=r.indexYInNode+1;for(;this.model.sections.get(`${r.id}_copy_${r.indexXInNode}_${i}`,!0)!==void 0;)++i;this.model.sections.new(this,r.indexXInNode,r.indexYInNode+1,[r.coords[0],r.coords[1]+r.height+e],r.width,r.height,`${r.id}_copy_${r.indexXInNode}_${i}`)}for(const r of l)r.indexYInNode>t&&(++r.indexYInNode,r.move([r.coords[0],r.coords[1]+a+e]));this.stretch(f.Bottom,e+a)}}class To extends gt{constructor(t){super(),this.types=new Kt,this.model=t}new(t,e,a){let l;if(t instanceof je)l=t;else{const i=this.types.get(t);if(i===void 0)throw new TypeError(`Node type with id '${t}' could not be found.`);l=i}const r=new R(this.model,l,e,a);if(super.add(r),r.updateInView(),l.sectionGrid!==null){let i=r.coords[1]+(l.sectionGrid.margin||0);for(let n=0;n<l.sectionGrid.sections.length;++n){let o=r.coords[0]+(l.sectionGrid.margin||0);for(let d=0;d<l.sectionGrid.sections[n].length;++d)this.model.sections.new(r,d,n,[o,i],l.sectionGrid.defaultWidths?.[d]||Ae,l.sectionGrid.defaultHeights?.[n]||Le,`${r.id}_${n}_${d}`),o+=(l.sectionGrid.defaultWidths?.[d]||Ae)+(l.sectionGrid.margin||0);i+=(l.sectionGrid.defaultHeights?.[n]||Le)+(l.sectionGrid.margin||0)}}if(l.ports.length>0)for(let i=0;i<l.ports.length;++i){const n=l.ports[i],o=n.type!==void 0?this.model.ports.types.get(n.type):void 0,d=this.model.ports.new(o,r,[r.coords[0]+n.coords[0],r.coords[1]+n.coords[1]],n.connectionPoint!==void 0?[r.coords[0]+(n.connectionPoint[0]||0),r.coords[1]+(n.connectionPoint[1]||0)]:void 0,n.direction,`${r.id}_port_${i}`,n.anchorPointX||"floating",n.anchorPointY||"floating");if(d.type?.label){const c={...O,...d.type?.label},h=6*c.fontSize+Ot(c)+_t(c),u=c.fontSize+Ht(c)+Vt(c);let b;switch(d.direction){case f.Bottom:case f.Left:case f.Right:b=[d.coords[0]-h/2,d.coords[1]-u-q(c)];break;case f.Top:b=[d.coords[0]-h/2,d.coords[1]+G(c)];break;default:b=d.coords}this.model.fields.new(d,b,c.fontSize,c.fontFamily,c.color,c.selectedColor,h,u,c.horizontalAlign,c.verticalAlign,c.orientation,"",c.editable,c.fit,c.shrink)}}if(l.label){const i={...O,...l.label};this.model.fields.new(r,[r.coords[0]+D(i),r.coords[1]+G(i)],i.fontSize,i.fontFamily,i.color,i.selectedColor,r.width-D(i)-it(i),r.height-G(i)-q(i),i.horizontalAlign,i.verticalAlign,i.orientation,"",i.editable,i.fit,i.shrink)}if(l.decorators.length>0)for(let i=0;i<l.decorators.length;++i){const n=l.decorators[i];this.model.decorators.new(r,[r.coords[0]+n.coords[0],r.coords[1]+n.coords[1]],n.width,n.height,r.getPriority(),n.html,`${r.id}_decorator_${i}`,n.anchorPointX||"floating",n.anchorPointY||"floating")}return r.valueSet.resetValues(),r.model.canvas?.fitNodeInView(r.id),r}remove(t){const e=this.get(t,!0);if(e){for(e.parent&&B(e.parent.children,e);e.children.length>0;)this.model.nodes.remove(e.children[0].id);for(;e.sections.length>0;)this.model.sections.remove(e.sections[0].id);for(;e.ports.length>0;)this.model.ports.remove(e.ports[0].id);for(;e.decorators.length>0;)this.model.decorators.remove(e.decorators[0].id);e.label&&this.model.fields.remove(e.label.id),super.remove(t),e.updateInView()}}getAtCoordinates(t,e){const a=[];for(const l of this)l.coords[0]<t&&t<l.coords[0]+l.width&&l.coords[1]<e&&e<l.coords[1]+l.height&&a.push(l);return a}}const Ge=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},No=s=>s?.padding===null||s?.padding===void 0?ht.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?ht.padding:s.padding.length===1||s.padding.length===2?s.padding[0]:(s.padding.length===3,s.padding[2]),Po=s=>s?.padding===null||s?.padding===void 0?ht.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?ht.padding:s.padding.length===1?s.padding[0]:s.padding.length===2||s.padding.length===3?s.padding[1]:s.padding[3],Ro=s=>s?.padding===null||s?.padding===void 0?ht.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?ht.padding:s.padding.length===1?s.padding[0]:(s.padding.length===2||s.padding.length===3,s.padding[1]),zo=s=>s?.padding===null||s?.padding===void 0?ht.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?ht.padding:(s.padding.length===1||s.padding.length===2||s.padding.length===3,s.padding[0]),Fe={lookType:"shaped-look",shape:Tt.Ellipse,fillColor:"transparent",borderColor:"transparent",borderThickness:0,selected:{fillColor:"rgba(255, 0, 255, 0.5)"},highlighted:{fillColor:"rgba(0, 255, 255, 0.5)"}},Dt=nt(Fe),Ue={name:"",label:null,allowsOutgoing:!0,allowsIncoming:!0,width:24,look:Fe};class Vo{constructor(t){const e={...Ue,...t};this.id=e.id,this.name=e.name,this.label=e.label,this.allowsOutgoing=e.allowsOutgoing,this.allowsIncoming=e.allowsIncoming,this.width=e.width;const a=nt(e.look);this.defaultLook=a.defaultLook,this.selectedLook=a.selectedLook,this.highlightedLook=a.highlightedLook,this.selectedAndHighlightedLook=a.selectedAndHighlightedLook}}class yt extends Ct{constructor(t,e,a,l,r,i,n,o="floating",d="floating"){if(t.ports.get(n)!==void 0)throw new Error(`DiagramPort with id "${n}" already exists`);if(!n)throw new Error("DiagramPort cannot have an empty or null id");super(t,n),this.outgoingConnections=[],this.incomingConnections=[],this._type=e,this.rootElement=a,this.coords=l,this.connectionPoint=r||l,this.direction=i,this.anchorPointX=o,this.anchorPointY=d}get type(){return this._type}set type(t){t!==this._type&&(this._type=t,this.updateInView())}get typeString(){return this.type?.id}set typeString(t){if(t!==this.type?.id)if(t===void 0)this.type=void 0;else{const e=this.model.ports.types.get(t);e&&(this.type=e)}}get allowsOutgoing(){return this.type?.allowsOutgoing!==void 0?this.type?.allowsOutgoing:!0}get allowsIncoming(){return this.type?.allowsIncoming!==void 0?this.type?.allowsIncoming:!0}get name(){return this.label?.text||""}set name(t){this.label&&(this.label.text=t)}get look(){return this.selected?this.highlighted?this._selectedAndHighlightedLook!==void 0?this._selectedAndHighlightedLook:(this.type||Dt)?.selectedAndHighlightedLook:this._selectedLook!==void 0?this._selectedLook:(this.type||Dt)?.selectedLook:this.highlighted?this._highlightedLook!==void 0?this._highlightedLook:(this.type||Dt)?.highlightedLook:this._defaultLook!==void 0?this._defaultLook:(this.type||Dt)?.defaultLook}set look(t){this.lookConfig=t}get lookConfig(){return this._lookConfig}set lookConfig(t){if(this._lookConfig=t,t){const e=nt(t);this._defaultLook={...this._defaultLook,...e.defaultLook},this._selectedLook={...this._selectedLook,...e.selectedLook},this._highlightedLook={...this._highlightedLook,...e.highlightedLook},this._selectedAndHighlightedLook={...this._selectedAndHighlightedLook,...e.selectedAndHighlightedLook}}else this._defaultLook=t,this._selectedLook=t,this._highlightedLook=t,this._selectedAndHighlightedLook=t}get width(){return this.type?.width||Ue.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 U)return this.rootElement.node}getPriority(){return this.rootElement?.getPriority()||Nt}move(t){const e=[t[0]-this.coords[0],t[1]-this.coords[1]];this.coords=t,this.connectionPoint[0]=this.connectionPoint[0]+e[0],this.connectionPoint[1]=this.connectionPoint[1]+e[1];for(const a of this.outgoingConnections)a.setStart(this);for(const a of this.incomingConnections)a.setEnd(this);this.label&&this.label.move([this.label.coords[0]+e[0],this.label.coords[1]+e[1]]),this.updateInView()}distanceTo(t){return Re(this.coords,t)}}class Oo extends gt{constructor(t){super(),this.types=new Kt,this.model=t}new(t,e,a,l,r,i,n="floating",o="floating"){const d=new yt(this.model,t,e,a,l,r,i,n,o);return super.add(d),d.updateInView(),e!==void 0&&e.ports.push(d),d}remove(t){const e=this.get(t,!0);if(e){for(;e.outgoingConnections.length>0;)this.model.connections.remove(e.outgoingConnections[0].id);for(;e.incomingConnections.length>0;)this.model.connections.remove(e.incomingConnections[0].id);e.label&&this.model.fields.remove(e.label.id),(e.rootElement instanceof R||e.rootElement instanceof U)&&B(e.rootElement.ports,e),super.remove(t),e.updateInView()}}}class De{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 n=a.decorators[i];t.decorators.new(l,[l.coords[0]+n.coords[0],l.coords[1]+n.coords[1]],n.width,n.height,l.getPriority(),n.html,`${l.id}_decorator_${i}`)}if(a.label){const i={...O,...a.label},n=new ct(t,l,[l.coords[0]+D(i),l.coords[1]+G(i)],l.width-D(i)-it(i),l.height-G(i)-q(i),i.fontSize,i.fontFamily,i.color,i.selectedColor,i.horizontalAlign,i.verticalAlign,i.orientation,"",i.editable,i.fit,i.shrink);n.text=e.label,l.label=n,t.fields.add(n),n.updateInView()}}for(const i of e.children||[]){const n=this.importNode(t,i);n!==void 0&&(l.children?.push(n),n.parent=l)}for(const i of e.sections||[]){const n=new U(t,l,i.indexXInNode,i.indexYInNode,i.coords,i.width,i.height,i.id);if(l.sections?.push(n),t.sections.add(n),i.label&&a.sectionGrid?.sections?.[i.indexYInNode]?.[i.indexXInNode]?.label){const d={...O,...a.sectionGrid?.sections?.[i.indexYInNode]?.[i.indexXInNode]?.label},c=new ct(t,n,[n.coords[0]+D(d),n.coords[1]+G(d)],n.width-D(d)-it(d),n.height-G(d)-q(d),d.fontSize,d.fontFamily,d.color,d.selectedColor,d.horizontalAlign,d.verticalAlign,d.orientation,"",d.editable,d.fit,d.shrink);c.text=i.label,n.label=c,t.fields.add(c),c.updateInView()}let o=0;for(const d of i.ports||[]){const c=d.type!==void 0?t.ports.types.get(d.type):void 0,h=new yt(t,c,n,d.coords,d.connectionPoint||d.coords,d.direction,d.id);if(n.ports.push(h),t.ports.add(h),d.label){if(a.ports.length>o&&c?.label){const u={...O,...c?.label};let b;switch(h.direction){case f.Top:case f.Left:b=[h.coords[0]-u.fontSize,h.coords[1]-u.fontSize];break;case f.Bottom:b=[h.coords[0]-u.fontSize,h.coords[1]+u.fontSize];break;case f.Right:b=[h.coords[0]+u.fontSize,h.coords[1]-u.fontSize];break;default:b=h.coords}const m=new ct(t,h,b,u.fontSize,u.fontSize,u.fontSize,u.fontFamily,u.color,u.selectedColor,u.horizontalAlign,u.verticalAlign,u.orientation,"",u.editable,u.fit,u.shrink);m.text=d.label,h.label=m,t.fields.add(m),m.updateInView()}++o}d.collabMeta&&(h.selfRemoved=d.collabMeta.selfRemoved,h.selfRemovedTimestamp=d.collabMeta.selfRemovedTimestamp,this.importLabelCollabMeta(h.label,d.collabMeta.label)),h.updateInView()}i.collabMeta&&(n.selfRemoved=i.collabMeta.selfRemoved,n.selfRemovedTimestamp=i.collabMeta.selfRemovedTimestamp,this.importLabelCollabMeta(n.label,i.collabMeta.label)),n.updateInView()}let r=0;for(const i of e.ports||[]){const n=i.type!==void 0?t.ports.types.get(i.type):void 0,o=new yt(t,n,l,i.coords,i.connectionPoint||i.coords,i.direction,i.id);if(l.ports.push(o),t.ports.add(o),i.label){if(a.ports.length>r&&n?.label){const d={...O,...n?.label};let c;switch(o.direction){case f.Top:case f.Left:c=[o.coords[0]-d.fontSize,o.coords[1]-d.fontSize];break;case f.Bottom:c=[o.coords[0]-d.fontSize,o.coords[1]+d.fontSize];break;case f.Right:c=[o.coords[0]+d.fontSize,o.coords[1]-d.fontSize];break;default:c=o.coords}const h=new ct(t,o,c,d.fontSize,d.fontSize,d.fontSize,d.fontFamily,d.color,d.selectedColor,d.horizontalAlign,d.verticalAlign,d.orientation,"",d.editable,d.fit,d.shrink);h.text=i.label,o.label=h,t.fields.add(h),h.updateInView()}++r}i.collabMeta&&(o.selfRemoved=i.collabMeta.selfRemoved,o.selfRemovedTimestamp=i.collabMeta.selfRemovedTimestamp,this.importLabelCollabMeta(o.label,i.collabMeta.label)),o.updateInView()}return e.data&&l.valueSet.setValues(e.data),e.collabMeta&&(l.selfRemoved=e.collabMeta.selfRemoved,l.selfRemovedTimestamp=e.collabMeta.selfRemovedTimestamp,l.geometryTimestamp=e.collabMeta.geometryTimestamp,this.importLabelCollabMeta(l.label,e.collabMeta.label),l.valueSet.setTimestamps(e.collabMeta.dataTimestamps)),l.updateInView(),l.raise(),l}}importConnection(t,e){const a=t.connections.types.get(e.type);if(a){const l=new lt(t,a,e.start?t.ports.get(e.start):void 0,e.end?t.ports.get(e.end):void 0,e.id);return t.connections.add(l),l.startLabel=e.startLabel,l.middleLabel=e.middleLabel,l.endLabel=e.endLabel,l.points=e.points,e.data&&l.valueSet.setValues(e.data),e.collabMeta&&(l.selfRemoved=e.collabMeta.selfRemoved,l.selfRemovedTimestamp=e.collabMeta.selfRemovedTimestamp,l.valueSet.setTimestamps(e.collabMeta.dataTimestamps)),l.updateInView(),l.raise(),l}}importLabelCollabMeta(t,e){t&&e&&(t.selfRemoved=e.selfRemoved,t.selfRemovedTimestamp=e.selfRemovedTimestamp,t.textTimestamp=e.textTimestamp)}}class Jt{constructor(t,e,a,l,r,i,n){this.canvas=t,this.id=e,this.typeId=a,this.coords=l,this.parentId=r,this.label=i,this.values=n}do(){const t=this.canvas.model.nodes.new(this.typeId,this.coords,this.id);this.parentId!==void 0&&this.canvas.model.nodes.get(this.parentId)?.addChild(t),t.label&&(t.label.text=this.label||""),this.values!==void 0?t.valueSet.setValues(St({...t.valueSet.getValues(),...this.values})):t.valueSet.resetValues()}serialize(){return{type:"addNode",id:this.id,typeId:this.typeId,coords:this.coords,parentId:this.parentId,label:this.label,values:this.values}}static deserialize(t,e){return new Jt(t,e.id,e.typeId,e.coords,e.parentId,e.label,e.values)}}class me{constructor(t,e,a,l,r,i,n){this.canvas=t,this.nodeId=e,this.copyColumnIndex=a,this.copyRowIndex=l,this.removeColumnIndex=r,this.removeRowIndex=i,this.timestamp=n}do(){const t=this.canvas.model.nodes.get(this.nodeId);t&&bt(this.timestamp,t.geometryTimestamp)&&(this.copyColumnIndex!==void 0&&t.copySectionColumn(this.copyColumnIndex),this.copyRowIndex!==void 0&&t.copySectionRow(this.copyRowIndex),this.removeColumnIndex!==void 0&&t.removeSectionColumn(this.removeColumnIndex),this.removeRowIndex!==void 0&&t.removeSectionRow(this.removeRowIndex),t.geometryTimestamp=this.timestamp)}serialize(){return{type:"addSection",nodeId:this.nodeId,copyColumnIndex:this.copyColumnIndex,copyRowIndex:this.copyRowIndex,removeColumnIndex:this.removeColumnIndex,removeRowIndex:this.removeRowIndex,timestamp:this.timestamp}}static deserialize(t,e){return new me(t,e.nodeId,e.copyColumnIndex,e.copyRowIndex,e.removeColumnIndex,e.removeRowIndex,e.timestamp)}}class ve{constructor(t,e,a){this.canvas=t,this.to=e,this.timestamp=a}do(){for(const t in this.to){const e=this.canvas.model.nodes.get(t,!0);if(e&&bt(this.timestamp,e.geometryTimestamp)){const a=this.to[t];e.move([a[0],a[1]]),e.geometryTimestamp=this.timestamp}}}serialize(){return{type:"applyLayout",to:this.to,timestamp:this.timestamp}}static deserialize(t,e){return new ve(t,e.to,e.timestamp)}}class jt{constructor(t,e,a,l){this.canvas=t,this.nodeIds=e,this.delta=a,this.timestamp=l}do(){for(const t of this.nodeIds){const e=this.canvas.model.nodes.get(t,!0);e&&bt(this.timestamp,e.geometryTimestamp)&&(e.move([e.coords[0]+this.delta[0],e.coords[1]+this.delta[1]]),e.parent?.fitToChild(e),e.geometryTimestamp=this.timestamp)}}serialize(){return{type:"move",nodeIds:this.nodeIds,delta:this.delta,timestamp:this.timestamp}}static deserialize(t,e){return new jt(t,e.nodeIds,e.delta,e.timestamp)}}class st{constructor(t,e,a,l){this.canvas=t,this.nodeId=e,this.to=a,this.timestamp=l}do(){const t=this.canvas.model.nodes.get(this.nodeId,!0);if(t&&bt(this.timestamp,t.geometryTimestamp)){t.setGeometry(this.to),t.label?.fit&&this.canvas.fitFieldRootInView(t.label.id,t.label.shrink);for(const e of t.sections)e.label?.fit&&this.canvas.fitFieldRootInView(e.label.id,e.label.shrink);t.parent?.fitToChild(t),t.geometryTimestamp=this.timestamp}}serialize(){return{type:"setGeometry",nodeId:this.nodeId,to:this.to,timestamp:this.timestamp}}static deserialize(t,e){return new st(t,e.nodeId,e.to,e.timestamp)}}class Gt{constructor(t,e,a,l,r){this.canvas=t,this.childId=e,this.parentId=a,this.childGeometry=l,this.timestamp=r}do(){const t=this.canvas.model.nodes.get(this.childId,!0),e=this.parentId!==void 0?this.canvas.model.nodes.get(this.parentId,!0):void 0;t&&(this.parentId===void 0||e)&&bt(this.timestamp,t.geometryTimestamp)&&(t.parent?.removeChild(t),t.setGeometry(this.childGeometry),e?.addChild(t))}serialize(){return{type:"setParent",childId:this.childId,parentId:this.parentId,childGeometry:this.childGeometry,timestamp:this.timestamp}}static deserialize(t,e){return new Gt(t,e.childId,e.parentId,e.childGeometry,e.timestamp)}}class Qt{constructor(t,e,a,l,r){this.canvas=t,this.id=e,this.typeId=a,this.startId=l,this.endId=r}do(){const t=this.canvas.model.ports.get(this.startId,!0),e=this.canvas.model.ports.get(this.endId,!0);t&&e&&this.canvas.model.connections.new(this.typeId,t,e,this.id)}serialize(){return{type:"addConnection",id:this.id,typeId:this.typeId,startId:this.startId,endId:this.endId}}static deserialize(t,e){return new Qt(t,e.id,e.typeId,e.startId,e.endId)}}class Et{constructor(t,e,a,l){this.canvas=t,this.fieldId=e,this.to=a,this.timestamp=l}do(){const t=this.canvas.model.fields.get(this.fieldId,!0);t&&bt(this.timestamp,t.textTimestamp)&&(t.text=this.to,t.textTimestamp=this.timestamp)}serialize(){return{type:"editField",fieldId:this.fieldId,to:this.to,timestamp:this.timestamp}}static deserialize(t,e){return new Et(t,e.fieldId,e.to,e.timestamp)}}class Mt{constructor(t,e,a,l){this.canvas=t,this.id=e,this.to=a,this.timestamp=l}getValueSet(){return this.id===void 0?this.canvas.model.valueSet:(this.canvas.model.nodes.get(this.id,!0)||this.canvas.model.connections.get(this.id,!0))?.valueSet}do(){this.getValueSet()?.overwriteValuesLww(this.to,this.timestamp)}serialize(){return{type:"updateValues",id:this.id,to:this.to,timestamp:this.timestamp}}static deserialize(t,e){return new Mt(t,e.id,e.to,e.timestamp)}}class rt{constructor(t,e,a,l,r,i,n,o){this.canvas=t,this.nodeIds=e,this.sectionIds=a,this.portIds=l,this.connectionIds=r,this.fieldIds=i,this.selfRemoved=n,this.timestamp=o}doOne(t){t&&bt(this.timestamp,t.selfRemovedTimestamp)&&(t.selfRemoved=this.selfRemoved,t.selfRemovedTimestamp=this.timestamp)}do(){for(const t of this.nodeIds)this.doOne(this.canvas.model.nodes.get(t,!0));for(const t of this.sectionIds)this.doOne(this.canvas.model.sections.get(t,!0));for(const t of this.portIds)this.doOne(this.canvas.model.ports.get(t,!0));for(const t of this.connectionIds)this.doOne(this.canvas.model.connections.get(t,!0));for(const t of this.fieldIds)this.doOne(this.canvas.model.fields.get(t,!0));this.canvas.updateNodesInView(...this.nodeIds),this.canvas.updateSectionsInView(...this.sectionIds),this.canvas.updatePortsInView(...this.portIds),this.canvas.updateConnectionsInView(...this.connectionIds),this.canvas.updateFieldsInView(...this.fieldIds),this.canvas.updateDecoratorsInView()}serialize(){return{type:"setSelfRemoved",nodeIds:this.nodeIds,sectionIds:this.sectionIds,portIds:this.portIds,connectionIds:this.connectionIds,fieldIds:this.fieldIds,removed:this.selfRemoved,timestamp:this.timestamp}}static deserialize(t,e){return new rt(t,e.nodeIds,e.sectionIds,e.portIds,e.connectionIds,e.fieldIds,e.removed,e.timestamp)}}class te{constructor(t,e,a){this.canvas=t,this.nodes=e,this.connections=a}do(){const t=new De;this.canvas.userSelection.clear();for(const e of this.nodes){const a=t.importNode(this.canvas.model,e);a&&this.canvas.userSelection.add(a)}for(const e of this.connections){const a=t.importConnection(this.canvas.model,e);a&&this.canvas.userSelection.add(a)}}serialize(){return{type:"paste",nodes:this.nodes,connections:this.connections}}static deserialize(t,e){return new te(t,e.nodes,e.connections)}}class _o{constructor(t){this.isInRoom=!1,this.canvas=t,this.replicaId=$e()}freshTimestamp(){return this.canvas.model.logicalClock++,[this.canvas.model.logicalClock,this.replicaId]}freshId(){return"id"+$e()}doCollaboratively(t){if(t.do(),this.onSend){const e=t.serialize();this.onSend(e)}}receive(t){switch("timestamp"in t&&(this.canvas.model.logicalClock=Math.max(this.canvas.model.logicalClock,t.timestamp[0])),t.type){case"addNode":{Jt.deserialize(this.canvas,t).do();break}case"addSection":{me.deserialize(this.canvas,t).do();break}case"applyLayout":{ve.deserialize(this.canvas,t).do();break}case"move":{jt.deserialize(this.canvas,t).do();break}case"setGeometry":{st.deserialize(this.canvas,t).do();break}case"setParent":{Gt.deserialize(this.canvas,t).do();break}case"addConnection":{Qt.deserialize(this.canvas,t).do();break}case"editField":{Et.deserialize(this.canvas,t).do();break}case"updateValues":{Mt.deserialize(this.canvas,t).do();break}case"setSelfRemoved":{rt.deserialize(this.canvas,t).do();break}case"paste":{te.deserialize(this.canvas,t).do();break}default:console.error("Unknown CollabAction type, skipping:",t)}}}class Ho{constructor(t,e){this.canvas=t,this.maximum=e,this.history=[],this.index=0}add(t){this.index<this.history.length&&(this.history=this.history.slice(0,this.index)),this.history.length>=this.maximum?(this.history=this.history.slice(1,this.history.length),this.history.push(t)):(this.history.push(t),++this.index),this.canvas.diagramChange$.next({action:t,method:0})}undo(){let t;if(this.index>0){let e;do--this.index,t=this.history[this.index],e=t.undo();while(!e&&this.index>0)}this.canvas.diagramChange$.next({action:t,method:1})}redo(){let t;if(this.index<this.history.length){let e;do t=this.history[this.index],e=t.redo(),++this.index;while(!e&&this.index<this.history.length)}this.canvas.diagramChange$.next({action:t,method:2})}}var k=(s=>(s.AddConnection="add-connection",s.AddNode="add-node",s.AddSectionAction="add-section",s.ApplyLayout="apply-layout",s.Clipboard="clipboard",s.ContextMenu="context-menu",s.EditField="edit-field",s.MoveNode="move-node",s.Paste="paste",s.Remove="remove",s.StretchNode="stretch-node",s.StretchSection="stretch-section",s.UpdateValues="update-values",s.Zoom="zoom",s))(k||{});class jo{constructor(t,e,a,l,r,i,n,o,d){this.canvas=t,this.type=e,this.coords=a,this.parentId=l,this.ancestorId=r,this.fromAncestorGeometry=i,this.toAncestorGeometry=n,this.label=o,this.values=d,this.id=this.canvas.collabEngine.freshId()}do(){const t=new Jt(this.canvas,this.id,this.type.id,this.coords,this.parentId,this.label,this.values);if(this.canvas.collabEngine.doCollaboratively(t),this.ancestorId!==void 0&&this.toAncestorGeometry!==void 0){const e=new st(this.canvas,this.ancestorId,this.toAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(e)}return!0}undo(){const t=this.canvas.model.nodes.get(this.id),e=new rt(this.canvas,[this.id],[],[],[],[],!0,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(e),this.ancestorId!==void 0&&this.fromAncestorGeometry!==void 0){const a=new st(this.canvas,this.ancestorId,this.fromAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(a)}return t!==void 0}redo(){const t=this.canvas.model.nodes.get(this.id),e=new rt(this.canvas,[this.id],[],[],[],[],!1,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(e),this.ancestorId!==void 0&&this.toAncestorGeometry!==void 0){const a=new st(this.canvas,this.ancestorId,this.toAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(a)}return t===void 0}}class ie{constructor(t,e,a){this.canvas=t,this.nodeIds=e,this.delta=a}do(){const t=new jt(this.canvas,this.nodeIds,this.delta,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(t),this.nodeIds.map(e=>this.canvas.model.nodes.get(e)!==void 0).includes(!0)&&(this.delta[0]!==0||this.delta[1]!==0)}undo(){const t=new jt(this.canvas,this.nodeIds,[-this.delta[0],-this.delta[1]],this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(t),this.nodeIds.map(e=>this.canvas.model.nodes.get(e)!==void 0).includes(!0)&&(this.delta[0]!==0||this.delta[1]!==0)}redo(){return this.do()}}class X{constructor(t,e,a,l,r,i,n,o){this.canvas=t,this.intent=e,this.nodeId=a,this.from=l,this.to=r,this.ancestorId=i,this.fromAncestorGeometry=n,this.toAncestorGeometry=o}do(){const t=this.canvas.model.nodes.get(this.nodeId);if(t){const e=new st(this.canvas,this.nodeId,this.to,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(e),this.ancestorId!==void 0&&this.toAncestorGeometry!==void 0){const a=new st(this.canvas,this.ancestorId,this.toAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(a)}}return t!==void 0}undo(){const t=this.canvas.model.nodes.get(this.nodeId);if(t){this.to=t.getGeometry();const e=new st(this.canvas,this.nodeId,this.from,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(e),this.ancestorId!==void 0&&this.fromAncestorGeometry!==void 0){const a=new st(this.canvas,this.ancestorId,this.fromAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(a)}}return t!==void 0}redo(){const t=this.canvas.model.nodes.get(this.nodeId);if(t){this.from=t.getGeometry();const e=new st(this.canvas,this.nodeId,this.to,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(e)}return t!==void 0}}class Go{constructor(t,e,a,l,r,i,n,o,d){this.canvas=t,this.childId=e,this.fromParentId=a,this.toParentId=l,this.fromChildGeometry=r,this.toChildGeometry=i,this.ancestorId=n,this.fromAncestorGeometry=o,this.toAncestorGeometry=d}do(){const t=this.canvas.model.nodes.get(this.childId),e=new Gt(this.canvas,this.childId,this.toParentId,this.toChildGeometry,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(e),this.ancestorId!==void 0&&this.toAncestorGeometry!==void 0){const a=new st(this.canvas,this.ancestorId,this.toAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(a)}return t!==void 0}undo(){const t=this.canvas.model.nodes.get(this.childId),e=new Gt(this.canvas,this.childId,this.fromParentId,this.fromChildGeometry,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(e),this.ancestorId!==void 0&&this.fromAncestorGeometry!==void 0){const a=new st(this.canvas,this.ancestorId,this.fromAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(a)}return t!==void 0}redo(){return this.do()}}class se{constructor(t,e,a,l){this.canvas=t,this.type=e,this.startId=a,this.endId=l,this.id=this.canvas.collabEngine.freshId()}do(){const t=new Qt(this.canvas,this.id,this.type.id,this.startId,this.endId);return this.canvas.collabEngine.doCollaboratively(t),!0}undo(){const t=this.canvas.model.connections.get(this.id),e=new rt(this.canvas,[],[],[],[this.id],[],!0,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),t!==void 0}redo(){const t=this.canvas.model.connections.get(this.id),e=new rt(this.canvas,[],[],[],[this.id],[],!1,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),t===void 0}}class Ee{constructor(t,e,a,l){this.canvas=t,this.fieldId=e,this.from=a,this.to=l}do(){const t=this.canvas.model.fields.get(this.fieldId),e=new Et(this.canvas,this.fieldId,this.to,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),t!==void 0}undo(){const t=this.canvas.model.fields.get(this.fieldId);if(t){this.to=t.text;const e=new Et(this.canvas,this.fieldId,this.from,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(e)}return t!==void 0}redo(){const t=this.canvas.model.fields.get(this.fieldId);if(t){this.from=t.text;const e=new Et(this.canvas,this.fieldId,this.to,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(e)}return t!==void 0}}class Fo{constructor(t,e,a,l){this.canvas=t,this.id=e,this.from=a,this.to=l}do(){const t=new Mt(this.canvas,this.id,this.to,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(t),!0}undo(){const t=new Mt(this.canvas,this.id,this.from,this.canvas.collabEngine.freshTimestamp()),e=t.getValueSet();if(e)this.to=e.getValuesForKeys(this.to),this.canvas.collabEngine.doCollaboratively(t);else return!1;return!e.rootElement.removed}redo(){const t=new Mt(this.canvas,this.id,this.to,this.canvas.collabEngine.freshTimestamp()),e=t.getValueSet();if(e)this.from=e.getValuesForKeys(this.from),this.canvas.collabEngine.doCollaboratively(t);else return!1;return!e.rootElement.removed}}class Uo{constructor(t,e,a,l,r,i){this.canvas=t,this.nodeIds=e,this.sectionIds=a,this.portIds=l,this.connectionIds=r,this.fieldIds=i}do(){const t=this.nodeIds.map(a=>this.canvas.model.nodes.get(a)!==void 0).includes(!0)||this.sectionIds.map(a=>this.canvas.model.sections.get(a)!==void 0).includes(!0)||this.portIds.map(a=>this.canvas.model.ports.get(a)!==void 0).includes(!0)||this.connectionIds.map(a=>this.canvas.model.connections.get(a)!==void 0).includes(!0)||this.fieldIds.map(a=>this.canvas.model.fields.get(a)!==void 0).includes(!0),e=new rt(this.canvas,this.nodeIds,this.sectionIds,this.portIds,this.connectionIds,this.fieldIds,!0,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),t}undo(){const t=this.nodeIds.map(a=>this.canvas.model.nodes.get(a)===void 0).includes(!0)||this.sectionIds.map(a=>this.canvas.model.sections.get(a)===void 0).includes(!0)||this.portIds.map(a=>this.canvas.model.ports.get(a)===void 0).includes(!0)||this.connectionIds.map(a=>this.canvas.model.connections.get(a)===void 0).includes(!0)||this.fieldIds.map(a=>this.canvas.model.fields.get(a)===void 0).includes(!0),e=new rt(this.canvas,this.nodeIds,this.sectionIds,this.portIds,this.connectionIds,this.fieldIds,!1,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),t}redo(){return this.do()}}class Do{constructor(t,e,a,l){this.canvas=t,this.nodes=e,this.connections=a,this.coords=l}do(){const t=[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY];for(const r of this.nodes)r.coords[0]<t[0]&&(t[0]=r.coords[0]),r.coords[1]<t[1]&&(t[1]=r.coords[1]);const e=this.coords!==void 0?[this.coords[0]-t[0],this.coords[1]-t[1]]:void 0,a={};for(const r of this.nodes){const i=r.id,n=this.canvas.collabEngine.freshId();if(a[i]=n,r.id=n,e&&(r.coords=[r.coords[0]+e[0],r.coords[1]+e[1]]),r.sections)for(const o of r.sections){const d=o.id;if(o.id.includes(r.id)?o.id=o.id.replace(r.id,n):o.id=this.canvas.collabEngine.freshId(),a[d]=o.id,e&&(o.coords=[o.coords[0]+e[0],o.coords[1]+e[1]]),o.ports)for(const c of o.ports){const h=c.id;c.id.includes(r.id)?c.id=c.id.replace(r.id,n):c.id=this.canvas.collabEngine.freshId(),a[h]=c.id,e&&(c.coords=[c.coords[0]+e[0],c.coords[1]+e[1]],c.connectionPoint&&(c.connectionPoint=[c.connectionPoint[0]+e[0],c.connectionPoint[1]+e[1]]))}}if(r.ports)for(const o of r.ports){const d=o.id;o.id.includes(r.id)?o.id=o.id.replace(r.id,n):o.id=this.canvas.collabEngine.freshId(),a[d]=o.id,e&&(o.coords=[o.coords[0]+e[0],o.coords[1]+e[1]],o.connectionPoint&&(o.connectionPoint=[o.connectionPoint[0]+e[0],o.connectionPoint[1]+e[1]]))}}for(const r of this.connections){const i=this.canvas.collabEngine.freshId();if(a[r.id]=i,r.id=i,r.start=a[r.start]||r.start,r.end=a[r.end]||r.end,e)for(let n=0;n<r.points.length;++n)r.points[n]=[r.points[n][0]+e[0],r.points[n][1]+e[1]]}const l=new te(this.canvas,this.nodes,this.connections);return this.canvas.collabEngine.doCollaboratively(l),!0}undo(){const t=this.nodes.map(a=>this.canvas.model.nodes.get(a.id)!==void 0).includes(!0)||this.connections.map(a=>this.canvas.model.connections.get(a.id)!==void 0).includes(!0),e=new rt(this.canvas,this.nodes.map(a=>a.id),[],[],this.connections.map(a=>a.id),[],!0,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),t}redo(){const t=this.nodes.map(a=>this.canvas.model.nodes.get(a.id)===void 0).includes(!0)||this.connections.map(a=>this.canvas.model.connections.get(a.id)===void 0).includes(!0),e=new rt(this.canvas,this.nodes.map(a=>a.id),[],[],this.connections.map(a=>a.id),[],!1,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),t}}class Ft{constructor(t){this.type=t,this.defaultPrevented=!1}preventDefault(){this.defaultPrevented=!0}}var Be=(s=>(s[s.Zoom=0]="Zoom",s[s.DoubleClick=1]="DoubleClick",s[s.SecondaryClick=2]="SecondaryClick",s[s.Selection=3]="Selection",s[s.Highlight=4]="Highlight",s))(Be||{});class Bo extends Ft{constructor(t,e){super(0),this.coords=t,this.zoom=e}}class ut extends Ft{constructor(t,e,a){super(1),this.cause=t,this.target=e,this.coords=a}}class pt extends Ft{constructor(t,e,a){super(2),this.cause=t,this.target=e,this.coords=a}}class H extends Ft{constructor(t,e){super(3),this.targets=t,this.selected=e}}class Q extends Ft{constructor(t){super(4),this.target=t}}class Ye extends Ct{constructor(t,e,a,l,r,i,n,o,d="floating",c="floating"){if(t.objects.get(o)!==void 0)throw new Error(`DiagramDecorator with id "${o}" already exists`);if(!o)throw new Error("DiagramDecorator cannot have an empty or null id");super(t,o),this.rootElement=e,this.coords=a,this.width=l,this.height=r,this.priority=i,this.html=n,this.anchorPointX=d,this.anchorPointY=c}get removed(){return this.selfRemoved||this.rootElement!==void 0&&this.rootElement.removed}updateInView(){this.model.canvas?.updateDecoratorsInView(this.id)}raise(){this.select()?.raise()}move(t){this.coords=t,this.updateInView()}getPriority(){return this.priority}}class Yo extends gt{constructor(t){super(),this.model=t}new(t,e,a,l,r,i,n,o="floating",d="floating"){const c=new Ye(this.model,t,e,a,l,r,i,n,o,d);return super.add(c),c.updateInView(),t!==void 0&&t.decorators.push(c),c}remove(t){const e=this.get(t,!0);e&&((e.rootElement instanceof R||e.rootElement instanceof U)&&B(e.rootElement.decorators,e),super.remove(t),e.updateInView())}}class Xo extends Ct{constructor(t,e,a,l,r,i,n){if(t.objects.get(n)!==void 0)throw new Error(`DiagramObject with id "${n}" already exists`);if(!n)throw new Error("DiagramObject cannot have an empty or null id");super(t,n),this.coords=e,this.width=a,this.height=l,this.priority=r,this.html=i}get removed(){return this.selfRemoved}updateInView(){this.model.canvas?.updateObjectsInView(this.id)}raise(){this.select()?.raise()}move(t){this.coords=t,this.updateInView()}getPriority(){return this.priority}}class Wo extends gt{constructor(t){super(),this.model=t}new(t,e,a,l,r,i){const n=new Xo(this.model,t,e,a,l,r,i);return super.add(n),n.updateInView(),n}remove(t){const e=this.get(t,!0);e&&(super.remove(t),e.updateInView())}}class Xe{constructor(t,e,a,l,r,i=[]){this.nodes=new To(this),this.sections=new Mo(this),this.ports=new Oo(this),this.connections=new Co(this),this.fields=new $o(this),this.objects=new Wo(this),this.decorators=new Yo(this),this.canvas=t,this.id=e,this.name=a,this.description=l,this.type=r,this.createdAt=new Date,this.updatedAt=new Date,this.logicalClock=0,this.valueSet=new vt(new qt(i),this)}clear(){this.canvas?.cancelAllUserActions(),this.id=void 0,this.name="",this.description=void 0,this.createdAt=new Date,this.updatedAt=new Date,this.logicalClock=0,this.nodes.clear(),this.sections.clear(),this.ports.clear(),this.connections.clear(),this.fields.clear(),this.objects.clear(),this.decorators.clear(),this.valueSet.resetValues(),this.canvas?.updateModelInView()}}const mt=s=>!!s.button,ne=(s,t,e,a,l,r,i,n)=>ro(s,[t,e],a,l,Math.max(10,i||0,n||0)*r),w=s=>{s?A.select("body").style("cursor",s):A.select("body").style("cursor",L.Auto)},dt=s=>s instanceof R?s:s instanceof U?s.node||s:s.rootElement instanceof R||s.rootElement instanceof U||s.rootElement instanceof yt?dt(s.rootElement):s,re=s=>{s.filter(".shaped-look").append("path"),s.filter(".image-look").append("image").attr("preserveAspectRatio","none"),s.filter(".stretchable-image-look").append("image").attr("class","top-left-image").attr("preserveAspectRatio","none"),s.filter(".stretchable-image-look").append("image").attr("class","top-image").attr("preserveAspectRatio","none"),s.filter(".stretchable-image-look").append("image").attr("class","top-right-image").attr("preserveAspectRatio","none"),s.filter(".stretchable-image-look").append("image").attr("class","left-image").attr("preserveAspectRatio","none"),s.filter(".stretchable-image-look").append("image").attr("class","center-image").attr("preserveAspectRatio","none"),s.filter(".stretchable-image-look").append("image").attr("class","right-image").attr("preserveAspectRatio","none"),s.filter(".stretchable-image-look").append("image").attr("class","bottom-left-image").attr("preserveAspectRatio","none"),s.filter(".stretchable-image-look").append("image").attr("class","bottom-image").attr("preserveAspectRatio","none"),s.filter(".stretchable-image-look").append("image").attr("class","bottom-right-image").attr("preserveAspectRatio","none")},Rt={fillColor:"#FFFFFF",borderColor:"#000000",borderThickness:1,borderStyle:pe.Solid},ae=s=>{s.filter(".shaped-look").select("path").attr("d",t=>ge(t.look.shape||Tt.Rectangle,0,0,t.width,t.height)).attr("fill",t=>t.look.fillColor||Rt.fillColor).attr("stroke",t=>t.look.borderColor||Rt.borderColor).attr("stroke-width",t=>`${t.look.borderThickness||Rt.borderThickness}px`).attr("stroke-dasharray",t=>he(t.look.borderStyle||Rt.borderStyle,t.type?.defaultLook?.borderThickness||t.look?.borderThickness||Rt.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)},zt={style:"dots",color:"rgba(0, 0, 0, 0.1)",snap:!1,spacing:10,thickness:.05},Zo=(s,t,e)=>{const a=t.append("defs");if(s.gridSize>0&&isFinite(s.gridSize)){const l=a.append("pattern").attr("id",e).attr("x",-s.gridSize/2).attr("y",-s.gridSize/2).attr("width",s.gridSize).attr("height",s.gridSize).attr("patternUnits","userSpaceOnUse");switch(l.append("rect").attr("x",0).attr("y",0).attr("width",s.gridSize).attr("height",s.gridSize).attr("fill",s.backgroundColor),s.gridStyle){case"dots":l.append("circle").attr("cx",s.gridSize/2).attr("cy",s.gridSize/2).attr("r",s.gridSize*s.gridThickness).attr("fill",s.gridColor);break;case"lines":l.append("line").attr("x1",s.gridSize/2).attr("x2",s.gridSize/2).attr("y1",0).attr("y2",s.gridSize).attr("stroke-width",s.gridSize*s.gridThickness).attr("stroke",s.gridColor),l.append("line").attr("x1",0).attr("x2",(s.gridSize-s.gridSize*s.gridThickness)/2).attr("y1",s.gridSize/2).attr("y2",s.gridSize/2).attr("stroke-width",s.gridSize*s.gridThickness).attr("stroke",s.gridColor),l.append("line").attr("x1",(s.gridSize+s.gridSize*s.gridThickness)/2).attr("x2",s.gridSize).attr("y1",s.gridSize/2).attr("y2",s.gridSize/2).attr("stroke-width",s.gridSize*s.gridThickness).attr("stroke",s.gridColor);break}t.select("rect").attr("fill",`url(#${e})`)}},fe=96,W=32,At=fe+W,Ko=Math.PI/4,qo=100,Me={customButtons:[]};class Jo{constructor(t,e){this.canvas=t,this.config=e||Me}open(t){this.close();const e=this.canvas.getPointerLocationRelativeToRoot(t),a=this.canvas.getPointerLocationRelativeToCanvas(t),l=this.canvas.selectSVGElement().append("foreignObject").attr("class","daga-context-menu").attr("x",`${e[0]-At}px`).attr("y",`${e[1]-At}px`).attr("width",`${2*At}px`).attr("height",`${2*At}px`).style("pointer-events","none").on(S.ContextMenu,i=>{this.canvas.canUserPerformAction(k.ContextMenu)&&(t.preventDefault(),this.open(i))}).on(S.Click,i=>{i.preventDefault(),this.close()});this.contextMenuContainer=l;const r=[];this.canvas.userSelection.length!==0&&this.canvas.canUserPerformAction(k.Clipboard)&&this.canvas.canUserPerformAction(k.Remove)&&r.push({name:"CUT",imageClass:"daga-cut",onPress:i=>{i.userSelection.cutToClipboard(),i.cancelAllUserActions()}}),this.canvas.userSelection.length!==0&&this.canvas.canUserPerformAction(k.Clipboard)&&r.push({name:"COPY",imageClass:"daga-copy",onPress:i=>{i.userSelection.copyToClipboard(),i.cancelAllUserActions()}}),this.canvas.canUserPerformAction(k.Paste)&&r.push({name:"PASTE",imageClass:"daga-paste",onPress:i=>{i.userSelection.pasteFromClipboard(i.getClosestGridPoint(a)),i.cancelAllUserActions()}}),this.canvas.userSelection.length!==0&&this.canvas.canUserPerformAction(k.Remove)&&r.push({name:"DELETE",imageClass:"daga-delete",onPress:i=>{i.userSelection.removeFromModel(),i.cancelAllUserActions()}});for(const i of this.config.customButtons||Me.customButtons)(i.condition===void 0||i.condition(this.canvas))&&r.push(i);r.length===0&&r.push({name:"NONE",imageClass:"daga-cross",onPress:void 0});for(let i=0;i<r.length;++i){const n=r[i],o=n.onPress,d=(i+.5-r.length/2)*Ko,c=l.append("xhtml:div").attr("class",`daga-context-menu-button ${n.onPress!==void 0?" daga-clickable":""}`).attr("tabindex",0).style("position","absolute").style("box-sizing","border-box").style("width",`${2*W}px`).style("height",`${2*W}px`).style("border-radius",`${W}px`).style("pointer-events","auto").on(S.Click,h=>{o&&(h.preventDefault(),o(this.canvas))}).on(S.KeyDown,h=>{o&&h.key===K.Enter&&(h.preventDefault(),o(this.canvas))});n.imageClass!==void 0?c.append("xhtml:div").style("position","absolute").style("left",`${.75*W}px`).style("top",`${.5*W}px`).style("width",`${.5*W}px`).style("height",`${.5*W}px`).style("background-size","contain").style("background-repeat","no-repeat").attr("class",n.imageClass):n.image!==void 0&&c.append("xhtml:img").style("position","absolute").style("left",`${.75*W}px`).style("top",`${.5*W}px`).style("width",`${.5*W}px`).style("height",`${.5*W}px`).attr("src",n.image),c.append("xhtml:span").style("position","absolute").style("left",`${.2*W}px`).style("top",`${1.1*W}px`).style("text-align","center").style("width",`${1.6*W}px`).style("height",`${.35*W}px`).style("margin","0").style("font-size",`${.35*W}px`).style("font-weight","700").style("user-select","none").text(n.name),c.transition().ease(A.easeLinear).duration(qo).tween("progress",()=>h=>{const u=d*h;return c.style("left",`${Math.sin(u)*fe-W+At}px`).style("top",`${-Math.cos(u)*fe-W+At}px`)})}}close(){this.contextMenuContainer?.remove(),this.contextMenuContainer=void 0}}class Qo extends gt{constructor(t,e=!0){super(),this.focus=void 0,this.canvas=t,this.highlightSections=e}getFocus(){return this.focus}focusOn(t){this.clear(),this.focus=t,(t instanceof ct||t instanceof Ye)&&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 U)if(!this.highlightSections&&t.node)this.add(t.node);else{for(const e of t.ports)super.add(e),this.canvas.updatePortsInView(e.id);t.label&&(super.add(t.label),this.canvas.updateFieldsInView(t.label.id)),this.canvas.updateSectionsInView(t.id)}else t instanceof yt?(t.label&&(super.add(t.label),this.canvas.updateFieldsInView(t.label.id)),this.canvas.updatePortsInView(t.id)):t instanceof lt&&this.canvas.updateConnectionsInView(t.id)}clear(){for(;this.entities.length>0;){const t=this.entities[0];this.remove(t.id),t.updateInView()}this.focus=void 0}}const ti=1;class We{export(t,e=!1){const a={name:t.name,type:t.type,typeVersion:ti,createdAt:t.createdAt,updatedAt:t.updatedAt,nodes:[],connections:[],data:t.valueSet.getValues(),...e?{collabMeta:{logicalClock:t.logicalClock,dataTimestamps:t.valueSet.getTimestamps()}}:{}};t.id&&(a.id=t.id),t.description&&(a.description=t.description);for(const l of t.nodes.all(!0))!e&&l.removed||l.parent===void 0&&a.nodes.push(this.exportNode(l,e));for(const l of t.connections.all(!0))!e&&l.removed||a.connections.push(this.exportConnection(l,e));return a}exportNode(t,e=!1){const a=[];for(const i of t.children)a.push(this.exportNode(i,e));const l=[];for(const i of t.sections){const n=[];for(const o of i.ports)n.push({id:o.id,type:o.type?.id,coords:It(o.coords),connectionPoint:It(o.connectionPoint||o.coords),direction:o.direction,label:o.label?.text||"",...e?{collabMeta:{removed:o.removed,selfRemoved:o.selfRemoved,selfRemovedTimestamp:o.selfRemovedTimestamp,...this.exportLabelCollabMeta(o)}}:{}});l.push({id:i.id,ports:n,label:i.label?.text||"",indexXInNode:i.indexXInNode,indexYInNode:i.indexYInNode,coords:It(i.coords),width:i.width,height:i.height,...e?{collabMeta:{removed:i.removed,selfRemoved:i.selfRemoved,selfRemovedTimestamp:i.selfRemovedTimestamp,...this.exportLabelCollabMeta(i)}}:{}})}const r=[];for(const i of t.ports)r.push({id:i.id,type:i.type?.id,coords:It(i.coords),connectionPoint:It(i.connectionPoint||i.coords),direction:i.direction,label:i.label?.text||"",...e?{collabMeta:{removed:i.removed,selfRemoved:i.selfRemoved,selfRemovedTimestamp:i.selfRemovedTimestamp,...this.exportLabelCollabMeta(i)}}:{}});return{id:t.id,type:t.type.id,children:a,sections:l,ports:r,label:t.label?.text||"",coords:It(t.coords),width:t.width,height:t.height,data:t.valueSet.getValues(),...e?{collabMeta:{removed:t.removed,selfRemoved:t.selfRemoved,selfRemovedTimestamp:t.selfRemovedTimestamp,geometryTimestamp:t.geometryTimestamp,dataTimestamps:t.valueSet.getTimestamps(),...this.exportLabelCollabMeta(t)}}:{}}}exportConnection(t,e=!1){return{id:t.id,type:t.type.id,start:t.start?.id||"",end:t.end?.id||"",startLabel:t.startLabel,middleLabel:t.middleLabel,endLabel:t.endLabel,points:t.points,data:t.valueSet.getValues(),...e?{collabMeta:{removed:t.removed,selfRemoved:t.selfRemoved,selfRemovedTimestamp:t.selfRemovedTimestamp,dataTimestamps:t.valueSet.getTimestamps()}}:{}}}exportLabelCollabMeta({label:t}){return t?{label:{removed:t.removed,selfRemoved:t.selfRemoved,selfRemovedTimestamp:t.selfRemovedTimestamp,textTimestamp:t.textTimestamp}}:{}}}const ei="Diagram properties";class oi extends gt{constructor(t,e){super(),this.canvas=t,this.canvas.propertyEditorChanges$.pipe(kt.debounceTime(2e3)).subscribe(()=>{this.makeUpdateValuesAction()}),this.diagramPropertiesText=e!==void 0?e:ei}add(t){if(!this.contains(t.id)&&(this.length===0?this.propertyEditorSelection===void 0&&(t instanceof R||t instanceof lt)?this.openInPropertyEditor(t):this.propertyEditorSelection===void 0&&t instanceof U?this.openInPropertyEditor(t.node):this.openInPropertyEditor(void 0):this.openInPropertyEditor(void 0),super.add(t),t.updateInView(),t instanceof 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=[],r=[];for(const n of this.all())n instanceof R?t.push(n.id):n instanceof U?e.push(n.id):n instanceof yt?a.push(n.id):n instanceof lt?l.push(n.id):n instanceof ct&&r.push(n.id);const i=new Uo(this.canvas,t,e,a,l,r);i.do(),this.canvas.actionStack.add(i)}}copyToClipboard(){const t={type:"daga-user-selection",nodes:[],connections:[]},e=new We;for(const a of this.all())a instanceof R&&t.nodes.push(e.exportNode(a,!1)),a instanceof lt&&t.connections.push(e.exportConnection(a,!1));navigator.clipboard.writeText(JSON.stringify(t))}cutToClipboard(){this.copyToClipboard(),this.removeFromModel()}pasteFromClipboard(t){navigator.clipboard.readText().then(e=>{try{const a=JSON.parse(e);if(a.type!=="daga-user-selection")return;const l=new Do(this.canvas,a.nodes,a.connections,t);this.canvas.actionStack.add(l),l.do()}catch{return}})}openInPropertyEditor(t,e=!0){e&&this.makeUpdateValuesAction();const a=this.canvas.parentComponent?.propertyEditor;if(a===void 0)return;const l=t?.valueSet;l?(this.propertyEditorSelection=t,e&&(this.propertyEditorValues=St(l.getValues())),a&&(t instanceof R||t instanceof lt?(t instanceof R?t.name?a.title=`${t.type.name}: ${t.name}`:a.title=t.type.name:t instanceof lt&&(a.title=t.type.name),a.valueSet=void 0,a.valueSet=l):(a.title=this.diagramPropertiesText,a.valueSet=void 0,a.valueSet=l))):(this.propertyEditorSelection=void 0,this.propertyEditorValues=void 0,a&&(a.title="",a.valueSet=void 0))}makeUpdateValuesAction(){if(this.propertyEditorSelection===void 0||this.propertyEditorValues===void 0)return;const t=this.propertyEditorSelection instanceof Xe?void 0:this.propertyEditorSelection.id;if(wt(this.propertyEditorValues,this.propertyEditorSelection?.valueSet.getValues()))return;const e=this.propertyEditorValues,a=St(this.propertyEditorSelection?.valueSet.getValues()),[l,r]=Oe(e,a,this.propertyEditorSelection?.valueSet),i=new Fo(this.canvas,t,l,r);i.do(),this.canvas.actionStack.add(i),this.propertyEditorValues=a}}const ii=s=>s*Math.PI/180,Te=(s,t,e)=>{const a=ii(e),l=Math.sin(a),r=Math.cos(a),i=(Math.abs(s*r)-Math.abs(t*l))/(r*r-l*l),n=(Math.abs(s*l)-Math.abs(t*r))/(l*l-r*r);return[i,n]},si=12,_=6,ni=25,le="diagram-connection-unfinished",Zt=class Zt{constructor(t,e){if(this.backgroundPatternId=`daga-background-pattern-id-${Zt.canvasCount++}`,this.zoomTransform=A.zoomIdentity,this.draggingFrom=[0,0],this.dragging=!1,this.secondaryButton=!1,this.validatorChange$=new kt.Subject,this.diagramChange$=new kt.Subject,this.diagramEvent$=new kt.Subject,this.propertyEditorChanges$=new kt.Subject,this.parentComponent=t,this.model=new Xe(this,void 0,e.name||"unnamed","",e.type||"",e.properties||[]),this.userSelection=new oi(this,e.components?.propertyEditor?.title),this.userHighlight=new Qo(this,e.canvas?.highlightSections!==!1),this.contextMenu=new Jo(this,e.canvas?.contextMenu),this.backgroundColor=e.canvas?.backgroundColor||"#FFFFFF",this.gridStyle=e.canvas?.grid?.style??zt.style,this.gridSize=e.canvas?.grid?.enabled===!1||e.canvas?.grid===void 0?0:Math.abs(e.canvas?.grid?.spacing||zt.spacing),this.gridThickness=Math.abs(e.canvas?.grid?.thickness||zt.thickness),this.gridColor=e.canvas?.grid?.color||zt.color,this.snapToGrid=e.canvas?.grid?.enabled===!1||e.canvas?.grid===void 0?!1:e.canvas?.grid?.snap||zt.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 Ho(this,ni),this.collabEngine=new _o(this),e.nodeTypes)for(const a of e.nodeTypes){const l=new je({...e.nodeTypeDefaults,...a});this.model.nodes.types.add(l)}if(e.portTypes)for(const a of e.portTypes){const l=new Vo({...e.portTypeDefaults,...a});this.model.ports.types.add(l)}if(e.connectionTypes){for(const a of e.connectionTypes){const l=new _e({...e.connectionTypeDefaults,...a});this.model.connections.types.add(l)}this._connectionType=e?.connectionSettings?.defaultConnection!==void 0?this.model.connections.types.get(e.connectionSettings.defaultConnection):void 0}}get connectionType(){return this._connectionType}set connectionType(t){this._connectionType=t,this.parentComponent?.palette?.refreshPalette()}addValidator(t){this.validators.push(t),this.validatorChange$.next()}removeValidator(t){B(this.validators,t),this.validatorChange$.next()}getPriorityThresholdOptions(){return this.priorityThresholds}getPriorityThreshold(){return this.priorityThreshold}setPriorityThreshold(t){this.priorityThreshold=t,this.updateModelInView();for(const e of this.model.nodes)this.fitNodeInView(e.id);this.parentComponent?.palette?.refreshPalette()}initView(t){const e=A.select(t);e.html(""),this.diagramRoot=e.append("div").node(),A.select(this.diagramRoot).attr("tabindex",0).style("width","100%").style("height","100%").append("svg").style("width","100%").style("height","100%"),A.select(this.diagramRoot).on(S.Click,()=>{A.select(this.diagramRoot).node()?.focus()}).on(S.ContextMenu,l=>{if(this.dragging){l.preventDefault(),l.stopPropagation(),this.dragging=!1;return}const r=new pt(l,null);this.diagramEvent$.next(r),!r.defaultPrevented&&this.canUserPerformAction(k.ContextMenu)&&(l.preventDefault(),this.contextMenu.open(l))}).on(S.DoubleClick,l=>{const r=new ut(l,null);this.diagramEvent$.next(r)}).on(S.KeyDown,l=>{if(!l.ctrlKey&&(l.key===K.Delete||l.key===K.Backspace)&&this.canUserPerformAction(k.Remove)&&(this.userSelection.removeFromModel(),this.cancelAllUserActions()),l.ctrlKey&&l.key==="a"){l.preventDefault();for(const r of this.model.nodes)this.userSelection.add(r);for(const r of this.model.connections)this.userSelection.add(r);this.diagramEvent$.next(new H(this.userSelection.all(),!0))}if(l.ctrlKey&&l.key==="i"){l.preventDefault();const r=[],i=[];for(const n of this.model.nodes)this.userSelection.toggle(n),n.selected?r.push(n):i.push(n);for(const n of this.model.connections)this.userSelection.toggle(n),n.selected?r.push(n):i.push(n);r.length>0&&this.diagramEvent$.next(new H(r,!0)),i.length>0&&this.diagramEvent$.next(new H(i,!1))}if(l.ctrlKey&&l.key==="c"&&this.canUserPerformAction(k.Clipboard)&&(l.preventDefault(),this.userSelection.copyToClipboard(),this.cancelAllUserActions()),l.ctrlKey&&l.key==="x"&&this.canUserPerformAction(k.Clipboard)&&this.canUserPerformAction(k.Remove)&&(l.preventDefault(),this.userSelection.cutToClipboard(),this.cancelAllUserActions()),l.ctrlKey&&l.key==="v"&&this.canUserPerformAction(k.Paste)){l.preventDefault();const r=this.getCoordinatesOnScreen();this.userSelection.pasteFromClipboard(this.getClosestGridPoint([(r[0][0]+r[1][0])/2,(r[0][1]+r[1][1])/2])),this.cancelAllUserActions()}l.ctrlKey&&l.key==="y"&&(l.preventDefault(),this.actionStack.redo()),l.ctrlKey&&l.key==="z"&&(l.preventDefault(),this.actionStack.undo()),l.key==="+"&&this.canUserPerformAction(k.Zoom)&&(l.preventDefault(),this.zoomBy(this.zoomFactor)),l.key==="-"&&this.canUserPerformAction(k.Zoom)&&(l.preventDefault(),this.zoomBy(1/this.zoomFactor)),l.key===K.ArrowLeft&&this.canUserPerformAction(k.Zoom)&&(l.preventDefault(),this.translateBy(this.panRate/this.zoomTransform.k,0)),l.key===K.ArrowRight&&this.canUserPerformAction(k.Zoom)&&(l.preventDefault(),this.translateBy(-this.panRate/this.zoomTransform.k,0)),l.key===K.ArrowDown&&this.canUserPerformAction(k.Zoom)&&(l.preventDefault(),this.translateBy(0,-this.panRate/this.zoomTransform.k)),l.key===K.ArrowUp&&this.canUserPerformAction(k.Zoom)&&(l.preventDefault(),this.translateBy(0,this.panRate/this.zoomTransform.k))});const a=this.selectSVGElement().append("g").attr("class","daga-canvas-view").attr("width","100%").attr("height","100%");a.call(this.zoomBehavior=A.zoom().filter(l=>l.type!==S.DoubleClick).on(de.Zoom,l=>{if(l.sourceEvent){if(!this.canUserPerformAction(k.Zoom)){w(L.NotAllowed);return}l.sourceEvent.type===S.Wheel&&l.sourceEvent.wheelDelta!==void 0?(l.sourceEvent.wheelDelta>0&&w(L.ZoomIn),l.sourceEvent.wheelDelta<0&&w(L.ZoomOut)):l.sourceEvent.type===S.MouseMove&&w(L.AllScroll)}this.zoomTransform=l.transform;const r=l.transform.toString();this.selectCanvasElements().attr("transform",r),A.select(`#${this.backgroundPatternId}`).attr("patternTransform",r),this.contextMenu.close(),this.diagramEvent$.next(new Bo([this.zoomTransform.x,this.zoomTransform.y],this.zoomTransform.k))}).on(de.End,()=>{w()})),a.append("rect").attr("x",0).attr("y",0).attr("width","100%").attr("height","100%").attr("fill",this.backgroundColor).attr("stroke-width","0").on(S.MouseMove,l=>{if(this.unfinishedConnection!==void 0){const r=this.getPointerLocationRelativeToCanvas(l);this.unfinishedConnection.endCoords=r}}).on(S.MouseOver,()=>{this.userHighlight.size()>0&&(this.userHighlight.clear(),this.diagramEvent$.next(new Q(null)))}).on(S.Click,()=>{if(this.userHighlight.size()>0&&(this.userHighlight.clear(),this.diagramEvent$.next(new Q(null))),this.contextMenu.close(),this.userSelection.size()>0){const l=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new H(l,!1))}this.userSelection.openInPropertyEditor(this.model)}).call(A.drag().filter(l=>this.multipleSelectionOn||mt(l)).on($.Start,l=>{this.startMultipleSelection(l)}).on($.Drag,l=>{this.continueMultipleSelection(l)}).on($.End,l=>{this.finishMultipleSelection(l)})),Zo(this,a,this.backgroundPatternId),a.append("g").attr("class","daga-canvas-elements")}getZoomLevel(){return this.zoomTransform.k}zoomBy(t){isNaN(t)||this.zoomBehavior.scaleBy(this.selectCanvasView(),t)}zoomTo(t){isNaN(t)||this.zoomBehavior.scaleTo(this.selectCanvasView(),t)}getViewCoordinates(){return[this.zoomTransform.x,this.zoomTransform.y]}translateBy(t,e){!isNaN(t)&&!isNaN(e)&&this.zoomBehavior.translateBy(this.selectCanvasView(),t,e)}translateTo(t,e){!isNaN(t)&&!isNaN(e)&&this.zoomBehavior.translateTo(this.selectCanvasView(),t,e)}center(){if(this.model.nodes.length>0){const t=this.selectCanvasView().select("rect").node()?.getBBox(),e=this.model.nodes.all(),a=Math.min(...e.map(m=>m.coords[0])),l=Math.max(...e.map(m=>m.coords[0]+m.width)),r=(a+l)/2,i=l-a,n=t.width,o=Math.min(...e.map(m=>m.coords[1])),d=Math.max(...e.map(m=>m.coords[1]+m.height)),c=(o+d)/2,h=d-o,u=t.height,b=Math.min(n/i,u/h,1);this.translateTo(r,c),this.zoomTo(b)}}getClosestGridPoint(t){return this.gridSize===0||!isFinite(this.gridSize)?t:[Math.round(t[0]/this.gridSize)*this.gridSize,Math.round(t[1]/this.gridSize)*this.gridSize]}getCoordinatesOnScreen(){const t=this.selectSVGElement().node()?.getBoundingClientRect(),e=[t?.width||0,t?.height||0];return[[-this.zoomTransform.x/this.zoomTransform.k,-this.zoomTransform.y/this.zoomTransform.k],[(e[0]-this.zoomTransform.x)/this.zoomTransform.k,(e[1]-this.zoomTransform.y)/this.zoomTransform.k]]}getEventHoldingCoordinates(t){if(t.type==="drag"||t.type==="start"||t.type==="end"){const e=t.sourceEvent;if(e&&(e.type==="touchmove"||e.type==="touchstart"||e.type==="touchend"))return t.sourceEvent.touches[0]||t.sourceEvent.changedTouches[0]}return t}getPointerLocationRelativeToCanvas(t){return A.pointer(this.getEventHoldingCoordinates(t),this.selectCanvasElements().node())}getPointerLocationRelativeToRoot(t){return A.pointer(this.getEventHoldingCoordinates(t),this.selectSVGElement().node())}getPointerLocationRelativeToBody(t){return A.pointer(this.getEventHoldingCoordinates(t),A.select("body").node())}getPointerLocationRelativeToScreen(t){const e=this.getPointerLocationRelativeToBody(t);return[e[0]-window.scrollX,e[1]-window.scrollY]}updateModelInView(){this.updateNodesInView(),this.updateSectionsInView(),this.updatePortsInView(),this.updateConnectionsInView(),this.updateFieldsInView(),this.updateObjectsInView(),this.updateDecoratorsInView()}updateNodesInView(...t){let e=this.selectCanvasElements().selectAll("g.diagram-node").data(this.model.nodes.filter(i=>this.priorityThreshold!==void 0?i.getPriority()>=this.priorityThreshold:!0),i=>i.id);const a=e.exit(),l=e.enter().append("g").attr("id",i=>i.id).attr("class",i=>`diagram-node${i.type.resizableX?" resizable-x":""}${i.type.resizableY?" resizable-y":""} ${i.type.defaultLook.lookType}`);t&&t.length>0&&(e=e.filter(i=>t.includes(i.id)));const r=l.merge(e);a.remove(),l.on(S.MouseOver,(i,n)=>{this.dragging||(this.userHighlight.focusOn(n),this.diagramEvent$.next(new Q(n)))}).on(S.Click,(i,n)=>{if(!i.ctrlKey&&!i.shiftKey){const o=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new H(o,!1))}this.userSelection.toggle(n),this.diagramEvent$.next(new H([n],n.selected))}).on(S.ContextMenu,(i,n)=>{if(this.dragging){i.preventDefault(),i.stopPropagation(),this.dragging=!1;return}const o=new pt(i,n);this.diagramEvent$.next(o),!o.defaultPrevented&&this.canUserPerformAction(k.ContextMenu)&&(i.preventDefault(),this.userHighlight.focusOn(n),this.diagramEvent$.next(new Q(n)),this.userSelection.add(n),this.diagramEvent$.next(new H([n],!0)),this.contextMenu.open(i))}).on(S.DoubleClick,(i,n)=>{const o=new ut(i,n);this.diagramEvent$.next(o)}).call(A.drag().filter(i=>(this.secondaryButton=mt(i),!0)).on($.Start,(i,n)=>{this.multipleSelectionOn||this.secondaryButton?this.startMultipleSelection(i):this.startMovingNode(i,n)}).on($.Drag,(i,n)=>{this.multipleSelectionOn||this.secondaryButton?this.continueMultipleSelection(i):this.continueMovingNode(i,n)}).on($.End,(i,n)=>{this.multipleSelectionOn||this.secondaryButton?this.finishMultipleSelection(i):this.finishMovingNode(i,n),this.secondaryButton=!1})),re(l),l.filter(".resizable-x").append("line").attr("class","left-resizer").attr("stroke","transparent").attr("stroke-width",`${_}px`).on(S.MouseOver,(i,n)=>{this.canUserPerformAction(k.StretchNode)&&n.type.resizableX&&!n.removed&&w(L.EWResize)}).on(S.MouseOut,(i,n)=>{this.canUserPerformAction(k.StretchNode)&&n.type.resizableX&&!n.removed&&w()}).call(A.drag().on($.Start,(i,n)=>{this.canUserPerformAction(k.StretchNode)&&n.type.resizableX&&!n.removed?(w(L.EWResize),this.currentAction=new X(this,k.StretchNode,n.id,n.getGeometry(),n.getGeometry())):w(L.NotAllowed)}).on($.Drag,(i,n)=>{if(this.canUserPerformAction(k.StretchNode)&&n.type.resizableX&&!n.removed){const o=this.getPointerLocationRelativeToCanvas(i);n.stretch(f.Left,n.coords[0]-o[0])}}).on($.End,(i,n)=>{if(this.canUserPerformAction(k.StretchNode)&&n.type.resizableX&&!n.removed&&this.currentAction instanceof X&&this.currentAction.intent===k.StretchNode){let o=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(o=this.getClosestGridPoint([o[0]-n.type.snapToGridOffset[0],o[1]-n.type.snapToGridOffset[1]]),o[0]+=n.type.snapToGridOffset[0],o[1]+=n.type.snapToGridOffset[1]),n.stretch(f.Left,n.coords[0]-o[0]),this.currentAction.to=n.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}w()})),l.filter(".resizable-y").append("line").attr("class","top-resizer").attr("stroke","transparent").attr("stroke-width",`${_}px`).on(S.MouseOver,(i,n)=>{this.canUserPerformAction(k.StretchNode)&&n.type.resizableY&&!n.removed&&w(L.NSResize)}).on(S.MouseOut,(i,n)=>{this.canUserPerformAction(k.StretchNode)&&n.type.resizableY&&!n.removed&&w()}).call(A.drag().on($.Start,(i,n)=>{this.canUserPerformAction(k.StretchNode)&&n.type.resizableY&&!n.removed?(w(L.NSResize),this.currentAction=new X(this,k.StretchNode,n.id,n.getGeometry(),n.getGeometry())):w(L.NotAllowed)}).on($.Drag,(i,n)=>{if(this.canUserPerformAction(k.StretchNode)&&n.type.resizableY&&!n.removed){const o=this.getPointerLocationRelativeToCanvas(i);n.stretch(f.Top,n.coords[1]-o[1])}}).on($.End,(i,n)=>{if(this.canUserPerformAction(k.StretchNode)&&n.type.resizableY&&!n.removed&&this.currentAction instanceof X&&this.currentAction.intent===k.StretchNode){let o=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(o=this.getClosestGridPoint([o[0]-n.type.snapToGridOffset[0],o[1]-n.type.snapToGridOffset[1]]),o[0]+=n.type.snapToGridOffset[0],o[1]+=n.type.snapToGridOffset[1]),n.stretch(f.Top,n.coords[1]-o[1]),this.currentAction.to=n.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}w()})),l.filter(".resizable-x").append("line").attr("class","right-resizer").attr("stroke","transparent").attr("stroke-width",`${_}px`).on(S.MouseOver,(i,n)=>{this.canUserPerformAction(k.StretchNode)&&n.type.resizableX&&!n.removed&&w(L.EWResize)}).on(S.MouseOut,(i,n)=>{this.canUserPerformAction(k.StretchNode)&&n.type.resizableX&&!n.removed&&w()}).call(A.drag().on($.Start,(i,n)=>{this.canUserPerformAction(k.StretchNode)&&n.type.resizableX&&!n.removed?(w(L.EWResize),this.currentAction=new X(this,k.StretchNode,n.id,n.getGeometry(),n.getGeometry())):w(L.NotAllowed)}).on($.Drag,(i,n)=>{if(this.canUserPerformAction(k.StretchNode)&&n.type.resizableX&&!n.removed){const o=this.getPointerLocationRelativeToCanvas(i);n.stretch(f.Right,o[0]-(n.coords[0]+n.width))}}).on($.End,(i,n)=>{if(this.canUserPerformAction(k.StretchNode)&&n.type.resizableX&&!n.removed&&this.currentAction instanceof X&&this.currentAction.intent===k.StretchNode){let o=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(o=this.getClosestGridPoint([o[0]-n.type.snapToGridOffset[2],o[1]-n.type.snapToGridOffset[3]]),o[0]+=n.type.snapToGridOffset[2],o[1]+=n.type.snapToGridOffset[3]),n.stretch(f.Right,o[0]-(n.coords[0]+n.width)),this.currentAction.to=n.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}w()})),l.filter(".resizable-y").append("line").attr("class","bottom-resizer").attr("stroke","transparent").attr("stroke-width",`${_}px`).on(S.MouseOver,(i,n)=>{this.canUserPerformAction(k.StretchNode)&&n.type.resizableY&&!n.removed&&w(L.NSResize)}).on(S.MouseOut,(i,n)=>{this.canUserPerformAction(k.StretchNode)&&n.type.resizableY&&!n.removed&&w()}).call(A.drag().on($.Start,(i,n)=>{this.canUserPerformAction(k.StretchNode)&&n.type.resizableY&&!n.removed?(w(L.NSResize),this.currentAction=new X(this,k.StretchNode,n.id,n.getGeometry(),n.getGeometry())):w(L.NotAllowed)}).on($.Drag,(i,n)=>{if(this.canUserPerformAction(k.StretchNode)&&n.type.resizableY&&!n.removed){const o=this.getPointerLocationRelativeToCanvas(i);n.stretch(f.Bottom,o[1]-(n.coords[1]+n.height))}}).on($.End,(i,n)=>{if(this.canUserPerformAction(k.StretchNode)&&n.type.resizableY&&!n.removed&&this.currentAction instanceof X&&this.currentAction.intent===k.StretchNode){let o=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&this.snapToGrid&&(o=this.getClosestGridPoint([o[0]-n.type.snapToGridOffset[2],o[1]-n.type.snapToGridOffset[3]]),o[0]+=n.type.snapToGridOffset[2],o[1]+=n.type.snapToGridOffset[3]),n.stretch(f.Bottom,o[1]-(n.coords[1]+n.height)),this.currentAction.to=n.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}w()})),r.attr("transform",i=>`translate(${i.coords[0]},${i.coords[1]})`).attr("opacity",i=>i.removed?.5:1),ae(r),r.filter(".resizable-x").select("line.left-resizer").attr("x1",_/2).attr("x2",_/2).attr("y1",0).attr("y2",i=>i.height),r.filter(".resizable-y").select("line.top-resizer").attr("x1",0).attr("x2",i=>i.width).attr("y1",_/2).attr("y2",_/2),r.filter(".resizable-x").select("line.right-resizer").attr("x1",i=>i.width-_/2).attr("x2",i=>i.width-_/2).attr("y1",0).attr("y2",i=>i.height),r.filter(".resizable-y").select("line.bottom-resizer").attr("x1",0).attr("x2",i=>i.width).attr("y1",i=>i.height-_/2).attr("y2",i=>i.height-_/2)}updateSectionsInView(...t){let e=this.selectCanvasElements().selectAll("g.diagram-section").data(this.model.sections.filter(i=>this.priorityThreshold!==void 0?i.getPriority()>=this.priorityThreshold:!0),i=>i.id);const a=e.exit(),l=e.enter().append("g").attr("id",i=>i.id).attr("class",i=>`diagram-section${i.getResizableX()?" resizable-x":""}${i.getResizableY()?" resizable-y":""} ${i.look?.lookType}`);t&&t.length>0&&(e=e.filter(i=>t.includes(i.id)));const r=l.merge(e);a.remove(),l.on(S.MouseOver,(i,n)=>{this.dragging||(this.userHighlight.focusOn(n),this.diagramEvent$.next(new Q(n)))}).on(S.Click,(i,n)=>{if(!i.ctrlKey&&!i.shiftKey){const d=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new H(d,!1))}const o=dt(n);this.userSelection.toggle(o),this.diagramEvent$.next(new H([o],o.selected))}).on(S.ContextMenu,(i,n)=>{if(this.dragging){i.preventDefault(),i.stopPropagation(),this.dragging=!1;return}const o=new pt(i,n);if(this.diagramEvent$.next(o),!o.defaultPrevented&&this.canUserPerformAction(k.ContextMenu)){i.preventDefault();const d=dt(n);this.userHighlight.focusOn(d),this.diagramEvent$.next(new Q(d)),this.userSelection.add(d),this.diagramEvent$.next(new H([d],!0)),this.contextMenu.open(i)}}).on(S.DoubleClick,(i,n)=>{const o=new ut(i,n);this.diagramEvent$.next(o)}).call(A.drag().filter(i=>(this.secondaryButton=mt(i),!0)).on($.Start,(i,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.startMultipleSelection(i);else{const o=n?.node;o?this.startMovingNode(i,o):w(L.NotAllowed)}}).on($.Drag,(i,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(i);else{const o=n?.node;o?this.continueMovingNode(i,o):w(L.NotAllowed)}}).on($.End,(i,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(i);else{const o=n?.node;o?this.finishMovingNode(i,o):w()}this.secondaryButton=!1})),re(l),l.filter(".resizable-x").append("line").attr("class","left-resizer").attr("stroke","transparent").attr("stroke-width",`${_}px`).on(S.MouseOver,(i,n)=>{this.canUserPerformAction(k.StretchSection)&&n.getResizableX()&&!n.removed&&w(L.EWResize)}).on(S.MouseOut,(i,n)=>{this.canUserPerformAction(k.StretchSection)&&n.getResizableX()&&!n.removed&&w()}).call(A.drag().on($.Start,(i,n)=>{this.canUserPerformAction(k.StretchSection)&&n.getResizableX()&&!n.removed&&n.node?(w(L.EWResize),this.currentAction=new X(this,k.StretchSection,n.node.id,n.node.getGeometry(),n.node.getGeometry())):w(L.NotAllowed)}).on($.Drag,(i,n)=>{if(this.canUserPerformAction(k.StretchSection)&&n.getResizableX()&&!n.removed&&n.node){const o=this.getPointerLocationRelativeToCanvas(i);n.node.stretchSections(f.Left,n.coords[0]-o[0],n.indexXInNode,n.indexYInNode)}}).on($.End,(i,n)=>{if(this.canUserPerformAction(k.StretchSection)&&n.getResizableX()&&!n.removed&&this.currentAction instanceof X&&this.currentAction.intent===k.StretchSection&&n.node){let o=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(o=this.getClosestGridPoint(o)),n.node.stretchSections(f.Left,n.coords[0]-o[0],n.indexXInNode,n.indexYInNode),this.currentAction.to=n.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}w()})),l.filter(".resizable-y").append("line").attr("class","top-resizer").attr("stroke","transparent").attr("stroke-width",`${_}px`).on(S.MouseOver,(i,n)=>{this.canUserPerformAction(k.StretchSection)&&n.getResizableY()&&!n.removed&&w(L.NSResize)}).on(S.MouseOut,(i,n)=>{this.canUserPerformAction(k.StretchSection)&&n.getResizableY()&&!n.removed&&w()}).call(A.drag().on($.Start,(i,n)=>{this.canUserPerformAction(k.StretchSection)&&n.getResizableY()&&!n.removed&&n.node?(w(L.NSResize),this.currentAction=new X(this,k.StretchSection,n.node.id,n.node.getGeometry(),n.node.getGeometry())):w(L.NotAllowed)}).on($.Drag,(i,n)=>{if(this.canUserPerformAction(k.StretchSection)&&n.getResizableY()&&!n.removed&&n.node){const o=this.getPointerLocationRelativeToCanvas(i);n.node.stretchSections(f.Top,n.coords[1]-o[1],n.indexXInNode,n.indexYInNode)}}).on($.End,(i,n)=>{if(this.canUserPerformAction(k.StretchSection)&&n.getResizableY()&&!n.removed&&this.currentAction instanceof X&&this.currentAction.intent===k.StretchSection&&n.node){let o=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(o=this.getClosestGridPoint(o)),n.node.stretchSections(f.Top,n.coords[1]-o[1],n.indexXInNode,n.indexYInNode),this.currentAction.to=n.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}w()})),l.filter(".resizable-x").append("line").attr("class","right-resizer").attr("stroke","transparent").attr("stroke-width",`${_}px`).on(S.MouseOver,(i,n)=>{this.canUserPerformAction(k.StretchSection)&&n.getResizableX()&&!n.removed&&w(L.EWResize)}).on(S.MouseOut,(i,n)=>{this.canUserPerformAction(k.StretchSection)&&n.getResizableX()&&!n.removed&&w()}).call(A.drag().on($.Start,(i,n)=>{this.canUserPerformAction(k.StretchSection)&&n.getResizableX()&&!n.removed&&n.node?(w(L.EWResize),this.currentAction=new X(this,k.StretchSection,n.node.id,n.node.getGeometry(),n.node.getGeometry())):w(L.NotAllowed)}).on($.Drag,(i,n)=>{if(this.canUserPerformAction(k.StretchSection)&&n.getResizableX()&&!n.removed&&n.node){const o=this.getPointerLocationRelativeToCanvas(i);n.node.stretchSections(f.Right,o[0]-(n.coords[0]+n.width),n.indexXInNode,n.indexYInNode)}}).on($.End,(i,n)=>{if(this.canUserPerformAction(k.StretchSection)&&n.getResizableX()&&!n.removed&&this.currentAction instanceof X&&this.currentAction.intent===k.StretchSection&&n.node){let o=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(o=this.getClosestGridPoint(o)),n.node.stretchSections(f.Right,o[0]-(n.coords[0]+n.width),n.indexXInNode,n.indexYInNode),this.currentAction.to=n.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}w()})),l.filter(".resizable-y").append("line").attr("class","bottom-resizer").attr("stroke","transparent").attr("stroke-width",`${_}px`).on(S.MouseOver,(i,n)=>{this.canUserPerformAction(k.StretchSection)&&n.getResizableY()&&!n.removed&&w(L.NSResize)}).on(S.MouseOut,(i,n)=>{this.canUserPerformAction(k.StretchSection)&&n.getResizableY()&&!n.removed&&w()}).call(A.drag().on($.Start,(i,n)=>{this.canUserPerformAction(k.StretchSection)&&n.getResizableY()&&!n.removed&&n.node?(w(L.NSResize),this.currentAction=new X(this,k.StretchSection,n.node.id,n.node.getGeometry(),n.node.getGeometry())):w(L.NotAllowed)}).on($.Drag,(i,n)=>{if(this.canUserPerformAction(k.StretchSection)&&n.getResizableY()&&!n.removed&&n.node){const o=this.getPointerLocationRelativeToCanvas(i);n.node.stretchSections(f.Bottom,o[1]-(n.coords[1]+n.height),n.indexXInNode,n.indexYInNode)}}).on($.End,(i,n)=>{if(this.canUserPerformAction(k.StretchSection)&&n.getResizableY()&&!n.removed&&this.currentAction instanceof X&&this.currentAction.intent===k.StretchSection&&n.node){let o=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(o=this.getClosestGridPoint(o)),n.node.stretchSections(f.Bottom,o[1]-(n.coords[1]+n.height),n.indexXInNode,n.indexYInNode),this.currentAction.to=n.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}w()})),r.attr("transform",i=>`translate(${i.coords[0]},${i.coords[1]})`).attr("opacity",i=>i.removed?.5:1),ae(r),r.filter(".resizable-x").select("line.left-resizer").attr("x1",_/2).attr("x2",_/2).attr("y1",0).attr("y2",i=>i.height),r.filter(".resizable-y").select("line.top-resizer").attr("x1",0).attr("x2",i=>i.width).attr("y1",_/2).attr("y2",_/2),r.filter(".resizable-x").select("line.right-resizer").attr("x1",i=>i.width-_/2).attr("x2",i=>i.width-_/2).attr("y1",0).attr("y2",i=>i.height),r.filter(".resizable-y").select("line.bottom-resizer").attr("x1",0).attr("x2",i=>i.width).attr("y1",i=>i.height-_/2).attr("y2",i=>i.height-_/2)}updatePortsInView(...t){let e=this.selectCanvasElements().selectAll("g.diagram-port").data(this.model.ports.filter(i=>this.priorityThreshold!==void 0?i.getPriority()>=this.priorityThreshold:!0),i=>i.id);const a=e.exit(),l=e.enter().append("g").attr("id",i=>i.id).attr("class",i=>`diagram-port ${i.look.lookType}`);t&&t.length>0&&(e=e.filter(i=>t.includes(i.id)));const r=l.merge(e);a.remove(),l.on(S.MouseOver,(i,n)=>{!this.unfinishedConnection&&!this.dragging&&(this.userHighlight.focusOn(n),this.diagramEvent$.next(new Q(n))),this.unfinishedConnection&&(this.unfinishedConnection.type.canStartFromType(this.unfinishedConnection.start?.getNode()?.type?.id||"")&&this.unfinishedConnection.start?.allowsOutgoing&&this.unfinishedConnection.type.canFinishOnType(n.getNode()?.type?.id||"")&&n.allowsIncoming||this.unfinishedConnection.type.canStartFromType(n.getNode()?.type?.id||"")&&n.allowsOutgoing&&this.unfinishedConnection.type.canFinishOnType(this.unfinishedConnection.start?.getNode()?.type?.id||"")&&this.unfinishedConnection.start?.allowsIncoming||w(L.NoDrop))}).on(S.MouseOut,()=>{this.unfinishedConnection&&w(L.Grabbing)}).on(S.Click,(i,n)=>{if(!i.ctrlKey&&!i.shiftKey){const d=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new H(d,!1))}const o=dt(n);this.userSelection.toggle(o),this.diagramEvent$.next(new H([o],o.selected))}).on(S.ContextMenu,(i,n)=>{if(this.dragging){i.preventDefault(),i.stopPropagation(),this.dragging=!1;return}const o=new pt(i,n);if(this.diagramEvent$.next(o),!o.defaultPrevented&&this.canUserPerformAction(k.ContextMenu)){i.preventDefault();const d=dt(n);this.userHighlight.focusOn(d),this.diagramEvent$.next(new Q(d)),this.userSelection.add(d),this.diagramEvent$.next(new H([d],!0)),this.contextMenu.open(i)}}).on(S.DoubleClick,(i,n)=>{const o=new ut(i,n);this.diagramEvent$.next(o)}).call(A.drag().filter(i=>(this.secondaryButton=mt(i),!0)).on($.Start,(i,n)=>{this.multipleSelectionOn||this.secondaryButton?this.startMultipleSelection(i):this.canUserPerformAction(k.AddConnection)&&(this.allowSharingPorts||n.incomingConnections.filter(o=>!o.removed).length===0&&n.outgoingConnections.filter(o=>!o.removed).length===0)&&!n.removed?(w(L.Grabbing),this.startConnection(n),this.unfinishedConnection&&(this.unfinishedConnectionTracer=this.selectCanvasElements().append("path").attr("stroke","none").attr("fill","none"))):w(L.NotAllowed)}).on($.Drag,(i,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(i);else if(this.canUserPerformAction(k.AddConnection)&&!n.removed&&this.unfinishedConnection!==void 0){const o=[i.x,i.y];this.unfinishedConnectionTracer?.attr("d",ne(this.unfinishedConnection.look.shape||ot.look.shape,this.unfinishedConnection.startCoords,o,this.unfinishedConnection.startDirection,this.unfinishedConnection.endDirection,this.unfinishedConnection.type.defaultLook.thickness||ot.look.thickness,this.unfinishedConnection.type.defaultStartMarkerLook?.width,this.unfinishedConnection.type.defaultEndMarkerLook?.width));const d=this.unfinishedConnectionTracer?.node();if(d){let c=2;const h=d.getTotalLength();h<c&&(c=0);const u=d.getPointAtLength(h-c);this.unfinishedConnection.endCoords=[u.x,u.y]}else this.unfinishedConnection.endCoords=o;if(this.updateConnectionsInView(le),this.model.ports.length>0){const c=this.getPointerLocationRelativeToCanvas(i);let h=Number.POSITIVE_INFINITY,u;for(const b of this.model.ports){const m=b.distanceTo(c);m<h&&(h=m,u=b)}u&&h<this.portHighlightRadius?this.userHighlight.focusOn(u):this.userHighlight.clear()}}}).on($.End,(i,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(i);else{if(this.canUserPerformAction(k.AddConnection)&&!n.removed){this.unfinishedConnectionTracer?.remove();const o=this.userHighlight.getFocus();if(o instanceof yt)this.finishConnection(o);else if(o instanceof ct&&o.rootElement instanceof yt)this.finishConnection(o.rootElement);else if(o instanceof R||o instanceof U||o instanceof ct){let d;if(o instanceof R||o instanceof U)d=o;else if(o.rootElement instanceof R||o.rootElement instanceof U)d=o.rootElement;else{this.dropConnection();return}const c=d.getClosestPortToPoint([i.x,i.y]);c!==void 0?this.finishConnection(c):this.dropConnection()}else this.dropConnection()}w()}this.secondaryButton=!1})),l.filter(".image-look").append("image"),re(l),r.attr("transform",i=>`translate(${i.coords[0]-i.width/2},${i.coords[1]-i.width/2})`).attr("opacity",i=>i.removed?.5:1),ae(r)}updateConnectionsInView(...t){const e=this.model.connections.filter(n=>this.priorityThreshold!==void 0?n.getPriority()>=this.priorityThreshold:!0);this.unfinishedConnection&&e.push(this.unfinishedConnection);let a=this.selectCanvasElements().selectAll("g.diagram-connection").data(e,n=>n.id);const l=a.exit(),r=a.enter().append("g").attr("id",n=>n.id).attr("class","diagram-connection");t&&t.length>0&&(a=a.filter(n=>t.includes(n.id)));const i=r.merge(a);l.remove(),r.on(S.MouseOver,(n,o)=>{o.end!==void 0&&!this.dragging&&(this.userHighlight.focusOn(o),this.diagramEvent$.next(new Q(o)))}).on(S.Click,(n,o)=>{if(!n.ctrlKey&&!n.shiftKey){const d=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new H(d,!1))}this.userSelection.toggle(o),this.diagramEvent$.next(new H([o],o.selected))}).on(S.ContextMenu,(n,o)=>{if(this.dragging){n.preventDefault(),n.stopPropagation(),this.dragging=!1;return}const d=new pt(n,o);this.diagramEvent$.next(d),!d.defaultPrevented&&this.canUserPerformAction(k.ContextMenu)&&(n.preventDefault(),this.userHighlight.focusOn(o),this.diagramEvent$.next(new Q(o)),this.userSelection.add(o),this.diagramEvent$.next(new H([o],!0)),this.contextMenu.open(n))}).on(S.DoubleClick,(n,o)=>{const d=new ut(n,o);this.diagramEvent$.next(d)}).call(A.drag().filter(n=>(this.secondaryButton=mt(n),!0)).on($.Start,n=>{this.startMultipleSelection(n)}).on($.Drag,n=>{this.continueMultipleSelection(n)}).on($.End,n=>{this.finishMultipleSelection(n)})),r.append("path").attr("class","diagram-connection-path"),r.append("path").attr("class","diagram-connection-path-box"),r.append("marker").attr("id",n=>`${n.id}-start-marker`).attr("class","diagram-connection-start-marker").append("image").attr("preserveAspectRatio","none"),r.append("marker").attr("id",n=>`${n.id}-end-marker`).attr("class","diagram-connection-end-marker").append("image").attr("preserveAspectRatio","none"),r.append("g").attr("class","diagram-connection-start-label"),r.select("g.diagram-connection-start-label").append("path"),r.select("g.diagram-connection-start-label").append("text").style("user-select","none"),r.append("g").attr("class","diagram-connection-middle-label"),r.select("g.diagram-connection-middle-label").append("path"),r.select("g.diagram-connection-middle-label").append("text").style("user-select","none"),r.append("g").attr("class","diagram-connection-end-label"),r.select("g.diagram-connection-end-label").append("path"),r.select("g.diagram-connection-end-label").append("text").style("user-select","none"),i.attr("opacity",n=>n.removed?.5:1).select("path.diagram-connection-path").attr("d",n=>ne(n.look.shape||ot.look.shape,n.startCoords,n.endCoords,n.startDirection,n.endDirection,n.type.defaultLook.thickness||ot.look.thickness,n.type.defaultStartMarkerLook?.width,n.type.defaultEndMarkerLook?.width)).attr("marker-start",n=>`url(#${n.id}-start-marker)`).attr("marker-end",n=>`url(#${n.id}-end-marker)`).attr("stroke",n=>n.look.color||ot.look.color).attr("stroke-width",n=>`${n.look.thickness}px`).attr("stroke-dasharray",n=>he(n.look.style||ot.look.style,n.type.defaultLook.thickness||ot.look.thickness)).attr("fill","none"),i.select("path.diagram-connection-path-box").attr("d",n=>ne(n.look.shape||ot.look.shape,n.startCoords,n.endCoords,n.startDirection,n.endDirection,n.type.defaultLook.thickness||ot.look.thickness,n.type.defaultStartMarkerLook?.width,n.type.defaultEndMarkerLook?.width)).attr("stroke","transparent").attr("pointer-events","stroke").attr("stroke-width",n=>`${(n.look.thickness||ot.look.thickness)+si}px`).attr("stroke-dasharray",n=>he(n.look.style||ot.look.style,n.type.defaultLook.thickness||ot.look.thickness)).attr("fill","none"),i.data().forEach(n=>{this.updateConnectionLabelsInView(n),this.updateConnectionMarkersInView(n)})}updateFieldsInView(...t){let e=this.selectCanvasElements().selectAll("foreignObject.diagram-field").data(this.model.fields.filter(i=>this.priorityThreshold!==void 0?i.getPriority()>=this.priorityThreshold:!0),i=>i.id);const a=e.exit(),l=e.enter().append("foreignObject").attr("id",i=>i.id).attr("class","diagram-field");t&&t.length>0&&(e=e.filter(i=>t.includes(i.id)));const r=l.merge(e);a.remove(),l.style("box-sizing","border-box").on(S.MouseOver,(i,n)=>{this.dragging||(this.userHighlight.focusOn(n),this.diagramEvent$.next(new Q(n)))}).on(S.Click,(i,n)=>{if(!i.ctrlKey&&!i.shiftKey){const d=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new H(d,!1))}const o=dt(n);this.userSelection.toggle(o),this.diagramEvent$.next(new H([o],o.selected))}).on(S.ContextMenu,(i,n)=>{if(this.dragging){i.preventDefault(),i.stopPropagation(),this.dragging=!1;return}const o=new pt(i,n);if(this.diagramEvent$.next(o),!o.defaultPrevented&&this.canUserPerformAction(k.ContextMenu)){i.preventDefault();const d=dt(n);this.userHighlight.focusOn(d),this.diagramEvent$.next(new Q(d)),this.userSelection.add(d),this.diagramEvent$.next(new H([d],!0)),this.contextMenu.open(i)}}).on(S.DoubleClick,(i,n)=>{const o=new ut(i,n);this.diagramEvent$.next(o),!o.defaultPrevented&&this.canUserPerformAction(k.EditField)&&n.editable&&!n.removed&&(this.currentAction=new Ee(this,n.id,n.text,""),this.createInputField(n.text,n.coords,n.width,n.height,n.fontSize,n.fontFamily||O.fontFamily,n.orientation,()=>{},d=>{n.text=d,this.currentAction instanceof Ee&&(this.currentAction.to=d,this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0)}))}).call(A.drag().filter(i=>(this.secondaryButton=mt(i),!0)).on($.Start,(i,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.startMultipleSelection(i);else{let o;n.rootElement instanceof R?o=n.rootElement:n.rootElement instanceof U&&(o=n.rootElement.node),o?this.startMovingNode(i,o):w(L.NotAllowed)}}).on($.Drag,(i,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(i);else{let o;n.rootElement instanceof R?o=n.rootElement:n.rootElement instanceof U&&(o=n.rootElement.node),o?this.continueMovingNode(i,o):w(L.NotAllowed)}}).on($.End,(i,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(i);else{let o;n.rootElement instanceof R?o=n.rootElement:n.rootElement instanceof U&&(o=n.rootElement.node),o?this.finishMovingNode(i,o):w()}this.secondaryButton=!1})).append("xhtml:div").style("width","100%").style("height","100%").style("display","flex").append("xhtml:p").style("box-sizing","border-box").style("outline",0).style("margin",0).style("border",0).style("padding",0).style("user-select","none").style("font-kerning","none").style("white-space","nowrap"),r.attr("x",0).attr("y",0).attr("width",i=>`${i.width}px`).attr("height",i=>`${i.height}px`).attr("transform",i=>`translate(${i.coords[0]},${i.coords[1]})`).attr("opacity",i=>i.removed?.5:1).select("div").style("justify-content",i=>i.horizontalAlign===Lt.Center?"center":i.horizontalAlign===Lt.Right?"flex-end":"flex-start").style("align-items",i=>i.verticalAlign===Xt.Center?"center":i.verticalAlign===Xt.Bottom?"end":"start").select("p").style("max-width",i=>i.fit?"default":`${Te(i.width,i.height,i.orientation)[0]}px`).style("max-height",i=>i.fit?"default":`${Te(i.width,i.height,i.orientation)[1]}px`).style("overflow",i=>i.fit?"default":"clip").style("text-overflow",i=>i.fit?"default":"ellipsis").style("text-align",i=>i.horizontalAlign===Lt.Center?"center":i.horizontalAlign===Lt.Right?"end":"start").style("transform",i=>`rotate(${i.orientation}deg)`).style("font-size",i=>`${i.fontSize}px`).style("font-family",i=>i.fontFamily||"'Wonder Unit Sans', sans-serif").style("font-weight",i=>i.highlighted?600:400).style("color",i=>i.selected?i.selectedColor||"#000000":i.color||"#000000").html(i=>i.text.replace(/</g,"<").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(S.ContextMenu,(i,n)=>{if(this.dragging){i.preventDefault(),i.stopPropagation(),this.dragging=!1;return}const o=new pt(i,n);this.diagramEvent$.next(o),!o.defaultPrevented&&this.canUserPerformAction(k.ContextMenu)&&(i.preventDefault(),this.contextMenu.open(i))}).on(S.DoubleClick,(i,n)=>{const o=new ut(i,n);this.diagramEvent$.next(o)}).call(A.drag().filter(i=>(this.secondaryButton=mt(i),!0)).on($.Start,i=>{(this.multipleSelectionOn||this.secondaryButton)&&this.startMultipleSelection(i)}).on($.Drag,i=>{(this.multipleSelectionOn||this.secondaryButton)&&this.continueMultipleSelection(i)}).on($.End,i=>{(this.multipleSelectionOn||this.secondaryButton)&&this.finishMultipleSelection(i)}))}updateDecoratorsInView(...t){let e=this.selectCanvasElements().selectAll("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(S.MouseOver,(i,n)=>{this.dragging||(this.userHighlight.focusOn(n),this.diagramEvent$.next(new Q(n)))}).on(S.Click,(i,n)=>{if(!i.ctrlKey&&!i.shiftKey){const o=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new H(o,!1))}if(n.rootElement){const o=dt(n.rootElement);this.userSelection.toggle(o),this.diagramEvent$.next(new H([o],o.selected))}}).on(S.ContextMenu,(i,n)=>{if(this.dragging){i.preventDefault(),i.stopPropagation(),this.dragging=!1;return}const o=new pt(i,n);if(this.diagramEvent$.next(o),!o.defaultPrevented&&this.canUserPerformAction(k.ContextMenu)&&n.rootElement){i.preventDefault();const d=dt(n.rootElement);this.userHighlight.focusOn(d),this.diagramEvent$.next(new Q(d)),this.userSelection.add(d),this.diagramEvent$.next(new H([d],!0)),this.contextMenu.open(i)}}).on(S.DoubleClick,(i,n)=>{const o=new ut(i,n);this.diagramEvent$.next(o)}).call(A.drag().filter(i=>(this.secondaryButton=mt(i),!0)).on($.Start,(i,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.startMultipleSelection(i);else{let o;n.rootElement instanceof R?o=n.rootElement:n.rootElement instanceof U&&(o=n.rootElement.node),o?this.startMovingNode(i,o):w(L.NotAllowed)}}).on($.Drag,(i,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(i);else{let o;n.rootElement instanceof R?o=n.rootElement:n.rootElement instanceof U&&(o=n.rootElement.node),o?this.continueMovingNode(i,o):w(L.NotAllowed)}}).on($.End,(i,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(i);else{let o;n.rootElement instanceof R?o=n.rootElement:n.rootElement instanceof U&&(o=n.rootElement.node),o?this.finishMovingNode(i,o):w()}this.secondaryButton=!1}))}updateConnectionLabelsInView(t){const e=this.selectCanvasView().select(`[id='${ce(t.id)}']`),l=e.select("path").node(),r={...O,...t.type.label};if(l){const i=l.getTotalLength();let n=0,o=0,d=0,c=0,h=0,u=0;if(r.backgroundColor==="#00000000"){const g=t.endCoords[0]-t.startCoords[0],v=t.endCoords[1]-t.startCoords[1];switch(t.startDirection){case f.Top:n=g>=0?-.5:.5,h=n;break;case f.Bottom:n=g>=0?-.5:.5,h=n;break;case f.Left:o=v>0?-.5:.5,u=o;break;case f.Right:o=v>0?-.5:.5,u=o;break;default:n=.5,h=n,o=-.5,u=o}switch(t.endDirection){case f.Top:h=g>=0?.5:-.5;break;case f.Bottom:h=g>=0?.5:-.5;break;case f.Left:u=v>0?.5:-.5;break;case f.Right:u=v>0?.5:-.5;break;default:h=.5,u=-.5}Math.abs(g)>=Math.abs(v)?(d=g>0?-.5:.5,c=v>0?.5:-.5):(d=g>0?.5:-.5,c=v>0?-.5:.5)}e.select("g.diagram-connection-start-label text").attr("x",0).attr("y",r.fontSize/3).attr("text-anchor","middle").attr("font-family",r.fontFamily).attr("font-size",r.fontSize).attr("fill",t.selected?r.selectedColor:r.color).style("font-kerning","none").text(t.startLabel);const b=e.select("g.diagram-connection-start-label text").node()?.getBoundingClientRect();if(b){const g=t.startLabel?b.width/this.zoomTransform.k+Ot(r)+_t(r):0,v=t.startLabel?b.height/this.zoomTransform.k+Ht(r)+Vt(r):0;let y;switch(t.startDirection){case f.Left:y=l.getPointAtLength(it(r)+g/2);break;case f.Right:y=l.getPointAtLength(D(r)+g/2);break;case f.Top:y=l.getPointAtLength(q(r)+g/2);break;case f.Bottom:y=l.getPointAtLength(G(r)+g/2);break;default:y=l.getPointAtLength(Math.max(D(r)+g/2,it(r)+g/2,G(r)+v/2,q(r)+v/2))}e.select("g.diagram-connection-start-label path").attr("d",Yt(-g/2,-v/2,g,v)).attr("fill",r.backgroundColor).attr("stroke","none"),e.select("g.diagram-connection-start-label").attr("transform",`translate(${y.x+n*g},${y.y+o*v})`)}e.select("g.diagram-connection-middle-label text").attr("x",0).attr("y",r.fontSize/3).attr("text-anchor","middle").attr("font-family",r.fontFamily).attr("font-size",r.fontSize).attr("fill",t.selected?r.selectedColor:r.color).style("font-kerning","none").text(t.middleLabel);const m=e.select("g.diagram-connection-middle-label text").node()?.getBoundingClientRect();if(m){const g=t.middleLabel?m.width/this.zoomTransform.k+Ot(r)+_t(r):0,v=t.middleLabel?m.height/this.zoomTransform.k+Ht(r)+Vt(r):0,y=l.getPointAtLength(i/2);e.select("g.diagram-connection-middle-label path").attr("d",Yt(-g/2,-v/2,g,v)).attr("fill",r.backgroundColor).attr("stroke","none"),e.select("g.diagram-connection-middle-label").attr("transform",`translate(${y.x+d*g},${y.y+c*v})`)}e.select("g.diagram-connection-end-label text").attr("x",0).attr("y",r.fontSize/3).attr("text-anchor","middle").attr("font-family",r.fontFamily).attr("font-size",r.fontSize).attr("fill",t.selected?r.selectedColor:r.color).style("font-kerning","none").text(t.endLabel);const x=e.select("g.diagram-connection-end-label text").node()?.getBoundingClientRect();if(x){const g=t.endLabel?x.width/this.zoomTransform.k+Ot(r)+_t(r):0,v=t.endLabel?x.height/this.zoomTransform.k+Ht(r)+Vt(r):0;let y;switch(t.endDirection){case f.Left:y=l.getPointAtLength(i-(it(r)+g/2));break;case f.Right:y=l.getPointAtLength(i-(D(r)+g/2));break;case f.Top:y=l.getPointAtLength(i-(q(r)+g/2));break;case f.Bottom:y=l.getPointAtLength(i-(G(r)+g/2));break;default:y=l.getPointAtLength(i-Math.max(D(r)+g/2,it(r)+g/2,G(r)+v/2,q(r)+v/2))}e.select("g.diagram-connection-end-label path").attr("d",Yt(-g/2,-v/2,g,v)).attr("fill",r.backgroundColor).attr("stroke","none"),e.select("g.diagram-connection-end-label").attr("transform",`translate(${y.x+h*g},${y.y+u*v})`)}}}updateConnectionMarkersInView(t){const e=this.selectCanvasView().select(`[id='${ce(t.id)}']`),a=e.select("marker.diagram-connection-start-marker"),l=e.select("marker.diagram-connection-end-marker");t.startMarkerLook!==null?a.attr("orient","auto-start-reverse").attr("markerWidth",t.startMarkerLook.width).attr("markerHeight",t.startMarkerLook.height).attr("refX",t.startMarkerLook.refX).attr("refY",t.startMarkerLook.refY).select("image").attr("href",t.startMarkerLook.image).attr("width",t.startMarkerLook.width).attr("height",t.startMarkerLook.height):a.attr("orient","auto-start-reverse").attr("markerWidth",0).attr("markerHeight",0),t.endMarkerLook!==null?l.attr("orient","auto-start-reverse").attr("markerWidth",t.endMarkerLook.width).attr("markerHeight",t.endMarkerLook.height).attr("refX",t.endMarkerLook.refX).attr("refY",t.endMarkerLook.refY).select("image").attr("href",t.endMarkerLook.image).attr("width",t.endMarkerLook.width).attr("height",t.endMarkerLook.height):l.attr("orient","auto-start-reverse").attr("markerWidth",0).attr("markerHeight",0)}fieldRootFitsInView(t){const e=this.model.fields.get(t);if(!e)return!1;if(e.rootElement instanceof R||e.rootElement instanceof U){const a=this.minimumSizeOfField(e),l=a[0]+D(e.rootElement.type?.label)+it(e.rootElement.type?.label)-e.rootElement.width,r=a[1]+G(e.rootElement.type?.label)+q(e.rootElement.type?.label)-e.rootElement.height;return l<=0&&r<=0}return!0}fitFieldRootInView(t,e=!0){const a=this.model.fields.get(t);if(a){if(a.rootElement instanceof R){const l=this.minimumSizeOfField(a);let r=l[0]+D(a.rootElement.type.label)+it(a.rootElement.type.label)-a.rootElement.width,i=l[1]+G(a.rootElement.type.label)+q(a.rootElement.type.label)-a.rootElement.height;this.snapToGrid&&(r=Math.ceil(r/this.gridSize)*this.gridSize,i=Math.ceil(i/this.gridSize)*this.gridSize),a.rootElement.width+r<a.rootElement.type.minWidth&&(r=a.rootElement.type.minWidth-a.rootElement.width),a.rootElement.height+i<a.rootElement.type.minHeight&&(i=a.rootElement.type.minHeight-a.rootElement.height),(e!==!1||r>0)&&a.rootElement.stretch(f.Right,r),(e!==!1||i>0)&&a.rootElement.stretch(f.Bottom,i)}if(a.rootElement instanceof U){const l=this.minimumSizeOfField(a);let r=l[0],i=l[1];for(const c of a.rootElement.node?.sections||[])c.label&&(c.indexXInNode===a.rootElement.indexXInNode&&c.indexYInNode!==a.rootElement.indexYInNode?r=Math.max(r,this.minimumSizeOfField(c.label)[0]):c.indexXInNode!==a.rootElement.indexXInNode&&c.indexYInNode===a.rootElement.indexYInNode&&(i=Math.max(i,this.minimumSizeOfField(c.label)[1])));l[0]<r&&(l[0]=r),l[1]<i&&(l[1]=i);const n=a.rootElement.type;let o=l[0]+D(n?.label)+it(n?.label)-a.rootElement.width,d=l[1]+G(n?.label)+q(n?.label)-a.rootElement.height;this.snapToGrid&&(o=Math.ceil(o/this.gridSize)*this.gridSize,d=Math.ceil(d/this.gridSize)*this.gridSize),a.rootElement.width+o<(a.rootElement.getMinWidth()||0)&&(o=(a.rootElement.getMinWidth()||0)-a.rootElement.width),a.rootElement.height+d<(a.rootElement.getMinHeight()||0)&&(d=(a.rootElement.getMinHeight()||0)-a.rootElement.height),(e||o>0)&&a.rootElement.node?.stretchSections(f.Right,o,a.rootElement.indexXInNode,a.rootElement.indexYInNode),(e||d>0)&&a.rootElement.node?.stretchSections(f.Bottom,d,a.rootElement.indexXInNode,a.rootElement.indexYInNode)}}}fitNodeInView(t,e=!0){const a=this.model.nodes.get(t);if(a&&a.sections.length>0&&this.priorityThreshold){let l=0,r=0;for(const i of a.sections)if(i.getPriority()>=this.priorityThreshold){const n=i.coords[0]+i.width-a.coords[0],o=i.coords[1]+i.height-a.coords[1];l=Math.max(l,n),r=Math.max(r,o)}l+=a.type.sectionGrid?.margin||0,r+=a.type.sectionGrid?.margin||0,(e||l>a.width)&&a.stretch(f.Right,l-a.width),(e||r>a.height)&&a.stretch(f.Bottom,r-a.height)}}selectRoot(){return A.select(this.diagramRoot)}selectSVGElement(){return A.select(this.diagramRoot).select("svg")}selectCanvasView(){return this.selectSVGElement().select(".daga-canvas-view")}selectCanvasElements(){return this.selectSVGElement().select(".daga-canvas-elements")}startConnection(t){if(t.allowsOutgoing||t.allowsIncoming){if(this.connectionType&&(this.connectionType.canStartFromType(t.getNode()?.type?.id||"")&&t.allowsOutgoing||this.connectionType.canFinishOnType(t.getNode()?.type?.id||"")&&t.allowsIncoming))this.unfinishedConnection=new lt(this.model,this.connectionType,t,void 0,le);else if(this.inferConnectionType){let e=this.model.connections.types.all().find(a=>t.allowsOutgoing&&a.canStartFromType(t.getNode()?.type?.id||""));e===void 0&&(e=this.model.connections.types.all().find(a=>t.allowsIncoming&&a.canFinishOnType(t.getNode()?.type?.id||""))),e!==void 0&&(this.unfinishedConnection=new lt(this.model,e,t,void 0,le))}}}finishConnection(t){if(this.userHighlight.clear(),this.unfinishedConnection!==void 0){if(!this.allowConnectionLoops&&this.unfinishedConnection.start===t){this.dropConnection();return}if(!this.allowSharingPorts&&(t.incomingConnections.filter(e=>!e.removed).length>0||t.outgoingConnections.filter(e=>!e.removed).length>0)){this.dropConnection();return}if(!this.allowSharingBothPorts&&this.model.connections.find(e=>!e.removed&&(e.start===this.unfinishedConnection?.start&&e.end===t||e.end===this.unfinishedConnection?.start&&e.start===t))!==void 0){this.dropConnection();return}if(this.unfinishedConnection.type.canStartFromType(this.unfinishedConnection?.start?.getNode()?.type?.id||"")&&this.unfinishedConnection?.start?.allowsOutgoing&&this.unfinishedConnection.type.canFinishOnType(t.getNode()?.type?.id||"")&&t.allowsIncoming){const e=new se(this,this.unfinishedConnection.type,this.unfinishedConnection.start?.id,t.id);this.dropConnection(),e.do(),this.actionStack.add(e)}else if(this.unfinishedConnection.type.canFinishOnType(this.unfinishedConnection?.start?.getNode()?.type?.id||"")&&this.unfinishedConnection?.start?.allowsIncoming&&this.unfinishedConnection.type.canStartFromType(t.getNode()?.type?.id||"")&&t.allowsOutgoing){const e=new se(this,this.unfinishedConnection.type,t.id,this.unfinishedConnection.start?.id);this.dropConnection(),e.do(),this.actionStack.add(e)}else if(this.inferConnectionType){let e=this.model.connections.types.all().find(l=>l.canStartFromType(this.unfinishedConnection?.start?.getNode()?.type?.id||"")&&this.unfinishedConnection?.start?.allowsOutgoing&&l.canFinishOnType(t.getNode()?.type?.id||"")&&t.allowsIncoming),a=!1;if(e===void 0&&(e=this.model.connections.types.all().find(l=>l.canFinishOnType(this.unfinishedConnection?.start?.getNode()?.type?.id||"")&&this.unfinishedConnection?.start?.allowsIncoming&&l.canStartFromType(t.getNode()?.type?.id||"")&&t.allowsOutgoing),a=!0),e!==void 0){const l=new se(this,e,a?t.id:this.unfinishedConnection.start?.id,a?this.unfinishedConnection.start?.id:t.id);this.dropConnection(),l.do(),this.actionStack.add(l)}else this.dropConnection()}else this.dropConnection()}}dropConnection(){this.unfinishedConnection?.setStart(void 0),this.unfinishedConnection?.setEnd(void 0),this.unfinishedConnection?.select()?.remove(),this.unfinishedConnection=void 0}cancelAllUserActions(){this.currentAction=void 0,this.dropConnection(),this.removeInputField(),this.contextMenu.close(),this.userSelection.clear()}canUserPerformAction(t){return this.userActions[t]!==!1}createInputField(t,e,a,l,r,i,n,o,d){this.removeInputField();const c=this.selectCanvasElements().append("foreignObject").attr("x",`${e[0]}px`).attr("y",`${e[1]}px`).attr("width",`${a}px`).attr("height",`${l}px`).style("box-sizing","border-box").style("border","1px solid");this.inputFieldContainer=c;const h=c.append("xhtml:textarea");let u,b;h.text(t).style("box-sizing","border-box").style("width",`${a}px`).style("height",`${l}px`).style("font-size",`${r}px`).style("font-family",i).style("resize","none").style("outline",0).style("border",0).style("margin",0).style("padding",0).on(S.KeyDown,x=>{x.stopPropagation()}).on(S.KeyUp,x=>{if(x.stopPropagation(),x.key===K.Escape){const g=h.property("value");this.removeInputField(),d&&d(g)}}).on(S.Input,()=>{const x=h.property("value");h.attr("cols",po(x)+1),h.attr("rows",mo(x)+1),h.style("width",""),h.style("height",""),u=h.property("scrollWidth")+1,b=h.property("scrollHeight")+1;const g=Math.max(u,a),v=Math.max(b,l);c?.attr("width",`${g}px`),h.style("width",`${g}px`),c?.attr("height",`${v}px`),h.style("height",`${v}px`),o&&o(x)}).on(S.Click,x=>{x.stopPropagation()}).on(S.FocusOut,()=>{const x=h.property("value");this.removeInputField(),d&&d(x)});const m=h.node();m.focus(),m.select()}removeInputField(){this.inputFieldContainer?.select("input")?.on(S.Blur,null),this.inputFieldContainer?.remove(),this.inputFieldContainer=void 0}minimumSizeOfField(t){const e=t.select()?.select("p")?.node();if(!e)return[0,0];const a=e.getBoundingClientRect();return[a.width/this.zoomTransform.k,a.height/this.zoomTransform.k]}startMovingNode(t,e){if(this.canUserPerformAction(k.MoveNode)&&!e.removed)if(w(L.Grabbing),this.draggingFrom=[t.x,t.y],e.selected&&this.userSelection.count(a=>a instanceof 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 X(this,k.MoveNode,e.id,e.getGeometry(),e.getGeometry(),a?.id,a?.getGeometry(e.id),a?.getGeometry(e.id))}else w(L.NotAllowed)}continueMovingNode(t,e){if(this.canUserPerformAction(k.MoveNode)&&(this.currentAction instanceof ie||this.currentAction instanceof X)&&!e.removed){const a=[t.x-e.width/2,t.y-e.height/2];e.selected?this.userSelection.move([a[0]-e.coords[0],a[1]-e.coords[1]]):e.move(a),this.userHighlight.clear(),this.dragging=!0}}finishMovingNode(t,e){if(this.canUserPerformAction(k.MoveNode)&&!e.removed&&(this.draggingFrom[0]!==t.x||this.draggingFrom[1]!==t.y)){let a=[t.x-e.width/2,t.y-e.height/2];if(this.snapToGrid&&(a=this.getClosestGridPoint([a[0]-e.type.snapToGridOffset[0],a[1]-e.type.snapToGridOffset[1]]),a[0]+=e.type.snapToGridOffset[0],a[1]+=e.type.snapToGridOffset[1]),this.currentAction instanceof ie){const l=this.currentAction.delta;this.currentAction.delta=[a[0]-l[0],a[1]-l[1]],e.selected?this.userSelection.move([l[0]-e.coords[0],l[1]-e.coords[1]]):e.move(l)}else if(this.currentAction instanceof X){e.move(a);const r=this.model.nodes.getAtCoordinates(t.x,t.y).filter(o=>o.id!==e.id&&!o.isDescendantOf(e)).filter(o=>o.type.childrenTypes.includes(e.type.id)),i=Ge(r),n=i[i.length-1];if(n!==e.parent&&(e.type.canBeParentless||n!==void 0)){const o=n?.getLastAncestor(),d=this.currentAction.from,c=new Go(this,e.id,e.parent?.id,n?.id,d,e.getGeometry(),o?.id,o?.getGeometry(e.id),o?.getGeometry(e.id));e.parent?.removeChild(e),n!==void 0&&n.addChild(e),c.toChildGeometry=e.getGeometry(e.id),c.toAncestorGeometry=o?.getGeometry(e.id),this.currentAction=c}else{const o=e?.getLastAncestor();this.currentAction.ancestorId=o?.id,this.currentAction.fromAncestorGeometry=o?.getGeometry(e.id),e.parent?.fitToChild(e),this.currentAction.to=e.getGeometry(e.id),this.currentAction.toAncestorGeometry=o?.getGeometry(e.id)}}this.currentAction!==void 0&&(this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0)}w(),this.dragging=!1}startMultipleSelection(t){this.draggingFrom=this.getPointerLocationRelativeToCanvas(t),this.multipleSelectionContainer=this.selectSVGElement().append("rect").attr("stroke","#0E74B6").attr("fill","rgba(14, 116, 182, 0.06)")}continueMultipleSelection(t){const e=this.getPointerLocationRelativeToCanvas(t);(this.draggingFrom[0]!==e[0]||this.draggingFrom[1]!==e[1])&&(w(L.Crosshair),this.multipleSelectionContainer?.attr("x",Math.min(this.draggingFrom[0],e[0])*this.zoomTransform.k+this.zoomTransform.x)?.attr("y",Math.min(this.draggingFrom[1],e[1])*this.zoomTransform.k+this.zoomTransform.y)?.attr("width",Math.abs(this.draggingFrom[0]-e[0])*this.zoomTransform.k)?.attr("height",Math.abs(this.draggingFrom[1]-e[1])*this.zoomTransform.k),this.dragging=!0)}finishMultipleSelection(t){const e=this.getPointerLocationRelativeToCanvas(t);this.multipleSelectionContainer?.remove(),this.multipleSelectionContainer=void 0,this.userSelection.clear();for(const a of this.model.nodes)so([a.coords,[a.coords[0]+a.width,a.coords[1]+a.height]],[this.draggingFrom,e])&&this.userSelection.add(a);this.multipleSelectionOn=!1,this.diagramEvent$.next(new H(this.userSelection.all(),!0)),w()}};Zt.canvasCount=0;let ue=Zt;class Ze{constructor(){this.grid=[[void 0]],this.offsetX=0,this.offsetY=0}minX(){return-this.offsetX}maxX(){return this.width()-1-this.offsetX}minY(){return-this.offsetY}maxY(){return this.height()-1-this.offsetY}width(){return this.grid[0].length}height(){return this.grid.length}addColumnLeft(){for(const t of this.grid)t.splice(0,0,void 0);this.offsetX=this.offsetX+1}addColumnRight(){for(const t of this.grid)t.push(void 0)}addRowTop(){const t=[];for(let e=0;e<this.grid[0].length;++e)t.push(void 0);this.grid.splice(0,0,t),this.offsetY=this.offsetY+1}addRowBottom(){const t=[];for(let e=0;e<this.grid[0].length;++e)t.push(void 0);this.grid.push(t)}get(t){if(this.grid[t[1]+this.offsetY])return this.grid[t[1]+this.offsetY][t[0]+this.offsetX]}set(t,e){for(;t[0]<-this.offsetX;)this.addColumnLeft();for(;t[0]>=this.width()-this.offsetX;)this.addColumnRight();for(;t[1]<-this.offsetY;)this.addRowTop();for(;t[1]>=this.height()-this.offsetY;)this.addRowBottom();this.grid[t[1]+this.offsetY][t[0]+this.offsetX]=e}getClosestEmptyCoordinate(t){if(this.get(t)===void 0)return t;const e=[...t];for(let a=1;;++a){const l=a%2>0?a:-a,r=l>0?1:-1,i=[e[0]+l,e[1]+l];for(let n=e[0];n!==i[0]+r;n+=r)if(e[0]=n,this.get(e)===void 0)return e;for(let n=e[1];n!==i[1]+r;n+=r)if(e[1]=n,this.get(e)===void 0)return e}}}class ri{constructor(t){this.gapSize=t}apply(t){if(t.nodes.length===0)return t;const e=new Ze,a=t.nodes.filter(n=>!n.parent);for(;a.length>0;)Ke(a[0],e,[0,0],a);const l=Math.max(...t.nodes.map(n=>n.width)),r=Math.max(...t.nodes.map(n=>n.height)),i=this.gapSize!==void 0?this.gapSize:(t.canvas?.gridSize||0)*2;for(let n=e.minY();n<=e.maxY();++n)for(let o=e.minX();o<=e.maxX();++o){const d=e.get([o,n]);d!==void 0&&d.move([o*(l+i),n*(r+i)])}return t}}const Ke=(s,t,e,a)=>{const l=t.getClosestEmptyCoordinate(e);t.set(l,s),B(a,s);for(const r of s.getAdjacentNodes())a.includes(r)&&Ke(r,t,l,a)};class ai{constructor(t){this.gapSize=t}apply(t){if(t.nodes.length===0)return t;const e=new Ze,a=t.nodes.filter(c=>!c.parent),l={},r=a[0];let i=[r];for(l[r.id]=[0,0];a.length>0;){const c=[];for(const h of i){e.set(e.getClosestEmptyCoordinate(l[h.id]),h),B(a,h);const u=h.getAdjacentNodes();for(const b of u)a.includes(b)&&(c.push(b),l[b.id]=l[h.id])}if(c.length>0)i=c;else if(a.length>0){const h=a[0];i=[h],l[h.id]=e.getClosestEmptyCoordinate([0,0])}}const n=Math.max(...t.nodes.map(c=>c.width)),o=Math.max(...t.nodes.map(c=>c.height)),d=this.gapSize!==void 0?this.gapSize:(t.canvas?.gridSize||0)*2;for(let c=e.minY();c<=e.maxY();++c)for(let h=e.minX();h<=e.maxX();++h){const u=e.get([h,c]);u!==void 0&&u.move([h*(n+d),c*(o+d)])}return t}}class ee{constructor(t){this.gapSize=t}apply(t){if(t.nodes.length===0)return t;const e=this.gapSize!==void 0?this.gapSize:(t.canvas?.gridSize||0)*2;let a=t.nodes.filter(n=>!n.parent);const l=a[0];B(a,l);const r=[[l]];for(;a.length>0;){const n=r[r.length-1],o=[];for(const d of n){const c=d.getAdjacentNodes();for(const h of c)a.includes(h)&&(B(a,h),o.push(h))}o.length>0?r.push(o):(r.push(a),a=[])}let i=0;for(const n of r){let o=0;for(const c of n)c.move([i,o]),o+=e+c.height;const d=Math.max(...n.map(c=>c.width));i+=e+d}for(const n of t.connections)n.tighten();return t}}class li{constructor(t){this.gapSize=t}apply(t){if(t.nodes.length===0)return t;new ee(this.gapSize).apply(t);const e=this.gapSize!==void 0?this.gapSize:(t.canvas?.gridSize||0)*2,a=.99,l=1,r=.1,i=2e5,n=.5,o=1,d=.002;let c=100;for(;c>l;){c=c*a;const h=[0,0];{for(const u of t.nodes)h[0]=h[0]+u.coords[0]+u.width/2,h[1]=h[1]+u.coords[1]+u.width/2;h[0]=h[0]/t.nodes.length,h[1]=h[1]/t.nodes.length}for(const u of t.nodes){const b=u.getAdjacentNodes();for(const m of t.nodes){const x=[u.coords[0]+u.width/2,u.coords[1]+u.height/2],g=[m.coords[0]+m.width/2,m.coords[1]+m.height/2],v=Re(u.coords,m.coords),y=[m.coords[0],m.coords[1]];if(b.includes(m)&&v>0&&(v>e+(Math.max(u.width,u.height)+Math.max(m.width,m.height))/2?(y[0]=y[0]-(g[0]-x[0])*r,y[1]=y[1]-(g[1]-x[1])*r):(y[0]=y[0]+(g[0]-x[0])*n,y[1]=y[1]+(g[1]-x[1])*n)),v>0){const T=i/(v*v);y[0]=y[0]+T*(g[0]-x[0])/v,y[1]=y[1]+T*(g[1]-x[1])/v}else y[0]=y[0]+o*(Math.random()*2-1),y[1]=y[1]+o*(Math.random()*2-1);y[0]=y[0]-(g[0]-h[0])*d,y[1]=y[1]-(g[1]-h[1])*d,y[0]-m.coords[0]>c?y[0]=m.coords[0]+c:y[0]-m.coords[0]<-c&&(y[0]=m.coords[0]-c),y[1]-m.coords[1]>c?y[1]=m.coords[1]+c:y[1]-m.coords[1]<-c&&(y[1]=m.coords[1]-c),m.move(y)}}}if(t.canvas&&t.canvas.snapToGrid)for(const h of t.nodes){const u=t.canvas.getClosestGridPoint([h.coords[0]-h.type.snapToGridOffset[0],h.coords[1]-h.type.snapToGridOffset[1]]);u[0]+=h.type.snapToGridOffset[0],u[1]+=h.type.snapToGridOffset[1],h.move(u)}for(const h of t.connections)h.tighten();return t}}class di{constructor(t){this.gapSize=t}apply(t){if(t.nodes.length===0)return t;const e=this.gapSize!==void 0?this.gapSize:(t.canvas?.gridSize||0)*2,a=t.nodes.filter(r=>!r.parent);a.sort((r,i)=>i.type.priority-r.type.priority);let l=0;for(const r of a)r.move([l,0]),l+=r.width+e;return t}}class ci{constructor(t){this.gapSize=t}apply(t){if(t.nodes.length===0)return t;const e=Math.max(...t.nodes.map(c=>c.getPriority())),a=Math.min(...t.nodes.map(c=>c.getPriority()));if(e===a)return new ee(this.gapSize).apply(t),t;const l=this.gapSize!==void 0?this.gapSize:(t.canvas?.gridSize||0)*2,r=t.nodes.filter(c=>!c.parent),i=[],n=t.nodes.filter(c=>!c.parent).filter(c=>c.getPriority()>=e),o=[];if(n.length>1){const c=n[0];n.splice(0,1),o.push(c);const h=[c],u=[c];for(;h.length>0;){const b=h[0];h.splice(0,1),n.includes(b)&&(o.push(b),B(n,b));const m=b.getAdjacentNodes();for(const x of m)u.includes(x)||(h.push(x),u.push(x))}for(const b of n)o.push(b)}else o.push(n[0]);for(const c of o)B(r,c),i.push([c]);for(i.push([]),r.sort((c,h)=>h.type.priority-c.type.priority);r.length>0;){const c=r[0];r.splice(0,1);const h=[c],u=[c];let b=!1;for(;h.length>0;){const m=h[0];h.splice(0,1);const x=o.indexOf(m);if(x>=0){i[x].push(c),b=!0;break}else{const g=m.getAdjacentNodes();for(const v of g)u.includes(v)||(h.push(v),u.push(v))}}b||i[i.length-1].push(c)}let d=0;for(let c=0;c<i.length;++c){let h=0;for(let b=0;b<i[c].length;++b){const m=i[c][b];m.move([d,h]),h+=l+m.height}const u=Math.max(...i[c].map(b=>b.width));d+=l+u}for(const c of t.connections)c.tighten();return t}}class hi{constructor(t){this.gapSize=t}apply(t){if(t.nodes.length===0)return t;const e=Math.max(...t.nodes.map(c=>c.getPriority())),a=Math.min(...t.nodes.map(c=>c.getPriority()));if(e===a)return new ee(this.gapSize).apply(t),t;const l=this.gapSize!==void 0?this.gapSize:(t.canvas?.gridSize||0)*2,r=t.nodes.filter(c=>!c.parent).sort((c,h)=>h.getPriority()-c.getPriority()),i=[];for(;r.length>0;){const c=r[0];r.splice(0,1);const h=new ye(void 0,c);qe(h,r),i.push(h)}const n=[];for(const c of i)n.push([c]),Je(c,n,n.length);const o=Math.max(...t.nodes.map(c=>c.height));let d=0;for(let c=0;c<n.length;++c){let h=0;for(let b=0;b<n[c].length;++b){const m=n[c][b];m.node.move([d,h]),h+=(l+o)*m.countBranchHeight()}const u=Math.max(...n[c].map(b=>b.node.width));d+=l+u}for(const c of t.connections)c.tighten();return t}}const qe=(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);qe(l,t)}}},Je=(s,t,e)=>{if(s.branches.length>0){for(;e>=t.length;)t.push([]);for(const a of s.branches)t[e].push(a),Je(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 gi{constructor(t){this.gapSize=t}apply(t){if(t.nodes.length===0)return t;const e=this.gapSize!==void 0?this.gapSize:(t.canvas?.gridSize||0)*2,a=t.nodes.filter(r=>!r.parent);a.sort((r,i)=>i.type.priority-r.type.priority);let l=0;for(const r of a)r.move([0,l]),l+=r.height+e;return t}}const Ne={adjacency:new ri,breadth:new ee,"breadth-adjacency":new ai,force:new li,horizontal:new di,priority:new ci,tree:new hi,vertical:new gi},fi=I.createContext({}),xt=I.createContext({});class ui{constructor(t,e){this.onTitleChange=t,this.onValueSetChange=e}get title(){return this._title}set title(t){this._title=t,this.onTitleChange(t)}get valueSet(){return this._valueSet}set valueSet(t){this._valueSet=t,this.onValueSetChange(t)}highlightProperty(...t){}}const be=({direction:s,collapsableSelector:t,collapsableAdditionalSelector:e,collapsed:a,disabled:l,rule:r,collapsedValue:i,visibleValue:n,onCollapse:o})=>{const[d,c]=I.useState(a),h=()=>{if(!l){const b=!d;c(b),o?.(b);let m;if(typeof t=="string")m=A.select(t),e&&(m=m.select(e));else{const x=t;if(!x)throw new Error("collapsableSelector is not a valid ref");m=A.select(x.current),e&&(m=m.select(e))}m.style(r,b?i:n)}},u=()=>{switch(s){case f.Right:return l?"daga-horizontal-none":d?"daga-horizontal-right":"daga-horizontal-left";case f.Bottom:return l?"daga-vertical-none":d?"daga-vertical-down":"daga-vertical-up";case f.Left:return l?"daga-horizontal-none":d?"daga-horizontal-left":"daga-horizontal-right";case f.Top:return l?"daga-vertical-none":d?"daga-vertical-up":"daga-vertical-down"}};return p.jsx("daga-collapse-button",{children:p.jsx("button",{className:`daga-collapse-button daga-${s}`,onClick:h,children:p.jsx("div",{className:u()})})})},pi=()=>{const s=I.useContext(xt),t=I.useRef(null),[e,a]=I.useState([]);kt.merge(s.validatorChange$,s.diagramChange$).pipe(kt.map(()=>l())).subscribe();const l=()=>{a([]);for(const i of s.validators){const n=i.validate(s.model);a(n)}},r=i=>{if(i.elementId&&(i.propertyNames===void 0||i.propertyNames.length===0)){const n=s.model.nodes.get(i.elementId)||s.model.connections.get(i.elementId);n&&s.userHighlight.add(n)}else if(i.elementId&&i.propertyNames!==void 0&&i.propertyNames.length>0){s.userSelection.openInPropertyEditor(s.model.nodes.get(i.elementId)||s.model.connections.get(i.elementId));const n=s.model.nodes.get(i.elementId)||s.model.connections.get(i.elementId);n&&s.userHighlight.add(n),s.parentComponent?.propertyEditor?.highlightProperty(...i.propertyNames)}else!i.elementId&&i.propertyNames!==void 0&&i.propertyNames.length>0&&(s.userSelection.openInPropertyEditor(),s.parentComponent?.propertyEditor?.highlightProperty(...i.propertyNames))};return p.jsx("daga-errors",{children:p.jsxs("div",{ref:t,className:"daga-errors",children:[e.length===0&&p.jsx("div",{className:"daga-errors-summary daga-no-errors daga-prevent-user-select",children:p.jsx("span",{children:"No errors found"})}),e.length>0&&p.jsxs("div",{className:"daga-errors-summary daga-with-errors daga-prevent-user-select",children:[p.jsxs("span",{children:[e.length," errors found"]}),p.jsx("div",{className:"daga-collapse-button-container",children:p.jsx(be,{collapsableSelector:t,collapsableAdditionalSelector:".daga-error-panel",direction:f.Top,rule:"display",collapsedValue:"none",visibleValue:"block",collapsed:!1,disabled:!1})})]}),e.length>0&&p.jsx("div",{className:"daga-error-panel",children:p.jsx("ol",{children:e.map((i,n)=>p.jsx("li",{onClick:()=>r(i),dangerouslySetInnerHTML:{__html:i.message}},n))})})]})})},mi=200,Pe=s=>(s||"").toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g,""),Qe=({disabled:s,options:t,value:e,onChange:a})=>{const l=I.useRef(null),[r,i]=I.useState(""),[n,o]=I.useState(void 0),[d,c]=I.useState([]),[h,u]=I.useState([]),[b,m]=I.useState([]),[x,g]=I.useState([]),[v,y]=I.useState(!1);I.useEffect(()=>{i(t.find(E=>wt(E.key,e))?.label||"")},[e,t]);const T=E=>{if(!s)switch(E.key){case K.PageDown:n===void 0?(F(0),M(0)):(F(n+5),M(n)),E.preventDefault();break;case K.ArrowDown:n===void 0?(F(0),M(0)):(F(n+1),M(n)),E.preventDefault();break;case K.PageUp:n===void 0?(F(t.length-1),M(t.length-1)):(F(n-5),M(n)),E.preventDefault();break;case K.ArrowUp:n===void 0?(F(t.length-1),M(t.length-1)):(F(n-1),M(n)),E.preventDefault();break;case K.Escape:j(),E.preventDefault();break;case K.Enter:z(t[n||0]),E.preventDefault();break;default:P()}},P=()=>{if(!s){const E=Pe(r.trim());c([]),u([]),m([]),g([]);for(const V of t){const J=Pe(V.label).indexOf(E);if(J>=0){const tt=V.label.substring(0,J),$t=V.label.substring(J,J+E.length),Pt=V.label.substring(J+E.length);c(et=>[...et,V]),u(et=>[...et,tt]),m(et=>[...et,$t]),g(et=>[...et,Pt])}}y(!0)}},j=()=>{y(!1)},F=E=>{if(!s){let V=E;if(E===void 0){o(void 0);return}E<0&&(V=0),E>=t.length&&(V=t.length-1),o(V)}},Y=()=>{setTimeout(()=>{j()},mi)},M=E=>{const V=l.current?.querySelectorAll("li")[E];V&&V.scrollIntoView({block:"center"})},C=()=>{s||(i(""),y(!1),o(void 0))},z=E=>{s||(i(E.label),y(!1),o(void 0),a(E.key))};return p.jsxs("div",{ref:l,className:`daga-autocomplete ${v?"daga-showing-options":""}`,children:[p.jsxs("div",{className:"daga-autocomplete-input",children:[p.jsx("input",{value:r,disabled:s,onKeyUp:T,onFocus:P,onBlur:Y,onChange:E=>i(E.target.value)}),r!==""&&p.jsx("button",{className:"daga-clear",onClick:C})]}),p.jsx("div",{className:"daga-autocomplete-options",children:p.jsxs("ul",{className:"daga-autocomplete-option-list",children:[d.length===0&&p.jsx("li",{className:"daga-autocomplete-option no-options",children:"(No options)"}),d.map((E,V)=>p.jsxs("li",{className:`daga-autocomplete-option ${V===n?"daga-focused":""}`,onMouseMove:()=>F(V),onClick:()=>z(E),children:[p.jsx("span",{children:h[V]}),p.jsx("span",{className:"daga-match",children:b[V]}),p.jsx("span",{children:x[V]})]},V))]})})]})},vi=(s,t)=>s.find(e=>e.key===t)?.label||`${t}`,yi=({disabled:s,allowRepeats:t,options:e,value:a,onChange:l})=>{const[r,i]=I.useState(),[n,o]=I.useState([]),[d,c]=I.useState([]),h=g=>{for(const v of a)if(v===g)return!0;return!1},u=()=>{if(!t){const g=[];for(const v of e)h(v.key)||g.push(v);c(g)}};I.useEffect(()=>{const g=a.length===0,v=a.map(y=>vi(e,y));o(v),g&&l(a),u()},[a,e]);const b=g=>{a.length>g&&(a.splice(g,1),o(n.filter((v,y)=>y!==g)),l(a),u())},m=()=>{r!==void 0&&(t||!h(r))&&(l(a.concat(r)),x())},x=()=>{i("")};return p.jsxs("div",{children:[a.map((g,v)=>p.jsxs("div",{className:"daga-value-item-element",children:[p.jsx("span",{className:"daga-input",children:n[v]}),!s&&p.jsx("button",{className:"daga-property-button",onClick:()=>b(v),children:p.jsx("div",{className:"daga-icon daga-close-icon"})})]},v)),!s&&p.jsxs("div",{className:"daga-value-item-input",children:[p.jsx("div",{className:"daga-input daga-relatively-positioned",children:p.jsx(Qe,{disabled:s,options:t?e||[]:d||[],value:r,onChange:i})}),p.jsx("button",{className:"daga-property-button",onClick:m,children:p.jsx("div",{className:"daga-icon daga-add-icon"})})]})]})},bi=({disabled:s,allowRepeats:t,value:e,onChange:a})=>{const[l,r]=I.useState(""),i=u=>{for(const b of u||[])if(b===u)return!0;return!1},n=u=>{e.length>u&&a(e.filter((b,m)=>m!==u))},o=(u,b,m)=>{const x=e.map((g,v)=>v===b?m==="blur"?u.trim():u:g);a(x)},d=()=>{const u=l.trim();u!==""&&(t||!i(u))&&(a(e.concat(u)),c())},c=()=>{r("")},h=u=>{u.key==="Enter"&&d()};return p.jsxs(p.Fragment,{children:[e.map((u,b)=>p.jsxs("div",{className:"daga-value-item-element",children:[p.jsx("input",{className:"daga-input",disabled:s,value:u,onChange:m=>o(m.target.value,b,"change"),onBlur:m=>o(m.target.value,b,"blur")}),p.jsx("button",{className:"daga-property-button",onClick:()=>n(b),children:p.jsx("div",{className:"daga-icon daga-close-icon"})})]},b)),!s&&p.jsxs("div",{className:"daga-value-item-input",children:[p.jsxs("div",{className:"daga-input daga-relatively-positioned",children:[p.jsx("input",{type:"text",onKeyUp:h,value:l,onChange:u=>r(u.target.value)}),p.jsx("button",{className:"daga-clear",onClick:c})]}),p.jsx("button",{className:"daga-property-button",onClick:d,children:p.jsx("div",{className:"daga-icon daga-add-icon"})})]})]})},ki=({disabled:s,value:t,onChange:e})=>{const[a,l]=I.useState(""),[r,i]=I.useState(""),[n,o]=I.useState({}),d=g=>{const v={};Object.keys(t).forEach(y=>{y!==g&&(v[y]=t[y])}),e(v)},c=(g,v,y)=>{const T=y==="blur"?v.trim():v;if(y==="blur"){if(g!==T){const P={};Object.keys(t).forEach(j=>{j===g?P[T]=t[j]:P[j]=t[j]}),e(P),o(j=>{const F={...j};return delete F[g],F})}}else o(P=>({...P,[g]:v}))},h=(g,v,y)=>{const T=y==="blur"?v.trim():v;if(T!==""){const P={};Object.keys(t).forEach(j=>{j===g?P[j]=T:P[j]=t[j]}),e(P)}},u=()=>{const g=a.trim(),v=r.trim();if(g!==""&&v!==""){const y={};Object.keys(t).forEach(T=>{y[T]=t[T]}),y[g]=v,e(y),l(""),i("")}},b=()=>{l("")},m=()=>{i("")},x=g=>{g.key==="Enter"&&u()};return p.jsxs("div",{children:[Object.entries(t).map(([g,v],y)=>p.jsxs("div",{className:"daga-value-item-element",children:[p.jsx("input",{id:`key-${y}`,className:"daga-input",type:"text",disabled:s,value:n[g]??g,onChange:T=>c(g,T.target.value,"change"),onBlur:T=>c(g,T.target.value,"blur")}),p.jsx("input",{id:`value-${y}`,className:"daga-input",type:"text",disabled:s,value:v,onChange:T=>h(g,T.target.value,"change"),onBlur:T=>h(g,T.target.value,"blur")}),p.jsx("button",{className:"daga-property-button",onClick:()=>d(g),children:p.jsx("div",{className:"daga-icon daga-close-icon"})})]},g)),!s&&p.jsxs("div",{className:"daga-value-item-input",children:[p.jsxs("div",{className:"daga-input daga-relatively-positioned",children:[p.jsx("input",{type:"text",value:a,onKeyUp:x,onChange:g=>l(g.target.value),onBlur:g=>c(a,g.target.value,"blur")}),p.jsx("button",{className:"daga-clear",onClick:b})]}),p.jsxs("div",{className:"daga-input daga-relatively-positioned",children:[p.jsx("input",{type:"text",value:r,onKeyUp:x,onChange:g=>i(g.target.value),onBlur:g=>h(a,g.target.value,"blur")}),p.jsx("button",{className:"daga-clear",onClick:m})]}),p.jsx("button",{className:"daga-property-button",onClick:u,children:p.jsx("div",{className:"daga-icon daga-add-icon"})})]})]})},to=({valueSet:s,onValueChange:t,depth:e})=>{const l=I.useContext(xt).canUserPerformAction(k.UpdateValues)&&s?.rootElement?.removed!==!0,r=o=>"daga-property-name-"+o.replace(/\s/g,""),i=o=>{if(typeof o=="string")return o;if(o==null||isNaN(o.valueOf()))return"";const d=new Date(o),c=d.getTimezoneOffset();return d.setMinutes(d.getMinutes()-c),d.toISOString().substring(0,19)},n=o=>new Date(o);return p.jsx("daga-object-editor",{children:s.displayedProperties.map(o=>p.jsxs("div",{className:`daga-property ${r(o.name)}`,children:[p.jsx("p",{className:"daga-property-name",children:o.label||o.name}),o.type===N.Text&&p.jsx("input",{type:"daga-text",disabled:o.editable===!1||!l,value:s?.getValue(o.name),onChange:d=>t(s,o,d.target.value)}),o.type===N.TextArea&&p.jsx("textarea",{disabled:o.editable===!1||!l,value:s?.getValue(o.name),onChange:d=>t(s,o,d.target.value)}),o.type===N.Number&&p.jsx("input",{type:"number",disabled:o.editable===!1||!l,value:s?.getValue(o.name),onChange:d=>t(s,o,d.target.value)}),o.type===N.Color&&p.jsx("input",{type:"text",pattern:"#[0-9a-fA-F]{6}",disabled:o.editable===!1||!l,value:s?.getValue(o.name),onChange:d=>t(s,o,d.target.value)}),o.type===N.Datetime&&p.jsx("input",{type:"datetime-local",disabled:o.editable===!1||!l,value:i(s?.getValue(o.name)),onChange:d=>t(s,o,n(d.target.value))}),o.type===N.Date&&p.jsx("input",{type:"date",disabled:o.editable===!1||!l,value:s?.getValue(o.name),onChange:d=>t(s,o,d.target.value)}),o.type===N.Time&&p.jsx("input",{type:"time",disabled:o.editable===!1||!l,value:s?.getValue(o.name),onChange:d=>t(s,o,d.target.value)}),o.type===N.Url&&p.jsx("input",{type:"url",disabled:o.editable===!1||!l,value:s?.getValue(o.name),onChange:d=>t(s,o,d.target.value)}),o.type===N.Boolean&&p.jsxs("div",{className:"daga-radio",children:[p.jsxs("label",{className:"daga-radio-item daga-radio-start"+(s?.getValue(o.name)===!1?" daga-checked":""),children:[p.jsx("input",{type:"radio",disabled:o.editable===!1||!l,name:o.name,value:"false",checked:s?.getValue(o.name)===!1,onChange:()=>t(s,o,!1)}),"No"]}),p.jsxs("label",{className:"daga-radio-item daga-radio-end"+(s?.getValue(o.name)===!0?" daga-checked":""),children:[p.jsx("input",{type:"radio",disabled:o.editable===!1||!l,name:o.name,value:"true",checked:s?.getValue(o.name)===!0,onChange:()=>t(s,o,!0)}),"Yes"]})]}),o.type===N.Option&&p.jsx("div",{className:"daga-relatively-positioned",children:p.jsx(Qe,{disabled:o.editable===!1||!l,options:o.options||[],value:s?.getValue(o.name),onChange:d=>t(s,o,d)})}),(o.type===N.OptionList||o.type===N.OptionSet)&&p.jsx(yi,{disabled:o.editable===!1||!l,allowRepeats:o.type===N.OptionList,options:o.options||[],value:s?.getValue(o.name),onChange:d=>t(s,o,d)}),(o.type===N.TextList||o.type===N.TextSet)&&p.jsx(bi,{disabled:o.editable===!1||!l,allowRepeats:o.type===N.TextList,value:s?.getValue(o.name),onChange:d=>t(s,o,d)}),o.type===N.TextMap&&p.jsx(ki,{disabled:o.editable===!1||!l,value:s?.getValue(o.name),onChange:d=>t(s,o,d)}),o.type===N.Object&&p.jsx("div",{className:"daga-left-bar",children:p.jsx(to,{valueSet:s.getSubValueSet(o.name),onValueChange:t,depth:e+1})})]},o.name))})},eo=({valueSet:s,depth:t})=>{const e=I.useContext(xt),a=I.useRef(null),l=o=>"daga-property-name-"+o.replace(/\s/g,""),r=()=>{for(const o of s?.displayedProperties||[]){let d=0,c=0,h=0;const u=A.select(a.current).select(`.daga-property.${l(o.name)}.daga-depth-${t}`);u.select("button.daga-move-button").call(A.drag().on($.Start,b=>{w(L.Grabbing);const m=e.getPointerLocationRelativeToScreen(b);if(m.length<2||isNaN(m[0])||isNaN(m[1]))return;const x=u.node()?.getBoundingClientRect();d=x?.width||0,c=x?.height||0,u.style("position","fixed").style("left",`${m[0]-d/2}px`).style("top",`${m[1]-c/2}px`).style("width",`${d}px`).style("height",`${c}px`).style("z-index",1)}).on($.Drag,b=>{w(L.Grabbing);const m=e.getPointerLocationRelativeToScreen(b);m.length<2||isNaN(m[0])||isNaN(m[1])||(u.style("position","fixed").style("left",`${m[0]-d/2}px`).style("top",`${m[1]-c/2}px`).style("width",`${d}px`).style("height",`${c}px`).style("z-index",1),A.select(a.current).select(`.daga-dropbar.daga-index-${h}.daga-depth-${t}`).style("visibility","hidden").style("height",0),h=i(m),A.select(a.current).select(`.daga-dropbar.daga-index-${h}.daga-depth-${t}`).style("visibility","visible").style("height","0.25rem"))}).on($.End,b=>{w(L.Auto),u.style("position","relative").style("left",0).style("top",0).style("z-index",0).style("width","unset").style("height","unset"),A.select(a.current).select(`.daga-dropbar.daga-index-${h}.daga-depth-${t}`).style("visibility","hidden").style("height",0);const m=e.getPointerLocationRelativeToScreen(b);m.length<2||isNaN(m[0])||isNaN(m[1])||(h=i(m),s?.displayedProperties?.splice(s.displayedProperties.indexOf(o),1),s?.displayedProperties?.splice(h,0,o))}))}},i=o=>{const d=s?.propertySet.propertyList||[],c=[];for(let h=0;h<=d.length;++h){const u=A.select(a.current).select(`.daga-dropbar.daga-index-${h}.daga-depth-${t}`).node()?.getBoundingClientRect();u&&c.push([u.x+u.width/2,u.y+u.height/2])}if(c.length>0){const h=c.map(b=>((o[0]-b[0])**2+(o[1]-b[1])**2)**.5);return h.indexOf(Math.min(...h))}return 0},n=o=>{if(s===void 0)return;let d;o instanceof So?d=o:o instanceof Event?d=s?.propertySet.getProperty(o.target?.value||""):d=s?.propertySet.getProperty(o||""),d&&s?.hideProperty(d),r()};return p.jsxs("daga-property-settings",{ref:a,children:[p.jsx("div",{className:`daga-dropbar daga-index-0 daga-depth-${t}`}),s?.displayedProperties.map((o,d)=>p.jsxs("div",{className:`daga-property-and-dropbar ${l(o.name)} daga-depth-${t}`,children:[p.jsxs("div",{className:`daga-property ${l(o.name)} daga-depth-${t}`,children:[p.jsxs("div",{className:"daga-property-name",children:[p.jsx("span",{children:o.label||o.name}),p.jsxs("div",{className:"daga-buttons",children:[p.jsx("button",{className:"daga-property-button daga-move-button",children:p.jsx("div",{className:"daga-icon daga-move-icon"})}),p.jsx("button",{className:"daga-property-button daga-hide-button",onClick:()=>n(o.name),children:p.jsx("div",{className:"daga-icon daga-hide-icon"})})]})]}),o.type!==N.Object&&p.jsx("div",{className:"daga-property-value",children:wi(s?.getValue(o.name))}),o.type===N.Object&&p.jsx(eo,{valueSet:s?.getSubValueSet(o.name),depth:t+1})]}),p.jsx("div",{className:`daga-dropbar daga-index-${d+1} daga-depth-${t}`})]},o.name))]})},wi=s=>Array.isArray(s)?s.join(", "):xo(s)?Object.entries(s).map(t=>t.map(e=>JSON.stringify(e)).join(": ")).join(", "):s instanceof Date?s.toLocaleString():s==null?"":""+s,Si=({location:s,direction:t,width:e,height:a,title:l,valueSet:r,onValueChange:i})=>{const n=I.useRef(null),[o,d]=I.useState(!1),[c,h]=I.useState(!1),u=()=>A.select(n.current);return I.useEffect(()=>{if(n.current)switch(t){case f.Bottom:case f.Top:u().style("width",e),a&&u().select(".daga-panel-content").style("height",a);break;case f.Left:case f.Right:u().style("height",e),a&&u().select(".daga-panel-content").style("width",a);break}},[e,a,t]),p.jsx("daga-property-editor",{children:p.jsxs("div",{ref:n,className:`daga-panel daga-bottom daga-${s} daga-${t}`,children:[p.jsx(be,{disabled:!r||!r.propertySet||!r.propertySet.hasProperties(),collapsed:o,direction:t,collapsableSelector:n,collapsableAdditionalSelector:".daga-panel-content",rule:"display",collapsedValue:"none",visibleValue:"block",onCollapse:d}),p.jsx("div",{className:"daga-panel-content",children:r&&r.propertySet&&r.propertySet.hasProperties()&&!o&&p.jsxs("div",{children:[l&&p.jsxs("p",{className:"daga-title",children:[l,p.jsx("button",{className:"daga-property-button",onClick:()=>h(!c),children:p.jsx("div",{className:`daga-icon daga-settings-icon ${c?"daga-unrotate":"daga-rotate"}`})})]}),!c&&p.jsx(to,{valueSet:r,onValueChange:i,depth:0}),c&&p.jsx(eo,{valueSet:r,depth:0})]})})]})})},xi=6,Ci=s=>{const t=I.useContext(xt),[e,a]=I.useState(s.currentPalette||s.palettes[0]),[l,r]=I.useState(0),[i,n]=I.useState(void 0),o=I.useRef(null),d=I.useRef(!1),c=g=>{if(a(g),h().selectAll("*").remove(),r(t.getPriorityThreshold()||0),g.categories&&u(g.categories),g.templates)for(const v of g.templates)b(v)},h=()=>A.select(o.current).select(".daga-palette-view"),u=g=>{const v=h().append("select").style("width","100%").style("height","2rem").style("padding","0.5rem").style("border-radius","0.25rem").style("background-color","#f7f8fc").style("border","1px solid #e6e6e6");v.append("option").attr("value","").text("(None selected)");for(const y in g)v.append("option").attr("value",y).text(y);v.on(S.Change,()=>{i&&h().selectAll(".daga-template-container.daga-in-category").remove();const y=v.property("value");n(y);const T=g[y]||[];for(const P of T)b(P,"daga-in-category")}),i&&(v.property("value",i),v.dispatch(S.Change))},b=(g,v)=>{if(g.templateType==="node"){const y=t.model.nodes.types.get(g.type);y?m(y,g,v):console.error(`Could not find a node type called '${g.type}'`)}else if(g.templateType==="connection"){const y=t.model.connections.types.get(g.type);y?x(y,g,v):console.error(`Could not find a connection type called '${g.type}'`)}},m=(g,v,y)=>{if(l!==void 0&&g.priority<l)return;const T=g.defaultLook.lookType==="shaped-look"?g.defaultLook.borderThickness||1:0,P=g.defaultHeight+T,j=g.defaultWidth+T,F=v.height||P,Y=v.width||j,M=h().append("div").attr("class",`daga-template-container ${y!==void 0?y:""}`).style("width",`${Y}px`).style("height",`${F}px`).call(A.drag().on($.Drag,z=>{if(t.canUserPerformAction(k.AddNode)){const E=t.getPointerLocationRelativeToScreen(z);if(E.length<2||isNaN(E[0])||isNaN(E[1]))return;M.style("position","fixed").style("left",`${E[0]-Y/2}px`).style("top",`${E[1]-F/2}px`).style("z-index",1)}}).on($.Start,z=>{if(t.canUserPerformAction(k.AddNode)){w(L.Grabbing);const E=t.getPointerLocationRelativeToScreen(z);if(E.length<2||isNaN(E[0])||isNaN(E[1]))return;M.style("position","fixed").style("left",`${E[0]-Y/2}px`).style("top",`${E[1]-F/2}px`).style("z-index",1),g.isUnique&&t.model.nodes.find(V=>!V.removed&&V.type.id===g.id)!==void 0&&w(L.NotAllowed)}}).on($.End,z=>{if(t.canUserPerformAction(k.AddNode)){if(w(L.Auto),M.style("position","relative").style("left",0).style("top",0).style("z-index","auto"),g.isUnique&&t.model.nodes.find(Ut=>!Ut.removed&&Ut.type.id===g.id)!==void 0)return;const E=t.getPointerLocationRelativeToScreen(z);if(E.length<2||isNaN(E[0])||isNaN(E[1]))return;const V=document.elementFromPoint(E[0],E[1]);if(V&&!t.selectCanvasView().node()?.contains(V))return;const at=t.getPointerLocationRelativeToCanvas(z);if(at.length<2||isNaN(at[0])||isNaN(at[1]))return;let J=[at[0]-g.defaultWidth/2,at[1]-g.defaultHeight/2];t.snapToGrid&&(J=t.getClosestGridPoint([J[0]-g.snapToGridOffset[0],J[1]-g.snapToGridOffset[1]]),J[0]+=g.snapToGridOffset[0],J[1]+=g.snapToGridOffset[1]);const $t=t.model.nodes.getAtCoordinates(at[0],at[1]).filter(Ut=>Ut.type.childrenTypes.includes(g.id)),Pt=Ge($t),et=Pt[Pt.length-1];if(!g.canBeParentless&&et===void 0)return;const ke=et?.getLastAncestor(),we=new jo(t,g,J,et?.id,ke?.id,ke?.getGeometry(),void 0,v.label,v.values);we.do(),t?.actionStack.add(we),w()}})).append("svg").attr("class",`palette-node ${g.id}`).attr("viewBox",`0 0 ${j} ${P}`).attr("preserveAspectRatio","none").style("position","relative").style("left",0).style("top",0).style("width",`${Y}px`).style("height",`${F}px`),C=v.look||g.defaultLook;switch(C.lookType){case"shaped-look":M.append("path").attr("d",ge(C.shape||Tt.Rectangle,(C.borderThickness||1)/2,(C.borderThickness||1)/2,g.defaultWidth,g.defaultHeight)).attr("fill",C.fillColor||"#FFFFFF").attr("stroke",C.borderColor||"#000000").attr("stroke-width",`${C.borderThickness}px`);break;case"image-look":M.append("image").attr("x",0).attr("y",0).attr("width",g.defaultWidth).attr("height",g.defaultHeight).attr("href",C.backgroundImage).attr("preserveAspectRatio","none");break;case"stretchable-image-look":M.append("image").attr("x",0).attr("y",0).attr("width",C.leftMargin).attr("height",C.topMargin).attr("href",C.backgroundImageTopLeft).attr("preserveAspectRatio","none"),M.append("image").attr("x",C.leftMargin).attr("y",0).attr("width",g.defaultWidth-C.rightMargin-C.leftMargin).attr("height",C.topMargin).attr("href",C.backgroundImageTop).attr("preserveAspectRatio","none"),M.append("image").attr("x",g.defaultWidth-C.rightMargin).attr("y",0).attr("width",C.rightMargin).attr("height",C.topMargin).attr("href",C.backgroundImageTopRight).attr("preserveAspectRatio","none"),M.append("image").attr("x",0).attr("y",C.topMargin).attr("width",C.leftMargin).attr("height",g.defaultHeight-C.bottomMargin-C.topMargin).attr("href",C.backgroundImageLeft).attr("preserveAspectRatio","none"),M.append("image").attr("x",C.leftMargin).attr("y",C.topMargin).attr("width",g.defaultWidth-C.rightMargin-C.leftMargin).attr("height",g.defaultHeight-C.bottomMargin-C.topMargin).attr("href",C.backgroundImageCenter).attr("preserveAspectRatio","none"),M.append("image").attr("x",g.defaultWidth-C.rightMargin).attr("y",C.topMargin).attr("width",C.rightMargin).attr("height",g.defaultHeight-C.bottomMargin-C.topMargin).attr("href",C.backgroundImageRight).attr("preserveAspectRatio","none"),M.append("image").attr("x",0).attr("y",g.defaultHeight-C.bottomMargin).attr("width",C.leftMargin).attr("height",C.bottomMargin).attr("href",C.backgroundImageBottomLeft).attr("preserveAspectRatio","none"),M.append("image").attr("x",C.leftMargin).attr("y",g.defaultHeight-C.bottomMargin).attr("width",g.defaultWidth-C.rightMargin-C.leftMargin).attr("height",C.bottomMargin).attr("href",C.backgroundImageBottom).attr("preserveAspectRatio","none"),M.append("image").attr("x",g.defaultWidth-C.rightMargin).attr("y",g.defaultHeight-C.bottomMargin).attr("width",C.rightMargin).attr("height",C.bottomMargin).attr("href",C.backgroundImageBottomRight).attr("preserveAspectRatio","none")}if(v.look===void 0){if(g.decorators)for(const z of g.decorators)M.append("foreignObject").attr("width",`${z.width}px`).attr("height",`${z.height}px`).attr("transform",`translate(${z.coords[0]},${z.coords[1]})`).html(z.html);if(v.label){const z={...O,...g.label,...v.labelLook};M.append("text").attr("transform",`translate(${(D(z)+g.defaultWidth)/2},${(G(z)+g.defaultHeight)/2})`).attr("x",0).attr("y",0).attr("font-size",`${z.fontSize}px`).attr("text-anchor","middle").attr("font-family",z.fontFamily).attr("font-weight",400).attr("fill",z.color).attr("stroke","none").style("font-kerning","none").style("user-select","none").text(v.label)}}},x=(g,v,y)=>{const T=h().append("div").attr("class",`daga-template-container ${y!==void 0?y:""}`).style("width",`${v.width}px`).style("height",`${v.height}px`).append("svg").attr("class",`palette-button ${g.id}`).style("position","relative").style("left",0).style("top",0).style("width","100%").style("height","100%").on("click",()=>{t.connectionType=g});T.append("path").attr("d",ge(Tt.Rectangle,0,0,v.width,v.height)).attr("fill",v.backgroundColor).attr("stroke","black").attr("stroke-width","1px"),v.icon!==""&&T.append("image").attr("x",0).attr("y",0).attr("width",v.width).attr("height",v.height).attr("href",v.icon),v.label!==""&&T.append("text").attr("transform",`translate(${v.width/2},${v.height/2+xi})`).attr("x",0).attr("y",0).attr("font-size","20px").attr("text-anchor","middle").attr("font-family","'Wonder Unit Sans', sans-serif").attr("font-weight",400).attr("fill","#000000").attr("stroke","none").style("font-kerning","none").style("user-select","none").text(v.label)};return I.useEffect(()=>{s.palettes.length>0&&!d.current&&(d.current=!0,c(s.palettes[0]))},[s.palettes]),I.useEffect(()=>{if(o.current)switch(s.direction){case f.Bottom:case f.Top:o.current.style.width=s.width,s.height&&(o.current.style.height=s.height);break;case f.Left:case f.Right:o.current.style.height=s.width,s.height&&(o.current.style.width=s.height);break}},[s.direction,s.width,s.height]),p.jsx("daga-palette",{children:p.jsxs("div",{ref:o,className:`daga-panel daga-${s.location} daga-${s.direction}`,children:[p.jsx(be,{direction:s.direction,collapsableSelector:o,collapsableAdditionalSelector:".daga-panel-content",rule:"display",collapsedValue:"none",visibleValue:"block",collapsed:!1,disabled:!1}),p.jsxs("div",{className:"daga-panel-content",children:[s.palettes.length>1&&p.jsx("div",{className:"daga-panel-tabs",children:s.palettes.map(g=>p.jsx("div",{className:`daga-panel-tab ${g===e?"daga-current-tab":""}`,onClick:()=>c(g),children:g.name}))}),p.jsx("div",{className:"daga-palette-view"})]})]})})},$i=({location:s,direction:t,enableAction:e,enableFilter:a,enableLayout:l,enableSelection:r,enableZoom:i})=>{let n=!1,o=!0,d=!1,c,h,u,b;switch(t){case f.Bottom:c="height",h="scaleY",u="top",b="bottom";break;case f.Top:c="height",h="scaleY",u="bottom",b="top";break;case f.Left:c="width",h="scaleX",u="right",b="left";break;case f.Right:c="width",h="scaleX",u="left",b="right";break}const m=I.useRef(null),x=I.useRef(null),g=I.useRef(null);I.useEffect(()=>{A.select(m.current).style(`margin-${b}`,"-1rem").style(c,"0rem").style("transform",`${h}(0)`).style("transform-origin",u)});const v=async()=>{const tt=A.select(m.current);if(!d)if(o){o=!1;const et=`${4*tt.selectChildren().size()}rem`;tt.transition().duration(500).ease(A.easeLinear).style(c,et).style("transform",`${h}(1)`),setTimeout(()=>{d=!1},500)}else o=!0,tt.transition().duration(500).ease(A.easeLinear).style(c,"0rem").style("transform",`${h}(0)`),setTimeout(()=>{d=!1},500)},y=I.useContext(xt),T=()=>{y.zoomBy(y.zoomFactor)},P=()=>{y.zoomBy(1/y.zoomFactor)},j=()=>{y.center()},F=()=>{y.layoutFormat&&y.layoutFormat in Ne&&Ne[y.layoutFormat].apply(y.model)},Y=()=>{n=!n,A.select(g.current).classed("daga-on",n).classed("daga-off",!n);const tt=y.getPriorityThresholdOptions();tt&&tt.length>=2&&y.setPriorityThreshold(tt[n?1:0])},M=()=>{y.actionStack.undo()},C=()=>{y.actionStack.redo()},z=()=>{y.userSelection.copyToClipboard()},E=()=>{y.userSelection.cutToClipboard()},V=()=>{y.userSelection.pasteFromClipboard()},at=()=>{y.userSelection.removeFromModel()},J=()=>{y.multipleSelectionOn=!0,A.select(x.current).classed("daga-on",!0).classed("daga-off",!1);const tt=y.diagramEvent$.subscribe($t=>{$t.type===Be.Selection&&(A.select(x.current).classed("daga-on",!1).classed("daga-off",!0),tt.unsubscribe())})};return p.jsx("daga-diagram-buttons",{children:p.jsxs("div",{className:`daga-diagram-buttons daga-${s} daga-${t}`,children:[i&&y.canUserPerformAction(k.Zoom)&&p.jsx("button",{className:"daga-zoom-in",onClick:T,children:p.jsx("span",{className:"daga-tooltip",children:"Zoom in"})}),i&&y.canUserPerformAction(k.Zoom)&&p.jsx("button",{className:"daga-zoom-out",onClick:P,children:p.jsx("span",{className:"daga-tooltip",children:"Zoom out"})}),p.jsxs("div",{className:"daga-collapsable-buttons daga-collapsed",ref:m,children:[i&&y.canUserPerformAction(k.Zoom)&&p.jsx("button",{className:"daga-center",onClick:j,children:p.jsx("span",{className:"daga-tooltip",children:"Fit diagram to screen"})}),e&&p.jsx("button",{className:"daga-undo",onClick:M,children:p.jsx("span",{className:"daga-tooltip",children:"Undo"})}),e&&p.jsx("button",{className:"daga-redo",onClick:C,children:p.jsx("span",{className:"daga-tooltip",children:"Redo"})}),r&&p.jsx("button",{className:"daga-copy",onClick:z,children:p.jsx("span",{className:"daga-tooltip",children:"Copy"})}),r&&p.jsx("button",{className:"daga-cut",onClick:E,children:p.jsx("span",{className:"daga-tooltip",children:"Cut"})}),r&&p.jsx("button",{className:`daga-multiple-selection ${n?"daga-on":"daga-off"}`,onClick:J,ref:x,children:p.jsx("span",{className:"daga-tooltip",children:"Multiple selection"})}),r&&p.jsx("button",{className:"daga-paste",onClick:V,children:p.jsx("span",{className:"daga-tooltip",children:"Paste"})}),r&&p.jsx("button",{className:"daga-delete",onClick:at,children:p.jsx("span",{className:"daga-tooltip",children:"Delete"})}),l&&y.layoutFormat&&p.jsx("button",{className:"daga-layout",onClick:F,children:p.jsx("span",{className:"daga-tooltip",children:"Apply layout"})}),a&&p.jsx("button",{className:`daga-filter ${n?"daga-on":"daga-off"}`,onClick:Y,ref:g,children:p.jsx("span",{className:"daga-tooltip",children:"Apply filter"})})]}),p.jsx("button",{className:"daga-more-options",onClick:v,children:o?p.jsx("span",{className:"daga-tooltip",children:"More options"}):p.jsx("span",{className:"daga-tooltip",children:"Less options"})})]})})},Ii=({config:s,model:t,onCanvasCreated:e,onDiagramEvent:a,onModelChange:l})=>{const r=new De,i=new We,n=I.useRef(null),o=I.useRef(void 0),d=I.useRef(!1),c=[],[h,u]=I.useState(void 0),[b,m]=I.useState(void 0),x={zoomIn:()=>{},zoomOut:()=>{},center:()=>{},layout:()=>{},filter:()=>{},undo:()=>{},redo:()=>{}},g={refreshPalette:()=>{}},v=new ui(Y=>u(Y),Y=>m(Y)),y={diagramButtons:x,palette:g,propertyEditor:v},T=(Y=!1)=>{if((!o.current||Y)&&(c.forEach(M=>M.unsubscribe()),o.current=new ue(y,s)),!o.current)throw new Error("Canvas could not be created");return o.current},P=T(),j=Y=>{P.initView(Y),c.push(P.diagramEvent$.subscribe(M=>{a?.(M)})),c.push(P.diagramChange$.subscribe(()=>{const M=i.export(P.model);l?.(M)}))};I.useEffect(()=>{n.current&&(d.current||(j(n.current),d.current=!0,e?.(P)))},[n.current]),I.useEffect(()=>{n.current&&(T(!0),j(n.current),e?.(P))},[s]),I.useEffect(()=>{t&&r.import(P.model,t)},[t]);const F=(Y,M,C)=>{if(b!==void 0&&M.editable!==!1&&!wt(Y.getValue(M.name),C)){Y.setValue(M.name,C);const z=new vt(b.propertySet,void 0);z.setValues(b.getValues()),z.rootElement=b.rootElement,v.valueSet=z,b.rootElement.valueSet=z,P.propertyEditorChanges$?.next()}};return p.jsx("daga-diagram",{children:p.jsx(fi.Provider,{value:s,children:p.jsx(xt.Provider,{value:P,children:p.jsxs("daga-diagram-editor",{children:[p.jsx("div",{className:"daga-append-to",ref:n}),p.jsxs(xt.Provider,{value:P,children:[s.components?.buttons!==void 0&&s.components?.buttons?.enabled!==!1&&p.jsx($i,{location:s.components?.buttons?.location||Bt.BottomRight,direction:s.components?.buttons?.direction||f.Top,enableAction:s.components?.buttons?.enableAction!==!1,enableFilter:s.components?.buttons?.enableFilter===!0,enableLayout:s.components?.buttons?.enableLayout===!0,enableSelection:s.components?.buttons?.enableSelection!==!1,enableZoom:s.components?.buttons?.enableZoom!==!1}),s.components?.palette!==void 0&&s.components?.palette?.enabled!==!1&&s.components?.palette?.sections&&(s.components?.palette?.sections?.length||0)>0&&p.jsx(Ci,{location:s.components?.palette?.location||Bt.TopLeft,direction:s.components?.palette?.direction||f.Bottom,width:s.components?.palette?.width||"12rem",height:s.components?.palette?.height,palettes:s.components?.palette?.sections||[]}),s.components?.propertyEditor!==void 0&&s.components?.propertyEditor?.enabled!==!1&&p.jsx(Si,{location:s.components?.propertyEditor?.location||Bt.TopRight,direction:s.components?.propertyEditor?.direction||f.Bottom,width:s.components?.propertyEditor?.width||"24rem",height:s.components?.propertyEditor?.height,title:h,valueSet:b,onValueChange:F}),s.components?.errors!==void 0&&s.components?.errors?.enabled!==!1&&p.jsx(pi,{})]})]})})})})};exports.DagaDiagram=Ii;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("react/jsx-runtime"),io=require("d3"),kt=require("rxjs"),I=require("react");function so(s){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const e in s)if(e!=="default"){const a=Object.getOwnPropertyDescriptor(s,e);Object.defineProperty(t,e,a.get?a:{enumerable:!0,get:()=>s[e]})}}return t.default=s,Object.freeze(t)}const A=so(io);var f=(s=>(s.Bottom="bottom",s.Left="left",s.Right="right",s.Top="top",s))(f||{}),Bt=(s=>(s.BottomLeft="bottom-left",s.BottomRight="bottom-right",s.TopLeft="top-left",s.TopRight="top-right",s))(Bt||{}),Lt=(s=>(s.Left="left",s.Center="center",s.Right="right",s))(Lt||{}),Xt=(s=>(s.Top="top",s.Center="center",s.Bottom="bottom",s))(Xt||{});const It=s=>[Math.round(s[0]),Math.round(s[1])],ft=(s,t,e)=>t<e?t<=s&&s<=e:e<=s&&s<=t,Se=(s,t,e)=>(s-t[0])/(t[1]-t[0])*(e[1]-e[0])+e[0],Wt=(s,t,e,a,l,r,i)=>{const n=(()=>{switch(r){case"start":return a[0]+(s[0]-t[0]);case"end":return a[1]-(t[1]-s[0]);case"middle":{const d=(t[0]+t[1])/2,c=(a[0]+a[1])/2,h=t[1]-t[0],u=a[1]-a[0],b=(s[0]-d)/h;return c+b*u}default:return Se(s[0],t,a)}})(),o=(()=>{switch(i){case"start":return l[0]+(s[1]-e[0]);case"end":return l[1]-(e[1]-s[1]);case"middle":{const d=(e[0]+e[1])/2,c=(l[0]+l[1])/2,h=e[1]-e[0],u=l[1]-l[0],b=(s[1]-d)/h;return c+b*u}default:return Se(s[1],e,l)}})();return[n,o]},Re=(s,t)=>((s[0]-t[0])**2+(s[1]-t[1])**2)**.5,no=(s,t)=>(ft(s[0][0],t[0][0],t[1][0])||ft(s[1][0],t[1][0],t[0][0])||ft(t[0][0],s[0][0],s[1][0])||ft(t[1][0],s[1][0],s[0][0]))&&(ft(s[0][1],t[0][1],t[1][1])||ft(s[1][1],t[1][1],t[0][1])||ft(t[0][1],s[0][1],s[1][1])||ft(t[1][1],s[1][1],s[0][1]));var S=(s=>(s.Blur="blur",s.Change="change",s.Click="click",s.ContextMenu="contextmenu",s.DoubleClick="dblclick",s.Focus="focus",s.FocusIn="focusin",s.FocusOut="focusout",s.Input="input",s.KeyDown="keydown",s.KeyUp="keyup",s.MouseDown="mousedown",s.MouseEnter="mouseenter",s.MouseLeave="mouseleave",s.MouseMove="mousemove",s.MouseOut="mouseout",s.MouseOver="mouseover",s.MouseUp="mouseup",s.TouchStart="touchstart",s.TouchEnd="touchend",s.Wheel="wheel",s))(S||{}),K=(s=>(s.Alt="Alt",s.AltGraph="AltGraph",s.ArrowDown="ArrowDown",s.ArrowLeft="ArrowLeft",s.ArrowRight="ArrowRight",s.ArrowUp="ArrowUp",s.Backspace="Backspace",s.Control="Control",s.Delete="Delete",s.End="End",s.Enter="Enter",s.Escape="Escape",s.Home="Home",s.OS="OS",s.PageDown="PageDown",s.PageUp="PageUp",s.Shift="Shift",s.Tab="Tab",s))(K||{}),$=(s=>(s.Drag="drag",s.Start="start",s.End="end",s))($||{}),de=(s=>(s.Zoom="zoom",s.Start="start",s.End="end",s))(de||{});const ce=s=>s.replace(/([!"#$%&'()*+,\-./:;<=>?@[\\\]^`{|}])/g,"\\$1");var Ve=(s=>(s.Straight="straight",s.Bezier="bezier",s.Square="square",s))(Ve||{}),pe=(s=>(s.Solid="solid",s.Dashed="dashed",s.GappedDashes="gapped-dashes",s.Dotted="dotted",s))(pe||{});const ro=20,ao=(s,t,e,a,l)=>{if(typeof s=="function")return s(t,e,a,l);if(t.length===0)return"";if(t.length===1)return`M ${t[0][0]} ${t[0][1]}`;{l=l||ro;let r="",i,n;switch(s){case"straight":r+=`M ${t[0][0]} ${t[0][1]}`;for(let o=1;o<t.length;++o)r+=` L ${t[o][0]} ${t[o][1]}`;break;case"bezier":i=e,r+=`M ${t[0][0]} ${t[0][1]}`;for(let o=1;o<t.length;++o){if(o+1>=t.length)switch(a){case f.Bottom:n=f.Top;break;case f.Top:n=f.Bottom;break;case f.Right:n=f.Left;break;case f.Left:n=f.Right;break}else Math.abs(t[o][0]-t[o-1][0])<Math.abs(t[o][1]-t[o-1][1])?t[o][1]>t[o-1][1]?n=f.Bottom:n=f.Top:t[o][0]>t[o-1][0]?n=f.Right:n=f.Left;if(i!==void 0){let d="",c="";const h=(Math.abs(t[o][0]-t[o-1][0])+Math.abs(t[o][1]-t[o-1][1]))/2;switch(i){case f.Bottom:d=`${t[o-1][0]} ${t[o-1][1]+h}`;break;case f.Top:d=`${t[o-1][0]} ${t[o-1][1]-h}`;break;case f.Right:d=`${t[o-1][0]+h} ${t[o-1][1]}`;break;case f.Left:d=`${t[o-1][0]-h} ${t[o-1][1]}`;break}if(n!==void 0){switch(n){case f.Top:c=`${t[o][0]} ${t[o][1]+h}`;break;case f.Bottom:c=`${t[o][0]} ${t[o][1]-h}`;break;case f.Left:c=`${t[o][0]+h} ${t[o][1]}`;break;case f.Right:c=`${t[o][0]-h} ${t[o][1]}`;break}r+=` C ${d} ${c} ${t[o][0]} ${t[o][1]}`}else r+=` Q ${d} ${t[o][0]} ${t[o][1]}`}else if(n!==void 0){let d="";const c=(Math.abs(t[o][0]-t[o-1][0])+Math.abs(t[o][1]-t[o-1][1]))/2;switch(n){case f.Top:d=`${t[o][0]} ${t[o][1]+c}`;break;case f.Bottom:d=`${t[o][0]} ${t[o][1]-c}`;break;case f.Left:d=`${t[o][0]+c} ${t[o][1]}`;break;case f.Right:d=`${t[o][0]-c} ${t[o][1]}`;break}r+=` Q ${d} ${t[o][0]} ${t[o][1]}`}else r+=` L ${t[o][0]} ${t[o][1]}`;i=n}break;case"square":i=e,r+=`M ${t[0][0]} ${t[0][1]}`;for(let o=1;o<t.length;++o){if(o+1>=t.length)switch(a){case f.Bottom:n=f.Top;break;case f.Top:n=f.Bottom;break;case f.Right:n=f.Left;break;case f.Left:n=f.Right;break}switch(i){case f.Bottom:switch(n){case f.Bottom:t[o][1]>t[o-1][1]?(t[o][0]!==t[o-1][0]?(r+=` V ${(t[o][1]+t[o-1][1])/2}`,r+=` H ${t[o][0]}`,r+=` V ${t[o][1]}`):r+=` V ${t[o][1]}`,i=n):t[o][0]>t[o-1][0]?(r+=` V ${t[o-1][1]+l}`,r+=` H ${Math.max(t[o-1][0],t[o][0])+l}`,r+=` V ${t[o][1]-l}`,r+=` H ${t[o][0]}`,r+=` V ${t[o][1]}`):(r+=` V ${t[o-1][1]+l}`,r+=` H ${Math.min(t[o-1][0],t[o][0])-l}`,r+=` V ${t[o][1]-l}`,r+=` H ${t[o][0]}`,r+=` V ${t[o][1]}`);break;case f.Top:r+=` V ${Math.max(t[o-1][1],t[o][1])+l}`,r+=` H ${t[o][0]}`,r+=` V ${t[o][1]}`;break;case f.Left:t[o][1]>t[o-1][1]+l?t[o][0]<t[o-1][0]-l?(r+=` V ${t[o][1]}`,r+=` H ${t[o][0]}`):(r+=` V ${(t[o-1][1]+t[o][1])/2}`,r+=` H ${t[o][0]+l}`,r+=` V ${t[o][1]}`,r+=` H ${t[o][0]}`):t[o][0]<t[o-1][0]-l?(r+=` V ${t[o-1][1]+l}`,r+=` H ${(t[o-1][0]+t[o][0])/2}`,r+=` V ${t[o][1]}`,r+=` H ${t[o][0]}`):(r+=` V ${t[o-1][1]+l}`,r+=` H ${t[o][0]+l}`,r+=` V ${t[o][1]}`,r+=` H ${t[o][0]}`);break;case f.Right:t[o][1]>t[o-1][1]+l?t[o][0]>t[o-1][0]+l?(r+=` V ${t[o][1]}`,r+=` H ${t[o][0]}`):(r+=` V ${(t[o-1][1]+t[o][1])/2}`,r+=` H ${t[o][0]-l}`,r+=` V ${t[o][1]}`,r+=` H ${t[o][0]}`):t[o][0]>t[o-1][0]+l?(r+=` V ${t[o-1][1]+l}`,r+=` H ${(t[o-1][0]+t[o][0])/2}`,r+=` V ${t[o][1]}`,r+=` H ${t[o][0]}`):(r+=` V ${t[o-1][1]+l}`,r+=` H ${t[o][0]-l}`,r+=` V ${t[o][1]}`,r+=` H ${t[o][0]}`);break;default:t[o][1]<t[o-1][1]+l?(r+=` V ${t[o-1][1]+l}`,t[o][0]!==t[o-1][0]&&(r+=` H ${t[o][0]}`),r+=` V ${t[o][1]}`,i=f.Top):(r+=` V ${t[o][1]}`,i=f.Bottom,t[o][0]!==t[o-1][0]&&(r+=` H ${t[o][0]}`,i=t[o][0]>t[o-1][0]?f.Right:f.Left));break}break;case f.Top:switch(n){case f.Top:t[o][1]<t[o-1][1]?(t[o][0]!==t[o-1][0]?(r+=` V ${(t[o][1]+t[o-1][1])/2}`,r+=` H ${t[o][0]}`,r+=` V ${t[o][1]}`):r+=` V ${t[o][1]}`,i=n):t[o][0]<t[o-1][0]?(r+=` V ${t[o-1][1]-l}`,r+=` H ${Math.min(t[o-1][0],t[o][0])-l}`,r+=` V ${t[o][1]+l}`,r+=` H ${t[o][0]}`,r+=` V ${t[o][1]}`):(r+=` V ${t[o-1][1]-l}`,r+=` H ${Math.max(t[o-1][0],t[o][0])+l}`,r+=` V ${t[o][1]+l}`,r+=` H ${t[o][0]}`,r+=` V ${t[o][1]}`);break;case f.Bottom:r+=` V ${Math.min(t[o-1][1],t[o][1])-l}`,r+=` H ${t[o][0]}`,r+=` V ${t[o][1]}`;break;case f.Right:t[o][1]<t[o-1][1]-l?t[o][0]>t[o-1][0]+l?(r+=` V ${t[o][1]}`,r+=` H ${t[o][0]}`):(r+=` V ${(t[o-1][1]+t[o][1])/2}`,r+=` H ${t[o][0]-l}`,r+=` V ${t[o][1]}`,r+=` H ${t[o][0]}`):t[o][0]>t[o-1][0]+l?(r+=` V ${t[o-1][1]-l}`,r+=` H ${(t[o-1][0]+t[o][0])/2}`,r+=` V ${t[o][1]}`,r+=` H ${t[o][0]}`):(r+=` V ${t[o-1][1]-l}`,r+=` H ${t[o][0]-l}`,r+=` V ${t[o][1]}`,r+=` H ${t[o][0]}`);break;case f.Left:t[o][1]<t[o-1][1]-l?t[o][0]<t[o-1][0]-l?(r+=` V ${t[o][1]}`,r+=` H ${t[o][0]}`):(r+=` V ${(t[o-1][1]+t[o][1])/2}`,r+=` H ${t[o][0]+l}`,r+=` V ${t[o][1]}`,r+=` H ${t[o][0]}`):t[o][0]<t[o-1][0]-l?(r+=` V ${t[o-1][1]-l}`,r+=` H ${(t[o-1][0]+t[o][0])/2}`,r+=` V ${t[o][1]}`,r+=` H ${t[o][0]}`):(r+=` V ${t[o-1][1]-l}`,r+=` H ${t[o][0]+l}`,r+=` V ${t[o][1]}`,r+=` H ${t[o][0]}`);break;default:t[o][1]>t[o-1][1]-l?(r+=` V ${t[o-1][1]-l}`,t[o][0]!==t[o-1][0]&&(r+=` H ${t[o][0]}`),r+=` V ${t[o][1]}`,i=f.Bottom):(r+=` V ${t[o][1]}`,i=f.Top,t[o][0]!==t[o-1][0]&&(r+=` H ${t[o][0]}`,i=t[o][0]>t[o-1][0]?f.Right:f.Left));break}break;case f.Left:switch(n){case f.Left:t[o][0]<t[o-1][0]?(t[o][1]!==t[o-1][1]?(r+=` H ${(t[o][0]+t[o-1][0])/2}`,r+=` V ${t[o][1]}`,r+=` H ${t[o][0]}`):r+=` H ${t[o][0]}`,i=n):t[o][1]<t[o-1][1]?(r+=` H ${t[o-1][0]-l}`,r+=` V ${Math.min(t[o-1][1],t[o][1])-l}`,r+=` H ${t[o][0]+l}`,r+=` V ${t[o][1]}`,r+=` H ${t[o][0]}`):(r+=` H ${t[o-1][0]-l}`,r+=` V ${Math.max(t[o-1][1],t[o][1])+l}`,r+=` H ${t[o][0]+l}`,r+=` V ${t[o][1]}`,r+=` H ${t[o][0]}`);break;case f.Right:r+=` H ${Math.min(t[o-1][0],t[o][0])-l}`,r+=` V ${t[o][1]}`,r+=` H ${t[o][0]}`;break;case f.Bottom:t[o][0]<t[o-1][0]-l?t[o][1]>t[o-1][1]+l?(r+=` H ${t[o][0]}`,r+=` V ${t[o][1]}`):(r+=` H ${(t[o-1][0]+t[o][0])/2}`,r+=` V ${t[o][1]-l}`,r+=` H ${t[o][0]}`,r+=` V ${t[o][1]}`):t[o][1]>t[o-1][1]+l?(r+=` H ${t[o-1][0]-l}`,r+=` V ${(t[o-1][1]+t[o][1])/2}`,r+=` H ${t[o][0]}`,r+=` V ${t[o][1]}`):(r+=` H ${t[o-1][0]-l}`,r+=` V ${t[o][1]-l}`,r+=` H ${t[o][0]}`,r+=` V ${t[o][1]}`);break;case f.Top:t[o][0]<t[o-1][0]-l?t[o][1]<t[o-1][1]-l?(r+=` H ${t[o][0]}`,r+=` V ${t[o][1]}`):(r+=` H ${(t[o-1][0]+t[o][0])/2}`,r+=` V ${t[o][1]+l}`,r+=` H ${t[o][0]}`,r+=` V ${t[o][1]}`):t[o][1]<t[o-1][1]-l?(r+=` H ${t[o-1][0]-l}`,r+=` V ${(t[o-1][1]+t[o][1])/2}`,r+=` H ${t[o][0]}`,r+=` V ${t[o][1]}`):(r+=` H ${t[o-1][0]-l}`,r+=` V ${t[o][1]+l}`,r+=` H ${t[o][0]}`,r+=` V ${t[o][1]}`);break;default:t[o][0]>t[o-1][0]-l?(r+=` H ${t[o-1][0]-l}`,t[o][1]!==t[o-1][1]&&(r+=` V ${t[o][1]}`),r+=` H ${t[o][0]}`,i=f.Right):(r+=` H ${t[o][0]}`,i=f.Left,t[o][1]!==t[o-1][1]&&(r+=` V ${t[o][1]}`,i=t[o][1]>t[o-1][1]?f.Bottom:f.Top));break}break;case f.Right:switch(n){case f.Right:t[o][0]>t[o-1][0]?(t[o][1]!==t[o-1][1]?(r+=` H ${(t[o][0]+t[o-1][0])/2}`,r+=` V ${t[o][1]}`,r+=` H ${t[o][0]}`):r+=` H ${t[o][0]}`,i=n):t[o][1]>t[o-1][1]?(r+=` H ${t[o-1][0]+l}`,r+=` V ${Math.max(t[o-1][1],t[o][1])+l}`,r+=` H ${t[o][0]-l}`,r+=` V ${t[o][1]}`,r+=` H ${t[o][0]}`):(r+=` H ${t[o-1][0]+l}`,r+=` V ${Math.min(t[o-1][1],t[o][1])-l}`,r+=` H ${t[o][0]-l}`,r+=` V ${t[o][1]}`,r+=` H ${t[o][0]}`);break;case f.Left:r+=` H ${Math.max(t[o-1][0],t[o][0])+l}`,r+=` V ${t[o][1]}`,r+=` H ${t[o][0]}`;break;case f.Top:t[o][0]>t[o-1][0]+l?t[o][1]<t[o-1][1]-l?(r+=` H ${t[o][0]}`,r+=` V ${t[o][1]}`):(r+=` H ${(t[o-1][0]+t[o][0])/2}`,r+=` V ${t[o][1]+l}`,r+=` H ${t[o][0]}`,r+=` V ${t[o][1]}`):t[o][1]<t[o-1][1]-l?(r+=` H ${t[o-1][0]+l}`,r+=` V ${(t[o-1][1]+t[o][1])/2}`,r+=` H ${t[o][0]}`,r+=` V ${t[o][1]}`):(r+=` H ${t[o-1][0]+l}`,r+=` V ${t[o][1]+l}`,r+=` H ${t[o][0]}`,r+=` V ${t[o][1]}`);break;case f.Bottom:t[o][0]>t[o-1][0]+l?t[o][1]>t[o-1][1]+l?(r+=` H ${t[o][0]}`,r+=` V ${t[o][1]}`):(r+=` H ${(t[o-1][0]+t[o][0])/2}`,r+=` V ${t[o][1]-l}`,r+=` H ${t[o][0]}`,r+=` V ${t[o][1]}`):t[o][1]>t[o-1][1]+l?(r+=` H ${t[o-1][0]+l}`,r+=` V ${(t[o-1][1]+t[o][1])/2}`,r+=` H ${t[o][0]}`,r+=` V ${t[o][1]}`):(r+=` H ${t[o-1][0]+l}`,r+=` V ${t[o][1]-l}`,r+=` H ${t[o][0]}`,r+=` V ${t[o][1]}`);break;default:t[o][0]<t[o-1][0]+l?(r+=` H ${t[o-1][0]+l}`,t[o][1]!==t[o-1][1]&&(r+=` V ${t[o][1]}`),r+=` H ${t[o][0]}`,i=f.Left):(r+=` H ${t[o][0]}`,i=f.Right,t[o][1]!==t[o-1][1]&&(r+=` V ${t[o][1]}`,i=t[o][1]>t[o-1][1]?f.Bottom:f.Top));break}break;default:t[o][0]!==t[o-1][0]&&(r+=` H ${t[o][0]}`,i=t[o][0]>t[o-1][0]?f.Right:f.Left),t[o][1]!==t[o-1][1]&&(r+=` V ${t[o][1]}`,i=t[o][1]>t[o-1][1]?f.Bottom:f.Top)}}break}return r}},he=(s,t)=>{switch(s){case"dotted":return`${t}`;case"dashed":return`${4*t} ${t}`;case"gapped-dashes":return`${4*t} ${4*t}`;default:return"none"}},B=(s,t)=>{const e=s.indexOf(t);return e>=0&&s.splice(e,1),s};var Tt=(s=>(s.Ellipse="ellipse",s.Empty="empty",s.Folder="folder",s.Hexagon="hexagon",s.Octagon="octagon",s.Pill="pill",s.Rectangle="rectangle",s.Rhombus="rhombus",s.RoundedRectangle="rounded-rectangle",s.StickyNote="sticky-note",s))(Tt||{});const ge=(s,t,e,a,l)=>{if(typeof s=="function")return s(t,e,a,l);switch(s){case"ellipse":return Oe(t,e,a,l);case"empty":return lo();case"folder":return co(t,e,a,l);case"hexagon":return ho(t,e,a,l);case"octagon":return go(t,e,a,l);case"pill":return Yt(t,e,a,l);case"rectangle":return xe(t,e,a,l);case"rhombus":return fo(t,e,a,l);case"rounded-rectangle":return uo(t,e,a,l);case"sticky-note":return po(t,e,a,l);default:return xe(t,e,a,l)}},Oe=(s,t,e,a)=>`M ${s+e/2} ${t} A ${e/2} ${a/2} 0 0 0 ${s+e/2} ${t+a} A ${e/2} ${a/2} 0 1 0 ${s+e/2} ${t} Z`,lo=()=>"Z",co=(s,t,e,a)=>`M ${s} ${t} L ${s+e/3} ${t} L ${s+e/2} ${t+a/6} L ${s+e} ${t+a/6} L ${s+e} ${t+a} L ${s} ${t+a} Z`,ho=(s,t,e,a)=>`M ${s+e/4} ${t} L ${s+3*e/4} ${t} L ${s+e} ${t+a/2} L ${s+3*e/4} ${t+a} L ${s+e/4} ${t+a} L ${s} ${t+a/2} Z`,go=(s,t,e,a)=>`M ${s+e/4} ${t} L ${s+3*e/4} ${t} L ${s+e} ${t+a/4} L ${s+e} ${t+3*a/4} L ${s+3*e/4} ${t+a} L ${s+e/4} ${t+a} L ${s} ${t+3*a/4} L ${s} ${t+a/4} L ${s+e/4} ${t} Z`,Yt=(s,t,e,a)=>a<e?`M ${s+a/2} ${t} L ${s+e-a/2} ${t} A ${a/2} ${a/2} 0 0 1 ${s+e} ${t+a/2} A ${a/2} ${a/2} 0 0 1 ${s+e-a/2} ${t+a} L ${s+a/2} ${t+a} A ${a/2} ${a/2} 0 0 1 ${s} ${t+a/2} A ${a/2} ${a/2} 0 0 1 ${s+a/2} ${t} Z`:a>e?`M ${s} ${t+e/2} L ${s} ${t+a-e/2} A ${e/2} ${e/2} 0 0 0 ${s+e/2} ${t+a} A ${e/2} ${e/2} 0 0 0 ${s+e} ${t+a-e/2} L ${s+e} ${t+e/2} A ${e/2} ${e/2} 0 0 0 ${s+e/2} ${t} A ${e/2} ${e/2} 0 0 0 ${s} ${t+e/2} Z`:Oe(s,t,e,a),xe=(s,t,e,a)=>`M ${s} ${t} L ${s+e} ${t} L ${s+e} ${t+a} L ${s} ${t+a} Z`,fo=(s,t,e,a)=>`M ${s+e/2} ${t} L ${s+e} ${t+a/2} L ${s+e/2} ${t+a} L ${s} ${t+a/2} Z`,uo=(s,t,e,a)=>`M ${s+e/4} ${t} L ${s+3*e/4} ${t} A ${e/4} ${a/4} 0 0 1 ${s+e} ${t+a/4} L ${s+e} ${t+3*a/4} A ${e/4} ${a/4} 0 0 1 ${s+3*e/4} ${t+a} L ${s+e/4} ${t+a} A ${e/4} ${a/4} 0 0 1 ${s} ${t+3*a/4} L ${s} ${t+a/4} A ${e/4} ${a/4} 0 0 1 ${s+e/4} ${t} Z`,po=(s,t,e,a)=>`M ${s} ${t} L ${s+3*e/4} ${t} L ${s+3*e/4} ${t+a/4} L ${s+3*e/4} ${t} L ${s+e} ${t+a/4} L ${s+3*e/4} ${t+a/4} L ${s+e} ${t+a/4} L ${s+e} ${t+a} L ${s} ${t+a} Z`;var L=(s=>(s.AllScroll="all-scroll",s.Auto="auto",s.Crosshair="crosshair",s.EWResize="ew-resize",s.Grab="grab",s.Grabbing="grabbing",s.Move="move",s.NoDrop="no-drop",s.NSResize="ns-resize",s.NotAllowed="not-allowed",s.ZoomIn="zoom-in",s.ZoomOut="zoom-out",s))(L||{});const mo=s=>Math.max(...s.split(`
|
|
2
|
+
`).map(t=>t.length)),vo=s=>s.match(/\n/g)?.length||0,Z=[];for(let s=0;s<256;++s)Z.push((s+256).toString(16).slice(1));function yo(s,t=0){return(Z[s[t+0]]+Z[s[t+1]]+Z[s[t+2]]+Z[s[t+3]]+"-"+Z[s[t+4]]+Z[s[t+5]]+"-"+Z[s[t+6]]+Z[s[t+7]]+"-"+Z[s[t+8]]+Z[s[t+9]]+"-"+Z[s[t+10]]+Z[s[t+11]]+Z[s[t+12]]+Z[s[t+13]]+Z[s[t+14]]+Z[s[t+15]]).toLowerCase()}let oe;const bo=new Uint8Array(16);function ko(){if(!oe){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");oe=crypto.getRandomValues.bind(crypto)}return oe(bo)}const wo=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),Ce={randomUUID:wo};function So(s,t,e){s=s||{};const a=s.random??s.rng?.()??ko();if(a.length<16)throw new Error("Random bytes length must be >= 16");return a[6]=a[6]&15|64,a[8]=a[8]&63|128,yo(a)}function $e(s,t,e){return Ce.randomUUID&&!s?Ce.randomUUID():So(s)}const St=s=>{if(typeof s!="object")return s;if(Array.isArray(s))return s.map(St);const t={};for(const e of Object.entries(s))t[e[0]]=St(e[1]);return t},nt=s=>{const{selected:t,highlighted:e,selectedAndHighlighted:a,...l}=s,r=l,i={...r,...t},n={...r,...e},o={...r,...e,...t,...a};return{defaultLook:r,selectedLook:i,highlightedLook:n,selectedAndHighlightedLook:o}};class Kt{constructor(){this.entities=[],this.entityMap={}}get length(){return this.size()}all(){return[...this.entities]}add(t){this.entityMap[t.id]===void 0&&(this.entityMap[t.id]=t,this.entities.push(t))}clear(){for(;this.entities.length>0;)this.remove(this.entities[0].id)}contains(t){return this.entityMap[t]!==void 0}count(t){return this.entities.filter(t).length}filter(t){return this.entities.filter(t)}find(t){return this.entities.find(t)}get(t){return this.entityMap[t]}map(t){return this.entities.map(t)}remove(t){const e=this.get(t);e!==void 0&&(delete this.entityMap[t],B(this.entities,e))}size(){return this.entities.length}*[Symbol.iterator](){for(const t of this.entities)yield t}}const Nt=0;class Ct{constructor(t,e){this.selfRemoved=!1,this.selfRemovedTimestamp=null,this.model=t,this._id=e}get id(){return this._id}get highlighted(){return this.model.canvas?.userHighlight?.contains(this.id)||!1}get selected(){return this.model.canvas?.userSelection?.contains(this.id)||!1}select(){return this.model.canvas?.selectCanvasView()?.select(`[id='${ce(this.id)}']`)}}class gt extends Kt{all(t=!1){return t?super.all():super.filter(e=>!e.removed)}contains(t,e=!1){return e?super.contains(t):super.contains(t)&&!this.entityMap[t].removed}count(t,e=!1){return e?super.count(t):super.count((a,l,r)=>t(a,l,r)&&!a.removed)}filter(t,e=!1){return e?super.filter(t):super.filter((a,l,r)=>t(a,l,r)&&!a.removed)}find(t,e=!1){return e?super.find(t):super.find((a,l,r)=>t(a,l,r)&&!a.removed)}get(t,e=!1){return e?super.get(t):this.contains(t)?super.get(t):void 0}map(t,e=!1){return e?super.map(t):super.filter(a=>!a.removed).map(t)}remove(t){const e=this.get(t,!0);e!==void 0&&(delete this.entityMap[t],B(this.entities,e))}size(t=!1){return t?super.size():super.filter(e=>!e.removed).length}*[Symbol.iterator](t=!1){if(t)for(const e of this.entities)yield e;else for(const e of this.entities.filter(a=>!a.removed))yield e}}class xo{constructor(t,e,a,l,r,i,n){this.name=t,this.label=e,this.type=a,this.defaultValue=l,this.basic=r,this.editable=i,this.rootAttribute=n,this.options=void 0,this.properties=void 0}}var N=(s=>(s.Boolean="boolean",s.Color="color",s.Date="date",s.Datetime="datetime",s.Number="number",s.Object="object",s.Option="option",s.OptionList="option-list",s.OptionSet="option-set",s.Text="text",s.TextArea="text-area",s.TextList="text-list",s.TextSet="text-set",s.TextMap="text-map",s.Time="time",s.Url="url",s))(N||{});class qt{constructor(t=[]){this.propertyList=t,this.propertyMap={};for(const e of this.propertyList)this.propertyMap[e.name]=e}getProperty(t){return this.propertyMap[t]}hasProperty(t){return this.propertyMap[t]!==void 0}hasProperties(){return this.propertyList.length>0}}function bt(s,t){return!t||s[0]>t[0]?!0:s[0]===t[0]?s[1]>=t[1]:!1}const Ie=s=>s==null||s===""||s instanceof Array&&s.length===0||s instanceof Object&&Object.keys(s).length===0,wt=(s,t)=>s===t||JSON.stringify(s)===JSON.stringify(t),_e=(s,t,e)=>{const a={},l={};for(const r in e.propertySet.propertyMap)if(e.propertySet.propertyMap[r].type===N.Object){const i=_e(s[r],t[r],e.getSubValueSet(r));Object.keys(i[0]).length>0&&Object.keys(i[1]).length>0&&(a[r]=i[0],l[r]=i[1])}else wt(s[r],t[r])||(a[r]=s[r],l[r]=t[r]);return[a,l]},Co=s=>s!=null&&s.constructor===Object;class vt{constructor(t,e){this.displayedProperties=[],this.hiddenProperties=[],this.values={},this.valueSets={},this.ownTimestamps={},this.propertySet=t,this.rootElement=e,this.resetValues()}getRootElementValue(t){if(this.rootElement){if(typeof t=="string")return this.rootElement[t];if(Array.isArray(t)&&t.length>0){let e=this.rootElement;for(const a of t){if(e==null)return;e=e[a]}return e}}}setRootElementValue(t,e){if(this.rootElement){if(typeof t=="string"&&(this.rootElement[t]=e),Array.isArray(t)&&t.length>0){let a=this.rootElement;for(let l=0;l<t.length-1;++l){const r=t[l];if(a==null)return;a=a[r]}if(a==null)return;a[t[t.length-1]]=e}typeof this.rootElement.updateInView=="function"&&this.rootElement.updateInView()}}getValue(t){const e=this.propertySet.getProperty(t)?.rootAttribute;return e!=null&&(this.values[t]=this.getRootElementValue(e)),this.propertySet.getProperty(t).type===N.Object?this.valueSets[t].getValues():this.values[t]}getValues(){const t={};for(const e in this.propertySet.propertyMap)this.propertySet.getProperty(e).type===N.Object?t[e]=this.valueSets[e].getValues():t[e]=this.getValue(e);return t}getValuesForKeys(t){const e={};for(const a in t)this.propertySet.getProperty(a).type===N.Object?e[a]=this.valueSets[a].getValuesForKeys(t[a]):e[a]=this.getValue(a);return e}getTimestamps(){const t={};for(const e in this.propertySet.propertyMap)if(this.propertySet.getProperty(e).type===N.Object)t[e]=this.valueSets[e].getTimestamps();else{const l=this.ownTimestamps[e];l&&(t[e]=l)}return t}hasValue(t){const e=this.getValue(t);return!Ie(e)}hasSetValue(t){const e=this.getValue(t),a=this.propertySet.getProperty(t);return a&&a.type===N.Object?this.getSubValueSet(t).hasAnySetValue():!Ie(e)&&!wt(e,a?.defaultValue)}hasAnySetValue(){for(const t of this.propertySet.propertyList)if(this.hasSetValue(t.name))return!0;return!1}setValue(t,e){const a=this.propertySet.getProperty(t);if(a){a.type===N.Object?this.valueSets[t].setValues(e):(this.values[t]=e,wt(e,a.defaultValue)||this.displayProperty(a));const l=a.rootAttribute;l!=null&&this.setRootElementValue(l,e)}}setValues(t){this.resetValues();for(const e in t)this.propertySet.getProperty(e).type===N.Object?this.valueSets[e].setValues(t[e]):this.setValue(e,t[e])}setTimestamps(t){this.ownTimestamps={};for(const e in t)this.propertySet.getProperty(e).type===N.Object?this.valueSets[e].setTimestamps(t[e]):this.ownTimestamps[e]=t[e]}overwriteValues(t){for(const e in t)this.propertySet.getProperty(e).type===N.Object?this.valueSets[e].overwriteValues(t[e]):this.setValue(e,t[e])}overwriteValuesLww(t,e){for(const a in t)this.propertySet.getProperty(a).type===N.Object?this.valueSets[a].overwriteValuesLww(t[a],e):bt(e,this.ownTimestamps[a])&&(this.setValue(a,t[a]),this.ownTimestamps[a]=e)}resetValues(){this.displayedProperties=[],this.hiddenProperties=[],this.ownTimestamps={};for(const t in this.propertySet.propertyMap){const e=this.propertySet.getProperty(t),a=e.rootAttribute;e.type===N.Object?this.valueSets[t]=this.constructSubValueSet(t):this.values[t]=St(e.defaultValue),a!=null&&e.defaultValue!==void 0&&!wt(this.getRootElementValue(a),e.defaultValue)&&this.setRootElementValue(a,this.values[t]),e.basic!==!1?this.displayedProperties.push(e):this.hiddenProperties.push(e)}}constructSubValueSet(t){const e=this.propertySet.getProperty(t),a=new qt(e.properties),l=new vt(a,this.rootElement);return l.overwriteValues(St(e.defaultValue)),l}getSubValueSet(t){return this.valueSets[t]}displayProperty(t){this.displayedProperties.includes(t)||(this.displayedProperties.push(t),B(this.hiddenProperties,t))}hideProperty(t){this.hiddenProperties.includes(t)||(this.hiddenProperties.push(t),B(this.displayedProperties,t))}}const ot={name:"",label:null,look:{lookType:"connection-look",color:"#000000",thickness:1,shape:Ve.Straight,style:pe.Solid,selected:{color:"#AA00AA"},highlighted:{thickness:2}},startMarkerLook:void 0,endMarkerLook:void 0,startTypes:[],endTypes:[],properties:[]};class He{constructor(t){const e={...ot,...t};this.id=e.id,this.name=e.name,this.label=e.label;const a=nt(e.look);if(this.defaultLook=a.defaultLook,this.selectedLook=a.selectedLook,this.highlightedLook=a.highlightedLook,this.selectedAndHighlightedLook=a.selectedAndHighlightedLook,e.startMarkerLook!==void 0){const l=nt(e.startMarkerLook);this.defaultStartMarkerLook=l.defaultLook,this.selectedStartMarkerLook=l.selectedLook,this.highlightedStartMarkerLook=l.highlightedLook,this.selectedAndHighlightedStartMarkerLook=l.selectedAndHighlightedLook}else this.defaultStartMarkerLook=null,this.selectedStartMarkerLook=null,this.highlightedStartMarkerLook=null,this.selectedAndHighlightedStartMarkerLook=null;if(e.endMarkerLook!==void 0){const l=nt(e.endMarkerLook);this.defaultEndMarkerLook=l.defaultLook,this.selectedEndMarkerLook=l.selectedLook,this.highlightedEndMarkerLook=l.highlightedLook,this.selectedAndHighlightedEndMarkerLook=l.selectedAndHighlightedLook}else this.defaultEndMarkerLook=null,this.selectedEndMarkerLook=null,this.highlightedEndMarkerLook=null,this.selectedAndHighlightedEndMarkerLook=null;this.startTypes=e.startTypes,this.endTypes=e.endTypes,this.propertySet=new qt(e.properties)}canStartFromType(t){return this.startTypes.indexOf(t)>=0}canFinishOnType(t){return this.endTypes.indexOf(t)>=0}}class lt extends Ct{constructor(t,e,a,l,r){if(t.connections.get(r)!==void 0)throw new Error(`DiagramConnection with id "${r}" already exists`);if(!r)throw new Error("DiagramConnection cannot have an empty or null id");super(t,r),this.startCoords=[0,0],this.endCoords=[0,0],this.startLabel="",this.middleLabel="",this.endLabel="",this.points=[],this._type=e,this.valueSet=new vt(e.propertySet,this),this.originalData={},this.setStart(a),this.setEnd(l)}get type(){return this._type}set type(t){t!==this._type&&(this._type=t,this.valueSet&&(this.valueSet=new vt(t.propertySet,this)),this.model.canvas?.userSelection?.openInPropertyEditor(this,!1),this.updateInView())}get typeString(){return this.type.id}set typeString(t){if(t!==this.type.id){const e=this.model.connections.types.get(t);e&&(this.type=e)}}get name(){return this.middleLabel}set name(t){this.middleLabel=t}get look(){return this.selected?this.highlighted?this._selectedAndHighlightedLook!==void 0?this._selectedAndHighlightedLook:this.type.selectedAndHighlightedLook:this._selectedLook!==void 0?this._selectedLook:this.type.selectedLook:this.highlighted?this._highlightedLook!==void 0?this._highlightedLook:this.type.highlightedLook:this._defaultLook!==void 0?this._defaultLook:this.type.defaultLook}set look(t){this.lookConfig=t}get lookConfig(){return this._lookConfig}set lookConfig(t){if(this._lookConfig=t,t){const e=nt(t);this._defaultLook={...this._defaultLook,...e.defaultLook},this._selectedLook={...this._selectedLook,...e.selectedLook},this._highlightedLook={...this._highlightedLook,...e.highlightedLook},this._selectedAndHighlightedLook={...this._selectedAndHighlightedLook,...e.selectedAndHighlightedLook}}else this._defaultLook=t,this._selectedLook=t,this._highlightedLook=t,this._selectedAndHighlightedLook=t}get startMarkerLook(){return this.selected?this.highlighted?this._selectedAndHighlightedStartMarkerLook!==void 0?this._selectedAndHighlightedStartMarkerLook:this.type.selectedAndHighlightedStartMarkerLook:this._selectedStartMarkerLook!==void 0?this._selectedStartMarkerLook:this.type.selectedStartMarkerLook:this.highlighted?this._highlightedStartMarkerLook!==void 0?this._highlightedStartMarkerLook:this.type.highlightedStartMarkerLook:this._defaultStartMarkerLook!==void 0?this._defaultStartMarkerLook:this.type.defaultStartMarkerLook}set startMarkerLook(t){this.startMarkerLookConfig=t}get startMarkerLookConfig(){return this._startMarkerLookConfig}set startMarkerLookConfig(t){if(this._startMarkerLookConfig=t,t){const e=nt(t);this._defaultStartMarkerLook={...this._defaultStartMarkerLook,...e.defaultLook},this._selectedStartMarkerLook={...this._selectedStartMarkerLook,...e.selectedLook},this._highlightedStartMarkerLook={...this._highlightedStartMarkerLook,...e.highlightedLook},this._selectedAndHighlightedStartMarkerLook={...this._selectedAndHighlightedStartMarkerLook,...e.selectedAndHighlightedLook}}else this._defaultStartMarkerLook=t,this._selectedStartMarkerLook=t,this._highlightedStartMarkerLook=t,this._selectedAndHighlightedStartMarkerLook=t}get endMarkerLook(){return this.selected?this.highlighted?this._selectedAndHighlightedEndMarkerLook!==void 0?this._selectedAndHighlightedEndMarkerLook:this.type.selectedAndHighlightedEndMarkerLook:this._selectedEndMarkerLook!==void 0?this._selectedEndMarkerLook:this.type.selectedEndMarkerLook:this.highlighted?this._highlightedEndMarkerLook!==void 0?this._highlightedEndMarkerLook:this.type.highlightedEndMarkerLook:this._defaultEndMarkerLook!==void 0?this._defaultEndMarkerLook:this.type.defaultEndMarkerLook}set endMarkerLook(t){this.endMarkerLookConfig=t}get endMarkerLookConfig(){return this._endMarkerLookConfig}set endMarkerLookConfig(t){if(this._endMarkerLookConfig=t,t){const e=nt(t);this._defaultEndMarkerLook={...this._defaultEndMarkerLook,...e.defaultLook},this._selectedEndMarkerLook={...this._selectedEndMarkerLook,...e.selectedLook},this._highlightedEndMarkerLook={...this._highlightedEndMarkerLook,...e.highlightedLook},this._selectedAndHighlightedEndMarkerLook={...this._selectedAndHighlightedEndMarkerLook,...e.selectedAndHighlightedLook}}else this._defaultEndMarkerLook=t,this._selectedEndMarkerLook=t,this._highlightedEndMarkerLook=t,this._selectedAndHighlightedEndMarkerLook=t}get removed(){return this.selfRemoved||this.start!==void 0&&this.start.removed||this.end!==void 0&&this.end.removed}updateInView(){this.model.canvas?.updateConnectionsInView(this.id)}raise(){this.select()?.raise()}setStart(t){this.start!==t?(this.start!==void 0&&B(this.start.outgoingConnections,this),this.start=t,t!==void 0&&(t.outgoingConnections.push(this),this.startDirection=t?.direction,this.startCoords=t?.connectionPoint||[0,0])):(this.startDirection=t?.direction,this.startCoords=t?.connectionPoint||[0,0]),this.updateInView()}setEnd(t){this.end!==t?(this.end!==void 0&&B(this.end.incomingConnections,this),this.end=t,t!==void 0&&(t.incomingConnections.push(this),this.endDirection=t?.direction,this.endCoords=t?.connectionPoint||[0,0])):(this.endDirection=t?.direction,this.endCoords=t?.connectionPoint||[0,0]),this.updateInView()}tighten(){const t=this.model.canvas?.allowConnectionLoops||!1,e=this.model.canvas?.allowSharingPorts!==!1,a=this.model.canvas?.allowSharingBothPorts||!1;if(this.start?.rootElement&&this.end){const l=this.start.rootElement.ports.map(r=>[r,r.distanceTo(this.end.coords)]).sort((r,i)=>r[1]-i[1]).map(r=>r[0]);t:for(const r of l){if(!t&&r===this.end||!r.allowsOutgoing||!e&&(r.incomingConnections.filter(i=>!i.removed&&i!==this).length>0||r.outgoingConnections.filter(i=>!i.removed&&i!==this).length>0))continue t;if(!a){for(const i of r.outgoingConnections.filter(n=>!n.removed))if(i!==this&&i.end===this.end)continue t;for(const i of r.incomingConnections.filter(n=>!n.removed))if(i!==this&&i.start===this.end)continue t}if(r===this.start)break t;this.setStart(r);break t}}if(this.end?.rootElement&&this.start){const l=this.end.rootElement.ports.map(r=>[r,r.distanceTo(this.start.coords)]).sort((r,i)=>r[1]-i[1]).map(r=>r[0]);t:for(const r of l){if(!t&&r===this.start||!r.allowsIncoming||!e&&(r.incomingConnections.filter(i=>!i.removed&&i!==this).length>0||r.outgoingConnections.filter(i=>!i.removed&&i!==this).length>0))continue t;if(!a){for(const i of r.incomingConnections.filter(n=>!n.removed))if(i!==this&&i.start===this.start)continue t;for(const i of r.outgoingConnections.filter(n=>!n.removed))if(i!==this&&i.end===this.start)continue t}if(r===this.end)break t;this.setEnd(r);break t}}}getPriority(){return this.start?this.end?Math.min(this.start.getPriority(),this.end.getPriority()):this.start.getPriority():this.end?this.end.getPriority():Nt}}class $o extends gt{constructor(t){super(),this.types=new Kt,this.model=t}new(t,e,a,l){let r;if(t instanceof He)r=t;else{const n=this.types.get(t);if(n===void 0)throw new TypeError(`Connection type with id '${t}' could not be found.`);r=n}const i=new lt(this.model,r,e,a,l);return super.add(i),i.updateInView(),i.valueSet.resetValues(),i}remove(t){const e=this.get(t,!0);e&&(B(e.start?.outgoingConnections||[],e),B(e.end?.incomingConnections||[],e),super.remove(t),e.updateInView())}}const O={editable:!0,fontSize:0,margin:0,padding:0,fontFamily:"'Wonder Unit Sans', sans-serif",color:"#000000",selectedColor:"#000000",backgroundColor:"#00000000",horizontalAlign:Lt.Center,verticalAlign:Xt.Center,orientation:f.Top,fit:!1,shrink:!0};class ct extends Ct{constructor(t,e,a,l,r,i,n,o,d,c,h,u,b,m,x,g){const v=`${e?.id}_field`;if(t.fields.get(v)!==void 0)throw new Error("DiagramField for rootElement already exists");if(super(t,v),this.textTimestamp=null,this.rootElement=e,this.coords=a,this.width=l,this.height=r,this.fontSize=i,this.fontFamily=n,this.color=o,this.selectedColor=d,this.horizontalAlign=c,this.verticalAlign=h,!isNaN(Number(u)))this.orientation=Number(u);else switch(u){case f.Top:this.orientation=0;break;case f.Right:this.orientation=90;break;case f.Bottom:this.orientation=180;break;case f.Left:this.orientation=270;break;default:this.orientation=0}this.defaultText=b,this._text=b,this.editable=m,this.fit=x,this.shrink=g}get text(){return this._text}set text(t){(t==null||t?.trim()==="")&&(t=this.defaultText),this._text=t,this.updateInView(),this.fit&&this.model.canvas?.fitFieldRootInView(this.id,this.shrink)}get removed(){return this.selfRemoved||this.rootElement!==void 0&&this.rootElement.removed}updateInView(){this.model.canvas?.updateFieldsInView(this.id)}raise(){this.select()?.raise()}move(t){this.coords=t,this.updateInView()}getPriority(){return this.rootElement?.getPriority()||Nt}}class Io extends gt{constructor(t){super(),this.model=t}new(t,e,a,l,r,i,n,o,d,c,h,u,b,m,x){const g=new ct(this.model,t,e,n,o,a,l,r,i,d,c,h,u,b,m,x);return super.add(g),g.updateInView(),t!==void 0&&(t.label=g),g}remove(t){const e=this.get(t,!0);e&&(e.rootElement?.label!==void 0&&e.rootElement.label===e&&(e.rootElement.label=void 0),super.remove(t),e.updateInView())}}const q=s=>s?.margin===null||s?.margin===void 0?O.margin:typeof s.margin=="number"?s.margin:s.margin.length===0?O.margin:s.margin.length===1||s.margin.length===2?s.margin[0]:(s.margin.length===3,s.margin[2]),D=s=>s?.margin===null||s?.margin===void 0?O.margin:typeof s.margin=="number"?s.margin:s.margin.length===0?O.margin:s.margin.length===1?s.margin[0]:s.margin.length===2||s.margin.length===3?s.margin[1]:s.margin[3],it=s=>s?.margin===null||s?.margin===void 0?O.margin:typeof s.margin=="number"?s.margin:s.margin.length===0?O.margin:s.margin.length===1?s.margin[0]:(s.margin.length===2||s.margin.length===3,s.margin[1]),G=s=>s?.margin===null||s?.margin===void 0?O.margin:typeof s.margin=="number"?s.margin:s.margin.length===0?O.margin:(s.margin.length===1||s.margin.length===2||s.margin.length===3,s.margin[0]),Vt=s=>s?.padding===null||s?.padding===void 0?O.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?O.padding:s.padding.length===1||s.padding.length===2?s.padding[0]:(s.padding.length===3,s.padding[2]),Ot=s=>s?.padding===null||s?.padding===void 0?O.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?O.padding:s.padding.length===1?s.padding[0]:s.padding.length===2||s.padding.length===3?s.padding[1]:s.padding[3],_t=s=>s?.padding===null||s?.padding===void 0?O.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?O.padding:s.padding.length===1?s.padding[0]:(s.padding.length===2||s.padding.length===3,s.padding[1]),Ht=s=>s?.padding===null||s?.padding===void 0?O.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?O.padding:(s.padding.length===1||s.padding.length===2||s.padding.length===3,s.padding[0]),Ae=1,Le=1,Ao=1,Lo=1;class Eo{constructor(t){this.margin=t.margin||0,this.defaultWidths=t.defaultWidths||null,this.defaultHeights=t.defaultHeights||null,this.minWidths=t.minWidths||null,this.minHeights=t.minHeights||null,this.sections=[];for(const e of t.sections){const a=[];this.sections.push(a);for(const l of e)a.push(new Mo(l))}}}class Mo{constructor(t){this.label=t.label||null,this.ports=t.ports||[],this.priority=t.priority||Nt,this.resizableX=t.resizableX,this.resizableY=t.resizableY;const e=nt(t.look||je);this.defaultLook=e.defaultLook,this.selectedLook=e.selectedLook,this.highlightedLook=e.highlightedLook,this.selectedAndHighlightedLook=e.selectedAndHighlightedLook}}class U extends Ct{constructor(t,e,a,l,r,i,n,o){if(t.sections.get(o)!==void 0)throw new Error(`DiagramSection with id "${o}" already exists`);if(!o)throw new Error("DiagramSection cannot have an empty or null id");super(t,o),this.ports=[],this.decorators=[],this.node=e,this.indexXInNode=a,this.indexYInNode=l,this.coords=r,this.width=i,this.height=n}get name(){return this.label?.text||""}set name(t){this.label&&(this.label.text=t)}get look(){return this.selected?this.highlighted?this._selectedAndHighlightedLook!==void 0?this._selectedAndHighlightedLook:this.type?.selectedAndHighlightedLook||this.node?.look:this._selectedLook!==void 0?this._selectedLook:this.type?.selectedLook||this.node?.look:this.highlighted?this._highlightedLook!==void 0?this._highlightedLook:this.type?.highlightedLook||this.node?.look:this._defaultLook!==void 0?this._defaultLook:this.type?.defaultLook||this.node?.look}set look(t){this.lookConfig=t}get lookConfig(){return this._lookConfig}set lookConfig(t){if(this._lookConfig=t,t){const e=nt(t);this._defaultLook={...this._defaultLook,...e.defaultLook},this._selectedLook={...this._selectedLook,...e.selectedLook},this._highlightedLook={...this._highlightedLook,...e.highlightedLook},this._selectedAndHighlightedLook={...this._selectedAndHighlightedLook,...e.selectedAndHighlightedLook}}else this._defaultLook=t,this._selectedLook=t,this._highlightedLook=t,this._selectedAndHighlightedLook=t}get removed(){return this.selfRemoved||this.node!==void 0&&this.node.removed}updateInView(){this.model.canvas?.updateSectionsInView(this.id)}raise(){this.select()?.raise(),this.label&&this.label.raise();for(const t of this.ports)t.raise();for(const t of this.decorators)t.raise()}get type(){return this.node?.type?.sectionGrid?.sections?.[this.indexYInNode]?.[this.indexXInNode]}getMinWidth(){return this.node?.type?.sectionGrid?.minWidths?.[this.indexXInNode]||Ao}getMinHeight(){return this.node?.type?.sectionGrid?.minHeights?.[this.indexYInNode]||Lo}getPriority(){return this.node?.type?.sectionGrid?.sections?.[this.indexYInNode]?.[this.indexXInNode]?.priority||Nt}getResizableX(){const t=this.type;return t?.resizableX!==void 0?t.resizableX:this.node?.type?.resizableX||!1}getResizableY(){const t=this.type;return t?.resizableY!==void 0?t.resizableY:this.node?.type?.resizableY||!1}getClosestPortToPoint(t){if(this.ports.length!==0){if(this.ports.length===1)return this.ports[1];{const e=this.ports.map(r=>r.distanceTo(t)),a=e.indexOf(Math.min(...e));return this.ports[a]}}}getIncomingConnections(t=!1){const e=[];for(const a of this.ports)for(const l of a.incomingConnections)!t&&l.removed||e.push(l);return e}getOutgoingConnections(t=!1){const e=[];for(const a of this.ports)for(const l of a.outgoingConnections)!t&&l.removed||e.push(l);return e}getConnections(t=!1){const e=[];for(const a of this.ports){for(const l of a.incomingConnections)!t&&l.removed||e.push(l);for(const l of a.outgoingConnections)!t&&l.removed||e.push(l)}return e}move(t){this.setGeometry({coords:t,width:this.width,height:this.height})}stretch(t,e){const a=[this.coords[0],this.coords[0]+this.width],l=[this.coords[1],this.coords[1]+this.height];let r,i;switch(t){case f.Left:r=[a[0]-e,a[1]],i=[l[0],l[1]],r[1]-r[0]<this.getMinWidth()&&(r[0]=r[1]-this.getMinWidth());break;case f.Top:r=[a[0],a[1]],i=[l[0]-e,l[1]],i[1]-i[0]<this.getMinHeight()&&(i[0]=i[1]-this.getMinHeight());break;case f.Right:r=[a[0],a[1]+e],i=[l[0],l[1]],r[1]-r[0]<this.getMinWidth()&&(r[1]=r[0]+this.getMinWidth());break;case f.Bottom:r=[a[0],a[1]],i=[l[0],l[1]+e],i[1]-i[0]<this.getMinHeight()&&(i[1]=i[0]+this.getMinHeight());break}this.setGeometry({coords:[r[0],i[0]],width:r[1]-r[0],height:i[1]-i[0]})}getGeometry(){return{coords:[...this.coords],width:this.width,height:this.height}}setGeometry(t){const e=[this.coords[0],this.coords[0]+this.width],a=[this.coords[1],this.coords[1]+this.height];this.coords=[...t.coords],this.width=t.width,this.height=t.height;const l=[this.coords[0],this.coords[0]+this.width],r=[this.coords[1],this.coords[1]+this.height];for(const n of this.ports)n.move(Wt(n.coords,e,a,l,r,n.anchorPointX,n.anchorPointY));const i=this.type;this.label&&(this.label.coords=[this.coords[0]+D(i?.label),this.coords[1]+G(i?.label)],this.label.width=this.width-D(i?.label)-it(i?.label),this.label.height=this.height-G(i?.label)-q(i?.label),this.label.updateInView());for(const n of this.decorators)n.move(Wt(n.coords,e,a,l,r,n.anchorPointX,n.anchorPointY));this.model.canvas?.autoTightenConnections!==!1&&this.getConnections().forEach(n=>n.tighten()),this.updateInView()}}class To extends gt{constructor(t){super(),this.model=t}new(t,e,a,l,r,i,n){const o=new U(this.model,t,e,a,l,r,i,n);super.add(o),o.updateInView(),t.sections.push(o),t.updateInView();const d=t.type.sectionGrid?.sections?.[a]?.[e]?.ports;if(d&&d.length>0)for(let h=0;h<d.length;++h){const u=d[h],b=this.model.ports.new(u.type!==void 0?this.model.ports.types.get(u.type):void 0,o,[o.coords[0]+(u.coords[0]||0),o.coords[1]+(u.coords[1]||0)],u.connectionPoint!==void 0?[o.coords[0]+(u.connectionPoint[0]||0),o.coords[1]+(u.connectionPoint[1]||0)]:void 0,u?.direction,`${o.id}_${h}`,u.anchorPointX||"floating",u.anchorPointY||"floating");if(b.type?.label){const m={...O,...b.type?.label},x=6*m.fontSize+Ot(m)+_t(m),g=m.fontSize+Ht(m)+Vt(m);let v;switch(b.direction){case f.Bottom:case f.Left:case f.Right:v=[b.coords[0]-x/2,b.coords[1]-g-q(m)];break;case f.Top:v=[b.coords[0]-x/2,b.coords[1]+G(m)];break;default:v=b.coords}this.model.fields.new(b,v,m.fontSize,m.fontFamily,m.color,m.selectedColor,x,g,m.horizontalAlign,m.verticalAlign,m.orientation,"",m.editable,m.fit,m.shrink)}}const c=t.type.sectionGrid?.sections?.[a]?.[e]?.label;if(c){const h={...O,...c};this.model.fields.new(o,[o.coords[0]+D(h),o.coords[1]+G(h)],h.fontSize,h.fontFamily,h.color,h.selectedColor,o.width-D(h)-it(h),o.height-G(h)-q(h),h.horizontalAlign,h.verticalAlign,h.orientation,"",h.editable,h.fit,h.shrink)}return o}remove(t){const e=this.get(t,!0);if(e){for(;e.ports.length>0;)this.model.ports.remove(e.ports[0].id);e.label&&this.model.fields.remove(e.label.id),e.node&&B(e.node.sections,e),super.remove(t),e.updateInView()}}}const je={lookType:"shaped-look",shape:Tt.Rectangle,fillColor:"#FFFFFF",borderColor:"#000000",borderThickness:1,selected:{fillColor:"#FFAAFF",borderColor:"#AA00AA"},highlighted:{borderThickness:3}},ht={name:"",defaultWidth:1,defaultHeight:1,minWidth:1,minHeight:1,resizableX:!1,resizableY:!1,snapToGridOffset:[0,0,0,0],padding:0,label:null,ports:[],decorators:[],sectionGrid:null,look:je,isUnique:!1,canBeParentless:!0,childrenTypes:[],priority:Nt,properties:[]};class Ge{constructor(t){const e={...ht,...t};this.id=e.id,this.name=e.name,this.defaultWidth=e.defaultWidth,this.defaultHeight=e.defaultHeight,this.minWidth=e.minWidth,this.minHeight=e.minHeight,this.resizableX=e.resizableX,this.resizableY=e.resizableY,this.snapToGridOffset=e.snapToGridOffset,this.bottomPadding=Po(e),this.leftPadding=zo(e),this.rightPadding=Ro(e),this.topPadding=Vo(e),this.label=e.label,this.ports=e.ports,this.decorators=e.decorators,this.sectionGrid=e.sectionGrid?new Eo(e.sectionGrid):null;const a=nt(e.look);this.defaultLook=a.defaultLook,this.selectedLook=a.selectedLook,this.highlightedLook=a.highlightedLook,this.selectedAndHighlightedLook=a.selectedAndHighlightedLook,this.isUnique=e.isUnique,this.canBeParentless=e.canBeParentless,this.childrenTypes=e.childrenTypes,this.priority=e.priority,this.propertySet=new qt(t?.properties||[])}}class z extends Ct{constructor(t,e,a=[0,0],l){if(t.nodes.get(l)!==void 0)throw new Error(`DiagramNode with id "${l}" already exists`);if(!l)throw new Error("DiagramNode cannot have an empty or null id");super(t,l),this.children=[],this.sections=[],this.ports=[],this.decorators=[],this.geometryTimestamp=null,this._type=e,this.valueSet=new vt(e.propertySet,this),this.originalData={},this.coords=a,this.width=e.defaultWidth,this.height=e.defaultHeight}get type(){return this._type}set type(t){t!==this._type&&(this._type=t,this.valueSet&&(this.valueSet=new vt(t.propertySet,this)),this.model.canvas?.userSelection?.openInPropertyEditor(this,!1),this.updateInView())}get typeString(){return this.type.id}set typeString(t){if(t!==this.type.id){const e=this.model.nodes.types.get(t);e&&(this.type=e)}}get name(){return this.label?.text||""}set name(t){this.label&&(this.label.text=t)}get look(){return this.selected?this.highlighted?this._selectedAndHighlightedLook!==void 0?this._selectedAndHighlightedLook:this.type.selectedAndHighlightedLook:this._selectedLook!==void 0?this._selectedLook:this.type.selectedLook:this.highlighted?this._highlightedLook!==void 0?this._highlightedLook:this.type.highlightedLook:this._defaultLook!==void 0?this._defaultLook:this.type.defaultLook}set look(t){this.lookConfig=t}get lookConfig(){return this._lookConfig}set lookConfig(t){if(this._lookConfig=t,t){const e=nt(t);this._defaultLook={...this._defaultLook,...e.defaultLook},this._selectedLook={...this._selectedLook,...e.selectedLook},this._highlightedLook={...this._highlightedLook,...e.highlightedLook},this._selectedAndHighlightedLook={...this._selectedAndHighlightedLook,...e.selectedAndHighlightedLook}}else this._defaultLook=t,this._selectedLook=t,this._highlightedLook=t,this._selectedAndHighlightedLook=t}get removed(){return this.selfRemoved}updateInView(){this.model.canvas?.updateNodesInView(this.id)}raise(){this.select()?.raise();for(const t of this.sections)t.raise();this.label&&this.label.raise();for(const t of this.ports)t.raise();for(const t of this.decorators)t.raise();for(const t of this.children)t.raise()}getPriority(){return this.type.priority}getClosestPortToPoint(t){if(this.ports.length!==0){if(this.ports.length===1)return this.ports[1];{const e=this.ports.map(r=>r.distanceTo(t)),a=e.indexOf(Math.min(...e));return this.ports[a]}}}getIncomingConnections(t=!1){const e=[];for(const a of this.ports)for(const l of a.incomingConnections)!t&&l.removed||e.push(l);return e}getOutgoingConnections(t=!1){const e=[];for(const a of this.ports)for(const l of a.outgoingConnections)!t&&l.removed||e.push(l);return e}getConnections(t=!1){const e=[];for(const a of this.ports){for(const l of a.incomingConnections)!t&&l.removed||e.push(l);for(const l of a.outgoingConnections)!t&&l.removed||e.push(l)}return e}getAdjacentNodes(t=!1){const e=[];for(const a of this.ports){for(const l of a.incomingConnections){if(!t&&l.removed)continue;const r=l.start?.getNode();if(r){if(!t&&r.removed)continue;e.push(r)}}for(const l of a.outgoingConnections){if(!t&&l.removed)continue;const r=l.end?.getNode();if(r){if(!t&&r.removed)continue;e.push(r)}}}return e}getLastAncestor(){let t=this;for(;t.parent!==void 0;)t=t?.parent;return t}isAncestorOf(t){let e=t;for(;e!==void 0;){if(this.id===e.id)return!0;e=e.parent}return!1}isDescendantOf(t){return t.isAncestorOf(this)}addChild(t){if(t.id===this.id)return;let e=this.parent,a=!1;for(;e!==void 0;){if(e.id===t.id){a=!0;break}e=e.parent}a||this.children.indexOf(t)>=0||(this.fitToChild(t),this.children.push(t),t.parent=this,t.raise())}removeChild(t){B(this.children,t),t.parent=void 0}fitToChild(t){const e=Math.max(...this.sections.map(o=>o.indexXInNode)),a=Math.max(...this.sections.map(o=>o.indexYInNode)),l=this.coords[0]-t.coords[0]+this.type.leftPadding;l>=0&&(this.sections.length>0?this.stretchSections(f.Left,l,e,a):this.stretch(f.Left,l));const r=this.coords[1]-t.coords[1]+this.type.topPadding;r>=0&&(this.sections.length>0?this.stretchSections(f.Top,r,e,a):this.stretch(f.Top,r));const i=t.coords[0]+t.width-(this.coords[0]+this.width)+this.type.rightPadding;i>=0&&(this.sections.length>0?this.stretchSections(f.Right,i,e,a):this.stretch(f.Right,i));const n=t.coords[1]+t.height-(this.coords[1]+this.height)+this.type.bottomPadding;n>=0&&(this.sections.length>0?this.stretchSections(f.Bottom,n,e,a):this.stretch(f.Bottom,n)),this.parent&&this.parent.fitToChild(this)}move(t){const e=[t[0]-this.coords[0],t[1]-this.coords[1]];for(const a of this.children)a.move([a.coords[0]+e[0],a.coords[1]+e[1]]);for(const a of this.sections)a.move([a.coords[0]+e[0],a.coords[1]+e[1]]);this.setGeometry({coords:t,width:this.width,height:this.height,sections:{},children:{}})}stretch(t,e){const a=[this.coords[0],this.coords[0]+this.width],l=[this.coords[1],this.coords[1]+this.height];let r,i;switch(t){case f.Left:r=[a[0]-e,a[1]],i=[l[0],l[1]],r[1]-r[0]<this.type.minWidth&&(r[0]=r[1]-this.type.minWidth);break;case f.Top:r=[a[0],a[1]],i=[l[0]-e,l[1]],i[1]-i[0]<this.type.minHeight&&(i[0]=i[1]-this.type.minHeight);break;case f.Right:r=[a[0],a[1]+e],i=[l[0],l[1]],r[1]-r[0]<this.type.minWidth&&(r[1]=r[0]+this.type.minWidth);break;case f.Bottom:r=[a[0],a[1]],i=[l[0],l[1]+e],i[1]-i[0]<this.type.minHeight&&(i[1]=i[0]+this.type.minHeight);break}this.setGeometry({coords:[r[0],i[0]],width:r[1]-r[0],height:i[1]-i[0],sections:{},children:{}})}stretchSections(t,e,a,l){let r=Number.NEGATIVE_INFINITY;switch(t){case f.Bottom:for(const i of this.sections)i.indexYInNode===l&&(r=Math.max(r,i.getMinHeight()-i.height));e<r&&(e=r);for(const i of this.sections)i.indexYInNode===l?i.stretch(t,e):i.indexYInNode>l&&i.move([i.coords[0],i.coords[1]+e]);break;case f.Right:for(const i of this.sections)i.indexXInNode===a&&(r=Math.max(r,i.getMinWidth()-i.width));e<r&&(e=r);for(const i of this.sections)i.indexXInNode===a?i.stretch(t,e):i.indexXInNode>a&&i.move([i.coords[0]+e,i.coords[1]]);break;case f.Top:for(const i of this.sections)i.indexYInNode===l&&(r=Math.max(r,i.getMinHeight()-i.height));e<r&&(e=r);for(const i of this.sections)i.indexYInNode===l?i.stretch(t,e):i.indexYInNode<l&&i.move([i.coords[0],i.coords[1]-e]);break;case f.Left:for(const i of this.sections)i.indexXInNode===a&&(r=Math.max(r,i.getMinWidth()-i.width));e<r&&(e=r);for(const i of this.sections)i.indexXInNode===a?i.stretch(t,e):i.indexXInNode<a&&i.move([i.coords[0]-e,i.coords[1]]);break}this.stretch(t,e)}getGeometry(t){const e={};for(const l of this.sections)e[l.id]=l.getGeometry();const a={};for(const l of this.children)l.id!==t&&(a[l.id]=l.getGeometry(t));return{coords:[...this.coords],width:this.width,height:this.height,sections:e,children:a}}setGeometry(t){this.raise();const e=[this.coords[0],this.coords[0]+this.width],a=[this.coords[1],this.coords[1]+this.height];this.coords=[...t.coords],this.width=t.width,this.height=t.height;const l=[this.coords[0],this.coords[0]+this.width],r=[this.coords[1],this.coords[1]+this.height];for(const i of this.children){const n=t.children[i.id];n&&i.setGeometry(n)}for(const i of this.sections){const n=t.sections[i.id];n&&i.setGeometry(n)}for(const i of this.ports)i.move(Wt(i.coords,e,a,l,r,i.anchorPointX,i.anchorPointY));this.label&&(this.label.coords=[this.coords[0]+D(this.type.label),this.coords[1]+G(this.type.label)],this.label.width=this.width-D(this.type.label)-it(this.type.label),this.label.height=this.height-G(this.type.label)-q(this.type.label),this.label.updateInView());for(const i of this.decorators)i.move(Wt(i.coords,e,a,l,r,i.anchorPointX,i.anchorPointY));this.model.canvas?.autoTightenConnections!==!1&&this.getConnections().forEach(i=>i.tighten()),this.updateInView()}removeSectionColumn(t){const e=this.type.sectionGrid?.margin||0;let a=0;const l=[...this.sections];for(const r of l)r.indexYInNode===t&&(a=Math.max(a,r.width),this.model.sections.remove(r.id));for(const r of l)r.indexYInNode>t&&(--r.indexYInNode,r.move([r.coords[0]-a-e,r.coords[1]]));this.stretch(f.Right,-e-a)}removeSectionRow(t){const e=this.type.sectionGrid?.margin||0;let a=0;const l=[...this.sections];for(const r of l)r.indexXInNode===t&&(a=Math.max(a,r.height),this.model.sections.remove(r.id));for(const r of l)r.indexYInNode>t&&(--r.indexXInNode,r.move([r.coords[0],r.coords[1]-a-e]));this.stretch(f.Bottom,-e-a)}copySectionColumn(t){const e=this.type.sectionGrid?.margin||0;let a=0;const l=[...this.sections];for(const r of l)if(r.indexXInNode===t){a=Math.max(a,r.width);let i=r.indexXInNode+1;for(;this.model.sections.get(`${r.id}_copy_${i}_${r.indexYInNode}`,!0)!==void 0;)++i;this.model.sections.new(this,r.indexXInNode+1,r.indexYInNode,[r.coords[0]+r.width+e,r.coords[1]],r.width,r.height,`${r.id}_copy_${i}_${r.indexYInNode}`)}for(const r of l)r.indexXInNode>t&&(++r.indexXInNode,r.move([r.coords[0]+a+e,r.coords[1]]));this.stretch(f.Right,e+a)}copySectionRow(t){const e=this.type.sectionGrid?.margin||0;let a=0;const l=[...this.sections];for(const r of l)if(r.indexYInNode===t){a=Math.max(a,r.height);let i=r.indexYInNode+1;for(;this.model.sections.get(`${r.id}_copy_${r.indexXInNode}_${i}`,!0)!==void 0;)++i;this.model.sections.new(this,r.indexXInNode,r.indexYInNode+1,[r.coords[0],r.coords[1]+r.height+e],r.width,r.height,`${r.id}_copy_${r.indexXInNode}_${i}`)}for(const r of l)r.indexYInNode>t&&(++r.indexYInNode,r.move([r.coords[0],r.coords[1]+a+e]));this.stretch(f.Bottom,e+a)}}class No extends gt{constructor(t){super(),this.types=new Kt,this.model=t}new(t,e,a){let l;if(t instanceof Ge)l=t;else{const i=this.types.get(t);if(i===void 0)throw new TypeError(`Node type with id '${t}' could not be found.`);l=i}const r=new z(this.model,l,e,a);if(super.add(r),r.updateInView(),l.sectionGrid!==null){let i=r.coords[1]+(l.sectionGrid.margin||0);for(let n=0;n<l.sectionGrid.sections.length;++n){let o=r.coords[0]+(l.sectionGrid.margin||0);for(let d=0;d<l.sectionGrid.sections[n].length;++d)this.model.sections.new(r,d,n,[o,i],l.sectionGrid.defaultWidths?.[d]||Ae,l.sectionGrid.defaultHeights?.[n]||Le,`${r.id}_${n}_${d}`),o+=(l.sectionGrid.defaultWidths?.[d]||Ae)+(l.sectionGrid.margin||0);i+=(l.sectionGrid.defaultHeights?.[n]||Le)+(l.sectionGrid.margin||0)}}if(l.ports.length>0)for(let i=0;i<l.ports.length;++i){const n=l.ports[i],o=n.type!==void 0?this.model.ports.types.get(n.type):void 0,d=this.model.ports.new(o,r,[r.coords[0]+n.coords[0],r.coords[1]+n.coords[1]],n.connectionPoint!==void 0?[r.coords[0]+(n.connectionPoint[0]||0),r.coords[1]+(n.connectionPoint[1]||0)]:void 0,n.direction,`${r.id}_port_${i}`,n.anchorPointX||"floating",n.anchorPointY||"floating");if(d.type?.label){const c={...O,...d.type?.label},h=6*c.fontSize+Ot(c)+_t(c),u=c.fontSize+Ht(c)+Vt(c);let b;switch(d.direction){case f.Bottom:case f.Left:case f.Right:b=[d.coords[0]-h/2,d.coords[1]-u-q(c)];break;case f.Top:b=[d.coords[0]-h/2,d.coords[1]+G(c)];break;default:b=d.coords}this.model.fields.new(d,b,c.fontSize,c.fontFamily,c.color,c.selectedColor,h,u,c.horizontalAlign,c.verticalAlign,c.orientation,"",c.editable,c.fit,c.shrink)}}if(l.label){const i={...O,...l.label};this.model.fields.new(r,[r.coords[0]+D(i),r.coords[1]+G(i)],i.fontSize,i.fontFamily,i.color,i.selectedColor,r.width-D(i)-it(i),r.height-G(i)-q(i),i.horizontalAlign,i.verticalAlign,i.orientation,"",i.editable,i.fit,i.shrink)}if(l.decorators.length>0)for(let i=0;i<l.decorators.length;++i){const n=l.decorators[i];this.model.decorators.new(r,[r.coords[0]+n.coords[0],r.coords[1]+n.coords[1]],n.width,n.height,r.getPriority(),n.html,`${r.id}_decorator_${i}`,n.anchorPointX||"floating",n.anchorPointY||"floating")}return r.valueSet.resetValues(),r.model.canvas?.fitNodeInView(r.id),r}remove(t){const e=this.get(t,!0);if(e){for(e.parent&&B(e.parent.children,e);e.children.length>0;)this.model.nodes.remove(e.children[0].id);for(;e.sections.length>0;)this.model.sections.remove(e.sections[0].id);for(;e.ports.length>0;)this.model.ports.remove(e.ports[0].id);for(;e.decorators.length>0;)this.model.decorators.remove(e.decorators[0].id);e.label&&this.model.fields.remove(e.label.id),super.remove(t),e.updateInView()}}getAtCoordinates(t,e){const a=[];for(const l of this)l.coords[0]<t&&t<l.coords[0]+l.width&&l.coords[1]<e&&e<l.coords[1]+l.height&&a.push(l);return a}}const Fe=s=>{for(let t=0;t<s.length;++t)for(let e=0;e<s.length;++e)e!==t&&s[e].isAncestorOf(s[t])&&(s.splice(e,1),--e,t>e&&--t);return s},Po=s=>s?.padding===null||s?.padding===void 0?ht.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?ht.padding:s.padding.length===1||s.padding.length===2?s.padding[0]:(s.padding.length===3,s.padding[2]),zo=s=>s?.padding===null||s?.padding===void 0?ht.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?ht.padding:s.padding.length===1?s.padding[0]:s.padding.length===2||s.padding.length===3?s.padding[1]:s.padding[3],Ro=s=>s?.padding===null||s?.padding===void 0?ht.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?ht.padding:s.padding.length===1?s.padding[0]:(s.padding.length===2||s.padding.length===3,s.padding[1]),Vo=s=>s?.padding===null||s?.padding===void 0?ht.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?ht.padding:(s.padding.length===1||s.padding.length===2||s.padding.length===3,s.padding[0]),Ue={lookType:"shaped-look",shape:Tt.Ellipse,fillColor:"transparent",borderColor:"transparent",borderThickness:0,selected:{fillColor:"rgba(255, 0, 255, 0.5)"},highlighted:{fillColor:"rgba(0, 255, 255, 0.5)"}},Dt=nt(Ue),De={name:"",label:null,allowsOutgoing:!0,allowsIncoming:!0,width:24,look:Ue};class Oo{constructor(t){const e={...De,...t};this.id=e.id,this.name=e.name,this.label=e.label,this.allowsOutgoing=e.allowsOutgoing,this.allowsIncoming=e.allowsIncoming,this.width=e.width;const a=nt(e.look);this.defaultLook=a.defaultLook,this.selectedLook=a.selectedLook,this.highlightedLook=a.highlightedLook,this.selectedAndHighlightedLook=a.selectedAndHighlightedLook}}class yt extends Ct{constructor(t,e,a,l,r,i,n,o="floating",d="floating"){if(t.ports.get(n)!==void 0)throw new Error(`DiagramPort with id "${n}" already exists`);if(!n)throw new Error("DiagramPort cannot have an empty or null id");super(t,n),this.outgoingConnections=[],this.incomingConnections=[],this._type=e,this.rootElement=a,this.coords=l,this.connectionPoint=r||l,this.direction=i,this.anchorPointX=o,this.anchorPointY=d}get type(){return this._type}set type(t){t!==this._type&&(this._type=t,this.updateInView())}get typeString(){return this.type?.id}set typeString(t){if(t!==this.type?.id)if(t===void 0)this.type=void 0;else{const e=this.model.ports.types.get(t);e&&(this.type=e)}}get allowsOutgoing(){return this.type?.allowsOutgoing!==void 0?this.type?.allowsOutgoing:!0}get allowsIncoming(){return this.type?.allowsIncoming!==void 0?this.type?.allowsIncoming:!0}get name(){return this.label?.text||""}set name(t){this.label&&(this.label.text=t)}get look(){return this.selected?this.highlighted?this._selectedAndHighlightedLook!==void 0?this._selectedAndHighlightedLook:(this.type||Dt)?.selectedAndHighlightedLook:this._selectedLook!==void 0?this._selectedLook:(this.type||Dt)?.selectedLook:this.highlighted?this._highlightedLook!==void 0?this._highlightedLook:(this.type||Dt)?.highlightedLook:this._defaultLook!==void 0?this._defaultLook:(this.type||Dt)?.defaultLook}set look(t){this.lookConfig=t}get lookConfig(){return this._lookConfig}set lookConfig(t){if(this._lookConfig=t,t){const e=nt(t);this._defaultLook={...this._defaultLook,...e.defaultLook},this._selectedLook={...this._selectedLook,...e.selectedLook},this._highlightedLook={...this._highlightedLook,...e.highlightedLook},this._selectedAndHighlightedLook={...this._selectedAndHighlightedLook,...e.selectedAndHighlightedLook}}else this._defaultLook=t,this._selectedLook=t,this._highlightedLook=t,this._selectedAndHighlightedLook=t}get width(){return this.type?.width||De.width}get height(){return this.width}get removed(){return this.selfRemoved||this.rootElement!==void 0&&this.rootElement.removed}updateInView(){this.model.canvas?.updatePortsInView(this.id)}raise(){this.select()?.raise(),this.label&&this.label.raise();for(const t of this.incomingConnections)t.raise();for(const t of this.outgoingConnections)t.raise()}startConnection(t){this.outgoingConnections.push(t)}finishConnection(t){this.incomingConnections.push(t)}getNode(){if(this.rootElement instanceof z)return this.rootElement;if(this.rootElement instanceof U)return this.rootElement.node}getPriority(){return this.rootElement?.getPriority()||Nt}move(t){const e=[t[0]-this.coords[0],t[1]-this.coords[1]];this.coords=t,this.connectionPoint[0]=this.connectionPoint[0]+e[0],this.connectionPoint[1]=this.connectionPoint[1]+e[1];for(const a of this.outgoingConnections)a.setStart(this);for(const a of this.incomingConnections)a.setEnd(this);this.label&&this.label.move([this.label.coords[0]+e[0],this.label.coords[1]+e[1]]),this.updateInView()}distanceTo(t){return Re(this.coords,t)}}class _o extends gt{constructor(t){super(),this.types=new Kt,this.model=t}new(t,e,a,l,r,i,n="floating",o="floating"){const d=new yt(this.model,t,e,a,l,r,i,n,o);return super.add(d),d.updateInView(),e!==void 0&&e.ports.push(d),d}remove(t){const e=this.get(t,!0);if(e){for(;e.outgoingConnections.length>0;)this.model.connections.remove(e.outgoingConnections[0].id);for(;e.incomingConnections.length>0;)this.model.connections.remove(e.incomingConnections[0].id);e.label&&this.model.fields.remove(e.label.id),(e.rootElement instanceof z||e.rootElement instanceof U)&&B(e.rootElement.ports,e),super.remove(t),e.updateInView()}}}class Be{import(t,e){t.clear(),e.id&&(t.id=e.id),t.name=e.name,t.description=e.description,t.type=e.type,t.createdAt=new Date(e.createdAt),t.updatedAt=new Date(e.updatedAt);for(const a of e.nodes||[])this.importNode(t,a);for(const a of e.connections||[])this.importConnection(t,a);return e.data&&t.valueSet.setValues(e.data),e.collabMeta&&(t.logicalClock=e.collabMeta.logicalClock,t.valueSet.setTimestamps(e.collabMeta.dataTimestamps)),t}importNode(t,e){const a=t.nodes.types.get(e.type);if(a){const l=new z(t,a,e.coords,e.id);if(t.nodes.add(l),l.width=e.width,l.height=e.height,e.label){if(a.decorators)for(let i=0;i<a.decorators.length;++i){const n=a.decorators[i];t.decorators.new(l,[l.coords[0]+n.coords[0],l.coords[1]+n.coords[1]],n.width,n.height,l.getPriority(),n.html,`${l.id}_decorator_${i}`)}if(a.label){const i={...O,...a.label},n=new ct(t,l,[l.coords[0]+D(i),l.coords[1]+G(i)],l.width-D(i)-it(i),l.height-G(i)-q(i),i.fontSize,i.fontFamily,i.color,i.selectedColor,i.horizontalAlign,i.verticalAlign,i.orientation,"",i.editable,i.fit,i.shrink);n.text=e.label,l.label=n,t.fields.add(n),n.updateInView()}}for(const i of e.children||[]){const n=this.importNode(t,i);n!==void 0&&(l.children?.push(n),n.parent=l)}for(const i of e.sections||[]){const n=new U(t,l,i.indexXInNode,i.indexYInNode,i.coords,i.width,i.height,i.id);if(l.sections?.push(n),t.sections.add(n),i.label&&a.sectionGrid?.sections?.[i.indexYInNode]?.[i.indexXInNode]?.label){const d={...O,...a.sectionGrid?.sections?.[i.indexYInNode]?.[i.indexXInNode]?.label},c=new ct(t,n,[n.coords[0]+D(d),n.coords[1]+G(d)],n.width-D(d)-it(d),n.height-G(d)-q(d),d.fontSize,d.fontFamily,d.color,d.selectedColor,d.horizontalAlign,d.verticalAlign,d.orientation,"",d.editable,d.fit,d.shrink);c.text=i.label,n.label=c,t.fields.add(c),c.updateInView()}let o=0;for(const d of i.ports||[]){const c=d.type!==void 0?t.ports.types.get(d.type):void 0,h=new yt(t,c,n,d.coords,d.connectionPoint||d.coords,d.direction,d.id);if(n.ports.push(h),t.ports.add(h),d.label){if(a.ports.length>o&&c?.label){const u={...O,...c?.label};let b;switch(h.direction){case f.Top:case f.Left:b=[h.coords[0]-u.fontSize,h.coords[1]-u.fontSize];break;case f.Bottom:b=[h.coords[0]-u.fontSize,h.coords[1]+u.fontSize];break;case f.Right:b=[h.coords[0]+u.fontSize,h.coords[1]-u.fontSize];break;default:b=h.coords}const m=new ct(t,h,b,u.fontSize,u.fontSize,u.fontSize,u.fontFamily,u.color,u.selectedColor,u.horizontalAlign,u.verticalAlign,u.orientation,"",u.editable,u.fit,u.shrink);m.text=d.label,h.label=m,t.fields.add(m),m.updateInView()}++o}d.collabMeta&&(h.selfRemoved=d.collabMeta.selfRemoved,h.selfRemovedTimestamp=d.collabMeta.selfRemovedTimestamp,this.importLabelCollabMeta(h.label,d.collabMeta.label)),h.updateInView()}i.collabMeta&&(n.selfRemoved=i.collabMeta.selfRemoved,n.selfRemovedTimestamp=i.collabMeta.selfRemovedTimestamp,this.importLabelCollabMeta(n.label,i.collabMeta.label)),n.updateInView()}let r=0;for(const i of e.ports||[]){const n=i.type!==void 0?t.ports.types.get(i.type):void 0,o=new yt(t,n,l,i.coords,i.connectionPoint||i.coords,i.direction,i.id);if(l.ports.push(o),t.ports.add(o),i.label){if(a.ports.length>r&&n?.label){const d={...O,...n?.label};let c;switch(o.direction){case f.Top:case f.Left:c=[o.coords[0]-d.fontSize,o.coords[1]-d.fontSize];break;case f.Bottom:c=[o.coords[0]-d.fontSize,o.coords[1]+d.fontSize];break;case f.Right:c=[o.coords[0]+d.fontSize,o.coords[1]-d.fontSize];break;default:c=o.coords}const h=new ct(t,o,c,d.fontSize,d.fontSize,d.fontSize,d.fontFamily,d.color,d.selectedColor,d.horizontalAlign,d.verticalAlign,d.orientation,"",d.editable,d.fit,d.shrink);h.text=i.label,o.label=h,t.fields.add(h),h.updateInView()}++r}i.collabMeta&&(o.selfRemoved=i.collabMeta.selfRemoved,o.selfRemovedTimestamp=i.collabMeta.selfRemovedTimestamp,this.importLabelCollabMeta(o.label,i.collabMeta.label)),o.updateInView()}return e.data&&l.valueSet.setValues(e.data),e.collabMeta&&(l.selfRemoved=e.collabMeta.selfRemoved,l.selfRemovedTimestamp=e.collabMeta.selfRemovedTimestamp,l.geometryTimestamp=e.collabMeta.geometryTimestamp,this.importLabelCollabMeta(l.label,e.collabMeta.label),l.valueSet.setTimestamps(e.collabMeta.dataTimestamps)),l.updateInView(),l.raise(),l}}importConnection(t,e){const a=t.connections.types.get(e.type);if(a){const l=new lt(t,a,e.start?t.ports.get(e.start):void 0,e.end?t.ports.get(e.end):void 0,e.id);return t.connections.add(l),l.startLabel=e.startLabel,l.middleLabel=e.middleLabel,l.endLabel=e.endLabel,l.points=e.points,e.data&&l.valueSet.setValues(e.data),e.collabMeta&&(l.selfRemoved=e.collabMeta.selfRemoved,l.selfRemovedTimestamp=e.collabMeta.selfRemovedTimestamp,l.valueSet.setTimestamps(e.collabMeta.dataTimestamps)),l.updateInView(),l.raise(),l}}importLabelCollabMeta(t,e){t&&e&&(t.selfRemoved=e.selfRemoved,t.selfRemovedTimestamp=e.selfRemovedTimestamp,t.textTimestamp=e.textTimestamp)}}class Jt{constructor(t,e,a,l,r,i,n){this.canvas=t,this.id=e,this.typeId=a,this.coords=l,this.parentId=r,this.label=i,this.values=n}do(){const t=this.canvas.model.nodes.new(this.typeId,this.coords,this.id);this.parentId!==void 0&&this.canvas.model.nodes.get(this.parentId)?.addChild(t),t.label&&(t.label.text=this.label||""),this.values!==void 0?t.valueSet.setValues(St({...t.valueSet.getValues(),...this.values})):t.valueSet.resetValues()}serialize(){return{type:"addNode",id:this.id,typeId:this.typeId,coords:this.coords,parentId:this.parentId,label:this.label,values:this.values}}static deserialize(t,e){return new Jt(t,e.id,e.typeId,e.coords,e.parentId,e.label,e.values)}}class me{constructor(t,e,a,l,r,i,n){this.canvas=t,this.nodeId=e,this.copyColumnIndex=a,this.copyRowIndex=l,this.removeColumnIndex=r,this.removeRowIndex=i,this.timestamp=n}do(){const t=this.canvas.model.nodes.get(this.nodeId);t&&bt(this.timestamp,t.geometryTimestamp)&&(this.copyColumnIndex!==void 0&&t.copySectionColumn(this.copyColumnIndex),this.copyRowIndex!==void 0&&t.copySectionRow(this.copyRowIndex),this.removeColumnIndex!==void 0&&t.removeSectionColumn(this.removeColumnIndex),this.removeRowIndex!==void 0&&t.removeSectionRow(this.removeRowIndex),t.geometryTimestamp=this.timestamp)}serialize(){return{type:"addSection",nodeId:this.nodeId,copyColumnIndex:this.copyColumnIndex,copyRowIndex:this.copyRowIndex,removeColumnIndex:this.removeColumnIndex,removeRowIndex:this.removeRowIndex,timestamp:this.timestamp}}static deserialize(t,e){return new me(t,e.nodeId,e.copyColumnIndex,e.copyRowIndex,e.removeColumnIndex,e.removeRowIndex,e.timestamp)}}class ve{constructor(t,e,a){this.canvas=t,this.to=e,this.timestamp=a}do(){for(const t in this.to){const e=this.canvas.model.nodes.get(t,!0);if(e&&bt(this.timestamp,e.geometryTimestamp)){const a=this.to[t];e.move([a[0],a[1]]),e.geometryTimestamp=this.timestamp}}}serialize(){return{type:"applyLayout",to:this.to,timestamp:this.timestamp}}static deserialize(t,e){return new ve(t,e.to,e.timestamp)}}class jt{constructor(t,e,a,l){this.canvas=t,this.nodeIds=e,this.delta=a,this.timestamp=l}do(){for(const t of this.nodeIds){const e=this.canvas.model.nodes.get(t,!0);e&&bt(this.timestamp,e.geometryTimestamp)&&(e.move([e.coords[0]+this.delta[0],e.coords[1]+this.delta[1]]),e.parent?.fitToChild(e),e.geometryTimestamp=this.timestamp)}}serialize(){return{type:"move",nodeIds:this.nodeIds,delta:this.delta,timestamp:this.timestamp}}static deserialize(t,e){return new jt(t,e.nodeIds,e.delta,e.timestamp)}}class st{constructor(t,e,a,l){this.canvas=t,this.nodeId=e,this.to=a,this.timestamp=l}do(){const t=this.canvas.model.nodes.get(this.nodeId,!0);if(t&&bt(this.timestamp,t.geometryTimestamp)){t.setGeometry(this.to),t.label?.fit&&this.canvas.fitFieldRootInView(t.label.id,t.label.shrink);for(const e of t.sections)e.label?.fit&&this.canvas.fitFieldRootInView(e.label.id,e.label.shrink);t.parent?.fitToChild(t),t.geometryTimestamp=this.timestamp}}serialize(){return{type:"setGeometry",nodeId:this.nodeId,to:this.to,timestamp:this.timestamp}}static deserialize(t,e){return new st(t,e.nodeId,e.to,e.timestamp)}}class Gt{constructor(t,e,a,l,r){this.canvas=t,this.childId=e,this.parentId=a,this.childGeometry=l,this.timestamp=r}do(){const t=this.canvas.model.nodes.get(this.childId,!0),e=this.parentId!==void 0?this.canvas.model.nodes.get(this.parentId,!0):void 0;t&&(this.parentId===void 0||e)&&bt(this.timestamp,t.geometryTimestamp)&&(t.parent?.removeChild(t),t.setGeometry(this.childGeometry),e?.addChild(t))}serialize(){return{type:"setParent",childId:this.childId,parentId:this.parentId,childGeometry:this.childGeometry,timestamp:this.timestamp}}static deserialize(t,e){return new Gt(t,e.childId,e.parentId,e.childGeometry,e.timestamp)}}class Qt{constructor(t,e,a,l,r){this.canvas=t,this.id=e,this.typeId=a,this.startId=l,this.endId=r}do(){const t=this.canvas.model.ports.get(this.startId,!0),e=this.canvas.model.ports.get(this.endId,!0);t&&e&&this.canvas.model.connections.new(this.typeId,t,e,this.id)}serialize(){return{type:"addConnection",id:this.id,typeId:this.typeId,startId:this.startId,endId:this.endId}}static deserialize(t,e){return new Qt(t,e.id,e.typeId,e.startId,e.endId)}}class Et{constructor(t,e,a,l){this.canvas=t,this.fieldId=e,this.to=a,this.timestamp=l}do(){const t=this.canvas.model.fields.get(this.fieldId,!0);t&&bt(this.timestamp,t.textTimestamp)&&(t.text=this.to,t.textTimestamp=this.timestamp)}serialize(){return{type:"editField",fieldId:this.fieldId,to:this.to,timestamp:this.timestamp}}static deserialize(t,e){return new Et(t,e.fieldId,e.to,e.timestamp)}}class Mt{constructor(t,e,a,l){this.canvas=t,this.id=e,this.to=a,this.timestamp=l}getValueSet(){return this.id===void 0?this.canvas.model.valueSet:(this.canvas.model.nodes.get(this.id,!0)||this.canvas.model.connections.get(this.id,!0))?.valueSet}do(){this.getValueSet()?.overwriteValuesLww(this.to,this.timestamp)}serialize(){return{type:"updateValues",id:this.id,to:this.to,timestamp:this.timestamp}}static deserialize(t,e){return new Mt(t,e.id,e.to,e.timestamp)}}class rt{constructor(t,e,a,l,r,i,n,o){this.canvas=t,this.nodeIds=e,this.sectionIds=a,this.portIds=l,this.connectionIds=r,this.fieldIds=i,this.selfRemoved=n,this.timestamp=o}doOne(t){t&&bt(this.timestamp,t.selfRemovedTimestamp)&&(t.selfRemoved=this.selfRemoved,t.selfRemovedTimestamp=this.timestamp)}do(){for(const t of this.nodeIds)this.doOne(this.canvas.model.nodes.get(t,!0));for(const t of this.sectionIds)this.doOne(this.canvas.model.sections.get(t,!0));for(const t of this.portIds)this.doOne(this.canvas.model.ports.get(t,!0));for(const t of this.connectionIds)this.doOne(this.canvas.model.connections.get(t,!0));for(const t of this.fieldIds)this.doOne(this.canvas.model.fields.get(t,!0));this.canvas.updateNodesInView(...this.nodeIds),this.canvas.updateSectionsInView(...this.sectionIds),this.canvas.updatePortsInView(...this.portIds),this.canvas.updateConnectionsInView(...this.connectionIds),this.canvas.updateFieldsInView(...this.fieldIds),this.canvas.updateDecoratorsInView()}serialize(){return{type:"setSelfRemoved",nodeIds:this.nodeIds,sectionIds:this.sectionIds,portIds:this.portIds,connectionIds:this.connectionIds,fieldIds:this.fieldIds,removed:this.selfRemoved,timestamp:this.timestamp}}static deserialize(t,e){return new rt(t,e.nodeIds,e.sectionIds,e.portIds,e.connectionIds,e.fieldIds,e.removed,e.timestamp)}}class te{constructor(t,e,a){this.canvas=t,this.nodes=e,this.connections=a}do(){const t=new Be;this.canvas.userSelection.clear();for(const e of this.nodes){const a=t.importNode(this.canvas.model,e);a&&this.canvas.userSelection.add(a)}for(const e of this.connections){const a=t.importConnection(this.canvas.model,e);a&&this.canvas.userSelection.add(a)}}serialize(){return{type:"paste",nodes:this.nodes,connections:this.connections}}static deserialize(t,e){return new te(t,e.nodes,e.connections)}}class Ho{constructor(t){this.isInRoom=!1,this.canvas=t,this.replicaId=$e()}freshTimestamp(){return this.canvas.model.logicalClock++,[this.canvas.model.logicalClock,this.replicaId]}freshId(){return"id"+$e()}doCollaboratively(t){if(t.do(),this.onSend){const e=t.serialize();this.onSend(e)}}receive(t){switch("timestamp"in t&&(this.canvas.model.logicalClock=Math.max(this.canvas.model.logicalClock,t.timestamp[0])),t.type){case"addNode":{Jt.deserialize(this.canvas,t).do();break}case"addSection":{me.deserialize(this.canvas,t).do();break}case"applyLayout":{ve.deserialize(this.canvas,t).do();break}case"move":{jt.deserialize(this.canvas,t).do();break}case"setGeometry":{st.deserialize(this.canvas,t).do();break}case"setParent":{Gt.deserialize(this.canvas,t).do();break}case"addConnection":{Qt.deserialize(this.canvas,t).do();break}case"editField":{Et.deserialize(this.canvas,t).do();break}case"updateValues":{Mt.deserialize(this.canvas,t).do();break}case"setSelfRemoved":{rt.deserialize(this.canvas,t).do();break}case"paste":{te.deserialize(this.canvas,t).do();break}default:console.error("Unknown CollabAction type, skipping:",t)}}}class jo{constructor(t,e){this.canvas=t,this.maximum=e,this.history=[],this.index=0}add(t){this.index<this.history.length&&(this.history=this.history.slice(0,this.index)),this.history.length>=this.maximum?(this.history=this.history.slice(1,this.history.length),this.history.push(t)):(this.history.push(t),++this.index),this.canvas.diagramChange$.next({action:t,method:0})}undo(){let t;if(this.index>0){let e;do--this.index,t=this.history[this.index],e=t.undo();while(!e&&this.index>0)}this.canvas.diagramChange$.next({action:t,method:1})}redo(){let t;if(this.index<this.history.length){let e;do t=this.history[this.index],e=t.redo(),++this.index;while(!e&&this.index<this.history.length)}this.canvas.diagramChange$.next({action:t,method:2})}}var k=(s=>(s.AddConnection="add-connection",s.AddNode="add-node",s.AddSectionAction="add-section",s.ApplyLayout="apply-layout",s.Clipboard="clipboard",s.ContextMenu="context-menu",s.EditField="edit-field",s.MoveNode="move-node",s.Paste="paste",s.Remove="remove",s.StretchNode="stretch-node",s.StretchSection="stretch-section",s.UpdateValues="update-values",s.Zoom="zoom",s))(k||{});class Go{constructor(t,e,a,l,r,i,n,o,d){this.canvas=t,this.type=e,this.coords=a,this.parentId=l,this.ancestorId=r,this.fromAncestorGeometry=i,this.toAncestorGeometry=n,this.label=o,this.values=d,this.id=this.canvas.collabEngine.freshId()}do(){const t=new Jt(this.canvas,this.id,this.type.id,this.coords,this.parentId,this.label,this.values);if(this.canvas.collabEngine.doCollaboratively(t),this.ancestorId!==void 0&&this.toAncestorGeometry!==void 0){const e=new st(this.canvas,this.ancestorId,this.toAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(e)}return!0}undo(){const t=this.canvas.model.nodes.get(this.id),e=new rt(this.canvas,[this.id],[],[],[],[],!0,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(e),this.ancestorId!==void 0&&this.fromAncestorGeometry!==void 0){const a=new st(this.canvas,this.ancestorId,this.fromAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(a)}return t!==void 0}redo(){const t=this.canvas.model.nodes.get(this.id),e=new rt(this.canvas,[this.id],[],[],[],[],!1,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(e),this.ancestorId!==void 0&&this.toAncestorGeometry!==void 0){const a=new st(this.canvas,this.ancestorId,this.toAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(a)}return t===void 0}}class ie{constructor(t,e,a){this.canvas=t,this.nodeIds=e,this.delta=a}do(){const t=new jt(this.canvas,this.nodeIds,this.delta,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(t),this.nodeIds.map(e=>this.canvas.model.nodes.get(e)!==void 0).includes(!0)&&(this.delta[0]!==0||this.delta[1]!==0)}undo(){const t=new jt(this.canvas,this.nodeIds,[-this.delta[0],-this.delta[1]],this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(t),this.nodeIds.map(e=>this.canvas.model.nodes.get(e)!==void 0).includes(!0)&&(this.delta[0]!==0||this.delta[1]!==0)}redo(){return this.do()}}class X{constructor(t,e,a,l,r,i,n,o){this.canvas=t,this.intent=e,this.nodeId=a,this.from=l,this.to=r,this.ancestorId=i,this.fromAncestorGeometry=n,this.toAncestorGeometry=o}do(){const t=this.canvas.model.nodes.get(this.nodeId);if(t){const e=new st(this.canvas,this.nodeId,this.to,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(e),this.ancestorId!==void 0&&this.toAncestorGeometry!==void 0){const a=new st(this.canvas,this.ancestorId,this.toAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(a)}}return t!==void 0}undo(){const t=this.canvas.model.nodes.get(this.nodeId);if(t){this.to=t.getGeometry();const e=new st(this.canvas,this.nodeId,this.from,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(e),this.ancestorId!==void 0&&this.fromAncestorGeometry!==void 0){const a=new st(this.canvas,this.ancestorId,this.fromAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(a)}}return t!==void 0}redo(){const t=this.canvas.model.nodes.get(this.nodeId);if(t){this.from=t.getGeometry();const e=new st(this.canvas,this.nodeId,this.to,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(e)}return t!==void 0}}class Fo{constructor(t,e,a,l,r,i,n,o,d){this.canvas=t,this.childId=e,this.fromParentId=a,this.toParentId=l,this.fromChildGeometry=r,this.toChildGeometry=i,this.ancestorId=n,this.fromAncestorGeometry=o,this.toAncestorGeometry=d}do(){const t=this.canvas.model.nodes.get(this.childId),e=new Gt(this.canvas,this.childId,this.toParentId,this.toChildGeometry,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(e),this.ancestorId!==void 0&&this.toAncestorGeometry!==void 0){const a=new st(this.canvas,this.ancestorId,this.toAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(a)}return t!==void 0}undo(){const t=this.canvas.model.nodes.get(this.childId),e=new Gt(this.canvas,this.childId,this.fromParentId,this.fromChildGeometry,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(e),this.ancestorId!==void 0&&this.fromAncestorGeometry!==void 0){const a=new st(this.canvas,this.ancestorId,this.fromAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(a)}return t!==void 0}redo(){return this.do()}}class se{constructor(t,e,a,l){this.canvas=t,this.type=e,this.startId=a,this.endId=l,this.id=this.canvas.collabEngine.freshId()}do(){const t=new Qt(this.canvas,this.id,this.type.id,this.startId,this.endId);return this.canvas.collabEngine.doCollaboratively(t),!0}undo(){const t=this.canvas.model.connections.get(this.id),e=new rt(this.canvas,[],[],[],[this.id],[],!0,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),t!==void 0}redo(){const t=this.canvas.model.connections.get(this.id),e=new rt(this.canvas,[],[],[],[this.id],[],!1,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),t===void 0}}class Ee{constructor(t,e,a,l){this.canvas=t,this.fieldId=e,this.from=a,this.to=l}do(){const t=this.canvas.model.fields.get(this.fieldId),e=new Et(this.canvas,this.fieldId,this.to,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),t!==void 0}undo(){const t=this.canvas.model.fields.get(this.fieldId);if(t){this.to=t.text;const e=new Et(this.canvas,this.fieldId,this.from,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(e)}return t!==void 0}redo(){const t=this.canvas.model.fields.get(this.fieldId);if(t){this.from=t.text;const e=new Et(this.canvas,this.fieldId,this.to,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(e)}return t!==void 0}}class Uo{constructor(t,e,a,l){this.canvas=t,this.id=e,this.from=a,this.to=l}do(){const t=new Mt(this.canvas,this.id,this.to,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(t),!0}undo(){const t=new Mt(this.canvas,this.id,this.from,this.canvas.collabEngine.freshTimestamp()),e=t.getValueSet();if(e)this.to=e.getValuesForKeys(this.to),this.canvas.collabEngine.doCollaboratively(t);else return!1;return!e.rootElement.removed}redo(){const t=new Mt(this.canvas,this.id,this.to,this.canvas.collabEngine.freshTimestamp()),e=t.getValueSet();if(e)this.from=e.getValuesForKeys(this.from),this.canvas.collabEngine.doCollaboratively(t);else return!1;return!e.rootElement.removed}}class Do{constructor(t,e,a,l,r,i){this.canvas=t,this.nodeIds=e,this.sectionIds=a,this.portIds=l,this.connectionIds=r,this.fieldIds=i}do(){const t=this.nodeIds.map(a=>this.canvas.model.nodes.get(a)!==void 0).includes(!0)||this.sectionIds.map(a=>this.canvas.model.sections.get(a)!==void 0).includes(!0)||this.portIds.map(a=>this.canvas.model.ports.get(a)!==void 0).includes(!0)||this.connectionIds.map(a=>this.canvas.model.connections.get(a)!==void 0).includes(!0)||this.fieldIds.map(a=>this.canvas.model.fields.get(a)!==void 0).includes(!0),e=new rt(this.canvas,this.nodeIds,this.sectionIds,this.portIds,this.connectionIds,this.fieldIds,!0,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),t}undo(){const t=this.nodeIds.map(a=>this.canvas.model.nodes.get(a)===void 0).includes(!0)||this.sectionIds.map(a=>this.canvas.model.sections.get(a)===void 0).includes(!0)||this.portIds.map(a=>this.canvas.model.ports.get(a)===void 0).includes(!0)||this.connectionIds.map(a=>this.canvas.model.connections.get(a)===void 0).includes(!0)||this.fieldIds.map(a=>this.canvas.model.fields.get(a)===void 0).includes(!0),e=new rt(this.canvas,this.nodeIds,this.sectionIds,this.portIds,this.connectionIds,this.fieldIds,!1,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),t}redo(){return this.do()}}class Bo{constructor(t,e,a,l){this.canvas=t,this.nodes=e,this.connections=a,this.coords=l}do(){const t=[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY];for(const r of this.nodes)r.coords[0]<t[0]&&(t[0]=r.coords[0]),r.coords[1]<t[1]&&(t[1]=r.coords[1]);const e=this.coords!==void 0?[this.coords[0]-t[0],this.coords[1]-t[1]]:void 0,a={};for(const r of this.nodes){const i=r.id,n=this.canvas.collabEngine.freshId();if(a[i]=n,r.id=n,e&&(r.coords=[r.coords[0]+e[0],r.coords[1]+e[1]]),r.sections)for(const o of r.sections){const d=o.id;if(o.id.includes(r.id)?o.id=o.id.replace(r.id,n):o.id=this.canvas.collabEngine.freshId(),a[d]=o.id,e&&(o.coords=[o.coords[0]+e[0],o.coords[1]+e[1]]),o.ports)for(const c of o.ports){const h=c.id;c.id.includes(r.id)?c.id=c.id.replace(r.id,n):c.id=this.canvas.collabEngine.freshId(),a[h]=c.id,e&&(c.coords=[c.coords[0]+e[0],c.coords[1]+e[1]],c.connectionPoint&&(c.connectionPoint=[c.connectionPoint[0]+e[0],c.connectionPoint[1]+e[1]]))}}if(r.ports)for(const o of r.ports){const d=o.id;o.id.includes(r.id)?o.id=o.id.replace(r.id,n):o.id=this.canvas.collabEngine.freshId(),a[d]=o.id,e&&(o.coords=[o.coords[0]+e[0],o.coords[1]+e[1]],o.connectionPoint&&(o.connectionPoint=[o.connectionPoint[0]+e[0],o.connectionPoint[1]+e[1]]))}}for(const r of this.connections){const i=this.canvas.collabEngine.freshId();if(a[r.id]=i,r.id=i,r.start=a[r.start]||r.start,r.end=a[r.end]||r.end,e)for(let n=0;n<r.points.length;++n)r.points[n]=[r.points[n][0]+e[0],r.points[n][1]+e[1]]}const l=new te(this.canvas,this.nodes,this.connections);return this.canvas.collabEngine.doCollaboratively(l),!0}undo(){const t=this.nodes.map(a=>this.canvas.model.nodes.get(a.id)!==void 0).includes(!0)||this.connections.map(a=>this.canvas.model.connections.get(a.id)!==void 0).includes(!0),e=new rt(this.canvas,this.nodes.map(a=>a.id),[],[],this.connections.map(a=>a.id),[],!0,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),t}redo(){const t=this.nodes.map(a=>this.canvas.model.nodes.get(a.id)===void 0).includes(!0)||this.connections.map(a=>this.canvas.model.connections.get(a.id)===void 0).includes(!0),e=new rt(this.canvas,this.nodes.map(a=>a.id),[],[],this.connections.map(a=>a.id),[],!1,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),t}}class Ft{constructor(t){this.type=t,this.defaultPrevented=!1}preventDefault(){this.defaultPrevented=!0}}var Ye=(s=>(s[s.Zoom=0]="Zoom",s[s.DoubleClick=1]="DoubleClick",s[s.SecondaryClick=2]="SecondaryClick",s[s.Selection=3]="Selection",s[s.Highlight=4]="Highlight",s))(Ye||{});class Yo extends Ft{constructor(t,e){super(0),this.coords=t,this.zoom=e}}class ut extends Ft{constructor(t,e,a){super(1),this.cause=t,this.target=e,this.coords=a}}class pt extends Ft{constructor(t,e,a){super(2),this.cause=t,this.target=e,this.coords=a}}class H extends Ft{constructor(t,e){super(3),this.targets=t,this.selected=e}}class Q extends Ft{constructor(t){super(4),this.target=t}}class Xe extends Ct{constructor(t,e,a,l,r,i,n,o,d="floating",c="floating"){if(t.objects.get(o)!==void 0)throw new Error(`DiagramDecorator with id "${o}" already exists`);if(!o)throw new Error("DiagramDecorator cannot have an empty or null id");super(t,o),this.rootElement=e,this.coords=a,this.width=l,this.height=r,this.priority=i,this.html=n,this.anchorPointX=d,this.anchorPointY=c}get removed(){return this.selfRemoved||this.rootElement!==void 0&&this.rootElement.removed}updateInView(){this.model.canvas?.updateDecoratorsInView(this.id)}raise(){this.select()?.raise()}move(t){this.coords=t,this.updateInView()}getPriority(){return this.priority}}class Xo extends gt{constructor(t){super(),this.model=t}new(t,e,a,l,r,i,n,o="floating",d="floating"){const c=new Xe(this.model,t,e,a,l,r,i,n,o,d);return super.add(c),c.updateInView(),t!==void 0&&t.decorators.push(c),c}remove(t){const e=this.get(t,!0);e&&((e.rootElement instanceof z||e.rootElement instanceof U)&&B(e.rootElement.decorators,e),super.remove(t),e.updateInView())}}class Wo extends Ct{constructor(t,e,a,l,r,i,n){if(t.objects.get(n)!==void 0)throw new Error(`DiagramObject with id "${n}" already exists`);if(!n)throw new Error("DiagramObject cannot have an empty or null id");super(t,n),this.coords=e,this.width=a,this.height=l,this.priority=r,this.html=i}get removed(){return this.selfRemoved}updateInView(){this.model.canvas?.updateObjectsInView(this.id)}raise(){this.select()?.raise()}move(t){this.coords=t,this.updateInView()}getPriority(){return this.priority}}class Zo extends gt{constructor(t){super(),this.model=t}new(t,e,a,l,r,i){const n=new Wo(this.model,t,e,a,l,r,i);return super.add(n),n.updateInView(),n}remove(t){const e=this.get(t,!0);e&&(super.remove(t),e.updateInView())}}class We{constructor(t,e,a,l,r,i=[]){this.nodes=new No(this),this.sections=new To(this),this.ports=new _o(this),this.connections=new $o(this),this.fields=new Io(this),this.objects=new Zo(this),this.decorators=new Xo(this),this.canvas=t,this.id=e,this.name=a,this.description=l,this.type=r,this.createdAt=new Date,this.updatedAt=new Date,this.logicalClock=0,this.valueSet=new vt(new qt(i),this)}clear(){this.canvas?.cancelAllUserActions(),this.id=void 0,this.name="",this.description=void 0,this.createdAt=new Date,this.updatedAt=new Date,this.logicalClock=0,this.nodes.clear(),this.sections.clear(),this.ports.clear(),this.connections.clear(),this.fields.clear(),this.objects.clear(),this.decorators.clear(),this.valueSet.resetValues(),this.canvas?.updateModelInView()}}const mt=s=>!!s.button,ne=(s,t,e,a,l,r,i,n)=>ao(s,[t,e],a,l,Math.max(10,i||0,n||0)*r),w=s=>{s?A.select("body").style("cursor",s):A.select("body").style("cursor",L.Auto)},dt=s=>s instanceof z?s:s instanceof U?s.node||s:s.rootElement instanceof z||s.rootElement instanceof U||s.rootElement instanceof yt?dt(s.rootElement):s,re=s=>{s.filter(".shaped-look").append("path"),s.filter(".image-look").append("image").attr("preserveAspectRatio","none"),s.filter(".stretchable-image-look").append("image").attr("class","top-left-image").attr("preserveAspectRatio","none"),s.filter(".stretchable-image-look").append("image").attr("class","top-image").attr("preserveAspectRatio","none"),s.filter(".stretchable-image-look").append("image").attr("class","top-right-image").attr("preserveAspectRatio","none"),s.filter(".stretchable-image-look").append("image").attr("class","left-image").attr("preserveAspectRatio","none"),s.filter(".stretchable-image-look").append("image").attr("class","center-image").attr("preserveAspectRatio","none"),s.filter(".stretchable-image-look").append("image").attr("class","right-image").attr("preserveAspectRatio","none"),s.filter(".stretchable-image-look").append("image").attr("class","bottom-left-image").attr("preserveAspectRatio","none"),s.filter(".stretchable-image-look").append("image").attr("class","bottom-image").attr("preserveAspectRatio","none"),s.filter(".stretchable-image-look").append("image").attr("class","bottom-right-image").attr("preserveAspectRatio","none")},zt={fillColor:"#FFFFFF",borderColor:"#000000",borderThickness:1,borderStyle:pe.Solid},ae=s=>{s.filter(".shaped-look").select("path").attr("d",t=>ge(t.look.shape||Tt.Rectangle,0,0,t.width,t.height)).attr("fill",t=>t.look.fillColor||zt.fillColor).attr("stroke",t=>t.look.borderColor||zt.borderColor).attr("stroke-width",t=>`${t.look.borderThickness||zt.borderThickness}px`).attr("stroke-dasharray",t=>he(t.look.borderStyle||zt.borderStyle,t.type?.defaultLook?.borderThickness||t.look?.borderThickness||zt.borderThickness)),s.filter(".image-look").select("image").attr("x",0).attr("y",0).attr("width",t=>t.width).attr("height",t=>t.height).attr("href",t=>t.look.backgroundImage),s.filter(".stretchable-image-look").select("image.top-left-image").attr("x",0).attr("y",0).attr("width",t=>t.look.leftMargin).attr("height",t=>t.look.topMargin).attr("href",t=>t.look.backgroundImageTopLeft),s.filter(".stretchable-image-look").select("image.top-image").attr("x",t=>t.look.leftMargin).attr("y",0).attr("width",t=>t.width-t.look.rightMargin-t.look.leftMargin).attr("height",t=>t.look.topMargin).attr("href",t=>t.look.backgroundImageTop),s.filter(".stretchable-image-look").select("image.top-right-image").attr("x",t=>t.width-t.look.rightMargin).attr("y",0).attr("width",t=>t.look.rightMargin).attr("height",t=>t.look.topMargin).attr("href",t=>t.look.backgroundImageTopRight),s.filter(".stretchable-image-look").select("image.left-image").attr("x",0).attr("y",t=>t.look.topMargin).attr("width",t=>t.look.leftMargin).attr("height",t=>t.height-t.look.bottomMargin-t.look.topMargin).attr("href",t=>t.look.backgroundImageLeft),s.filter(".stretchable-image-look").select("image.center-image").attr("x",t=>t.look.leftMargin).attr("y",t=>t.look.topMargin).attr("width",t=>t.width-t.look.rightMargin-t.look.leftMargin).attr("height",t=>t.height-t.look.bottomMargin-t.look.topMargin).attr("href",t=>t.look.backgroundImageCenter),s.filter(".stretchable-image-look").select("image.right-image").attr("x",t=>t.width-t.look.rightMargin).attr("y",t=>t.look.topMargin).attr("width",t=>t.look.rightMargin).attr("height",t=>t.height-t.look.bottomMargin-t.look.topMargin).attr("href",t=>t.look.backgroundImageRight),s.filter(".stretchable-image-look").select("image.bottom-left-image").attr("x",0).attr("y",t=>t.height-t.look.bottomMargin).attr("width",t=>t.look.leftMargin).attr("height",t=>t.look.bottomMargin).attr("href",t=>t.look.backgroundImageBottomLeft),s.filter(".stretchable-image-look").select("image.bottom-image").attr("x",t=>t.look.leftMargin).attr("y",t=>t.height-t.look.bottomMargin).attr("width",t=>t.width-t.look.rightMargin-t.look.leftMargin).attr("height",t=>t.look.bottomMargin).attr("href",t=>t.look.backgroundImageBottom),s.filter(".stretchable-image-look").select("image.bottom-right-image").attr("x",t=>t.width-t.look.rightMargin).attr("y",t=>t.height-t.look.bottomMargin).attr("width",t=>t.look.rightMargin).attr("height",t=>t.look.bottomMargin).attr("href",t=>t.look.backgroundImageBottomRight)},Rt={style:"dots",color:"rgba(0, 0, 0, 0.1)",snap:!1,spacing:10,thickness:.05},Ko=(s,t,e)=>{const a=t.append("defs");if(s.gridSize>0&&isFinite(s.gridSize)){const l=a.append("pattern").attr("id",e).attr("x",-s.gridSize/2).attr("y",-s.gridSize/2).attr("width",s.gridSize).attr("height",s.gridSize).attr("patternUnits","userSpaceOnUse");switch(l.append("rect").attr("x",0).attr("y",0).attr("width",s.gridSize).attr("height",s.gridSize).attr("fill",s.backgroundColor),s.gridStyle){case"dots":l.append("circle").attr("cx",s.gridSize/2).attr("cy",s.gridSize/2).attr("r",s.gridSize*s.gridThickness).attr("fill",s.gridColor);break;case"lines":l.append("line").attr("x1",s.gridSize/2).attr("x2",s.gridSize/2).attr("y1",0).attr("y2",s.gridSize).attr("stroke-width",s.gridSize*s.gridThickness).attr("stroke",s.gridColor),l.append("line").attr("x1",0).attr("x2",(s.gridSize-s.gridSize*s.gridThickness)/2).attr("y1",s.gridSize/2).attr("y2",s.gridSize/2).attr("stroke-width",s.gridSize*s.gridThickness).attr("stroke",s.gridColor),l.append("line").attr("x1",(s.gridSize+s.gridSize*s.gridThickness)/2).attr("x2",s.gridSize).attr("y1",s.gridSize/2).attr("y2",s.gridSize/2).attr("stroke-width",s.gridSize*s.gridThickness).attr("stroke",s.gridColor);break}t.select("rect").attr("fill",`url(#${e})`)}},fe=96,W=32,At=fe+W,qo=Math.PI/4,Jo=100,Me={customButtons:[]};class Qo{constructor(t,e){this.canvas=t,this.config=e||Me}open(t){this.close();const e=this.canvas.getPointerLocationRelativeToRoot(t),a=this.canvas.getPointerLocationRelativeToCanvas(t),l=this.canvas.selectSVGElement().append("foreignObject").attr("class","daga-context-menu").attr("x",`${e[0]-At}px`).attr("y",`${e[1]-At}px`).attr("width",`${2*At}px`).attr("height",`${2*At}px`).style("pointer-events","none").on(S.ContextMenu,i=>{this.canvas.canUserPerformAction(k.ContextMenu)&&(t.preventDefault(),this.open(i))}).on(S.Click,i=>{i.preventDefault(),this.close()});this.contextMenuContainer=l;const r=[];this.canvas.userSelection.length!==0&&this.canvas.canUserPerformAction(k.Clipboard)&&this.canvas.canUserPerformAction(k.Remove)&&r.push({name:"CUT",imageClass:"daga-cut",onPress:i=>{i.userSelection.cutToClipboard(),i.cancelAllUserActions()}}),this.canvas.userSelection.length!==0&&this.canvas.canUserPerformAction(k.Clipboard)&&r.push({name:"COPY",imageClass:"daga-copy",onPress:i=>{i.userSelection.copyToClipboard(),i.cancelAllUserActions()}}),this.canvas.canUserPerformAction(k.Paste)&&r.push({name:"PASTE",imageClass:"daga-paste",onPress:i=>{i.userSelection.pasteFromClipboard(i.getClosestGridPoint(a)),i.cancelAllUserActions()}}),this.canvas.userSelection.length!==0&&this.canvas.canUserPerformAction(k.Remove)&&r.push({name:"DELETE",imageClass:"daga-delete",onPress:i=>{i.userSelection.removeFromModel(),i.cancelAllUserActions()}});for(const i of this.config.customButtons||Me.customButtons)(i.condition===void 0||i.condition(this.canvas))&&r.push(i);r.length===0&&r.push({name:"NONE",imageClass:"daga-cross",onPress:void 0});for(let i=0;i<r.length;++i){const n=r[i],o=n.onPress,d=(i+.5-r.length/2)*qo,c=l.append("xhtml:div").attr("class",`daga-context-menu-button ${n.onPress!==void 0?" daga-clickable":""}`).attr("tabindex",0).style("position","absolute").style("box-sizing","border-box").style("width",`${2*W}px`).style("height",`${2*W}px`).style("border-radius",`${W}px`).style("pointer-events","auto").on(S.Click,h=>{o&&(h.preventDefault(),o(this.canvas))}).on(S.KeyDown,h=>{o&&h.key===K.Enter&&(h.preventDefault(),o(this.canvas))});n.imageClass!==void 0?c.append("xhtml:div").style("position","absolute").style("left",`${.75*W}px`).style("top",`${.5*W}px`).style("width",`${.5*W}px`).style("height",`${.5*W}px`).style("background-size","contain").style("background-repeat","no-repeat").attr("class",n.imageClass):n.image!==void 0&&c.append("xhtml:img").style("position","absolute").style("left",`${.75*W}px`).style("top",`${.5*W}px`).style("width",`${.5*W}px`).style("height",`${.5*W}px`).attr("src",n.image),c.append("xhtml:span").style("position","absolute").style("left",`${.2*W}px`).style("top",`${1.1*W}px`).style("text-align","center").style("width",`${1.6*W}px`).style("height",`${.35*W}px`).style("margin","0").style("font-size",`${.35*W}px`).style("font-weight","700").style("user-select","none").text(n.name),c.transition().ease(A.easeLinear).duration(Jo).tween("progress",()=>h=>{const u=d*h;return c.style("left",`${Math.sin(u)*fe-W+At}px`).style("top",`${-Math.cos(u)*fe-W+At}px`)})}}close(){this.contextMenuContainer?.remove(),this.contextMenuContainer=void 0}}class ti extends gt{constructor(t,e=!0){super(),this.focus=void 0,this.canvas=t,this.highlightSections=e}getFocus(){return this.focus}focusOn(t){this.clear(),this.focus=t,(t instanceof ct||t instanceof Xe)&&t.rootElement?this.focusOn(t.rootElement):this.add(t)}add(t){if(super.add(t),t instanceof z){if(!this.highlightSections)for(const e of t.sections){super.add(e);for(const a of e.ports)super.add(a),this.canvas.updatePortsInView(a.id);e.label&&(super.add(e.label),this.canvas.updateFieldsInView(e.label.id)),this.canvas.updateSectionsInView(e.id)}for(const e of t.ports)super.add(e),this.canvas.updatePortsInView(e.id);t.label&&(super.add(t.label),this.canvas.updateFieldsInView(t.label.id)),this.canvas.updateNodesInView(t.id)}else if(t instanceof U)if(!this.highlightSections&&t.node)this.add(t.node);else{for(const e of t.ports)super.add(e),this.canvas.updatePortsInView(e.id);t.label&&(super.add(t.label),this.canvas.updateFieldsInView(t.label.id)),this.canvas.updateSectionsInView(t.id)}else t instanceof yt?(t.label&&(super.add(t.label),this.canvas.updateFieldsInView(t.label.id)),this.canvas.updatePortsInView(t.id)):t instanceof lt&&this.canvas.updateConnectionsInView(t.id)}clear(){for(;this.entities.length>0;){const t=this.entities[0];this.remove(t.id),t.updateInView()}this.focus=void 0}}const ei=1;class Ze{export(t,e=!1){const a={name:t.name,type:t.type,typeVersion:ei,createdAt:t.createdAt,updatedAt:t.updatedAt,nodes:[],connections:[],data:t.valueSet.getValues(),...e?{collabMeta:{logicalClock:t.logicalClock,dataTimestamps:t.valueSet.getTimestamps()}}:{}};t.id&&(a.id=t.id),t.description&&(a.description=t.description);for(const l of t.nodes.all(!0))!e&&l.removed||l.parent===void 0&&a.nodes.push(this.exportNode(l,e));for(const l of t.connections.all(!0))!e&&l.removed||a.connections.push(this.exportConnection(l,e));return a}exportNode(t,e=!1){const a=[];for(const i of t.children)a.push(this.exportNode(i,e));const l=[];for(const i of t.sections){const n=[];for(const o of i.ports)n.push({id:o.id,type:o.type?.id,coords:It(o.coords),connectionPoint:It(o.connectionPoint||o.coords),direction:o.direction,label:o.label?.text||"",...e?{collabMeta:{removed:o.removed,selfRemoved:o.selfRemoved,selfRemovedTimestamp:o.selfRemovedTimestamp,...this.exportLabelCollabMeta(o)}}:{}});l.push({id:i.id,ports:n,label:i.label?.text||"",indexXInNode:i.indexXInNode,indexYInNode:i.indexYInNode,coords:It(i.coords),width:i.width,height:i.height,...e?{collabMeta:{removed:i.removed,selfRemoved:i.selfRemoved,selfRemovedTimestamp:i.selfRemovedTimestamp,...this.exportLabelCollabMeta(i)}}:{}})}const r=[];for(const i of t.ports)r.push({id:i.id,type:i.type?.id,coords:It(i.coords),connectionPoint:It(i.connectionPoint||i.coords),direction:i.direction,label:i.label?.text||"",...e?{collabMeta:{removed:i.removed,selfRemoved:i.selfRemoved,selfRemovedTimestamp:i.selfRemovedTimestamp,...this.exportLabelCollabMeta(i)}}:{}});return{id:t.id,type:t.type.id,children:a,sections:l,ports:r,label:t.label?.text||"",coords:It(t.coords),width:t.width,height:t.height,data:t.valueSet.getValues(),...e?{collabMeta:{removed:t.removed,selfRemoved:t.selfRemoved,selfRemovedTimestamp:t.selfRemovedTimestamp,geometryTimestamp:t.geometryTimestamp,dataTimestamps:t.valueSet.getTimestamps(),...this.exportLabelCollabMeta(t)}}:{}}}exportConnection(t,e=!1){return{id:t.id,type:t.type.id,start:t.start?.id||"",end:t.end?.id||"",startLabel:t.startLabel,middleLabel:t.middleLabel,endLabel:t.endLabel,points:t.points,data:t.valueSet.getValues(),...e?{collabMeta:{removed:t.removed,selfRemoved:t.selfRemoved,selfRemovedTimestamp:t.selfRemovedTimestamp,dataTimestamps:t.valueSet.getTimestamps()}}:{}}}exportLabelCollabMeta({label:t}){return t?{label:{removed:t.removed,selfRemoved:t.selfRemoved,selfRemovedTimestamp:t.selfRemovedTimestamp,textTimestamp:t.textTimestamp}}:{}}}const oi="Diagram properties";class ii extends gt{constructor(t,e){super(),this.canvas=t,this.canvas.propertyEditorChanges$.pipe(kt.debounceTime(2e3)).subscribe(()=>{this.makeUpdateValuesAction()}),this.diagramPropertiesText=e!==void 0?e:oi}add(t){if(!this.contains(t.id)&&(this.length===0?this.propertyEditorSelection===void 0&&(t instanceof z||t instanceof lt)?this.openInPropertyEditor(t):this.propertyEditorSelection===void 0&&t instanceof U?this.openInPropertyEditor(t.node):this.openInPropertyEditor(void 0):this.openInPropertyEditor(void 0),super.add(t),t.updateInView(),t instanceof z&&t.sections))for(const e of t.sections)super.add(e),e.updateInView()}remove(t){const e=this.get(t);if(e&&(this.propertyEditorSelection===e&&this.openInPropertyEditor(void 0),super.remove(t),e.updateInView(),e instanceof z&&e.sections))for(const a of e.sections)super.remove(a.id),a.updateInView()}toggle(t){this.contains(t.id)?this.remove(t.id):this.add(t)}clear(){for(this.openInPropertyEditor(void 0);this.entities.length>0;){const t=this.entities[0];super.remove(t.id),t.updateInView()}}move(t){for(const e of this.all())e instanceof z&&e.move([e.coords[0]+t[0],e.coords[1]+t[1]])}removeFromModel(){if(this.length>0){const t=[],e=[],a=[],l=[],r=[];for(const n of this.all())n instanceof z?t.push(n.id):n instanceof U?e.push(n.id):n instanceof yt?a.push(n.id):n instanceof lt?l.push(n.id):n instanceof ct&&r.push(n.id);const i=new Do(this.canvas,t,e,a,l,r);i.do(),this.canvas.actionStack.add(i)}}copyToClipboard(){const t={type:"daga-user-selection",nodes:[],connections:[]},e=new Ze;for(const a of this.all())a instanceof z&&t.nodes.push(e.exportNode(a,!1)),a instanceof lt&&t.connections.push(e.exportConnection(a,!1));navigator.clipboard.writeText(JSON.stringify(t))}cutToClipboard(){this.copyToClipboard(),this.removeFromModel()}pasteFromClipboard(t){navigator.clipboard.readText().then(e=>{try{const a=JSON.parse(e);if(a.type!=="daga-user-selection")return;const l=new Bo(this.canvas,a.nodes,a.connections,t);this.canvas.actionStack.add(l),l.do()}catch{return}})}openInPropertyEditor(t,e=!0){e&&this.makeUpdateValuesAction();const a=this.canvas.parentComponent?.propertyEditor;if(a===void 0)return;const l=t?.valueSet;l?(this.propertyEditorSelection=t,e&&(this.propertyEditorValues=St(l.getValues())),a&&(t instanceof z||t instanceof lt?(t instanceof z?t.name?a.title=`${t.type.name}: ${t.name}`:a.title=t.type.name:t instanceof lt&&(a.title=t.type.name),a.valueSet=void 0,a.valueSet=l):(a.title=this.diagramPropertiesText,a.valueSet=void 0,a.valueSet=l))):(this.propertyEditorSelection=void 0,this.propertyEditorValues=void 0,a&&(a.title="",a.valueSet=void 0))}makeUpdateValuesAction(){if(this.propertyEditorSelection===void 0||this.propertyEditorValues===void 0)return;const t=this.propertyEditorSelection instanceof We?void 0:this.propertyEditorSelection.id;if(wt(this.propertyEditorValues,this.propertyEditorSelection?.valueSet.getValues()))return;const e=this.propertyEditorValues,a=St(this.propertyEditorSelection?.valueSet.getValues()),[l,r]=_e(e,a,this.propertyEditorSelection?.valueSet),i=new Uo(this.canvas,t,l,r);i.do(),this.canvas.actionStack.add(i),this.propertyEditorValues=a}}const si=s=>s*Math.PI/180,Te=(s,t,e)=>{const a=si(e),l=Math.sin(a),r=Math.cos(a),i=(Math.abs(s*r)-Math.abs(t*l))/(r*r-l*l),n=(Math.abs(s*l)-Math.abs(t*r))/(l*l-r*r);return[i,n]},Ne=navigator?.userAgent?.indexOf("AppleWebKit")>=0,ni=12,_=6,ri=25,le="diagram-connection-unfinished",Zt=class Zt{constructor(t,e){if(this.backgroundPatternId=`daga-background-pattern-id-${Zt.canvasCount++}`,this.zoomTransform=A.zoomIdentity,this.draggingFrom=[0,0],this.dragging=!1,this.secondaryButton=!1,this.validatorChange$=new kt.Subject,this.diagramChange$=new kt.Subject,this.diagramEvent$=new kt.Subject,this.propertyEditorChanges$=new kt.Subject,this.parentComponent=t,this.model=new We(this,void 0,e.name||"unnamed","",e.type||"",e.properties||[]),this.userSelection=new ii(this,e.components?.propertyEditor?.title),this.userHighlight=new ti(this,e.canvas?.highlightSections!==!1),this.contextMenu=new Qo(this,e.canvas?.contextMenu),this.backgroundColor=e.canvas?.backgroundColor||"#FFFFFF",this.gridStyle=e.canvas?.grid?.style??Rt.style,this.gridSize=e.canvas?.grid?.enabled===!1||e.canvas?.grid===void 0?0:Math.abs(e.canvas?.grid?.spacing||Rt.spacing),this.gridThickness=Math.abs(e.canvas?.grid?.thickness||Rt.thickness),this.gridColor=e.canvas?.grid?.color||Rt.color,this.snapToGrid=e.canvas?.grid?.enabled===!1||e.canvas?.grid===void 0?!1:e.canvas?.grid?.snap||Rt.snap,this.zoomFactor=e.canvas?.zoomFactor||2,this.panRate=e.canvas?.panRate||100,this.inferConnectionType=e.connectionSettings?.inferConnectionType||!1,this.autoTightenConnections=e.connectionSettings?.autoTighten!==!1,this.allowConnectionLoops=e.connectionSettings?.allowLoops||!1,this.allowSharingPorts=e.connectionSettings?.sharePorts!==!1,this.allowSharingBothPorts=e.connectionSettings?.shareBothPorts||!1,this.portHighlightRadius=e.connectionSettings?.portHighlightRadius||100,this.multipleSelectionOn=!1,this.priorityThresholds=e.canvas?.priorityThresholds||[],this.priorityThreshold=this.priorityThresholds?this.priorityThresholds[0]:void 0,this.layoutFormat=e.layoutFormat,this.userActions=e.userActions||{},this.validators=[],this.actionStack=new jo(this,ri),this.collabEngine=new Ho(this),e.nodeTypes)for(const a of e.nodeTypes){const l=new Ge({...e.nodeTypeDefaults,...a});this.model.nodes.types.add(l)}if(e.portTypes)for(const a of e.portTypes){const l=new Oo({...e.portTypeDefaults,...a});this.model.ports.types.add(l)}if(e.connectionTypes){for(const a of e.connectionTypes){const l=new He({...e.connectionTypeDefaults,...a});this.model.connections.types.add(l)}this._connectionType=e?.connectionSettings?.defaultConnection!==void 0?this.model.connections.types.get(e.connectionSettings.defaultConnection):void 0}}get connectionType(){return this._connectionType}set connectionType(t){this._connectionType=t,this.parentComponent?.palette?.refreshPalette()}addValidator(t){this.validators.push(t),this.validatorChange$.next()}removeValidator(t){B(this.validators,t),this.validatorChange$.next()}getPriorityThresholdOptions(){return this.priorityThresholds}getPriorityThreshold(){return this.priorityThreshold}setPriorityThreshold(t){this.priorityThreshold=t,this.updateModelInView();for(const e of this.model.nodes)this.fitNodeInView(e.id);this.parentComponent?.palette?.refreshPalette()}initView(t){const e=A.select(t);e.html(""),this.diagramRoot=e.append("div").node(),A.select(this.diagramRoot).attr("tabindex",0).style("width","100%").style("height","100%").append("svg").style("width","100%").style("height","100%"),A.select(this.diagramRoot).on(S.Click,()=>{A.select(this.diagramRoot).node()?.focus()}).on(S.ContextMenu,l=>{if(this.dragging){l.preventDefault(),l.stopPropagation(),this.dragging=!1;return}const r=new pt(l,null);this.diagramEvent$.next(r),!r.defaultPrevented&&this.canUserPerformAction(k.ContextMenu)&&(l.preventDefault(),this.contextMenu.open(l))}).on(S.DoubleClick,l=>{const r=new ut(l,null);this.diagramEvent$.next(r)}).on(S.KeyDown,l=>{if(!l.ctrlKey&&(l.key===K.Delete||l.key===K.Backspace)&&this.canUserPerformAction(k.Remove)&&(this.userSelection.removeFromModel(),this.cancelAllUserActions()),l.ctrlKey&&l.key==="a"){l.preventDefault();for(const r of this.model.nodes)this.userSelection.add(r);for(const r of this.model.connections)this.userSelection.add(r);this.diagramEvent$.next(new H(this.userSelection.all(),!0))}if(l.ctrlKey&&l.key==="i"){l.preventDefault();const r=[],i=[];for(const n of this.model.nodes)this.userSelection.toggle(n),n.selected?r.push(n):i.push(n);for(const n of this.model.connections)this.userSelection.toggle(n),n.selected?r.push(n):i.push(n);r.length>0&&this.diagramEvent$.next(new H(r,!0)),i.length>0&&this.diagramEvent$.next(new H(i,!1))}if(l.ctrlKey&&l.key==="c"&&this.canUserPerformAction(k.Clipboard)&&(l.preventDefault(),this.userSelection.copyToClipboard(),this.cancelAllUserActions()),l.ctrlKey&&l.key==="x"&&this.canUserPerformAction(k.Clipboard)&&this.canUserPerformAction(k.Remove)&&(l.preventDefault(),this.userSelection.cutToClipboard(),this.cancelAllUserActions()),l.ctrlKey&&l.key==="v"&&this.canUserPerformAction(k.Paste)){l.preventDefault();const r=this.getCoordinatesOnScreen();this.userSelection.pasteFromClipboard(this.getClosestGridPoint([(r[0][0]+r[1][0])/2,(r[0][1]+r[1][1])/2])),this.cancelAllUserActions()}l.ctrlKey&&l.key==="y"&&(l.preventDefault(),this.actionStack.redo()),l.ctrlKey&&l.key==="z"&&(l.preventDefault(),this.actionStack.undo()),l.key==="+"&&this.canUserPerformAction(k.Zoom)&&(l.preventDefault(),this.zoomBy(this.zoomFactor)),l.key==="-"&&this.canUserPerformAction(k.Zoom)&&(l.preventDefault(),this.zoomBy(1/this.zoomFactor)),l.key===K.ArrowLeft&&this.canUserPerformAction(k.Zoom)&&(l.preventDefault(),this.translateBy(this.panRate/this.zoomTransform.k,0)),l.key===K.ArrowRight&&this.canUserPerformAction(k.Zoom)&&(l.preventDefault(),this.translateBy(-this.panRate/this.zoomTransform.k,0)),l.key===K.ArrowDown&&this.canUserPerformAction(k.Zoom)&&(l.preventDefault(),this.translateBy(0,-this.panRate/this.zoomTransform.k)),l.key===K.ArrowUp&&this.canUserPerformAction(k.Zoom)&&(l.preventDefault(),this.translateBy(0,this.panRate/this.zoomTransform.k))});const a=this.selectSVGElement().append("g").attr("class","daga-canvas-view").attr("width","100%").attr("height","100%");a.call(this.zoomBehavior=A.zoom().filter(l=>l.type!==S.DoubleClick).on(de.Zoom,l=>{if(l.sourceEvent){if(!this.canUserPerformAction(k.Zoom)){w(L.NotAllowed);return}l.sourceEvent.type===S.Wheel&&l.sourceEvent.wheelDelta!==void 0?(l.sourceEvent.wheelDelta>0&&w(L.ZoomIn),l.sourceEvent.wheelDelta<0&&w(L.ZoomOut)):l.sourceEvent.type===S.MouseMove&&w(L.AllScroll)}this.zoomTransform=l.transform;const r=l.transform.toString();this.selectCanvasElements().attr("transform",r),A.select(`#${this.backgroundPatternId}`).attr("patternTransform",r),Ne&&this.updateFieldsInView(),this.contextMenu.close(),this.diagramEvent$.next(new Yo([this.zoomTransform.x,this.zoomTransform.y],this.zoomTransform.k))}).on(de.End,()=>{w()})),a.append("rect").attr("x",0).attr("y",0).attr("width","100%").attr("height","100%").attr("fill",this.backgroundColor).attr("stroke-width","0").on(S.MouseMove,l=>{if(this.unfinishedConnection!==void 0){const r=this.getPointerLocationRelativeToCanvas(l);this.unfinishedConnection.endCoords=r}}).on(S.MouseOver,()=>{this.userHighlight.size()>0&&(this.userHighlight.clear(),this.diagramEvent$.next(new Q(null)))}).on(S.Click,()=>{if(this.userHighlight.size()>0&&(this.userHighlight.clear(),this.diagramEvent$.next(new Q(null))),this.contextMenu.close(),this.userSelection.size()>0){const l=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new H(l,!1))}this.userSelection.openInPropertyEditor(this.model)}).call(A.drag().filter(l=>this.multipleSelectionOn||mt(l)).on($.Start,l=>{this.startMultipleSelection(l)}).on($.Drag,l=>{this.continueMultipleSelection(l)}).on($.End,l=>{this.finishMultipleSelection(l)})),Ko(this,a,this.backgroundPatternId),a.append("g").attr("class","daga-canvas-elements")}getZoomLevel(){return this.zoomTransform.k}zoomBy(t){isNaN(t)||this.zoomBehavior.scaleBy(this.selectCanvasView(),t)}zoomTo(t){isNaN(t)||this.zoomBehavior.scaleTo(this.selectCanvasView(),t)}getViewCoordinates(){return[this.zoomTransform.x,this.zoomTransform.y]}translateBy(t,e){!isNaN(t)&&!isNaN(e)&&this.zoomBehavior.translateBy(this.selectCanvasView(),t,e)}translateTo(t,e){!isNaN(t)&&!isNaN(e)&&this.zoomBehavior.translateTo(this.selectCanvasView(),t,e)}center(){if(this.model.nodes.length>0){const t=this.selectCanvasView().select("rect").node()?.getBBox(),e=this.model.nodes.all(),a=Math.min(...e.map(m=>m.coords[0])),l=Math.max(...e.map(m=>m.coords[0]+m.width)),r=(a+l)/2,i=l-a,n=t.width,o=Math.min(...e.map(m=>m.coords[1])),d=Math.max(...e.map(m=>m.coords[1]+m.height)),c=(o+d)/2,h=d-o,u=t.height,b=Math.min(n/i,u/h,1);this.translateTo(r,c),this.zoomTo(b)}}getClosestGridPoint(t){return this.gridSize===0||!isFinite(this.gridSize)?t:[Math.round(t[0]/this.gridSize)*this.gridSize,Math.round(t[1]/this.gridSize)*this.gridSize]}getCoordinatesOnScreen(){const t=this.selectSVGElement().node()?.getBoundingClientRect(),e=[t?.width||0,t?.height||0];return[[-this.zoomTransform.x/this.zoomTransform.k,-this.zoomTransform.y/this.zoomTransform.k],[(e[0]-this.zoomTransform.x)/this.zoomTransform.k,(e[1]-this.zoomTransform.y)/this.zoomTransform.k]]}getEventHoldingCoordinates(t){if(t.type==="drag"||t.type==="start"||t.type==="end"){const e=t.sourceEvent;if(e&&(e.type==="touchmove"||e.type==="touchstart"||e.type==="touchend"))return t.sourceEvent.touches[0]||t.sourceEvent.changedTouches[0]}return t}getPointerLocationRelativeToCanvas(t){return A.pointer(this.getEventHoldingCoordinates(t),this.selectCanvasElements().node())}getPointerLocationRelativeToRoot(t){return A.pointer(this.getEventHoldingCoordinates(t),this.selectSVGElement().node())}getPointerLocationRelativeToBody(t){return A.pointer(this.getEventHoldingCoordinates(t),A.select("body").node())}getPointerLocationRelativeToScreen(t){const e=this.getPointerLocationRelativeToBody(t);return[e[0]-window.scrollX,e[1]-window.scrollY]}updateModelInView(){this.updateNodesInView(),this.updateSectionsInView(),this.updatePortsInView(),this.updateConnectionsInView(),this.updateFieldsInView(),this.updateObjectsInView(),this.updateDecoratorsInView()}updateNodesInView(...t){let e=this.selectCanvasElements().selectAll("g.diagram-node").data(this.model.nodes.filter(i=>this.priorityThreshold!==void 0?i.getPriority()>=this.priorityThreshold:!0),i=>i.id);const a=e.exit(),l=e.enter().append("g").attr("id",i=>i.id).attr("class",i=>`diagram-node${i.type.resizableX?" resizable-x":""}${i.type.resizableY?" resizable-y":""} ${i.type.defaultLook.lookType}`);t&&t.length>0&&(e=e.filter(i=>t.includes(i.id)));const r=l.merge(e);a.remove(),l.on(S.MouseOver,(i,n)=>{this.dragging||(this.userHighlight.focusOn(n),this.diagramEvent$.next(new Q(n)))}).on(S.Click,(i,n)=>{if(!i.ctrlKey&&!i.shiftKey){const o=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new H(o,!1))}this.userSelection.toggle(n),this.diagramEvent$.next(new H([n],n.selected))}).on(S.ContextMenu,(i,n)=>{if(this.dragging){i.preventDefault(),i.stopPropagation(),this.dragging=!1;return}const o=new pt(i,n);this.diagramEvent$.next(o),!o.defaultPrevented&&this.canUserPerformAction(k.ContextMenu)&&(i.preventDefault(),this.userHighlight.focusOn(n),this.diagramEvent$.next(new Q(n)),this.userSelection.add(n),this.diagramEvent$.next(new H([n],!0)),this.contextMenu.open(i))}).on(S.DoubleClick,(i,n)=>{const o=new ut(i,n);this.diagramEvent$.next(o)}).call(A.drag().filter(i=>(this.secondaryButton=mt(i),!0)).on($.Start,(i,n)=>{this.multipleSelectionOn||this.secondaryButton?this.startMultipleSelection(i):this.startMovingNode(i,n)}).on($.Drag,(i,n)=>{this.multipleSelectionOn||this.secondaryButton?this.continueMultipleSelection(i):this.continueMovingNode(i,n)}).on($.End,(i,n)=>{this.multipleSelectionOn||this.secondaryButton?this.finishMultipleSelection(i):this.finishMovingNode(i,n),this.secondaryButton=!1})),re(l),l.filter(".resizable-x").append("line").attr("class","left-resizer").attr("stroke","transparent").attr("stroke-width",`${_}px`).on(S.MouseOver,(i,n)=>{this.canUserPerformAction(k.StretchNode)&&n.type.resizableX&&!n.removed&&w(L.EWResize)}).on(S.MouseOut,(i,n)=>{this.canUserPerformAction(k.StretchNode)&&n.type.resizableX&&!n.removed&&w()}).call(A.drag().on($.Start,(i,n)=>{this.canUserPerformAction(k.StretchNode)&&n.type.resizableX&&!n.removed?(w(L.EWResize),this.currentAction=new X(this,k.StretchNode,n.id,n.getGeometry(),n.getGeometry())):w(L.NotAllowed)}).on($.Drag,(i,n)=>{if(this.canUserPerformAction(k.StretchNode)&&n.type.resizableX&&!n.removed){const o=this.getPointerLocationRelativeToCanvas(i);n.stretch(f.Left,n.coords[0]-o[0])}}).on($.End,(i,n)=>{if(this.canUserPerformAction(k.StretchNode)&&n.type.resizableX&&!n.removed&&this.currentAction instanceof X&&this.currentAction.intent===k.StretchNode){let o=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(o=this.getClosestGridPoint([o[0]-n.type.snapToGridOffset[0],o[1]-n.type.snapToGridOffset[1]]),o[0]+=n.type.snapToGridOffset[0],o[1]+=n.type.snapToGridOffset[1]),n.stretch(f.Left,n.coords[0]-o[0]),this.currentAction.to=n.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}w()})),l.filter(".resizable-y").append("line").attr("class","top-resizer").attr("stroke","transparent").attr("stroke-width",`${_}px`).on(S.MouseOver,(i,n)=>{this.canUserPerformAction(k.StretchNode)&&n.type.resizableY&&!n.removed&&w(L.NSResize)}).on(S.MouseOut,(i,n)=>{this.canUserPerformAction(k.StretchNode)&&n.type.resizableY&&!n.removed&&w()}).call(A.drag().on($.Start,(i,n)=>{this.canUserPerformAction(k.StretchNode)&&n.type.resizableY&&!n.removed?(w(L.NSResize),this.currentAction=new X(this,k.StretchNode,n.id,n.getGeometry(),n.getGeometry())):w(L.NotAllowed)}).on($.Drag,(i,n)=>{if(this.canUserPerformAction(k.StretchNode)&&n.type.resizableY&&!n.removed){const o=this.getPointerLocationRelativeToCanvas(i);n.stretch(f.Top,n.coords[1]-o[1])}}).on($.End,(i,n)=>{if(this.canUserPerformAction(k.StretchNode)&&n.type.resizableY&&!n.removed&&this.currentAction instanceof X&&this.currentAction.intent===k.StretchNode){let o=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(o=this.getClosestGridPoint([o[0]-n.type.snapToGridOffset[0],o[1]-n.type.snapToGridOffset[1]]),o[0]+=n.type.snapToGridOffset[0],o[1]+=n.type.snapToGridOffset[1]),n.stretch(f.Top,n.coords[1]-o[1]),this.currentAction.to=n.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}w()})),l.filter(".resizable-x").append("line").attr("class","right-resizer").attr("stroke","transparent").attr("stroke-width",`${_}px`).on(S.MouseOver,(i,n)=>{this.canUserPerformAction(k.StretchNode)&&n.type.resizableX&&!n.removed&&w(L.EWResize)}).on(S.MouseOut,(i,n)=>{this.canUserPerformAction(k.StretchNode)&&n.type.resizableX&&!n.removed&&w()}).call(A.drag().on($.Start,(i,n)=>{this.canUserPerformAction(k.StretchNode)&&n.type.resizableX&&!n.removed?(w(L.EWResize),this.currentAction=new X(this,k.StretchNode,n.id,n.getGeometry(),n.getGeometry())):w(L.NotAllowed)}).on($.Drag,(i,n)=>{if(this.canUserPerformAction(k.StretchNode)&&n.type.resizableX&&!n.removed){const o=this.getPointerLocationRelativeToCanvas(i);n.stretch(f.Right,o[0]-(n.coords[0]+n.width))}}).on($.End,(i,n)=>{if(this.canUserPerformAction(k.StretchNode)&&n.type.resizableX&&!n.removed&&this.currentAction instanceof X&&this.currentAction.intent===k.StretchNode){let o=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(o=this.getClosestGridPoint([o[0]-n.type.snapToGridOffset[2],o[1]-n.type.snapToGridOffset[3]]),o[0]+=n.type.snapToGridOffset[2],o[1]+=n.type.snapToGridOffset[3]),n.stretch(f.Right,o[0]-(n.coords[0]+n.width)),this.currentAction.to=n.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}w()})),l.filter(".resizable-y").append("line").attr("class","bottom-resizer").attr("stroke","transparent").attr("stroke-width",`${_}px`).on(S.MouseOver,(i,n)=>{this.canUserPerformAction(k.StretchNode)&&n.type.resizableY&&!n.removed&&w(L.NSResize)}).on(S.MouseOut,(i,n)=>{this.canUserPerformAction(k.StretchNode)&&n.type.resizableY&&!n.removed&&w()}).call(A.drag().on($.Start,(i,n)=>{this.canUserPerformAction(k.StretchNode)&&n.type.resizableY&&!n.removed?(w(L.NSResize),this.currentAction=new X(this,k.StretchNode,n.id,n.getGeometry(),n.getGeometry())):w(L.NotAllowed)}).on($.Drag,(i,n)=>{if(this.canUserPerformAction(k.StretchNode)&&n.type.resizableY&&!n.removed){const o=this.getPointerLocationRelativeToCanvas(i);n.stretch(f.Bottom,o[1]-(n.coords[1]+n.height))}}).on($.End,(i,n)=>{if(this.canUserPerformAction(k.StretchNode)&&n.type.resizableY&&!n.removed&&this.currentAction instanceof X&&this.currentAction.intent===k.StretchNode){let o=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&this.snapToGrid&&(o=this.getClosestGridPoint([o[0]-n.type.snapToGridOffset[2],o[1]-n.type.snapToGridOffset[3]]),o[0]+=n.type.snapToGridOffset[2],o[1]+=n.type.snapToGridOffset[3]),n.stretch(f.Bottom,o[1]-(n.coords[1]+n.height)),this.currentAction.to=n.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}w()})),r.attr("transform",i=>`translate(${i.coords[0]},${i.coords[1]})`).attr("opacity",i=>i.removed?.5:1),ae(r),r.filter(".resizable-x").select("line.left-resizer").attr("x1",_/2).attr("x2",_/2).attr("y1",0).attr("y2",i=>i.height),r.filter(".resizable-y").select("line.top-resizer").attr("x1",0).attr("x2",i=>i.width).attr("y1",_/2).attr("y2",_/2),r.filter(".resizable-x").select("line.right-resizer").attr("x1",i=>i.width-_/2).attr("x2",i=>i.width-_/2).attr("y1",0).attr("y2",i=>i.height),r.filter(".resizable-y").select("line.bottom-resizer").attr("x1",0).attr("x2",i=>i.width).attr("y1",i=>i.height-_/2).attr("y2",i=>i.height-_/2)}updateSectionsInView(...t){let e=this.selectCanvasElements().selectAll("g.diagram-section").data(this.model.sections.filter(i=>this.priorityThreshold!==void 0?i.getPriority()>=this.priorityThreshold:!0),i=>i.id);const a=e.exit(),l=e.enter().append("g").attr("id",i=>i.id).attr("class",i=>`diagram-section${i.getResizableX()?" resizable-x":""}${i.getResizableY()?" resizable-y":""} ${i.look?.lookType}`);t&&t.length>0&&(e=e.filter(i=>t.includes(i.id)));const r=l.merge(e);a.remove(),l.on(S.MouseOver,(i,n)=>{this.dragging||(this.userHighlight.focusOn(n),this.diagramEvent$.next(new Q(n)))}).on(S.Click,(i,n)=>{if(!i.ctrlKey&&!i.shiftKey){const d=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new H(d,!1))}const o=dt(n);this.userSelection.toggle(o),this.diagramEvent$.next(new H([o],o.selected))}).on(S.ContextMenu,(i,n)=>{if(this.dragging){i.preventDefault(),i.stopPropagation(),this.dragging=!1;return}const o=new pt(i,n);if(this.diagramEvent$.next(o),!o.defaultPrevented&&this.canUserPerformAction(k.ContextMenu)){i.preventDefault();const d=dt(n);this.userHighlight.focusOn(d),this.diagramEvent$.next(new Q(d)),this.userSelection.add(d),this.diagramEvent$.next(new H([d],!0)),this.contextMenu.open(i)}}).on(S.DoubleClick,(i,n)=>{const o=new ut(i,n);this.diagramEvent$.next(o)}).call(A.drag().filter(i=>(this.secondaryButton=mt(i),!0)).on($.Start,(i,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.startMultipleSelection(i);else{const o=n?.node;o?this.startMovingNode(i,o):w(L.NotAllowed)}}).on($.Drag,(i,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(i);else{const o=n?.node;o?this.continueMovingNode(i,o):w(L.NotAllowed)}}).on($.End,(i,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(i);else{const o=n?.node;o?this.finishMovingNode(i,o):w()}this.secondaryButton=!1})),re(l),l.filter(".resizable-x").append("line").attr("class","left-resizer").attr("stroke","transparent").attr("stroke-width",`${_}px`).on(S.MouseOver,(i,n)=>{this.canUserPerformAction(k.StretchSection)&&n.getResizableX()&&!n.removed&&w(L.EWResize)}).on(S.MouseOut,(i,n)=>{this.canUserPerformAction(k.StretchSection)&&n.getResizableX()&&!n.removed&&w()}).call(A.drag().on($.Start,(i,n)=>{this.canUserPerformAction(k.StretchSection)&&n.getResizableX()&&!n.removed&&n.node?(w(L.EWResize),this.currentAction=new X(this,k.StretchSection,n.node.id,n.node.getGeometry(),n.node.getGeometry())):w(L.NotAllowed)}).on($.Drag,(i,n)=>{if(this.canUserPerformAction(k.StretchSection)&&n.getResizableX()&&!n.removed&&n.node){const o=this.getPointerLocationRelativeToCanvas(i);n.node.stretchSections(f.Left,n.coords[0]-o[0],n.indexXInNode,n.indexYInNode)}}).on($.End,(i,n)=>{if(this.canUserPerformAction(k.StretchSection)&&n.getResizableX()&&!n.removed&&this.currentAction instanceof X&&this.currentAction.intent===k.StretchSection&&n.node){let o=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(o=this.getClosestGridPoint(o)),n.node.stretchSections(f.Left,n.coords[0]-o[0],n.indexXInNode,n.indexYInNode),this.currentAction.to=n.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}w()})),l.filter(".resizable-y").append("line").attr("class","top-resizer").attr("stroke","transparent").attr("stroke-width",`${_}px`).on(S.MouseOver,(i,n)=>{this.canUserPerformAction(k.StretchSection)&&n.getResizableY()&&!n.removed&&w(L.NSResize)}).on(S.MouseOut,(i,n)=>{this.canUserPerformAction(k.StretchSection)&&n.getResizableY()&&!n.removed&&w()}).call(A.drag().on($.Start,(i,n)=>{this.canUserPerformAction(k.StretchSection)&&n.getResizableY()&&!n.removed&&n.node?(w(L.NSResize),this.currentAction=new X(this,k.StretchSection,n.node.id,n.node.getGeometry(),n.node.getGeometry())):w(L.NotAllowed)}).on($.Drag,(i,n)=>{if(this.canUserPerformAction(k.StretchSection)&&n.getResizableY()&&!n.removed&&n.node){const o=this.getPointerLocationRelativeToCanvas(i);n.node.stretchSections(f.Top,n.coords[1]-o[1],n.indexXInNode,n.indexYInNode)}}).on($.End,(i,n)=>{if(this.canUserPerformAction(k.StretchSection)&&n.getResizableY()&&!n.removed&&this.currentAction instanceof X&&this.currentAction.intent===k.StretchSection&&n.node){let o=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(o=this.getClosestGridPoint(o)),n.node.stretchSections(f.Top,n.coords[1]-o[1],n.indexXInNode,n.indexYInNode),this.currentAction.to=n.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}w()})),l.filter(".resizable-x").append("line").attr("class","right-resizer").attr("stroke","transparent").attr("stroke-width",`${_}px`).on(S.MouseOver,(i,n)=>{this.canUserPerformAction(k.StretchSection)&&n.getResizableX()&&!n.removed&&w(L.EWResize)}).on(S.MouseOut,(i,n)=>{this.canUserPerformAction(k.StretchSection)&&n.getResizableX()&&!n.removed&&w()}).call(A.drag().on($.Start,(i,n)=>{this.canUserPerformAction(k.StretchSection)&&n.getResizableX()&&!n.removed&&n.node?(w(L.EWResize),this.currentAction=new X(this,k.StretchSection,n.node.id,n.node.getGeometry(),n.node.getGeometry())):w(L.NotAllowed)}).on($.Drag,(i,n)=>{if(this.canUserPerformAction(k.StretchSection)&&n.getResizableX()&&!n.removed&&n.node){const o=this.getPointerLocationRelativeToCanvas(i);n.node.stretchSections(f.Right,o[0]-(n.coords[0]+n.width),n.indexXInNode,n.indexYInNode)}}).on($.End,(i,n)=>{if(this.canUserPerformAction(k.StretchSection)&&n.getResizableX()&&!n.removed&&this.currentAction instanceof X&&this.currentAction.intent===k.StretchSection&&n.node){let o=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(o=this.getClosestGridPoint(o)),n.node.stretchSections(f.Right,o[0]-(n.coords[0]+n.width),n.indexXInNode,n.indexYInNode),this.currentAction.to=n.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}w()})),l.filter(".resizable-y").append("line").attr("class","bottom-resizer").attr("stroke","transparent").attr("stroke-width",`${_}px`).on(S.MouseOver,(i,n)=>{this.canUserPerformAction(k.StretchSection)&&n.getResizableY()&&!n.removed&&w(L.NSResize)}).on(S.MouseOut,(i,n)=>{this.canUserPerformAction(k.StretchSection)&&n.getResizableY()&&!n.removed&&w()}).call(A.drag().on($.Start,(i,n)=>{this.canUserPerformAction(k.StretchSection)&&n.getResizableY()&&!n.removed&&n.node?(w(L.NSResize),this.currentAction=new X(this,k.StretchSection,n.node.id,n.node.getGeometry(),n.node.getGeometry())):w(L.NotAllowed)}).on($.Drag,(i,n)=>{if(this.canUserPerformAction(k.StretchSection)&&n.getResizableY()&&!n.removed&&n.node){const o=this.getPointerLocationRelativeToCanvas(i);n.node.stretchSections(f.Bottom,o[1]-(n.coords[1]+n.height),n.indexXInNode,n.indexYInNode)}}).on($.End,(i,n)=>{if(this.canUserPerformAction(k.StretchSection)&&n.getResizableY()&&!n.removed&&this.currentAction instanceof X&&this.currentAction.intent===k.StretchSection&&n.node){let o=this.getPointerLocationRelativeToCanvas(i);this.snapToGrid&&(o=this.getClosestGridPoint(o)),n.node.stretchSections(f.Bottom,o[1]-(n.coords[1]+n.height),n.indexXInNode,n.indexYInNode),this.currentAction.to=n.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}w()})),r.attr("transform",i=>`translate(${i.coords[0]},${i.coords[1]})`).attr("opacity",i=>i.removed?.5:1),ae(r),r.filter(".resizable-x").select("line.left-resizer").attr("x1",_/2).attr("x2",_/2).attr("y1",0).attr("y2",i=>i.height),r.filter(".resizable-y").select("line.top-resizer").attr("x1",0).attr("x2",i=>i.width).attr("y1",_/2).attr("y2",_/2),r.filter(".resizable-x").select("line.right-resizer").attr("x1",i=>i.width-_/2).attr("x2",i=>i.width-_/2).attr("y1",0).attr("y2",i=>i.height),r.filter(".resizable-y").select("line.bottom-resizer").attr("x1",0).attr("x2",i=>i.width).attr("y1",i=>i.height-_/2).attr("y2",i=>i.height-_/2)}updatePortsInView(...t){let e=this.selectCanvasElements().selectAll("g.diagram-port").data(this.model.ports.filter(i=>this.priorityThreshold!==void 0?i.getPriority()>=this.priorityThreshold:!0),i=>i.id);const a=e.exit(),l=e.enter().append("g").attr("id",i=>i.id).attr("class",i=>`diagram-port ${i.look.lookType}`);t&&t.length>0&&(e=e.filter(i=>t.includes(i.id)));const r=l.merge(e);a.remove(),l.on(S.MouseOver,(i,n)=>{!this.unfinishedConnection&&!this.dragging&&(this.userHighlight.focusOn(n),this.diagramEvent$.next(new Q(n))),this.unfinishedConnection&&(this.unfinishedConnection.type.canStartFromType(this.unfinishedConnection.start?.getNode()?.type?.id||"")&&this.unfinishedConnection.start?.allowsOutgoing&&this.unfinishedConnection.type.canFinishOnType(n.getNode()?.type?.id||"")&&n.allowsIncoming||this.unfinishedConnection.type.canStartFromType(n.getNode()?.type?.id||"")&&n.allowsOutgoing&&this.unfinishedConnection.type.canFinishOnType(this.unfinishedConnection.start?.getNode()?.type?.id||"")&&this.unfinishedConnection.start?.allowsIncoming||w(L.NoDrop))}).on(S.MouseOut,()=>{this.unfinishedConnection&&w(L.Grabbing)}).on(S.Click,(i,n)=>{if(!i.ctrlKey&&!i.shiftKey){const d=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new H(d,!1))}const o=dt(n);this.userSelection.toggle(o),this.diagramEvent$.next(new H([o],o.selected))}).on(S.ContextMenu,(i,n)=>{if(this.dragging){i.preventDefault(),i.stopPropagation(),this.dragging=!1;return}const o=new pt(i,n);if(this.diagramEvent$.next(o),!o.defaultPrevented&&this.canUserPerformAction(k.ContextMenu)){i.preventDefault();const d=dt(n);this.userHighlight.focusOn(d),this.diagramEvent$.next(new Q(d)),this.userSelection.add(d),this.diagramEvent$.next(new H([d],!0)),this.contextMenu.open(i)}}).on(S.DoubleClick,(i,n)=>{const o=new ut(i,n);this.diagramEvent$.next(o)}).call(A.drag().filter(i=>(this.secondaryButton=mt(i),!0)).on($.Start,(i,n)=>{this.multipleSelectionOn||this.secondaryButton?this.startMultipleSelection(i):this.canUserPerformAction(k.AddConnection)&&(this.allowSharingPorts||n.incomingConnections.filter(o=>!o.removed).length===0&&n.outgoingConnections.filter(o=>!o.removed).length===0)&&!n.removed?(w(L.Grabbing),this.startConnection(n),this.unfinishedConnection&&(this.unfinishedConnectionTracer=this.selectCanvasElements().append("path").attr("stroke","none").attr("fill","none"))):w(L.NotAllowed)}).on($.Drag,(i,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(i);else if(this.canUserPerformAction(k.AddConnection)&&!n.removed&&this.unfinishedConnection!==void 0){const o=[i.x,i.y];this.unfinishedConnectionTracer?.attr("d",ne(this.unfinishedConnection.look.shape||ot.look.shape,this.unfinishedConnection.startCoords,o,this.unfinishedConnection.startDirection,this.unfinishedConnection.endDirection,this.unfinishedConnection.type.defaultLook.thickness||ot.look.thickness,this.unfinishedConnection.type.defaultStartMarkerLook?.width,this.unfinishedConnection.type.defaultEndMarkerLook?.width));const d=this.unfinishedConnectionTracer?.node();if(d){let c=2;const h=d.getTotalLength();h<c&&(c=0);const u=d.getPointAtLength(h-c);this.unfinishedConnection.endCoords=[u.x,u.y]}else this.unfinishedConnection.endCoords=o;if(this.updateConnectionsInView(le),this.model.ports.length>0){const c=this.getPointerLocationRelativeToCanvas(i);let h=Number.POSITIVE_INFINITY,u;for(const b of this.model.ports){const m=b.distanceTo(c);m<h&&(h=m,u=b)}u&&h<this.portHighlightRadius?this.userHighlight.focusOn(u):this.userHighlight.clear()}}}).on($.End,(i,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(i);else{if(this.canUserPerformAction(k.AddConnection)&&!n.removed){this.unfinishedConnectionTracer?.remove();const o=this.userHighlight.getFocus();if(o instanceof yt)this.finishConnection(o);else if(o instanceof ct&&o.rootElement instanceof yt)this.finishConnection(o.rootElement);else if(o instanceof z||o instanceof U||o instanceof ct){let d;if(o instanceof z||o instanceof U)d=o;else if(o.rootElement instanceof z||o.rootElement instanceof U)d=o.rootElement;else{this.dropConnection();return}const c=d.getClosestPortToPoint([i.x,i.y]);c!==void 0?this.finishConnection(c):this.dropConnection()}else this.dropConnection()}w()}this.secondaryButton=!1})),l.filter(".image-look").append("image"),re(l),r.attr("transform",i=>`translate(${i.coords[0]-i.width/2},${i.coords[1]-i.width/2})`).attr("opacity",i=>i.removed?.5:1),ae(r)}updateConnectionsInView(...t){const e=this.model.connections.filter(n=>this.priorityThreshold!==void 0?n.getPriority()>=this.priorityThreshold:!0);this.unfinishedConnection&&e.push(this.unfinishedConnection);let a=this.selectCanvasElements().selectAll("g.diagram-connection").data(e,n=>n.id);const l=a.exit(),r=a.enter().append("g").attr("id",n=>n.id).attr("class","diagram-connection");t&&t.length>0&&(a=a.filter(n=>t.includes(n.id)));const i=r.merge(a);l.remove(),r.on(S.MouseOver,(n,o)=>{o.end!==void 0&&!this.dragging&&(this.userHighlight.focusOn(o),this.diagramEvent$.next(new Q(o)))}).on(S.Click,(n,o)=>{if(!n.ctrlKey&&!n.shiftKey){const d=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new H(d,!1))}this.userSelection.toggle(o),this.diagramEvent$.next(new H([o],o.selected))}).on(S.ContextMenu,(n,o)=>{if(this.dragging){n.preventDefault(),n.stopPropagation(),this.dragging=!1;return}const d=new pt(n,o);this.diagramEvent$.next(d),!d.defaultPrevented&&this.canUserPerformAction(k.ContextMenu)&&(n.preventDefault(),this.userHighlight.focusOn(o),this.diagramEvent$.next(new Q(o)),this.userSelection.add(o),this.diagramEvent$.next(new H([o],!0)),this.contextMenu.open(n))}).on(S.DoubleClick,(n,o)=>{const d=new ut(n,o);this.diagramEvent$.next(d)}).call(A.drag().filter(n=>(this.secondaryButton=mt(n),!0)).on($.Start,n=>{this.startMultipleSelection(n)}).on($.Drag,n=>{this.continueMultipleSelection(n)}).on($.End,n=>{this.finishMultipleSelection(n)})),r.append("path").attr("class","diagram-connection-path"),r.append("path").attr("class","diagram-connection-path-box"),r.append("marker").attr("id",n=>`${n.id}-start-marker`).attr("class","diagram-connection-start-marker").append("image").attr("preserveAspectRatio","none"),r.append("marker").attr("id",n=>`${n.id}-end-marker`).attr("class","diagram-connection-end-marker").append("image").attr("preserveAspectRatio","none"),r.append("g").attr("class","diagram-connection-start-label"),r.select("g.diagram-connection-start-label").append("path"),r.select("g.diagram-connection-start-label").append("text").style("user-select","none"),r.append("g").attr("class","diagram-connection-middle-label"),r.select("g.diagram-connection-middle-label").append("path"),r.select("g.diagram-connection-middle-label").append("text").style("user-select","none"),r.append("g").attr("class","diagram-connection-end-label"),r.select("g.diagram-connection-end-label").append("path"),r.select("g.diagram-connection-end-label").append("text").style("user-select","none"),i.attr("opacity",n=>n.removed?.5:1).select("path.diagram-connection-path").attr("d",n=>ne(n.look.shape||ot.look.shape,n.startCoords,n.endCoords,n.startDirection,n.endDirection,n.type.defaultLook.thickness||ot.look.thickness,n.type.defaultStartMarkerLook?.width,n.type.defaultEndMarkerLook?.width)).attr("marker-start",n=>`url(#${n.id}-start-marker)`).attr("marker-end",n=>`url(#${n.id}-end-marker)`).attr("stroke",n=>n.look.color||ot.look.color).attr("stroke-width",n=>`${n.look.thickness}px`).attr("stroke-dasharray",n=>he(n.look.style||ot.look.style,n.type.defaultLook.thickness||ot.look.thickness)).attr("fill","none"),i.select("path.diagram-connection-path-box").attr("d",n=>ne(n.look.shape||ot.look.shape,n.startCoords,n.endCoords,n.startDirection,n.endDirection,n.type.defaultLook.thickness||ot.look.thickness,n.type.defaultStartMarkerLook?.width,n.type.defaultEndMarkerLook?.width)).attr("stroke","transparent").attr("pointer-events","stroke").attr("stroke-width",n=>`${(n.look.thickness||ot.look.thickness)+ni}px`).attr("stroke-dasharray",n=>he(n.look.style||ot.look.style,n.type.defaultLook.thickness||ot.look.thickness)).attr("fill","none"),i.data().forEach(n=>{this.updateConnectionLabelsInView(n),this.updateConnectionMarkersInView(n)})}updateFieldsInView(...t){let e=this.selectCanvasElements().selectAll("foreignObject.diagram-field").data(this.model.fields.filter(i=>this.priorityThreshold!==void 0?i.getPriority()>=this.priorityThreshold:!0),i=>i.id);const a=e.exit(),l=e.enter().append("foreignObject").attr("id",i=>i.id).attr("class","diagram-field");t&&t.length>0&&(e=e.filter(i=>t.includes(i.id)));const r=l.merge(e);if(a.remove(),l.style("box-sizing","border-box").on(S.MouseOver,(i,n)=>{this.dragging||(this.userHighlight.focusOn(n),this.diagramEvent$.next(new Q(n)))}).on(S.Click,(i,n)=>{if(!i.ctrlKey&&!i.shiftKey){const d=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new H(d,!1))}const o=dt(n);this.userSelection.toggle(o),this.diagramEvent$.next(new H([o],o.selected))}).on(S.ContextMenu,(i,n)=>{if(this.dragging){i.preventDefault(),i.stopPropagation(),this.dragging=!1;return}const o=new pt(i,n);if(this.diagramEvent$.next(o),!o.defaultPrevented&&this.canUserPerformAction(k.ContextMenu)){i.preventDefault();const d=dt(n);this.userHighlight.focusOn(d),this.diagramEvent$.next(new Q(d)),this.userSelection.add(d),this.diagramEvent$.next(new H([d],!0)),this.contextMenu.open(i)}}).on(S.DoubleClick,(i,n)=>{const o=new ut(i,n);this.diagramEvent$.next(o),!o.defaultPrevented&&this.canUserPerformAction(k.EditField)&&n.editable&&!n.removed&&(this.currentAction=new Ee(this,n.id,n.text,""),this.createInputField(n.text,n.coords,n.width,n.height,n.fontSize,n.fontFamily||O.fontFamily,n.orientation,()=>{},d=>{n.text=d,this.currentAction instanceof Ee&&(this.currentAction.to=d,this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0)}))}).call(A.drag().filter(i=>(this.secondaryButton=mt(i),!0)).on($.Start,(i,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.startMultipleSelection(i);else{let o;n.rootElement instanceof z?o=n.rootElement:n.rootElement instanceof U&&(o=n.rootElement.node),o?this.startMovingNode(i,o):w(L.NotAllowed)}}).on($.Drag,(i,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(i);else{let o;n.rootElement instanceof z?o=n.rootElement:n.rootElement instanceof U&&(o=n.rootElement.node),o?this.continueMovingNode(i,o):w(L.NotAllowed)}}).on($.End,(i,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(i);else{let o;n.rootElement instanceof z?o=n.rootElement:n.rootElement instanceof U&&(o=n.rootElement.node),o?this.finishMovingNode(i,o):w()}this.secondaryButton=!1})).append("xhtml:div").style("width","100%").style("height","100%").style("display","flex").append("xhtml:p").style("box-sizing","border-box").style("outline",0).style("margin",0).style("border",0).style("padding",0).style("user-select","none").style("font-kerning","none").style("white-space","nowrap"),r.attr("x",0).attr("y",0).attr("width",i=>`${i.width}px`).attr("height",i=>`${i.height}px`).attr("transform",i=>`translate(${i.coords[0]},${i.coords[1]})`).attr("opacity",i=>i.removed?.5:1).select("div").style("justify-content",i=>i.horizontalAlign===Lt.Center?"center":i.horizontalAlign===Lt.Right?"flex-end":"flex-start").style("align-items",i=>i.verticalAlign===Xt.Center?"center":i.verticalAlign===Xt.Bottom?"end":"start").select("p").style("max-width",i=>i.fit?"default":`${Te(i.width,i.height,i.orientation)[0]}px`).style("max-height",i=>i.fit?"default":`${Te(i.width,i.height,i.orientation)[1]}px`).style("overflow",i=>i.fit?"default":"clip").style("text-overflow",i=>i.fit?"default":"ellipsis").style("text-align",i=>i.horizontalAlign===Lt.Center?"center":i.horizontalAlign===Lt.Right?"end":"start").style("transform",i=>`rotate(${i.orientation}deg)`).style("font-size",i=>`${i.fontSize}px`).style("font-family",i=>i.fontFamily||"'Wonder Unit Sans', sans-serif").style("font-weight",i=>i.highlighted?600:400).style("color",i=>i.selected?i.selectedColor||"#000000":i.color||"#000000").html(i=>i.text.replace(/</g,"<").replace(/>/g,">").replace(/\n/g,"<br/>")),Ne){const i=this.zoomTransform.k;r.attr("width",n=>`${n.width*i}px`).attr("height",n=>`${n.height*i}px`).select("div").style("position","absolute").style("left",n=>`${n.coords[0]*i+this.zoomTransform.x}px`).style("top",n=>`${n.coords[1]*i+this.zoomTransform.y}px`).select("p").style("font-size",n=>`${n.fontSize*i}px`)}}updateObjectsInView(...t){let e=this.selectCanvasElements().selectAll("g.diagram-object").data(this.model.objects.filter(i=>this.priorityThreshold!==void 0?i.getPriority()>=this.priorityThreshold:!0),i=>i.id);const a=e.exit(),l=e.enter().append("g").attr("id",i=>i.id).attr("class","diagram-object");t&&t.length>0&&(e=e.filter(i=>t.includes(i.id))),l.merge(e).attr("width",i=>`${i.width}px`).attr("height",i=>`${i.height}px`).attr("transform",i=>`translate(${i.coords[0]},${i.coords[1]})`).html(i=>i.html),a.remove(),l.on(S.ContextMenu,(i,n)=>{if(this.dragging){i.preventDefault(),i.stopPropagation(),this.dragging=!1;return}const o=new pt(i,n);this.diagramEvent$.next(o),!o.defaultPrevented&&this.canUserPerformAction(k.ContextMenu)&&(i.preventDefault(),this.contextMenu.open(i))}).on(S.DoubleClick,(i,n)=>{const o=new ut(i,n);this.diagramEvent$.next(o)}).call(A.drag().filter(i=>(this.secondaryButton=mt(i),!0)).on($.Start,i=>{(this.multipleSelectionOn||this.secondaryButton)&&this.startMultipleSelection(i)}).on($.Drag,i=>{(this.multipleSelectionOn||this.secondaryButton)&&this.continueMultipleSelection(i)}).on($.End,i=>{(this.multipleSelectionOn||this.secondaryButton)&&this.finishMultipleSelection(i)}))}updateDecoratorsInView(...t){let e=this.selectCanvasElements().selectAll("g.diagram-decorator").data(this.model.decorators.filter(i=>this.priorityThreshold!==void 0?i.getPriority()>=this.priorityThreshold:!0),i=>i.id);const a=e.exit(),l=e.enter().append("g").attr("id",i=>i.id).attr("class","diagram-decorator");t&&t.length>0&&(e=e.filter(i=>t.includes(i.id))),l.merge(e).attr("width",i=>`${i.width}px`).attr("height",i=>`${i.height}px`).attr("transform",i=>`translate(${i.coords[0]},${i.coords[1]})`).html(i=>i.html),a.remove(),l.on(S.MouseOver,(i,n)=>{this.dragging||(this.userHighlight.focusOn(n),this.diagramEvent$.next(new Q(n)))}).on(S.Click,(i,n)=>{if(!i.ctrlKey&&!i.shiftKey){const o=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new H(o,!1))}if(n.rootElement){const o=dt(n.rootElement);this.userSelection.toggle(o),this.diagramEvent$.next(new H([o],o.selected))}}).on(S.ContextMenu,(i,n)=>{if(this.dragging){i.preventDefault(),i.stopPropagation(),this.dragging=!1;return}const o=new pt(i,n);if(this.diagramEvent$.next(o),!o.defaultPrevented&&this.canUserPerformAction(k.ContextMenu)&&n.rootElement){i.preventDefault();const d=dt(n.rootElement);this.userHighlight.focusOn(d),this.diagramEvent$.next(new Q(d)),this.userSelection.add(d),this.diagramEvent$.next(new H([d],!0)),this.contextMenu.open(i)}}).on(S.DoubleClick,(i,n)=>{const o=new ut(i,n);this.diagramEvent$.next(o)}).call(A.drag().filter(i=>(this.secondaryButton=mt(i),!0)).on($.Start,(i,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.startMultipleSelection(i);else{let o;n.rootElement instanceof z?o=n.rootElement:n.rootElement instanceof U&&(o=n.rootElement.node),o?this.startMovingNode(i,o):w(L.NotAllowed)}}).on($.Drag,(i,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(i);else{let o;n.rootElement instanceof z?o=n.rootElement:n.rootElement instanceof U&&(o=n.rootElement.node),o?this.continueMovingNode(i,o):w(L.NotAllowed)}}).on($.End,(i,n)=>{if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(i);else{let o;n.rootElement instanceof z?o=n.rootElement:n.rootElement instanceof U&&(o=n.rootElement.node),o?this.finishMovingNode(i,o):w()}this.secondaryButton=!1}))}updateConnectionLabelsInView(t){const e=this.selectCanvasView().select(`[id='${ce(t.id)}']`),l=e.select("path").node(),r={...O,...t.type.label};if(l){const i=l.getTotalLength();let n=0,o=0,d=0,c=0,h=0,u=0;if(r.backgroundColor==="#00000000"){const g=t.endCoords[0]-t.startCoords[0],v=t.endCoords[1]-t.startCoords[1];switch(t.startDirection){case f.Top:n=g>=0?-.5:.5,h=n;break;case f.Bottom:n=g>=0?-.5:.5,h=n;break;case f.Left:o=v>0?-.5:.5,u=o;break;case f.Right:o=v>0?-.5:.5,u=o;break;default:n=.5,h=n,o=-.5,u=o}switch(t.endDirection){case f.Top:h=g>=0?.5:-.5;break;case f.Bottom:h=g>=0?.5:-.5;break;case f.Left:u=v>0?.5:-.5;break;case f.Right:u=v>0?.5:-.5;break;default:h=.5,u=-.5}Math.abs(g)>=Math.abs(v)?(d=g>0?-.5:.5,c=v>0?.5:-.5):(d=g>0?.5:-.5,c=v>0?-.5:.5)}e.select("g.diagram-connection-start-label text").attr("x",0).attr("y",r.fontSize/3).attr("text-anchor","middle").attr("font-family",r.fontFamily).attr("font-size",r.fontSize).attr("fill",t.selected?r.selectedColor:r.color).style("font-kerning","none").text(t.startLabel);const b=e.select("g.diagram-connection-start-label text").node()?.getBoundingClientRect();if(b){const g=t.startLabel?b.width/this.zoomTransform.k+Ot(r)+_t(r):0,v=t.startLabel?b.height/this.zoomTransform.k+Ht(r)+Vt(r):0;let y;switch(t.startDirection){case f.Left:y=l.getPointAtLength(it(r)+g/2);break;case f.Right:y=l.getPointAtLength(D(r)+g/2);break;case f.Top:y=l.getPointAtLength(q(r)+g/2);break;case f.Bottom:y=l.getPointAtLength(G(r)+g/2);break;default:y=l.getPointAtLength(Math.max(D(r)+g/2,it(r)+g/2,G(r)+v/2,q(r)+v/2))}e.select("g.diagram-connection-start-label path").attr("d",Yt(-g/2,-v/2,g,v)).attr("fill",r.backgroundColor).attr("stroke","none"),e.select("g.diagram-connection-start-label").attr("transform",`translate(${y.x+n*g},${y.y+o*v})`)}e.select("g.diagram-connection-middle-label text").attr("x",0).attr("y",r.fontSize/3).attr("text-anchor","middle").attr("font-family",r.fontFamily).attr("font-size",r.fontSize).attr("fill",t.selected?r.selectedColor:r.color).style("font-kerning","none").text(t.middleLabel);const m=e.select("g.diagram-connection-middle-label text").node()?.getBoundingClientRect();if(m){const g=t.middleLabel?m.width/this.zoomTransform.k+Ot(r)+_t(r):0,v=t.middleLabel?m.height/this.zoomTransform.k+Ht(r)+Vt(r):0,y=l.getPointAtLength(i/2);e.select("g.diagram-connection-middle-label path").attr("d",Yt(-g/2,-v/2,g,v)).attr("fill",r.backgroundColor).attr("stroke","none"),e.select("g.diagram-connection-middle-label").attr("transform",`translate(${y.x+d*g},${y.y+c*v})`)}e.select("g.diagram-connection-end-label text").attr("x",0).attr("y",r.fontSize/3).attr("text-anchor","middle").attr("font-family",r.fontFamily).attr("font-size",r.fontSize).attr("fill",t.selected?r.selectedColor:r.color).style("font-kerning","none").text(t.endLabel);const x=e.select("g.diagram-connection-end-label text").node()?.getBoundingClientRect();if(x){const g=t.endLabel?x.width/this.zoomTransform.k+Ot(r)+_t(r):0,v=t.endLabel?x.height/this.zoomTransform.k+Ht(r)+Vt(r):0;let y;switch(t.endDirection){case f.Left:y=l.getPointAtLength(i-(it(r)+g/2));break;case f.Right:y=l.getPointAtLength(i-(D(r)+g/2));break;case f.Top:y=l.getPointAtLength(i-(q(r)+g/2));break;case f.Bottom:y=l.getPointAtLength(i-(G(r)+g/2));break;default:y=l.getPointAtLength(i-Math.max(D(r)+g/2,it(r)+g/2,G(r)+v/2,q(r)+v/2))}e.select("g.diagram-connection-end-label path").attr("d",Yt(-g/2,-v/2,g,v)).attr("fill",r.backgroundColor).attr("stroke","none"),e.select("g.diagram-connection-end-label").attr("transform",`translate(${y.x+h*g},${y.y+u*v})`)}}}updateConnectionMarkersInView(t){const e=this.selectCanvasView().select(`[id='${ce(t.id)}']`),a=e.select("marker.diagram-connection-start-marker"),l=e.select("marker.diagram-connection-end-marker");t.startMarkerLook!==null?a.attr("orient","auto-start-reverse").attr("markerWidth",t.startMarkerLook.width).attr("markerHeight",t.startMarkerLook.height).attr("refX",t.startMarkerLook.refX).attr("refY",t.startMarkerLook.refY).select("image").attr("href",t.startMarkerLook.image).attr("width",t.startMarkerLook.width).attr("height",t.startMarkerLook.height):a.attr("orient","auto-start-reverse").attr("markerWidth",0).attr("markerHeight",0),t.endMarkerLook!==null?l.attr("orient","auto-start-reverse").attr("markerWidth",t.endMarkerLook.width).attr("markerHeight",t.endMarkerLook.height).attr("refX",t.endMarkerLook.refX).attr("refY",t.endMarkerLook.refY).select("image").attr("href",t.endMarkerLook.image).attr("width",t.endMarkerLook.width).attr("height",t.endMarkerLook.height):l.attr("orient","auto-start-reverse").attr("markerWidth",0).attr("markerHeight",0)}fieldRootFitsInView(t){const e=this.model.fields.get(t);if(!e)return!1;if(e.rootElement instanceof z||e.rootElement instanceof U){const a=this.minimumSizeOfField(e),l=a[0]+D(e.rootElement.type?.label)+it(e.rootElement.type?.label)-e.rootElement.width,r=a[1]+G(e.rootElement.type?.label)+q(e.rootElement.type?.label)-e.rootElement.height;return l<=0&&r<=0}return!0}fitFieldRootInView(t,e=!0){const a=this.model.fields.get(t);if(a){if(a.rootElement instanceof z){const l=this.minimumSizeOfField(a);let r=l[0]+D(a.rootElement.type.label)+it(a.rootElement.type.label)-a.rootElement.width,i=l[1]+G(a.rootElement.type.label)+q(a.rootElement.type.label)-a.rootElement.height;this.snapToGrid&&(r=Math.ceil(r/this.gridSize)*this.gridSize,i=Math.ceil(i/this.gridSize)*this.gridSize),a.rootElement.width+r<a.rootElement.type.minWidth&&(r=a.rootElement.type.minWidth-a.rootElement.width),a.rootElement.height+i<a.rootElement.type.minHeight&&(i=a.rootElement.type.minHeight-a.rootElement.height),(e!==!1||r>0)&&a.rootElement.stretch(f.Right,r),(e!==!1||i>0)&&a.rootElement.stretch(f.Bottom,i)}if(a.rootElement instanceof U){const l=this.minimumSizeOfField(a);let r=l[0],i=l[1];for(const c of a.rootElement.node?.sections||[])c.label&&(c.indexXInNode===a.rootElement.indexXInNode&&c.indexYInNode!==a.rootElement.indexYInNode?r=Math.max(r,this.minimumSizeOfField(c.label)[0]):c.indexXInNode!==a.rootElement.indexXInNode&&c.indexYInNode===a.rootElement.indexYInNode&&(i=Math.max(i,this.minimumSizeOfField(c.label)[1])));l[0]<r&&(l[0]=r),l[1]<i&&(l[1]=i);const n=a.rootElement.type;let o=l[0]+D(n?.label)+it(n?.label)-a.rootElement.width,d=l[1]+G(n?.label)+q(n?.label)-a.rootElement.height;this.snapToGrid&&(o=Math.ceil(o/this.gridSize)*this.gridSize,d=Math.ceil(d/this.gridSize)*this.gridSize),a.rootElement.width+o<(a.rootElement.getMinWidth()||0)&&(o=(a.rootElement.getMinWidth()||0)-a.rootElement.width),a.rootElement.height+d<(a.rootElement.getMinHeight()||0)&&(d=(a.rootElement.getMinHeight()||0)-a.rootElement.height),(e||o>0)&&a.rootElement.node?.stretchSections(f.Right,o,a.rootElement.indexXInNode,a.rootElement.indexYInNode),(e||d>0)&&a.rootElement.node?.stretchSections(f.Bottom,d,a.rootElement.indexXInNode,a.rootElement.indexYInNode)}}}fitNodeInView(t,e=!0){const a=this.model.nodes.get(t);if(a&&a.sections.length>0&&this.priorityThreshold){let l=0,r=0;for(const i of a.sections)if(i.getPriority()>=this.priorityThreshold){const n=i.coords[0]+i.width-a.coords[0],o=i.coords[1]+i.height-a.coords[1];l=Math.max(l,n),r=Math.max(r,o)}l+=a.type.sectionGrid?.margin||0,r+=a.type.sectionGrid?.margin||0,(e||l>a.width)&&a.stretch(f.Right,l-a.width),(e||r>a.height)&&a.stretch(f.Bottom,r-a.height)}}selectRoot(){return A.select(this.diagramRoot)}selectSVGElement(){return A.select(this.diagramRoot).select("svg")}selectCanvasView(){return this.selectSVGElement().select(".daga-canvas-view")}selectCanvasElements(){return this.selectSVGElement().select(".daga-canvas-elements")}startConnection(t){if(t.allowsOutgoing||t.allowsIncoming){if(this.connectionType&&(this.connectionType.canStartFromType(t.getNode()?.type?.id||"")&&t.allowsOutgoing||this.connectionType.canFinishOnType(t.getNode()?.type?.id||"")&&t.allowsIncoming))this.unfinishedConnection=new lt(this.model,this.connectionType,t,void 0,le);else if(this.inferConnectionType){let e=this.model.connections.types.all().find(a=>t.allowsOutgoing&&a.canStartFromType(t.getNode()?.type?.id||""));e===void 0&&(e=this.model.connections.types.all().find(a=>t.allowsIncoming&&a.canFinishOnType(t.getNode()?.type?.id||""))),e!==void 0&&(this.unfinishedConnection=new lt(this.model,e,t,void 0,le))}}}finishConnection(t){if(this.userHighlight.clear(),this.unfinishedConnection!==void 0){if(!this.allowConnectionLoops&&this.unfinishedConnection.start===t){this.dropConnection();return}if(!this.allowSharingPorts&&(t.incomingConnections.filter(e=>!e.removed).length>0||t.outgoingConnections.filter(e=>!e.removed).length>0)){this.dropConnection();return}if(!this.allowSharingBothPorts&&this.model.connections.find(e=>!e.removed&&(e.start===this.unfinishedConnection?.start&&e.end===t||e.end===this.unfinishedConnection?.start&&e.start===t))!==void 0){this.dropConnection();return}if(this.unfinishedConnection.type.canStartFromType(this.unfinishedConnection?.start?.getNode()?.type?.id||"")&&this.unfinishedConnection?.start?.allowsOutgoing&&this.unfinishedConnection.type.canFinishOnType(t.getNode()?.type?.id||"")&&t.allowsIncoming){const e=new se(this,this.unfinishedConnection.type,this.unfinishedConnection.start?.id,t.id);this.dropConnection(),e.do(),this.actionStack.add(e)}else if(this.unfinishedConnection.type.canFinishOnType(this.unfinishedConnection?.start?.getNode()?.type?.id||"")&&this.unfinishedConnection?.start?.allowsIncoming&&this.unfinishedConnection.type.canStartFromType(t.getNode()?.type?.id||"")&&t.allowsOutgoing){const e=new se(this,this.unfinishedConnection.type,t.id,this.unfinishedConnection.start?.id);this.dropConnection(),e.do(),this.actionStack.add(e)}else if(this.inferConnectionType){let e=this.model.connections.types.all().find(l=>l.canStartFromType(this.unfinishedConnection?.start?.getNode()?.type?.id||"")&&this.unfinishedConnection?.start?.allowsOutgoing&&l.canFinishOnType(t.getNode()?.type?.id||"")&&t.allowsIncoming),a=!1;if(e===void 0&&(e=this.model.connections.types.all().find(l=>l.canFinishOnType(this.unfinishedConnection?.start?.getNode()?.type?.id||"")&&this.unfinishedConnection?.start?.allowsIncoming&&l.canStartFromType(t.getNode()?.type?.id||"")&&t.allowsOutgoing),a=!0),e!==void 0){const l=new se(this,e,a?t.id:this.unfinishedConnection.start?.id,a?this.unfinishedConnection.start?.id:t.id);this.dropConnection(),l.do(),this.actionStack.add(l)}else this.dropConnection()}else this.dropConnection()}}dropConnection(){this.unfinishedConnection?.setStart(void 0),this.unfinishedConnection?.setEnd(void 0),this.unfinishedConnection?.select()?.remove(),this.unfinishedConnection=void 0}cancelAllUserActions(){this.currentAction=void 0,this.dropConnection(),this.removeInputField(),this.contextMenu.close(),this.userSelection.clear()}canUserPerformAction(t){return this.userActions[t]!==!1}createInputField(t,e,a,l,r,i,n,o,d){this.removeInputField();const c=this.selectCanvasElements().append("foreignObject").attr("x",`${e[0]}px`).attr("y",`${e[1]}px`).attr("width",`${a}px`).attr("height",`${l}px`).style("box-sizing","border-box").style("border","1px solid");this.inputFieldContainer=c;const h=c.append("xhtml:textarea");let u,b;h.text(t).style("box-sizing","border-box").style("width",`${a}px`).style("height",`${l}px`).style("font-size",`${r}px`).style("font-family",i).style("resize","none").style("outline",0).style("border",0).style("margin",0).style("padding",0).on(S.KeyDown,x=>{x.stopPropagation()}).on(S.KeyUp,x=>{if(x.stopPropagation(),x.key===K.Escape){const g=h.property("value");this.removeInputField(),d&&d(g)}}).on(S.Input,()=>{const x=h.property("value");h.attr("cols",mo(x)+1),h.attr("rows",vo(x)+1),h.style("width",""),h.style("height",""),u=h.property("scrollWidth")+1,b=h.property("scrollHeight")+1;const g=Math.max(u,a),v=Math.max(b,l);c?.attr("width",`${g}px`),h.style("width",`${g}px`),c?.attr("height",`${v}px`),h.style("height",`${v}px`),o&&o(x)}).on(S.Click,x=>{x.stopPropagation()}).on(S.FocusOut,()=>{const x=h.property("value");this.removeInputField(),d&&d(x)});const m=h.node();m.focus(),m.select()}removeInputField(){this.inputFieldContainer?.select("input")?.on(S.Blur,null),this.inputFieldContainer?.remove(),this.inputFieldContainer=void 0}minimumSizeOfField(t){const e=t.select()?.select("p")?.node();if(!e)return[0,0];const a=e.getBoundingClientRect();return[a.width/this.zoomTransform.k,a.height/this.zoomTransform.k]}startMovingNode(t,e){if(this.canUserPerformAction(k.MoveNode)&&!e.removed)if(w(L.Grabbing),this.draggingFrom=[t.x,t.y],e.selected&&this.userSelection.count(a=>a instanceof z)>1)this.currentAction=new ie(this,this.userSelection.filter(a=>a instanceof z).map(a=>a.id),e.coords);else{const a=e.getLastAncestor();this.currentAction=new X(this,k.MoveNode,e.id,e.getGeometry(),e.getGeometry(),a?.id,a?.getGeometry(e.id),a?.getGeometry(e.id))}else w(L.NotAllowed)}continueMovingNode(t,e){if(this.canUserPerformAction(k.MoveNode)&&(this.currentAction instanceof ie||this.currentAction instanceof X)&&!e.removed){const a=[t.x-e.width/2,t.y-e.height/2];e.selected?this.userSelection.move([a[0]-e.coords[0],a[1]-e.coords[1]]):e.move(a),this.userHighlight.clear(),this.dragging=!0}}finishMovingNode(t,e){if(this.canUserPerformAction(k.MoveNode)&&!e.removed&&(this.draggingFrom[0]!==t.x||this.draggingFrom[1]!==t.y)){let a=[t.x-e.width/2,t.y-e.height/2];if(this.snapToGrid&&(a=this.getClosestGridPoint([a[0]-e.type.snapToGridOffset[0],a[1]-e.type.snapToGridOffset[1]]),a[0]+=e.type.snapToGridOffset[0],a[1]+=e.type.snapToGridOffset[1]),this.currentAction instanceof ie){const l=this.currentAction.delta;this.currentAction.delta=[a[0]-l[0],a[1]-l[1]],e.selected?this.userSelection.move([l[0]-e.coords[0],l[1]-e.coords[1]]):e.move(l)}else if(this.currentAction instanceof X){e.move(a);const r=this.model.nodes.getAtCoordinates(t.x,t.y).filter(o=>o.id!==e.id&&!o.isDescendantOf(e)).filter(o=>o.type.childrenTypes.includes(e.type.id)),i=Fe(r),n=i[i.length-1];if(n!==e.parent&&(e.type.canBeParentless||n!==void 0)){const o=n?.getLastAncestor(),d=this.currentAction.from,c=new Fo(this,e.id,e.parent?.id,n?.id,d,e.getGeometry(),o?.id,o?.getGeometry(e.id),o?.getGeometry(e.id));e.parent?.removeChild(e),n!==void 0&&n.addChild(e),c.toChildGeometry=e.getGeometry(e.id),c.toAncestorGeometry=o?.getGeometry(e.id),this.currentAction=c}else{const o=e?.getLastAncestor();this.currentAction.ancestorId=o?.id,this.currentAction.fromAncestorGeometry=o?.getGeometry(e.id),e.parent?.fitToChild(e),this.currentAction.to=e.getGeometry(e.id),this.currentAction.toAncestorGeometry=o?.getGeometry(e.id)}}this.currentAction!==void 0&&(this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0)}w(),this.dragging=!1}startMultipleSelection(t){this.draggingFrom=this.getPointerLocationRelativeToCanvas(t),this.multipleSelectionContainer=this.selectSVGElement().append("rect").attr("stroke","#0E74B6").attr("fill","rgba(14, 116, 182, 0.06)")}continueMultipleSelection(t){const e=this.getPointerLocationRelativeToCanvas(t);(this.draggingFrom[0]!==e[0]||this.draggingFrom[1]!==e[1])&&(w(L.Crosshair),this.multipleSelectionContainer?.attr("x",Math.min(this.draggingFrom[0],e[0])*this.zoomTransform.k+this.zoomTransform.x)?.attr("y",Math.min(this.draggingFrom[1],e[1])*this.zoomTransform.k+this.zoomTransform.y)?.attr("width",Math.abs(this.draggingFrom[0]-e[0])*this.zoomTransform.k)?.attr("height",Math.abs(this.draggingFrom[1]-e[1])*this.zoomTransform.k),this.dragging=!0)}finishMultipleSelection(t){const e=this.getPointerLocationRelativeToCanvas(t);this.multipleSelectionContainer?.remove(),this.multipleSelectionContainer=void 0,this.userSelection.clear();for(const a of this.model.nodes)no([a.coords,[a.coords[0]+a.width,a.coords[1]+a.height]],[this.draggingFrom,e])&&this.userSelection.add(a);this.multipleSelectionOn=!1,this.diagramEvent$.next(new H(this.userSelection.all(),!0)),w()}};Zt.canvasCount=0;let ue=Zt;class Ke{constructor(){this.grid=[[void 0]],this.offsetX=0,this.offsetY=0}minX(){return-this.offsetX}maxX(){return this.width()-1-this.offsetX}minY(){return-this.offsetY}maxY(){return this.height()-1-this.offsetY}width(){return this.grid[0].length}height(){return this.grid.length}addColumnLeft(){for(const t of this.grid)t.splice(0,0,void 0);this.offsetX=this.offsetX+1}addColumnRight(){for(const t of this.grid)t.push(void 0)}addRowTop(){const t=[];for(let e=0;e<this.grid[0].length;++e)t.push(void 0);this.grid.splice(0,0,t),this.offsetY=this.offsetY+1}addRowBottom(){const t=[];for(let e=0;e<this.grid[0].length;++e)t.push(void 0);this.grid.push(t)}get(t){if(this.grid[t[1]+this.offsetY])return this.grid[t[1]+this.offsetY][t[0]+this.offsetX]}set(t,e){for(;t[0]<-this.offsetX;)this.addColumnLeft();for(;t[0]>=this.width()-this.offsetX;)this.addColumnRight();for(;t[1]<-this.offsetY;)this.addRowTop();for(;t[1]>=this.height()-this.offsetY;)this.addRowBottom();this.grid[t[1]+this.offsetY][t[0]+this.offsetX]=e}getClosestEmptyCoordinate(t){if(this.get(t)===void 0)return t;const e=[...t];for(let a=1;;++a){const l=a%2>0?a:-a,r=l>0?1:-1,i=[e[0]+l,e[1]+l];for(let n=e[0];n!==i[0]+r;n+=r)if(e[0]=n,this.get(e)===void 0)return e;for(let n=e[1];n!==i[1]+r;n+=r)if(e[1]=n,this.get(e)===void 0)return e}}}class ai{constructor(t){this.gapSize=t}apply(t){if(t.nodes.length===0)return t;const e=new Ke,a=t.nodes.filter(n=>!n.parent);for(;a.length>0;)qe(a[0],e,[0,0],a);const l=Math.max(...t.nodes.map(n=>n.width)),r=Math.max(...t.nodes.map(n=>n.height)),i=this.gapSize!==void 0?this.gapSize:(t.canvas?.gridSize||0)*2;for(let n=e.minY();n<=e.maxY();++n)for(let o=e.minX();o<=e.maxX();++o){const d=e.get([o,n]);d!==void 0&&d.move([o*(l+i),n*(r+i)])}return t}}const qe=(s,t,e,a)=>{const l=t.getClosestEmptyCoordinate(e);t.set(l,s),B(a,s);for(const r of s.getAdjacentNodes())a.includes(r)&&qe(r,t,l,a)};class li{constructor(t){this.gapSize=t}apply(t){if(t.nodes.length===0)return t;const e=new Ke,a=t.nodes.filter(c=>!c.parent),l={},r=a[0];let i=[r];for(l[r.id]=[0,0];a.length>0;){const c=[];for(const h of i){e.set(e.getClosestEmptyCoordinate(l[h.id]),h),B(a,h);const u=h.getAdjacentNodes();for(const b of u)a.includes(b)&&(c.push(b),l[b.id]=l[h.id])}if(c.length>0)i=c;else if(a.length>0){const h=a[0];i=[h],l[h.id]=e.getClosestEmptyCoordinate([0,0])}}const n=Math.max(...t.nodes.map(c=>c.width)),o=Math.max(...t.nodes.map(c=>c.height)),d=this.gapSize!==void 0?this.gapSize:(t.canvas?.gridSize||0)*2;for(let c=e.minY();c<=e.maxY();++c)for(let h=e.minX();h<=e.maxX();++h){const u=e.get([h,c]);u!==void 0&&u.move([h*(n+d),c*(o+d)])}return t}}class ee{constructor(t){this.gapSize=t}apply(t){if(t.nodes.length===0)return t;const e=this.gapSize!==void 0?this.gapSize:(t.canvas?.gridSize||0)*2;let a=t.nodes.filter(n=>!n.parent);const l=a[0];B(a,l);const r=[[l]];for(;a.length>0;){const n=r[r.length-1],o=[];for(const d of n){const c=d.getAdjacentNodes();for(const h of c)a.includes(h)&&(B(a,h),o.push(h))}o.length>0?r.push(o):(r.push(a),a=[])}let i=0;for(const n of r){let o=0;for(const c of n)c.move([i,o]),o+=e+c.height;const d=Math.max(...n.map(c=>c.width));i+=e+d}for(const n of t.connections)n.tighten();return t}}class di{constructor(t){this.gapSize=t}apply(t){if(t.nodes.length===0)return t;new ee(this.gapSize).apply(t);const e=this.gapSize!==void 0?this.gapSize:(t.canvas?.gridSize||0)*2,a=.99,l=1,r=.1,i=2e5,n=.5,o=1,d=.002;let c=100;for(;c>l;){c=c*a;const h=[0,0];{for(const u of t.nodes)h[0]=h[0]+u.coords[0]+u.width/2,h[1]=h[1]+u.coords[1]+u.width/2;h[0]=h[0]/t.nodes.length,h[1]=h[1]/t.nodes.length}for(const u of t.nodes){const b=u.getAdjacentNodes();for(const m of t.nodes){const x=[u.coords[0]+u.width/2,u.coords[1]+u.height/2],g=[m.coords[0]+m.width/2,m.coords[1]+m.height/2],v=Re(u.coords,m.coords),y=[m.coords[0],m.coords[1]];if(b.includes(m)&&v>0&&(v>e+(Math.max(u.width,u.height)+Math.max(m.width,m.height))/2?(y[0]=y[0]-(g[0]-x[0])*r,y[1]=y[1]-(g[1]-x[1])*r):(y[0]=y[0]+(g[0]-x[0])*n,y[1]=y[1]+(g[1]-x[1])*n)),v>0){const T=i/(v*v);y[0]=y[0]+T*(g[0]-x[0])/v,y[1]=y[1]+T*(g[1]-x[1])/v}else y[0]=y[0]+o*(Math.random()*2-1),y[1]=y[1]+o*(Math.random()*2-1);y[0]=y[0]-(g[0]-h[0])*d,y[1]=y[1]-(g[1]-h[1])*d,y[0]-m.coords[0]>c?y[0]=m.coords[0]+c:y[0]-m.coords[0]<-c&&(y[0]=m.coords[0]-c),y[1]-m.coords[1]>c?y[1]=m.coords[1]+c:y[1]-m.coords[1]<-c&&(y[1]=m.coords[1]-c),m.move(y)}}}if(t.canvas&&t.canvas.snapToGrid)for(const h of t.nodes){const u=t.canvas.getClosestGridPoint([h.coords[0]-h.type.snapToGridOffset[0],h.coords[1]-h.type.snapToGridOffset[1]]);u[0]+=h.type.snapToGridOffset[0],u[1]+=h.type.snapToGridOffset[1],h.move(u)}for(const h of t.connections)h.tighten();return t}}class ci{constructor(t){this.gapSize=t}apply(t){if(t.nodes.length===0)return t;const e=this.gapSize!==void 0?this.gapSize:(t.canvas?.gridSize||0)*2,a=t.nodes.filter(r=>!r.parent);a.sort((r,i)=>i.type.priority-r.type.priority);let l=0;for(const r of a)r.move([l,0]),l+=r.width+e;return t}}class hi{constructor(t){this.gapSize=t}apply(t){if(t.nodes.length===0)return t;const e=Math.max(...t.nodes.map(c=>c.getPriority())),a=Math.min(...t.nodes.map(c=>c.getPriority()));if(e===a)return new ee(this.gapSize).apply(t),t;const l=this.gapSize!==void 0?this.gapSize:(t.canvas?.gridSize||0)*2,r=t.nodes.filter(c=>!c.parent),i=[],n=t.nodes.filter(c=>!c.parent).filter(c=>c.getPriority()>=e),o=[];if(n.length>1){const c=n[0];n.splice(0,1),o.push(c);const h=[c],u=[c];for(;h.length>0;){const b=h[0];h.splice(0,1),n.includes(b)&&(o.push(b),B(n,b));const m=b.getAdjacentNodes();for(const x of m)u.includes(x)||(h.push(x),u.push(x))}for(const b of n)o.push(b)}else o.push(n[0]);for(const c of o)B(r,c),i.push([c]);for(i.push([]),r.sort((c,h)=>h.type.priority-c.type.priority);r.length>0;){const c=r[0];r.splice(0,1);const h=[c],u=[c];let b=!1;for(;h.length>0;){const m=h[0];h.splice(0,1);const x=o.indexOf(m);if(x>=0){i[x].push(c),b=!0;break}else{const g=m.getAdjacentNodes();for(const v of g)u.includes(v)||(h.push(v),u.push(v))}}b||i[i.length-1].push(c)}let d=0;for(let c=0;c<i.length;++c){let h=0;for(let b=0;b<i[c].length;++b){const m=i[c][b];m.move([d,h]),h+=l+m.height}const u=Math.max(...i[c].map(b=>b.width));d+=l+u}for(const c of t.connections)c.tighten();return t}}class gi{constructor(t){this.gapSize=t}apply(t){if(t.nodes.length===0)return t;const e=Math.max(...t.nodes.map(c=>c.getPriority())),a=Math.min(...t.nodes.map(c=>c.getPriority()));if(e===a)return new ee(this.gapSize).apply(t),t;const l=this.gapSize!==void 0?this.gapSize:(t.canvas?.gridSize||0)*2,r=t.nodes.filter(c=>!c.parent).sort((c,h)=>h.getPriority()-c.getPriority()),i=[];for(;r.length>0;){const c=r[0];r.splice(0,1);const h=new ye(void 0,c);Je(h,r),i.push(h)}const n=[];for(const c of i)n.push([c]),Qe(c,n,n.length);const o=Math.max(...t.nodes.map(c=>c.height));let d=0;for(let c=0;c<n.length;++c){let h=0;for(let b=0;b<n[c].length;++b){const m=n[c][b];m.node.move([d,h]),h+=(l+o)*m.countBranchHeight()}const u=Math.max(...n[c].map(b=>b.node.width));d+=l+u}for(const c of t.connections)c.tighten();return t}}const Je=(s,t)=>{for(const e of s.node.getAdjacentNodes().sort((a,l)=>l.getPriority()-a.getPriority())){const a=t.indexOf(e);if(a>=0){t.splice(a,1);const l=s.addBranch(e);Je(l,t)}}},Qe=(s,t,e)=>{if(s.branches.length>0){for(;e>=t.length;)t.push([]);for(const a of s.branches)t[e].push(a),Qe(a,t,e+1)}};class ye{constructor(t,e){this.parent=t,this.branches=[],this.depth=0,this.node=e}addBranch(t){const e=new ye(this,t);return e.depth=this.depth+1,this.branches.push(e),e}countBranchHeight(){if(this.branches.length<=0)return 1;{let t=0;for(const e of this.branches)t+=e.countBranchHeight();return t}}}class fi{constructor(t){this.gapSize=t}apply(t){if(t.nodes.length===0)return t;const e=this.gapSize!==void 0?this.gapSize:(t.canvas?.gridSize||0)*2,a=t.nodes.filter(r=>!r.parent);a.sort((r,i)=>i.type.priority-r.type.priority);let l=0;for(const r of a)r.move([0,l]),l+=r.height+e;return t}}const Pe={adjacency:new ai,breadth:new ee,"breadth-adjacency":new li,force:new di,horizontal:new ci,priority:new hi,tree:new gi,vertical:new fi},ui=I.createContext({}),xt=I.createContext({});class pi{constructor(t,e){this.onTitleChange=t,this.onValueSetChange=e}get title(){return this._title}set title(t){this._title=t,this.onTitleChange(t)}get valueSet(){return this._valueSet}set valueSet(t){this._valueSet=t,this.onValueSetChange(t)}highlightProperty(...t){}}const be=({direction:s,collapsableSelector:t,collapsableAdditionalSelector:e,collapsed:a,disabled:l,rule:r,collapsedValue:i,visibleValue:n,onCollapse:o})=>{const[d,c]=I.useState(a),h=()=>{if(!l){const b=!d;c(b),o?.(b);let m;if(typeof t=="string")m=A.select(t),e&&(m=m.select(e));else{const x=t;if(!x)throw new Error("collapsableSelector is not a valid ref");m=A.select(x.current),e&&(m=m.select(e))}m.style(r,b?i:n)}},u=()=>{switch(s){case f.Right:return l?"daga-horizontal-none":d?"daga-horizontal-right":"daga-horizontal-left";case f.Bottom:return l?"daga-vertical-none":d?"daga-vertical-down":"daga-vertical-up";case f.Left:return l?"daga-horizontal-none":d?"daga-horizontal-left":"daga-horizontal-right";case f.Top:return l?"daga-vertical-none":d?"daga-vertical-up":"daga-vertical-down"}};return p.jsx("daga-collapse-button",{children:p.jsx("button",{className:`daga-collapse-button daga-${s}`,onClick:h,children:p.jsx("div",{className:u()})})})},mi=()=>{const s=I.useContext(xt),t=I.useRef(null),[e,a]=I.useState([]);kt.merge(s.validatorChange$,s.diagramChange$).pipe(kt.map(()=>l())).subscribe();const l=()=>{a([]);for(const i of s.validators){const n=i.validate(s.model);a(n)}},r=i=>{if(i.elementId&&(i.propertyNames===void 0||i.propertyNames.length===0)){const n=s.model.nodes.get(i.elementId)||s.model.connections.get(i.elementId);n&&s.userHighlight.add(n)}else if(i.elementId&&i.propertyNames!==void 0&&i.propertyNames.length>0){s.userSelection.openInPropertyEditor(s.model.nodes.get(i.elementId)||s.model.connections.get(i.elementId));const n=s.model.nodes.get(i.elementId)||s.model.connections.get(i.elementId);n&&s.userHighlight.add(n),s.parentComponent?.propertyEditor?.highlightProperty(...i.propertyNames)}else!i.elementId&&i.propertyNames!==void 0&&i.propertyNames.length>0&&(s.userSelection.openInPropertyEditor(),s.parentComponent?.propertyEditor?.highlightProperty(...i.propertyNames))};return p.jsx("daga-errors",{children:p.jsxs("div",{ref:t,className:"daga-errors",children:[e.length===0&&p.jsx("div",{className:"daga-errors-summary daga-no-errors daga-prevent-user-select",children:p.jsx("span",{children:"No errors found"})}),e.length>0&&p.jsxs("div",{className:"daga-errors-summary daga-with-errors daga-prevent-user-select",children:[p.jsxs("span",{children:[e.length," errors found"]}),p.jsx("div",{className:"daga-collapse-button-container",children:p.jsx(be,{collapsableSelector:t,collapsableAdditionalSelector:".daga-error-panel",direction:f.Top,rule:"display",collapsedValue:"none",visibleValue:"block",collapsed:!1,disabled:!1})})]}),e.length>0&&p.jsx("div",{className:"daga-error-panel",children:p.jsx("ol",{children:e.map((i,n)=>p.jsx("li",{onClick:()=>r(i),dangerouslySetInnerHTML:{__html:i.message}},n))})})]})})},vi=200,ze=s=>(s||"").toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g,""),to=({disabled:s,options:t,value:e,onChange:a})=>{const l=I.useRef(null),[r,i]=I.useState(""),[n,o]=I.useState(void 0),[d,c]=I.useState([]),[h,u]=I.useState([]),[b,m]=I.useState([]),[x,g]=I.useState([]),[v,y]=I.useState(!1);I.useEffect(()=>{i(t.find(E=>wt(E.key,e))?.label||"")},[e,t]);const T=E=>{if(!s)switch(E.key){case K.PageDown:n===void 0?(F(0),M(0)):(F(n+5),M(n)),E.preventDefault();break;case K.ArrowDown:n===void 0?(F(0),M(0)):(F(n+1),M(n)),E.preventDefault();break;case K.PageUp:n===void 0?(F(t.length-1),M(t.length-1)):(F(n-5),M(n)),E.preventDefault();break;case K.ArrowUp:n===void 0?(F(t.length-1),M(t.length-1)):(F(n-1),M(n)),E.preventDefault();break;case K.Escape:j(),E.preventDefault();break;case K.Enter:R(t[n||0]),E.preventDefault();break;default:P()}},P=()=>{if(!s){const E=ze(r.trim());c([]),u([]),m([]),g([]);for(const V of t){const J=ze(V.label).indexOf(E);if(J>=0){const tt=V.label.substring(0,J),$t=V.label.substring(J,J+E.length),Pt=V.label.substring(J+E.length);c(et=>[...et,V]),u(et=>[...et,tt]),m(et=>[...et,$t]),g(et=>[...et,Pt])}}y(!0)}},j=()=>{y(!1)},F=E=>{if(!s){let V=E;if(E===void 0){o(void 0);return}E<0&&(V=0),E>=t.length&&(V=t.length-1),o(V)}},Y=()=>{setTimeout(()=>{j()},vi)},M=E=>{const V=l.current?.querySelectorAll("li")[E];V&&V.scrollIntoView({block:"center"})},C=()=>{s||(i(""),y(!1),o(void 0))},R=E=>{s||(i(E.label),y(!1),o(void 0),a(E.key))};return p.jsxs("div",{ref:l,className:`daga-autocomplete ${v?"daga-showing-options":""}`,children:[p.jsxs("div",{className:"daga-autocomplete-input",children:[p.jsx("input",{value:r,disabled:s,onKeyUp:T,onFocus:P,onBlur:Y,onChange:E=>i(E.target.value)}),r!==""&&p.jsx("button",{className:"daga-clear",onClick:C})]}),p.jsx("div",{className:"daga-autocomplete-options",children:p.jsxs("ul",{className:"daga-autocomplete-option-list",children:[d.length===0&&p.jsx("li",{className:"daga-autocomplete-option no-options",children:"(No options)"}),d.map((E,V)=>p.jsxs("li",{className:`daga-autocomplete-option ${V===n?"daga-focused":""}`,onMouseMove:()=>F(V),onClick:()=>R(E),children:[p.jsx("span",{children:h[V]}),p.jsx("span",{className:"daga-match",children:b[V]}),p.jsx("span",{children:x[V]})]},V))]})})]})},yi=(s,t)=>s.find(e=>e.key===t)?.label||`${t}`,bi=({disabled:s,allowRepeats:t,options:e,value:a,onChange:l})=>{const[r,i]=I.useState(),[n,o]=I.useState([]),[d,c]=I.useState([]),h=g=>{for(const v of a)if(v===g)return!0;return!1},u=()=>{if(!t){const g=[];for(const v of e)h(v.key)||g.push(v);c(g)}};I.useEffect(()=>{const g=a.length===0,v=a.map(y=>yi(e,y));o(v),g&&l(a),u()},[a,e]);const b=g=>{a.length>g&&(a.splice(g,1),o(n.filter((v,y)=>y!==g)),l(a),u())},m=()=>{r!==void 0&&(t||!h(r))&&(l(a.concat(r)),x())},x=()=>{i("")};return p.jsxs("div",{children:[a.map((g,v)=>p.jsxs("div",{className:"daga-value-item-element",children:[p.jsx("span",{className:"daga-input",children:n[v]}),!s&&p.jsx("button",{className:"daga-property-button",onClick:()=>b(v),children:p.jsx("div",{className:"daga-icon daga-close-icon"})})]},v)),!s&&p.jsxs("div",{className:"daga-value-item-input",children:[p.jsx("div",{className:"daga-input daga-relatively-positioned",children:p.jsx(to,{disabled:s,options:t?e||[]:d||[],value:r,onChange:i})}),p.jsx("button",{className:"daga-property-button",onClick:m,children:p.jsx("div",{className:"daga-icon daga-add-icon"})})]})]})},ki=({disabled:s,allowRepeats:t,value:e,onChange:a})=>{const[l,r]=I.useState(""),i=u=>{for(const b of u||[])if(b===u)return!0;return!1},n=u=>{e.length>u&&a(e.filter((b,m)=>m!==u))},o=(u,b,m)=>{const x=e.map((g,v)=>v===b?m==="blur"?u.trim():u:g);a(x)},d=()=>{const u=l.trim();u!==""&&(t||!i(u))&&(a(e.concat(u)),c())},c=()=>{r("")},h=u=>{u.key==="Enter"&&d()};return p.jsxs(p.Fragment,{children:[e.map((u,b)=>p.jsxs("div",{className:"daga-value-item-element",children:[p.jsx("input",{className:"daga-input",disabled:s,value:u,onChange:m=>o(m.target.value,b,"change"),onBlur:m=>o(m.target.value,b,"blur")}),p.jsx("button",{className:"daga-property-button",onClick:()=>n(b),children:p.jsx("div",{className:"daga-icon daga-close-icon"})})]},b)),!s&&p.jsxs("div",{className:"daga-value-item-input",children:[p.jsxs("div",{className:"daga-input daga-relatively-positioned",children:[p.jsx("input",{type:"text",onKeyUp:h,value:l,onChange:u=>r(u.target.value)}),p.jsx("button",{className:"daga-clear",onClick:c})]}),p.jsx("button",{className:"daga-property-button",onClick:d,children:p.jsx("div",{className:"daga-icon daga-add-icon"})})]})]})},wi=({disabled:s,value:t,onChange:e})=>{const[a,l]=I.useState(""),[r,i]=I.useState(""),[n,o]=I.useState({}),d=g=>{const v={};Object.keys(t).forEach(y=>{y!==g&&(v[y]=t[y])}),e(v)},c=(g,v,y)=>{const T=y==="blur"?v.trim():v;if(y==="blur"){if(g!==T){const P={};Object.keys(t).forEach(j=>{j===g?P[T]=t[j]:P[j]=t[j]}),e(P),o(j=>{const F={...j};return delete F[g],F})}}else o(P=>({...P,[g]:v}))},h=(g,v,y)=>{const T=y==="blur"?v.trim():v;if(T!==""){const P={};Object.keys(t).forEach(j=>{j===g?P[j]=T:P[j]=t[j]}),e(P)}},u=()=>{const g=a.trim(),v=r.trim();if(g!==""&&v!==""){const y={};Object.keys(t).forEach(T=>{y[T]=t[T]}),y[g]=v,e(y),l(""),i("")}},b=()=>{l("")},m=()=>{i("")},x=g=>{g.key==="Enter"&&u()};return p.jsxs("div",{children:[Object.entries(t).map(([g,v],y)=>p.jsxs("div",{className:"daga-value-item-element",children:[p.jsx("input",{id:`key-${y}`,className:"daga-input",type:"text",disabled:s,value:n[g]??g,onChange:T=>c(g,T.target.value,"change"),onBlur:T=>c(g,T.target.value,"blur")}),p.jsx("input",{id:`value-${y}`,className:"daga-input",type:"text",disabled:s,value:v,onChange:T=>h(g,T.target.value,"change"),onBlur:T=>h(g,T.target.value,"blur")}),p.jsx("button",{className:"daga-property-button",onClick:()=>d(g),children:p.jsx("div",{className:"daga-icon daga-close-icon"})})]},g)),!s&&p.jsxs("div",{className:"daga-value-item-input",children:[p.jsxs("div",{className:"daga-input daga-relatively-positioned",children:[p.jsx("input",{type:"text",value:a,onKeyUp:x,onChange:g=>l(g.target.value),onBlur:g=>c(a,g.target.value,"blur")}),p.jsx("button",{className:"daga-clear",onClick:b})]}),p.jsxs("div",{className:"daga-input daga-relatively-positioned",children:[p.jsx("input",{type:"text",value:r,onKeyUp:x,onChange:g=>i(g.target.value),onBlur:g=>h(a,g.target.value,"blur")}),p.jsx("button",{className:"daga-clear",onClick:m})]}),p.jsx("button",{className:"daga-property-button",onClick:u,children:p.jsx("div",{className:"daga-icon daga-add-icon"})})]})]})},eo=({valueSet:s,onValueChange:t,depth:e})=>{const l=I.useContext(xt).canUserPerformAction(k.UpdateValues)&&s?.rootElement?.removed!==!0,r=o=>"daga-property-name-"+o.replace(/\s/g,""),i=o=>{if(typeof o=="string")return o;if(o==null||isNaN(o.valueOf()))return"";const d=new Date(o),c=d.getTimezoneOffset();return d.setMinutes(d.getMinutes()-c),d.toISOString().substring(0,19)},n=o=>new Date(o);return p.jsx("daga-object-editor",{children:s.displayedProperties.map(o=>p.jsxs("div",{className:`daga-property ${r(o.name)}`,children:[p.jsx("p",{className:"daga-property-name",children:o.label||o.name}),o.type===N.Text&&p.jsx("input",{type:"daga-text",disabled:o.editable===!1||!l,value:s?.getValue(o.name),onChange:d=>t(s,o,d.target.value)}),o.type===N.TextArea&&p.jsx("textarea",{disabled:o.editable===!1||!l,value:s?.getValue(o.name),onChange:d=>t(s,o,d.target.value)}),o.type===N.Number&&p.jsx("input",{type:"number",disabled:o.editable===!1||!l,value:s?.getValue(o.name),onChange:d=>t(s,o,d.target.value)}),o.type===N.Color&&p.jsx("input",{type:"text",pattern:"#[0-9a-fA-F]{6}",disabled:o.editable===!1||!l,value:s?.getValue(o.name),onChange:d=>t(s,o,d.target.value)}),o.type===N.Datetime&&p.jsx("input",{type:"datetime-local",disabled:o.editable===!1||!l,value:i(s?.getValue(o.name)),onChange:d=>t(s,o,n(d.target.value))}),o.type===N.Date&&p.jsx("input",{type:"date",disabled:o.editable===!1||!l,value:s?.getValue(o.name),onChange:d=>t(s,o,d.target.value)}),o.type===N.Time&&p.jsx("input",{type:"time",disabled:o.editable===!1||!l,value:s?.getValue(o.name),onChange:d=>t(s,o,d.target.value)}),o.type===N.Url&&p.jsx("input",{type:"url",disabled:o.editable===!1||!l,value:s?.getValue(o.name),onChange:d=>t(s,o,d.target.value)}),o.type===N.Boolean&&p.jsxs("div",{className:"daga-radio",children:[p.jsxs("label",{className:"daga-radio-item daga-radio-start"+(s?.getValue(o.name)===!1?" daga-checked":""),children:[p.jsx("input",{type:"radio",disabled:o.editable===!1||!l,name:o.name,value:"false",checked:s?.getValue(o.name)===!1,onChange:()=>t(s,o,!1)}),"No"]}),p.jsxs("label",{className:"daga-radio-item daga-radio-end"+(s?.getValue(o.name)===!0?" daga-checked":""),children:[p.jsx("input",{type:"radio",disabled:o.editable===!1||!l,name:o.name,value:"true",checked:s?.getValue(o.name)===!0,onChange:()=>t(s,o,!0)}),"Yes"]})]}),o.type===N.Option&&p.jsx("div",{className:"daga-relatively-positioned",children:p.jsx(to,{disabled:o.editable===!1||!l,options:o.options||[],value:s?.getValue(o.name),onChange:d=>t(s,o,d)})}),(o.type===N.OptionList||o.type===N.OptionSet)&&p.jsx(bi,{disabled:o.editable===!1||!l,allowRepeats:o.type===N.OptionList,options:o.options||[],value:s?.getValue(o.name),onChange:d=>t(s,o,d)}),(o.type===N.TextList||o.type===N.TextSet)&&p.jsx(ki,{disabled:o.editable===!1||!l,allowRepeats:o.type===N.TextList,value:s?.getValue(o.name),onChange:d=>t(s,o,d)}),o.type===N.TextMap&&p.jsx(wi,{disabled:o.editable===!1||!l,value:s?.getValue(o.name),onChange:d=>t(s,o,d)}),o.type===N.Object&&p.jsx("div",{className:"daga-left-bar",children:p.jsx(eo,{valueSet:s.getSubValueSet(o.name),onValueChange:t,depth:e+1})})]},o.name))})},oo=({valueSet:s,depth:t})=>{const e=I.useContext(xt),a=I.useRef(null),l=o=>"daga-property-name-"+o.replace(/\s/g,""),r=()=>{for(const o of s?.displayedProperties||[]){let d=0,c=0,h=0;const u=A.select(a.current).select(`.daga-property.${l(o.name)}.daga-depth-${t}`);u.select("button.daga-move-button").call(A.drag().on($.Start,b=>{w(L.Grabbing);const m=e.getPointerLocationRelativeToScreen(b);if(m.length<2||isNaN(m[0])||isNaN(m[1]))return;const x=u.node()?.getBoundingClientRect();d=x?.width||0,c=x?.height||0,u.style("position","fixed").style("left",`${m[0]-d/2}px`).style("top",`${m[1]-c/2}px`).style("width",`${d}px`).style("height",`${c}px`).style("z-index",1)}).on($.Drag,b=>{w(L.Grabbing);const m=e.getPointerLocationRelativeToScreen(b);m.length<2||isNaN(m[0])||isNaN(m[1])||(u.style("position","fixed").style("left",`${m[0]-d/2}px`).style("top",`${m[1]-c/2}px`).style("width",`${d}px`).style("height",`${c}px`).style("z-index",1),A.select(a.current).select(`.daga-dropbar.daga-index-${h}.daga-depth-${t}`).style("visibility","hidden").style("height",0),h=i(m),A.select(a.current).select(`.daga-dropbar.daga-index-${h}.daga-depth-${t}`).style("visibility","visible").style("height","0.25rem"))}).on($.End,b=>{w(L.Auto),u.style("position","relative").style("left",0).style("top",0).style("z-index",0).style("width","unset").style("height","unset"),A.select(a.current).select(`.daga-dropbar.daga-index-${h}.daga-depth-${t}`).style("visibility","hidden").style("height",0);const m=e.getPointerLocationRelativeToScreen(b);m.length<2||isNaN(m[0])||isNaN(m[1])||(h=i(m),s?.displayedProperties?.splice(s.displayedProperties.indexOf(o),1),s?.displayedProperties?.splice(h,0,o))}))}},i=o=>{const d=s?.propertySet.propertyList||[],c=[];for(let h=0;h<=d.length;++h){const u=A.select(a.current).select(`.daga-dropbar.daga-index-${h}.daga-depth-${t}`).node()?.getBoundingClientRect();u&&c.push([u.x+u.width/2,u.y+u.height/2])}if(c.length>0){const h=c.map(b=>((o[0]-b[0])**2+(o[1]-b[1])**2)**.5);return h.indexOf(Math.min(...h))}return 0},n=o=>{if(s===void 0)return;let d;o instanceof xo?d=o:o instanceof Event?d=s?.propertySet.getProperty(o.target?.value||""):d=s?.propertySet.getProperty(o||""),d&&s?.hideProperty(d),r()};return p.jsxs("daga-property-settings",{ref:a,children:[p.jsx("div",{className:`daga-dropbar daga-index-0 daga-depth-${t}`}),s?.displayedProperties.map((o,d)=>p.jsxs("div",{className:`daga-property-and-dropbar ${l(o.name)} daga-depth-${t}`,children:[p.jsxs("div",{className:`daga-property ${l(o.name)} daga-depth-${t}`,children:[p.jsxs("div",{className:"daga-property-name",children:[p.jsx("span",{children:o.label||o.name}),p.jsxs("div",{className:"daga-buttons",children:[p.jsx("button",{className:"daga-property-button daga-move-button",children:p.jsx("div",{className:"daga-icon daga-move-icon"})}),p.jsx("button",{className:"daga-property-button daga-hide-button",onClick:()=>n(o.name),children:p.jsx("div",{className:"daga-icon daga-hide-icon"})})]})]}),o.type!==N.Object&&p.jsx("div",{className:"daga-property-value",children:Si(s?.getValue(o.name))}),o.type===N.Object&&p.jsx(oo,{valueSet:s?.getSubValueSet(o.name),depth:t+1})]}),p.jsx("div",{className:`daga-dropbar daga-index-${d+1} daga-depth-${t}`})]},o.name))]})},Si=s=>Array.isArray(s)?s.join(", "):Co(s)?Object.entries(s).map(t=>t.map(e=>JSON.stringify(e)).join(": ")).join(", "):s instanceof Date?s.toLocaleString():s==null?"":""+s,xi=({location:s,direction:t,width:e,height:a,title:l,valueSet:r,onValueChange:i})=>{const n=I.useRef(null),[o,d]=I.useState(!1),[c,h]=I.useState(!1),u=()=>A.select(n.current);return I.useEffect(()=>{if(n.current)switch(t){case f.Bottom:case f.Top:u().style("width",e),a&&u().select(".daga-panel-content").style("height",a);break;case f.Left:case f.Right:u().style("height",e),a&&u().select(".daga-panel-content").style("width",a);break}},[e,a,t]),p.jsx("daga-property-editor",{children:p.jsxs("div",{ref:n,className:`daga-panel daga-bottom daga-${s} daga-${t}`,children:[p.jsx(be,{disabled:!r||!r.propertySet||!r.propertySet.hasProperties(),collapsed:o,direction:t,collapsableSelector:n,collapsableAdditionalSelector:".daga-panel-content",rule:"display",collapsedValue:"none",visibleValue:"block",onCollapse:d}),p.jsx("div",{className:"daga-panel-content",children:r&&r.propertySet&&r.propertySet.hasProperties()&&!o&&p.jsxs("div",{children:[l&&p.jsxs("p",{className:"daga-title",children:[l,p.jsx("button",{className:"daga-property-button",onClick:()=>h(!c),children:p.jsx("div",{className:`daga-icon daga-settings-icon ${c?"daga-unrotate":"daga-rotate"}`})})]}),!c&&p.jsx(eo,{valueSet:r,onValueChange:i,depth:0}),c&&p.jsx(oo,{valueSet:r,depth:0})]})})]})})},Ci=6,$i=s=>{const t=I.useContext(xt),[e,a]=I.useState(s.currentPalette||s.palettes[0]),[l,r]=I.useState(0),[i,n]=I.useState(void 0),o=I.useRef(null),d=I.useRef(!1),c=g=>{if(a(g),h().selectAll("*").remove(),r(t.getPriorityThreshold()||0),g.categories&&u(g.categories),g.templates)for(const v of g.templates)b(v)},h=()=>A.select(o.current).select(".daga-palette-view"),u=g=>{const v=h().append("select").style("width","100%").style("height","2rem").style("padding","0.5rem").style("border-radius","0.25rem").style("background-color","#f7f8fc").style("border","1px solid #e6e6e6");v.append("option").attr("value","").text("(None selected)");for(const y in g)v.append("option").attr("value",y).text(y);v.on(S.Change,()=>{i&&h().selectAll(".daga-template-container.daga-in-category").remove();const y=v.property("value");n(y);const T=g[y]||[];for(const P of T)b(P,"daga-in-category")}),i&&(v.property("value",i),v.dispatch(S.Change))},b=(g,v)=>{if(g.templateType==="node"){const y=t.model.nodes.types.get(g.type);y?m(y,g,v):console.error(`Could not find a node type called '${g.type}'`)}else if(g.templateType==="connection"){const y=t.model.connections.types.get(g.type);y?x(y,g,v):console.error(`Could not find a connection type called '${g.type}'`)}},m=(g,v,y)=>{if(l!==void 0&&g.priority<l)return;const T=g.defaultLook.lookType==="shaped-look"?g.defaultLook.borderThickness||1:0,P=g.defaultHeight+T,j=g.defaultWidth+T,F=v.height||P,Y=v.width||j,M=h().append("div").attr("class",`daga-template-container ${y!==void 0?y:""}`).style("width",`${Y}px`).style("height",`${F}px`).call(A.drag().on($.Drag,R=>{if(t.canUserPerformAction(k.AddNode)){const E=t.getPointerLocationRelativeToScreen(R);if(E.length<2||isNaN(E[0])||isNaN(E[1]))return;M.style("position","fixed").style("left",`${E[0]-Y/2}px`).style("top",`${E[1]-F/2}px`).style("z-index",1)}}).on($.Start,R=>{if(t.canUserPerformAction(k.AddNode)){w(L.Grabbing);const E=t.getPointerLocationRelativeToScreen(R);if(E.length<2||isNaN(E[0])||isNaN(E[1]))return;M.style("position","fixed").style("left",`${E[0]-Y/2}px`).style("top",`${E[1]-F/2}px`).style("z-index",1),g.isUnique&&t.model.nodes.find(V=>!V.removed&&V.type.id===g.id)!==void 0&&w(L.NotAllowed)}}).on($.End,R=>{if(t.canUserPerformAction(k.AddNode)){if(w(L.Auto),M.style("position","relative").style("left",0).style("top",0).style("z-index","auto"),g.isUnique&&t.model.nodes.find(Ut=>!Ut.removed&&Ut.type.id===g.id)!==void 0)return;const E=t.getPointerLocationRelativeToScreen(R);if(E.length<2||isNaN(E[0])||isNaN(E[1]))return;const V=document.elementFromPoint(E[0],E[1]);if(V&&!t.selectCanvasView().node()?.contains(V))return;const at=t.getPointerLocationRelativeToCanvas(R);if(at.length<2||isNaN(at[0])||isNaN(at[1]))return;let J=[at[0]-g.defaultWidth/2,at[1]-g.defaultHeight/2];t.snapToGrid&&(J=t.getClosestGridPoint([J[0]-g.snapToGridOffset[0],J[1]-g.snapToGridOffset[1]]),J[0]+=g.snapToGridOffset[0],J[1]+=g.snapToGridOffset[1]);const $t=t.model.nodes.getAtCoordinates(at[0],at[1]).filter(Ut=>Ut.type.childrenTypes.includes(g.id)),Pt=Fe($t),et=Pt[Pt.length-1];if(!g.canBeParentless&&et===void 0)return;const ke=et?.getLastAncestor(),we=new Go(t,g,J,et?.id,ke?.id,ke?.getGeometry(),void 0,v.label,v.values);we.do(),t?.actionStack.add(we),w()}})).append("svg").attr("class",`palette-node ${g.id}`).attr("viewBox",`0 0 ${j} ${P}`).attr("preserveAspectRatio","none").style("position","relative").style("left",0).style("top",0).style("width",`${Y}px`).style("height",`${F}px`),C=v.look||g.defaultLook;switch(C.lookType){case"shaped-look":M.append("path").attr("d",ge(C.shape||Tt.Rectangle,(C.borderThickness||1)/2,(C.borderThickness||1)/2,g.defaultWidth,g.defaultHeight)).attr("fill",C.fillColor||"#FFFFFF").attr("stroke",C.borderColor||"#000000").attr("stroke-width",`${C.borderThickness}px`);break;case"image-look":M.append("image").attr("x",0).attr("y",0).attr("width",g.defaultWidth).attr("height",g.defaultHeight).attr("href",C.backgroundImage).attr("preserveAspectRatio","none");break;case"stretchable-image-look":M.append("image").attr("x",0).attr("y",0).attr("width",C.leftMargin).attr("height",C.topMargin).attr("href",C.backgroundImageTopLeft).attr("preserveAspectRatio","none"),M.append("image").attr("x",C.leftMargin).attr("y",0).attr("width",g.defaultWidth-C.rightMargin-C.leftMargin).attr("height",C.topMargin).attr("href",C.backgroundImageTop).attr("preserveAspectRatio","none"),M.append("image").attr("x",g.defaultWidth-C.rightMargin).attr("y",0).attr("width",C.rightMargin).attr("height",C.topMargin).attr("href",C.backgroundImageTopRight).attr("preserveAspectRatio","none"),M.append("image").attr("x",0).attr("y",C.topMargin).attr("width",C.leftMargin).attr("height",g.defaultHeight-C.bottomMargin-C.topMargin).attr("href",C.backgroundImageLeft).attr("preserveAspectRatio","none"),M.append("image").attr("x",C.leftMargin).attr("y",C.topMargin).attr("width",g.defaultWidth-C.rightMargin-C.leftMargin).attr("height",g.defaultHeight-C.bottomMargin-C.topMargin).attr("href",C.backgroundImageCenter).attr("preserveAspectRatio","none"),M.append("image").attr("x",g.defaultWidth-C.rightMargin).attr("y",C.topMargin).attr("width",C.rightMargin).attr("height",g.defaultHeight-C.bottomMargin-C.topMargin).attr("href",C.backgroundImageRight).attr("preserveAspectRatio","none"),M.append("image").attr("x",0).attr("y",g.defaultHeight-C.bottomMargin).attr("width",C.leftMargin).attr("height",C.bottomMargin).attr("href",C.backgroundImageBottomLeft).attr("preserveAspectRatio","none"),M.append("image").attr("x",C.leftMargin).attr("y",g.defaultHeight-C.bottomMargin).attr("width",g.defaultWidth-C.rightMargin-C.leftMargin).attr("height",C.bottomMargin).attr("href",C.backgroundImageBottom).attr("preserveAspectRatio","none"),M.append("image").attr("x",g.defaultWidth-C.rightMargin).attr("y",g.defaultHeight-C.bottomMargin).attr("width",C.rightMargin).attr("height",C.bottomMargin).attr("href",C.backgroundImageBottomRight).attr("preserveAspectRatio","none")}if(v.look===void 0){if(g.decorators)for(const R of g.decorators)M.append("foreignObject").attr("width",`${R.width}px`).attr("height",`${R.height}px`).attr("transform",`translate(${R.coords[0]},${R.coords[1]})`).html(R.html);if(v.label){const R={...O,...g.label,...v.labelLook};M.append("text").attr("transform",`translate(${(D(R)+g.defaultWidth)/2},${(G(R)+g.defaultHeight)/2})`).attr("x",0).attr("y",0).attr("font-size",`${R.fontSize}px`).attr("text-anchor","middle").attr("font-family",R.fontFamily).attr("font-weight",400).attr("fill",R.color).attr("stroke","none").style("font-kerning","none").style("user-select","none").text(v.label)}}},x=(g,v,y)=>{const T=h().append("div").attr("class",`daga-template-container ${y!==void 0?y:""}`).style("width",`${v.width}px`).style("height",`${v.height}px`).append("svg").attr("class",`palette-button ${g.id}`).style("position","relative").style("left",0).style("top",0).style("width","100%").style("height","100%").on("click",()=>{t.connectionType=g});T.append("path").attr("d",ge(Tt.Rectangle,0,0,v.width,v.height)).attr("fill",v.backgroundColor).attr("stroke","black").attr("stroke-width","1px"),v.icon!==""&&T.append("image").attr("x",0).attr("y",0).attr("width",v.width).attr("height",v.height).attr("href",v.icon),v.label!==""&&T.append("text").attr("transform",`translate(${v.width/2},${v.height/2+Ci})`).attr("x",0).attr("y",0).attr("font-size","20px").attr("text-anchor","middle").attr("font-family","'Wonder Unit Sans', sans-serif").attr("font-weight",400).attr("fill","#000000").attr("stroke","none").style("font-kerning","none").style("user-select","none").text(v.label)};return I.useEffect(()=>{s.palettes.length>0&&!d.current&&(d.current=!0,c(s.palettes[0]))},[s.palettes]),I.useEffect(()=>{if(o.current)switch(s.direction){case f.Bottom:case f.Top:o.current.style.width=s.width,s.height&&(o.current.style.height=s.height);break;case f.Left:case f.Right:o.current.style.height=s.width,s.height&&(o.current.style.width=s.height);break}},[s.direction,s.width,s.height]),p.jsx("daga-palette",{children:p.jsxs("div",{ref:o,className:`daga-panel daga-${s.location} daga-${s.direction}`,children:[p.jsx(be,{direction:s.direction,collapsableSelector:o,collapsableAdditionalSelector:".daga-panel-content",rule:"display",collapsedValue:"none",visibleValue:"block",collapsed:!1,disabled:!1}),p.jsxs("div",{className:"daga-panel-content",children:[s.palettes.length>1&&p.jsx("div",{className:"daga-panel-tabs",children:s.palettes.map(g=>p.jsx("div",{className:`daga-panel-tab ${g===e?"daga-current-tab":""}`,onClick:()=>c(g),children:g.name}))}),p.jsx("div",{className:"daga-palette-view"})]})]})})},Ii=({location:s,direction:t,enableAction:e,enableFilter:a,enableLayout:l,enableSelection:r,enableZoom:i})=>{let n=!1,o=!0,d=!1,c,h,u,b;switch(t){case f.Bottom:c="height",h="scaleY",u="top",b="bottom";break;case f.Top:c="height",h="scaleY",u="bottom",b="top";break;case f.Left:c="width",h="scaleX",u="right",b="left";break;case f.Right:c="width",h="scaleX",u="left",b="right";break}const m=I.useRef(null),x=I.useRef(null),g=I.useRef(null);I.useEffect(()=>{A.select(m.current).style(`margin-${b}`,"-1rem").style(c,"0rem").style("transform",`${h}(0)`).style("transform-origin",u)});const v=async()=>{const tt=A.select(m.current);if(!d)if(o){o=!1;const et=`${4*tt.selectChildren().size()}rem`;tt.transition().duration(500).ease(A.easeLinear).style(c,et).style("transform",`${h}(1)`),setTimeout(()=>{d=!1},500)}else o=!0,tt.transition().duration(500).ease(A.easeLinear).style(c,"0rem").style("transform",`${h}(0)`),setTimeout(()=>{d=!1},500)},y=I.useContext(xt),T=()=>{y.zoomBy(y.zoomFactor)},P=()=>{y.zoomBy(1/y.zoomFactor)},j=()=>{y.center()},F=()=>{y.layoutFormat&&y.layoutFormat in Pe&&Pe[y.layoutFormat].apply(y.model)},Y=()=>{n=!n,A.select(g.current).classed("daga-on",n).classed("daga-off",!n);const tt=y.getPriorityThresholdOptions();tt&&tt.length>=2&&y.setPriorityThreshold(tt[n?1:0])},M=()=>{y.actionStack.undo()},C=()=>{y.actionStack.redo()},R=()=>{y.userSelection.copyToClipboard()},E=()=>{y.userSelection.cutToClipboard()},V=()=>{y.userSelection.pasteFromClipboard()},at=()=>{y.userSelection.removeFromModel()},J=()=>{y.multipleSelectionOn=!0,A.select(x.current).classed("daga-on",!0).classed("daga-off",!1);const tt=y.diagramEvent$.subscribe($t=>{$t.type===Ye.Selection&&(A.select(x.current).classed("daga-on",!1).classed("daga-off",!0),tt.unsubscribe())})};return p.jsx("daga-diagram-buttons",{children:p.jsxs("div",{className:`daga-diagram-buttons daga-${s} daga-${t}`,children:[i&&y.canUserPerformAction(k.Zoom)&&p.jsx("button",{className:"daga-zoom-in",onClick:T,children:p.jsx("span",{className:"daga-tooltip",children:"Zoom in"})}),i&&y.canUserPerformAction(k.Zoom)&&p.jsx("button",{className:"daga-zoom-out",onClick:P,children:p.jsx("span",{className:"daga-tooltip",children:"Zoom out"})}),p.jsxs("div",{className:"daga-collapsable-buttons daga-collapsed",ref:m,children:[i&&y.canUserPerformAction(k.Zoom)&&p.jsx("button",{className:"daga-center",onClick:j,children:p.jsx("span",{className:"daga-tooltip",children:"Fit diagram to screen"})}),e&&p.jsx("button",{className:"daga-undo",onClick:M,children:p.jsx("span",{className:"daga-tooltip",children:"Undo"})}),e&&p.jsx("button",{className:"daga-redo",onClick:C,children:p.jsx("span",{className:"daga-tooltip",children:"Redo"})}),r&&p.jsx("button",{className:"daga-copy",onClick:R,children:p.jsx("span",{className:"daga-tooltip",children:"Copy"})}),r&&p.jsx("button",{className:"daga-cut",onClick:E,children:p.jsx("span",{className:"daga-tooltip",children:"Cut"})}),r&&p.jsx("button",{className:`daga-multiple-selection ${n?"daga-on":"daga-off"}`,onClick:J,ref:x,children:p.jsx("span",{className:"daga-tooltip",children:"Multiple selection"})}),r&&p.jsx("button",{className:"daga-paste",onClick:V,children:p.jsx("span",{className:"daga-tooltip",children:"Paste"})}),r&&p.jsx("button",{className:"daga-delete",onClick:at,children:p.jsx("span",{className:"daga-tooltip",children:"Delete"})}),l&&y.layoutFormat&&p.jsx("button",{className:"daga-layout",onClick:F,children:p.jsx("span",{className:"daga-tooltip",children:"Apply layout"})}),a&&p.jsx("button",{className:`daga-filter ${n?"daga-on":"daga-off"}`,onClick:Y,ref:g,children:p.jsx("span",{className:"daga-tooltip",children:"Apply filter"})})]}),p.jsx("button",{className:"daga-more-options",onClick:v,children:o?p.jsx("span",{className:"daga-tooltip",children:"More options"}):p.jsx("span",{className:"daga-tooltip",children:"Less options"})})]})})},Ai=({config:s,model:t,onCanvasCreated:e,onDiagramEvent:a,onModelChange:l})=>{const r=new Be,i=new Ze,n=I.useRef(null),o=I.useRef(void 0),d=I.useRef(!1),c=[],[h,u]=I.useState(void 0),[b,m]=I.useState(void 0),x={zoomIn:()=>{},zoomOut:()=>{},center:()=>{},layout:()=>{},filter:()=>{},undo:()=>{},redo:()=>{}},g={refreshPalette:()=>{}},v=new pi(Y=>u(Y),Y=>m(Y)),y={diagramButtons:x,palette:g,propertyEditor:v},T=(Y=!1)=>{if((!o.current||Y)&&(c.forEach(M=>M.unsubscribe()),o.current=new ue(y,s)),!o.current)throw new Error("Canvas could not be created");return o.current},P=T(),j=Y=>{P.initView(Y),c.push(P.diagramEvent$.subscribe(M=>{a?.(M)})),c.push(P.diagramChange$.subscribe(()=>{const M=i.export(P.model);l?.(M)}))};I.useEffect(()=>{n.current&&(d.current||(j(n.current),d.current=!0,e?.(P)))},[n.current]),I.useEffect(()=>{n.current&&(T(!0),j(n.current),e?.(P))},[s]),I.useEffect(()=>{t&&r.import(P.model,t)},[t]);const F=(Y,M,C)=>{if(b!==void 0&&M.editable!==!1&&!wt(Y.getValue(M.name),C)){Y.setValue(M.name,C);const R=new vt(b.propertySet,void 0);R.setValues(b.getValues()),R.rootElement=b.rootElement,v.valueSet=R,b.rootElement.valueSet=R,P.propertyEditorChanges$?.next()}};return p.jsx("daga-diagram",{children:p.jsx(ui.Provider,{value:s,children:p.jsx(xt.Provider,{value:P,children:p.jsxs("daga-diagram-editor",{children:[p.jsx("div",{className:"daga-append-to",ref:n}),p.jsxs(xt.Provider,{value:P,children:[s.components?.buttons!==void 0&&s.components?.buttons?.enabled!==!1&&p.jsx(Ii,{location:s.components?.buttons?.location||Bt.BottomRight,direction:s.components?.buttons?.direction||f.Top,enableAction:s.components?.buttons?.enableAction!==!1,enableFilter:s.components?.buttons?.enableFilter===!0,enableLayout:s.components?.buttons?.enableLayout===!0,enableSelection:s.components?.buttons?.enableSelection!==!1,enableZoom:s.components?.buttons?.enableZoom!==!1}),s.components?.palette!==void 0&&s.components?.palette?.enabled!==!1&&s.components?.palette?.sections&&(s.components?.palette?.sections?.length||0)>0&&p.jsx($i,{location:s.components?.palette?.location||Bt.TopLeft,direction:s.components?.palette?.direction||f.Bottom,width:s.components?.palette?.width||"12rem",height:s.components?.palette?.height,palettes:s.components?.palette?.sections||[]}),s.components?.propertyEditor!==void 0&&s.components?.propertyEditor?.enabled!==!1&&p.jsx(xi,{location:s.components?.propertyEditor?.location||Bt.TopRight,direction:s.components?.propertyEditor?.direction||f.Bottom,width:s.components?.propertyEditor?.width||"24rem",height:s.components?.propertyEditor?.height,title:h,valueSet:b,onValueChange:F}),s.components?.errors!==void 0&&s.components?.errors?.enabled!==!1&&p.jsx(mi,{})]})]})})})})};exports.DagaDiagram=Ai;
|