@tooee/renderers 0.10.1 → 0.10.2

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.
Files changed (140) hide show
  1. package/dist/chooser/choose-filter.d.ts.map +1 -1
  2. package/dist/chooser/choose-filter.js.map +1 -1
  3. package/dist/chooser/choose-highlighted-text.d.ts.map +1 -1
  4. package/dist/chooser/choose-highlighted-text.js.map +1 -1
  5. package/dist/chooser/choose-list.d.ts.map +1 -1
  6. package/dist/chooser/choose-list.js +5 -2
  7. package/dist/chooser/choose-list.js.map +1 -1
  8. package/dist/chooser/choose-store.d.ts.map +1 -1
  9. package/dist/chooser/choose-store.js.map +1 -1
  10. package/dist/chooser/chooser.d.ts.map +1 -1
  11. package/dist/chooser/chooser.js.map +1 -1
  12. package/dist/chooser/fuzzy.d.ts.map +1 -1
  13. package/dist/chooser/fuzzy.js.map +1 -1
  14. package/dist/chooser/use-choose.d.ts.map +1 -1
  15. package/dist/chooser/use-choose.js +2 -2
  16. package/dist/chooser/use-choose.js.map +1 -1
  17. package/dist/code-blocks.d.ts +2 -2
  18. package/dist/code-blocks.d.ts.map +1 -1
  19. package/dist/code-blocks.js.map +1 -1
  20. package/dist/code-view.d.ts +1 -1
  21. package/dist/code-view.d.ts.map +1 -1
  22. package/dist/code-view.js +1 -1
  23. package/dist/code-view.js.map +1 -1
  24. package/dist/command-palette.d.ts.map +1 -1
  25. package/dist/command-palette.js +2 -2
  26. package/dist/command-palette.js.map +1 -1
  27. package/dist/context-menu.d.ts.map +1 -1
  28. package/dist/context-menu.js +1 -1
  29. package/dist/context-menu.js.map +1 -1
  30. package/dist/document-bindings.d.ts +1 -1
  31. package/dist/document-bindings.d.ts.map +1 -1
  32. package/dist/markdown/blocks/blockquote.d.ts +1 -1
  33. package/dist/markdown/blocks/blockquote.d.ts.map +1 -1
  34. package/dist/markdown/blocks/blockquote.js.map +1 -1
  35. package/dist/markdown/blocks/flat-block.d.ts +1 -1
  36. package/dist/markdown/blocks/flat-block.d.ts.map +1 -1
  37. package/dist/markdown/blocks/flat-block.js +2 -2
  38. package/dist/markdown/blocks/flat-block.js.map +1 -1
  39. package/dist/markdown/blocks/heading.d.ts +1 -1
  40. package/dist/markdown/blocks/heading.d.ts.map +1 -1
  41. package/dist/markdown/blocks/heading.js.map +1 -1
  42. package/dist/markdown/blocks/horizontal-rule.d.ts +1 -1
  43. package/dist/markdown/blocks/horizontal-rule.d.ts.map +1 -1
  44. package/dist/markdown/blocks/list-line.d.ts +1 -1
  45. package/dist/markdown/blocks/list-line.d.ts.map +1 -1
  46. package/dist/markdown/blocks/list-line.js.map +1 -1
  47. package/dist/markdown/blocks/paragraph.d.ts +1 -1
  48. package/dist/markdown/blocks/paragraph.d.ts.map +1 -1
  49. package/dist/markdown/blocks/paragraph.js.map +1 -1
  50. package/dist/markdown/blocks/table.d.ts +3 -1
  51. package/dist/markdown/blocks/table.d.ts.map +1 -1
  52. package/dist/markdown/blocks/table.js +5 -3
  53. package/dist/markdown/blocks/table.js.map +1 -1
  54. package/dist/markdown/chunks.d.ts +1 -1
  55. package/dist/markdown/chunks.d.ts.map +1 -1
  56. package/dist/markdown/chunks.js +1 -1
  57. package/dist/markdown/chunks.js.map +1 -1
  58. package/dist/markdown/inline.d.ts +1 -1
  59. package/dist/markdown/inline.d.ts.map +1 -1
  60. package/dist/markdown/inline.js.map +1 -1
  61. package/dist/markdown/links.d.ts +1 -1
  62. package/dist/markdown/links.d.ts.map +1 -1
  63. package/dist/markdown/links.js.map +1 -1
  64. package/dist/markdown/plain-text.d.ts.map +1 -1
  65. package/dist/markdown/plain-text.js.map +1 -1
  66. package/dist/markdown/table-links.d.ts +10 -0
  67. package/dist/markdown/table-links.d.ts.map +1 -0
  68. package/dist/markdown/table-links.js +47 -0
  69. package/dist/markdown/table-links.js.map +1 -0
  70. package/dist/markdown/visit-inline.d.ts.map +1 -1
  71. package/dist/markdown/visit-inline.js.map +1 -1
  72. package/dist/markdown-blocks.d.ts.map +1 -1
  73. package/dist/markdown-blocks.js.map +1 -1
  74. package/dist/markdown-images.d.ts.map +1 -1
  75. package/dist/markdown-images.js.map +1 -1
  76. package/dist/markdown-view.d.ts +1 -1
  77. package/dist/markdown-view.d.ts.map +1 -1
  78. package/dist/markdown-view.js +1 -1
  79. package/dist/markdown-view.js.map +1 -1
  80. package/dist/mermaid.d.ts.map +1 -1
  81. package/dist/mermaid.js +1 -1
  82. package/dist/mermaid.js.map +1 -1
  83. package/dist/row-document-renderable.d.ts.map +1 -1
  84. package/dist/row-document-renderable.js.map +1 -1
  85. package/dist/row-document.d.ts.map +1 -1
  86. package/dist/row-document.js.map +1 -1
  87. package/dist/table.d.ts +1 -1
  88. package/dist/table.d.ts.map +1 -1
  89. package/dist/table.js +1 -1
  90. package/dist/table.js.map +1 -1
  91. package/dist/text-table-internals.d.ts +34 -0
  92. package/dist/text-table-internals.d.ts.map +1 -0
  93. package/dist/text-table-internals.js +68 -0
  94. package/dist/text-table-internals.js.map +1 -0
  95. package/dist/text-table.d.ts.map +1 -1
  96. package/dist/text-table.js +1 -1
  97. package/dist/text-table.js.map +1 -1
  98. package/dist/use-gutter-palette.d.ts.map +1 -1
  99. package/dist/use-gutter-palette.js +1 -1
  100. package/dist/use-gutter-palette.js.map +1 -1
  101. package/package.json +15 -15
  102. package/src/chooser/choose-filter.tsx +2 -1
  103. package/src/chooser/choose-highlighted-text.tsx +5 -7
  104. package/src/chooser/choose-list.tsx +7 -4
  105. package/src/chooser/choose-store.ts +2 -1
  106. package/src/chooser/chooser.tsx +2 -1
  107. package/src/chooser/fuzzy.ts +1 -0
  108. package/src/chooser/source.ts +1 -1
  109. package/src/chooser/use-choose.ts +11 -10
  110. package/src/code-blocks.tsx +6 -5
  111. package/src/code-view.tsx +3 -2
  112. package/src/command-palette.tsx +5 -4
  113. package/src/context-menu.tsx +29 -31
  114. package/src/document-bindings.ts +2 -1
  115. package/src/markdown/blocks/blockquote.tsx +2 -1
  116. package/src/markdown/blocks/flat-block.tsx +5 -4
  117. package/src/markdown/blocks/heading.tsx +3 -2
  118. package/src/markdown/blocks/horizontal-rule.tsx +1 -1
  119. package/src/markdown/blocks/list-line.tsx +3 -2
  120. package/src/markdown/blocks/paragraph.tsx +14 -14
  121. package/src/markdown/blocks/table.tsx +14 -4
  122. package/src/markdown/chunks.ts +7 -4
  123. package/src/markdown/inline.tsx +2 -1
  124. package/src/markdown/links.ts +5 -4
  125. package/src/markdown/plain-text.ts +1 -0
  126. package/src/markdown/table-links.ts +58 -0
  127. package/src/markdown/tokens.ts +1 -1
  128. package/src/markdown/visit-inline.ts +2 -1
  129. package/src/markdown-blocks.ts +5 -4
  130. package/src/markdown-images.ts +5 -4
  131. package/src/markdown-view.tsx +20 -21
  132. package/src/mermaid.ts +9 -9
  133. package/src/parsers.ts +1 -1
  134. package/src/row-document-renderable.ts +8 -7
  135. package/src/row-document.ts +1 -0
  136. package/src/source.ts +1 -1
  137. package/src/table.tsx +54 -59
  138. package/src/text-table-internals.ts +124 -0
  139. package/src/text-table.ts +1 -1
  140. package/src/use-gutter-palette.ts +3 -2
@@ -1,17 +1,18 @@
1
- import type { ReactNode, RefObject } from "react";
2
1
  import type { SyntaxStyle, TextBufferRenderable } from "@opentui/core";
3
2
  import type { ResolvedTheme } from "@tooee/themes";
3
+ import type { ReactNode, RefObject } from "react";
4
+
4
5
  import { CodeBlock } from "../../code-blocks.js";
5
6
  import type { CodeBlockRenderer } from "../../code-blocks.js";
6
7
  import type { FlatBlock } from "../../markdown-blocks.js";
8
+ import type { MarkdownLinkHandler } from "../links.js";
9
+ import { hasMarkedText, narrowToken } from "../tokens.js";
7
10
  import { BlockquoteRenderer } from "./blockquote.js";
8
11
  import { HeadingRenderer } from "./heading.js";
9
12
  import { HorizontalRule } from "./horizontal-rule.js";
10
13
  import { ListLineRenderer } from "./list-line.js";
11
14
  import { ParagraphRenderer } from "./paragraph.js";
12
15
  import { MarkdownTableRenderer } from "./table.js";
13
- import type { MarkdownLinkHandler } from "../links.js";
14
- import { hasMarkedText, narrowToken } from "../tokens.js";
15
16
 
16
17
  type CodeBlockRendererRegistry = Record<string, CodeBlockRenderer>;
17
18
 
@@ -93,7 +94,7 @@ export const FlatBlockRenderer = function FlatBlockRenderer({
93
94
  }
94
95
  const table = narrowToken(token, "table");
95
96
  if (table !== null) {
96
- return <MarkdownTableRenderer token={table} indent={indent} />;
97
+ return <MarkdownTableRenderer token={table} indent={indent} onLinkActivate={onLinkActivate} />;
97
98
  }
98
99
  if (token.type === "hr") {
99
100
  return <HorizontalRule theme={theme} indent={indent} />;
@@ -1,6 +1,7 @@
1
+ import type { ResolvedTheme } from "@tooee/themes";
1
2
  import type { Tokens } from "marked";
2
3
  import type { ReactNode } from "react";
3
- import type { ResolvedTheme } from "@tooee/themes";
4
+
4
5
  import { InlineTokens } from "../inline.js";
5
6
  import { linkMouseHandler } from "../links.js";
6
7
  import type { MarkdownLinkHandler } from "../links.js";
@@ -40,7 +41,7 @@ export const HeadingRenderer = function HeadingRenderer({
40
41
  onMouseDown={linkMouseHandler(
41
42
  token.tokens,
42
43
  onLinkActivate,
43
- Bun.stringWidth(prefixes.get(token.depth) ?? ""),
44
+ Bun.stringWidth(prefixes.get(token.depth) ?? "")
44
45
  )}
45
46
  >
46
47
  <span fg={theme.textMuted}>{prefixes.get(token.depth)}</span>
@@ -1,5 +1,5 @@
1
- import type { ReactNode } from "react";
2
1
  import type { ResolvedTheme } from "@tooee/themes";
2
+ import type { ReactNode } from "react";
3
3
 
4
4
  export const HorizontalRule = function HorizontalRule({
5
5
  theme,
@@ -1,6 +1,7 @@
1
+ import type { ResolvedTheme } from "@tooee/themes";
1
2
  import type { Token } from "marked";
2
3
  import type { ReactNode } from "react";
3
- import type { ResolvedTheme } from "@tooee/themes";
4
+
4
5
  import { checkboxMarker } from "../../markdown-blocks.js";
5
6
  import type { FlatBlock } from "../../markdown-blocks.js";
6
7
  import { InlineTokens } from "../inline.js";
@@ -38,7 +39,7 @@ export const ListLineRenderer = function ListLineRenderer({
38
39
  onMouseDown={linkMouseHandler(
39
40
  inlineTokens,
40
41
  onLinkActivate,
41
- Bun.stringWidth(`${bullet}${checkboxPrefix}`),
42
+ Bun.stringWidth(`${bullet}${checkboxPrefix}`)
42
43
  )}
43
44
  >
44
45
  <span fg={theme.markdownListItem}>{bullet}</span>
@@ -1,7 +1,8 @@
1
+ import type { ResolvedTheme } from "@tooee/themes";
1
2
  import type { Tokens } from "marked";
2
3
  import { useEffect, useState } from "react";
3
4
  import type { ReactNode } from "react";
4
- import type { ResolvedTheme } from "@tooee/themes";
5
+
5
6
  import { resolveMarkdownImageSource, splitMarkdownImages } from "../../markdown-images.js";
6
7
  import type { MarkdownImageEmbed } from "../../markdown-images.js";
7
8
  import { InlineTokens } from "../inline.js";
@@ -71,19 +72,18 @@ export const ParagraphRenderer = function ParagraphRenderer({
71
72
  marginRight: 1,
72
73
  }}
73
74
  >
74
- {segments.map(
75
- (segment, index): ReactNode =>
76
- segment.type === "image" ? (
77
- <MarkdownImage key={index} image={segment} basePath={imageBasePath} theme={theme} />
78
- ) : (
79
- <text
80
- key={index}
81
- style={{ fg: theme.markdownText }}
82
- onMouseDown={linkMouseHandler(segment.tokens, onLinkActivate)}
83
- >
84
- <InlineTokens tokens={segment.tokens} theme={theme} />
85
- </text>
86
- ),
75
+ {segments.map((segment, index): ReactNode =>
76
+ segment.type === "image" ? (
77
+ <MarkdownImage key={index} image={segment} basePath={imageBasePath} theme={theme} />
78
+ ) : (
79
+ <text
80
+ key={index}
81
+ style={{ fg: theme.markdownText }}
82
+ onMouseDown={linkMouseHandler(segment.tokens, onLinkActivate)}
83
+ >
84
+ <InlineTokens tokens={segment.tokens} theme={theme} />
85
+ </text>
86
+ )
87
87
  )}
88
88
  </box>
89
89
  );
@@ -1,18 +1,23 @@
1
- import type { Tokens } from "marked";
2
- import { useMemo } from "react";
3
- import type { ReactNode } from "react";
4
1
  import { bold as boldChunk } from "@opentui/core";
5
2
  import type { TextTableCellContent, TextTableContent } from "@opentui/core";
6
3
  import { useTheme } from "@tooee/themes";
4
+ import type { Tokens } from "marked";
5
+ import { useMemo } from "react";
6
+ import type { ReactNode } from "react";
7
+
7
8
  import { inlineTokensToChunks } from "../chunks.js";
9
+ import type { MarkdownLinkHandler } from "../links.js";
8
10
  import { getPlainText } from "../plain-text.js";
11
+ import { tableLinkMouseHandler } from "../table-links.js";
9
12
 
10
13
  export const MarkdownTableRenderer = function MarkdownTableRenderer({
11
14
  token,
12
15
  indent,
16
+ onLinkActivate,
13
17
  }: {
14
18
  token: Tokens.Table;
15
19
  indent: number;
20
+ onLinkActivate?: MarkdownLinkHandler;
16
21
  }): ReactNode {
17
22
  const { theme } = useTheme();
18
23
 
@@ -33,10 +38,14 @@ export const MarkdownTableRenderer = function MarkdownTableRenderer({
33
38
  { __isChunk: true, text: getPlainText(cell.tokens) },
34
39
  ];
35
40
  return fallbackCell;
36
- }),
41
+ })
37
42
  );
38
43
  return [headerRow, ...dataRows];
39
44
  }, [token, theme]);
45
+ const onMouseDown = useMemo(
46
+ () => tableLinkMouseHandler(content, onLinkActivate),
47
+ [content, onLinkActivate]
48
+ );
40
49
 
41
50
  return (
42
51
  <box style={{ marginBottom: 1, marginLeft: 1 + indent, marginRight: 1 }}>
@@ -49,6 +58,7 @@ export const MarkdownTableRenderer = function MarkdownTableRenderer({
49
58
  borderStyle="single"
50
59
  borderColor={theme.border}
51
60
  fg={theme.text}
61
+ onMouseDown={onMouseDown}
52
62
  />
53
63
  </box>
54
64
  );
@@ -1,4 +1,3 @@
1
- import type { Token } from "marked";
2
1
  import {
3
2
  bold as boldChunk,
4
3
  italic as italicChunk,
@@ -7,6 +6,8 @@ import {
7
6
  } from "@opentui/core";
8
7
  import type { TextChunk } from "@opentui/core";
9
8
  import type { ResolvedTheme } from "@tooee/themes";
9
+ import type { Token } from "marked";
10
+
10
11
  import { hasMarkedText } from "./tokens.js";
11
12
  import { visitInline } from "./visit-inline.js";
12
13
 
@@ -16,7 +17,7 @@ const chunk = function chunk(text: string): TextChunk {
16
17
 
17
18
  export const inlineTokensToChunks = function inlineTokensToChunks(
18
19
  tokens: readonly Token[],
19
- theme: ResolvedTheme,
20
+ theme: ResolvedTheme
20
21
  ): TextChunk[] {
21
22
  return visitInline<TextChunk>(tokens, {
22
23
  br: () => [],
@@ -33,8 +34,10 @@ export const inlineTokensToChunks = function inlineTokensToChunks(
33
34
  escape: (token) => [chunk(token.text)],
34
35
  fallback: (token) => (hasMarkedText(token) ? [chunk(token.text)] : []),
35
36
  image: (token) => [chunk(token.text)],
36
- link: (_token, children) =>
37
- children.map((child) => underlineChunk({ ...child, fg: parseColor(theme.markdownLink) })),
37
+ link: (token, children) =>
38
+ children.map((child) =>
39
+ underlineChunk({ ...child, fg: parseColor(theme.markdownLink), link: { url: token.href } })
40
+ ),
38
41
  space: () => [],
39
42
  strong: (_token, children) => children.map((child) => boldChunk(child)),
40
43
  text: (token) => [chunk(token.text)],
@@ -1,6 +1,7 @@
1
+ import type { ResolvedTheme } from "@tooee/themes";
1
2
  import type { Token } from "marked";
2
3
  import type { ReactNode } from "react";
3
- import type { ResolvedTheme } from "@tooee/themes";
4
+
4
5
  import { hasMarkedText, normalizeSoftLineEndings } from "./tokens.js";
5
6
  import { visitInline } from "./visit-inline.js";
6
7
 
@@ -1,5 +1,6 @@
1
- import type { Token } from "marked";
2
1
  import type { MouseEvent, TextBufferRenderable } from "@opentui/core";
2
+ import type { Token } from "marked";
3
+
3
4
  import { hasMarkedText, narrowToken, normalizeSoftLineEndings } from "./tokens.js";
4
5
 
5
6
  // oxlint-disable-next-line anti-slop/no-unknown-returns -- public host callback accepts any ignored result; only literal true marks a handled link
@@ -14,7 +15,7 @@ export interface InlineLinkPosition {
14
15
  export const inlineLinkAtPosition = function inlineLinkAtPosition(
15
16
  tokens: readonly Token[],
16
17
  position: InlineLinkPosition,
17
- initialColumn = 0,
18
+ initialColumn = 0
18
19
  ): string | null {
19
20
  let line = 0;
20
21
  let column = initialColumn;
@@ -94,7 +95,7 @@ export const inlineLinkAtPosition = function inlineLinkAtPosition(
94
95
  export const linkMouseHandler = function linkMouseHandler(
95
96
  tokens: readonly Token[],
96
97
  onLinkActivate: MarkdownLinkHandler | undefined,
97
- initialColumn = 0,
98
+ initialColumn = 0
98
99
  ): ((event: MouseEvent) => void) | undefined {
99
100
  if (onLinkActivate === undefined) {
100
101
  return undefined;
@@ -122,7 +123,7 @@ export const linkMouseHandler = function linkMouseHandler(
122
123
  column: startColumn + event.x - text.x,
123
124
  line: sourceLine,
124
125
  },
125
- initialColumn,
126
+ initialColumn
126
127
  );
127
128
  if (href === null || onLinkActivate(href) !== true) {
128
129
  return;
@@ -1,4 +1,5 @@
1
1
  import type { Token } from "marked";
2
+
2
3
  import { hasMarkedText, narrowToken } from "./tokens.js";
3
4
 
4
5
  /** Extract unstyled inline text for table-cell fallback content. */
@@ -0,0 +1,58 @@
1
+ import type { MouseEvent, TextChunk, TextTableContent } from "@opentui/core";
2
+
3
+ import { textTableCellAt } from "../text-table-internals.js";
4
+ import type { MarkdownLinkHandler } from "./links.js";
5
+
6
+ /** The OSC 8 link URL of the chunk at a text position in one table cell. */
7
+ export const chunkLinkAt = function chunkLinkAt(
8
+ chunks: readonly TextChunk[],
9
+ line: number,
10
+ offset: number
11
+ ): string | null {
12
+ let currentLine = 0;
13
+ let column = 0;
14
+ for (const chunk of chunks) {
15
+ const parts = chunk.text.split("\n");
16
+ for (const [index, part] of parts.entries()) {
17
+ const width = Bun.stringWidth(part);
18
+ if (currentLine === line && offset >= column && offset < column + width) {
19
+ return chunk.link?.url ?? null;
20
+ }
21
+ column += width;
22
+ if (index < parts.length - 1) {
23
+ currentLine += 1;
24
+ column = 0;
25
+ }
26
+ }
27
+ }
28
+ return null;
29
+ };
30
+
31
+ /**
32
+ * Primary-click handler for a Markdown table. It activates the link under the pointer and
33
+ * consumes the event only when the host handler returns literal true.
34
+ */
35
+ export const tableLinkMouseHandler = function tableLinkMouseHandler(
36
+ content: TextTableContent,
37
+ onLinkActivate?: MarkdownLinkHandler
38
+ ): ((event: MouseEvent) => void) | undefined {
39
+ if (onLinkActivate === undefined) {
40
+ return undefined;
41
+ }
42
+ return (event: MouseEvent): void => {
43
+ if (event.button !== 0 || event.target === null) {
44
+ return;
45
+ }
46
+ const hit = textTableCellAt(event.target, event.x, event.y);
47
+ const chunks = hit === null ? null : content[hit.row]?.[hit.column];
48
+ if (hit === null || chunks === null || chunks === undefined) {
49
+ return;
50
+ }
51
+ const href = chunkLinkAt(chunks, hit.line, hit.offset);
52
+ if (href === null || onLinkActivate(href) !== true) {
53
+ return;
54
+ }
55
+ event.preventDefault();
56
+ event.stopPropagation();
57
+ };
58
+ };
@@ -28,7 +28,7 @@ export interface MarkedText {
28
28
  */
29
29
  export const narrowToken = function narrowToken<Type extends keyof KnownTokenByType>(
30
30
  token: Token,
31
- type: Type,
31
+ type: Type
32
32
  ): KnownTokenByType[Type] | null {
33
33
  if (token.type !== type) {
34
34
  return null;
@@ -1,4 +1,5 @@
1
1
  import type { Token, Tokens } from "marked";
2
+
2
3
  import { narrowToken } from "./tokens.js";
3
4
 
4
5
  export interface InlineVisitorSink<Result> {
@@ -19,7 +20,7 @@ export interface InlineVisitorSink<Result> {
19
20
  export const visitInline = function visitInline<Result>(
20
21
  tokens: readonly Token[],
21
22
  sink: InlineVisitorSink<Result>,
22
- keyPrefix = "",
23
+ keyPrefix = ""
23
24
  ): Result[] {
24
25
  const result: Result[] = [];
25
26
 
@@ -1,5 +1,6 @@
1
1
  import { marked } from "marked";
2
2
  import type { Token, Tokens } from "marked";
3
+
3
4
  import { SourceIndex } from "./source.js";
4
5
  import type { DocumentRowSource } from "./source.js";
5
6
 
@@ -206,7 +207,7 @@ const flattenList = function flattenList(
206
207
  indent: number,
207
208
  out: FlatBlock[],
208
209
  res: MarkdownResolver | null,
209
- bound: number,
210
+ bound: number
210
211
  ): void {
211
212
  for (let i = 0; i < list.items.length; i += 1) {
212
213
  const item = list.items[i];
@@ -239,7 +240,7 @@ const flattenListItem = function flattenListItem(
239
240
  out: FlatBlock[],
240
241
  res: MarkdownResolver | null,
241
242
  itemStart: number | null,
242
- itemEnd: number,
243
+ itemEnd: number
243
244
  ): void {
244
245
  const checked = item.checked === null ? undefined : item.checked;
245
246
  const childTokens = item.tokens;
@@ -302,7 +303,7 @@ const flattenWalk = function flattenWalk(
302
303
  indent: number,
303
304
  out: FlatBlock[],
304
305
  res: MarkdownResolver | null,
305
- bound: number,
306
+ bound: number
306
307
  ): void {
307
308
  for (const token of tokens) {
308
309
  if (token.type === "space") {
@@ -329,7 +330,7 @@ const flattenWalk = function flattenWalk(
329
330
  */
330
331
  export const flattenMarkdown = function flattenMarkdown(
331
332
  markdown: string,
332
- options?: FlattenMarkdownOptions,
333
+ options?: FlattenMarkdownOptions
333
334
  ): FlatBlock[] {
334
335
  const res = new MarkdownResolver(markdown, options?.sourceId);
335
336
  const out: FlatBlock[] = [];
@@ -1,4 +1,5 @@
1
1
  import path from "node:path";
2
+
2
3
  import type { Token, Tokens } from "marked";
3
4
 
4
5
  const OBSIDIAN_IMAGE_EMBED = /!\[\[(?<target>[^\]|]+)(?:\|(?<display>[^\]]+))?\]\]/gu;
@@ -18,7 +19,7 @@ export type MarkdownInlineSegment =
18
19
 
19
20
  const obsidianEmbed = function obsidianEmbed(
20
21
  target: string,
21
- display: string | undefined,
22
+ display: string | undefined
22
23
  ): MarkdownImageEmbed {
23
24
  const source = target.trim();
24
25
  const dimensions = display?.trim().match(IMAGE_DIMENSIONS);
@@ -35,7 +36,7 @@ const obsidianEmbed = function obsidianEmbed(
35
36
 
36
37
  /** Parse a complete Obsidian image embed such as `![[cover.png|40x12]]`. */
37
38
  export const parseObsidianImageEmbed = function parseObsidianImageEmbed(
38
- value: string,
39
+ value: string
39
40
  ): MarkdownImageEmbed | null {
40
41
  const match = /^!\[\[(?<target>[^\]|]+)(?:\|(?<display>[^\]]+))?\]\]$/u.exec(value.trim());
41
42
  if (match?.groups?.target === undefined) {
@@ -80,7 +81,7 @@ const splitTextToken = function splitTextToken(text: string): MarkdownInlineSegm
80
81
 
81
82
  /** Split paragraph tokens into text and native-image render segments. */
82
83
  export const splitMarkdownImages = function splitMarkdownImages(
83
- tokens: readonly Token[],
84
+ tokens: readonly Token[]
84
85
  ): MarkdownInlineSegment[] {
85
86
  const result: MarkdownInlineSegment[] = [];
86
87
  let pendingText: Token[] = [];
@@ -129,7 +130,7 @@ export const splitMarkdownImages = function splitMarkdownImages(
129
130
  /** Resolve relative image links against the Markdown document directory. */
130
131
  export const resolveMarkdownImageSource = function resolveMarkdownImageSource(
131
132
  source: string,
132
- basePath?: string,
133
+ basePath?: string
133
134
  ): string {
134
135
  if (path.isAbsolute(source) || URL_SCHEME.test(source)) {
135
136
  return source;
@@ -1,8 +1,9 @@
1
- import { useMemo } from "react";
2
- import type { ReactNode, RefObject } from "react";
3
1
  import type { TextBufferRenderable } from "@opentui/core";
4
2
  import { useTerminalDimensions } from "@opentui/react";
5
3
  import { useTheme } from "@tooee/themes";
4
+ import { useMemo } from "react";
5
+ import type { ReactNode, RefObject } from "react";
6
+
6
7
  import { DEFAULT_CODE_BLOCK_RENDERERS } from "./code-blocks.js";
7
8
  import type { CodeBlockRenderer } from "./code-blocks.js";
8
9
  import type { DocumentBindings } from "./document-bindings.js";
@@ -74,7 +75,7 @@ export const MarkdownView = function MarkdownView({
74
75
  const { width: terminalWidth } = useTerminalDimensions();
75
76
  const blocks = useMemo(
76
77
  () => providedBlocks ?? flattenMarkdown(content),
77
- [providedBlocks, content],
78
+ [providedBlocks, content]
78
79
  );
79
80
 
80
81
  const contentWidth = Math.max(
@@ -85,7 +86,7 @@ export const MarkdownView = function MarkdownView({
85
86
  showLineNumbers,
86
87
  signColumnWidth: DEFAULT_SIGN_COLUMN_WIDTH,
87
88
  }) -
88
- MARKDOWN_SCROLLBAR_RESERVE,
89
+ MARKDOWN_SCROLLBAR_RESERVE
89
90
  );
90
91
 
91
92
  const mergedCodeBlockRenderers = useMemo(() => {
@@ -98,22 +99,20 @@ export const MarkdownView = function MarkdownView({
98
99
 
99
100
  const blockElements = useMemo(
100
101
  () =>
101
- blocks.map(
102
- (block, index): ReactNode => (
103
- <FlatBlockRenderer
104
- key={index}
105
- block={block}
106
- blockIndex={index}
107
- theme={theme}
108
- syntax={syntax}
109
- contentWidth={contentWidth}
110
- hScrollableBlocksRef={hScrollableBlocksRef}
111
- codeBlockRenderers={mergedCodeBlockRenderers}
112
- onLinkActivate={onLinkActivate}
113
- imageBasePath={imageBasePath}
114
- />
115
- ),
116
- ),
102
+ blocks.map((block, index): ReactNode => (
103
+ <FlatBlockRenderer
104
+ key={index}
105
+ block={block}
106
+ blockIndex={index}
107
+ theme={theme}
108
+ syntax={syntax}
109
+ contentWidth={contentWidth}
110
+ hScrollableBlocksRef={hScrollableBlocksRef}
111
+ codeBlockRenderers={mergedCodeBlockRenderers}
112
+ onLinkActivate={onLinkActivate}
113
+ imageBasePath={imageBasePath}
114
+ />
115
+ )),
117
116
  [
118
117
  blocks,
119
118
  theme,
@@ -123,7 +122,7 @@ export const MarkdownView = function MarkdownView({
123
122
  mergedCodeBlockRenderers,
124
123
  onLinkActivate,
125
124
  imageBasePath,
126
- ],
125
+ ]
127
126
  );
128
127
 
129
128
  return (
package/src/mermaid.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { parseMermaid, renderMermaidASCII } from "beautiful-mermaid";
2
1
  import { parseColor, StyledText } from "@opentui/core";
3
2
  import type { TextChunk } from "@opentui/core";
3
+ import { parseMermaid, renderMermaidASCII } from "beautiful-mermaid";
4
4
 
5
5
  interface BeautifulMermaidAsciiTheme {
6
6
  fg?: string;
@@ -52,7 +52,7 @@ export const isMermaidFence = function isMermaidFence(lang?: string): boolean {
52
52
  const hasDirectedPath = function hasDirectedPath(
53
53
  adjacency: Map<string, Set<string>>,
54
54
  source: string,
55
- target: string,
55
+ target: string
56
56
  ): boolean {
57
57
  const pending = [...(adjacency.get(source) ?? [])];
58
58
  const visited = new Set<string>([source]);
@@ -77,7 +77,7 @@ const hasDirectedPath = function hasDirectedPath(
77
77
  };
78
78
 
79
79
  const hasUnsafeCyclicFanTopology = function hasUnsafeCyclicFanTopology(
80
- edges: ReturnType<typeof parseMermaid>["edges"],
80
+ edges: ReturnType<typeof parseMermaid>["edges"]
81
81
  ): boolean {
82
82
  const adjacency = new Map<string, Set<string>>();
83
83
  const incomingDegree = new Map<string, number>();
@@ -101,13 +101,13 @@ const hasUnsafeCyclicFanTopology = function hasUnsafeCyclicFanTopology(
101
101
  return fanInNodes.some((fanIn) =>
102
102
  fanOutNodes.some(
103
103
  (fanOut) =>
104
- hasDirectedPath(adjacency, fanIn, fanOut) && hasDirectedPath(adjacency, fanOut, fanIn),
105
- ),
104
+ hasDirectedPath(adjacency, fanIn, fanOut) && hasDirectedPath(adjacency, fanOut, fanIn)
105
+ )
106
106
  );
107
107
  };
108
108
 
109
109
  const exceedsSynchronousRenderBudget = function exceedsSynchronousRenderBudget(
110
- source: string,
110
+ source: string
111
111
  ): boolean {
112
112
  if (source.length > MAX_SOURCE_LENGTH || source.split("\n").length > MAX_SOURCE_LINES) {
113
113
  return true;
@@ -127,7 +127,7 @@ const exceedsSynchronousRenderBudget = function exceedsSynchronousRenderBudget(
127
127
  const appendStyledChunk = function appendStyledChunk(
128
128
  chunks: TextChunk[],
129
129
  text: string,
130
- fg?: string,
130
+ fg?: string
131
131
  ) {
132
132
  if (text.length === 0) {
133
133
  return;
@@ -149,7 +149,7 @@ const sgrParams = function sgrParams(rawParams: string): number[] {
149
149
 
150
150
  const updateAnsiForeground = function updateAnsiForeground(
151
151
  params: number[],
152
- currentFg: string | undefined,
152
+ currentFg: string | undefined
153
153
  ): string | undefined {
154
154
  let fg = currentFg;
155
155
 
@@ -216,7 +216,7 @@ export const ansiToStyledText = function ansiToStyledText(input: string): AnsiSt
216
216
  */
217
217
  export const renderMermaidForTerminal = function renderMermaidForTerminal(
218
218
  source: string,
219
- options: MermaidRenderOptions = {},
219
+ options: MermaidRenderOptions = {}
220
220
  ): MermaidRenderResult {
221
221
  if (source.trim().length === 0) {
222
222
  return { message: "Mermaid block is empty", ok: false, reason: "empty" };
package/src/parsers.ts CHANGED
@@ -134,7 +134,7 @@ export const parseTSV = function parseTSV(input: string): TableData {
134
134
  const columns = createColumnDefs(lines[0].split("\t"));
135
135
  const rows = buildRows(
136
136
  columns,
137
- lines.slice(1).map((line) => line.split("\t")),
137
+ lines.slice(1).map((line) => line.split("\t"))
138
138
  );
139
139
  return { columns, rows };
140
140
  };
@@ -6,6 +6,7 @@ import type {
6
6
  OptimizedBuffer,
7
7
  Renderable,
8
8
  } from "@opentui/core";
9
+
9
10
  import type { DecorationLayer, RowDecoration } from "./decoration-layer.js";
10
11
 
11
12
  // ---------------------------------------------------------------------------
@@ -49,7 +50,7 @@ export interface RowDocumentOptions extends ScrollBoxOptions {
49
50
  // ---------------------------------------------------------------------------
50
51
 
51
52
  const isRowContentProvider = function isRowContentProvider(
52
- renderable: Renderable,
53
+ renderable: Renderable
53
54
  ): renderable is Renderable & LineInfoProvider {
54
55
  return "lineInfo" in renderable && "lineCount" in renderable && "virtualLineCount" in renderable;
55
56
  };
@@ -70,7 +71,7 @@ const cachedColor = function cachedColor(hex: string): RGBA {
70
71
  };
71
72
 
72
73
  const normalizePalette = function normalizePalette(
73
- palette: RowDocumentPalette = {},
74
+ palette: RowDocumentPalette = {}
74
75
  ): Required<RowDocumentPalette> {
75
76
  return {
76
77
  gutterBg: palette.gutterBg ?? "#0d1117",
@@ -79,7 +80,7 @@ const normalizePalette = function normalizePalette(
79
80
  };
80
81
 
81
82
  const normalizeDecorationLayers = function normalizeDecorationLayers(
82
- layers: readonly DecorationLayer[] | undefined,
83
+ layers: readonly DecorationLayer[] | undefined
83
84
  ): readonly DecorationLayer[] {
84
85
  if (!layers || layers.length === 0) {
85
86
  return [];
@@ -433,7 +434,7 @@ export class RowDocumentRenderable extends ScrollBoxRenderable {
433
434
  rowVirtualHeights,
434
435
  virtualRowToRow,
435
436
  virtualRowWraps,
436
- rowCount,
437
+ rowCount
437
438
  );
438
439
  }
439
440
 
@@ -485,7 +486,7 @@ export class RowDocumentRenderable extends ScrollBoxRenderable {
485
486
  rowVirtualHeights,
486
487
  virtualRowToRow,
487
488
  virtualRowWraps,
488
- rowCount,
489
+ rowCount
489
490
  );
490
491
  }
491
492
 
@@ -494,7 +495,7 @@ export class RowDocumentRenderable extends ScrollBoxRenderable {
494
495
  rowVirtualHeights: number[],
495
496
  virtualRowToRow: number[],
496
497
  virtualRowWraps: number[],
497
- rowCount: number,
498
+ rowCount: number
498
499
  ): void {
499
500
  let contentVirtualEnd = 0;
500
501
  for (let row = 0; row < rowCount; row += 1) {
@@ -669,7 +670,7 @@ export class RowDocumentRenderable extends ScrollBoxRenderable {
669
670
  drawX + col,
670
671
  vpY + screenY,
671
672
  signFg,
672
- effectiveGutterBg,
673
+ effectiveGutterBg
673
674
  );
674
675
  }
675
676
  }
@@ -1,4 +1,5 @@
1
1
  import { extend } from "@opentui/react";
2
+
2
3
  import { RowDocumentRenderable } from "./row-document-renderable.js";
3
4
 
4
5
  extend({ "row-document": RowDocumentRenderable });
package/src/source.ts CHANGED
@@ -175,7 +175,7 @@ export interface SourceLineRow {
175
175
  */
176
176
  export const sourceLines = function sourceLines(
177
177
  source: string,
178
- options?: { sourceId?: string },
178
+ options?: { sourceId?: string }
179
179
  ): SourceLineRow[] {
180
180
  const index = new SourceIndex(source, options?.sourceId);
181
181
  const rows: SourceLineRow[] = [];