UNPKG

@metadev/daga-react

Version:

![Daga banner](https://metadev.pro/content/daga/daga-banner.png)

2 lines 201 kB
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("react/jsx-runtime"),to=require("d3"),kt=require("rxjs"),E=require("react");function eo(s){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const e in s)if(e!=="default"){const a=Object.getOwnPropertyDescriptor(s,e);Object.defineProperty(t,e,a.get?a:{enumerable:!0,get:()=>s[e]})}}return t.default=s,Object.freeze(t)}const A=eo(to);var g=(s=>(s.Bottom="bottom",s.Left="left",s.Right="right",s.Top="top",s))(g||{}),Ut=(s=>(s.BottomLeft="bottom-left",s.BottomRight="bottom-right",s.TopLeft="top-left",s.TopRight="top-right",s))(Ut||{}),It=(s=>(s.Left="left",s.Center="center",s.Right="right",s))(It||{}),Bt=(s=>(s.Top="top",s.Center="center",s.Bottom="bottom",s))(Bt||{});const Ct=s=>[Math.round(s[0]),Math.round(s[1])],gt=(s,t,e)=>t<e?t<=s&&s<=e:e<=s&&s<=t,ke=(s,t,e)=>(s-t[0])/(t[1]-t[0])*(e[1]-e[0])+e[0],Yt=(s,t,e,a,l,n,i)=>{const r=(()=>{switch(n){case"start":return a[0]+(s[0]-t[0]);case"end":return a[1]-(t[1]-s[0]);case"middle":{const c=(t[0]+t[1])/2,d=(a[0]+a[1])/2,h=t[1]-t[0],u=a[1]-a[0],y=(s[0]-c)/h;return d+y*u}case"floating":default:return ke(s[0],t,a)}})(),o=(()=>{switch(i){case"start":return l[0]+(s[1]-e[0]);case"end":return l[1]-(e[1]-s[1]);case"middle":{const c=(e[0]+e[1])/2,d=(l[0]+l[1])/2,h=e[1]-e[0],u=l[1]-l[0],y=(s[1]-c)/h;return d+y*u}case"floating":default:return ke(s[1],e,l)}})();return[r,o]},Ne=(s,t)=>((s[0]-t[0])**2+(s[1]-t[1])**2)**.5,oo=(s,t)=>(gt(s[0][0],t[0][0],t[1][0])||gt(s[1][0],t[1][0],t[0][0])||gt(t[0][0],s[0][0],s[1][0])||gt(t[1][0],s[1][0],s[0][0]))&&(gt(s[0][1],t[0][1],t[1][1])||gt(s[1][1],t[1][1],t[0][1])||gt(t[0][1],s[0][1],s[1][1])||gt(t[1][1],s[1][1],s[0][1]));var C=(s=>(s.Blur="blur",s.Change="change",s.Click="click",s.ContextMenu="contextmenu",s.DoubleClick="dblclick",s.Focus="focus",s.FocusIn="focusin",s.FocusOut="focusout",s.Input="input",s.KeyDown="keydown",s.KeyUp="keyup",s.MouseDown="mousedown",s.MouseEnter="mouseenter",s.MouseLeave="mouseleave",s.MouseMove="mousemove",s.MouseOut="mouseout",s.MouseOver="mouseover",s.MouseUp="mouseup",s.TouchStart="touchstart",s.TouchEnd="touchend",s.Wheel="wheel",s))(C||{}),W=(s=>(s.Alt="Alt",s.AltGraph="AltGraph",s.ArrowDown="ArrowDown",s.ArrowLeft="ArrowLeft",s.ArrowRight="ArrowRight",s.ArrowUp="ArrowUp",s.Backspace="Backspace",s.Control="Control",s.Delete="Delete",s.End="End",s.Enter="Enter",s.Escape="Escape",s.Home="Home",s.OS="OS",s.PageDown="PageDown",s.PageUp="PageUp",s.Shift="Shift",s.Tab="Tab",s))(W||{}),$=(s=>(s.Drag="drag",s.Start="start",s.End="end",s))($||{}),le=(s=>(s.Zoom="zoom",s.Start="start",s.End="end",s))(le||{});const ce=s=>s.replace(/([!"#$%&'()*+,\-./:;<=>?@[\\\]^`{|}])/g,"\\$1");var Pe=(s=>(s.Straight="straight",s.Bezier="bezier",s.Square="square",s))(Pe||{}),ue=(s=>(s.Solid="solid",s.Dashed="dashed",s.GappedDashes="gapped-dashes",s.Dotted="dotted",s))(ue||{});const io=20,so=(s,t,e,a,l)=>{if(typeof s=="function")return s(t,e,a,l);if(t.length===0)return"";if(t.length===1)return`M ${t[0][0]} ${t[0][1]}`;{l=l||io;let n="",i,r;switch(s){case"straight":n+=`M ${t[0][0]} ${t[0][1]}`;for(let o=1;o<t.length;++o)n+=` L ${t[o][0]} ${t[o][1]}`;break;case"bezier":i=e,n+=`M ${t[0][0]} ${t[0][1]}`;for(let o=1;o<t.length;++o){if(o+1>=t.length)switch(a){case g.Bottom:r=g.Top;break;case g.Top:r=g.Bottom;break;case g.Right:r=g.Left;break;case g.Left:r=g.Right;break}else Math.abs(t[o][0]-t[o-1][0])<Math.abs(t[o][1]-t[o-1][1])?t[o][1]>t[o-1][1]?r=g.Bottom:r=g.Top:t[o][0]>t[o-1][0]?r=g.Right:r=g.Left;if(i!==void 0){let c="",d="";const h=(Math.abs(t[o][0]-t[o-1][0])+Math.abs(t[o][1]-t[o-1][1]))/2;switch(i){case g.Bottom:c=`${t[o-1][0]} ${t[o-1][1]+h}`;break;case g.Top:c=`${t[o-1][0]} ${t[o-1][1]-h}`;break;case g.Right:c=`${t[o-1][0]+h} ${t[o-1][1]}`;break;case g.Left:c=`${t[o-1][0]-h} ${t[o-1][1]}`;break}if(r!==void 0){switch(r){case g.Top:d=`${t[o][0]} ${t[o][1]+h}`;break;case g.Bottom:d=`${t[o][0]} ${t[o][1]-h}`;break;case g.Left:d=`${t[o][0]+h} ${t[o][1]}`;break;case g.Right:d=`${t[o][0]-h} ${t[o][1]}`;break}n+=` C ${c} ${d} ${t[o][0]} ${t[o][1]}`}else n+=` Q ${c} ${t[o][0]} ${t[o][1]}`}else if(r!==void 0){let c="";const d=(Math.abs(t[o][0]-t[o-1][0])+Math.abs(t[o][1]-t[o-1][1]))/2;switch(r){case g.Top:c=`${t[o][0]} ${t[o][1]+d}`;break;case g.Bottom:c=`${t[o][0]} ${t[o][1]-d}`;break;case g.Left:c=`${t[o][0]+d} ${t[o][1]}`;break;case g.Right:c=`${t[o][0]-d} ${t[o][1]}`;break}n+=` Q ${c} ${t[o][0]} ${t[o][1]}`}else n+=` L ${t[o][0]} ${t[o][1]}`;i=r}break;case"square":i=e,n+=`M ${t[0][0]} ${t[0][1]}`;for(let o=1;o<t.length;++o){if(o+1>=t.length)switch(a){case g.Bottom:r=g.Top;break;case g.Top:r=g.Bottom;break;case g.Right:r=g.Left;break;case g.Left:r=g.Right;break}switch(i){case g.Bottom:switch(r){case g.Bottom:t[o][1]>t[o-1][1]?(t[o][0]!==t[o-1][0]?(n+=` V ${(t[o][1]+t[o-1][1])/2}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`):n+=` V ${t[o][1]}`,i=r):t[o][0]>t[o-1][0]?(n+=` V ${t[o-1][1]+l}`,n+=` H ${Math.max(t[o-1][0],t[o][0])+l}`,n+=` V ${t[o][1]-l}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`):(n+=` V ${t[o-1][1]+l}`,n+=` H ${Math.min(t[o-1][0],t[o][0])-l}`,n+=` V ${t[o][1]-l}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`);break;case g.Top:n+=` V ${Math.max(t[o-1][1],t[o][1])+l}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`;break;case g.Left:t[o][1]>t[o-1][1]+l?t[o][0]<t[o-1][0]-l?(n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`):(n+=` V ${(t[o-1][1]+t[o][1])/2}`,n+=` H ${t[o][0]+l}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`):t[o][0]<t[o-1][0]-l?(n+=` V ${t[o-1][1]+l}`,n+=` H ${(t[o-1][0]+t[o][0])/2}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`):(n+=` V ${t[o-1][1]+l}`,n+=` H ${t[o][0]+l}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`);break;case g.Right:t[o][1]>t[o-1][1]+l?t[o][0]>t[o-1][0]+l?(n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`):(n+=` V ${(t[o-1][1]+t[o][1])/2}`,n+=` H ${t[o][0]-l}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`):t[o][0]>t[o-1][0]+l?(n+=` V ${t[o-1][1]+l}`,n+=` H ${(t[o-1][0]+t[o][0])/2}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`):(n+=` V ${t[o-1][1]+l}`,n+=` H ${t[o][0]-l}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`);break;default:t[o][1]<t[o-1][1]+l?(n+=` V ${t[o-1][1]+l}`,t[o][0]!==t[o-1][0]&&(n+=` H ${t[o][0]}`),n+=` V ${t[o][1]}`,i=g.Top):(n+=` V ${t[o][1]}`,i=g.Bottom,t[o][0]!==t[o-1][0]&&(n+=` H ${t[o][0]}`,i=t[o][0]>t[o-1][0]?g.Right:g.Left));break}break;case g.Top:switch(r){case g.Top:t[o][1]<t[o-1][1]?(t[o][0]!==t[o-1][0]?(n+=` V ${(t[o][1]+t[o-1][1])/2}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`):n+=` V ${t[o][1]}`,i=r):t[o][0]<t[o-1][0]?(n+=` V ${t[o-1][1]-l}`,n+=` H ${Math.min(t[o-1][0],t[o][0])-l}`,n+=` V ${t[o][1]+l}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`):(n+=` V ${t[o-1][1]-l}`,n+=` H ${Math.max(t[o-1][0],t[o][0])+l}`,n+=` V ${t[o][1]+l}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`);break;case g.Bottom:n+=` V ${Math.min(t[o-1][1],t[o][1])-l}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`;break;case g.Right:t[o][1]<t[o-1][1]-l?t[o][0]>t[o-1][0]+l?(n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`):(n+=` V ${(t[o-1][1]+t[o][1])/2}`,n+=` H ${t[o][0]-l}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`):t[o][0]>t[o-1][0]+l?(n+=` V ${t[o-1][1]-l}`,n+=` H ${(t[o-1][0]+t[o][0])/2}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`):(n+=` V ${t[o-1][1]-l}`,n+=` H ${t[o][0]-l}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`);break;case g.Left:t[o][1]<t[o-1][1]-l?t[o][0]<t[o-1][0]-l?(n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`):(n+=` V ${(t[o-1][1]+t[o][1])/2}`,n+=` H ${t[o][0]+l}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`):t[o][0]<t[o-1][0]-l?(n+=` V ${t[o-1][1]-l}`,n+=` H ${(t[o-1][0]+t[o][0])/2}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`):(n+=` V ${t[o-1][1]-l}`,n+=` H ${t[o][0]+l}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`);break;default:t[o][1]>t[o-1][1]-l?(n+=` V ${t[o-1][1]-l}`,t[o][0]!==t[o-1][0]&&(n+=` H ${t[o][0]}`),n+=` V ${t[o][1]}`,i=g.Bottom):(n+=` V ${t[o][1]}`,i=g.Top,t[o][0]!==t[o-1][0]&&(n+=` H ${t[o][0]}`,i=t[o][0]>t[o-1][0]?g.Right:g.Left));break}break;case g.Left:switch(r){case g.Left:t[o][0]<t[o-1][0]?(t[o][1]!==t[o-1][1]?(n+=` H ${(t[o][0]+t[o-1][0])/2}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`):n+=` H ${t[o][0]}`,i=r):t[o][1]<t[o-1][1]?(n+=` H ${t[o-1][0]-l}`,n+=` V ${Math.min(t[o-1][1],t[o][1])-l}`,n+=` H ${t[o][0]+l}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`):(n+=` H ${t[o-1][0]-l}`,n+=` V ${Math.max(t[o-1][1],t[o][1])+l}`,n+=` H ${t[o][0]+l}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`);break;case g.Right:n+=` H ${Math.min(t[o-1][0],t[o][0])-l}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`;break;case g.Bottom:t[o][0]<t[o-1][0]-l?t[o][1]>t[o-1][1]+l?(n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`):(n+=` H ${(t[o-1][0]+t[o][0])/2}`,n+=` V ${t[o][1]-l}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`):t[o][1]>t[o-1][1]+l?(n+=` H ${t[o-1][0]-l}`,n+=` V ${(t[o-1][1]+t[o][1])/2}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`):(n+=` H ${t[o-1][0]-l}`,n+=` V ${t[o][1]-l}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`);break;case g.Top:t[o][0]<t[o-1][0]-l?t[o][1]<t[o-1][1]-l?(n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`):(n+=` H ${(t[o-1][0]+t[o][0])/2}`,n+=` V ${t[o][1]+l}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`):t[o][1]<t[o-1][1]-l?(n+=` H ${t[o-1][0]-l}`,n+=` V ${(t[o-1][1]+t[o][1])/2}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`):(n+=` H ${t[o-1][0]-l}`,n+=` V ${t[o][1]+l}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`);break;default:t[o][0]>t[o-1][0]-l?(n+=` H ${t[o-1][0]-l}`,t[o][1]!==t[o-1][1]&&(n+=` V ${t[o][1]}`),n+=` H ${t[o][0]}`,i=g.Right):(n+=` H ${t[o][0]}`,i=g.Left,t[o][1]!==t[o-1][1]&&(n+=` V ${t[o][1]}`,i=t[o][1]>t[o-1][1]?g.Bottom:g.Top));break}break;case g.Right:switch(r){case g.Right:t[o][0]>t[o-1][0]?(t[o][1]!==t[o-1][1]?(n+=` H ${(t[o][0]+t[o-1][0])/2}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`):n+=` H ${t[o][0]}`,i=r):t[o][1]>t[o-1][1]?(n+=` H ${t[o-1][0]+l}`,n+=` V ${Math.max(t[o-1][1],t[o][1])+l}`,n+=` H ${t[o][0]-l}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`):(n+=` H ${t[o-1][0]+l}`,n+=` V ${Math.min(t[o-1][1],t[o][1])-l}`,n+=` H ${t[o][0]-l}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`);break;case g.Left:n+=` H ${Math.max(t[o-1][0],t[o][0])+l}`,n+=` V ${t[o][1]}`,n+=` H ${t[o][0]}`;break;case g.Top:t[o][0]>t[o-1][0]+l?t[o][1]<t[o-1][1]-l?(n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`):(n+=` H ${(t[o-1][0]+t[o][0])/2}`,n+=` V ${t[o][1]+l}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`):t[o][1]<t[o-1][1]-l?(n+=` H ${t[o-1][0]+l}`,n+=` V ${(t[o-1][1]+t[o][1])/2}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`):(n+=` H ${t[o-1][0]+l}`,n+=` V ${t[o][1]+l}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`);break;case g.Bottom:t[o][0]>t[o-1][0]+l?t[o][1]>t[o-1][1]+l?(n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`):(n+=` H ${(t[o-1][0]+t[o][0])/2}`,n+=` V ${t[o][1]-l}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`):t[o][1]>t[o-1][1]+l?(n+=` H ${t[o-1][0]+l}`,n+=` V ${(t[o-1][1]+t[o][1])/2}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`):(n+=` H ${t[o-1][0]+l}`,n+=` V ${t[o][1]-l}`,n+=` H ${t[o][0]}`,n+=` V ${t[o][1]}`);break;default:t[o][0]<t[o-1][0]+l?(n+=` H ${t[o-1][0]+l}`,t[o][1]!==t[o-1][1]&&(n+=` V ${t[o][1]}`),n+=` H ${t[o][0]}`,i=g.Left):(n+=` H ${t[o][0]}`,i=g.Right,t[o][1]!==t[o-1][1]&&(n+=` V ${t[o][1]}`,i=t[o][1]>t[o-1][1]?g.Bottom:g.Top));break}break;default:t[o][0]!==t[o-1][0]&&(n+=` H ${t[o][0]}`,i=t[o][0]>t[o-1][0]?g.Right:g.Left),t[o][1]!==t[o-1][1]&&(n+=` V ${t[o][1]}`,i=t[o][1]>t[o-1][1]?g.Bottom:g.Top)}}break}return n}},de=(s,t)=>{switch(s){case"dotted":return`${t}`;case"dashed":return`${4*t} ${t}`;case"gapped-dashes":return`${4*t} ${4*t}`;case"solid":default:return"none"}},D=(s,t)=>{const e=s.indexOf(t);return e>=0&&s.splice(e,1),s};var Et=(s=>(s.Ellipse="ellipse",s.Empty="empty",s.Folder="folder",s.Hexagon="hexagon",s.Octagon="octagon",s.Pill="pill",s.Rectangle="rectangle",s.Rhombus="rhombus",s.RoundedRectangle="rounded-rectangle",s.StickyNote="sticky-note",s))(Et||{});const he=(s,t,e,a,l)=>{if(typeof s=="function")return s(t,e,a,l);switch(s){case"ellipse":return Re(t,e,a,l);case"empty":return no();case"folder":return ro(t,e,a,l);case"hexagon":return ao(t,e,a,l);case"octagon":return lo(t,e,a,l);case"pill":return Dt(t,e,a,l);case"rectangle":return we(t,e,a,l);case"rhombus":return co(t,e,a,l);case"rounded-rectangle":return ho(t,e,a,l);case"sticky-note":return go(t,e,a,l);default:return we(t,e,a,l)}},Re=(s,t,e,a)=>`M ${s+e/2} ${t} A ${e/2} ${a/2} 0 0 0 ${s+e/2} ${t+a} A ${e/2} ${a/2} 0 1 0 ${s+e/2} ${t} Z`,no=()=>"Z",ro=(s,t,e,a)=>`M ${s} ${t} L ${s+e/3} ${t} L ${s+e/2} ${t+a/6} L ${s+e} ${t+a/6} L ${s+e} ${t+a} L ${s} ${t+a} Z`,ao=(s,t,e,a)=>`M ${s+e/4} ${t} L ${s+3*e/4} ${t} L ${s+e} ${t+a/2} L ${s+3*e/4} ${t+a} L ${s+e/4} ${t+a} L ${s} ${t+a/2} Z`,lo=(s,t,e,a)=>`M ${s+e/4} ${t} L ${s+3*e/4} ${t} L ${s+e} ${t+a/4} L ${s+e} ${t+3*a/4} L ${s+3*e/4} ${t+a} L ${s+e/4} ${t+a} L ${s} ${t+3*a/4} L ${s} ${t+a/4} L ${s+e/4} ${t} Z`,Dt=(s,t,e,a)=>a<e?`M ${s+a/2} ${t} L ${s+e-a/2} ${t} A ${a/2} ${a/2} 0 0 1 ${s+e} ${t+a/2} A ${a/2} ${a/2} 0 0 1 ${s+e-a/2} ${t+a} L ${s+a/2} ${t+a} A ${a/2} ${a/2} 0 0 1 ${s} ${t+a/2} A ${a/2} ${a/2} 0 0 1 ${s+a/2} ${t} Z`:a>e?`M ${s} ${t+e/2} L ${s} ${t+a-e/2} A ${e/2} ${e/2} 0 0 0 ${s+e/2} ${t+a} A ${e/2} ${e/2} 0 0 0 ${s+e} ${t+a-e/2} L ${s+e} ${t+e/2} A ${e/2} ${e/2} 0 0 0 ${s+e/2} ${t} A ${e/2} ${e/2} 0 0 0 ${s} ${t+e/2} Z`:Re(s,t,e,a),we=(s,t,e,a)=>`M ${s} ${t} L ${s+e} ${t} L ${s+e} ${t+a} L ${s} ${t+a} Z`,co=(s,t,e,a)=>`M ${s+e/2} ${t} L ${s+e} ${t+a/2} L ${s+e/2} ${t+a} L ${s} ${t+a/2} Z`,ho=(s,t,e,a)=>`M ${s+e/4} ${t} L ${s+3*e/4} ${t} A ${e/4} ${a/4} 0 0 1 ${s+e} ${t+a/4} L ${s+e} ${t+3*a/4} A ${e/4} ${a/4} 0 0 1 ${s+3*e/4} ${t+a} L ${s+e/4} ${t+a} A ${e/4} ${a/4} 0 0 1 ${s} ${t+3*a/4} L ${s} ${t+a/4} A ${e/4} ${a/4} 0 0 1 ${s+e/4} ${t} Z`,go=(s,t,e,a)=>`M ${s} ${t} L ${s+3*e/4} ${t} L ${s+3*e/4} ${t+a/4} L ${s+3*e/4} ${t} L ${s+e} ${t+a/4} L ${s+3*e/4} ${t+a/4} L ${s+e} ${t+a/4} L ${s+e} ${t+a} L ${s} ${t+a} Z`;var L=(s=>(s.AllScroll="all-scroll",s.Auto="auto",s.Crosshair="crosshair",s.EWResize="ew-resize",s.Grab="grab",s.Grabbing="grabbing",s.Move="move",s.NoDrop="no-drop",s.NSResize="ns-resize",s.NotAllowed="not-allowed",s.ZoomIn="zoom-in",s.ZoomOut="zoom-out",s))(L||{});const fo=s=>Math.max(...s.split(` `).map(t=>t.length)),uo=s=>s.match(/\n/g)?.length||0,X=[];for(let s=0;s<256;++s)X.push((s+256).toString(16).slice(1));function po(s,t=0){return(X[s[t+0]]+X[s[t+1]]+X[s[t+2]]+X[s[t+3]]+"-"+X[s[t+4]]+X[s[t+5]]+"-"+X[s[t+6]]+X[s[t+7]]+"-"+X[s[t+8]]+X[s[t+9]]+"-"+X[s[t+10]]+X[s[t+11]]+X[s[t+12]]+X[s[t+13]]+X[s[t+14]]+X[s[t+15]]).toLowerCase()}let ee;const mo=new Uint8Array(16);function vo(){if(!ee){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");ee=crypto.getRandomValues.bind(crypto)}return ee(mo)}const yo=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),Se={randomUUID:yo};function xe(s,t,e){if(Se.randomUUID&&!s)return Se.randomUUID();s=s||{};const a=s.random??s.rng?.()??vo();if(a.length<16)throw new Error("Random bytes length must be >= 16");return a[6]=a[6]&15|64,a[8]=a[8]&63|128,po(a)}const it=s=>{const{selected:t,highlighted:e,selectedAndHighlighted:a,...l}=s,n=l,i={...n,...t},r={...n,...e},o={...n,...e,...t,...a};return{defaultLook:n,selectedLook:i,highlightedLook:r,selectedAndHighlightedLook:o}};class Wt{constructor(){this.entities=[],this.entityMap={}}get length(){return this.size()}all(){return[...this.entities]}add(t){this.entityMap[t.id]===void 0&&(this.entityMap[t.id]=t,this.entities.push(t))}clear(){for(;this.entities.length>0;)this.remove(this.entities[0].id)}contains(t){return this.entityMap[t]!==void 0}count(t){return this.entities.filter(t).length}filter(t){return this.entities.filter(t)}find(t){return this.entities.find(t)}get(t){return this.entityMap[t]}map(t){return this.entities.map(t)}remove(t){const e=this.get(t);e!==void 0&&(delete this.entityMap[t],D(this.entities,e))}size(){return this.entities.length}*[Symbol.iterator](){for(const t of this.entities)yield t}}const Mt=0;class xt{constructor(t,e){this.selfRemoved=!1,this.selfRemovedTimestamp=null,this.model=t,this._id=e}get id(){return this._id}get highlighted(){return this.model.canvas?.userHighlight?.contains(this.id)||!1}get selected(){return this.model.canvas?.userSelection?.contains(this.id)||!1}select(){return this.model.canvas?.selectCanvasView()?.select(`[id='${ce(this.id)}']`)}}class ht extends Wt{all(t=!1){return t?super.all():super.filter(e=>!e.removed)}contains(t,e=!1){return e?super.contains(t):super.contains(t)&&!this.entityMap[t].removed}count(t,e=!1){return e?super.count(t):super.count((a,l,n)=>t(a,l,n)&&!a.removed)}filter(t,e=!1){return e?super.filter(t):super.filter((a,l,n)=>t(a,l,n)&&!a.removed)}find(t,e=!1){return e?super.find(t):super.find((a,l,n)=>t(a,l,n)&&!a.removed)}get(t,e=!1){return e?super.get(t):this.contains(t)?super.get(t):void 0}map(t,e=!1){return e?super.map(t):super.filter(a=>!a.removed).map(t)}remove(t){const e=this.get(t,!0);e!==void 0&&(delete this.entityMap[t],D(this.entities,e))}size(t=!1){return t?super.size():super.filter(e=>!e.removed).length}*[Symbol.iterator](t=!1){if(t)for(const e of this.entities)yield e;else for(const e of this.entities.filter(a=>!a.removed))yield e}}class bo{constructor(t,e,a,l,n,i,r){this.name=t,this.label=e,this.type=a,this.defaultValue=l,this.basic=n,this.editable=i,this.rootAttribute=r,this.options=void 0,this.properties=void 0}}var T=(s=>(s.Boolean="boolean",s.Color="color",s.Date="date",s.Datetime="datetime",s.Number="number",s.Object="object",s.Option="option",s.OptionList="option-list",s.OptionSet="option-set",s.Text="text",s.TextArea="text-area",s.TextList="text-list",s.TextSet="text-set",s.TextMap="text-map",s.Time="time",s.Url="url",s))(T||{});class Zt{constructor(t=[]){this.propertyList=t,this.propertyMap={};for(const e of this.propertyList)this.propertyMap[e.name]=e}getProperty(t){return this.propertyMap[t]}hasProperty(t){return this.propertyMap[t]!==void 0}hasProperties(){return this.propertyList.length>0}}function yt(s,t){return!t||s[0]>t[0]?!0:s[0]===t[0]?s[1]>=t[1]:!1}const Ce=s=>s==null||s===""||s instanceof Array&&s.length===0||s instanceof Object&&Object.keys(s).length===0,wt=(s,t)=>s===t||JSON.stringify(s)===JSON.stringify(t),ze=(s,t,e)=>{const a={},l={};for(const n in e.propertySet.propertyMap)if(e.propertySet.propertyMap[n].type===T.Object){const i=ze(s[n],t[n],e.getSubValueSet(n));Object.keys(i[0]).length>0&&Object.keys(i[1]).length>0&&(a[n]=i[0],l[n]=i[1])}else wt(s[n],t[n])||(a[n]=s[n],l[n]=t[n]);return[a,l]},ko=s=>s!=null&&s.constructor===Object;class mt{constructor(t,e){this.displayedProperties=[],this.hiddenProperties=[],this.values={},this.valueSets={},this.ownTimestamps={},this.propertySet=t,this.rootElement=e,this.resetValues()}getRootElementValue(t){if(this.rootElement){if(typeof t=="string")return this.rootElement[t];if(Array.isArray(t)&&t.length>0){let e=this.rootElement;for(const a of t){if(e==null)return;e=e[a]}return e}}}setRootElementValue(t,e){if(this.rootElement){if(typeof t=="string"&&(this.rootElement[t]=e),Array.isArray(t)&&t.length>0){let a=this.rootElement;for(let l=0;l<t.length-1;++l){const n=t[l];if(a==null)return;a=a[n]}if(a==null)return;a[t[t.length-1]]=e}typeof this.rootElement.updateInView=="function"&&this.rootElement.updateInView()}}getValue(t){const e=this.propertySet.getProperty(t)?.rootAttribute;return e!=null&&(this.values[t]=this.getRootElementValue(e)),this.propertySet.getProperty(t).type===T.Object?this.valueSets[t].getValues():this.values[t]}getValues(){const t={};for(const e in this.propertySet.propertyMap)this.propertySet.getProperty(e).type===T.Object?t[e]=this.valueSets[e].getValues():t[e]=this.getValue(e);return t}getValuesForKeys(t){const e={};for(const a in t)this.propertySet.getProperty(a).type===T.Object?e[a]=this.valueSets[a].getValuesForKeys(t[a]):e[a]=this.getValue(a);return e}getTimestamps(){const t={};for(const e in this.propertySet.propertyMap)if(this.propertySet.getProperty(e).type===T.Object)t[e]=this.valueSets[e].getTimestamps();else{const l=this.ownTimestamps[e];l&&(t[e]=l)}return t}hasValue(t){const e=this.getValue(t);return!Ce(e)}hasSetValue(t){const e=this.getValue(t),a=this.propertySet.getProperty(t);return a&&a.type===T.Object?this.getSubValueSet(t).hasAnySetValue():!Ce(e)&&!wt(e,a?.defaultValue)}hasAnySetValue(){for(const t of this.propertySet.propertyList)if(this.hasSetValue(t.name))return!0;return!1}setValue(t,e){const a=this.propertySet.getProperty(t);if(a){a.type===T.Object?this.valueSets[t].setValues(e):(this.values[t]=e,wt(e,a.defaultValue)||this.displayProperty(a));const l=a.rootAttribute;l!=null&&this.setRootElementValue(l,e)}}setValues(t){this.resetValues();for(const e in t)this.propertySet.getProperty(e).type===T.Object?this.valueSets[e].setValues(t[e]):this.setValue(e,t[e])}setTimestamps(t){this.ownTimestamps={};for(const e in t)this.propertySet.getProperty(e).type===T.Object?this.valueSets[e].setTimestamps(t[e]):this.ownTimestamps[e]=t[e]}overwriteValues(t){for(const e in t)this.propertySet.getProperty(e).type===T.Object?this.valueSets[e].overwriteValues(t[e]):this.setValue(e,t[e])}overwriteValuesLww(t,e){for(const a in t)this.propertySet.getProperty(a).type===T.Object?this.valueSets[a].overwriteValuesLww(t[a],e):yt(e,this.ownTimestamps[a])&&(this.setValue(a,t[a]),this.ownTimestamps[a]=e)}resetValues(){this.displayedProperties=[],this.hiddenProperties=[],this.ownTimestamps={};for(const t in this.propertySet.propertyMap){const e=this.propertySet.getProperty(t),a=e.rootAttribute;e.type===T.Object?this.valueSets[t]=this.constructSubValueSet(t):this.values[t]=structuredClone(e.defaultValue),a!=null&&e.defaultValue!==void 0&&!wt(this.getRootElementValue(a),e.defaultValue)&&this.setRootElementValue(a,this.values[t]),e.basic!==!1?this.displayedProperties.push(e):this.hiddenProperties.push(e)}}constructSubValueSet(t){const e=this.propertySet.getProperty(t),a=new Zt(e.properties),l=new mt(a,this.rootElement);return l.overwriteValues(structuredClone(e.defaultValue)),l}getSubValueSet(t){return this.valueSets[t]}displayProperty(t){this.displayedProperties.includes(t)||(this.displayedProperties.push(t),D(this.hiddenProperties,t))}hideProperty(t){this.hiddenProperties.includes(t)||(this.hiddenProperties.push(t),D(this.displayedProperties,t))}}const tt={name:"",label:null,look:{lookType:"connection-look",color:"#000000",thickness:1,shape:Pe.Straight,style:ue.Solid,selected:{color:"#AA00AA"},highlighted:{thickness:2}},startMarkerLook:void 0,endMarkerLook:void 0,startTypes:[],endTypes:[],properties:[]};class Ve{constructor(t){const e={...tt,...t};this.id=e.id,this.name=e.name,this.label=e.label;const a=it(e.look);if(this.defaultLook=a.defaultLook,this.selectedLook=a.selectedLook,this.highlightedLook=a.highlightedLook,this.selectedAndHighlightedLook=a.selectedAndHighlightedLook,e.startMarkerLook!==void 0){const l=it(e.startMarkerLook);this.defaultStartMarkerLook=l.defaultLook,this.selectedStartMarkerLook=l.selectedLook,this.highlightedStartMarkerLook=l.highlightedLook,this.selectedAndHighlightedStartMarkerLook=l.selectedAndHighlightedLook}else this.defaultStartMarkerLook=null,this.selectedStartMarkerLook=null,this.highlightedStartMarkerLook=null,this.selectedAndHighlightedStartMarkerLook=null;if(e.endMarkerLook!==void 0){const l=it(e.endMarkerLook);this.defaultEndMarkerLook=l.defaultLook,this.selectedEndMarkerLook=l.selectedLook,this.highlightedEndMarkerLook=l.highlightedLook,this.selectedAndHighlightedEndMarkerLook=l.selectedAndHighlightedLook}else this.defaultEndMarkerLook=null,this.selectedEndMarkerLook=null,this.highlightedEndMarkerLook=null,this.selectedAndHighlightedEndMarkerLook=null;this.startTypes=e.startTypes,this.endTypes=e.endTypes,this.propertySet=new Zt(e.properties)}canStartFromType(t){return this.startTypes.indexOf(t)>=0}canFinishOnType(t){return this.endTypes.indexOf(t)>=0}}class at extends xt{constructor(t,e,a,l,n){if(t.connections.get(n)!==void 0)throw new Error(`DiagramConnection with id "${n}" already exists`);if(!n)throw new Error("DiagramConnection cannot have an empty or null id");super(t,n),this.startCoords=[0,0],this.endCoords=[0,0],this.startLabel="",this.middleLabel="",this.endLabel="",this.points=[],this._type=e,this.valueSet=new mt(e.propertySet,this),this.originalData={},this.setStart(a),this.setEnd(l)}get type(){return this._type}set type(t){t!==this._type&&(this._type=t,this.valueSet&&(this.valueSet=new mt(t.propertySet,this)),this.model.canvas?.userSelection?.openInPropertyEditor(this,!1),this.updateInView())}get typeString(){return this.type.id}set typeString(t){if(t!==this.type.id){const e=this.model.connections.types.get(t);e&&(this.type=e)}}get name(){return this.middleLabel}set name(t){this.middleLabel=t}get look(){return this.selected?this.highlighted?this._selectedAndHighlightedLook!==void 0?this._selectedAndHighlightedLook:this.type.selectedAndHighlightedLook:this._selectedLook!==void 0?this._selectedLook:this.type.selectedLook:this.highlighted?this._highlightedLook!==void 0?this._highlightedLook:this.type.highlightedLook:this._defaultLook!==void 0?this._defaultLook:this.type.defaultLook}set look(t){if(t){const e=it(t);this._defaultLook={...this._defaultLook,...e.defaultLook},this._selectedLook={...this._selectedLook,...e.selectedLook},this._highlightedLook={...this._highlightedLook,...e.highlightedLook},this._selectedAndHighlightedLook={...this._selectedAndHighlightedLook,...e.selectedAndHighlightedLook}}else this._defaultLook=t,this._selectedLook=t,this._highlightedLook=t,this._selectedAndHighlightedLook=t}get startMarkerLook(){return this.selected?this.highlighted?this._selectedAndHighlightedStartMarkerLook!==void 0?this._selectedAndHighlightedStartMarkerLook:this.type.selectedAndHighlightedStartMarkerLook:this._selectedStartMarkerLook!==void 0?this._selectedStartMarkerLook:this.type.selectedStartMarkerLook:this.highlighted?this._highlightedStartMarkerLook!==void 0?this._highlightedStartMarkerLook:this.type.highlightedStartMarkerLook:this._defaultStartMarkerLook!==void 0?this._defaultStartMarkerLook:this.type.defaultStartMarkerLook}set startMarkerLook(t){if(t){const e=it(t);this._defaultStartMarkerLook={...this._defaultStartMarkerLook,...e.defaultLook},this._selectedStartMarkerLook={...this._selectedStartMarkerLook,...e.selectedLook},this._highlightedStartMarkerLook={...this._highlightedStartMarkerLook,...e.highlightedLook},this._selectedAndHighlightedStartMarkerLook={...this._selectedAndHighlightedStartMarkerLook,...e.selectedAndHighlightedLook}}else this._defaultStartMarkerLook=t,this._selectedStartMarkerLook=t,this._highlightedStartMarkerLook=t,this._selectedAndHighlightedStartMarkerLook=t}get endMarkerLook(){return this.selected?this.highlighted?this._selectedAndHighlightedEndMarkerLook!==void 0?this._selectedAndHighlightedEndMarkerLook:this.type.selectedAndHighlightedEndMarkerLook:this._selectedEndMarkerLook!==void 0?this._selectedEndMarkerLook:this.type.selectedEndMarkerLook:this.highlighted?this._highlightedEndMarkerLook!==void 0?this._highlightedEndMarkerLook:this.type.highlightedEndMarkerLook:this._defaultEndMarkerLook!==void 0?this._defaultEndMarkerLook:this.type.defaultEndMarkerLook}set endMarkerLook(t){if(t){const e=it(t);this._defaultEndMarkerLook={...this._defaultEndMarkerLook,...e.defaultLook},this._selectedEndMarkerLook={...this._selectedEndMarkerLook,...e.selectedLook},this._highlightedEndMarkerLook={...this._highlightedEndMarkerLook,...e.highlightedLook},this._selectedAndHighlightedEndMarkerLook={...this._selectedAndHighlightedEndMarkerLook,...e.selectedAndHighlightedLook}}else this._defaultEndMarkerLook=t,this._selectedEndMarkerLook=t,this._highlightedEndMarkerLook=t,this._selectedAndHighlightedEndMarkerLook=t}get removed(){return this.selfRemoved||this.start!==void 0&&this.start.removed||this.end!==void 0&&this.end.removed}updateInView(){this.model.canvas?.updateConnectionsInView(this.id)}raise(){this.select()?.raise()}setStart(t){this.start!==t?(this.start!==void 0&&D(this.start.outgoingConnections,this),this.start=t,t!==void 0&&(t.outgoingConnections.push(this),this.startDirection=t?.direction,this.startCoords=t?.connectionPoint||[0,0])):(this.startDirection=t?.direction,this.startCoords=t?.connectionPoint||[0,0]),this.updateInView()}setEnd(t){this.end!==t?(this.end!==void 0&&D(this.end.incomingConnections,this),this.end=t,t!==void 0&&(t.incomingConnections.push(this),this.endDirection=t?.direction,this.endCoords=t?.connectionPoint||[0,0])):(this.endDirection=t?.direction,this.endCoords=t?.connectionPoint||[0,0]),this.updateInView()}tighten(){const t=this.model.canvas?.allowConnectionLoops||!1,e=this.model.canvas?.allowSharingPorts!==!1,a=this.model.canvas?.allowSharingBothPorts||!1;if(this.start?.rootElement&&this.end){const l=this.start.rootElement.ports.map(n=>[n,n.distanceTo(this.end.coords)]).sort((n,i)=>n[1]-i[1]).map(n=>n[0]);t:for(const n of l){if(!t&&n===this.end||!n.allowsOutgoing||!e&&(n.incomingConnections.length===1&&n.incomingConnections[0]!==this||n.incomingConnections.length>1||n.outgoingConnections.length===1&&n.outgoingConnections[0]!==this||n.outgoingConnections.length>1))continue t;if(!a){for(const i of n.outgoingConnections)if(i!==this&&i.end===this.end)continue t;for(const i of n.incomingConnections)if(i!==this&&i.start===this.end)continue t}if(n===this.start)break t;this.setStart(n);break t}}if(this.end?.rootElement&&this.start){const l=this.end.rootElement.ports.map(n=>[n,n.distanceTo(this.start.coords)]).sort((n,i)=>n[1]-i[1]).map(n=>n[0]);t:for(const n of l){if(!t&&n===this.start||!n.allowsIncoming||!e&&(n.outgoingConnections.length===1&&n.outgoingConnections[0]!==this||n.outgoingConnections.length>1||n.incomingConnections.length===1&&n.incomingConnections[0]!==this||n.incomingConnections.length>1))continue t;if(!a){for(const i of n.incomingConnections)if(i!==this&&i.start===this.start)continue t;for(const i of n.outgoingConnections)if(i!==this&&i.end===this.start)continue t}if(n===this.end)break t;this.setEnd(n);break t}}}getPriority(){return this.start?this.end?Math.min(this.start.getPriority(),this.end.getPriority()):this.start.getPriority():this.end?this.end.getPriority():Mt}}class wo extends ht{constructor(t){super(),this.types=new Wt,this.model=t}new(t,e,a,l){let n;if(t instanceof Ve)n=t;else{const r=this.types.get(t);if(r===void 0)throw new TypeError(`Connection type with id '${t}' could not be found.`);n=r}const i=new at(this.model,n,e,a,l);return super.add(i),i.updateInView(),i.valueSet.resetValues(),i}remove(t){const e=this.get(t,!0);e&&(D(e.start?.outgoingConnections||[],e),D(e.end?.incomingConnections||[],e),super.remove(t),e.updateInView())}}const V={editable:!0,fontSize:0,margin:0,padding:0,fontFamily:"'Wonder Unit Sans', sans-serif",color:"#000000",selectedColor:"#000000",backgroundColor:"#00000000",horizontalAlign:It.Center,verticalAlign:Bt.Center,orientation:g.Top,fit:!1,shrink:!0};class ct extends xt{constructor(t,e,a,l,n,i,r,o,c,d,h,u,y,v,m,p){const k=`${e?.id}_field`;if(t.fields.get(k)!==void 0)throw new Error("DiagramField for rootElement already exists");if(super(t,k),this.textTimestamp=null,this.rootElement=e,this.coords=a,this.width=l,this.height=n,this.fontSize=i,this.fontFamily=r,this.color=o,this.selectedColor=c,this.horizontalAlign=d,this.verticalAlign=h,!isNaN(Number(u)))this.orientation=Number(u);else switch(u){case g.Top:this.orientation=0;break;case g.Right:this.orientation=90;break;case g.Bottom:this.orientation=180;break;case g.Left:this.orientation=270;break;default:this.orientation=0}this.defaultText=y,this._text=y,this.editable=v,this.fit=m,this.shrink=p}get text(){return this._text}set text(t){(t==null||t?.trim()==="")&&(t=this.defaultText),this._text=t,this.updateInView(),this.fit&&this.model.canvas?.fitFieldRootInView(this.id,this.shrink)}get removed(){return this.selfRemoved||this.rootElement!==void 0&&this.rootElement.removed}updateInView(){this.model.canvas?.updateFieldsInView(this.id)}raise(){this.select()?.raise()}move(t){this.coords=t,this.updateInView()}getPriority(){return this.rootElement?.getPriority()||Mt}}class So extends ht{constructor(t){super(),this.model=t}new(t,e,a,l,n,i,r,o,c,d,h,u,y,v,m){const p=new ct(this.model,t,e,r,o,a,l,n,i,c,d,h,u,y,v,m);return super.add(p),p.updateInView(),t!==void 0&&(t.label=p),p}remove(t){const e=this.get(t,!0);e&&(e.rootElement?.label!==void 0&&e.rootElement.label===e&&(e.rootElement.label=void 0),super.remove(t),e.updateInView())}}const Z=s=>s?.margin===null||s?.margin===void 0?V.margin:typeof s.margin=="number"?s.margin:s.margin.length===0?V.margin:s.margin.length===1||s.margin.length===2?s.margin[0]:(s.margin.length===3,s.margin[2]),U=s=>s?.margin===null||s?.margin===void 0?V.margin:typeof s.margin=="number"?s.margin:s.margin.length===0?V.margin:s.margin.length===1?s.margin[0]:s.margin.length===2||s.margin.length===3?s.margin[1]:s.margin[3],et=s=>s?.margin===null||s?.margin===void 0?V.margin:typeof s.margin=="number"?s.margin:s.margin.length===0?V.margin:s.margin.length===1?s.margin[0]:(s.margin.length===2||s.margin.length===3,s.margin[1]),G=s=>s?.margin===null||s?.margin===void 0?V.margin:typeof s.margin=="number"?s.margin:s.margin.length===0?V.margin:(s.margin.length===1||s.margin.length===2||s.margin.length===3,s.margin[0]),Pt=s=>s?.padding===null||s?.padding===void 0?V.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?V.padding:s.padding.length===1||s.padding.length===2?s.padding[0]:(s.padding.length===3,s.padding[2]),Rt=s=>s?.padding===null||s?.padding===void 0?V.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?V.padding:s.padding.length===1?s.padding[0]:s.padding.length===2||s.padding.length===3?s.padding[1]:s.padding[3],zt=s=>s?.padding===null||s?.padding===void 0?V.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?V.padding:s.padding.length===1?s.padding[0]:(s.padding.length===2||s.padding.length===3,s.padding[1]),Vt=s=>s?.padding===null||s?.padding===void 0?V.padding:typeof s.padding=="number"?s.padding:s.padding.length===0?V.padding:(s.padding.length===1||s.padding.length===2||s.padding.length===3,s.padding[0]),$e=1,Ie=1,xo=1,Co=1;class $o{constructor(t){this.margin=t.margin||0,this.defaultWidths=t.defaultWidths||null,this.defaultHeights=t.defaultHeights||null,this.minWidths=t.minWidths||null,this.minHeights=t.minHeights||null,this.sections=[];for(const e of t.sections){const a=[];this.sections.push(a);for(const l of e)a.push(new Io(l))}}}class Io{constructor(t){this.label=t.label||null,this.ports=t.ports||[],this.priority=t.priority||Mt,this.resizableX=t.resizableX,this.resizableY=t.resizableY;const e=it(t.look||Oe);this.defaultLook=e.defaultLook,this.selectedLook=e.selectedLook,this.highlightedLook=e.highlightedLook,this.selectedAndHighlightedLook=e.selectedAndHighlightedLook}}class F extends xt{constructor(t,e,a,l,n,i,r,o){if(t.sections.get(o)!==void 0)throw new Error(`DiagramSection with id "${o}" already exists`);if(!o)throw new Error("DiagramSection cannot have an empty or null id");super(t,o),this.ports=[],this.decorators=[],this.node=e,this.indexXInNode=a,this.indexYInNode=l,this.coords=n,this.width=i,this.height=r}get name(){return this.label?.text||""}set name(t){this.label&&(this.label.text=t)}get look(){return this.selected?this.highlighted?this._selectedAndHighlightedLook!==void 0?this._selectedAndHighlightedLook:this.type?.selectedAndHighlightedLook||this.node?.look:this._selectedLook!==void 0?this._selectedLook:this.type?.selectedLook||this.node?.look:this.highlighted?this._highlightedLook!==void 0?this._highlightedLook:this.type?.highlightedLook||this.node?.look:this._defaultLook!==void 0?this._defaultLook:this.type?.defaultLook||this.node?.look}set look(t){if(t){const e=it(t);this._defaultLook={...this._defaultLook,...e.defaultLook},this._selectedLook={...this._selectedLook,...e.selectedLook},this._highlightedLook={...this._highlightedLook,...e.highlightedLook},this._selectedAndHighlightedLook={...this._selectedAndHighlightedLook,...e.selectedAndHighlightedLook}}else this._defaultLook=t,this._selectedLook=t,this._highlightedLook=t,this._selectedAndHighlightedLook=t}get removed(){return this.selfRemoved||this.node!==void 0&&this.node.removed}updateInView(){this.model.canvas?.updateSectionsInView(this.id)}raise(){this.select()?.raise(),this.label&&this.label.raise();for(const t of this.ports)t.raise();for(const t of this.decorators)t.raise()}get type(){return this.node?.type?.sectionGrid?.sections?.[this.indexYInNode]?.[this.indexXInNode]}getMinWidth(){return this.node?.type?.sectionGrid?.minWidths?.[this.indexXInNode]||xo}getMinHeight(){return this.node?.type?.sectionGrid?.minHeights?.[this.indexYInNode]||Co}getPriority(){return this.node?.type?.sectionGrid?.sections?.[this.indexYInNode]?.[this.indexXInNode]?.priority||Mt}getResizableX(){const t=this.type;return t?.resizableX!==void 0?t.resizableX:this.node?.type?.resizableX||!1}getResizableY(){const t=this.type;return t?.resizableY!==void 0?t.resizableY:this.node?.type?.resizableY||!1}getClosestPortToPoint(t){if(this.ports.length!==0){if(this.ports.length===1)return this.ports[1];{const e=this.ports.map(n=>n.distanceTo(t)),a=e.indexOf(Math.min(...e));return this.ports[a]}}}getIncomingConnections(t=!1){const e=[];for(const a of this.ports)for(const l of a.incomingConnections)!t&&l.removed||e.push(l);return e}getOutgoingConnections(t=!1){const e=[];for(const a of this.ports)for(const l of a.outgoingConnections)!t&&l.removed||e.push(l);return e}getConnections(t=!1){const e=[];for(const a of this.ports){for(const l of a.incomingConnections)!t&&l.removed||e.push(l);for(const l of a.outgoingConnections)!t&&l.removed||e.push(l)}return e}move(t){this.setGeometry({coords:t,width:this.width,height:this.height})}stretch(t,e){const a=[this.coords[0],this.coords[0]+this.width],l=[this.coords[1],this.coords[1]+this.height];let n,i;switch(t){case g.Left:n=[a[0]-e,a[1]],i=[l[0],l[1]],n[1]-n[0]<this.getMinWidth()&&(n[0]=n[1]-this.getMinWidth());break;case g.Top:n=[a[0],a[1]],i=[l[0]-e,l[1]],i[1]-i[0]<this.getMinHeight()&&(i[0]=i[1]-this.getMinHeight());break;case g.Right:n=[a[0],a[1]+e],i=[l[0],l[1]],n[1]-n[0]<this.getMinWidth()&&(n[1]=n[0]+this.getMinWidth());break;case g.Bottom:n=[a[0],a[1]],i=[l[0],l[1]+e],i[1]-i[0]<this.getMinHeight()&&(i[1]=i[0]+this.getMinHeight());break}this.setGeometry({coords:[n[0],i[0]],width:n[1]-n[0],height:i[1]-i[0]})}getGeometry(){return{coords:[...this.coords],width:this.width,height:this.height}}setGeometry(t){const e=[this.coords[0],this.coords[0]+this.width],a=[this.coords[1],this.coords[1]+this.height];this.coords=[...t.coords],this.width=t.width,this.height=t.height;const l=[this.coords[0],this.coords[0]+this.width],n=[this.coords[1],this.coords[1]+this.height];for(const r of this.ports)r.move(Yt(r.coords,e,a,l,n,r.anchorPointX,r.anchorPointY));const i=this.type;this.label&&(this.label.coords=[this.coords[0]+U(i?.label),this.coords[1]+G(i?.label)],this.label.width=this.width-U(i?.label)-et(i?.label),this.label.height=this.height-G(i?.label)-Z(i?.label),this.label.updateInView());for(const r of this.decorators)r.move(Yt(r.coords,e,a,l,n,r.anchorPointX,r.anchorPointY));this.model.canvas?.autoTightenConnections!==!1&&this.getConnections().forEach(r=>r.tighten()),this.updateInView()}}class Ao extends ht{constructor(t){super(),this.model=t}new(t,e,a,l,n,i,r){const o=new F(this.model,t,e,a,l,n,i,r);super.add(o),o.updateInView(),t.sections.push(o),t.updateInView();const c=t.type.sectionGrid?.sections?.[a]?.[e]?.ports;if(c&&c.length>0)for(let h=0;h<c.length;++h){const u=c[h],y=this.model.ports.new(u.type!==void 0?this.model.ports.types.get(u.type):void 0,o,[o.coords[0]+(u.coords[0]||0),o.coords[1]+(u.coords[1]||0)],u.connectionPoint!==void 0?[o.coords[0]+(u.connectionPoint[0]||0),o.coords[1]+(u.connectionPoint[1]||0)]:void 0,u?.direction,`${o.id}_${h}`,u.anchorPointX||"floating",u.anchorPointY||"floating");if(y.type?.label){const v={...V,...y.type?.label},m=6*v.fontSize+Rt(v)+zt(v),p=v.fontSize+Vt(v)+Pt(v);let k;switch(y.direction){case g.Bottom:case g.Left:case g.Right:k=[y.coords[0]-m/2,y.coords[1]-p-Z(v)];break;case g.Top:k=[y.coords[0]-m/2,y.coords[1]+G(v)];break;default:k=y.coords}this.model.fields.new(y,k,v.fontSize,v.fontFamily,v.color,v.selectedColor,m,p,v.horizontalAlign,v.verticalAlign,v.orientation,"",v.editable,v.fit,v.shrink)}}const d=t.type.sectionGrid?.sections?.[a]?.[e]?.label;if(d){const h={...V,...d};this.model.fields.new(o,[o.coords[0]+U(h),o.coords[1]+G(h)],h.fontSize,h.fontFamily,h.color,h.selectedColor,o.width-U(h)-et(h),o.height-G(h)-Z(h),h.horizontalAlign,h.verticalAlign,h.orientation,"",h.editable,h.fit,h.shrink)}return o}remove(t){const e=this.get(t,!0);if(e){for(;e.ports.length>0;)this.model.ports.remove(e.ports[0].id);e.label&&this.model.fields.remove(e.label.id),e.node&&D(e.node.sections,e),super.remove(t),e.updateInView()}}}const Oe={lookType:"shaped-look",shape:Et.Rectangle,fillColor:"#FFFFFF",borderColor:"#000000",borderThickness:1,selected:{fillColor:"#FFAAFF",borderColor:"#AA00AA"},highlighted:{borderThickness:3}},dt={name:"",defaultWidth:1,defaultHeight:1,minWidth:1,minHeight:1,resizableX:!1,resizableY:!1,snapToGridOffset:[0,0,0,0],padding:0,label:null,ports:[],decorators:[],sectionGrid:null,look:Oe,isUnique:!1,canBeParentless:!0,childrenTypes:[],priority:Mt,properties:[]};class He{constructor(t){const e={...dt,...t};this.id=e.id,this.name=e.name,this.defaultWidth=e.defaultWidth,this.defaultHeight=e.defaultHeight,this.minWidth=e.minWidth,this.minHeight=e.minHeight,this.resizableX=e.resizableX,this.resizableY=e.resizableY,this.snapToGridOffset=e.snapToGridOffset,this.bottomPadding=Eo(e),this.leftPadding=Mo(e),this.rightPadding=To(e),this.topPadding=No(e),this.label=e.label,this.ports=e.ports,this.decorators=e.decorators,this.sectionGrid=e.sectionGrid?new $o(e.sectionGrid):null;const a=it(e.look);this.defaultLook=a.defaultLook,this.selectedLook=a.selectedLook,this.highlightedLook=a.highlightedLook,this.selectedAndHighlightedLook=a.selectedAndHighlightedLook,this.isUnique=e.isUnique,this.canBeParentless=e.canBeParentless,this.childrenTypes=e.childrenTypes,this.priority=e.priority,this.propertySet=new Zt(t?.properties||[])}}class R extends xt{constructor(t,e,a=[0,0],l){if(t.nodes.get(l)!==void 0)throw new Error(`DiagramNode with id "${l}" already exists`);if(!l)throw new Error("DiagramNode cannot have an empty or null id");super(t,l),this.children=[],this.sections=[],this.ports=[],this.decorators=[],this.geometryTimestamp=null,this._type=e,this.valueSet=new mt(e.propertySet,this),this.originalData={},this.coords=a,this.width=e.defaultWidth,this.height=e.defaultHeight}get type(){return this._type}set type(t){t!==this._type&&(this._type=t,this.valueSet&&(this.valueSet=new mt(t.propertySet,this)),this.model.canvas?.userSelection?.openInPropertyEditor(this,!1),this.updateInView())}get typeString(){return this.type.id}set typeString(t){if(t!==this.type.id){const e=this.model.nodes.types.get(t);e&&(this.type=e)}}get name(){return this.label?.text||""}set name(t){this.label&&(this.label.text=t)}get look(){return this.selected?this.highlighted?this._selectedAndHighlightedLook!==void 0?this._selectedAndHighlightedLook:this.type.selectedAndHighlightedLook:this._selectedLook!==void 0?this._selectedLook:this.type.selectedLook:this.highlighted?this._highlightedLook!==void 0?this._highlightedLook:this.type.highlightedLook:this._defaultLook!==void 0?this._defaultLook:this.type.defaultLook}set look(t){if(t){const e=it(t);this._defaultLook={...this._defaultLook,...e.defaultLook},this._selectedLook={...this._selectedLook,...e.selectedLook},this._highlightedLook={...this._highlightedLook,...e.highlightedLook},this._selectedAndHighlightedLook={...this._selectedAndHighlightedLook,...e.selectedAndHighlightedLook}}else this._defaultLook=t,this._selectedLook=t,this._highlightedLook=t,this._selectedAndHighlightedLook=t}get removed(){return this.selfRemoved}updateInView(){this.model.canvas?.updateNodesInView(this.id)}raise(){this.select()?.raise();for(const t of this.sections)t.raise();this.label&&this.label.raise();for(const t of this.ports)t.raise();for(const t of this.decorators)t.raise();for(const t of this.children)t.raise()}getPriority(){return this.type.priority}getClosestPortToPoint(t){if(this.ports.length!==0){if(this.ports.length===1)return this.ports[1];{const e=this.ports.map(n=>n.distanceTo(t)),a=e.indexOf(Math.min(...e));return this.ports[a]}}}getIncomingConnections(t=!1){const e=[];for(const a of this.ports)for(const l of a.incomingConnections)!t&&l.removed||e.push(l);return e}getOutgoingConnections(t=!1){const e=[];for(const a of this.ports)for(const l of a.outgoingConnections)!t&&l.removed||e.push(l);return e}getConnections(t=!1){const e=[];for(const a of this.ports){for(const l of a.incomingConnections)!t&&l.removed||e.push(l);for(const l of a.outgoingConnections)!t&&l.removed||e.push(l)}return e}getAdjacentNodes(t=!1){const e=[];for(const a of this.ports){for(const l of a.incomingConnections){if(!t&&l.removed)continue;const n=l.start?.getNode();if(n){if(!t&&n.removed)continue;e.push(n)}}for(const l of a.outgoingConnections){if(!t&&l.removed)continue;const n=l.end?.getNode();if(n){if(!t&&n.removed)continue;e.push(n)}}}return e}getLastAncestor(){let t=this;for(;t.parent!==void 0;)t=t?.parent;return t}isAncestorOf(t){let e=t;for(;e!==void 0;){if(this.id===e.id)return!0;e=e.parent}return!1}isDescendantOf(t){return t.isAncestorOf(this)}addChild(t){if(t.id===this.id)return;let e=this.parent,a=!1;for(;e!==void 0;){if(e.id===t.id){a=!0;break}e=e.parent}a||this.children.indexOf(t)>=0||(this.fitToChild(t),this.children.push(t),t.parent=this,t.raise())}removeChild(t){D(this.children,t),t.parent=void 0}fitToChild(t){const e=Math.max(...this.sections.map(o=>o.indexXInNode)),a=Math.max(...this.sections.map(o=>o.indexYInNode)),l=this.coords[0]-t.coords[0]+this.type.leftPadding;l>=0&&(this.sections.length>0?this.stretchSections(g.Left,l,e,a):this.stretch(g.Left,l));const n=this.coords[1]-t.coords[1]+this.type.topPadding;n>=0&&(this.sections.length>0?this.stretchSections(g.Top,n,e,a):this.stretch(g.Top,n));const i=t.coords[0]+t.width-(this.coords[0]+this.width)+this.type.rightPadding;i>=0&&(this.sections.length>0?this.stretchSections(g.Right,i,e,a):this.stretch(g.Right,i));const r=t.coords[1]+t.height-(this.coords[1]+this.height)+this.type.bottomPadding;r>=0&&(this.sections.length>0?this.stretchSections(g.Bottom,r,e,a):this.stretch(g.Bottom,r)),this.parent&&this.parent.fitToChild(this)}move(t){const e=[t[0]-this.coords[0],t[1]-this.coords[1]];for(const a of this.children)a.move([a.coords[0]+e[0],a.coords[1]+e[1]]);for(const a of this.sections)a.move([a.coords[0]+e[0],a.coords[1]+e[1]]);this.setGeometry({coords:t,width:this.width,height:this.height,sections:{},children:{}})}stretch(t,e){const a=[this.coords[0],this.coords[0]+this.width],l=[this.coords[1],this.coords[1]+this.height];let n,i;switch(t){case g.Left:n=[a[0]-e,a[1]],i=[l[0],l[1]],n[1]-n[0]<this.type.minWidth&&(n[0]=n[1]-this.type.minWidth);break;case g.Top:n=[a[0],a[1]],i=[l[0]-e,l[1]],i[1]-i[0]<this.type.minHeight&&(i[0]=i[1]-this.type.minHeight);break;case g.Right:n=[a[0],a[1]+e],i=[l[0],l[1]],n[1]-n[0]<this.type.minWidth&&(n[1]=n[0]+this.type.minWidth);break;case g.Bottom:n=[a[0],a[1]],i=[l[0],l[1]+e],i[1]-i[0]<this.type.minHeight&&(i[1]=i[0]+this.type.minHeight);break}this.setGeometry({coords:[n[0],i[0]],width:n[1]-n[0],height:i[1]-i[0],sections:{},children:{}})}stretchSections(t,e,a,l){let n=Number.NEGATIVE_INFINITY;switch(t){case g.Bottom:for(const i of this.sections)i.indexYInNode===l&&(n=Math.max(n,i.getMinHeight()-i.height));e<n&&(e=n);for(const i of this.sections)i.indexYInNode===l?i.stretch(t,e):i.indexYInNode>l&&i.move([i.coords[0],i.coords[1]+e]);break;case g.Right:for(const i of this.sections)i.indexXInNode===a&&(n=Math.max(n,i.getMinWidth()-i.width));e<n&&(e=n);for(const i of this.sections)i.indexXInNode===a?i.stretch(t,e):i.indexXInNode>a&&i.move([i.coords[0]+e,i.coords[1]]);break;case g.Top:for(const i of this.sections)i.indexYInNode===l&&(n=Math.max(n,i.getMinHeight()-i.height));e<n&&(e=n);for(const i of this.sections)i.indexYInNode===l?i.stretch(t,e):i.indexYInNode<l&&i.move([i.coords[0],i.coords[1]-e]);break;case g.Left:for(const i of this.sections)i.indexXInNode===a&&(n=Math.max(n,i.getMinWidth()-i.width));e<n&&(e=n);for(const i of this.sections)i.indexXInNode===a?i.stretch(t,e):i.indexXInNode<a&&i.move([i.coords[0]-e,i.coords[1]]);break}this.stretch(t,e)}getGeometry(t){const e={};for(const l of this.sections)e[l.id]=l.getGeometry();const a={};for(const l of this.children)l.id!==t&&(a[l.id]=l.getGeometry(t));return{coords:[...this.coords],width:this.width,height:this.height,sections:e,children:a}}setGeometry(t){this.raise();const e=[this.coords[0],this.coords[0]+this.width],a=[this.coords[1],this.coords[1]+this.height];this.coords=[...t.coords],this.width=t.width,this.height=t.height;const l=[this.coords[0],this.coords[0]+this.width],n=[this.coords[1],this.coords[1]+this.height];for(const i of this.children){const r=t.children[i.id];r&&i.setGeometry(r)}for(const i of this.sections){const r=t.sections[i.id];r&&i.setGeometry(r)}for(const i of this.ports)i.move(Yt(i.coords,e,a,l,n,i.anchorPointX,i.anchorPointY));this.label&&(this.label.coords=[this.coords[0]+U(this.type.label),this.coords[1]+G(this.type.label)],this.label.width=this.width-U(this.type.label)-et(this.type.label),this.label.height=this.height-G(this.type.label)-Z(this.type.label),this.label.updateInView());for(const i of this.decorators)i.move(Yt(i.coords,e,a,l,n,i.anchorPointX,i.anchorPointY));this.model.canvas?.autoTightenConnections!==!1&&this.getConnections().forEach(i=>i.tighten()),this.updateInView()}removeSectionColumn(t){const e=this.type.sectionGrid?.margin||0;let a=0;const l=[...this.sections];for(const n of l)n.indexYInNode===t&&(a=Math.max(a,n.width),this.model.sections.remove(n.id));for(const n of l)n.indexYInNode>t&&(--n.indexYInNode,n.move([n.coords[0]-a-e,n.coords[1]]));this.stretch(g.Right,-e-a)}removeSectionRow(t){const e=this.type.sectionGrid?.margin||0;let a=0;const l=[...this