import { G as Ct, K as Pt, i as Nt, f as zt, W as At, U as Tt, p as g, s as J, ah as It, o as Lt, g as tt, a0 as Et, A as Bt, H as Ft, Z as H } from "./index-CNUFa5l3.js";
import { t as Rt } from "./chunk-4BX2VUAB-C_NnimAy-9zhkU6MG.js";
import { r as Ot } from "./wardley-L42UT6IY-BjAkE_cs-li1xYed9.js";
var Y = /* @__PURE__ */ g((r, e) => {
  let a = r <= 1 ? r * 100 : r;
  if (a < 0 || a > 100) throw Error(`${e} must be between 0-1 (decimal) or 0-100 (percentage). Received: ${r}`);
  return a;
}, "toPercent"), I = /* @__PURE__ */ g((r, e, a) => ({
  x: Y(e, `${a} evolution`),
  y: Y(r, `${a} visibility`)
}), "toCoordinates"), Q = /* @__PURE__ */ g((r) => {
  if (r) {
    if (r === "+<>") return "bidirectional";
    if (r === "+<") return "backward";
    if (r === "+>") return "forward";
  }
}, "getFlowFromPort"), Xt = /* @__PURE__ */ g((r) => {
  var a;
  if (!(r != null && r.startsWith("+"))) return {};
  let e = (a = /^\+'([^']*)'/.exec(r)) == null ? void 0 : a[1];
  return r.includes("<>") ? {
    flow: "bidirectional",
    label: e
  } : r.includes("<") ? {
    flow: "backward",
    label: e
  } : r.includes(">") ? {
    flow: "forward",
    label: e
  } : { label: e };
}, "extractFlowFromArrow"), Yt = /* @__PURE__ */ g((r, e) => {
  if (Rt(r, e), r.size && e.setSize(r.size.width, r.size.height), r.evolution) {
    let a = r.evolution.stages.map((o) => o.secondName ? `${o.name.trim()} / ${o.secondName.trim()}` : o.name.trim()), c = r.evolution.stages.filter((o) => o.boundary !== void 0).map((o) => o.boundary);
    e.updateAxes({
      stages: a,
      stageBoundaries: c
    });
  }
  if (r.anchors.forEach((a) => {
    let c = I(a.visibility, a.evolution, `Anchor "${a.name}"`);
    e.addNode(a.name, a.name, c.x, c.y, "anchor");
  }), r.components.forEach((a) => {
    var v;
    let c = I(a.visibility, a.evolution, `Component "${a.name}"`), o = a.label ? (a.label.negX ? -1 : 1) * a.label.offsetX : void 0, s = a.label ? (a.label.negY ? -1 : 1) * a.label.offsetY : void 0, u = (v = a.decorator) == null ? void 0 : v.strategy;
    e.addNode(a.name, a.name, c.x, c.y, "component", o, s, a.inertia, u);
  }), r.notes.forEach((a) => {
    let c = I(a.visibility, a.evolution, `Note "${a.text}"`);
    e.addNote(a.text, c.x, c.y);
  }), r.pipelines.forEach((a) => {
    let c = e.getNode(a.parent);
    if (!c || typeof c.y != "number") throw Error(`Pipeline "${a.parent}" must reference an existing component with coordinates.`);
    let o = c.y;
    e.startPipeline(a.parent), a.components.forEach((s) => {
      let u = `${a.parent}_${s.name}`, v = s.label ? (s.label.negX ? -1 : 1) * s.label.offsetX : void 0, y = s.label ? (s.label.negY ? -1 : 1) * s.label.offsetY : void 0, N = Y(s.evolution, `Pipeline component "${s.name}" evolution`);
      e.addNode(u, s.name, N, o, "pipeline-component", v, y), e.addPipelineComponent(a.parent, u);
    });
  }), r.links.forEach((a) => {
    let c = !!a.arrow && (a.arrow.includes("-.->") || a.arrow.includes(".-.")), o = Q(a.fromPort) ?? Q(a.toPort), { flow: s, label: u } = Xt(a.arrow);
    !o && s && (o = s);
    let v = a.linkLabel, y = u ?? v;
    e.addLink(e.resolveNodeId(a.from), e.resolveNodeId(a.to), c, y, o);
  }), r.evolves.forEach((a) => {
    let c = e.getNode(a.component);
    if ((c == null ? void 0 : c.y) !== void 0) {
      let o = Y(a.target, `Evolve target for "${a.component}"`);
      e.addTrend(a.component, o, c.y);
    }
  }), r.annotations.length > 0) {
    let a = r.annotations[0], c = I(a.x, a.y, "Annotations box");
    e.setAnnotationsBox(c.x, c.y);
  }
  r.annotation.forEach((a) => {
    let c = I(a.x, a.y, `Annotation ${a.number}`);
    e.addAnnotation(a.number, [{
      x: c.x,
      y: c.y
    }], a.text);
  }), r.accelerators.forEach((a) => {
    let c = I(a.x, a.y, `Accelerator "${a.name}"`);
    e.addAccelerator(a.name, c.x, c.y);
  }), r.deaccelerators.forEach((a) => {
    let c = I(a.x, a.y, `Deaccelerator "${a.name}"`);
    e.addDeaccelerator(a.name, c.x, c.y);
  });
}, "populateDb"), et = {
  parser: { yy: void 0 },
  parse: /* @__PURE__ */ g(async (r) => {
    var c;
    let e = await Ot("wardley", r);
    tt.debug(e);
    let a = (c = et.parser) == null ? void 0 : c.yy;
    if (!a || typeof a.addNode != "function") throw Error("parser.parser?.yy was not a WardleyDB. This is due to a bug within Mermaid, please report this issue at https://github.com/mermaid-js/mermaid/issues.");
    Yt(e, a);
  }, "parse")
}, E, k = new (E = class {
  constructor() {
    this.nodes = /* @__PURE__ */ new Map(), this.links = [], this.trends = /* @__PURE__ */ new Map(), this.pipelines = /* @__PURE__ */ new Map(), this.annotations = [], this.notes = [], this.accelerators = [], this.deaccelerators = [], this.axes = {};
  }
  addNode(e) {
    let a = this.nodes.get(e.id) ?? {
      id: e.id,
      label: e.label
    }, c = {
      ...a,
      ...e,
      className: e.className ?? a.className,
      labelOffsetX: e.labelOffsetX ?? a.labelOffsetX,
      labelOffsetY: e.labelOffsetY ?? a.labelOffsetY
    };
    this.nodes.set(e.id, c);
  }
  addLink(e) {
    this.links.push(e);
  }
  addTrend(e) {
    this.trends.set(e.nodeId, e);
  }
  startPipeline(e) {
    this.pipelines.set(e, {
      nodeId: e,
      componentIds: []
    });
    let a = this.nodes.get(e);
    a && (a.isPipelineParent = !0);
  }
  addPipelineComponent(e, a) {
    let c = this.pipelines.get(e);
    c && c.componentIds.push(a);
    let o = this.nodes.get(a);
    o && (o.inPipeline = !0);
  }
  addAnnotation(e) {
    this.annotations.push(e);
  }
  addNote(e) {
    this.notes.push(e);
  }
  addAccelerator(e) {
    this.accelerators.push(e);
  }
  addDeaccelerator(e) {
    this.deaccelerators.push(e);
  }
  setAnnotationsBox(e, a) {
    this.annotationsBox = {
      x: e,
      y: a
    };
  }
  setAxes(e) {
    this.axes = {
      ...this.axes,
      ...e
    };
  }
  setSize(e, a) {
    this.size = {
      width: e,
      height: a
    };
  }
  getNode(e) {
    return this.nodes.get(e);
  }
  resolveNodeId(e) {
    if (this.nodes.has(e)) return e;
    for (let [a, c] of this.nodes) if (c.label === e) return a;
    return e;
  }
  build() {
    let e = [];
    for (let a of this.nodes.values()) {
      if (typeof a.x != "number" || typeof a.y != "number") throw Error(`Node "${a.label}" is missing coordinates`);
      e.push(a);
    }
    return {
      nodes: e,
      links: [...this.links],
      trends: [...this.trends.values()],
      pipelines: [...this.pipelines.values()],
      annotations: [...this.annotations],
      notes: [...this.notes],
      accelerators: [...this.accelerators],
      deaccelerators: [...this.deaccelerators],
      annotationsBox: this.annotationsBox,
      axes: { ...this.axes },
      size: this.size
    };
  }
  clear() {
    this.nodes.clear(), this.links = [], this.trends.clear(), this.pipelines.clear(), this.annotations = [], this.notes = [], this.accelerators = [], this.deaccelerators = [], this.annotationsBox = void 0, this.axes = {}, this.size = void 0;
  }
}, g(E, "WardleyBuilder"), E)();
function at() {
  return H()["wardley-beta"];
}
g(at, "getConfig");
function rt(r, e, a, c, o, s, u, v, y) {
  k.addNode({
    id: r,
    label: e,
    x: a,
    y: c,
    className: o,
    labelOffsetX: s,
    labelOffsetY: u,
    inertia: v,
    sourceStrategy: y
  });
}
g(rt, "addNode");
function ot(r, e, a = !1, c, o) {
  k.addLink({
    source: r,
    target: e,
    dashed: a,
    label: c,
    flow: o
  });
}
g(ot, "addLink");
function nt(r, e, a) {
  k.addTrend({
    nodeId: r,
    targetX: e,
    targetY: a
  });
}
g(nt, "addTrend");
function it(r, e, a) {
  k.addAnnotation({
    number: r,
    coordinates: e,
    text: a
  });
}
g(it, "addAnnotation");
function lt(r, e, a) {
  k.addNote({
    text: r,
    x: e,
    y: a
  });
}
g(lt, "addNote");
function st(r, e, a) {
  k.addAccelerator({
    name: r,
    x: e,
    y: a
  });
}
g(st, "addAccelerator");
function dt(r, e, a) {
  k.addDeaccelerator({
    name: r,
    x: e,
    y: a
  });
}
g(dt, "addDeaccelerator");
function ct(r, e) {
  k.setAnnotationsBox(r, e);
}
g(ct, "setAnnotationsBox");
function pt(r, e) {
  k.setSize(r, e);
}
g(pt, "setSize");
function xt(r) {
  k.startPipeline(r);
}
g(xt, "startPipeline");
function ht(r, e) {
  k.addPipelineComponent(r, e);
}
g(ht, "addPipelineComponent");
function yt(r) {
  k.setAxes(r);
}
g(yt, "updateAxes");
function ft(r) {
  return k.getNode(r);
}
g(ft, "getNode");
function gt(r) {
  return k.resolveNodeId(r);
}
g(gt, "resolveNodeId");
function ut() {
  return k.build();
}
g(ut, "getWardleyData");
function mt() {
  k.clear(), Ft();
}
g(mt, "clear");
var Dt = {
  getConfig: at,
  addNode: rt,
  addLink: ot,
  addTrend: nt,
  addAnnotation: it,
  addNote: lt,
  addAccelerator: st,
  addDeaccelerator: dt,
  setAnnotationsBox: ct,
  setSize: pt,
  startPipeline: xt,
  addPipelineComponent: ht,
  updateAxes: yt,
  getNode: ft,
  resolveNodeId: gt,
  getWardleyData: ut,
  clear: mt,
  setAccTitle: Tt,
  getAccTitle: At,
  setDiagramTitle: zt,
  getDiagramTitle: Nt,
  getAccDescription: Pt,
  setAccDescription: Ct
}, Wt = [
  "Genesis",
  "Custom Built",
  "Product",
  "Commodity"
], qt = /* @__PURE__ */ g(() => {
  var e, a, c, o, s, u, v, y, N, M, w, C;
  let { themeVariables: r } = H();
  return {
    backgroundColor: ((e = r.wardley) == null ? void 0 : e.backgroundColor) ?? r.background ?? "#fff",
    axisColor: ((a = r.wardley) == null ? void 0 : a.axisColor) ?? "#000",
    axisTextColor: ((c = r.wardley) == null ? void 0 : c.axisTextColor) ?? r.primaryTextColor ?? "#222",
    gridColor: ((o = r.wardley) == null ? void 0 : o.gridColor) ?? "rgba(100, 100, 100, 0.2)",
    componentFill: ((s = r.wardley) == null ? void 0 : s.componentFill) ?? "#fff",
    componentStroke: ((u = r.wardley) == null ? void 0 : u.componentStroke) ?? "#000",
    componentLabelColor: ((v = r.wardley) == null ? void 0 : v.componentLabelColor) ?? r.primaryTextColor ?? "#222",
    linkStroke: ((y = r.wardley) == null ? void 0 : y.linkStroke) ?? "#000",
    evolutionStroke: ((N = r.wardley) == null ? void 0 : N.evolutionStroke) ?? "#dc3545",
    annotationStroke: ((M = r.wardley) == null ? void 0 : M.annotationStroke) ?? "#000",
    annotationTextColor: ((w = r.wardley) == null ? void 0 : w.annotationTextColor) ?? r.primaryTextColor ?? "#222",
    annotationFill: ((C = r.wardley) == null ? void 0 : C.annotationFill) ?? r.background ?? "#fff"
  };
}, "getTheme"), jt = /* @__PURE__ */ g(() => {
  let r = H()["wardley-beta"];
  return {
    width: (r == null ? void 0 : r.width) ?? 900,
    height: (r == null ? void 0 : r.height) ?? 600,
    padding: (r == null ? void 0 : r.padding) ?? 48,
    nodeRadius: (r == null ? void 0 : r.nodeRadius) ?? 6,
    nodeLabelOffset: (r == null ? void 0 : r.nodeLabelOffset) ?? 8,
    axisFontSize: (r == null ? void 0 : r.axisFontSize) ?? 12,
    labelFontSize: (r == null ? void 0 : r.labelFontSize) ?? 10,
    showGrid: (r == null ? void 0 : r.showGrid) ?? !1,
    useMaxWidth: (r == null ? void 0 : r.useMaxWidth) ?? !0
  };
}, "getConfigValues"), Zt = {
  parser: et,
  db: Dt,
  renderer: { draw: /* @__PURE__ */ g((r, e, a, c) => {
    var _, K;
    tt.debug(`Rendering Wardley map
` + r);
    let o = jt(), s = qt(), u = o.nodeRadius * 1.6, v = c.db, y = v.getWardleyData(), N = v.getDiagramTitle(), M = ((_ = y.size) == null ? void 0 : _.width) ?? o.width, w = ((K = y.size) == null ? void 0 : K.height) ?? o.height, C = Et(e);
    C.selectAll("*").remove(), Bt(C, w, M, o.useMaxWidth), C.attr("viewBox", `0 0 ${M} ${w}`);
    let S = C.append("g").attr("class", "wardley-map"), D = C.append("defs");
    D.append("marker").attr("id", `arrow-${e}`).attr("viewBox", "0 0 10 10").attr("refX", 9).attr("refY", 5).attr("markerWidth", 6).attr("markerHeight", 6).attr("orient", "auto-start-reverse").append("path").attr("d", "M 0 0 L 10 5 L 0 10 z").attr("fill", s.evolutionStroke).attr("stroke", "none"), D.append("marker").attr("id", `link-arrow-end-${e}`).attr("viewBox", "0 0 10 10").attr("refX", 9).attr("refY", 5).attr("markerWidth", 5).attr("markerHeight", 5).attr("orient", "auto").append("path").attr("d", "M 0 0 L 10 5 L 0 10 z").attr("fill", s.linkStroke).attr("stroke", "none"), D.append("marker").attr("id", `link-arrow-start-${e}`).attr("viewBox", "0 0 10 10").attr("refX", 1).attr("refY", 5).attr("markerWidth", 5).attr("markerHeight", 5).attr("orient", "auto").append("path").attr("d", "M 10 0 L 0 5 L 10 10 z").attr("fill", s.linkStroke).attr("stroke", "none"), S.append("rect").attr("class", "wardley-background").attr("width", M).attr("height", w).attr("fill", s.backgroundColor);
    let B = M - o.padding * 2, F = w - o.padding * 2;
    N && S.append("text").attr("class", "wardley-title").attr("x", M / 2).attr("y", o.padding / 2).attr("fill", s.axisTextColor).attr("font-size", o.axisFontSize * 1.05).attr("font-weight", "bold").attr("text-anchor", "middle").attr("dominant-baseline", "middle").text(N);
    let z = /* @__PURE__ */ g((t) => o.padding + t / 100 * B, "projectX"), A = /* @__PURE__ */ g((t) => w - o.padding - t / 100 * F, "projectY"), O = S.append("g").attr("class", "wardley-axes");
    O.append("line").attr("x1", o.padding).attr("x2", M - o.padding).attr("y1", w - o.padding).attr("y2", w - o.padding).attr("stroke", s.axisColor).attr("stroke-width", 1), O.append("line").attr("x1", o.padding).attr("x2", o.padding).attr("y1", o.padding).attr("y2", w - o.padding).attr("stroke", s.axisColor).attr("stroke-width", 1);
    let wt = y.axes.xLabel ?? "Evolution", kt = y.axes.yLabel ?? "Visibility";
    O.append("text").attr("class", "wardley-axis-label wardley-axis-label-x").attr("x", o.padding + B / 2).attr("y", w - o.padding / 4).attr("fill", s.axisTextColor).attr("font-size", o.axisFontSize).attr("font-weight", "bold").attr("text-anchor", "middle").text(wt), O.append("text").attr("class", "wardley-axis-label wardley-axis-label-y").attr("x", o.padding / 3).attr("y", o.padding + F / 2).attr("fill", s.axisTextColor).attr("font-size", o.axisFontSize).attr("font-weight", "bold").attr("text-anchor", "middle").attr("transform", `rotate(-90 ${o.padding / 3} ${o.padding + F / 2})`).text(kt);
    let R = y.axes.stages && y.axes.stages.length > 0 ? y.axes.stages : Wt;
    if (R.length > 0) {
      let t = S.append("g").attr("class", "wardley-stages"), i = y.axes.stageBoundaries, n = [];
      if (i && i.length === R.length) {
        let l = 0;
        i.forEach((p) => {
          n.push({
            start: l,
            end: p
          }), l = p;
        });
      } else {
        let l = 1 / R.length;
        R.forEach((p, x) => {
          n.push({
            start: x * l,
            end: (x + 1) * l
          });
        });
      }
      R.forEach((l, p) => {
        let x = n[p], f = o.padding + x.start * B, h = (f + (o.padding + x.end * B)) / 2;
        p > 0 && t.append("line").attr("x1", f).attr("x2", f).attr("y1", o.padding).attr("y2", w - o.padding).attr("stroke", "#000").attr("stroke-width", 1).attr("stroke-dasharray", "5 5").attr("opacity", 0.8), t.append("text").attr("class", "wardley-stage-label").attr("x", h).attr("y", w - o.padding / 1.5).attr("fill", s.axisTextColor).attr("font-size", o.axisFontSize - 2).attr("text-anchor", "middle").text(l);
      });
    }
    if (o.showGrid) {
      let t = S.append("g").attr("class", "wardley-grid");
      for (let i = 1; i < 4; i++) {
        let n = i / 4, l = o.padding + B * n;
        t.append("line").attr("x1", l).attr("x2", l).attr("y1", o.padding).attr("y2", w - o.padding).attr("stroke", s.gridColor).attr("stroke-dasharray", "2 6"), t.append("line").attr("x1", o.padding).attr("x2", M - o.padding).attr("y1", w - o.padding - F * n).attr("y2", w - o.padding - F * n).attr("stroke", s.gridColor).attr("stroke-dasharray", "2 6");
      }
    }
    let d = /* @__PURE__ */ new Map();
    if (y.nodes.forEach((t) => {
      d.set(t.id, {
        x: z(t.x),
        y: A(t.y),
        node: t
      });
    }), y.pipelines.length > 0) {
      let t = S.append("g").attr("class", "wardley-pipelines"), i = S.append("g").attr("class", "wardley-pipeline-links");
      y.pipelines.forEach((n) => {
        if (n.componentIds.length === 0) return;
        let l = n.componentIds.map((h) => ({
          id: h,
          pos: d.get(h),
          node: y.nodes.find((m) => m.id === h)
        })).filter((h) => h.pos && h.node).sort((h, m) => h.node.x - m.node.x);
        for (let h = 0; h < l.length - 1; h++) {
          let m = l[h], $ = l[h + 1];
          i.append("line").attr("class", "wardley-pipeline-evolution-link").attr("x1", m.pos.x).attr("y1", m.pos.y).attr("x2", $.pos.x).attr("y2", $.pos.y).attr("stroke", s.linkStroke).attr("stroke-width", 1).attr("stroke-dasharray", "4 4");
        }
        let p = 1 / 0, x = -1 / 0, f = 0;
        if (n.componentIds.forEach((h) => {
          let m = d.get(h);
          m && (p = Math.min(p, m.x), x = Math.max(x, m.x), f = m.y);
        }), p !== 1 / 0 && x !== -1 / 0) {
          let h = o.nodeRadius * 4, m = f - h / 2, $ = d.get(n.nodeId);
          $ && ($.x = (p + x) / 2, $.y = m - u / 6), t.append("rect").attr("class", "wardley-pipeline-box").attr("x", p - 15).attr("y", m).attr("width", x - p + 30).attr("height", h).attr("fill", "none").attr("stroke", s.axisColor).attr("stroke-width", 1.5).attr("rx", 4).attr("ry", 4);
        }
      });
    }
    let V = S.append("g").attr("class", "wardley-links"), Z = /* @__PURE__ */ new Map();
    y.pipelines.forEach((t) => {
      Z.set(t.nodeId, new Set(t.componentIds));
    });
    let U = y.links.filter((t) => {
      var i;
      return !(!d.has(t.source) || !d.has(t.target) || (i = Z.get(t.target)) != null && i.has(t.source));
    });
    V.selectAll("line").data(U).enter().append("line").attr("class", (t) => `wardley-link${t.dashed ? " wardley-link--dashed" : ""}`).attr("x1", (t) => {
      let i = d.get(t.source), n = d.get(t.target), l = y.nodes.find((h) => h.id === t.source).isPipelineParent ? u / Math.sqrt(2) : o.nodeRadius, p = n.x - i.x, x = n.y - i.y, f = Math.sqrt(p * p + x * x);
      return i.x + p / f * l;
    }).attr("y1", (t) => {
      let i = d.get(t.source), n = d.get(t.target), l = y.nodes.find((h) => h.id === t.source).isPipelineParent ? u / Math.sqrt(2) : o.nodeRadius, p = n.x - i.x, x = n.y - i.y, f = Math.sqrt(p * p + x * x);
      return i.y + x / f * l;
    }).attr("x2", (t) => {
      let i = d.get(t.source), n = d.get(t.target), l = y.nodes.find((h) => h.id === t.target).isPipelineParent ? u / Math.sqrt(2) : o.nodeRadius, p = i.x - n.x, x = i.y - n.y, f = Math.sqrt(p * p + x * x);
      return n.x + p / f * l;
    }).attr("y2", (t) => {
      let i = d.get(t.source), n = d.get(t.target), l = y.nodes.find((h) => h.id === t.target).isPipelineParent ? u / Math.sqrt(2) : o.nodeRadius, p = i.x - n.x, x = i.y - n.y, f = Math.sqrt(p * p + x * x);
      return n.y + x / f * l;
    }).attr("stroke", s.linkStroke).attr("stroke-width", 1).attr("stroke-dasharray", (t) => t.dashed ? "6 6" : null).attr("marker-end", (t) => t.flow === "forward" || t.flow === "bidirectional" ? `url(#link-arrow-end-${e})` : null).attr("marker-start", (t) => t.flow === "backward" || t.flow === "bidirectional" ? `url(#link-arrow-start-${e})` : null), V.selectAll("text").data(U.filter((t) => t.label)).enter().append("text").attr("class", "wardley-link-label").attr("x", (t) => {
      let i = d.get(t.source), n = d.get(t.target), l = (i.x + n.x) / 2, p = n.y - i.y, x = n.x - i.x;
      return l + p / Math.sqrt(x * x + p * p) * 8;
    }).attr("y", (t) => {
      let i = d.get(t.source), n = d.get(t.target), l = (i.y + n.y) / 2, p = n.x - i.x, x = n.y - i.y, f = Math.sqrt(p * p + x * x);
      return l + -p / f * 8;
    }).attr("fill", s.axisTextColor).attr("font-size", o.labelFontSize).attr("text-anchor", "middle").attr("dominant-baseline", "middle").attr("transform", (t) => {
      let i = d.get(t.source), n = d.get(t.target), l = (i.x + n.x) / 2, p = (i.y + n.y) / 2, x = n.x - i.x, f = n.y - i.y, h = Math.sqrt(x * x + f * f), m = f / h, $ = -x / h, q = l + m * 8, j = p + $ * 8, L = Math.atan2(f, x) * 180 / Math.PI;
      return (L > 90 || L < -90) && (L += 180), `rotate(${L} ${q} ${j})`;
    }).text((t) => t.label);
    let bt = S.append("g").attr("class", "wardley-trends"), vt = y.trends.map((t) => {
      let i = d.get(t.nodeId);
      if (!i) return null;
      let n = z(t.targetX), l = A(t.targetY), p = n - i.x, x = l - i.y, f = Math.sqrt(p * p + x * x), h = o.nodeRadius + 2;
      return {
        origin: i,
        targetX: n,
        targetY: l,
        adjustedX2: f > h ? n - p / f * h : n,
        adjustedY2: f > h ? l - x / f * h : l
      };
    }).filter((t) => t !== null);
    bt.selectAll("line").data(vt).enter().append("line").attr("class", "wardley-trend").attr("x1", (t) => t.origin.x).attr("y1", (t) => t.origin.y).attr("x2", (t) => t.adjustedX2).attr("y2", (t) => t.adjustedY2).attr("stroke", s.evolutionStroke).attr("stroke-width", 1).attr("stroke-dasharray", "4 4").attr("marker-end", `url(#arrow-${e})`);
    let P = S.append("g").attr("class", "wardley-nodes").selectAll("g").data(y.nodes).enter().append("g").attr("class", (t) => ["wardley-node", t.className ? `wardley-node--${t.className}` : ""].filter(Boolean).join(" "));
    P.filter((t) => t.sourceStrategy === "outsource").append("circle").attr("class", "wardley-outsource-overlay").attr("cx", (t) => d.get(t.id).x).attr("cy", (t) => d.get(t.id).y).attr("r", o.nodeRadius * 2).attr("fill", "#666").attr("stroke", s.componentStroke).attr("stroke-width", 1), P.filter((t) => t.sourceStrategy === "buy").append("circle").attr("class", "wardley-buy-overlay").attr("cx", (t) => d.get(t.id).x).attr("cy", (t) => d.get(t.id).y).attr("r", o.nodeRadius * 2).attr("fill", "#ccc").attr("stroke", s.componentStroke).attr("stroke-width", 1), P.filter((t) => t.sourceStrategy === "build").append("circle").attr("class", "wardley-build-overlay").attr("cx", (t) => d.get(t.id).x).attr("cy", (t) => d.get(t.id).y).attr("r", o.nodeRadius * 2).attr("fill", "#eee").attr("stroke", "#000").attr("stroke-width", 1);
    let T = P.filter((t) => t.sourceStrategy === "market");
    T.append("circle").attr("class", "wardley-market-overlay").attr("cx", (t) => d.get(t.id).x).attr("cy", (t) => d.get(t.id).y).attr("r", o.nodeRadius * 2).attr("fill", "white").attr("stroke", s.componentStroke).attr("stroke-width", 1), P.filter((t) => !t.isPipelineParent && t.sourceStrategy !== "market" && t.className !== "anchor").append("circle").attr("cx", (t) => d.get(t.id).x).attr("cy", (t) => d.get(t.id).y).attr("r", o.nodeRadius).attr("fill", s.componentFill).attr("stroke", s.componentStroke).attr("stroke-width", 1);
    let W = o.nodeRadius * 0.7, b = o.nodeRadius * 1.2;
    if (T.append("line").attr("class", "wardley-market-line").attr("x1", (t) => d.get(t.id).x).attr("y1", (t) => d.get(t.id).y - b).attr("x2", (t) => d.get(t.id).x - b * Math.cos(Math.PI / 6)).attr("y2", (t) => d.get(t.id).y + b * Math.sin(Math.PI / 6)).attr("stroke", s.componentStroke).attr("stroke-width", 1), T.append("line").attr("class", "wardley-market-line").attr("x1", (t) => d.get(t.id).x - b * Math.cos(Math.PI / 6)).attr("y1", (t) => d.get(t.id).y + b * Math.sin(Math.PI / 6)).attr("x2", (t) => d.get(t.id).x + b * Math.cos(Math.PI / 6)).attr("y2", (t) => d.get(t.id).y + b * Math.sin(Math.PI / 6)).attr("stroke", s.componentStroke).attr("stroke-width", 1), T.append("line").attr("class", "wardley-market-line").attr("x1", (t) => d.get(t.id).x + b * Math.cos(Math.PI / 6)).attr("y1", (t) => d.get(t.id).y + b * Math.sin(Math.PI / 6)).attr("x2", (t) => d.get(t.id).x).attr("y2", (t) => d.get(t.id).y - b).attr("stroke", s.componentStroke).attr("stroke-width", 1), T.append("circle").attr("class", "wardley-market-dot").attr("cx", (t) => d.get(t.id).x).attr("cy", (t) => d.get(t.id).y - b).attr("r", W).attr("fill", "white").attr("stroke", s.componentStroke).attr("stroke-width", 2), T.append("circle").attr("class", "wardley-market-dot").attr("cx", (t) => d.get(t.id).x - b * Math.cos(Math.PI / 6)).attr("cy", (t) => d.get(t.id).y + b * Math.sin(Math.PI / 6)).attr("r", W).attr("fill", "white").attr("stroke", s.componentStroke).attr("stroke-width", 2), T.append("circle").attr("class", "wardley-market-dot").attr("cx", (t) => d.get(t.id).x + b * Math.cos(Math.PI / 6)).attr("cy", (t) => d.get(t.id).y + b * Math.sin(Math.PI / 6)).attr("r", W).attr("fill", "white").attr("stroke", s.componentStroke).attr("stroke-width", 2), P.filter((t) => t.isPipelineParent === !0).append("rect").attr("x", (t) => d.get(t.id).x - u / 2).attr("y", (t) => d.get(t.id).y - u / 2).attr("width", u).attr("height", u).attr("fill", s.componentFill).attr("stroke", s.componentStroke).attr("stroke-width", 1), P.filter((t) => t.inertia === !0).append("line").attr("class", "wardley-inertia").attr("x1", (t) => {
      let i = d.get(t.id), n = t.isPipelineParent ? u / 2 + 15 : o.nodeRadius + 15;
      return t.sourceStrategy && (n += o.nodeRadius + 10), i.x + n;
    }).attr("y1", (t) => {
      let i = d.get(t.id), n = t.isPipelineParent ? u : o.nodeRadius * 2;
      return i.y - n / 2;
    }).attr("x2", (t) => {
      let i = d.get(t.id), n = t.isPipelineParent ? u / 2 + 15 : o.nodeRadius + 15;
      return t.sourceStrategy && (n += o.nodeRadius + 10), i.x + n;
    }).attr("y2", (t) => {
      let i = d.get(t.id), n = t.isPipelineParent ? u : o.nodeRadius * 2;
      return i.y + n / 2;
    }).attr("stroke", s.componentStroke).attr("stroke-width", 6), P.append("text").attr("x", (t) => {
      let i = d.get(t.id);
      if (t.className === "anchor") return t.labelOffsetX === void 0 ? i.x : i.x + t.labelOffsetX;
      let n = o.nodeLabelOffset;
      t.sourceStrategy && t.labelOffsetX === void 0 && (n += 10);
      let l = t.labelOffsetX ?? n;
      return i.x + l;
    }).attr("y", (t) => {
      let i = d.get(t.id);
      if (t.className === "anchor") return t.labelOffsetY === void 0 ? i.y - 3 : i.y + t.labelOffsetY;
      let n = -o.nodeLabelOffset;
      t.sourceStrategy && t.labelOffsetY === void 0 && (n -= 10);
      let l = t.labelOffsetY ?? n;
      return i.y + l;
    }).attr("class", "wardley-node-label").attr("fill", (t) => t.className === "evolved" ? s.evolutionStroke : t.className === "anchor" ? "#000" : s.componentLabelColor).attr("font-size", o.labelFontSize).attr("font-weight", (t) => t.className === "anchor" ? "bold" : "normal").attr("text-anchor", (t) => t.className === "anchor" ? "middle" : "start").attr("dominant-baseline", (t) => t.className === "anchor" ? "middle" : "auto").text((t) => t.label), y.annotations.length > 0) {
      let t = S.append("g").attr("class", "wardley-annotations");
      if (y.annotations.forEach((i) => {
        let n = i.coordinates.map((l) => ({
          x: z(l.x),
          y: A(l.y)
        }));
        if (n.length > 1) for (let l = 0; l < n.length - 1; l++) t.append("line").attr("class", "wardley-annotation-line").attr("x1", n[l].x).attr("y1", n[l].y).attr("x2", n[l + 1].x).attr("y2", n[l + 1].y).attr("stroke", s.axisColor).attr("stroke-width", 1.5).attr("stroke-dasharray", "4 4");
        n.forEach((l) => {
          let p = t.append("g").attr("class", "wardley-annotation");
          p.append("circle").attr("cx", l.x).attr("cy", l.y).attr("r", 10).attr("fill", "white").attr("stroke", s.axisColor).attr("stroke-width", 1.5), p.append("text").attr("x", l.x).attr("y", l.y).attr("text-anchor", "middle").attr("dominant-baseline", "central").attr("font-size", 10).attr("fill", s.axisTextColor).attr("font-weight", "bold").text(i.number);
        });
      }), y.annotationsBox) {
        let i = z(y.annotationsBox.x), n = A(y.annotationsBox.y), l = t.append("g").attr("class", "wardley-annotations-box"), p = [...y.annotations].filter((f) => f.text).sort((f, h) => f.number - h.number), x = [];
        if (p.forEach((f, h) => {
          let m = l.append("text").attr("x", i + 10).attr("y", n + 10 + (h + 1) * 16).attr("font-size", 11).attr("fill", s.axisTextColor).attr("text-anchor", "start").attr("dominant-baseline", "middle").text(`${f.number}. ${f.text}`);
          x.push(m);
        }), x.length > 0) {
          let f = 0, h = 0;
          x.forEach((G) => {
            let X = G.node(), Mt = X.getComputedTextLength();
            f = Math.max(f, Mt);
            let $t = X.getBBox();
            h = Math.max(h, $t.height);
          });
          let m = f + 20 + 105, $ = p.length * 16 + 20 + h / 2, q = o.padding, j = M - o.padding - m, L = o.padding, St = w - o.padding - $;
          i = Math.max(q, Math.min(i, j)), n = Math.max(L, Math.min(n, St)), x.forEach((G, X) => {
            G.attr("x", i + 10).attr("y", n + 10 + (X + 1) * 16);
          }), l.insert("rect", "text").attr("x", i).attr("y", n).attr("width", m).attr("height", $).attr("fill", "white").attr("stroke", s.axisColor).attr("stroke-width", 1.5).attr("rx", 4).attr("ry", 4);
        }
      }
    }
    if (y.notes.length > 0) {
      let t = S.append("g").attr("class", "wardley-notes");
      y.notes.forEach((i) => {
        let n = z(i.x), l = A(i.y);
        t.append("text").attr("x", n).attr("y", l).attr("text-anchor", "start").attr("font-size", 11).attr("fill", s.axisTextColor).attr("font-weight", "bold").text(i.text);
      });
    }
    if (y.accelerators.length > 0) {
      let t = S.append("g").attr("class", "wardley-accelerators");
      y.accelerators.forEach((i) => {
        let n = z(i.x), l = A(i.y), p = `
        M ${n} ${l - 30 / 2}
        L ${n + 60 - 20} ${l - 30 / 2}
        L ${n + 60 - 20} ${l - 30 / 2 - 8}
        L ${n + 60} ${l}
        L ${n + 60 - 20} ${l + 30 / 2 + 8}
        L ${n + 60 - 20} ${l + 30 / 2}
        L ${n} ${l + 30 / 2}
        Z
      `;
        t.append("path").attr("d", p).attr("fill", "white").attr("stroke", s.componentStroke).attr("stroke-width", 1), t.append("text").attr("x", n + 60 / 2).attr("y", l + 30 / 2 + 15).attr("text-anchor", "middle").attr("font-size", 10).attr("fill", s.axisTextColor).attr("font-weight", "bold").text(i.name);
      });
    }
    if (y.deaccelerators.length > 0) {
      let t = S.append("g").attr("class", "wardley-deaccelerators");
      y.deaccelerators.forEach((i) => {
        let n = z(i.x), l = A(i.y), p = `
        M ${n + 60} ${l - 30 / 2}
        L ${n + 20} ${l - 30 / 2}
        L ${n + 20} ${l - 30 / 2 - 8}
        L ${n} ${l}
        L ${n + 20} ${l + 30 / 2 + 8}
        L ${n + 20} ${l + 30 / 2}
        L ${n + 60} ${l + 30 / 2}
        Z
      `;
        t.append("path").attr("d", p).attr("fill", "white").attr("stroke", s.componentStroke).attr("stroke-width", 1), t.append("text").attr("x", n + 60 / 2).attr("y", l + 30 / 2 + 15).attr("text-anchor", "middle").attr("font-size", 10).attr("fill", s.axisTextColor).attr("font-weight", "bold").text(i.name);
      });
    }
  }, "draw") },
  styles: /* @__PURE__ */ g(({ wardley: r } = {}) => {
    let e = J(J(It(), Lt().themeVariables).wardley, r);
    return `
  .wardley-background {
    fill: ${e.backgroundColor};
  }
  .wardley-axes line, .wardley-axes path {
    stroke: ${e.axisColor};
  }
  .wardley-axis-label {
    fill: ${e.axisTextColor};
  }
  .wardley-stage-label {
    fill: ${e.axisTextColor};
  }
  .wardley-grid line {
    stroke: ${e.gridColor};
  }
  .wardley-node circle {
    fill: ${e.componentFill};
    stroke: ${e.componentStroke};
  }
  .wardley-node-label {
    fill: ${e.componentLabelColor};
  }
  .wardley-link {
    stroke: ${e.linkStroke};
  }
  .wardley-link--dashed {
    stroke-dasharray: 4 4;
  }
  .wardley-link-label {
    fill: ${e.axisTextColor};
  }
  .wardley-trend line {
    stroke: ${e.evolutionStroke};
  }
  .wardley-annotation-line {
    stroke: ${e.annotationStroke};
  }
  .wardley-annotation circle {
    fill: ${e.annotationFill};
    stroke: ${e.annotationStroke};
  }
  .wardley-annotation text {
    fill: ${e.annotationTextColor};
  }
  .wardley-annotations-box rect {
    fill: ${e.annotationFill};
    stroke: ${e.annotationStroke};
  }
  .wardley-annotations-box text {
    fill: ${e.annotationTextColor};
  }
  .wardley-pipeline-box {
    stroke: ${e.componentStroke};
  }
  .wardley-notes text {
    fill: ${e.axisTextColor};
  }
  `;
  }, "styles")
};
export {
  Zt as diagram
};
