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

//# sourceMappingURL=wardleyDiagram-NUSXRM2D.js.map