@zyro-sec/merman 1.0.2 → 1.0.3
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/package.json +2 -2
- package/script/layout-audit.ts +98 -98
- package/src/core/canvas.ts +228 -228
- package/src/core/color/style.ts +56 -56
- package/src/core/drawing.ts +301 -301
- package/src/core/geometry.ts +347 -347
- package/src/core/mermaid.ts +38 -38
- package/src/core/render-grid.ts +51 -51
- package/src/core/spatial.ts +243 -243
- package/src/core/text-lines.ts +32 -32
- package/src/core/text.ts +44 -44
- package/src/detect.ts +17 -17
- package/src/diagnostics.ts +16 -16
- package/src/flowchart/drawing.ts +340 -340
- package/src/flowchart/labels.ts +144 -144
- package/src/flowchart/layout.ts +1427 -1427
- package/src/flowchart/options.ts +12 -12
- package/src/flowchart/parser.ts +467 -467
- package/src/flowchart/render.ts +10 -10
- package/src/flowchart/routing.ts +1542 -1542
- package/src/flowchart/style.ts +79 -79
- package/src/flowchart/types.ts +65 -65
- package/src/gantt/diagram.ts +8 -8
- package/src/gantt/drawing.ts +191 -191
- package/src/gantt/parser.ts +161 -161
- package/src/gantt/render-grid.ts +17 -17
- package/src/gantt/style.ts +36 -36
- package/src/gantt/types.ts +44 -44
- package/src/gitgraph/diagram.ts +8 -8
- package/src/gitgraph/drawing.ts +234 -234
- package/src/gitgraph/parser.ts +219 -219
- package/src/gitgraph/render-grid.ts +17 -17
- package/src/gitgraph/style.ts +37 -37
- package/src/gitgraph/types.ts +36 -36
- package/src/markdown.ts +336 -336
- package/src/palette.ts +75 -75
- package/src/plugin.ts +15 -15
- package/src/sequence/diagram.ts +8 -8
- package/src/sequence/drawing.ts +287 -287
- package/src/sequence/options.ts +8 -8
- package/src/sequence/parser.ts +282 -282
- package/src/sequence/placement.ts +684 -684
- package/src/sequence/render-grid.ts +22 -22
- package/src/sequence/style.ts +81 -81
- package/src/sequence/types.ts +74 -74
- package/src/state/diagram.ts +8 -8
- package/src/state/drawing.ts +360 -360
- package/src/state/endpoint.ts +15 -15
- package/src/state/layout.ts +1134 -1134
- package/src/state/note.ts +59 -59
- package/src/state/options.ts +11 -11
- package/src/state/parser.ts +224 -224
- package/src/state/render-grid.ts +22 -22
- package/src/state/routing.ts +1522 -1522
- package/src/state/search.ts +103 -103
- package/src/state/style.ts +52 -52
- package/src/state/types.ts +63 -63
- package/src/state/visible-model.ts +77 -77
- package/src/test/diagram.ts +32 -32
- package/src/test/layout-audit/fixtures.ts +538 -538
- package/src/test/layout-audit/harness.ts +522 -522
- package/src/timeline/diagram.ts +8 -8
- package/src/timeline/drawing.ts +109 -109
- package/src/timeline/parser.ts +119 -119
- package/src/timeline/render-grid.ts +17 -17
- package/src/timeline/style.ts +36 -36
- package/src/timeline/types.ts +31 -31
- package/tsconfig.json +10 -10
- package/src/core/canvas.test.ts +0 -203
- package/src/core/color/style.test.ts +0 -24
- package/src/core/drawing.test.ts +0 -116
- package/src/core/geometry.test.ts +0 -112
- package/src/core/spatial.test.ts +0 -87
- package/src/core/text.test.ts +0 -33
- package/src/flowchart/flowchart.test.ts +0 -2800
- package/src/flowchart/labels.test.ts +0 -127
- package/src/flowchart/routing.test.ts +0 -368
- package/src/gantt/diagram.test.ts +0 -124
- package/src/gitgraph/diagram.test.ts +0 -183
- package/src/layout-audit.test.ts +0 -92
- package/src/palette.test.ts +0 -103
- package/src/sequence/diagram.test.ts +0 -757
- package/src/sequence/placement.test.ts +0 -219
- package/src/state/diagram.test.ts +0 -1386
- package/src/state/layout.test.ts +0 -314
- package/src/state/routing.test.ts +0 -693
- package/src/state/style.test.ts +0 -113
- package/src/state/visible-model.test.ts +0 -84
- package/src/test/diagnostics.test.ts +0 -129
- package/src/test/markdown.test.ts +0 -474
- package/src/timeline/diagram.test.ts +0 -188
|
@@ -1,219 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from "bun:test"
|
|
2
|
-
import { diagramTextWidth } from "../core/text.js"
|
|
3
|
-
import { parseMermaidSequenceDiagram } from "./parser.js"
|
|
4
|
-
import { createSequencePlacementPlan } from "./placement.js"
|
|
5
|
-
|
|
6
|
-
describe("createSequencePlacementPlan", () => {
|
|
7
|
-
test("expands one fragment frame for a longer else label", () => {
|
|
8
|
-
const plan = createSequencePlacementPlan(
|
|
9
|
-
parseMermaidSequenceDiagram(`sequenceDiagram
|
|
10
|
-
A->>B: start
|
|
11
|
-
alt ok
|
|
12
|
-
A->>B: yes
|
|
13
|
-
else validation failed with a substantially longer explanation
|
|
14
|
-
B-->>A: no
|
|
15
|
-
end`),
|
|
16
|
-
)
|
|
17
|
-
const fragments = plan.steps.filter((step) => step.type === "fragment")
|
|
18
|
-
|
|
19
|
-
expect(fragments).toHaveLength(3)
|
|
20
|
-
expect(fragments.map((fragment) => fragment.bounds.rightX)).toEqual([
|
|
21
|
-
fragments[0]!.bounds.rightX,
|
|
22
|
-
fragments[0]!.bounds.rightX,
|
|
23
|
-
fragments[0]!.bounds.rightX,
|
|
24
|
-
])
|
|
25
|
-
expect(fragments[1]!.labelText).toContain("validation failed")
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
test("includes non-adjacent message and note labels within planned width", () => {
|
|
29
|
-
const plan = createSequencePlacementPlan(
|
|
30
|
-
parseMermaidSequenceDiagram(`sequenceDiagram
|
|
31
|
-
participant A
|
|
32
|
-
participant B
|
|
33
|
-
participant C
|
|
34
|
-
A->>C: this message needs room past the final participant
|
|
35
|
-
Note over A,C: this note also needs full horizontal room`),
|
|
36
|
-
)
|
|
37
|
-
const message = plan.steps.find((step) => step.type === "message")!
|
|
38
|
-
const note = plan.steps.find((step) => step.type === "note")!
|
|
39
|
-
|
|
40
|
-
const messageWidth = Math.max(...message.labelLines.map(diagramTextWidth))
|
|
41
|
-
expect(message.labelX + messageWidth).toBeLessThanOrEqual(plan.width)
|
|
42
|
-
expect(note.textX + Math.max(...note.textLines.map(diagramTextWidth))).toBeLessThanOrEqual(plan.width)
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
test("keeps side notes clear of adjacent participant lifelines", () => {
|
|
46
|
-
const plan = createSequencePlacementPlan(
|
|
47
|
-
parseMermaidSequenceDiagram(`sequenceDiagram
|
|
48
|
-
participant A
|
|
49
|
-
participant B
|
|
50
|
-
participant C
|
|
51
|
-
Note right of A: a long note between the first two participants
|
|
52
|
-
Note left of C: another long note between the final participants`),
|
|
53
|
-
)
|
|
54
|
-
const notes = plan.steps.filter((step) => step.type === "note")
|
|
55
|
-
|
|
56
|
-
expect(notes[0]!.textX + Math.max(...notes[0]!.textLines.map(diagramTextWidth))).toBeLessThan(
|
|
57
|
-
plan.participants[1]!.centerX,
|
|
58
|
-
)
|
|
59
|
-
expect(notes[1]!.textX).toBeGreaterThan(plan.participants[1]!.centerX)
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
test("allocates group space around a contained self-message loop", () => {
|
|
63
|
-
const plan = createSequencePlacementPlan(
|
|
64
|
-
parseMermaidSequenceDiagram(`sequenceDiagram
|
|
65
|
-
box Backend
|
|
66
|
-
participant Service
|
|
67
|
-
Service->>Service: Check Permissions
|
|
68
|
-
end`),
|
|
69
|
-
)
|
|
70
|
-
const group = plan.groups[0]!
|
|
71
|
-
const message = plan.steps.find((step) => step.type === "selfMessage")!
|
|
72
|
-
|
|
73
|
-
expect(group.leftX).toBeGreaterThanOrEqual(0)
|
|
74
|
-
expect(group.rightX).toBeGreaterThanOrEqual(message.rightX + 2)
|
|
75
|
-
expect(plan.width).toBeGreaterThan(group.rightX)
|
|
76
|
-
})
|
|
77
|
-
|
|
78
|
-
test("keeps external participants outside a group expanded by internal content", () => {
|
|
79
|
-
const plan = createSequencePlacementPlan(
|
|
80
|
-
parseMermaidSequenceDiagram(`sequenceDiagram
|
|
81
|
-
box G
|
|
82
|
-
participant A
|
|
83
|
-
end
|
|
84
|
-
participant B as External
|
|
85
|
-
A->>A: this self-loop extends underneath the external participant header`),
|
|
86
|
-
)
|
|
87
|
-
const group = plan.groups[0]!
|
|
88
|
-
const external = plan.participants.find((participant) => participant.participant.id === "B")!
|
|
89
|
-
|
|
90
|
-
expect(external.headerLeftX).toBeGreaterThan(group.rightX)
|
|
91
|
-
})
|
|
92
|
-
|
|
93
|
-
test("keeps many adjacent wide groups at a linear width", () => {
|
|
94
|
-
const groupCount = 16
|
|
95
|
-
const source = `sequenceDiagram
|
|
96
|
-
${Array.from(
|
|
97
|
-
{ length: groupCount },
|
|
98
|
-
(_, index) => ` box Group ${index} has a deliberately wide heading
|
|
99
|
-
participant P${index}
|
|
100
|
-
end`,
|
|
101
|
-
).join("\n")}
|
|
102
|
-
P0->>P15: hi`
|
|
103
|
-
const plan = createSequencePlacementPlan(parseMermaidSequenceDiagram(source), { compact: true })
|
|
104
|
-
|
|
105
|
-
expect(plan.groups).toHaveLength(groupCount)
|
|
106
|
-
for (let index = 1; index < plan.groups.length; index++) {
|
|
107
|
-
expect(plan.groups[index]!.leftX).toBeGreaterThan(plan.groups[index - 1]!.rightX)
|
|
108
|
-
}
|
|
109
|
-
expect(plan.width).toBeLessThan(groupCount * 60)
|
|
110
|
-
})
|
|
111
|
-
|
|
112
|
-
test("expands group and fragment frames around contained long content", () => {
|
|
113
|
-
const groupPlan = createSequencePlacementPlan(
|
|
114
|
-
parseMermaidSequenceDiagram(`sequenceDiagram
|
|
115
|
-
box Services
|
|
116
|
-
participant A
|
|
117
|
-
participant B
|
|
118
|
-
participant C
|
|
119
|
-
A->>C: this message text runs far outside of the group container boundary
|
|
120
|
-
end`),
|
|
121
|
-
)
|
|
122
|
-
const group = groupPlan.groups[0]!
|
|
123
|
-
const groupedMessage = groupPlan.steps.find((step) => step.type === "message")!
|
|
124
|
-
const groupedMessageRight = groupedMessage.labelX + Math.max(...groupedMessage.labelLines.map(diagramTextWidth)) - 1
|
|
125
|
-
|
|
126
|
-
expect(group.rightX).toBeGreaterThan(groupedMessageRight)
|
|
127
|
-
|
|
128
|
-
const fragmentPlan = createSequencePlacementPlan(
|
|
129
|
-
parseMermaidSequenceDiagram(`sequenceDiagram
|
|
130
|
-
participant A
|
|
131
|
-
participant B
|
|
132
|
-
participant C
|
|
133
|
-
alt lookup
|
|
134
|
-
A->>C: this non adjacent message is deliberately much wider than the frame
|
|
135
|
-
end`),
|
|
136
|
-
)
|
|
137
|
-
const fragment = fragmentPlan.steps
|
|
138
|
-
.filter((step) => step.type === "fragment")
|
|
139
|
-
.find((step) => step.fragment.kind === "alt")!
|
|
140
|
-
const fragmentMessage = fragmentPlan.steps.find((step) => step.type === "message")!
|
|
141
|
-
const fragmentMessageRight =
|
|
142
|
-
fragmentMessage.labelX + Math.max(...fragmentMessage.labelLines.map(diagramTextWidth)) - 1
|
|
143
|
-
|
|
144
|
-
expect(fragment.bounds.rightX).toBeGreaterThan(fragmentMessageRight)
|
|
145
|
-
})
|
|
146
|
-
|
|
147
|
-
test("sizes multiline notes and their group and fragment bounds for every br spelling", () => {
|
|
148
|
-
const plan = createSequencePlacementPlan(
|
|
149
|
-
parseMermaidSequenceDiagram(`sequenceDiagram
|
|
150
|
-
box Tools
|
|
151
|
-
participant Tool
|
|
152
|
-
alt retry
|
|
153
|
-
Note over Tool: directory instead?<br/>the WrongKind error carries the answer —<br/>branch to list, no extra round trip
|
|
154
|
-
Note over Tool: first<br>second<br />third
|
|
155
|
-
end
|
|
156
|
-
end`),
|
|
157
|
-
)
|
|
158
|
-
const notes = plan.steps.filter((step) => step.type === "note")
|
|
159
|
-
const fragment = plan.steps.filter((step) => step.type === "fragment").find((step) => step.fragment.kind === "alt")!
|
|
160
|
-
const group = plan.groups[0]!
|
|
161
|
-
const firstNoteWidth = Math.max(...notes[0]!.textLines.map(diagramTextWidth))
|
|
162
|
-
|
|
163
|
-
expect(notes[0]!.textLines.map((line) => line.trim())).toEqual([
|
|
164
|
-
"directory instead?",
|
|
165
|
-
"the WrongKind error carries the answer —",
|
|
166
|
-
"branch to list, no extra round trip",
|
|
167
|
-
])
|
|
168
|
-
expect(notes[1]!.textLines.map((line) => line.trim())).toEqual(["first", "second", "third"])
|
|
169
|
-
expect(fragment.bounds.rightX).toBeGreaterThan(notes[0]!.textX + firstNoteWidth - 1)
|
|
170
|
-
expect(group.rightX).toBeGreaterThan(notes[0]!.textX + firstNoteWidth - 1)
|
|
171
|
-
expect(plan.height).toBeGreaterThan(notes[1]!.textY + notes[1]!.textLines.length)
|
|
172
|
-
})
|
|
173
|
-
|
|
174
|
-
test("preserves nesting inset when a child fragment has a wide heading", () => {
|
|
175
|
-
const plan = createSequencePlacementPlan(
|
|
176
|
-
parseMermaidSequenceDiagram(`sequenceDiagram
|
|
177
|
-
participant A
|
|
178
|
-
participant B
|
|
179
|
-
alt outer
|
|
180
|
-
loop inner heading wider than outer frame and participant span
|
|
181
|
-
A->>B: x
|
|
182
|
-
end
|
|
183
|
-
end`),
|
|
184
|
-
)
|
|
185
|
-
const starts = plan.steps
|
|
186
|
-
.filter((step) => step.type === "fragment")
|
|
187
|
-
.filter((step) => step.fragment.kind === "alt" || step.fragment.kind === "loop")
|
|
188
|
-
|
|
189
|
-
expect(starts[0]!.bounds.rightX).toBeGreaterThan(starts[1]!.bounds.rightX)
|
|
190
|
-
})
|
|
191
|
-
|
|
192
|
-
test("aligns explicit and shorthand activation intervals to message events", () => {
|
|
193
|
-
const shorthand = createSequencePlacementPlan(
|
|
194
|
-
parseMermaidSequenceDiagram(`sequenceDiagram
|
|
195
|
-
A->>+B: request
|
|
196
|
-
B-->>-A: response`),
|
|
197
|
-
)
|
|
198
|
-
const explicit = createSequencePlacementPlan(
|
|
199
|
-
parseMermaidSequenceDiagram(`sequenceDiagram
|
|
200
|
-
A->>B: request
|
|
201
|
-
activate B
|
|
202
|
-
B-->>A: response
|
|
203
|
-
deactivate B`),
|
|
204
|
-
)
|
|
205
|
-
|
|
206
|
-
expect(explicit.activations).toEqual(shorthand.activations)
|
|
207
|
-
})
|
|
208
|
-
|
|
209
|
-
test("left-aligns message label blocks inside their arrow span", () => {
|
|
210
|
-
const plan = createSequencePlacementPlan(
|
|
211
|
-
parseMermaidSequenceDiagram(`sequenceDiagram
|
|
212
|
-
participant A
|
|
213
|
-
participant B
|
|
214
|
-
A->>B: short<br/>a much longer line`),
|
|
215
|
-
)
|
|
216
|
-
const message = plan.steps.find((step) => step.type === "message")!
|
|
217
|
-
expect(message.labelX).toBe(message.leftX + 2)
|
|
218
|
-
})
|
|
219
|
-
})
|