UNPKG

@metadev/daga-react

Version:

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

1,131 lines (1,130 loc) 302 kB
import { jsx as v, jsxs as M, Fragment as no } from "react/jsx-runtime"; import * as x from "d3"; import { debounceTime as ro, Subject as Yt, merge as ao, map as lo } from "rxjs"; import { createContext as Ve, useState as U, useContext as Ft, useRef as rt, useEffect as Ct, useMemo as co } from "react"; var g = /* @__PURE__ */ ((s) => (s.Bottom = "bottom", s.Left = "left", s.Right = "right", s.Top = "top", s))(g || {}), jt = /* @__PURE__ */ ((s) => (s.BottomLeft = "bottom-left", s.BottomRight = "bottom-right", s.TopLeft = "top-left", s.TopRight = "top-right", s))(jt || {}), Lt = /* @__PURE__ */ ((s) => (s.Left = "left", s.Center = "center", s.Right = "right", s))(Lt || {}), Zt = /* @__PURE__ */ ((s) => (s.Top = "top", s.Center = "center", s.Bottom = "bottom", s))(Zt || {}); const At = (s) => [Math.round(s[0]), Math.round(s[1])], ut = (s, t, e) => t < e ? t <= s && s <= e : e <= s && s <= t, $e = (s, t, e) => (s - t[0]) / (t[1] - t[0]) * (e[1] - e[0]) + e[0], Kt = (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 d = (t[0] + t[1]) / 2, c = (a[0] + a[1]) / 2, h = t[1] - t[0], f = a[1] - a[0], y = (s[0] - d) / h; return c + y * f; } case "floating": default: return $e(s[0], t, a); } })(), o = (() => { switch (i) { case "start": return l[0] + (s[1] - e[0]); case "end": return l[1] - (e[1] - s[1]); case "middle": { const d = (e[0] + e[1]) / 2, c = (l[0] + l[1]) / 2, h = e[1] - e[0], f = l[1] - l[0], y = (s[1] - d) / h; return c + y * f; } case "floating": default: return $e(s[1], e, l); } })(); return [r, o]; }, Oe = (s, t) => ((s[0] - t[0]) ** 2 + (s[1] - t[1]) ** 2) ** 0.5, ho = (s, t) => (ut( s[0][0], t[0][0], t[1][0] ) || ut( s[1][0], t[1][0], t[0][0] ) || ut( t[0][0], s[0][0], s[1][0] ) || ut( t[1][0], s[1][0], s[0][0] )) && (ut( s[0][1], t[0][1], t[1][1] ) || ut( s[1][1], t[1][1], t[0][1] ) || ut( t[0][1], s[0][1], s[1][1] ) || ut( t[1][1], s[1][1], s[0][1] )); var $ = /* @__PURE__ */ ((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))($ || {}), Z = /* @__PURE__ */ ((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))(Z || {}), I = /* @__PURE__ */ ((s) => (s.Drag = "drag", s.Start = "start", s.End = "end", s))(I || {}), ge = /* @__PURE__ */ ((s) => (s.Zoom = "zoom", s.Start = "start", s.End = "end", s))(ge || {}); const fe = (s) => s.replace(/([!"#$%&'()*+,\-./:;<=>?@[\\\]^`{|}])/g, "\\$1"); var He = /* @__PURE__ */ ((s) => (s.Straight = "straight", s.Bezier = "bezier", s.Square = "square", s))(He || {}), ye = /* @__PURE__ */ ((s) => (s.Solid = "solid", s.Dashed = "dashed", s.GappedDashes = "gapped-dashes", s.Dotted = "dotted", s))(ye || {}); const go = 20, fo = (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 || go; 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 d = "", c = ""; const h = (Math.abs(t[o][0] - t[o - 1][0]) + Math.abs(t[o][1] - t[o - 1][1])) / 2; switch (i) { case g.Bottom: d = `${t[o - 1][0]} ${t[o - 1][1] + h}`; break; case g.Top: d = `${t[o - 1][0]} ${t[o - 1][1] - h}`; break; case g.Right: d = `${t[o - 1][0] + h} ${t[o - 1][1]}`; break; case g.Left: d = `${t[o - 1][0] - h} ${t[o - 1][1]}`; break; } if (r !== void 0) { switch (r) { case g.Top: c = `${t[o][0]} ${t[o][1] + h}`; break; case g.Bottom: c = `${t[o][0]} ${t[o][1] - h}`; break; case g.Left: c = `${t[o][0] + h} ${t[o][1]}`; break; case g.Right: c = `${t[o][0] - h} ${t[o][1]}`; break; } n += ` C ${d} ${c} ${t[o][0]} ${t[o][1]}`; } else n += ` Q ${d} ${t[o][0]} ${t[o][1]}`; } else if (r !== void 0) { let d = ""; const c = (Math.abs(t[o][0] - t[o - 1][0]) + Math.abs(t[o][1] - t[o - 1][1])) / 2; switch (r) { case g.Top: d = `${t[o][0]} ${t[o][1] + c}`; break; case g.Bottom: d = `${t[o][0]} ${t[o][1] - c}`; break; case g.Left: d = `${t[o][0] + c} ${t[o][1]}`; break; case g.Right: d = `${t[o][0] - c} ${t[o][1]}`; break; } n += ` Q ${d} ${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; } }, ue = (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"; } }, Y = (s, t) => { const e = s.indexOf(t); return e >= 0 && s.splice(e, 1), s; }; var Tt = /* @__PURE__ */ ((s) => (s.Ellipse = "ellipse", s.Empty = "empty", s.Folder = "folder", s.Hexagon = "hexagon", s.Octagon = "octagon", s.Pill = "pill", s.Rectangle = "rectangle", s.Rhombus = "rhombus", s.RoundedRectangle = "rounded-rectangle", s.StickyNote = "sticky-note", s))(Tt || {}); const pe = (s, t, e, a, l) => { if (typeof s == "function") return s(t, e, a, l); switch (s) { case "ellipse": return _e(t, e, a, l); case "empty": return uo(); case "folder": return po(t, e, a, l); case "hexagon": return mo(t, e, a, l); case "octagon": return vo(t, e, a, l); case "pill": return Wt(t, e, a, l); case "rectangle": return Ie(t, e, a, l); case "rhombus": return yo(t, e, a, l); case "rounded-rectangle": return bo(t, e, a, l); case "sticky-note": return ko(t, e, a, l); default: return Ie(t, e, a, l); } }, _e = (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`, uo = () => "Z", po = (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`, mo = (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`, vo = (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`, Wt = (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` : _e(s, t, e, a), Ie = (s, t, e, a) => `M ${s} ${t} L ${s + e} ${t} L ${s + e} ${t + a} L ${s} ${t + a} Z`, yo = (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`, bo = (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`, ko = (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 = /* @__PURE__ */ ((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 wo = (s) => Math.max(...s.split(` `).map((t) => t.length)), So = (s) => s.match(/\n/g)?.length || 0, W = []; for (let s = 0; s < 256; ++s) W.push((s + 256).toString(16).slice(1)); function Co(s, t = 0) { return (W[s[t + 0]] + W[s[t + 1]] + W[s[t + 2]] + W[s[t + 3]] + "-" + W[s[t + 4]] + W[s[t + 5]] + "-" + W[s[t + 6]] + W[s[t + 7]] + "-" + W[s[t + 8]] + W[s[t + 9]] + "-" + W[s[t + 10]] + W[s[t + 11]] + W[s[t + 12]] + W[s[t + 13]] + W[s[t + 14]] + W[s[t + 15]]).toLowerCase(); } let ne; const $o = new Uint8Array(16); function Io() { if (!ne) { if (typeof crypto > "u" || !crypto.getRandomValues) throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported"); ne = crypto.getRandomValues.bind(crypto); } return ne($o); } const Ao = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), Ae = { randomUUID: Ao }; function xe(s, t, e) { if (Ae.randomUUID && !s) return Ae.randomUUID(); s = s || {}; const a = s.random ?? s.rng?.() ?? Io(); 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, Co(a); } const st = (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 Jt { constructor() { this.entities = [], this.entityMap = {}; } /** * The number of entities in this set. * @public */ get length() { return this.size(); } /** * Gets all of the entities of this set. * @public * @returns An array containing all of the entities of this set. */ all() { return [...this.entities]; } /** * Adds an entity to this set if there are no entities with the same id. Has no effect if there already exists an entity with the same id as the given entity. * For creating entities with relationships with other entities, the new() method should be used instead. The add() method adds an entity but doesn't take care of setting that entity's relationships with other entities. * @private * @param entity An entity to be added to this set. */ add(t) { this.entityMap[t.id] === void 0 && (this.entityMap[t.id] = t, this.entities.push(t)); } /** * Removes all the entities in this set. * @public */ clear() { for (; this.entities.length > 0; ) this.remove(this.entities[0].id); } /** * Checks if this set contains an entity with the given id. * @public * @param id An id. * @returns `true` if this set contains an entity with the given id, `false` otherwise. */ contains(t) { return this.entityMap[t] !== void 0; } /** * Counts the number of entities of this set following the given criteria. * @public * @returns The number of entities of this set following the given criteria. */ count(t) { return this.entities.filter(t).length; } /** * Gets all of the entities of this set filtered following given criteria. * @public * @returns An array containing the entities of this set that meet the given criteria. */ filter(t) { return this.entities.filter(t); } /** * Gets an entity of this set matching specific criteria. * @public * @returns An entity of this set. */ find(t) { return this.entities.find(t); } /** * Gets an entity from this set. * @public * @param id An id. * @returns An entity with the given id, or `undefined` if there are no entities with the given id. */ get(t) { return this.entityMap[t]; } /** * Gets all of the entities of this set mapped to the result of the given function applied to them. * @public * @returns An array containing the entities of this set that meet the given criteria. */ map(t) { return this.entities.map(t); } /** * Attempts to find and remove an entity with the given id. Has no effect if there are no entities with the given id. * @public * @param id An id. */ remove(t) { const e = this.get(t); e !== void 0 && (delete this.entityMap[t], Y(this.entities, e)); } /** * Gets the number of entities in this set. * @public */ size() { return this.entities.length; } /** * Iterator to iterate over the entities of this set. * @public */ *[Symbol.iterator]() { for (const t of this.entities) yield t; } } const Nt = 0; class It { constructor(t, e) { this.selfRemoved = !1, this.selfRemovedTimestamp = null, this.model = t, this._id = e; } /** * Identifier that uniquely identifies this element within its diagram model. Cannot be an empty string. * @public */ get id() { return this._id; } /** * Whether this diagram element is currently in the user highlight. * @private */ get highlighted() { return this.model.canvas?.userHighlight?.contains(this.id) || !1; } /** * Whether this diagram element is currently in the user selection. */ get selected() { return this.model.canvas?.userSelection?.contains(this.id) || !1; } /** * Obtain the selection of this element. * @private */ select() { return this.model.canvas?.selectCanvasView()?.select(`[id='${fe(this.id)}']`); } } class ft extends Jt { 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], Y(this.entities, e)); } size(t = !1) { return t ? super.size() : super.filter((e) => !e.removed).length; } *[Symbol.iterator](t = !1) { if (t) for (const e of this.entities) yield e; else for (const e of this.entities.filter((a) => !a.removed)) yield e; } } class xo { constructor(t, e, a, l, 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 = /* @__PURE__ */ ((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 Qt { constructor(t = []) { this.propertyList = t, this.propertyMap = {}; for (const e of this.propertyList) this.propertyMap[e.name] = e; } getProperty(t) { return this.propertyMap[t]; } hasProperty(t) { return this.propertyMap[t] !== void 0; } hasProperties() { return this.propertyList.length > 0; } } function kt(s, t) { return !t || s[0] > t[0] ? !0 : s[0] === t[0] ? s[1] >= t[1] : !1; } const Le = (s) => s == null || s === "" || s instanceof Array && s.length === 0 || s instanceof Object && Object.keys(s).length === 0, St = (s, t) => s === t || JSON.stringify(s) === JSON.stringify(t), Ge = (s, t, e) => { const a = {}, l = {}; for (const n in e.propertySet.propertyMap) if (e.propertySet.propertyMap[n].type === T.Object) { const i = Ge( 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 St(s[n], t[n]) || (a[n] = s[n], l[n] = t[n]); return [a, l]; }, Lo = (s) => s != null && s.constructor === Object; class yt { constructor(t, e) { this.displayedProperties = [], this.hiddenProperties = [], this.values = {}, this.valueSets = {}, this.ownTimestamps = {}, this.propertySet = t, this.rootElement = e, this.resetValues(); } /** * Gets the value of the root element attribute under the given keys. * If given an array of keys, the value is found under repeated lookups to enable obtaining nested values. * @public * @param rootAttribute A key or array of keys to look up in the root element. * @returns The value if it could be found, `undefined` if nothing could be found. */ 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; } } } /** * Sets the value of the root element's attribute under the given keys. * If given an array of keys, the value is found under repeated lookups to enable setting nested values. * If the root element has a function `updateInView()`, it is called upon successful setting of the value. * If the root element's attribute doesn't exist, it does nothing. * @private * @param rootAttribute A key or array of keys to look up in the root element. * @param value The value to set the root element's attribute to. */ 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(); } } /** * Obtains the value under the given key. * @private * @param key A key. * @returns The value under the given key. */ // eslint-disable-next-line @typescript-eslint/no-explicit-any 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]; } /** * Obtains all the values in the set. * @private * @returns An object containing all the values in the set. */ 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; } /** * Returns the values for all keys present in the given object, including keys in sub-objects. * @private * @param values An object containing all values for keys present in the given object. */ 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; } /** * Obtains all CollabTimestamps in the set, including those corresponding to nested keys. * @private * @returns An object containing all the CollabTimestamps in the set. */ 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; } /** * Checks if the value under the key is not empty. * @private * @param key A key. * @returns `true` if the value under the key is empty, `false` otherwise. */ hasValue(t) { const e = this.getValue(t); return !Le(e); } /** * Checks if the value under the key is not empty or the default value. * @private * @param key A key. * @returns `true` if the value under the key is not empty or the default value, `false` otherwise. */ hasSetValue(t) { const e = this.getValue(t), a = this.propertySet.getProperty(t); return a && a.type === T.Object ? this.getSubValueSet(t).hasAnySetValue() : !Le(e) && !St(e, a?.defaultValue); } /** * Checks if any of the values in the set are not empty or the default value. * @private * @returns `true` if any of the values in the set are not empty or the default value, `false` otherwise. */ hasAnySetValue() { for (const t of this.propertySet.propertyList) if (this.hasSetValue(t.name)) return !0; return !1; } /** * Sets the value under the given key. * @private * @param key A key. * @param value A value. */ setValue(t, e) { const a = this.propertySet.getProperty(t); if (a) { a.type === T.Object ? this.valueSets[t].setValues(e) : (this.values[t] = e, St(e, a.defaultValue) || this.displayProperty(a)); const l = a.rootAttribute; l != null && this.setRootElementValue(l, e); } } /** * Resets all values and then set them to the given values. * @private * @param values An object containing all values to set the values to. */ 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]); } /** * Resets all timestamps and then set them to the given timestamps. * @private * @param values An object containing all the CollabTimestamps in the set. */ 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]; } /** * Writes the given values over the value set's existing values without resetting the existing values. * @private * @param values An object containing all values to set the values to. */ 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]); } /** * Variant of `overwriteValues` that applies last-writer-wins to each key, updating timestamps if appropriate. * @private * @param values An object containing all values to set the values to. */ overwriteValuesLww(t, e) { for (const a in t) this.propertySet.getProperty(a).type === T.Object ? this.valueSets[a].overwriteValuesLww( t[a], e ) : kt(e, this.ownTimestamps[a]) && (this.setValue(a, t[a]), this.ownTimestamps[a] = e); } /** * Sets all the values of this set to the defaults. * If this set has a root element and any of its properties have root attributes, the root element's attributes are also set to the property's default value if one is provided. * @private */ 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 && !St( this.getRootElementValue(a), e.defaultValue ) && this.setRootElementValue(a, this.values[t]), e.basic !== !1 ? this.displayedProperties.push(e) : this.hiddenProperties.push(e); } } /** * Constructs a ValueSet with its corresponding PropertySet representing the values of the object. * @private * @param key Key that the ValueSet is under. * @returns The constructed ValueSet. */ constructSubValueSet(t) { const e = this.propertySet.getProperty(t), a = new Qt(e.properties), l = new yt(a, this.rootElement); return l.overwriteValues( structuredClone(e.defaultValue) ), l; } /** * Gets the ValueSet under the given key when there are nested ValueSets. * @private * @param key A key. * @returns A ValueSet. */ getSubValueSet(t) { return this.valueSets[t]; } /** * Moves the given property to the list of displayed properties. * @private * @param property A property. */ displayProperty(t) { this.displayedProperties.includes(t) || (this.displayedProperties.push(t), Y(this.hiddenProperties, t)); } /** * Moves the given property to the list of hidden properties. * @private * @param property A property. */ hideProperty(t) { this.hiddenProperties.includes(t) || (this.hiddenProperties.push(t), Y(this.displayedProperties, t)); } } const et = { name: "", label: null, look: { lookType: "connection-look", color: "#000000", thickness: 1, shape: He.Straight, style: ye.Solid, selected: { color: "#AA00AA" }, highlighted: { thickness: 2 } }, startMarkerLook: void 0, endMarkerLook: void 0, startTypes: [], endTypes: [], properties: [] }; class Fe { constructor(t) { const e = { ...et, ...t }; this.id = e.id, this.name = e.name, this.label = e.label; const a = st(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 = st( 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 = st( e.endMarkerLook ); this.defaultEndMarkerLook = l.defaultLook, this.selectedEndMarkerLook = l.selectedLook, this.highlightedEndMarkerLook = l.highlightedLook, this.selectedAndHighlightedEndMarkerLook = l.selectedAndHighlightedLook; } else this.defaultEndMarkerLook = null, this.selectedEndMarkerLook = null, this.highlightedEndMarkerLook = null, this.selectedAndHighlightedEndMarkerLook = null; this.startTypes = e.startTypes, this.endTypes = e.endTypes, this.propertySet = new Qt(e.properties); } canStartFromType(t) { return this.startTypes.indexOf(t) >= 0; } canFinishOnType(t) { return this.endTypes.indexOf(t) >= 0; } } class dt extends It { 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 yt(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 yt(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); } } /** * Name of this connection. Alias for this connection's middle label. * @public */ get name() { return this.middleLabel; } set name(t) { this.middleLabel = t; } /** * Current look of the connection. * @private */ 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; } /** * Sets the look configuration of the connection to override the one determined by the type. * `undefined` resets it to the one determined by the type. * @private */ set look(t) { if (t) { const e = st(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; } /** * Current look of the start marker. * @private */ 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; } /** * Sets the look configuration of the start marker to override the one determined by the type. * `null` stands for no marker and `undefined` resets it to the one determined by the type. * @private */ set startMarkerLook(t) { if (t) { const e = st(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; } /** * Current look of the end marker. * @private */ 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; } /** * Sets the look configuration of the end marker to override the one determined by the type. * `null` stands for no marker and `undefined` resets it to the one determined by the type. * @private */ set endMarkerLook(t) { if (t) { const e = st(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(); } /** * Set the start of this connection to the given port or reset this connection's starting port if `undefined`. * Add or remove this connection from the list of outgoing connections of ports correspondingly. * @public * @param start A port. */ setStart(t) { this.start !== t ? (this.start !== void 0 && Y(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(); } /** * Set the end of this connection to the given port or reset this connection's ending port if `undefined`. * Add or remove this connection from the list of incoming connections of ports correspondingly. * @public * @param end A port. */ setEnd(t) { this.end !== t ? (this.end !== void 0 && Y(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(); } /** * Reassign the start and end ports of this connection to ports with less distance between them that have the same root element. * If no ports with less distance between them are found, do nothing. * @public */ 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() : Nt; } } class Eo extends ft { /** * Instance a set of connections for the given model. This method is used internally. * @private */ constructor(t) { super(), this.types = new Jt(), this.model = t; } /** * Instance a new connection and add it to this set. * @public * @param type The type of the connection given as either the type itself or the id of the type. * @param start The start port of the connection. * @param end The end port of the connection. * @param id The id of the connection. Cannot be an empty string. * @returns The instanced connection. */ new(t, e, a, l) { let n; if (t instanceof Fe) 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 dt( this.model, n,