@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/cli.cjs +87 -87
- package/dist/index.cjs +56 -31
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +56 -31
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/sequence/parser.ts +9 -17
- package/src/sequence/renderer.ts +58 -26
package/dist/index.d.cts
CHANGED
|
@@ -546,6 +546,7 @@ interface SequenceNote {
|
|
|
546
546
|
position: 'right' | 'left';
|
|
547
547
|
participantId: string;
|
|
548
548
|
lineNumber: number;
|
|
549
|
+
endLineNumber: number;
|
|
549
550
|
}
|
|
550
551
|
type SequenceElement = SequenceMessage | SequenceBlock | SequenceSection | SequenceNote;
|
|
551
552
|
declare function isSequenceBlock(el: SequenceElement): el is SequenceBlock;
|
package/dist/index.d.ts
CHANGED
|
@@ -546,6 +546,7 @@ interface SequenceNote {
|
|
|
546
546
|
position: 'right' | 'left';
|
|
547
547
|
participantId: string;
|
|
548
548
|
lineNumber: number;
|
|
549
|
+
endLineNumber: number;
|
|
549
550
|
}
|
|
550
551
|
type SequenceElement = SequenceMessage | SequenceBlock | SequenceSection | SequenceNote;
|
|
551
552
|
declare function isSequenceBlock(el: SequenceElement): el is SequenceBlock;
|
package/dist/index.js
CHANGED
|
@@ -528,22 +528,19 @@ function parseSequenceDgmo(content) {
|
|
|
528
528
|
const notePosition = noteSingleMatch[1]?.toLowerCase() || "right";
|
|
529
529
|
let noteParticipant = noteSingleMatch[2] || null;
|
|
530
530
|
if (!noteParticipant) {
|
|
531
|
-
if (!lastMsgFrom)
|
|
532
|
-
result.error = `Line ${lineNumber}: note requires a preceding message`;
|
|
533
|
-
return result;
|
|
534
|
-
}
|
|
531
|
+
if (!lastMsgFrom) continue;
|
|
535
532
|
noteParticipant = lastMsgFrom;
|
|
536
533
|
}
|
|
537
534
|
if (!result.participants.some((p) => p.id === noteParticipant)) {
|
|
538
|
-
|
|
539
|
-
return result;
|
|
535
|
+
continue;
|
|
540
536
|
}
|
|
541
537
|
const note = {
|
|
542
538
|
kind: "note",
|
|
543
539
|
text: noteSingleMatch[3].trim(),
|
|
544
540
|
position: notePosition,
|
|
545
541
|
participantId: noteParticipant,
|
|
546
|
-
lineNumber
|
|
542
|
+
lineNumber,
|
|
543
|
+
endLineNumber: lineNumber
|
|
547
544
|
};
|
|
548
545
|
currentContainer().push(note);
|
|
549
546
|
continue;
|
|
@@ -553,15 +550,11 @@ function parseSequenceDgmo(content) {
|
|
|
553
550
|
const notePosition = noteMultiMatch[1]?.toLowerCase() || "right";
|
|
554
551
|
let noteParticipant = noteMultiMatch[2] || null;
|
|
555
552
|
if (!noteParticipant) {
|
|
556
|
-
if (!lastMsgFrom)
|
|
557
|
-
result.error = `Line ${lineNumber}: note requires a preceding message`;
|
|
558
|
-
return result;
|
|
559
|
-
}
|
|
553
|
+
if (!lastMsgFrom) continue;
|
|
560
554
|
noteParticipant = lastMsgFrom;
|
|
561
555
|
}
|
|
562
556
|
if (!result.participants.some((p) => p.id === noteParticipant)) {
|
|
563
|
-
|
|
564
|
-
return result;
|
|
557
|
+
continue;
|
|
565
558
|
}
|
|
566
559
|
const noteLines = [];
|
|
567
560
|
while (i + 1 < lines.length) {
|
|
@@ -573,16 +566,15 @@ function parseSequenceDgmo(content) {
|
|
|
573
566
|
noteLines.push(nextTrimmed);
|
|
574
567
|
i++;
|
|
575
568
|
}
|
|
576
|
-
if (noteLines.length === 0)
|
|
577
|
-
result.error = `Line ${lineNumber}: multi-line note has no content \u2014 add indented lines or use 'note: text'`;
|
|
578
|
-
return result;
|
|
579
|
-
}
|
|
569
|
+
if (noteLines.length === 0) continue;
|
|
580
570
|
const note = {
|
|
581
571
|
kind: "note",
|
|
582
572
|
text: noteLines.join("\n"),
|
|
583
573
|
position: notePosition,
|
|
584
574
|
participantId: noteParticipant,
|
|
585
|
-
lineNumber
|
|
575
|
+
lineNumber,
|
|
576
|
+
endLineNumber: i + 1
|
|
577
|
+
// i has advanced past the body lines (1-based)
|
|
586
578
|
};
|
|
587
579
|
currentContainer().push(note);
|
|
588
580
|
continue;
|
|
@@ -630,7 +622,7 @@ var init_parser = __esm({
|
|
|
630
622
|
ARROW_RETURN_PATTERN = /^(.+?)\s*<-\s*(.+)$/;
|
|
631
623
|
UML_RETURN_PATTERN = /^(\w+\([^)]*\))\s*:\s*(.+)$/;
|
|
632
624
|
NOTE_SINGLE = /^note(?:\s+(right|left)\s+of\s+(\S+))?\s*:\s*(.+)$/i;
|
|
633
|
-
NOTE_MULTI = /^note(?:\s+(right|left)\s+of\s+(
|
|
625
|
+
NOTE_MULTI = /^note(?:\s+(right|left)\s+of\s+([^\s:]+))?\s*:?\s*$/i;
|
|
634
626
|
}
|
|
635
627
|
});
|
|
636
628
|
|
|
@@ -2543,14 +2535,16 @@ __export(renderer_exports, {
|
|
|
2543
2535
|
import * as d3Selection2 from "d3-selection";
|
|
2544
2536
|
function parseInlineMarkdown(text) {
|
|
2545
2537
|
const spans = [];
|
|
2546
|
-
const regex = /\*\*(.+?)
|
|
2538
|
+
const regex = /\*\*(.+?)\*\*|__(.+?)__|\*(.+?)\*|_(.+?)_|`(.+?)`|\[(.+?)\]\((.+?)\)|([^*_`[]+)/g;
|
|
2547
2539
|
let match;
|
|
2548
2540
|
while ((match = regex.exec(text)) !== null) {
|
|
2549
2541
|
if (match[1]) spans.push({ text: match[1], bold: true });
|
|
2550
|
-
else if (match[2]) spans.push({ text: match[2],
|
|
2551
|
-
else if (match[3]) spans.push({ text: match[3],
|
|
2552
|
-
else if (match[4]) spans.push({ text: match[4],
|
|
2553
|
-
else if (match[
|
|
2542
|
+
else if (match[2]) spans.push({ text: match[2], bold: true });
|
|
2543
|
+
else if (match[3]) spans.push({ text: match[3], italic: true });
|
|
2544
|
+
else if (match[4]) spans.push({ text: match[4], italic: true });
|
|
2545
|
+
else if (match[5]) spans.push({ text: match[5], code: true });
|
|
2546
|
+
else if (match[6]) spans.push({ text: match[6], href: match[7] });
|
|
2547
|
+
else if (match[8]) spans.push({ text: match[8] });
|
|
2554
2548
|
}
|
|
2555
2549
|
return spans;
|
|
2556
2550
|
}
|
|
@@ -2949,6 +2943,34 @@ function renderSequenceDiagram(container, parsed, palette, isDark, _onNavigateTo
|
|
|
2949
2943
|
if (elements && elements.length > 0) {
|
|
2950
2944
|
markBlockSpacing(elements);
|
|
2951
2945
|
}
|
|
2946
|
+
const NOTE_OFFSET_BELOW = 16;
|
|
2947
|
+
const computeNoteHeight = (text) => {
|
|
2948
|
+
const lines = wrapTextLines(text, NOTE_CHARS_PER_LINE);
|
|
2949
|
+
return lines.length * NOTE_LINE_H + NOTE_PAD_V * 2;
|
|
2950
|
+
};
|
|
2951
|
+
const markNoteSpacing = (els) => {
|
|
2952
|
+
for (let i = 0; i < els.length; i++) {
|
|
2953
|
+
const el = els[i];
|
|
2954
|
+
if (isSequenceNote(el)) {
|
|
2955
|
+
const noteH = computeNoteHeight(el.text);
|
|
2956
|
+
const nextIdx = i + 1 < els.length ? findFirstMsgIndex([els[i + 1]]) : -1;
|
|
2957
|
+
if (nextIdx >= 0) {
|
|
2958
|
+
addExtra(nextIdx, noteH + NOTE_OFFSET_BELOW);
|
|
2959
|
+
}
|
|
2960
|
+
} else if (isSequenceBlock(el)) {
|
|
2961
|
+
markNoteSpacing(el.children);
|
|
2962
|
+
if (el.elseIfBranches) {
|
|
2963
|
+
for (const branch of el.elseIfBranches) {
|
|
2964
|
+
markNoteSpacing(branch.children);
|
|
2965
|
+
}
|
|
2966
|
+
}
|
|
2967
|
+
markNoteSpacing(el.elseChildren);
|
|
2968
|
+
}
|
|
2969
|
+
}
|
|
2970
|
+
};
|
|
2971
|
+
if (elements && elements.length > 0) {
|
|
2972
|
+
markNoteSpacing(elements);
|
|
2973
|
+
}
|
|
2952
2974
|
const preSectionMsgIndices = [];
|
|
2953
2975
|
const sectionRegions = [];
|
|
2954
2976
|
{
|
|
@@ -3460,8 +3482,8 @@ function renderSequenceDiagram(container, parsed, palette, isDark, _onNavigateTo
|
|
|
3460
3482
|
);
|
|
3461
3483
|
const isRight = el.position === "right";
|
|
3462
3484
|
const noteX = isRight ? px + ACTIVATION_WIDTH + NOTE_GAP : px - ACTIVATION_WIDTH - NOTE_GAP - noteW;
|
|
3463
|
-
const noteTopY = noteY
|
|
3464
|
-
const noteG = svg.append("g").attr("class", "note").attr("data-note-toggle", "").attr("data-line-number", String(el.lineNumber));
|
|
3485
|
+
const noteTopY = noteY + NOTE_OFFSET_BELOW;
|
|
3486
|
+
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));
|
|
3465
3487
|
noteG.append("path").attr(
|
|
3466
3488
|
"d",
|
|
3467
3489
|
[
|
|
@@ -3481,13 +3503,16 @@ function renderSequenceDiagram(container, parsed, palette, isDark, _onNavigateTo
|
|
|
3481
3503
|
`L ${noteX + noteW} ${noteTopY + NOTE_FOLD}`
|
|
3482
3504
|
].join(" ")
|
|
3483
3505
|
).attr("fill", "none").attr("stroke", palette.textMuted).attr("stroke-width", 0.75).attr("class", "note-fold");
|
|
3484
|
-
const connectorNoteX = isRight ? noteX : noteX + noteW;
|
|
3485
|
-
const connectorLifeX = isRight ? px + ACTIVATION_WIDTH / 2 : px - ACTIVATION_WIDTH / 2;
|
|
3486
|
-
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");
|
|
3487
3506
|
wrappedLines.forEach((line3, li) => {
|
|
3488
3507
|
const textY = noteTopY + NOTE_PAD_V + (li + 1) * NOTE_LINE_H - 3;
|
|
3489
|
-
const
|
|
3490
|
-
const
|
|
3508
|
+
const isBullet = line3.startsWith("- ");
|
|
3509
|
+
const bulletIndent = isBullet ? 10 : 0;
|
|
3510
|
+
const displayLine = isBullet ? line3.slice(2) : line3;
|
|
3511
|
+
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");
|
|
3512
|
+
if (isBullet) {
|
|
3513
|
+
noteG.append("text").attr("x", noteX + NOTE_PAD_H).attr("y", textY).attr("fill", palette.text).attr("font-size", NOTE_FONT_SIZE).text("\u2022");
|
|
3514
|
+
}
|
|
3515
|
+
const spans = parseInlineMarkdown(displayLine);
|
|
3491
3516
|
for (const span of spans) {
|
|
3492
3517
|
if (span.href) {
|
|
3493
3518
|
const a = textEl.append("a").attr("href", span.href);
|