@diagrammo/dgmo 0.2.7 → 0.2.8

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.
package/dist/index.cjs CHANGED
@@ -550,22 +550,19 @@ function parseSequenceDgmo(content) {
550
550
  const notePosition = noteSingleMatch[1]?.toLowerCase() || "right";
551
551
  let noteParticipant = noteSingleMatch[2] || null;
552
552
  if (!noteParticipant) {
553
- if (!lastMsgFrom) {
554
- result.error = `Line ${lineNumber}: note requires a preceding message`;
555
- return result;
556
- }
553
+ if (!lastMsgFrom) continue;
557
554
  noteParticipant = lastMsgFrom;
558
555
  }
559
556
  if (!result.participants.some((p) => p.id === noteParticipant)) {
560
- result.error = `Line ${lineNumber}: note references unknown participant '${noteParticipant}'`;
561
- return result;
557
+ continue;
562
558
  }
563
559
  const note = {
564
560
  kind: "note",
565
561
  text: noteSingleMatch[3].trim(),
566
562
  position: notePosition,
567
563
  participantId: noteParticipant,
568
- lineNumber
564
+ lineNumber,
565
+ endLineNumber: lineNumber
569
566
  };
570
567
  currentContainer().push(note);
571
568
  continue;
@@ -575,15 +572,11 @@ function parseSequenceDgmo(content) {
575
572
  const notePosition = noteMultiMatch[1]?.toLowerCase() || "right";
576
573
  let noteParticipant = noteMultiMatch[2] || null;
577
574
  if (!noteParticipant) {
578
- if (!lastMsgFrom) {
579
- result.error = `Line ${lineNumber}: note requires a preceding message`;
580
- return result;
581
- }
575
+ if (!lastMsgFrom) continue;
582
576
  noteParticipant = lastMsgFrom;
583
577
  }
584
578
  if (!result.participants.some((p) => p.id === noteParticipant)) {
585
- result.error = `Line ${lineNumber}: note references unknown participant '${noteParticipant}'`;
586
- return result;
579
+ continue;
587
580
  }
588
581
  const noteLines = [];
589
582
  while (i + 1 < lines.length) {
@@ -595,16 +588,15 @@ function parseSequenceDgmo(content) {
595
588
  noteLines.push(nextTrimmed);
596
589
  i++;
597
590
  }
598
- if (noteLines.length === 0) {
599
- result.error = `Line ${lineNumber}: multi-line note has no content \u2014 add indented lines or use 'note: text'`;
600
- return result;
601
- }
591
+ if (noteLines.length === 0) continue;
602
592
  const note = {
603
593
  kind: "note",
604
594
  text: noteLines.join("\n"),
605
595
  position: notePosition,
606
596
  participantId: noteParticipant,
607
- lineNumber
597
+ lineNumber,
598
+ endLineNumber: i + 1
599
+ // i has advanced past the body lines (1-based)
608
600
  };
609
601
  currentContainer().push(note);
610
602
  continue;
@@ -652,7 +644,7 @@ var init_parser = __esm({
652
644
  ARROW_RETURN_PATTERN = /^(.+?)\s*<-\s*(.+)$/;
653
645
  UML_RETURN_PATTERN = /^(\w+\([^)]*\))\s*:\s*(.+)$/;
654
646
  NOTE_SINGLE = /^note(?:\s+(right|left)\s+of\s+(\S+))?\s*:\s*(.+)$/i;
655
- NOTE_MULTI = /^note(?:\s+(right|left)\s+of\s+(\S+))?\s*$/i;
647
+ NOTE_MULTI = /^note(?:\s+(right|left)\s+of\s+([^\s:]+))?\s*:?\s*$/i;
656
648
  }
657
649
  });
658
650
 
@@ -2564,14 +2556,16 @@ __export(renderer_exports, {
2564
2556
  });
2565
2557
  function parseInlineMarkdown(text) {
2566
2558
  const spans = [];
2567
- const regex = /\*\*(.+?)\*\*|\*(.+?)\*|`(.+?)`|\[(.+?)\]\((.+?)\)|([^*`[]+)/g;
2559
+ const regex = /\*\*(.+?)\*\*|__(.+?)__|\*(.+?)\*|_(.+?)_|`(.+?)`|\[(.+?)\]\((.+?)\)|([^*_`[]+)/g;
2568
2560
  let match;
2569
2561
  while ((match = regex.exec(text)) !== null) {
2570
2562
  if (match[1]) spans.push({ text: match[1], bold: true });
2571
- else if (match[2]) spans.push({ text: match[2], italic: true });
2572
- else if (match[3]) spans.push({ text: match[3], code: true });
2573
- else if (match[4]) spans.push({ text: match[4], href: match[5] });
2574
- else if (match[6]) spans.push({ text: match[6] });
2563
+ else if (match[2]) spans.push({ text: match[2], bold: true });
2564
+ else if (match[3]) spans.push({ text: match[3], italic: true });
2565
+ else if (match[4]) spans.push({ text: match[4], italic: true });
2566
+ else if (match[5]) spans.push({ text: match[5], code: true });
2567
+ else if (match[6]) spans.push({ text: match[6], href: match[7] });
2568
+ else if (match[8]) spans.push({ text: match[8] });
2575
2569
  }
2576
2570
  return spans;
2577
2571
  }
@@ -2970,6 +2964,34 @@ function renderSequenceDiagram(container, parsed, palette, isDark, _onNavigateTo
2970
2964
  if (elements && elements.length > 0) {
2971
2965
  markBlockSpacing(elements);
2972
2966
  }
2967
+ const NOTE_OFFSET_BELOW = 16;
2968
+ const computeNoteHeight = (text) => {
2969
+ const lines = wrapTextLines(text, NOTE_CHARS_PER_LINE);
2970
+ return lines.length * NOTE_LINE_H + NOTE_PAD_V * 2;
2971
+ };
2972
+ const markNoteSpacing = (els) => {
2973
+ for (let i = 0; i < els.length; i++) {
2974
+ const el = els[i];
2975
+ if (isSequenceNote(el)) {
2976
+ const noteH = computeNoteHeight(el.text);
2977
+ const nextIdx = i + 1 < els.length ? findFirstMsgIndex([els[i + 1]]) : -1;
2978
+ if (nextIdx >= 0) {
2979
+ addExtra(nextIdx, noteH + NOTE_OFFSET_BELOW);
2980
+ }
2981
+ } else if (isSequenceBlock(el)) {
2982
+ markNoteSpacing(el.children);
2983
+ if (el.elseIfBranches) {
2984
+ for (const branch of el.elseIfBranches) {
2985
+ markNoteSpacing(branch.children);
2986
+ }
2987
+ }
2988
+ markNoteSpacing(el.elseChildren);
2989
+ }
2990
+ }
2991
+ };
2992
+ if (elements && elements.length > 0) {
2993
+ markNoteSpacing(elements);
2994
+ }
2973
2995
  const preSectionMsgIndices = [];
2974
2996
  const sectionRegions = [];
2975
2997
  {
@@ -3481,8 +3503,8 @@ function renderSequenceDiagram(container, parsed, palette, isDark, _onNavigateTo
3481
3503
  );
3482
3504
  const isRight = el.position === "right";
3483
3505
  const noteX = isRight ? px + ACTIVATION_WIDTH + NOTE_GAP : px - ACTIVATION_WIDTH - NOTE_GAP - noteW;
3484
- const noteTopY = noteY - noteH / 2;
3485
- const noteG = svg.append("g").attr("class", "note").attr("data-note-toggle", "").attr("data-line-number", String(el.lineNumber));
3506
+ const noteTopY = noteY + NOTE_OFFSET_BELOW;
3507
+ const noteG = svg.append("g").attr("class", "note").attr("data-note-toggle", "").attr("data-line-number", String(el.lineNumber)).attr("data-line-end", String(el.endLineNumber));
3486
3508
  noteG.append("path").attr(
3487
3509
  "d",
3488
3510
  [
@@ -3502,13 +3524,16 @@ function renderSequenceDiagram(container, parsed, palette, isDark, _onNavigateTo
3502
3524
  `L ${noteX + noteW} ${noteTopY + NOTE_FOLD}`
3503
3525
  ].join(" ")
3504
3526
  ).attr("fill", "none").attr("stroke", palette.textMuted).attr("stroke-width", 0.75).attr("class", "note-fold");
3505
- const connectorNoteX = isRight ? noteX : noteX + noteW;
3506
- const connectorLifeX = isRight ? px + ACTIVATION_WIDTH / 2 : px - ACTIVATION_WIDTH / 2;
3507
- noteG.append("line").attr("x1", connectorNoteX).attr("y1", noteY).attr("x2", connectorLifeX).attr("y2", noteY).attr("stroke", palette.textMuted).attr("stroke-width", 0.75).attr("stroke-dasharray", "3 2").attr("class", "note-connector");
3508
3527
  wrappedLines.forEach((line3, li) => {
3509
3528
  const textY = noteTopY + NOTE_PAD_V + (li + 1) * NOTE_LINE_H - 3;
3510
- const textEl = noteG.append("text").attr("x", noteX + NOTE_PAD_H).attr("y", textY).attr("fill", palette.text).attr("font-size", NOTE_FONT_SIZE).attr("class", "note-text");
3511
- const spans = parseInlineMarkdown(line3);
3529
+ const isBullet = line3.startsWith("- ");
3530
+ const bulletIndent = isBullet ? 10 : 0;
3531
+ const displayLine = isBullet ? line3.slice(2) : line3;
3532
+ const textEl = noteG.append("text").attr("x", noteX + NOTE_PAD_H + bulletIndent).attr("y", textY).attr("fill", palette.text).attr("font-size", NOTE_FONT_SIZE).attr("class", "note-text");
3533
+ if (isBullet) {
3534
+ noteG.append("text").attr("x", noteX + NOTE_PAD_H).attr("y", textY).attr("fill", palette.text).attr("font-size", NOTE_FONT_SIZE).text("\u2022");
3535
+ }
3536
+ const spans = parseInlineMarkdown(displayLine);
3512
3537
  for (const span of spans) {
3513
3538
  if (span.href) {
3514
3539
  const a = textEl.append("a").attr("href", span.href);