UNPKG

ranui

Version:

A framework-agnostic Web Components UI library built on native custom elements, with TypeScript types, light/dark theming, SSR and PWA support.

1,710 lines 176 kB
import { n as l } from "./chunk-Y2CYZVJY-0JxdZxki.js"; import { m as We } from "./src-DtRLxcYO.js"; import { b as Cr, x as Lr } from "./chunk-WYO6CB5R-DDHkKowO.js"; import { g as Ne } from "./chunk-ICXQ74PX-DR8rL-xF.js"; import "./chunk-HOUHSVGY-DRQcQeMT.js"; import "./chunk-Q4XR5HBZ-3BHjjc9u.js"; import { r as To } from "./chunk-7BUUIJ7U-9hiBbc7O.js"; import { n as vr } from "./chunk-OGEWGWER-BV51ll2w.js"; import { t as wr } from "./graphlib-CCKThIKP.js"; import { n as Tr } from "./chunk-RYQCIY6F-BER2T9t0.js"; import "./chunk-C7G6YPKG-CA-DNpvI.js"; import { a as Er, c as Ar, i as Rr, n as Nr, t as Or } from "./chunk-ZGVPDNZ5-6uMbTJXy.js"; import { a as Pr, i as Br, n as kr, r as Fr, s as Xe, t as _r } from "./chunk-52WLFC77-wpL7en7e.js"; async function Bo(t, e) { const n = new wr({ multigraph: !0, compound: !0 }), o = [...e.edges], s = Lr(), r = t.insert("g").attr("class", "root"), i = r.insert("g").attr("class", "clusters"), a = r.insert("g").attr("class", "edges edgePath"), d = r.insert("g").attr("class", "edgeLabels"), c = r.insert("g").attr("class", "nodes"), g = /* @__PURE__ */ new Map(), b = t.node() != null; await Promise.all(e.nodes.map(async (x) => { if (x.isGroup) n.setNode(x.id, { ...x }); else { if (b) { const h = await Er(c, x, { config: s, dir: x.dir }), p = h.node()?.getBBox() ?? { width: 0, height: 0 }; g.set(x.id, h), x.width = p.width, x.height = p.height; } n.setNode(x.id, { ...x }); } })); for (const x of o) n.setEdge(x.start, x.end, { ...x }, x.id), e.edges.some((h) => h.id === x.id) || e.edges.push(x); if (globalThis.mermaidCaptureSizes) { const { captureNodeSizes: x } = await import("./sizeCapture-X5ZJPWSS-D7rGsqTl.js"); x(t, e); } return { graph: n, groups: { clusters: i, edgePaths: a, edgeLabels: d, nodes: c, rootGroups: r }, nodeElements: g }; } l(Bo, "createGraphWithElements"); var Eo = 5, Ye = 1e-5, $e = 1e-6; function Ke(t) { const e = []; for (let n = 0; n < t.length - 1; n++) e.push({ a: t[n], b: t[n + 1] }); return e; } l(Ke, "buildSegmentList"); function ko(t, e, n, o) { const s = e.x - t.x, r = e.y - t.y, i = o.x - n.x, a = o.y - n.y, d = s * a - r * i; if (d === 0) return null; const c = n.x - t.x, g = n.y - t.y, b = (c * a - g * i) / d, x = (c * r - g * s) / d; return b <= $e || b >= 1 - $e || x <= $e || x >= 1 - $e ? null : { point: { x: t.x + b * s, y: t.y + b * r }, tA: b, tB: x }; } l(ko, "segmentIntersection"); function Sn(t) { return Math.abs(t.b.x - t.a.x) >= Math.abs(t.b.y - t.a.y); } l(Sn, "isHorizontalSeg"); function Fo(t) { const e = []; for (let n = 0; n < t.length; n++) { const o = t[n], s = Ke(o.points); for (let r = n + 1; r < t.length; r++) { const i = t[r], a = Ke(i.points); for (const [d, c] of s.entries()) for (const [g, b] of a.entries()) { const x = ko(c.a, c.b, b.a, b.b); if (!x) continue; const h = Sn(c); h !== Sn(b) && h ? e.push({ jumpEdgeId: o.id, otherEdgeId: i.id, segIndex: d, t: x.tA, point: x.point }) : e.push({ jumpEdgeId: i.id, otherEdgeId: o.id, segIndex: g, t: x.tB, point: x.point }); } } } return e; } l(Fo, "findEdgeIntersections"); function te(t) { const e = Math.round(t * 1e3) / 1e3; return Number.isInteger(e) ? `${e}` : `${e}`; } l(te, "fmt"); function we(t) { return `${te(t.x)},${te(t.y)}`; } l(we, "pointToString"); function _o(t) { const e = t.b.x - t.a.x, n = t.b.y - t.a.y; return Math.abs(e) >= Math.abs(n) ? e >= 0 ? 1 : 0 : n >= 0 ? 1 : 0; } l(_o, "getArcSweepFlag"); var Dr = 1e-3; function Do(t, e) { if (t.length < 2) return t.map((r) => ({ ...r })); const n = t.map((r) => ({ ...r })), o = e.arrowTypeStart && To[e.arrowTypeStart]; if (o) { const r = t[0], i = t[1], a = Math.atan2(i.y - r.y, i.x - r.x); n[0].x = r.x + o * Math.cos(a), n[0].y = r.y + o * Math.sin(a); } const s = e.arrowTypeEnd && To[e.arrowTypeEnd]; if (s) { const r = t.length, i = t[r - 2], a = t[r - 1], d = Math.atan2(a.y - i.y, a.x - i.x); n[r - 1].x = a.x - s * Math.cos(d), n[r - 1].y = a.y - s * Math.sin(d); } return n; } l(Do, "applyMarkerOffsets"); function Ho(t, e, n, o, s) { const r = t.point.x, i = t.point.y, a = { x: r - e * t.r, y: i - n * t.r }, d = { x: r + e * t.r, y: i + n * t.r }, c = [`L${we(a)}`]; return s === "arc" ? c.push(`A${te(t.r)},${te(t.r)} 0 0 ${o} ${we(d)}`) : c.push(`M${we(d)}`), c; } l(Ho, "emitJump"); function Cn(t, e, n, o) { const s = e.x - t.x, r = e.y - t.y, i = n.x - e.x, a = n.y - e.y, d = Math.hypot(s, r), c = Math.hypot(i, a); if (d < Ye || c < Ye) return null; const g = s / d, b = r / d, x = i / c, h = a / c, p = g * x + b * h, f = Math.acos(Math.max(-1, Math.min(1, p))); if (f < Ye || Math.abs(Math.PI - f) < Ye) return null; const M = Math.min(o / Math.sin(f / 2), d / 2, c / 2); return { startX: e.x - g * M, startY: e.y - b * M, endX: e.x + x * M, endY: e.y + h * M, ctrlX: e.x, ctrlY: e.y, cutLen: M }; } l(Cn, "computeRoundedCorner"); function Xo(t, e, n) { const o = t.points; if (o.length < 2) return ""; const s = Do(o, t), r = t.curve === "rounded", i = Ke(s), a = /* @__PURE__ */ new Map(); for (const c of e) { const g = i[c.segIndex]; if (!g) continue; const b = Math.hypot(g.b.x - g.a.x, g.b.y - g.a.y), x = a.get(c.segIndex) ?? []; x.push({ t: c.t, point: c.point, d: c.t * b, r: n.jumpRadius }), a.set(c.segIndex, x); } const d = [`M${we(s[0])}`]; for (let c = 0; c < i.length; c++) { const g = i[c], b = Math.hypot(g.b.x - g.a.x, g.b.y - g.a.y), x = b === 0 ? 0 : (g.b.x - g.a.x) / b, h = b === 0 ? 0 : (g.b.y - g.a.y) / b, p = _o(g); let f = 0; if (r && c > 0) { const T = Cn(s[c - 1], s[c], s[c + 1] ?? s[c], Eo); T && (f = T.cutLen); } let M = b, w = null; r && c < i.length - 1 && (w = Cn(s[c], s[c + 1], s[c + 2] ?? s[c + 1], Eo), w && (M = b - w.cutLen)); const S = [...a.get(c) ?? []].sort((T, v) => T.t - v.t); for (const T of S) T.r = Math.min(T.r, T.d - f, M - T.d); for (let T = 0; T < S.length - 1; T++) { const v = S[T + 1].d - S[T].d; if (S[T].r + S[T + 1].r > v) { const m = v / 2; S[T].r = Math.min(S[T].r, m), S[T + 1].r = Math.min(S[T + 1].r, m); } } for (const T of S) T.r < Dr || d.push(...Ho(T, x, h, p, n.jumpStyle)); r && w ? (d.push(`L${te(w.startX)},${te(w.startY)}`), d.push(`Q${te(w.ctrlX)},${te(w.ctrlY)} ${te(w.endX)},${te(w.endY)}`)) : d.push(`L${we(g.b)}`); } return d.join(" "); } l(Xo, "rewriteEdgePath"); function Yo(t) { return /^[\d\s+,.LMelm-]*$/.test(t); } l(Yo, "isStraightPath"); function $o(t) { return t ? t === "linear" || t === "rounded" || t === "step" || t === "stepBefore" || t === "stepAfter" : !0; } l($o, "curveSupportsLineHops"); function Go(t) { if (!t) return null; try { const e = typeof atob == "function" ? atob(t) : Buffer.from(t, "base64").toString(), n = JSON.parse(e); if (!Array.isArray(n)) return null; const o = []; for (const s of n) s && typeof s.x == "number" && typeof s.y == "number" && o.push({ x: s.x, y: s.y }); return o.length >= 2 ? o : null; } catch { return null; } } l(Go, "decodeDataPoints"); function zo(t, e, n) { if (!n.enabled) return; const o = t.node(); if (!o) return; const s = /* @__PURE__ */ new Map(); for (const c of e) s.set(c.id, c); const r = [], i = /* @__PURE__ */ new Map(); for (const c of e) { const g = typeof CSS < "u" && CSS.escape ? CSS.escape(c.id) : c.id, b = o.querySelector(`path[data-id="${g}"]`); if (!b) continue; i.set(c.id, b); const x = Go(b.getAttribute("data-points")) ?? c.points; r.push({ ...c, points: x }); } const a = Fo(r); if (a.length === 0) return; const d = /* @__PURE__ */ new Map(); for (const c of a) { const g = d.get(c.jumpEdgeId) ?? []; g.push(c), d.set(c.jumpEdgeId, g); } for (const c of r) { const g = d.get(c.id); if (!g || g.length === 0) continue; const b = s.get(c.id)?.curve; if (b !== void 0 && !$o(b)) continue; const x = i.get(c.id); if (!x || b === void 0 && !Yo(x.getAttribute("d") ?? "")) continue; const h = x.getAttribute("style") ?? "", p = /stroke-dasharray\s*:\s*0\s+([\d.]+)\s+[\d.]+\s+([\d.]+)/.exec(h), f = p ? Number.parseFloat(p[1]) : null, M = p ? Number.parseFloat(p[2]) : null, w = Xo(c, g, n); if (x.setAttribute("d", w), f !== null && M !== null && typeof x.getTotalLength == "function") { const S = x.getTotalLength(), T = `0 ${f} ${Math.max(0, S - f - M)} ${M}`, v = h.replace(/stroke-dasharray\s*:[^;]*;?/g, `stroke-dasharray: ${T};`).replace(/;\s*;+/g, ";"); x.setAttribute("style", v); } } } l(zo, "applyLineJumpsToSvg"); async function jo(t, e) { for (const s of t.nodes) s.isGroup ? await Rr(e.clusters, s) : Ar(s); const n = /* @__PURE__ */ new Map(); for (const s of t.nodes) s?.id && n.set(s.id, s); for (const s of t.edges) { const r = s.start ? n.get(s.start) ?? {} : {}, i = s.end ? n.get(s.end) ?? {} : {}, a = Fr(e.edgePaths, { ...s }, {}, t.type, r, i, t.diagramId); s.label && await Br(e.rootGroups, s), s.label && Vo(s, a); } const o = t.config?.swimlane?.lineHops; if (o !== !1) { const s = o === "gap" ? "gap" : "arc", r = t.edges.filter((i) => Array.isArray(i.points) && i.points.length >= 2).map((i) => ({ id: i.id, points: i.points, curve: i.curve, arrowTypeStart: i.arrowTypeStart, arrowTypeEnd: i.arrowTypeEnd })); zo(e.edgePaths, r, { enabled: !0, jumpRadius: 6, jumpStyle: s }); } } l(jo, "adjustLayout"); function Vo(t, e) { const n = e?.updatedPath ?? e?.originalPath, { subGraphTitleTotalMargin: o } = vr({ flowchart: Cr().flowchart ?? {} }); if (t.label) { const s = kr.get(t.id); let r = t.x, i = t.y; if (n) { const a = Ne.calcLabelPosition(n); We.debug("Moving label " + t.label + " from (", r, ",", i, ") to (", a.x, ",", a.y, ") abc88"), e && (r = a.x, i = a.y); } s.attr("transform", `translate(${r}, ${i + o / 2})`); } if (t?.startLabelLeft) { const s = Xe.get(t.id).startLeft; let r = t?.x, i = t?.y; if (n) { const a = Ne.calcTerminalLabelPosition(t.arrowTypeStart ? 10 : 0, "start_left", n); r = a.x, i = a.y; } s.attr("transform", `translate(${r}, ${i})`); } if (t.startLabelRight) { const s = Xe.get(t.id).startRight; let r = t.x, i = t.y; if (n) { const a = Ne.calcTerminalLabelPosition(t.arrowTypeStart ? 10 : 0, "start_right", n); r = a.x, i = a.y; } s.attr("transform", `translate(${r}, ${i})`); } if (t.endLabelLeft) { const s = Xe.get(t.id).endLeft; let r = t.x, i = t.y; if (n) { const a = Ne.calcTerminalLabelPosition(t.arrowTypeEnd ? 10 : 0, "end_left", n); r = a.x, i = a.y; } s.attr("transform", `translate(${r}, ${i})`); } if (t.endLabelRight) { const s = Xe.get(t.id).endRight; let r = t.x, i = t.y; if (n) { const a = Ne.calcTerminalLabelPosition(t.arrowTypeEnd ? 10 : 0, "end_right", n); r = a.x, i = a.y; } s.attr("transform", `translate(${r}, ${i})`); } } l(Vo, "positionEdgeLabel"); var xn = "__swimlane_default__", Hr = 21, Ao = 20; function Ln(t) { return Math.max(t.padding ?? Ao, Ao); } l(Ln, "topLaneHorizontalPadding"); function Uo(t) { const { x: e, y: n, width: o, height: s } = t, r = t.swimlaneContentTop; if (typeof e != "number" || typeof n != "number" || typeof o != "number" || typeof s != "number" || typeof r != "number" || !Number.isFinite(e) || !Number.isFinite(n) || !Number.isFinite(o) || !Number.isFinite(s) || !Number.isFinite(r) || o <= 0 || s <= 0) { delete t.groupTitleRect; return; } const i = n - s / 2, a = Math.min(r, n + s / 2), d = i + Math.min(Hr, Math.max(0, a - i)); if (d <= i) { delete t.groupTitleRect; return; } t.groupTitleRect = { left: e - o / 2, right: e + o / 2, top: i, bottom: d }; } l(Uo, "assignTopLaneTitleRect"); function Wo(t) { const e = t.direction, n = t.nodes ??= []; for (const r of t.nodes ?? []) r.isGroup && !r.parentId && (r.shape = "swimlane", e && (r.direction = e)); const o = n.filter((r) => !r.isGroup && !r.parentId); if (o.length === 0) return; let s = n.find((r) => r.id === xn); s ? s.isGroup && (s.shape = "swimlane", e && (s.direction = e)) : (s = { id: xn, label: "", isGroup: !0, shape: "swimlane", padding: 20, ...e ? { direction: e } : {} }, n.push(s)); for (const r of o) r.parentId = xn; } l(Wo, "prepareLayoutForSwimlanes"); function Ko(t) { const e = /* @__PURE__ */ new Map(); for (const i of t.nodes ?? []) e.set(i.id, i); const n = []; for (const i of t.edges ?? []) { const a = typeof i.start == "string" ? i.start : void 0, d = typeof i.end == "string" ? i.end : void 0; !a || !d || i.labelNodeId || n.push({ id: i.id, src: a, dst: d, ref: i }); } const o = t.nodes ?? [], s = o.filter((i) => i.isGroup), r = o.filter((i) => !i.isGroup); return { nodes: [...[...s].reverse(), ...r].map((i) => i.id), edges: n, layout: t, nodeById: e }; } l(Ko, "toGraphView"); function qo(t, e, n, o) { const { layout: s } = t, r = t.nodeById, i = o?.layerGap ?? 100, a = o?.nodeGap ?? 40; let d = 0; for (const x of e.layers) { let h = 0; for (const p of x) { const f = r.get(p); if (!f) { h++; continue; } f.layer = d, f.order = h; const M = n.x[p] ?? h * a, w = n.y[p] ?? d * i; f.x = M, f.y = w, h++; } d++; } const c = s.nodes ?? [], g = /* @__PURE__ */ new Map(), b = []; for (const x of c) { if (!x?.isGroup) continue; x.parentId || b.push(x); const h = c.filter((S) => S.parentId === x.id); let p = 1 / 0, f = -1 / 0, M = 1 / 0, w = -1 / 0; for (const S of h) { const T = S.x ?? n.x[S.id], v = S.y ?? n.y[S.id], m = S.width ?? 0, I = S.height ?? 0; T != null && v != null && (p = Math.min(p, T - m / 2), f = Math.max(f, T + m / 2), M = Math.min(M, v - I / 2), w = Math.max(w, v + I / 2)); } if (p === 1 / 0 || M === 1 / 0) x.x = x.x ?? 0, x.y = x.y ?? 0, x.width = x.width ?? 0, x.height = x.height ?? 0; else { const S = x.padding ?? 20, T = x.parentId ? S : 2 * Ln(x), v = S, m = Math.max(0, f - p) + T, I = Math.max(0, w - M) + v, A = (p + f) / 2, O = (M + w) / 2; x.x = A, x.y = O, x.width = m, x.height = I, g.set(x.id, { minX: p, maxX: f, minY: M, maxY: w }); } } if (b.length > 0 && g.size > 0) { let x = 1 / 0, h = -1 / 0, p = 0; for (const f of b) { const M = f.padding ?? 20; M > p && (p = M); const w = g.get(f.id); w && (x = Math.min(x, w.minY), h = Math.max(h, w.maxY)); } if (x !== 1 / 0 && h !== -1 / 0) { const f = Math.max(0, h - x) + 2 * Math.max(p, 36), M = (x + h) / 2; for (const I of b) I.y = M, I.height = f, I.swimlaneContentTop = x; const w = [...b].sort((I, A) => (I.x ?? 0) - (A.x ?? 0)), S = [], T = [], v = []; for (const I of w) { const A = g.get(I.id); if (!A) continue; const O = Math.max(0, A.maxX - A.minX) + 2 * Ln(I), N = (A.minX + A.maxX) / 2; S.push(I.id), T.push(N), v.push(O); } const m = S.length; if (m > 0) { const I = /* @__PURE__ */ new Map(); if (m === 1) I.set(S[0], v[0]); else { const A = []; for (let k = 0; k < m - 1; k++) A.push(T[k + 1] - T[k]); const O = new Array(m); O[0] = 0; for (let k = 0; k < m - 1; k++) O[k + 1] = 2 * A[k] - O[k]; let N = 0, R = Number.POSITIVE_INFINITY; for (let k = 0; k < m; k++) { const X = v[k]; k % 2 === 0 ? N = Math.max(N, X - O[k]) : R = Math.min(R, O[k] - X); } let F = N; N <= R ? F = (N + R) / 2 : F = N; for (let k = 0; k < m; k++) { const X = O[k] + (k % 2 === 0 ? F : -F), q = Math.max(v[k], X); I.set(S[k], q); } } for (const A of b) { const O = I.get(A.id); O != null && (A.width = O), Uo(A); } } } } } l(qo, "writeBackToLayoutData"); var Xr = "[EdgeLabelNodes]"; function Jo(t) { const e = [], n = [], o = /* @__PURE__ */ new Map(); for (const i of t.nodes) o.set(i.id, i); for (const i of t.edges) { if (!i.label || i.label.length === 0 || i.isLayoutOnly || i.labelNodeId) continue; const a = i.start ? o.get(i.start) : void 0, d = i.end ? o.get(i.end) : void 0; if (!a || !d) { We.warn(Xr, `Edge ${i.id} has missing source or target node`); continue; } const c = `edge-label-${i.start}-${i.end}-${i.id}`, g = a.parentId !== d.parentId ? d.parentId : a.parentId, b = { id: c, label: i.label, edgeStart: i.start ?? "", edgeEnd: i.end ?? "", shape: "labelRect", width: 0, height: 0, isEdgeLabel: !0, isDummy: !0, parentId: g, isGroup: !1, labelStyle: Array.isArray(i.labelStyle) ? i.labelStyle[0] : i.labelStyle ?? "", ...a.dir ? { dir: a.dir } : {} }; e.push(b), i.labelNodeId = c, i.label = void 0, i.text = void 0; const x = { id: `${i.id}-to-label`, start: i.start, end: c, type: "normal", isLayoutOnly: !0 }, h = { id: `${i.id}-from-label`, start: c, end: i.end, type: "normal", isLayoutOnly: !0 }; n.push(x, h); } const s = [...t.nodes, ...e], r = [...t.edges, ...n]; return { ...t, nodes: s, edges: r }; } l(Jo, "createEdgeLabelNodes"); var Ft = 1e-3; function eo(t) { const e = t.x ?? 0, n = t.y ?? 0, o = t.width ?? 0, s = t.height ?? 0; return o > 0 && s > 0 ? { cx: e, cy: n, rect: Te(e, n, o, s) } : void 0; } l(eo, "measuredNodeRect"); function no(t) { if (t.isGroup) return; const e = eo(t); if (e) return { id: String(t.id ?? ""), cx: e.cx, cy: e.cy, rect: e.rect }; } l(no, "nodeBoundsInfoFor"); function Zt(t, e, n = Ft) { return Math.abs(t.x - e.x) < n && Math.abs(t.y - e.y) < n; } l(Zt, "samePoint"); function ft(t, e, n = Ft) { return Math.abs(t.x - e.x) < n; } l(ft, "sameX"); function dt(t, e, n = Ft) { return Math.abs(t.y - e.y) < n; } l(dt, "sameY"); function vt(t, e, n = Ft) { return dt(t, e, n) && Math.abs(t.x - e.x) > n; } l(vt, "isHorizontalSegment"); function wt(t, e, n = Ft) { return ft(t, e, n) && Math.abs(t.y - e.y) > n; } l(wt, "isVerticalSegment"); function $t(t, e, n, o) { return Math.max(0, Math.min(Math.max(t, e), Math.max(n, o)) - Math.max(Math.min(t, e), Math.min(n, o))); } l($t, "overlapLength"); function ne(t, e, n = Ft) { return t.horizontal && e.horizontal && dt(t.a, e.a, n) ? $t(t.a.x, t.b.x, e.a.x, e.b.x) : t.vertical && e.vertical && ft(t.a, e.a, n) ? $t(t.a.y, t.b.y, e.a.y, e.b.y) : 0; } l(ne, "sameAxisSegmentOverlapLength"); function Ee(t, e = Ft) { const n = []; for (let o = 0; o < t.length - 1; o++) { const s = t[o], r = t[o + 1], i = vt(s, r, e), a = wt(s, r, e); (i || a) && n.push({ index: o, a: s, b: r, horizontal: i, vertical: a }); } return n; } l(Ee, "orthogonalSegmentsForPoints"); function Kt(t, e = Ft) { const n = Ee(t, e); let o = 0; for (let s = 1; s < n.length; s++) n[s - 1].horizontal !== n[s].horizontal && o++; return o; } l(Kt, "countOrthogonalBends"); function gt(t, e = Ft) { const n = []; for (const o of t) { const s = n.length > 0 ? n[n.length - 1] : void 0; (!s || !Zt(s, o, e)) && n.push({ x: o.x, y: o.y }); } return n; } l(gt, "dedupeConsecutivePoints"); function oo(t, e = Ft) { if (!t || t.length !== 4) return; const [n, o, s, r] = t; return vt(n, o, e) && wt(o, s, e) && vt(s, r, e) ? { kind: "HVH", p0: n, p1: o, p2: s, p3: r } : wt(n, o, e) && vt(o, s, e) && wt(s, r, e) ? { kind: "VHV", p0: n, p1: o, p2: s, p3: r } : void 0; } l(oo, "classifyThreeSegmentRoute"); function rn(t, e, n, o = 0) { const s = Math.min(t.x, e.x), r = Math.max(t.x, e.x), i = Math.min(t.y, e.y), a = Math.max(t.y, e.y); return r > n.left - o && s < n.right + o && a > n.top - o && i < n.bottom + o; } l(rn, "segmentBoundsOverlapRect"); function so(t, e, n = 0) { return t.x > e.left + n && t.x < e.right - n && t.y > e.top + n && t.y < e.bottom - n; } l(so, "pointInsideRect"); function Zo(t, e) { return t.left <= e.left && t.right >= e.right && t.top <= e.top && t.bottom >= e.bottom; } l(Zo, "rectContainsRect"); function qe(t, e) { return t.left < e.right && t.right > e.left && t.top < e.bottom && t.bottom > e.top; } l(qe, "rectsOverlap"); function vn(t, e) { return { left: t.left - e, right: t.right + e, top: t.top - e, bottom: t.bottom + e }; } l(vn, "inflateRect"); function Te(t, e, n, o) { return { left: t - n / 2, right: t + n / 2, top: e - o / 2, bottom: e + o / 2 }; } l(Te, "rectFromCenterSize"); function jt(t) { return eo(t)?.rect; } l(jt, "rectOfNodeBounds"); function Me(t, e) { switch (e) { case "top": return { x: t.cx, y: t.rect.top }; case "bottom": return { x: t.cx, y: t.rect.bottom }; case "left": return { x: t.rect.left, y: t.cy }; case "right": return { x: t.rect.right, y: t.cy }; } } l(Me, "portForRectSide"); function ro(t, e, n, o, s, r = Ft) { const i = e === "left" || e === "right", a = o === "left" || o === "right"; if (i && a) { if (e === "right" && o === "left" && t.x < n.x || e === "left" && o === "right" && t.x > n.x) { if (dt(t, n, r)) return [t, n]; const g = (t.x + n.x) / 2; return [ t, { x: g, y: t.y }, { x: g, y: n.y }, n ]; } if (e === o) { if (dt(t, n, r)) return; const g = e === "left" ? Math.min(t.x, n.x) - s : Math.max(t.x, n.x) + s; return [ t, { x: g, y: t.y }, { x: g, y: n.y }, n ]; } return; } if (!i && !a) { if (e === o) { if (ft(t, n, r)) return; const b = e === "top" ? Math.min(t.y, n.y) - s : Math.max(t.y, n.y) + s; return [ t, { x: t.x, y: b }, { x: n.x, y: b }, n ]; } if (!(e === "bottom" && o === "top" && t.y < n.y || e === "top" && o === "bottom" && t.y > n.y)) return; if (ft(t, n, r)) return [t, n]; const g = (t.y + n.y) / 2; return [ t, { x: t.x, y: g }, { x: n.x, y: g }, n ]; } if (i && !a) { const g = e === "right" && n.x > t.x || e === "left" && n.x < t.x, b = o === "top" && t.y < n.y || o === "bottom" && t.y > n.y; return g && b ? [ t, { x: n.x, y: t.y }, n ] : void 0; } const d = e === "bottom" && n.y > t.y || e === "top" && n.y < t.y, c = o === "left" && t.x < n.x || o === "right" && t.x > n.x; return d && c ? [ t, { x: t.x, y: n.y }, n ] : void 0; } l(ro, "buildOrthogonalPortPath"); function io(t, e, n, o) { return e === "left" || e === "right" ? [ t, { x: o, y: t.y }, { x: o, y: n.y }, n ] : [ t, { x: t.x, y: o }, { x: n.x, y: o }, n ]; } l(io, "buildSameSideTrackPath"); function cn(t) { const e = /* @__PURE__ */ new Map(), n = []; for (const o of t) { if (o.isEdgeLabel) continue; const s = no(o); s && (e.set(s.id, s), n.push({ id: s.id, rect: s.rect })); } return { nodeInfoById: e, realNodeRects: n }; } l(cn, "collectRealNodeBounds"); function pe(t) { const e = [], n = []; for (const o of t) { const s = no(o); if (!s) continue; const r = { id: s.id, rect: s.rect }; o.isEdgeLabel ? n.push(r) : e.push(r); } return { realNodeRects: e, labelNodeRects: n }; } l(pe, "collectNodeRectEntries"); function Qo(t, { includeEdgeLabels: e = !0 } = {}) { const n = []; for (const o of t) { if (o.isGroup || !e && o.isEdgeLabel) continue; const s = o.x ?? 0, r = o.y ?? 0, i = o.width ?? 0, a = o.height ?? 0; n.push({ nodeId: o.id, ...Te(s, r, i, a) }); } return n; } l(Qo, "collectLayoutNodeRects"); function co(t, e, n = Ft) { const o = t.start, s = t.end; if (!o || !s) return; const r = e.get(o), i = e.get(s); if (!(!r || !i)) return { srcId: o, dstId: s, srcInfo: r, dstInfo: i, collinearX: Math.abs(r.cx - i.cx) < n, collinearY: Math.abs(r.cy - i.cy) < n }; } l(co, "getNodePairGeometry"); function Et(t, e, n, o = [], s = 0) { for (const r of n) if (!o.includes(r.id) && rn(t, e, r.rect, -s)) return !0; return !1; } l(Et, "segmentHitsAnyRect"); function ao(t, e, n, o, s = Ft, r = 1e-6) { const i = dt(t, e, s), a = ft(t, e, s), d = dt(n, o, s), c = ft(n, o, s); if (i && d || a && c || !(i || a) || !(d || c)) return !1; const g = i ? { a: t, b: e } : { a: n, b: o }, b = a ? { a: t, b: e } : { a: n, b: o }, x = g.a.y, h = Math.min(g.a.x, g.b.x), p = Math.max(g.a.x, g.b.x), f = b.a.x, M = Math.min(b.a.y, b.b.y), w = Math.max(b.a.y, b.b.y); if (f < h || f > p || x < M || x > w) return !1; const S = Math.abs(f - g.a.x) < r && Math.abs(x - g.a.y) < r || Math.abs(f - g.b.x) < r && Math.abs(x - g.b.y) < r, T = Math.abs(f - b.a.x) < r && Math.abs(x - b.a.y) < r || Math.abs(f - b.b.x) < r && Math.abs(x - b.b.y) < r; return !(S && T); } l(ao, "orthogonalSegmentsCross"); function ts(t, e, n, o, s = Ft) { const r = dt(t, e, s), i = ft(t, e, s), a = dt(n, o, s), d = ft(n, o, s); return i && d && ft(t, n, s) ? $t(t.y, e.y, n.y, o.y) > s : r && a && dt(t, n, s) ? $t(t.x, e.x, n.x, o.x) > s : !1; } l(ts, "sameAxisSegmentsOverlap"); function Je(t, e, n, o, { epsilon: s = Ft, skipDegenerateOther: r = !1 } = {}) { for (const i of n) { if (i === o || i.isLayoutOnly) continue; const a = i.points; if (!(!a || a.length < 2)) for (let d = 0; d < a.length - 1; d++) { const c = a[d], g = a[d + 1]; if (!(r && Zt(c, g, s)) && (ao(t, e, c, g, s) || ts(t, e, c, g, s))) return !0; } } return !1; } l(Je, "segmentConflictsWithAnyEdge"); function ce(t, e, n, o, s = Ft) { const r = dt(t, e, s), i = ft(t, e, s), a = dt(n, o, s), d = ft(n, o, s); if (!(r && d || i && a)) return !1; const c = r ? { a: t, b: e } : { a: n, b: o }, g = r ? { a: n, b: o } : { a: t, b: e }, b = c.a.y, x = Math.min(c.a.x, c.b.x), h = Math.max(c.a.x, c.b.x), p = g.a.x, f = Math.min(g.a.y, g.b.y), M = Math.max(g.a.y, g.b.y); return p > x + s && p < h - s && b > f + s && b < M - s; } l(ce, "orthogonalSegmentsStrictlyCross"); function wn(t, e, n) { const o = Math.min(e, n), s = Math.max(e, n); return t > o + Ft && t < s - Ft; } l(wn, "strictlyBetween"); function es(t, e, n) { return ft(t, e) && ft(e, n) ? wn(e.y, t.y, n.y) : dt(t, e) && dt(e, n) ? wn(e.x, t.x, n.x) : !1; } l(es, "isCollinearIntermediate"); function ns(t) { let e = !1; const n = []; for (let o = 0; o < t.length; o++) { const s = n[n.length - 1], r = t[o], i = o + 1 < t.length ? t[o + 1] : void 0; if (s && i) { if (Zt(s, i)) { o++, e = !0; continue; } if (es(s, r, i)) { e = !0; continue; } } n.push(r); } return { points: n, changed: e }; } l(ns, "simplifyPolylineOnce"); function Ze(t) { const e = [t[0]]; for (let o = 1; o < t.length; o++) { const s = e[e.length - 1], r = t[o]; if (!ft(s, r) && !dt(s, r)) { const i = e.length >= 2 ? e[e.length - 2] : void 0, a = i && ft(i, s) ? { x: s.x, y: r.y } : { x: r.x, y: s.y }; e.push(a); } e.push(r); } const n = []; for (const o of e) { const s = n[n.length - 1]; (!s || !Zt(s, o)) && n.push(o); } return n; } l(Ze, "orthogonalizePolyline"); function oe(t) { if (t.length < 3) return t; let e = [...t]; for (let n = 0; n < 32; n++) { const o = ns(e); if (e = o.points, !o.changed) break; } return e; } l(oe, "simplifyPolyline"); var Q = 1e-3, Yr = 0.5, Ro = 4; function lo(t, e, n) { const o = t; if (o.isLayoutOnly || !o.points || o.points.length < n) return; const s = o.start ? e.get(o.start) : void 0, r = o.end ? e.get(o.end) : void 0; return { edge: o, points: o.points, srcRect: s ? jt(s) : void 0, dstRect: r ? jt(r) : void 0 }; } l(lo, "endpointContextFor"); function os(t, e, n) { if (dt(t, e, Q)) return { x: t.x < n.left ? n.left : n.right, y: t.y }; if (ft(t, e, Q)) { const o = t.y < n.top ? n.top : n.bottom; return { x: t.x, y: o }; } return { x: Math.min(n.right, Math.max(n.left, t.x)), y: Math.min(n.bottom, Math.max(n.top, t.y)) }; } l(os, "segmentEnterPoint"); function Tn(t, e, n) { const o = n ? 1 : -1; let s = n ? 0 : t.length - 1; for (; s >= 0 && s < t.length && so(t[s], e, Yr); ) s += o; if (s < 0 || s >= t.length) return t; const r = s - o; if (r < 0 || r >= t.length) return t; const i = os(t[s], t[r], e); return n ? [i, ...t.slice(s)] : [...t.slice(0, s + 1), i]; } l(Tn, "clipEndpoint"); function ss(t, e) { for (const n of t) { const o = lo(n, e, 2); if (!o) continue; let s = [...o.points]; o.srcRect && (s = Tn(s, o.srcRect, !0)), o.dstRect && (s = Tn(s, o.dstRect, !1)), s = oe(Ze(s)), s = fo(s, o.srcRect, o.dstRect), o.edge.points = oe(Ze(s)); } } l(ss, "clipEdgeEndpointsToNodeBoundaries"); function En(t, e, n, o = !1) { if (dt(t, e, Q)) { if (e.y < n.top - Q || e.y > n.bottom + Q) return e; if (o) { if (t.x < n.left - Q) return { x: n.left, y: t.y }; if (t.x > n.right + Q) return { x: n.right, y: t.y }; } return { x: Math.abs(e.x - n.left) <= Math.abs(e.x - n.right) ? n.left : n.right, y: t.y }; } if (ft(t, e, Q)) { if (e.x < n.left - Q || e.x > n.right + Q) return e; if (o) { if (t.y < n.top - Q) return { x: t.x, y: n.top }; if (t.y > n.bottom + Q) return { x: t.x, y: n.bottom }; } const s = Math.abs(e.y - n.top) <= Math.abs(e.y - n.bottom); return { x: t.x, y: s ? n.top : n.bottom }; } return e; } l(En, "snapEndpointToBoundary"); function Qe(t, e, n) { const o = t[e]; for (let s = e + n; s >= 0 && s < t.length; s += n) { const r = t[s]; if (!Zt(r, o, Q)) return r; } return t[e + n]; } l(Qe, "firstDistinctAdjacent"); function tn(t, e) { const n = t + Ro, o = e - Ro; return n <= o ? { lo: n, hi: o } : { lo: (t + e) / 2, hi: (t + e) / 2 }; } l(tn, "cornerClearanceRange"); function An(t, e, n) { const { lo: o, hi: s } = tn(e, n); return Math.min(s, Math.max(o, t)); } l(An, "clampToCornerClearance"); function rs(t) { const e = Math.max(...t.map((o) => o.lo)), n = Math.min(...t.map((o) => o.hi)); if (!(e > n)) return { lo: e, hi: n }; } l(rs, "intersectRanges"); function Rn(t, e) { return e === "left" || e === "right" ? tn(t.top, t.bottom) : tn(t.left, t.right); } l(Rn, "clearanceRangeForSide"); function en(t, e, n) { const o = t.y >= n.top - Q && t.y <= n.bottom + Q, s = t.x >= n.left - Q && t.x <= n.right + Q; if (dt(t, e, Q) && o) { if (Math.abs(t.x - n.left) < Q) return "left"; if (Math.abs(t.x - n.right) < Q) return "right"; } if (ft(t, e, Q) && s) { if (Math.abs(t.y - n.top) < Q) return "top"; if (Math.abs(t.y - n.bottom) < Q) return "bottom"; } } l(en, "terminalSideForSegment"); function Oe(t) { return t === "left" || t === "right"; } l(Oe, "isHorizontalSide"); function is(t, e, n, o, s) { const r = [], i = n ? en(t, e, n) : void 0, a = o ? en(e, t, o) : void 0; return n && i && Oe(i) === s && r.push(Rn(n, i)), o && a && Oe(a) === s && r.push(Rn(o, a)), r.length > 0 ? rs(r) : void 0; } l(is, "straightClearanceRange"); function Nn(t, e, n, o, s) { const r = is(t, e, n, o, s); if (!r) return; const i = s ? t.y : t.x, a = Math.min(r.hi, Math.max(r.lo, i)); if (!(Math.abs(a - i) < Q)) return s ? [{ x: t.x, y: a }, { x: e.x, y: a }] : [{ x: a, y: t.y }, { x: a, y: e.y }]; } l(Nn, "clearStraightEndpointCornerAxis"); function fo(t, e, n) { if (t.length !== 2) return t; const [o, s] = t; return dt(o, s, Q) ? Nn(o, s, e, n, !0) ?? t : ft(o, s, Q) ? Nn(o, s, e, n, !1) ?? t : t; } l(fo, "clearStraightEndpointCornerConnections"); function cs(t, e, n) { return Oe(n) ? { x: t.x, y: An(t.y, e.top, e.bottom) } : { x: An(t.x, e.left, e.right), y: t.y }; } l(cs, "cornerClearedEndpoint"); function as(t, e, n, o, s, r) { const i = t.map((a) => ({ ...a })); for (let a = e; a >= 0 && a < t.length; a += n) { const d = t[a]; if (r && !dt(d, o, Q) || !r && !ft(d, o, Q)) break; r ? i[a].y = s.y : i[a].x = s.x; } return i; } l(as, "moveCollinearEndpointRun"); function On(t, e, n) { if (t.length < 2) return t; const o = n ? 0 : t.length - 1, s = n ? 1 : -1, r = t[o], i = Qe(t, o, s); if (!i) return t; const a = en(r, i, e); if (!a) return t; const d = Oe(a), c = cs(r, e, a); return Zt(r, c, Q) ? t : as(t, o, s, r, c, d); } l(On, "clearEndpointCornerConnection"); function Pn(t, e, n) { const o = Math.min(t.x, e.x) >= n.left - Q && Math.max(t.x, e.x) <= n.right + Q, s = Math.min(t.y, e.y) >= n.top - Q && Math.max(t.y, e.y) <= n.bottom + Q; if (Math.abs(t.y - n.top) < Q && Math.abs(e.y - n.top) < Q && o) return "top"; if (Math.abs(t.y - n.bottom) < Q && Math.abs(e.y - n.bottom) < Q && o) return "bottom"; if (Math.abs(t.x - n.left) < Q && Math.abs(e.x - n.left) < Q && s) return "left"; if (Math.abs(t.x - n.right) < Q && Math.abs(e.x - n.right) < Q && s) return "right"; } l(Pn, "borderSideForSegment"); function Bn(t, e, n, o) { switch (t) { case "top": return ft(e, n, Q) && n.y < o.top - Q; case "bottom": return ft(e, n, Q) && n.y > o.bottom + Q; case "left": return dt(e, n, Q) && n.x < o.left - Q; case "right": return dt(e, n, Q) && n.x > o.right + Q; } } l(Bn, "leavesOutward"); function kn(t, e, n) { if (t.length < 3) return t; if (n) { const r = Pn(t[0], t[1], e); return r && Bn(r, t[1], t[2], e) ? t.slice(1) : t; } const o = t.length - 1, s = Pn(t[o - 1], t[o], e); return s && Bn(s, t[o - 1], t[o - 2], e) ? t.slice(0, o) : t; } l(kn, "collapseOwnBorderStub"); function ls(t, e, n) { let o = t; if (e) { const r = Qe(o, 0, 1); if (r) { const i = En(r, o[0], e); i !== o[0] && (o = [i, ...o.slice(1)]); } o = kn(o, e, !0); } if (n) { const r = o.length - 1, i = Qe(o, r, -1); if (i) { const a = En(i, o[r], n, !0); a !== o[r] && (o = [...o.slice(0, r), a]); } o = kn(o, n, !1); } const s = fo(o, e, n); return s !== o || o.length === 2 ? s : (e && (o = On(o, e, !0)), n && (o = On(o, n, !1)), o); } l(ls, "snapAndCollapseEndpoints"); function Fn(t, e) { for (const n of t) { const o = lo(n, e, 2); if (!o) continue; const s = ls(gt(o.points, Q), o.srcRect, o.dstRect); if (s.length < 3) { o.edge.points = s; continue; } const r = [ s[0], { ...s[0] }, ...s.slice(1, -1), s[s.length - 1], { ...s[s.length - 1] } ]; o.edge.points = r; } } l(Fn, "prepareEdgeEndpointsForRenderer"); function uo(t) { return new Map(t.map((e) => [e.id, e])); } l(uo, "buildNodeMap"); function fs(t, e) { let n = t.parentId, o = null; for (; n; ) { const s = e.get(n); if (!s?.isGroup) break; o = s.id, n = s.parentId; } return o; } l(fs, "resolveTopLevelGroupId"); function _n(t, e) { let n = 0, o = t.parentId; for (; o; ) { const s = e.get(o); if (!s?.isGroup) break; n++, o = s.parentId; } return n; } l(_n, "groupDepth"); function ho(t) { let e = 1 / 0, n = -1 / 0, o = 1 / 0, s = -1 / 0; for (const r of t) { const i = r.x, a = r.y; if (typeof i != "number" || typeof a != "number") continue; const d = r.width ?? 0, c = r.height ?? 0; e = Math.min(e, i - d / 2), n = Math.max(n, i + d / 2), o = Math.min(o, a - c / 2), s = Math.max(s, a + c / 2); } return e === 1 / 0 || o === 1 / 0 ? null : { minX: e, maxX: n, minY: o, maxY: s }; } l(ho, "boundsForChildren"); function ds(t, e) { const n = t.padding ?? 20; t.x = (e.minX + e.maxX) / 2, t.y = (e.minY + e.maxY) / 2, t.width = Math.max(0, e.maxX - e.minX) + n, t.height = Math.max(0, e.maxY - e.minY) + n; } l(ds, "applyGroupBounds"); function us(t) { const e = uo(t), n = t.filter((o) => o.isGroup && o.parentId).sort((o, s) => _n(s, e) - _n(o, e)); for (const o of n) { const s = ho(t.filter((r) => r.parentId === o.id)); s && ds(o, s); } } l(us, "recomputeNestedGroupBounds"); function nn(t, e) { const n = t.nodes ?? [], o = t.edges ?? [], s = n.filter((d) => !d.isGroup); let r = 1 / 0, i = -1 / 0; for (const d of s) { const c = d[e]; typeof c == "number" && (r = Math.min(r, c), i = Math.max(i, c)); } if (!Number.isFinite(r) || !Number.isFinite(i)) return !1; const a = /* @__PURE__ */ l((d) => r + i - d, "mirror"); for (const d of n) { const c = d[e]; typeof c == "number" && (d[e] = a(c)); const g = d.groupTitleRect; g && (d.groupTitleRect = e === "x" ? { ...g, left: a(g.right), right: a(g.left) } : { ...g, top: a(g.bottom), bottom: a(g.top) }); } for (const d of o) for (const c of d.points ?? []) c[e] = a(c[e]); return !0; } l(nn, "mirrorAxis"); function hs(t) { return (t.nodes ?? []).some((e) => !e.isGroup) ? nn(t, "y") : !0; } l(hs, "applyBtDirectionTransform"); function gs(t, e = "LR") { const n = t.nodes ?? [], o = t.edges ?? [], s = n.filter((N) => !N.isGroup); let r = 1 / 0, i = 1 / 0; for (const N of s) { const R = N.x ?? 0, F = N.y ?? 0; R < r && (r = R), F < i && (i = F); } if (!Number.isFinite(r) || !Number.isFinite(i)) return !1; const a = 36; let d = 0, c = 0; for (const N of s) d += N.width ?? 0, c += N.height ?? 0; const g = d / s.length, b = c / s.length, x = b > 0 ? Math.max(1, g / b) : 1; for (const N of s) { const R = N.x ?? 0, F = ((N.y ?? 0) - i) * x + a, k = R - r; N.x = F, N.y = k; } for (const N of o) if (N.points) for (const R of N.points) { const F = R.x, k = (R.y - i) * x + a, X = F - r; R.x = k, R.y = X; } us(n); const h = n.filter((N) => N.isGroup && !N.parentId); if (h.length === 0) return e === "RL" && nn(t, "x"), !0; const p = uo(n), f = /* @__PURE__ */ new Map(); for (const N of n) { if (N.isGroup) continue; const R = fs(N, p); if (!R) continue; const F = f.get(R) ?? []; F.push(N), f.set(R, F); } let M = 0; for (const N of h) { const R = N.padding ?? 0; R > M && (M = R); } const w = []; let S = 1 / 0, T = -1 / 0; for (const N of h) { const R = ho(f.get(N.id) ?? []); R && (S = Math.min(S, R.minX), T = Math.max(T, R.maxX), w.push({ lane: N, contentTop: R.minY, contentBottom: R.maxY, centerY: (R.minY + R.maxY) / 2 })); } if (S === 1 / 0 || T === -1 / 0) return !0; const v = Math.max(0, T - S) + 2 * Math.max(M, 10), m = a + v, I = (S + T) / 2 - v / 2 - a, A = I + m / 2, O = Math.max(M, a); w.sort((N, R) => N.centerY - R.centerY); for (let N = 0; N < w.length; N++) { const R = w[N]; let F, k; if (N === 0 ? F = R.contentTop - O : F = (w[N - 1].contentBottom + R.contentTop) / 2, N === w.length - 1) k = R.contentBottom + O; else { const tt = w[N + 1]; k = (R.contentBottom + tt.contentTop) / 2; } const X = Math.max(0, k - F), q = (F + k) / 2; R.lane.x = A, R.lane.y = q, R.lane.width = m, R.lane.height = X, R.lane.swimlaneContentTop = R.contentTop, R.lane.groupTitleRect = { left: I, right: I + a, top: F, bottom: k }; } return e === "RL" && nn(t, "x"), !0; } l(gs, "applyLrDirectionTransform"); var Qt = 1e-6, Ge = 8, $r = [ 0, Ge, -Ge, 2 * Ge, -2 * Ge ]; function ps(t, e) { const { nodeInfoById: n, realNodeRects: o } = cn(e); for (const s of t) { if (s.isLayoutOnly) continue; const r = s.points; if (!r || r.length < 4) continue; const i = oo(gt(r, Qt), Qt); if (!i) continue; const { p3: a } = i, d = i.kind === "HVH", c = co(s, n, Qt); if (!c) continue; const { srcId: g, dstId: b, srcInfo: x, dstInfo: h, collinearX: p, collinearY: f } = c; if (p || f) continue; let M; const w = x.rect; for (const S of $r) { let T, v, m; if (d) { const R = h.cy > x.cy ? w.bottom : w.top, F = x.cx + S; if (F <= w.left + Qt || F >= w.right - Qt) continue; T = { x: F, y: R }, v = { x: F, y: a.y }, m = { x: a.x, y: a.y }; } else { const R = h.cx > x.cx ? w.right : w.left, F = x.cy + S; if (F <= w.top + Qt || F >= w.bottom - Qt) continue; T = { x: R, y: F }, v = { x: a.x, y: F }, m = { x: a.x, y: a.y }; } const I = Zt(T, v, Qt), A = Zt(v, m, Qt); if (I && A || !I && Et(T, v, o, [g], 1) || !A && Et(v, m, o, [b], 1)) continue; const O = !I && Je(T, v, t, s, { epsilon: Qt, skipDegenerateOther: !0 }), N = !A && Je(v, m, t, s, { epsilon: Qt, skipDegenerateOther: !0 }); if (!(O || N)) { I ? M = [v, m] : A ? M = [T, v] : M = [ T, v, m ]; break; } } M && (s.points = M); } } l(ps, "portSwapToLShape"); function ms(t, e) { const { realNodeRects: r, labelNodeRects: i } = pe(e.values()); for (const a of t) { if (a.isLayoutOnly) continue; const d = a.points; if (!d || d.length < 4) continue; const c = gt(d, 1e-3); if (c.length < 4) continue; const g = c.length - 1, b = c[g], x = c[g - 1], h = c[g - 2], p = b.x - x.x, f = b.y - x.y, M = Math.hypot(p, f); if (M >= 10 || M < 1e-3) continue; const w = x.x - h.x, S = x.y - h.y; if (Math.hypot(w, S) < 1e-3) continue; const T = vt(x, b, 1e-3), v = wt(x, b, 1e-3), m = vt(h, x, 1e-3), I = wt(h, x, 1e-3); if (!(T && I || v && m)) continue; const A = a.end, O = a.start, N = A ? e.get(A) : void 0; if (!N) continue; const R = N.x ?? 0, F = N.y ?? 0, k = jt(N); if (!k) continue; let X, q; if (I) { const st = S < 0; X = { x: R, y: h.y }, q = { x: R, y: st ? k.bottom : k.top }; } else { const st = w > 0; X = { x: h.x, y: F }, q = { x: st ? k.right : k.left, y: F }; } if (Et(X, q, r, A ? [A] : [], -2) || Et(X, q, i, [], -2)) continue; if (O) { const st = e.get(O), W = st ? jt(st) : void 0; if (W && so(X, W, 2)) continue; } const tt = /* @__PURE__ */ l((st, W) => `${st.x.toFixed(3)},${st.y.toFixed(3)}|${W.x.toFixed(3)},${W.y.toFixed(3)}`, "ownSegmentKey"), et = /* @__PURE__ */ new Set(); for (let st = 0; st < c.length - 1; st++) et.add(tt(c[st], c[st + 1])); const bt = /* @__PURE__ */ l((st, W) => { for (const Z of t) { if (Z === a || Z.isLayoutOnly) continue; const ot = Z.points; if (!(!ot || ot.length < 2)) for (let ct = 0; ct < ot.length - 1; ct++) { const xt = ot[ct], Mt = ot[ct + 1]; if (!et.has(tt(xt, Mt)) && ce(st, W, xt, Mt, 1e-3)) return !0; } } return !1; }, "segmentCrossesOtherEdge"); if (bt(X, q)) continue; if (g - 3 >= 0) { const st = c[g - 3], W = [O, A].filter((Z) => !!Z); if (Et(st, X, r, W, -2) || bt(st, X)) continue; } const yt = [ ...c.slice(0, g - 2), X, q ]; a.points = yt; const Bt = a.labelNodeId; if (Bt) { const st = e.get(Bt); if (st) { const W = st.width ?? 0, Z = st.height ?? 0; if (W > 0 && Z > 0) { let ot, ct, xt = -1; for (let Mt = 0; Mt < yt.length - 1; Mt++) { const Ct = yt[Mt], Vt = yt[Mt + 1], qt = Math.hypot(Vt.x - Ct.x, Vt.y - Ct.y), se = dt(Ct, Vt, 1e-3), re = ft(Ct, Vt, 1e-3); (se && qt >= W + 2 || re && qt >= Z + 2) && qt > xt && (xt = qt, ot = (Ct.x + Vt.x) / 2, ct = (Ct.y + Vt.y) / 2); } ot !== void 0 && ct !== void 0 && (st.x = ot, st.y = ct); } } } } } l(ms, "collapseShortTerminalStub"); var J = 1e-3, kt = 8, rt = Ee, bn = /* @__PURE__ */ l((t, e) => ft(t, e, J) || dt(t, e, J), "orthogonallyAligned"); function ys(t, e) { const s = /* @__PURE__ */ l((h, p) => { const f = h.x ?? 0, M = h.y ?? 0, w = p.x - f, S = p.y - M; let T = (h.width ?? 0) / 2, v = (h.height ?? 0) / 2; return Math.abs(S) * T > Math.abs(w) * v ? (S < 0 && (v = -v), { x: f + (S === 0 ? 0 : v * w / S), y: M + v }) : (w < 0 && (T = -T), { x: f + T, y: M + (w === 0 ? 0 : T * S / w) }); }, "rectIntersect"), r = /* @__PURE__ */ l((h, p) => { const f = gt(h.points ?? []); if (f.length < 2) return; const M = p ? h.start : h.end, w = M ? e.get(M) : void 0, S = w ? jt(w) : void 0; if (!w || !M || !S) return; const T = p ? f[0] : f[f.length - 1], v = p ? f[1] : f[f.length - 2], m = s(w, T); let I = T; if (bn(v, m) && (I = v), ft(m, I, J)) return { edge: h, edgeId: String(h.id ?? ""), nodeId: M, atStart: p, orientation: "V", coord: m.x, min: Math.min(m.y, I.y), max: Math.max(m.y, I.y), boundary: m, railEnd: I, rect: S }; if (dt(m, I, J)) return { edge: h, edgeId: String(h.id ?? ""), nodeId: M, atStart: p, orientation: "H", coord: m.y, min: Math.min(m.x, I.x), max: Math.max(m.x, I.x), boundary: m, railEnd: I, rect: S }; }, "terminalLaneFor"), i = /* @__PURE__ */ l((h, p) => Math.max(0, Math.min(h.max, p.max) - Math.max(h.min, p.min)), "projectedOverlapLength"), a = /* @__PURE__ */ l((h, p) => h.nodeId !== p.nodeId || h.orientation !== p.orientation ? !1 : h.orientation === "H" ? (Math.abs(h.boundary.x - h.rect.left) < 1 || Math.abs(h.boundary.x - h.rect.right) < 1) && ft(h.boundary, p.boundary, 1) : (Math.abs(h.boundary.y - h.rect.top) < 1 || Math.abs(h.boundary.y - h.rect.bottom) < 1) && dt(h.boundary, p.boundary, 1), "sameTerminalFace"), d = /* @__PURE__ */ l((h, p) => h.nodeId !== p.nodeId || h.orientation !== p.orientation ? !1 : i(h, p) >= kt && Math.abs(h.coord - p.coord) < 0.5, "exactTerminalLaneConflict"), c = /* @__PURE__ */ l((h, p) => { if (h.nodeId !== p.nodeId || h.orientation !== p.orientation || h.orientation !== "H" || h.atStart === p.atStart) return !1; const f = i(h, p); if (f < kt) return !1; const M = h.rect.bottom - h.rect.top; return f < M || f > 2 * M ? !1 : a(h, p) && Math.abs(h.coord - p.coord) < 16; }, "nearTerminalLaneConflict"), g = /* @__PURE__ */ l((h, p) => { const f = gt(h.edge.points ?? []); if (f.length < 2) return; const M = h.orientation === "V" ? { x: h.boundary.x + p, y: h.boundary.y } : { x: h.boundary.x, y: h.boundary.y + p }, w = h.orientation === "V" ? { x: h.railEnd.x + p, y: h.railEnd.y } : { x: h.railEnd.x, y: h.railEnd.y + p }; if (!(/* @__PURE__ */ l(() => Math.abs(h.boundary.y - h.rect.top) < 1 || Math.abs(h.boundary.y - h.rect.bottom) < 1 ? dt(M, h.boundary, J) && M.x >= h.rect.left + 1 && M.x <= h.rect.right - 1 : Math.abs(h.boundary.x - h.rect.left) < 1 || Math.abs(h.boundary.x - h.rect.right) < 1 ? ft(M, h.boundary, J) && M.y >= h.rect.top + 1 && M.y <= h.rect.bottom - 1 : !1, "boundaryStaysOnSameFace"))()) return; if (h.atStart) { const m = f.length > 1 && Zt(f[1], h.railEnd, J), I = f.slice(m ? 2 : 1), A = I[0]; return A && !bn(A, w) ? void 0 : [ M, w, ...I ]; } const S = f.length > 1 && Zt(f[f.length - 2], h.railEnd, J), T = f.slice(0, S ? -2 : -1), v = T[T.length - 1]; if (!(v && !bn(v, w))) return [ ...T, w, M ]; }, "shiftedCandidate"), b = /* @__PURE__ */ l((h) => { const p = h.edge, f = gt(p.points ?? []); if (f.length !== 2) return !1; const M = p.start, w = p.end, S = M ? e.get(M) : void 0, T = w ? e.get(w) : void 0; if (!S || !T) return !1; const v = S.x ?? 0, m = S.y ?? 0, I = T.x ?? 0, A = T.y ?? 0, [O, N] = f; return dt(O, N, J) &&