paseo-plugin-mermaid 0.2.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 dutchakdev
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,182 @@
1
+ <h1 align="center">paseo-plugin-mermaid</h1>
2
+
3
+ <p align="center">
4
+ Mermaid diagrams drawn inside the <a href="https://paseo.sh">Paseo</a> chat timeline.<br>
5
+ When an agent replies with a <code>```mermaid</code> block, you get the drawing instead of the source.
6
+ </p>
7
+
8
+ <p align="center">
9
+ <img src="https://img.shields.io/badge/Paseo-0.8.x%20%E2%80%93%200.11.x-3987e5" alt="Supports Paseo 0.8.x through 0.11.x, including betas">
10
+ <img src="https://img.shields.io/badge/tests-110-199e70" alt="110 tests">
11
+ <img src="https://img.shields.io/badge/dependencies-none-c98500" alt="No runtime dependencies">
12
+ <img src="https://img.shields.io/badge/license-MIT-9aa1a6" alt="MIT licensed">
13
+ </p>
14
+
15
+ <p align="center">
16
+ <img src="docs/preview.svg" alt="A flowchart and a sequence diagram rendered in a Paseo transcript" width="920">
17
+ </p>
18
+
19
+ <p align="center"><sub>Generated by <code>npm run preview</code>: the diagram above comes from the plugin&apos;s own parser and layout, so the picture cannot drift from the code.</sub></p>
20
+
21
+ Built on the plugin timeline API introduced in Paseo 0.8.
22
+
23
+ Paseo draws Mermaid itself too, in an iframe inside a zoomable box with a
24
+ fullscreen viewer. This plugin draws it inline instead: readable at the width of
25
+ the message, from the first streamed line, with the same controls above it for
26
+ the times the fitted drawing is not enough: zoom, fit to view, pop out, and the
27
+ source on demand.
28
+
29
+ ## Install
30
+
31
+ ```sh
32
+ paseo plugin install npm:paseo-plugin-mermaid # Paseo 0.9 and newer
33
+ paseo plugin ls # expect: running
34
+ ```
35
+
36
+ Paseo 0.8 has no npm sources, so install from Git there:
37
+ `paseo plugin add dutchakdev/paseo-plugin-mermaid`. Either way,
38
+ `paseo plugin update mermaid` pulls later releases. The plugin supports **Paseo 0.8.x through 0.11.x, including betas**, on both
39
+ sides: the daemon compiles it, and the app checks its declared version range.
40
+ It has no server entry, so it starts no daemon process.
41
+
42
+ The manifest remains `>=0.8.0`, which already admits 0.9.x, 0.10.x and 0.11.x. Paseo also checks a
43
+ prerelease's stable version core, so `0.11.0-beta.3` satisfies this range; see
44
+ [version requirements](https://paseo.sh/docs/plugins/reference#requirements).
45
+ The development SDK stays pinned to 0.8.0; Paseo supplies the runtime modules.
46
+
47
+ To work on it locally instead:
48
+
49
+ ```sh
50
+ git clone https://github.com/dutchakdev/paseo-plugin-mermaid.git
51
+ cd paseo-plugin-mermaid
52
+ npm install
53
+ npm run typecheck && npm test
54
+ paseo plugin install "$PWD"
55
+ ```
56
+
57
+ Plugins must be enabled daemon-wide first, under **Settings → Plugins → Enable
58
+ plugins**.
59
+
60
+ ## What it draws
61
+
62
+ | Diagram | Supported |
63
+ | ------- | --------- |
64
+ | `flowchart` / `graph` | `TD`, `TB`, `BT`, `LR`, `RL` |
65
+ | Node shapes | `[rect]`, `(round)`, `([stadium])`, `[[subroutine]]`, `{diamond}`, `((circle))`, `>asymmetric]` |
66
+ | Edges | `-->`, `---`, `-.->`, `-.-`, `==>`, `===` |
67
+ | Edge labels | `-->|both|` and `-- forms -->` |
68
+ | `sequenceDiagram` | participants, actors, notes |
69
+ | Message arrows | `->`, `->>`, `-->`, `-->>`, `-x`, `--x`, `-)`, `--)` |
70
+
71
+ Not supported yet: subgraphs, `style`/`classDef` directives, and the diagram types
72
+ beyond these two. Unrecognised lines are counted and reported under the drawing
73
+ rather than dropped, and a diagram the parser cannot read at all falls back to
74
+ showing its source.
75
+
76
+ ## Controls
77
+
78
+ Every drawing carries a toolbar: `Zoom out · 100% · Zoom in · Fit to view · Pop out`
79
+ on the left and `Show code` on the right. The zoom model is the one Paseo's own
80
+ diagram box uses, so a reader who knows one knows the other.
81
+
82
+ | Control | What it does |
83
+ | ------- | ------------ |
84
+ | **Zoom in / out** | Steps by ×1.25 and ÷1.25 between 25% and 400%. A button goes quiet at its limit. |
85
+ | **100%** | The zoom relative to the fitted drawing. Fitted means scaled to the width of the row, grown a little when small, and never shrunk past the point where labels stop being readable. |
86
+ | **Fit to view** | In the row: show the whole drawing across the row, even below the readability floor, for the wide ones that would otherwise scroll sideways. It never grows a drawing past 100%. In the pop-out: fit both axes of the window. Quiet once it is there. |
87
+ | **Pop out** | Opens the drawing in a host modal, fitted to the window on both axes, with the same toolbar. Zoomed past the window, it scrolls on both axes. |
88
+ | **Show code** | Swaps the drawing for its Mermaid source and quiets the zoom controls until you switch back. |
89
+
90
+ Zooming in the row makes the row taller and, past its width, scrolls it
91
+ sideways; the transcript scrolls vertically as it always does, so nothing is
92
+ clipped. On phones and narrow windows the button labels drop and the icons and
93
+ the percent stay.
94
+
95
+ ## How it works
96
+
97
+ ```mermaid
98
+ flowchart TD
99
+ Msg([Message arrives]) --> Check{Has mermaid?}
100
+ Check -->|no| Paseo[Paseo renders it]
101
+ Check -->|yes| Split[[Split into segments]]
102
+ Split --> Text(Prose)
103
+ Split --> Src(Diagram source)
104
+ Text --> Md[Minimal markdown]
105
+ Src --> Parse{Which parser?}
106
+ Parse -->|flowchart| Layout[Layered layout]
107
+ Parse -->|sequence| Columns[Column layout]
108
+ Parse -.->|neither| Raw[Show source]
109
+ Layout --> Draw((Views))
110
+ Columns --> Draw
111
+ ```
112
+
113
+ Three constraints shaped this plugin.
114
+
115
+ **Mermaid itself cannot run here.** A Paseo client bundle may import only the modules the
116
+ app provides: `react`, `react-native`, `@tanstack/react-query`, `zod` and the
117
+ `@getpaseo/plugin` entries. There is no
118
+ SVG, no canvas and no webview, and Mermaid needs a DOM. So the parser, the layout
119
+ and the drawing are all written from scratch. Every line you see is a positioned
120
+ `View`: node boxes, edge segments 1.5px thick, and arrowheads made from a View
121
+ with three transparent borders.
122
+
123
+ **A transformer replaces the whole timeline entry.** Once a message contains a
124
+ diagram, the plugin owns the message. It is split into prose and diagram
125
+ segments, and each becomes its own item, so the text around the diagram keeps its
126
+ place. That prose goes through a small Markdown renderer covering headings,
127
+ lists, emphasis and code — less than Paseo's own, which is why messages without a
128
+ diagram are left alone entirely.
129
+
130
+ **Items store the source, not a parsed graph.** Parsing happens at render time.
131
+ The stored data stays small, and a later fix to the parser improves diagrams that
132
+ were sent months ago.
133
+
134
+ **The fence is claimed while it is still open.** Paseo runs transformers on every
135
+ streaming update, and it renders `mermaid` fences itself as soon as one opens. A
136
+ transformer that waited for the closing ``` would leave the host drawing the
137
+ diagram for the whole stream and then swap renderers at the last line. An
138
+ unfinished block is therefore taken over at once and drawn from whatever has
139
+ parsed so far.
140
+
141
+ **The drawing is fitted to the row.** A diagram's natural size is whatever its
142
+ labels happened to add up to, which is no basis for how big it should appear. The
143
+ row is measured, the drawing is scaled to fit, small diagrams are grown a little
144
+ so they do not look lost, and shrinking stops at the point where labels would
145
+ stop being readable. Only past that does it scroll sideways. The toolbar's zoom
146
+ multiplies that fit, which is why 100% is the fit itself and not the natural size.
147
+
148
+ ## Development
149
+
150
+ ```sh
151
+ npm run typecheck
152
+ npm test # 110 tests
153
+ paseo plugin reload mermaid
154
+ ```
155
+
156
+ The parsers, the layout, the zoom model and the transform are pure functions
157
+ with no runtime dependencies, and that is where the tests are: bracket shapes,
158
+ operator precedence (`-.->` must never read as `-.-` plus a stray `>`), cycles in
159
+ a flowchart, node overlap, arrow direction, zoom steps that land back on 100%,
160
+ which toolbar controls are live, and the JSON round trip Paseo performs on item
161
+ data before rendering. The Views themselves are checked by `npm run typecheck`
162
+ and by reloading the plugin.
163
+
164
+ | File | Role |
165
+ | ---- | ---- |
166
+ | `shared/segment.ts` | splits a message into prose and diagram blocks |
167
+ | `shared/flowchart.ts` | flowchart parser |
168
+ | `shared/sequence.ts` | sequence diagram parser |
169
+ | `shared/layout.ts` | layered layout, orthogonal edge routing, column layout |
170
+ | `shared/markdown.ts` | the Markdown subset used for prose |
171
+ | `shared/zoom.ts` | zoom steps, fit to view, and which controls are live |
172
+ | `shared/transform.ts` | the timeline transform itself |
173
+ | `client/diagram.tsx` | drawing, in Views, at natural size |
174
+ | `client/viewer.tsx` | fitting, zoom and the source toggle, in the row and in the pop-out |
175
+ | `client/toolbar.tsx` | the toolbar |
176
+ | `client/markdown.tsx` | prose rendering |
177
+ | `client/item.tsx` | the two timeline renderers |
178
+ | `index.client.tsx` | registers the transformers and renderers; the only entry |
179
+
180
+ ## License
181
+
182
+ MIT
@@ -0,0 +1,395 @@
1
+ import type { PluginTheme } from "@getpaseo/plugin";
2
+ import React from "react";
3
+ import { StyleSheet, Text, View } from "react-native";
4
+ import { parseFlowchart, type Flowchart, type NodeShape } from "../shared/flowchart";
5
+ import { namesADiagram } from "../shared/segment";
6
+ import {
7
+ layoutFlowchart,
8
+ layoutSequence,
9
+ type FlowLayout,
10
+ type LaidOutEdge,
11
+ type LaidOutNode,
12
+ } from "../shared/layout";
13
+ import { parseSequence, type SeqEvent, type SequenceDiagram } from "../shared/sequence";
14
+ import type { Size } from "../shared/zoom";
15
+
16
+ /**
17
+ * Draws Mermaid with plain Views.
18
+ *
19
+ * A Paseo client bundle has no SVG, no canvas and no webview, and Mermaid itself
20
+ * needs a DOM, so nothing can render the source directly. Every line here is a
21
+ * positioned View: node boxes, one-and-a-half pixel edge segments, and
22
+ * arrowheads made from a View with three transparent borders.
23
+ *
24
+ * Everything is drawn at the natural size of the layout. Fitting it to a row or
25
+ * a window, and zooming, is the viewer's job (viewer.tsx), so the drawing does
26
+ * not need to know where it is.
27
+ */
28
+
29
+ const ARROW = 5;
30
+
31
+ export type ParsedDiagram =
32
+ | { kind: "flow"; layout: FlowLayout; skipped: Flowchart["skipped"] }
33
+ | { kind: "sequence"; diagram: SequenceDiagram; size: Size }
34
+ | { kind: "unsupported" };
35
+
36
+ export type DrawableDiagram = Exclude<ParsedDiagram, { kind: "unsupported" }>;
37
+
38
+ /** Reads the source as whichever diagram it names, laid out at natural size. */
39
+ export function parseDiagram(source: string): ParsedDiagram {
40
+ const flow = parseFlowchart(source);
41
+ if (flow && flow.nodes.length > 0) return { kind: "flow", layout: layoutFlowchart(flow), skipped: flow.skipped };
42
+ const sequence = parseSequence(source);
43
+ if (sequence && sequence.participants.length > 0) {
44
+ const box = layoutSequence(sequence.participants, sequence.events.length);
45
+ return { kind: "sequence", diagram: sequence, size: { width: box.width, height: box.height } };
46
+ }
47
+ return { kind: "unsupported" };
48
+ }
49
+
50
+ /** The size the drawing was laid out at, before any fitting or zoom. */
51
+ export function naturalSize(parsed: DrawableDiagram): Size {
52
+ return parsed.kind === "flow" ? { width: parsed.layout.width, height: parsed.layout.height } : parsed.size;
53
+ }
54
+
55
+ /** Draws a parsed diagram at its natural size; the caller scales and places it. */
56
+ export function Drawing({ parsed, theme }: { parsed: DrawableDiagram; theme: PluginTheme }) {
57
+ return parsed.kind === "flow" ? (
58
+ <FlowchartView layout={parsed.layout} theme={theme} />
59
+ ) : (
60
+ <SequenceView diagram={parsed.diagram} theme={theme} />
61
+ );
62
+ }
63
+
64
+ export function Unsupported({ source, theme }: { source: string; theme: PluginTheme }) {
65
+ // The item is claimed as soon as the fence opens, so most of the time this is a
66
+ // diagram halfway through arriving rather than one this plugin cannot draw.
67
+ // Saying "unsupported" about unfinished source would be a lie that flashes on
68
+ // screen every time.
69
+ const arriving = namesADiagram(source);
70
+ return (
71
+ <View
72
+ style={{
73
+ borderRadius: 8,
74
+ borderWidth: StyleSheet.hairlineWidth,
75
+ borderColor: theme.colors.foregroundMuted,
76
+ padding: 10,
77
+ gap: 6,
78
+ }}
79
+ >
80
+ {arriving ? null : (
81
+ <Text style={{ color: theme.colors.foregroundMuted, fontSize: 11 }}>
82
+ This plugin draws flowchart and sequenceDiagram. Showing the source instead.
83
+ </Text>
84
+ )}
85
+ <Text selectable style={{ color: theme.colors.foreground, fontFamily: "Menlo", fontSize: 12 }}>
86
+ {source}
87
+ </Text>
88
+ </View>
89
+ );
90
+ }
91
+
92
+ /* -------------------------------------------------------------------------- */
93
+ /* Flowchart */
94
+ /* -------------------------------------------------------------------------- */
95
+
96
+ function radiusFor(shape: NodeShape, node: LaidOutNode): number {
97
+ if (shape === "circle") return node.width / 2;
98
+ if (shape === "stadium") return node.height / 2;
99
+ if (shape === "round") return 12;
100
+ return 4;
101
+ }
102
+
103
+ function FlowchartView({ layout, theme }: { layout: FlowLayout; theme: PluginTheme }) {
104
+ return (
105
+ <View style={{ width: layout.width, height: layout.height, paddingBottom: 4 }}>
106
+ {layout.edges.map((edge, index) => (
107
+ <EdgeView key={index} edge={edge} theme={theme} />
108
+ ))}
109
+ {layout.nodes.map((node) => (
110
+ <NodeView key={node.id} node={node} theme={theme} />
111
+ ))}
112
+ </View>
113
+ );
114
+ }
115
+
116
+ function NodeView({ node, theme }: { node: LaidOutNode; theme: PluginTheme }) {
117
+ const common = {
118
+ position: "absolute" as const,
119
+ left: node.x,
120
+ top: node.y,
121
+ width: node.width,
122
+ height: node.height,
123
+ };
124
+
125
+ if (node.shape === "diamond") {
126
+ // A square turned 45 degrees is the diamond. Its side is the box divided by
127
+ // root two, so the rotated corners reach the box edges and an arrow routed to
128
+ // the box touches the shape. The label sits upright on top, which avoids
129
+ // counter-rotating text and the clipping that brings.
130
+ const side = Math.min(node.width, node.height) / Math.SQRT2;
131
+ return (
132
+ <View style={[common, { alignItems: "center", justifyContent: "center" }]}>
133
+ <View
134
+ style={{
135
+ position: "absolute",
136
+ width: side,
137
+ height: side,
138
+ transform: [{ rotate: "45deg" }],
139
+ borderWidth: 1,
140
+ borderColor: theme.colors.accent,
141
+ backgroundColor: theme.colors.surface0,
142
+ }}
143
+ />
144
+ <Text numberOfLines={2} style={{ color: theme.colors.foreground, fontSize: 12, textAlign: "center" }}>
145
+ {node.label}
146
+ </Text>
147
+ </View>
148
+ );
149
+ }
150
+
151
+ return (
152
+ <View
153
+ style={[
154
+ common,
155
+ {
156
+ alignItems: "center",
157
+ justifyContent: "center",
158
+ paddingHorizontal: 8,
159
+ borderWidth: 1,
160
+ borderColor: theme.colors.accent,
161
+ borderRadius: radiusFor(node.shape, node),
162
+ backgroundColor: theme.colors.surface0,
163
+ },
164
+ ]}
165
+ >
166
+ {node.shape === "subroutine" ? (
167
+ <View
168
+ style={{
169
+ position: "absolute",
170
+ left: 5,
171
+ right: 5,
172
+ top: 0,
173
+ bottom: 0,
174
+ borderLeftWidth: 1,
175
+ borderRightWidth: 1,
176
+ borderColor: theme.colors.accent,
177
+ }}
178
+ />
179
+ ) : null}
180
+ <Text style={{ color: theme.colors.foreground, fontSize: 12, textAlign: "center" }}>{node.label}</Text>
181
+ </View>
182
+ );
183
+ }
184
+
185
+ function EdgeView({ edge, theme }: { edge: LaidOutEdge; theme: PluginTheme }) {
186
+ const color = theme.colors.foregroundMuted;
187
+ return (
188
+ <>
189
+ {edge.segments.map((segment, index) => (
190
+ <View
191
+ key={index}
192
+ style={{
193
+ position: "absolute",
194
+ left: segment.x,
195
+ top: segment.y,
196
+ width: segment.width,
197
+ height: segment.height,
198
+ backgroundColor: color,
199
+ // A dotted edge is drawn dimmer; React Native cannot dash a View.
200
+ opacity: edge.style === "dotted" ? 0.45 : 1,
201
+ }}
202
+ />
203
+ ))}
204
+ {edge.arrowAt ? <Arrow at={edge.arrowAt} color={color} /> : null}
205
+ {edge.label && edge.labelAt ? (
206
+ <Text
207
+ numberOfLines={1}
208
+ style={{
209
+ position: "absolute",
210
+ left: edge.labelAt.x - 60,
211
+ top: edge.labelAt.y - 9,
212
+ width: 120,
213
+ textAlign: "center",
214
+ fontSize: 10,
215
+ color: theme.colors.foregroundMuted,
216
+ backgroundColor: theme.colors.surface0,
217
+ }}
218
+ >
219
+ {edge.label}
220
+ </Text>
221
+ ) : null}
222
+ </>
223
+ );
224
+ }
225
+
226
+ /** Three transparent borders and one solid one make a triangle. */
227
+ function Arrow({ at, color }: { at: NonNullable<LaidOutEdge["arrowAt"]>; color: string }) {
228
+ const vertical = at.direction === "down" || at.direction === "up";
229
+ const side = {
230
+ borderLeftWidth: ARROW,
231
+ borderRightWidth: ARROW,
232
+ borderTopWidth: ARROW,
233
+ borderBottomWidth: ARROW,
234
+ borderLeftColor: "transparent",
235
+ borderRightColor: "transparent",
236
+ borderTopColor: "transparent",
237
+ borderBottomColor: "transparent",
238
+ };
239
+ const filled =
240
+ at.direction === "down"
241
+ ? { borderTopColor: color, borderBottomWidth: 0 }
242
+ : at.direction === "up"
243
+ ? { borderBottomColor: color, borderTopWidth: 0 }
244
+ : at.direction === "right"
245
+ ? { borderLeftColor: color, borderRightWidth: 0 }
246
+ : { borderRightColor: color, borderLeftWidth: 0 };
247
+
248
+ return (
249
+ <View
250
+ style={[
251
+ {
252
+ position: "absolute",
253
+ width: 0,
254
+ height: 0,
255
+ left: at.x - (vertical ? ARROW : at.direction === "right" ? ARROW : 0),
256
+ top: at.y - (vertical ? (at.direction === "down" ? ARROW : 0) : ARROW),
257
+ },
258
+ side,
259
+ filled,
260
+ ]}
261
+ />
262
+ );
263
+ }
264
+
265
+ /* -------------------------------------------------------------------------- */
266
+ /* Sequence */
267
+ /* -------------------------------------------------------------------------- */
268
+
269
+ function SequenceView({
270
+ diagram,
271
+ theme,
272
+ }: {
273
+ diagram: SequenceDiagram;
274
+ theme: PluginTheme;
275
+ }) {
276
+ const layout = layoutSequence(diagram.participants, diagram.events.length);
277
+ const centers = new Map(layout.columns.map((column) => [column.id, column.centerX]));
278
+
279
+ return (
280
+ <View style={{ width: layout.width, height: layout.height, paddingBottom: 4 }}>
281
+ {layout.columns.map((column) => (
282
+ <React.Fragment key={column.id}>
283
+ <View
284
+ style={{
285
+ position: "absolute",
286
+ left: column.centerX - 0.75,
287
+ top: layout.headerHeight,
288
+ width: 1.5,
289
+ height: layout.height - layout.headerHeight,
290
+ backgroundColor: theme.colors.foregroundMuted,
291
+ opacity: 0.4,
292
+ }}
293
+ />
294
+ <View
295
+ style={{
296
+ position: "absolute",
297
+ left: column.centerX - column.width / 2,
298
+ top: 0,
299
+ width: column.width,
300
+ height: 28,
301
+ alignItems: "center",
302
+ justifyContent: "center",
303
+ borderWidth: 1,
304
+ borderColor: theme.colors.accent,
305
+ borderRadius: column.actor ? 14 : 4,
306
+ backgroundColor: theme.colors.surface0,
307
+ }}
308
+ >
309
+ <Text numberOfLines={1} style={{ color: theme.colors.foreground, fontSize: 12 }}>
310
+ {column.label}
311
+ </Text>
312
+ </View>
313
+ </React.Fragment>
314
+ ))}
315
+
316
+ {diagram.events.map((event, index) => (
317
+ <EventView key={index} event={event} y={layout.rows[index].y} centers={centers} theme={theme} />
318
+ ))}
319
+ </View>
320
+ );
321
+ }
322
+
323
+ function EventView({
324
+ event,
325
+ y,
326
+ centers,
327
+ theme,
328
+ }: {
329
+ event: SeqEvent;
330
+ y: number;
331
+ centers: Map<string, number>;
332
+ theme: PluginTheme;
333
+ }) {
334
+ if (event.kind === "note") {
335
+ const xs = event.over.map((id) => centers.get(id) ?? 0);
336
+ const left = Math.min(...xs, 0);
337
+ const right = Math.max(...xs, 0);
338
+ return (
339
+ <View
340
+ style={{
341
+ position: "absolute",
342
+ left: left - 40,
343
+ top: y + 6,
344
+ width: Math.max(120, right - left + 80),
345
+ paddingVertical: 4,
346
+ paddingHorizontal: 8,
347
+ borderWidth: StyleSheet.hairlineWidth,
348
+ borderColor: theme.colors.foregroundMuted,
349
+ borderRadius: 4,
350
+ backgroundColor: theme.colors.surface0,
351
+ }}
352
+ >
353
+ <Text style={{ color: theme.colors.foregroundMuted, fontSize: 11, textAlign: "center" }}>{event.text}</Text>
354
+ </View>
355
+ );
356
+ }
357
+
358
+ const from = centers.get(event.from) ?? 0;
359
+ const to = centers.get(event.to) ?? 0;
360
+ const forward = to >= from;
361
+ const left = Math.min(from, to);
362
+ const width = Math.max(Math.abs(to - from), 1);
363
+ const color = theme.colors.foregroundMuted;
364
+
365
+ return (
366
+ <>
367
+ <Text
368
+ numberOfLines={1}
369
+ style={{
370
+ position: "absolute",
371
+ left,
372
+ top: y + 2,
373
+ width,
374
+ textAlign: "center",
375
+ fontSize: 11,
376
+ color: theme.colors.foreground,
377
+ }}
378
+ >
379
+ {event.text}
380
+ </Text>
381
+ <View
382
+ style={{
383
+ position: "absolute",
384
+ left,
385
+ top: y + 22,
386
+ width,
387
+ height: 1.5,
388
+ backgroundColor: color,
389
+ opacity: event.style === "dashed" ? 0.45 : 1,
390
+ }}
391
+ />
392
+ <Arrow at={{ x: to, y: y + 22.75, direction: forward ? "right" : "left" }} color={color} />
393
+ </>
394
+ );
395
+ }
@@ -0,0 +1,25 @@
1
+ import type { PluginTimelineItemProps } from "@getpaseo/plugin/client";
2
+ import React from "react";
3
+ import { View } from "react-native";
4
+ import { Markdown } from "./markdown";
5
+ import { DiagramViewer } from "./viewer";
6
+
7
+ export interface TextData {
8
+ text: string;
9
+ }
10
+
11
+ export interface DiagramData {
12
+ source: string;
13
+ }
14
+
15
+ export function TextItem({ item, theme, layout }: PluginTimelineItemProps<TextData>) {
16
+ return <Markdown text={item.data.text} theme={theme} compact={layout.compact} />;
17
+ }
18
+
19
+ export function DiagramItem({ item, theme, layout }: PluginTimelineItemProps<DiagramData>) {
20
+ return (
21
+ <View style={{ paddingVertical: 4 }}>
22
+ <DiagramViewer source={item.data.source} theme={theme} compact={layout.compact} />
23
+ </View>
24
+ );
25
+ }