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.

247 lines (246 loc) 9.67 kB
import { n as f } from "./chunk-Y2CYZVJY-0JxdZxki.js"; import { m as o } from "./src-DtRLxcYO.js"; import { r as m, t as h } from "./graphlib-CCKThIKP.js"; import { r as j, t as X } from "./map-DMSWkcq6.js"; var F = 4; function M(e) { return j(e, F); } function C(e) { var r = { options: { directed: e.isDirected(), multigraph: e.isMultigraph(), compound: e.isCompound() }, nodes: R(e), edges: _(e) }; return m(e.graph()) || (r.value = M(e.graph())), r; } function R(e) { return X(e.nodes(), function(r) { var n = e.node(r), s = e.parent(r), t = { v: r }; return m(n) || (t.value = n), m(s) || (t.parent = s), t; }); } function _(e) { return X(e.edges(), function(r) { var n = e.edge(r), s = { v: r.v, w: r.w }; return m(r.name) || (s.name = r.name), m(n) || (s.value = n), s; }); } var a = /* @__PURE__ */ new Map(), d = /* @__PURE__ */ new Map(), A = /* @__PURE__ */ new Map(), U = /* @__PURE__ */ f(() => { d.clear(), A.clear(), a.clear(); }, "clear"), w = /* @__PURE__ */ f((e, r) => { const n = d.get(r) || []; return o.trace("In isDescendant", r, " ", e, " = ", n.includes(e)), n.includes(e); }, "isDescendant"), p = /* @__PURE__ */ f((e, r) => { const n = d.get(r) || []; return o.info("Descendants of ", r, " is ", n), o.info("Edge is ", e), e.v === r || e.w === r ? !1 : n ? n.includes(e.v) || w(e.v, r) || w(e.w, r) || n.includes(e.w) : (o.debug("Tilt, ", r, ",not in descendants"), !1); }, "edgeInCluster"), E = /* @__PURE__ */ f((e, r, n, s) => { o.warn("Copying children of ", e, "root", s, "data", r.node(e), s); const t = r.children(e) || []; e !== s && t.push(e), o.warn("Copying (nodes) clusterId", e, "nodes", t), t.forEach((i) => { if (r.children(i).length > 0) E(i, r, n, s); else { const u = r.node(i); o.info("cp ", i, " to ", s, " with parent ", e), n.setNode(i, u), s !== r.parent(i) && (o.warn("Setting parent", i, r.parent(i)), n.setParent(i, r.parent(i))), e !== s && i !== e ? (o.debug("Setting parent", i, e), n.setParent(i, e)) : (o.info("In copy ", e, "root", s, "data", r.node(e), s), o.debug("Not Setting parent for node=", i, "cluster!==rootId", e !== s, "node!==clusterId", i !== e)); const l = r.edges(i); o.debug("Copying Edges", l), l.forEach((c) => { o.info("Edge", c); const v = r.edge(c.v, c.w, c.name); o.info("Edge data", v, s); try { if (p(c, s)) { const g = d.get(s) || [], b = g.includes(c.v) || w(c.v, s) || c.v === s, x = g.includes(c.w) || w(c.w, s) || c.w === s; if (b && x) o.info("Copying as ", c.v, c.w, v, c.name), n.setEdge(c.v, c.w, v, c.name), o.info("newGraph edges ", n.edges(), n.edge(n.edges()[0])); else { const N = b ? s : c.v, y = x ? s : c.w; o.info("Rebinding cross-boundary edge as ", N, y, v, c.name), r.setEdge(N, y, v, c.name); } } else o.info("Skipping copy of edge ", c.v, "-->", c.w, " rootId: ", s, " clusterId:", e); } catch (g) { o.error(g); } }); } o.debug("Removing node", i), r.removeNode(i); }); }, "copy"), O = /* @__PURE__ */ f((e, r) => { const n = r.children(e); let s = [...n]; for (const t of n) A.set(t, e), s = [...s, ...O(t, r)]; return s; }, "extractDescendants"), P = /* @__PURE__ */ f((e, r, n) => { const s = e.edges().filter((l) => l.v === r || l.w === r), t = e.edges().filter((l) => l.v === n || l.w === n), i = s.map((l) => ({ v: l.v === r ? n : l.v, w: l.w === r ? r : l.w })), u = t.map((l) => ({ v: l.v, w: l.w })); return i.filter((l) => u.some((c) => l.v === c.v && l.w === c.w)); }, "findCommonEdges"), D = /* @__PURE__ */ f((e, r, n) => { const s = r.children(e); if (o.trace("Searching children of id ", e, s), s.length < 1) return e; let t; for (const i of s) { const u = D(i, r, n), l = P(r, n, u); if (u) if (l.length > 0) t = u; else return u; } return t; }, "findNonClusterChild"), S = /* @__PURE__ */ f((e) => !a.has(e) || !a.get(e).externalConnections ? e : a.has(e) ? a.get(e).id : e, "getAnchorId"), W = /* @__PURE__ */ f((e, r) => { if (!e || r > 10) { o.debug("Opting out, no graph "); return; } else o.debug("Opting in, graph "); e.nodes().forEach(function(n) { e.children(n).length > 0 && (o.warn("Cluster identified", n, " Replacement id in edges: ", D(n, e, n)), d.set(n, O(n, e)), a.set(n, { id: D(n, e, n), clusterData: e.node(n) })); }), e.nodes().forEach(function(n) { const s = e.children(n), t = e.edges(); s.length > 0 ? (o.debug("Cluster identified", n, d), t.forEach((i) => { w(i.v, n) ^ w(i.w, n) && (o.warn("Edge: ", i, " leaves cluster ", n), o.warn("Descendants of XXX ", n, ": ", d.get(n)), a.get(n).externalConnections = !0); })) : o.debug("Not a cluster ", n, d); }); for (let n of a.keys()) { const s = a.get(n).id, t = e.parent(s); t !== n && a.has(t) && !a.get(t).externalConnections && (a.get(n).id = t); const i = e.edges().some((u) => u.v === n); if (s && a.get(n)?.externalConnections && i && L(e, s, n)) { const u = T(e, n, e.parent(s)); u && (a.get(n).id = u); } } e.edges().forEach(function(n) { const s = e.edge(n); o.warn("Edge " + n.v + " -> " + n.w + ": " + JSON.stringify(n)), o.warn("Edge " + n.v + " -> " + n.w + ": " + JSON.stringify(e.edge(n))); let t = n.v, i = n.w; if (o.warn("Fix XXX", a, "ids:", n.v, n.w, "Translating: ", a.get(n.v), " --- ", a.get(n.w)), a.get(n.v) || a.get(n.w)) { if (o.warn("Fixing and trying - removing XXX", n.v, n.w, n.name), t = S(n.v), i = S(n.w), e.removeEdge(n.v, n.w, n.name), t !== n.v) { const u = e.parent(t); a.get(u).externalConnections = !0, s.fromCluster = n.v; } if (i !== n.w) { const u = e.parent(i); a.get(u).externalConnections = !0, s.toCluster = n.w; } o.warn("Fix Replacing with XXX", t, i, n.name), e.setEdge(t, i, s, n.name); } }), o.warn("Adjusted Graph", C(e)), k(e, 0), o.trace(a); }, "adjustClustersAndEdges"), k = /* @__PURE__ */ f((e, r) => { if (o.warn("extractor - ", r, C(e), e.children("D")), r > 10) { o.error("Bailing out"); return; } let n = e.nodes(), s = !1; for (const t of n) { const i = e.children(t); s = s || i.length > 0; } if (!s) { o.debug("Done, no node has children", e.nodes()); return; } o.debug("Nodes = ", n, r); for (const t of n) if (o.debug("Extracting node", t, a, a.has(t) && !a.get(t).externalConnections, !e.parent(t), e.node(t), e.children("D"), " Depth ", r), !a.has(t)) o.debug("Not a cluster", t, r); else if (a.get(t)?.clusterData?.explicitDir && e.children(t) && e.children(t).length > 0) { o.warn("Cluster with explicit dir, creating subgraph for children", t, r); const i = a.get(t).clusterData.dir, u = new h({ multigraph: !0, compound: !0 }).setGraph({ rankdir: i, nodesep: 50, ranksep: 50, marginx: 8, marginy: 8 }).setDefaultEdgeLabel(function() { return {}; }); E(t, e, u, t); const l = e.node(t) || {}; e.setNode(t, { ...l, clusterNode: !0, id: t, clusterData: a.get(t).clusterData, label: a.get(t).label, graph: u }), o.warn("Subgraph for cluster with explicit dir created:", t, C(u)); } else if (!a.get(t).externalConnections && e.children(t) && e.children(t).length > 0) { o.warn("Cluster without external connections, without a parent and with children", t, r); let i = e.graph().rankdir === "TB" ? "LR" : "TB"; a.get(t)?.clusterData?.dir && (i = a.get(t).clusterData.dir, o.warn("Fixing dir", a.get(t).clusterData.dir, i)); const u = new h({ multigraph: !0, compound: !0 }).setGraph({ rankdir: i, nodesep: 50, ranksep: 50, marginx: 8, marginy: 8 }).setDefaultEdgeLabel(function() { return {}; }); E(t, e, u, t); const l = e.node(t) || {}; e.setNode(t, { ...l, clusterNode: !0, id: t, clusterData: a.get(t).clusterData, label: a.get(t).label, graph: u }), o.debug("Old graph after copy", C(e)); } else o.warn("Cluster ** ", t, " **not meeting the criteria !externalConnections:", !a.get(t).externalConnections, " no parent: ", !e.parent(t), " children ", e.children(t) && e.children(t).length > 0, e.children("D"), r), o.debug(a); n = e.nodes(), o.warn("New list of nodes", n); for (const t of n) { const i = e.node(t); o.warn(" Now next level", t, i), i?.clusterNode && k(i.graph, r + 1); } }, "extractor"), B = /* @__PURE__ */ f((e, r) => { if (r.length === 0) return []; let n = Object.assign([], r); return r.forEach((s) => { const t = B(e, e.children(s)); n = [...n, ...t]; }), n; }, "sorter"), Y = /* @__PURE__ */ f((e) => B(e, e.children()), "sortNodesByHierarchy"), L = /* @__PURE__ */ f((e, r, n) => { let s = e.parent(r); for (; s && s !== n; ) { const t = a.get(s); if (t && !t.externalConnections) return !0; s = e.parent(s); } return !1; }, "isNodeInExtractableCluster"), T = /* @__PURE__ */ f((e, r, n) => { const s = e.children(r) ?? []; for (const t of s) { if (t === n || w(t, n)) continue; const i = D(t, e, r); if (i && !L(e, i, r)) return i; } return null; }, "findSafeAnchorNode"); export { Y as a, D as i, U as n, C as o, a as r, W as t };