import { StateField as p } from "@codemirror/state";
import { parser as c } from "../grammar/zenuml-parser.js";
const f = p.define({
  create(t) {
    const e = t.doc.toString(), n = c.parse(e);
    return s(e, n);
  },
  update(t, e) {
    if (e.docChanged) {
      const n = e.state.doc.toString(), i = c.parse(n), a = s(n, i);
      if (!d(t, a))
        return a;
    }
    return t;
  }
});
function l(t) {
  return t.field(f);
}
function s(t, e) {
  const n = /* @__PURE__ */ new Set();
  return e.cursor().iterate((i) => {
    if (i.type.name === "Participant") {
      let r = i.node.lastChild;
      for (; r; ) {
        if (r.type.name === "Name" || r.type.name === "Identifier") {
          const o = t.slice(r.from, r.to).trim();
          o && n.add(o);
          break;
        }
        r = r.prevSibling;
      }
    }
  }), n;
}
function d(t, e) {
  if (t.size !== e.size)
    return !1;
  for (const n of t)
    if (!e.has(n))
      return !1;
  return !0;
}
export {
  l as getParticipants,
  f as zenumlParticipantStateField
};
//# sourceMappingURL=zenuml-participant-manager.js.map
