@zyro-sec/merman 0.0.0-stage → 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 +29 -4
- package/script/layout-audit.ts +98 -0
- package/src/core/canvas.ts +228 -0
- package/src/core/color/style.ts +56 -0
- package/src/core/drawing.ts +301 -0
- package/src/core/geometry.ts +347 -0
- package/src/core/mermaid.ts +38 -0
- package/src/core/render-grid.ts +51 -0
- package/src/core/spatial.ts +243 -0
- package/src/core/text-lines.ts +32 -0
- package/src/core/text.ts +44 -0
- package/src/detect.ts +17 -0
- package/src/diagnostics.ts +16 -0
- package/src/flowchart/drawing.ts +340 -0
- package/src/flowchart/labels.ts +144 -0
- package/src/flowchart/layout.ts +1427 -0
- package/src/flowchart/options.ts +12 -0
- package/src/flowchart/parser.ts +467 -0
- package/src/flowchart/render.ts +10 -0
- package/src/flowchart/routing.ts +1542 -0
- package/src/flowchart/style.ts +79 -0
- package/src/flowchart/types.ts +65 -0
- package/src/gantt/diagram.ts +8 -0
- package/src/gantt/drawing.ts +191 -0
- package/src/gantt/parser.ts +161 -0
- package/src/gantt/render-grid.ts +17 -0
- package/src/gantt/style.ts +36 -0
- package/src/gantt/types.ts +44 -0
- package/src/gitgraph/diagram.ts +8 -0
- package/src/gitgraph/drawing.ts +234 -0
- package/src/gitgraph/parser.ts +219 -0
- package/src/gitgraph/render-grid.ts +17 -0
- package/src/gitgraph/style.ts +37 -0
- package/src/gitgraph/types.ts +36 -0
- package/src/markdown.ts +336 -0
- package/src/palette.ts +75 -0
- package/src/plugin.ts +15 -0
- package/src/sequence/diagram.ts +8 -0
- package/src/sequence/drawing.ts +287 -0
- package/src/sequence/options.ts +8 -0
- package/src/sequence/parser.ts +282 -0
- package/src/sequence/placement.ts +684 -0
- package/src/sequence/render-grid.ts +22 -0
- package/src/sequence/style.ts +81 -0
- package/src/sequence/types.ts +74 -0
- package/src/state/diagram.ts +8 -0
- package/src/state/drawing.ts +360 -0
- package/src/state/endpoint.ts +15 -0
- package/src/state/layout.ts +1134 -0
- package/src/state/note.ts +59 -0
- package/src/state/options.ts +11 -0
- package/src/state/parser.ts +224 -0
- package/src/state/render-grid.ts +22 -0
- package/src/state/routing.ts +1522 -0
- package/src/state/search.ts +103 -0
- package/src/state/style.ts +52 -0
- package/src/state/types.ts +63 -0
- package/src/state/visible-model.ts +77 -0
- package/src/test/diagram.ts +32 -0
- package/src/test/layout-audit/fixtures.ts +538 -0
- package/src/test/layout-audit/harness.ts +522 -0
- package/src/timeline/diagram.ts +8 -0
- package/src/timeline/drawing.ts +109 -0
- package/src/timeline/parser.ts +119 -0
- package/src/timeline/render-grid.ts +17 -0
- package/src/timeline/style.ts +36 -0
- package/src/timeline/types.ts +31 -0
- package/tsconfig.json +10 -0
- package/README.md +0 -3
package/src/markdown.ts
ADDED
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
import {
|
|
2
|
+
TextRenderable,
|
|
3
|
+
RenderableEvents,
|
|
4
|
+
createMarkdownCodeBlockRenderer,
|
|
5
|
+
parseColor,
|
|
6
|
+
type ColorInput,
|
|
7
|
+
type MarkdownOptions,
|
|
8
|
+
type MarkdownCodeBlockRenderer,
|
|
9
|
+
type MouseEvent,
|
|
10
|
+
type RenderContext,
|
|
11
|
+
type RGBA,
|
|
12
|
+
type StyledText,
|
|
13
|
+
} from "@opentui/core"
|
|
14
|
+
import { MermaidSyntaxError } from "./diagnostics.js"
|
|
15
|
+
import type { OpenCodeDiagramPalette } from "./palette.js"
|
|
16
|
+
import { DiagramCanvasSizeError } from "./core/canvas.js"
|
|
17
|
+
import { detectMermaidDiagram } from "./detect.js"
|
|
18
|
+
import { drawFlowchartDiagramGrid } from "./flowchart/drawing.js"
|
|
19
|
+
import { parseMermaidFlowchartDiagram } from "./flowchart/parser.js"
|
|
20
|
+
import { renderGridStyledText, resolveFlowchartStyleColors } from "./flowchart/style.js"
|
|
21
|
+
import { drawGanttDiagramGrid } from "./gantt/drawing.js"
|
|
22
|
+
import { parseMermaidGanttDiagram } from "./gantt/parser.js"
|
|
23
|
+
import { renderGanttGridStyledText } from "./gantt/render-grid.js"
|
|
24
|
+
import { resolveGanttStyleColors } from "./gantt/style.js"
|
|
25
|
+
import type { GanttDiagramRenderOptions } from "./gantt/types.js"
|
|
26
|
+
import { drawGitGraphDiagramGrid } from "./gitgraph/drawing.js"
|
|
27
|
+
import { parseMermaidGitGraphDiagram } from "./gitgraph/parser.js"
|
|
28
|
+
import { renderGitGraphGridStyledText } from "./gitgraph/render-grid.js"
|
|
29
|
+
import { resolveGitGraphStyleColors } from "./gitgraph/style.js"
|
|
30
|
+
import { drawSequenceDiagramGrid } from "./sequence/drawing.js"
|
|
31
|
+
import { parseMermaidSequenceDiagram } from "./sequence/parser.js"
|
|
32
|
+
import { renderSequenceGridStyledText } from "./sequence/render-grid.js"
|
|
33
|
+
import { resolveSequenceStyleColors } from "./sequence/style.js"
|
|
34
|
+
import { drawStateDiagramGrid } from "./state/drawing.js"
|
|
35
|
+
import { parseMermaidStateDiagram } from "./state/parser.js"
|
|
36
|
+
import { renderStateGridStyledText } from "./state/render-grid.js"
|
|
37
|
+
import { resolveStateStyleColors } from "./state/style.js"
|
|
38
|
+
import { drawTimelineDiagramGrid } from "./timeline/drawing.js"
|
|
39
|
+
import { parseMermaidTimelineDiagram } from "./timeline/parser.js"
|
|
40
|
+
import { renderTimelineGridStyledText } from "./timeline/render-grid.js"
|
|
41
|
+
import { resolveTimelineStyleColors } from "./timeline/style.js"
|
|
42
|
+
|
|
43
|
+
type DiagramKind = NonNullable<ReturnType<typeof detectMermaidDiagram>>
|
|
44
|
+
|
|
45
|
+
interface PreparedDiagram {
|
|
46
|
+
readonly kind: DiagramKind
|
|
47
|
+
readonly source: string
|
|
48
|
+
readonly text: StyledText
|
|
49
|
+
readonly height: number
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface MermaidMarkdownRendererOptions {
|
|
53
|
+
/** Use terminal-optimized diagram spacing. Defaults to true. */
|
|
54
|
+
compact?: boolean
|
|
55
|
+
/** Fold responsive horizontal diagrams that exceed this width. Defaults to 120 columns. */
|
|
56
|
+
layoutMaxWidth?: number
|
|
57
|
+
/** Gantt-specific terminal rendering options. */
|
|
58
|
+
gantt?: Omit<GanttDiagramRenderOptions, "layoutMaxWidth">
|
|
59
|
+
colors?: Partial<Record<keyof OpenCodeDiagramPalette, ColorInput>>
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function color(value: ColorInput | undefined): RGBA | undefined {
|
|
63
|
+
return value === undefined ? undefined : parseColor(value)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
class StaticDiagramRenderable extends TextRenderable {
|
|
67
|
+
constructor(ctx: RenderContext, prepared: PreparedDiagram) {
|
|
68
|
+
super(ctx, {
|
|
69
|
+
content: prepared.text,
|
|
70
|
+
width: "100%",
|
|
71
|
+
height: prepared.height,
|
|
72
|
+
wrapMode: "none",
|
|
73
|
+
selectable: false,
|
|
74
|
+
marginTop: 1,
|
|
75
|
+
})
|
|
76
|
+
let dragX: number | undefined
|
|
77
|
+
this.onMouseDown = (event: MouseEvent) => {
|
|
78
|
+
if (event.button !== 0) return
|
|
79
|
+
ctx.clearSelection()
|
|
80
|
+
dragX = event.x
|
|
81
|
+
event.preventDefault()
|
|
82
|
+
event.stopPropagation()
|
|
83
|
+
}
|
|
84
|
+
this.onMouseDrag = (event: MouseEvent) => {
|
|
85
|
+
event.preventDefault()
|
|
86
|
+
event.stopPropagation()
|
|
87
|
+
if (dragX === undefined) return
|
|
88
|
+
const dx = event.x - dragX
|
|
89
|
+
dragX = event.x
|
|
90
|
+
if (dx) this.scrollX -= dx
|
|
91
|
+
}
|
|
92
|
+
this.onMouseDragEnd = (event: MouseEvent) => {
|
|
93
|
+
dragX = undefined
|
|
94
|
+
event.preventDefault()
|
|
95
|
+
event.stopPropagation()
|
|
96
|
+
}
|
|
97
|
+
this.onMouseUp = (event: MouseEvent) => {
|
|
98
|
+
if (event.button !== 0) return
|
|
99
|
+
dragX = undefined
|
|
100
|
+
event.preventDefault()
|
|
101
|
+
event.stopPropagation()
|
|
102
|
+
}
|
|
103
|
+
this.onMouseScroll = (event: MouseEvent) => {
|
|
104
|
+
const scroll = event.scroll
|
|
105
|
+
if (!scroll || (scroll.direction !== "left" && scroll.direction !== "right")) return
|
|
106
|
+
event.preventDefault()
|
|
107
|
+
event.stopPropagation()
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function prepareDiagram(
|
|
113
|
+
kind: DiagramKind,
|
|
114
|
+
source: string,
|
|
115
|
+
options: MermaidMarkdownRendererOptions,
|
|
116
|
+
layoutMaxWidth: number,
|
|
117
|
+
): PreparedDiagram {
|
|
118
|
+
const colors = options.colors ?? {}
|
|
119
|
+
const compact = options.compact ?? true
|
|
120
|
+
switch (kind) {
|
|
121
|
+
case "flowchart": {
|
|
122
|
+
const grid = drawFlowchartDiagramGrid(parseMermaidFlowchartDiagram(source), {
|
|
123
|
+
compact,
|
|
124
|
+
layoutMaxWidth,
|
|
125
|
+
})
|
|
126
|
+
const size = grid.getTextSize({ trimTop: true, trimBottom: true })
|
|
127
|
+
return {
|
|
128
|
+
kind,
|
|
129
|
+
source,
|
|
130
|
+
text: renderGridStyledText(
|
|
131
|
+
grid,
|
|
132
|
+
resolveFlowchartStyleColors({
|
|
133
|
+
node: color(colors.boxText ?? colors.primary),
|
|
134
|
+
nodeBorder: color(colors.boxBorder ?? colors.muted),
|
|
135
|
+
database: color(colors.boxText ?? colors.primary),
|
|
136
|
+
databaseBorder: color(colors.boxBorder ?? colors.muted),
|
|
137
|
+
edge: color(colors.line ?? colors.secondary),
|
|
138
|
+
label: color(colors.text),
|
|
139
|
+
group: color(colors.group ?? colors.muted),
|
|
140
|
+
groupLabel: color(colors.groupText ?? colors.group ?? colors.muted),
|
|
141
|
+
}),
|
|
142
|
+
{ label: color(colors.labelBackground) },
|
|
143
|
+
),
|
|
144
|
+
height: size.height,
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
case "gitGraph": {
|
|
148
|
+
const grid = drawGitGraphDiagramGrid(parseMermaidGitGraphDiagram(source))
|
|
149
|
+
const size = grid.getTextSize({ trimBottom: true })
|
|
150
|
+
return {
|
|
151
|
+
kind,
|
|
152
|
+
source,
|
|
153
|
+
text: renderGitGraphGridStyledText(
|
|
154
|
+
grid,
|
|
155
|
+
resolveGitGraphStyleColors({
|
|
156
|
+
primary: color(colors.primary),
|
|
157
|
+
secondary: color(colors.secondary),
|
|
158
|
+
muted: color(colors.muted),
|
|
159
|
+
warning: color(colors.warning),
|
|
160
|
+
text: color(colors.text),
|
|
161
|
+
}),
|
|
162
|
+
),
|
|
163
|
+
height: size.height,
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
case "gantt": {
|
|
167
|
+
const grid = drawGanttDiagramGrid(parseMermaidGanttDiagram(source), { ...options.gantt, layoutMaxWidth })
|
|
168
|
+
const size = grid.getTextSize({ trimBottom: true })
|
|
169
|
+
return {
|
|
170
|
+
kind,
|
|
171
|
+
source,
|
|
172
|
+
text: renderGanttGridStyledText(
|
|
173
|
+
grid,
|
|
174
|
+
resolveGanttStyleColors({
|
|
175
|
+
title: color(colors.text),
|
|
176
|
+
axis: color(colors.muted),
|
|
177
|
+
background: color(colors.background),
|
|
178
|
+
section: color(colors.secondary),
|
|
179
|
+
task: color(colors.primary),
|
|
180
|
+
active: color(colors.primary),
|
|
181
|
+
critical: color(colors.warning),
|
|
182
|
+
done: color(colors.muted),
|
|
183
|
+
}),
|
|
184
|
+
),
|
|
185
|
+
height: size.height,
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
case "sequence": {
|
|
189
|
+
const grid = drawSequenceDiagramGrid(parseMermaidSequenceDiagram(source), { compact })
|
|
190
|
+
const size = grid.getTextSize()
|
|
191
|
+
return {
|
|
192
|
+
kind,
|
|
193
|
+
source,
|
|
194
|
+
text: renderSequenceGridStyledText(
|
|
195
|
+
grid,
|
|
196
|
+
resolveSequenceStyleColors({
|
|
197
|
+
participant: color(colors.primary),
|
|
198
|
+
lifeline: color(colors.muted),
|
|
199
|
+
group: color(colors.secondary),
|
|
200
|
+
request: color(colors.request ?? colors.primary),
|
|
201
|
+
response: color(colors.response ?? colors.primary),
|
|
202
|
+
fragment: color(colors.secondary),
|
|
203
|
+
fragmentLabelBg: color(colors.background),
|
|
204
|
+
note: color(colors.note ?? colors.warning),
|
|
205
|
+
noteBg: color(colors.noteBackground ?? colors.background),
|
|
206
|
+
}),
|
|
207
|
+
),
|
|
208
|
+
height: size.height,
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
case "state": {
|
|
212
|
+
const grid = drawStateDiagramGrid(parseMermaidStateDiagram(source), { layoutMaxWidth })
|
|
213
|
+
const size = grid.getTextSize({ trimTop: true, trimBottom: true })
|
|
214
|
+
return {
|
|
215
|
+
kind,
|
|
216
|
+
source,
|
|
217
|
+
text: renderStateGridStyledText(
|
|
218
|
+
grid,
|
|
219
|
+
resolveStateStyleColors({
|
|
220
|
+
state: color(colors.boxText ?? colors.primary),
|
|
221
|
+
stateBorder: color(colors.boxBorder ?? colors.primary),
|
|
222
|
+
composite: color(colors.group ?? colors.muted),
|
|
223
|
+
compositeLabel: color(colors.groupText ?? colors.group ?? colors.muted),
|
|
224
|
+
transition: color(colors.line ?? colors.secondary),
|
|
225
|
+
label: color(colors.text),
|
|
226
|
+
noteBorder: color(colors.noteBorder ?? colors.warning),
|
|
227
|
+
noteText: color(colors.noteText ?? colors.warning),
|
|
228
|
+
noteConnector: color(colors.noteConnector ?? colors.muted),
|
|
229
|
+
start: color(colors.marker ?? colors.muted),
|
|
230
|
+
end: color(colors.marker ?? colors.muted),
|
|
231
|
+
choice: color(colors.marker ?? colors.secondary),
|
|
232
|
+
}),
|
|
233
|
+
{ label: color(colors.labelBackground) },
|
|
234
|
+
),
|
|
235
|
+
height: size.height,
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
case "timeline": {
|
|
239
|
+
const grid = drawTimelineDiagramGrid(parseMermaidTimelineDiagram(source))
|
|
240
|
+
const size = grid.getTextSize({ trimBottom: true })
|
|
241
|
+
return {
|
|
242
|
+
kind,
|
|
243
|
+
source,
|
|
244
|
+
text: renderTimelineGridStyledText(
|
|
245
|
+
grid,
|
|
246
|
+
resolveTimelineStyleColors({
|
|
247
|
+
title: color(colors.text),
|
|
248
|
+
section: color(colors.secondary),
|
|
249
|
+
period: color(colors.warning),
|
|
250
|
+
spine: color(colors.muted),
|
|
251
|
+
event: color(colors.primary),
|
|
252
|
+
}),
|
|
253
|
+
),
|
|
254
|
+
height: size.height,
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/** Create an OpenTUI Markdown node renderer for fenced Mermaid diagrams. */
|
|
261
|
+
export function createMermaidMarkdownRenderer(
|
|
262
|
+
ctx: RenderContext,
|
|
263
|
+
input: MermaidMarkdownRendererOptions | (() => MermaidMarkdownRendererOptions) = {},
|
|
264
|
+
): NonNullable<MarkdownOptions["renderBlock"]> {
|
|
265
|
+
return createMarkdownCodeBlockRenderer({ mermaid: createMermaidCodeBlockRenderer(ctx, input) })!
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
export function createMermaidCodeBlockRenderer(
|
|
269
|
+
ctx: RenderContext,
|
|
270
|
+
input: MermaidMarkdownRendererOptions | (() => MermaidMarkdownRendererOptions) = {},
|
|
271
|
+
): MarkdownCodeBlockRenderer {
|
|
272
|
+
const lastGood = new Map<string, PreparedDiagram>()
|
|
273
|
+
return (token, context) => {
|
|
274
|
+
const kind = detectMermaidDiagram(token.text)
|
|
275
|
+
if (!kind) return undefined
|
|
276
|
+
// OpenTUI's default block ID is the stable identity available for this fence across streaming updates.
|
|
277
|
+
const key = context.defaultRender()?.id
|
|
278
|
+
const options = typeof input === "function" ? input() : input
|
|
279
|
+
const configuredMaxWidth =
|
|
280
|
+
options.layoutMaxWidth === undefined ? 120 : Math.max(1, Math.trunc(options.layoutMaxWidth))
|
|
281
|
+
const layoutMaxWidth = Math.min(configuredMaxWidth, Math.max(1, Math.trunc(ctx.width)))
|
|
282
|
+
|
|
283
|
+
try {
|
|
284
|
+
const prepared = prepareDiagram(kind, token.text, options, layoutMaxWidth)
|
|
285
|
+
const diagram = new StaticDiagramRenderable(ctx, prepared)
|
|
286
|
+
if (key) claimLastGood(key, prepared, diagram, lastGood)
|
|
287
|
+
return diagram
|
|
288
|
+
} catch (error) {
|
|
289
|
+
if (error instanceof MermaidSyntaxError) {
|
|
290
|
+
const previous = key ? lastGood.get(key) : undefined
|
|
291
|
+
if (previous?.kind === kind) {
|
|
292
|
+
const diagram = new StaticDiagramRenderable(ctx, previous)
|
|
293
|
+
claimLastGood(key!, previous, diagram, lastGood)
|
|
294
|
+
return diagram
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
const lines = token.text.split("\n")
|
|
298
|
+
if (error.lineNumber <= 2 || lines.slice(error.lineNumber).some((line) => line.trim())) return undefined
|
|
299
|
+
|
|
300
|
+
try {
|
|
301
|
+
const prepared = prepareDiagram(
|
|
302
|
+
kind,
|
|
303
|
+
lines.slice(0, error.lineNumber - 1).join("\n"),
|
|
304
|
+
options,
|
|
305
|
+
layoutMaxWidth,
|
|
306
|
+
)
|
|
307
|
+
if (!prepared.height) return undefined
|
|
308
|
+
const diagram = new StaticDiagramRenderable(ctx, prepared)
|
|
309
|
+
if (key) claimLastGood(key, prepared, diagram, lastGood)
|
|
310
|
+
return diagram
|
|
311
|
+
} catch (error) {
|
|
312
|
+
if (error instanceof MermaidSyntaxError || error instanceof DiagramCanvasSizeError) return undefined
|
|
313
|
+
throw error
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
if (error instanceof DiagramCanvasSizeError) return undefined
|
|
317
|
+
throw error
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
function claimLastGood(
|
|
323
|
+
key: string,
|
|
324
|
+
value: PreparedDiagram,
|
|
325
|
+
owner: StaticDiagramRenderable,
|
|
326
|
+
cache: Map<string, PreparedDiagram>,
|
|
327
|
+
): void {
|
|
328
|
+
const claim = { ...value }
|
|
329
|
+
cache.set(key, claim)
|
|
330
|
+
owner.once(RenderableEvents.DESTROYED, () => {
|
|
331
|
+
// Reconciliation destroys the old block before synchronously creating its replacement.
|
|
332
|
+
queueMicrotask(() => {
|
|
333
|
+
if (cache.get(key) === claim) cache.delete(key)
|
|
334
|
+
})
|
|
335
|
+
})
|
|
336
|
+
}
|
package/src/palette.ts
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { RGBA } from "@opentui/core"
|
|
2
|
+
import { blendColor } from "./core/color/style.js"
|
|
3
|
+
|
|
4
|
+
export interface OpenCodeDiagramPaletteInput {
|
|
5
|
+
readonly text: RGBA
|
|
6
|
+
readonly subdued: RGBA
|
|
7
|
+
readonly info: RGBA
|
|
8
|
+
readonly success: RGBA
|
|
9
|
+
readonly warning: RGBA
|
|
10
|
+
readonly background: RGBA
|
|
11
|
+
readonly accent: {
|
|
12
|
+
readonly soft: RGBA
|
|
13
|
+
readonly clear: RGBA
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type OpenCodeDiagramPalette = ReturnType<typeof createOpenCodeDiagramPalette>
|
|
18
|
+
|
|
19
|
+
export function createOpenCodeDiagramPalette(input: OpenCodeDiagramPaletteInput) {
|
|
20
|
+
const secondary = blendColor(input.text, input.subdued, 0.5)
|
|
21
|
+
const muted = blendColor(input.text, input.subdued, 0.7)
|
|
22
|
+
return {
|
|
23
|
+
text: input.text,
|
|
24
|
+
primary: input.text,
|
|
25
|
+
secondary,
|
|
26
|
+
muted,
|
|
27
|
+
warning: input.info,
|
|
28
|
+
background: input.background,
|
|
29
|
+
request: input.success,
|
|
30
|
+
response: input.warning,
|
|
31
|
+
note: input.text,
|
|
32
|
+
noteBackground: blendColor(input.background, input.subdued, 0.25),
|
|
33
|
+
boxText: input.text,
|
|
34
|
+
boxBorder: muted,
|
|
35
|
+
line: input.subdued,
|
|
36
|
+
labelBackground: RGBA.fromValues(input.text.r, input.text.g, input.text.b, 0.08),
|
|
37
|
+
group: input.accent.soft,
|
|
38
|
+
groupText: input.accent.soft,
|
|
39
|
+
marker: secondary,
|
|
40
|
+
noteBorder: input.accent.soft,
|
|
41
|
+
noteText: input.accent.clear,
|
|
42
|
+
noteConnector: input.accent.soft,
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function resolveOpenCodeDiagramPalette(
|
|
47
|
+
theme: {
|
|
48
|
+
readonly text: {
|
|
49
|
+
readonly base: RGBA
|
|
50
|
+
readonly muted: RGBA
|
|
51
|
+
readonly feedback: {
|
|
52
|
+
readonly info: { readonly base: RGBA }
|
|
53
|
+
readonly success: { readonly base: RGBA }
|
|
54
|
+
readonly warning: { readonly base: RGBA }
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
readonly background: { readonly base: RGBA }
|
|
58
|
+
readonly categorical: readonly Readonly<Record<200 | 300 | 700 | 800, RGBA>>[]
|
|
59
|
+
},
|
|
60
|
+
mode: "dark" | "light",
|
|
61
|
+
) {
|
|
62
|
+
const accent = theme.categorical[3] ?? theme.categorical[0]!
|
|
63
|
+
return createOpenCodeDiagramPalette({
|
|
64
|
+
text: theme.text.base,
|
|
65
|
+
subdued: theme.text.muted,
|
|
66
|
+
info: theme.text.feedback.info.base,
|
|
67
|
+
success: theme.text.feedback.success.base,
|
|
68
|
+
warning: theme.text.feedback.warning.base,
|
|
69
|
+
background: theme.background.base,
|
|
70
|
+
accent: {
|
|
71
|
+
soft: accent[mode === "dark" ? 300 : 700],
|
|
72
|
+
clear: accent[mode === "dark" ? 200 : 800],
|
|
73
|
+
},
|
|
74
|
+
})
|
|
75
|
+
}
|
package/src/plugin.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Plugin } from "@zyro-sec/plugin/tui"
|
|
2
|
+
import { createMermaidCodeBlockRenderer } from "./markdown.js"
|
|
3
|
+
import { resolveOpenCodeDiagramPalette } from "./palette.js"
|
|
4
|
+
|
|
5
|
+
export default Plugin.define({
|
|
6
|
+
id: "opencode.merman",
|
|
7
|
+
setup(context) {
|
|
8
|
+
context.markdown.registerCodeBlockRenderer(
|
|
9
|
+
"mermaid",
|
|
10
|
+
createMermaidCodeBlockRenderer(context.renderer, () => ({
|
|
11
|
+
colors: resolveOpenCodeDiagramPalette(context.theme, context.themeMode),
|
|
12
|
+
})),
|
|
13
|
+
)
|
|
14
|
+
},
|
|
15
|
+
})
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { drawSequenceDiagramGrid } from "./drawing.js"
|
|
2
|
+
import { parseMermaidSequenceDiagram } from "./parser.js"
|
|
3
|
+
import { renderSequenceGridText } from "./render-grid.js"
|
|
4
|
+
import type { SequenceDiagramRenderOptions } from "./types.js"
|
|
5
|
+
|
|
6
|
+
export function renderSequenceDiagram(content: string, options: SequenceDiagramRenderOptions = {}): string {
|
|
7
|
+
return renderSequenceGridText(drawSequenceDiagramGrid(parseMermaidSequenceDiagram(content), options))
|
|
8
|
+
}
|