opentui-markdown-render 0.0.0-stage → 0.1.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 +21 -0
- package/NOTICE +27 -0
- package/README.md +173 -2
- package/native/Cargo.lock +3708 -0
- package/native/Cargo.toml +28 -0
- package/native/build.rs +3 -0
- package/native/src/lib.rs +880 -0
- package/package.json +62 -4
- package/prebuilds/linux-x64-gnu/opentui_markdown_render.node +4 -0
- package/src/app.tsx +180 -0
- package/src/config/index.ts +45 -0
- package/src/config/load.ts +308 -0
- package/src/config/resolve.ts +37 -0
- package/src/config/theme.ts +88 -0
- package/src/config/types.ts +102 -0
- package/src/core/document.ts +44 -0
- package/src/core/frame.ts +144 -0
- package/src/core/image.ts +9 -0
- package/src/core/index.ts +6 -0
- package/src/core/layout.ts +27 -0
- package/src/core/math.ts +170 -0
- package/src/core/parse.ts +208 -0
- package/src/core/tables.ts +58 -0
- package/src/graphics.ts +85 -0
- package/src/headings.ts +77 -0
- package/src/index.ts +98 -0
- package/src/math/index.ts +86 -0
- package/src/math/native.ts +39 -0
- package/src/math/renderer.ts +84 -0
- package/src/math/validate.ts +44 -0
- package/src/media.tsx +267 -0
- package/src/merman/class/dagre-layout.ts +171 -0
- package/src/merman/class/diagram.ts +8 -0
- package/src/merman/class/drawing.ts +343 -0
- package/src/merman/class/labels.ts +38 -0
- package/src/merman/class/layout.ts +531 -0
- package/src/merman/class/parser.ts +308 -0
- package/src/merman/class/render-grid.ts +18 -0
- package/src/merman/class/style.ts +27 -0
- package/src/merman/class/types.ts +57 -0
- package/src/merman/core/canvas.ts +228 -0
- package/src/merman/core/color/style.ts +56 -0
- package/src/merman/core/drawing.ts +307 -0
- package/src/merman/core/geometry.ts +347 -0
- package/src/merman/core/mermaid.ts +38 -0
- package/src/merman/core/render-grid.ts +51 -0
- package/src/merman/core/spatial.ts +243 -0
- package/src/merman/core/text-lines.ts +32 -0
- package/src/merman/core/text.ts +44 -0
- package/src/merman/detect.ts +19 -0
- package/src/merman/diagnostics.ts +16 -0
- package/src/merman/diagram.ts +268 -0
- package/src/merman/flowchart/drawing.ts +433 -0
- package/src/merman/flowchart/labels.ts +144 -0
- package/src/merman/flowchart/layout.ts +1057 -0
- package/src/merman/flowchart/options.ts +12 -0
- package/src/merman/flowchart/parser.ts +477 -0
- package/src/merman/flowchart/render.ts +10 -0
- package/src/merman/flowchart/routing.ts +1429 -0
- package/src/merman/flowchart/style.ts +79 -0
- package/src/merman/flowchart/types.ts +63 -0
- package/src/merman/gantt/diagram.ts +8 -0
- package/src/merman/gantt/drawing.ts +193 -0
- package/src/merman/gantt/parser.ts +198 -0
- package/src/merman/gantt/render-grid.ts +17 -0
- package/src/merman/gantt/style.ts +36 -0
- package/src/merman/gantt/types.ts +45 -0
- package/src/merman/gitgraph/diagram.ts +8 -0
- package/src/merman/gitgraph/drawing.ts +234 -0
- package/src/merman/gitgraph/parser.ts +234 -0
- package/src/merman/gitgraph/render-grid.ts +17 -0
- package/src/merman/gitgraph/style.ts +37 -0
- package/src/merman/gitgraph/types.ts +36 -0
- package/src/merman/palette.ts +60 -0
- package/src/merman/sequence/diagram.ts +8 -0
- package/src/merman/sequence/drawing.ts +288 -0
- package/src/merman/sequence/options.ts +8 -0
- package/src/merman/sequence/parser.ts +303 -0
- package/src/merman/sequence/placement.ts +692 -0
- package/src/merman/sequence/render-grid.ts +22 -0
- package/src/merman/sequence/style.ts +81 -0
- package/src/merman/sequence/types.ts +74 -0
- package/src/merman/state/diagram.ts +8 -0
- package/src/merman/state/drawing.ts +363 -0
- package/src/merman/state/endpoint.ts +15 -0
- package/src/merman/state/layout.ts +1134 -0
- package/src/merman/state/note.ts +59 -0
- package/src/merman/state/options.ts +11 -0
- package/src/merman/state/parser.ts +245 -0
- package/src/merman/state/render-grid.ts +22 -0
- package/src/merman/state/routing.ts +1522 -0
- package/src/merman/state/search.ts +103 -0
- package/src/merman/state/style.ts +52 -0
- package/src/merman/state/types.ts +63 -0
- package/src/merman/state/visible-model.ts +77 -0
- package/src/merman/timeline/diagram.ts +8 -0
- package/src/merman/timeline/drawing.ts +109 -0
- package/src/merman/timeline/parser.ts +119 -0
- package/src/merman/timeline/render-grid.ts +17 -0
- package/src/merman/timeline/style.ts +36 -0
- package/src/merman/timeline/types.ts +31 -0
- package/src/merman.ts +3 -0
- package/src/statusline.tsx +183 -0
- package/src/theme/colors.ts +11 -0
- package/src/theme/defaults.ts +190 -0
- package/src/theme/index.ts +5 -0
- package/src/theme/resolve.ts +166 -0
- package/src/theme/syntax.ts +96 -0
- package/src/theme/types.ts +150 -0
- package/src/view/code.tsx +27 -0
- package/src/view/document-slots.ts +111 -0
- package/src/view/document-table.tsx +98 -0
- package/src/view/document.tsx +195 -0
- package/src/view/frame.tsx +83 -0
- package/src/view/inline-flow.tsx +113 -0
- package/src/view/inline-layout.ts +149 -0
- package/src/view/inline-math.ts +42 -0
- package/src/view/inline-style.ts +103 -0
- package/src/view/math.tsx +85 -0
- package/src/view/mermaid.tsx +128 -0
- package/src/view/table.ts +100 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BoxRenderable,
|
|
3
|
+
TextTableRenderable,
|
|
4
|
+
type MouseEvent,
|
|
5
|
+
type RenderContext,
|
|
6
|
+
} from "@opentui/core"
|
|
7
|
+
|
|
8
|
+
// In content mode a table keeps its natural columns even when its layout box is
|
|
9
|
+
// narrower, so its drawn width can be larger than `table.width`. The layout
|
|
10
|
+
// itself knows the drawn width; fall back to the box when the field is gone.
|
|
11
|
+
function tableWidth(table: TextTableRenderable): number {
|
|
12
|
+
const layout = (
|
|
13
|
+
table as unknown as { computeLayout?: (maxWidth?: number) => { tableWidth?: number } | undefined }
|
|
14
|
+
).computeLayout?.(undefined)
|
|
15
|
+
const width = layout?.tableWidth
|
|
16
|
+
if (typeof width === "number" && Number.isFinite(width) && width > 0) return Math.round(width)
|
|
17
|
+
return Number.isFinite(table.width) ? Math.round(table.width) : 0
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// OpenTUI's table draws itself into the bounds it is given, so a table wider
|
|
21
|
+
// than the document is clipped by the terminal. The wrapper keeps the table at
|
|
22
|
+
// its natural width and moves it sideways, the same way a Mermaid diagram is
|
|
23
|
+
// panned. A table that actually needs the scroller gives up cell selection:
|
|
24
|
+
// otherwise a drag would select text instead of panning.
|
|
25
|
+
export class ScrollableTableRenderable extends BoxRenderable {
|
|
26
|
+
protected readonly table: TextTableRenderable
|
|
27
|
+
protected offset = 0
|
|
28
|
+
protected panEnabled = true
|
|
29
|
+
private dragX: number | undefined
|
|
30
|
+
|
|
31
|
+
constructor(ctx: RenderContext, table: TextTableRenderable) {
|
|
32
|
+
super(ctx, {
|
|
33
|
+
width: "100%",
|
|
34
|
+
flexDirection: "row",
|
|
35
|
+
flexShrink: 0,
|
|
36
|
+
overflow: "hidden",
|
|
37
|
+
})
|
|
38
|
+
this.table = table
|
|
39
|
+
table.flexShrink = 0
|
|
40
|
+
this.add(table)
|
|
41
|
+
this.onMouseDown = (event: MouseEvent) => {
|
|
42
|
+
if (event.button !== 0) return
|
|
43
|
+
this.dragX = event.x
|
|
44
|
+
}
|
|
45
|
+
this.onMouseDrag = (event: MouseEvent) => {
|
|
46
|
+
if (this.dragX === undefined || !this.panEnabled) return
|
|
47
|
+
const dx = event.x - this.dragX
|
|
48
|
+
this.dragX = event.x
|
|
49
|
+
if (!dx || !this.overflows()) return
|
|
50
|
+
event.preventDefault()
|
|
51
|
+
event.stopPropagation()
|
|
52
|
+
this.scrollBy(-dx)
|
|
53
|
+
}
|
|
54
|
+
this.onMouseDragEnd = () => {
|
|
55
|
+
this.dragX = undefined
|
|
56
|
+
}
|
|
57
|
+
this.onMouseUp = () => {
|
|
58
|
+
this.dragX = undefined
|
|
59
|
+
}
|
|
60
|
+
// A vertical wheel is left to the host: the document scroll box owns it.
|
|
61
|
+
this.onMouseScroll = (event: MouseEvent) => {
|
|
62
|
+
const direction = event.scroll?.direction
|
|
63
|
+
if (!this.panEnabled || (direction !== "left" && direction !== "right")) return
|
|
64
|
+
if (!this.overflows()) return
|
|
65
|
+
event.preventDefault()
|
|
66
|
+
event.stopPropagation()
|
|
67
|
+
this.scrollBy(direction === "left" ? -2 : 2)
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// A table that fits keeps cell selection; only a table that has to scroll
|
|
72
|
+
// gives its drag to the scroller.
|
|
73
|
+
protected override onResize(width: number, _height: number) {
|
|
74
|
+
super.onResize(width, _height)
|
|
75
|
+
this.syncOverflowState(width)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
protected syncOverflowState(width = this.width) {
|
|
79
|
+
// A Solid custom renderable receives props before Yoga assigns its first
|
|
80
|
+
// width. Measuring the table at that point can poison the layout cache.
|
|
81
|
+
if (!Number.isFinite(width) || width <= 0) return
|
|
82
|
+
const viewport = Math.round(width)
|
|
83
|
+
const max = Math.max(0, tableWidth(this.table) - viewport)
|
|
84
|
+
this.offset = this.panEnabled ? Math.min(this.offset, max) : 0
|
|
85
|
+
this.table.marginLeft = -this.offset
|
|
86
|
+
this.table.selectable = !this.panEnabled || max === 0
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
private overflows(width = this.width) {
|
|
90
|
+
const viewportWidth = Number.isFinite(width) ? Math.round(width) : 0
|
|
91
|
+
return tableWidth(this.table) > viewportWidth
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
private scrollBy(delta: number) {
|
|
95
|
+
const viewportWidth = Number.isFinite(this.width) ? Math.round(this.width) : 0
|
|
96
|
+
const max = Math.max(0, tableWidth(this.table) - viewportWidth)
|
|
97
|
+
this.offset = Math.max(0, Math.min(max, this.offset + delta))
|
|
98
|
+
this.table.marginLeft = -this.offset
|
|
99
|
+
}
|
|
100
|
+
}
|