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