@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
package/src/state/layout.test.ts
DELETED
|
@@ -1,314 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from "bun:test"
|
|
2
|
-
import { spatialPathClaim } from "../core/spatial.js"
|
|
3
|
-
import { diagramTextWidth } from "../core/text.js"
|
|
4
|
-
import type { StateDiagram } from "./types.js"
|
|
5
|
-
import { createStateDiagramLayout, expandCompositeBoundsForInternalTransitions } from "./layout.js"
|
|
6
|
-
import { stateDiagramNoteConnector } from "./note.js"
|
|
7
|
-
import { parseMermaidStateDiagram } from "./parser.js"
|
|
8
|
-
import { createStateTransitionRenderPlans } from "./routing.js"
|
|
9
|
-
import { prepareVisibleStateDiagram } from "./visible-model.js"
|
|
10
|
-
|
|
11
|
-
describe("StateDiagramLayout", () => {
|
|
12
|
-
test("lays out horizontal main-path states before branch states", () => {
|
|
13
|
-
const diagram: StateDiagram = {
|
|
14
|
-
direction: "LR",
|
|
15
|
-
states: [
|
|
16
|
-
{ id: "A", label: "A", kind: "state" },
|
|
17
|
-
{ id: "B", label: "B", kind: "state" },
|
|
18
|
-
{ id: "C", label: "C", kind: "state" },
|
|
19
|
-
],
|
|
20
|
-
transitions: [
|
|
21
|
-
{ from: "A", to: "B", label: "main" },
|
|
22
|
-
{ from: "A", to: "C", label: "branch" },
|
|
23
|
-
],
|
|
24
|
-
composites: [],
|
|
25
|
-
notes: [],
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const layout = createStateDiagramLayout(diagram, { minStateGap: 5 })
|
|
29
|
-
const a = layout.bounds.get("A")!
|
|
30
|
-
const b = layout.bounds.get("B")!
|
|
31
|
-
const c = layout.bounds.get("C")!
|
|
32
|
-
|
|
33
|
-
expect(a.left).toBeLessThan(b.left)
|
|
34
|
-
expect(c.top).toBeGreaterThan(a.top)
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
test("aligns a reconverging side branch under the parallel main-path stage", () => {
|
|
38
|
-
const diagram: StateDiagram = {
|
|
39
|
-
direction: "LR",
|
|
40
|
-
states: ["Fork", "Upper", "Lower", "Join"].map((id) => ({ id, label: id, kind: "state" })),
|
|
41
|
-
transitions: [
|
|
42
|
-
{ from: "Fork", to: "Upper", label: "upper" },
|
|
43
|
-
{ from: "Fork", to: "Lower", label: "lower" },
|
|
44
|
-
{ from: "Upper", to: "Join", label: "join" },
|
|
45
|
-
{ from: "Lower", to: "Join", label: "join" },
|
|
46
|
-
],
|
|
47
|
-
composites: [],
|
|
48
|
-
notes: [],
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const layout = createStateDiagramLayout(diagram, { minStateGap: 5 })
|
|
52
|
-
const upper = layout.bounds.get("Upper")!
|
|
53
|
-
const lower = layout.bounds.get("Lower")!
|
|
54
|
-
|
|
55
|
-
expect(lower.centerX).toBe(upper.centerX)
|
|
56
|
-
expect(lower.top).toBeGreaterThan(upper.top)
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
test("places note bounds outside their target state", () => {
|
|
60
|
-
const diagram: StateDiagram = {
|
|
61
|
-
direction: "LR",
|
|
62
|
-
states: [
|
|
63
|
-
{ id: "A", label: "A", kind: "state" },
|
|
64
|
-
{ id: "B", label: "B", kind: "state" },
|
|
65
|
-
],
|
|
66
|
-
transitions: [{ from: "A", to: "B", label: "next" }],
|
|
67
|
-
composites: [],
|
|
68
|
-
notes: [{ target: "A", position: "right", lines: ["note"] }],
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const layout = createStateDiagramLayout(diagram, { minStateGap: 5 })
|
|
72
|
-
const target = layout.bounds.get("A")!
|
|
73
|
-
const note = layout.noteBounds[0]!
|
|
74
|
-
|
|
75
|
-
expect(note.left).toBeGreaterThanOrEqual(target.left + target.width)
|
|
76
|
-
expect(note.lines).toEqual(["note"])
|
|
77
|
-
})
|
|
78
|
-
|
|
79
|
-
test("widens only the horizontal gap that carries a long label", () => {
|
|
80
|
-
const diagram: StateDiagram = {
|
|
81
|
-
direction: "LR",
|
|
82
|
-
states: [
|
|
83
|
-
{ id: "A", label: "A", kind: "state" },
|
|
84
|
-
{ id: "B", label: "B", kind: "state" },
|
|
85
|
-
{ id: "C", label: "C", kind: "state" },
|
|
86
|
-
],
|
|
87
|
-
transitions: [
|
|
88
|
-
{ from: "A", to: "B", label: "a transition label requiring substantially more room" },
|
|
89
|
-
{ from: "B", to: "C", label: "ok" },
|
|
90
|
-
],
|
|
91
|
-
composites: [],
|
|
92
|
-
notes: [],
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
const layout = createStateDiagramLayout(diagram, { minStateGap: 5 })
|
|
96
|
-
const a = layout.bounds.get("A")!
|
|
97
|
-
const b = layout.bounds.get("B")!
|
|
98
|
-
const c = layout.bounds.get("C")!
|
|
99
|
-
const longGap = b.left - (a.left + a.width)
|
|
100
|
-
const shortGap = c.left - (b.left + b.width)
|
|
101
|
-
|
|
102
|
-
expect(longGap).toBeGreaterThan(shortGap)
|
|
103
|
-
})
|
|
104
|
-
|
|
105
|
-
test("reserves notes and connectors from final transition geometry", () => {
|
|
106
|
-
const diagram = prepareVisibleStateDiagram(
|
|
107
|
-
parseMermaidStateDiagram(`stateDiagram-v2
|
|
108
|
-
direction LR
|
|
109
|
-
A --> B: advance
|
|
110
|
-
B --> C: continue
|
|
111
|
-
note right of B: first note
|
|
112
|
-
note right of B: second note
|
|
113
|
-
note left of C: left note`),
|
|
114
|
-
)
|
|
115
|
-
const layout = createStateDiagramLayout(diagram, { minStateGap: 5 })
|
|
116
|
-
const plans = createStateTransitionRenderPlans(diagram, layout.bounds, 30, { noteBounds: layout.noteBounds })
|
|
117
|
-
const occupiedByNote = layout.noteBounds.map((noteBound) => {
|
|
118
|
-
const target = layout.bounds.get(noteBound.note.target)!
|
|
119
|
-
const connector = spatialPathClaim(
|
|
120
|
-
`connector:${noteBound.id}`,
|
|
121
|
-
`connector:${noteBound.id}`,
|
|
122
|
-
"boundary",
|
|
123
|
-
stateDiagramNoteConnector(noteBound, target).points,
|
|
124
|
-
)
|
|
125
|
-
return new Set([
|
|
126
|
-
...Array.from({ length: noteBound.height }, (_, dy) =>
|
|
127
|
-
Array.from({ length: noteBound.width }, (_, dx) => `${noteBound.left + dx}:${noteBound.top + dy}`),
|
|
128
|
-
).flat(),
|
|
129
|
-
...connector.spans.flatMap((span) =>
|
|
130
|
-
Array.from({ length: span.toX - span.fromX + 1 }, (_, dx) => `${span.fromX + dx}:${span.y}`),
|
|
131
|
-
),
|
|
132
|
-
])
|
|
133
|
-
})
|
|
134
|
-
|
|
135
|
-
for (const [index, occupied] of occupiedByNote.entries()) {
|
|
136
|
-
for (const other of occupiedByNote.slice(index + 1)) {
|
|
137
|
-
expect([...occupied].some((cell) => other.has(cell))).toBe(false)
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
const noteCells = new Set(occupiedByNote.flatMap((occupied) => [...occupied]))
|
|
141
|
-
for (const plan of plans) {
|
|
142
|
-
expect(plan.path.some(([x, y]) => noteCells.has(`${x}:${y}`))).toBe(false)
|
|
143
|
-
if (!plan.label) continue
|
|
144
|
-
const width = Math.max(...plan.label.lines.map(diagramTextWidth))
|
|
145
|
-
expect(
|
|
146
|
-
plan.label.lines.some((_, dy) =>
|
|
147
|
-
Array.from({ length: width }, (_, dx) => `${plan.label!.x + dx}:${plan.label!.y + dy}`).some((cell) =>
|
|
148
|
-
noteCells.has(cell),
|
|
149
|
-
),
|
|
150
|
-
),
|
|
151
|
-
).toBe(false)
|
|
152
|
-
}
|
|
153
|
-
})
|
|
154
|
-
|
|
155
|
-
test("finalizes nested composite bounds after transition-aware note placement", () => {
|
|
156
|
-
const diagram = prepareVisibleStateDiagram(
|
|
157
|
-
parseMermaidStateDiagram(`stateDiagram-v2
|
|
158
|
-
direction LR
|
|
159
|
-
state Outer {
|
|
160
|
-
state Inner {
|
|
161
|
-
A --> B: internal route
|
|
162
|
-
note right of B: nested note
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
Outer --> Done: leave composite`),
|
|
166
|
-
)
|
|
167
|
-
const layout = createStateDiagramLayout(diagram, { minStateGap: 5 })
|
|
168
|
-
const note = layout.noteBounds[0]!
|
|
169
|
-
const inner = layout.compositeBounds.get("Inner")!
|
|
170
|
-
const outer = layout.compositeBounds.get("Outer")!
|
|
171
|
-
const done = layout.bounds.get("Done")!
|
|
172
|
-
|
|
173
|
-
for (const composite of [inner, outer]) {
|
|
174
|
-
expect(note.left).toBeGreaterThan(composite.left)
|
|
175
|
-
expect(note.top).toBeGreaterThan(composite.top)
|
|
176
|
-
expect(note.left + note.width).toBeLessThan(composite.left + composite.width)
|
|
177
|
-
expect(note.top + note.height).toBeLessThan(composite.top + composite.height)
|
|
178
|
-
}
|
|
179
|
-
expect(
|
|
180
|
-
done.left < outer.left + outer.width &&
|
|
181
|
-
done.left + done.width > outer.left &&
|
|
182
|
-
done.top < outer.top + outer.height &&
|
|
183
|
-
done.top + done.height > outer.top,
|
|
184
|
-
).toBe(false)
|
|
185
|
-
|
|
186
|
-
const maxY = Math.max(...[...layout.bounds.values(), note].map((bound) => bound.top + bound.height))
|
|
187
|
-
const plans = createStateTransitionRenderPlans(diagram, layout.bounds, maxY + 3, { noteBounds: layout.noteBounds })
|
|
188
|
-
const noteCells = new Set(
|
|
189
|
-
Array.from({ length: note.height }, (_, dy) =>
|
|
190
|
-
Array.from({ length: note.width }, (_, dx) => `${note.left + dx}:${note.top + dy}`),
|
|
191
|
-
).flat(),
|
|
192
|
-
)
|
|
193
|
-
expect(plans.every((plan) => plan.path.every(([x, y]) => !noteCells.has(`${x}:${y}`)))).toBe(true)
|
|
194
|
-
})
|
|
195
|
-
|
|
196
|
-
test.each([
|
|
197
|
-
["LR", -1],
|
|
198
|
-
["RL", 1],
|
|
199
|
-
] as const)("keeps a reciprocal pair on the %s axis", (direction, expectedSign) => {
|
|
200
|
-
const diagram = prepareVisibleStateDiagram(
|
|
201
|
-
parseMermaidStateDiagram(`stateDiagram-v2
|
|
202
|
-
direction ${direction}
|
|
203
|
-
A --> B: forward
|
|
204
|
-
B --> A: backward`),
|
|
205
|
-
)
|
|
206
|
-
const layout = createStateDiagramLayout(diagram, { minStateGap: 5 })
|
|
207
|
-
const a = layout.bounds.get("A")!
|
|
208
|
-
const b = layout.bounds.get("B")!
|
|
209
|
-
|
|
210
|
-
expect(a.centerY).toBe(b.centerY)
|
|
211
|
-
expect(Math.sign(a.centerX - b.centerX)).toBe(expectedSign)
|
|
212
|
-
})
|
|
213
|
-
|
|
214
|
-
test("continues the horizontal backbone through a reciprocal pair after an entry marker", () => {
|
|
215
|
-
const diagram = prepareVisibleStateDiagram(
|
|
216
|
-
parseMermaidStateDiagram(`stateDiagram-v2
|
|
217
|
-
direction LR
|
|
218
|
-
[*] --> Clean
|
|
219
|
-
Clean --> Dirty: edit
|
|
220
|
-
Dirty --> Clean: save
|
|
221
|
-
Dirty --> Closing: request close
|
|
222
|
-
Closing --> [*]: closed`),
|
|
223
|
-
)
|
|
224
|
-
const layout = createStateDiagramLayout(diagram, { minStateGap: 5 })
|
|
225
|
-
const clean = layout.bounds.get("Clean")!
|
|
226
|
-
const dirty = layout.bounds.get("Dirty")!
|
|
227
|
-
const closing = layout.bounds.get("Closing")!
|
|
228
|
-
|
|
229
|
-
expect(clean.centerY).toBe(dirty.centerY)
|
|
230
|
-
expect(dirty.centerY).toBe(closing.centerY)
|
|
231
|
-
expect(clean.centerX).toBeLessThan(dirty.centerX)
|
|
232
|
-
expect(dirty.centerX).toBeLessThan(closing.centerX)
|
|
233
|
-
})
|
|
234
|
-
|
|
235
|
-
test("does not reserve an unused right-side lane for aligned nested composite transitions", () => {
|
|
236
|
-
const diagram = prepareVisibleStateDiagram(
|
|
237
|
-
parseMermaidStateDiagram(`stateDiagram-v2
|
|
238
|
-
direction TB
|
|
239
|
-
state Session {
|
|
240
|
-
[*] --> Open
|
|
241
|
-
state Open {
|
|
242
|
-
[*] --> Clean
|
|
243
|
-
Clean --> Dirty: edit
|
|
244
|
-
Dirty --> Clean: save
|
|
245
|
-
Dirty --> [*]
|
|
246
|
-
}
|
|
247
|
-
Open --> Closing: request close
|
|
248
|
-
Closing --> Open: cancel
|
|
249
|
-
Closing --> [*]: closed
|
|
250
|
-
note right of Dirty: unsaved changes
|
|
251
|
-
}
|
|
252
|
-
[*] --> Session: hydrate
|
|
253
|
-
Session --> [*]: release`),
|
|
254
|
-
)
|
|
255
|
-
const layout = createStateDiagramLayout(diagram, { minStateGap: 5 })
|
|
256
|
-
const open = layout.compositeBounds.get("Open")!
|
|
257
|
-
const session = layout.compositeBounds.get("Session")!
|
|
258
|
-
|
|
259
|
-
expect(session.width).toBeLessThanOrEqual(open.width + 4)
|
|
260
|
-
})
|
|
261
|
-
|
|
262
|
-
test.each(["TB", "TD"] as const)(
|
|
263
|
-
"contains nested internal feedback with strict margins in %s diagrams",
|
|
264
|
-
(direction) => {
|
|
265
|
-
const diagram = prepareVisibleStateDiagram(
|
|
266
|
-
parseMermaidStateDiagram(`stateDiagram-v2
|
|
267
|
-
direction ${direction}
|
|
268
|
-
state Outer {
|
|
269
|
-
state Inner {
|
|
270
|
-
A --> B: down
|
|
271
|
-
B --> A: up
|
|
272
|
-
note right of B: nested note
|
|
273
|
-
}
|
|
274
|
-
}`),
|
|
275
|
-
)
|
|
276
|
-
const layout = createStateDiagramLayout(diagram, { minStateGap: 5 })
|
|
277
|
-
const plans = createStateTransitionRenderPlans(diagram, layout.bounds, 30, { noteBounds: layout.noteBounds })
|
|
278
|
-
expandCompositeBoundsForInternalTransitions(diagram, layout.compositeBounds, plans)
|
|
279
|
-
const inner = layout.compositeBounds.get("Inner")!
|
|
280
|
-
const outer = layout.compositeBounds.get("Outer")!
|
|
281
|
-
const note = layout.noteBounds[0]!
|
|
282
|
-
|
|
283
|
-
for (const composite of [inner, outer]) {
|
|
284
|
-
for (const plan of plans) {
|
|
285
|
-
expect(
|
|
286
|
-
plan.path.every(
|
|
287
|
-
([x, y]) =>
|
|
288
|
-
x > composite.left &&
|
|
289
|
-
x < composite.left + composite.width - 1 &&
|
|
290
|
-
y > composite.top &&
|
|
291
|
-
y < composite.top + composite.height - 1,
|
|
292
|
-
),
|
|
293
|
-
).toBe(true)
|
|
294
|
-
}
|
|
295
|
-
expect(
|
|
296
|
-
note.connector!.points.every(
|
|
297
|
-
(point) =>
|
|
298
|
-
point.x > composite.left &&
|
|
299
|
-
point.x < composite.left + composite.width - 1 &&
|
|
300
|
-
point.y > composite.top &&
|
|
301
|
-
point.y < composite.top + composite.height - 1,
|
|
302
|
-
),
|
|
303
|
-
).toBe(true)
|
|
304
|
-
}
|
|
305
|
-
expect(new Set(note.connector!.points.map((point) => point.y))).toEqual(
|
|
306
|
-
new Set([layout.bounds.get("B")!.centerY]),
|
|
307
|
-
)
|
|
308
|
-
expect(inner.left - outer.left).toBeGreaterThanOrEqual(2)
|
|
309
|
-
expect(inner.top - outer.top).toBeGreaterThanOrEqual(2)
|
|
310
|
-
expect(outer.left + outer.width - (inner.left + inner.width)).toBeGreaterThanOrEqual(2)
|
|
311
|
-
expect(outer.top + outer.height - (inner.top + inner.height)).toBeGreaterThanOrEqual(2)
|
|
312
|
-
},
|
|
313
|
-
)
|
|
314
|
-
})
|