@zenuml/core 4.0.0 → 4.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2738,7 +2738,7 @@ class sequenceParser extends antlr4.Parser {
2738
2738
 
2739
2739
 
2740
2740
  returnAsyncMessage() {
2741
- let localctx = new ReturnAsyncMessageContext$2(this, this._ctx, this.state);
2741
+ let localctx = new ReturnAsyncMessageContext$3(this, this._ctx, this.state);
2742
2742
  this.enterRule(localctx, 30, sequenceParser.RULE_returnAsyncMessage);
2743
2743
  var _la = 0; // Token type
2744
2744
  try {
@@ -5800,7 +5800,7 @@ let RetContext$3 = class RetContext extends antlr4.ParserRuleContext {
5800
5800
  };
5801
5801
 
5802
5802
  returnAsyncMessage() {
5803
- return this.getTypedRuleContext(ReturnAsyncMessageContext$2,0);
5803
+ return this.getTypedRuleContext(ReturnAsyncMessageContext$3,0);
5804
5804
  };
5805
5805
 
5806
5806
  enterRule(listener) {
@@ -5820,7 +5820,7 @@ let RetContext$3 = class RetContext extends antlr4.ParserRuleContext {
5820
5820
 
5821
5821
 
5822
5822
 
5823
- let ReturnAsyncMessageContext$2 = class ReturnAsyncMessageContext extends antlr4.ParserRuleContext {
5823
+ let ReturnAsyncMessageContext$3 = class ReturnAsyncMessageContext extends antlr4.ParserRuleContext {
5824
5824
 
5825
5825
  constructor(parser, parent, invokingState) {
5826
5826
  if(parent===undefined) {
@@ -8714,7 +8714,7 @@ sequenceParser.WidthContext = WidthContext;
8714
8714
  sequenceParser.EmojiContext = EmojiContext;
8715
8715
  sequenceParser.BlockContext = BlockContext;
8716
8716
  sequenceParser.RetContext = RetContext$3;
8717
- sequenceParser.ReturnAsyncMessageContext = ReturnAsyncMessageContext$2;
8717
+ sequenceParser.ReturnAsyncMessageContext = ReturnAsyncMessageContext$3;
8718
8718
  sequenceParser.DividerContext = DividerContext$1;
8719
8719
  sequenceParser.DividerNoteContext = DividerNoteContext;
8720
8720
  sequenceParser.StatContext = StatContext$3;
@@ -8779,6 +8779,10 @@ const blankParticipant = {
8779
8779
  };
8780
8780
  let Participant$1 = class Participant {
8781
8781
  name;
8782
+ // Fields the renderer-facing ParticipantView (ir/contract.ts) exposes are
8783
+ // public; they were already fully exposed via ToValue(), so the previous
8784
+ // `private` was inconsistent encapsulation. `width` stays private — it is not
8785
+ // part of ParticipantView.
8782
8786
  stereotype;
8783
8787
  width;
8784
8788
  groupId;
@@ -9204,7 +9208,7 @@ const seqParser$7 = sequenceParser;
9204
9208
  const CreationContext$6 = seqParser$7.CreationContext;
9205
9209
  const MessageContext$6 = seqParser$7.MessageContext;
9206
9210
  const AsyncMessageContext$2 = seqParser$7.AsyncMessageContext;
9207
- const ReturnAsyncMessageContext$1 = seqParser$7.ReturnAsyncMessageContext;
9211
+ const ReturnAsyncMessageContext$2 = seqParser$7.ReturnAsyncMessageContext;
9208
9212
  const RetMessageContext = seqParser$7.RetContext;
9209
9213
 
9210
9214
  CreationContext$6.prototype.Assignee = function () {
@@ -9264,12 +9268,12 @@ AsyncMessageContext$2.prototype.Owner = function () {
9264
9268
  return this.To() || getOwnerFromAncestor(this.parentCtx);
9265
9269
  };
9266
9270
 
9267
- ReturnAsyncMessageContext$1.prototype.To = function () {
9271
+ ReturnAsyncMessageContext$2.prototype.To = function () {
9268
9272
  const toCtx = this.to();
9269
9273
  return toCtx?.name?.()?.getFormattedText() || toCtx?.getFormattedText();
9270
9274
  };
9271
9275
 
9272
- ReturnAsyncMessageContext$1.prototype.Owner = function () {
9276
+ ReturnAsyncMessageContext$2.prototype.Owner = function () {
9273
9277
  return this.To() || getOwnerFromAncestor(this.parentCtx);
9274
9278
  };
9275
9279
 
@@ -9386,13 +9390,13 @@ RefContext.prototype.Participants = function() {
9386
9390
  return this.name().slice(1) ?? [];
9387
9391
  };
9388
9392
 
9389
- const ParserRuleContext = antlr4.ParserRuleContext;
9393
+ const ParserRuleContext$1 = antlr4.ParserRuleContext;
9390
9394
  const StatContext$2 = sequenceParser.StatContext;
9391
9395
  const ProgContext = sequenceParser.ProgContext;
9392
9396
  const MessageContext$4 = sequenceParser.MessageContext;
9393
9397
  const CreationContext$4 = sequenceParser.CreationContext;
9394
9398
 
9395
- ParserRuleContext.prototype.Origin = function () {
9399
+ ParserRuleContext$1.prototype.Origin = function () {
9396
9400
  let ctx = this.parentCtx;
9397
9401
  while (ctx && !(ctx instanceof StatContext$2 || ctx instanceof ProgContext)) {
9398
9402
  ctx = this.parentCtx;
@@ -9438,8 +9442,8 @@ function formatParameter(param) {
9438
9442
  if (param.namedParameter?.()) {
9439
9443
  const namedParam = param.namedParameter();
9440
9444
  if (namedParam) {
9441
- const expr = namedParam.expr();
9442
- const value = expr ? expr.getFormattedText() : "";
9445
+ const expr2 = namedParam.expr();
9446
+ const value = expr2 ? expr2.getFormattedText() : "";
9443
9447
  return `${namedParam.ID().getText()}=${value}`;
9444
9448
  }
9445
9449
  }
@@ -9449,8 +9453,9 @@ function formatParameter(param) {
9449
9453
  return `${decl.type().getText()} ${decl.ID().getText()}`;
9450
9454
  }
9451
9455
  }
9452
- if (param.expr?.()) {
9453
- return param.expr().getFormattedText();
9456
+ const expr = param.expr?.();
9457
+ if (expr) {
9458
+ return expr.getFormattedText();
9454
9459
  }
9455
9460
  return param.getFormattedText();
9456
9461
  }
@@ -9462,6 +9467,7 @@ const ParametersContext = sequenceParser.ParametersContext;
9462
9467
  const AsyncMessageContext$1 = sequenceParser.AsyncMessageContext;
9463
9468
  const CreationContext$3 = sequenceParser.CreationContext;
9464
9469
  const RetContext$1 = sequenceParser.RetContext;
9470
+ const ReturnAsyncMessageContext$1 = sequenceParser.ReturnAsyncMessageContext;
9465
9471
  MessageContext$3.prototype.SignatureText = function() {
9466
9472
  return this.messageBody()?.func()?.signature()?.map((s) => s?.getFormattedText()).join(".") ?? "";
9467
9473
  };
@@ -9482,7 +9488,7 @@ CreationContext$3.prototype.isParamValid = function() {
9482
9488
  RetContext$1.prototype.SignatureText = function() {
9483
9489
  return this.asyncMessage()?.content()?.getFormattedText() ?? this.returnAsyncMessage()?.content()?.getFormattedText() ?? this.expr()?.getFormattedText() ?? "";
9484
9490
  };
9485
- sequenceParser.ReturnAsyncMessageContext.prototype.SignatureText = function() {
9491
+ ReturnAsyncMessageContext$1.prototype.SignatureText = function() {
9486
9492
  return this.content()?.getFormattedText() ?? "";
9487
9493
  };
9488
9494
  ParametersContext.prototype.getFormattedText = function() {
@@ -9557,46 +9563,47 @@ LoopContext.prototype.Statements = function() {
9557
9563
  };
9558
9564
 
9559
9565
  const seqParser$1 = sequenceParser;
9560
- const CreationContext = seqParser$1.CreationContext;
9561
9566
  const StatContext$1 = seqParser$1.StatContext;
9567
+ const CreationContext = seqParser$1.CreationContext;
9562
9568
  const MessageContext = seqParser$1.MessageContext;
9563
9569
  const AsyncMessageContext = seqParser$1.AsyncMessageContext;
9564
9570
  const ReturnAsyncMessageContext = seqParser$1.ReturnAsyncMessageContext;
9565
9571
  const RetContext = seqParser$1.RetContext;
9566
9572
  CreationContext.prototype.From = function() {
9567
9573
  if (this.parentCtx instanceof StatContext$1) {
9568
- return this.ClosestAncestorStat().Origin();
9574
+ return this.ClosestAncestorStat()?.Origin();
9569
9575
  }
9570
9576
  return void 0;
9571
9577
  };
9572
9578
  MessageContext.prototype.ProvidedFrom = function() {
9573
- const fromCtx = this.messageBody()?.fromTo()?.from();
9574
- return fromCtx?.name?.()?.getFormattedText() || fromCtx?.getFormattedText();
9579
+ const fromCtx = this.messageBody()?.fromTo?.()?.from?.();
9580
+ return fromCtx?.name?.()?.getFormattedText?.() || fromCtx?.getFormattedText?.();
9575
9581
  };
9576
9582
  MessageContext.prototype.From = function() {
9577
- return this.ProvidedFrom() || this.ClosestAncestorStat().Origin();
9583
+ return this.ProvidedFrom() || this.ClosestAncestorStat()?.Origin();
9578
9584
  };
9579
9585
  AsyncMessageContext.prototype.ProvidedFrom = function() {
9580
9586
  const fromCtx = this.from();
9581
- return fromCtx?.name?.()?.getFormattedText() || fromCtx?.getFormattedText();
9587
+ return fromCtx?.name?.()?.getFormattedText?.() || fromCtx?.getFormattedText?.();
9582
9588
  };
9583
9589
  AsyncMessageContext.prototype.From = function() {
9584
- return this.ProvidedFrom() || this.ClosestAncestorStat().Origin();
9590
+ return this.ProvidedFrom() || this.ClosestAncestorStat()?.Origin();
9585
9591
  };
9586
9592
  ReturnAsyncMessageContext.prototype.ProvidedFrom = function() {
9587
9593
  const fromCtx = this.from();
9588
- return fromCtx?.name?.()?.getFormattedText() || fromCtx?.getFormattedText();
9594
+ return fromCtx?.name?.()?.getFormattedText?.() || fromCtx?.getFormattedText?.();
9589
9595
  };
9590
9596
  ReturnAsyncMessageContext.prototype.From = function() {
9591
- return this.ProvidedFrom() || this.ClosestAncestorStat().Origin();
9597
+ return this.ProvidedFrom() || this.ClosestAncestorStat()?.Origin();
9592
9598
  };
9593
9599
  RetContext.prototype.From = function() {
9594
- return this.asyncMessage()?.From() || this.returnAsyncMessage()?.From() || this.ClosestAncestorStat().Origin();
9600
+ return this.asyncMessage()?.From?.() || this.returnAsyncMessage()?.From?.() || this.ClosestAncestorStat()?.Origin();
9595
9601
  };
9596
9602
 
9597
9603
  const seqParser = sequenceParser;
9598
9604
  const StatContext = seqParser.StatContext;
9599
- antlr4.ParserRuleContext.prototype.ClosestAncestorStat = function() {
9605
+ const ParserRuleContext = antlr4.ParserRuleContext;
9606
+ ParserRuleContext.prototype.ClosestAncestorStat = function() {
9600
9607
  if (this instanceof StatContext) {
9601
9608
  return this;
9602
9609
  }
@@ -9609,7 +9616,7 @@ antlr4.ParserRuleContext.prototype.ClosestAncestorStat = function() {
9609
9616
  }
9610
9617
  return void 0;
9611
9618
  };
9612
- antlr4.ParserRuleContext.prototype.ClosestAncestorBlock = function() {
9619
+ ParserRuleContext.prototype.ClosestAncestorBlock = function() {
9613
9620
  const parentCtx = this.ClosestAncestorStat()?.parentCtx;
9614
9621
  if (parentCtx instanceof seqParser.BlockContext) {
9615
9622
  return parentCtx;
@@ -9648,6 +9655,21 @@ class SeqErrorListener extends antlr4.error.ErrorListener {
9648
9655
  }
9649
9656
  }
9650
9657
 
9658
+ // Reentrant error listener: collects syntax errors into its OWN instance array
9659
+ // instead of the shared module-level `errors`/`errorDetails`. This is what lets
9660
+ // validate()/parse() below run repeatedly or concurrently (e.g. server-side)
9661
+ // without the clear-before/clear-after dance the legacy globals require.
9662
+ class CollectingErrorListener extends antlr4.error.ErrorListener {
9663
+ constructor() {
9664
+ super();
9665
+ /** @type {{ line: number, column: number, msg: string }[]} */
9666
+ this.errorDetails = [];
9667
+ }
9668
+ syntaxError(recognizer, offendingSymbol, line, column, msg) {
9669
+ this.errorDetails.push({ line, column, msg });
9670
+ }
9671
+ }
9672
+
9651
9673
  function createParser(code, { silent = false } = {}) {
9652
9674
  const chars = new antlr4.InputStream(code);
9653
9675
  const lexer = new sequenceLexer(chars);
@@ -9722,6 +9744,43 @@ antlr4.ParserRuleContext.prototype.getComment = function () {
9722
9744
  );
9723
9745
  };
9724
9746
 
9747
+ /**
9748
+ * Parse ZenUML DSL with a per-call (reentrant) error listener and return both
9749
+ * the error-recovered parse tree and a structured error list. Safe to call
9750
+ * repeatedly/concurrently — it does not touch the module-level Errors/ErrorDetails.
9751
+ *
9752
+ * @param {string} code ZenUML DSL source
9753
+ * @returns {{ rootContext: object, pass: boolean, errorDetails: { line: number, column: number, msg: string }[] }}
9754
+ */
9755
+ function parse(code) {
9756
+ const listener = new CollectingErrorListener();
9757
+ const chars = new antlr4.InputStream(code);
9758
+ const lexer = new sequenceLexer(chars);
9759
+ lexer.removeErrorListeners();
9760
+ lexer.addErrorListener(listener);
9761
+ const tokens = new antlr4.CommonTokenStream(lexer);
9762
+ const parser = new sequenceParser(tokens);
9763
+ parser.removeErrorListeners();
9764
+ parser.addErrorListener(listener);
9765
+ const tree = parser.prog();
9766
+ return {
9767
+ rootContext: tree,
9768
+ pass: listener.errorDetails.length === 0,
9769
+ errorDetails: listener.errorDetails,
9770
+ };
9771
+ }
9772
+
9773
+ /**
9774
+ * Validate ZenUML DSL syntax without exposing the parse tree. Reentrant.
9775
+ *
9776
+ * @param {string} code ZenUML DSL source
9777
+ * @returns {{ pass: boolean, errorDetails: { line: number, column: number, msg: string }[] }}
9778
+ */
9779
+ function validate(code) {
9780
+ const { pass, errorDetails } = parse(code);
9781
+ return { pass, errorDetails };
9782
+ }
9783
+
9725
9784
  sequenceParser.ProgContext;
9726
9785
  const RootContext = rootContext;
9727
9786
  sequenceParser.GroupContext;
@@ -9740,6 +9799,8 @@ const Parser = {
9740
9799
  const toCollector = ToCollector;
9741
9800
  return toCollector.getParticipants(ctx);
9742
9801
  },
9802
+ parse,
9803
+ validate,
9743
9804
  Errors: errors,
9744
9805
  ErrorDetails: errorDetails,
9745
9806
  /**
@@ -9866,33 +9927,31 @@ function OrderedParticipants(rootContext) {
9866
9927
  const cached = orderedParticipantsCache.get(rootContext);
9867
9928
  if (cached) return cached;
9868
9929
  const participants = ToCollector.getParticipants(rootContext);
9869
- const participantEntries = Array.from(participants.participants.entries());
9930
+ const participantEntries = participants.Array().map((p) => p.ToValue());
9870
9931
  const allMessages = AllMessages(rootContext);
9871
9932
  const emptyContext = allMessages.length === 0 && participantEntries.length === 0;
9872
9933
  const someMessagesMissFrom = allMessages.some((m) => !m.from);
9873
9934
  const needDefaultStarter = emptyContext || someMessagesMissFrom;
9874
9935
  if (needDefaultStarter) {
9875
- participantEntries.unshift([
9876
- _STARTER_,
9877
- { ...blankParticipant, name: _STARTER_, isStarter: true }
9878
- ]);
9879
- }
9880
- const result = participantEntries.map(
9881
- (entry, index, entries) => {
9882
- const participant = entry[1];
9883
- const previousName = index > 0 ? entries[index - 1][1].name : "";
9884
- return new Participant(
9885
- participant.name,
9886
- previousName,
9887
- participant.label,
9888
- participant.type,
9889
- participant.stereotype,
9890
- participant.color,
9891
- participant.groupId,
9892
- participant.emoji
9893
- );
9894
- }
9895
- );
9936
+ participantEntries.unshift({
9937
+ ...blankParticipant,
9938
+ name: _STARTER_,
9939
+ isStarter: true
9940
+ });
9941
+ }
9942
+ const result = participantEntries.map((participant, index, entries) => {
9943
+ const previousName = index > 0 ? entries[index - 1].name : "";
9944
+ return new Participant(
9945
+ participant.name,
9946
+ previousName,
9947
+ participant.label,
9948
+ participant.type,
9949
+ participant.stereotype,
9950
+ participant.color,
9951
+ participant.groupId,
9952
+ participant.emoji
9953
+ );
9954
+ });
9896
9955
  orderedParticipantsCache.set(rootContext, result);
9897
9956
  return result;
9898
9957
  }
@@ -9991,7 +10050,7 @@ function longestPathTable(graph, gaps) {
9991
10050
  }
9992
10051
  return [tracker.delta, table];
9993
10052
  }
9994
- function freezeCriticalGaps(table, graph, gaps) {
10053
+ function freezeCriticalGaps(table, gaps) {
9995
10054
  let j = table.length - 1;
9996
10055
  while (j > 0) {
9997
10056
  const argument = table[j].argument;
@@ -10028,7 +10087,7 @@ function find_optimal(matrix) {
10028
10087
  return positionsFromTable(table);
10029
10088
  }
10030
10089
  if (table[n - 1].maximum.velocity > 0) {
10031
- freezeCriticalGaps(table, graph, gaps);
10090
+ freezeCriticalGaps(table, gaps);
10032
10091
  } else {
10033
10092
  advanceGaps(gaps, delta);
10034
10093
  }
@@ -11466,7 +11525,7 @@ function snapX(x) {
11466
11525
  return x;
11467
11526
  }
11468
11527
  const COMMENT_FONT_ASCENT = 15;
11469
- function buildFragmentGeometry(info, coord, coordinates, verticalCoordinates, allParticipants, measureText, commentHeight = 0, commentText, commentStyle, commentYBase) {
11528
+ function buildFragmentGeometry(info, coord, coordinates, verticalCoordinates, allParticipants, _measureText, commentHeight = 0, commentText, commentStyle, commentYBase) {
11470
11529
  const statNode = info.statNode;
11471
11530
  if (!statNode) return null;
11472
11531
  const fragmentCtx = findFragmentContext(statNode);