@metadev/daga-react 5.1.0 → 5.1.1
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 +440 -431
- package/index.js +3 -3
- package/index.mjs +854 -633
- package/package.json +50 -50
package/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require("d3");c=s(c);let l=require("rxjs"),u=require("react");u=s(u);let d=require("react/jsx-runtime");var f=function(e){return e.Bottom=`bottom`,e.Left=`left`,e.Right=`right`,e.Top=`top`,e}({}),p=function(e){return e.BottomLeft=`bottom-left`,e.BottomRight=`bottom-right`,e.TopLeft=`top-left`,e.TopRight=`top-right`,e}({}),m=function(e){return e.Left=`left`,e.Center=`center`,e.Right=`right`,e}({}),h=function(e){return e.Top=`top`,e.Center=`center`,e.Bottom=`bottom`,e}({}),g=e=>[Math.round(e[0]),Math.round(e[1])],_=(e,t,n)=>t<n?t<=e&&e<=n:n<=e&&e<=t,v=(e,t,n)=>(e-t[0])/(t[1]-t[0])*(n[1]-n[0])+n[0],y=(e,t,n,r,i,a,o)=>[(()=>{switch(a){case`start`:return r[0]+(e[0]-t[0]);case`end`:return r[1]-(t[1]-e[0]);case`middle`:{let n=(t[0]+t[1])/2,i=(r[0]+r[1])/2,a=t[1]-t[0],o=r[1]-r[0];return i+(e[0]-n)/a*o}default:return v(e[0],t,r)}})(),(()=>{switch(o){case`start`:return i[0]+(e[1]-n[0]);case`end`:return i[1]-(n[1]-e[1]);case`middle`:{let t=(n[0]+n[1])/2,r=(i[0]+i[1])/2,a=n[1]-n[0],o=i[1]-i[0];return r+(e[1]-t)/a*o}default:return v(e[1],n,i)}})()],b=(e,t)=>((e[0]-t[0])**2+(e[1]-t[1])**2)**.5,ee=(e,t)=>(_(e[0][0],t[0][0],t[1][0])||_(e[1][0],t[1][0],t[0][0])||_(t[0][0],e[0][0],e[1][0])||_(t[1][0],e[1][0],e[0][0]))&&(_(e[0][1],t[0][1],t[1][1])||_(e[1][1],t[1][1],t[0][1])||_(t[0][1],e[0][1],e[1][1])||_(t[1][1],e[1][1],e[0][1])),x=function(e){return e.Blur=`blur`,e.Change=`change`,e.Click=`click`,e.ContextMenu=`contextmenu`,e.DoubleClick=`dblclick`,e.Focus=`focus`,e.FocusIn=`focusin`,e.FocusOut=`focusout`,e.Input=`input`,e.KeyDown=`keydown`,e.KeyUp=`keyup`,e.MouseDown=`mousedown`,e.MouseEnter=`mouseenter`,e.MouseLeave=`mouseleave`,e.MouseMove=`mousemove`,e.MouseOut=`mouseout`,e.MouseOver=`mouseover`,e.MouseUp=`mouseup`,e.TouchStart=`touchstart`,e.TouchEnd=`touchend`,e.Wheel=`wheel`,e}({}),S=function(e){return e.Alt=`Alt`,e.AltGraph=`AltGraph`,e.ArrowDown=`ArrowDown`,e.ArrowLeft=`ArrowLeft`,e.ArrowRight=`ArrowRight`,e.ArrowUp=`ArrowUp`,e.Backspace=`Backspace`,e.Control=`Control`,e.Delete=`Delete`,e.End=`End`,e.Enter=`Enter`,e.Escape=`Escape`,e.Home=`Home`,e.OS=`OS`,e.PageDown=`PageDown`,e.PageUp=`PageUp`,e.Shift=`Shift`,e.Tab=`Tab`,e}({}),C=function(e){return e.Drag=`drag`,e.Start=`start`,e.End=`end`,e}({}),w=function(e){return e.Zoom=`zoom`,e.Start=`start`,e.End=`end`,e}({}),te=e=>e.replace(/([!"#$%&'()*+,\-./:;<=>?@[\\\]^`{|}])/g,`\\$1`),T=function(e){return e.Straight=`straight`,e.Bezier=`bezier`,e.Square=`square`,e}({}),ne=function(e){return e.Solid=`solid`,e.Dashed=`dashed`,e.GappedDashes=`gapped-dashes`,e.Dotted=`dotted`,e}({}),re=20,ie=(e,t,n,r,i)=>{if(typeof e==`function`)return e(t,n,r,i);if(t.length===0)return``;if(t.length===1)return`M ${t[0][0]} ${t[0][1]}`;{i||=re;let a=``,o,s;switch(e){case`straight`:a+=`M ${t[0][0]} ${t[0][1]}`;for(let e=1;e<t.length;++e)a+=` L ${t[e][0]} ${t[e][1]}`;break;case`bezier`:o=n,a+=`M ${t[0][0]} ${t[0][1]}`;for(let e=1;e<t.length;++e){if(e+1>=t.length)switch(r){case f.Bottom:s=f.Top;break;case f.Top:s=f.Bottom;break;case f.Right:s=f.Left;break;case f.Left:s=f.Right;break}else s=Math.abs(t[e][0]-t[e-1][0])<Math.abs(t[e][1]-t[e-1][1])?t[e][1]>t[e-1][1]?f.Bottom:f.Top:t[e][0]>t[e-1][0]?f.Right:f.Left;if(o!==void 0){let n=``,r=``,i=(Math.abs(t[e][0]-t[e-1][0])+Math.abs(t[e][1]-t[e-1][1]))/2;switch(o){case f.Bottom:n=`${t[e-1][0]} ${t[e-1][1]+i}`;break;case f.Top:n=`${t[e-1][0]} ${t[e-1][1]-i}`;break;case f.Right:n=`${t[e-1][0]+i} ${t[e-1][1]}`;break;case f.Left:n=`${t[e-1][0]-i} ${t[e-1][1]}`;break}if(s!==void 0){switch(s){case f.Top:r=`${t[e][0]} ${t[e][1]+i}`;break;case f.Bottom:r=`${t[e][0]} ${t[e][1]-i}`;break;case f.Left:r=`${t[e][0]+i} ${t[e][1]}`;break;case f.Right:r=`${t[e][0]-i} ${t[e][1]}`;break}a+=` C ${n} ${r} ${t[e][0]} ${t[e][1]}`}else a+=` Q ${n} ${t[e][0]} ${t[e][1]}`}else if(s!==void 0){let n=``,r=(Math.abs(t[e][0]-t[e-1][0])+Math.abs(t[e][1]-t[e-1][1]))/2;switch(s){case f.Top:n=`${t[e][0]} ${t[e][1]+r}`;break;case f.Bottom:n=`${t[e][0]} ${t[e][1]-r}`;break;case f.Left:n=`${t[e][0]+r} ${t[e][1]}`;break;case f.Right:n=`${t[e][0]-r} ${t[e][1]}`;break}a+=` Q ${n} ${t[e][0]} ${t[e][1]}`}else a+=` L ${t[e][0]} ${t[e][1]}`;o=s}break;case`square`:o=n,a+=`M ${t[0][0]} ${t[0][1]}`;for(let e=1;e<t.length;++e){if(e+1>=t.length)switch(r){case f.Bottom:s=f.Top;break;case f.Top:s=f.Bottom;break;case f.Right:s=f.Left;break;case f.Left:s=f.Right;break}switch(o){case f.Bottom:switch(s){case f.Bottom:t[e][1]>t[e-1][1]?(t[e][0]===t[e-1][0]?a+=` V ${t[e][1]}`:(a+=` V ${(t[e][1]+t[e-1][1])/2}`,a+=` H ${t[e][0]}`,a+=` V ${t[e][1]}`),o=s):t[e][0]>t[e-1][0]?(a+=` V ${t[e-1][1]+i}`,a+=` H ${Math.max(t[e-1][0],t[e][0])+i}`,a+=` V ${t[e][1]-i}`,a+=` H ${t[e][0]}`,a+=` V ${t[e][1]}`):(a+=` V ${t[e-1][1]+i}`,a+=` H ${Math.min(t[e-1][0],t[e][0])-i}`,a+=` V ${t[e][1]-i}`,a+=` H ${t[e][0]}`,a+=` V ${t[e][1]}`);break;case f.Top:a+=` V ${Math.max(t[e-1][1],t[e][1])+i}`,a+=` H ${t[e][0]}`,a+=` V ${t[e][1]}`;break;case f.Left:t[e][1]>t[e-1][1]+i?t[e][0]<t[e-1][0]-i?(a+=` V ${t[e][1]}`,a+=` H ${t[e][0]}`):(a+=` V ${(t[e-1][1]+t[e][1])/2}`,a+=` H ${t[e][0]+i}`,a+=` V ${t[e][1]}`,a+=` H ${t[e][0]}`):t[e][0]<t[e-1][0]-i?(a+=` V ${t[e-1][1]+i}`,a+=` H ${(t[e-1][0]+t[e][0])/2}`,a+=` V ${t[e][1]}`,a+=` H ${t[e][0]}`):(a+=` V ${t[e-1][1]+i}`,a+=` H ${t[e][0]+i}`,a+=` V ${t[e][1]}`,a+=` H ${t[e][0]}`);break;case f.Right:t[e][1]>t[e-1][1]+i?t[e][0]>t[e-1][0]+i?(a+=` V ${t[e][1]}`,a+=` H ${t[e][0]}`):(a+=` V ${(t[e-1][1]+t[e][1])/2}`,a+=` H ${t[e][0]-i}`,a+=` V ${t[e][1]}`,a+=` H ${t[e][0]}`):t[e][0]>t[e-1][0]+i?(a+=` V ${t[e-1][1]+i}`,a+=` H ${(t[e-1][0]+t[e][0])/2}`,a+=` V ${t[e][1]}`,a+=` H ${t[e][0]}`):(a+=` V ${t[e-1][1]+i}`,a+=` H ${t[e][0]-i}`,a+=` V ${t[e][1]}`,a+=` H ${t[e][0]}`);break;default:t[e][1]<t[e-1][1]+i?(a+=` V ${t[e-1][1]+i}`,t[e][0]!==t[e-1][0]&&(a+=` H ${t[e][0]}`),a+=` V ${t[e][1]}`,o=f.Top):(a+=` V ${t[e][1]}`,o=f.Bottom,t[e][0]!==t[e-1][0]&&(a+=` H ${t[e][0]}`,o=t[e][0]>t[e-1][0]?f.Right:f.Left));break}break;case f.Top:switch(s){case f.Top:t[e][1]<t[e-1][1]?(t[e][0]===t[e-1][0]?a+=` V ${t[e][1]}`:(a+=` V ${(t[e][1]+t[e-1][1])/2}`,a+=` H ${t[e][0]}`,a+=` V ${t[e][1]}`),o=s):t[e][0]<t[e-1][0]?(a+=` V ${t[e-1][1]-i}`,a+=` H ${Math.min(t[e-1][0],t[e][0])-i}`,a+=` V ${t[e][1]+i}`,a+=` H ${t[e][0]}`,a+=` V ${t[e][1]}`):(a+=` V ${t[e-1][1]-i}`,a+=` H ${Math.max(t[e-1][0],t[e][0])+i}`,a+=` V ${t[e][1]+i}`,a+=` H ${t[e][0]}`,a+=` V ${t[e][1]}`);break;case f.Bottom:a+=` V ${Math.min(t[e-1][1],t[e][1])-i}`,a+=` H ${t[e][0]}`,a+=` V ${t[e][1]}`;break;case f.Right:t[e][1]<t[e-1][1]-i?t[e][0]>t[e-1][0]+i?(a+=` V ${t[e][1]}`,a+=` H ${t[e][0]}`):(a+=` V ${(t[e-1][1]+t[e][1])/2}`,a+=` H ${t[e][0]-i}`,a+=` V ${t[e][1]}`,a+=` H ${t[e][0]}`):t[e][0]>t[e-1][0]+i?(a+=` V ${t[e-1][1]-i}`,a+=` H ${(t[e-1][0]+t[e][0])/2}`,a+=` V ${t[e][1]}`,a+=` H ${t[e][0]}`):(a+=` V ${t[e-1][1]-i}`,a+=` H ${t[e][0]-i}`,a+=` V ${t[e][1]}`,a+=` H ${t[e][0]}`);break;case f.Left:t[e][1]<t[e-1][1]-i?t[e][0]<t[e-1][0]-i?(a+=` V ${t[e][1]}`,a+=` H ${t[e][0]}`):(a+=` V ${(t[e-1][1]+t[e][1])/2}`,a+=` H ${t[e][0]+i}`,a+=` V ${t[e][1]}`,a+=` H ${t[e][0]}`):t[e][0]<t[e-1][0]-i?(a+=` V ${t[e-1][1]-i}`,a+=` H ${(t[e-1][0]+t[e][0])/2}`,a+=` V ${t[e][1]}`,a+=` H ${t[e][0]}`):(a+=` V ${t[e-1][1]-i}`,a+=` H ${t[e][0]+i}`,a+=` V ${t[e][1]}`,a+=` H ${t[e][0]}`);break;default:t[e][1]>t[e-1][1]-i?(a+=` V ${t[e-1][1]-i}`,t[e][0]!==t[e-1][0]&&(a+=` H ${t[e][0]}`),a+=` V ${t[e][1]}`,o=f.Bottom):(a+=` V ${t[e][1]}`,o=f.Top,t[e][0]!==t[e-1][0]&&(a+=` H ${t[e][0]}`,o=t[e][0]>t[e-1][0]?f.Right:f.Left));break}break;case f.Left:switch(s){case f.Left:t[e][0]<t[e-1][0]?(t[e][1]===t[e-1][1]?a+=` H ${t[e][0]}`:(a+=` H ${(t[e][0]+t[e-1][0])/2}`,a+=` V ${t[e][1]}`,a+=` H ${t[e][0]}`),o=s):t[e][1]<t[e-1][1]?(a+=` H ${t[e-1][0]-i}`,a+=` V ${Math.min(t[e-1][1],t[e][1])-i}`,a+=` H ${t[e][0]+i}`,a+=` V ${t[e][1]}`,a+=` H ${t[e][0]}`):(a+=` H ${t[e-1][0]-i}`,a+=` V ${Math.max(t[e-1][1],t[e][1])+i}`,a+=` H ${t[e][0]+i}`,a+=` V ${t[e][1]}`,a+=` H ${t[e][0]}`);break;case f.Right:a+=` H ${Math.min(t[e-1][0],t[e][0])-i}`,a+=` V ${t[e][1]}`,a+=` H ${t[e][0]}`;break;case f.Bottom:t[e][0]<t[e-1][0]-i?t[e][1]>t[e-1][1]+i?(a+=` H ${t[e][0]}`,a+=` V ${t[e][1]}`):(a+=` H ${(t[e-1][0]+t[e][0])/2}`,a+=` V ${t[e][1]-i}`,a+=` H ${t[e][0]}`,a+=` V ${t[e][1]}`):t[e][1]>t[e-1][1]+i?(a+=` H ${t[e-1][0]-i}`,a+=` V ${(t[e-1][1]+t[e][1])/2}`,a+=` H ${t[e][0]}`,a+=` V ${t[e][1]}`):(a+=` H ${t[e-1][0]-i}`,a+=` V ${t[e][1]-i}`,a+=` H ${t[e][0]}`,a+=` V ${t[e][1]}`);break;case f.Top:t[e][0]<t[e-1][0]-i?t[e][1]<t[e-1][1]-i?(a+=` H ${t[e][0]}`,a+=` V ${t[e][1]}`):(a+=` H ${(t[e-1][0]+t[e][0])/2}`,a+=` V ${t[e][1]+i}`,a+=` H ${t[e][0]}`,a+=` V ${t[e][1]}`):t[e][1]<t[e-1][1]-i?(a+=` H ${t[e-1][0]-i}`,a+=` V ${(t[e-1][1]+t[e][1])/2}`,a+=` H ${t[e][0]}`,a+=` V ${t[e][1]}`):(a+=` H ${t[e-1][0]-i}`,a+=` V ${t[e][1]+i}`,a+=` H ${t[e][0]}`,a+=` V ${t[e][1]}`);break;default:t[e][0]>t[e-1][0]-i?(a+=` H ${t[e-1][0]-i}`,t[e][1]!==t[e-1][1]&&(a+=` V ${t[e][1]}`),a+=` H ${t[e][0]}`,o=f.Right):(a+=` H ${t[e][0]}`,o=f.Left,t[e][1]!==t[e-1][1]&&(a+=` V ${t[e][1]}`,o=t[e][1]>t[e-1][1]?f.Bottom:f.Top));break}break;case f.Right:switch(s){case f.Right:t[e][0]>t[e-1][0]?(t[e][1]===t[e-1][1]?a+=` H ${t[e][0]}`:(a+=` H ${(t[e][0]+t[e-1][0])/2}`,a+=` V ${t[e][1]}`,a+=` H ${t[e][0]}`),o=s):t[e][1]>t[e-1][1]?(a+=` H ${t[e-1][0]+i}`,a+=` V ${Math.max(t[e-1][1],t[e][1])+i}`,a+=` H ${t[e][0]-i}`,a+=` V ${t[e][1]}`,a+=` H ${t[e][0]}`):(a+=` H ${t[e-1][0]+i}`,a+=` V ${Math.min(t[e-1][1],t[e][1])-i}`,a+=` H ${t[e][0]-i}`,a+=` V ${t[e][1]}`,a+=` H ${t[e][0]}`);break;case f.Left:a+=` H ${Math.max(t[e-1][0],t[e][0])+i}`,a+=` V ${t[e][1]}`,a+=` H ${t[e][0]}`;break;case f.Top:t[e][0]>t[e-1][0]+i?t[e][1]<t[e-1][1]-i?(a+=` H ${t[e][0]}`,a+=` V ${t[e][1]}`):(a+=` H ${(t[e-1][0]+t[e][0])/2}`,a+=` V ${t[e][1]+i}`,a+=` H ${t[e][0]}`,a+=` V ${t[e][1]}`):t[e][1]<t[e-1][1]-i?(a+=` H ${t[e-1][0]+i}`,a+=` V ${(t[e-1][1]+t[e][1])/2}`,a+=` H ${t[e][0]}`,a+=` V ${t[e][1]}`):(a+=` H ${t[e-1][0]+i}`,a+=` V ${t[e][1]+i}`,a+=` H ${t[e][0]}`,a+=` V ${t[e][1]}`);break;case f.Bottom:t[e][0]>t[e-1][0]+i?t[e][1]>t[e-1][1]+i?(a+=` H ${t[e][0]}`,a+=` V ${t[e][1]}`):(a+=` H ${(t[e-1][0]+t[e][0])/2}`,a+=` V ${t[e][1]-i}`,a+=` H ${t[e][0]}`,a+=` V ${t[e][1]}`):t[e][1]>t[e-1][1]+i?(a+=` H ${t[e-1][0]+i}`,a+=` V ${(t[e-1][1]+t[e][1])/2}`,a+=` H ${t[e][0]}`,a+=` V ${t[e][1]}`):(a+=` H ${t[e-1][0]+i}`,a+=` V ${t[e][1]-i}`,a+=` H ${t[e][0]}`,a+=` V ${t[e][1]}`);break;default:t[e][0]<t[e-1][0]+i?(a+=` H ${t[e-1][0]+i}`,t[e][1]!==t[e-1][1]&&(a+=` V ${t[e][1]}`),a+=` H ${t[e][0]}`,o=f.Left):(a+=` H ${t[e][0]}`,o=f.Right,t[e][1]!==t[e-1][1]&&(a+=` V ${t[e][1]}`,o=t[e][1]>t[e-1][1]?f.Bottom:f.Top));break}break;default:t[e][0]!==t[e-1][0]&&(a+=` H ${t[e][0]}`,o=t[e][0]>t[e-1][0]?f.Right:f.Left),t[e][1]!==t[e-1][1]&&(a+=` V ${t[e][1]}`,o=t[e][1]>t[e-1][1]?f.Bottom:f.Top)}}break}return a}},ae=(e,t)=>{switch(e){case`dotted`:return`${t}`;case`dashed`:return`${4*t} ${t}`;case`gapped-dashes`:return`${4*t} ${4*t}`;default:return`none`}},E=(e,t)=>{let n=e.indexOf(t);return n>=0&&e.splice(n,1),e},oe=function(e){return e.Ellipse=`ellipse`,e.Empty=`empty`,e.Folder=`folder`,e.Hexagon=`hexagon`,e.Octagon=`octagon`,e.Pill=`pill`,e.Rectangle=`rectangle`,e.Rhombus=`rhombus`,e.RoundedRectangle=`rounded-rectangle`,e.StickyNote=`sticky-note`,e}({}),se=(e,t,n,r,i)=>{if(typeof e==`function`)return e(t,n,r,i);switch(e){case`ellipse`:return ce(t,n,r,i);case`empty`:return le();case`folder`:return ue(t,n,r,i);case`hexagon`:return de(t,n,r,i);case`octagon`:return fe(t,n,r,i);case`pill`:return pe(t,n,r,i);case`rectangle`:return me(t,n,r,i);case`rhombus`:return he(t,n,r,i);case`rounded-rectangle`:return ge(t,n,r,i);case`sticky-note`:return _e(t,n,r,i);default:return me(t,n,r,i)}},ce=(e,t,n,r)=>`M ${e+n/2} ${t} A ${n/2} ${r/2} 0 0 0 ${e+n/2} ${t+r} A ${n/2} ${r/2} 0 1 0 ${e+n/2} ${t} Z`,le=()=>`Z`,ue=(e,t,n,r)=>`M ${e} ${t} L ${e+n/3} ${t} L ${e+n/2} ${t+r/6} L ${e+n} ${t+r/6} L ${e+n} ${t+r} L ${e} ${t+r} Z`,de=(e,t,n,r)=>`M ${e+n/4} ${t} L ${e+3*n/4} ${t} L ${e+n} ${t+r/2} L ${e+3*n/4} ${t+r} L ${e+n/4} ${t+r} L ${e} ${t+r/2} Z`,fe=(e,t,n,r)=>`M ${e+n/4} ${t} L ${e+3*n/4} ${t} L ${e+n} ${t+r/4} L ${e+n} ${t+3*r/4} L ${e+3*n/4} ${t+r} L ${e+n/4} ${t+r} L ${e} ${t+3*r/4} L ${e} ${t+r/4} L ${e+n/4} ${t} Z`,pe=(e,t,n,r)=>r<n?`M ${e+r/2} ${t} L ${e+n-r/2} ${t} A ${r/2} ${r/2} 0 0 1 ${e+n} ${t+r/2} A ${r/2} ${r/2} 0 0 1 ${e+n-r/2} ${t+r} L ${e+r/2} ${t+r} A ${r/2} ${r/2} 0 0 1 ${e} ${t+r/2} A ${r/2} ${r/2} 0 0 1 ${e+r/2} ${t} Z`:r>n?`M ${e} ${t+n/2} L ${e} ${t+r-n/2} A ${n/2} ${n/2} 0 0 0 ${e+n/2} ${t+r} A ${n/2} ${n/2} 0 0 0 ${e+n} ${t+r-n/2} L ${e+n} ${t+n/2} A ${n/2} ${n/2} 0 0 0 ${e+n/2} ${t} A ${n/2} ${n/2} 0 0 0 ${e} ${t+n/2} Z`:ce(e,t,n,r),me=(e,t,n,r)=>`M ${e} ${t} L ${e+n} ${t} L ${e+n} ${t+r} L ${e} ${t+r} Z`,he=(e,t,n,r)=>`M ${e+n/2} ${t} L ${e+n} ${t+r/2} L ${e+n/2} ${t+r} L ${e} ${t+r/2} Z`,ge=(e,t,n,r)=>`M ${e+n/4} ${t} L ${e+3*n/4} ${t} A ${n/4} ${r/4} 0 0 1 ${e+n} ${t+r/4} L ${e+n} ${t+3*r/4} A ${n/4} ${r/4} 0 0 1 ${e+3*n/4} ${t+r} L ${e+n/4} ${t+r} A ${n/4} ${r/4} 0 0 1 ${e} ${t+3*r/4} L ${e} ${t+r/4} A ${n/4} ${r/4} 0 0 1 ${e+n/4} ${t} Z`,_e=(e,t,n,r)=>`M ${e} ${t} L ${e+3*n/4} ${t} L ${e+3*n/4} ${t+r/4} L ${e+3*n/4} ${t} L ${e+n} ${t+r/4} L ${e+3*n/4} ${t+r/4} L ${e+n} ${t+r/4} L ${e+n} ${t+r} L ${e} ${t+r} Z`,D=function(e){return e.AllScroll=`all-scroll`,e.Auto=`auto`,e.Crosshair=`crosshair`,e.EWResize=`ew-resize`,e.Grab=`grab`,e.Grabbing=`grabbing`,e.Move=`move`,e.NoDrop=`no-drop`,e.NSResize=`ns-resize`,e.NotAllowed=`not-allowed`,e.ZoomIn=`zoom-in`,e.ZoomOut=`zoom-out`,e}({}),ve=e=>Math.max(...e.split(`
|
|
2
|
-
`).map(e=>e.length)),ye=e=>e.match(/\n/g)?.length||0,O=[];for(let e=0;e<256;++e)O.push((e+256).toString(16).slice(1));function be(e,t=0){return(O[e[t+0]]+O[e[t+1]]+O[e[t+2]]+O[e[t+3]]+`-`+O[e[t+4]]+O[e[t+5]]+`-`+O[e[t+6]]+O[e[t+7]]+`-`+O[e[t+8]]+O[e[t+9]]+`-`+O[e[t+10]]+O[e[t+11]]+O[e[t+12]]+O[e[t+13]]+O[e[t+14]]+O[e[t+15]]).toLowerCase()}var xe=new Uint8Array(16);function Se(){return crypto.getRandomValues(xe)}function Ce(e,t,n){return!t&&!e&&crypto.randomUUID?crypto.randomUUID():we(e,t,n)}function we(e,t,n){e||={};let r=e.random??e.rng?.()??Se();if(r.length<16)throw Error(`Random bytes length must be >= 16`);if(r[6]=r[6]&15|64,r[8]=r[8]&63|128,t){if(n||=0,n<0||n+16>t.length)throw RangeError(`UUID byte range ${n}:${n+15} is out of buffer bounds`);for(let e=0;e<16;++e)t[n+e]=r[e];return t}return be(r)}var Te=e=>{if(typeof e!=`object`||!e)return e;if(Array.isArray(e))return e.map(Te);let t={};for(let n of Object.entries(e))t[n[0]]=Te(n[1]);return t},k=e=>{let{selected:t,highlighted:n,selectedAndHighlighted:r,...i}=e,a=i;return{defaultLook:a,selectedLook:{...a,...t},highlightedLook:{...a,...n},selectedAndHighlightedLook:{...a,...n,...t,...r}}},Ee=class{constructor(){this.entities=[],this.entityMap={}}get length(){return this.size()}all(){return[...this.entities]}add(e){this.entityMap[e.id]===void 0&&(this.entityMap[e.id]=e,this.entities.push(e))}clear(){for(;this.entities.length>0;)this.remove(this.entities[0].id)}contains(e){return this.entityMap[e]!==void 0}count(e){return this.entities.filter(e).length}filter(e){return this.entities.filter(e)}find(e){return this.entities.find(e)}get(e){return this.entityMap[e]}map(e){return this.entities.map(e)}remove(e){let t=this.get(e);t!==void 0&&(delete this.entityMap[e],E(this.entities,t))}size(){return this.entities.length}*[Symbol.iterator](){for(let e of this.entities)yield e}},De=class{get id(){return this._id}get highlighted(){return this.model.canvas?.userHighlight?.contains(this.id)||!1}get selected(){return this.model.canvas?.userSelection?.contains(this.id)||!1}constructor(e,t){this.selfRemoved=!1,this.selfRemovedTimestamp=null,this.model=e,this._id=t}select(){return this.model.canvas?.selectCanvasView()?.select(`[id='${te(this.id)}']`)}},A=class extends Ee{all(e=!1){return e?super.all():super.filter(e=>!e.removed)}contains(e,t=!1){return t?super.contains(e):super.contains(e)&&!this.entityMap[e].removed}count(e,t=!1){return t?super.count(e):super.count((t,n,r)=>e(t,n,r)&&!t.removed)}filter(e,t=!1){return t?super.filter(e):super.filter((t,n,r)=>e(t,n,r)&&!t.removed)}find(e,t=!1){return t?super.find(e):super.find((t,n,r)=>e(t,n,r)&&!t.removed)}get(e,t=!1){return t||this.contains(e)?super.get(e):void 0}map(e,t=!1){return t?super.map(e):super.filter(e=>!e.removed).map(e)}remove(e){let t=this.get(e,!0);t!==void 0&&(delete this.entityMap[e],E(this.entities,t))}size(e=!1){return e?super.size():super.filter(e=>!e.removed).length}*[Symbol.iterator](e=!1){if(e)for(let e of this.entities)yield e;else for(let e of this.entities.filter(e=>!e.removed))yield e}},Oe=class{constructor(e,t,n,r,i,a,o){this.name=e,this.label=t,this.type=n,this.defaultValue=r,this.basic=i,this.editable=a,this.rootAttribute=o,this.options=void 0,this.properties=void 0}},j=function(e){return e.Boolean=`boolean`,e.Color=`color`,e.Date=`date`,e.Datetime=`datetime`,e.Number=`number`,e.Object=`object`,e.Option=`option`,e.OptionList=`option-list`,e.OptionSet=`option-set`,e.Text=`text`,e.TextArea=`text-area`,e.TextList=`text-list`,e.TextSet=`text-set`,e.TextMap=`text-map`,e.Time=`time`,e.Url=`url`,e}({}),ke=class{constructor(e=[]){this.propertyList=e,this.propertyMap={};for(let e of this.propertyList)this.propertyMap[e.name]=e}getProperty(e){return this.propertyMap[e]}hasProperty(e){return this.propertyMap[e]!==void 0}hasProperties(){return this.propertyList.length>0}};function Ae(e,t){return!t||e[0]>t[0]?!0:e[0]===t[0]?e[1]>=t[1]:!1}var je=e=>e==null||e===``||e instanceof Array&&e.length===0||e instanceof Object&&Object.keys(e).length===0,Me=(e,t)=>e===t||JSON.stringify(e)===JSON.stringify(t),Ne=(e,t,n)=>{let r={},i={};for(let a in n.propertySet.propertyMap)if(n.propertySet.propertyMap[a].type===j.Object){let o=Ne(e[a],t[a],n.getSubValueSet(a));Object.keys(o[0]).length>0&&Object.keys(o[1]).length>0&&(r[a]=o[0],i[a]=o[1])}else Me(e[a],t[a])||(r[a]=e[a],i[a]=t[a]);return[r,i]},Pe=e=>e!=null&&e.constructor===Object,Fe=class e{constructor(e,t){this.displayedProperties=[],this.hiddenProperties=[],this.values={},this.valueSets={},this.ownTimestamps={},this.propertySet=e,this.rootElement=t,this.resetValues()}getRootElementValue(e){if(this.rootElement){if(typeof e==`string`)return this.rootElement[e];if(Array.isArray(e)&&e.length>0){let t=this.rootElement;for(let n of e){if(t==null)return;t=t[n]}return t}}}setRootElementValue(e,t){if(this.rootElement){if(typeof e==`string`&&(this.rootElement[e]=t),Array.isArray(e)&&e.length>0){let n=this.rootElement;for(let t=0;t<e.length-1;++t){let r=e[t];if(n==null)return;n=n[r]}if(n==null)return;n[e[e.length-1]]=t}typeof this.rootElement.updateInView==`function`&&this.rootElement.updateInView()}}getValue(e){let t=this.propertySet.getProperty(e)?.rootAttribute;return t!=null&&(this.values[e]=this.getRootElementValue(t)),this.propertySet.getProperty(e).type===j.Object?this.valueSets[e].getValues():this.values[e]}getValues(){let e={};for(let t in this.propertySet.propertyMap)this.propertySet.getProperty(t).type===j.Object?e[t]=this.valueSets[t].getValues():e[t]=this.getValue(t);return e}getValuesForKeys(e){let t={};for(let n in e)this.propertySet.getProperty(n).type===j.Object?t[n]=this.valueSets[n].getValuesForKeys(e[n]):t[n]=this.getValue(n);return t}getTimestamps(){let e={};for(let t in this.propertySet.propertyMap)if(this.propertySet.getProperty(t).type===j.Object)e[t]=this.valueSets[t].getTimestamps();else{let n=this.ownTimestamps[t];n&&(e[t]=n)}return e}hasValue(e){return!je(this.getValue(e))}hasSetValue(e){let t=this.getValue(e),n=this.propertySet.getProperty(e);return n&&n.type===j.Object?this.getSubValueSet(e).hasAnySetValue():!je(t)&&!Me(t,n?.defaultValue)}hasAnySetValue(){for(let e of this.propertySet.propertyList)if(this.hasSetValue(e.name))return!0;return!1}setValue(e,t){let n=this.propertySet.getProperty(e);if(n){n.type===j.Object?this.valueSets[e].setValues(t):(this.values[e]=t,Me(t,n.defaultValue)||this.displayProperty(n));let r=n.rootAttribute;r!=null&&this.setRootElementValue(r,t)}}setValues(e){this.resetValues();for(let t in e)this.propertySet.getProperty(t).type===j.Object?this.valueSets[t].setValues(e[t]):this.setValue(t,e[t])}setTimestamps(e){this.ownTimestamps={};for(let t in e)this.propertySet.getProperty(t).type===j.Object?this.valueSets[t].setTimestamps(e[t]):this.ownTimestamps[t]=e[t]}overwriteValues(e){for(let t in e)this.propertySet.getProperty(t).type===j.Object?this.valueSets[t].overwriteValues(e[t]):this.setValue(t,e[t])}overwriteValuesLww(e,t){for(let n in e)this.propertySet.getProperty(n).type===j.Object?this.valueSets[n].overwriteValuesLww(e[n],t):Ae(t,this.ownTimestamps[n])&&(this.setValue(n,e[n]),this.ownTimestamps[n]=t)}resetValues(){this.displayedProperties=[],this.hiddenProperties=[],this.ownTimestamps={};for(let e in this.propertySet.propertyMap){let t=this.propertySet.getProperty(e),n=t.rootAttribute;t.type===j.Object?this.valueSets[e]=this.constructSubValueSet(e):this.values[e]=Te(t.defaultValue),n!=null&&t.defaultValue!==void 0&&!Me(this.getRootElementValue(n),t.defaultValue)&&this.setRootElementValue(n,this.values[e]),t.basic===!1?this.hiddenProperties.push(t):this.displayedProperties.push(t)}}constructSubValueSet(t){let n=this.propertySet.getProperty(t),r=new e(new ke(n.properties),this.rootElement);return r.overwriteValues(Te(n.defaultValue)),r}getSubValueSet(e){return this.valueSets[e]}displayProperty(e){this.displayedProperties.includes(e)||(this.displayedProperties.push(e),E(this.hiddenProperties,e))}hideProperty(e){this.hiddenProperties.includes(e)||(this.hiddenProperties.push(e),E(this.displayedProperties,e))}},M={name:``,label:null,look:{lookType:`connection-look`,color:`#000000`,thickness:1,shape:T.Straight,style:ne.Solid,selected:{color:`#AA00AA`},highlighted:{thickness:2}},startMarkerLook:void 0,endMarkerLook:void 0,startTypes:[],endTypes:[],properties:[]},Ie=class{constructor(e){let t={...M,...e};this.id=t.id,this.name=t.name,this.label=t.label;let n=k(t.look);if(this.defaultLook=n.defaultLook,this.selectedLook=n.selectedLook,this.highlightedLook=n.highlightedLook,this.selectedAndHighlightedLook=n.selectedAndHighlightedLook,t.startMarkerLook!==void 0){let e=k(t.startMarkerLook);this.defaultStartMarkerLook=e.defaultLook,this.selectedStartMarkerLook=e.selectedLook,this.highlightedStartMarkerLook=e.highlightedLook,this.selectedAndHighlightedStartMarkerLook=e.selectedAndHighlightedLook}else this.defaultStartMarkerLook=null,this.selectedStartMarkerLook=null,this.highlightedStartMarkerLook=null,this.selectedAndHighlightedStartMarkerLook=null;if(t.endMarkerLook!==void 0){let e=k(t.endMarkerLook);this.defaultEndMarkerLook=e.defaultLook,this.selectedEndMarkerLook=e.selectedLook,this.highlightedEndMarkerLook=e.highlightedLook,this.selectedAndHighlightedEndMarkerLook=e.selectedAndHighlightedLook}else this.defaultEndMarkerLook=null,this.selectedEndMarkerLook=null,this.highlightedEndMarkerLook=null,this.selectedAndHighlightedEndMarkerLook=null;this.startTypes=t.startTypes,this.endTypes=t.endTypes,this.propertySet=new ke(t.properties)}canStartFromType(e){return this.startTypes.indexOf(e)>=0}canFinishOnType(e){return this.endTypes.indexOf(e)>=0}},N=class extends De{get type(){return this._type}set type(e){e!==this._type&&(this._type=e,this.valueSet&&=new Fe(e.propertySet,this),this.model.canvas?.userSelection?.openInPropertyEditor(this,!1),this.updateInView())}get typeString(){return this.type.id}set typeString(e){if(e!==this.type.id){let t=this.model.connections.types.get(e);t&&(this.type=t)}}get name(){return this.middleLabel}set name(e){this.middleLabel=e}get look(){return this.selected?this.highlighted?this._selectedAndHighlightedLook===void 0?this.type.selectedAndHighlightedLook:this._selectedAndHighlightedLook:this._selectedLook===void 0?this.type.selectedLook:this._selectedLook:this.highlighted?this._highlightedLook===void 0?this.type.highlightedLook:this._highlightedLook:this._defaultLook===void 0?this.type.defaultLook:this._defaultLook}set look(e){this.lookConfig=e}get lookConfig(){return this._lookConfig}set lookConfig(e){if(this._lookConfig=e,e){let t=k(e);this._defaultLook={...this._defaultLook,...t.defaultLook},this._selectedLook={...this._selectedLook,...t.selectedLook},this._highlightedLook={...this._highlightedLook,...t.highlightedLook},this._selectedAndHighlightedLook={...this._selectedAndHighlightedLook,...t.selectedAndHighlightedLook}}else this._defaultLook=e,this._selectedLook=e,this._highlightedLook=e,this._selectedAndHighlightedLook=e}get startMarkerLook(){return this.selected?this.highlighted?this._selectedAndHighlightedStartMarkerLook===void 0?this.type.selectedAndHighlightedStartMarkerLook:this._selectedAndHighlightedStartMarkerLook:this._selectedStartMarkerLook===void 0?this.type.selectedStartMarkerLook:this._selectedStartMarkerLook:this.highlighted?this._highlightedStartMarkerLook===void 0?this.type.highlightedStartMarkerLook:this._highlightedStartMarkerLook:this._defaultStartMarkerLook===void 0?this.type.defaultStartMarkerLook:this._defaultStartMarkerLook}set startMarkerLook(e){this.startMarkerLookConfig=e}get startMarkerLookConfig(){return this._startMarkerLookConfig}set startMarkerLookConfig(e){if(this._startMarkerLookConfig=e,e){let t=k(e);this._defaultStartMarkerLook={...this._defaultStartMarkerLook,...t.defaultLook},this._selectedStartMarkerLook={...this._selectedStartMarkerLook,...t.selectedLook},this._highlightedStartMarkerLook={...this._highlightedStartMarkerLook,...t.highlightedLook},this._selectedAndHighlightedStartMarkerLook={...this._selectedAndHighlightedStartMarkerLook,...t.selectedAndHighlightedLook}}else this._defaultStartMarkerLook=e,this._selectedStartMarkerLook=e,this._highlightedStartMarkerLook=e,this._selectedAndHighlightedStartMarkerLook=e}get endMarkerLook(){return this.selected?this.highlighted?this._selectedAndHighlightedEndMarkerLook===void 0?this.type.selectedAndHighlightedEndMarkerLook:this._selectedAndHighlightedEndMarkerLook:this._selectedEndMarkerLook===void 0?this.type.selectedEndMarkerLook:this._selectedEndMarkerLook:this.highlighted?this._highlightedEndMarkerLook===void 0?this.type.highlightedEndMarkerLook:this._highlightedEndMarkerLook:this._defaultEndMarkerLook===void 0?this.type.defaultEndMarkerLook:this._defaultEndMarkerLook}set endMarkerLook(e){this.endMarkerLookConfig=e}get endMarkerLookConfig(){return this._endMarkerLookConfig}set endMarkerLookConfig(e){if(this._endMarkerLookConfig=e,e){let t=k(e);this._defaultEndMarkerLook={...this._defaultEndMarkerLook,...t.defaultLook},this._selectedEndMarkerLook={...this._selectedEndMarkerLook,...t.selectedLook},this._highlightedEndMarkerLook={...this._highlightedEndMarkerLook,...t.highlightedLook},this._selectedAndHighlightedEndMarkerLook={...this._selectedAndHighlightedEndMarkerLook,...t.selectedAndHighlightedLook}}else this._defaultEndMarkerLook=e,this._selectedEndMarkerLook=e,this._highlightedEndMarkerLook=e,this._selectedAndHighlightedEndMarkerLook=e}constructor(e,t,n,r,i){if(e.connections.get(i)!==void 0)throw Error(`DiagramConnection with id "${i}" already exists`);if(!i)throw Error(`DiagramConnection cannot have an empty or null id`);super(e,i),this.startCoords=[0,0],this.endCoords=[0,0],this.startLabel=``,this.middleLabel=``,this.endLabel=``,this.points=[],this._type=t,this.valueSet=new Fe(t.propertySet,this),this.originalData={},this.setStart(n),this.setEnd(r)}get removed(){return this.selfRemoved||this.start!==void 0&&this.start.removed||this.end!==void 0&&this.end.removed}updateInView(){this.model.canvas?.updateConnectionsInView(this.id)}raise(){this.select()?.raise(),this.start?.raise(!1),this.end?.raise(!1)}setStart(e){this.start===e?(this.startDirection=e?.direction,this.startCoords=e?.connectionPoint||[0,0]):(this.start!==void 0&&E(this.start.outgoingConnections,this),this.start=e,e!==void 0&&(e.outgoingConnections.push(this),this.startDirection=e?.direction,this.startCoords=e?.connectionPoint||[0,0])),this.updateInView()}setEnd(e){this.end===e?(this.endDirection=e?.direction,this.endCoords=e?.connectionPoint||[0,0]):(this.end!==void 0&&E(this.end.incomingConnections,this),this.end=e,e!==void 0&&(e.incomingConnections.push(this),this.endDirection=e?.direction,this.endCoords=e?.connectionPoint||[0,0])),this.updateInView()}tighten(){let e=this.model.canvas?.allowConnectionLoops||!1,t=this.model.canvas?.allowSharingPorts!==!1,n=this.model.canvas?.allowSharingBothPorts||!1,r=this.model.canvas?.tightenConnectionsAcrossPortTypes||!1;if(this.start?.rootElement&&this.end){let i=this.start.rootElement.ports.map(e=>[e,e.distanceTo(this.end.coords)]).sort((e,t)=>e[1]-t[1]).map(e=>e[0]);checkAlternativeStartPorts:for(let a of i){if(!e&&a===this.end||!a.allowsOutgoing||!r&&a.type!==this.start.type||!t&&(a.incomingConnections.filter(e=>!e.removed&&e!==this).length>0||a.outgoingConnections.filter(e=>!e.removed&&e!==this).length>0))continue checkAlternativeStartPorts;if(!n){for(let e of a.outgoingConnections.filter(e=>!e.removed))if(e!==this&&e.end===this.end)continue checkAlternativeStartPorts;for(let e of a.incomingConnections.filter(e=>!e.removed))if(e!==this&&e.start===this.end)continue checkAlternativeStartPorts}if(a===this.start)break checkAlternativeStartPorts;this.setStart(a);break checkAlternativeStartPorts}}if(this.end?.rootElement&&this.start){let i=this.end.rootElement.ports.map(e=>[e,e.distanceTo(this.start.coords)]).sort((e,t)=>e[1]-t[1]).map(e=>e[0]);checkAlternativeEndPorts:for(let a of i){if(!e&&a===this.start||!a.allowsIncoming||!r&&a.type!==this.end.type||!t&&(a.incomingConnections.filter(e=>!e.removed&&e!==this).length>0||a.outgoingConnections.filter(e=>!e.removed&&e!==this).length>0))continue checkAlternativeEndPorts;if(!n){for(let e of a.incomingConnections.filter(e=>!e.removed))if(e!==this&&e.start===this.start)continue checkAlternativeEndPorts;for(let e of a.outgoingConnections.filter(e=>!e.removed))if(e!==this&&e.end===this.start)continue checkAlternativeEndPorts}if(a===this.end)break checkAlternativeEndPorts;this.setEnd(a);break checkAlternativeEndPorts}}}getPriority(){return this.start?this.end?Math.min(this.start.getPriority(),this.end.getPriority()):this.start.getPriority():this.end?this.end.getPriority():0}},Le=class extends A{constructor(e){super(),this.types=new Ee,this.model=e}new(e,t,n,r){let i;if(e instanceof Ie)i=e;else{let t=this.types.get(e);if(t===void 0)throw TypeError(`Connection type with id '${e}' could not be found.`);i=t}let a=new N(this.model,i,t,n,r);return super.add(a),a.updateInView(),a.valueSet.resetValues(),a.start?.raise(!1),a.end?.raise(!1),a}remove(e){let t=this.get(e,!0);t&&(E(t.start?.outgoingConnections||[],t),E(t.end?.incomingConnections||[],t),super.remove(e),t.updateInView())}},Re=function(e){return e[e.OnlyWhenSelected=0]=`OnlyWhenSelected`,e}({}),P={editable:!0,margin:0,padding:0,horizontalAlign:m.Center,verticalAlign:h.Center,orientation:f.Top,multiline:!1,fit:!1,shrink:!0,look:{lookType:`field-look`,fillColor:`transparent`,fontColor:`#000000`,fontFamily:`'Wonder Unit Sans', sans-serif`,fontSize:10,fontWeight:400}},F=class extends De{get text(){return this._text}set text(e){(e==null||e?.trim()===``)&&(e=this.defaultText),this._text=e,this.updateInView(),this.fit&&this.model.canvas?.fitFieldRootInView(this.id,this.shrink)}get look(){return this.selected?this.highlighted?this.selectedAndHighlightedLook:this.selectedLook:this.highlighted?this.highlightedLook:this.defaultLook}constructor(e,t,n,r,i,a,o,s,c,l,u,d,p,m){let h=`${t?.id}_field`;if(e.fields.get(h)!==void 0)throw Error(`DiagramField for rootElement already exists`);if(super(e,h),this.textTimestamp=null,this.rootElement=t,this.coords=n,this.width=r,this.height=i,this.horizontalAlign=a,this.verticalAlign=o,this.multiline=c,!isNaN(Number(s)))this.orientation=Number(s);else switch(s){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}let g=k(l);this.defaultLook=g.defaultLook,this.selectedLook=g.selectedLook,this.highlightedLook=g.highlightedLook,this.selectedAndHighlightedLook=g.selectedAndHighlightedLook,this.defaultText=u,this._text=u,this.editable=d,this.fit=p,this.shrink=m}get removed(){return this.selfRemoved||this.rootElement!==void 0&&this.rootElement.removed}updateInView(){this.model.canvas?.updateFieldsInView(this.id)}raise(){this.select()?.raise()}move(e){this.coords=e,this.updateInView()}getPriority(){return this.rootElement?.getPriority()||0}},ze=class extends A{constructor(e){super(),this.model=e}new(e,t,n,r,i,a,o,s,c,l,u,d,f){let p=new F(this.model,e,t,n,r,i,a,o,s,c,l,u,d,f);return super.add(p),p.updateInView(),e!==void 0&&(e.label=p),p}remove(e){let t=this.get(e,!0);t&&(t.rootElement?.label!==void 0&&t.rootElement.label===t&&(t.rootElement.label=void 0),super.remove(e),t.updateInView())}},I=e=>e?.margin===null||e?.margin===void 0?P.margin:typeof e.margin==`number`?e.margin:e.margin.length===0?P.margin:e.margin.length===1||e.margin.length===2?e.margin[0]:(e.margin.length,e.margin[2]),L=e=>e?.margin===null||e?.margin===void 0?P.margin:typeof e.margin==`number`?e.margin:e.margin.length===0?P.margin:e.margin.length===1?e.margin[0]:e.margin.length===2||e.margin.length===3?e.margin[1]:e.margin[3],R=e=>e?.margin===null||e?.margin===void 0?P.margin:typeof e.margin==`number`?e.margin:e.margin.length===0?P.margin:e.margin.length===1?e.margin[0]:(e.margin.length===2||e.margin.length,e.margin[1]),z=e=>e?.margin===null||e?.margin===void 0?P.margin:typeof e.margin==`number`?e.margin:e.margin.length===0?P.margin:(e.margin.length===1||e.margin.length===2||e.margin.length,e.margin[0]),Be=e=>e?.padding===null||e?.padding===void 0?P.padding:typeof e.padding==`number`?e.padding:e.padding.length===0?P.padding:e.padding.length===1||e.padding.length===2?e.padding[0]:(e.padding.length,e.padding[2]),Ve=e=>e?.padding===null||e?.padding===void 0?P.padding:typeof e.padding==`number`?e.padding:e.padding.length===0?P.padding:e.padding.length===1?e.padding[0]:e.padding.length===2||e.padding.length===3?e.padding[1]:e.padding[3],He=e=>e?.padding===null||e?.padding===void 0?P.padding:typeof e.padding==`number`?e.padding:e.padding.length===0?P.padding:e.padding.length===1?e.padding[0]:(e.padding.length===2||e.padding.length,e.padding[1]),Ue=e=>e?.padding===null||e?.padding===void 0?P.padding:typeof e.padding==`number`?e.padding:e.padding.length===0?P.padding:(e.padding.length===1||e.padding.length===2||e.padding.length,e.padding[0]),We=class{constructor(e){this.margin=e.margin||0,this.defaultWidths=e.defaultWidths||null,this.defaultHeights=e.defaultHeights||null,this.minWidths=e.minWidths||null,this.minHeights=e.minHeights||null,this.sections=[];for(let t of e.sections){let e=[];this.sections.push(e);for(let n of t)e.push(new Ge(n))}}},Ge=class{constructor(e){this.label=e.label||null,this.ports=e.ports||[],this.priority=e.priority||0,this.resizableX=e.resizableX,this.resizableY=e.resizableY;let t=k(e.look||qe);this.defaultLook=t.defaultLook,this.selectedLook=t.selectedLook,this.highlightedLook=t.highlightedLook,this.selectedAndHighlightedLook=t.selectedAndHighlightedLook}},B=class extends De{get name(){return this.label?.text||``}set name(e){this.label&&(this.label.text=e)}get look(){return this.selected?this.highlighted?this._selectedAndHighlightedLook===void 0?this.type?.selectedAndHighlightedLook||this.node?.look:this._selectedAndHighlightedLook:this._selectedLook===void 0?this.type?.selectedLook||this.node?.look:this._selectedLook:this.highlighted?this._highlightedLook===void 0?this.type?.highlightedLook||this.node?.look:this._highlightedLook:this._defaultLook===void 0?this.type?.defaultLook||this.node?.look:this._defaultLook}set look(e){this.lookConfig=e}get lookConfig(){return this._lookConfig}set lookConfig(e){if(this._lookConfig=e,e){let t=k(e);this._defaultLook={...this._defaultLook,...t.defaultLook},this._selectedLook={...this._selectedLook,...t.selectedLook},this._highlightedLook={...this._highlightedLook,...t.highlightedLook},this._selectedAndHighlightedLook={...this._selectedAndHighlightedLook,...t.selectedAndHighlightedLook}}else this._defaultLook=e,this._selectedLook=e,this._highlightedLook=e,this._selectedAndHighlightedLook=e}constructor(e,t,n,r,i,a,o,s){if(e.sections.get(s)!==void 0)throw Error(`DiagramSection with id "${s}" already exists`);if(!s)throw Error(`DiagramSection cannot have an empty or null id`);super(e,s),this.ports=[],this.decorators=[],this.node=t,this.indexXInNode=n,this.indexYInNode=r,this.coords=i,this.width=a,this.height=o}get removed(){return this.selfRemoved||this.node!==void 0&&this.node.removed}updateInView(){this.model.canvas?.updateSectionsInView(this.id)}raise(){this.select()?.raise(),this.label&&this.label.raise();for(let e of this.ports)e.raise();for(let e of this.decorators)e.raise()}get type(){return this.node?.type?.sectionGrid?.sections?.[this.indexYInNode]?.[this.indexXInNode]}getMinWidth(){return this.node?.type?.sectionGrid?.minWidths?.[this.indexXInNode]||1}getMinHeight(){return this.node?.type?.sectionGrid?.minHeights?.[this.indexYInNode]||1}getPriority(){return this.node?.type?.sectionGrid?.sections?.[this.indexYInNode]?.[this.indexXInNode]?.priority||0}getResizableX(){let e=this.type;return e?.resizableX===void 0?this.node?.getResizableX()||!1:e.resizableX===Re.OnlyWhenSelected?this.selected:e.resizableX}getResizableY(){let e=this.type;return e?.resizableY===void 0?this.node?.getResizableY()||!1:e.resizableY===Re.OnlyWhenSelected?this.selected:e.resizableY}getClosestPortToPoint(e){if(this.ports.length!==0){if(this.ports.length===1)return this.ports[1];{let t=this.ports.map(t=>t.distanceTo(e)),n=t.indexOf(Math.min(...t));return this.ports[n]}}}getIncomingConnections(e=!1){let t=[];for(let n of this.ports)for(let r of n.incomingConnections)!e&&r.removed||t.push(r);return t}getOutgoingConnections(e=!1){let t=[];for(let n of this.ports)for(let r of n.outgoingConnections)!e&&r.removed||t.push(r);return t}getConnections(e=!1){let t=[];for(let n of this.ports){for(let r of n.incomingConnections)!e&&r.removed||t.push(r);for(let r of n.outgoingConnections)!e&&r.removed||t.push(r)}return t}move(e){this.setGeometry({coords:e,width:this.width,height:this.height})}stretch(e,t){let n=[this.coords[0],this.coords[0]+this.width],r=[this.coords[1],this.coords[1]+this.height],i,a;switch(e){case f.Left:i=[n[0]-t,n[1]],a=[r[0],r[1]],i[1]-i[0]<this.getMinWidth()&&(i[0]=i[1]-this.getMinWidth());break;case f.Top:i=[n[0],n[1]],a=[r[0]-t,r[1]],a[1]-a[0]<this.getMinHeight()&&(a[0]=a[1]-this.getMinHeight());break;case f.Right:i=[n[0],n[1]+t],a=[r[0],r[1]],i[1]-i[0]<this.getMinWidth()&&(i[1]=i[0]+this.getMinWidth());break;case f.Bottom:i=[n[0],n[1]],a=[r[0],r[1]+t],a[1]-a[0]<this.getMinHeight()&&(a[1]=a[0]+this.getMinHeight());break}this.setGeometry({coords:[i[0],a[0]],width:i[1]-i[0],height:a[1]-a[0]})}getGeometry(){return{coords:[...this.coords],width:this.width,height:this.height}}setGeometry(e){let t=[this.coords[0],this.coords[0]+this.width],n=[this.coords[1],this.coords[1]+this.height];this.coords=[...e.coords],this.width=e.width,this.height=e.height;let r=[this.coords[0],this.coords[0]+this.width],i=[this.coords[1],this.coords[1]+this.height];for(let e of this.ports)e.move(y(e.coords,t,n,r,i,e.anchorPointX,e.anchorPointY));let a=this.type;this.label&&(this.label.coords=[this.coords[0]+L(a?.label),this.coords[1]+z(a?.label)],this.label.width=this.width-L(a?.label)-R(a?.label),this.label.height=this.height-z(a?.label)-I(a?.label),this.label.updateInView());for(let e of this.decorators)e.move(y(e.coords,t,n,r,i,e.anchorPointX,e.anchorPointY));this.model.canvas?.autoTightenConnections!==!1&&this.getConnections().forEach(e=>e.tighten()),this.updateInView()}},Ke=class extends A{constructor(e){super(),this.model=e}new(e,t,n,r,i,a,o){let s=new B(this.model,e,t,n,r,i,a,o);super.add(s),s.updateInView(),e.sections.push(s),e.updateInView();let c=e.type.sectionGrid?.sections?.[n]?.[t]?.ports;if(c&&c.length>0)for(let e=0;e<c.length;++e){let t=c[e],n=this.model.ports.new(t.type===void 0?void 0:this.model.ports.types.get(t.type),s,[s.coords[0]+(t.coords[0]||0),s.coords[1]+(t.coords[1]||0)],t.connectionPoint===void 0?void 0:[s.coords[0]+(t.connectionPoint[0]||0),s.coords[1]+(t.connectionPoint[1]||0)],t?.direction,`${s.id}_${e}`,t.anchorPointX||`floating`,t.anchorPointY||`floating`);if(n.type?.label){let e={...P,...n.type?.label};e.look={...P.look,...e.look};let t=6*(e.look.fontSize||P.look.fontSize)+Ve(e)+He(e),r=(e.look.fontSize||P.look.fontSize)+Ue(e)+Be(e),i;switch(n.direction){case f.Bottom:case f.Left:case f.Right:i=[n.coords[0]-t/2,n.coords[1]-r-I(e)];break;case f.Top:i=[n.coords[0]-t/2,n.coords[1]+z(e)];break;default:i=n.coords}this.model.fields.new(n,i,t,r,e.horizontalAlign,e.verticalAlign,e.orientation,e.multiline,e.look,``,e.editable,e.fit,e.shrink)}}let l=e.type.sectionGrid?.sections?.[n]?.[t]?.label;if(l){let e={...P,...l};e.look={...P.look,...e.look},this.model.fields.new(s,[s.coords[0]+L(e),s.coords[1]+z(e)],s.width-L(e)-R(e),s.height-z(e)-I(e),e.horizontalAlign,e.verticalAlign,e.orientation,e.multiline,e.look,``,e.editable,e.fit,e.shrink)}return s}remove(e){let t=this.get(e,!0);if(t){for(;t.ports.length>0;)this.model.ports.remove(t.ports[0].id);t.label&&this.model.fields.remove(t.label.id),t.node&&E(t.node.sections,t),super.remove(e),t.updateInView()}}},qe={lookType:`shaped-look`,shape:oe.Rectangle,fillColor:`#FFFFFF`,borderColor:`#000000`,borderThickness:1,selected:{fillColor:`#FFAAFF`,borderColor:`#AA00AA`},highlighted:{borderThickness:3}},V={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:qe,isUnique:!1,canBeParentless:!0,childrenTypes:[],priority:0,properties:[]},Je=class{constructor(e){let t={...V,...e};this.id=t.id,this.name=t.name,this.defaultWidth=t.defaultWidth,this.defaultHeight=t.defaultHeight,this.minWidth=t.minWidth,this.minHeight=t.minHeight,this.resizableX=t.resizableX,this.resizableY=t.resizableY,this.snapToGridOffset=t.snapToGridOffset,this.bottomPadding=Ze(t),this.leftPadding=Qe(t),this.rightPadding=$e(t),this.topPadding=et(t),this.label=t.label,this.ports=t.ports,this.decorators=t.decorators,this.sectionGrid=t.sectionGrid?new We(t.sectionGrid):null;let n=k(t.look);this.defaultLook=n.defaultLook,this.selectedLook=n.selectedLook,this.highlightedLook=n.highlightedLook,this.selectedAndHighlightedLook=n.selectedAndHighlightedLook,this.isUnique=t.isUnique,this.canBeParentless=t.canBeParentless,this.childrenTypes=t.childrenTypes,this.priority=t.priority,this.propertySet=new ke(e?.properties||[])}},H=class extends De{get type(){return this._type}set type(e){e!==this._type&&(this._type=e,this.valueSet&&=new Fe(e.propertySet,this),this.model.canvas?.userSelection?.openInPropertyEditor(this,!1),this.updateInView())}get typeString(){return this.type.id}set typeString(e){if(e!==this.type.id){let t=this.model.nodes.types.get(e);t&&(this.type=t)}}get name(){return this.label?.text||``}set name(e){this.label&&(this.label.text=e)}get look(){return this.selected?this.highlighted?this._selectedAndHighlightedLook===void 0?this.type.selectedAndHighlightedLook:this._selectedAndHighlightedLook:this._selectedLook===void 0?this.type.selectedLook:this._selectedLook:this.highlighted?this._highlightedLook===void 0?this.type.highlightedLook:this._highlightedLook:this._defaultLook===void 0?this.type.defaultLook:this._defaultLook}set look(e){this.lookConfig=e}get lookConfig(){return this._lookConfig}set lookConfig(e){if(this._lookConfig=e,e){let t=k(e);this._defaultLook={...this._defaultLook,...t.defaultLook},this._selectedLook={...this._selectedLook,...t.selectedLook},this._highlightedLook={...this._highlightedLook,...t.highlightedLook},this._selectedAndHighlightedLook={...this._selectedAndHighlightedLook,...t.selectedAndHighlightedLook}}else this._defaultLook=e,this._selectedLook=e,this._highlightedLook=e,this._selectedAndHighlightedLook=e}constructor(e,t,n=[0,0],r){if(e.nodes.get(r)!==void 0)throw Error(`DiagramNode with id "${r}" already exists`);if(!r)throw Error(`DiagramNode cannot have an empty or null id`);super(e,r),this.children=[],this.sections=[],this.ports=[],this.decorators=[],this.geometryTimestamp=null,this._type=t,this.valueSet=new Fe(t.propertySet,this),this.originalData={},this.coords=n,this.width=t.defaultWidth,this.height=t.defaultHeight}get removed(){return this.selfRemoved}updateInView(){this.model.canvas?.updateNodesInView(this.id)}raise(){this.select()?.raise();for(let e of this.sections)e.raise();this.label&&this.label.raise();for(let e of this.ports)e.raise();for(let e of this.decorators)e.raise();for(let e of this.children)e.raise()}getPriority(){return this.type.priority}getResizableX(){let e=this.type.resizableX;return e===Re.OnlyWhenSelected?this.selected:e}getResizableY(){let e=this.type.resizableY;return e===Re.OnlyWhenSelected?this.selected:e}getClosestPortToPoint(e){if(this.ports.length!==0){if(this.ports.length===1)return this.ports[1];{let t=this.ports.map(t=>t.distanceTo(e)),n=t.indexOf(Math.min(...t));return this.ports[n]}}}getIncomingConnections(e=!1){let t=[];for(let n of this.ports)for(let r of n.incomingConnections)!e&&r.removed||t.push(r);return t}getOutgoingConnections(e=!1){let t=[];for(let n of this.ports)for(let r of n.outgoingConnections)!e&&r.removed||t.push(r);return t}getConnections(e=!1){let t=[];for(let n of this.ports){for(let r of n.incomingConnections)!e&&r.removed||t.push(r);for(let r of n.outgoingConnections)!e&&r.removed||t.push(r)}return t}getAdjacentNodes(e=!1){let t=[];for(let n of this.ports){for(let r of n.incomingConnections){if(!e&&r.removed)continue;let n=r.start?.getNode();if(n){if(!e&&n.removed)continue;t.push(n)}}for(let r of n.outgoingConnections){if(!e&&r.removed)continue;let n=r.end?.getNode();if(n){if(!e&&n.removed)continue;t.push(n)}}}return t}getLastAncestor(){let e=this;for(;e.parent!==void 0;)e=e?.parent;return e}isAncestorOf(e){let t=e;for(;t!==void 0;){if(this.id===t.id)return!0;t=t.parent}return!1}isDescendantOf(e){return e.isAncestorOf(this)}addChild(e){if(e.id===this.id)return;let t=this.parent,n=!1;for(;t!==void 0;){if(t.id===e.id){n=!0;break}t=t.parent}n||this.children.indexOf(e)>=0||(this.fitToChild(e),this.children.push(e),e.parent=this,e.raise())}removeChild(e){E(this.children,e),e.parent=void 0}fitToChild(e){let t=Math.max(...this.sections.map(e=>e.indexXInNode)),n=Math.max(...this.sections.map(e=>e.indexYInNode)),r=this.coords[0]-e.coords[0]+this.type.leftPadding;r>=0&&(this.sections.length>0?this.stretchSections(f.Left,r,t,n):this.stretch(f.Left,r));let i=this.coords[1]-e.coords[1]+this.type.topPadding;i>=0&&(this.sections.length>0?this.stretchSections(f.Top,i,t,n):this.stretch(f.Top,i));let a=e.coords[0]+e.width-(this.coords[0]+this.width)+this.type.rightPadding;a>=0&&(this.sections.length>0?this.stretchSections(f.Right,a,t,n):this.stretch(f.Right,a));let o=e.coords[1]+e.height-(this.coords[1]+this.height)+this.type.bottomPadding;o>=0&&(this.sections.length>0?this.stretchSections(f.Bottom,o,t,n):this.stretch(f.Bottom,o)),this.parent&&this.parent.fitToChild(this)}move(e){let t=[e[0]-this.coords[0],e[1]-this.coords[1]];for(let e of this.children)e.move([e.coords[0]+t[0],e.coords[1]+t[1]]);for(let e of this.sections)e.move([e.coords[0]+t[0],e.coords[1]+t[1]]);this.setGeometry({coords:e,width:this.width,height:this.height,sections:{},children:{}})}stretch(e,t){let n=[this.coords[0],this.coords[0]+this.width],r=[this.coords[1],this.coords[1]+this.height],i,a;switch(e){case f.Left:i=[n[0]-t,n[1]],a=[r[0],r[1]],i[1]-i[0]<this.type.minWidth&&(i[0]=i[1]-this.type.minWidth);break;case f.Top:i=[n[0],n[1]],a=[r[0]-t,r[1]],a[1]-a[0]<this.type.minHeight&&(a[0]=a[1]-this.type.minHeight);break;case f.Right:i=[n[0],n[1]+t],a=[r[0],r[1]],i[1]-i[0]<this.type.minWidth&&(i[1]=i[0]+this.type.minWidth);break;case f.Bottom:i=[n[0],n[1]],a=[r[0],r[1]+t],a[1]-a[0]<this.type.minHeight&&(a[1]=a[0]+this.type.minHeight);break}this.setGeometry({coords:[i[0],a[0]],width:i[1]-i[0],height:a[1]-a[0],sections:{},children:{}})}stretchSections(e,t,n,r){let i=-1/0;switch(e){case f.Bottom:for(let e of this.sections)e.indexYInNode===r&&(i=Math.max(i,e.getMinHeight()-e.height));t<i&&(t=i);for(let n of this.sections)n.indexYInNode===r?n.stretch(e,t):n.indexYInNode>r&&n.move([n.coords[0],n.coords[1]+t]);break;case f.Right:for(let e of this.sections)e.indexXInNode===n&&(i=Math.max(i,e.getMinWidth()-e.width));t<i&&(t=i);for(let r of this.sections)r.indexXInNode===n?r.stretch(e,t):r.indexXInNode>n&&r.move([r.coords[0]+t,r.coords[1]]);break;case f.Top:for(let e of this.sections)e.indexYInNode===r&&(i=Math.max(i,e.getMinHeight()-e.height));t<i&&(t=i);for(let n of this.sections)n.indexYInNode===r?n.stretch(e,t):n.indexYInNode<r&&n.move([n.coords[0],n.coords[1]-t]);break;case f.Left:for(let e of this.sections)e.indexXInNode===n&&(i=Math.max(i,e.getMinWidth()-e.width));t<i&&(t=i);for(let r of this.sections)r.indexXInNode===n?r.stretch(e,t):r.indexXInNode<n&&r.move([r.coords[0]-t,r.coords[1]]);break}this.stretch(e,t)}getGeometry(e){let t={};for(let e of this.sections)t[e.id]=e.getGeometry();let n={};for(let t of this.children)t.id!==e&&(n[t.id]=t.getGeometry(e));return{coords:[...this.coords],width:this.width,height:this.height,sections:t,children:n}}setGeometry(e){this.raise();let t=[this.coords[0],this.coords[0]+this.width],n=[this.coords[1],this.coords[1]+this.height];this.coords=[...e.coords],this.width=e.width,this.height=e.height;let r=[this.coords[0],this.coords[0]+this.width],i=[this.coords[1],this.coords[1]+this.height];for(let t of this.children){let n=e.children[t.id];n&&t.setGeometry(n)}for(let t of this.sections){let n=e.sections[t.id];n&&t.setGeometry(n)}for(let e of this.ports)e.move(y(e.coords,t,n,r,i,e.anchorPointX,e.anchorPointY));this.label&&(this.label.coords=[this.coords[0]+L(this.type.label),this.coords[1]+z(this.type.label)],this.label.width=this.width-L(this.type.label)-R(this.type.label),this.label.height=this.height-z(this.type.label)-I(this.type.label),this.label.updateInView());for(let e of this.decorators)e.move(y(e.coords,t,n,r,i,e.anchorPointX,e.anchorPointY));this.model.canvas?.autoTightenConnections!==!1&&this.getConnections().forEach(e=>e.tighten()),this.updateInView()}removeSectionColumn(e){let t=this.type.sectionGrid?.margin||0,n=0,r=[...this.sections];for(let t of r)t.indexYInNode===e&&(n=Math.max(n,t.width),this.model.sections.remove(t.id));for(let i of r)i.indexYInNode>e&&(--i.indexYInNode,i.move([i.coords[0]-n-t,i.coords[1]]));this.stretch(f.Right,-t-n)}removeSectionRow(e){let t=this.type.sectionGrid?.margin||0,n=0,r=[...this.sections];for(let t of r)t.indexXInNode===e&&(n=Math.max(n,t.height),this.model.sections.remove(t.id));for(let i of r)i.indexYInNode>e&&(--i.indexXInNode,i.move([i.coords[0],i.coords[1]-n-t]));this.stretch(f.Bottom,-t-n)}copySectionColumn(e){let t=this.type.sectionGrid?.margin||0,n=0,r=[...this.sections];for(let i of r)if(i.indexXInNode===e){n=Math.max(n,i.width);let e=i.indexXInNode+1;for(;this.model.sections.get(`${i.id}_copy_${e}_${i.indexYInNode}`,!0)!==void 0;)++e;this.model.sections.new(this,i.indexXInNode+1,i.indexYInNode,[i.coords[0]+i.width+t,i.coords[1]],i.width,i.height,`${i.id}_copy_${e}_${i.indexYInNode}`)}for(let i of r)i.indexXInNode>e&&(++i.indexXInNode,i.move([i.coords[0]+n+t,i.coords[1]]));this.stretch(f.Right,t+n)}copySectionRow(e){let t=this.type.sectionGrid?.margin||0,n=0,r=[...this.sections];for(let i of r)if(i.indexYInNode===e){n=Math.max(n,i.height);let e=i.indexYInNode+1;for(;this.model.sections.get(`${i.id}_copy_${i.indexXInNode}_${e}`,!0)!==void 0;)++e;this.model.sections.new(this,i.indexXInNode,i.indexYInNode+1,[i.coords[0],i.coords[1]+i.height+t],i.width,i.height,`${i.id}_copy_${i.indexXInNode}_${e}`)}for(let i of r)i.indexYInNode>e&&(++i.indexYInNode,i.move([i.coords[0],i.coords[1]+n+t]));this.stretch(f.Bottom,t+n)}},Ye=class extends A{constructor(e){super(),this.types=new Ee,this.model=e}new(e,t,n){let r;if(e instanceof Je)r=e;else{let t=this.types.get(e);if(t===void 0)throw TypeError(`Node type with id '${e}' could not be found.`);r=t}let i=new H(this.model,r,t,n);if(super.add(i),i.updateInView(),r.sectionGrid!==null){let e=i.coords[1]+(r.sectionGrid.margin||0);for(let t=0;t<r.sectionGrid.sections.length;++t){let n=i.coords[0]+(r.sectionGrid.margin||0);for(let a=0;a<r.sectionGrid.sections[t].length;++a)this.model.sections.new(i,a,t,[n,e],r.sectionGrid.defaultWidths?.[a]||1,r.sectionGrid.defaultHeights?.[t]||1,`${i.id}_${t}_${a}`),n+=(r.sectionGrid.defaultWidths?.[a]||1)+(r.sectionGrid.margin||0);e+=(r.sectionGrid.defaultHeights?.[t]||1)+(r.sectionGrid.margin||0)}}if(r.ports.length>0)for(let e=0;e<r.ports.length;++e){let t=r.ports[e],n=t.type===void 0?void 0:this.model.ports.types.get(t.type),a=this.model.ports.new(n,i,[i.coords[0]+t.coords[0],i.coords[1]+t.coords[1]],t.connectionPoint===void 0?void 0:[i.coords[0]+(t.connectionPoint[0]||0),i.coords[1]+(t.connectionPoint[1]||0)],t.direction,`${i.id}_port_${e}`,t.anchorPointX||`floating`,t.anchorPointY||`floating`);if(a.type?.label){let e={...P,...a.type?.label};e.look={...P.look,...e.look};let t=6*(e.look.fontSize||P.look.fontSize)+Ve(e)+He(e),n=(e.look.fontSize||P.look.fontSize)+Ue(e)+Be(e),r;switch(a.direction){case f.Bottom:case f.Left:case f.Right:r=[a.coords[0]-t/2,a.coords[1]-n-I(e)];break;case f.Top:r=[a.coords[0]-t/2,a.coords[1]+z(e)];break;default:r=a.coords}this.model.fields.new(a,r,t,n,e.horizontalAlign,e.verticalAlign,e.orientation,e.multiline,e.look,``,e.editable,e.fit,e.shrink)}}if(r.label){let e={...P,...r.label};e.look={...P.look,...e.look},this.model.fields.new(i,[i.coords[0]+L(e),i.coords[1]+z(e)],i.width-L(e)-R(e),i.height-z(e)-I(e),e.horizontalAlign,e.verticalAlign,e.orientation,e.multiline,e.look,``,e.editable,e.fit,e.shrink)}if(r.decorators.length>0)for(let e=0;e<r.decorators.length;++e){let t=r.decorators[e];this.model.decorators.new(i,[i.coords[0]+t.coords[0],i.coords[1]+t.coords[1]],t.width,t.height,i.getPriority(),t.svg,`${i.id}_decorator_${e}`,t.anchorPointX||`floating`,t.anchorPointY||`floating`)}return i.valueSet.resetValues(),i.model.canvas?.fitNodeInView(i.id),i}remove(e){let t=this.get(e,!0);if(t){for(t.parent&&E(t.parent.children,t);t.children.length>0;)this.model.nodes.remove(t.children[0].id);for(;t.sections.length>0;)this.model.sections.remove(t.sections[0].id);for(;t.ports.length>0;)this.model.ports.remove(t.ports[0].id);for(;t.decorators.length>0;)this.model.decorators.remove(t.decorators[0].id);t.label&&this.model.fields.remove(t.label.id),super.remove(e),t.updateInView()}}getAtCoordinates(e,t){let n=[];for(let r of this)r.coords[0]<e&&e<r.coords[0]+r.width&&r.coords[1]<t&&t<r.coords[1]+r.height&&n.push(r);return n}},Xe=e=>{for(let t=0;t<e.length;++t)for(let n=0;n<e.length;++n)n!==t&&e[n].isAncestorOf(e[t])&&(e.splice(n,1),--n,t>n&&--t);return e},Ze=e=>e?.padding===null||e?.padding===void 0?V.padding:typeof e.padding==`number`?e.padding:e.padding.length===0?V.padding:e.padding.length===1||e.padding.length===2?e.padding[0]:(e.padding.length,e.padding[2]),Qe=e=>e?.padding===null||e?.padding===void 0?V.padding:typeof e.padding==`number`?e.padding:e.padding.length===0?V.padding:e.padding.length===1?e.padding[0]:e.padding.length===2||e.padding.length===3?e.padding[1]:e.padding[3],$e=e=>e?.padding===null||e?.padding===void 0?V.padding:typeof e.padding==`number`?e.padding:e.padding.length===0?V.padding:e.padding.length===1?e.padding[0]:(e.padding.length===2||e.padding.length,e.padding[1]),et=e=>e?.padding===null||e?.padding===void 0?V.padding:typeof e.padding==`number`?e.padding:e.padding.length===0?V.padding:(e.padding.length===1||e.padding.length===2||e.padding.length,e.padding[0]),tt=class extends De{constructor(e,t,n,r,i,a,o,s,c=`floating`,l=`floating`){if(e.objects.get(s)!==void 0)throw Error(`DiagramDecorator with id "${s}" already exists`);if(!s)throw Error(`DiagramDecorator cannot have an empty or null id`);super(e,s),this.rootElement=t,this.coords=n,this.width=r,this.height=i,this.priority=a,this.svg=o,this.anchorPointX=c,this.anchorPointY=l}get removed(){return this.selfRemoved||this.rootElement!==void 0&&this.rootElement.removed}updateInView(){this.model.canvas?.updateDecoratorsInView(this.id)}raise(){this.select()?.raise()}move(e){this.coords=e,this.updateInView()}getPriority(){return this.priority}},nt=class extends A{constructor(e){super(),this.model=e}new(e,t,n,r,i,a,o,s=`floating`,c=`floating`){let l=new tt(this.model,e,t,n,r,i,a,o,s,c);return super.add(l),l.updateInView(),e!==void 0&&e.decorators.push(l),l}remove(e){let t=this.get(e,!0);t&&((t.rootElement instanceof H||t.rootElement instanceof B)&&E(t.rootElement.decorators,t),super.remove(e),t.updateInView())}},rt=class extends De{constructor(e,t,n,r,i,a,o){if(e.objects.get(o)!==void 0)throw Error(`DiagramObject with id "${o}" already exists`);if(!o)throw Error(`DiagramObject cannot have an empty or null id`);super(e,o),this.coords=t,this.width=n,this.height=r,this.priority=i,this.svg=a}get removed(){return this.selfRemoved}updateInView(){this.model.canvas?.updateObjectsInView(this.id)}raise(){this.select()?.raise()}move(e){this.coords=e,this.updateInView()}getPriority(){return this.priority}},it=class extends A{constructor(e){super(),this.model=e}new(e,t,n,r,i,a){let o=new rt(this.model,e,t,n,r,i,a);return super.add(o),o.updateInView(),o}remove(e){let t=this.get(e,!0);t&&(super.remove(e),t.updateInView())}},at={lookType:`shaped-look`,shape:oe.Ellipse,fillColor:`transparent`,borderColor:`transparent`,borderThickness:0,selected:{fillColor:`rgba(255, 0, 255, 0.5)`},highlighted:{fillColor:`rgba(0, 255, 255, 0.5)`}},ot=k(at),st={name:``,label:null,allowsOutgoing:!0,allowsIncoming:!0,width:24,look:at},ct=class{constructor(e){let t={...st,...e};this.id=t.id,this.name=t.name,this.label=t.label,this.allowsOutgoing=t.allowsOutgoing,this.allowsIncoming=t.allowsIncoming,this.width=t.width;let n=k(t.look);this.defaultLook=n.defaultLook,this.selectedLook=n.selectedLook,this.highlightedLook=n.highlightedLook,this.selectedAndHighlightedLook=n.selectedAndHighlightedLook}},lt=class extends De{get type(){return this._type}set type(e){e!==this._type&&(this._type=e,this.updateInView())}get typeString(){return this.type?.id}set typeString(e){if(e!==this.type?.id)if(e===void 0)this.type=void 0;else{let t=this.model.ports.types.get(e);t&&(this.type=t)}}get allowsOutgoing(){return this.type?.allowsOutgoing===void 0?!0:this.type?.allowsOutgoing}get allowsIncoming(){return this.type?.allowsIncoming===void 0?!0:this.type?.allowsIncoming}get name(){return this.label?.text||``}set name(e){this.label&&(this.label.text=e)}get look(){return this.selected?this.highlighted?this._selectedAndHighlightedLook===void 0?(this.type||ot)?.selectedAndHighlightedLook:this._selectedAndHighlightedLook:this._selectedLook===void 0?(this.type||ot)?.selectedLook:this._selectedLook:this.highlighted?this._highlightedLook===void 0?(this.type||ot)?.highlightedLook:this._highlightedLook:this._defaultLook===void 0?(this.type||ot)?.defaultLook:this._defaultLook}set look(e){this.lookConfig=e}get lookConfig(){return this._lookConfig}set lookConfig(e){if(this._lookConfig=e,e){let t=k(e);this._defaultLook={...this._defaultLook,...t.defaultLook},this._selectedLook={...this._selectedLook,...t.selectedLook},this._highlightedLook={...this._highlightedLook,...t.highlightedLook},this._selectedAndHighlightedLook={...this._selectedAndHighlightedLook,...t.selectedAndHighlightedLook}}else this._defaultLook=e,this._selectedLook=e,this._highlightedLook=e,this._selectedAndHighlightedLook=e}get width(){return this.type?.width||st.width}get height(){return this.width}constructor(e,t,n,r,i,a,o,s=`floating`,c=`floating`){if(e.ports.get(o)!==void 0)throw Error(`DiagramPort with id "${o}" already exists`);if(!o)throw Error(`DiagramPort cannot have an empty or null id`);super(e,o),this.outgoingConnections=[],this.incomingConnections=[],this._type=t,this.rootElement=n,this.coords=r,this.connectionPoint=i||r,this.direction=a,this.anchorPointX=s,this.anchorPointY=c}get removed(){return this.selfRemoved||this.rootElement!==void 0&&this.rootElement.removed}updateInView(){this.model.canvas?.updatePortsInView(this.id)}raise(e=!0){if(this.select()?.raise(),this.label&&this.label.raise(),e){for(let e of this.incomingConnections)e.raise();for(let e of this.outgoingConnections)e.raise()}}startConnection(e){this.outgoingConnections.push(e)}finishConnection(e){this.incomingConnections.push(e)}getNode(){if(this.rootElement instanceof H)return this.rootElement;if(this.rootElement instanceof B)return this.rootElement.node}getPriority(){return this.rootElement?.getPriority()||0}move(e){let t=[e[0]-this.coords[0],e[1]-this.coords[1]];this.coords=e,this.connectionPoint[0]=this.connectionPoint[0]+t[0],this.connectionPoint[1]=this.connectionPoint[1]+t[1];for(let e of this.outgoingConnections)e.setStart(this);for(let e of this.incomingConnections)e.setEnd(this);this.label&&this.label.move([this.label.coords[0]+t[0],this.label.coords[1]+t[1]]),this.updateInView()}distanceTo(e){return b(this.coords,e)}},ut=class extends A{constructor(e){super(),this.types=new Ee,this.model=e}new(e,t,n,r,i,a,o=`floating`,s=`floating`){let c=new lt(this.model,e,t,n,r,i,a,o,s);return super.add(c),c.updateInView(),t!==void 0&&t.ports.push(c),c}remove(e){let t=this.get(e,!0);if(t){for(;t.outgoingConnections.length>0;)this.model.connections.remove(t.outgoingConnections[0].id);for(;t.incomingConnections.length>0;)this.model.connections.remove(t.incomingConnections[0].id);t.label&&this.model.fields.remove(t.label.id),(t.rootElement instanceof H||t.rootElement instanceof B)&&E(t.rootElement.ports,t),super.remove(e),t.updateInView()}}},dt=class{import(e,t){e.clear(),t.id&&(e.id=t.id),e.name=t.name,e.description=t.description,e.type=t.type,e.createdAt=new Date(t.createdAt),e.updatedAt=new Date(t.updatedAt);for(let n of t.nodes||[])this.importNode(e,n);for(let n of t.connections||[])this.importConnection(e,n);for(let n of t.objects||[]){let t=new rt(e,n.coords,n.width,n.height,n.priority,n.svg,n.id);n.collabMeta&&(t.selfRemoved=n.collabMeta.selfRemoved),e.objects.add(t),t.updateInView()}return t.data&&e.valueSet.setValues(t.data),t.collabMeta&&(e.logicalClock=t.collabMeta.logicalClock,e.valueSet.setTimestamps(t.collabMeta.dataTimestamps)),e}importNode(e,t){let n=e.nodes.types.get(t.type);if(n){let r=new H(e,n,t.coords,t.id);if(e.nodes.add(r),r.width=t.width,r.height=t.height,n.label){let i={...P,...n.label};i.look={...P.look,...i.look};let a=new F(e,r,[r.coords[0]+L(i),r.coords[1]+z(i)],r.width-L(i)-R(i),r.height-z(i)-I(i),i.horizontalAlign,i.verticalAlign,i.orientation,i.multiline,i.look,``,i.editable,i.fit,i.shrink);a.text=t.label,r.label=a,e.fields.add(a),a.updateInView()}for(let n of t.children||[]){let t=this.importNode(e,n);t!==void 0&&(r.children?.push(t),t.parent=r)}for(let i of t.sections||[]){let t=new B(e,r,i.indexXInNode,i.indexYInNode,i.coords,i.width,i.height,i.id);if(r.sections?.push(t),e.sections.add(t),n.sectionGrid?.sections?.[i.indexYInNode]?.[i.indexXInNode]?.label){let r={...P,...n.sectionGrid?.sections?.[i.indexYInNode]?.[i.indexXInNode]?.label};r.look={...P.look,...r.look};let a=new F(e,t,[t.coords[0]+L(r),t.coords[1]+z(r)],t.width-L(r)-R(r),t.height-z(r)-I(r),r.horizontalAlign,r.verticalAlign,r.orientation,r.multiline,r.look,``,r.editable,r.fit,r.shrink);a.text=i.label,t.label=a,e.fields.add(a),a.updateInView()}let a=0;for(let r of i.ports||[]){let i=r.type===void 0?void 0:e.ports.types.get(r.type),o=new lt(e,i,t,r.coords,r.connectionPoint||r.coords,r.direction,r.id);if(t.ports.push(o),e.ports.add(o),r.label){if(n.ports.length>a&&i?.label){let t={...P,...i?.label};t.look={...P.look,...t.look};let n;switch(o.direction){case f.Top:case f.Left:n=[o.coords[0]-(t.look.fontSize||P.look.fontSize),o.coords[1]-(t.look.fontSize||P.look.fontSize)];break;case f.Bottom:n=[o.coords[0]-(t.look.fontSize||P.look.fontSize),o.coords[1]+(t.look.fontSize||P.look.fontSize)];break;case f.Right:n=[o.coords[0]+(t.look.fontSize||P.look.fontSize),o.coords[1]-(t.look.fontSize||P.look.fontSize)];break;default:n=o.coords}let a=new F(e,o,n,t.look.fontSize||P.look.fontSize,t.look.fontSize||P.look.fontSize,t.horizontalAlign,t.verticalAlign,t.orientation,t.multiline,t.look,``,t.editable,t.fit,t.shrink);a.text=r.label,o.label=a,e.fields.add(a),a.updateInView()}++a}r.collabMeta&&(o.selfRemoved=r.collabMeta.selfRemoved,o.selfRemovedTimestamp=r.collabMeta.selfRemovedTimestamp,this.importLabelCollabMeta(o.label,r.collabMeta.label)),o.updateInView()}for(let n of i.decorators||[]){let i=new tt(e,t,n.coords,n.width,n.height,n.priority,n.svg,n.id,n.anchorPoints[0],n.anchorPoints[1]);n.collabMeta&&(i.selfRemoved=n.collabMeta.selfRemoved),r.decorators.push(i),e.decorators.add(i),i.updateInView()}i.collabMeta&&(t.selfRemoved=i.collabMeta.selfRemoved,t.selfRemovedTimestamp=i.collabMeta.selfRemovedTimestamp,this.importLabelCollabMeta(t.label,i.collabMeta.label)),t.updateInView()}let i=0;for(let a of t.ports||[]){let t=a.type===void 0?void 0:e.ports.types.get(a.type),o=new lt(e,t,r,a.coords,a.connectionPoint||a.coords,a.direction,a.id);if(r.ports.push(o),e.ports.add(o),a.label){if(n.ports.length>i&&t?.label){let n={...P,...t?.label};n.look={...P.look,...n.look};let r;switch(o.direction){case f.Top:case f.Left:r=[o.coords[0]-(n.look.fontSize||P.look.fontSize),o.coords[1]-(n.look.fontSize||P.look.fontSize)];break;case f.Bottom:r=[o.coords[0]-(n.look.fontSize||P.look.fontSize),o.coords[1]+(n.look.fontSize||P.look.fontSize)];break;case f.Right:r=[o.coords[0]+(n.look.fontSize||P.look.fontSize),o.coords[1]-(n.look.fontSize||P.look.fontSize)];break;default:r=o.coords}let i=new F(e,o,r,n.look.fontSize||P.look.fontSize,n.look.fontSize||P.look.fontSize,n.horizontalAlign,n.verticalAlign,n.orientation,n.multiline,n.look,``,n.editable,n.fit,n.shrink);i.text=a.label,o.label=i,e.fields.add(i),i.updateInView()}++i}a.collabMeta&&(o.selfRemoved=a.collabMeta.selfRemoved,o.selfRemovedTimestamp=a.collabMeta.selfRemovedTimestamp,this.importLabelCollabMeta(o.label,a.collabMeta.label)),o.updateInView()}for(let n of t.decorators||[]){let t=new tt(e,r,n.coords,n.width,n.height,n.priority,n.svg,n.id,n.anchorPoints[0],n.anchorPoints[1]);n.collabMeta&&(t.selfRemoved=n.collabMeta.selfRemoved),r.decorators.push(t),e.decorators.add(t),t.updateInView()}return t.data&&r.valueSet.setValues(t.data),t.collabMeta&&(r.selfRemoved=t.collabMeta.selfRemoved,r.selfRemovedTimestamp=t.collabMeta.selfRemovedTimestamp,r.geometryTimestamp=t.collabMeta.geometryTimestamp,this.importLabelCollabMeta(r.label,t.collabMeta.label),r.valueSet.setTimestamps(t.collabMeta.dataTimestamps)),r.updateInView(),r.raise(),r}}importConnection(e,t){let n=e.connections.types.get(t.type);if(n){let r=new N(e,n,t.start?e.ports.get(t.start):void 0,t.end?e.ports.get(t.end):void 0,t.id);return e.connections.add(r),r.startLabel=t.startLabel,r.middleLabel=t.middleLabel,r.endLabel=t.endLabel,r.points=t.points,t.data&&r.valueSet.setValues(t.data),t.collabMeta&&(r.selfRemoved=t.collabMeta.selfRemoved,r.selfRemovedTimestamp=t.collabMeta.selfRemovedTimestamp,r.valueSet.setTimestamps(t.collabMeta.dataTimestamps)),r.updateInView(),r.raise(),r}}importLabelCollabMeta(e,t){e&&t&&(e.selfRemoved=t.selfRemoved,e.selfRemovedTimestamp=t.selfRemovedTimestamp,e.textTimestamp=t.textTimestamp)}},ft=class e{constructor(e,t,n,r,i,a,o){this.canvas=e,this.id=t,this.typeId=n,this.coords=r,this.parentId=i,this.label=a,this.values=o}do(){let e=this.canvas.model.nodes.new(this.typeId,this.coords,this.id);this.parentId!==void 0&&this.canvas.model.nodes.get(this.parentId)?.addChild(e),e.label&&(e.label.text=this.label||``),this.values===void 0?e.valueSet.resetValues():e.valueSet.setValues(Te({...e.valueSet.getValues(),...this.values}))}serialize(){return{type:`addNode`,id:this.id,typeId:this.typeId,coords:this.coords,parentId:this.parentId,label:this.label,values:this.values}}static deserialize(t,n){return new e(t,n.id,n.typeId,n.coords,n.parentId,n.label,n.values)}},pt=class e{constructor(e,t,n,r,i,a,o){this.canvas=e,this.nodeId=t,this.copyColumnIndex=n,this.copyRowIndex=r,this.removeColumnIndex=i,this.removeRowIndex=a,this.timestamp=o}do(){let e=this.canvas.model.nodes.get(this.nodeId);e&&Ae(this.timestamp,e.geometryTimestamp)&&(this.copyColumnIndex!==void 0&&e.copySectionColumn(this.copyColumnIndex),this.copyRowIndex!==void 0&&e.copySectionRow(this.copyRowIndex),this.removeColumnIndex!==void 0&&e.removeSectionColumn(this.removeColumnIndex),this.removeRowIndex!==void 0&&e.removeSectionRow(this.removeRowIndex),e.geometryTimestamp=this.timestamp)}serialize(){return{type:`addSection`,nodeId:this.nodeId,copyColumnIndex:this.copyColumnIndex,copyRowIndex:this.copyRowIndex,removeColumnIndex:this.removeColumnIndex,removeRowIndex:this.removeRowIndex,timestamp:this.timestamp}}static deserialize(t,n){return new e(t,n.nodeId,n.copyColumnIndex,n.copyRowIndex,n.removeColumnIndex,n.removeRowIndex,n.timestamp)}},mt=class e{constructor(e,t,n){this.canvas=e,this.to=t,this.timestamp=n}do(){for(let e in this.to){let t=this.canvas.model.nodes.get(e,!0);if(t&&Ae(this.timestamp,t.geometryTimestamp)){let n=this.to[e];t.move([n[0],n[1]]),t.geometryTimestamp=this.timestamp}}}serialize(){return{type:`applyLayout`,to:this.to,timestamp:this.timestamp}}static deserialize(t,n){return new e(t,n.to,n.timestamp)}},ht=class e{constructor(e,t,n,r){this.canvas=e,this.nodeIds=t,this.delta=n,this.timestamp=r}do(){for(let e of this.nodeIds){let t=this.canvas.model.nodes.get(e,!0);t&&Ae(this.timestamp,t.geometryTimestamp)&&(t.move([t.coords[0]+this.delta[0],t.coords[1]+this.delta[1]]),t.parent?.fitToChild(t),t.geometryTimestamp=this.timestamp)}}serialize(){return{type:`move`,nodeIds:this.nodeIds,delta:this.delta,timestamp:this.timestamp}}static deserialize(t,n){return new e(t,n.nodeIds,n.delta,n.timestamp)}},U=class e{constructor(e,t,n,r){this.canvas=e,this.nodeId=t,this.to=n,this.timestamp=r}do(){let e=this.canvas.model.nodes.get(this.nodeId,!0);if(e&&Ae(this.timestamp,e.geometryTimestamp)){e.setGeometry(this.to),e.label?.fit&&this.canvas.fitFieldRootInView(e.label.id,e.label.shrink);for(let t of e.sections)t.label?.fit&&this.canvas.fitFieldRootInView(t.label.id,t.label.shrink);e.parent?.fitToChild(e),e.geometryTimestamp=this.timestamp}}serialize(){return{type:`setGeometry`,nodeId:this.nodeId,to:this.to,timestamp:this.timestamp}}static deserialize(t,n){return new e(t,n.nodeId,n.to,n.timestamp)}},gt=class e{constructor(e,t,n,r,i){this.canvas=e,this.childId=t,this.parentId=n,this.childGeometry=r,this.timestamp=i}do(){let e=this.canvas.model.nodes.get(this.childId,!0),t=this.parentId===void 0?void 0:this.canvas.model.nodes.get(this.parentId,!0);e&&(this.parentId===void 0||t)&&Ae(this.timestamp,e.geometryTimestamp)&&(e.parent?.removeChild(e),e.setGeometry(this.childGeometry),t?.addChild(e))}serialize(){return{type:`setParent`,childId:this.childId,parentId:this.parentId,childGeometry:this.childGeometry,timestamp:this.timestamp}}static deserialize(t,n){return new e(t,n.childId,n.parentId,n.childGeometry,n.timestamp)}},_t=class e{constructor(e,t,n,r,i){this.canvas=e,this.id=t,this.typeId=n,this.startId=r,this.endId=i}do(){let e=this.canvas.model.ports.get(this.startId,!0),t=this.canvas.model.ports.get(this.endId,!0);e&&t&&this.canvas.model.connections.new(this.typeId,e,t,this.id)}serialize(){return{type:`addConnection`,id:this.id,typeId:this.typeId,startId:this.startId,endId:this.endId}}static deserialize(t,n){return new e(t,n.id,n.typeId,n.startId,n.endId)}},vt=class e{constructor(e,t,n,r){this.canvas=e,this.fieldId=t,this.to=n,this.timestamp=r}do(){let e=this.canvas.model.fields.get(this.fieldId,!0);e&&Ae(this.timestamp,e.textTimestamp)&&(e.text=this.to,e.textTimestamp=this.timestamp)}serialize(){return{type:`editField`,fieldId:this.fieldId,to:this.to,timestamp:this.timestamp}}static deserialize(t,n){return new e(t,n.fieldId,n.to,n.timestamp)}},yt=class e{constructor(e,t,n,r){this.canvas=e,this.id=t,this.to=n,this.timestamp=r}getValueSet(){return this.id===void 0?this.canvas.model.valueSet:(this.canvas.model.nodes.get(this.id,!0)||this.canvas.model.connections.get(this.id,!0))?.valueSet}do(){this.getValueSet()?.overwriteValuesLww(this.to,this.timestamp)}serialize(){return{type:`updateValues`,id:this.id,to:this.to,timestamp:this.timestamp}}static deserialize(t,n){return new e(t,n.id,n.to,n.timestamp)}},W=class e{constructor(e,t,n,r,i,a,o,s){this.canvas=e,this.nodeIds=t,this.sectionIds=n,this.portIds=r,this.connectionIds=i,this.fieldIds=a,this.selfRemoved=o,this.timestamp=s}doOne(e){e&&Ae(this.timestamp,e.selfRemovedTimestamp)&&(e.selfRemoved=this.selfRemoved,e.selfRemovedTimestamp=this.timestamp)}do(){for(let e of this.nodeIds)this.doOne(this.canvas.model.nodes.get(e,!0));for(let e of this.sectionIds)this.doOne(this.canvas.model.sections.get(e,!0));for(let e of this.portIds)this.doOne(this.canvas.model.ports.get(e,!0));for(let e of this.connectionIds)this.doOne(this.canvas.model.connections.get(e,!0));for(let e of this.fieldIds)this.doOne(this.canvas.model.fields.get(e,!0));this.canvas.updateNodesInView(...this.nodeIds),this.canvas.updateSectionsInView(...this.sectionIds),this.canvas.updatePortsInView(...this.portIds),this.canvas.updateConnectionsInView(...this.connectionIds),this.canvas.updateFieldsInView(...this.fieldIds),this.canvas.updateDecoratorsInView()}serialize(){return{type:`setSelfRemoved`,nodeIds:this.nodeIds,sectionIds:this.sectionIds,portIds:this.portIds,connectionIds:this.connectionIds,fieldIds:this.fieldIds,removed:this.selfRemoved,timestamp:this.timestamp}}static deserialize(t,n){return new e(t,n.nodeIds,n.sectionIds,n.portIds,n.connectionIds,n.fieldIds,n.removed,n.timestamp)}},bt=class e{constructor(e,t,n){this.canvas=e,this.nodes=t,this.connections=n}do(){let e=new dt;this.canvas.userSelection.clear();for(let t of this.nodes){let n=e.importNode(this.canvas.model,t);n&&this.canvas.userSelection.add(n)}for(let t of this.connections){let n=e.importConnection(this.canvas.model,t);n&&this.canvas.userSelection.add(n)}}serialize(){return{type:`paste`,nodes:this.nodes,connections:this.connections}}static deserialize(t,n){return new e(t,n.nodes,n.connections)}},xt=class{constructor(e){this.isInRoom=!1,this.canvas=e,this.replicaId=Ce()}freshTimestamp(){return this.canvas.model.logicalClock++,[this.canvas.model.logicalClock,this.replicaId]}freshId(){return`id`+Ce()}doCollaboratively(e){if(e.do(),this.onSend){let t=e.serialize();this.onSend(t)}}receive(e){switch(`timestamp`in e&&(this.canvas.model.logicalClock=Math.max(this.canvas.model.logicalClock,e.timestamp[0])),e.type){case`addNode`:ft.deserialize(this.canvas,e).do();break;case`addSection`:pt.deserialize(this.canvas,e).do();break;case`applyLayout`:mt.deserialize(this.canvas,e).do();break;case`move`:ht.deserialize(this.canvas,e).do();break;case`setGeometry`:U.deserialize(this.canvas,e).do();break;case`setParent`:gt.deserialize(this.canvas,e).do();break;case`addConnection`:_t.deserialize(this.canvas,e).do();break;case`editField`:vt.deserialize(this.canvas,e).do();break;case`updateValues`:yt.deserialize(this.canvas,e).do();break;case`setSelfRemoved`:W.deserialize(this.canvas,e).do();break;case`paste`:bt.deserialize(this.canvas,e).do();break;default:console.error(`Unknown CollabAction type, skipping:`,e)}}},St=class{constructor(e,t){this.canvas=e,this.maximum=t,this.history=[],this.index=0}add(e){this.index<this.history.length&&(this.history=this.history.slice(0,this.index)),this.history.length>=this.maximum?(this.history=this.history.slice(1,this.history.length),this.history.push(e)):(this.history.push(e),++this.index),this.canvas.diagramChange$.next({action:e,method:0})}undo(){let e;if(this.index>0){let t;do--this.index,e=this.history[this.index],t=e.undo();while(!t&&this.index>0)}this.canvas.diagramChange$.next({action:e,method:1})}redo(){let e;if(this.index<this.history.length){let t;do e=this.history[this.index],t=e.redo(),++this.index;while(!t&&this.index<this.history.length)}this.canvas.diagramChange$.next({action:e,method:2})}},G=function(e){return e.AddConnection=`add-connection`,e.AddNode=`add-node`,e.AddSectionAction=`add-section`,e.ApplyLayout=`apply-layout`,e.Clipboard=`clipboard`,e.ContextMenu=`context-menu`,e.EditField=`edit-field`,e.MoveNode=`move-node`,e.Paste=`paste`,e.Remove=`remove`,e.StretchNode=`stretch-node`,e.StretchSection=`stretch-section`,e.UpdateValues=`update-values`,e.Zoom=`zoom`,e}({}),Ct=class{constructor(e,t,n,r,i,a,o,s,c){this.canvas=e,this.type=t,this.coords=n,this.parentId=r,this.ancestorId=i,this.fromAncestorGeometry=a,this.toAncestorGeometry=o,this.label=s,this.values=c,this.id=this.canvas.collabEngine.freshId()}do(){let e=new ft(this.canvas,this.id,this.type.id,this.coords,this.parentId,this.label,this.values);if(this.canvas.collabEngine.doCollaboratively(e),this.ancestorId!==void 0&&this.toAncestorGeometry!==void 0){let e=new U(this.canvas,this.ancestorId,this.toAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(e)}return!0}undo(){let e=this.canvas.model.nodes.get(this.id),t=new W(this.canvas,[this.id],[],[],[],[],!0,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(t),this.ancestorId!==void 0&&this.fromAncestorGeometry!==void 0){let e=new U(this.canvas,this.ancestorId,this.fromAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(e)}return e!==void 0}redo(){let e=this.canvas.model.nodes.get(this.id),t=new W(this.canvas,[this.id],[],[],[],[],!1,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(t),this.ancestorId!==void 0&&this.toAncestorGeometry!==void 0){let e=new U(this.canvas,this.ancestorId,this.toAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(e)}return e===void 0}},wt=class{constructor(e,t,n){this.canvas=e,this.nodeIds=t,this.delta=n}do(){let e=new ht(this.canvas,this.nodeIds,this.delta,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),this.nodeIds.map(e=>this.canvas.model.nodes.get(e)!==void 0).includes(!0)&&(this.delta[0]!==0||this.delta[1]!==0)}undo(){let e=new ht(this.canvas,this.nodeIds,[-this.delta[0],-this.delta[1]],this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),this.nodeIds.map(e=>this.canvas.model.nodes.get(e)!==void 0).includes(!0)&&(this.delta[0]!==0||this.delta[1]!==0)}redo(){return this.do()}},K=class{constructor(e,t,n,r,i,a,o,s){this.canvas=e,this.intent=t,this.nodeId=n,this.from=r,this.to=i,this.ancestorId=a,this.fromAncestorGeometry=o,this.toAncestorGeometry=s}do(){let e=this.canvas.model.nodes.get(this.nodeId);if(e){let e=new U(this.canvas,this.nodeId,this.to,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(e),this.ancestorId!==void 0&&this.toAncestorGeometry!==void 0){let e=new U(this.canvas,this.ancestorId,this.toAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(e)}}return e!==void 0}undo(){let e=this.canvas.model.nodes.get(this.nodeId);if(e){this.to=e.getGeometry();let t=new U(this.canvas,this.nodeId,this.from,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(t),this.ancestorId!==void 0&&this.fromAncestorGeometry!==void 0){let e=new U(this.canvas,this.ancestorId,this.fromAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(e)}}return e!==void 0}redo(){let e=this.canvas.model.nodes.get(this.nodeId);if(e){this.from=e.getGeometry();let t=new U(this.canvas,this.nodeId,this.to,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(t)}return e!==void 0}},Tt=class{constructor(e,t,n,r,i,a,o,s,c){this.canvas=e,this.childId=t,this.fromParentId=n,this.toParentId=r,this.fromChildGeometry=i,this.toChildGeometry=a,this.ancestorId=o,this.fromAncestorGeometry=s,this.toAncestorGeometry=c}do(){let e=this.canvas.model.nodes.get(this.childId),t=new gt(this.canvas,this.childId,this.toParentId,this.toChildGeometry,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(t),this.ancestorId!==void 0&&this.toAncestorGeometry!==void 0){let e=new U(this.canvas,this.ancestorId,this.toAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(e)}return e!==void 0}undo(){let e=this.canvas.model.nodes.get(this.childId),t=new gt(this.canvas,this.childId,this.fromParentId,this.fromChildGeometry,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(t),this.ancestorId!==void 0&&this.fromAncestorGeometry!==void 0){let e=new U(this.canvas,this.ancestorId,this.fromAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(e)}return e!==void 0}redo(){return this.do()}},Et=class{constructor(e,t,n,r){this.canvas=e,this.type=t,this.startId=n,this.endId=r,this.id=this.canvas.collabEngine.freshId()}do(){let e=new _t(this.canvas,this.id,this.type.id,this.startId,this.endId);return this.canvas.collabEngine.doCollaboratively(e),!0}undo(){let e=this.canvas.model.connections.get(this.id),t=new W(this.canvas,[],[],[],[this.id],[],!0,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(t),e!==void 0}redo(){let e=this.canvas.model.connections.get(this.id),t=new W(this.canvas,[],[],[],[this.id],[],!1,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(t),e===void 0}},Dt=class{constructor(e,t,n,r){this.canvas=e,this.fieldId=t,this.from=n,this.to=r}do(){let e=this.canvas.model.fields.get(this.fieldId),t=new vt(this.canvas,this.fieldId,this.to,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(t),e!==void 0}undo(){let e=this.canvas.model.fields.get(this.fieldId);if(e){this.to=e.text;let t=new vt(this.canvas,this.fieldId,this.from,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(t)}return e!==void 0}redo(){let e=this.canvas.model.fields.get(this.fieldId);if(e){this.from=e.text;let t=new vt(this.canvas,this.fieldId,this.to,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(t)}return e!==void 0}},Ot=class{constructor(e,t,n,r){this.canvas=e,this.id=t,this.from=n,this.to=r}do(){let e=new yt(this.canvas,this.id,this.to,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),!0}undo(){let e=new yt(this.canvas,this.id,this.from,this.canvas.collabEngine.freshTimestamp()),t=e.getValueSet();if(t)this.to=t.getValuesForKeys(this.to),this.canvas.collabEngine.doCollaboratively(e);else return!1;return!t.rootElement.removed}redo(){let e=new yt(this.canvas,this.id,this.to,this.canvas.collabEngine.freshTimestamp()),t=e.getValueSet();if(t)this.from=t.getValuesForKeys(this.from),this.canvas.collabEngine.doCollaboratively(e);else return!1;return!t.rootElement.removed}},kt=class{constructor(e,t,n,r,i,a){this.canvas=e,this.nodeIds=t,this.sectionIds=n,this.portIds=r,this.connectionIds=i,this.fieldIds=a}do(){let e=this.nodeIds.map(e=>this.canvas.model.nodes.get(e)!==void 0).includes(!0)||this.sectionIds.map(e=>this.canvas.model.sections.get(e)!==void 0).includes(!0)||this.portIds.map(e=>this.canvas.model.ports.get(e)!==void 0).includes(!0)||this.connectionIds.map(e=>this.canvas.model.connections.get(e)!==void 0).includes(!0)||this.fieldIds.map(e=>this.canvas.model.fields.get(e)!==void 0).includes(!0),t=new W(this.canvas,this.nodeIds,this.sectionIds,this.portIds,this.connectionIds,this.fieldIds,!0,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(t),e}undo(){let e=this.nodeIds.map(e=>this.canvas.model.nodes.get(e)===void 0).includes(!0)||this.sectionIds.map(e=>this.canvas.model.sections.get(e)===void 0).includes(!0)||this.portIds.map(e=>this.canvas.model.ports.get(e)===void 0).includes(!0)||this.connectionIds.map(e=>this.canvas.model.connections.get(e)===void 0).includes(!0)||this.fieldIds.map(e=>this.canvas.model.fields.get(e)===void 0).includes(!0),t=new W(this.canvas,this.nodeIds,this.sectionIds,this.portIds,this.connectionIds,this.fieldIds,!1,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(t),e}redo(){return this.do()}},At=class{constructor(e,t,n,r){this.canvas=e,this.nodes=t,this.connections=n,this.coords=r}do(){let e=[1/0,1/0];for(let t of this.nodes)t.coords[0]<e[0]&&(e[0]=t.coords[0]),t.coords[1]<e[1]&&(e[1]=t.coords[1]);let t=this.coords===void 0?void 0:[this.coords[0]-e[0],this.coords[1]-e[1]],n={};for(let e of this.nodes){let r=e.id,i=this.canvas.collabEngine.freshId();if(n[r]=i,e.id=i,t&&(e.coords=[e.coords[0]+t[0],e.coords[1]+t[1]]),e.sections)for(let r of e.sections){let a=r.id;if(r.id.includes(e.id)?r.id=r.id.replace(e.id,i):r.id=this.canvas.collabEngine.freshId(),n[a]=r.id,t&&(r.coords=[r.coords[0]+t[0],r.coords[1]+t[1]]),r.ports)for(let a of r.ports){let r=a.id;a.id.includes(e.id)?a.id=a.id.replace(e.id,i):a.id=this.canvas.collabEngine.freshId(),n[r]=a.id,t&&(a.coords=[a.coords[0]+t[0],a.coords[1]+t[1]],a.connectionPoint&&=[a.connectionPoint[0]+t[0],a.connectionPoint[1]+t[1]])}}if(e.ports)for(let r of e.ports){let a=r.id;r.id.includes(e.id)?r.id=r.id.replace(e.id,i):r.id=this.canvas.collabEngine.freshId(),n[a]=r.id,t&&(r.coords=[r.coords[0]+t[0],r.coords[1]+t[1]],r.connectionPoint&&=[r.connectionPoint[0]+t[0],r.connectionPoint[1]+t[1]])}}for(let e of this.connections){let r=this.canvas.collabEngine.freshId();if(n[e.id]=r,e.id=r,e.start=n[e.start]||e.start,e.end=n[e.end]||e.end,t)for(let n=0;n<e.points.length;++n)e.points[n]=[e.points[n][0]+t[0],e.points[n][1]+t[1]]}let r=new bt(this.canvas,this.nodes,this.connections);return this.canvas.collabEngine.doCollaboratively(r),!0}undo(){let e=this.nodes.map(e=>this.canvas.model.nodes.get(e.id)!==void 0).includes(!0)||this.connections.map(e=>this.canvas.model.connections.get(e.id)!==void 0).includes(!0),t=new W(this.canvas,this.nodes.map(e=>e.id),[],[],this.connections.map(e=>e.id),[],!0,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(t),e}redo(){let e=this.nodes.map(e=>this.canvas.model.nodes.get(e.id)===void 0).includes(!0)||this.connections.map(e=>this.canvas.model.connections.get(e.id)===void 0).includes(!0),t=new W(this.canvas,this.nodes.map(e=>e.id),[],[],this.connections.map(e=>e.id),[],!1,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(t),e}},jt=class{constructor(e){this.type=e,this.defaultPrevented=!1}preventDefault(){this.defaultPrevented=!0}},Mt=function(e){return e[e.Zoom=0]=`Zoom`,e[e.DoubleClick=1]=`DoubleClick`,e[e.SecondaryClick=2]=`SecondaryClick`,e[e.Selection=3]=`Selection`,e[e.Highlight=4]=`Highlight`,e[e.DraggingNode=5]=`DraggingNode`,e}({}),Nt=class extends jt{constructor(e,t){super(0),this.coords=e,this.zoom=t}},Pt=class extends jt{constructor(e,t,n){super(1),this.cause=e,this.target=t,this.coords=n}},Ft=class extends jt{constructor(e,t,n){super(2),this.cause=e,this.target=t,this.coords=n}},q=class extends jt{constructor(e,t){super(3),this.targets=e,this.selected=t}},J=class extends jt{constructor(e){super(4),this.target=e}},It=class extends jt{constructor(e){super(5),this.target=e}},Lt=class{constructor(e,t,n,r,i,a=[]){this.nodes=new Ye(this),this.sections=new Ke(this),this.ports=new ut(this),this.connections=new Le(this),this.fields=new ze(this),this.objects=new it(this),this.decorators=new nt(this),this.canvas=e,this.id=t,this.name=n,this.description=r,this.type=i,this.createdAt=new Date,this.updatedAt=new Date,this.logicalClock=0,this.valueSet=new Fe(new ke(a),this)}clear(){this.canvas?.cancelAllUserActions(),this.id=void 0,this.name=``,this.description=void 0,this.createdAt=new Date,this.updatedAt=new Date,this.logicalClock=0,this.nodes.clear(),this.sections.clear(),this.ports.clear(),this.connections.clear(),this.fields.clear(),this.objects.clear(),this.decorators.clear(),this.valueSet.resetValues(),this.canvas?.updateModelInView()}},Rt=e=>!!e.button,zt=(e,t,n,r,i,a,o,s,c)=>ie(e,[t,...a,n],r,i,Math.max(10,s??0,c??0)*o),Y=e=>{e?c.select(`body`).style(`cursor`,e):c.select(`body`).style(`cursor`,D.Auto)},X=e=>e instanceof H?e:e instanceof B?e.node??e:e.rootElement instanceof H||e.rootElement instanceof B||e.rootElement instanceof lt?X(e.rootElement):e,Bt=e=>{if(e instanceof H)return e.type.resizableX!==!1;if(e instanceof B){if(e.type!==void 0)return e.type.resizableX!==!1;if(e.node!==void 0)return Bt(e.node)}return!1},Vt=e=>{if(e instanceof H)return e.type.resizableY!==!1;if(e instanceof B){if(e.type!==void 0)return e.type.resizableY!==!1;if(e.node!==void 0)return Vt(e.node)}return!1},Ht=e=>{e.filter(`.shaped-look`).append(`path`),e.filter(`.image-look`).append(`image`).attr(`preserveAspectRatio`,`none`),e.filter(`.stretchable-image-look`).append(`image`).attr(`class`,`top-left-image`).attr(`preserveAspectRatio`,`none`),e.filter(`.stretchable-image-look`).append(`image`).attr(`class`,`top-image`).attr(`preserveAspectRatio`,`none`),e.filter(`.stretchable-image-look`).append(`image`).attr(`class`,`top-right-image`).attr(`preserveAspectRatio`,`none`),e.filter(`.stretchable-image-look`).append(`image`).attr(`class`,`left-image`).attr(`preserveAspectRatio`,`none`),e.filter(`.stretchable-image-look`).append(`image`).attr(`class`,`center-image`).attr(`preserveAspectRatio`,`none`),e.filter(`.stretchable-image-look`).append(`image`).attr(`class`,`right-image`).attr(`preserveAspectRatio`,`none`),e.filter(`.stretchable-image-look`).append(`image`).attr(`class`,`bottom-left-image`).attr(`preserveAspectRatio`,`none`),e.filter(`.stretchable-image-look`).append(`image`).attr(`class`,`bottom-image`).attr(`preserveAspectRatio`,`none`),e.filter(`.stretchable-image-look`).append(`image`).attr(`class`,`bottom-right-image`).attr(`preserveAspectRatio`,`none`)},Ut={fillColor:`#FFFFFF`,borderColor:`#000000`,borderThickness:1,borderStyle:ne.Solid},Wt=e=>{e.filter(`.shaped-look`).select(`path`).attr(`d`,e=>se(e.look.shape??oe.Rectangle,0,0,e.width,e.height)).attr(`fill`,e=>e.look.fillColor??Ut.fillColor).attr(`stroke`,e=>e.look.borderColor??Ut.borderColor).attr(`stroke-width`,e=>`${e.look.borderThickness??Ut.borderThickness}px`).attr(`stroke-dasharray`,e=>ae(e.look.borderStyle??Ut.borderStyle,e.type?.defaultLook?.borderThickness??e.look?.borderThickness??Ut.borderThickness)),e.filter(`.image-look`).select(`image`).attr(`x`,0).attr(`y`,0).attr(`width`,e=>e.width).attr(`height`,e=>e.height).attr(`href`,e=>e.look.backgroundImage),e.filter(`.stretchable-image-look`).select(`image.top-left-image`).attr(`x`,0).attr(`y`,0).attr(`width`,e=>e.look.leftMargin).attr(`height`,e=>e.look.topMargin).attr(`href`,e=>e.look.backgroundImageTopLeft),e.filter(`.stretchable-image-look`).select(`image.top-image`).attr(`x`,e=>e.look.leftMargin).attr(`y`,0).attr(`width`,e=>e.width-e.look.rightMargin-e.look.leftMargin).attr(`height`,e=>e.look.topMargin).attr(`href`,e=>e.look.backgroundImageTop),e.filter(`.stretchable-image-look`).select(`image.top-right-image`).attr(`x`,e=>e.width-e.look.rightMargin).attr(`y`,0).attr(`width`,e=>e.look.rightMargin).attr(`height`,e=>e.look.topMargin).attr(`href`,e=>e.look.backgroundImageTopRight),e.filter(`.stretchable-image-look`).select(`image.left-image`).attr(`x`,0).attr(`y`,e=>e.look.topMargin).attr(`width`,e=>e.look.leftMargin).attr(`height`,e=>e.height-e.look.bottomMargin-e.look.topMargin).attr(`href`,e=>e.look.backgroundImageLeft),e.filter(`.stretchable-image-look`).select(`image.center-image`).attr(`x`,e=>e.look.leftMargin).attr(`y`,e=>e.look.topMargin).attr(`width`,e=>e.width-e.look.rightMargin-e.look.leftMargin).attr(`height`,e=>e.height-e.look.bottomMargin-e.look.topMargin).attr(`href`,e=>e.look.backgroundImageCenter),e.filter(`.stretchable-image-look`).select(`image.right-image`).attr(`x`,e=>e.width-e.look.rightMargin).attr(`y`,e=>e.look.topMargin).attr(`width`,e=>e.look.rightMargin).attr(`height`,e=>e.height-e.look.bottomMargin-e.look.topMargin).attr(`href`,e=>e.look.backgroundImageRight),e.filter(`.stretchable-image-look`).select(`image.bottom-left-image`).attr(`x`,0).attr(`y`,e=>e.height-e.look.bottomMargin).attr(`width`,e=>e.look.leftMargin).attr(`height`,e=>e.look.bottomMargin).attr(`href`,e=>e.look.backgroundImageBottomLeft),e.filter(`.stretchable-image-look`).select(`image.bottom-image`).attr(`x`,e=>e.look.leftMargin).attr(`y`,e=>e.height-e.look.bottomMargin).attr(`width`,e=>e.width-e.look.rightMargin-e.look.leftMargin).attr(`height`,e=>e.look.bottomMargin).attr(`href`,e=>e.look.backgroundImageBottom),e.filter(`.stretchable-image-look`).select(`image.bottom-right-image`).attr(`x`,e=>e.width-e.look.rightMargin).attr(`y`,e=>e.height-e.look.bottomMargin).attr(`width`,e=>e.look.rightMargin).attr(`height`,e=>e.look.bottomMargin).attr(`href`,e=>e.look.backgroundImageBottomRight)},Gt={style:`solid`,color:`#FFFFFF`},Kt={enabled:!0,style:`none`,snap:!1,spacing:1},qt={...Kt,style:`dots`,snap:!1,spacing:10,thickness:.05,color:`rgba(0, 0, 0, 0.1)`},Jt=(e,t,n)=>{switch(n?.style??``){case`image`:return t.append(`image`).attr(`x`,0).attr(`y`,0).attr(`width`,`100%`).attr(`height`,`100%`).attr(`href`,n.image).attr(`preserveAspectRatio`,`none`);default:return t.append(`rect`).attr(`x`,0).attr(`y`,0).attr(`width`,`100%`).attr(`height`,`100%`).attr(`fill`,n.color??`#FFFFFF`).attr(`stroke-width`,`0`)}},Yt=e=>{if(!e)return qt;switch(e.style){case`dots`:case`lines`:return{...qt,...e};default:return{...Kt,...e}}},Xt=(e,t,n,r,i)=>{if(Z(i)!==0&&Q(i)!==0){let e=n.append(`pattern`).attr(`id`,r).attr(`x`,-Z(i)/2).attr(`y`,-Q(i)/2).attr(`width`,Z(i)).attr(`height`,Q(i)).attr(`patternUnits`,`userSpaceOnUse`);switch(e.append(`rect`).attr(`x`,0).attr(`y`,0).attr(`width`,Z(i)).attr(`height`,Q(i)).attr(`fill`,`transparent`),i.style){case`dots`:e.append(`circle`).attr(`cx`,Z(i)/2).attr(`cy`,Q(i)/2).attr(`r`,Math.min(Z(i),Q(i))*(i.thickness??0)).attr(`fill`,i.color??``);break;case`lines`:e.append(`line`).attr(`x1`,Z(i)/2).attr(`x2`,Z(i)/2).attr(`y1`,0).attr(`y2`,Q(i)).attr(`stroke-width`,Math.min(Z(i),Q(i))*(i.thickness??0)).attr(`stroke`,i.color??``),e.append(`line`).attr(`x1`,0).attr(`x2`,(Z(i)-Z(i)*(i.thickness??0))/2).attr(`y1`,Q(i)/2).attr(`y2`,Q(i)/2).attr(`stroke-width`,Math.min(Z(i),Q(i))*(i.thickness??0)).attr(`stroke`,i.color??``),e.append(`line`).attr(`x1`,(Z(i)+Z(i)*(i.thickness??0))/2).attr(`x2`,Z(i)).attr(`y1`,Q(i)/2).attr(`y2`,Q(i)/2).attr(`stroke-width`,Math.min(Z(i),Q(i))*(i.thickness??0)).attr(`stroke`,i.color??``);break;case`image`:e.append(`image`).attr(`x`,0).attr(`y`,0).attr(`width`,Z(i)).attr(`height`,Q(i)).attr(`href`,i.image).attr(`preserveAspectRatio`,`none`);break}return t.append(`rect`).attr(`x`,0).attr(`y`,0).attr(`width`,`100%`).attr(`height`,`100%`).attr(`fill`,`url(#${r})`).attr(`stroke-width`,`0`)}},Z=e=>{let t=0;return typeof e.spacing==`number`?t=e.spacing:Array.isArray(e.spacing)&&typeof e.spacing[0]==`number`&&(t=e.spacing[0]),isFinite(t)?t:0},Q=e=>{let t=0;return typeof e.spacing==`number`?t=e.spacing:Array.isArray(e.spacing)&&typeof e.spacing[1]==`number`&&(t=e.spacing[1]),isFinite(t)?t:0},Zt=96,$=32,Qt=128,$t=Math.PI/4,en=100,tn={customButtons:[]},nn=class{constructor(e,t){this.canvas=e,this.config=t||tn}open(e){this.close();let t=this.canvas.getPointerLocationRelativeToRoot(e),n=this.canvas.getPointerLocationRelativeToCanvas(e),r=this.canvas.selectSVGElement().append(`foreignObject`).attr(`class`,`daga-context-menu`).attr(`x`,`${t[0]-Qt}px`).attr(`y`,`${t[1]-Qt}px`).attr(`width`,`${2*Qt}px`).attr(`height`,`${2*Qt}px`).style(`pointer-events`,`none`).on(x.ContextMenu,t=>{this.canvas.canUserPerformAction(G.ContextMenu)&&(e.preventDefault(),this.open(t))}).on(x.Click,e=>{e.preventDefault(),this.close()});this.contextMenuContainer=r;let i=[];this.canvas.userSelection.length!==0&&this.canvas.canUserPerformAction(G.Clipboard)&&this.canvas.canUserPerformAction(G.Remove)&&i.push({name:`CUT`,imageClass:`daga-cut`,onPress:e=>{e.userSelection.cutToClipboard(),e.cancelAllUserActions()}}),this.canvas.userSelection.length!==0&&this.canvas.canUserPerformAction(G.Clipboard)&&i.push({name:`COPY`,imageClass:`daga-copy`,onPress:e=>{e.userSelection.copyToClipboard(),e.cancelAllUserActions()}}),this.canvas.canUserPerformAction(G.Paste)&&i.push({name:`PASTE`,imageClass:`daga-paste`,onPress:e=>{e.userSelection.pasteFromClipboard(e.getClosestGridPoint(n)),e.cancelAllUserActions()}}),this.canvas.userSelection.length!==0&&this.canvas.canUserPerformAction(G.Remove)&&i.push({name:`DELETE`,imageClass:`daga-delete`,onPress:e=>{e.userSelection.removeFromModel(),e.cancelAllUserActions()}});for(let e of this.config.customButtons||tn.customButtons)(e.condition===void 0||e.condition(this.canvas))&&i.push(e);i.length===0&&i.push({name:`NONE`,imageClass:`daga-cross`,onPress:void 0});for(let e=0;e<i.length;++e){let t=i[e],n=t.onPress,a=(e+.5-i.length/2)*$t,o=r.append(`xhtml:div`).attr(`class`,`daga-context-menu-button ${t.onPress===void 0?``:` daga-clickable`}`).attr(`tabindex`,0).style(`position`,`absolute`).style(`box-sizing`,`border-box`).style(`width`,`${2*$}px`).style(`height`,`${2*$}px`).style(`border-radius`,`${$}px`).style(`pointer-events`,`auto`).on(x.Click,e=>{n&&(e.preventDefault(),n(this.canvas))}).on(x.KeyDown,e=>{n&&e.key===S.Enter&&(e.preventDefault(),n(this.canvas))});t.imageClass===void 0?t.image!==void 0&&o.append(`xhtml:img`).style(`position`,`absolute`).style(`left`,`${.75*$}px`).style(`top`,`${.5*$}px`).style(`width`,`${.5*$}px`).style(`height`,`${.5*$}px`).attr(`src`,t.image):o.append(`xhtml:div`).style(`position`,`absolute`).style(`left`,`${.75*$}px`).style(`top`,`${.5*$}px`).style(`width`,`${.5*$}px`).style(`height`,`${.5*$}px`).style(`background-size`,`contain`).style(`background-repeat`,`no-repeat`).attr(`class`,t.imageClass),o.append(`xhtml:span`).style(`position`,`absolute`).style(`left`,`${.2*$}px`).style(`top`,`${1.1*$}px`).style(`text-align`,`center`).style(`width`,`${1.6*$}px`).style(`height`,`${.35*$}px`).style(`margin`,`0`).style(`font-size`,`${.35*$}px`).style(`font-weight`,`700`).style(`user-select`,`none`).text(t.name),o.transition().ease(c.easeLinear).duration(en).tween(`progress`,()=>e=>{let t=a*e;return o.style(`left`,`${Math.sin(t)*Zt-$+Qt}px`).style(`top`,`${-Math.cos(t)*Zt-$+Qt}px`)})}}close(){this.contextMenuContainer?.remove(),this.contextMenuContainer=void 0}},rn=class extends A{constructor(e,t=!0){super(),this.focus=void 0,this.canvas=e,this.highlightSections=t}getFocus(){return this.focus}focusOn(e){this.clear(),this.focus=e,(e instanceof F||e instanceof tt)&&e.rootElement?this.focusOn(e.rootElement):this.add(e)}add(e){if(super.add(e),e instanceof H){if(!this.highlightSections)for(let t of e.sections){super.add(t);for(let e of t.ports)super.add(e),this.canvas.updatePortsInView(e.id);t.label&&(super.add(t.label),this.canvas.updateFieldsInView(t.label.id)),this.canvas.updateSectionsInView(t.id)}for(let t of e.ports)super.add(t),this.canvas.updatePortsInView(t.id);e.label&&(super.add(e.label),this.canvas.updateFieldsInView(e.label.id)),this.canvas.updateNodesInView(e.id)}else if(e instanceof B)if(!this.highlightSections&&e.node)this.add(e.node);else{for(let t of e.ports)super.add(t),this.canvas.updatePortsInView(t.id);e.label&&(super.add(e.label),this.canvas.updateFieldsInView(e.label.id)),this.canvas.updateSectionsInView(e.id)}else e instanceof lt?(e.label&&(super.add(e.label),this.canvas.updateFieldsInView(e.label.id)),this.canvas.updatePortsInView(e.id)):e instanceof N&&this.canvas.updateConnectionsInView(e.id)}clear(){for(;this.entities.length>0;){let e=this.entities[0];this.remove(e.id),e.updateInView()}this.focus=void 0}},an=class{export(e,t=!1){let n={name:e.name,type:e.type,typeVersion:1,createdAt:e.createdAt,updatedAt:e.updatedAt,nodes:[],connections:[],objects:[],data:e.valueSet.getValues(),...t?{collabMeta:{logicalClock:e.logicalClock,dataTimestamps:e.valueSet.getTimestamps()}}:{}};e.id&&(n.id=e.id),e.description&&(n.description=e.description);for(let r of e.nodes.all(!0))!t&&r.removed||r.parent===void 0&&n.nodes.push(this.exportNode(r,t));for(let r of e.connections.all(!0))!t&&r.removed||n.connections.push(this.exportConnection(r,t));for(let r of e.objects.all(!0))n.objects?.push({id:r.id,coords:g(r.coords),width:r.width,height:r.height,priority:r.priority,svg:r.svg,...t?{collabMeta:{removed:r.removed,selfRemoved:r.selfRemoved}}:{}});return n}exportNode(e,t=!1){let n=[];for(let r of e.children)n.push(this.exportNode(r,t));let r=[];for(let n of e.sections){let e=[];for(let r of n.ports)e.push({id:r.id,type:r.type?.id,coords:g(r.coords),connectionPoint:g(r.connectionPoint||r.coords),direction:r.direction,label:r.label?.text||``,...t?{collabMeta:{removed:r.removed,selfRemoved:r.selfRemoved,selfRemovedTimestamp:r.selfRemovedTimestamp,...this.exportLabelCollabMeta(r)}}:{}});let i=[];for(let e of n.decorators)i.push({id:e.id,coords:g(e.coords),width:e.width,height:e.height,priority:e.priority,svg:e.svg,anchorPoints:[e.anchorPointX,e.anchorPointY],...t?{collabMeta:{removed:e.removed,selfRemoved:e.selfRemoved}}:{}});r.push({id:n.id,ports:e,decorators:i,label:n.label?.text||``,indexXInNode:n.indexXInNode,indexYInNode:n.indexYInNode,coords:g(n.coords),width:n.width,height:n.height,...t?{collabMeta:{removed:n.removed,selfRemoved:n.selfRemoved,selfRemovedTimestamp:n.selfRemovedTimestamp,...this.exportLabelCollabMeta(n)}}:{}})}let i=[];for(let n of e.ports)i.push({id:n.id,type:n.type?.id,coords:g(n.coords),connectionPoint:g(n.connectionPoint||n.coords),direction:n.direction,label:n.label?.text||``,...t?{collabMeta:{removed:n.removed,selfRemoved:n.selfRemoved,selfRemovedTimestamp:n.selfRemovedTimestamp,...this.exportLabelCollabMeta(n)}}:{}});let a=[];for(let n of e.decorators)a.push({id:n.id,coords:g(n.coords),width:n.width,height:n.height,priority:n.priority,svg:n.svg,anchorPoints:[n.anchorPointX,n.anchorPointY],...t?{collabMeta:{removed:n.removed,selfRemoved:n.selfRemoved}}:{}});return{id:e.id,type:e.type.id,children:n,sections:r,ports:i,decorators:a,label:e.label?.text||``,coords:g(e.coords),width:e.width,height:e.height,data:e.valueSet.getValues(),...t?{collabMeta:{removed:e.removed,selfRemoved:e.selfRemoved,selfRemovedTimestamp:e.selfRemovedTimestamp,geometryTimestamp:e.geometryTimestamp,dataTimestamps:e.valueSet.getTimestamps(),...this.exportLabelCollabMeta(e)}}:{}}}exportConnection(e,t=!1){return{id:e.id,type:e.type.id,start:e.start?.id||``,end:e.end?.id||``,startLabel:e.startLabel,middleLabel:e.middleLabel,endLabel:e.endLabel,points:e.points,data:e.valueSet.getValues(),...t?{collabMeta:{removed:e.removed,selfRemoved:e.selfRemoved,selfRemovedTimestamp:e.selfRemovedTimestamp,dataTimestamps:e.valueSet.getTimestamps()}}:{}}}exportLabelCollabMeta({label:e}){return e?{label:{removed:e.removed,selfRemoved:e.selfRemoved,selfRemovedTimestamp:e.selfRemovedTimestamp,textTimestamp:e.textTimestamp}}:{}}},on=`Diagram properties`,sn=class extends A{constructor(e,t){super(),this.canvas=e,this.canvas.propertyEditorChanges$.pipe((0,l.debounceTime)(2e3)).subscribe(()=>{this.makeUpdateValuesAction()}),this.diagramPropertiesText=t===void 0?on:t}add(e){if(!this.contains(e.id)&&(this.length===0?this.propertyEditorSelection===void 0&&(e instanceof H||e instanceof N)?this.openInPropertyEditor(e):this.propertyEditorSelection===void 0&&e instanceof B?this.openInPropertyEditor(e.node):this.openInPropertyEditor(void 0):this.openInPropertyEditor(void 0),super.add(e),e.updateInView(),e instanceof H&&e.sections))for(let t of e.sections)super.add(t),t.updateInView()}remove(e){let t=this.get(e);if(t&&(this.propertyEditorSelection===t&&this.openInPropertyEditor(void 0),super.remove(e),t.updateInView(),t instanceof H&&t.sections))for(let e of t.sections)super.remove(e.id),e.updateInView()}toggle(e){this.contains(e.id)?this.remove(e.id):this.add(e)}clear(){for(this.openInPropertyEditor(void 0);this.entities.length>0;){let e=this.entities[0];super.remove(e.id),e.updateInView()}}move(e){for(let t of this.all())t instanceof H&&t.move([t.coords[0]+e[0],t.coords[1]+e[1]])}removeFromModel(){if(this.length>0){let e=[],t=[],n=[],r=[],i=[];for(let a of this.all())a instanceof H?e.push(a.id):a instanceof B?t.push(a.id):a instanceof lt?n.push(a.id):a instanceof N?r.push(a.id):a instanceof F&&i.push(a.id);let a=new kt(this.canvas,e,t,n,r,i);a.do(),this.canvas.actionStack.add(a)}}copyToClipboard(){let e={type:`daga-user-selection`,nodes:[],connections:[]},t=new an;for(let n of this.all())n instanceof H&&e.nodes.push(t.exportNode(n,!1)),n instanceof N&&e.connections.push(t.exportConnection(n,!1));navigator.clipboard.writeText(JSON.stringify(e))}cutToClipboard(){this.copyToClipboard(),this.removeFromModel()}pasteFromClipboard(e){navigator.clipboard.readText().then(t=>{try{let n=JSON.parse(t);if(n.type!==`daga-user-selection`)return;let r=new At(this.canvas,n.nodes,n.connections,e);this.canvas.actionStack.add(r),r.do()}catch{return}})}openInPropertyEditor(e,t=!0){t&&this.makeUpdateValuesAction();let n=this.canvas.parentComponent?.propertyEditor;if(n===void 0)return;let r=e?.valueSet;r?(this.propertyEditorSelection=e,t&&(this.propertyEditorValues=Te(r.getValues())),n&&(e instanceof H||e instanceof N?(e instanceof H?e.name?n.title=`${e.type.name}: ${e.name}`:n.title=e.type.name:e instanceof N&&(n.title=e.type.name),n.valueSet=void 0,n.valueSet=r):(n.title=this.diagramPropertiesText,n.valueSet=void 0,n.valueSet=r))):(this.propertyEditorSelection=void 0,this.propertyEditorValues=void 0,n&&(n.title=``,n.valueSet=void 0))}makeUpdateValuesAction(){if(this.propertyEditorSelection===void 0||this.propertyEditorValues===void 0)return;let e=this.propertyEditorSelection instanceof Lt?void 0:this.propertyEditorSelection.id;if(Me(this.propertyEditorValues,this.propertyEditorSelection?.valueSet.getValues()))return;let t=this.propertyEditorValues,n=Te(this.propertyEditorSelection?.valueSet.getValues()),[r,i]=Ne(t,n,this.propertyEditorSelection?.valueSet),a=new Ot(this.canvas,e,r,i);a.do(),this.canvas.actionStack.add(a),this.propertyEditorValues=n}},cn=`diagram-connection-unfinished`,ln=class e{static{this.canvasCount=0}get connectionType(){return this._connectionType}set connectionType(e){this._connectionType=e,this.parentComponent?.palette?.refreshPalette()}constructor(t,n){this.gridPatternId=`daga-grid-pattern-id-${++e.canvasCount}`,this.ancillaryGridPatternIds=[],this.zoomTransform=c.zoomIdentity,this.draggingFrom=[0,0],this.dragging=!1,this.secondaryButton=!1,this.validatorChange$=new l.Subject,this.diagramChange$=new l.Subject,this.diagramEvent$=new l.Subject,this.propertyEditorChanges$=new l.Subject,this.parentComponent=t,this.model=new Lt(this,void 0,n.name||`unnamed`,``,n.type||``,n.properties||[]),this.userSelection=new sn(this,n.components?.propertyEditor?.title),this.userHighlight=new rn(this,n.canvas?.highlightSections!==!1),this.contextMenu=new nn(this,n.canvas?.contextMenu),this.backgroundConfig=n.canvas?.background??Gt,this.gridConfig=Yt(n.canvas?.grid),this.ancillaryGridsConfig=[];for(let e=0;e<(n.canvas?.ancillaryGrids?.length||0);++e)this.ancillaryGridsConfig.push(Yt(n.canvas?.ancillaryGrids?.[e])),this.ancillaryGridPatternIds.push(`${this.gridPatternId}-ancillary-${e}`);if(this.zoomFactor=n.canvas?.zoomFactor||2,this.panRate=n.canvas?.panRate||100,this.inferConnectionType=n.connectionSettings?.inferConnectionType||!1,this.autoTightenConnections=n.connectionSettings?.autoTighten!==!1,this.tightenConnectionsAcrossPortTypes=n.connectionSettings?.tightenAcrossPortTypes||!1,this.allowConnectionLoops=n.connectionSettings?.allowLoops||!1,this.allowSharingPorts=n.connectionSettings?.sharePorts!==!1,this.allowSharingBothPorts=n.connectionSettings?.shareBothPorts||!1,this.portHighlightRadius=n.connectionSettings?.portHighlightRadius||100,this.multipleSelectionOn=!1,this.priorityThresholds=n.canvas?.priorityThresholds||[],this.priorityThreshold=this.priorityThresholds?this.priorityThresholds[0]:void 0,this.layoutFormat=n.layoutFormat,this.userActions=n.userActions||{},this.validators=[],this.actionStack=new St(this,25),this.collabEngine=new xt(this),n.nodeTypes)for(let e of n.nodeTypes){let t=new Je({...n.nodeTypeDefaults,...e});this.model.nodes.types.add(t)}if(n.portTypes)for(let e of n.portTypes){let t=new ct({...n.portTypeDefaults,...e});this.model.ports.types.add(t)}if(n.connectionTypes){for(let e of n.connectionTypes){let t=new Ie({...n.connectionTypeDefaults,...e});this.model.connections.types.add(t)}this._connectionType=n?.connectionSettings?.defaultConnection===void 0?void 0:this.model.connections.types.get(n.connectionSettings.defaultConnection)}}addValidator(e){this.validators.push(e),this.validatorChange$.next()}removeValidator(e){E(this.validators,e),this.validatorChange$.next()}getPriorityThresholdOptions(){return this.priorityThresholds}getPriorityThreshold(){return this.priorityThreshold}setPriorityThreshold(e){this.priorityThreshold=e,this.updateModelInView();for(let e of this.model.nodes)this.fitNodeInView(e.id);this.parentComponent?.palette?.refreshPalette()}initView(e){let t=c.select(e);t.html(``),this.diagramRoot=t.append(`div`).node(),this.selectRoot().attr(`tabindex`,0).style(`width`,`100%`).style(`height`,`100%`).append(`svg`).style(`width`,`100%`).style(`height`,`100%`),this.selectRoot().on(x.Click,()=>{this.selectRoot().node()?.focus()}).on(x.ContextMenu,e=>{if(this.dragging){e.preventDefault(),e.stopPropagation(),this.dragging=!1;return}let t=new Ft(e,null);this.diagramEvent$.next(t),!t.defaultPrevented&&this.canUserPerformAction(G.ContextMenu)&&(e.preventDefault(),this.contextMenu.open(e))}).on(x.DoubleClick,e=>{let t=new Pt(e,null);this.diagramEvent$.next(t)}).on(x.KeyDown,e=>{if(!e.ctrlKey&&(e.key===S.Delete||e.key===S.Backspace)&&this.canUserPerformAction(G.Remove)&&(this.userSelection.removeFromModel(),this.cancelAllUserActions()),e.ctrlKey&&e.key===`a`){e.preventDefault();for(let e of this.model.nodes)this.userSelection.add(e);for(let e of this.model.connections)this.userSelection.add(e);this.diagramEvent$.next(new q(this.userSelection.all(),!0))}if(e.ctrlKey&&e.key===`i`){e.preventDefault();let t=[],n=[];for(let e of this.model.nodes)this.userSelection.toggle(e),e.selected?t.push(e):n.push(e);for(let e of this.model.connections)this.userSelection.toggle(e),e.selected?t.push(e):n.push(e);t.length>0&&this.diagramEvent$.next(new q(t,!0)),n.length>0&&this.diagramEvent$.next(new q(n,!1))}if(e.ctrlKey&&e.key===`c`&&this.canUserPerformAction(G.Clipboard)&&(e.preventDefault(),this.userSelection.copyToClipboard(),this.cancelAllUserActions()),e.ctrlKey&&e.key===`x`&&this.canUserPerformAction(G.Clipboard)&&this.canUserPerformAction(G.Remove)&&(e.preventDefault(),this.userSelection.cutToClipboard(),this.cancelAllUserActions()),e.ctrlKey&&e.key===`v`&&this.canUserPerformAction(G.Paste)){e.preventDefault();let t=this.getCoordinatesOnScreen();this.userSelection.pasteFromClipboard(this.getClosestGridPoint([(t[0][0]+t[1][0])/2,(t[0][1]+t[1][1])/2])),this.cancelAllUserActions()}e.ctrlKey&&e.key===`y`&&(e.preventDefault(),this.actionStack.redo()),e.ctrlKey&&e.key===`z`&&(e.preventDefault(),this.actionStack.undo()),e.key===`+`&&this.canUserPerformAction(G.Zoom)&&(e.preventDefault(),this.zoomBy(this.zoomFactor)),e.key===`-`&&this.canUserPerformAction(G.Zoom)&&(e.preventDefault(),this.zoomBy(1/this.zoomFactor)),e.key===S.ArrowLeft&&this.canUserPerformAction(G.Zoom)&&(e.preventDefault(),this.translateBy(this.panRate/this.zoomTransform.k,0)),e.key===S.ArrowRight&&this.canUserPerformAction(G.Zoom)&&(e.preventDefault(),this.translateBy(-this.panRate/this.zoomTransform.k,0)),e.key===S.ArrowDown&&this.canUserPerformAction(G.Zoom)&&(e.preventDefault(),this.translateBy(0,-this.panRate/this.zoomTransform.k)),e.key===S.ArrowUp&&this.canUserPerformAction(G.Zoom)&&(e.preventDefault(),this.translateBy(0,this.panRate/this.zoomTransform.k))});let n=this.selectSVGElement().append(`g`).attr(`class`,`daga-canvas-view`).attr(`width`,`100%`).attr(`height`,`100%`);n.call(this.zoomBehavior=c.zoom().filter(e=>e.type!==x.DoubleClick).on(w.Zoom,e=>{if(e.sourceEvent){if(!this.canUserPerformAction(G.Zoom)){Y(D.NotAllowed);return}e.sourceEvent.type===x.Wheel&&e.sourceEvent.wheelDelta!==void 0?(e.sourceEvent.wheelDelta>0&&Y(D.ZoomIn),e.sourceEvent.wheelDelta<0&&Y(D.ZoomOut)):e.sourceEvent.type===x.MouseMove&&Y(D.AllScroll)}this.zoomTransform=e.transform;let t=e.transform.toString();this.selectCanvasElements().attr(`transform`,t);for(let e of[this.gridPatternId,...this.ancillaryGridPatternIds])this.selectCanvasView().select(`#${e}`).attr(`patternTransform`,t);this.contextMenu.close(),this.diagramEvent$.next(new Nt([this.zoomTransform.x,this.zoomTransform.y],this.zoomTransform.k))}).on(w.End,()=>{Y()}));let r=n.append(`defs`),i=[];i.push(Jt(this,n,this.backgroundConfig));for(let e=0;e<this.ancillaryGridsConfig.length;++e)i.push(Xt(this,n,r,this.ancillaryGridPatternIds[e],this.ancillaryGridsConfig[e]));i.push(Xt(this,n,r,this.gridPatternId,this.gridConfig));for(let e of i)e.on(x.MouseMove,e=>{if(this.unfinishedConnection!==void 0){let t=this.getPointerLocationRelativeToCanvas(e);this.unfinishedConnection.endCoords=t}}),e.on(x.MouseOver,()=>{this.userHighlight.size()>0&&(this.userHighlight.clear(),this.diagramEvent$.next(new J(null)))}),e.on(x.Click,()=>{if(this.userHighlight.size()>0&&(this.userHighlight.clear(),this.diagramEvent$.next(new J(null))),this.contextMenu.close(),this.userSelection.size()>0){let e=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new q(e,!1))}this.userSelection.openInPropertyEditor(this.model)}),e.call(c.drag().filter(e=>this.multipleSelectionOn||Rt(e)).on(C.Start,e=>{this.startMultipleSelection(e)}).on(C.Drag,e=>{this.continueMultipleSelection(e)}).on(C.End,e=>{this.finishMultipleSelection(e)}));n.append(`g`).attr(`class`,`daga-canvas-elements`)}getZoomLevel(){return this.zoomTransform.k}zoomBy(e){isNaN(e)||this.zoomBehavior.scaleBy(this.selectCanvasView(),e)}zoomTo(e){isNaN(e)||this.zoomBehavior.scaleTo(this.selectCanvasView(),e)}getViewCoordinates(){let e=this.selectCanvasView()?.select(`rect`)?.node()?.getBBox();return[((e.width+e.x)/2-this.zoomTransform.x)/this.zoomTransform.k,((e.height+e.y)/2-this.zoomTransform.y)/this.zoomTransform.k]}translateBy(e,t){!isNaN(e)&&!isNaN(t)&&this.zoomBehavior.translateBy(this.selectCanvasView(),e,t)}translateTo(e,t){!isNaN(e)&&!isNaN(t)&&this.zoomBehavior.translateTo(this.selectCanvasView(),e,t)}zoomAndPanTo(e,t,n,r){if(!r||r<=0){this.zoomBehavior.scaleTo(this.selectCanvasView(),n),this.zoomBehavior.translateTo(this.selectCanvasView(),e,t);return}this.zoomBehavior.interpolate(c.interpolate);let[i,a]=this.getViewCoordinates(),o=this.getZoomLevel(),s=e,l=t,u=n;this.selectCanvasElements().transition().duration(r).ease(c.easeCubicInOut).tween(`progress`,()=>{let e=!1;return t=>{try{if(!e){let e=t*(s-i)+i,n=t*(l-a)+a,r=t*(u-o)+o;this.zoomBehavior.scaleTo(this.selectCanvasView(),r),this.zoomBehavior.translateTo(this.selectCanvasView(),e,n)}}catch(t){console.warn(`Animation has been interrupted.`,t),e=!0}}})}center(e,t,n){if(this.model.nodes.length>0){let r=this.selectCanvasView().select(`rect`).node()?.getBBox(),i=e?.map(e=>this.model.nodes.get(e)).filter(e=>!!e)||this.model.nodes.all(),a=Math.min(...i.map(e=>e.coords[0])),o=Math.max(...i.map(e=>e.coords[0]+e.width)),s=(a+o)/2,c=o-a,l=r.width,u=Math.min(...i.map(e=>e.coords[1])),d=Math.max(...i.map(e=>e.coords[1]+e.height)),f=(u+d)/2,p=d-u,m=r.height,h=Math.min(l/c,m/p,t===void 0?1:t);this.zoomAndPanTo(s,f,h,n)}}getClosestGridPoint(e){let t=e[0],n=Z(this.gridConfig);n!==0&&(t=Math.round(t/n)*n);let r=e[1],i=Q(this.gridConfig);return i!==0&&(r=Math.round(r/i)*i),[t,r]}getCoordinatesOnScreen(){let e=this.selectSVGElement().node()?.getBoundingClientRect(),t=[e?.width||0,e?.height||0];return[[-this.zoomTransform.x/this.zoomTransform.k,-this.zoomTransform.y/this.zoomTransform.k],[(t[0]-this.zoomTransform.x)/this.zoomTransform.k,(t[1]-this.zoomTransform.y)/this.zoomTransform.k]]}getEventHoldingCoordinates(e){if(e.type===`drag`||e.type===`start`||e.type===`end`){let t=e.sourceEvent;if(t&&(t.type===`touchmove`||t.type===`touchstart`||t.type===`touchend`))return e.sourceEvent.touches[0]||e.sourceEvent.changedTouches[0]}return e}getPointerLocationRelativeToCanvas(e){return c.pointer(this.getEventHoldingCoordinates(e),this.selectCanvasElements().node())}getPointerLocationRelativeToRoot(e){return c.pointer(this.getEventHoldingCoordinates(e),this.selectSVGElement().node())}getPointerLocationRelativeToBody(e){return c.pointer(this.getEventHoldingCoordinates(e),c.select(`body`).node())}getPointerLocationRelativeToScreen(e){let t=this.getPointerLocationRelativeToBody(e);return[t[0]-window.scrollX,t[1]-window.scrollY]}updateModelInView(){this.updateNodesInView(),this.updateSectionsInView(),this.updatePortsInView(),this.updateConnectionsInView(),this.updateFieldsInView(),this.updateObjectsInView(),this.updateDecoratorsInView()}updateNodesInView(...e){let t=this.selectCanvasElements().selectAll(`g.diagram-node`).data(this.model.nodes.filter(e=>this.priorityThreshold===void 0?!0:e.getPriority()>=this.priorityThreshold),e=>e.id),n=t.exit(),r=t.enter().append(`g`).attr(`id`,e=>e.id).attr(`class`,e=>`diagram-node${Bt(e)?` resizable-x`:``}${Vt(e)?` resizable-y`:``} ${e.type.defaultLook.lookType}`);e&&e.length>0&&(t=t.filter(t=>e.includes(t.id)));let i=r.merge(t);n.remove(),r.on(x.MouseOver,(e,t)=>{this.dragging||(this.userHighlight.focusOn(t),this.diagramEvent$.next(new J(t)))}).on(x.Click,(e,t)=>{if(!e.ctrlKey&&!e.shiftKey){let e=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new q(e,!1))}this.userSelection.toggle(t),this.diagramEvent$.next(new q([t],t.selected))}).on(x.ContextMenu,(e,t)=>{if(this.dragging){e.preventDefault(),e.stopPropagation(),this.dragging=!1;return}let n=new Ft(e,t);this.diagramEvent$.next(n),!n.defaultPrevented&&this.canUserPerformAction(G.ContextMenu)&&(e.preventDefault(),this.userHighlight.focusOn(t),this.diagramEvent$.next(new J(t)),this.userSelection.add(t),this.diagramEvent$.next(new q([t],!0)),this.contextMenu.open(e))}).on(x.DoubleClick,(e,t)=>{let n=new Pt(e,t);this.diagramEvent$.next(n)}).call(c.drag().filter(e=>(this.secondaryButton=Rt(e),!0)).on(C.Start,(e,t)=>{this.multipleSelectionOn||this.secondaryButton?this.startMultipleSelection(e):this.startMovingNode(e,t)}).on(C.Drag,(e,t)=>{this.multipleSelectionOn||this.secondaryButton?this.continueMultipleSelection(e):this.continueMovingNode(e,t)}).on(C.End,(e,t)=>{this.multipleSelectionOn||this.secondaryButton?this.finishMultipleSelection(e):this.finishMovingNode(e,t),this.secondaryButton=!1})),Ht(r),r.filter(`.resizable-x`).append(`line`).attr(`class`,`left-resizer`).attr(`stroke`,`transparent`).attr(`stroke-width`,6).on(x.MouseOver,(e,t)=>{this.canUserPerformAction(G.StretchNode)&&t.getResizableX()&&!t.removed&&Y(D.EWResize)}).on(x.MouseOut,(e,t)=>{this.canUserPerformAction(G.StretchNode)&&t.getResizableX()&&!t.removed&&Y()}).call(c.drag().on(C.Start,(e,t)=>{this.canUserPerformAction(G.StretchNode)&&t.getResizableX()&&!t.removed?(Y(D.EWResize),this.currentAction=new K(this,G.StretchNode,t.id,t.getGeometry(),t.getGeometry())):Y(D.NotAllowed)}).on(C.Drag,(e,t)=>{if(this.canUserPerformAction(G.StretchNode)&&t.getResizableX()&&!t.removed){let n=this.getPointerLocationRelativeToCanvas(e);t.stretch(f.Left,t.coords[0]-n[0])}}).on(C.End,(e,t)=>{if(this.canUserPerformAction(G.StretchNode)&&t.getResizableX()&&!t.removed&&this.currentAction instanceof K&&this.currentAction.intent===G.StretchNode){let n=this.getPointerLocationRelativeToCanvas(e);this.gridConfig.snap&&(n=this.getClosestGridPoint([n[0]-t.type.snapToGridOffset[0],n[1]-t.type.snapToGridOffset[1]]),n[0]+=t.type.snapToGridOffset[0],n[1]+=t.type.snapToGridOffset[1]),t.stretch(f.Left,t.coords[0]-n[0]),this.currentAction.to=t.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}Y()})),r.filter(`.resizable-y`).append(`line`).attr(`class`,`top-resizer`).attr(`stroke`,`transparent`).attr(`stroke-width`,6).on(x.MouseOver,(e,t)=>{this.canUserPerformAction(G.StretchNode)&&t.getResizableY()&&!t.removed&&Y(D.NSResize)}).on(x.MouseOut,(e,t)=>{this.canUserPerformAction(G.StretchNode)&&t.getResizableY()&&!t.removed&&Y()}).call(c.drag().on(C.Start,(e,t)=>{this.canUserPerformAction(G.StretchNode)&&t.getResizableY()&&!t.removed?(Y(D.NSResize),this.currentAction=new K(this,G.StretchNode,t.id,t.getGeometry(),t.getGeometry())):Y(D.NotAllowed)}).on(C.Drag,(e,t)=>{if(this.canUserPerformAction(G.StretchNode)&&t.getResizableY()&&!t.removed){let n=this.getPointerLocationRelativeToCanvas(e);t.stretch(f.Top,t.coords[1]-n[1])}}).on(C.End,(e,t)=>{if(this.canUserPerformAction(G.StretchNode)&&t.getResizableY()&&!t.removed&&this.currentAction instanceof K&&this.currentAction.intent===G.StretchNode){let n=this.getPointerLocationRelativeToCanvas(e);this.gridConfig.snap&&(n=this.getClosestGridPoint([n[0]-t.type.snapToGridOffset[0],n[1]-t.type.snapToGridOffset[1]]),n[0]+=t.type.snapToGridOffset[0],n[1]+=t.type.snapToGridOffset[1]),t.stretch(f.Top,t.coords[1]-n[1]),this.currentAction.to=t.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}Y()})),r.filter(`.resizable-x`).append(`line`).attr(`class`,`right-resizer`).attr(`stroke`,`transparent`).attr(`stroke-width`,6).on(x.MouseOver,(e,t)=>{this.canUserPerformAction(G.StretchNode)&&t.getResizableX()&&!t.removed&&Y(D.EWResize)}).on(x.MouseOut,(e,t)=>{this.canUserPerformAction(G.StretchNode)&&t.getResizableX()&&!t.removed&&Y()}).call(c.drag().on(C.Start,(e,t)=>{this.canUserPerformAction(G.StretchNode)&&t.getResizableX()&&!t.removed?(Y(D.EWResize),this.currentAction=new K(this,G.StretchNode,t.id,t.getGeometry(),t.getGeometry())):Y(D.NotAllowed)}).on(C.Drag,(e,t)=>{if(this.canUserPerformAction(G.StretchNode)&&t.getResizableX()&&!t.removed){let n=this.getPointerLocationRelativeToCanvas(e);t.stretch(f.Right,n[0]-(t.coords[0]+t.width))}}).on(C.End,(e,t)=>{if(this.canUserPerformAction(G.StretchNode)&&t.getResizableX()&&!t.removed&&this.currentAction instanceof K&&this.currentAction.intent===G.StretchNode){let n=this.getPointerLocationRelativeToCanvas(e);this.gridConfig.snap&&(n=this.getClosestGridPoint([n[0]-t.type.snapToGridOffset[2],n[1]-t.type.snapToGridOffset[3]]),n[0]+=t.type.snapToGridOffset[2],n[1]+=t.type.snapToGridOffset[3]),t.stretch(f.Right,n[0]-(t.coords[0]+t.width)),this.currentAction.to=t.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}Y()})),r.filter(`.resizable-y`).append(`line`).attr(`class`,`bottom-resizer`).attr(`stroke`,`transparent`).attr(`stroke-width`,6).on(x.MouseOver,(e,t)=>{this.canUserPerformAction(G.StretchNode)&&t.getResizableY()&&!t.removed&&Y(D.NSResize)}).on(x.MouseOut,(e,t)=>{this.canUserPerformAction(G.StretchNode)&&t.getResizableY()&&!t.removed&&Y()}).call(c.drag().on(C.Start,(e,t)=>{this.canUserPerformAction(G.StretchNode)&&t.getResizableY()&&!t.removed?(Y(D.NSResize),this.currentAction=new K(this,G.StretchNode,t.id,t.getGeometry(),t.getGeometry())):Y(D.NotAllowed)}).on(C.Drag,(e,t)=>{if(this.canUserPerformAction(G.StretchNode)&&t.getResizableY()&&!t.removed){let n=this.getPointerLocationRelativeToCanvas(e);t.stretch(f.Bottom,n[1]-(t.coords[1]+t.height))}}).on(C.End,(e,t)=>{if(this.canUserPerformAction(G.StretchNode)&&t.getResizableY()&&!t.removed&&this.currentAction instanceof K&&this.currentAction.intent===G.StretchNode){let n=this.getPointerLocationRelativeToCanvas(e);this.gridConfig.snap&&(n=this.getClosestGridPoint([n[0]-t.type.snapToGridOffset[2],n[1]-t.type.snapToGridOffset[3]]),n[0]+=t.type.snapToGridOffset[2],n[1]+=t.type.snapToGridOffset[3]),t.stretch(f.Bottom,n[1]-(t.coords[1]+t.height)),this.currentAction.to=t.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}Y()})),i.attr(`transform`,e=>`translate(${e.coords[0]},${e.coords[1]})`).attr(`opacity`,e=>e.removed?.5:1),Wt(i),i.filter(`.resizable-x`).select(`line.left-resizer`).style(`pointer-events`,e=>e.getResizableX()?`initial`:`none`).attr(`x1`,6/2).attr(`x2`,6/2).attr(`y1`,0).attr(`y2`,e=>e.height),i.filter(`.resizable-y`).select(`line.top-resizer`).style(`pointer-events`,e=>e.getResizableY()?`initial`:`none`).attr(`x1`,0).attr(`x2`,e=>e.width).attr(`y1`,6/2).attr(`y2`,6/2),i.filter(`.resizable-x`).select(`line.right-resizer`).style(`pointer-events`,e=>e.getResizableX()?`initial`:`none`).attr(`x1`,e=>e.width-6/2).attr(`x2`,e=>e.width-6/2).attr(`y1`,0).attr(`y2`,e=>e.height),i.filter(`.resizable-y`).select(`line.bottom-resizer`).style(`pointer-events`,e=>e.getResizableY()?`initial`:`none`).attr(`x1`,0).attr(`x2`,e=>e.width).attr(`y1`,e=>e.height-6/2).attr(`y2`,e=>e.height-6/2)}updateSectionsInView(...e){let t=this.selectCanvasElements().selectAll(`g.diagram-section`).data(this.model.sections.filter(e=>this.priorityThreshold===void 0?!0:e.getPriority()>=this.priorityThreshold),e=>e.id),n=t.exit(),r=t.enter().append(`g`).attr(`id`,e=>e.id).attr(`class`,e=>`diagram-section${Bt(e)?` resizable-x`:``}${Vt(e)?` resizable-y`:``} ${e.look?.lookType}`);e&&e.length>0&&(t=t.filter(t=>e.includes(t.id)));let i=r.merge(t);n.remove(),r.on(x.MouseOver,(e,t)=>{this.dragging||(this.userHighlight.focusOn(t),this.diagramEvent$.next(new J(t)))}).on(x.Click,(e,t)=>{if(!e.ctrlKey&&!e.shiftKey){let e=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new q(e,!1))}let n=X(t);this.userSelection.toggle(n),this.diagramEvent$.next(new q([n],n.selected))}).on(x.ContextMenu,(e,t)=>{if(this.dragging){e.preventDefault(),e.stopPropagation(),this.dragging=!1;return}let n=new Ft(e,t);if(this.diagramEvent$.next(n),!n.defaultPrevented&&this.canUserPerformAction(G.ContextMenu)){e.preventDefault();let n=X(t);this.userHighlight.focusOn(n),this.diagramEvent$.next(new J(n)),this.userSelection.add(n),this.diagramEvent$.next(new q([n],!0)),this.contextMenu.open(e)}}).on(x.DoubleClick,(e,t)=>{let n=new Pt(e,t);this.diagramEvent$.next(n)}).call(c.drag().filter(e=>(this.secondaryButton=Rt(e),!0)).on(C.Start,(e,t)=>{if(this.multipleSelectionOn||this.secondaryButton)this.startMultipleSelection(e);else{let n=t?.node;n?this.startMovingNode(e,n):Y(D.NotAllowed)}}).on(C.Drag,(e,t)=>{if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(e);else{let n=t?.node;n?this.continueMovingNode(e,n):Y(D.NotAllowed)}}).on(C.End,(e,t)=>{if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(e);else{let n=t?.node;n?this.finishMovingNode(e,n):Y()}this.secondaryButton=!1})),Ht(r),r.filter(`.resizable-x`).append(`line`).attr(`class`,`left-resizer`).attr(`stroke`,`transparent`).attr(`stroke-width`,6).on(x.MouseOver,(e,t)=>{this.canUserPerformAction(G.StretchSection)&&t.getResizableX()&&!t.removed&&Y(D.EWResize)}).on(x.MouseOut,(e,t)=>{this.canUserPerformAction(G.StretchSection)&&t.getResizableX()&&!t.removed&&Y()}).call(c.drag().on(C.Start,(e,t)=>{this.canUserPerformAction(G.StretchSection)&&t.getResizableX()&&!t.removed&&t.node?(Y(D.EWResize),this.currentAction=new K(this,G.StretchSection,t.node.id,t.node.getGeometry(),t.node.getGeometry())):Y(D.NotAllowed)}).on(C.Drag,(e,t)=>{if(this.canUserPerformAction(G.StretchSection)&&t.getResizableX()&&!t.removed&&t.node){let n=this.getPointerLocationRelativeToCanvas(e);t.node.stretchSections(f.Left,t.coords[0]-n[0],t.indexXInNode,t.indexYInNode)}}).on(C.End,(e,t)=>{if(this.canUserPerformAction(G.StretchSection)&&t.getResizableX()&&!t.removed&&this.currentAction instanceof K&&this.currentAction.intent===G.StretchSection&&t.node){let n=this.getPointerLocationRelativeToCanvas(e);this.gridConfig.snap&&(n=this.getClosestGridPoint(n)),t.node.stretchSections(f.Left,t.coords[0]-n[0],t.indexXInNode,t.indexYInNode),this.currentAction.to=t.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}Y()})),r.filter(`.resizable-y`).append(`line`).attr(`class`,`top-resizer`).attr(`stroke`,`transparent`).attr(`stroke-width`,6).on(x.MouseOver,(e,t)=>{this.canUserPerformAction(G.StretchSection)&&t.getResizableY()&&!t.removed&&Y(D.NSResize)}).on(x.MouseOut,(e,t)=>{this.canUserPerformAction(G.StretchSection)&&t.getResizableY()&&!t.removed&&Y()}).call(c.drag().on(C.Start,(e,t)=>{this.canUserPerformAction(G.StretchSection)&&t.getResizableY()&&!t.removed&&t.node?(Y(D.NSResize),this.currentAction=new K(this,G.StretchSection,t.node.id,t.node.getGeometry(),t.node.getGeometry())):Y(D.NotAllowed)}).on(C.Drag,(e,t)=>{if(this.canUserPerformAction(G.StretchSection)&&t.getResizableY()&&!t.removed&&t.node){let n=this.getPointerLocationRelativeToCanvas(e);t.node.stretchSections(f.Top,t.coords[1]-n[1],t.indexXInNode,t.indexYInNode)}}).on(C.End,(e,t)=>{if(this.canUserPerformAction(G.StretchSection)&&t.getResizableY()&&!t.removed&&this.currentAction instanceof K&&this.currentAction.intent===G.StretchSection&&t.node){let n=this.getPointerLocationRelativeToCanvas(e);this.gridConfig.snap&&(n=this.getClosestGridPoint(n)),t.node.stretchSections(f.Top,t.coords[1]-n[1],t.indexXInNode,t.indexYInNode),this.currentAction.to=t.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}Y()})),r.filter(`.resizable-x`).append(`line`).attr(`class`,`right-resizer`).attr(`stroke`,`transparent`).attr(`stroke-width`,6).on(x.MouseOver,(e,t)=>{this.canUserPerformAction(G.StretchSection)&&t.getResizableX()&&!t.removed&&Y(D.EWResize)}).on(x.MouseOut,(e,t)=>{this.canUserPerformAction(G.StretchSection)&&t.getResizableX()&&!t.removed&&Y()}).call(c.drag().on(C.Start,(e,t)=>{this.canUserPerformAction(G.StretchSection)&&t.getResizableX()&&!t.removed&&t.node?(Y(D.EWResize),this.currentAction=new K(this,G.StretchSection,t.node.id,t.node.getGeometry(),t.node.getGeometry())):Y(D.NotAllowed)}).on(C.Drag,(e,t)=>{if(this.canUserPerformAction(G.StretchSection)&&t.getResizableX()&&!t.removed&&t.node){let n=this.getPointerLocationRelativeToCanvas(e);t.node.stretchSections(f.Right,n[0]-(t.coords[0]+t.width),t.indexXInNode,t.indexYInNode)}}).on(C.End,(e,t)=>{if(this.canUserPerformAction(G.StretchSection)&&t.getResizableX()&&!t.removed&&this.currentAction instanceof K&&this.currentAction.intent===G.StretchSection&&t.node){let n=this.getPointerLocationRelativeToCanvas(e);this.gridConfig.snap&&(n=this.getClosestGridPoint(n)),t.node.stretchSections(f.Right,n[0]-(t.coords[0]+t.width),t.indexXInNode,t.indexYInNode),this.currentAction.to=t.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}Y()})),r.filter(`.resizable-y`).append(`line`).attr(`class`,`bottom-resizer`).attr(`stroke`,`transparent`).attr(`stroke-width`,6).on(x.MouseOver,(e,t)=>{this.canUserPerformAction(G.StretchSection)&&t.getResizableY()&&!t.removed&&Y(D.NSResize)}).on(x.MouseOut,(e,t)=>{this.canUserPerformAction(G.StretchSection)&&t.getResizableY()&&!t.removed&&Y()}).call(c.drag().on(C.Start,(e,t)=>{this.canUserPerformAction(G.StretchSection)&&t.getResizableY()&&!t.removed&&t.node?(Y(D.NSResize),this.currentAction=new K(this,G.StretchSection,t.node.id,t.node.getGeometry(),t.node.getGeometry())):Y(D.NotAllowed)}).on(C.Drag,(e,t)=>{if(this.canUserPerformAction(G.StretchSection)&&t.getResizableY()&&!t.removed&&t.node){let n=this.getPointerLocationRelativeToCanvas(e);t.node.stretchSections(f.Bottom,n[1]-(t.coords[1]+t.height),t.indexXInNode,t.indexYInNode)}}).on(C.End,(e,t)=>{if(this.canUserPerformAction(G.StretchSection)&&t.getResizableY()&&!t.removed&&this.currentAction instanceof K&&this.currentAction.intent===G.StretchSection&&t.node){let n=this.getPointerLocationRelativeToCanvas(e);this.gridConfig.snap&&(n=this.getClosestGridPoint(n)),t.node.stretchSections(f.Bottom,n[1]-(t.coords[1]+t.height),t.indexXInNode,t.indexYInNode),this.currentAction.to=t.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}Y()})),i.attr(`transform`,e=>`translate(${e.coords[0]},${e.coords[1]})`).attr(`opacity`,e=>e.removed?.5:1),Wt(i),i.filter(`.resizable-x`).select(`line.left-resizer`).style(`pointer-events`,e=>e.getResizableX()?`initial`:`none`).attr(`x1`,6/2).attr(`x2`,6/2).attr(`y1`,0).attr(`y2`,e=>e.height),i.filter(`.resizable-y`).select(`line.top-resizer`).style(`pointer-events`,e=>e.getResizableY()?`initial`:`none`).attr(`x1`,0).attr(`x2`,e=>e.width).attr(`y1`,6/2).attr(`y2`,6/2),i.filter(`.resizable-x`).select(`line.right-resizer`).style(`pointer-events`,e=>e.getResizableX()?`initial`:`none`).attr(`x1`,e=>e.width-6/2).attr(`x2`,e=>e.width-6/2).attr(`y1`,0).attr(`y2`,e=>e.height),i.filter(`.resizable-y`).select(`line.bottom-resizer`).style(`pointer-events`,e=>e.getResizableY()?`initial`:`none`).attr(`x1`,0).attr(`x2`,e=>e.width).attr(`y1`,e=>e.height-6/2).attr(`y2`,e=>e.height-6/2)}updatePortsInView(...e){let t=this.selectCanvasElements().selectAll(`g.diagram-port`).data(this.model.ports.filter(e=>this.priorityThreshold===void 0?!0:e.getPriority()>=this.priorityThreshold),e=>e.id),n=t.exit(),r=t.enter().append(`g`).attr(`id`,e=>e.id).attr(`class`,e=>`diagram-port ${e.look.lookType}`);e&&e.length>0&&(t=t.filter(t=>e.includes(t.id)));let i=r.merge(t);n.remove(),r.on(x.MouseOver,(e,t)=>{!this.unfinishedConnection&&!this.dragging&&(this.userHighlight.focusOn(t),this.diagramEvent$.next(new J(t))),this.unfinishedConnection&&(this.unfinishedConnection.type.canStartFromType(this.unfinishedConnection.start?.getNode()?.type?.id||``)&&this.unfinishedConnection.start?.allowsOutgoing&&this.unfinishedConnection.type.canFinishOnType(t.getNode()?.type?.id||``)&&t.allowsIncoming||this.unfinishedConnection.type.canStartFromType(t.getNode()?.type?.id||``)&&t.allowsOutgoing&&this.unfinishedConnection.type.canFinishOnType(this.unfinishedConnection.start?.getNode()?.type?.id||``)&&this.unfinishedConnection.start?.allowsIncoming||Y(D.NoDrop))}).on(x.MouseOut,()=>{this.unfinishedConnection&&Y(D.Grabbing)}).on(x.Click,(e,t)=>{if(!e.ctrlKey&&!e.shiftKey){let e=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new q(e,!1))}let n=X(t);this.userSelection.toggle(n),this.diagramEvent$.next(new q([n],n.selected))}).on(x.ContextMenu,(e,t)=>{if(this.dragging){e.preventDefault(),e.stopPropagation(),this.dragging=!1;return}let n=new Ft(e,t);if(this.diagramEvent$.next(n),!n.defaultPrevented&&this.canUserPerformAction(G.ContextMenu)){e.preventDefault();let n=X(t);this.userHighlight.focusOn(n),this.diagramEvent$.next(new J(n)),this.userSelection.add(n),this.diagramEvent$.next(new q([n],!0)),this.contextMenu.open(e)}}).on(x.DoubleClick,(e,t)=>{let n=new Pt(e,t);this.diagramEvent$.next(n)}).call(c.drag().filter(e=>(this.secondaryButton=Rt(e),!0)).on(C.Start,(e,t)=>{this.multipleSelectionOn||this.secondaryButton?this.startMultipleSelection(e):this.canUserPerformAction(G.AddConnection)&&(this.allowSharingPorts||t.incomingConnections.filter(e=>!e.removed).length===0&&t.outgoingConnections.filter(e=>!e.removed).length===0)&&!t.removed?(Y(D.Grabbing),this.startConnection(t),this.unfinishedConnection&&(this.unfinishedConnectionTracer=this.selectCanvasElements().append(`path`).attr(`stroke`,`none`).attr(`fill`,`none`))):Y(D.NotAllowed)}).on(C.Drag,(e,t)=>{if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(e);else if(this.canUserPerformAction(G.AddConnection)&&!t.removed&&this.unfinishedConnection!==void 0){let t=[e.x,e.y];this.unfinishedConnectionTracer?.attr(`d`,zt(this.unfinishedConnection.look.shape||M.look.shape,this.unfinishedConnection.startCoords,t,this.unfinishedConnection.startDirection,this.unfinishedConnection.endDirection,this.unfinishedConnection.points,this.unfinishedConnection.type.defaultLook.thickness||M.look.thickness,this.unfinishedConnection.type.defaultStartMarkerLook?.width,this.unfinishedConnection.type.defaultEndMarkerLook?.width));let n=this.unfinishedConnectionTracer?.node();if(n){let e=2,t=n.getTotalLength();t<e&&(e=0);let r=n.getPointAtLength(t-e);this.unfinishedConnection.endCoords=[r.x,r.y]}else this.unfinishedConnection.endCoords=t;if(this.updateConnectionsInView(cn),this.unfinishedConnectionPort?.raise(!1),this.model.ports.length>0){let t=this.getPointerLocationRelativeToCanvas(e),n=1/0,r;for(let e of this.model.ports){let i=e.distanceTo(t);i<n&&(n=i,r=e)}r&&n<this.portHighlightRadius?this.userHighlight.focusOn(r):this.userHighlight.clear()}}}).on(C.End,(e,t)=>{if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(e);else{if(this.canUserPerformAction(G.AddConnection)&&!t.removed){this.unfinishedConnectionTracer?.remove();let t=this.userHighlight.getFocus();if(t instanceof lt)this.finishConnection(t);else if(t instanceof F&&t.rootElement instanceof lt)this.finishConnection(t.rootElement);else if(t instanceof H||t instanceof B||t instanceof F){let n;if(t instanceof H||t instanceof B)n=t;else if(t.rootElement instanceof H||t.rootElement instanceof B)n=t.rootElement;else{this.dropConnection();return}let r=n.getClosestPortToPoint([e.x,e.y]);r===void 0?this.dropConnection():this.finishConnection(r)}else this.dropConnection()}Y()}this.secondaryButton=!1})),r.filter(`.image-look`).append(`image`),Ht(r),i.attr(`transform`,e=>`translate(${e.coords[0]-e.width/2},${e.coords[1]-e.width/2})`).attr(`opacity`,e=>e.removed?.5:1),Wt(i)}updateConnectionsInView(...e){let t=this.model.connections.filter(e=>this.priorityThreshold===void 0?!0:e.getPriority()>=this.priorityThreshold);this.unfinishedConnection&&t.push(this.unfinishedConnection);let n=this.selectCanvasElements().selectAll(`g.diagram-connection`).data(t,e=>e.id),r=n.exit(),i=n.enter().append(`g`).attr(`id`,e=>e.id).attr(`class`,`diagram-connection`);e&&e.length>0&&(n=n.filter(t=>e.includes(t.id)));let a=i.merge(n);r.remove(),i.on(x.MouseOver,(e,t)=>{t.end!==void 0&&!this.dragging&&(this.userHighlight.focusOn(t),this.diagramEvent$.next(new J(t)))}).on(x.Click,(e,t)=>{if(!e.ctrlKey&&!e.shiftKey){let e=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new q(e,!1))}this.userSelection.toggle(t),this.diagramEvent$.next(new q([t],t.selected))}).on(x.ContextMenu,(e,t)=>{if(this.dragging){e.preventDefault(),e.stopPropagation(),this.dragging=!1;return}let n=new Ft(e,t);this.diagramEvent$.next(n),!n.defaultPrevented&&this.canUserPerformAction(G.ContextMenu)&&(e.preventDefault(),this.userHighlight.focusOn(t),this.diagramEvent$.next(new J(t)),this.userSelection.add(t),this.diagramEvent$.next(new q([t],!0)),this.contextMenu.open(e))}).on(x.DoubleClick,(e,t)=>{let n=new Pt(e,t);this.diagramEvent$.next(n)}).call(c.drag().filter(e=>(this.secondaryButton=Rt(e),!0)).on(C.Start,e=>{this.startMultipleSelection(e)}).on(C.Drag,e=>{this.continueMultipleSelection(e)}).on(C.End,e=>{this.finishMultipleSelection(e)})),i.append(`path`).attr(`class`,`diagram-connection-path`),i.append(`path`).attr(`class`,`diagram-connection-path-box`),i.append(`marker`).attr(`id`,e=>`${e.id}-start-marker`).attr(`class`,`diagram-connection-start-marker`).append(`image`).attr(`preserveAspectRatio`,`none`),i.append(`marker`).attr(`id`,e=>`${e.id}-end-marker`).attr(`class`,`diagram-connection-end-marker`).append(`image`).attr(`preserveAspectRatio`,`none`),i.append(`g`).attr(`class`,`diagram-connection-start-label`),i.select(`g.diagram-connection-start-label`).append(`path`),i.select(`g.diagram-connection-start-label`).append(`text`).style(`user-select`,`none`),i.append(`g`).attr(`class`,`diagram-connection-middle-label`),i.select(`g.diagram-connection-middle-label`).append(`path`),i.select(`g.diagram-connection-middle-label`).append(`text`).style(`user-select`,`none`),i.append(`g`).attr(`class`,`diagram-connection-end-label`),i.select(`g.diagram-connection-end-label`).append(`path`),i.select(`g.diagram-connection-end-label`).append(`text`).style(`user-select`,`none`),a.attr(`opacity`,e=>e.removed?.5:1).select(`path.diagram-connection-path`).attr(`d`,e=>zt(e.look.shape||M.look.shape,e.startCoords,e.endCoords,e.startDirection,e.endDirection,e.points,e.type.defaultLook.thickness||M.look.thickness,e.type.defaultStartMarkerLook?.width,e.type.defaultEndMarkerLook?.width)).attr(`marker-start`,e=>`url(#${e.id}-start-marker)`).attr(`marker-end`,e=>`url(#${e.id}-end-marker)`).attr(`stroke`,e=>e.look.color||M.look.color).attr(`stroke-width`,e=>e.look.thickness||M.look.thickness).attr(`stroke-dasharray`,e=>ae(e.look.style||M.look.style,e.type.defaultLook.thickness||M.look.thickness)).attr(`fill`,`none`),a.select(`path.diagram-connection-path-box`).attr(`d`,e=>zt(e.look.shape||M.look.shape,e.startCoords,e.endCoords,e.startDirection,e.endDirection,e.points,e.type.defaultLook.thickness||M.look.thickness,e.type.defaultStartMarkerLook?.width,e.type.defaultEndMarkerLook?.width)).attr(`stroke`,`transparent`).attr(`pointer-events`,`stroke`).attr(`stroke-width`,e=>(e.look.thickness||M.look.thickness)+12).attr(`stroke-dasharray`,e=>ae(e.look.style||M.look.style,e.type.defaultLook.thickness||M.look.thickness)).attr(`fill`,`none`),a.data().forEach(e=>{this.updateConnectionLabelsInView(e),this.updateConnectionMarkersInView(e)})}updateFieldsInView(...e){let t=this.selectCanvasElements().selectAll(`g.diagram-field`).data(this.model.fields.filter(e=>this.priorityThreshold===void 0?!0:e.getPriority()>=this.priorityThreshold),e=>e.id),n=t.exit(),r=t.enter().append(`g`).attr(`id`,e=>e.id).attr(`class`,`diagram-field`);e&&e.length>0&&(t=t.filter(t=>e.includes(t.id)));let i=r.merge(t);n.remove(),r.on(x.MouseOver,(e,t)=>{this.dragging||(this.userHighlight.focusOn(t),this.diagramEvent$.next(new J(t)))}).on(x.Click,(e,t)=>{if(!e.ctrlKey&&!e.shiftKey){let e=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new q(e,!1))}let n=X(t);this.userSelection.toggle(n),this.diagramEvent$.next(new q([n],n.selected))}).on(x.ContextMenu,(e,t)=>{if(this.dragging){e.preventDefault(),e.stopPropagation(),this.dragging=!1;return}let n=new Ft(e,t);if(this.diagramEvent$.next(n),!n.defaultPrevented&&this.canUserPerformAction(G.ContextMenu)){e.preventDefault();let n=X(t);this.userHighlight.focusOn(n),this.diagramEvent$.next(new J(n)),this.userSelection.add(n),this.diagramEvent$.next(new q([n],!0)),this.contextMenu.open(e)}}).on(x.DoubleClick,(e,t)=>{let n=new Pt(e,t);this.diagramEvent$.next(n),!n.defaultPrevented&&this.canUserPerformAction(G.EditField)&&t.editable&&!t.removed&&(this.currentAction=new Dt(this,t.id,t.text,``),this.openTextInput(t.id))}).call(c.drag().filter(e=>(this.secondaryButton=Rt(e),!0)).on(C.Start,(e,t)=>{if(this.multipleSelectionOn||this.secondaryButton)this.startMultipleSelection(e);else{let n;t.rootElement instanceof H?n=t.rootElement:t.rootElement instanceof B&&(n=t.rootElement.node),n?this.startMovingNode(e,n):Y(D.NotAllowed)}}).on(C.Drag,(e,t)=>{if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(e);else{let n;t.rootElement instanceof H?n=t.rootElement:t.rootElement instanceof B&&(n=t.rootElement.node),n?this.continueMovingNode(e,n):Y(D.NotAllowed)}}).on(C.End,(e,t)=>{if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(e);else{let n;t.rootElement instanceof H?n=t.rootElement:t.rootElement instanceof B&&(n=t.rootElement.node),n?this.finishMovingNode(e,n):Y()}this.secondaryButton=!1})),r.append(`text`).style(`user-select`,`none`).style(`font-kerning`,`none`).style(`white-space`,`nowrap`),r.append(`rect`),i.attr(`x`,0).attr(`y`,0).attr(`width`,e=>e.width).attr(`height`,e=>e.height).attr(`transform`,e=>`translate(${e.coords[0]},${e.coords[1]}) rotate(${e.orientation} ${e.width/2} ${e.height/2})`).attr(`opacity`,e=>e.removed?.5:1).select(`text`).attr(`x`,e=>e.horizontalAlign===m.Center?e.width/2:e.horizontalAlign===m.Right?e.width:0).attr(`text-anchor`,e=>e.horizontalAlign===m.Center?`middle`:e.horizontalAlign===m.Right?`end`:`start`).attr(`y`,e=>e.verticalAlign===h.Center?e.height/2:e.verticalAlign===h.Bottom?e.height:0).attr(`dominant-baseline`,e=>e.verticalAlign===h.Center?`middle`:e.verticalAlign===h.Bottom?`auto`:`hanging`).attr(`font-size`,e=>e.look.fontSize||P.look.fontSize).attr(`font-family`,e=>e.look.fontFamily||`'Wonder Unit Sans', sans-serif`).attr(`font-weight`,e=>e.look.fontWeight||P.look.fontWeight).attr(`fill`,e=>e.look.fontColor||P.look.fontColor).style(`font-kerning`,`none`).each(e=>{this.setFieldTextAndWrap(e)}),i.select(`rect`).attr(`x`,0).attr(`y`,0).attr(`width`,e=>e.width).attr(`height`,e=>e.height).attr(`fill`,`transparent`)}updateObjectsInView(...e){let t=this.selectCanvasElements().selectAll(`g.diagram-object`).data(this.model.objects.filter(e=>this.priorityThreshold===void 0?!0:e.getPriority()>=this.priorityThreshold),e=>e.id),n=t.exit(),r=t.enter().append(`g`).attr(`id`,e=>e.id).attr(`class`,`diagram-object`);e&&e.length>0&&(t=t.filter(t=>e.includes(t.id))),r.merge(t).attr(`width`,e=>e.width).attr(`height`,e=>e.height).attr(`transform`,e=>`translate(${e.coords[0]},${e.coords[1]})`).html(e=>e.svg),n.remove(),r.on(x.ContextMenu,(e,t)=>{if(this.dragging){e.preventDefault(),e.stopPropagation(),this.dragging=!1;return}let n=new Ft(e,t);this.diagramEvent$.next(n),!n.defaultPrevented&&this.canUserPerformAction(G.ContextMenu)&&(e.preventDefault(),this.contextMenu.open(e))}).on(x.DoubleClick,(e,t)=>{let n=new Pt(e,t);this.diagramEvent$.next(n)}).call(c.drag().filter(e=>(this.secondaryButton=Rt(e),!0)).on(C.Start,e=>{(this.multipleSelectionOn||this.secondaryButton)&&this.startMultipleSelection(e)}).on(C.Drag,e=>{(this.multipleSelectionOn||this.secondaryButton)&&this.continueMultipleSelection(e)}).on(C.End,e=>{(this.multipleSelectionOn||this.secondaryButton)&&this.finishMultipleSelection(e)}))}updateDecoratorsInView(...e){let t=this.selectCanvasElements().selectAll(`g.diagram-decorator`).data(this.model.decorators.filter(e=>this.priorityThreshold===void 0?!0:e.getPriority()>=this.priorityThreshold),e=>e.id),n=t.exit(),r=t.enter().append(`g`).attr(`id`,e=>e.id).attr(`class`,`diagram-decorator`);e&&e.length>0&&(t=t.filter(t=>e.includes(t.id))),r.merge(t).attr(`width`,e=>e.width).attr(`height`,e=>e.height).attr(`transform`,e=>`translate(${e.coords[0]},${e.coords[1]})`).html(e=>e.svg),n.remove(),r.on(x.MouseOver,(e,t)=>{this.dragging||(this.userHighlight.focusOn(t),this.diagramEvent$.next(new J(t)))}).on(x.Click,(e,t)=>{if(!e.ctrlKey&&!e.shiftKey){let e=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new q(e,!1))}if(t.rootElement){let e=X(t.rootElement);this.userSelection.toggle(e),this.diagramEvent$.next(new q([e],e.selected))}}).on(x.ContextMenu,(e,t)=>{if(this.dragging){e.preventDefault(),e.stopPropagation(),this.dragging=!1;return}let n=new Ft(e,t);if(this.diagramEvent$.next(n),!n.defaultPrevented&&this.canUserPerformAction(G.ContextMenu)&&t.rootElement){e.preventDefault();let n=X(t.rootElement);this.userHighlight.focusOn(n),this.diagramEvent$.next(new J(n)),this.userSelection.add(n),this.diagramEvent$.next(new q([n],!0)),this.contextMenu.open(e)}}).on(x.DoubleClick,(e,t)=>{let n=new Pt(e,t);this.diagramEvent$.next(n)}).call(c.drag().filter(e=>(this.secondaryButton=Rt(e),!0)).on(C.Start,(e,t)=>{if(this.multipleSelectionOn||this.secondaryButton)this.startMultipleSelection(e);else{let n;t.rootElement instanceof H?n=t.rootElement:t.rootElement instanceof B&&(n=t.rootElement.node),n?this.startMovingNode(e,n):Y(D.NotAllowed)}}).on(C.Drag,(e,t)=>{if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(e);else{let n;t.rootElement instanceof H?n=t.rootElement:t.rootElement instanceof B&&(n=t.rootElement.node),n?this.continueMovingNode(e,n):Y(D.NotAllowed)}}).on(C.End,(e,t)=>{if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(e);else{let n;t.rootElement instanceof H?n=t.rootElement:t.rootElement instanceof B&&(n=t.rootElement.node),n?this.finishMovingNode(e,n):Y()}this.secondaryButton=!1}))}updateConnectionLabelsInView(e){let t=this.selectCanvasView().select(`[id='${te(e.id)}']`),n=t.select(`path`).node(),r={...P,...e.type.label};if(r.look={...P.look,...r.look},n){let i=n.getTotalLength(),a=0,o=0,s=0,c=0,l=0,u=0;if(r.look.fillColor===`transparent`){let t=e.endCoords[0]-e.startCoords[0],n=e.endCoords[1]-e.startCoords[1];switch(e.startDirection){case f.Top:a=t>=0?-.5:.5,l=a;break;case f.Bottom:a=t>=0?-.5:.5,l=a;break;case f.Left:o=n>0?-.5:.5,u=o;break;case f.Right:o=n>0?-.5:.5,u=o;break;default:a=.5,l=a,o=-.5,u=o}switch(e.endDirection){case f.Top:l=t>=0?.5:-.5;break;case f.Bottom:l=t>=0?.5:-.5;break;case f.Left:u=n>0?.5:-.5;break;case f.Right:u=n>0?.5:-.5;break;default:l=.5,u=-.5}Math.abs(t)>=Math.abs(n)?(s=t>0?-.5:.5,c=n>0?.5:-.5):(s=t>0?.5:-.5,c=n>0?-.5:.5)}t.select(`g.diagram-connection-start-label text`).attr(`x`,0).attr(`y`,(r.look.fontSize||P.look.fontSize)/3).attr(`text-anchor`,`middle`).attr(`font-family`,r.look.fontFamily||P.look.fontFamily).attr(`font-size`,r.look.fontSize||P.look.fontSize).attr(`fill`,r.look.fontColor||P.look.fontColor).text(e.startLabel);let d=t.select(`g.diagram-connection-start-label text`).node()?.getBoundingClientRect();if(d){let i=e.startLabel?d.width/this.zoomTransform.k+Ve(r)+He(r):0,s=e.startLabel?d.height/this.zoomTransform.k+Ue(r)+Be(r):0,c;switch(e.startDirection){case f.Left:c=n.getPointAtLength(R(r)+i/2);break;case f.Right:c=n.getPointAtLength(L(r)+i/2);break;case f.Top:c=n.getPointAtLength(I(r)+s/2);break;case f.Bottom:c=n.getPointAtLength(z(r)+s/2);break;default:c=n.getPointAtLength(Math.max(L(r)+i/2,R(r)+i/2,z(r)+s/2,I(r)+s/2))}t.select(`g.diagram-connection-start-label path`).attr(`d`,pe(-i/2,-s/2,i,s)).attr(`fill`,r.look.fillColor||P.look.fillColor).attr(`stroke`,`none`),t.select(`g.diagram-connection-start-label`).attr(`transform`,`translate(${c.x+a*i},${c.y+o*s})`)}t.select(`g.diagram-connection-middle-label text`).attr(`x`,0).attr(`y`,(r.look.fontSize||P.look.fontSize)/3).attr(`text-anchor`,`middle`).attr(`font-family`,r.look.fontFamily||P.look.fontFamily).attr(`font-size`,r.look.fontSize||P.look.fontSize).attr(`fill`,r.look.fontColor||P.look.fillColor).style(`font-kerning`,`none`).text(e.middleLabel);let p=t.select(`g.diagram-connection-middle-label text`).node()?.getBoundingClientRect();if(p){let a=e.middleLabel?p.width/this.zoomTransform.k+Ve(r)+He(r):0,o=e.middleLabel?p.height/this.zoomTransform.k+Ue(r)+Be(r):0,l=n.getPointAtLength(i/2);t.select(`g.diagram-connection-middle-label path`).attr(`d`,pe(-a/2,-o/2,a,o)).attr(`fill`,r.look.fillColor||P.look.fillColor).attr(`stroke`,`none`),t.select(`g.diagram-connection-middle-label`).attr(`transform`,`translate(${l.x+s*a},${l.y+c*o})`)}t.select(`g.diagram-connection-end-label text`).attr(`x`,0).attr(`y`,(r.look.fontSize||P.look.fontSize)/3).attr(`text-anchor`,`middle`).attr(`font-family`,r.look.fontFamily||P.look.fontFamily).attr(`font-size`,r.look.fontSize||P.look.fontSize).attr(`fill`,r.look.fontColor||P.look.fontColor).style(`font-kerning`,`none`).text(e.endLabel);let m=t.select(`g.diagram-connection-end-label text`).node()?.getBoundingClientRect();if(m){let a=e.endLabel?m.width/this.zoomTransform.k+Ve(r)+He(r):0,o=e.endLabel?m.height/this.zoomTransform.k+Ue(r)+Be(r):0,s;switch(e.endDirection){case f.Left:s=n.getPointAtLength(i-(R(r)+a/2));break;case f.Right:s=n.getPointAtLength(i-(L(r)+a/2));break;case f.Top:s=n.getPointAtLength(i-(I(r)+o/2));break;case f.Bottom:s=n.getPointAtLength(i-(z(r)+o/2));break;default:s=n.getPointAtLength(i-Math.max(L(r)+a/2,R(r)+a/2,z(r)+o/2,I(r)+o/2))}t.select(`g.diagram-connection-end-label path`).attr(`d`,pe(-a/2,-o/2,a,o)).attr(`fill`,r.look.fillColor||P.look.fillColor).attr(`stroke`,`none`),t.select(`g.diagram-connection-end-label`).attr(`transform`,`translate(${s.x+l*a},${s.y+u*o})`)}}}updateConnectionMarkersInView(e){let t=this.selectCanvasView().select(`[id='${te(e.id)}']`),n=t.select(`marker.diagram-connection-start-marker`),r=t.select(`marker.diagram-connection-end-marker`);e.startMarkerLook===null?n.attr(`orient`,`auto-start-reverse`).attr(`markerWidth`,0).attr(`markerHeight`,0):n.attr(`orient`,`auto-start-reverse`).attr(`markerWidth`,e.startMarkerLook.width).attr(`markerHeight`,e.startMarkerLook.height).attr(`refX`,e.startMarkerLook.refX).attr(`refY`,e.startMarkerLook.refY).select(`image`).attr(`href`,e.startMarkerLook.image).attr(`width`,e.startMarkerLook.width).attr(`height`,e.startMarkerLook.height),e.endMarkerLook===null?r.attr(`orient`,`auto-start-reverse`).attr(`markerWidth`,0).attr(`markerHeight`,0):r.attr(`orient`,`auto-start-reverse`).attr(`markerWidth`,e.endMarkerLook.width).attr(`markerHeight`,e.endMarkerLook.height).attr(`refX`,e.endMarkerLook.refX).attr(`refY`,e.endMarkerLook.refY).select(`image`).attr(`href`,e.endMarkerLook.image).attr(`width`,e.endMarkerLook.width).attr(`height`,e.endMarkerLook.height)}fieldRootFitsInView(e){let t=this.model.fields.get(e);if(!t)return!1;if(t.rootElement instanceof H||t.rootElement instanceof B){let e=this.minimumSizeOfField(t),n=e[0]+L(t.rootElement.type?.label)+R(t.rootElement.type?.label)-t.rootElement.width,r=e[1]+z(t.rootElement.type?.label)+I(t.rootElement.type?.label)-t.rootElement.height;return n<=0&&r<=0}return!0}fitFieldRootInView(e,t=!0){let n=this.model.fields.get(e);if(n){if(n.rootElement instanceof H){let e=this.minimumSizeOfField(n),r=e[0]+L(n.rootElement.type.label)+R(n.rootElement.type.label)-n.rootElement.width,i=e[1]+z(n.rootElement.type.label)+I(n.rootElement.type.label)-n.rootElement.height,a=Z(this.gridConfig),o=Q(this.gridConfig);this.gridConfig.snap&&a!==0&&(r=Math.ceil(r/a)*a),this.gridConfig.snap&&o!==0&&(i=Math.ceil(i/o)*o),n.rootElement.width+r<n.rootElement.type.minWidth&&(r=n.rootElement.type.minWidth-n.rootElement.width),n.rootElement.height+i<n.rootElement.type.minHeight&&(i=n.rootElement.type.minHeight-n.rootElement.height),(t!==!1||r>0)&&n.rootElement.stretch(f.Right,r),(t!==!1||i>0)&&n.rootElement.stretch(f.Bottom,i)}if(n.rootElement instanceof B){let e=this.minimumSizeOfField(n),r=e[0],i=e[1];for(let e of n.rootElement.node?.sections||[])e.label&&(e.indexXInNode===n.rootElement.indexXInNode&&e.indexYInNode!==n.rootElement.indexYInNode?r=Math.max(r,this.minimumSizeOfField(e.label)[0]):e.indexXInNode!==n.rootElement.indexXInNode&&e.indexYInNode===n.rootElement.indexYInNode&&(i=Math.max(i,this.minimumSizeOfField(e.label)[1])));e[0]<r&&(e[0]=r),e[1]<i&&(e[1]=i);let a=n.rootElement.type,o=e[0]+L(a?.label)+R(a?.label)-n.rootElement.width,s=e[1]+z(a?.label)+I(a?.label)-n.rootElement.height,c=Z(this.gridConfig),l=Q(this.gridConfig);this.gridConfig.snap&&c!==0&&(o=Math.ceil(o/c)*c),this.gridConfig.snap&&l!==0&&(s=Math.ceil(s/l)*l),n.rootElement.width+o<(n.rootElement.getMinWidth()||0)&&(o=(n.rootElement.getMinWidth()||0)-n.rootElement.width),n.rootElement.height+s<(n.rootElement.getMinHeight()||0)&&(s=(n.rootElement.getMinHeight()||0)-n.rootElement.height),(t||o>0)&&n.rootElement.node?.stretchSections(f.Right,o,n.rootElement.indexXInNode,n.rootElement.indexYInNode),(t||s>0)&&n.rootElement.node?.stretchSections(f.Bottom,s,n.rootElement.indexXInNode,n.rootElement.indexYInNode)}}}fitNodeInView(e,t=!0){let n=this.model.nodes.get(e);if(n&&n.sections.length>0&&this.priorityThreshold){let e=0,r=0;for(let t of n.sections)if(t.getPriority()>=this.priorityThreshold){let i=t.coords[0]+t.width-n.coords[0],a=t.coords[1]+t.height-n.coords[1];e=Math.max(e,i),r=Math.max(r,a)}e+=n.type.sectionGrid?.margin||0,r+=n.type.sectionGrid?.margin||0,(t||e>n.width)&&n.stretch(f.Right,e-n.width),(t||r>n.height)&&n.stretch(f.Bottom,r-n.height)}}selectRoot(){return c.select(this.diagramRoot)}selectSVGElement(){return this.selectRoot().select(`svg`)}selectCanvasView(){return this.selectSVGElement().select(`.daga-canvas-view`)}selectCanvasElements(){return this.selectCanvasView().select(`.daga-canvas-elements`)}startConnection(e){if(e.allowsOutgoing||e.allowsIncoming){if(this.connectionType&&(this.connectionType.canStartFromType(e.getNode()?.type?.id||``)&&e.allowsOutgoing||this.connectionType.canFinishOnType(e.getNode()?.type?.id||``)&&e.allowsIncoming))this.unfinishedConnection=new N(this.model,this.connectionType,e,void 0,cn),this.unfinishedConnectionPort=e;else if(this.inferConnectionType){let t=this.model.connections.types.all().find(t=>e.allowsOutgoing&&t.canStartFromType(e.getNode()?.type?.id||``));t===void 0&&(t=this.model.connections.types.all().find(t=>e.allowsIncoming&&t.canFinishOnType(e.getNode()?.type?.id||``))),t!==void 0&&(this.unfinishedConnection=new N(this.model,t,e,void 0,cn),this.unfinishedConnectionPort=e)}}}finishConnection(e){if(this.userHighlight.clear(),this.unfinishedConnection!==void 0){if(!this.allowConnectionLoops&&this.unfinishedConnection.start===e){this.dropConnection();return}if(!this.allowSharingPorts&&(e.incomingConnections.filter(e=>!e.removed).length>0||e.outgoingConnections.filter(e=>!e.removed).length>0)){this.dropConnection();return}if(!this.allowSharingBothPorts&&this.model.connections.find(t=>!t.removed&&(t.start===this.unfinishedConnection?.start&&t.end===e||t.end===this.unfinishedConnection?.start&&t.start===e))!==void 0){this.dropConnection();return}if(this.unfinishedConnection.type.canStartFromType(this.unfinishedConnection?.start?.getNode()?.type?.id||``)&&this.unfinishedConnection?.start?.allowsOutgoing&&this.unfinishedConnection.type.canFinishOnType(e.getNode()?.type?.id||``)&&e.allowsIncoming){let t=new Et(this,this.unfinishedConnection.type,this.unfinishedConnection.start?.id,e.id);this.dropConnection(),t.do(),this.actionStack.add(t)}else if(this.unfinishedConnection.type.canFinishOnType(this.unfinishedConnection?.start?.getNode()?.type?.id||``)&&this.unfinishedConnection?.start?.allowsIncoming&&this.unfinishedConnection.type.canStartFromType(e.getNode()?.type?.id||``)&&e.allowsOutgoing){let t=new Et(this,this.unfinishedConnection.type,e.id,this.unfinishedConnection.start?.id);this.dropConnection(),t.do(),this.actionStack.add(t)}else if(this.inferConnectionType){let t=this.model.connections.types.all().find(t=>t.canStartFromType(this.unfinishedConnection?.start?.getNode()?.type?.id||``)&&this.unfinishedConnection?.start?.allowsOutgoing&&t.canFinishOnType(e.getNode()?.type?.id||``)&&e.allowsIncoming),n=!1;if(t===void 0&&(t=this.model.connections.types.all().find(t=>t.canFinishOnType(this.unfinishedConnection?.start?.getNode()?.type?.id||``)&&this.unfinishedConnection?.start?.allowsIncoming&&t.canStartFromType(e.getNode()?.type?.id||``)&&e.allowsOutgoing),n=!0),t!==void 0){let r=new Et(this,t,n?e.id:this.unfinishedConnection.start?.id,n?this.unfinishedConnection.start?.id:e.id);this.dropConnection(),r.do(),this.actionStack.add(r)}else this.dropConnection()}else this.dropConnection()}}dropConnection(){this.unfinishedConnection?.setStart(void 0),this.unfinishedConnection?.setEnd(void 0),this.unfinishedConnection?.select()?.remove(),this.unfinishedConnection=void 0,this.unfinishedConnectionPort=void 0}cancelAllUserActions(){this.currentAction=void 0,this.dropConnection(),this.removeInputField(),this.contextMenu.close(),this.userSelection.clear()}canUserPerformAction(e){return this.userActions[e]!==!1}openTextInput(e){let t=this.model.fields.get(e);t&&this.createInputField(t.text,t.coords,t.width,t.height,t.look.fontSize||P.look.fontSize,t.look.fontFamily||P.look.fontFamily,t.orientation,t.multiline,()=>{},e=>{t.text=e,this.currentAction instanceof Dt&&(this.currentAction.to=e,this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0)})}createInputField(e,t,n,r,i,a,o,s,c,l){this.removeInputField();let u=this.selectCanvasElements().append(`foreignObject`).attr(`x`,`${t[0]}px`).attr(`y`,`${t[1]}px`).attr(`width`,`${n}px`).attr(`height`,`${r}px`).style(`box-sizing`,`border-box`).style(`border`,`1px solid`);this.inputFieldContainer=u;let d=u.append(`xhtml:textarea`),f,p;d.text(e).style(`box-sizing`,`border-box`).style(`width`,`${n}px`).style(`height`,`${r}px`).style(`font-size`,`${i}px`).style(`font-family`,a).style(`resize`,`none`).style(`outline`,0).style(`border`,0).style(`margin`,0).style(`padding`,0).on(x.KeyDown,e=>{if(e.stopPropagation(),e.key===S.Escape||e.key===S.Enter&&!s){let e=d.property(`value`)||``;this.removeInputField(),l&&l(e)}}).on(x.KeyUp,e=>{e.stopPropagation()}).on(x.Input,()=>{let e=d.property(`value`);d.attr(`cols`,ve(e)+1),d.attr(`rows`,ye(e)+1),d.style(`width`,``),d.style(`height`,``),f=d.property(`scrollWidth`)+1,p=d.property(`scrollHeight`)+1;let t=Math.max(f,n),i=Math.max(p,r);u?.attr(`width`,`${t}px`),d.style(`width`,`${t}px`),u?.attr(`height`,`${i}px`),d.style(`height`,`${i}px`),c&&c(e)}).on(x.Click,e=>{e.stopPropagation()}).on(x.FocusOut,()=>{let e=d.property(`value`);this.removeInputField(),l&&l(e)});let m=d.node();m.focus(),m.select()}removeInputField(){this.inputFieldContainer?.select(`input`)?.on(x.Blur,null),this.inputFieldContainer?.remove(),this.inputFieldContainer=void 0}minimumSizeOfField(e){let t=e.select()?.select(`text`)?.node();if(!t)return[0,0];let n=t.getBoundingClientRect();return[n.width/this.zoomTransform.k,n.height/this.zoomTransform.k]}setFieldTextAndWrap(e){let t=e.select()?.select(`text`),n=t?.node();if(t&&n)this.setFieldText(e,t,e.text);else return;if(e.fit)return;let r=this.minimumSizeOfField(e);for(;r[0]>e.width||r[1]>e.height;){let n=t?.html()?.replace(/<\/tspan>/g,`
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require("d3");c=s(c);let l=require("rxjs"),u=require("react");u=s(u);let d=require("react/jsx-runtime");var f=function(e){return e.Bottom=`bottom`,e.Left=`left`,e.Right=`right`,e.Top=`top`,e}({}),p=function(e){return e.BottomLeft=`bottom-left`,e.BottomRight=`bottom-right`,e.TopLeft=`top-left`,e.TopRight=`top-right`,e}({}),m=function(e){return e.Left=`left`,e.Center=`center`,e.Right=`right`,e}({}),h=function(e){return e.Top=`top`,e.Center=`center`,e.Bottom=`bottom`,e}({}),g=e=>[Math.round(e[0]),Math.round(e[1])],_=(e,t,n)=>t<n?t<=e&&e<=n:n<=e&&e<=t,v=(e,t,n)=>(e-t[0])/(t[1]-t[0])*(n[1]-n[0])+n[0],y=(e,t,n,r,i,a,o)=>[(()=>{switch(a){case`start`:return r[0]+(e[0]-t[0]);case`end`:return r[1]-(t[1]-e[0]);case`middle`:{let n=(t[0]+t[1])/2,i=(r[0]+r[1])/2,a=t[1]-t[0],o=r[1]-r[0];return i+(e[0]-n)/a*o}default:return v(e[0],t,r)}})(),(()=>{switch(o){case`start`:return i[0]+(e[1]-n[0]);case`end`:return i[1]-(n[1]-e[1]);case`middle`:{let t=(n[0]+n[1])/2,r=(i[0]+i[1])/2,a=n[1]-n[0],o=i[1]-i[0];return r+(e[1]-t)/a*o}default:return v(e[1],n,i)}})()],b=(e,t)=>((e[0]-t[0])**2+(e[1]-t[1])**2)**.5,ee=(e,t)=>(_(e[0][0],t[0][0],t[1][0])||_(e[1][0],t[1][0],t[0][0])||_(t[0][0],e[0][0],e[1][0])||_(t[1][0],e[1][0],e[0][0]))&&(_(e[0][1],t[0][1],t[1][1])||_(e[1][1],t[1][1],t[0][1])||_(t[0][1],e[0][1],e[1][1])||_(t[1][1],e[1][1],e[0][1])),x=function(e){return e.Blur=`blur`,e.Change=`change`,e.Click=`click`,e.ContextMenu=`contextmenu`,e.DoubleClick=`dblclick`,e.Focus=`focus`,e.FocusIn=`focusin`,e.FocusOut=`focusout`,e.Input=`input`,e.KeyDown=`keydown`,e.KeyUp=`keyup`,e.MouseDown=`mousedown`,e.MouseEnter=`mouseenter`,e.MouseLeave=`mouseleave`,e.MouseMove=`mousemove`,e.MouseOut=`mouseout`,e.MouseOver=`mouseover`,e.MouseUp=`mouseup`,e.TouchStart=`touchstart`,e.TouchEnd=`touchend`,e.Wheel=`wheel`,e}({}),S=function(e){return e.Alt=`Alt`,e.AltGraph=`AltGraph`,e.ArrowDown=`ArrowDown`,e.ArrowLeft=`ArrowLeft`,e.ArrowRight=`ArrowRight`,e.ArrowUp=`ArrowUp`,e.Backspace=`Backspace`,e.Control=`Control`,e.Delete=`Delete`,e.End=`End`,e.Enter=`Enter`,e.Escape=`Escape`,e.Home=`Home`,e.OS=`OS`,e.PageDown=`PageDown`,e.PageUp=`PageUp`,e.Shift=`Shift`,e.Tab=`Tab`,e}({}),C=function(e){return e.Drag=`drag`,e.Start=`start`,e.End=`end`,e}({}),w=function(e){return e.Zoom=`zoom`,e.Start=`start`,e.End=`end`,e}({}),te=e=>e.replace(/([!"#$%&'()*+,\-./:;<=>?@[\\\]^`{|}])/g,`\\$1`),T=function(e){return e.Straight=`straight`,e.Bezier=`bezier`,e.Square=`square`,e}({}),ne=function(e){return e.Solid=`solid`,e.Dashed=`dashed`,e.GappedDashes=`gapped-dashes`,e.Dotted=`dotted`,e}({}),re=20,ie=(e,t,n,r,i)=>{if(typeof e==`function`)return e(t,n,r,i);if(t.length===0)return``;if(t.length===1)return`M ${t[0][0]} ${t[0][1]}`;{i||=re;let a=``,o,s;switch(e){case`straight`:a+=`M ${t[0][0]} ${t[0][1]}`;for(let e=1;e<t.length;++e)a+=` L ${t[e][0]} ${t[e][1]}`;break;case`bezier`:o=n,a+=`M ${t[0][0]} ${t[0][1]}`;for(let e=1;e<t.length;++e){if(e+1>=t.length)switch(r){case f.Bottom:s=f.Top;break;case f.Top:s=f.Bottom;break;case f.Right:s=f.Left;break;case f.Left:s=f.Right;break}else s=Math.abs(t[e][0]-t[e-1][0])<Math.abs(t[e][1]-t[e-1][1])?t[e][1]>t[e-1][1]?f.Bottom:f.Top:t[e][0]>t[e-1][0]?f.Right:f.Left;if(o!==void 0){let n=``,r=``,i=(Math.abs(t[e][0]-t[e-1][0])+Math.abs(t[e][1]-t[e-1][1]))/2;switch(o){case f.Bottom:n=`${t[e-1][0]} ${t[e-1][1]+i}`;break;case f.Top:n=`${t[e-1][0]} ${t[e-1][1]-i}`;break;case f.Right:n=`${t[e-1][0]+i} ${t[e-1][1]}`;break;case f.Left:n=`${t[e-1][0]-i} ${t[e-1][1]}`;break}if(s!==void 0){switch(s){case f.Top:r=`${t[e][0]} ${t[e][1]+i}`;break;case f.Bottom:r=`${t[e][0]} ${t[e][1]-i}`;break;case f.Left:r=`${t[e][0]+i} ${t[e][1]}`;break;case f.Right:r=`${t[e][0]-i} ${t[e][1]}`;break}a+=` C ${n} ${r} ${t[e][0]} ${t[e][1]}`}else a+=` Q ${n} ${t[e][0]} ${t[e][1]}`}else if(s!==void 0){let n=``,r=(Math.abs(t[e][0]-t[e-1][0])+Math.abs(t[e][1]-t[e-1][1]))/2;switch(s){case f.Top:n=`${t[e][0]} ${t[e][1]+r}`;break;case f.Bottom:n=`${t[e][0]} ${t[e][1]-r}`;break;case f.Left:n=`${t[e][0]+r} ${t[e][1]}`;break;case f.Right:n=`${t[e][0]-r} ${t[e][1]}`;break}a+=` Q ${n} ${t[e][0]} ${t[e][1]}`}else a+=` L ${t[e][0]} ${t[e][1]}`;o=s}break;case`square`:o=n,a+=`M ${t[0][0]} ${t[0][1]}`;for(let e=1;e<t.length;++e){if(e+1>=t.length)switch(r){case f.Bottom:s=f.Top;break;case f.Top:s=f.Bottom;break;case f.Right:s=f.Left;break;case f.Left:s=f.Right;break}switch(o){case f.Bottom:switch(s){case f.Bottom:t[e][1]>t[e-1][1]?(t[e][0]===t[e-1][0]?a+=` V ${t[e][1]}`:(a+=` V ${(t[e][1]+t[e-1][1])/2}`,a+=` H ${t[e][0]}`,a+=` V ${t[e][1]}`),o=s):t[e][0]>t[e-1][0]?(a+=` V ${t[e-1][1]+i}`,a+=` H ${Math.max(t[e-1][0],t[e][0])+i}`,a+=` V ${t[e][1]-i}`,a+=` H ${t[e][0]}`,a+=` V ${t[e][1]}`):(a+=` V ${t[e-1][1]+i}`,a+=` H ${Math.min(t[e-1][0],t[e][0])-i}`,a+=` V ${t[e][1]-i}`,a+=` H ${t[e][0]}`,a+=` V ${t[e][1]}`);break;case f.Top:a+=` V ${Math.max(t[e-1][1],t[e][1])+i}`,a+=` H ${t[e][0]}`,a+=` V ${t[e][1]}`;break;case f.Left:t[e][1]>t[e-1][1]+i?t[e][0]<t[e-1][0]-i?(a+=` V ${t[e][1]}`,a+=` H ${t[e][0]}`):(a+=` V ${(t[e-1][1]+t[e][1])/2}`,a+=` H ${t[e][0]+i}`,a+=` V ${t[e][1]}`,a+=` H ${t[e][0]}`):t[e][0]<t[e-1][0]-i?(a+=` V ${t[e-1][1]+i}`,a+=` H ${(t[e-1][0]+t[e][0])/2}`,a+=` V ${t[e][1]}`,a+=` H ${t[e][0]}`):(a+=` V ${t[e-1][1]+i}`,a+=` H ${t[e][0]+i}`,a+=` V ${t[e][1]}`,a+=` H ${t[e][0]}`);break;case f.Right:t[e][1]>t[e-1][1]+i?t[e][0]>t[e-1][0]+i?(a+=` V ${t[e][1]}`,a+=` H ${t[e][0]}`):(a+=` V ${(t[e-1][1]+t[e][1])/2}`,a+=` H ${t[e][0]-i}`,a+=` V ${t[e][1]}`,a+=` H ${t[e][0]}`):t[e][0]>t[e-1][0]+i?(a+=` V ${t[e-1][1]+i}`,a+=` H ${(t[e-1][0]+t[e][0])/2}`,a+=` V ${t[e][1]}`,a+=` H ${t[e][0]}`):(a+=` V ${t[e-1][1]+i}`,a+=` H ${t[e][0]-i}`,a+=` V ${t[e][1]}`,a+=` H ${t[e][0]}`);break;default:t[e][1]<t[e-1][1]+i?(a+=` V ${t[e-1][1]+i}`,t[e][0]!==t[e-1][0]&&(a+=` H ${t[e][0]}`),a+=` V ${t[e][1]}`,o=f.Top):(a+=` V ${t[e][1]}`,o=f.Bottom,t[e][0]!==t[e-1][0]&&(a+=` H ${t[e][0]}`,o=t[e][0]>t[e-1][0]?f.Right:f.Left));break}break;case f.Top:switch(s){case f.Top:t[e][1]<t[e-1][1]?(t[e][0]===t[e-1][0]?a+=` V ${t[e][1]}`:(a+=` V ${(t[e][1]+t[e-1][1])/2}`,a+=` H ${t[e][0]}`,a+=` V ${t[e][1]}`),o=s):t[e][0]<t[e-1][0]?(a+=` V ${t[e-1][1]-i}`,a+=` H ${Math.min(t[e-1][0],t[e][0])-i}`,a+=` V ${t[e][1]+i}`,a+=` H ${t[e][0]}`,a+=` V ${t[e][1]}`):(a+=` V ${t[e-1][1]-i}`,a+=` H ${Math.max(t[e-1][0],t[e][0])+i}`,a+=` V ${t[e][1]+i}`,a+=` H ${t[e][0]}`,a+=` V ${t[e][1]}`);break;case f.Bottom:a+=` V ${Math.min(t[e-1][1],t[e][1])-i}`,a+=` H ${t[e][0]}`,a+=` V ${t[e][1]}`;break;case f.Right:t[e][1]<t[e-1][1]-i?t[e][0]>t[e-1][0]+i?(a+=` V ${t[e][1]}`,a+=` H ${t[e][0]}`):(a+=` V ${(t[e-1][1]+t[e][1])/2}`,a+=` H ${t[e][0]-i}`,a+=` V ${t[e][1]}`,a+=` H ${t[e][0]}`):t[e][0]>t[e-1][0]+i?(a+=` V ${t[e-1][1]-i}`,a+=` H ${(t[e-1][0]+t[e][0])/2}`,a+=` V ${t[e][1]}`,a+=` H ${t[e][0]}`):(a+=` V ${t[e-1][1]-i}`,a+=` H ${t[e][0]-i}`,a+=` V ${t[e][1]}`,a+=` H ${t[e][0]}`);break;case f.Left:t[e][1]<t[e-1][1]-i?t[e][0]<t[e-1][0]-i?(a+=` V ${t[e][1]}`,a+=` H ${t[e][0]}`):(a+=` V ${(t[e-1][1]+t[e][1])/2}`,a+=` H ${t[e][0]+i}`,a+=` V ${t[e][1]}`,a+=` H ${t[e][0]}`):t[e][0]<t[e-1][0]-i?(a+=` V ${t[e-1][1]-i}`,a+=` H ${(t[e-1][0]+t[e][0])/2}`,a+=` V ${t[e][1]}`,a+=` H ${t[e][0]}`):(a+=` V ${t[e-1][1]-i}`,a+=` H ${t[e][0]+i}`,a+=` V ${t[e][1]}`,a+=` H ${t[e][0]}`);break;default:t[e][1]>t[e-1][1]-i?(a+=` V ${t[e-1][1]-i}`,t[e][0]!==t[e-1][0]&&(a+=` H ${t[e][0]}`),a+=` V ${t[e][1]}`,o=f.Bottom):(a+=` V ${t[e][1]}`,o=f.Top,t[e][0]!==t[e-1][0]&&(a+=` H ${t[e][0]}`,o=t[e][0]>t[e-1][0]?f.Right:f.Left));break}break;case f.Left:switch(s){case f.Left:t[e][0]<t[e-1][0]?(t[e][1]===t[e-1][1]?a+=` H ${t[e][0]}`:(a+=` H ${(t[e][0]+t[e-1][0])/2}`,a+=` V ${t[e][1]}`,a+=` H ${t[e][0]}`),o=s):t[e][1]<t[e-1][1]?(a+=` H ${t[e-1][0]-i}`,a+=` V ${Math.min(t[e-1][1],t[e][1])-i}`,a+=` H ${t[e][0]+i}`,a+=` V ${t[e][1]}`,a+=` H ${t[e][0]}`):(a+=` H ${t[e-1][0]-i}`,a+=` V ${Math.max(t[e-1][1],t[e][1])+i}`,a+=` H ${t[e][0]+i}`,a+=` V ${t[e][1]}`,a+=` H ${t[e][0]}`);break;case f.Right:a+=` H ${Math.min(t[e-1][0],t[e][0])-i}`,a+=` V ${t[e][1]}`,a+=` H ${t[e][0]}`;break;case f.Bottom:t[e][0]<t[e-1][0]-i?t[e][1]>t[e-1][1]+i?(a+=` H ${t[e][0]}`,a+=` V ${t[e][1]}`):(a+=` H ${(t[e-1][0]+t[e][0])/2}`,a+=` V ${t[e][1]-i}`,a+=` H ${t[e][0]}`,a+=` V ${t[e][1]}`):t[e][1]>t[e-1][1]+i?(a+=` H ${t[e-1][0]-i}`,a+=` V ${(t[e-1][1]+t[e][1])/2}`,a+=` H ${t[e][0]}`,a+=` V ${t[e][1]}`):(a+=` H ${t[e-1][0]-i}`,a+=` V ${t[e][1]-i}`,a+=` H ${t[e][0]}`,a+=` V ${t[e][1]}`);break;case f.Top:t[e][0]<t[e-1][0]-i?t[e][1]<t[e-1][1]-i?(a+=` H ${t[e][0]}`,a+=` V ${t[e][1]}`):(a+=` H ${(t[e-1][0]+t[e][0])/2}`,a+=` V ${t[e][1]+i}`,a+=` H ${t[e][0]}`,a+=` V ${t[e][1]}`):t[e][1]<t[e-1][1]-i?(a+=` H ${t[e-1][0]-i}`,a+=` V ${(t[e-1][1]+t[e][1])/2}`,a+=` H ${t[e][0]}`,a+=` V ${t[e][1]}`):(a+=` H ${t[e-1][0]-i}`,a+=` V ${t[e][1]+i}`,a+=` H ${t[e][0]}`,a+=` V ${t[e][1]}`);break;default:t[e][0]>t[e-1][0]-i?(a+=` H ${t[e-1][0]-i}`,t[e][1]!==t[e-1][1]&&(a+=` V ${t[e][1]}`),a+=` H ${t[e][0]}`,o=f.Right):(a+=` H ${t[e][0]}`,o=f.Left,t[e][1]!==t[e-1][1]&&(a+=` V ${t[e][1]}`,o=t[e][1]>t[e-1][1]?f.Bottom:f.Top));break}break;case f.Right:switch(s){case f.Right:t[e][0]>t[e-1][0]?(t[e][1]===t[e-1][1]?a+=` H ${t[e][0]}`:(a+=` H ${(t[e][0]+t[e-1][0])/2}`,a+=` V ${t[e][1]}`,a+=` H ${t[e][0]}`),o=s):t[e][1]>t[e-1][1]?(a+=` H ${t[e-1][0]+i}`,a+=` V ${Math.max(t[e-1][1],t[e][1])+i}`,a+=` H ${t[e][0]-i}`,a+=` V ${t[e][1]}`,a+=` H ${t[e][0]}`):(a+=` H ${t[e-1][0]+i}`,a+=` V ${Math.min(t[e-1][1],t[e][1])-i}`,a+=` H ${t[e][0]-i}`,a+=` V ${t[e][1]}`,a+=` H ${t[e][0]}`);break;case f.Left:a+=` H ${Math.max(t[e-1][0],t[e][0])+i}`,a+=` V ${t[e][1]}`,a+=` H ${t[e][0]}`;break;case f.Top:t[e][0]>t[e-1][0]+i?t[e][1]<t[e-1][1]-i?(a+=` H ${t[e][0]}`,a+=` V ${t[e][1]}`):(a+=` H ${(t[e-1][0]+t[e][0])/2}`,a+=` V ${t[e][1]+i}`,a+=` H ${t[e][0]}`,a+=` V ${t[e][1]}`):t[e][1]<t[e-1][1]-i?(a+=` H ${t[e-1][0]+i}`,a+=` V ${(t[e-1][1]+t[e][1])/2}`,a+=` H ${t[e][0]}`,a+=` V ${t[e][1]}`):(a+=` H ${t[e-1][0]+i}`,a+=` V ${t[e][1]+i}`,a+=` H ${t[e][0]}`,a+=` V ${t[e][1]}`);break;case f.Bottom:t[e][0]>t[e-1][0]+i?t[e][1]>t[e-1][1]+i?(a+=` H ${t[e][0]}`,a+=` V ${t[e][1]}`):(a+=` H ${(t[e-1][0]+t[e][0])/2}`,a+=` V ${t[e][1]-i}`,a+=` H ${t[e][0]}`,a+=` V ${t[e][1]}`):t[e][1]>t[e-1][1]+i?(a+=` H ${t[e-1][0]+i}`,a+=` V ${(t[e-1][1]+t[e][1])/2}`,a+=` H ${t[e][0]}`,a+=` V ${t[e][1]}`):(a+=` H ${t[e-1][0]+i}`,a+=` V ${t[e][1]-i}`,a+=` H ${t[e][0]}`,a+=` V ${t[e][1]}`);break;default:t[e][0]<t[e-1][0]+i?(a+=` H ${t[e-1][0]+i}`,t[e][1]!==t[e-1][1]&&(a+=` V ${t[e][1]}`),a+=` H ${t[e][0]}`,o=f.Left):(a+=` H ${t[e][0]}`,o=f.Right,t[e][1]!==t[e-1][1]&&(a+=` V ${t[e][1]}`,o=t[e][1]>t[e-1][1]?f.Bottom:f.Top));break}break;default:t[e][0]!==t[e-1][0]&&(a+=` H ${t[e][0]}`,o=t[e][0]>t[e-1][0]?f.Right:f.Left),t[e][1]!==t[e-1][1]&&(a+=` V ${t[e][1]}`,o=t[e][1]>t[e-1][1]?f.Bottom:f.Top)}}break}return a}},ae=(e,t)=>{switch(e){case`dotted`:return`${t}`;case`dashed`:return`${4*t} ${t}`;case`gapped-dashes`:return`${4*t} ${4*t}`;default:return`none`}},E=(e,t)=>{let n=e.indexOf(t);return n>=0&&e.splice(n,1),e},oe=function(e){return e.Ellipse=`ellipse`,e.Empty=`empty`,e.Folder=`folder`,e.Hexagon=`hexagon`,e.Octagon=`octagon`,e.Pill=`pill`,e.Rectangle=`rectangle`,e.Rhombus=`rhombus`,e.RoundedRectangle=`rounded-rectangle`,e.StickyNote=`sticky-note`,e}({}),se=(e,t,n,r,i)=>{if(typeof e==`function`)return e(t,n,r,i);switch(e){case`ellipse`:return ce(t,n,r,i);case`empty`:return le();case`folder`:return ue(t,n,r,i);case`hexagon`:return de(t,n,r,i);case`octagon`:return fe(t,n,r,i);case`pill`:return pe(t,n,r,i);case`rectangle`:return me(t,n,r,i);case`rhombus`:return he(t,n,r,i);case`rounded-rectangle`:return ge(t,n,r,i);case`sticky-note`:return _e(t,n,r,i);default:return me(t,n,r,i)}},ce=(e,t,n,r)=>`M ${e+n/2} ${t} A ${n/2} ${r/2} 0 0 0 ${e+n/2} ${t+r} A ${n/2} ${r/2} 0 1 0 ${e+n/2} ${t} Z`,le=()=>`Z`,ue=(e,t,n,r)=>`M ${e} ${t} L ${e+n/3} ${t} L ${e+n/2} ${t+r/6} L ${e+n} ${t+r/6} L ${e+n} ${t+r} L ${e} ${t+r} Z`,de=(e,t,n,r)=>`M ${e+n/4} ${t} L ${e+3*n/4} ${t} L ${e+n} ${t+r/2} L ${e+3*n/4} ${t+r} L ${e+n/4} ${t+r} L ${e} ${t+r/2} Z`,fe=(e,t,n,r)=>`M ${e+n/4} ${t} L ${e+3*n/4} ${t} L ${e+n} ${t+r/4} L ${e+n} ${t+3*r/4} L ${e+3*n/4} ${t+r} L ${e+n/4} ${t+r} L ${e} ${t+3*r/4} L ${e} ${t+r/4} L ${e+n/4} ${t} Z`,pe=(e,t,n,r)=>r<n?`M ${e+r/2} ${t} L ${e+n-r/2} ${t} A ${r/2} ${r/2} 0 0 1 ${e+n} ${t+r/2} A ${r/2} ${r/2} 0 0 1 ${e+n-r/2} ${t+r} L ${e+r/2} ${t+r} A ${r/2} ${r/2} 0 0 1 ${e} ${t+r/2} A ${r/2} ${r/2} 0 0 1 ${e+r/2} ${t} Z`:r>n?`M ${e} ${t+n/2} L ${e} ${t+r-n/2} A ${n/2} ${n/2} 0 0 0 ${e+n/2} ${t+r} A ${n/2} ${n/2} 0 0 0 ${e+n} ${t+r-n/2} L ${e+n} ${t+n/2} A ${n/2} ${n/2} 0 0 0 ${e+n/2} ${t} A ${n/2} ${n/2} 0 0 0 ${e} ${t+n/2} Z`:ce(e,t,n,r),me=(e,t,n,r)=>`M ${e} ${t} L ${e+n} ${t} L ${e+n} ${t+r} L ${e} ${t+r} Z`,he=(e,t,n,r)=>`M ${e+n/2} ${t} L ${e+n} ${t+r/2} L ${e+n/2} ${t+r} L ${e} ${t+r/2} Z`,ge=(e,t,n,r)=>`M ${e+n/4} ${t} L ${e+3*n/4} ${t} A ${n/4} ${r/4} 0 0 1 ${e+n} ${t+r/4} L ${e+n} ${t+3*r/4} A ${n/4} ${r/4} 0 0 1 ${e+3*n/4} ${t+r} L ${e+n/4} ${t+r} A ${n/4} ${r/4} 0 0 1 ${e} ${t+3*r/4} L ${e} ${t+r/4} A ${n/4} ${r/4} 0 0 1 ${e+n/4} ${t} Z`,_e=(e,t,n,r)=>`M ${e} ${t} L ${e+3*n/4} ${t} L ${e+3*n/4} ${t+r/4} L ${e+3*n/4} ${t} L ${e+n} ${t+r/4} L ${e+3*n/4} ${t+r/4} L ${e+n} ${t+r/4} L ${e+n} ${t+r} L ${e} ${t+r} Z`,D=function(e){return e.AllScroll=`all-scroll`,e.Auto=`auto`,e.Crosshair=`crosshair`,e.EWResize=`ew-resize`,e.Grab=`grab`,e.Grabbing=`grabbing`,e.Move=`move`,e.NoDrop=`no-drop`,e.NESWResize=`nesw-resize`,e.NSResize=`ns-resize`,e.NWSEResize=`nwse-resize`,e.NotAllowed=`not-allowed`,e.ZoomIn=`zoom-in`,e.ZoomOut=`zoom-out`,e}({}),ve=e=>Math.max(...e.split(`
|
|
2
|
+
`).map(e=>e.length)),ye=e=>e.match(/\n/g)?.length||0,O=[];for(let e=0;e<256;++e)O.push((e+256).toString(16).slice(1));function be(e,t=0){return(O[e[t+0]]+O[e[t+1]]+O[e[t+2]]+O[e[t+3]]+`-`+O[e[t+4]]+O[e[t+5]]+`-`+O[e[t+6]]+O[e[t+7]]+`-`+O[e[t+8]]+O[e[t+9]]+`-`+O[e[t+10]]+O[e[t+11]]+O[e[t+12]]+O[e[t+13]]+O[e[t+14]]+O[e[t+15]]).toLowerCase()}var xe=new Uint8Array(16);function Se(){return crypto.getRandomValues(xe)}function Ce(e,t,n){return!t&&!e&&crypto.randomUUID?crypto.randomUUID():we(e,t,n)}function we(e,t,n){e||={};let r=e.random??e.rng?.()??Se();if(r.length<16)throw Error(`Random bytes length must be >= 16`);if(r[6]=r[6]&15|64,r[8]=r[8]&63|128,t){if(n||=0,n<0||n+16>t.length)throw RangeError(`UUID byte range ${n}:${n+15} is out of buffer bounds`);for(let e=0;e<16;++e)t[n+e]=r[e];return t}return be(r)}var Te=e=>{if(typeof e!=`object`||!e)return e;if(Array.isArray(e))return e.map(Te);let t={};for(let n of Object.entries(e))t[n[0]]=Te(n[1]);return t},k=e=>{let{selected:t,highlighted:n,selectedAndHighlighted:r,...i}=e,a=i;return{defaultLook:a,selectedLook:{...a,...t},highlightedLook:{...a,...n},selectedAndHighlightedLook:{...a,...n,...t,...r}}},Ee=class{constructor(e,t,n,r,i,a,o){this.name=e,this.label=t,this.type=n,this.defaultValue=r,this.basic=i,this.editable=a,this.rootAttribute=o,this.options=void 0,this.properties=void 0}},A=function(e){return e.Boolean=`boolean`,e.Color=`color`,e.Date=`date`,e.Datetime=`datetime`,e.Number=`number`,e.Object=`object`,e.Option=`option`,e.OptionList=`option-list`,e.OptionSet=`option-set`,e.Text=`text`,e.TextArea=`text-area`,e.TextList=`text-list`,e.TextSet=`text-set`,e.TextMap=`text-map`,e.Time=`time`,e.Url=`url`,e}({}),De=class{constructor(e=[]){this.propertyList=e,this.propertyMap={};for(let e of this.propertyList)this.propertyMap[e.name]=e}getProperty(e){return this.propertyMap[e]}hasProperty(e){return this.propertyMap[e]!==void 0}hasProperties(){return this.propertyList.length>0}};function Oe(e,t){return!t||e[0]>t[0]?!0:e[0]===t[0]?e[1]>=t[1]:!1}var ke=e=>e==null||e===``||e instanceof Array&&e.length===0||e instanceof Object&&Object.keys(e).length===0,Ae=(e,t)=>e===t||JSON.stringify(e)===JSON.stringify(t),je=(e,t,n)=>{let r={},i={};for(let a in n.propertySet.propertyMap)if(n.propertySet.propertyMap[a].type===A.Object){let o=je(e[a],t[a],n.getSubValueSet(a));Object.keys(o[0]).length>0&&Object.keys(o[1]).length>0&&(r[a]=o[0],i[a]=o[1])}else Ae(e[a],t[a])||(r[a]=e[a],i[a]=t[a]);return[r,i]},Me=e=>e!=null&&e.constructor===Object,Ne=class e{constructor(e,t){this.displayedProperties=[],this.hiddenProperties=[],this.values={},this.valueSets={},this.ownTimestamps={},this.propertySet=e,this.rootElement=t,this.resetValues()}getRootElementValue(e){if(this.rootElement){if(typeof e==`string`)return this.rootElement[e];if(Array.isArray(e)&&e.length>0){let t=this.rootElement;for(let n of e){if(t==null)return;t=t[n]}return t}}}setRootElementValue(e,t){if(this.rootElement){if(typeof e==`string`&&(this.rootElement[e]=t),Array.isArray(e)&&e.length>0){let n=this.rootElement;for(let t=0;t<e.length-1;++t){let r=e[t];if(n==null)return;n=n[r]}if(n==null)return;n[e[e.length-1]]=t}typeof this.rootElement.updateInView==`function`&&this.rootElement.updateInView()}}getValue(e){let t=this.propertySet.getProperty(e)?.rootAttribute;return t!=null&&(this.values[e]=this.getRootElementValue(t)),this.propertySet.getProperty(e).type===A.Object?this.valueSets[e].getValues():this.values[e]}getValues(){let e={};for(let t in this.propertySet.propertyMap)this.propertySet.getProperty(t).type===A.Object?e[t]=this.valueSets[t].getValues():e[t]=this.getValue(t);return e}getValuesForKeys(e){let t={};for(let n in e)this.propertySet.getProperty(n).type===A.Object?t[n]=this.valueSets[n].getValuesForKeys(e[n]):t[n]=this.getValue(n);return t}getTimestamps(){let e={};for(let t in this.propertySet.propertyMap)if(this.propertySet.getProperty(t).type===A.Object)e[t]=this.valueSets[t].getTimestamps();else{let n=this.ownTimestamps[t];n&&(e[t]=n)}return e}hasValue(e){return!ke(this.getValue(e))}hasSetValue(e){let t=this.getValue(e),n=this.propertySet.getProperty(e);return n&&n.type===A.Object?this.getSubValueSet(e).hasAnySetValue():!ke(t)&&!Ae(t,n?.defaultValue)}hasAnySetValue(){for(let e of this.propertySet.propertyList)if(this.hasSetValue(e.name))return!0;return!1}setValue(e,t){let n=this.propertySet.getProperty(e);if(n){n.type===A.Object?this.valueSets[e].setValues(t):(this.values[e]=t,Ae(t,n.defaultValue)||this.displayProperty(n));let r=n.rootAttribute;r!=null&&this.setRootElementValue(r,t)}}setValues(e){this.resetValues();for(let t in e)this.propertySet.getProperty(t).type===A.Object?this.valueSets[t].setValues(e[t]):this.setValue(t,e[t])}setTimestamps(e){this.ownTimestamps={};for(let t in e)this.propertySet.getProperty(t).type===A.Object?this.valueSets[t].setTimestamps(e[t]):this.ownTimestamps[t]=e[t]}overwriteValues(e){for(let t in e)this.propertySet.getProperty(t).type===A.Object?this.valueSets[t].overwriteValues(e[t]):this.setValue(t,e[t])}overwriteValuesLww(e,t){for(let n in e)this.propertySet.getProperty(n).type===A.Object?this.valueSets[n].overwriteValuesLww(e[n],t):Oe(t,this.ownTimestamps[n])&&(this.setValue(n,e[n]),this.ownTimestamps[n]=t)}resetValues(){this.displayedProperties=[],this.hiddenProperties=[],this.ownTimestamps={};for(let e in this.propertySet.propertyMap){let t=this.propertySet.getProperty(e),n=t.rootAttribute;t.type===A.Object?this.valueSets[e]=this.constructSubValueSet(e):this.values[e]=Te(t.defaultValue),n!=null&&t.defaultValue!==void 0&&!Ae(this.getRootElementValue(n),t.defaultValue)&&this.setRootElementValue(n,this.values[e]),t.basic===!1?this.hiddenProperties.push(t):this.displayedProperties.push(t)}}constructSubValueSet(t){let n=this.propertySet.getProperty(t),r=new e(new De(n.properties),this.rootElement);return r.overwriteValues(Te(n.defaultValue)),r}getSubValueSet(e){return this.valueSets[e]}displayProperty(e){this.displayedProperties.includes(e)||(this.displayedProperties.push(e),E(this.hiddenProperties,e))}hideProperty(e){this.hiddenProperties.includes(e)||(this.hiddenProperties.push(e),E(this.displayedProperties,e))}},Pe=class{constructor(){this.entities=[],this.entityMap={}}get length(){return this.size()}all(){return[...this.entities]}add(e){this.entityMap[e.id]===void 0&&(this.entityMap[e.id]=e,this.entities.push(e))}clear(){for(;this.entities.length>0;)this.remove(this.entities[0].id)}contains(e){return this.entityMap[e]!==void 0}count(e){return this.entities.filter(e).length}filter(e){return this.entities.filter(e)}find(e){return this.entities.find(e)}get(e){return this.entityMap[e]}map(e){return this.entities.map(e)}remove(e){let t=this.get(e);t!==void 0&&(delete this.entityMap[e],E(this.entities,t))}size(){return this.entities.length}*[Symbol.iterator](){for(let e of this.entities)yield e}},Fe=class{get id(){return this._id}get highlighted(){return this.model.canvas?.userHighlight?.contains(this.id)||!1}get selected(){return this.model.canvas?.userSelection?.contains(this.id)||!1}constructor(e,t){this.selfRemoved=!1,this.selfRemovedTimestamp=null,this.model=e,this._id=t}select(){return this.model.canvas?.selectCanvasView()?.select(`[id='${te(this.id)}']`)}},j=class extends Pe{all(e=!1){return e?super.all():super.filter(e=>!e.removed)}contains(e,t=!1){return t?super.contains(e):super.contains(e)&&!this.entityMap[e].removed}count(e,t=!1){return t?super.count(e):super.count((t,n,r)=>e(t,n,r)&&!t.removed)}filter(e,t=!1){return t?super.filter(e):super.filter((t,n,r)=>e(t,n,r)&&!t.removed)}find(e,t=!1){return t?super.find(e):super.find((t,n,r)=>e(t,n,r)&&!t.removed)}get(e,t=!1){return t||this.contains(e)?super.get(e):void 0}map(e,t=!1){return t?super.map(e):super.filter(e=>!e.removed).map(e)}remove(e){let t=this.get(e,!0);t!==void 0&&(delete this.entityMap[e],E(this.entities,t))}size(e=!1){return e?super.size():super.filter(e=>!e.removed).length}*[Symbol.iterator](e=!1){if(e)for(let e of this.entities)yield e;else for(let e of this.entities.filter(e=>!e.removed))yield e}},M={name:``,label:null,look:{color:`#000000`,thickness:1,shape:T.Straight,style:ne.Solid,selected:{color:`#AA00AA`},highlighted:{thickness:2}},startMarkerLook:void 0,endMarkerLook:void 0,startTypes:[],endTypes:[],properties:[]},Ie=class{constructor(e){let t={...M,...e};this.id=t.id,this.name=t.name,this.label=t.label;let n=k(t.look);if(this.defaultLook=n.defaultLook,this.selectedLook=n.selectedLook,this.highlightedLook=n.highlightedLook,this.selectedAndHighlightedLook=n.selectedAndHighlightedLook,t.startMarkerLook!==void 0){let e=k(t.startMarkerLook);this.defaultStartMarkerLook=e.defaultLook,this.selectedStartMarkerLook=e.selectedLook,this.highlightedStartMarkerLook=e.highlightedLook,this.selectedAndHighlightedStartMarkerLook=e.selectedAndHighlightedLook}else this.defaultStartMarkerLook=null,this.selectedStartMarkerLook=null,this.highlightedStartMarkerLook=null,this.selectedAndHighlightedStartMarkerLook=null;if(t.endMarkerLook!==void 0){let e=k(t.endMarkerLook);this.defaultEndMarkerLook=e.defaultLook,this.selectedEndMarkerLook=e.selectedLook,this.highlightedEndMarkerLook=e.highlightedLook,this.selectedAndHighlightedEndMarkerLook=e.selectedAndHighlightedLook}else this.defaultEndMarkerLook=null,this.selectedEndMarkerLook=null,this.highlightedEndMarkerLook=null,this.selectedAndHighlightedEndMarkerLook=null;this.startTypes=t.startTypes,this.endTypes=t.endTypes,this.propertySet=new De(t.properties)}canStartFromType(e){return this.startTypes.indexOf(e)>=0}canFinishOnType(e){return this.endTypes.indexOf(e)>=0}},N=class extends Fe{get type(){return this._type}set type(e){e!==this._type&&(this._type=e,this.valueSet&&=new Ne(e.propertySet,this),this.model.canvas?.userSelection?.openInPropertyEditor(this,!1),this.updateInView())}get typeString(){return this.type.id}set typeString(e){if(e!==this.type.id){let t=this.model.connections.types.get(e);t&&(this.type=t)}}get name(){return this.middleLabel}set name(e){this.middleLabel=e}get look(){return this.selected?this.highlighted?this._selectedAndHighlightedLook===void 0?this.type.selectedAndHighlightedLook:this._selectedAndHighlightedLook:this._selectedLook===void 0?this.type.selectedLook:this._selectedLook:this.highlighted?this._highlightedLook===void 0?this.type.highlightedLook:this._highlightedLook:this._defaultLook===void 0?this.type.defaultLook:this._defaultLook}set look(e){this.lookConfig=e}get lookConfig(){return this._lookConfig}set lookConfig(e){if(this._lookConfig=e,e){let t=k(e);this._defaultLook={...this._defaultLook,...t.defaultLook},this._selectedLook={...this._selectedLook,...t.selectedLook},this._highlightedLook={...this._highlightedLook,...t.highlightedLook},this._selectedAndHighlightedLook={...this._selectedAndHighlightedLook,...t.selectedAndHighlightedLook}}else this._defaultLook=e,this._selectedLook=e,this._highlightedLook=e,this._selectedAndHighlightedLook=e}get startMarkerLook(){return this.selected?this.highlighted?this._selectedAndHighlightedStartMarkerLook===void 0?this.type.selectedAndHighlightedStartMarkerLook:this._selectedAndHighlightedStartMarkerLook:this._selectedStartMarkerLook===void 0?this.type.selectedStartMarkerLook:this._selectedStartMarkerLook:this.highlighted?this._highlightedStartMarkerLook===void 0?this.type.highlightedStartMarkerLook:this._highlightedStartMarkerLook:this._defaultStartMarkerLook===void 0?this.type.defaultStartMarkerLook:this._defaultStartMarkerLook}set startMarkerLook(e){this.startMarkerLookConfig=e}get startMarkerLookConfig(){return this._startMarkerLookConfig}set startMarkerLookConfig(e){if(this._startMarkerLookConfig=e,e){let t=k(e);this._defaultStartMarkerLook={...this._defaultStartMarkerLook,...t.defaultLook},this._selectedStartMarkerLook={...this._selectedStartMarkerLook,...t.selectedLook},this._highlightedStartMarkerLook={...this._highlightedStartMarkerLook,...t.highlightedLook},this._selectedAndHighlightedStartMarkerLook={...this._selectedAndHighlightedStartMarkerLook,...t.selectedAndHighlightedLook}}else this._defaultStartMarkerLook=e,this._selectedStartMarkerLook=e,this._highlightedStartMarkerLook=e,this._selectedAndHighlightedStartMarkerLook=e}get endMarkerLook(){return this.selected?this.highlighted?this._selectedAndHighlightedEndMarkerLook===void 0?this.type.selectedAndHighlightedEndMarkerLook:this._selectedAndHighlightedEndMarkerLook:this._selectedEndMarkerLook===void 0?this.type.selectedEndMarkerLook:this._selectedEndMarkerLook:this.highlighted?this._highlightedEndMarkerLook===void 0?this.type.highlightedEndMarkerLook:this._highlightedEndMarkerLook:this._defaultEndMarkerLook===void 0?this.type.defaultEndMarkerLook:this._defaultEndMarkerLook}set endMarkerLook(e){this.endMarkerLookConfig=e}get endMarkerLookConfig(){return this._endMarkerLookConfig}set endMarkerLookConfig(e){if(this._endMarkerLookConfig=e,e){let t=k(e);this._defaultEndMarkerLook={...this._defaultEndMarkerLook,...t.defaultLook},this._selectedEndMarkerLook={...this._selectedEndMarkerLook,...t.selectedLook},this._highlightedEndMarkerLook={...this._highlightedEndMarkerLook,...t.highlightedLook},this._selectedAndHighlightedEndMarkerLook={...this._selectedAndHighlightedEndMarkerLook,...t.selectedAndHighlightedLook}}else this._defaultEndMarkerLook=e,this._selectedEndMarkerLook=e,this._highlightedEndMarkerLook=e,this._selectedAndHighlightedEndMarkerLook=e}constructor(e,t,n,r,i){if(e.connections.get(i)!==void 0)throw Error(`DiagramConnection with id "${i}" already exists`);if(!i)throw Error(`DiagramConnection cannot have an empty or null id`);super(e,i),this.startCoords=[0,0],this.endCoords=[0,0],this.startLabel=``,this.middleLabel=``,this.endLabel=``,this.points=[],this._type=t,this.valueSet=new Ne(t.propertySet,this),this.originalData={},this.setStart(n),this.setEnd(r)}get removed(){return this.selfRemoved||this.start!==void 0&&this.start.removed||this.end!==void 0&&this.end.removed}updateInView(){this.model.canvas?.updateConnectionsInView(this.id)}raise(){this.select()?.raise(),this.start?.raise(!1),this.end?.raise(!1)}setStart(e){this.start===e?(this.startDirection=e?.direction,this.startCoords=e?.connectionPoint||[0,0]):(this.start!==void 0&&E(this.start.outgoingConnections,this),this.start=e,e!==void 0&&(e.outgoingConnections.push(this),this.startDirection=e?.direction,this.startCoords=e?.connectionPoint||[0,0])),this.updateInView()}setEnd(e){this.end===e?(this.endDirection=e?.direction,this.endCoords=e?.connectionPoint||[0,0]):(this.end!==void 0&&E(this.end.incomingConnections,this),this.end=e,e!==void 0&&(e.incomingConnections.push(this),this.endDirection=e?.direction,this.endCoords=e?.connectionPoint||[0,0])),this.updateInView()}tighten(){let e=this.model.canvas?.allowConnectionLoops||!1,t=this.model.canvas?.allowSharingPorts!==!1,n=this.model.canvas?.allowSharingBothPorts||!1,r=this.model.canvas?.tightenConnectionsAcrossPortTypes||!1;if(this.start?.rootElement&&this.end){let i=this.start.rootElement.ports.map(e=>[e,e.distanceTo(this.end.coords)]).sort((e,t)=>e[1]-t[1]).map(e=>e[0]);checkAlternativeStartPorts:for(let a of i){if(!e&&a===this.end||!a.allowsOutgoing||!r&&a.type!==this.start.type||!t&&(a.incomingConnections.filter(e=>!e.removed&&e!==this).length>0||a.outgoingConnections.filter(e=>!e.removed&&e!==this).length>0))continue checkAlternativeStartPorts;if(!n){for(let e of a.outgoingConnections.filter(e=>!e.removed))if(e!==this&&e.end===this.end)continue checkAlternativeStartPorts;for(let e of a.incomingConnections.filter(e=>!e.removed))if(e!==this&&e.start===this.end)continue checkAlternativeStartPorts}if(a===this.start)break checkAlternativeStartPorts;this.setStart(a);break checkAlternativeStartPorts}}if(this.end?.rootElement&&this.start){let i=this.end.rootElement.ports.map(e=>[e,e.distanceTo(this.start.coords)]).sort((e,t)=>e[1]-t[1]).map(e=>e[0]);checkAlternativeEndPorts:for(let a of i){if(!e&&a===this.start||!a.allowsIncoming||!r&&a.type!==this.end.type||!t&&(a.incomingConnections.filter(e=>!e.removed&&e!==this).length>0||a.outgoingConnections.filter(e=>!e.removed&&e!==this).length>0))continue checkAlternativeEndPorts;if(!n){for(let e of a.incomingConnections.filter(e=>!e.removed))if(e!==this&&e.start===this.start)continue checkAlternativeEndPorts;for(let e of a.outgoingConnections.filter(e=>!e.removed))if(e!==this&&e.end===this.start)continue checkAlternativeEndPorts}if(a===this.end)break checkAlternativeEndPorts;this.setEnd(a);break checkAlternativeEndPorts}}}getPriority(){return this.start?this.end?Math.min(this.start.getPriority(),this.end.getPriority()):this.start.getPriority():this.end?this.end.getPriority():0}},Le=class extends j{constructor(e){super(),this.types=new Pe,this.model=e}new(e,t,n,r){let i;if(e instanceof Ie)i=e;else{let t=this.types.get(e);if(t===void 0)throw TypeError(`Connection type with id '${e}' could not be found.`);i=t}let a=new N(this.model,i,t,n,r);return super.add(a),a.updateInView(),a.valueSet.resetValues(),a.start?.raise(!1),a.end?.raise(!1),a}remove(e){let t=this.get(e,!0);t&&(E(t.start?.outgoingConnections||[],t),E(t.end?.incomingConnections||[],t),super.remove(e),t.updateInView())}},P=function(e){return e[e.Always=0]=`Always`,e[e.OnlyWhenSelected=1]=`OnlyWhenSelected`,e[e.Never=2]=`Never`,e}({}),F={editable:!0,margin:0,padding:0,horizontalAlign:m.Center,verticalAlign:h.Center,orientation:f.Top,multiline:!1,fit:!1,shrink:!0,look:{fillColor:`transparent`,fontColor:`#000000`,fontFamily:`'Wonder Unit Sans', sans-serif`,fontSize:10,fontWeight:400}},I=class extends Fe{get text(){return this._text}set text(e){(e==null||e?.trim()===``)&&(e=this.defaultText),this._text=e,this.updateInView(),this.fit&&this.model.canvas?.fitFieldRootInView(this.id,this.shrink)}get look(){return this.selected?this.highlighted?this.selectedAndHighlightedLook:this.selectedLook:this.highlighted?this.highlightedLook:this.defaultLook}constructor(e,t,n,r,i,a,o,s,c,l,u,d,p,m){let h=`${t?.id}_field`;if(e.fields.get(h)!==void 0)throw Error(`DiagramField for rootElement already exists`);if(super(e,h),this.textTimestamp=null,this.rootElement=t,this.coords=n,this.width=r,this.height=i,this.horizontalAlign=a,this.verticalAlign=o,this.multiline=c,!isNaN(Number(s)))this.orientation=Number(s);else switch(s){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}let g=k(l);this.defaultLook=g.defaultLook,this.selectedLook=g.selectedLook,this.highlightedLook=g.highlightedLook,this.selectedAndHighlightedLook=g.selectedAndHighlightedLook,this.defaultText=u,this._text=u,this.editable=d,this.fit=p,this.shrink=m}get removed(){return this.selfRemoved||this.rootElement!==void 0&&this.rootElement.removed}updateInView(){this.model.canvas?.updateFieldsInView(this.id)}raise(){this.select()?.raise()}move(e){this.coords=e,this.updateInView()}getPriority(){return this.rootElement?.getPriority()||0}},Re=class extends j{constructor(e){super(),this.model=e}new(e,t,n,r,i,a,o,s,c,l,u,d,f){let p=new I(this.model,e,t,n,r,i,a,o,s,c,l,u,d,f);return super.add(p),p.updateInView(),e!==void 0&&(e.label=p),p}remove(e){let t=this.get(e,!0);t&&(t.rootElement?.label!==void 0&&t.rootElement.label===t&&(t.rootElement.label=void 0),super.remove(e),t.updateInView())}},L=e=>e?.margin===null||e?.margin===void 0?F.margin:typeof e.margin==`number`?e.margin:e.margin.length===1||e.margin.length===2?e.margin[0]:(e.margin.length,e.margin[2]),R=e=>e?.margin===null||e?.margin===void 0?F.margin:typeof e.margin==`number`?e.margin:e.margin.length===1?e.margin[0]:e.margin.length===2||e.margin.length===3?e.margin[1]:e.margin[3],z=e=>e?.margin===null||e?.margin===void 0?F.margin:typeof e.margin==`number`?e.margin:e.margin.length===1?e.margin[0]:(e.margin.length===2||e.margin.length,e.margin[1]),B=e=>e?.margin===null||e?.margin===void 0?F.margin:typeof e.margin==`number`?e.margin:(e.margin.length===1||e.margin.length===2||e.margin.length,e.margin[0]),ze=e=>e?.padding===null||e?.padding===void 0?F.padding:typeof e.padding==`number`?e.padding:e.padding.length===1||e.padding.length===2?e.padding[0]:(e.padding.length,e.padding[2]),Be=e=>e?.padding===null||e?.padding===void 0?F.padding:typeof e.padding==`number`?e.padding:e.padding.length===1?e.padding[0]:e.padding.length===2||e.padding.length===3?e.padding[1]:e.padding[3],Ve=e=>e?.padding===null||e?.padding===void 0?F.padding:typeof e.padding==`number`?e.padding:e.padding.length===1?e.padding[0]:(e.padding.length===2||e.padding.length,e.padding[1]),He=e=>e?.padding===null||e?.padding===void 0?F.padding:typeof e.padding==`number`?e.padding:(e.padding.length===1||e.padding.length===2||e.padding.length,e.padding[0]),Ue={mode:P.Never,thickness:10,outerMargin:0,look:{fillColor:`transparent`,borderColor:`transparent`,borderThickness:0}},V=class{constructor(e){let t;t=typeof e==`boolean`?{mode:e?P.Always:P.Never}:typeof e==`string`||typeof e==`number`?{mode:e}:e,t={...Ue,...t},this.mode=t.mode,this.thickness=t.thickness,this.outerMargin=t.outerMargin;let n=k(t.look??Ue.look);this.defaultLook=n.defaultLook,this.selectedLook=n.selectedLook,this.highlightedLook=n.highlightedLook,this.selectedAndHighlightedLook=n.selectedAndHighlightedLook}getLook(e){return e?e.selected?e.highlighted?this.selectedAndHighlightedLook:this.selectedLook:e.highlighted?this.highlightedLook:this.defaultLook:this.defaultLook}},We=new V(Ue),Ge=class{constructor(e){this.margin=e.margin||0,this.defaultWidths=e.defaultWidths||null,this.defaultHeights=e.defaultHeights||null,this.minWidths=e.minWidths||null,this.minHeights=e.minHeights||null,this.sections=[];for(let t of e.sections){let e=[];this.sections.push(e);for(let n of t)e.push(new Ke(n))}}},Ke=class{constructor(e){this.label=e.label||null,this.ports=e.ports||[],this.priority=e.priority||0,e.resizableX===void 0?this.resizerX=void 0:this.resizerX=new V(e.resizableX),e.resizableY===void 0?this.resizerY=void 0:this.resizerY=new V(e.resizableY),e.resizableXY===void 0?this.resizerXY=void 0:this.resizerXY=new V(e.resizableXY);let t=k(e.look||Je);this.defaultLook=t.defaultLook,this.selectedLook=t.selectedLook,this.highlightedLook=t.highlightedLook,this.selectedAndHighlightedLook=t.selectedAndHighlightedLook}},H=class extends Fe{get name(){return this.label?.text||``}set name(e){this.label&&(this.label.text=e)}get look(){return this.selected?this.highlighted?this._selectedAndHighlightedLook===void 0?this.type?.selectedAndHighlightedLook||this.node?.look:this._selectedAndHighlightedLook:this._selectedLook===void 0?this.type?.selectedLook||this.node?.look:this._selectedLook:this.highlighted?this._highlightedLook===void 0?this.type?.highlightedLook||this.node?.look:this._highlightedLook:this._defaultLook===void 0?this.type?.defaultLook||this.node?.look:this._defaultLook}set look(e){this.lookConfig=e}get lookConfig(){return this._lookConfig}set lookConfig(e){if(this._lookConfig=e,e){let t=k(e);this._defaultLook={...this._defaultLook,...t.defaultLook},this._selectedLook={...this._selectedLook,...t.selectedLook},this._highlightedLook={...this._highlightedLook,...t.highlightedLook},this._selectedAndHighlightedLook={...this._selectedAndHighlightedLook,...t.selectedAndHighlightedLook}}else this._defaultLook=e,this._selectedLook=e,this._highlightedLook=e,this._selectedAndHighlightedLook=e}constructor(e,t,n,r,i,a,o,s){if(e.sections.get(s)!==void 0)throw Error(`DiagramSection with id "${s}" already exists`);if(!s)throw Error(`DiagramSection cannot have an empty or null id`);super(e,s),this.ports=[],this.decorators=[],this.node=t,this.indexXInNode=n,this.indexYInNode=r,this.coords=i,this.width=a,this.height=o}get removed(){return this.selfRemoved||this.node!==void 0&&this.node.removed}updateInView(){this.model.canvas?.updateSectionsInView(this.id)}raise(){this.select()?.raise(),this.label&&this.label.raise();for(let e of this.ports)e.raise();for(let e of this.decorators)e.raise()}get type(){return this.node?.type?.sectionGrid?.sections?.[this.indexYInNode]?.[this.indexXInNode]}getMinWidth(){return this.node?.type?.sectionGrid?.minWidths?.[this.indexXInNode]||1}getMinHeight(){return this.node?.type?.sectionGrid?.minHeights?.[this.indexYInNode]||1}getPriority(){return this.node?.type?.sectionGrid?.sections?.[this.indexYInNode]?.[this.indexXInNode]?.priority||0}getResizerX(){return this.type?.resizerX??this.node?.getResizerX()??We}getResizerY(){return this.type?.resizerY??this.node?.getResizerY()??We}getResizerXY(){return this.type?.resizerXY??this.node?.getResizerXY()??We}getResizableX(){let e=this.type;if(e?.resizerX!==void 0)switch(e.resizerX.mode){case P.OnlyWhenSelected:return this.selected;case P.Always:return!0;case P.Never:default:return!1}return this.node?.getResizableX()||!1}getResizableY(){let e=this.type;if(e?.resizerY!==void 0)switch(e.resizerY.mode){case P.OnlyWhenSelected:return this.selected;case P.Always:return!0;case P.Never:default:return!1}return this.node?.getResizableY()||!1}getResizableXY(){let e=this.type;if(e?.resizerXY!==void 0)switch(e.resizerXY.mode){case P.OnlyWhenSelected:return this.selected;case P.Always:return!0;case P.Never:default:return!1}return this.node?.getResizableXY()||!1}getClosestPortToPoint(e){if(this.ports.length!==0){if(this.ports.length===1)return this.ports[1];{let t=this.ports.map(t=>t.distanceTo(e)),n=t.indexOf(Math.min(...t));return this.ports[n]}}}getIncomingConnections(e=!1){let t=[];for(let n of this.ports)for(let r of n.incomingConnections)!e&&r.removed||t.push(r);return t}getOutgoingConnections(e=!1){let t=[];for(let n of this.ports)for(let r of n.outgoingConnections)!e&&r.removed||t.push(r);return t}getConnections(e=!1){let t=[];for(let n of this.ports){for(let r of n.incomingConnections)!e&&r.removed||t.push(r);for(let r of n.outgoingConnections)!e&&r.removed||t.push(r)}return t}move(e){this.setGeometry({coords:e,width:this.width,height:this.height})}stretch(e,t){let n=[this.coords[0],this.coords[0]+this.width],r=[this.coords[1],this.coords[1]+this.height],i,a;switch(e){case f.Left:i=[n[0]-t,n[1]],a=[r[0],r[1]],i[1]-i[0]<this.getMinWidth()&&(i[0]=i[1]-this.getMinWidth());break;case f.Top:i=[n[0],n[1]],a=[r[0]-t,r[1]],a[1]-a[0]<this.getMinHeight()&&(a[0]=a[1]-this.getMinHeight());break;case f.Right:i=[n[0],n[1]+t],a=[r[0],r[1]],i[1]-i[0]<this.getMinWidth()&&(i[1]=i[0]+this.getMinWidth());break;case f.Bottom:i=[n[0],n[1]],a=[r[0],r[1]+t],a[1]-a[0]<this.getMinHeight()&&(a[1]=a[0]+this.getMinHeight());break}this.setGeometry({coords:[i[0],a[0]],width:i[1]-i[0],height:a[1]-a[0]})}getGeometry(){return{coords:[...this.coords],width:this.width,height:this.height}}setGeometry(e){let t=[this.coords[0],this.coords[0]+this.width],n=[this.coords[1],this.coords[1]+this.height];this.coords=[...e.coords],this.width=e.width,this.height=e.height;let r=[this.coords[0],this.coords[0]+this.width],i=[this.coords[1],this.coords[1]+this.height];for(let e of this.ports)e.move(y(e.coords,t,n,r,i,e.anchorPointX,e.anchorPointY));let a=this.type;this.label&&(this.label.coords=[this.coords[0]+R(a?.label),this.coords[1]+B(a?.label)],this.label.width=this.width-R(a?.label)-z(a?.label),this.label.height=this.height-B(a?.label)-L(a?.label),this.label.updateInView());for(let e of this.decorators)e.move(y(e.coords,t,n,r,i,e.anchorPointX,e.anchorPointY));this.model.canvas?.autoTightenConnections!==!1&&this.getConnections().forEach(e=>e.tighten()),this.updateInView()}},qe=class extends j{constructor(e){super(),this.model=e}new(e,t,n,r,i,a,o){let s=new H(this.model,e,t,n,r,i,a,o);super.add(s),s.updateInView(),e.sections.push(s),e.updateInView();let c=e.type.sectionGrid?.sections?.[n]?.[t]?.ports;if(c&&c.length>0)for(let e=0;e<c.length;++e){let t=c[e],n=this.model.ports.new(t.type===void 0?void 0:this.model.ports.types.get(t.type),s,[s.coords[0]+(t.coords[0]||0),s.coords[1]+(t.coords[1]||0)],t.connectionPoint===void 0?void 0:[s.coords[0]+(t.connectionPoint[0]||0),s.coords[1]+(t.connectionPoint[1]||0)],t?.direction,`${s.id}_${e}`,t.anchorPointX||`floating`,t.anchorPointY||`floating`);if(n.type?.label){let e={...F,...n.type?.label};e.look={...F.look,...e.look};let t=6*(e.look.fontSize||F.look.fontSize)+Be(e)+Ve(e),r=(e.look.fontSize||F.look.fontSize)+He(e)+ze(e),i;switch(n.direction){case f.Bottom:case f.Left:case f.Right:i=[n.coords[0]-t/2,n.coords[1]-r-L(e)];break;case f.Top:i=[n.coords[0]-t/2,n.coords[1]+B(e)];break;default:i=n.coords}this.model.fields.new(n,i,t,r,e.horizontalAlign,e.verticalAlign,e.orientation,e.multiline,e.look,``,e.editable,e.fit,e.shrink)}}let l=e.type.sectionGrid?.sections?.[n]?.[t]?.label;if(l){let e={...F,...l};e.look={...F.look,...e.look},this.model.fields.new(s,[s.coords[0]+R(e),s.coords[1]+B(e)],s.width-R(e)-z(e),s.height-B(e)-L(e),e.horizontalAlign,e.verticalAlign,e.orientation,e.multiline,e.look,``,e.editable,e.fit,e.shrink)}return s}remove(e){let t=this.get(e,!0);if(t){for(;t.ports.length>0;)this.model.ports.remove(t.ports[0].id);t.label&&this.model.fields.remove(t.label.id),t.node&&E(t.node.sections,t),super.remove(e),t.updateInView()}}},Je={lookType:`shaped-look`,shape:oe.Rectangle,fillColor:`#FFFFFF`,borderColor:`#000000`,borderThickness:1,selected:{fillColor:`#FFAAFF`,borderColor:`#AA00AA`},highlighted:{borderThickness:3}},Ye={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:0,properties:[]},Xe=class{constructor(e){let t={...Ye,...e};this.id=t.id,this.name=t.name,this.defaultWidth=t.defaultWidth,this.defaultHeight=t.defaultHeight,this.minWidth=t.minWidth,this.minHeight=t.minHeight,e.resizableX===void 0?this.resizerX=new V({mode:P.Never}):this.resizerX=new V(e.resizableX),e.resizableY===void 0?this.resizerY=new V({mode:P.Never}):this.resizerY=new V(e.resizableY),e.resizableXY===void 0?this.resizerXY=new V({mode:P.Never}):this.resizerXY=new V(e.resizableXY),this.snapToGridOffset=t.snapToGridOffset,this.bottomPadding=$e(t),this.leftPadding=et(t),this.rightPadding=tt(t),this.topPadding=nt(t),this.label=t.label,this.ports=t.ports,this.decorators=t.decorators,this.sectionGrid=t.sectionGrid?new Ge(t.sectionGrid):null;let n=k(t.look);this.defaultLook=n.defaultLook,this.selectedLook=n.selectedLook,this.highlightedLook=n.highlightedLook,this.selectedAndHighlightedLook=n.selectedAndHighlightedLook,this.isUnique=t.isUnique,this.canBeParentless=t.canBeParentless,this.childrenTypes=t.childrenTypes,this.priority=t.priority,this.propertySet=new De(e?.properties||[])}},U=class extends Fe{get type(){return this._type}set type(e){e!==this._type&&(this._type=e,this.valueSet&&=new Ne(e.propertySet,this),this.model.canvas?.userSelection?.openInPropertyEditor(this,!1),this.updateInView())}get typeString(){return this.type.id}set typeString(e){if(e!==this.type.id){let t=this.model.nodes.types.get(e);t&&(this.type=t)}}get name(){return this.label?.text||``}set name(e){this.label&&(this.label.text=e)}get look(){return this.selected?this.highlighted?this._selectedAndHighlightedLook===void 0?this.type.selectedAndHighlightedLook:this._selectedAndHighlightedLook:this._selectedLook===void 0?this.type.selectedLook:this._selectedLook:this.highlighted?this._highlightedLook===void 0?this.type.highlightedLook:this._highlightedLook:this._defaultLook===void 0?this.type.defaultLook:this._defaultLook}set look(e){this.lookConfig=e}get lookConfig(){return this._lookConfig}set lookConfig(e){if(this._lookConfig=e,e){let t=k(e);this._defaultLook={...this._defaultLook,...t.defaultLook},this._selectedLook={...this._selectedLook,...t.selectedLook},this._highlightedLook={...this._highlightedLook,...t.highlightedLook},this._selectedAndHighlightedLook={...this._selectedAndHighlightedLook,...t.selectedAndHighlightedLook}}else this._defaultLook=e,this._selectedLook=e,this._highlightedLook=e,this._selectedAndHighlightedLook=e}constructor(e,t,n=[0,0],r){if(e.nodes.get(r)!==void 0)throw Error(`DiagramNode with id "${r}" already exists`);if(!r)throw Error(`DiagramNode cannot have an empty or null id`);super(e,r),this.children=[],this.sections=[],this.ports=[],this.decorators=[],this.geometryTimestamp=null,this._type=t,this.valueSet=new Ne(t.propertySet,this),this.originalData={},this.coords=n,this.width=t.defaultWidth,this.height=t.defaultHeight}get removed(){return this.selfRemoved}updateInView(){this.model.canvas?.updateNodesInView(this.id)}raise(){this.select()?.raise();for(let e of this.sections)e.raise();this.label&&this.label.raise();for(let e of this.ports)e.raise();for(let e of this.decorators)e.raise();for(let e of this.children)e.raise()}getPriority(){return this.type.priority}getResizerX(){return this.type.resizerX}getResizerY(){return this.type.resizerY}getResizerXY(){return this.type.resizerXY}getResizableX(){switch(this.type.resizerX.mode){case P.OnlyWhenSelected:return this.selected;case P.Always:return!0;case P.Never:default:return!1}}getResizableY(){switch(this.type.resizerY.mode){case P.OnlyWhenSelected:return this.selected;case P.Always:return!0;case P.Never:default:return!1}}getResizableXY(){switch(this.type.resizerXY.mode){case P.OnlyWhenSelected:return this.selected;case P.Always:return!0;case P.Never:default:return!1}}getClosestPortToPoint(e){if(this.ports.length!==0){if(this.ports.length===1)return this.ports[1];{let t=this.ports.map(t=>t.distanceTo(e)),n=t.indexOf(Math.min(...t));return this.ports[n]}}}getIncomingConnections(e=!1){let t=[];for(let n of this.ports)for(let r of n.incomingConnections)!e&&r.removed||t.push(r);return t}getOutgoingConnections(e=!1){let t=[];for(let n of this.ports)for(let r of n.outgoingConnections)!e&&r.removed||t.push(r);return t}getConnections(e=!1){let t=[];for(let n of this.ports){for(let r of n.incomingConnections)!e&&r.removed||t.push(r);for(let r of n.outgoingConnections)!e&&r.removed||t.push(r)}return t}getAdjacentNodes(e=!1){let t=[];for(let n of this.ports){for(let r of n.incomingConnections){if(!e&&r.removed)continue;let n=r.start?.getNode();if(n){if(!e&&n.removed)continue;t.push(n)}}for(let r of n.outgoingConnections){if(!e&&r.removed)continue;let n=r.end?.getNode();if(n){if(!e&&n.removed)continue;t.push(n)}}}return t}getLastAncestor(){let e=this;for(;e.parent!==void 0;)e=e?.parent;return e}isAncestorOf(e){let t=e;for(;t!==void 0;){if(this.id===t.id)return!0;t=t.parent}return!1}isDescendantOf(e){return e.isAncestorOf(this)}addChild(e){if(e.id===this.id)return;let t=this.parent,n=!1;for(;t!==void 0;){if(t.id===e.id){n=!0;break}t=t.parent}n||this.children.indexOf(e)>=0||(this.fitToChild(e),this.children.push(e),e.parent=this,e.raise())}removeChild(e){E(this.children,e),e.parent=void 0}fitToChild(e){let t=Math.max(...this.sections.map(e=>e.indexXInNode)),n=Math.max(...this.sections.map(e=>e.indexYInNode)),r=this.coords[0]-e.coords[0]+this.type.leftPadding;r>=0&&(this.sections.length>0?this.stretchSections(f.Left,r,t,n):this.stretch(f.Left,r));let i=this.coords[1]-e.coords[1]+this.type.topPadding;i>=0&&(this.sections.length>0?this.stretchSections(f.Top,i,t,n):this.stretch(f.Top,i));let a=e.coords[0]+e.width-(this.coords[0]+this.width)+this.type.rightPadding;a>=0&&(this.sections.length>0?this.stretchSections(f.Right,a,t,n):this.stretch(f.Right,a));let o=e.coords[1]+e.height-(this.coords[1]+this.height)+this.type.bottomPadding;o>=0&&(this.sections.length>0?this.stretchSections(f.Bottom,o,t,n):this.stretch(f.Bottom,o)),this.parent&&this.parent.fitToChild(this)}move(e){let t=[e[0]-this.coords[0],e[1]-this.coords[1]];for(let e of this.children)e.move([e.coords[0]+t[0],e.coords[1]+t[1]]);for(let e of this.sections)e.move([e.coords[0]+t[0],e.coords[1]+t[1]]);this.setGeometry({coords:e,width:this.width,height:this.height,sections:{},children:{}})}stretch(e,t){let n=[this.coords[0],this.coords[0]+this.width],r=[this.coords[1],this.coords[1]+this.height],i,a;switch(e){case f.Left:i=[n[0]-t,n[1]],a=[r[0],r[1]],i[1]-i[0]<this.type.minWidth&&(i[0]=i[1]-this.type.minWidth);break;case f.Top:i=[n[0],n[1]],a=[r[0]-t,r[1]],a[1]-a[0]<this.type.minHeight&&(a[0]=a[1]-this.type.minHeight);break;case f.Right:i=[n[0],n[1]+t],a=[r[0],r[1]],i[1]-i[0]<this.type.minWidth&&(i[1]=i[0]+this.type.minWidth);break;case f.Bottom:i=[n[0],n[1]],a=[r[0],r[1]+t],a[1]-a[0]<this.type.minHeight&&(a[1]=a[0]+this.type.minHeight);break}this.setGeometry({coords:[i[0],a[0]],width:i[1]-i[0],height:a[1]-a[0],sections:{},children:{}})}stretchSections(e,t,n,r){let i=-1/0;switch(e){case f.Bottom:for(let e of this.sections)e.indexYInNode===r&&(i=Math.max(i,e.getMinHeight()-e.height));t<i&&(t=i);for(let n of this.sections)n.indexYInNode===r?n.stretch(e,t):n.indexYInNode>r&&n.move([n.coords[0],n.coords[1]+t]);break;case f.Right:for(let e of this.sections)e.indexXInNode===n&&(i=Math.max(i,e.getMinWidth()-e.width));t<i&&(t=i);for(let r of this.sections)r.indexXInNode===n?r.stretch(e,t):r.indexXInNode>n&&r.move([r.coords[0]+t,r.coords[1]]);break;case f.Top:for(let e of this.sections)e.indexYInNode===r&&(i=Math.max(i,e.getMinHeight()-e.height));t<i&&(t=i);for(let n of this.sections)n.indexYInNode===r?n.stretch(e,t):n.indexYInNode<r&&n.move([n.coords[0],n.coords[1]-t]);break;case f.Left:for(let e of this.sections)e.indexXInNode===n&&(i=Math.max(i,e.getMinWidth()-e.width));t<i&&(t=i);for(let r of this.sections)r.indexXInNode===n?r.stretch(e,t):r.indexXInNode<n&&r.move([r.coords[0]-t,r.coords[1]]);break}this.stretch(e,t)}getGeometry(e){let t={};for(let e of this.sections)t[e.id]=e.getGeometry();let n={};for(let t of this.children)t.id!==e&&(n[t.id]=t.getGeometry(e));return{coords:[...this.coords],width:this.width,height:this.height,sections:t,children:n}}setGeometry(e){this.raise();let t=[this.coords[0],this.coords[0]+this.width],n=[this.coords[1],this.coords[1]+this.height];this.coords=[...e.coords],this.width=e.width,this.height=e.height;let r=[this.coords[0],this.coords[0]+this.width],i=[this.coords[1],this.coords[1]+this.height];for(let t of this.children){let n=e.children[t.id];n&&t.setGeometry(n)}for(let t of this.sections){let n=e.sections[t.id];n&&t.setGeometry(n)}for(let e of this.ports)e.move(y(e.coords,t,n,r,i,e.anchorPointX,e.anchorPointY));this.label&&(this.label.coords=[this.coords[0]+R(this.type.label),this.coords[1]+B(this.type.label)],this.label.width=this.width-R(this.type.label)-z(this.type.label),this.label.height=this.height-B(this.type.label)-L(this.type.label),this.label.updateInView());for(let e of this.decorators)e.move(y(e.coords,t,n,r,i,e.anchorPointX,e.anchorPointY));this.model.canvas?.autoTightenConnections!==!1&&this.getConnections().forEach(e=>e.tighten()),this.updateInView()}removeSectionColumn(e){let t=this.type.sectionGrid?.margin||0,n=0,r=[...this.sections];for(let t of r)t.indexYInNode===e&&(n=Math.max(n,t.width),this.model.sections.remove(t.id));for(let i of r)i.indexYInNode>e&&(--i.indexYInNode,i.move([i.coords[0]-n-t,i.coords[1]]));this.stretch(f.Right,-t-n)}removeSectionRow(e){let t=this.type.sectionGrid?.margin||0,n=0,r=[...this.sections];for(let t of r)t.indexXInNode===e&&(n=Math.max(n,t.height),this.model.sections.remove(t.id));for(let i of r)i.indexYInNode>e&&(--i.indexXInNode,i.move([i.coords[0],i.coords[1]-n-t]));this.stretch(f.Bottom,-t-n)}copySectionColumn(e){let t=this.type.sectionGrid?.margin||0,n=0,r=[...this.sections];for(let i of r)if(i.indexXInNode===e){n=Math.max(n,i.width);let e=i.indexXInNode+1;for(;this.model.sections.get(`${i.id}_copy_${e}_${i.indexYInNode}`,!0)!==void 0;)++e;this.model.sections.new(this,i.indexXInNode+1,i.indexYInNode,[i.coords[0]+i.width+t,i.coords[1]],i.width,i.height,`${i.id}_copy_${e}_${i.indexYInNode}`)}for(let i of r)i.indexXInNode>e&&(++i.indexXInNode,i.move([i.coords[0]+n+t,i.coords[1]]));this.stretch(f.Right,t+n)}copySectionRow(e){let t=this.type.sectionGrid?.margin||0,n=0,r=[...this.sections];for(let i of r)if(i.indexYInNode===e){n=Math.max(n,i.height);let e=i.indexYInNode+1;for(;this.model.sections.get(`${i.id}_copy_${i.indexXInNode}_${e}`,!0)!==void 0;)++e;this.model.sections.new(this,i.indexXInNode,i.indexYInNode+1,[i.coords[0],i.coords[1]+i.height+t],i.width,i.height,`${i.id}_copy_${i.indexXInNode}_${e}`)}for(let i of r)i.indexYInNode>e&&(++i.indexYInNode,i.move([i.coords[0],i.coords[1]+n+t]));this.stretch(f.Bottom,t+n)}},Ze=class extends j{constructor(e){super(),this.types=new Pe,this.model=e}new(e,t,n){let r;if(e instanceof Xe)r=e;else{let t=this.types.get(e);if(t===void 0)throw TypeError(`Node type with id '${e}' could not be found.`);r=t}let i=new U(this.model,r,t,n);if(super.add(i),i.updateInView(),r.sectionGrid!==null){let e=i.coords[1]+(r.sectionGrid.margin||0);for(let t=0;t<r.sectionGrid.sections.length;++t){let n=i.coords[0]+(r.sectionGrid.margin||0);for(let a=0;a<r.sectionGrid.sections[t].length;++a)this.model.sections.new(i,a,t,[n,e],r.sectionGrid.defaultWidths?.[a]||1,r.sectionGrid.defaultHeights?.[t]||1,`${i.id}_${t}_${a}`),n+=(r.sectionGrid.defaultWidths?.[a]||1)+(r.sectionGrid.margin||0);e+=(r.sectionGrid.defaultHeights?.[t]||1)+(r.sectionGrid.margin||0)}}if(r.ports.length>0)for(let e=0;e<r.ports.length;++e){let t=r.ports[e],n=t.type===void 0?void 0:this.model.ports.types.get(t.type),a=this.model.ports.new(n,i,[i.coords[0]+t.coords[0],i.coords[1]+t.coords[1]],t.connectionPoint===void 0?void 0:[i.coords[0]+(t.connectionPoint[0]||0),i.coords[1]+(t.connectionPoint[1]||0)],t.direction,`${i.id}_port_${e}`,t.anchorPointX||`floating`,t.anchorPointY||`floating`);if(a.type?.label){let e={...F,...a.type?.label};e.look={...F.look,...e.look};let t=6*(e.look.fontSize||F.look.fontSize)+Be(e)+Ve(e),n=(e.look.fontSize||F.look.fontSize)+He(e)+ze(e),r;switch(a.direction){case f.Bottom:case f.Left:case f.Right:r=[a.coords[0]-t/2,a.coords[1]-n-L(e)];break;case f.Top:r=[a.coords[0]-t/2,a.coords[1]+B(e)];break;default:r=a.coords}this.model.fields.new(a,r,t,n,e.horizontalAlign,e.verticalAlign,e.orientation,e.multiline,e.look,``,e.editable,e.fit,e.shrink)}}if(r.label){let e={...F,...r.label};e.look={...F.look,...e.look},this.model.fields.new(i,[i.coords[0]+R(e),i.coords[1]+B(e)],i.width-R(e)-z(e),i.height-B(e)-L(e),e.horizontalAlign,e.verticalAlign,e.orientation,e.multiline,e.look,``,e.editable,e.fit,e.shrink)}if(r.decorators.length>0)for(let e=0;e<r.decorators.length;++e){let t=r.decorators[e];this.model.decorators.new(i,[i.coords[0]+t.coords[0],i.coords[1]+t.coords[1]],t.width,t.height,i.getPriority(),t.svg,`${i.id}_decorator_${e}`,t.anchorPointX||`floating`,t.anchorPointY||`floating`)}return i.valueSet.resetValues(),i.model.canvas?.fitNodeInView(i.id),i}remove(e){let t=this.get(e,!0);if(t){for(t.parent&&E(t.parent.children,t);t.children.length>0;)this.model.nodes.remove(t.children[0].id);for(;t.sections.length>0;)this.model.sections.remove(t.sections[0].id);for(;t.ports.length>0;)this.model.ports.remove(t.ports[0].id);for(;t.decorators.length>0;)this.model.decorators.remove(t.decorators[0].id);t.label&&this.model.fields.remove(t.label.id),super.remove(e),t.updateInView()}}getAtCoordinates(e,t){let n=[];for(let r of this)r.coords[0]<e&&e<r.coords[0]+r.width&&r.coords[1]<t&&t<r.coords[1]+r.height&&n.push(r);return n}},Qe=e=>{for(let t=0;t<e.length;++t)for(let n=0;n<e.length;++n)n!==t&&e[n].isAncestorOf(e[t])&&(e.splice(n,1),--n,t>n&&--t);return e},$e=e=>e?.padding===null||e?.padding===void 0?Ye.padding:typeof e.padding==`number`?e.padding:e.padding.length===1||e.padding.length===2?e.padding[0]:(e.padding.length,e.padding[2]),et=e=>e?.padding===null||e?.padding===void 0?Ye.padding:typeof e.padding==`number`?e.padding:e.padding.length===1?e.padding[0]:e.padding.length===2||e.padding.length===3?e.padding[1]:e.padding[3],tt=e=>e?.padding===null||e?.padding===void 0?Ye.padding:typeof e.padding==`number`?e.padding:e.padding.length===1?e.padding[0]:(e.padding.length===2||e.padding.length,e.padding[1]),nt=e=>e?.padding===null||e?.padding===void 0?Ye.padding:typeof e.padding==`number`?e.padding:(e.padding.length===1||e.padding.length===2||e.padding.length,e.padding[0]),rt=class extends Fe{constructor(e,t,n,r,i,a,o,s,c=`floating`,l=`floating`){if(e.objects.get(s)!==void 0)throw Error(`DiagramDecorator with id "${s}" already exists`);if(!s)throw Error(`DiagramDecorator cannot have an empty or null id`);super(e,s),this.rootElement=t,this.coords=n,this.width=r,this.height=i,this.priority=a,this.svg=o,this.anchorPointX=c,this.anchorPointY=l}get removed(){return this.selfRemoved||this.rootElement!==void 0&&this.rootElement.removed}updateInView(){this.model.canvas?.updateDecoratorsInView(this.id)}raise(){this.select()?.raise()}move(e){this.coords=e,this.updateInView()}getPriority(){return this.priority}},it=class extends j{constructor(e){super(),this.model=e}new(e,t,n,r,i,a,o,s=`floating`,c=`floating`){let l=new rt(this.model,e,t,n,r,i,a,o,s,c);return super.add(l),l.updateInView(),e!==void 0&&e.decorators.push(l),l}remove(e){let t=this.get(e,!0);t&&((t.rootElement instanceof U||t.rootElement instanceof H)&&E(t.rootElement.decorators,t),super.remove(e),t.updateInView())}},at=class extends Fe{constructor(e,t,n,r,i,a,o){if(e.objects.get(o)!==void 0)throw Error(`DiagramObject with id "${o}" already exists`);if(!o)throw Error(`DiagramObject cannot have an empty or null id`);super(e,o),this.coords=t,this.width=n,this.height=r,this.priority=i,this.svg=a}get removed(){return this.selfRemoved}updateInView(){this.model.canvas?.updateObjectsInView(this.id)}raise(){this.select()?.raise()}move(e){this.coords=e,this.updateInView()}getPriority(){return this.priority}},ot=class extends j{constructor(e){super(),this.model=e}new(e,t,n,r,i,a){let o=new at(this.model,e,t,n,r,i,a);return super.add(o),o.updateInView(),o}remove(e){let t=this.get(e,!0);t&&(super.remove(e),t.updateInView())}},st={lookType:`shaped-look`,shape:oe.Ellipse,fillColor:`transparent`,borderColor:`transparent`,borderThickness:0,selected:{fillColor:`rgba(255, 0, 255, 0.5)`},highlighted:{fillColor:`rgba(0, 255, 255, 0.5)`}},ct=k(st),lt={name:``,label:null,allowsOutgoing:!0,allowsIncoming:!0,width:24,look:st},ut=class{constructor(e){let t={...lt,...e};this.id=t.id,this.name=t.name,this.label=t.label,this.allowsOutgoing=t.allowsOutgoing,this.allowsIncoming=t.allowsIncoming,this.width=t.width;let n=k(t.look);this.defaultLook=n.defaultLook,this.selectedLook=n.selectedLook,this.highlightedLook=n.highlightedLook,this.selectedAndHighlightedLook=n.selectedAndHighlightedLook}},dt=class extends Fe{get type(){return this._type}set type(e){e!==this._type&&(this._type=e,this.updateInView())}get typeString(){return this.type?.id}set typeString(e){if(e!==this.type?.id)if(e===void 0)this.type=void 0;else{let t=this.model.ports.types.get(e);t&&(this.type=t)}}get allowsOutgoing(){return this.type?.allowsOutgoing===void 0?!0:this.type?.allowsOutgoing}get allowsIncoming(){return this.type?.allowsIncoming===void 0?!0:this.type?.allowsIncoming}get name(){return this.label?.text||``}set name(e){this.label&&(this.label.text=e)}get look(){return this.selected?this.highlighted?this._selectedAndHighlightedLook===void 0?(this.type||ct)?.selectedAndHighlightedLook:this._selectedAndHighlightedLook:this._selectedLook===void 0?(this.type||ct)?.selectedLook:this._selectedLook:this.highlighted?this._highlightedLook===void 0?(this.type||ct)?.highlightedLook:this._highlightedLook:this._defaultLook===void 0?(this.type||ct)?.defaultLook:this._defaultLook}set look(e){this.lookConfig=e}get lookConfig(){return this._lookConfig}set lookConfig(e){if(this._lookConfig=e,e){let t=k(e);this._defaultLook={...this._defaultLook,...t.defaultLook},this._selectedLook={...this._selectedLook,...t.selectedLook},this._highlightedLook={...this._highlightedLook,...t.highlightedLook},this._selectedAndHighlightedLook={...this._selectedAndHighlightedLook,...t.selectedAndHighlightedLook}}else this._defaultLook=e,this._selectedLook=e,this._highlightedLook=e,this._selectedAndHighlightedLook=e}get width(){return this.type?.width||lt.width}get height(){return this.width}constructor(e,t,n,r,i,a,o,s=`floating`,c=`floating`){if(e.ports.get(o)!==void 0)throw Error(`DiagramPort with id "${o}" already exists`);if(!o)throw Error(`DiagramPort cannot have an empty or null id`);super(e,o),this.outgoingConnections=[],this.incomingConnections=[],this._type=t,this.rootElement=n,this.coords=r,this.connectionPoint=i||r,this.direction=a,this.anchorPointX=s,this.anchorPointY=c}get removed(){return this.selfRemoved||this.rootElement!==void 0&&this.rootElement.removed}updateInView(){this.model.canvas?.updatePortsInView(this.id)}raise(e=!0){if(this.select()?.raise(),this.label&&this.label.raise(),e){for(let e of this.incomingConnections)e.raise();for(let e of this.outgoingConnections)e.raise()}}startConnection(e){this.outgoingConnections.push(e)}finishConnection(e){this.incomingConnections.push(e)}getNode(){if(this.rootElement instanceof U)return this.rootElement;if(this.rootElement instanceof H)return this.rootElement.node}getPriority(){return this.rootElement?.getPriority()||0}move(e){let t=[e[0]-this.coords[0],e[1]-this.coords[1]];this.coords=e,this.connectionPoint[0]=this.connectionPoint[0]+t[0],this.connectionPoint[1]=this.connectionPoint[1]+t[1];for(let e of this.outgoingConnections)e.setStart(this);for(let e of this.incomingConnections)e.setEnd(this);this.label&&this.label.move([this.label.coords[0]+t[0],this.label.coords[1]+t[1]]),this.updateInView()}distanceTo(e){return b(this.coords,e)}},ft=class extends j{constructor(e){super(),this.types=new Pe,this.model=e}new(e,t,n,r,i,a,o=`floating`,s=`floating`){let c=new dt(this.model,e,t,n,r,i,a,o,s);return super.add(c),c.updateInView(),t!==void 0&&t.ports.push(c),c}remove(e){let t=this.get(e,!0);if(t){for(;t.outgoingConnections.length>0;)this.model.connections.remove(t.outgoingConnections[0].id);for(;t.incomingConnections.length>0;)this.model.connections.remove(t.incomingConnections[0].id);t.label&&this.model.fields.remove(t.label.id),(t.rootElement instanceof U||t.rootElement instanceof H)&&E(t.rootElement.ports,t),super.remove(e),t.updateInView()}}},pt=class{import(e,t){e.clear(),t.id&&(e.id=t.id),e.name=t.name,e.description=t.description,e.type=t.type,e.createdAt=new Date(t.createdAt),e.updatedAt=new Date(t.updatedAt);for(let n of t.nodes||[])this.importNode(e,n);for(let n of t.connections||[])this.importConnection(e,n);for(let n of t.objects||[]){let t=new at(e,n.coords,n.width,n.height,n.priority,n.svg,n.id);n.collabMeta&&(t.selfRemoved=n.collabMeta.selfRemoved),e.objects.add(t),t.updateInView()}return t.data&&e.valueSet.setValues(t.data),t.collabMeta&&(e.logicalClock=t.collabMeta.logicalClock,e.valueSet.setTimestamps(t.collabMeta.dataTimestamps)),e}importNode(e,t){let n=e.nodes.types.get(t.type);if(n){let r=new U(e,n,t.coords,t.id);if(e.nodes.add(r),r.width=t.width,r.height=t.height,n.label){let i={...F,...n.label};i.look={...F.look,...i.look};let a=new I(e,r,[r.coords[0]+R(i),r.coords[1]+B(i)],r.width-R(i)-z(i),r.height-B(i)-L(i),i.horizontalAlign,i.verticalAlign,i.orientation,i.multiline,i.look,``,i.editable,i.fit,i.shrink);a.text=t.label,r.label=a,e.fields.add(a),a.updateInView()}for(let n of t.children||[]){let t=this.importNode(e,n);t!==void 0&&(r.children?.push(t),t.parent=r)}for(let i of t.sections||[]){let t=new H(e,r,i.indexXInNode,i.indexYInNode,i.coords,i.width,i.height,i.id);if(r.sections?.push(t),e.sections.add(t),n.sectionGrid?.sections?.[i.indexYInNode]?.[i.indexXInNode]?.label){let r={...F,...n.sectionGrid?.sections?.[i.indexYInNode]?.[i.indexXInNode]?.label};r.look={...F.look,...r.look};let a=new I(e,t,[t.coords[0]+R(r),t.coords[1]+B(r)],t.width-R(r)-z(r),t.height-B(r)-L(r),r.horizontalAlign,r.verticalAlign,r.orientation,r.multiline,r.look,``,r.editable,r.fit,r.shrink);a.text=i.label,t.label=a,e.fields.add(a),a.updateInView()}let a=0;for(let r of i.ports||[]){let i=r.type===void 0?void 0:e.ports.types.get(r.type),o=new dt(e,i,t,r.coords,r.connectionPoint||r.coords,r.direction,r.id);if(t.ports.push(o),e.ports.add(o),r.label){if(n.ports.length>a&&i?.label){let t={...F,...i?.label};t.look={...F.look,...t.look};let n;switch(o.direction){case f.Top:case f.Left:n=[o.coords[0]-(t.look.fontSize||F.look.fontSize),o.coords[1]-(t.look.fontSize||F.look.fontSize)];break;case f.Bottom:n=[o.coords[0]-(t.look.fontSize||F.look.fontSize),o.coords[1]+(t.look.fontSize||F.look.fontSize)];break;case f.Right:n=[o.coords[0]+(t.look.fontSize||F.look.fontSize),o.coords[1]-(t.look.fontSize||F.look.fontSize)];break;default:n=o.coords}let a=new I(e,o,n,t.look.fontSize||F.look.fontSize,t.look.fontSize||F.look.fontSize,t.horizontalAlign,t.verticalAlign,t.orientation,t.multiline,t.look,``,t.editable,t.fit,t.shrink);a.text=r.label,o.label=a,e.fields.add(a),a.updateInView()}++a}r.collabMeta&&(o.selfRemoved=r.collabMeta.selfRemoved,o.selfRemovedTimestamp=r.collabMeta.selfRemovedTimestamp,this.importLabelCollabMeta(o.label,r.collabMeta.label)),o.updateInView()}for(let n of i.decorators||[]){let i=new rt(e,t,n.coords,n.width,n.height,n.priority,n.svg,n.id,n.anchorPoints[0],n.anchorPoints[1]);n.collabMeta&&(i.selfRemoved=n.collabMeta.selfRemoved),r.decorators.push(i),e.decorators.add(i),i.updateInView()}i.collabMeta&&(t.selfRemoved=i.collabMeta.selfRemoved,t.selfRemovedTimestamp=i.collabMeta.selfRemovedTimestamp,this.importLabelCollabMeta(t.label,i.collabMeta.label)),t.updateInView()}let i=0;for(let a of t.ports||[]){let t=a.type===void 0?void 0:e.ports.types.get(a.type),o=new dt(e,t,r,a.coords,a.connectionPoint||a.coords,a.direction,a.id);if(r.ports.push(o),e.ports.add(o),a.label){if(n.ports.length>i&&t?.label){let n={...F,...t?.label};n.look={...F.look,...n.look};let r;switch(o.direction){case f.Top:case f.Left:r=[o.coords[0]-(n.look.fontSize||F.look.fontSize),o.coords[1]-(n.look.fontSize||F.look.fontSize)];break;case f.Bottom:r=[o.coords[0]-(n.look.fontSize||F.look.fontSize),o.coords[1]+(n.look.fontSize||F.look.fontSize)];break;case f.Right:r=[o.coords[0]+(n.look.fontSize||F.look.fontSize),o.coords[1]-(n.look.fontSize||F.look.fontSize)];break;default:r=o.coords}let i=new I(e,o,r,n.look.fontSize||F.look.fontSize,n.look.fontSize||F.look.fontSize,n.horizontalAlign,n.verticalAlign,n.orientation,n.multiline,n.look,``,n.editable,n.fit,n.shrink);i.text=a.label,o.label=i,e.fields.add(i),i.updateInView()}++i}a.collabMeta&&(o.selfRemoved=a.collabMeta.selfRemoved,o.selfRemovedTimestamp=a.collabMeta.selfRemovedTimestamp,this.importLabelCollabMeta(o.label,a.collabMeta.label)),o.updateInView()}for(let n of t.decorators||[]){let t=new rt(e,r,n.coords,n.width,n.height,n.priority,n.svg,n.id,n.anchorPoints[0],n.anchorPoints[1]);n.collabMeta&&(t.selfRemoved=n.collabMeta.selfRemoved),r.decorators.push(t),e.decorators.add(t),t.updateInView()}return t.data&&r.valueSet.setValues(t.data),t.collabMeta&&(r.selfRemoved=t.collabMeta.selfRemoved,r.selfRemovedTimestamp=t.collabMeta.selfRemovedTimestamp,r.geometryTimestamp=t.collabMeta.geometryTimestamp,this.importLabelCollabMeta(r.label,t.collabMeta.label),r.valueSet.setTimestamps(t.collabMeta.dataTimestamps)),r.updateInView(),r.raise(),r}}importConnection(e,t){let n=e.connections.types.get(t.type);if(n){let r=new N(e,n,t.start?e.ports.get(t.start):void 0,t.end?e.ports.get(t.end):void 0,t.id);return e.connections.add(r),r.startLabel=t.startLabel,r.middleLabel=t.middleLabel,r.endLabel=t.endLabel,r.points=t.points,t.data&&r.valueSet.setValues(t.data),t.collabMeta&&(r.selfRemoved=t.collabMeta.selfRemoved,r.selfRemovedTimestamp=t.collabMeta.selfRemovedTimestamp,r.valueSet.setTimestamps(t.collabMeta.dataTimestamps)),r.updateInView(),r.raise(),r}}importLabelCollabMeta(e,t){e&&t&&(e.selfRemoved=t.selfRemoved,e.selfRemovedTimestamp=t.selfRemovedTimestamp,e.textTimestamp=t.textTimestamp)}},mt=class e{constructor(e,t,n,r,i,a,o){this.canvas=e,this.id=t,this.typeId=n,this.coords=r,this.parentId=i,this.label=a,this.values=o}do(){let e=this.canvas.model.nodes.new(this.typeId,this.coords,this.id);this.parentId!==void 0&&this.canvas.model.nodes.get(this.parentId)?.addChild(e),e.label&&(e.label.text=this.label||``),this.values===void 0?e.valueSet.resetValues():e.valueSet.setValues(Te({...e.valueSet.getValues(),...this.values}))}serialize(){return{type:`addNode`,id:this.id,typeId:this.typeId,coords:this.coords,parentId:this.parentId,label:this.label,values:this.values}}static deserialize(t,n){return new e(t,n.id,n.typeId,n.coords,n.parentId,n.label,n.values)}},ht=class e{constructor(e,t,n,r,i,a,o){this.canvas=e,this.nodeId=t,this.copyColumnIndex=n,this.copyRowIndex=r,this.removeColumnIndex=i,this.removeRowIndex=a,this.timestamp=o}do(){let e=this.canvas.model.nodes.get(this.nodeId);e&&Oe(this.timestamp,e.geometryTimestamp)&&(this.copyColumnIndex!==void 0&&e.copySectionColumn(this.copyColumnIndex),this.copyRowIndex!==void 0&&e.copySectionRow(this.copyRowIndex),this.removeColumnIndex!==void 0&&e.removeSectionColumn(this.removeColumnIndex),this.removeRowIndex!==void 0&&e.removeSectionRow(this.removeRowIndex),e.geometryTimestamp=this.timestamp)}serialize(){return{type:`addSection`,nodeId:this.nodeId,copyColumnIndex:this.copyColumnIndex,copyRowIndex:this.copyRowIndex,removeColumnIndex:this.removeColumnIndex,removeRowIndex:this.removeRowIndex,timestamp:this.timestamp}}static deserialize(t,n){return new e(t,n.nodeId,n.copyColumnIndex,n.copyRowIndex,n.removeColumnIndex,n.removeRowIndex,n.timestamp)}},gt=class e{constructor(e,t,n){this.canvas=e,this.to=t,this.timestamp=n}do(){for(let e in this.to){let t=this.canvas.model.nodes.get(e,!0);if(t&&Oe(this.timestamp,t.geometryTimestamp)){let n=this.to[e];t.move([n[0],n[1]]),t.geometryTimestamp=this.timestamp}}}serialize(){return{type:`applyLayout`,to:this.to,timestamp:this.timestamp}}static deserialize(t,n){return new e(t,n.to,n.timestamp)}},_t=class e{constructor(e,t,n,r){this.canvas=e,this.nodeIds=t,this.delta=n,this.timestamp=r}do(){for(let e of this.nodeIds){let t=this.canvas.model.nodes.get(e,!0);t&&Oe(this.timestamp,t.geometryTimestamp)&&(t.move([t.coords[0]+this.delta[0],t.coords[1]+this.delta[1]]),t.parent?.fitToChild(t),t.geometryTimestamp=this.timestamp)}}serialize(){return{type:`move`,nodeIds:this.nodeIds,delta:this.delta,timestamp:this.timestamp}}static deserialize(t,n){return new e(t,n.nodeIds,n.delta,n.timestamp)}},W=class e{constructor(e,t,n,r){this.canvas=e,this.nodeId=t,this.to=n,this.timestamp=r}do(){let e=this.canvas.model.nodes.get(this.nodeId,!0);if(e&&Oe(this.timestamp,e.geometryTimestamp)){e.setGeometry(this.to),e.label?.fit&&this.canvas.fitFieldRootInView(e.label.id,e.label.shrink);for(let t of e.sections)t.label?.fit&&this.canvas.fitFieldRootInView(t.label.id,t.label.shrink);e.parent?.fitToChild(e),e.geometryTimestamp=this.timestamp}}serialize(){return{type:`setGeometry`,nodeId:this.nodeId,to:this.to,timestamp:this.timestamp}}static deserialize(t,n){return new e(t,n.nodeId,n.to,n.timestamp)}},vt=class e{constructor(e,t,n,r,i){this.canvas=e,this.childId=t,this.parentId=n,this.childGeometry=r,this.timestamp=i}do(){let e=this.canvas.model.nodes.get(this.childId,!0),t=this.parentId===void 0?void 0:this.canvas.model.nodes.get(this.parentId,!0);e&&(this.parentId===void 0||t)&&Oe(this.timestamp,e.geometryTimestamp)&&(e.parent?.removeChild(e),e.setGeometry(this.childGeometry),t?.addChild(e))}serialize(){return{type:`setParent`,childId:this.childId,parentId:this.parentId,childGeometry:this.childGeometry,timestamp:this.timestamp}}static deserialize(t,n){return new e(t,n.childId,n.parentId,n.childGeometry,n.timestamp)}},yt=class e{constructor(e,t,n,r,i){this.canvas=e,this.id=t,this.typeId=n,this.startId=r,this.endId=i}do(){let e=this.canvas.model.ports.get(this.startId,!0),t=this.canvas.model.ports.get(this.endId,!0);e&&t&&this.canvas.model.connections.new(this.typeId,e,t,this.id)}serialize(){return{type:`addConnection`,id:this.id,typeId:this.typeId,startId:this.startId,endId:this.endId}}static deserialize(t,n){return new e(t,n.id,n.typeId,n.startId,n.endId)}},bt=class e{constructor(e,t,n,r){this.canvas=e,this.fieldId=t,this.to=n,this.timestamp=r}do(){let e=this.canvas.model.fields.get(this.fieldId,!0);e&&Oe(this.timestamp,e.textTimestamp)&&(e.text=this.to,e.textTimestamp=this.timestamp)}serialize(){return{type:`editField`,fieldId:this.fieldId,to:this.to,timestamp:this.timestamp}}static deserialize(t,n){return new e(t,n.fieldId,n.to,n.timestamp)}},xt=class e{constructor(e,t,n,r){this.canvas=e,this.id=t,this.to=n,this.timestamp=r}getValueSet(){return this.id===void 0?this.canvas.model.valueSet:(this.canvas.model.nodes.get(this.id,!0)||this.canvas.model.connections.get(this.id,!0))?.valueSet}do(){this.getValueSet()?.overwriteValuesLww(this.to,this.timestamp)}serialize(){return{type:`updateValues`,id:this.id,to:this.to,timestamp:this.timestamp}}static deserialize(t,n){return new e(t,n.id,n.to,n.timestamp)}},G=class e{constructor(e,t,n,r,i,a,o,s){this.canvas=e,this.nodeIds=t,this.sectionIds=n,this.portIds=r,this.connectionIds=i,this.fieldIds=a,this.selfRemoved=o,this.timestamp=s}doOne(e){e&&Oe(this.timestamp,e.selfRemovedTimestamp)&&(e.selfRemoved=this.selfRemoved,e.selfRemovedTimestamp=this.timestamp)}do(){for(let e of this.nodeIds)this.doOne(this.canvas.model.nodes.get(e,!0));for(let e of this.sectionIds)this.doOne(this.canvas.model.sections.get(e,!0));for(let e of this.portIds)this.doOne(this.canvas.model.ports.get(e,!0));for(let e of this.connectionIds)this.doOne(this.canvas.model.connections.get(e,!0));for(let e of this.fieldIds)this.doOne(this.canvas.model.fields.get(e,!0));this.canvas.updateNodesInView(...this.nodeIds),this.canvas.updateSectionsInView(...this.sectionIds),this.canvas.updatePortsInView(...this.portIds),this.canvas.updateConnectionsInView(...this.connectionIds),this.canvas.updateFieldsInView(...this.fieldIds),this.canvas.updateDecoratorsInView()}serialize(){return{type:`setSelfRemoved`,nodeIds:this.nodeIds,sectionIds:this.sectionIds,portIds:this.portIds,connectionIds:this.connectionIds,fieldIds:this.fieldIds,removed:this.selfRemoved,timestamp:this.timestamp}}static deserialize(t,n){return new e(t,n.nodeIds,n.sectionIds,n.portIds,n.connectionIds,n.fieldIds,n.removed,n.timestamp)}},St=class e{constructor(e,t,n){this.canvas=e,this.nodes=t,this.connections=n}do(){let e=new pt;this.canvas.userSelection.clear();for(let t of this.nodes){let n=e.importNode(this.canvas.model,t);n&&this.canvas.userSelection.add(n)}for(let t of this.connections){let n=e.importConnection(this.canvas.model,t);n&&this.canvas.userSelection.add(n)}}serialize(){return{type:`paste`,nodes:this.nodes,connections:this.connections}}static deserialize(t,n){return new e(t,n.nodes,n.connections)}},Ct=class{constructor(e){this.isInRoom=!1,this.canvas=e,this.replicaId=Ce()}freshTimestamp(){return this.canvas.model.logicalClock++,[this.canvas.model.logicalClock,this.replicaId]}freshId(){return`id`+Ce()}doCollaboratively(e){if(e.do(),this.onSend){let t=e.serialize();this.onSend(t)}}receive(e){switch(`timestamp`in e&&(this.canvas.model.logicalClock=Math.max(this.canvas.model.logicalClock,e.timestamp[0])),e.type){case`addNode`:mt.deserialize(this.canvas,e).do();break;case`addSection`:ht.deserialize(this.canvas,e).do();break;case`applyLayout`:gt.deserialize(this.canvas,e).do();break;case`move`:_t.deserialize(this.canvas,e).do();break;case`setGeometry`:W.deserialize(this.canvas,e).do();break;case`setParent`:vt.deserialize(this.canvas,e).do();break;case`addConnection`:yt.deserialize(this.canvas,e).do();break;case`editField`:bt.deserialize(this.canvas,e).do();break;case`updateValues`:xt.deserialize(this.canvas,e).do();break;case`setSelfRemoved`:G.deserialize(this.canvas,e).do();break;case`paste`:St.deserialize(this.canvas,e).do();break;default:console.error(`Unknown CollabAction type, skipping:`,e)}}},wt=class{constructor(e,t){this.canvas=e,this.maximum=t,this.history=[],this.index=0}add(e){this.index<this.history.length&&(this.history=this.history.slice(0,this.index)),this.history.length>=this.maximum?(this.history=this.history.slice(1,this.history.length),this.history.push(e)):(this.history.push(e),++this.index),this.canvas.diagramChange$.next({action:e,method:0})}undo(){let e;if(this.index>0){let t;do--this.index,e=this.history[this.index],t=e.undo();while(!t&&this.index>0)}this.canvas.diagramChange$.next({action:e,method:1})}redo(){let e;if(this.index<this.history.length){let t;do e=this.history[this.index],t=e.redo(),++this.index;while(!t&&this.index<this.history.length)}this.canvas.diagramChange$.next({action:e,method:2})}},K=function(e){return e.AddConnection=`add-connection`,e.AddNode=`add-node`,e.AddSectionAction=`add-section`,e.ApplyLayout=`apply-layout`,e.Clipboard=`clipboard`,e.ContextMenu=`context-menu`,e.EditField=`edit-field`,e.MoveNode=`move-node`,e.Paste=`paste`,e.Remove=`remove`,e.StretchNode=`stretch-node`,e.StretchSection=`stretch-section`,e.UpdateValues=`update-values`,e.Zoom=`zoom`,e}({}),Tt=class{constructor(e,t,n,r,i,a,o,s,c){this.canvas=e,this.type=t,this.coords=n,this.parentId=r,this.ancestorId=i,this.fromAncestorGeometry=a,this.toAncestorGeometry=o,this.label=s,this.values=c,this.id=this.canvas.collabEngine.freshId()}do(){let e=new mt(this.canvas,this.id,this.type.id,this.coords,this.parentId,this.label,this.values);if(this.canvas.collabEngine.doCollaboratively(e),this.ancestorId!==void 0&&this.toAncestorGeometry!==void 0){let e=new W(this.canvas,this.ancestorId,this.toAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(e)}return!0}undo(){let e=this.canvas.model.nodes.get(this.id),t=new G(this.canvas,[this.id],[],[],[],[],!0,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(t),this.ancestorId!==void 0&&this.fromAncestorGeometry!==void 0){let e=new W(this.canvas,this.ancestorId,this.fromAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(e)}return e!==void 0}redo(){let e=this.canvas.model.nodes.get(this.id),t=new G(this.canvas,[this.id],[],[],[],[],!1,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(t),this.ancestorId!==void 0&&this.toAncestorGeometry!==void 0){let e=new W(this.canvas,this.ancestorId,this.toAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(e)}return e===void 0}},Et=class{constructor(e,t,n){this.canvas=e,this.nodeIds=t,this.delta=n}do(){let e=new _t(this.canvas,this.nodeIds,this.delta,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),this.nodeIds.map(e=>this.canvas.model.nodes.get(e)!==void 0).includes(!0)&&(this.delta[0]!==0||this.delta[1]!==0)}undo(){let e=new _t(this.canvas,this.nodeIds,[-this.delta[0],-this.delta[1]],this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),this.nodeIds.map(e=>this.canvas.model.nodes.get(e)!==void 0).includes(!0)&&(this.delta[0]!==0||this.delta[1]!==0)}redo(){return this.do()}},q=class{constructor(e,t,n,r,i,a,o,s){this.canvas=e,this.intent=t,this.nodeId=n,this.from=r,this.to=i,this.ancestorId=a,this.fromAncestorGeometry=o,this.toAncestorGeometry=s}do(){let e=this.canvas.model.nodes.get(this.nodeId);if(e){let e=new W(this.canvas,this.nodeId,this.to,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(e),this.ancestorId!==void 0&&this.toAncestorGeometry!==void 0){let e=new W(this.canvas,this.ancestorId,this.toAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(e)}}return e!==void 0}undo(){let e=this.canvas.model.nodes.get(this.nodeId);if(e){this.to=e.getGeometry();let t=new W(this.canvas,this.nodeId,this.from,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(t),this.ancestorId!==void 0&&this.fromAncestorGeometry!==void 0){let e=new W(this.canvas,this.ancestorId,this.fromAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(e)}}return e!==void 0}redo(){let e=this.canvas.model.nodes.get(this.nodeId);if(e){this.from=e.getGeometry();let t=new W(this.canvas,this.nodeId,this.to,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(t)}return e!==void 0}},Dt=class{constructor(e,t,n,r,i,a,o,s,c){this.canvas=e,this.childId=t,this.fromParentId=n,this.toParentId=r,this.fromChildGeometry=i,this.toChildGeometry=a,this.ancestorId=o,this.fromAncestorGeometry=s,this.toAncestorGeometry=c}do(){let e=this.canvas.model.nodes.get(this.childId),t=new vt(this.canvas,this.childId,this.toParentId,this.toChildGeometry,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(t),this.ancestorId!==void 0&&this.toAncestorGeometry!==void 0){let e=new W(this.canvas,this.ancestorId,this.toAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(e)}return e!==void 0}undo(){let e=this.canvas.model.nodes.get(this.childId),t=new vt(this.canvas,this.childId,this.fromParentId,this.fromChildGeometry,this.canvas.collabEngine.freshTimestamp());if(this.canvas.collabEngine.doCollaboratively(t),this.ancestorId!==void 0&&this.fromAncestorGeometry!==void 0){let e=new W(this.canvas,this.ancestorId,this.fromAncestorGeometry,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(e)}return e!==void 0}redo(){return this.do()}},Ot=class{constructor(e,t,n,r){this.canvas=e,this.type=t,this.startId=n,this.endId=r,this.id=this.canvas.collabEngine.freshId()}do(){let e=new yt(this.canvas,this.id,this.type.id,this.startId,this.endId);return this.canvas.collabEngine.doCollaboratively(e),!0}undo(){let e=this.canvas.model.connections.get(this.id),t=new G(this.canvas,[],[],[],[this.id],[],!0,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(t),e!==void 0}redo(){let e=this.canvas.model.connections.get(this.id),t=new G(this.canvas,[],[],[],[this.id],[],!1,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(t),e===void 0}},kt=class{constructor(e,t,n,r){this.canvas=e,this.fieldId=t,this.from=n,this.to=r}do(){let e=this.canvas.model.fields.get(this.fieldId),t=new bt(this.canvas,this.fieldId,this.to,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(t),e!==void 0}undo(){let e=this.canvas.model.fields.get(this.fieldId);if(e){this.to=e.text;let t=new bt(this.canvas,this.fieldId,this.from,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(t)}return e!==void 0}redo(){let e=this.canvas.model.fields.get(this.fieldId);if(e){this.from=e.text;let t=new bt(this.canvas,this.fieldId,this.to,this.canvas.collabEngine.freshTimestamp());this.canvas.collabEngine.doCollaboratively(t)}return e!==void 0}},At=class{constructor(e,t,n,r){this.canvas=e,this.id=t,this.from=n,this.to=r}do(){let e=new xt(this.canvas,this.id,this.to,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(e),!0}undo(){let e=new xt(this.canvas,this.id,this.from,this.canvas.collabEngine.freshTimestamp()),t=e.getValueSet();if(t)this.to=t.getValuesForKeys(this.to),this.canvas.collabEngine.doCollaboratively(e);else return!1;return!t.rootElement.removed}redo(){let e=new xt(this.canvas,this.id,this.to,this.canvas.collabEngine.freshTimestamp()),t=e.getValueSet();if(t)this.from=t.getValuesForKeys(this.from),this.canvas.collabEngine.doCollaboratively(e);else return!1;return!t.rootElement.removed}},jt=class{constructor(e,t,n,r,i,a){this.canvas=e,this.nodeIds=t,this.sectionIds=n,this.portIds=r,this.connectionIds=i,this.fieldIds=a}do(){let e=this.nodeIds.map(e=>this.canvas.model.nodes.get(e)!==void 0).includes(!0)||this.sectionIds.map(e=>this.canvas.model.sections.get(e)!==void 0).includes(!0)||this.portIds.map(e=>this.canvas.model.ports.get(e)!==void 0).includes(!0)||this.connectionIds.map(e=>this.canvas.model.connections.get(e)!==void 0).includes(!0)||this.fieldIds.map(e=>this.canvas.model.fields.get(e)!==void 0).includes(!0),t=new G(this.canvas,this.nodeIds,this.sectionIds,this.portIds,this.connectionIds,this.fieldIds,!0,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(t),e}undo(){let e=this.nodeIds.map(e=>this.canvas.model.nodes.get(e)===void 0).includes(!0)||this.sectionIds.map(e=>this.canvas.model.sections.get(e)===void 0).includes(!0)||this.portIds.map(e=>this.canvas.model.ports.get(e)===void 0).includes(!0)||this.connectionIds.map(e=>this.canvas.model.connections.get(e)===void 0).includes(!0)||this.fieldIds.map(e=>this.canvas.model.fields.get(e)===void 0).includes(!0),t=new G(this.canvas,this.nodeIds,this.sectionIds,this.portIds,this.connectionIds,this.fieldIds,!1,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(t),e}redo(){return this.do()}},Mt=class{constructor(e,t,n,r){this.canvas=e,this.nodes=t,this.connections=n,this.coords=r}do(){let e=[1/0,1/0];for(let t of this.nodes)t.coords[0]<e[0]&&(e[0]=t.coords[0]),t.coords[1]<e[1]&&(e[1]=t.coords[1]);let t=this.coords===void 0?void 0:[this.coords[0]-e[0],this.coords[1]-e[1]],n={};for(let e of this.nodes){let r=e.id,i=this.canvas.collabEngine.freshId();if(n[r]=i,e.id=i,t&&(e.coords=[e.coords[0]+t[0],e.coords[1]+t[1]]),e.sections)for(let r of e.sections){let a=r.id;if(r.id.includes(e.id)?r.id=r.id.replace(e.id,i):r.id=this.canvas.collabEngine.freshId(),n[a]=r.id,t&&(r.coords=[r.coords[0]+t[0],r.coords[1]+t[1]]),r.ports)for(let a of r.ports){let r=a.id;a.id.includes(e.id)?a.id=a.id.replace(e.id,i):a.id=this.canvas.collabEngine.freshId(),n[r]=a.id,t&&(a.coords=[a.coords[0]+t[0],a.coords[1]+t[1]],a.connectionPoint&&=[a.connectionPoint[0]+t[0],a.connectionPoint[1]+t[1]])}}if(e.ports)for(let r of e.ports){let a=r.id;r.id.includes(e.id)?r.id=r.id.replace(e.id,i):r.id=this.canvas.collabEngine.freshId(),n[a]=r.id,t&&(r.coords=[r.coords[0]+t[0],r.coords[1]+t[1]],r.connectionPoint&&=[r.connectionPoint[0]+t[0],r.connectionPoint[1]+t[1]])}}for(let e of this.connections){let r=this.canvas.collabEngine.freshId();if(n[e.id]=r,e.id=r,e.start=n[e.start]||e.start,e.end=n[e.end]||e.end,t)for(let n=0;n<e.points.length;++n)e.points[n]=[e.points[n][0]+t[0],e.points[n][1]+t[1]]}let r=new St(this.canvas,this.nodes,this.connections);return this.canvas.collabEngine.doCollaboratively(r),!0}undo(){let e=this.nodes.map(e=>this.canvas.model.nodes.get(e.id)!==void 0).includes(!0)||this.connections.map(e=>this.canvas.model.connections.get(e.id)!==void 0).includes(!0),t=new G(this.canvas,this.nodes.map(e=>e.id),[],[],this.connections.map(e=>e.id),[],!0,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(t),e}redo(){let e=this.nodes.map(e=>this.canvas.model.nodes.get(e.id)===void 0).includes(!0)||this.connections.map(e=>this.canvas.model.connections.get(e.id)===void 0).includes(!0),t=new G(this.canvas,this.nodes.map(e=>e.id),[],[],this.connections.map(e=>e.id),[],!1,this.canvas.collabEngine.freshTimestamp());return this.canvas.collabEngine.doCollaboratively(t),e}},Nt=class{constructor(e){this.type=e,this.defaultPrevented=!1}preventDefault(){this.defaultPrevented=!0}},Pt=function(e){return e[e.Zoom=0]=`Zoom`,e[e.DoubleClick=1]=`DoubleClick`,e[e.SecondaryClick=2]=`SecondaryClick`,e[e.Selection=3]=`Selection`,e[e.Highlight=4]=`Highlight`,e[e.DraggingNode=5]=`DraggingNode`,e}({}),Ft=class extends Nt{constructor(e,t){super(0),this.coords=e,this.zoom=t}},It=class extends Nt{constructor(e,t,n){super(1),this.cause=e,this.target=t,this.coords=n}},Lt=class extends Nt{constructor(e,t,n){super(2),this.cause=e,this.target=t,this.coords=n}},J=class extends Nt{constructor(e,t){super(3),this.targets=e,this.selected=t}},Y=class extends Nt{constructor(e){super(4),this.target=e}},Rt=class extends Nt{constructor(e){super(5),this.target=e}},zt=class{constructor(e,t,n,r,i,a=[]){this.nodes=new Ze(this),this.sections=new qe(this),this.ports=new ft(this),this.connections=new Le(this),this.fields=new Re(this),this.objects=new ot(this),this.decorators=new it(this),this.canvas=e,this.id=t,this.name=n,this.description=r,this.type=i,this.createdAt=new Date,this.updatedAt=new Date,this.logicalClock=0,this.valueSet=new Ne(new De(a),this)}clear(){this.canvas?.cancelAllUserActions(),this.id=void 0,this.name=``,this.description=void 0,this.createdAt=new Date,this.updatedAt=new Date,this.logicalClock=0,this.nodes.clear(),this.sections.clear(),this.ports.clear(),this.connections.clear(),this.fields.clear(),this.objects.clear(),this.decorators.clear(),this.valueSet.resetValues(),this.canvas?.updateModelInView()}},Bt=e=>!!e.button,Vt=(e,t,n,r,i,a,o,s,c)=>ie(e,[t,...a,n],r,i,Math.max(10,s??0,c??0)*o),X=e=>{e?c.select(`body`).style(`cursor`,e):c.select(`body`).style(`cursor`,D.Auto)},Ht=e=>e instanceof U?e:e instanceof H?e.node??e:e.rootElement instanceof U||e.rootElement instanceof H||e.rootElement instanceof dt?Ht(e.rootElement):e,Ut=e=>{if(e instanceof U)return e.type.resizerX.mode!==P.Never;if(e instanceof H){if(e.type?.resizerX!==void 0)return e.type.resizerX.mode!==P.Never;if(e.node!==void 0)return Ut(e.node)}return!1},Wt=e=>{if(e instanceof U)return e.type.resizerY.mode!==P.Never;if(e instanceof H){if(e.type?.resizerY!==void 0)return e.type.resizerY.mode!==P.Never;if(e.node!==void 0)return Wt(e.node)}return!1},Gt=e=>{if(e instanceof U)return e.type.resizerXY.mode!==P.Never;if(e instanceof H){if(e.type?.resizerXY!==void 0)return e.type.resizerXY.mode!==P.Never;if(e.node!==void 0)return Gt(e.node)}return!1},Kt=e=>{e.filter(`.shaped-look`).append(`path`),e.filter(`.image-look`).append(`image`).attr(`preserveAspectRatio`,`none`),e.filter(`.stretchable-image-look`).append(`image`).attr(`class`,`top-left-image`).attr(`preserveAspectRatio`,`none`),e.filter(`.stretchable-image-look`).append(`image`).attr(`class`,`top-image`).attr(`preserveAspectRatio`,`none`),e.filter(`.stretchable-image-look`).append(`image`).attr(`class`,`top-right-image`).attr(`preserveAspectRatio`,`none`),e.filter(`.stretchable-image-look`).append(`image`).attr(`class`,`left-image`).attr(`preserveAspectRatio`,`none`),e.filter(`.stretchable-image-look`).append(`image`).attr(`class`,`center-image`).attr(`preserveAspectRatio`,`none`),e.filter(`.stretchable-image-look`).append(`image`).attr(`class`,`right-image`).attr(`preserveAspectRatio`,`none`),e.filter(`.stretchable-image-look`).append(`image`).attr(`class`,`bottom-left-image`).attr(`preserveAspectRatio`,`none`),e.filter(`.stretchable-image-look`).append(`image`).attr(`class`,`bottom-image`).attr(`preserveAspectRatio`,`none`),e.filter(`.stretchable-image-look`).append(`image`).attr(`class`,`bottom-right-image`).attr(`preserveAspectRatio`,`none`)},qt={fillColor:`#FFFFFF`,borderColor:`#000000`,borderThickness:1,borderStyle:ne.Solid},Jt=e=>{e.filter(`.shaped-look`).select(`path`).attr(`d`,e=>se(e.look.shape??oe.Rectangle,0,0,e.width,e.height)).attr(`fill`,e=>e.look.fillColor??qt.fillColor).attr(`stroke`,e=>e.look.borderColor??qt.borderColor).attr(`stroke-width`,e=>`${e.look.borderThickness??qt.borderThickness}px`).attr(`stroke-dasharray`,e=>ae(e.look.borderStyle??qt.borderStyle,e.type?.defaultLook?.borderThickness??e.look?.borderThickness??qt.borderThickness)),e.filter(`.image-look`).select(`image`).attr(`x`,0).attr(`y`,0).attr(`width`,e=>e.width).attr(`height`,e=>e.height).attr(`href`,e=>e.look.backgroundImage),e.filter(`.stretchable-image-look`).select(`image.top-left-image`).attr(`x`,0).attr(`y`,0).attr(`width`,e=>e.look.leftMargin).attr(`height`,e=>e.look.topMargin).attr(`href`,e=>e.look.backgroundImageTopLeft),e.filter(`.stretchable-image-look`).select(`image.top-image`).attr(`x`,e=>e.look.leftMargin).attr(`y`,0).attr(`width`,e=>e.width-e.look.rightMargin-e.look.leftMargin).attr(`height`,e=>e.look.topMargin).attr(`href`,e=>e.look.backgroundImageTop),e.filter(`.stretchable-image-look`).select(`image.top-right-image`).attr(`x`,e=>e.width-e.look.rightMargin).attr(`y`,0).attr(`width`,e=>e.look.rightMargin).attr(`height`,e=>e.look.topMargin).attr(`href`,e=>e.look.backgroundImageTopRight),e.filter(`.stretchable-image-look`).select(`image.left-image`).attr(`x`,0).attr(`y`,e=>e.look.topMargin).attr(`width`,e=>e.look.leftMargin).attr(`height`,e=>e.height-e.look.bottomMargin-e.look.topMargin).attr(`href`,e=>e.look.backgroundImageLeft),e.filter(`.stretchable-image-look`).select(`image.center-image`).attr(`x`,e=>e.look.leftMargin).attr(`y`,e=>e.look.topMargin).attr(`width`,e=>e.width-e.look.rightMargin-e.look.leftMargin).attr(`height`,e=>e.height-e.look.bottomMargin-e.look.topMargin).attr(`href`,e=>e.look.backgroundImageCenter),e.filter(`.stretchable-image-look`).select(`image.right-image`).attr(`x`,e=>e.width-e.look.rightMargin).attr(`y`,e=>e.look.topMargin).attr(`width`,e=>e.look.rightMargin).attr(`height`,e=>e.height-e.look.bottomMargin-e.look.topMargin).attr(`href`,e=>e.look.backgroundImageRight),e.filter(`.stretchable-image-look`).select(`image.bottom-left-image`).attr(`x`,0).attr(`y`,e=>e.height-e.look.bottomMargin).attr(`width`,e=>e.look.leftMargin).attr(`height`,e=>e.look.bottomMargin).attr(`href`,e=>e.look.backgroundImageBottomLeft),e.filter(`.stretchable-image-look`).select(`image.bottom-image`).attr(`x`,e=>e.look.leftMargin).attr(`y`,e=>e.height-e.look.bottomMargin).attr(`width`,e=>e.width-e.look.rightMargin-e.look.leftMargin).attr(`height`,e=>e.look.bottomMargin).attr(`href`,e=>e.look.backgroundImageBottom),e.filter(`.stretchable-image-look`).select(`image.bottom-right-image`).attr(`x`,e=>e.width-e.look.rightMargin).attr(`y`,e=>e.height-e.look.bottomMargin).attr(`width`,e=>e.look.rightMargin).attr(`height`,e=>e.look.bottomMargin).attr(`href`,e=>e.look.backgroundImageBottomRight)},Yt={style:`solid`,color:`#FFFFFF`},Xt={enabled:!0,style:`none`,snap:!1,spacing:1},Zt={...Xt,style:`dots`,snap:!1,spacing:10,thickness:.05,color:`rgba(0, 0, 0, 0.1)`},Qt=(e,t)=>{switch(t?.style??``){case`image`:return e.append(`image`).attr(`x`,0).attr(`y`,0).attr(`width`,`100%`).attr(`height`,`100%`).attr(`href`,t.image).attr(`preserveAspectRatio`,`none`);default:return e.append(`rect`).attr(`x`,0).attr(`y`,0).attr(`width`,`100%`).attr(`height`,`100%`).attr(`fill`,t.color??`#FFFFFF`).attr(`stroke-width`,`0`)}},$t=e=>{if(!e)return Zt;switch(e.style){case`dots`:case`lines`:return{...Zt,...e};default:return{...Xt,...e}}},en=(e,t,n,r,i)=>{if(Z(i)!==0&&Q(i)!==0){let e=n.append(`pattern`).attr(`id`,r).attr(`x`,-Z(i)/2).attr(`y`,-Q(i)/2).attr(`width`,Z(i)).attr(`height`,Q(i)).attr(`patternUnits`,`userSpaceOnUse`);switch(e.append(`rect`).attr(`x`,0).attr(`y`,0).attr(`width`,Z(i)).attr(`height`,Q(i)).attr(`fill`,`transparent`),i.style){case`dots`:e.append(`circle`).attr(`cx`,Z(i)/2).attr(`cy`,Q(i)/2).attr(`r`,Math.min(Z(i),Q(i))*(i.thickness??0)).attr(`fill`,i.color??``);break;case`lines`:e.append(`line`).attr(`x1`,Z(i)/2).attr(`x2`,Z(i)/2).attr(`y1`,0).attr(`y2`,Q(i)).attr(`stroke-width`,Math.min(Z(i),Q(i))*(i.thickness??0)).attr(`stroke`,i.color??``),e.append(`line`).attr(`x1`,0).attr(`x2`,(Z(i)-Z(i)*(i.thickness??0))/2).attr(`y1`,Q(i)/2).attr(`y2`,Q(i)/2).attr(`stroke-width`,Math.min(Z(i),Q(i))*(i.thickness??0)).attr(`stroke`,i.color??``),e.append(`line`).attr(`x1`,(Z(i)+Z(i)*(i.thickness??0))/2).attr(`x2`,Z(i)).attr(`y1`,Q(i)/2).attr(`y2`,Q(i)/2).attr(`stroke-width`,Math.min(Z(i),Q(i))*(i.thickness??0)).attr(`stroke`,i.color??``);break;case`image`:e.append(`image`).attr(`x`,0).attr(`y`,0).attr(`width`,Z(i)).attr(`height`,Q(i)).attr(`href`,i.image).attr(`preserveAspectRatio`,`none`);break}return t.append(`rect`).attr(`x`,0).attr(`y`,0).attr(`width`,`100%`).attr(`height`,`100%`).attr(`fill`,`url(#${r})`).attr(`stroke-width`,`0`)}},Z=e=>{let t=0;return typeof e.spacing==`number`?t=e.spacing:Array.isArray(e.spacing)&&typeof e.spacing[0]==`number`&&(t=e.spacing[0]),isFinite(t)?t:0},Q=e=>{let t=0;return typeof e.spacing==`number`?t=e.spacing:Array.isArray(e.spacing)&&typeof e.spacing[1]==`number`&&(t=e.spacing[1]),isFinite(t)?t:0},tn=96,$=32,nn=128,rn=Math.PI/4,an=100,on={customButtons:[]},sn=class{constructor(e,t){this.canvas=e,this.config=t||on}open(e){this.close();let t=this.canvas.getPointerLocationRelativeToRoot(e),n=this.canvas.getPointerLocationRelativeToCanvas(e),r=this.canvas.selectSVGElement().append(`foreignObject`).attr(`class`,`daga-context-menu`).attr(`x`,`${t[0]-nn}px`).attr(`y`,`${t[1]-nn}px`).attr(`width`,`${2*nn}px`).attr(`height`,`${2*nn}px`).style(`pointer-events`,`none`).on(x.ContextMenu,t=>{this.canvas.canUserPerformAction(K.ContextMenu)&&(e.preventDefault(),this.open(t))}).on(x.Click,e=>{e.preventDefault(),this.close()});this.contextMenuContainer=r;let i=[];this.canvas.userSelection.length!==0&&this.canvas.canUserPerformAction(K.Clipboard)&&this.canvas.canUserPerformAction(K.Remove)&&i.push({name:`CUT`,imageClass:`daga-cut`,onPress:e=>{e.userSelection.cutToClipboard(),e.cancelAllUserActions()}}),this.canvas.userSelection.length!==0&&this.canvas.canUserPerformAction(K.Clipboard)&&i.push({name:`COPY`,imageClass:`daga-copy`,onPress:e=>{e.userSelection.copyToClipboard(),e.cancelAllUserActions()}}),this.canvas.canUserPerformAction(K.Paste)&&i.push({name:`PASTE`,imageClass:`daga-paste`,onPress:e=>{e.userSelection.pasteFromClipboard(e.getClosestGridPoint(n)),e.cancelAllUserActions()}}),this.canvas.userSelection.length!==0&&this.canvas.canUserPerformAction(K.Remove)&&i.push({name:`DELETE`,imageClass:`daga-delete`,onPress:e=>{e.userSelection.removeFromModel(),e.cancelAllUserActions()}});for(let e of this.config.customButtons||on.customButtons)(e.condition===void 0||e.condition(this.canvas))&&i.push(e);i.length===0&&i.push({name:`NONE`,imageClass:`daga-cross`,onPress:void 0});for(let e=0;e<i.length;++e){let t=i[e],n=t.onPress,a=(e+.5-i.length/2)*rn,o=r.append(`xhtml:div`).attr(`class`,`daga-context-menu-button ${t.onPress===void 0?``:` daga-clickable`}`).attr(`tabindex`,0).style(`position`,`absolute`).style(`box-sizing`,`border-box`).style(`width`,`${2*$}px`).style(`height`,`${2*$}px`).style(`border-radius`,`${$}px`).style(`pointer-events`,`auto`).on(x.Click,e=>{n&&(e.preventDefault(),n(this.canvas))}).on(x.KeyDown,e=>{n&&e.key===S.Enter&&(e.preventDefault(),n(this.canvas))});t.imageClass===void 0?t.image!==void 0&&o.append(`xhtml:img`).style(`position`,`absolute`).style(`left`,`${.75*$}px`).style(`top`,`${.5*$}px`).style(`width`,`${.5*$}px`).style(`height`,`${.5*$}px`).attr(`src`,t.image):o.append(`xhtml:div`).style(`position`,`absolute`).style(`left`,`${.75*$}px`).style(`top`,`${.5*$}px`).style(`width`,`${.5*$}px`).style(`height`,`${.5*$}px`).style(`background-size`,`contain`).style(`background-repeat`,`no-repeat`).attr(`class`,t.imageClass),o.append(`xhtml:span`).style(`position`,`absolute`).style(`left`,`${.2*$}px`).style(`top`,`${1.1*$}px`).style(`text-align`,`center`).style(`width`,`${1.6*$}px`).style(`height`,`${.35*$}px`).style(`margin`,`0`).style(`font-size`,`${.35*$}px`).style(`font-weight`,`700`).style(`user-select`,`none`).text(t.name),o.transition().ease(c.easeLinear).duration(an).tween(`progress`,()=>e=>{let t=a*e;return o.style(`left`,`${Math.sin(t)*tn-$+nn}px`).style(`top`,`${-Math.cos(t)*tn-$+nn}px`)})}}close(){this.contextMenuContainer?.remove(),this.contextMenuContainer=void 0}},cn=class extends j{constructor(e,t=!0){super(),this.focus=void 0,this.canvas=e,this.highlightSections=t}getFocus(){return this.focus}focusOn(e){this.clear(),this.focus=e,(e instanceof I||e instanceof rt)&&e.rootElement?this.focusOn(e.rootElement):this.add(e)}add(e){if(super.add(e),e instanceof U){if(!this.highlightSections)for(let t of e.sections){super.add(t);for(let e of t.ports)super.add(e),this.canvas.updatePortsInView(e.id);t.label&&(super.add(t.label),this.canvas.updateFieldsInView(t.label.id)),this.canvas.updateSectionsInView(t.id)}for(let t of e.ports)super.add(t),this.canvas.updatePortsInView(t.id);e.label&&(super.add(e.label),this.canvas.updateFieldsInView(e.label.id)),this.canvas.updateNodesInView(e.id)}else if(e instanceof H)if(!this.highlightSections&&e.node)this.add(e.node);else{for(let t of e.ports)super.add(t),this.canvas.updatePortsInView(t.id);e.label&&(super.add(e.label),this.canvas.updateFieldsInView(e.label.id)),this.canvas.updateSectionsInView(e.id)}else e instanceof dt?(e.label&&(super.add(e.label),this.canvas.updateFieldsInView(e.label.id)),this.canvas.updatePortsInView(e.id)):e instanceof N&&this.canvas.updateConnectionsInView(e.id)}clear(){for(;this.entities.length>0;){let e=this.entities[0];this.remove(e.id),e.updateInView()}this.focus=void 0}},ln=class{export(e,t=!1){let n={name:e.name,type:e.type,typeVersion:1,createdAt:e.createdAt,updatedAt:e.updatedAt,nodes:[],connections:[],objects:[],data:e.valueSet.getValues(),...t?{collabMeta:{logicalClock:e.logicalClock,dataTimestamps:e.valueSet.getTimestamps()}}:{}};e.id&&(n.id=e.id),e.description&&(n.description=e.description);for(let r of e.nodes.all(!0))!t&&r.removed||r.parent===void 0&&n.nodes.push(this.exportNode(r,t));for(let r of e.connections.all(!0))!t&&r.removed||n.connections.push(this.exportConnection(r,t));for(let r of e.objects.all(!0))n.objects?.push({id:r.id,coords:g(r.coords),width:r.width,height:r.height,priority:r.priority,svg:r.svg,...t?{collabMeta:{removed:r.removed,selfRemoved:r.selfRemoved}}:{}});return n}exportNode(e,t=!1){let n=[];for(let r of e.children)n.push(this.exportNode(r,t));let r=[];for(let n of e.sections){let e=[];for(let r of n.ports)e.push({id:r.id,type:r.type?.id,coords:g(r.coords),connectionPoint:g(r.connectionPoint||r.coords),direction:r.direction,label:r.label?.text||``,...t?{collabMeta:{removed:r.removed,selfRemoved:r.selfRemoved,selfRemovedTimestamp:r.selfRemovedTimestamp,...this.exportLabelCollabMeta(r)}}:{}});let i=[];for(let e of n.decorators)i.push({id:e.id,coords:g(e.coords),width:e.width,height:e.height,priority:e.priority,svg:e.svg,anchorPoints:[e.anchorPointX,e.anchorPointY],...t?{collabMeta:{removed:e.removed,selfRemoved:e.selfRemoved}}:{}});r.push({id:n.id,ports:e,decorators:i,label:n.label?.text||``,indexXInNode:n.indexXInNode,indexYInNode:n.indexYInNode,coords:g(n.coords),width:n.width,height:n.height,...t?{collabMeta:{removed:n.removed,selfRemoved:n.selfRemoved,selfRemovedTimestamp:n.selfRemovedTimestamp,...this.exportLabelCollabMeta(n)}}:{}})}let i=[];for(let n of e.ports)i.push({id:n.id,type:n.type?.id,coords:g(n.coords),connectionPoint:g(n.connectionPoint||n.coords),direction:n.direction,label:n.label?.text||``,...t?{collabMeta:{removed:n.removed,selfRemoved:n.selfRemoved,selfRemovedTimestamp:n.selfRemovedTimestamp,...this.exportLabelCollabMeta(n)}}:{}});let a=[];for(let n of e.decorators)a.push({id:n.id,coords:g(n.coords),width:n.width,height:n.height,priority:n.priority,svg:n.svg,anchorPoints:[n.anchorPointX,n.anchorPointY],...t?{collabMeta:{removed:n.removed,selfRemoved:n.selfRemoved}}:{}});return{id:e.id,type:e.type.id,children:n,sections:r,ports:i,decorators:a,label:e.label?.text||``,coords:g(e.coords),width:e.width,height:e.height,data:e.valueSet.getValues(),...t?{collabMeta:{removed:e.removed,selfRemoved:e.selfRemoved,selfRemovedTimestamp:e.selfRemovedTimestamp,geometryTimestamp:e.geometryTimestamp,dataTimestamps:e.valueSet.getTimestamps(),...this.exportLabelCollabMeta(e)}}:{}}}exportConnection(e,t=!1){return{id:e.id,type:e.type.id,start:e.start?.id||``,end:e.end?.id||``,startLabel:e.startLabel,middleLabel:e.middleLabel,endLabel:e.endLabel,points:e.points,data:e.valueSet.getValues(),...t?{collabMeta:{removed:e.removed,selfRemoved:e.selfRemoved,selfRemovedTimestamp:e.selfRemovedTimestamp,dataTimestamps:e.valueSet.getTimestamps()}}:{}}}exportLabelCollabMeta({label:e}){return e?{label:{removed:e.removed,selfRemoved:e.selfRemoved,selfRemovedTimestamp:e.selfRemovedTimestamp,textTimestamp:e.textTimestamp}}:{}}},un=`Diagram properties`,dn=class extends j{constructor(e,t){super(),this.canvas=e,this.canvas.propertyEditorChanges$.pipe((0,l.debounceTime)(2e3)).subscribe(()=>{this.makeUpdateValuesAction()}),this.diagramPropertiesText=t===void 0?un:t}add(e){if(!this.contains(e.id)&&(this.length===0?this.propertyEditorSelection===void 0&&(e instanceof U||e instanceof N)?this.openInPropertyEditor(e):this.propertyEditorSelection===void 0&&e instanceof H?this.openInPropertyEditor(e.node):this.openInPropertyEditor(void 0):this.openInPropertyEditor(void 0),super.add(e),e.updateInView(),e instanceof U&&e.sections))for(let t of e.sections)super.add(t),t.updateInView()}remove(e){let t=this.get(e);if(t&&(this.propertyEditorSelection===t&&this.openInPropertyEditor(void 0),super.remove(e),t.updateInView(),t instanceof U&&t.sections))for(let e of t.sections)super.remove(e.id),e.updateInView()}toggle(e){this.contains(e.id)?this.remove(e.id):this.add(e)}clear(){for(this.openInPropertyEditor(void 0);this.entities.length>0;){let e=this.entities[0];super.remove(e.id),e.updateInView()}}move(e){for(let t of this.all())t instanceof U&&t.move([t.coords[0]+e[0],t.coords[1]+e[1]])}removeFromModel(){if(this.length>0){let e=[],t=[],n=[],r=[],i=[];for(let a of this.all())a instanceof U?e.push(a.id):a instanceof H?t.push(a.id):a instanceof dt?n.push(a.id):a instanceof N?r.push(a.id):a instanceof I&&i.push(a.id);let a=new jt(this.canvas,e,t,n,r,i);a.do(),this.canvas.actionStack.add(a)}}copyToClipboard(){let e={type:`daga-user-selection`,nodes:[],connections:[]},t=new ln;for(let n of this.all())n instanceof U&&e.nodes.push(t.exportNode(n,!1)),n instanceof N&&e.connections.push(t.exportConnection(n,!1));navigator.clipboard.writeText(JSON.stringify(e))}cutToClipboard(){this.copyToClipboard(),this.removeFromModel()}pasteFromClipboard(e){navigator.clipboard.readText().then(t=>{try{let n=JSON.parse(t);if(n.type!==`daga-user-selection`)return;let r=new Mt(this.canvas,n.nodes,n.connections,e);this.canvas.actionStack.add(r),r.do()}catch{return}})}openInPropertyEditor(e,t=!0){t&&this.makeUpdateValuesAction();let n=this.canvas.parentComponent?.propertyEditor;if(n===void 0)return;let r=e?.valueSet;r?(this.propertyEditorSelection=e,t&&(this.propertyEditorValues=Te(r.getValues())),n&&(e instanceof U||e instanceof N?(e instanceof U?e.name?n.title=`${e.type.name}: ${e.name}`:n.title=e.type.name:e instanceof N&&(n.title=e.type.name),n.valueSet=void 0,n.valueSet=r):(n.title=this.diagramPropertiesText,n.valueSet=void 0,n.valueSet=r))):(this.propertyEditorSelection=void 0,this.propertyEditorValues=void 0,n&&(n.title=``,n.valueSet=void 0))}makeUpdateValuesAction(){if(this.propertyEditorSelection===void 0||this.propertyEditorValues===void 0)return;let e=this.propertyEditorSelection instanceof zt?void 0:this.propertyEditorSelection.id;if(Ae(this.propertyEditorValues,this.propertyEditorSelection?.valueSet.getValues()))return;let t=this.propertyEditorValues,n=Te(this.propertyEditorSelection?.valueSet.getValues()),[r,i]=je(t,n,this.propertyEditorSelection?.valueSet),a=new At(this.canvas,e,r,i);a.do(),this.canvas.actionStack.add(a),this.propertyEditorValues=n}},fn=`diagram-connection-unfinished`,pn=class e{static{this.canvasCount=0}get connectionType(){return this._connectionType}set connectionType(e){this._connectionType=e,this.parentComponent?.palette?.refreshPalette()}constructor(t,n){this.gridPatternId=`daga-grid-pattern-id-${++e.canvasCount}`,this.ancillaryGridPatternIds=[],this.zoomTransform=c.zoomIdentity,this.draggingFrom=[0,0],this.dragging=!1,this.secondaryButton=!1,this.validatorChange$=new l.Subject,this.diagramChange$=new l.Subject,this.diagramEvent$=new l.Subject,this.propertyEditorChanges$=new l.Subject,this.parentComponent=t,this.model=new zt(this,void 0,n.name||`unnamed`,``,n.type||``,n.properties||[]),this.userSelection=new dn(this,n.components?.propertyEditor?.title),this.userHighlight=new cn(this,n.canvas?.highlightSections!==!1),this.contextMenu=new sn(this,n.canvas?.contextMenu),this.backgroundConfig=n.canvas?.background??Yt,this.gridConfig=$t(n.canvas?.grid),this.ancillaryGridsConfig=[];for(let e=0;e<(n.canvas?.ancillaryGrids?.length||0);++e)this.ancillaryGridsConfig.push($t(n.canvas?.ancillaryGrids?.[e])),this.ancillaryGridPatternIds.push(`${this.gridPatternId}-ancillary-${e}`);if(this.zoomFactor=n.canvas?.zoomFactor||2,this.panRate=n.canvas?.panRate||100,this.inferConnectionType=n.connectionSettings?.inferConnectionType||!1,this.autoTightenConnections=n.connectionSettings?.autoTighten!==!1,this.tightenConnectionsAcrossPortTypes=n.connectionSettings?.tightenAcrossPortTypes||!1,this.allowConnectionLoops=n.connectionSettings?.allowLoops||!1,this.allowSharingPorts=n.connectionSettings?.sharePorts!==!1,this.allowSharingBothPorts=n.connectionSettings?.shareBothPorts||!1,this.portHighlightRadius=n.connectionSettings?.portHighlightRadius||100,this.multipleSelectionOn=!1,this.priorityThresholds=n.canvas?.priorityThresholds||[],this.priorityThreshold=this.priorityThresholds?this.priorityThresholds[0]:void 0,this.layoutFormat=n.layoutFormat,this.userActions=n.userActions||{},this.validators=[],this.actionStack=new wt(this,25),this.collabEngine=new Ct(this),n.nodeTypes)for(let e of n.nodeTypes){let t=new Xe({...n.nodeTypeDefaults,...e});this.model.nodes.types.add(t)}if(n.portTypes)for(let e of n.portTypes){let t=new ut({...n.portTypeDefaults,...e});this.model.ports.types.add(t)}if(n.connectionTypes){for(let e of n.connectionTypes){let t=new Ie({...n.connectionTypeDefaults,...e});this.model.connections.types.add(t)}this._connectionType=n?.connectionSettings?.defaultConnection===void 0?void 0:this.model.connections.types.get(n.connectionSettings.defaultConnection)}}addValidator(e){this.validators.push(e),this.validatorChange$.next()}removeValidator(e){E(this.validators,e),this.validatorChange$.next()}getPriorityThresholdOptions(){return this.priorityThresholds}getPriorityThreshold(){return this.priorityThreshold}setPriorityThreshold(e){this.priorityThreshold=e,this.updateModelInView();for(let e of this.model.nodes)this.fitNodeInView(e.id);this.parentComponent?.palette?.refreshPalette()}initView(e){let t=c.select(e);t.html(``),this.diagramRoot=t.append(`div`).node(),this.selectRoot().attr(`tabindex`,0).style(`width`,`100%`).style(`height`,`100%`).append(`svg`).style(`width`,`100%`).style(`height`,`100%`),this.selectRoot().on(x.Click,()=>{this.selectRoot().node()?.focus()}).on(x.ContextMenu,e=>{if(this.dragging){e.preventDefault(),e.stopPropagation(),this.dragging=!1;return}let t=new Lt(e,null);this.diagramEvent$.next(t),!t.defaultPrevented&&this.canUserPerformAction(K.ContextMenu)&&(e.preventDefault(),this.contextMenu.open(e))}).on(x.DoubleClick,e=>{let t=new It(e,null);this.diagramEvent$.next(t)}).on(x.KeyDown,e=>{if(!e.ctrlKey&&(e.key===S.Delete||e.key===S.Backspace)&&this.canUserPerformAction(K.Remove)&&(this.userSelection.removeFromModel(),this.cancelAllUserActions()),e.ctrlKey&&e.key===`a`){e.preventDefault();for(let e of this.model.nodes)this.userSelection.add(e);for(let e of this.model.connections)this.userSelection.add(e);this.diagramEvent$.next(new J(this.userSelection.all(),!0))}if(e.ctrlKey&&e.key===`i`){e.preventDefault();let t=[],n=[];for(let e of this.model.nodes)this.userSelection.toggle(e),e.selected?t.push(e):n.push(e);for(let e of this.model.connections)this.userSelection.toggle(e),e.selected?t.push(e):n.push(e);t.length>0&&this.diagramEvent$.next(new J(t,!0)),n.length>0&&this.diagramEvent$.next(new J(n,!1))}if(e.ctrlKey&&e.key===`c`&&this.canUserPerformAction(K.Clipboard)&&(e.preventDefault(),this.userSelection.copyToClipboard(),this.cancelAllUserActions()),e.ctrlKey&&e.key===`x`&&this.canUserPerformAction(K.Clipboard)&&this.canUserPerformAction(K.Remove)&&(e.preventDefault(),this.userSelection.cutToClipboard(),this.cancelAllUserActions()),e.ctrlKey&&e.key===`v`&&this.canUserPerformAction(K.Paste)){e.preventDefault();let t=this.getCoordinatesOnScreen();this.userSelection.pasteFromClipboard(this.getClosestGridPoint([(t[0][0]+t[1][0])/2,(t[0][1]+t[1][1])/2])),this.cancelAllUserActions()}e.ctrlKey&&e.key===`y`&&(e.preventDefault(),this.actionStack.redo()),e.ctrlKey&&e.key===`z`&&(e.preventDefault(),this.actionStack.undo()),e.key===`+`&&this.canUserPerformAction(K.Zoom)&&(e.preventDefault(),this.zoomBy(this.zoomFactor)),e.key===`-`&&this.canUserPerformAction(K.Zoom)&&(e.preventDefault(),this.zoomBy(1/this.zoomFactor)),e.key===S.ArrowLeft&&this.canUserPerformAction(K.Zoom)&&(e.preventDefault(),this.translateBy(this.panRate/this.zoomTransform.k,0)),e.key===S.ArrowRight&&this.canUserPerformAction(K.Zoom)&&(e.preventDefault(),this.translateBy(-this.panRate/this.zoomTransform.k,0)),e.key===S.ArrowDown&&this.canUserPerformAction(K.Zoom)&&(e.preventDefault(),this.translateBy(0,-this.panRate/this.zoomTransform.k)),e.key===S.ArrowUp&&this.canUserPerformAction(K.Zoom)&&(e.preventDefault(),this.translateBy(0,this.panRate/this.zoomTransform.k))});let n=this.selectSVGElement().append(`g`).attr(`class`,`daga-canvas-view`).attr(`width`,`100%`).attr(`height`,`100%`);n.call(this.zoomBehavior=c.zoom().filter(e=>e.type!==x.DoubleClick).on(w.Zoom,e=>{if(e.sourceEvent){if(!this.canUserPerformAction(K.Zoom)){X(D.NotAllowed);return}e.sourceEvent.type===x.Wheel&&e.sourceEvent.wheelDelta!==void 0?(e.sourceEvent.wheelDelta>0&&X(D.ZoomIn),e.sourceEvent.wheelDelta<0&&X(D.ZoomOut)):e.sourceEvent.type===x.MouseMove&&X(D.AllScroll)}this.zoomTransform=e.transform;let t=e.transform.toString();this.selectCanvasElements().attr(`transform`,t);for(let e of[this.gridPatternId,...this.ancillaryGridPatternIds])this.selectCanvasView().select(`#${e}`).attr(`patternTransform`,t);this.contextMenu.close(),this.diagramEvent$.next(new Ft([this.zoomTransform.x,this.zoomTransform.y],this.zoomTransform.k))}).on(w.End,()=>{X()}));let r=n.append(`defs`),i=[];i.push(Qt(n,this.backgroundConfig).attr(`class`,`daga-background`));for(let e=0;e<this.ancillaryGridsConfig.length;++e)i.push(en(this,n,r,this.ancillaryGridPatternIds[e],this.ancillaryGridsConfig[e]));i.push(en(this,n,r,this.gridPatternId,this.gridConfig));for(let e of i)e.on(x.MouseMove,e=>{if(this.unfinishedConnection!==void 0){let t=this.getPointerLocationRelativeToCanvas(e);this.unfinishedConnection.endCoords=t}}),e.on(x.MouseOver,()=>{this.userHighlight.size()>0&&(this.userHighlight.clear(),this.diagramEvent$.next(new Y(null)))}),e.on(x.Click,()=>{if(this.userHighlight.size()>0&&(this.userHighlight.clear(),this.diagramEvent$.next(new Y(null))),this.contextMenu.close(),this.userSelection.size()>0){let e=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new J(e,!1))}this.userSelection.openInPropertyEditor(this.model)}),e.call(c.drag().filter(e=>this.multipleSelectionOn||Bt(e)).on(C.Start,e=>{this.startMultipleSelection(e)}).on(C.Drag,e=>{this.continueMultipleSelection(e)}).on(C.End,e=>{this.finishMultipleSelection(e)}));n.append(`g`).attr(`class`,`daga-canvas-elements`)}getZoomLevel(){return this.zoomTransform.k}zoomBy(e){isNaN(e)||this.zoomBehavior.scaleBy(this.selectCanvasView(),e)}zoomTo(e){isNaN(e)||this.zoomBehavior.scaleTo(this.selectCanvasView(),e)}getViewCoordinates(){let e=this.selectCanvasView()?.select(`.daga-background`)?.node()?.getBBox();return[((e.width+e.x)/2-this.zoomTransform.x)/this.zoomTransform.k,((e.height+e.y)/2-this.zoomTransform.y)/this.zoomTransform.k]}translateBy(e,t){!isNaN(e)&&!isNaN(t)&&this.zoomBehavior.translateBy(this.selectCanvasView(),e,t)}translateTo(e,t){!isNaN(e)&&!isNaN(t)&&this.zoomBehavior.translateTo(this.selectCanvasView(),e,t)}zoomAndPanTo(e,t,n,r){if(!r||r<=0){this.zoomBehavior.scaleTo(this.selectCanvasView(),n),this.zoomBehavior.translateTo(this.selectCanvasView(),e,t);return}this.zoomBehavior.interpolate(c.interpolate);let[i,a]=this.getViewCoordinates(),o=this.getZoomLevel(),s=e,l=t,u=n;this.selectCanvasElements().transition().duration(r).ease(c.easeCubicInOut).tween(`progress`,()=>{let e=!1;return t=>{try{if(!e){let e=t*(s-i)+i,n=t*(l-a)+a,r=t*(u-o)+o;this.zoomBehavior.scaleTo(this.selectCanvasView(),r),this.zoomBehavior.translateTo(this.selectCanvasView(),e,n)}}catch(t){console.warn(`Animation has been interrupted.`,t),e=!0}}})}center(e,t,n){if(this.model.nodes.length>0){let r=this.selectCanvasView().select(`.daga-background`).node()?.getBBox();if(!r.width||!r.height)return;let i=e?.map(e=>this.model.nodes.get(e)).filter(e=>!!e)||this.model.nodes.all(),a=Math.min(...i.map(e=>e.coords[0])),o=Math.max(...i.map(e=>e.coords[0]+e.width)),s=(a+o)/2,c=o-a,l=r.width,u=Math.min(...i.map(e=>e.coords[1])),d=Math.max(...i.map(e=>e.coords[1]+e.height)),f=(u+d)/2,p=d-u,m=r.height,h=Math.min(l/c,m/p,t===void 0?1:t);this.zoomAndPanTo(s,f,h,n)}}getClosestGridPoint(e){let t=e[0],n=Z(this.gridConfig);n!==0&&(t=Math.round(t/n)*n);let r=e[1],i=Q(this.gridConfig);return i!==0&&(r=Math.round(r/i)*i),[t,r]}getCoordinatesOnScreen(){let e=this.selectSVGElement().node()?.getBoundingClientRect(),t=[e?.width||0,e?.height||0];return[[-this.zoomTransform.x/this.zoomTransform.k,-this.zoomTransform.y/this.zoomTransform.k],[(t[0]-this.zoomTransform.x)/this.zoomTransform.k,(t[1]-this.zoomTransform.y)/this.zoomTransform.k]]}getEventHoldingCoordinates(e){if(e.type===`drag`||e.type===`start`||e.type===`end`){let t=e.sourceEvent;if(t&&(t.type===`touchmove`||t.type===`touchstart`||t.type===`touchend`))return e.sourceEvent.touches[0]||e.sourceEvent.changedTouches[0]}return e}getPointerLocationRelativeToCanvas(e){return c.pointer(this.getEventHoldingCoordinates(e),this.selectCanvasElements().node())}getPointerLocationRelativeToRoot(e){return c.pointer(this.getEventHoldingCoordinates(e),this.selectSVGElement().node())}getPointerLocationRelativeToBody(e){return c.pointer(this.getEventHoldingCoordinates(e),c.select(`body`).node())}getPointerLocationRelativeToScreen(e){let t=this.getPointerLocationRelativeToBody(e);return[t[0]-window.scrollX,t[1]-window.scrollY]}updateModelInView(){this.updateNodesInView(),this.updateSectionsInView(),this.updatePortsInView(),this.updateConnectionsInView(),this.updateFieldsInView(),this.updateObjectsInView(),this.updateDecoratorsInView()}updateNodesInView(...e){let t=this.selectCanvasElements().selectAll(`g.diagram-node`).data(this.model.nodes.filter(e=>this.priorityThreshold===void 0?!0:e.getPriority()>=this.priorityThreshold),e=>e.id),n=t.exit(),r=t.enter().append(`g`).attr(`id`,e=>e.id).attr(`class`,e=>`diagram-node${Ut(e)?` resizable-x`:``}${Wt(e)?` resizable-y`:``}${Gt(e)?` resizable-xy`:``} ${e.type.defaultLook.lookType}`);e&&e.length>0&&(t=t.filter(t=>e.includes(t.id)));let i=r.merge(t);n.remove(),r.on(x.MouseOver,(e,t)=>{this.dragging||(this.userHighlight.focusOn(t),this.diagramEvent$.next(new Y(t)))}).on(x.Click,(e,t)=>{if(!e.ctrlKey&&!e.shiftKey){let e=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new J(e,!1))}this.userSelection.toggle(t),this.diagramEvent$.next(new J([t],t.selected))}).on(x.ContextMenu,(e,t)=>{if(this.dragging){e.preventDefault(),e.stopPropagation(),this.dragging=!1;return}let n=new Lt(e,t);this.diagramEvent$.next(n),!n.defaultPrevented&&this.canUserPerformAction(K.ContextMenu)&&(e.preventDefault(),this.userHighlight.focusOn(t),this.diagramEvent$.next(new Y(t)),this.userSelection.add(t),this.diagramEvent$.next(new J([t],!0)),this.contextMenu.open(e))}).on(x.DoubleClick,(e,t)=>{let n=new It(e,t);this.diagramEvent$.next(n)}).call(c.drag().filter(e=>(this.secondaryButton=Bt(e),!0)).on(C.Start,(e,t)=>{this.multipleSelectionOn||this.secondaryButton?this.startMultipleSelection(e):this.startMovingNode(e,t)}).on(C.Drag,(e,t)=>{this.multipleSelectionOn||this.secondaryButton?this.continueMultipleSelection(e):this.continueMovingNode(e,t)}).on(C.End,(e,t)=>{this.multipleSelectionOn||this.secondaryButton?this.finishMultipleSelection(e):this.finishMovingNode(e,t),this.secondaryButton=!1})),Kt(r),r.filter(`.resizable-x`).append(`rect`).attr(`class`,`left-resizer`).on(x.MouseOver,(e,t)=>{this.canUserPerformAction(K.StretchNode)&&t.getResizableX()&&!t.removed&&X(D.EWResize)}).on(x.MouseOut,(e,t)=>{this.canUserPerformAction(K.StretchNode)&&t.getResizableX()&&!t.removed&&X()}).call(c.drag().on(C.Start,(e,t)=>{this.canUserPerformAction(K.StretchNode)&&t.getResizableX()&&!t.removed?(X(D.EWResize),this.currentAction=new q(this,K.StretchNode,t.id,t.getGeometry(),t.getGeometry())):X(D.NotAllowed)}).on(C.Drag,(e,t)=>{if(this.canUserPerformAction(K.StretchNode)&&t.getResizableX()&&!t.removed){let n=this.getPointerLocationRelativeToCanvas(e);t.stretch(f.Left,t.coords[0]-n[0])}}).on(C.End,(e,t)=>{if(this.canUserPerformAction(K.StretchNode)&&t.getResizableX()&&!t.removed&&this.currentAction instanceof q&&this.currentAction.intent===K.StretchNode){let n=this.getPointerLocationRelativeToCanvas(e);this.gridConfig.snap&&(n=this.getClosestGridPoint([n[0]-t.type.snapToGridOffset[0],n[1]-t.type.snapToGridOffset[1]]),n[0]+=t.type.snapToGridOffset[0],n[1]+=t.type.snapToGridOffset[1]),t.stretch(f.Left,t.coords[0]-n[0]),this.currentAction.to=t.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}X()})),r.filter(`.resizable-x`).append(`rect`).attr(`class`,`right-resizer`).on(x.MouseOver,(e,t)=>{this.canUserPerformAction(K.StretchNode)&&t.getResizableX()&&!t.removed&&X(D.EWResize)}).on(x.MouseOut,(e,t)=>{this.canUserPerformAction(K.StretchNode)&&t.getResizableX()&&!t.removed&&X()}).call(c.drag().on(C.Start,(e,t)=>{this.canUserPerformAction(K.StretchNode)&&t.getResizableX()&&!t.removed?(X(D.EWResize),this.currentAction=new q(this,K.StretchNode,t.id,t.getGeometry(),t.getGeometry())):X(D.NotAllowed)}).on(C.Drag,(e,t)=>{if(this.canUserPerformAction(K.StretchNode)&&t.getResizableX()&&!t.removed){let n=this.getPointerLocationRelativeToCanvas(e);t.stretch(f.Right,n[0]-(t.coords[0]+t.width))}}).on(C.End,(e,t)=>{if(this.canUserPerformAction(K.StretchNode)&&t.getResizableX()&&!t.removed&&this.currentAction instanceof q&&this.currentAction.intent===K.StretchNode){let n=this.getPointerLocationRelativeToCanvas(e);this.gridConfig.snap&&(n=this.getClosestGridPoint([n[0]-t.type.snapToGridOffset[2],n[1]-t.type.snapToGridOffset[3]]),n[0]+=t.type.snapToGridOffset[2],n[1]+=t.type.snapToGridOffset[3]),t.stretch(f.Right,n[0]-(t.coords[0]+t.width)),this.currentAction.to=t.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}X()})),r.filter(`.resizable-y`).append(`rect`).attr(`class`,`top-resizer`).on(x.MouseOver,(e,t)=>{this.canUserPerformAction(K.StretchNode)&&t.getResizableY()&&!t.removed&&X(D.NSResize)}).on(x.MouseOut,(e,t)=>{this.canUserPerformAction(K.StretchNode)&&t.getResizableY()&&!t.removed&&X()}).call(c.drag().on(C.Start,(e,t)=>{this.canUserPerformAction(K.StretchNode)&&t.getResizableY()&&!t.removed?(X(D.NSResize),this.currentAction=new q(this,K.StretchNode,t.id,t.getGeometry(),t.getGeometry())):X(D.NotAllowed)}).on(C.Drag,(e,t)=>{if(this.canUserPerformAction(K.StretchNode)&&t.getResizableY()&&!t.removed){let n=this.getPointerLocationRelativeToCanvas(e);t.stretch(f.Top,t.coords[1]-n[1])}}).on(C.End,(e,t)=>{if(this.canUserPerformAction(K.StretchNode)&&t.getResizableY()&&!t.removed&&this.currentAction instanceof q&&this.currentAction.intent===K.StretchNode){let n=this.getPointerLocationRelativeToCanvas(e);this.gridConfig.snap&&(n=this.getClosestGridPoint([n[0]-t.type.snapToGridOffset[0],n[1]-t.type.snapToGridOffset[1]]),n[0]+=t.type.snapToGridOffset[0],n[1]+=t.type.snapToGridOffset[1]),t.stretch(f.Top,t.coords[1]-n[1]),this.currentAction.to=t.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}X()})),r.filter(`.resizable-y`).append(`rect`).attr(`class`,`bottom-resizer`).on(x.MouseOver,(e,t)=>{this.canUserPerformAction(K.StretchNode)&&t.getResizableY()&&!t.removed&&X(D.NSResize)}).on(x.MouseOut,(e,t)=>{this.canUserPerformAction(K.StretchNode)&&t.getResizableY()&&!t.removed&&X()}).call(c.drag().on(C.Start,(e,t)=>{this.canUserPerformAction(K.StretchNode)&&t.getResizableY()&&!t.removed?(X(D.NSResize),this.currentAction=new q(this,K.StretchNode,t.id,t.getGeometry(),t.getGeometry())):X(D.NotAllowed)}).on(C.Drag,(e,t)=>{if(this.canUserPerformAction(K.StretchNode)&&t.getResizableY()&&!t.removed){let n=this.getPointerLocationRelativeToCanvas(e);t.stretch(f.Bottom,n[1]-(t.coords[1]+t.height))}}).on(C.End,(e,t)=>{if(this.canUserPerformAction(K.StretchNode)&&t.getResizableY()&&!t.removed&&this.currentAction instanceof q&&this.currentAction.intent===K.StretchNode){let n=this.getPointerLocationRelativeToCanvas(e);this.gridConfig.snap&&(n=this.getClosestGridPoint([n[0]-t.type.snapToGridOffset[2],n[1]-t.type.snapToGridOffset[3]]),n[0]+=t.type.snapToGridOffset[2],n[1]+=t.type.snapToGridOffset[3]),t.stretch(f.Bottom,n[1]-(t.coords[1]+t.height)),this.currentAction.to=t.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}X()})),r.filter(`.resizable-xy`).append(`rect`).attr(`class`,`top-left-resizer`).on(x.MouseOver,(e,t)=>{this.canUserPerformAction(K.StretchNode)&&t.getResizableXY()&&!t.removed&&X(D.NWSEResize)}).on(x.MouseOut,(e,t)=>{this.canUserPerformAction(K.StretchNode)&&t.getResizableXY()&&!t.removed&&X()}).call(c.drag().on(C.Start,(e,t)=>{this.canUserPerformAction(K.StretchNode)&&t.getResizableXY()&&!t.removed?(X(D.NWSEResize),this.currentAction=new q(this,K.StretchNode,t.id,t.getGeometry(),t.getGeometry())):X(D.NotAllowed)}).on(C.Drag,(e,t)=>{if(this.canUserPerformAction(K.StretchNode)&&t.getResizableXY()&&!t.removed){let n=this.getPointerLocationRelativeToCanvas(e);t.stretch(f.Left,t.coords[0]-n[0]),t.stretch(f.Top,t.coords[1]-n[1])}}).on(C.End,(e,t)=>{if(this.canUserPerformAction(K.StretchNode)&&t.getResizableXY()&&!t.removed&&this.currentAction instanceof q&&this.currentAction.intent===K.StretchNode){let n=this.getPointerLocationRelativeToCanvas(e);this.gridConfig.snap&&(n=this.getClosestGridPoint([n[0]-t.type.snapToGridOffset[0],n[1]-t.type.snapToGridOffset[1]]),n[0]+=t.type.snapToGridOffset[0],n[1]+=t.type.snapToGridOffset[1]),t.stretch(f.Left,t.coords[0]-n[0]),t.stretch(f.Top,t.coords[1]-n[1]),this.currentAction.to=t.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}X()})),r.filter(`.resizable-xy`).append(`rect`).attr(`class`,`top-right-resizer`).on(x.MouseOver,(e,t)=>{this.canUserPerformAction(K.StretchNode)&&t.getResizableXY()&&!t.removed&&X(D.NESWResize)}).on(x.MouseOut,(e,t)=>{this.canUserPerformAction(K.StretchNode)&&t.getResizableXY()&&!t.removed&&X()}).call(c.drag().on(C.Start,(e,t)=>{this.canUserPerformAction(K.StretchNode)&&t.getResizableXY()&&!t.removed?(X(D.NESWResize),this.currentAction=new q(this,K.StretchNode,t.id,t.getGeometry(),t.getGeometry())):X(D.NotAllowed)}).on(C.Drag,(e,t)=>{if(this.canUserPerformAction(K.StretchNode)&&t.getResizableXY()&&!t.removed){let n=this.getPointerLocationRelativeToCanvas(e);t.stretch(f.Right,n[0]-(t.coords[0]+t.width)),t.stretch(f.Top,t.coords[1]-n[1])}}).on(C.End,(e,t)=>{if(this.canUserPerformAction(K.StretchNode)&&t.getResizableXY()&&!t.removed&&this.currentAction instanceof q&&this.currentAction.intent===K.StretchNode){let n=this.getPointerLocationRelativeToCanvas(e);this.gridConfig.snap&&(n=this.getClosestGridPoint([n[0]-t.type.snapToGridOffset[0],n[1]-t.type.snapToGridOffset[1]]),n[0]+=t.type.snapToGridOffset[0],n[1]+=t.type.snapToGridOffset[1]),t.stretch(f.Right,n[0]-(t.coords[0]+t.width)),t.stretch(f.Top,t.coords[1]-n[1]),this.currentAction.to=t.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}X()})),r.filter(`.resizable-xy`).append(`rect`).attr(`class`,`bottom-left-resizer`).on(x.MouseOver,(e,t)=>{this.canUserPerformAction(K.StretchNode)&&t.getResizableXY()&&!t.removed&&X(D.NESWResize)}).on(x.MouseOut,(e,t)=>{this.canUserPerformAction(K.StretchNode)&&t.getResizableXY()&&!t.removed&&X()}).call(c.drag().on(C.Start,(e,t)=>{this.canUserPerformAction(K.StretchNode)&&t.getResizableXY()&&!t.removed?(X(D.NESWResize),this.currentAction=new q(this,K.StretchNode,t.id,t.getGeometry(),t.getGeometry())):X(D.NotAllowed)}).on(C.Drag,(e,t)=>{if(this.canUserPerformAction(K.StretchNode)&&t.getResizableXY()&&!t.removed){let n=this.getPointerLocationRelativeToCanvas(e);t.stretch(f.Left,t.coords[0]-n[0]),t.stretch(f.Bottom,n[1]-(t.coords[1]+t.height))}}).on(C.End,(e,t)=>{if(this.canUserPerformAction(K.StretchNode)&&t.getResizableXY()&&!t.removed&&this.currentAction instanceof q&&this.currentAction.intent===K.StretchNode){let n=this.getPointerLocationRelativeToCanvas(e);this.gridConfig.snap&&(n=this.getClosestGridPoint([n[0]-t.type.snapToGridOffset[0],n[1]-t.type.snapToGridOffset[1]]),n[0]+=t.type.snapToGridOffset[0],n[1]+=t.type.snapToGridOffset[1]),t.stretch(f.Left,t.coords[0]-n[0]),t.stretch(f.Bottom,n[1]-(t.coords[1]+t.height)),this.currentAction.to=t.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}X()})),r.filter(`.resizable-xy`).append(`rect`).attr(`class`,`bottom-right-resizer`).on(x.MouseOver,(e,t)=>{this.canUserPerformAction(K.StretchNode)&&t.getResizableXY()&&!t.removed&&X(D.NWSEResize)}).on(x.MouseOut,(e,t)=>{this.canUserPerformAction(K.StretchNode)&&t.getResizableXY()&&!t.removed&&X()}).call(c.drag().on(C.Start,(e,t)=>{this.canUserPerformAction(K.StretchNode)&&t.getResizableXY()&&!t.removed?(X(D.NWSEResize),this.currentAction=new q(this,K.StretchNode,t.id,t.getGeometry(),t.getGeometry())):X(D.NotAllowed)}).on(C.Drag,(e,t)=>{if(this.canUserPerformAction(K.StretchNode)&&t.getResizableXY()&&!t.removed){let n=this.getPointerLocationRelativeToCanvas(e);t.stretch(f.Right,n[0]-(t.coords[0]+t.width)),t.stretch(f.Bottom,n[1]-(t.coords[1]+t.height))}}).on(C.End,(e,t)=>{if(this.canUserPerformAction(K.StretchNode)&&t.getResizableXY()&&!t.removed&&this.currentAction instanceof q&&this.currentAction.intent===K.StretchNode){let n=this.getPointerLocationRelativeToCanvas(e);this.gridConfig.snap&&(n=this.getClosestGridPoint([n[0]-t.type.snapToGridOffset[0],n[1]-t.type.snapToGridOffset[1]]),n[0]+=t.type.snapToGridOffset[0],n[1]+=t.type.snapToGridOffset[1]),t.stretch(f.Right,n[0]-(t.coords[0]+t.width)),t.stretch(f.Bottom,n[1]-(t.coords[1]+t.height)),this.currentAction.to=t.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}X()})),i.attr(`transform`,e=>`translate(${e.coords[0]},${e.coords[1]})`).attr(`opacity`,e=>e.removed?.5:1),Jt(i),i.filter(`.resizable-x`).select(`rect.left-resizer`).style(`pointer-events`,e=>e.getResizableX()?`initial`:`none`).attr(`x`,e=>-e.getResizerX().outerMargin).attr(`y`,e=>e.getResizerXY().thickness-e.getResizerXY().outerMargin).attr(`width`,e=>e.getResizerX().thickness).attr(`height`,e=>e.height-e.getResizerXY().thickness*2+e.getResizerXY().outerMargin*2).attr(`fill`,e=>e.getResizerX().getLook(e).fillColor||`transparent`).attr(`stroke`,e=>e.getResizerX().getLook(e).borderColor||`transparent`).attr(`stroke-width`,e=>e.getResizerX().getLook(e).borderThickness||0),i.filter(`.resizable-x`).select(`rect.right-resizer`).style(`pointer-events`,e=>e.getResizableX()?`initial`:`none`).attr(`x`,e=>e.width-e.getResizerX().thickness+e.getResizerX().outerMargin).attr(`y`,e=>e.getResizerXY().thickness-e.getResizerXY().outerMargin).attr(`width`,e=>e.getResizerX().thickness).attr(`height`,e=>e.height-e.getResizerXY().thickness*2+e.getResizerXY().outerMargin*2).attr(`fill`,e=>e.getResizerX().getLook(e).fillColor||`transparent`).attr(`stroke`,e=>e.getResizerX().getLook(e).borderColor||`transparent`).attr(`stroke-width`,e=>e.getResizerX().getLook(e).borderThickness||0),i.filter(`.resizable-y`).select(`rect.top-resizer`).style(`pointer-events`,e=>e.getResizableY()?`initial`:`none`).attr(`x`,e=>e.getResizerXY().thickness-e.getResizerXY().outerMargin).attr(`y`,e=>-e.getResizerY().outerMargin).attr(`width`,e=>e.width-e.getResizerXY().thickness*2+e.getResizerXY().outerMargin*2).attr(`height`,e=>e.getResizerY().thickness).attr(`fill`,e=>e.getResizerY().getLook(e).fillColor||`transparent`).attr(`stroke`,e=>e.getResizerY().getLook(e).borderColor||`transparent`).attr(`stroke-width`,e=>e.getResizerY().getLook(e).borderThickness||0),i.filter(`.resizable-y`).select(`rect.bottom-resizer`).style(`pointer-events`,e=>e.getResizableY()?`initial`:`none`).attr(`x`,e=>e.getResizerXY().thickness-e.getResizerXY().outerMargin).attr(`y`,e=>e.height-e.getResizerY().thickness+e.getResizerY().outerMargin).attr(`width`,e=>e.width-e.getResizerXY().thickness*2+e.getResizerXY().outerMargin*2).attr(`height`,e=>e.getResizerY().thickness).attr(`fill`,e=>e.getResizerY().getLook(e).fillColor||`transparent`).attr(`stroke`,e=>e.getResizerY().getLook(e).borderColor||`transparent`).attr(`stroke-width`,e=>e.getResizerY().getLook(e).borderThickness||0),i.filter(`.resizable-xy`).select(`rect.top-left-resizer`).style(`pointer-events`,e=>e.getResizableXY()?`initial`:`none`).attr(`x`,e=>-e.getResizerXY().outerMargin).attr(`y`,e=>-e.getResizerXY().outerMargin).attr(`width`,e=>e.getResizerXY().thickness).attr(`height`,e=>e.getResizerXY().thickness).attr(`fill`,e=>e.getResizerXY().getLook(e).fillColor||`transparent`).attr(`stroke`,e=>e.getResizerXY().getLook(e).borderColor||`transparent`).attr(`stroke-width`,e=>e.getResizerXY().getLook(e).borderThickness||0),i.filter(`.resizable-xy`).select(`rect.top-right-resizer`).style(`pointer-events`,e=>e.getResizableXY()?`initial`:`none`).attr(`x`,e=>e.width-e.getResizerXY().thickness+e.getResizerXY().outerMargin).attr(`y`,e=>-e.getResizerXY().outerMargin).attr(`width`,e=>e.getResizerXY().thickness).attr(`height`,e=>e.getResizerXY().thickness).attr(`fill`,e=>e.getResizerXY().getLook(e).fillColor||`transparent`).attr(`stroke`,e=>e.getResizerXY().getLook(e).borderColor||`transparent`).attr(`stroke-width`,e=>e.getResizerXY().getLook(e).borderThickness||0),i.filter(`.resizable-xy`).select(`rect.bottom-left-resizer`).style(`pointer-events`,e=>e.getResizableXY()?`initial`:`none`).attr(`x`,e=>-e.getResizerXY().outerMargin).attr(`y`,e=>e.height-e.getResizerXY().thickness+e.getResizerXY().outerMargin).attr(`width`,e=>e.getResizerXY().thickness).attr(`height`,e=>e.getResizerXY().thickness).attr(`fill`,e=>e.getResizerXY().getLook(e).fillColor||`transparent`).attr(`stroke`,e=>e.getResizerXY().getLook(e).borderColor||`transparent`).attr(`stroke-width`,e=>e.getResizerXY().getLook(e).borderThickness||0),i.filter(`.resizable-xy`).select(`rect.bottom-right-resizer`).style(`pointer-events`,e=>e.getResizableXY()?`initial`:`none`).attr(`x`,e=>e.width-e.getResizerXY().thickness+e.getResizerXY().outerMargin).attr(`y`,e=>e.height-e.getResizerXY().thickness+e.getResizerXY().outerMargin).attr(`width`,e=>e.getResizerXY().thickness).attr(`height`,e=>e.getResizerXY().thickness).attr(`fill`,e=>e.getResizerXY().getLook(e).fillColor||`transparent`).attr(`stroke`,e=>e.getResizerXY().getLook(e).borderColor||`transparent`).attr(`stroke-width`,e=>e.getResizerXY().getLook(e).borderThickness||0)}updateSectionsInView(...e){let t=this.selectCanvasElements().selectAll(`g.diagram-section`).data(this.model.sections.filter(e=>this.priorityThreshold===void 0?!0:e.getPriority()>=this.priorityThreshold),e=>e.id),n=t.exit(),r=t.enter().append(`g`).attr(`id`,e=>e.id).attr(`class`,e=>`diagram-section${Ut(e)?` resizable-x`:``}${Wt(e)?` resizable-y`:``}${Gt(e)?` resizable-xy`:``} ${e.look?.lookType}`);e&&e.length>0&&(t=t.filter(t=>e.includes(t.id)));let i=r.merge(t);n.remove(),r.on(x.MouseOver,(e,t)=>{this.dragging||(this.userHighlight.focusOn(t),this.diagramEvent$.next(new Y(t)))}).on(x.Click,(e,t)=>{if(!e.ctrlKey&&!e.shiftKey){let e=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new J(e,!1))}let n=Ht(t);this.userSelection.toggle(n),this.diagramEvent$.next(new J([n],n.selected))}).on(x.ContextMenu,(e,t)=>{if(this.dragging){e.preventDefault(),e.stopPropagation(),this.dragging=!1;return}let n=new Lt(e,t);if(this.diagramEvent$.next(n),!n.defaultPrevented&&this.canUserPerformAction(K.ContextMenu)){e.preventDefault();let n=Ht(t);this.userHighlight.focusOn(n),this.diagramEvent$.next(new Y(n)),this.userSelection.add(n),this.diagramEvent$.next(new J([n],!0)),this.contextMenu.open(e)}}).on(x.DoubleClick,(e,t)=>{let n=new It(e,t);this.diagramEvent$.next(n)}).call(c.drag().filter(e=>(this.secondaryButton=Bt(e),!0)).on(C.Start,(e,t)=>{if(this.multipleSelectionOn||this.secondaryButton)this.startMultipleSelection(e);else{let n=t?.node;n?this.startMovingNode(e,n):X(D.NotAllowed)}}).on(C.Drag,(e,t)=>{if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(e);else{let n=t?.node;n?this.continueMovingNode(e,n):X(D.NotAllowed)}}).on(C.End,(e,t)=>{if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(e);else{let n=t?.node;n?this.finishMovingNode(e,n):X()}this.secondaryButton=!1})),Kt(r),r.filter(`.resizable-x`).append(`rect`).attr(`class`,`left-resizer`).on(x.MouseOver,(e,t)=>{this.canUserPerformAction(K.StretchSection)&&t.getResizableX()&&!t.removed&&X(D.EWResize)}).on(x.MouseOut,(e,t)=>{this.canUserPerformAction(K.StretchSection)&&t.getResizableX()&&!t.removed&&X()}).call(c.drag().on(C.Start,(e,t)=>{this.canUserPerformAction(K.StretchSection)&&t.getResizableX()&&!t.removed&&t.node?(X(D.EWResize),this.currentAction=new q(this,K.StretchSection,t.node.id,t.node.getGeometry(),t.node.getGeometry())):X(D.NotAllowed)}).on(C.Drag,(e,t)=>{if(this.canUserPerformAction(K.StretchSection)&&t.getResizableX()&&!t.removed&&t.node){let n=this.getPointerLocationRelativeToCanvas(e);t.node.stretchSections(f.Left,t.coords[0]-n[0],t.indexXInNode,t.indexYInNode)}}).on(C.End,(e,t)=>{if(this.canUserPerformAction(K.StretchSection)&&t.getResizableX()&&!t.removed&&this.currentAction instanceof q&&this.currentAction.intent===K.StretchSection&&t.node){let n=this.getPointerLocationRelativeToCanvas(e);this.gridConfig.snap&&(n=this.getClosestGridPoint(n)),t.node.stretchSections(f.Left,t.coords[0]-n[0],t.indexXInNode,t.indexYInNode),this.currentAction.to=t.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}X()})),r.filter(`.resizable-x`).append(`rect`).attr(`class`,`right-resizer`).on(x.MouseOver,(e,t)=>{this.canUserPerformAction(K.StretchSection)&&t.getResizableX()&&!t.removed&&X(D.EWResize)}).on(x.MouseOut,(e,t)=>{this.canUserPerformAction(K.StretchSection)&&t.getResizableX()&&!t.removed&&X()}).call(c.drag().on(C.Start,(e,t)=>{this.canUserPerformAction(K.StretchSection)&&t.getResizableX()&&!t.removed&&t.node?(X(D.EWResize),this.currentAction=new q(this,K.StretchSection,t.node.id,t.node.getGeometry(),t.node.getGeometry())):X(D.NotAllowed)}).on(C.Drag,(e,t)=>{if(this.canUserPerformAction(K.StretchSection)&&t.getResizableX()&&!t.removed&&t.node){let n=this.getPointerLocationRelativeToCanvas(e);t.node.stretchSections(f.Right,n[0]-(t.coords[0]+t.width),t.indexXInNode,t.indexYInNode)}}).on(C.End,(e,t)=>{if(this.canUserPerformAction(K.StretchSection)&&t.getResizableX()&&!t.removed&&this.currentAction instanceof q&&this.currentAction.intent===K.StretchSection&&t.node){let n=this.getPointerLocationRelativeToCanvas(e);this.gridConfig.snap&&(n=this.getClosestGridPoint(n)),t.node.stretchSections(f.Right,n[0]-(t.coords[0]+t.width),t.indexXInNode,t.indexYInNode),this.currentAction.to=t.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}X()})),r.filter(`.resizable-y`).append(`rect`).attr(`class`,`top-resizer`).on(x.MouseOver,(e,t)=>{this.canUserPerformAction(K.StretchSection)&&t.getResizableY()&&!t.removed&&X(D.NSResize)}).on(x.MouseOut,(e,t)=>{this.canUserPerformAction(K.StretchSection)&&t.getResizableY()&&!t.removed&&X()}).call(c.drag().on(C.Start,(e,t)=>{this.canUserPerformAction(K.StretchSection)&&t.getResizableY()&&!t.removed&&t.node?(X(D.NSResize),this.currentAction=new q(this,K.StretchSection,t.node.id,t.node.getGeometry(),t.node.getGeometry())):X(D.NotAllowed)}).on(C.Drag,(e,t)=>{if(this.canUserPerformAction(K.StretchSection)&&t.getResizableY()&&!t.removed&&t.node){let n=this.getPointerLocationRelativeToCanvas(e);t.node.stretchSections(f.Top,t.coords[1]-n[1],t.indexXInNode,t.indexYInNode)}}).on(C.End,(e,t)=>{if(this.canUserPerformAction(K.StretchSection)&&t.getResizableY()&&!t.removed&&this.currentAction instanceof q&&this.currentAction.intent===K.StretchSection&&t.node){let n=this.getPointerLocationRelativeToCanvas(e);this.gridConfig.snap&&(n=this.getClosestGridPoint(n)),t.node.stretchSections(f.Top,t.coords[1]-n[1],t.indexXInNode,t.indexYInNode),this.currentAction.to=t.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}X()})),r.filter(`.resizable-y`).append(`rect`).attr(`class`,`bottom-resizer`).on(x.MouseOver,(e,t)=>{this.canUserPerformAction(K.StretchSection)&&t.getResizableY()&&!t.removed&&X(D.NSResize)}).on(x.MouseOut,(e,t)=>{this.canUserPerformAction(K.StretchSection)&&t.getResizableY()&&!t.removed&&X()}).call(c.drag().on(C.Start,(e,t)=>{this.canUserPerformAction(K.StretchSection)&&t.getResizableY()&&!t.removed&&t.node?(X(D.NSResize),this.currentAction=new q(this,K.StretchSection,t.node.id,t.node.getGeometry(),t.node.getGeometry())):X(D.NotAllowed)}).on(C.Drag,(e,t)=>{if(this.canUserPerformAction(K.StretchSection)&&t.getResizableY()&&!t.removed&&t.node){let n=this.getPointerLocationRelativeToCanvas(e);t.node.stretchSections(f.Bottom,n[1]-(t.coords[1]+t.height),t.indexXInNode,t.indexYInNode)}}).on(C.End,(e,t)=>{if(this.canUserPerformAction(K.StretchSection)&&t.getResizableY()&&!t.removed&&this.currentAction instanceof q&&this.currentAction.intent===K.StretchSection&&t.node){let n=this.getPointerLocationRelativeToCanvas(e);this.gridConfig.snap&&(n=this.getClosestGridPoint(n)),t.node.stretchSections(f.Bottom,n[1]-(t.coords[1]+t.height),t.indexXInNode,t.indexYInNode),this.currentAction.to=t.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}X()})),r.filter(`.resizable-xy`).append(`rect`).attr(`class`,`top-left-resizer`).on(x.MouseOver,(e,t)=>{this.canUserPerformAction(K.StretchSection)&&t.getResizableXY()&&!t.removed&&X(D.NWSEResize)}).on(x.MouseOut,(e,t)=>{this.canUserPerformAction(K.StretchSection)&&t.getResizableXY()&&!t.removed&&X()}).call(c.drag().on(C.Start,(e,t)=>{this.canUserPerformAction(K.StretchSection)&&t.getResizableXY()&&!t.removed&&t.node?(X(D.NWSEResize),this.currentAction=new q(this,K.StretchSection,t.node.id,t.node.getGeometry(),t.node.getGeometry())):X(D.NotAllowed)}).on(C.Drag,(e,t)=>{if(this.canUserPerformAction(K.StretchSection)&&t.getResizableXY()&&!t.removed&&t.node){let n=this.getPointerLocationRelativeToCanvas(e);t.node.stretchSections(f.Left,t.coords[0]-n[0],t.indexXInNode,t.indexYInNode),t.node.stretchSections(f.Top,t.coords[1]-n[1],t.indexXInNode,t.indexYInNode)}}).on(C.End,(e,t)=>{if(this.canUserPerformAction(K.StretchSection)&&t.getResizableXY()&&!t.removed&&this.currentAction instanceof q&&this.currentAction.intent===K.StretchSection&&t.node){let n=this.getPointerLocationRelativeToCanvas(e);this.gridConfig.snap&&(n=this.getClosestGridPoint(n)),t.node.stretchSections(f.Left,t.coords[0]-n[0],t.indexXInNode,t.indexYInNode),t.node.stretchSections(f.Top,t.coords[1]-n[1],t.indexXInNode,t.indexYInNode),this.currentAction.to=t.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}X()})),r.filter(`.resizable-xy`).append(`rect`).attr(`class`,`top-right-resizer`).on(x.MouseOver,(e,t)=>{this.canUserPerformAction(K.StretchSection)&&t.getResizableXY()&&!t.removed&&X(D.NESWResize)}).on(x.MouseOut,(e,t)=>{this.canUserPerformAction(K.StretchSection)&&t.getResizableXY()&&!t.removed&&X()}).call(c.drag().on(C.Start,(e,t)=>{this.canUserPerformAction(K.StretchSection)&&t.getResizableXY()&&!t.removed&&t.node?(X(D.NESWResize),this.currentAction=new q(this,K.StretchSection,t.node.id,t.node.getGeometry(),t.node.getGeometry())):X(D.NotAllowed)}).on(C.Drag,(e,t)=>{if(this.canUserPerformAction(K.StretchSection)&&t.getResizableXY()&&!t.removed&&t.node){let n=this.getPointerLocationRelativeToCanvas(e);t.node.stretchSections(f.Right,n[0]-(t.coords[0]+t.width),t.indexXInNode,t.indexYInNode),t.node.stretchSections(f.Top,t.coords[1]-n[1],t.indexXInNode,t.indexYInNode)}}).on(C.End,(e,t)=>{if(this.canUserPerformAction(K.StretchSection)&&t.getResizableXY()&&!t.removed&&this.currentAction instanceof q&&this.currentAction.intent===K.StretchSection&&t.node){let n=this.getPointerLocationRelativeToCanvas(e);this.gridConfig.snap&&(n=this.getClosestGridPoint(n)),t.node.stretchSections(f.Right,n[0]-(t.coords[0]+t.width),t.indexXInNode,t.indexYInNode),t.node.stretchSections(f.Top,t.coords[1]-n[1],t.indexXInNode,t.indexYInNode),this.currentAction.to=t.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}X()})),r.filter(`.resizable-xy`).append(`rect`).attr(`class`,`bottom-left-resizer`).on(x.MouseOver,(e,t)=>{this.canUserPerformAction(K.StretchSection)&&t.getResizableXY()&&!t.removed&&X(D.NESWResize)}).on(x.MouseOut,(e,t)=>{this.canUserPerformAction(K.StretchSection)&&t.getResizableXY()&&!t.removed&&X()}).call(c.drag().on(C.Start,(e,t)=>{this.canUserPerformAction(K.StretchSection)&&t.getResizableXY()&&!t.removed&&t.node?(X(D.NESWResize),this.currentAction=new q(this,K.StretchSection,t.node.id,t.node.getGeometry(),t.node.getGeometry())):X(D.NotAllowed)}).on(C.Drag,(e,t)=>{if(this.canUserPerformAction(K.StretchSection)&&t.getResizableXY()&&!t.removed&&t.node){let n=this.getPointerLocationRelativeToCanvas(e);t.node.stretchSections(f.Left,t.coords[0]-n[0],t.indexXInNode,t.indexYInNode),t.node.stretchSections(f.Bottom,n[1]-(t.coords[1]+t.height),t.indexXInNode,t.indexYInNode)}}).on(C.End,(e,t)=>{if(this.canUserPerformAction(K.StretchSection)&&t.getResizableXY()&&!t.removed&&this.currentAction instanceof q&&this.currentAction.intent===K.StretchSection&&t.node){let n=this.getPointerLocationRelativeToCanvas(e);this.gridConfig.snap&&(n=this.getClosestGridPoint(n)),t.node.stretchSections(f.Left,t.coords[0]-n[0],t.indexXInNode,t.indexYInNode),t.node.stretchSections(f.Bottom,n[1]-(t.coords[1]+t.height),t.indexXInNode,t.indexYInNode),this.currentAction.to=t.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}X()})),r.filter(`.resizable-xy`).append(`rect`).attr(`class`,`bottom-right-resizer`).on(x.MouseOver,(e,t)=>{this.canUserPerformAction(K.StretchSection)&&t.getResizableXY()&&!t.removed&&X(D.NWSEResize)}).on(x.MouseOut,(e,t)=>{this.canUserPerformAction(K.StretchSection)&&t.getResizableXY()&&!t.removed&&X()}).call(c.drag().on(C.Start,(e,t)=>{this.canUserPerformAction(K.StretchSection)&&t.getResizableXY()&&!t.removed&&t.node?(X(D.NWSEResize),this.currentAction=new q(this,K.StretchSection,t.node.id,t.node.getGeometry(),t.node.getGeometry())):X(D.NotAllowed)}).on(C.Drag,(e,t)=>{if(this.canUserPerformAction(K.StretchSection)&&t.getResizableXY()&&!t.removed&&t.node){let n=this.getPointerLocationRelativeToCanvas(e);t.node.stretchSections(f.Right,n[0]-(t.coords[0]+t.width),t.indexXInNode,t.indexYInNode),t.node.stretchSections(f.Bottom,n[1]-(t.coords[1]+t.height),t.indexXInNode,t.indexYInNode)}}).on(C.End,(e,t)=>{if(this.canUserPerformAction(K.StretchSection)&&t.getResizableXY()&&!t.removed&&this.currentAction instanceof q&&this.currentAction.intent===K.StretchSection&&t.node){let n=this.getPointerLocationRelativeToCanvas(e);this.gridConfig.snap&&(n=this.getClosestGridPoint(n)),t.node.stretchSections(f.Right,n[0]-(t.coords[0]+t.width),t.indexXInNode,t.indexYInNode),t.node.stretchSections(f.Bottom,n[1]-(t.coords[1]+t.height),t.indexXInNode,t.indexYInNode),this.currentAction.to=t.node.getGeometry(),this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0}X()})),i.attr(`transform`,e=>`translate(${e.coords[0]},${e.coords[1]})`).attr(`opacity`,e=>e.removed?.5:1),Jt(i),i.filter(`.resizable-x`).select(`rect.left-resizer`).style(`pointer-events`,e=>e.getResizableX()?`initial`:`none`).attr(`x`,e=>-e.getResizerX().outerMargin).attr(`y`,e=>e.getResizerXY().thickness-e.getResizerXY().outerMargin).attr(`width`,e=>e.getResizerX().thickness).attr(`height`,e=>e.height-e.getResizerXY().thickness*2+e.getResizerXY().outerMargin*2).attr(`fill`,e=>e.getResizerX().getLook(e).fillColor||`transparent`).attr(`stroke`,e=>e.getResizerX().getLook(e).borderColor||`transparent`).attr(`stroke-width`,e=>e.getResizerX().getLook(e).borderThickness||0),i.filter(`.resizable-x`).select(`rect.right-resizer`).style(`pointer-events`,e=>e.getResizableX()?`initial`:`none`).attr(`x`,e=>e.width-e.getResizerX().thickness+e.getResizerX().outerMargin).attr(`y`,e=>e.getResizerXY().thickness-e.getResizerXY().outerMargin).attr(`width`,e=>e.getResizerX().thickness).attr(`height`,e=>e.height-e.getResizerXY().thickness*2+e.getResizerXY().outerMargin*2).attr(`fill`,e=>e.getResizerX().getLook(e).fillColor||`transparent`).attr(`stroke`,e=>e.getResizerX().getLook(e).borderColor||`transparent`).attr(`stroke-width`,e=>e.getResizerX().getLook(e).borderThickness||0),i.filter(`.resizable-y`).select(`rect.top-resizer`).style(`pointer-events`,e=>e.getResizableY()?`initial`:`none`).attr(`x`,e=>e.getResizerXY().thickness-e.getResizerXY().outerMargin).attr(`y`,e=>-e.getResizerY().outerMargin).attr(`width`,e=>e.width-e.getResizerXY().thickness*2+e.getResizerXY().outerMargin*2).attr(`height`,e=>e.getResizerY().thickness).attr(`fill`,e=>e.getResizerY().getLook(e).fillColor||`transparent`).attr(`stroke`,e=>e.getResizerY().getLook(e).borderColor||`transparent`).attr(`stroke-width`,e=>e.getResizerY().getLook(e).borderThickness||0),i.filter(`.resizable-y`).select(`rect.bottom-resizer`).style(`pointer-events`,e=>e.getResizableY()?`initial`:`none`).attr(`x`,e=>e.getResizerXY().thickness-e.getResizerXY().outerMargin).attr(`y`,e=>e.height-e.getResizerY().thickness+e.getResizerY().outerMargin).attr(`width`,e=>e.width-e.getResizerXY().thickness*2+e.getResizerXY().outerMargin*2).attr(`height`,e=>e.getResizerY().thickness).attr(`fill`,e=>e.getResizerY().getLook(e).fillColor||`transparent`).attr(`stroke`,e=>e.getResizerY().getLook(e).borderColor||`transparent`).attr(`stroke-width`,e=>e.getResizerY().getLook(e).borderThickness||0),i.filter(`.resizable-xy`).select(`rect.top-left-resizer`).style(`pointer-events`,e=>e.getResizableXY()?`initial`:`none`).attr(`x`,e=>-e.getResizerXY().outerMargin).attr(`y`,e=>-e.getResizerXY().outerMargin).attr(`width`,e=>e.getResizerXY().thickness).attr(`height`,e=>e.getResizerXY().thickness).attr(`fill`,e=>e.getResizerXY().getLook(e).fillColor||`transparent`).attr(`stroke`,e=>e.getResizerXY().getLook(e).borderColor||`transparent`).attr(`stroke-width`,e=>e.getResizerXY().getLook(e).borderThickness||0),i.filter(`.resizable-xy`).select(`rect.top-right-resizer`).style(`pointer-events`,e=>e.getResizableXY()?`initial`:`none`).attr(`x`,e=>e.width-e.getResizerXY().thickness+e.getResizerXY().outerMargin).attr(`y`,e=>-e.getResizerXY().outerMargin).attr(`width`,e=>e.getResizerXY().thickness).attr(`height`,e=>e.getResizerXY().thickness).attr(`fill`,e=>e.getResizerXY().getLook(e).fillColor||`transparent`).attr(`stroke`,e=>e.getResizerXY().getLook(e).borderColor||`transparent`).attr(`stroke-width`,e=>e.getResizerXY().getLook(e).borderThickness||0),i.filter(`.resizable-xy`).select(`rect.bottom-left-resizer`).style(`pointer-events`,e=>e.getResizableXY()?`initial`:`none`).attr(`x`,e=>-e.getResizerXY().outerMargin).attr(`y`,e=>e.height-e.getResizerXY().thickness+e.getResizerXY().outerMargin).attr(`width`,e=>e.getResizerXY().thickness).attr(`height`,e=>e.getResizerXY().thickness).attr(`fill`,e=>e.getResizerXY().getLook(e).fillColor||`transparent`).attr(`stroke`,e=>e.getResizerXY().getLook(e).borderColor||`transparent`).attr(`stroke-width`,e=>e.getResizerXY().getLook(e).borderThickness||0),i.filter(`.resizable-xy`).select(`rect.bottom-right-resizer`).style(`pointer-events`,e=>e.getResizableXY()?`initial`:`none`).attr(`x`,e=>e.width-e.getResizerXY().thickness+e.getResizerXY().outerMargin).attr(`y`,e=>e.height-e.getResizerXY().thickness+e.getResizerXY().outerMargin).attr(`width`,e=>e.getResizerXY().thickness).attr(`height`,e=>e.getResizerXY().thickness).attr(`fill`,e=>e.getResizerXY().getLook(e).fillColor||`transparent`).attr(`stroke`,e=>e.getResizerXY().getLook(e).borderColor||`transparent`).attr(`stroke-width`,e=>e.getResizerXY().getLook(e).borderThickness||0)}updatePortsInView(...e){let t=this.selectCanvasElements().selectAll(`g.diagram-port`).data(this.model.ports.filter(e=>this.priorityThreshold===void 0?!0:e.getPriority()>=this.priorityThreshold),e=>e.id),n=t.exit(),r=t.enter().append(`g`).attr(`id`,e=>e.id).attr(`class`,e=>`diagram-port ${e.look.lookType}`);e&&e.length>0&&(t=t.filter(t=>e.includes(t.id)));let i=r.merge(t);n.remove(),r.on(x.MouseOver,(e,t)=>{!this.unfinishedConnection&&!this.dragging&&(this.userHighlight.focusOn(t),this.diagramEvent$.next(new Y(t))),this.unfinishedConnection&&(this.unfinishedConnection.type.canStartFromType(this.unfinishedConnection.start?.getNode()?.type?.id||``)&&this.unfinishedConnection.start?.allowsOutgoing&&this.unfinishedConnection.type.canFinishOnType(t.getNode()?.type?.id||``)&&t.allowsIncoming||this.unfinishedConnection.type.canStartFromType(t.getNode()?.type?.id||``)&&t.allowsOutgoing&&this.unfinishedConnection.type.canFinishOnType(this.unfinishedConnection.start?.getNode()?.type?.id||``)&&this.unfinishedConnection.start?.allowsIncoming||X(D.NoDrop))}).on(x.MouseOut,()=>{this.unfinishedConnection&&X(D.Grabbing)}).on(x.Click,(e,t)=>{if(!e.ctrlKey&&!e.shiftKey){let e=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new J(e,!1))}let n=Ht(t);this.userSelection.toggle(n),this.diagramEvent$.next(new J([n],n.selected))}).on(x.ContextMenu,(e,t)=>{if(this.dragging){e.preventDefault(),e.stopPropagation(),this.dragging=!1;return}let n=new Lt(e,t);if(this.diagramEvent$.next(n),!n.defaultPrevented&&this.canUserPerformAction(K.ContextMenu)){e.preventDefault();let n=Ht(t);this.userHighlight.focusOn(n),this.diagramEvent$.next(new Y(n)),this.userSelection.add(n),this.diagramEvent$.next(new J([n],!0)),this.contextMenu.open(e)}}).on(x.DoubleClick,(e,t)=>{let n=new It(e,t);this.diagramEvent$.next(n)}).call(c.drag().filter(e=>(this.secondaryButton=Bt(e),!0)).on(C.Start,(e,t)=>{this.multipleSelectionOn||this.secondaryButton?this.startMultipleSelection(e):this.canUserPerformAction(K.AddConnection)&&(this.allowSharingPorts||t.incomingConnections.filter(e=>!e.removed).length===0&&t.outgoingConnections.filter(e=>!e.removed).length===0)&&!t.removed?(X(D.Grabbing),this.startConnection(t),this.unfinishedConnection&&(this.unfinishedConnectionTracer=this.selectCanvasElements().append(`path`).attr(`stroke`,`none`).attr(`fill`,`none`))):X(D.NotAllowed)}).on(C.Drag,(e,t)=>{if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(e);else if(this.canUserPerformAction(K.AddConnection)&&!t.removed&&this.unfinishedConnection!==void 0){let t=[e.x,e.y];this.unfinishedConnectionTracer?.attr(`d`,Vt(this.unfinishedConnection.look.shape||M.look.shape,this.unfinishedConnection.startCoords,t,this.unfinishedConnection.startDirection,this.unfinishedConnection.endDirection,this.unfinishedConnection.points,this.unfinishedConnection.type.defaultLook.thickness||M.look.thickness,this.unfinishedConnection.type.defaultStartMarkerLook?.width,this.unfinishedConnection.type.defaultEndMarkerLook?.width));let n=this.unfinishedConnectionTracer?.node();if(n){let e=2,t=n.getTotalLength();t<e&&(e=0);let r=n.getPointAtLength(t-e);this.unfinishedConnection.endCoords=[r.x,r.y]}else this.unfinishedConnection.endCoords=t;if(this.updateConnectionsInView(fn),this.unfinishedConnectionPort?.raise(!1),this.model.ports.length>0){let t=this.getPointerLocationRelativeToCanvas(e),n=1/0,r;for(let e of this.model.ports){let i=e.distanceTo(t);i<n&&(n=i,r=e)}r&&n<this.portHighlightRadius?this.userHighlight.focusOn(r):this.userHighlight.clear()}}}).on(C.End,(e,t)=>{if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(e);else{if(this.canUserPerformAction(K.AddConnection)&&!t.removed){this.unfinishedConnectionTracer?.remove();let t=this.userHighlight.getFocus();if(t instanceof dt)this.finishConnection(t);else if(t instanceof I&&t.rootElement instanceof dt)this.finishConnection(t.rootElement);else if(t instanceof U||t instanceof H||t instanceof I){let n;if(t instanceof U||t instanceof H)n=t;else if(t.rootElement instanceof U||t.rootElement instanceof H)n=t.rootElement;else{this.dropConnection();return}let r=n.getClosestPortToPoint([e.x,e.y]);r===void 0?this.dropConnection():this.finishConnection(r)}else this.dropConnection()}X()}this.secondaryButton=!1})),r.filter(`.image-look`).append(`image`),Kt(r),i.attr(`transform`,e=>`translate(${e.coords[0]-e.width/2},${e.coords[1]-e.width/2})`).attr(`opacity`,e=>e.removed?.5:1),Jt(i)}updateConnectionsInView(...e){let t=this.model.connections.filter(e=>this.priorityThreshold===void 0?!0:e.getPriority()>=this.priorityThreshold);this.unfinishedConnection&&t.push(this.unfinishedConnection);let n=this.selectCanvasElements().selectAll(`g.diagram-connection`).data(t,e=>e.id),r=n.exit(),i=n.enter().append(`g`).attr(`id`,e=>e.id).attr(`class`,`diagram-connection`);e&&e.length>0&&(n=n.filter(t=>e.includes(t.id)));let a=i.merge(n);r.remove(),i.on(x.MouseOver,(e,t)=>{t.end!==void 0&&!this.dragging&&(this.userHighlight.focusOn(t),this.diagramEvent$.next(new Y(t)))}).on(x.Click,(e,t)=>{if(!e.ctrlKey&&!e.shiftKey){let e=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new J(e,!1))}this.userSelection.toggle(t),this.diagramEvent$.next(new J([t],t.selected))}).on(x.ContextMenu,(e,t)=>{if(this.dragging){e.preventDefault(),e.stopPropagation(),this.dragging=!1;return}let n=new Lt(e,t);this.diagramEvent$.next(n),!n.defaultPrevented&&this.canUserPerformAction(K.ContextMenu)&&(e.preventDefault(),this.userHighlight.focusOn(t),this.diagramEvent$.next(new Y(t)),this.userSelection.add(t),this.diagramEvent$.next(new J([t],!0)),this.contextMenu.open(e))}).on(x.DoubleClick,(e,t)=>{let n=new It(e,t);this.diagramEvent$.next(n)}).call(c.drag().filter(e=>(this.secondaryButton=Bt(e),!0)).on(C.Start,e=>{this.startMultipleSelection(e)}).on(C.Drag,e=>{this.continueMultipleSelection(e)}).on(C.End,e=>{this.finishMultipleSelection(e)})),i.append(`path`).attr(`class`,`diagram-connection-path`),i.append(`path`).attr(`class`,`diagram-connection-path-box`),i.append(`marker`).attr(`id`,e=>`${e.id}-start-marker`).attr(`class`,`diagram-connection-start-marker`).append(`image`).attr(`preserveAspectRatio`,`none`),i.append(`marker`).attr(`id`,e=>`${e.id}-end-marker`).attr(`class`,`diagram-connection-end-marker`).append(`image`).attr(`preserveAspectRatio`,`none`),i.append(`g`).attr(`class`,`diagram-connection-start-label`),i.select(`g.diagram-connection-start-label`).append(`path`),i.select(`g.diagram-connection-start-label`).append(`text`).style(`user-select`,`none`),i.append(`g`).attr(`class`,`diagram-connection-middle-label`),i.select(`g.diagram-connection-middle-label`).append(`path`),i.select(`g.diagram-connection-middle-label`).append(`text`).style(`user-select`,`none`),i.append(`g`).attr(`class`,`diagram-connection-end-label`),i.select(`g.diagram-connection-end-label`).append(`path`),i.select(`g.diagram-connection-end-label`).append(`text`).style(`user-select`,`none`),a.attr(`opacity`,e=>e.removed?.5:1).select(`path.diagram-connection-path`).attr(`d`,e=>Vt(e.look.shape||M.look.shape,e.startCoords,e.endCoords,e.startDirection,e.endDirection,e.points,e.type.defaultLook.thickness||M.look.thickness,e.type.defaultStartMarkerLook?.width,e.type.defaultEndMarkerLook?.width)).attr(`marker-start`,e=>`url(#${e.id}-start-marker)`).attr(`marker-end`,e=>`url(#${e.id}-end-marker)`).attr(`stroke`,e=>e.look.color||M.look.color).attr(`stroke-width`,e=>e.look.thickness||M.look.thickness).attr(`stroke-dasharray`,e=>ae(e.look.style||M.look.style,e.type.defaultLook.thickness||M.look.thickness)).attr(`fill`,`none`),a.select(`path.diagram-connection-path-box`).attr(`d`,e=>Vt(e.look.shape||M.look.shape,e.startCoords,e.endCoords,e.startDirection,e.endDirection,e.points,e.type.defaultLook.thickness||M.look.thickness,e.type.defaultStartMarkerLook?.width,e.type.defaultEndMarkerLook?.width)).attr(`stroke`,`transparent`).attr(`pointer-events`,`stroke`).attr(`stroke-width`,e=>(e.look.thickness||M.look.thickness)+12).attr(`stroke-dasharray`,e=>ae(e.look.style||M.look.style,e.type.defaultLook.thickness||M.look.thickness)).attr(`fill`,`none`),a.data().forEach(e=>{this.updateConnectionLabelsInView(e),this.updateConnectionMarkersInView(e)})}updateFieldsInView(...e){let t=this.selectCanvasElements().selectAll(`g.diagram-field`).data(this.model.fields.filter(e=>this.priorityThreshold===void 0?!0:e.getPriority()>=this.priorityThreshold),e=>e.id),n=t.exit(),r=t.enter().append(`g`).attr(`id`,e=>e.id).attr(`class`,`diagram-field`);e&&e.length>0&&(t=t.filter(t=>e.includes(t.id)));let i=r.merge(t);n.remove(),r.on(x.MouseOver,(e,t)=>{this.dragging||(this.userHighlight.focusOn(t),this.diagramEvent$.next(new Y(t)))}).on(x.Click,(e,t)=>{if(!e.ctrlKey&&!e.shiftKey){let e=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new J(e,!1))}let n=Ht(t);this.userSelection.toggle(n),this.diagramEvent$.next(new J([n],n.selected))}).on(x.ContextMenu,(e,t)=>{if(this.dragging){e.preventDefault(),e.stopPropagation(),this.dragging=!1;return}let n=new Lt(e,t);if(this.diagramEvent$.next(n),!n.defaultPrevented&&this.canUserPerformAction(K.ContextMenu)){e.preventDefault();let n=Ht(t);this.userHighlight.focusOn(n),this.diagramEvent$.next(new Y(n)),this.userSelection.add(n),this.diagramEvent$.next(new J([n],!0)),this.contextMenu.open(e)}}).on(x.DoubleClick,(e,t)=>{let n=new It(e,t);this.diagramEvent$.next(n),!n.defaultPrevented&&this.canUserPerformAction(K.EditField)&&t.editable&&!t.removed&&(this.currentAction=new kt(this,t.id,t.text,``),this.openTextInput(t.id))}).call(c.drag().filter(e=>(this.secondaryButton=Bt(e),!0)).on(C.Start,(e,t)=>{if(this.multipleSelectionOn||this.secondaryButton)this.startMultipleSelection(e);else{let n;t.rootElement instanceof U?n=t.rootElement:t.rootElement instanceof H&&(n=t.rootElement.node),n?this.startMovingNode(e,n):X(D.NotAllowed)}}).on(C.Drag,(e,t)=>{if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(e);else{let n;t.rootElement instanceof U?n=t.rootElement:t.rootElement instanceof H&&(n=t.rootElement.node),n?this.continueMovingNode(e,n):X(D.NotAllowed)}}).on(C.End,(e,t)=>{if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(e);else{let n;t.rootElement instanceof U?n=t.rootElement:t.rootElement instanceof H&&(n=t.rootElement.node),n?this.finishMovingNode(e,n):X()}this.secondaryButton=!1})),r.append(`text`).style(`user-select`,`none`).style(`font-kerning`,`none`).style(`white-space`,`nowrap`),r.append(`rect`),i.attr(`x`,0).attr(`y`,0).attr(`width`,e=>e.width).attr(`height`,e=>e.height).attr(`transform`,e=>`translate(${e.coords[0]},${e.coords[1]}) rotate(${e.orientation} ${e.width/2} ${e.height/2})`).attr(`opacity`,e=>e.removed?.5:1).select(`text`).attr(`x`,e=>e.horizontalAlign===m.Center?e.width/2:e.horizontalAlign===m.Right?e.width:0).attr(`text-anchor`,e=>e.horizontalAlign===m.Center?`middle`:e.horizontalAlign===m.Right?`end`:`start`).attr(`y`,e=>e.verticalAlign===h.Center?e.height/2:e.verticalAlign===h.Bottom?e.height:0).attr(`dominant-baseline`,e=>e.verticalAlign===h.Center?`middle`:e.verticalAlign===h.Bottom?`auto`:`hanging`).attr(`font-size`,e=>e.look.fontSize||F.look.fontSize).attr(`font-family`,e=>e.look.fontFamily||`'Wonder Unit Sans', sans-serif`).attr(`font-weight`,e=>e.look.fontWeight||F.look.fontWeight).attr(`fill`,e=>e.look.fontColor||F.look.fontColor).style(`font-kerning`,`none`).each(e=>{this.setFieldTextAndWrap(e)}),i.select(`rect`).attr(`x`,0).attr(`y`,0).attr(`width`,e=>e.width).attr(`height`,e=>e.height).attr(`fill`,`transparent`)}updateObjectsInView(...e){let t=this.selectCanvasElements().selectAll(`g.diagram-object`).data(this.model.objects.filter(e=>this.priorityThreshold===void 0?!0:e.getPriority()>=this.priorityThreshold),e=>e.id),n=t.exit(),r=t.enter().append(`g`).attr(`id`,e=>e.id).attr(`class`,`diagram-object`);e&&e.length>0&&(t=t.filter(t=>e.includes(t.id))),r.merge(t).attr(`width`,e=>e.width).attr(`height`,e=>e.height).attr(`transform`,e=>`translate(${e.coords[0]},${e.coords[1]})`).html(e=>e.svg),n.remove(),r.on(x.ContextMenu,(e,t)=>{if(this.dragging){e.preventDefault(),e.stopPropagation(),this.dragging=!1;return}let n=new Lt(e,t);this.diagramEvent$.next(n),!n.defaultPrevented&&this.canUserPerformAction(K.ContextMenu)&&(e.preventDefault(),this.contextMenu.open(e))}).on(x.DoubleClick,(e,t)=>{let n=new It(e,t);this.diagramEvent$.next(n)}).call(c.drag().filter(e=>(this.secondaryButton=Bt(e),!0)).on(C.Start,e=>{(this.multipleSelectionOn||this.secondaryButton)&&this.startMultipleSelection(e)}).on(C.Drag,e=>{(this.multipleSelectionOn||this.secondaryButton)&&this.continueMultipleSelection(e)}).on(C.End,e=>{(this.multipleSelectionOn||this.secondaryButton)&&this.finishMultipleSelection(e)}))}updateDecoratorsInView(...e){let t=this.selectCanvasElements().selectAll(`g.diagram-decorator`).data(this.model.decorators.filter(e=>this.priorityThreshold===void 0?!0:e.getPriority()>=this.priorityThreshold),e=>e.id),n=t.exit(),r=t.enter().append(`g`).attr(`id`,e=>e.id).attr(`class`,`diagram-decorator`);e&&e.length>0&&(t=t.filter(t=>e.includes(t.id))),r.merge(t).attr(`width`,e=>e.width).attr(`height`,e=>e.height).attr(`transform`,e=>`translate(${e.coords[0]},${e.coords[1]})`).html(e=>e.svg),n.remove(),r.on(x.MouseOver,(e,t)=>{this.dragging||(this.userHighlight.focusOn(t),this.diagramEvent$.next(new Y(t)))}).on(x.Click,(e,t)=>{if(!e.ctrlKey&&!e.shiftKey){let e=this.userSelection.all();this.userSelection.clear(),this.diagramEvent$.next(new J(e,!1))}if(t.rootElement){let e=Ht(t.rootElement);this.userSelection.toggle(e),this.diagramEvent$.next(new J([e],e.selected))}}).on(x.ContextMenu,(e,t)=>{if(this.dragging){e.preventDefault(),e.stopPropagation(),this.dragging=!1;return}let n=new Lt(e,t);if(this.diagramEvent$.next(n),!n.defaultPrevented&&this.canUserPerformAction(K.ContextMenu)&&t.rootElement){e.preventDefault();let n=Ht(t.rootElement);this.userHighlight.focusOn(n),this.diagramEvent$.next(new Y(n)),this.userSelection.add(n),this.diagramEvent$.next(new J([n],!0)),this.contextMenu.open(e)}}).on(x.DoubleClick,(e,t)=>{let n=new It(e,t);this.diagramEvent$.next(n)}).call(c.drag().filter(e=>(this.secondaryButton=Bt(e),!0)).on(C.Start,(e,t)=>{if(this.multipleSelectionOn||this.secondaryButton)this.startMultipleSelection(e);else{let n;t.rootElement instanceof U?n=t.rootElement:t.rootElement instanceof H&&(n=t.rootElement.node),n?this.startMovingNode(e,n):X(D.NotAllowed)}}).on(C.Drag,(e,t)=>{if(this.multipleSelectionOn||this.secondaryButton)this.continueMultipleSelection(e);else{let n;t.rootElement instanceof U?n=t.rootElement:t.rootElement instanceof H&&(n=t.rootElement.node),n?this.continueMovingNode(e,n):X(D.NotAllowed)}}).on(C.End,(e,t)=>{if(this.multipleSelectionOn||this.secondaryButton)this.finishMultipleSelection(e);else{let n;t.rootElement instanceof U?n=t.rootElement:t.rootElement instanceof H&&(n=t.rootElement.node),n?this.finishMovingNode(e,n):X()}this.secondaryButton=!1}))}updateConnectionLabelsInView(e){let t=this.selectCanvasView().select(`[id='${te(e.id)}']`),n=t.select(`path`).node(),r={...F,...e.type.label};if(r.look={...F.look,...r.look},n){let i=n.getTotalLength(),a=0,o=0,s=0,c=0,l=0,u=0;if(r.look.fillColor===`transparent`){let t=e.endCoords[0]-e.startCoords[0],n=e.endCoords[1]-e.startCoords[1];switch(e.startDirection){case f.Top:a=t>=0?-.5:.5,l=a;break;case f.Bottom:a=t>=0?-.5:.5,l=a;break;case f.Left:o=n>0?-.5:.5,u=o;break;case f.Right:o=n>0?-.5:.5,u=o;break;default:a=.5,l=a,o=-.5,u=o}switch(e.endDirection){case f.Top:l=t>=0?.5:-.5;break;case f.Bottom:l=t>=0?.5:-.5;break;case f.Left:u=n>0?.5:-.5;break;case f.Right:u=n>0?.5:-.5;break;default:l=.5,u=-.5}Math.abs(t)>=Math.abs(n)?(s=t>0?-.5:.5,c=n>0?.5:-.5):(s=t>0?.5:-.5,c=n>0?-.5:.5)}t.select(`g.diagram-connection-start-label text`).attr(`x`,0).attr(`y`,(r.look.fontSize||F.look.fontSize)/3).attr(`text-anchor`,`middle`).attr(`font-family`,r.look.fontFamily||F.look.fontFamily).attr(`font-size`,r.look.fontSize||F.look.fontSize).attr(`fill`,r.look.fontColor||F.look.fontColor).text(e.startLabel);let d=t.select(`g.diagram-connection-start-label text`).node()?.getBoundingClientRect();if(d){let i=e.startLabel?d.width/this.zoomTransform.k+Be(r)+Ve(r):0,s=e.startLabel?d.height/this.zoomTransform.k+He(r)+ze(r):0,c;switch(e.startDirection){case f.Left:c=n.getPointAtLength(z(r)+i/2);break;case f.Right:c=n.getPointAtLength(R(r)+i/2);break;case f.Top:c=n.getPointAtLength(L(r)+s/2);break;case f.Bottom:c=n.getPointAtLength(B(r)+s/2);break;default:c=n.getPointAtLength(Math.max(R(r)+i/2,z(r)+i/2,B(r)+s/2,L(r)+s/2))}t.select(`g.diagram-connection-start-label path`).attr(`d`,pe(-i/2,-s/2,i,s)).attr(`fill`,r.look.fillColor||F.look.fillColor).attr(`stroke`,`none`),t.select(`g.diagram-connection-start-label`).attr(`transform`,`translate(${c.x+a*i},${c.y+o*s})`)}t.select(`g.diagram-connection-middle-label text`).attr(`x`,0).attr(`y`,(r.look.fontSize||F.look.fontSize)/3).attr(`text-anchor`,`middle`).attr(`font-family`,r.look.fontFamily||F.look.fontFamily).attr(`font-size`,r.look.fontSize||F.look.fontSize).attr(`fill`,r.look.fontColor||F.look.fillColor).style(`font-kerning`,`none`).text(e.middleLabel);let p=t.select(`g.diagram-connection-middle-label text`).node()?.getBoundingClientRect();if(p){let a=e.middleLabel?p.width/this.zoomTransform.k+Be(r)+Ve(r):0,o=e.middleLabel?p.height/this.zoomTransform.k+He(r)+ze(r):0,l=n.getPointAtLength(i/2);t.select(`g.diagram-connection-middle-label path`).attr(`d`,pe(-a/2,-o/2,a,o)).attr(`fill`,r.look.fillColor||F.look.fillColor).attr(`stroke`,`none`),t.select(`g.diagram-connection-middle-label`).attr(`transform`,`translate(${l.x+s*a},${l.y+c*o})`)}t.select(`g.diagram-connection-end-label text`).attr(`x`,0).attr(`y`,(r.look.fontSize||F.look.fontSize)/3).attr(`text-anchor`,`middle`).attr(`font-family`,r.look.fontFamily||F.look.fontFamily).attr(`font-size`,r.look.fontSize||F.look.fontSize).attr(`fill`,r.look.fontColor||F.look.fontColor).style(`font-kerning`,`none`).text(e.endLabel);let m=t.select(`g.diagram-connection-end-label text`).node()?.getBoundingClientRect();if(m){let a=e.endLabel?m.width/this.zoomTransform.k+Be(r)+Ve(r):0,o=e.endLabel?m.height/this.zoomTransform.k+He(r)+ze(r):0,s;switch(e.endDirection){case f.Left:s=n.getPointAtLength(i-(z(r)+a/2));break;case f.Right:s=n.getPointAtLength(i-(R(r)+a/2));break;case f.Top:s=n.getPointAtLength(i-(L(r)+o/2));break;case f.Bottom:s=n.getPointAtLength(i-(B(r)+o/2));break;default:s=n.getPointAtLength(i-Math.max(R(r)+a/2,z(r)+a/2,B(r)+o/2,L(r)+o/2))}t.select(`g.diagram-connection-end-label path`).attr(`d`,pe(-a/2,-o/2,a,o)).attr(`fill`,r.look.fillColor||F.look.fillColor).attr(`stroke`,`none`),t.select(`g.diagram-connection-end-label`).attr(`transform`,`translate(${s.x+l*a},${s.y+u*o})`)}}}updateConnectionMarkersInView(e){let t=this.selectCanvasView().select(`[id='${te(e.id)}']`),n=t.select(`marker.diagram-connection-start-marker`),r=t.select(`marker.diagram-connection-end-marker`);e.startMarkerLook===null?n.attr(`orient`,`auto-start-reverse`).attr(`markerWidth`,0).attr(`markerHeight`,0):n.attr(`orient`,`auto-start-reverse`).attr(`markerWidth`,e.startMarkerLook.width).attr(`markerHeight`,e.startMarkerLook.height).attr(`refX`,e.startMarkerLook.refX).attr(`refY`,e.startMarkerLook.refY).select(`image`).attr(`href`,e.startMarkerLook.image).attr(`width`,e.startMarkerLook.width).attr(`height`,e.startMarkerLook.height),e.endMarkerLook===null?r.attr(`orient`,`auto-start-reverse`).attr(`markerWidth`,0).attr(`markerHeight`,0):r.attr(`orient`,`auto-start-reverse`).attr(`markerWidth`,e.endMarkerLook.width).attr(`markerHeight`,e.endMarkerLook.height).attr(`refX`,e.endMarkerLook.refX).attr(`refY`,e.endMarkerLook.refY).select(`image`).attr(`href`,e.endMarkerLook.image).attr(`width`,e.endMarkerLook.width).attr(`height`,e.endMarkerLook.height)}fieldRootFitsInView(e){let t=this.model.fields.get(e);if(!t)return!1;if(t.rootElement instanceof U||t.rootElement instanceof H){let e=this.minimumSizeOfField(t),n=e[0]+R(t.rootElement.type?.label)+z(t.rootElement.type?.label)-t.rootElement.width,r=e[1]+B(t.rootElement.type?.label)+L(t.rootElement.type?.label)-t.rootElement.height;return n<=0&&r<=0}return!0}fitFieldRootInView(e,t=!0){let n=this.model.fields.get(e);if(n){if(n.rootElement instanceof U){let e=this.minimumSizeOfField(n),r=e[0]+R(n.rootElement.type.label)+z(n.rootElement.type.label)-n.rootElement.width,i=e[1]+B(n.rootElement.type.label)+L(n.rootElement.type.label)-n.rootElement.height,a=Z(this.gridConfig),o=Q(this.gridConfig);this.gridConfig.snap&&a!==0&&(r=Math.ceil(r/a)*a),this.gridConfig.snap&&o!==0&&(i=Math.ceil(i/o)*o),n.rootElement.width+r<n.rootElement.type.minWidth&&(r=n.rootElement.type.minWidth-n.rootElement.width),n.rootElement.height+i<n.rootElement.type.minHeight&&(i=n.rootElement.type.minHeight-n.rootElement.height),(t!==!1||r>0)&&n.rootElement.stretch(f.Right,r),(t!==!1||i>0)&&n.rootElement.stretch(f.Bottom,i)}if(n.rootElement instanceof H){let e=this.minimumSizeOfField(n),r=e[0],i=e[1];for(let e of n.rootElement.node?.sections||[])e.label&&(e.indexXInNode===n.rootElement.indexXInNode&&e.indexYInNode!==n.rootElement.indexYInNode?r=Math.max(r,this.minimumSizeOfField(e.label)[0]):e.indexXInNode!==n.rootElement.indexXInNode&&e.indexYInNode===n.rootElement.indexYInNode&&(i=Math.max(i,this.minimumSizeOfField(e.label)[1])));e[0]<r&&(e[0]=r),e[1]<i&&(e[1]=i);let a=n.rootElement.type,o=e[0]+R(a?.label)+z(a?.label)-n.rootElement.width,s=e[1]+B(a?.label)+L(a?.label)-n.rootElement.height,c=Z(this.gridConfig),l=Q(this.gridConfig);this.gridConfig.snap&&c!==0&&(o=Math.ceil(o/c)*c),this.gridConfig.snap&&l!==0&&(s=Math.ceil(s/l)*l),n.rootElement.width+o<(n.rootElement.getMinWidth()||0)&&(o=(n.rootElement.getMinWidth()||0)-n.rootElement.width),n.rootElement.height+s<(n.rootElement.getMinHeight()||0)&&(s=(n.rootElement.getMinHeight()||0)-n.rootElement.height),(t||o>0)&&n.rootElement.node?.stretchSections(f.Right,o,n.rootElement.indexXInNode,n.rootElement.indexYInNode),(t||s>0)&&n.rootElement.node?.stretchSections(f.Bottom,s,n.rootElement.indexXInNode,n.rootElement.indexYInNode)}}}fitNodeInView(e,t=!0){let n=this.model.nodes.get(e);if(n&&n.sections.length>0&&this.priorityThreshold){let e=0,r=0;for(let t of n.sections)if(t.getPriority()>=this.priorityThreshold){let i=t.coords[0]+t.width-n.coords[0],a=t.coords[1]+t.height-n.coords[1];e=Math.max(e,i),r=Math.max(r,a)}e+=n.type.sectionGrid?.margin||0,r+=n.type.sectionGrid?.margin||0,(t||e>n.width)&&n.stretch(f.Right,e-n.width),(t||r>n.height)&&n.stretch(f.Bottom,r-n.height)}}selectRoot(){return c.select(this.diagramRoot)}selectSVGElement(){return this.selectRoot().select(`svg`)}selectCanvasView(){return this.selectSVGElement().select(`.daga-canvas-view`)}selectCanvasElements(){return this.selectCanvasView().select(`.daga-canvas-elements`)}startConnection(e){if(e.allowsOutgoing||e.allowsIncoming){if(this.connectionType&&(this.connectionType.canStartFromType(e.getNode()?.type?.id||``)&&e.allowsOutgoing||this.connectionType.canFinishOnType(e.getNode()?.type?.id||``)&&e.allowsIncoming))this.unfinishedConnection=new N(this.model,this.connectionType,e,void 0,fn),this.unfinishedConnectionPort=e;else if(this.inferConnectionType){let t=this.model.connections.types.all().find(t=>e.allowsOutgoing&&t.canStartFromType(e.getNode()?.type?.id||``));t===void 0&&(t=this.model.connections.types.all().find(t=>e.allowsIncoming&&t.canFinishOnType(e.getNode()?.type?.id||``))),t!==void 0&&(this.unfinishedConnection=new N(this.model,t,e,void 0,fn),this.unfinishedConnectionPort=e)}}}finishConnection(e){if(this.userHighlight.clear(),this.unfinishedConnection!==void 0){if(!this.allowConnectionLoops&&this.unfinishedConnection.start===e){this.dropConnection();return}if(!this.allowSharingPorts&&(e.incomingConnections.filter(e=>!e.removed).length>0||e.outgoingConnections.filter(e=>!e.removed).length>0)){this.dropConnection();return}if(!this.allowSharingBothPorts&&this.model.connections.find(t=>!t.removed&&(t.start===this.unfinishedConnection?.start&&t.end===e||t.end===this.unfinishedConnection?.start&&t.start===e))!==void 0){this.dropConnection();return}if(this.unfinishedConnection.type.canStartFromType(this.unfinishedConnection?.start?.getNode()?.type?.id||``)&&this.unfinishedConnection?.start?.allowsOutgoing&&this.unfinishedConnection.type.canFinishOnType(e.getNode()?.type?.id||``)&&e.allowsIncoming){let t=new Ot(this,this.unfinishedConnection.type,this.unfinishedConnection.start?.id,e.id);this.dropConnection(),t.do(),this.actionStack.add(t)}else if(this.unfinishedConnection.type.canFinishOnType(this.unfinishedConnection?.start?.getNode()?.type?.id||``)&&this.unfinishedConnection?.start?.allowsIncoming&&this.unfinishedConnection.type.canStartFromType(e.getNode()?.type?.id||``)&&e.allowsOutgoing){let t=new Ot(this,this.unfinishedConnection.type,e.id,this.unfinishedConnection.start?.id);this.dropConnection(),t.do(),this.actionStack.add(t)}else if(this.inferConnectionType){let t=this.model.connections.types.all().find(t=>t.canStartFromType(this.unfinishedConnection?.start?.getNode()?.type?.id||``)&&this.unfinishedConnection?.start?.allowsOutgoing&&t.canFinishOnType(e.getNode()?.type?.id||``)&&e.allowsIncoming),n=!1;if(t===void 0&&(t=this.model.connections.types.all().find(t=>t.canFinishOnType(this.unfinishedConnection?.start?.getNode()?.type?.id||``)&&this.unfinishedConnection?.start?.allowsIncoming&&t.canStartFromType(e.getNode()?.type?.id||``)&&e.allowsOutgoing),n=!0),t!==void 0){let r=new Ot(this,t,n?e.id:this.unfinishedConnection.start?.id,n?this.unfinishedConnection.start?.id:e.id);this.dropConnection(),r.do(),this.actionStack.add(r)}else this.dropConnection()}else this.dropConnection()}}dropConnection(){this.unfinishedConnection?.setStart(void 0),this.unfinishedConnection?.setEnd(void 0),this.unfinishedConnection?.select()?.remove(),this.unfinishedConnection=void 0,this.unfinishedConnectionPort=void 0}cancelAllUserActions(){this.currentAction=void 0,this.dropConnection(),this.removeInputField(),this.contextMenu.close(),this.userSelection.clear()}canUserPerformAction(e){return this.userActions[e]!==!1}openTextInput(e){let t=this.model.fields.get(e);t&&this.createInputField(t.text,t.coords,t.width,t.height,t.look.fontSize||F.look.fontSize,t.look.fontFamily||F.look.fontFamily,t.orientation,t.multiline,()=>{},e=>{t.text=e,this.currentAction instanceof kt&&(this.currentAction.to=e,this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0)})}createInputField(e,t,n,r,i,a,o,s,c,l){this.removeInputField();let u=this.selectCanvasElements().append(`foreignObject`).attr(`x`,`${t[0]}px`).attr(`y`,`${t[1]}px`).attr(`width`,`${n}px`).attr(`height`,`${r}px`).style(`box-sizing`,`border-box`).style(`border`,`1px solid`);this.inputFieldContainer=u;let d=u.append(`xhtml:textarea`),f,p;d.text(e).style(`box-sizing`,`border-box`).style(`width`,`${n}px`).style(`height`,`${r}px`).style(`font-size`,`${i}px`).style(`font-family`,a).style(`resize`,`none`).style(`outline`,0).style(`border`,0).style(`margin`,0).style(`padding`,0).on(x.KeyDown,e=>{if(e.stopPropagation(),e.key===S.Escape||e.key===S.Enter&&!s){let e=d.property(`value`)||``;this.removeInputField(),l&&l(e)}}).on(x.KeyUp,e=>{e.stopPropagation()}).on(x.Input,()=>{let e=d.property(`value`);d.attr(`cols`,ve(e)+1),d.attr(`rows`,ye(e)+1),d.style(`width`,``),d.style(`height`,``),f=d.property(`scrollWidth`)+1,p=d.property(`scrollHeight`)+1;let t=Math.max(f,n),i=Math.max(p,r);u?.attr(`width`,`${t}px`),d.style(`width`,`${t}px`),u?.attr(`height`,`${i}px`),d.style(`height`,`${i}px`),c&&c(e)}).on(x.Click,e=>{e.stopPropagation()}).on(x.FocusOut,()=>{let e=d.property(`value`);this.removeInputField(),l&&l(e)});let m=d.node();m.focus(),m.select()}removeInputField(){this.inputFieldContainer?.select(`input`)?.on(x.Blur,null),this.inputFieldContainer?.remove(),this.inputFieldContainer=void 0}minimumSizeOfField(e){let t=e.select()?.select(`text`)?.node();if(!t)return[0,0];let n=t.getBoundingClientRect();return[n.width/this.zoomTransform.k,n.height/this.zoomTransform.k]}setFieldTextAndWrap(e){let t=e.select()?.select(`text`),n=t?.node();if(t&&n)this.setFieldText(e,t,e.text);else return;if(e.fit)return;let r=this.minimumSizeOfField(e);for(;r[0]>e.width||r[1]>e.height;){let n=t?.html()?.replace(/<\/tspan>/g,`
|
|
3
3
|
`)?.replace(/<tspan[^>]*>/g,``)?.slice(0,-1)||``,i=`...`;if(i=n.endsWith(`...`)?n.slice(0,-4)+`...`:n.slice(0,-1)+`...`,t&&this.setFieldText(e,t,i),i===`...`)return;r=this.minimumSizeOfField(e)}}setFieldText(e,t,n){let r=n.split(`
|
|
4
|
-
`);t.html(``);for(let n=0;n<r.length;++n)t.append(`tspan`).attr(`x`,e.horizontalAlign===m.Center?e.width/2:e.horizontalAlign===m.Right?e.width:0).attr(`y`,e.verticalAlign===h.Center?(n+.5-r.length/2)*(e.look.fontSize||P.look.fontSize)+e.height/2:e.verticalAlign===h.Bottom?e.height-(r.length-n-1)*(e.look.fontSize||P.look.fontSize):n*(e.look.fontSize||P.look.fontSize)).text(r[n])}startMovingNode(e,t){if(this.canUserPerformAction(G.MoveNode)&&!t.removed)if(Y(D.Grabbing),this.draggingFrom=[e.x,e.y],t.selected&&this.userSelection.count(e=>e instanceof H)>1)this.currentAction=new wt(this,this.userSelection.filter(e=>e instanceof H).map(e=>e.id),t.coords);else{let e=t.getLastAncestor();this.currentAction=new K(this,G.MoveNode,t.id,t.getGeometry(),t.getGeometry(),e?.id,e?.getGeometry(t.id),e?.getGeometry(t.id))}else Y(D.NotAllowed)}continueMovingNode(e,t){if(this.canUserPerformAction(G.MoveNode)&&(this.currentAction instanceof wt||this.currentAction instanceof K)&&!t.removed){let n=[e.x-t.width/2,e.y-t.height/2];t.selected?this.userSelection.move([n[0]-t.coords[0],n[1]-t.coords[1]]):t.move(n),this.userHighlight.clear(),this.dragging=!0,this.diagramEvent$.next(new It(t))}}finishMovingNode(e,t){if(this.canUserPerformAction(G.MoveNode)&&!t.removed&&(this.draggingFrom[0]!==e.x||this.draggingFrom[1]!==e.y)){let n=[e.x-t.width/2,e.y-t.height/2];if(this.gridConfig?.snap&&(n=this.getClosestGridPoint([n[0]-t.type.snapToGridOffset[0],n[1]-t.type.snapToGridOffset[1]]),n[0]+=t.type.snapToGridOffset[0],n[1]+=t.type.snapToGridOffset[1]),this.currentAction instanceof wt){let e=this.currentAction.delta;this.currentAction.delta=[n[0]-e[0],n[1]-e[1]],t.selected?this.userSelection.move([e[0]-t.coords[0],e[1]-t.coords[1]]):t.move(e)}else if(this.currentAction instanceof K){t.move(n);let r=Xe(this.model.nodes.getAtCoordinates(e.x,e.y).filter(e=>e.id!==t.id&&!e.isDescendantOf(t)).filter(e=>e.type.childrenTypes.includes(t.type.id))),i=r[r.length-1];if(i!==t.parent&&(t.type.canBeParentless||i!==void 0)){let e=i?.getLastAncestor(),n=this.currentAction.from,r=new Tt(this,t.id,t.parent?.id,i?.id,n,t.getGeometry(),e?.id,e?.getGeometry(t.id),e?.getGeometry(t.id));t.parent?.removeChild(t),i!==void 0&&i.addChild(t),r.toChildGeometry=t.getGeometry(t.id),r.toAncestorGeometry=e?.getGeometry(t.id),this.currentAction=r}else{let e=t?.getLastAncestor();this.currentAction.ancestorId=e?.id,this.currentAction.fromAncestorGeometry=e?.getGeometry(t.id),t.parent?.fitToChild(t),this.currentAction.to=t.getGeometry(t.id),this.currentAction.toAncestorGeometry=e?.getGeometry(t.id)}}this.currentAction!==void 0&&(this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0)}Y(),this.dragging=!1}startMultipleSelection(e){this.draggingFrom=this.getPointerLocationRelativeToCanvas(e),this.multipleSelectionContainer=this.selectSVGElement().append(`rect`).attr(`stroke`,`#0E74B6`).attr(`fill`,`rgba(14, 116, 182, 0.06)`)}continueMultipleSelection(e){let t=this.getPointerLocationRelativeToCanvas(e);(this.draggingFrom[0]!==t[0]||this.draggingFrom[1]!==t[1])&&(Y(D.Crosshair),this.multipleSelectionContainer?.attr(`x`,Math.min(this.draggingFrom[0],t[0])*this.zoomTransform.k+this.zoomTransform.x)?.attr(`y`,Math.min(this.draggingFrom[1],t[1])*this.zoomTransform.k+this.zoomTransform.y)?.attr(`width`,Math.abs(this.draggingFrom[0]-t[0])*this.zoomTransform.k)?.attr(`height`,Math.abs(this.draggingFrom[1]-t[1])*this.zoomTransform.k),this.dragging=!0)}finishMultipleSelection(e){let t=this.getPointerLocationRelativeToCanvas(e);this.multipleSelectionContainer?.remove(),this.multipleSelectionContainer=void 0,this.userSelection.clear();for(let e of this.model.nodes)ee([e.coords,[e.coords[0]+e.width,e.coords[1]+e.height]],[this.draggingFrom,t])&&this.userSelection.add(e);this.multipleSelectionOn=!1,this.diagramEvent$.next(new q(this.userSelection.all(),!0)),Y()}},un=class{constructor(){this.grid=[[void 0]],this.offsetX=0,this.offsetY=0}minX(){return-this.offsetX}maxX(){return this.width()-1-this.offsetX}minY(){return-this.offsetY}maxY(){return this.height()-1-this.offsetY}width(){return this.grid[0].length}height(){return this.grid.length}addColumnLeft(){for(let e of this.grid)e.splice(0,0,void 0);this.offsetX+=1}addColumnRight(){for(let e of this.grid)e.push(void 0)}addRowTop(){let e=[];for(let t=0;t<this.grid[0].length;++t)e.push(void 0);this.grid.splice(0,0,e),this.offsetY+=1}addRowBottom(){let e=[];for(let t=0;t<this.grid[0].length;++t)e.push(void 0);this.grid.push(e)}get(e){if(this.grid[e[1]+this.offsetY])return this.grid[e[1]+this.offsetY][e[0]+this.offsetX]}set(e,t){for(;e[0]<-this.offsetX;)this.addColumnLeft();for(;e[0]>=this.width()-this.offsetX;)this.addColumnRight();for(;e[1]<-this.offsetY;)this.addRowTop();for(;e[1]>=this.height()-this.offsetY;)this.addRowBottom();this.grid[e[1]+this.offsetY][e[0]+this.offsetX]=t}getClosestEmptyCoordinate(e){if(this.get(e)===void 0)return e;let t=[...e];for(let e=1;;++e){let n=e%2>0?e:-e,r=n>0?1:-1,i=[t[0]+n,t[1]+n];for(let e=t[0];e!==i[0]+r;e+=r)if(t[0]=e,this.get(t)===void 0)return t;for(let e=t[1];e!==i[1]+r;e+=r)if(t[1]=e,this.get(t)===void 0)return t}}},dn=class{constructor(e){this.gapSize=e}apply(e){if(e.nodes.length===0)return e;let t=new un,n=e.nodes.filter(e=>!e.parent);for(;n.length>0;)fn(n[0],t,[0,0],n);let r=Math.max(...e.nodes.map(e=>e.width)),i=Math.max(...e.nodes.map(e=>e.height)),a=this.gapSize===void 0?e.canvas?.gridConfig?Z(e.canvas?.gridConfig)*2:0:this.gapSize,o=this.gapSize===void 0?e.canvas?.gridConfig?Q(e.canvas?.gridConfig)*2:0:this.gapSize;for(let e=t.minY();e<=t.maxY();++e)for(let n=t.minX();n<=t.maxX();++n){let s=t.get([n,e]);s!==void 0&&s.move([n*(r+a),e*(i+o)])}return e}},fn=(e,t,n,r)=>{let i=t.getClosestEmptyCoordinate(n);t.set(i,e),E(r,e);for(let n of e.getAdjacentNodes())r.includes(n)&&fn(n,t,i,r)},pn=class{constructor(e){this.gapSize=e}apply(e){if(e.nodes.length===0)return e;let t=new un,n=e.nodes.filter(e=>!e.parent),r={},i=n[0],a=[i];for(r[i.id]=[0,0];n.length>0;){let e=[];for(let i of a){t.set(t.getClosestEmptyCoordinate(r[i.id]),i),E(n,i);let a=i.getAdjacentNodes();for(let t of a)n.includes(t)&&(e.push(t),r[t.id]=r[i.id])}if(e.length>0)a=e;else if(n.length>0){let e=n[0];a=[e],r[e.id]=t.getClosestEmptyCoordinate([0,0])}}let o=Math.max(...e.nodes.map(e=>e.width)),s=Math.max(...e.nodes.map(e=>e.height)),c=this.gapSize===void 0?e.canvas?.gridConfig?Z(e.canvas?.gridConfig)*2:0:this.gapSize,l=this.gapSize===void 0?e.canvas?.gridConfig?Q(e.canvas?.gridConfig)*2:0:this.gapSize;for(let e=t.minY();e<=t.maxY();++e)for(let n=t.minX();n<=t.maxX();++n){let r=t.get([n,e]);r!==void 0&&r.move([n*(o+c),e*(s+l)])}return e}},mn=class{constructor(e){this.gapSize=e}apply(e){if(e.nodes.length===0)return e;let t=this.gapSize===void 0?e.canvas?.gridConfig?Z(e.canvas?.gridConfig)*2:0:this.gapSize,n=this.gapSize===void 0?e.canvas?.gridConfig?Q(e.canvas?.gridConfig)*2:0:this.gapSize,r=e.nodes.filter(e=>!e.parent),i=r[0];E(r,i);let a=[[i]];for(;r.length>0;){let e=a[a.length-1],t=[];for(let n of e){let e=n.getAdjacentNodes();for(let n of e)r.includes(n)&&(E(r,n),t.push(n))}t.length>0?a.push(t):(a.push(r),r=[])}let o=0;for(let e of a){let r=0;for(let t of e)t.move([o,r]),r+=n+t.height;let i=Math.max(...e.map(e=>e.width));o+=t+i}for(let t of e.connections)t.tighten();return e}},hn=class{constructor(e){this.gapSize=e}apply(e){if(e.nodes.length===0)return e;new mn(this.gapSize).apply(e);let t=this.gapSize===void 0?e.canvas?.gridConfig?Z(e.canvas?.gridConfig)*2:0:this.gapSize,n=this.gapSize===void 0?e.canvas?.gridConfig?Q(e.canvas?.gridConfig)*2:0:this.gapSize,r=Math.max(t,n),i=.1,a=.5,o=.002,s=100;for(;s>1;){s*=.99;let t=[0,0];for(let n of e.nodes)t[0]=t[0]+n.coords[0]+n.width/2,t[1]=t[1]+n.coords[1]+n.width/2;t[0]/=e.nodes.length,t[1]/=e.nodes.length;for(let n of e.nodes){let c=n.getAdjacentNodes();for(let l of e.nodes){let e=[n.coords[0]+n.width/2,n.coords[1]+n.height/2],u=[l.coords[0]+l.width/2,l.coords[1]+l.height/2],d=b(n.coords,l.coords),f=[l.coords[0],l.coords[1]];if(c.includes(l)&&d>0&&(d>r+(Math.max(n.width,n.height)+Math.max(l.width,l.height))/2?(f[0]-=(u[0]-e[0])*i,f[1]-=(u[1]-e[1])*i):(f[0]+=(u[0]-e[0])*a,f[1]+=(u[1]-e[1])*a)),d>0){let t=2e5/(d*d);f[0]+=t*(u[0]-e[0])/d,f[1]+=t*(u[1]-e[1])/d}else f[0]+=1*(Math.random()*2-1),f[1]+=1*(Math.random()*2-1);f[0]-=(u[0]-t[0])*o,f[1]-=(u[1]-t[1])*o,f[0]-l.coords[0]>s?f[0]=l.coords[0]+s:f[0]-l.coords[0]<-s&&(f[0]=l.coords[0]-s),f[1]-l.coords[1]>s?f[1]=l.coords[1]+s:f[1]-l.coords[1]<-s&&(f[1]=l.coords[1]-s),l.move(f)}}}if(e.canvas&&e.canvas.gridConfig.snap)for(let t of e.nodes){let n=e.canvas.getClosestGridPoint([t.coords[0]-t.type.snapToGridOffset[0],t.coords[1]-t.type.snapToGridOffset[1]]);n[0]+=t.type.snapToGridOffset[0],n[1]+=t.type.snapToGridOffset[1],t.move(n)}for(let t of e.connections)t.tighten();return e}},gn=class{constructor(e){this.gapSize=e}apply(e){if(e.nodes.length===0)return e;let t=this.gapSize===void 0?e.canvas?.gridConfig?Z(e.canvas?.gridConfig)*2:0:this.gapSize,n=e.nodes.filter(e=>!e.parent);n.sort((e,t)=>t.type.priority-e.type.priority);let r=0;for(let e of n)e.move([r,0]),r+=e.width+t;return e}},_n=class{constructor(e){this.gapSize=e}apply(e){if(e.nodes.length===0)return e;let t=Math.max(...e.nodes.map(e=>e.getPriority()));if(t===Math.min(...e.nodes.map(e=>e.getPriority())))return new mn(this.gapSize).apply(e),e;let n=this.gapSize===void 0?e.canvas?.gridConfig?Z(e.canvas?.gridConfig)*2:0:this.gapSize,r=this.gapSize===void 0?e.canvas?.gridConfig?Q(e.canvas?.gridConfig)*2:0:this.gapSize,i=e.nodes.filter(e=>!e.parent),a=[],o=e.nodes.filter(e=>!e.parent).filter(e=>e.getPriority()>=t),s=[];if(o.length>1){let e=o[0];o.splice(0,1),s.push(e);let t=[e],n=[e];for(;t.length>0;){let e=t[0];t.splice(0,1),o.includes(e)&&(s.push(e),E(o,e));let r=e.getAdjacentNodes();for(let e of r)n.includes(e)||(t.push(e),n.push(e))}for(let e of o)s.push(e)}else s.push(o[0]);for(let e of s)E(i,e),a.push([e]);for(a.push([]),i.sort((e,t)=>t.type.priority-e.type.priority);i.length>0;){let e=i[0];i.splice(0,1);let t=[e],n=[e],r=!1;for(;t.length>0;){let i=t[0];t.splice(0,1);let o=s.indexOf(i);if(o>=0){a[o].push(e),r=!0;break}else{let e=i.getAdjacentNodes();for(let r of e)n.includes(r)||(t.push(r),n.push(r))}}r||a[a.length-1].push(e)}let c=0;for(let e=0;e<a.length;++e){let t=0;for(let n=0;n<a[e].length;++n){let i=a[e][n];i.move([c,t]),t+=r+i.height}let i=Math.max(...a[e].map(e=>e.width));c+=n+i}for(let t of e.connections)t.tighten();return e}},vn=class{constructor(e){this.gapSize=e}apply(e){if(e.nodes.length===0)return e;if(Math.max(...e.nodes.map(e=>e.getPriority()))===Math.min(...e.nodes.map(e=>e.getPriority())))return new mn(this.gapSize).apply(e),e;let t=this.gapSize===void 0?e.canvas?.gridConfig?Z(e.canvas?.gridConfig)*2:0:this.gapSize,n=this.gapSize===void 0?e.canvas?.gridConfig?Q(e.canvas?.gridConfig)*2:0:this.gapSize,r=e.nodes.filter(e=>!e.parent).sort((e,t)=>t.getPriority()-e.getPriority()),i=[];for(;r.length>0;){let e=r[0];r.splice(0,1);let t=new xn(void 0,e);yn(t,r),i.push(t)}let a=[];for(let e of i)a.push([e]),bn(e,a,a.length);let o=Math.max(...e.nodes.map(e=>e.height)),s=0;for(let e=0;e<a.length;++e){let r=0;for(let t=0;t<a[e].length;++t){let i=a[e][t];i.node.move([s,r]),r+=(n+o)*i.countBranchHeight()}let i=Math.max(...a[e].map(e=>e.node.width));s+=t+i}for(let t of e.connections)t.tighten();return e}},yn=(e,t)=>{for(let n of e.node.getAdjacentNodes().sort((e,t)=>t.getPriority()-e.getPriority())){let r=t.indexOf(n);r>=0&&(t.splice(r,1),yn(e.addBranch(n),t))}},bn=(e,t,n)=>{if(e.branches.length>0){for(;n>=t.length;)t.push([]);for(let r of e.branches)t[n].push(r),bn(r,t,n+1)}},xn=class e{constructor(e,t){this.parent=e,this.branches=[],this.depth=0,this.node=t}addBranch(t){let n=new e(this,t);return n.depth=this.depth+1,this.branches.push(n),n}countBranchHeight(){if(this.branches.length<=0)return 1;{let e=0;for(let t of this.branches)e+=t.countBranchHeight();return e}}},Sn=class{constructor(e){this.gapSize=e}apply(e){if(e.nodes.length===0)return e;let t=this.gapSize===void 0?e.canvas?.gridConfig?Q(e.canvas?.gridConfig)*2:0:this.gapSize,n=e.nodes.filter(e=>!e.parent);n.sort((e,t)=>t.type.priority-e.type.priority);let r=0;for(let e of n)e.move([0,r]),r+=e.height+t;return e}},Cn={adjacency:new dn,breadth:new mn,"breadth-adjacency":new pn,force:new hn,horizontal:new gn,priority:new _n,tree:new vn,vertical:new Sn},wn=(0,u.createContext)({}),Tn=(0,u.createContext)({}),En=class{constructor(e,t){this.onTitleChange=e,this.onValueSetChange=t}get title(){return this._title}set title(e){this._title=e,this.onTitleChange(e)}get valueSet(){return this._valueSet}set valueSet(e){this._valueSet=e,this.onValueSetChange(e)}highlightProperty(...e){}},Dn=({direction:e,collapsableSelector:t,collapsableAdditionalSelector:n,collapsed:r,disabled:i,rule:a,collapsedValue:o,visibleValue:s,onCollapse:l})=>{let[p,m]=(0,u.useState)(r),h=e=>{let r;if(typeof t==`string`)r=c.select(t),n&&(r=r.select(n));else{let e=t;if(!e)throw Error(`collapsableSelector is not a valid ref`);r=c.select(e.current),n&&(r=r.select(n))}r.style(a,e?o:s)};return(0,u.useEffect)(()=>{h(p)},[h,p]),(0,d.jsx)(`daga-collapse-button`,{children:(0,d.jsx)(`button`,{className:`daga-collapse-button daga-${e}`,onClick:()=>{if(!i){let e=!p;m(e),l?.(e),h(e)}},children:(0,d.jsx)(`div`,{className:(()=>{switch(e){case f.Right:return i?`daga-horizontal-none`:p?`daga-horizontal-right`:`daga-horizontal-left`;case f.Bottom:return i?`daga-vertical-none`:p?`daga-vertical-down`:`daga-vertical-up`;case f.Left:return i?`daga-horizontal-none`:p?`daga-horizontal-left`:`daga-horizontal-right`;case f.Top:return i?`daga-vertical-none`:p?`daga-vertical-up`:`daga-vertical-down`}})()})})})},On=()=>{let e=(0,u.useContext)(Tn),t=(0,u.useRef)(null),[n,r]=(0,u.useState)([]);(0,l.merge)(e.validatorChange$,e.diagramChange$).pipe((0,l.map)(()=>i())).subscribe();let i=()=>{r([]);for(let t of e.validators)r(t.validate(e.model))},a=t=>{if(t.elementId&&(t.propertyNames===void 0||t.propertyNames.length===0)){let n=e.model.nodes.get(t.elementId)||e.model.connections.get(t.elementId);n&&e.userHighlight.add(n)}else if(t.elementId&&t.propertyNames!==void 0&&t.propertyNames.length>0){e.userSelection.openInPropertyEditor(e.model.nodes.get(t.elementId)||e.model.connections.get(t.elementId));let n=e.model.nodes.get(t.elementId)||e.model.connections.get(t.elementId);n&&e.userHighlight.add(n),e.parentComponent?.propertyEditor?.highlightProperty(...t.propertyNames)}else !t.elementId&&t.propertyNames!==void 0&&t.propertyNames.length>0&&(e.userSelection.openInPropertyEditor(),e.parentComponent?.propertyEditor?.highlightProperty(...t.propertyNames))};return(0,d.jsx)(`daga-errors`,{children:(0,d.jsxs)(`div`,{ref:t,className:`daga-errors`,children:[n.length===0&&(0,d.jsx)(`div`,{className:`daga-errors-summary daga-no-errors daga-prevent-user-select`,children:(0,d.jsx)(`span`,{children:`No errors found`})}),n.length>0&&(0,d.jsxs)(`div`,{className:`daga-errors-summary daga-with-errors daga-prevent-user-select`,children:[(0,d.jsxs)(`span`,{children:[n.length,` errors found`]}),(0,d.jsx)(`div`,{className:`daga-collapse-button-container`,children:(0,d.jsx)(Dn,{collapsableSelector:t,collapsableAdditionalSelector:`.daga-error-panel`,direction:f.Top,rule:`display`,collapsedValue:`none`,visibleValue:`block`,collapsed:!1,disabled:!1})})]}),n.length>0&&(0,d.jsx)(`div`,{className:`daga-error-panel`,children:(0,d.jsx)(`ol`,{children:n.map((e,t)=>(0,d.jsx)(`li`,{onClick:()=>a(e),dangerouslySetInnerHTML:{__html:e.message}},t))})})]})})},kn=200,An=e=>(e||``).toLowerCase().normalize(`NFD`).replace(/[\u0300-\u036f]/g,``),jn=({disabled:e,options:t,value:n,onChange:r})=>{let i=(0,u.useRef)(null),[a,o]=(0,u.useState)(``),[s,c]=(0,u.useState)(void 0),[l,f]=(0,u.useState)([]),[p,m]=(0,u.useState)([]),[h,g]=(0,u.useState)([]),[_,v]=(0,u.useState)([]),[y,b]=(0,u.useState)(!1);(0,u.useEffect)(()=>{o(t.find(e=>Me(e.key,n))?.label||``)},[n,t]);let ee=n=>{if(!e)switch(n.key){case S.PageDown:s===void 0?(w(0),T(0)):(w(s+5),T(s)),n.preventDefault();break;case S.ArrowDown:s===void 0?(w(0),T(0)):(w(s+1),T(s)),n.preventDefault();break;case S.PageUp:s===void 0?(w(t.length-1),T(t.length-1)):(w(s-5),T(s)),n.preventDefault();break;case S.ArrowUp:s===void 0?(w(t.length-1),T(t.length-1)):(w(s-1),T(s)),n.preventDefault();break;case S.Escape:C(),n.preventDefault();break;case S.Enter:re(t[s||0]),n.preventDefault();break;default:x()}},x=()=>{if(!e){let e=An(a.trim());f([]),m([]),g([]),v([]);for(let n of t){let t=An(n.label).indexOf(e);if(t>=0){let r=n.label.substring(0,t),i=n.label.substring(t,t+e.length),a=n.label.substring(t+e.length);f(e=>[...e,n]),m(e=>[...e,r]),g(e=>[...e,i]),v(e=>[...e,a])}}b(!0)}},C=()=>{b(!1)},w=n=>{if(!e){let e=n;if(n===void 0){c(void 0);return}n<0&&(e=0),n>=t.length&&(e=t.length-1),c(e)}},te=()=>{setTimeout(()=>{C()},kn)},T=e=>{let t=i.current?.querySelectorAll(`li`)[e];t&&t.scrollIntoView({block:`center`})},ne=()=>{e||(o(``),b(!1),c(void 0))},re=t=>{e||(o(t.label),b(!1),c(void 0),r(t.key))};return(0,d.jsxs)(`div`,{ref:i,className:`daga-autocomplete ${y?`daga-showing-options`:``}`,children:[(0,d.jsxs)(`div`,{className:`daga-autocomplete-input`,children:[(0,d.jsx)(`input`,{value:a,disabled:e,onKeyUp:ee,onFocus:x,onBlur:te,onChange:e=>o(e.target.value)}),a!==``&&(0,d.jsx)(`button`,{className:`daga-clear`,onClick:ne})]}),(0,d.jsx)(`div`,{className:`daga-autocomplete-options`,children:(0,d.jsxs)(`ul`,{className:`daga-autocomplete-option-list`,children:[l.length===0&&(0,d.jsx)(`li`,{className:`daga-autocomplete-option no-options`,children:`(No options)`}),l.map((e,t)=>(0,d.jsxs)(`li`,{className:`daga-autocomplete-option ${t===s?`daga-focused`:``}`,onMouseMove:()=>w(t),onClick:()=>re(e),children:[(0,d.jsx)(`span`,{children:p[t]}),(0,d.jsx)(`span`,{className:`daga-match`,children:h[t]}),(0,d.jsx)(`span`,{children:_[t]})]},t))]})})]})},Mn=(e,t)=>e.find(e=>e.key===t)?.label||`${t}`,Nn=({disabled:e,allowRepeats:t,options:n,value:r,onChange:i})=>{let[a,o]=(0,u.useState)(),[s,c]=(0,u.useState)([]),[l,f]=(0,u.useState)([]),p=e=>{for(let t of r)if(t===e)return!0;return!1},m=()=>{if(!t){let e=[];for(let t of n)p(t.key)||e.push(t);f(e)}};(0,u.useEffect)(()=>{let e=r.length===0;c(r.map(e=>Mn(n,e))),e&&i(r),m()},[r,n]);let h=e=>{r.length>e&&(r.splice(e,1),c(s.filter((t,n)=>n!==e)),i(r),m())},g=()=>{a!==void 0&&(t||!p(a))&&(i(r.concat(a)),_())},_=()=>{o(``)};return(0,d.jsxs)(`div`,{children:[r.map((t,n)=>(0,d.jsxs)(`div`,{className:`daga-value-item-element`,children:[(0,d.jsx)(`span`,{className:`daga-input`,children:s[n]}),!e&&(0,d.jsx)(`button`,{className:`daga-property-button`,onClick:()=>h(n),children:(0,d.jsx)(`div`,{className:`daga-icon daga-close-icon`})})]},n)),!e&&(0,d.jsxs)(`div`,{className:`daga-value-item-input`,children:[(0,d.jsx)(`div`,{className:`daga-input daga-relatively-positioned`,children:(0,d.jsx)(jn,{disabled:e,options:t?n||[]:l||[],value:a,onChange:o})}),(0,d.jsx)(`button`,{className:`daga-property-button`,onClick:g,children:(0,d.jsx)(`div`,{className:`daga-icon daga-add-icon`})})]})]})},Pn=({disabled:e,allowRepeats:t,value:n,onChange:r})=>{let[i,a]=(0,u.useState)(``),o=e=>{for(let t of e||[])if(t===e)return!0;return!1},s=e=>{n.length>e&&r(n.filter((t,n)=>n!==e))},c=(e,t,i)=>{r(n.map((n,r)=>r===t?i===`blur`?e.trim():e:n))},l=()=>{let e=i.trim();e!==``&&(t||!o(e))&&(r(n.concat(e)),f())},f=()=>{a(``)};return(0,d.jsxs)(d.Fragment,{children:[n.map((t,n)=>(0,d.jsxs)(`div`,{className:`daga-value-item-element`,children:[(0,d.jsx)(`input`,{className:`daga-input`,disabled:e,value:t,onChange:e=>c(e.target.value,n,`change`),onBlur:e=>c(e.target.value,n,`blur`)}),(0,d.jsx)(`button`,{className:`daga-property-button`,onClick:()=>s(n),children:(0,d.jsx)(`div`,{className:`daga-icon daga-close-icon`})})]},n)),!e&&(0,d.jsxs)(`div`,{className:`daga-value-item-input`,children:[(0,d.jsxs)(`div`,{className:`daga-input daga-relatively-positioned`,children:[(0,d.jsx)(`input`,{type:`text`,onKeyUp:e=>{e.key===`Enter`&&l()},value:i,onChange:e=>a(e.target.value)}),(0,d.jsx)(`button`,{className:`daga-clear`,onClick:f})]}),(0,d.jsx)(`button`,{className:`daga-property-button`,onClick:l,children:(0,d.jsx)(`div`,{className:`daga-icon daga-add-icon`})})]})]})},Fn=({disabled:e,value:t,onChange:n})=>{let[r,i]=(0,u.useState)(``),[a,o]=(0,u.useState)(``),[s,c]=(0,u.useState)({}),l=e=>{let r={};Object.keys(t).forEach(n=>{n!==e&&(r[n]=t[n])}),n(r)},f=(e,r,i)=>{let a=i===`blur`?r.trim():r;if(i===`blur`){if(e!==a){let r={};Object.keys(t).forEach(n=>{n===e?r[a]=t[n]:r[n]=t[n]}),n(r),c(t=>{let n={...t};return delete n[e],n})}}else c(t=>({...t,[e]:r}))},p=(e,r,i)=>{let a=i===`blur`?r.trim():r;if(a!==``){let r={};Object.keys(t).forEach(n=>{n===e?r[n]=a:r[n]=t[n]}),n(r)}},m=()=>{let e=r.trim(),s=a.trim();if(e!==``&&s!==``){let r={};Object.keys(t).forEach(e=>{r[e]=t[e]}),r[e]=s,n(r),i(``),o(``)}},h=()=>{i(``)},g=()=>{o(``)},_=e=>{e.key===`Enter`&&m()};return(0,d.jsxs)(`div`,{children:[Object.entries(t).map(([t,n],r)=>(0,d.jsxs)(`div`,{className:`daga-value-item-element`,children:[(0,d.jsx)(`input`,{id:`key-${r}`,className:`daga-input`,type:`text`,disabled:e,value:s[t]??t,onChange:e=>f(t,e.target.value,`change`),onBlur:e=>f(t,e.target.value,`blur`)}),(0,d.jsx)(`input`,{id:`value-${r}`,className:`daga-input`,type:`text`,disabled:e,value:n,onChange:e=>p(t,e.target.value,`change`),onBlur:e=>p(t,e.target.value,`blur`)}),(0,d.jsx)(`button`,{className:`daga-property-button`,onClick:()=>l(t),children:(0,d.jsx)(`div`,{className:`daga-icon daga-close-icon`})})]},t)),!e&&(0,d.jsxs)(`div`,{className:`daga-value-item-input`,children:[(0,d.jsxs)(`div`,{className:`daga-input daga-relatively-positioned`,children:[(0,d.jsx)(`input`,{type:`text`,value:r,onKeyUp:_,onChange:e=>i(e.target.value),onBlur:e=>f(r,e.target.value,`blur`)}),(0,d.jsx)(`button`,{className:`daga-clear`,onClick:h})]}),(0,d.jsxs)(`div`,{className:`daga-input daga-relatively-positioned`,children:[(0,d.jsx)(`input`,{type:`text`,value:a,onKeyUp:_,onChange:e=>o(e.target.value),onBlur:e=>p(r,e.target.value,`blur`)}),(0,d.jsx)(`button`,{className:`daga-clear`,onClick:g})]}),(0,d.jsx)(`button`,{className:`daga-property-button`,onClick:m,children:(0,d.jsx)(`div`,{className:`daga-icon daga-add-icon`})})]})]})},In=({valueSet:e,onValueChange:t,depth:n})=>{let r=(0,u.useContext)(Tn).canUserPerformAction(G.UpdateValues)&&e?.rootElement?.removed!==!0,i=e=>`daga-property-name-`+e.replace(/\s/g,``),a=e=>{if(typeof e==`string`)return e;if(e==null||isNaN(e.valueOf()))return``;let t=new Date(e),n=t.getTimezoneOffset();return t.setMinutes(t.getMinutes()-n),t.toISOString().substring(0,19)},o=e=>new Date(e);return(0,d.jsx)(`daga-object-editor`,{children:e.displayedProperties.map(s=>(0,d.jsxs)(`div`,{className:`daga-property ${i(s.name)}`,children:[(0,d.jsx)(`p`,{className:`daga-property-name`,children:s.label||s.name}),s.type===j.Text&&(0,d.jsx)(`input`,{type:`daga-text`,disabled:s.editable===!1||!r,value:e?.getValue(s.name),onChange:n=>t(e,s,n.target.value)}),s.type===j.TextArea&&(0,d.jsx)(`textarea`,{disabled:s.editable===!1||!r,value:e?.getValue(s.name),onChange:n=>t(e,s,n.target.value)}),s.type===j.Number&&(0,d.jsx)(`input`,{type:`number`,disabled:s.editable===!1||!r,value:e?.getValue(s.name),onChange:n=>t(e,s,n.target.value)}),s.type===j.Color&&(0,d.jsx)(`input`,{type:`text`,pattern:`#[0-9a-fA-F]{6}`,disabled:s.editable===!1||!r,value:e?.getValue(s.name),onChange:n=>t(e,s,n.target.value)}),s.type===j.Datetime&&(0,d.jsx)(`input`,{type:`datetime-local`,disabled:s.editable===!1||!r,value:a(e?.getValue(s.name)),onChange:n=>t(e,s,o(n.target.value))}),s.type===j.Date&&(0,d.jsx)(`input`,{type:`date`,disabled:s.editable===!1||!r,value:e?.getValue(s.name),onChange:n=>t(e,s,n.target.value)}),s.type===j.Time&&(0,d.jsx)(`input`,{type:`time`,disabled:s.editable===!1||!r,value:e?.getValue(s.name),onChange:n=>t(e,s,n.target.value)}),s.type===j.Url&&(0,d.jsx)(`input`,{type:`url`,disabled:s.editable===!1||!r,value:e?.getValue(s.name),onChange:n=>t(e,s,n.target.value)}),s.type===j.Boolean&&(0,d.jsxs)(`div`,{className:`daga-radio`,children:[(0,d.jsxs)(`label`,{className:`daga-radio-item daga-radio-start`+(e?.getValue(s.name)===!1?` daga-checked`:``),children:[(0,d.jsx)(`input`,{type:`radio`,disabled:s.editable===!1||!r,name:s.name,value:`false`,checked:e?.getValue(s.name)===!1,onChange:()=>t(e,s,!1)}),`No`]}),(0,d.jsxs)(`label`,{className:`daga-radio-item daga-radio-end`+(e?.getValue(s.name)===!0?` daga-checked`:``),children:[(0,d.jsx)(`input`,{type:`radio`,disabled:s.editable===!1||!r,name:s.name,value:`true`,checked:e?.getValue(s.name)===!0,onChange:()=>t(e,s,!0)}),`Yes`]})]}),s.type===j.Option&&(0,d.jsx)(`div`,{className:`daga-relatively-positioned`,children:(0,d.jsx)(jn,{disabled:s.editable===!1||!r,options:s.options||[],value:e?.getValue(s.name),onChange:n=>t(e,s,n)})}),(s.type===j.OptionList||s.type===j.OptionSet)&&(0,d.jsx)(Nn,{disabled:s.editable===!1||!r,allowRepeats:s.type===j.OptionList,options:s.options||[],value:e?.getValue(s.name),onChange:n=>t(e,s,n)}),(s.type===j.TextList||s.type===j.TextSet)&&(0,d.jsx)(Pn,{disabled:s.editable===!1||!r,allowRepeats:s.type===j.TextList,value:e?.getValue(s.name),onChange:n=>t(e,s,n)}),s.type===j.TextMap&&(0,d.jsx)(Fn,{disabled:s.editable===!1||!r,value:e?.getValue(s.name),onChange:n=>t(e,s,n)}),s.type===j.Object&&(0,d.jsx)(`div`,{className:`daga-left-bar`,children:(0,d.jsx)(In,{valueSet:e.getSubValueSet(s.name),onValueChange:t,depth:n+1})})]},s.name))})},Ln=({valueSet:e,depth:t})=>{let n=(0,u.useContext)(Tn),r=(0,u.useRef)(null),i=e=>`daga-property-name-`+e.replace(/\s/g,``),a=()=>{for(let a of e?.displayedProperties||[]){let s=0,l=0,u=0,d=c.select(r.current).select(`.daga-property.${i(a.name)}.daga-depth-${t}`);d.select(`button.daga-move-button`).call(c.drag().on(C.Start,e=>{Y(D.Grabbing);let t=n.getPointerLocationRelativeToScreen(e);if(t.length<2||isNaN(t[0])||isNaN(t[1]))return;let r=d.node()?.getBoundingClientRect();s=r?.width||0,l=r?.height||0,d.style(`position`,`fixed`).style(`left`,`${t[0]-s/2}px`).style(`top`,`${t[1]-l/2}px`).style(`width`,`${s}px`).style(`height`,`${l}px`).style(`z-index`,1)}).on(C.Drag,e=>{Y(D.Grabbing);let i=n.getPointerLocationRelativeToScreen(e);i.length<2||isNaN(i[0])||isNaN(i[1])||(d.style(`position`,`fixed`).style(`left`,`${i[0]-s/2}px`).style(`top`,`${i[1]-l/2}px`).style(`width`,`${s}px`).style(`height`,`${l}px`).style(`z-index`,1),c.select(r.current).select(`.daga-dropbar.daga-index-${u}.daga-depth-${t}`).style(`visibility`,`hidden`).style(`height`,0),u=o(i),c.select(r.current).select(`.daga-dropbar.daga-index-${u}.daga-depth-${t}`).style(`visibility`,`visible`).style(`height`,`0.25rem`))}).on(C.End,i=>{Y(D.Auto),d.style(`position`,`relative`).style(`left`,0).style(`top`,0).style(`z-index`,0).style(`width`,`unset`).style(`height`,`unset`),c.select(r.current).select(`.daga-dropbar.daga-index-${u}.daga-depth-${t}`).style(`visibility`,`hidden`).style(`height`,0);let s=n.getPointerLocationRelativeToScreen(i);s.length<2||isNaN(s[0])||isNaN(s[1])||(u=o(s),e?.displayedProperties?.splice(e.displayedProperties.indexOf(a),1),e?.displayedProperties?.splice(u,0,a))}))}},o=n=>{let i=e?.propertySet.propertyList||[],a=[];for(let e=0;e<=i.length;++e){let n=c.select(r.current).select(`.daga-dropbar.daga-index-${e}.daga-depth-${t}`).node()?.getBoundingClientRect();n&&a.push([n.x+n.width/2,n.y+n.height/2])}if(a.length>0){let e=a.map(e=>((n[0]-e[0])**2+(n[1]-e[1])**2)**.5);return e.indexOf(Math.min(...e))}return 0},s=t=>{if(e===void 0)return;let n;n=t instanceof Oe?t:t instanceof Event?e?.propertySet.getProperty(t.target?.value||``):e?.propertySet.getProperty(t||``),n&&e?.hideProperty(n),a()};return(0,d.jsxs)(`daga-property-settings`,{ref:r,children:[(0,d.jsx)(`div`,{className:`daga-dropbar daga-index-0 daga-depth-${t}`}),e?.displayedProperties.map((n,r)=>(0,d.jsxs)(`div`,{className:`daga-property-and-dropbar ${i(n.name)} daga-depth-${t}`,children:[(0,d.jsxs)(`div`,{className:`daga-property ${i(n.name)} daga-depth-${t}`,children:[(0,d.jsxs)(`div`,{className:`daga-property-name`,children:[(0,d.jsx)(`span`,{children:n.label||n.name}),(0,d.jsxs)(`div`,{className:`daga-buttons`,children:[(0,d.jsx)(`button`,{className:`daga-property-button daga-move-button`,children:(0,d.jsx)(`div`,{className:`daga-icon daga-move-icon`})}),(0,d.jsx)(`button`,{className:`daga-property-button daga-hide-button`,onClick:()=>s(n.name),children:(0,d.jsx)(`div`,{className:`daga-icon daga-hide-icon`})})]})]}),n.type!==j.Object&&(0,d.jsx)(`div`,{className:`daga-property-value`,children:Rn(e?.getValue(n.name))}),n.type===j.Object&&(0,d.jsx)(Ln,{valueSet:e?.getSubValueSet(n.name),depth:t+1})]}),(0,d.jsx)(`div`,{className:`daga-dropbar daga-index-${r+1} daga-depth-${t}`})]},n.name))]})},Rn=e=>Array.isArray(e)?e.join(`, `):Pe(e)?Object.entries(e).map(e=>e.map(e=>JSON.stringify(e)).join(`: `)).join(`, `):e instanceof Date?e.toLocaleString():e==null?``:``+e,zn=({collapsed:e,location:t,direction:n,width:r,length:i,title:a,valueSet:o,onValueChange:s})=>{let l=(0,u.useRef)(null),[p,m]=(0,u.useState)(e),[h,g]=(0,u.useState)(!1),_=()=>c.select(l.current);return(0,u.useEffect)(()=>{if(l.current)switch(n){case f.Bottom:case f.Top:_().style(`width`,r).select(`.daga-panel-content`).style(`height`,i);break;case f.Left:case f.Right:_().style(`height`,r).select(`.daga-panel-content`).style(`width`,i);break}},[r,i,n]),(0,d.jsx)(`daga-property-editor`,{children:(0,d.jsxs)(`div`,{ref:l,className:`daga-panel daga-bottom daga-${t} daga-${n}`,children:[(0,d.jsx)(Dn,{disabled:!o||!o.propertySet||!o.propertySet.hasProperties(),collapsed:p,direction:n,collapsableSelector:l,collapsableAdditionalSelector:`.daga-panel-content`,rule:`display`,collapsedValue:`none`,visibleValue:`block`,onCollapse:m}),(0,d.jsx)(`div`,{className:`daga-panel-content`,children:o&&o.propertySet&&o.propertySet.hasProperties()&&!p&&(0,d.jsxs)(`div`,{children:[a&&(0,d.jsxs)(`p`,{className:`daga-title`,children:[a,(0,d.jsx)(`button`,{className:`daga-property-button`,onClick:()=>g(!h),children:(0,d.jsx)(`div`,{className:`daga-icon daga-settings-icon ${h?`daga-unrotate`:`daga-rotate`}`})})]}),!h&&(0,d.jsx)(In,{valueSet:o,onValueChange:s,depth:0}),h&&(0,d.jsx)(Ln,{valueSet:o,depth:0})]})})]})})},Bn=6,Vn=e=>{let t=(0,u.useContext)(Tn),[n,r]=(0,u.useState)(e.currentPalette||e.palettes[0]),[i,a]=(0,u.useState)(0),[o,s]=(0,u.useState)(void 0),l=(0,u.useRef)(null),p=(0,u.useRef)(!1),m=e=>{if(r(e),h().selectAll(`*`).remove(),a(t.getPriorityThreshold()||0),e.categories&&g(e.categories),e.templates)for(let t of e.templates)_(t)},h=()=>c.select(l.current).select(`.daga-palette-view`),g=e=>{let t=h().append(`select`).style(`width`,`100%`).style(`height`,`2rem`).style(`padding`,`0.5rem`).style(`border-radius`,`0.25rem`).style(`background-color`,`#f7f8fc`).style(`border`,`1px solid #e6e6e6`);t.append(`option`).attr(`value`,``).text(`(None selected)`);for(let n in e)t.append(`option`).attr(`value`,n).text(n);t.on(x.Change,()=>{o&&h().selectAll(`.daga-template-container.daga-in-category`).remove();let n=t.property(`value`);s(n);let r=e[n]||[];for(let e of r)_(e,`daga-in-category`)}),o&&(t.property(`value`,o),t.dispatch(x.Change))},_=(e,n)=>{if(e.templateType===`node`){let r=t.model.nodes.types.get(e.type);r?v(r,e,n):console.error(`Could not find a node type called '${e.type}'`)}else if(e.templateType===`connection`){let r=t.model.connections.types.get(e.type);r?y(r,e,n):console.error(`Could not find a connection type called '${e.type}'`)}},v=(e,n,r)=>{if(i!==void 0&&e.priority<i)return;let a=e.defaultLook.lookType===`shaped-look`?e.defaultLook.borderThickness||1:0,o=e.defaultHeight+a,s=e.defaultWidth+a,l=n.height||o,u=n.width||s,d=h().append(`div`).attr(`class`,`daga-template-container ${r===void 0?``:r}`).style(`width`,`${u}px`).style(`height`,`${l}px`).call(c.drag().on(C.Drag,e=>{if(t.canUserPerformAction(G.AddNode)){let n=t.getPointerLocationRelativeToScreen(e);if(n.length<2||isNaN(n[0])||isNaN(n[1]))return;d.style(`position`,`fixed`).style(`left`,`${n[0]-u/2}px`).style(`top`,`${n[1]-l/2}px`).style(`z-index`,1)}}).on(C.Start,n=>{if(t.canUserPerformAction(G.AddNode)){Y(D.Grabbing);let r=t.getPointerLocationRelativeToScreen(n);if(r.length<2||isNaN(r[0])||isNaN(r[1]))return;d.style(`position`,`fixed`).style(`left`,`${r[0]-u/2}px`).style(`top`,`${r[1]-l/2}px`).style(`z-index`,1),e.isUnique&&t.model.nodes.find(t=>!t.removed&&t.type.id===e.id)!==void 0&&Y(D.NotAllowed)}}).on(C.End,r=>{if(t.canUserPerformAction(G.AddNode)){if(Y(D.Auto),d.style(`position`,`relative`).style(`left`,0).style(`top`,0).style(`z-index`,`auto`),e.isUnique&&t.model.nodes.find(t=>!t.removed&&t.type.id===e.id)!==void 0)return;let i=t.getPointerLocationRelativeToScreen(r);if(i.length<2||isNaN(i[0])||isNaN(i[1]))return;let a=document.elementFromPoint(i[0],i[1]);if(a&&!t.selectCanvasView().node()?.contains(a))return;let o=t.getPointerLocationRelativeToCanvas(r);if(o.length<2||isNaN(o[0])||isNaN(o[1]))return;let s=[o[0]-e.defaultWidth/2,o[1]-e.defaultHeight/2];t.gridConfig.snap&&(s=t.getClosestGridPoint([s[0]-e.snapToGridOffset[0],s[1]-e.snapToGridOffset[1]]),s[0]+=e.snapToGridOffset[0],s[1]+=e.snapToGridOffset[1]);let c=Xe(t.model.nodes.getAtCoordinates(o[0],o[1]).filter(t=>t.type.childrenTypes.includes(e.id))),l=c[c.length-1];if(!e.canBeParentless&&l===void 0)return;let u=l?.getLastAncestor(),f=new Ct(t,e,s,l?.id,u?.id,u?.getGeometry(),void 0,n.label,n.values);f.do(),t?.actionStack.add(f),Y()}})).append(`svg`).attr(`class`,`palette-node ${e.id}`).attr(`viewBox`,`0 0 ${s} ${o}`).attr(`preserveAspectRatio`,`none`).style(`position`,`relative`).style(`left`,0).style(`top`,0).style(`width`,`${u}px`).style(`height`,`${l}px`),f=n.look||e.defaultLook;switch(f.lookType){case`shaped-look`:d.append(`path`).attr(`d`,se(f.shape||oe.Rectangle,(f.borderThickness||1)/2,(f.borderThickness||1)/2,e.defaultWidth,e.defaultHeight)).attr(`fill`,f.fillColor||`#FFFFFF`).attr(`stroke`,f.borderColor||`#000000`).attr(`stroke-width`,`${f.borderThickness}px`);break;case`image-look`:d.append(`image`).attr(`x`,0).attr(`y`,0).attr(`width`,e.defaultWidth).attr(`height`,e.defaultHeight).attr(`href`,f.backgroundImage).attr(`preserveAspectRatio`,`none`);break;case`stretchable-image-look`:d.append(`image`).attr(`x`,0).attr(`y`,0).attr(`width`,f.leftMargin).attr(`height`,f.topMargin).attr(`href`,f.backgroundImageTopLeft).attr(`preserveAspectRatio`,`none`),d.append(`image`).attr(`x`,f.leftMargin).attr(`y`,0).attr(`width`,e.defaultWidth-f.rightMargin-f.leftMargin).attr(`height`,f.topMargin).attr(`href`,f.backgroundImageTop).attr(`preserveAspectRatio`,`none`),d.append(`image`).attr(`x`,e.defaultWidth-f.rightMargin).attr(`y`,0).attr(`width`,f.rightMargin).attr(`height`,f.topMargin).attr(`href`,f.backgroundImageTopRight).attr(`preserveAspectRatio`,`none`),d.append(`image`).attr(`x`,0).attr(`y`,f.topMargin).attr(`width`,f.leftMargin).attr(`height`,e.defaultHeight-f.bottomMargin-f.topMargin).attr(`href`,f.backgroundImageLeft).attr(`preserveAspectRatio`,`none`),d.append(`image`).attr(`x`,f.leftMargin).attr(`y`,f.topMargin).attr(`width`,e.defaultWidth-f.rightMargin-f.leftMargin).attr(`height`,e.defaultHeight-f.bottomMargin-f.topMargin).attr(`href`,f.backgroundImageCenter).attr(`preserveAspectRatio`,`none`),d.append(`image`).attr(`x`,e.defaultWidth-f.rightMargin).attr(`y`,f.topMargin).attr(`width`,f.rightMargin).attr(`height`,e.defaultHeight-f.bottomMargin-f.topMargin).attr(`href`,f.backgroundImageRight).attr(`preserveAspectRatio`,`none`),d.append(`image`).attr(`x`,0).attr(`y`,e.defaultHeight-f.bottomMargin).attr(`width`,f.leftMargin).attr(`height`,f.bottomMargin).attr(`href`,f.backgroundImageBottomLeft).attr(`preserveAspectRatio`,`none`),d.append(`image`).attr(`x`,f.leftMargin).attr(`y`,e.defaultHeight-f.bottomMargin).attr(`width`,e.defaultWidth-f.rightMargin-f.leftMargin).attr(`height`,f.bottomMargin).attr(`href`,f.backgroundImageBottom).attr(`preserveAspectRatio`,`none`),d.append(`image`).attr(`x`,e.defaultWidth-f.rightMargin).attr(`y`,e.defaultHeight-f.bottomMargin).attr(`width`,f.rightMargin).attr(`height`,f.bottomMargin).attr(`href`,f.backgroundImageBottomRight).attr(`preserveAspectRatio`,`none`)}if(n.look===void 0){if(e.decorators)for(let t of e.decorators)d.append(`foreignObject`).attr(`width`,`${t.width}px`).attr(`height`,`${t.height}px`).attr(`transform`,`translate(${t.coords[0]},${t.coords[1]})`).html(t.svg);if(n.label){let t={...P,...e.label,...n.labelLook};t.look={...P.look,...t.look},d.append(`text`).attr(`transform`,`translate(${(L(t)+e.defaultWidth)/2},${(z(t)+e.defaultHeight)/2})`).attr(`x`,0).attr(`y`,0).attr(`font-size`,`${t.look.fontSize}px`).attr(`text-anchor`,`middle`).attr(`font-family`,t.look.fontFamily||P.look.fontFamily).attr(`font-weight`,t.look.fontWeight||P.look.fontWeight).attr(`fill`,t.look.fontColor||P.look.fontColor).attr(`stroke`,`none`).style(`font-kerning`,`none`).style(`user-select`,`none`).text(n.label)}}},y=(e,n,r)=>{let i=h().append(`div`).attr(`class`,`daga-template-container ${r===void 0?``:r}`).style(`width`,`${n.width}px`).style(`height`,`${n.height}px`).append(`svg`).attr(`class`,`palette-button ${e.id}`).style(`position`,`relative`).style(`left`,0).style(`top`,0).style(`width`,`100%`).style(`height`,`100%`).on(`click`,()=>{t.connectionType=e});i.append(`path`).attr(`d`,se(oe.Rectangle,0,0,n.width,n.height)).attr(`fill`,n.backgroundColor).attr(`stroke`,`black`).attr(`stroke-width`,`1px`),n.icon!==``&&i.append(`image`).attr(`x`,0).attr(`y`,0).attr(`width`,n.width).attr(`height`,n.height).attr(`href`,n.icon),n.label!==``&&i.append(`text`).attr(`transform`,`translate(${n.width/2},${n.height/2+Bn})`).attr(`x`,0).attr(`y`,0).attr(`font-size`,`20px`).attr(`text-anchor`,`middle`).attr(`font-family`,`'Wonder Unit Sans', sans-serif`).attr(`font-weight`,400).attr(`fill`,`#000000`).attr(`stroke`,`none`).style(`font-kerning`,`none`).style(`user-select`,`none`).text(n.label)};return(0,u.useEffect)(()=>{e.palettes.length>0&&!p.current&&(p.current=!0,m(e.palettes[0]))},[e.palettes]),(0,u.useEffect)(()=>{if(l.current)switch(e.direction){case f.Bottom:case f.Top:l.current.style.width=e.width,l.current.style.height=e.length;break;case f.Left:case f.Right:l.current.style.height=e.width,l.current.style.width=e.length;break}},[e.direction,e.width,e.length]),(0,d.jsx)(`daga-palette`,{children:(0,d.jsxs)(`div`,{ref:l,className:`daga-panel daga-${e.location} daga-${e.direction}`,children:[(0,d.jsx)(Dn,{direction:e.direction,collapsableSelector:l,collapsableAdditionalSelector:`.daga-panel-content`,rule:`display`,collapsedValue:`none`,visibleValue:`block`,collapsed:e.collapsed,disabled:!1}),(0,d.jsxs)(`div`,{className:`daga-panel-content`,children:[e.palettes.length>1&&(0,d.jsx)(`div`,{className:`daga-panel-tabs`,children:e.palettes.map(e=>(0,d.jsx)(`div`,{className:`daga-panel-tab ${e===n?`daga-current-tab`:``}`,onClick:()=>m(e),children:e.name}))}),(0,d.jsx)(`div`,{className:`daga-palette-view`})]})]})})},Hn=({location:e,direction:t,centerAnimationDuration:n,enableAction:r,enableFilter:i,enableLayout:a,enableSelection:o,enableZoom:s})=>{let l=!1,p=!0,m=!1,h,g,_,v;switch(t){case f.Bottom:h=`height`,g=`scaleY`,_=`top`,v=`bottom`;break;case f.Top:h=`height`,g=`scaleY`,_=`bottom`,v=`top`;break;case f.Left:h=`width`,g=`scaleX`,_=`right`,v=`left`;break;case f.Right:h=`width`,g=`scaleX`,_=`left`,v=`right`;break}let y=(0,u.useRef)(null),b=(0,u.useRef)(null),ee=(0,u.useRef)(null);(0,u.useEffect)(()=>{c.select(y.current).style(`margin-${v}`,`-1rem`).style(h,`0rem`).style(`transform`,`${g}(0)`).style(`transform-origin`,_)});let x=async()=>{let e=c.select(y.current);if(!m)if(p){p=!1;let t=`${4*e.selectChildren().size()}rem`;e.transition().duration(500).ease(c.easeLinear).style(h,t).style(`transform`,`${g}(1)`),setTimeout(()=>{m=!1},500)}else p=!0,e.transition().duration(500).ease(c.easeLinear).style(h,`0rem`).style(`transform`,`${g}(0)`),setTimeout(()=>{m=!1},500)},S=(0,u.useContext)(Tn);return(0,d.jsx)(`daga-diagram-buttons`,{children:(0,d.jsxs)(`div`,{className:`daga-diagram-buttons daga-${e} daga-${t}`,children:[s&&S.canUserPerformAction(G.Zoom)&&(0,d.jsx)(`button`,{className:`daga-zoom-in`,onClick:()=>{S.zoomBy(S.zoomFactor)},children:(0,d.jsx)(`span`,{className:`daga-tooltip`,children:`Zoom in`})}),s&&S.canUserPerformAction(G.Zoom)&&(0,d.jsx)(`button`,{className:`daga-zoom-out`,onClick:()=>{S.zoomBy(1/S.zoomFactor)},children:(0,d.jsx)(`span`,{className:`daga-tooltip`,children:`Zoom out`})}),(0,d.jsxs)(`div`,{className:`daga-collapsable-buttons daga-collapsed`,ref:y,children:[s&&S.canUserPerformAction(G.Zoom)&&(0,d.jsx)(`button`,{className:`daga-center`,onClick:()=>{S.center(void 0,1,n)},children:(0,d.jsx)(`span`,{className:`daga-tooltip`,children:`Fit diagram to screen`})}),r&&(0,d.jsx)(`button`,{className:`daga-undo`,onClick:()=>{S.actionStack.undo()},children:(0,d.jsx)(`span`,{className:`daga-tooltip`,children:`Undo`})}),r&&(0,d.jsx)(`button`,{className:`daga-redo`,onClick:()=>{S.actionStack.redo()},children:(0,d.jsx)(`span`,{className:`daga-tooltip`,children:`Redo`})}),o&&(0,d.jsx)(`button`,{className:`daga-copy`,onClick:()=>{S.userSelection.copyToClipboard()},children:(0,d.jsx)(`span`,{className:`daga-tooltip`,children:`Copy`})}),o&&(0,d.jsx)(`button`,{className:`daga-cut`,onClick:()=>{S.userSelection.cutToClipboard()},children:(0,d.jsx)(`span`,{className:`daga-tooltip`,children:`Cut`})}),o&&(0,d.jsx)(`button`,{className:`daga-multiple-selection ${l?`daga-on`:`daga-off`}`,onClick:()=>{S.multipleSelectionOn=!0,c.select(b.current).classed(`daga-on`,!0).classed(`daga-off`,!1);let e=S.diagramEvent$.subscribe(t=>{t.type===Mt.Selection&&(c.select(b.current).classed(`daga-on`,!1).classed(`daga-off`,!0),e.unsubscribe())})},ref:b,children:(0,d.jsx)(`span`,{className:`daga-tooltip`,children:`Multiple selection`})}),o&&(0,d.jsx)(`button`,{className:`daga-paste`,onClick:()=>{S.userSelection.pasteFromClipboard()},children:(0,d.jsx)(`span`,{className:`daga-tooltip`,children:`Paste`})}),o&&(0,d.jsx)(`button`,{className:`daga-delete`,onClick:()=>{S.userSelection.removeFromModel()},children:(0,d.jsx)(`span`,{className:`daga-tooltip`,children:`Delete`})}),a&&S.layoutFormat&&(0,d.jsx)(`button`,{className:`daga-layout`,onClick:()=>{S.layoutFormat&&S.layoutFormat in Cn&&Cn[S.layoutFormat].apply(S.model)},children:(0,d.jsx)(`span`,{className:`daga-tooltip`,children:`Apply layout`})}),i&&(0,d.jsx)(`button`,{className:`daga-filter ${l?`daga-on`:`daga-off`}`,onClick:()=>{l=!l,c.select(ee.current).classed(`daga-on`,l).classed(`daga-off`,!l);let e=S.getPriorityThresholdOptions();e&&e.length>=2&&S.setPriorityThreshold(e[+!!l])},ref:ee,children:(0,d.jsx)(`span`,{className:`daga-tooltip`,children:`Apply filter`})})]}),(0,d.jsx)(`button`,{className:`daga-more-options`,onClick:x,children:p?(0,d.jsx)(`span`,{className:`daga-tooltip`,children:`More options`}):(0,d.jsx)(`span`,{className:`daga-tooltip`,children:`Less options`})})]})})},Un=({config:e,model:t,onCanvasCreated:n,onDiagramEvent:r,onModelChange:i})=>{let a=new dt,o=new an,s=(0,u.useRef)(null),c=(0,u.useRef)(void 0),l=(0,u.useRef)(!1),m=[],[h,g]=(0,u.useState)(void 0),[_,v]=(0,u.useState)(void 0),y={zoomIn:()=>{},zoomOut:()=>{},center:()=>{},layout:()=>{},filter:()=>{},undo:()=>{},redo:()=>{}},b={refreshPalette:()=>{}},ee=new En(e=>g(e),e=>v(e)),x={diagramButtons:y,palette:b,propertyEditor:ee},S=(t=!1)=>{if((!c.current||t)&&(m.forEach(e=>e.unsubscribe()),c.current=new ln(x,e)),!c.current)throw Error(`Canvas could not be created`);return c.current},C=S(),w=e=>{C.initView(e),m.push(C.diagramEvent$.subscribe(e=>{r?.(e)})),m.push(C.diagramChange$.subscribe(()=>{let e=o.export(C.model);i?.(e)}))};return(0,u.useEffect)(()=>{s.current&&(l.current||(w(s.current),l.current=!0,n?.(C)))},[s.current]),(0,u.useEffect)(()=>{s.current&&(S(!0),w(s.current),n?.(C))},[e]),(0,u.useEffect)(()=>{t&&a.import(C.model,t)},[t]),(0,d.jsx)(`daga-diagram`,{children:(0,d.jsx)(wn.Provider,{value:e,children:(0,d.jsx)(Tn.Provider,{value:C,children:(0,d.jsxs)(`daga-diagram-editor`,{children:[(0,d.jsx)(`div`,{className:`daga-append-to`,ref:s}),(0,d.jsxs)(Tn.Provider,{value:C,children:[e.components?.buttons!==void 0&&e.components?.buttons?.enabled!==!1&&(0,d.jsx)(Hn,{location:e.components?.buttons?.location||p.BottomRight,direction:e.components?.buttons?.direction||f.Top,centerAnimationDuration:e.components?.buttons?.centerAnimationDuration,enableAction:e.components?.buttons?.enableAction!==!1,enableFilter:e.components?.buttons?.enableFilter===!0,enableLayout:e.components?.buttons?.enableLayout===!0,enableSelection:e.components?.buttons?.enableSelection!==!1,enableZoom:e.components?.buttons?.enableZoom!==!1}),e.components?.palette!==void 0&&e.components?.palette?.enabled!==!1&&e.components?.palette?.sections&&(e.components?.palette?.sections?.length||0)>0&&(0,d.jsx)(Vn,{collapsed:e.components?.palette?.open===!1,location:e.components?.palette?.location||p.TopLeft,direction:e.components?.palette?.direction||f.Bottom,width:e.components?.palette?.width||`12rem`,length:e.components?.palette?.length||`min-content`,gap:e.components?.palette?.gap||`1rem`,justifyContent:e.components?.palette?.justifyContent||`center`,palettes:e.components?.palette?.sections||[]}),e.components?.propertyEditor!==void 0&&e.components?.propertyEditor?.enabled!==!1&&(0,d.jsx)(zn,{collapsed:e.components?.propertyEditor?.open===!1,location:e.components?.propertyEditor?.location||p.TopRight,direction:e.components?.propertyEditor?.direction||f.Bottom,width:e.components?.propertyEditor?.width||`24rem`,length:e.components?.propertyEditor?.length||`min-content`,title:h,valueSet:_,onValueChange:(e,t,n)=>{if(_!==void 0&&t.editable!==!1&&!Me(e.getValue(t.name),n)){e.setValue(t.name,n);let r=new Fe(_.propertySet,void 0);r.setValues(_.getValues()),r.rootElement=_.rootElement,ee.valueSet=r,_.rootElement.valueSet=r,C.propertyEditorChanges$?.next()}}}),e.components?.errors!==void 0&&e.components?.errors?.enabled!==!1&&(0,d.jsx)(On,{})]})]})})})})};exports.DagaDiagram=Un;
|
|
4
|
+
`);t.html(``);for(let n=0;n<r.length;++n)t.append(`tspan`).attr(`x`,e.horizontalAlign===m.Center?e.width/2:e.horizontalAlign===m.Right?e.width:0).attr(`y`,e.verticalAlign===h.Center?(n+.5-r.length/2)*(e.look.fontSize||F.look.fontSize)+e.height/2:e.verticalAlign===h.Bottom?e.height-(r.length-n-1)*(e.look.fontSize||F.look.fontSize):n*(e.look.fontSize||F.look.fontSize)).text(r[n])}startMovingNode(e,t){if(this.canUserPerformAction(K.MoveNode)&&!t.removed)if(X(D.Grabbing),this.draggingFrom=[e.x,e.y],t.selected&&this.userSelection.count(e=>e instanceof U)>1)this.currentAction=new Et(this,this.userSelection.filter(e=>e instanceof U).map(e=>e.id),t.coords);else{let e=t.getLastAncestor();this.currentAction=new q(this,K.MoveNode,t.id,t.getGeometry(),t.getGeometry(),e?.id,e?.getGeometry(t.id),e?.getGeometry(t.id))}else X(D.NotAllowed)}continueMovingNode(e,t){if(this.canUserPerformAction(K.MoveNode)&&(this.currentAction instanceof Et||this.currentAction instanceof q)&&!t.removed){let n=[e.x-t.width/2,e.y-t.height/2];t.selected?this.userSelection.move([n[0]-t.coords[0],n[1]-t.coords[1]]):t.move(n),this.userHighlight.clear(),this.dragging=!0,this.diagramEvent$.next(new Rt(t))}}finishMovingNode(e,t){if(this.canUserPerformAction(K.MoveNode)&&!t.removed&&(this.draggingFrom[0]!==e.x||this.draggingFrom[1]!==e.y)){let n=[e.x-t.width/2,e.y-t.height/2];if(this.gridConfig?.snap&&(n=this.getClosestGridPoint([n[0]-t.type.snapToGridOffset[0],n[1]-t.type.snapToGridOffset[1]]),n[0]+=t.type.snapToGridOffset[0],n[1]+=t.type.snapToGridOffset[1]),this.currentAction instanceof Et){let e=this.currentAction.delta;this.currentAction.delta=[n[0]-e[0],n[1]-e[1]],t.selected?this.userSelection.move([e[0]-t.coords[0],e[1]-t.coords[1]]):t.move(e)}else if(this.currentAction instanceof q){t.move(n);let r=Qe(this.model.nodes.getAtCoordinates(e.x,e.y).filter(e=>e.id!==t.id&&!e.isDescendantOf(t)).filter(e=>e.type.childrenTypes.includes(t.type.id))),i=r[r.length-1];if(i!==t.parent&&(t.type.canBeParentless||i!==void 0)){let e=i?.getLastAncestor(),n=this.currentAction.from,r=new Dt(this,t.id,t.parent?.id,i?.id,n,t.getGeometry(),e?.id,e?.getGeometry(t.id),e?.getGeometry(t.id));t.parent?.removeChild(t),i!==void 0&&i.addChild(t),r.toChildGeometry=t.getGeometry(t.id),r.toAncestorGeometry=e?.getGeometry(t.id),this.currentAction=r}else{let e=t?.getLastAncestor();this.currentAction.ancestorId=e?.id,this.currentAction.fromAncestorGeometry=e?.getGeometry(t.id),t.parent?.fitToChild(t),this.currentAction.to=t.getGeometry(t.id),this.currentAction.toAncestorGeometry=e?.getGeometry(t.id)}}this.currentAction!==void 0&&(this.currentAction.do(),this.actionStack.add(this.currentAction),this.currentAction=void 0)}X(),this.dragging=!1}startMultipleSelection(e){this.draggingFrom=this.getPointerLocationRelativeToCanvas(e),this.multipleSelectionContainer=this.selectSVGElement().append(`rect`).attr(`stroke`,`#0E74B6`).attr(`fill`,`rgba(14, 116, 182, 0.06)`)}continueMultipleSelection(e){let t=this.getPointerLocationRelativeToCanvas(e);(this.draggingFrom[0]!==t[0]||this.draggingFrom[1]!==t[1])&&(X(D.Crosshair),this.multipleSelectionContainer?.attr(`x`,Math.min(this.draggingFrom[0],t[0])*this.zoomTransform.k+this.zoomTransform.x)?.attr(`y`,Math.min(this.draggingFrom[1],t[1])*this.zoomTransform.k+this.zoomTransform.y)?.attr(`width`,Math.abs(this.draggingFrom[0]-t[0])*this.zoomTransform.k)?.attr(`height`,Math.abs(this.draggingFrom[1]-t[1])*this.zoomTransform.k),this.dragging=!0)}finishMultipleSelection(e){let t=this.getPointerLocationRelativeToCanvas(e);this.multipleSelectionContainer?.remove(),this.multipleSelectionContainer=void 0,this.userSelection.clear();for(let e of this.model.nodes)ee([e.coords,[e.coords[0]+e.width,e.coords[1]+e.height]],[this.draggingFrom,t])&&this.userSelection.add(e);this.multipleSelectionOn=!1,this.diagramEvent$.next(new J(this.userSelection.all(),!0)),X()}},mn=class{constructor(){this.grid=[[void 0]],this.offsetX=0,this.offsetY=0}minX(){return-this.offsetX}maxX(){return this.width()-1-this.offsetX}minY(){return-this.offsetY}maxY(){return this.height()-1-this.offsetY}width(){return this.grid[0].length}height(){return this.grid.length}addColumnLeft(){for(let e of this.grid)e.splice(0,0,void 0);this.offsetX+=1}addColumnRight(){for(let e of this.grid)e.push(void 0)}addRowTop(){let e=[];for(let t=0;t<this.grid[0].length;++t)e.push(void 0);this.grid.splice(0,0,e),this.offsetY+=1}addRowBottom(){let e=[];for(let t=0;t<this.grid[0].length;++t)e.push(void 0);this.grid.push(e)}get(e){if(this.grid[e[1]+this.offsetY])return this.grid[e[1]+this.offsetY][e[0]+this.offsetX]}set(e,t){for(;e[0]<-this.offsetX;)this.addColumnLeft();for(;e[0]>=this.width()-this.offsetX;)this.addColumnRight();for(;e[1]<-this.offsetY;)this.addRowTop();for(;e[1]>=this.height()-this.offsetY;)this.addRowBottom();this.grid[e[1]+this.offsetY][e[0]+this.offsetX]=t}getClosestEmptyCoordinate(e){if(this.get(e)===void 0)return e;let t=[...e];for(let e=1;;++e){let n=e%2>0?e:-e,r=n>0?1:-1,i=[t[0]+n,t[1]+n];for(let e=t[0];e!==i[0]+r;e+=r)if(t[0]=e,this.get(t)===void 0)return t;for(let e=t[1];e!==i[1]+r;e+=r)if(t[1]=e,this.get(t)===void 0)return t}}},hn=class{constructor(e){this.gapSize=e}apply(e){if(e.nodes.length===0)return e;let t=new mn,n=e.nodes.filter(e=>!e.parent);for(;n.length>0;)gn(n[0],t,[0,0],n);let r=Math.max(...e.nodes.map(e=>e.width)),i=Math.max(...e.nodes.map(e=>e.height)),a=this.gapSize===void 0?e.canvas?.gridConfig?Z(e.canvas?.gridConfig)*2:0:this.gapSize,o=this.gapSize===void 0?e.canvas?.gridConfig?Q(e.canvas?.gridConfig)*2:0:this.gapSize;for(let e=t.minY();e<=t.maxY();++e)for(let n=t.minX();n<=t.maxX();++n){let s=t.get([n,e]);s!==void 0&&s.move([n*(r+a),e*(i+o)])}return e}},gn=(e,t,n,r)=>{let i=t.getClosestEmptyCoordinate(n);t.set(i,e),E(r,e);for(let n of e.getAdjacentNodes())r.includes(n)&&gn(n,t,i,r)},_n=class{constructor(e){this.gapSize=e}apply(e){if(e.nodes.length===0)return e;let t=new mn,n=e.nodes.filter(e=>!e.parent),r={},i=n[0],a=[i];for(r[i.id]=[0,0];n.length>0;){let e=[];for(let i of a){t.set(t.getClosestEmptyCoordinate(r[i.id]),i),E(n,i);let a=i.getAdjacentNodes();for(let t of a)n.includes(t)&&(e.push(t),r[t.id]=r[i.id])}if(e.length>0)a=e;else if(n.length>0){let e=n[0];a=[e],r[e.id]=t.getClosestEmptyCoordinate([0,0])}}let o=Math.max(...e.nodes.map(e=>e.width)),s=Math.max(...e.nodes.map(e=>e.height)),c=this.gapSize===void 0?e.canvas?.gridConfig?Z(e.canvas?.gridConfig)*2:0:this.gapSize,l=this.gapSize===void 0?e.canvas?.gridConfig?Q(e.canvas?.gridConfig)*2:0:this.gapSize;for(let e=t.minY();e<=t.maxY();++e)for(let n=t.minX();n<=t.maxX();++n){let r=t.get([n,e]);r!==void 0&&r.move([n*(o+c),e*(s+l)])}return e}},vn=class{constructor(e){this.gapSize=e}apply(e){if(e.nodes.length===0)return e;let t=this.gapSize===void 0?e.canvas?.gridConfig?Z(e.canvas?.gridConfig)*2:0:this.gapSize,n=this.gapSize===void 0?e.canvas?.gridConfig?Q(e.canvas?.gridConfig)*2:0:this.gapSize,r=e.nodes.filter(e=>!e.parent),i=r[0];E(r,i);let a=[[i]];for(;r.length>0;){let e=a[a.length-1],t=[];for(let n of e){let e=n.getAdjacentNodes();for(let n of e)r.includes(n)&&(E(r,n),t.push(n))}t.length>0?a.push(t):(a.push(r),r=[])}let o=0;for(let e of a){let r=0;for(let t of e)t.move([o,r]),r+=n+t.height;let i=Math.max(...e.map(e=>e.width));o+=t+i}for(let t of e.connections)t.tighten();return e}},yn=class{constructor(e){this.gapSize=e}apply(e){if(e.nodes.length===0)return e;new vn(this.gapSize).apply(e);let t=this.gapSize===void 0?e.canvas?.gridConfig?Z(e.canvas?.gridConfig)*2:0:this.gapSize,n=this.gapSize===void 0?e.canvas?.gridConfig?Q(e.canvas?.gridConfig)*2:0:this.gapSize,r=Math.max(t,n),i=.1,a=.5,o=.002,s=100;for(;s>1;){s*=.99;let t=[0,0];for(let n of e.nodes)t[0]=t[0]+n.coords[0]+n.width/2,t[1]=t[1]+n.coords[1]+n.width/2;t[0]/=e.nodes.length,t[1]/=e.nodes.length;for(let n of e.nodes){let c=n.getAdjacentNodes();for(let l of e.nodes){let e=[n.coords[0]+n.width/2,n.coords[1]+n.height/2],u=[l.coords[0]+l.width/2,l.coords[1]+l.height/2],d=b(n.coords,l.coords),f=[l.coords[0],l.coords[1]];if(c.includes(l)&&d>0&&(d>r+(Math.max(n.width,n.height)+Math.max(l.width,l.height))/2?(f[0]-=(u[0]-e[0])*i,f[1]-=(u[1]-e[1])*i):(f[0]+=(u[0]-e[0])*a,f[1]+=(u[1]-e[1])*a)),d>0){let t=2e5/(d*d);f[0]+=t*(u[0]-e[0])/d,f[1]+=t*(u[1]-e[1])/d}else f[0]+=1*(Math.random()*2-1),f[1]+=1*(Math.random()*2-1);f[0]-=(u[0]-t[0])*o,f[1]-=(u[1]-t[1])*o,f[0]-l.coords[0]>s?f[0]=l.coords[0]+s:f[0]-l.coords[0]<-s&&(f[0]=l.coords[0]-s),f[1]-l.coords[1]>s?f[1]=l.coords[1]+s:f[1]-l.coords[1]<-s&&(f[1]=l.coords[1]-s),l.move(f)}}}if(e.canvas&&e.canvas.gridConfig.snap)for(let t of e.nodes){let n=e.canvas.getClosestGridPoint([t.coords[0]-t.type.snapToGridOffset[0],t.coords[1]-t.type.snapToGridOffset[1]]);n[0]+=t.type.snapToGridOffset[0],n[1]+=t.type.snapToGridOffset[1],t.move(n)}for(let t of e.connections)t.tighten();return e}},bn=class{constructor(e){this.gapSize=e}apply(e){if(e.nodes.length===0)return e;let t=this.gapSize===void 0?e.canvas?.gridConfig?Z(e.canvas?.gridConfig)*2:0:this.gapSize,n=e.nodes.filter(e=>!e.parent);n.sort((e,t)=>t.type.priority-e.type.priority);let r=0;for(let e of n)e.move([r,0]),r+=e.width+t;return e}},xn=class{constructor(e){this.gapSize=e}apply(e){if(e.nodes.length===0)return e;let t=Math.max(...e.nodes.map(e=>e.getPriority()));if(t===Math.min(...e.nodes.map(e=>e.getPriority())))return new vn(this.gapSize).apply(e),e;let n=this.gapSize===void 0?e.canvas?.gridConfig?Z(e.canvas?.gridConfig)*2:0:this.gapSize,r=this.gapSize===void 0?e.canvas?.gridConfig?Q(e.canvas?.gridConfig)*2:0:this.gapSize,i=e.nodes.filter(e=>!e.parent),a=[],o=e.nodes.filter(e=>!e.parent).filter(e=>e.getPriority()>=t),s=[];if(o.length>1){let e=o[0];o.splice(0,1),s.push(e);let t=[e],n=[e];for(;t.length>0;){let e=t[0];t.splice(0,1),o.includes(e)&&(s.push(e),E(o,e));let r=e.getAdjacentNodes();for(let e of r)n.includes(e)||(t.push(e),n.push(e))}for(let e of o)s.push(e)}else s.push(o[0]);for(let e of s)E(i,e),a.push([e]);for(a.push([]),i.sort((e,t)=>t.type.priority-e.type.priority);i.length>0;){let e=i[0];i.splice(0,1);let t=[e],n=[e],r=!1;for(;t.length>0;){let i=t[0];t.splice(0,1);let o=s.indexOf(i);if(o>=0){a[o].push(e),r=!0;break}else{let e=i.getAdjacentNodes();for(let r of e)n.includes(r)||(t.push(r),n.push(r))}}r||a[a.length-1].push(e)}let c=0;for(let e=0;e<a.length;++e){let t=0;for(let n=0;n<a[e].length;++n){let i=a[e][n];i.move([c,t]),t+=r+i.height}let i=Math.max(...a[e].map(e=>e.width));c+=n+i}for(let t of e.connections)t.tighten();return e}},Sn=class{constructor(e){this.gapSize=e}apply(e){if(e.nodes.length===0)return e;if(Math.max(...e.nodes.map(e=>e.getPriority()))===Math.min(...e.nodes.map(e=>e.getPriority())))return new vn(this.gapSize).apply(e),e;let t=this.gapSize===void 0?e.canvas?.gridConfig?Z(e.canvas?.gridConfig)*2:0:this.gapSize,n=this.gapSize===void 0?e.canvas?.gridConfig?Q(e.canvas?.gridConfig)*2:0:this.gapSize,r=e.nodes.filter(e=>!e.parent).sort((e,t)=>t.getPriority()-e.getPriority()),i=[];for(;r.length>0;){let e=r[0];r.splice(0,1);let t=new Tn(void 0,e);Cn(t,r),i.push(t)}let a=[];for(let e of i)a.push([e]),wn(e,a,a.length);let o=Math.max(...e.nodes.map(e=>e.height)),s=0;for(let e=0;e<a.length;++e){let r=0;for(let t=0;t<a[e].length;++t){let i=a[e][t];i.node.move([s,r]),r+=(n+o)*i.countBranchHeight()}let i=Math.max(...a[e].map(e=>e.node.width));s+=t+i}for(let t of e.connections)t.tighten();return e}},Cn=(e,t)=>{for(let n of e.node.getAdjacentNodes().sort((e,t)=>t.getPriority()-e.getPriority())){let r=t.indexOf(n);r>=0&&(t.splice(r,1),Cn(e.addBranch(n),t))}},wn=(e,t,n)=>{if(e.branches.length>0){for(;n>=t.length;)t.push([]);for(let r of e.branches)t[n].push(r),wn(r,t,n+1)}},Tn=class e{constructor(e,t){this.parent=e,this.branches=[],this.depth=0,this.node=t}addBranch(t){let n=new e(this,t);return n.depth=this.depth+1,this.branches.push(n),n}countBranchHeight(){if(this.branches.length<=0)return 1;{let e=0;for(let t of this.branches)e+=t.countBranchHeight();return e}}},En=class{constructor(e){this.gapSize=e}apply(e){if(e.nodes.length===0)return e;let t=this.gapSize===void 0?e.canvas?.gridConfig?Q(e.canvas?.gridConfig)*2:0:this.gapSize,n=e.nodes.filter(e=>!e.parent);n.sort((e,t)=>t.type.priority-e.type.priority);let r=0;for(let e of n)e.move([0,r]),r+=e.height+t;return e}},Dn={adjacency:new hn,breadth:new vn,"breadth-adjacency":new _n,force:new yn,horizontal:new bn,priority:new xn,tree:new Sn,vertical:new En},On=(0,u.createContext)({}),kn=(0,u.createContext)({}),An=class{constructor(e,t){this.onTitleChange=e,this.onValueSetChange=t}get title(){return this._title}set title(e){this._title=e,this.onTitleChange(e)}get valueSet(){return this._valueSet}set valueSet(e){this._valueSet=e,this.onValueSetChange(e)}highlightProperty(...e){}},jn=({direction:e,collapsableSelector:t,collapsableAdditionalSelector:n,collapsed:r,disabled:i,rule:a,collapsedValue:o,visibleValue:s,onCollapse:l})=>{let[p,m]=(0,u.useState)(r),h=e=>{let r;if(typeof t==`string`)r=c.select(t),n&&(r=r.select(n));else{let e=t;if(!e)throw Error(`collapsableSelector is not a valid ref`);r=c.select(e.current),n&&(r=r.select(n))}r.style(a,e?o:s)};return(0,u.useEffect)(()=>{h(p)},[h,p]),(0,d.jsx)(`daga-collapse-button`,{children:(0,d.jsx)(`button`,{className:`daga-collapse-button daga-${e}`,onClick:()=>{if(!i){let e=!p;m(e),l?.(e),h(e)}},children:(0,d.jsx)(`div`,{className:(()=>{switch(e){case f.Right:return i?`daga-horizontal-none`:p?`daga-horizontal-right`:`daga-horizontal-left`;case f.Bottom:return i?`daga-vertical-none`:p?`daga-vertical-down`:`daga-vertical-up`;case f.Left:return i?`daga-horizontal-none`:p?`daga-horizontal-left`:`daga-horizontal-right`;case f.Top:return i?`daga-vertical-none`:p?`daga-vertical-up`:`daga-vertical-down`}})()})})})},Mn=()=>{let e=(0,u.useContext)(kn),t=(0,u.useRef)(null),[n,r]=(0,u.useState)([]);(0,l.merge)(e.validatorChange$,e.diagramChange$).pipe((0,l.map)(()=>i())).subscribe();let i=()=>{r([]);for(let t of e.validators)r(t.validate(e.model))},a=t=>{if(t.elementId&&(t.propertyNames===void 0||t.propertyNames.length===0)){let n=e.model.nodes.get(t.elementId)||e.model.connections.get(t.elementId);n&&e.userHighlight.add(n)}else if(t.elementId&&t.propertyNames!==void 0&&t.propertyNames.length>0){e.userSelection.openInPropertyEditor(e.model.nodes.get(t.elementId)||e.model.connections.get(t.elementId));let n=e.model.nodes.get(t.elementId)||e.model.connections.get(t.elementId);n&&e.userHighlight.add(n),e.parentComponent?.propertyEditor?.highlightProperty(...t.propertyNames)}else !t.elementId&&t.propertyNames!==void 0&&t.propertyNames.length>0&&(e.userSelection.openInPropertyEditor(),e.parentComponent?.propertyEditor?.highlightProperty(...t.propertyNames))};return(0,d.jsx)(`daga-errors`,{children:(0,d.jsxs)(`div`,{ref:t,className:`daga-errors`,children:[n.length===0&&(0,d.jsx)(`div`,{className:`daga-errors-summary daga-no-errors daga-prevent-user-select`,children:(0,d.jsx)(`span`,{children:`No errors found`})}),n.length>0&&(0,d.jsxs)(`div`,{className:`daga-errors-summary daga-with-errors daga-prevent-user-select`,children:[(0,d.jsxs)(`span`,{children:[n.length,` errors found`]}),(0,d.jsx)(`div`,{className:`daga-collapse-button-container`,children:(0,d.jsx)(jn,{collapsableSelector:t,collapsableAdditionalSelector:`.daga-error-panel`,direction:f.Top,rule:`display`,collapsedValue:`none`,visibleValue:`block`,collapsed:!1,disabled:!1})})]}),n.length>0&&(0,d.jsx)(`div`,{className:`daga-error-panel`,children:(0,d.jsx)(`ol`,{children:n.map((e,t)=>(0,d.jsx)(`li`,{onClick:()=>a(e),dangerouslySetInnerHTML:{__html:e.message}},t))})})]})})},Nn=200,Pn=e=>(e||``).toLowerCase().normalize(`NFD`).replace(/[\u0300-\u036f]/g,``),Fn=({disabled:e,options:t,value:n,onChange:r})=>{let i=(0,u.useRef)(null),[a,o]=(0,u.useState)(``),[s,c]=(0,u.useState)(void 0),[l,f]=(0,u.useState)([]),[p,m]=(0,u.useState)([]),[h,g]=(0,u.useState)([]),[_,v]=(0,u.useState)([]),[y,b]=(0,u.useState)(!1);(0,u.useEffect)(()=>{o(t.find(e=>Ae(e.key,n))?.label||``)},[n,t]);let ee=n=>{if(!e)switch(n.key){case S.PageDown:s===void 0?(w(0),T(0)):(w(s+5),T(s)),n.preventDefault();break;case S.ArrowDown:s===void 0?(w(0),T(0)):(w(s+1),T(s)),n.preventDefault();break;case S.PageUp:s===void 0?(w(t.length-1),T(t.length-1)):(w(s-5),T(s)),n.preventDefault();break;case S.ArrowUp:s===void 0?(w(t.length-1),T(t.length-1)):(w(s-1),T(s)),n.preventDefault();break;case S.Escape:C(),n.preventDefault();break;case S.Enter:re(t[s||0]),n.preventDefault();break;default:x()}},x=()=>{if(!e){let e=Pn(a.trim());f([]),m([]),g([]),v([]);for(let n of t){let t=Pn(n.label).indexOf(e);if(t>=0){let r=n.label.substring(0,t),i=n.label.substring(t,t+e.length),a=n.label.substring(t+e.length);f(e=>[...e,n]),m(e=>[...e,r]),g(e=>[...e,i]),v(e=>[...e,a])}}b(!0)}},C=()=>{b(!1)},w=n=>{if(!e){let e=n;if(n===void 0){c(void 0);return}n<0&&(e=0),n>=t.length&&(e=t.length-1),c(e)}},te=()=>{setTimeout(()=>{C()},Nn)},T=e=>{let t=i.current?.querySelectorAll(`li`)[e];t&&t.scrollIntoView({block:`center`})},ne=()=>{e||(o(``),b(!1),c(void 0))},re=t=>{e||(o(t.label),b(!1),c(void 0),r(t.key))};return(0,d.jsxs)(`div`,{ref:i,className:`daga-autocomplete ${y?`daga-showing-options`:``}`,children:[(0,d.jsxs)(`div`,{className:`daga-autocomplete-input`,children:[(0,d.jsx)(`input`,{value:a,disabled:e,onKeyUp:ee,onFocus:x,onBlur:te,onChange:e=>o(e.target.value)}),a!==``&&(0,d.jsx)(`button`,{className:`daga-clear`,onClick:ne})]}),(0,d.jsx)(`div`,{className:`daga-autocomplete-options`,children:(0,d.jsxs)(`ul`,{className:`daga-autocomplete-option-list`,children:[l.length===0&&(0,d.jsx)(`li`,{className:`daga-autocomplete-option no-options`,children:`(No options)`}),l.map((e,t)=>(0,d.jsxs)(`li`,{className:`daga-autocomplete-option ${t===s?`daga-focused`:``}`,onMouseMove:()=>w(t),onClick:()=>re(e),children:[(0,d.jsx)(`span`,{children:p[t]}),(0,d.jsx)(`span`,{className:`daga-match`,children:h[t]}),(0,d.jsx)(`span`,{children:_[t]})]},t))]})})]})},In=(e,t)=>e.find(e=>e.key===t)?.label||`${t}`,Ln=({disabled:e,allowRepeats:t,options:n,value:r,onChange:i})=>{let[a,o]=(0,u.useState)(),[s,c]=(0,u.useState)([]),[l,f]=(0,u.useState)([]),p=e=>{for(let t of r)if(t===e)return!0;return!1},m=()=>{if(!t){let e=[];for(let t of n)p(t.key)||e.push(t);f(e)}};(0,u.useEffect)(()=>{let e=r.length===0;c(r.map(e=>In(n,e))),e&&i(r),m()},[r,n]);let h=e=>{r.length>e&&(r.splice(e,1),c(s.filter((t,n)=>n!==e)),i(r),m())},g=()=>{a!==void 0&&(t||!p(a))&&(i(r.concat(a)),_())},_=()=>{o(``)};return(0,d.jsxs)(`div`,{children:[r.map((t,n)=>(0,d.jsxs)(`div`,{className:`daga-value-item-element`,children:[(0,d.jsx)(`span`,{className:`daga-input`,children:s[n]}),!e&&(0,d.jsx)(`button`,{className:`daga-property-button`,onClick:()=>h(n),children:(0,d.jsx)(`div`,{className:`daga-icon daga-close-icon`})})]},n)),!e&&(0,d.jsxs)(`div`,{className:`daga-value-item-input`,children:[(0,d.jsx)(`div`,{className:`daga-input daga-relatively-positioned`,children:(0,d.jsx)(Fn,{disabled:e,options:t?n||[]:l||[],value:a,onChange:o})}),(0,d.jsx)(`button`,{className:`daga-property-button`,onClick:g,children:(0,d.jsx)(`div`,{className:`daga-icon daga-add-icon`})})]})]})},Rn=({disabled:e,allowRepeats:t,value:n,onChange:r})=>{let[i,a]=(0,u.useState)(``),o=e=>{for(let t of e||[])if(t===e)return!0;return!1},s=e=>{n.length>e&&r(n.filter((t,n)=>n!==e))},c=(e,t,i)=>{r(n.map((n,r)=>r===t?i===`blur`?e.trim():e:n))},l=()=>{let e=i.trim();e!==``&&(t||!o(e))&&(r(n.concat(e)),f())},f=()=>{a(``)};return(0,d.jsxs)(d.Fragment,{children:[n.map((t,n)=>(0,d.jsxs)(`div`,{className:`daga-value-item-element`,children:[(0,d.jsx)(`input`,{className:`daga-input`,disabled:e,value:t,onChange:e=>c(e.target.value,n,`change`),onBlur:e=>c(e.target.value,n,`blur`)}),(0,d.jsx)(`button`,{className:`daga-property-button`,onClick:()=>s(n),children:(0,d.jsx)(`div`,{className:`daga-icon daga-close-icon`})})]},n)),!e&&(0,d.jsxs)(`div`,{className:`daga-value-item-input`,children:[(0,d.jsxs)(`div`,{className:`daga-input daga-relatively-positioned`,children:[(0,d.jsx)(`input`,{type:`text`,onKeyUp:e=>{e.key===`Enter`&&l()},value:i,onChange:e=>a(e.target.value)}),(0,d.jsx)(`button`,{className:`daga-clear`,onClick:f})]}),(0,d.jsx)(`button`,{className:`daga-property-button`,onClick:l,children:(0,d.jsx)(`div`,{className:`daga-icon daga-add-icon`})})]})]})},zn=({disabled:e,value:t,onChange:n})=>{let[r,i]=(0,u.useState)(``),[a,o]=(0,u.useState)(``),[s,c]=(0,u.useState)({}),l=e=>{let r={};Object.keys(t).forEach(n=>{n!==e&&(r[n]=t[n])}),n(r)},f=(e,r,i)=>{let a=i===`blur`?r.trim():r;if(i===`blur`){if(e!==a){let r={};Object.keys(t).forEach(n=>{n===e?r[a]=t[n]:r[n]=t[n]}),n(r),c(t=>{let n={...t};return delete n[e],n})}}else c(t=>({...t,[e]:r}))},p=(e,r,i)=>{let a=i===`blur`?r.trim():r;if(a!==``){let r={};Object.keys(t).forEach(n=>{n===e?r[n]=a:r[n]=t[n]}),n(r)}},m=()=>{let e=r.trim(),s=a.trim();if(e!==``&&s!==``){let r={};Object.keys(t).forEach(e=>{r[e]=t[e]}),r[e]=s,n(r),i(``),o(``)}},h=()=>{i(``)},g=()=>{o(``)},_=e=>{e.key===`Enter`&&m()};return(0,d.jsxs)(`div`,{children:[Object.entries(t).map(([t,n],r)=>(0,d.jsxs)(`div`,{className:`daga-value-item-element`,children:[(0,d.jsx)(`input`,{id:`key-${r}`,className:`daga-input`,type:`text`,disabled:e,value:s[t]??t,onChange:e=>f(t,e.target.value,`change`),onBlur:e=>f(t,e.target.value,`blur`)}),(0,d.jsx)(`input`,{id:`value-${r}`,className:`daga-input`,type:`text`,disabled:e,value:n,onChange:e=>p(t,e.target.value,`change`),onBlur:e=>p(t,e.target.value,`blur`)}),(0,d.jsx)(`button`,{className:`daga-property-button`,onClick:()=>l(t),children:(0,d.jsx)(`div`,{className:`daga-icon daga-close-icon`})})]},t)),!e&&(0,d.jsxs)(`div`,{className:`daga-value-item-input`,children:[(0,d.jsxs)(`div`,{className:`daga-input daga-relatively-positioned`,children:[(0,d.jsx)(`input`,{type:`text`,value:r,onKeyUp:_,onChange:e=>i(e.target.value),onBlur:e=>f(r,e.target.value,`blur`)}),(0,d.jsx)(`button`,{className:`daga-clear`,onClick:h})]}),(0,d.jsxs)(`div`,{className:`daga-input daga-relatively-positioned`,children:[(0,d.jsx)(`input`,{type:`text`,value:a,onKeyUp:_,onChange:e=>o(e.target.value),onBlur:e=>p(r,e.target.value,`blur`)}),(0,d.jsx)(`button`,{className:`daga-clear`,onClick:g})]}),(0,d.jsx)(`button`,{className:`daga-property-button`,onClick:m,children:(0,d.jsx)(`div`,{className:`daga-icon daga-add-icon`})})]})]})},Bn=({valueSet:e,onValueChange:t,depth:n})=>{let r=(0,u.useContext)(kn).canUserPerformAction(K.UpdateValues)&&e?.rootElement?.removed!==!0,i=e=>`daga-property-name-`+e.replace(/\s/g,``),a=e=>{if(typeof e==`string`)return e;if(e==null||isNaN(e.valueOf()))return``;let t=new Date(e),n=t.getTimezoneOffset();return t.setMinutes(t.getMinutes()-n),t.toISOString().substring(0,19)},o=e=>new Date(e);return(0,d.jsx)(`daga-object-editor`,{children:e.displayedProperties.map(s=>(0,d.jsxs)(`div`,{className:`daga-property ${i(s.name)}`,children:[(0,d.jsx)(`p`,{className:`daga-property-name`,children:s.label||s.name}),s.type===A.Text&&(0,d.jsx)(`input`,{type:`daga-text`,disabled:s.editable===!1||!r,value:e?.getValue(s.name),onChange:n=>t(e,s,n.target.value)}),s.type===A.TextArea&&(0,d.jsx)(`textarea`,{disabled:s.editable===!1||!r,value:e?.getValue(s.name),onChange:n=>t(e,s,n.target.value)}),s.type===A.Number&&(0,d.jsx)(`input`,{type:`number`,disabled:s.editable===!1||!r,value:e?.getValue(s.name),onChange:n=>t(e,s,n.target.value)}),s.type===A.Color&&(0,d.jsx)(`input`,{type:`text`,pattern:`#[0-9a-fA-F]{6}`,disabled:s.editable===!1||!r,value:e?.getValue(s.name),onChange:n=>t(e,s,n.target.value)}),s.type===A.Datetime&&(0,d.jsx)(`input`,{type:`datetime-local`,disabled:s.editable===!1||!r,value:a(e?.getValue(s.name)),onChange:n=>t(e,s,o(n.target.value))}),s.type===A.Date&&(0,d.jsx)(`input`,{type:`date`,disabled:s.editable===!1||!r,value:e?.getValue(s.name),onChange:n=>t(e,s,n.target.value)}),s.type===A.Time&&(0,d.jsx)(`input`,{type:`time`,disabled:s.editable===!1||!r,value:e?.getValue(s.name),onChange:n=>t(e,s,n.target.value)}),s.type===A.Url&&(0,d.jsx)(`input`,{type:`url`,disabled:s.editable===!1||!r,value:e?.getValue(s.name),onChange:n=>t(e,s,n.target.value)}),s.type===A.Boolean&&(0,d.jsxs)(`div`,{className:`daga-radio`,children:[(0,d.jsxs)(`label`,{className:`daga-radio-item daga-radio-start`+(e?.getValue(s.name)===!1?` daga-checked`:``),children:[(0,d.jsx)(`input`,{type:`radio`,disabled:s.editable===!1||!r,name:s.name,value:`false`,checked:e?.getValue(s.name)===!1,onChange:()=>t(e,s,!1)}),`No`]}),(0,d.jsxs)(`label`,{className:`daga-radio-item daga-radio-end`+(e?.getValue(s.name)===!0?` daga-checked`:``),children:[(0,d.jsx)(`input`,{type:`radio`,disabled:s.editable===!1||!r,name:s.name,value:`true`,checked:e?.getValue(s.name)===!0,onChange:()=>t(e,s,!0)}),`Yes`]})]}),s.type===A.Option&&(0,d.jsx)(`div`,{className:`daga-relatively-positioned`,children:(0,d.jsx)(Fn,{disabled:s.editable===!1||!r,options:s.options||[],value:e?.getValue(s.name),onChange:n=>t(e,s,n)})}),(s.type===A.OptionList||s.type===A.OptionSet)&&(0,d.jsx)(Ln,{disabled:s.editable===!1||!r,allowRepeats:s.type===A.OptionList,options:s.options||[],value:e?.getValue(s.name),onChange:n=>t(e,s,n)}),(s.type===A.TextList||s.type===A.TextSet)&&(0,d.jsx)(Rn,{disabled:s.editable===!1||!r,allowRepeats:s.type===A.TextList,value:e?.getValue(s.name),onChange:n=>t(e,s,n)}),s.type===A.TextMap&&(0,d.jsx)(zn,{disabled:s.editable===!1||!r,value:e?.getValue(s.name),onChange:n=>t(e,s,n)}),s.type===A.Object&&(0,d.jsx)(`div`,{className:`daga-left-bar`,children:(0,d.jsx)(Bn,{valueSet:e.getSubValueSet(s.name),onValueChange:t,depth:n+1})})]},s.name))})},Vn=({valueSet:e,depth:t})=>{let n=(0,u.useContext)(kn),r=(0,u.useRef)(null),i=e=>`daga-property-name-`+e.replace(/\s/g,``),a=()=>{for(let a of e?.displayedProperties||[]){let s=0,l=0,u=0,d=c.select(r.current).select(`.daga-property.${i(a.name)}.daga-depth-${t}`);d.select(`button.daga-move-button`).call(c.drag().on(C.Start,e=>{X(D.Grabbing);let t=n.getPointerLocationRelativeToScreen(e);if(t.length<2||isNaN(t[0])||isNaN(t[1]))return;let r=d.node()?.getBoundingClientRect();s=r?.width||0,l=r?.height||0,d.style(`position`,`fixed`).style(`left`,`${t[0]-s/2}px`).style(`top`,`${t[1]-l/2}px`).style(`width`,`${s}px`).style(`height`,`${l}px`).style(`z-index`,1)}).on(C.Drag,e=>{X(D.Grabbing);let i=n.getPointerLocationRelativeToScreen(e);i.length<2||isNaN(i[0])||isNaN(i[1])||(d.style(`position`,`fixed`).style(`left`,`${i[0]-s/2}px`).style(`top`,`${i[1]-l/2}px`).style(`width`,`${s}px`).style(`height`,`${l}px`).style(`z-index`,1),c.select(r.current).select(`.daga-dropbar.daga-index-${u}.daga-depth-${t}`).style(`visibility`,`hidden`).style(`height`,0),u=o(i),c.select(r.current).select(`.daga-dropbar.daga-index-${u}.daga-depth-${t}`).style(`visibility`,`visible`).style(`height`,`0.25rem`))}).on(C.End,i=>{X(D.Auto),d.style(`position`,`relative`).style(`left`,0).style(`top`,0).style(`z-index`,0).style(`width`,`unset`).style(`height`,`unset`),c.select(r.current).select(`.daga-dropbar.daga-index-${u}.daga-depth-${t}`).style(`visibility`,`hidden`).style(`height`,0);let s=n.getPointerLocationRelativeToScreen(i);s.length<2||isNaN(s[0])||isNaN(s[1])||(u=o(s),e?.displayedProperties?.splice(e.displayedProperties.indexOf(a),1),e?.displayedProperties?.splice(u,0,a))}))}},o=n=>{let i=e?.propertySet.propertyList||[],a=[];for(let e=0;e<=i.length;++e){let n=c.select(r.current).select(`.daga-dropbar.daga-index-${e}.daga-depth-${t}`).node()?.getBoundingClientRect();n&&a.push([n.x+n.width/2,n.y+n.height/2])}if(a.length>0){let e=a.map(e=>((n[0]-e[0])**2+(n[1]-e[1])**2)**.5);return e.indexOf(Math.min(...e))}return 0},s=t=>{if(e===void 0)return;let n;n=t instanceof Ee?t:t instanceof Event?e?.propertySet.getProperty(t.target?.value||``):e?.propertySet.getProperty(t||``),n&&e?.hideProperty(n),a()};return(0,d.jsxs)(`daga-property-settings`,{ref:r,children:[(0,d.jsx)(`div`,{className:`daga-dropbar daga-index-0 daga-depth-${t}`}),e?.displayedProperties.map((n,r)=>(0,d.jsxs)(`div`,{className:`daga-property-and-dropbar ${i(n.name)} daga-depth-${t}`,children:[(0,d.jsxs)(`div`,{className:`daga-property ${i(n.name)} daga-depth-${t}`,children:[(0,d.jsxs)(`div`,{className:`daga-property-name`,children:[(0,d.jsx)(`span`,{children:n.label||n.name}),(0,d.jsxs)(`div`,{className:`daga-buttons`,children:[(0,d.jsx)(`button`,{className:`daga-property-button daga-move-button`,children:(0,d.jsx)(`div`,{className:`daga-icon daga-move-icon`})}),(0,d.jsx)(`button`,{className:`daga-property-button daga-hide-button`,onClick:()=>s(n.name),children:(0,d.jsx)(`div`,{className:`daga-icon daga-hide-icon`})})]})]}),n.type!==A.Object&&(0,d.jsx)(`div`,{className:`daga-property-value`,children:Hn(e?.getValue(n.name))}),n.type===A.Object&&(0,d.jsx)(Vn,{valueSet:e?.getSubValueSet(n.name),depth:t+1})]}),(0,d.jsx)(`div`,{className:`daga-dropbar daga-index-${r+1} daga-depth-${t}`})]},n.name))]})},Hn=e=>Array.isArray(e)?e.join(`, `):Me(e)?Object.entries(e).map(e=>e.map(e=>JSON.stringify(e)).join(`: `)).join(`, `):e instanceof Date?e.toLocaleString():e==null?``:``+e,Un=({collapsed:e,location:t,direction:n,width:r,length:i,title:a,valueSet:o,onValueChange:s})=>{let l=(0,u.useRef)(null),[p,m]=(0,u.useState)(e),[h,g]=(0,u.useState)(!1),_=()=>c.select(l.current);return(0,u.useEffect)(()=>{if(l.current)switch(n){case f.Bottom:case f.Top:_().style(`width`,r).select(`.daga-panel-content`).style(`height`,i);break;case f.Left:case f.Right:_().style(`height`,r).select(`.daga-panel-content`).style(`width`,i);break}},[r,i,n]),(0,d.jsx)(`daga-property-editor`,{children:(0,d.jsxs)(`div`,{ref:l,className:`daga-panel daga-bottom daga-${t} daga-${n}`,children:[(0,d.jsx)(jn,{disabled:!o||!o.propertySet||!o.propertySet.hasProperties(),collapsed:p,direction:n,collapsableSelector:l,collapsableAdditionalSelector:`.daga-panel-content`,rule:`display`,collapsedValue:`none`,visibleValue:`block`,onCollapse:m}),(0,d.jsx)(`div`,{className:`daga-panel-content`,children:o&&o.propertySet&&o.propertySet.hasProperties()&&!p&&(0,d.jsxs)(`div`,{children:[a&&(0,d.jsxs)(`p`,{className:`daga-title`,children:[a,(0,d.jsx)(`button`,{className:`daga-property-button`,onClick:()=>g(!h),children:(0,d.jsx)(`div`,{className:`daga-icon daga-settings-icon ${h?`daga-unrotate`:`daga-rotate`}`})})]}),!h&&(0,d.jsx)(Bn,{valueSet:o,onValueChange:s,depth:0}),h&&(0,d.jsx)(Vn,{valueSet:o,depth:0})]})})]})})},Wn=6,Gn=e=>{let t=(0,u.useContext)(kn),[n,r]=(0,u.useState)(e.currentPalette||e.palettes[0]),[i,a]=(0,u.useState)(0),[o,s]=(0,u.useState)(void 0),l=(0,u.useRef)(null),p=(0,u.useRef)(!1),m=e=>{if(r(e),h().selectAll(`*`).remove(),a(t.getPriorityThreshold()||0),e.categories&&g(e.categories),e.templates)for(let t of e.templates)_(t)},h=()=>c.select(l.current).select(`.daga-palette-view`),g=e=>{let t=h().append(`select`).style(`width`,`100%`).style(`height`,`2rem`).style(`padding`,`0.5rem`).style(`border-radius`,`0.25rem`).style(`background-color`,`#f7f8fc`).style(`border`,`1px solid #e6e6e6`);t.append(`option`).attr(`value`,``).text(`(None selected)`);for(let n in e)t.append(`option`).attr(`value`,n).text(n);t.on(x.Change,()=>{o&&h().selectAll(`.daga-template-container.daga-in-category`).remove();let n=t.property(`value`);s(n);let r=e[n]||[];for(let e of r)_(e,`daga-in-category`)}),o&&(t.property(`value`,o),t.dispatch(x.Change))},_=(e,n)=>{if(e.templateType===`node`){let r=t.model.nodes.types.get(e.type);r?v(r,e,n):console.error(`Could not find a node type called '${e.type}'`)}else if(e.templateType===`connection`){let r=t.model.connections.types.get(e.type);r?y(r,e,n):console.error(`Could not find a connection type called '${e.type}'`)}},v=(e,n,r)=>{if(i!==void 0&&e.priority<i)return;let a=e.defaultLook.lookType===`shaped-look`?e.defaultLook.borderThickness||1:0,o=e.defaultHeight+a,s=e.defaultWidth+a,l=n.height||o,u=n.width||s,d=h().append(`div`).attr(`class`,`daga-template-container ${r===void 0?``:r}`).style(`width`,`${u}px`).style(`height`,`${l}px`).call(c.drag().on(C.Drag,e=>{if(t.canUserPerformAction(K.AddNode)){let n=t.getPointerLocationRelativeToScreen(e);if(n.length<2||isNaN(n[0])||isNaN(n[1]))return;d.style(`position`,`fixed`).style(`left`,`${n[0]-u/2}px`).style(`top`,`${n[1]-l/2}px`).style(`z-index`,1)}}).on(C.Start,n=>{if(t.canUserPerformAction(K.AddNode)){X(D.Grabbing);let r=t.getPointerLocationRelativeToScreen(n);if(r.length<2||isNaN(r[0])||isNaN(r[1]))return;d.style(`position`,`fixed`).style(`left`,`${r[0]-u/2}px`).style(`top`,`${r[1]-l/2}px`).style(`z-index`,1),e.isUnique&&t.model.nodes.find(t=>!t.removed&&t.type.id===e.id)!==void 0&&X(D.NotAllowed)}}).on(C.End,r=>{if(t.canUserPerformAction(K.AddNode)){if(X(D.Auto),d.style(`position`,`relative`).style(`left`,0).style(`top`,0).style(`z-index`,`auto`),e.isUnique&&t.model.nodes.find(t=>!t.removed&&t.type.id===e.id)!==void 0)return;let i=t.getPointerLocationRelativeToScreen(r);if(i.length<2||isNaN(i[0])||isNaN(i[1]))return;let a=document.elementFromPoint(i[0],i[1]);if(a&&!t.selectCanvasView().node()?.contains(a))return;let o=t.getPointerLocationRelativeToCanvas(r);if(o.length<2||isNaN(o[0])||isNaN(o[1]))return;let s=[o[0]-e.defaultWidth/2,o[1]-e.defaultHeight/2];t.gridConfig.snap&&(s=t.getClosestGridPoint([s[0]-e.snapToGridOffset[0],s[1]-e.snapToGridOffset[1]]),s[0]+=e.snapToGridOffset[0],s[1]+=e.snapToGridOffset[1]);let c=Qe(t.model.nodes.getAtCoordinates(o[0],o[1]).filter(t=>t.type.childrenTypes.includes(e.id))),l=c[c.length-1];if(!e.canBeParentless&&l===void 0)return;let u=l?.getLastAncestor(),f=new Tt(t,e,s,l?.id,u?.id,u?.getGeometry(),void 0,n.label,n.values);f.do(),t?.actionStack.add(f),X()}})).append(`svg`).attr(`class`,`palette-node ${e.id}`).attr(`viewBox`,`0 0 ${s} ${o}`).attr(`preserveAspectRatio`,`none`).style(`position`,`relative`).style(`left`,0).style(`top`,0).style(`width`,`${u}px`).style(`height`,`${l}px`),f=n.look||e.defaultLook;switch(f.lookType){case`shaped-look`:d.append(`path`).attr(`d`,se(f.shape||oe.Rectangle,(f.borderThickness||1)/2,(f.borderThickness||1)/2,e.defaultWidth,e.defaultHeight)).attr(`fill`,f.fillColor||`#FFFFFF`).attr(`stroke`,f.borderColor||`#000000`).attr(`stroke-width`,`${f.borderThickness}px`);break;case`image-look`:d.append(`image`).attr(`x`,0).attr(`y`,0).attr(`width`,e.defaultWidth).attr(`height`,e.defaultHeight).attr(`href`,f.backgroundImage).attr(`preserveAspectRatio`,`none`);break;case`stretchable-image-look`:d.append(`image`).attr(`x`,0).attr(`y`,0).attr(`width`,f.leftMargin).attr(`height`,f.topMargin).attr(`href`,f.backgroundImageTopLeft).attr(`preserveAspectRatio`,`none`),d.append(`image`).attr(`x`,f.leftMargin).attr(`y`,0).attr(`width`,e.defaultWidth-f.rightMargin-f.leftMargin).attr(`height`,f.topMargin).attr(`href`,f.backgroundImageTop).attr(`preserveAspectRatio`,`none`),d.append(`image`).attr(`x`,e.defaultWidth-f.rightMargin).attr(`y`,0).attr(`width`,f.rightMargin).attr(`height`,f.topMargin).attr(`href`,f.backgroundImageTopRight).attr(`preserveAspectRatio`,`none`),d.append(`image`).attr(`x`,0).attr(`y`,f.topMargin).attr(`width`,f.leftMargin).attr(`height`,e.defaultHeight-f.bottomMargin-f.topMargin).attr(`href`,f.backgroundImageLeft).attr(`preserveAspectRatio`,`none`),d.append(`image`).attr(`x`,f.leftMargin).attr(`y`,f.topMargin).attr(`width`,e.defaultWidth-f.rightMargin-f.leftMargin).attr(`height`,e.defaultHeight-f.bottomMargin-f.topMargin).attr(`href`,f.backgroundImageCenter).attr(`preserveAspectRatio`,`none`),d.append(`image`).attr(`x`,e.defaultWidth-f.rightMargin).attr(`y`,f.topMargin).attr(`width`,f.rightMargin).attr(`height`,e.defaultHeight-f.bottomMargin-f.topMargin).attr(`href`,f.backgroundImageRight).attr(`preserveAspectRatio`,`none`),d.append(`image`).attr(`x`,0).attr(`y`,e.defaultHeight-f.bottomMargin).attr(`width`,f.leftMargin).attr(`height`,f.bottomMargin).attr(`href`,f.backgroundImageBottomLeft).attr(`preserveAspectRatio`,`none`),d.append(`image`).attr(`x`,f.leftMargin).attr(`y`,e.defaultHeight-f.bottomMargin).attr(`width`,e.defaultWidth-f.rightMargin-f.leftMargin).attr(`height`,f.bottomMargin).attr(`href`,f.backgroundImageBottom).attr(`preserveAspectRatio`,`none`),d.append(`image`).attr(`x`,e.defaultWidth-f.rightMargin).attr(`y`,e.defaultHeight-f.bottomMargin).attr(`width`,f.rightMargin).attr(`height`,f.bottomMargin).attr(`href`,f.backgroundImageBottomRight).attr(`preserveAspectRatio`,`none`)}if(n.look===void 0){if(e.decorators)for(let t of e.decorators)d.append(`foreignObject`).attr(`width`,`${t.width}px`).attr(`height`,`${t.height}px`).attr(`transform`,`translate(${t.coords[0]},${t.coords[1]})`).html(t.svg);if(n.label){let t={...F,...e.label,...n.labelLook};t.look={...F.look,...t.look},d.append(`text`).attr(`transform`,`translate(${(R(t)+e.defaultWidth)/2},${(B(t)+e.defaultHeight)/2})`).attr(`x`,0).attr(`y`,0).attr(`font-size`,`${t.look.fontSize}px`).attr(`text-anchor`,`middle`).attr(`font-family`,t.look.fontFamily||F.look.fontFamily).attr(`font-weight`,t.look.fontWeight||F.look.fontWeight).attr(`fill`,t.look.fontColor||F.look.fontColor).attr(`stroke`,`none`).style(`font-kerning`,`none`).style(`user-select`,`none`).text(n.label)}}},y=(e,n,r)=>{let i=h().append(`div`).attr(`class`,`daga-template-container ${r===void 0?``:r}`).style(`width`,`${n.width}px`).style(`height`,`${n.height}px`).append(`svg`).attr(`class`,`palette-button ${e.id}`).style(`position`,`relative`).style(`left`,0).style(`top`,0).style(`width`,`100%`).style(`height`,`100%`).on(`click`,()=>{t.connectionType=e});i.append(`path`).attr(`d`,se(oe.Rectangle,0,0,n.width,n.height)).attr(`fill`,n.backgroundColor).attr(`stroke`,`black`).attr(`stroke-width`,`1px`),n.icon!==``&&i.append(`image`).attr(`x`,0).attr(`y`,0).attr(`width`,n.width).attr(`height`,n.height).attr(`href`,n.icon),n.label!==``&&i.append(`text`).attr(`transform`,`translate(${n.width/2},${n.height/2+Wn})`).attr(`x`,0).attr(`y`,0).attr(`font-size`,`20px`).attr(`text-anchor`,`middle`).attr(`font-family`,`'Wonder Unit Sans', sans-serif`).attr(`font-weight`,400).attr(`fill`,`#000000`).attr(`stroke`,`none`).style(`font-kerning`,`none`).style(`user-select`,`none`).text(n.label)};return(0,u.useEffect)(()=>{e.palettes.length>0&&!p.current&&(p.current=!0,m(e.palettes[0]))},[e.palettes]),(0,u.useEffect)(()=>{if(l.current)switch(e.direction){case f.Bottom:case f.Top:l.current.style.width=e.width,l.current.style.height=e.length;break;case f.Left:case f.Right:l.current.style.height=e.width,l.current.style.width=e.length;break}},[e.direction,e.width,e.length]),(0,d.jsx)(`daga-palette`,{children:(0,d.jsxs)(`div`,{ref:l,className:`daga-panel daga-${e.location} daga-${e.direction}`,children:[(0,d.jsx)(jn,{direction:e.direction,collapsableSelector:l,collapsableAdditionalSelector:`.daga-panel-content`,rule:`display`,collapsedValue:`none`,visibleValue:`block`,collapsed:e.collapsed,disabled:!1}),(0,d.jsxs)(`div`,{className:`daga-panel-content`,children:[e.palettes.length>1&&(0,d.jsx)(`div`,{className:`daga-panel-tabs`,children:e.palettes.map(e=>(0,d.jsx)(`div`,{className:`daga-panel-tab ${e===n?`daga-current-tab`:``}`,onClick:()=>m(e),children:e.name}))}),(0,d.jsx)(`div`,{className:`daga-palette-view`})]})]})})},Kn=({location:e,direction:t,centerAnimationDuration:n,enableAction:r,enableFilter:i,enableLayout:a,enableSelection:o,enableZoom:s})=>{let l=!1,p=!0,m=!1,h,g,_,v;switch(t){case f.Bottom:h=`height`,g=`scaleY`,_=`top`,v=`bottom`;break;case f.Top:h=`height`,g=`scaleY`,_=`bottom`,v=`top`;break;case f.Left:h=`width`,g=`scaleX`,_=`right`,v=`left`;break;case f.Right:h=`width`,g=`scaleX`,_=`left`,v=`right`;break}let y=(0,u.useRef)(null),b=(0,u.useRef)(null),ee=(0,u.useRef)(null);(0,u.useEffect)(()=>{c.select(y.current).style(`margin-${v}`,`-1rem`).style(h,`0rem`).style(`transform`,`${g}(0)`).style(`transform-origin`,_)});let x=async()=>{let e=c.select(y.current);if(!m)if(p){p=!1;let t=`${4*e.selectChildren().size()}rem`;e.transition().duration(500).ease(c.easeLinear).style(h,t).style(`transform`,`${g}(1)`),setTimeout(()=>{m=!1},500)}else p=!0,e.transition().duration(500).ease(c.easeLinear).style(h,`0rem`).style(`transform`,`${g}(0)`),setTimeout(()=>{m=!1},500)},S=(0,u.useContext)(kn);return(0,d.jsx)(`daga-diagram-buttons`,{children:(0,d.jsxs)(`div`,{className:`daga-diagram-buttons daga-${e} daga-${t}`,children:[s&&S.canUserPerformAction(K.Zoom)&&(0,d.jsx)(`button`,{className:`daga-zoom-in`,onClick:()=>{S.zoomBy(S.zoomFactor)},children:(0,d.jsx)(`span`,{className:`daga-tooltip`,children:`Zoom in`})}),s&&S.canUserPerformAction(K.Zoom)&&(0,d.jsx)(`button`,{className:`daga-zoom-out`,onClick:()=>{S.zoomBy(1/S.zoomFactor)},children:(0,d.jsx)(`span`,{className:`daga-tooltip`,children:`Zoom out`})}),(0,d.jsxs)(`div`,{className:`daga-collapsable-buttons daga-collapsed`,ref:y,children:[s&&S.canUserPerformAction(K.Zoom)&&(0,d.jsx)(`button`,{className:`daga-center`,onClick:()=>{S.center(void 0,1,n)},children:(0,d.jsx)(`span`,{className:`daga-tooltip`,children:`Fit diagram to screen`})}),r&&(0,d.jsx)(`button`,{className:`daga-undo`,onClick:()=>{S.actionStack.undo()},children:(0,d.jsx)(`span`,{className:`daga-tooltip`,children:`Undo`})}),r&&(0,d.jsx)(`button`,{className:`daga-redo`,onClick:()=>{S.actionStack.redo()},children:(0,d.jsx)(`span`,{className:`daga-tooltip`,children:`Redo`})}),o&&(0,d.jsx)(`button`,{className:`daga-copy`,onClick:()=>{S.userSelection.copyToClipboard()},children:(0,d.jsx)(`span`,{className:`daga-tooltip`,children:`Copy`})}),o&&(0,d.jsx)(`button`,{className:`daga-cut`,onClick:()=>{S.userSelection.cutToClipboard()},children:(0,d.jsx)(`span`,{className:`daga-tooltip`,children:`Cut`})}),o&&(0,d.jsx)(`button`,{className:`daga-multiple-selection ${l?`daga-on`:`daga-off`}`,onClick:()=>{S.multipleSelectionOn=!0,c.select(b.current).classed(`daga-on`,!0).classed(`daga-off`,!1);let e=S.diagramEvent$.subscribe(t=>{t.type===Pt.Selection&&(c.select(b.current).classed(`daga-on`,!1).classed(`daga-off`,!0),e.unsubscribe())})},ref:b,children:(0,d.jsx)(`span`,{className:`daga-tooltip`,children:`Multiple selection`})}),o&&(0,d.jsx)(`button`,{className:`daga-paste`,onClick:()=>{S.userSelection.pasteFromClipboard()},children:(0,d.jsx)(`span`,{className:`daga-tooltip`,children:`Paste`})}),o&&(0,d.jsx)(`button`,{className:`daga-delete`,onClick:()=>{S.userSelection.removeFromModel()},children:(0,d.jsx)(`span`,{className:`daga-tooltip`,children:`Delete`})}),a&&S.layoutFormat&&(0,d.jsx)(`button`,{className:`daga-layout`,onClick:()=>{S.layoutFormat&&S.layoutFormat in Dn&&Dn[S.layoutFormat].apply(S.model)},children:(0,d.jsx)(`span`,{className:`daga-tooltip`,children:`Apply layout`})}),i&&(0,d.jsx)(`button`,{className:`daga-filter ${l?`daga-on`:`daga-off`}`,onClick:()=>{l=!l,c.select(ee.current).classed(`daga-on`,l).classed(`daga-off`,!l);let e=S.getPriorityThresholdOptions();e&&e.length>=2&&S.setPriorityThreshold(e[+!!l])},ref:ee,children:(0,d.jsx)(`span`,{className:`daga-tooltip`,children:`Apply filter`})})]}),(0,d.jsx)(`button`,{className:`daga-more-options`,onClick:x,children:p?(0,d.jsx)(`span`,{className:`daga-tooltip`,children:`More options`}):(0,d.jsx)(`span`,{className:`daga-tooltip`,children:`Less options`})})]})})},qn=({config:e,model:t,onCanvasCreated:n,onDiagramEvent:r,onModelChange:i})=>{let a=new pt,o=new ln,s=(0,u.useRef)(null),c=(0,u.useRef)(void 0),l=(0,u.useRef)(!1),m=[],[h,g]=(0,u.useState)(void 0),[_,v]=(0,u.useState)(void 0),y={zoomIn:()=>{},zoomOut:()=>{},center:()=>{},layout:()=>{},filter:()=>{},undo:()=>{},redo:()=>{}},b={refreshPalette:()=>{}},ee=new An(e=>g(e),e=>v(e)),x={diagramButtons:y,palette:b,propertyEditor:ee},S=(t=!1)=>{if((!c.current||t)&&(m.forEach(e=>e.unsubscribe()),c.current=new pn(x,e)),!c.current)throw Error(`Canvas could not be created`);return c.current},C=S(),w=e=>{C.initView(e),m.push(C.diagramEvent$.subscribe(e=>{r?.(e)})),m.push(C.diagramChange$.subscribe(()=>{let e=o.export(C.model);i?.(e)}))};return(0,u.useEffect)(()=>{s.current&&(l.current||(w(s.current),l.current=!0,n?.(C)))},[s.current]),(0,u.useEffect)(()=>{s.current&&(S(!0),w(s.current),n?.(C))},[e]),(0,u.useEffect)(()=>{t&&a.import(C.model,t)},[t]),(0,d.jsx)(`daga-diagram`,{children:(0,d.jsx)(On.Provider,{value:e,children:(0,d.jsx)(kn.Provider,{value:C,children:(0,d.jsxs)(`daga-diagram-editor`,{children:[(0,d.jsx)(`div`,{className:`daga-append-to`,ref:s}),(0,d.jsxs)(kn.Provider,{value:C,children:[e.components?.buttons!==void 0&&e.components?.buttons?.enabled!==!1&&(0,d.jsx)(Kn,{location:e.components?.buttons?.location||p.BottomRight,direction:e.components?.buttons?.direction||f.Top,centerAnimationDuration:e.components?.buttons?.centerAnimationDuration,enableAction:e.components?.buttons?.enableAction!==!1,enableFilter:e.components?.buttons?.enableFilter===!0,enableLayout:e.components?.buttons?.enableLayout===!0,enableSelection:e.components?.buttons?.enableSelection!==!1,enableZoom:e.components?.buttons?.enableZoom!==!1}),e.components?.palette!==void 0&&e.components?.palette?.enabled!==!1&&e.components?.palette?.sections&&(e.components?.palette?.sections?.length||0)>0&&(0,d.jsx)(Gn,{collapsed:e.components?.palette?.open===!1,location:e.components?.palette?.location||p.TopLeft,direction:e.components?.palette?.direction||f.Bottom,width:e.components?.palette?.width||`12rem`,length:e.components?.palette?.length||`min-content`,gap:e.components?.palette?.gap||`1rem`,justifyContent:e.components?.palette?.justifyContent||`center`,palettes:e.components?.palette?.sections||[]}),e.components?.propertyEditor!==void 0&&e.components?.propertyEditor?.enabled!==!1&&(0,d.jsx)(Un,{collapsed:e.components?.propertyEditor?.open===!1,location:e.components?.propertyEditor?.location||p.TopRight,direction:e.components?.propertyEditor?.direction||f.Bottom,width:e.components?.propertyEditor?.width||`24rem`,length:e.components?.propertyEditor?.length||`min-content`,title:h,valueSet:_,onValueChange:(e,t,n)=>{if(_!==void 0&&t.editable!==!1&&!Ae(e.getValue(t.name),n)){e.setValue(t.name,n);let r=new Ne(_.propertySet,void 0);r.setValues(_.getValues()),r.rootElement=_.rootElement,ee.valueSet=r,_.rootElement.valueSet=r,C.propertyEditorChanges$?.next()}}}),e.components?.errors!==void 0&&e.components?.errors?.enabled!==!1&&(0,d.jsx)(Mn,{})]})]})})})})};exports.DagaDiagram=qn;
|