@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,474 +0,0 @@
|
|
|
1
|
-
import { afterAll, afterEach, beforeAll, expect, test } from "bun:test"
|
|
2
|
-
import { mkdir } from "node:fs/promises"
|
|
3
|
-
import { tmpdir } from "node:os"
|
|
4
|
-
import { join } from "node:path"
|
|
5
|
-
import { CodeRenderable, MarkdownRenderable, RGBA, SyntaxStyle, TextRenderable, TreeSitterClient } from "@opentui/core"
|
|
6
|
-
import { createTestRenderer } from "@opentui/core/testing"
|
|
7
|
-
import { createMermaidMarkdownRenderer } from "../markdown.js"
|
|
8
|
-
|
|
9
|
-
let syntaxStyle: SyntaxStyle
|
|
10
|
-
let treeSitterClient: TreeSitterClient
|
|
11
|
-
let renderer: Awaited<ReturnType<typeof createTestRenderer>>["renderer"]
|
|
12
|
-
|
|
13
|
-
beforeAll(async () => {
|
|
14
|
-
const dataPath = join(tmpdir(), "mermaid-markdown-test-data")
|
|
15
|
-
await mkdir(dataPath, { recursive: true })
|
|
16
|
-
treeSitterClient = new TreeSitterClient({ dataPath })
|
|
17
|
-
await treeSitterClient.initialize()
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
afterAll(async () => {
|
|
21
|
-
await treeSitterClient.destroy()
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
afterEach(async () => {
|
|
25
|
-
renderer?.destroy()
|
|
26
|
-
await renderer?.closed
|
|
27
|
-
syntaxStyle?.destroy()
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
async function setup(options: Parameters<typeof createTestRenderer>[0]) {
|
|
31
|
-
const output = await createTestRenderer(options)
|
|
32
|
-
renderer = output.renderer
|
|
33
|
-
syntaxStyle = SyntaxStyle.fromStyles({ default: { fg: RGBA.fromValues(1, 1, 1, 1) } }, renderer.nativeScene)
|
|
34
|
-
return output
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
async function renderMarkdown(
|
|
38
|
-
markdown: MarkdownRenderable,
|
|
39
|
-
renderOnce: () => Promise<void>,
|
|
40
|
-
timeoutMs = 2_000,
|
|
41
|
-
): Promise<void> {
|
|
42
|
-
const hasPendingHighlights = (): boolean => {
|
|
43
|
-
const children = [...markdown.getChildren()]
|
|
44
|
-
while (children.length > 0) {
|
|
45
|
-
const child = children.pop()!
|
|
46
|
-
if (child instanceof CodeRenderable && child.isHighlighting) return true
|
|
47
|
-
children.push(...child.getChildren())
|
|
48
|
-
}
|
|
49
|
-
return false
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const startedAt = Date.now()
|
|
53
|
-
await renderOnce()
|
|
54
|
-
while (hasPendingHighlights() && Date.now() - startedAt < timeoutMs) {
|
|
55
|
-
await Bun.sleep(10)
|
|
56
|
-
await renderOnce()
|
|
57
|
-
}
|
|
58
|
-
if (hasPendingHighlights()) throw new Error("Timed out waiting for Markdown highlights")
|
|
59
|
-
await renderOnce()
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
test("renders a Mermaid flowchart fence inside MarkdownRenderable", async () => {
|
|
63
|
-
const testRenderer = await setup({ width: 80, height: 14 })
|
|
64
|
-
const { renderOnce, captureCharFrame } = testRenderer
|
|
65
|
-
const markdown = new MarkdownRenderable(renderer, {
|
|
66
|
-
id: "markdown-mermaid",
|
|
67
|
-
content: `\`\`\`mermaid
|
|
68
|
-
flowchart LR
|
|
69
|
-
A[Start] --> B[Done]
|
|
70
|
-
\`\`\``,
|
|
71
|
-
syntaxStyle,
|
|
72
|
-
treeSitterClient,
|
|
73
|
-
renderBlock: createMermaidMarkdownRenderer(renderer),
|
|
74
|
-
})
|
|
75
|
-
|
|
76
|
-
renderer.root.add(markdown)
|
|
77
|
-
await renderMarkdown(markdown, renderOnce)
|
|
78
|
-
|
|
79
|
-
const frame = captureCharFrame()
|
|
80
|
-
expect(frame).toContain("Start")
|
|
81
|
-
expect(frame).toContain("Done")
|
|
82
|
-
expect(frame).not.toContain("flowchart LR")
|
|
83
|
-
expect(markdown.getChildren()[0]?.marginTop).toBe(1)
|
|
84
|
-
})
|
|
85
|
-
|
|
86
|
-
test("uses compact terminal spacing for Mermaid diagrams by default", async () => {
|
|
87
|
-
const testRenderer = await setup({ width: 80, height: 40 })
|
|
88
|
-
const markdown = new MarkdownRenderable(renderer, {
|
|
89
|
-
id: "markdown-compact-mermaid",
|
|
90
|
-
content: `\`\`\`mermaid
|
|
91
|
-
flowchart TD
|
|
92
|
-
repo[Organization profile repo] --> build[Build]
|
|
93
|
-
build --> worker[Isolated organization Worker]
|
|
94
|
-
worker --> sessions[SessionDOs]
|
|
95
|
-
sessions --> opencode[OpenCode + native plugins]
|
|
96
|
-
opencode --> modal[Modal workspaces]
|
|
97
|
-
\`\`\``,
|
|
98
|
-
syntaxStyle,
|
|
99
|
-
renderBlock: createMermaidMarkdownRenderer(renderer),
|
|
100
|
-
})
|
|
101
|
-
|
|
102
|
-
renderer.root.add(markdown)
|
|
103
|
-
await renderMarkdown(markdown, testRenderer.renderOnce)
|
|
104
|
-
|
|
105
|
-
expect(markdown.getChildren()[0]?.height).toBe(28)
|
|
106
|
-
})
|
|
107
|
-
|
|
108
|
-
test("recognizes normalized Mermaid fence info strings", async () => {
|
|
109
|
-
const testRenderer = await setup({ width: 80, height: 14 })
|
|
110
|
-
const { renderOnce, captureCharFrame } = testRenderer
|
|
111
|
-
const markdown = new MarkdownRenderable(renderer, {
|
|
112
|
-
id: "markdown-normalized-mermaid",
|
|
113
|
-
content: `\`\`\`MERMAID title=checkout
|
|
114
|
-
flowchart LR
|
|
115
|
-
A[Start] --> B[Done]
|
|
116
|
-
\`\`\``,
|
|
117
|
-
syntaxStyle,
|
|
118
|
-
treeSitterClient,
|
|
119
|
-
renderBlock: createMermaidMarkdownRenderer(renderer),
|
|
120
|
-
})
|
|
121
|
-
|
|
122
|
-
renderer.root.add(markdown)
|
|
123
|
-
await renderMarkdown(markdown, renderOnce)
|
|
124
|
-
|
|
125
|
-
const frame = captureCharFrame()
|
|
126
|
-
expect(frame).toContain("Start")
|
|
127
|
-
expect(frame).not.toContain("flowchart LR")
|
|
128
|
-
})
|
|
129
|
-
|
|
130
|
-
test("keeps surrounding Markdown content visible around a Mermaid diagram", async () => {
|
|
131
|
-
const testRenderer = await setup({ width: 80, height: 14 })
|
|
132
|
-
const { renderOnce, captureCharFrame } = testRenderer
|
|
133
|
-
const markdown = new MarkdownRenderable(renderer, {
|
|
134
|
-
id: "markdown-with-mermaid",
|
|
135
|
-
content: `Before
|
|
136
|
-
|
|
137
|
-
\`\`\`mermaid
|
|
138
|
-
flowchart LR
|
|
139
|
-
A[Start] --> B[Done]
|
|
140
|
-
\`\`\`
|
|
141
|
-
|
|
142
|
-
After`,
|
|
143
|
-
syntaxStyle,
|
|
144
|
-
treeSitterClient,
|
|
145
|
-
renderBlock: createMermaidMarkdownRenderer(renderer),
|
|
146
|
-
})
|
|
147
|
-
|
|
148
|
-
renderer.root.add(markdown)
|
|
149
|
-
await renderMarkdown(markdown, renderOnce)
|
|
150
|
-
|
|
151
|
-
const frame = captureCharFrame()
|
|
152
|
-
expect(frame).toContain("Before")
|
|
153
|
-
expect(frame).toContain("Start")
|
|
154
|
-
expect(frame).toContain("Done")
|
|
155
|
-
expect(frame).toContain("After")
|
|
156
|
-
})
|
|
157
|
-
|
|
158
|
-
test("renders an incomplete Mermaid fence as ordinary code", async () => {
|
|
159
|
-
const testRenderer = await setup({ width: 80, height: 10 })
|
|
160
|
-
const { renderOnce, captureCharFrame } = testRenderer
|
|
161
|
-
const markdown = new MarkdownRenderable(renderer, {
|
|
162
|
-
id: "markdown-incomplete-mermaid",
|
|
163
|
-
content: `\`\`\`mermaid
|
|
164
|
-
flowchart LR
|
|
165
|
-
A -->
|
|
166
|
-
\`\`\``,
|
|
167
|
-
syntaxStyle,
|
|
168
|
-
treeSitterClient,
|
|
169
|
-
renderBlock: createMermaidMarkdownRenderer(renderer),
|
|
170
|
-
})
|
|
171
|
-
|
|
172
|
-
renderer.root.add(markdown)
|
|
173
|
-
await renderMarkdown(markdown, renderOnce)
|
|
174
|
-
|
|
175
|
-
expect(captureCharFrame()).toContain("flowchart LR")
|
|
176
|
-
})
|
|
177
|
-
|
|
178
|
-
test("keeps the last valid Mermaid diagram while a fence is streaming", async () => {
|
|
179
|
-
const testRenderer = await setup({ width: 80, height: 12 })
|
|
180
|
-
const markdown = new MarkdownRenderable(renderer, {
|
|
181
|
-
id: "markdown-streaming-mermaid",
|
|
182
|
-
content: `\`\`\`mermaid
|
|
183
|
-
flowchart LR
|
|
184
|
-
A[Stable] --> B[Previous]
|
|
185
|
-
\`\`\``,
|
|
186
|
-
syntaxStyle,
|
|
187
|
-
streaming: true,
|
|
188
|
-
renderBlock: createMermaidMarkdownRenderer(renderer),
|
|
189
|
-
})
|
|
190
|
-
|
|
191
|
-
renderer.root.add(markdown)
|
|
192
|
-
await renderMarkdown(markdown, testRenderer.renderOnce)
|
|
193
|
-
expect(testRenderer.captureCharFrame()).toContain("Previous")
|
|
194
|
-
|
|
195
|
-
markdown.content = `\`\`\`mermaid
|
|
196
|
-
flowchart LR
|
|
197
|
-
A[Stable] --> B[Previous]
|
|
198
|
-
B -->
|
|
199
|
-
\`\`\``
|
|
200
|
-
await renderMarkdown(markdown, testRenderer.renderOnce)
|
|
201
|
-
expect(testRenderer.captureCharFrame()).toContain("Previous")
|
|
202
|
-
expect(testRenderer.captureCharFrame()).not.toContain("flowchart LR")
|
|
203
|
-
|
|
204
|
-
markdown.content = `\`\`\`mermaid
|
|
205
|
-
flowchart LR
|
|
206
|
-
A[Stable] --> B[Previous]
|
|
207
|
-
B --> C[Current]
|
|
208
|
-
\`\`\``
|
|
209
|
-
await renderMarkdown(markdown, testRenderer.renderOnce)
|
|
210
|
-
expect(testRenderer.captureCharFrame()).toContain("Current")
|
|
211
|
-
})
|
|
212
|
-
|
|
213
|
-
test("renders the valid prefix of an interrupted Mermaid fence", async () => {
|
|
214
|
-
const testRenderer = await setup({ width: 100, height: 18 })
|
|
215
|
-
const markdown = new MarkdownRenderable(renderer, {
|
|
216
|
-
id: "markdown-interrupted-mermaid",
|
|
217
|
-
content: `\`\`\`mermaid
|
|
218
|
-
flowchart TD
|
|
219
|
-
A[Resolve Project] --> B[Current directory]
|
|
220
|
-
B --> C[Search ancestors]
|
|
221
|
-
C --> D[Marker found]
|
|
222
|
-
C --> E[No marker found]
|
|
223
|
-
E --> G[Project root is`,
|
|
224
|
-
syntaxStyle,
|
|
225
|
-
renderBlock: createMermaidMarkdownRenderer(renderer),
|
|
226
|
-
})
|
|
227
|
-
|
|
228
|
-
renderer.root.add(markdown)
|
|
229
|
-
await renderMarkdown(markdown, testRenderer.renderOnce)
|
|
230
|
-
|
|
231
|
-
const frame = testRenderer.captureCharFrame()
|
|
232
|
-
expect(frame).toContain("Resolve Project")
|
|
233
|
-
expect(frame).toContain("No marker found")
|
|
234
|
-
expect(frame).not.toContain("flowchart TD")
|
|
235
|
-
})
|
|
236
|
-
|
|
237
|
-
test("renders a Mermaid sequence fence inside MarkdownRenderable", async () => {
|
|
238
|
-
const testRenderer = await setup({ width: 80, height: 14 })
|
|
239
|
-
const { renderOnce, captureCharFrame } = testRenderer
|
|
240
|
-
const markdown = new MarkdownRenderable(renderer, {
|
|
241
|
-
id: "markdown-sequence",
|
|
242
|
-
content: `\`\`\`mermaid
|
|
243
|
-
sequenceDiagram
|
|
244
|
-
Alice->>Bob: Hello
|
|
245
|
-
\`\`\``,
|
|
246
|
-
syntaxStyle,
|
|
247
|
-
treeSitterClient,
|
|
248
|
-
renderBlock: createMermaidMarkdownRenderer(renderer),
|
|
249
|
-
})
|
|
250
|
-
|
|
251
|
-
renderer.root.add(markdown)
|
|
252
|
-
await renderMarkdown(markdown, renderOnce)
|
|
253
|
-
|
|
254
|
-
const frame = captureCharFrame()
|
|
255
|
-
expect(frame).toContain("Alice")
|
|
256
|
-
expect(frame).toContain("Bob")
|
|
257
|
-
expect(frame).not.toContain("sequenceDiagram")
|
|
258
|
-
})
|
|
259
|
-
|
|
260
|
-
test("wraps wide Mermaid diagrams in a horizontal viewport", async () => {
|
|
261
|
-
const testRenderer = await setup({ width: 40, height: 14 })
|
|
262
|
-
const markdown = new MarkdownRenderable(renderer, {
|
|
263
|
-
id: "markdown-wide-sequence",
|
|
264
|
-
content: `\`\`\`mermaid
|
|
265
|
-
sequenceDiagram
|
|
266
|
-
participant A as Alpha participant
|
|
267
|
-
participant B as Beta participant
|
|
268
|
-
participant C as Gamma participant
|
|
269
|
-
A->>B: first
|
|
270
|
-
B->>C: second
|
|
271
|
-
\`\`\``,
|
|
272
|
-
syntaxStyle,
|
|
273
|
-
renderBlock: createMermaidMarkdownRenderer(renderer, {
|
|
274
|
-
compact: true,
|
|
275
|
-
colors: { primary: "#ff0000" },
|
|
276
|
-
}),
|
|
277
|
-
})
|
|
278
|
-
|
|
279
|
-
renderer.root.add(markdown)
|
|
280
|
-
await renderMarkdown(markdown, testRenderer.renderOnce)
|
|
281
|
-
|
|
282
|
-
const diagram = markdown.getChildren()[0] as CodeRenderable
|
|
283
|
-
expect(diagram.scrollWidth).toBeGreaterThan(diagram.width)
|
|
284
|
-
expect(diagram.scrollX).toBe(0)
|
|
285
|
-
|
|
286
|
-
await testRenderer.mockMouse.drag(diagram.x + 20, diagram.y + 2, diagram.x + 5, diagram.y + 2)
|
|
287
|
-
await testRenderer.renderOnce()
|
|
288
|
-
expect(diagram.scrollX).toBeGreaterThan(0)
|
|
289
|
-
expect(diagram.hasSelection()).toBe(false)
|
|
290
|
-
|
|
291
|
-
diagram.scrollX = 0
|
|
292
|
-
await testRenderer.mockMouse.scroll(diagram.x + 20, diagram.y + 2, "right")
|
|
293
|
-
await testRenderer.renderOnce()
|
|
294
|
-
expect(diagram.scrollX).toBeGreaterThan(0)
|
|
295
|
-
})
|
|
296
|
-
|
|
297
|
-
test("keeps surrounding Markdown anchored around a wide flowchart", async () => {
|
|
298
|
-
const testRenderer = await setup({ width: 100, height: 40 })
|
|
299
|
-
const markdown = new MarkdownRenderable(renderer, {
|
|
300
|
-
id: "markdown-wide-flowchart",
|
|
301
|
-
content: `## Architecture — the profile is three mechanisms
|
|
302
|
-
|
|
303
|
-
\`\`\`mermaid
|
|
304
|
-
flowchart TB
|
|
305
|
-
subgraph consumer["Durable Object"]
|
|
306
|
-
DO["ServerWorkerd.create({ storage, config })"]
|
|
307
|
-
end
|
|
308
|
-
DO --> SO["serverOptions()<br/><i>option flags</i>"]
|
|
309
|
-
DO --> RP["replacements()<br/><i>layer overrides</i>"]
|
|
310
|
-
SO -->|"fs: watcher/fff off<br/>events.persist: true<br/>mcp.stdio: false<br/>config as string"| SF["ServerFetch.make(options, { overrides })"]
|
|
311
|
-
RP -->|"Database → DO-SQLite<br/>Shell/FS/Pty → typed-unavailable<br/>Snapshot/Vcs → no-op<br/>plugins → precompiled only"| SF
|
|
312
|
-
SF --> GRAPH["LayerNode graph<br/>(core builds normally,<br/>swapped nodes substituted)"]
|
|
313
|
-
subgraph bundle["3rd mechanism: bundle conditions (build time)"]
|
|
314
|
-
COND["--conditions=workerd<br/>pty / fff / photon / shell-parser<br/>native modules → inert stubs<br/>#global-roots → workerd path rooting"]
|
|
315
|
-
end
|
|
316
|
-
COND -.->|import resolution| GRAPH
|
|
317
|
-
\`\`\``,
|
|
318
|
-
syntaxStyle,
|
|
319
|
-
treeSitterClient,
|
|
320
|
-
renderBlock: createMermaidMarkdownRenderer(renderer),
|
|
321
|
-
})
|
|
322
|
-
|
|
323
|
-
renderer.root.add(markdown)
|
|
324
|
-
await renderMarkdown(markdown, testRenderer.renderOnce)
|
|
325
|
-
|
|
326
|
-
const frame = testRenderer.captureCharFrame()
|
|
327
|
-
const heading = frame.split("\n").find((line) => line.includes("Architecture"))
|
|
328
|
-
// The wide diagram does not scroll the heading beside it.
|
|
329
|
-
const title = markdown.getChildren().find((child) => child instanceof TextRenderable) as TextRenderable
|
|
330
|
-
expect(heading?.trimStart()).toStartWith("Architecture")
|
|
331
|
-
expect(title.scrollX).toBe(0)
|
|
332
|
-
expect(frame).toContain("Durable Object")
|
|
333
|
-
expect(frame).not.toMatch(/<\/?i>|<br|events persist|mcp stdio/)
|
|
334
|
-
})
|
|
335
|
-
|
|
336
|
-
test("folds a horizontal flowchart to fit the Markdown viewport", async () => {
|
|
337
|
-
const testRenderer = await setup({ width: 160, height: 30 })
|
|
338
|
-
const markdown = new MarkdownRenderable(renderer, {
|
|
339
|
-
id: "markdown-horizontal-flowchart",
|
|
340
|
-
content: `\`\`\`mermaid
|
|
341
|
-
flowchart LR
|
|
342
|
-
A["per TURN<br/>fresh sandbox each turn"] --- B["per SESSION/thread<br/>one sandbox per Slack thread"] --- C["per REPO<br/>threads share a sandbox"] --- D["GLOBAL registry<br/>(upstream today: hardwired at boot)"]
|
|
343
|
-
\`\`\``,
|
|
344
|
-
syntaxStyle,
|
|
345
|
-
renderBlock: createMermaidMarkdownRenderer(renderer),
|
|
346
|
-
})
|
|
347
|
-
|
|
348
|
-
renderer.root.add(markdown)
|
|
349
|
-
await renderMarkdown(markdown, testRenderer.renderOnce)
|
|
350
|
-
|
|
351
|
-
const diagram = markdown.getChildren()[0] as CodeRenderable
|
|
352
|
-
expect(diagram.scrollWidth).toBeLessThanOrEqual(diagram.width)
|
|
353
|
-
expect(diagram.scrollWidth).toBeLessThanOrEqual(120)
|
|
354
|
-
expect(testRenderer.captureCharFrame()).toContain("GLOBAL registry")
|
|
355
|
-
})
|
|
356
|
-
|
|
357
|
-
test("folds a horizontal state diagram to the Markdown context width", async () => {
|
|
358
|
-
const testRenderer = await setup({ width: 60, height: 48 })
|
|
359
|
-
const markdown = new MarkdownRenderable(renderer, {
|
|
360
|
-
id: "markdown-horizontal-state",
|
|
361
|
-
content: `\`\`\`mermaid
|
|
362
|
-
stateDiagram-v2
|
|
363
|
-
direction LR
|
|
364
|
-
[*] --> A
|
|
365
|
-
A --> B: first
|
|
366
|
-
B --> C: second
|
|
367
|
-
C --> D: third
|
|
368
|
-
D --> [*]
|
|
369
|
-
\`\`\``,
|
|
370
|
-
syntaxStyle,
|
|
371
|
-
renderBlock: createMermaidMarkdownRenderer(renderer),
|
|
372
|
-
})
|
|
373
|
-
|
|
374
|
-
renderer.root.add(markdown)
|
|
375
|
-
await renderMarkdown(markdown, testRenderer.renderOnce)
|
|
376
|
-
|
|
377
|
-
const diagram = markdown.getChildren()[0] as CodeRenderable
|
|
378
|
-
expect(diagram.scrollWidth).toBeLessThanOrEqual(diagram.width)
|
|
379
|
-
expect(diagram.scrollWidth).toBeLessThanOrEqual(60)
|
|
380
|
-
expect(testRenderer.captureCharFrame()).toContain("third")
|
|
381
|
-
})
|
|
382
|
-
|
|
383
|
-
test("renders a Mermaid state fence inside MarkdownRenderable", async () => {
|
|
384
|
-
const testRenderer = await setup({ width: 80, height: 14 })
|
|
385
|
-
const { renderOnce, captureCharFrame } = testRenderer
|
|
386
|
-
const markdown = new MarkdownRenderable(renderer, {
|
|
387
|
-
id: "markdown-state",
|
|
388
|
-
content: `\`\`\`mermaid
|
|
389
|
-
stateDiagram-v2
|
|
390
|
-
[*] --> Idle
|
|
391
|
-
\`\`\``,
|
|
392
|
-
syntaxStyle,
|
|
393
|
-
treeSitterClient,
|
|
394
|
-
renderBlock: createMermaidMarkdownRenderer(renderer),
|
|
395
|
-
})
|
|
396
|
-
|
|
397
|
-
renderer.root.add(markdown)
|
|
398
|
-
await renderMarkdown(markdown, renderOnce)
|
|
399
|
-
|
|
400
|
-
const frame = captureCharFrame()
|
|
401
|
-
expect(frame).toContain("Idle")
|
|
402
|
-
expect(frame).not.toContain("stateDiagram-v2")
|
|
403
|
-
})
|
|
404
|
-
|
|
405
|
-
test("sizes a standalone state choice after trimming leading rows", async () => {
|
|
406
|
-
const testRenderer = await setup({ width: 80, height: 6 })
|
|
407
|
-
const markdown = new MarkdownRenderable(renderer, {
|
|
408
|
-
id: "markdown-state-choice",
|
|
409
|
-
content: `\`\`\`mermaid
|
|
410
|
-
stateDiagram-v2
|
|
411
|
-
direction LR
|
|
412
|
-
state Decision <<choice>>
|
|
413
|
-
\`\`\``,
|
|
414
|
-
syntaxStyle,
|
|
415
|
-
renderBlock: createMermaidMarkdownRenderer(renderer),
|
|
416
|
-
})
|
|
417
|
-
|
|
418
|
-
renderer.root.add(markdown)
|
|
419
|
-
await renderMarkdown(markdown, testRenderer.renderOnce)
|
|
420
|
-
|
|
421
|
-
expect(markdown.getChildren()[0]?.height).toBe(1)
|
|
422
|
-
expect(testRenderer.captureCharFrame()).toContain("◆")
|
|
423
|
-
})
|
|
424
|
-
|
|
425
|
-
test("renders a Mermaid timeline fence inside MarkdownRenderable", async () => {
|
|
426
|
-
const testRenderer = await setup({ width: 80, height: 18 })
|
|
427
|
-
const { renderOnce, captureCharFrame } = testRenderer
|
|
428
|
-
const markdown = new MarkdownRenderable(renderer, {
|
|
429
|
-
id: "markdown-timeline",
|
|
430
|
-
content: `\`\`\`mermaid
|
|
431
|
-
timeline
|
|
432
|
-
title Product history
|
|
433
|
-
section Foundation
|
|
434
|
-
2024 : Prototype
|
|
435
|
-
: First release
|
|
436
|
-
\`\`\``,
|
|
437
|
-
syntaxStyle,
|
|
438
|
-
treeSitterClient,
|
|
439
|
-
renderBlock: createMermaidMarkdownRenderer(renderer),
|
|
440
|
-
})
|
|
441
|
-
|
|
442
|
-
renderer.root.add(markdown)
|
|
443
|
-
await renderMarkdown(markdown, renderOnce)
|
|
444
|
-
|
|
445
|
-
const frame = captureCharFrame()
|
|
446
|
-
expect(frame).toContain("Product history")
|
|
447
|
-
expect(frame).toContain("Foundation")
|
|
448
|
-
expect(frame).toContain("First release")
|
|
449
|
-
expect(frame).not.toContain("timeline")
|
|
450
|
-
})
|
|
451
|
-
|
|
452
|
-
test("renders a Mermaid GitGraph fence inside MarkdownRenderable", async () => {
|
|
453
|
-
const testRenderer = await setup({ width: 80, height: 18 })
|
|
454
|
-
const markdown = new MarkdownRenderable(renderer, {
|
|
455
|
-
id: "markdown-gitgraph",
|
|
456
|
-
content: `\`\`\`mermaid
|
|
457
|
-
gitGraph
|
|
458
|
-
commit id: "baseline"
|
|
459
|
-
branch feature
|
|
460
|
-
commit id: "ship"
|
|
461
|
-
\`\`\``,
|
|
462
|
-
syntaxStyle,
|
|
463
|
-
treeSitterClient,
|
|
464
|
-
renderBlock: createMermaidMarkdownRenderer(renderer),
|
|
465
|
-
})
|
|
466
|
-
|
|
467
|
-
renderer.root.add(markdown)
|
|
468
|
-
await renderMarkdown(markdown, testRenderer.renderOnce)
|
|
469
|
-
|
|
470
|
-
const frame = testRenderer.captureCharFrame()
|
|
471
|
-
expect(frame).toContain("baseline")
|
|
472
|
-
expect(frame).toContain("ship")
|
|
473
|
-
expect(frame).not.toContain("gitGraph")
|
|
474
|
-
})
|
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from "bun:test"
|
|
2
|
-
import { renderTimelineDiagram } from "./diagram.js"
|
|
3
|
-
import { drawTimelineDiagramGrid } from "./drawing.js"
|
|
4
|
-
import { parseMermaidTimelineDiagram } from "./parser.js"
|
|
5
|
-
import { renderTimelineGridText } from "./render-grid.js"
|
|
6
|
-
import { resolveTimelineStyleColors } from "./style.js"
|
|
7
|
-
|
|
8
|
-
describe("TimelineDiagram", () => {
|
|
9
|
-
test("detects and parses titles, sections, periods, inline events, and continuations", () => {
|
|
10
|
-
const diagram = parseMermaidTimelineDiagram(`
|
|
11
|
-
%% product history
|
|
12
|
-
timeline LR
|
|
13
|
-
title Product &<br/>Platform
|
|
14
|
-
|
|
15
|
-
section Foundation
|
|
16
|
-
2024 : Prototype : First release
|
|
17
|
-
: Public beta
|
|
18
|
-
section Growth
|
|
19
|
-
2025 : "Scale: ≥ 10k"
|
|
20
|
-
`)
|
|
21
|
-
|
|
22
|
-
expect(diagram.direction).toBe("LR")
|
|
23
|
-
expect(diagram.title).toBe("Product &<br/>Platform")
|
|
24
|
-
expect(diagram.sections).toEqual([{ label: "Foundation" }, { label: "Growth" }])
|
|
25
|
-
expect(diagram.periods).toEqual([
|
|
26
|
-
{ period: "2024", events: ["Prototype", "First release", "Public beta"] },
|
|
27
|
-
{ period: "2025", events: ["Scale: ≥ 10k"] },
|
|
28
|
-
])
|
|
29
|
-
expect(diagram.entries.map((entry) => entry.type)).toEqual(["section", "period", "section", "period"])
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
test("renders a vertical spine with title, section, periods, events, entities, and line breaks", () => {
|
|
33
|
-
const output = renderTimelineDiagram(`timeline
|
|
34
|
-
title Product &<br/>Platform
|
|
35
|
-
section Foundation<br/>phase
|
|
36
|
-
2024 : Prototype<br/>ready : First release
|
|
37
|
-
: Scale ≥ 10k`)
|
|
38
|
-
|
|
39
|
-
expect(output).toBe(
|
|
40
|
-
[
|
|
41
|
-
" Product &",
|
|
42
|
-
" Platform",
|
|
43
|
-
"",
|
|
44
|
-
"Foundation ───┐",
|
|
45
|
-
" phase │",
|
|
46
|
-
" │",
|
|
47
|
-
" 2024 ───● Prototype",
|
|
48
|
-
" │ ready",
|
|
49
|
-
" │ First release",
|
|
50
|
-
" │ Scale ≥ 10k",
|
|
51
|
-
" │",
|
|
52
|
-
].join("\n"),
|
|
53
|
-
)
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
test.each(["timeline", "timeline TD", "timeline LR"])("uses the vertical terminal layout for %s", (header) => {
|
|
57
|
-
const output = renderTimelineDiagram(`${header}\n 2024 : One\n 2025 : Two`)
|
|
58
|
-
const lines = output.split("\n")
|
|
59
|
-
|
|
60
|
-
expect(lines.findIndex((line) => line.includes("2024"))).toBeLessThan(
|
|
61
|
-
lines.findIndex((line) => line.includes("2025")),
|
|
62
|
-
)
|
|
63
|
-
expect(output).toContain("│")
|
|
64
|
-
expect(output).toContain("●")
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
test("preserves Mermaid direction semantics while using vertical terminal layout", () => {
|
|
68
|
-
expect(parseMermaidTimelineDiagram("timeline\n 2024 : One").direction).toBe("LR")
|
|
69
|
-
expect(parseMermaidTimelineDiagram("timeline TD\n 2024 : One").direction).toBe("TD")
|
|
70
|
-
})
|
|
71
|
-
|
|
72
|
-
test("keeps ordinary colons in event text", () => {
|
|
73
|
-
const diagram = parseMermaidTimelineDiagram(`timeline
|
|
74
|
-
2024 : https://example.com : event:detail : next event`)
|
|
75
|
-
|
|
76
|
-
expect(diagram.periods[0]?.events).toEqual(["https://example.com", "event:detail", "next event"])
|
|
77
|
-
})
|
|
78
|
-
|
|
79
|
-
test("does not treat apostrophes in event prose as quotes", () => {
|
|
80
|
-
const diagram = parseMermaidTimelineDiagram("timeline\n 2024 : Kit's launch : Public beta")
|
|
81
|
-
|
|
82
|
-
expect(diagram.periods[0]?.events).toEqual(["Kit's launch", "Public beta"])
|
|
83
|
-
})
|
|
84
|
-
|
|
85
|
-
test("supports standalone periods followed by continuation events", () => {
|
|
86
|
-
const diagram = parseMermaidTimelineDiagram(`timeline
|
|
87
|
-
2024
|
|
88
|
-
: First release
|
|
89
|
-
: Public beta`)
|
|
90
|
-
|
|
91
|
-
expect(diagram.periods).toEqual([{ period: "2024", events: ["First release", "Public beta"] }])
|
|
92
|
-
})
|
|
93
|
-
|
|
94
|
-
test("ignores timeline comments and accessibility directives", () => {
|
|
95
|
-
const diagram = parseMermaidTimelineDiagram(`timeline
|
|
96
|
-
# product history
|
|
97
|
-
accTitle: Product timeline
|
|
98
|
-
accDescr Product release history
|
|
99
|
-
2024 : Prototype %% internal note`)
|
|
100
|
-
|
|
101
|
-
expect(diagram.periods).toEqual([{ period: "2024", events: ["Prototype"] }])
|
|
102
|
-
})
|
|
103
|
-
|
|
104
|
-
test("ignores multiline accessibility descriptions", () => {
|
|
105
|
-
const diagram = parseMermaidTimelineDiagram(`timeline
|
|
106
|
-
accDescr {
|
|
107
|
-
Product milestones by year.
|
|
108
|
-
Includes launch and growth.
|
|
109
|
-
}
|
|
110
|
-
2024 : Ship`)
|
|
111
|
-
|
|
112
|
-
expect(diagram.periods).toEqual([{ period: "2024", events: ["Ship"] }])
|
|
113
|
-
})
|
|
114
|
-
|
|
115
|
-
test("rejects a continuation without a period with source diagnostics", () => {
|
|
116
|
-
expect(() => parseMermaidTimelineDiagram("timeline\n : orphan event")).toThrow(
|
|
117
|
-
'Timeline continuation requires a preceding period in timeline diagram at line 2: ": orphan event"',
|
|
118
|
-
)
|
|
119
|
-
})
|
|
120
|
-
|
|
121
|
-
test("rejects unsupported and empty syntax", () => {
|
|
122
|
-
expect(() => parseMermaidTimelineDiagram("timeline\n section")).toThrow("Timeline section cannot be empty")
|
|
123
|
-
expect(() => parseMermaidTimelineDiagram("timeline\n 2024 :")).toThrow("Timeline event cannot be empty")
|
|
124
|
-
expect(() => parseMermaidTimelineDiagram("timeline\n : unsupported")).toThrow("requires a preceding period")
|
|
125
|
-
})
|
|
126
|
-
|
|
127
|
-
test("draws semantic styles for every timeline role", () => {
|
|
128
|
-
const grid = drawTimelineDiagramGrid(
|
|
129
|
-
parseMermaidTimelineDiagram("timeline\n title Roadmap\n section Now\n 2026 : Ship"),
|
|
130
|
-
)
|
|
131
|
-
const styles = new Set(grid.rows.flatMap((row) => row.map((cell) => cell.style).filter(Boolean)))
|
|
132
|
-
|
|
133
|
-
expect(styles).toEqual(
|
|
134
|
-
new Set([
|
|
135
|
-
"title",
|
|
136
|
-
"section",
|
|
137
|
-
"sectionFade1",
|
|
138
|
-
"sectionFade2",
|
|
139
|
-
"sectionFade3",
|
|
140
|
-
"spine",
|
|
141
|
-
"period",
|
|
142
|
-
"periodFade1",
|
|
143
|
-
"periodFade2",
|
|
144
|
-
"periodFade3",
|
|
145
|
-
"event",
|
|
146
|
-
]),
|
|
147
|
-
)
|
|
148
|
-
expect(Object.keys(resolveTimelineStyleColors()).sort()).toEqual([
|
|
149
|
-
"event",
|
|
150
|
-
"period",
|
|
151
|
-
"periodFade1",
|
|
152
|
-
"periodFade2",
|
|
153
|
-
"periodFade3",
|
|
154
|
-
"section",
|
|
155
|
-
"sectionFade1",
|
|
156
|
-
"sectionFade2",
|
|
157
|
-
"sectionFade3",
|
|
158
|
-
"spine",
|
|
159
|
-
"title",
|
|
160
|
-
])
|
|
161
|
-
expect(renderTimelineGridText(grid)).toBe(
|
|
162
|
-
renderTimelineDiagram("timeline\n title Roadmap\n section Now\n 2026 : Ship"),
|
|
163
|
-
)
|
|
164
|
-
})
|
|
165
|
-
|
|
166
|
-
test("uses section starts and joins with ordered color ramps", () => {
|
|
167
|
-
const grid = drawTimelineDiagramGrid(
|
|
168
|
-
parseMermaidTimelineDiagram("timeline\n section Morning\n 09:00 : Start\n section Midday\n 12:00 : Continue"),
|
|
169
|
-
)
|
|
170
|
-
const text = renderTimelineGridText(grid)
|
|
171
|
-
|
|
172
|
-
expect(text).toContain("Morning ───┐")
|
|
173
|
-
expect(text).toContain("Midday ───┤")
|
|
174
|
-
expect(grid.rows[0]?.map((cell) => cell.style).filter(Boolean)).toEqual([
|
|
175
|
-
"section",
|
|
176
|
-
"section",
|
|
177
|
-
"section",
|
|
178
|
-
"section",
|
|
179
|
-
"section",
|
|
180
|
-
"section",
|
|
181
|
-
"section",
|
|
182
|
-
"sectionFade1",
|
|
183
|
-
"sectionFade2",
|
|
184
|
-
"sectionFade3",
|
|
185
|
-
"spine",
|
|
186
|
-
])
|
|
187
|
-
})
|
|
188
|
-
})
|