markstream-solid 0.0.0-stage → 2.0.23
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/README.md +120 -2
- package/dist/client/extended-BTbixd9o.js +38 -0
- package/dist/client/index.js +5640 -0
- package/dist/client/katexWorkerClient-ZLzkPVv_.js +260 -0
- package/dist/client/languageIcon-CDTPjsAQ.js +280 -0
- package/dist/client/mermaidWorkerClient-BAvGYsCO.js +243 -0
- package/dist/client/utils/index.js +31 -0
- package/dist/client/utils/katex-threshold.js +32 -0
- package/dist/client/utils/performance-monitor.js +73 -0
- package/dist/client/utils/safeRaf.js +27 -0
- package/dist/client/workers/katexCdnWorker.js +177 -0
- package/dist/client/workers/katexRenderer.worker.js +45 -0
- package/dist/client/workers/katexWorkerClient.js +16 -0
- package/dist/client/workers/mermaidCdnWorker.js +226 -0
- package/dist/client/workers/mermaidParser.worker.js +73 -0
- package/dist/client/workers/mermaidWorkerClient.js +13 -0
- package/dist/components/BuiltinNodes.d.ts +42 -0
- package/dist/components/CodeBlockNode.d.ts +10 -0
- package/dist/components/DiagramBlockNode.d.ts +27 -0
- package/dist/components/HtmlPreviewFrame.d.ts +10 -0
- package/dist/components/MarkstreamProvider.d.ts +5 -0
- package/dist/components/MarkstreamVirtualTimeline.d.ts +35 -0
- package/dist/components/MathNode.d.ts +6 -0
- package/dist/components/NodeRenderer.d.ts +27 -0
- package/dist/components/NodeSlot.d.ts +11 -0
- package/dist/components/PreCodeBlock.d.ts +3 -0
- package/dist/components/PreCodeNode.d.ts +9 -0
- package/dist/components/RenderNode.d.ts +11 -0
- package/dist/components/StreamingTextNode.d.ts +2 -0
- package/dist/components/ToolbarButton.d.ts +14 -0
- package/dist/components/ToolbarIcon.d.ts +18 -0
- package/dist/components/Tooltip.d.ts +13 -0
- package/dist/components/lifecycle.d.ts +6 -0
- package/dist/components/mathHeightCache.d.ts +5 -0
- package/dist/components/rendererModeDefaults.d.ts +4 -0
- package/dist/components/shared/diagram-height.d.ts +16 -0
- package/dist/components/shared/node-helpers.d.ts +78 -0
- package/dist/components/shared/node-outlet-helpers.d.ts +10 -0
- package/dist/components/shared/render-window.d.ts +18 -0
- package/dist/components/shared/reuseParsedNodes.d.ts +3 -0
- package/dist/components/viewport.d.ts +5 -0
- package/dist/components/virtualLayoutKey.d.ts +13 -0
- package/dist/configuration.d.ts +9 -0
- package/dist/customComponents.d.ts +36 -0
- package/dist/enhanceRenderedHtml.d.ts +25 -0
- package/dist/hydrateCustomTagContent.d.ts +2 -0
- package/dist/i18n/useSafeI18n.d.ts +4 -0
- package/dist/icon-themes/index.d.ts +2 -0
- package/dist/icon-themes/material/core.d.ts +2 -0
- package/dist/icon-themes/material/extended.d.ts +2 -0
- package/dist/icon-themes/material/index.d.ts +2 -0
- package/dist/icon-themes/registry.d.ts +9 -0
- package/dist/icon-themes/types.d.ts +11 -0
- package/dist/index.css +3279 -0
- package/dist/index.d.ts +48 -0
- package/dist/index.px.css +3279 -0
- package/dist/index.tailwind.css +3279 -0
- package/dist/optional/d2.d.ts +17 -0
- package/dist/optional/infographic.d.ts +31 -0
- package/dist/optional/katex.d.ts +9 -0
- package/dist/optional/mermaid.d.ts +27 -0
- package/dist/optional/streamDiffs.d.ts +29 -0
- package/dist/renderMarkdownHtml.d.ts +30 -0
- package/dist/sanitizeHtmlContent.d.ts +2 -0
- package/dist/server/extended-CKyCqQt3.js +69 -0
- package/dist/server/index.js +6264 -0
- package/dist/server/languageIcon-TXkIEBPf.js +353 -0
- package/dist/server/utils/index.js +31 -0
- package/dist/server/utils/katex-threshold.js +41 -0
- package/dist/server/utils/performance-monitor.js +120 -0
- package/dist/server/utils/safeRaf.js +28 -0
- package/dist/server/workers/katexCdnWorker.js +190 -0
- package/dist/server/workers/katexWorkerClient.js +373 -0
- package/dist/server/workers/mermaidCdnWorker.js +238 -0
- package/dist/server/workers/mermaidWorkerClient.js +333 -0
- package/dist/streamDiffsWorker.d.ts +72 -0
- package/dist/tailwind.d.ts +2 -0
- package/dist/tailwind.js +3 -0
- package/dist/tooltip/singletonTooltip.d.ts +7 -0
- package/dist/types/component-props.d.ts +253 -0
- package/dist/types/node-renderer-props.d.ts +333 -0
- package/dist/useSmoothMarkdownStream.d.ts +22 -0
- package/dist/utils/clipboard.d.ts +1 -0
- package/dist/utils/d2RenderSalt.d.ts +1 -0
- package/dist/utils/footnoteTarget.d.ts +1 -0
- package/dist/utils/index.d.ts +8 -0
- package/dist/utils/katex-threshold.d.ts +20 -0
- package/dist/utils/languageIcon.d.ts +8 -0
- package/dist/utils/mermaidRenderId.d.ts +1 -0
- package/dist/utils/normalizeKaTeXRenderInput.d.ts +1 -0
- package/dist/utils/performance-monitor.d.ts +121 -0
- package/dist/utils/resolveLanguageIcon.d.ts +2 -0
- package/dist/utils/safeRaf.d.ts +2 -0
- package/dist/utils/virtualItemMeasurement.d.ts +5 -0
- package/dist/virtual-adapter.d.ts +165 -0
- package/dist/workers/katexCdnWorker.d.ts +20 -0
- package/dist/workers/katexRenderer.worker.d.ts +1 -0
- package/dist/workers/katexWorkerClient.d.ts +35 -0
- package/dist/workers/mermaidCdnWorker.d.ts +15 -0
- package/dist/workers/mermaidParser.worker.d.ts +1 -0
- package/dist/workers/mermaidWorkerClient.d.ts +15 -0
- package/package.json +149 -3
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
import type { CodeBlockNode } from 'stream-markdown-parser';
|
|
2
|
+
export interface CodeBlockThemePair {
|
|
3
|
+
dark: string;
|
|
4
|
+
light: string;
|
|
5
|
+
}
|
|
6
|
+
export type CodeBlockTheme = string;
|
|
7
|
+
export type CodeBlockThemeProp = CodeBlockTheme | CodeBlockThemePair;
|
|
8
|
+
export type CodeBlockThemes = readonly [dark: CodeBlockTheme, light: CodeBlockTheme];
|
|
9
|
+
export interface CommonCodeBlockProps {
|
|
10
|
+
showHeader?: boolean;
|
|
11
|
+
showCopyButton?: boolean;
|
|
12
|
+
showExpandButton?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export interface CodeBlockDiffHideUnchangedRegionsOptions {
|
|
15
|
+
enabled?: boolean;
|
|
16
|
+
contextLineCount?: number;
|
|
17
|
+
minimumLineCount?: number;
|
|
18
|
+
revealLineCount?: number;
|
|
19
|
+
}
|
|
20
|
+
export type CodeBlockDiffHideUnchangedRegions = boolean | CodeBlockDiffHideUnchangedRegionsOptions;
|
|
21
|
+
export interface CodeBlockOptions {
|
|
22
|
+
fontSize?: number;
|
|
23
|
+
lineHeight?: number;
|
|
24
|
+
fontFamily?: string;
|
|
25
|
+
maxHeight?: number;
|
|
26
|
+
padding?: number;
|
|
27
|
+
tabSize?: number;
|
|
28
|
+
disableLineNumbers?: boolean;
|
|
29
|
+
overflow?: 'scroll' | 'wrap';
|
|
30
|
+
disableVirtualizationBuffers?: boolean;
|
|
31
|
+
useCSSClasses?: boolean;
|
|
32
|
+
useTokenTransformer?: boolean;
|
|
33
|
+
tokenizeMaxLineLength?: number;
|
|
34
|
+
tokenizeMaxLength?: number;
|
|
35
|
+
unsafeCSS?: string;
|
|
36
|
+
diffStyle?: 'unified' | 'split';
|
|
37
|
+
diffIndicators?: 'classic' | 'bars' | 'none';
|
|
38
|
+
disableBackground?: boolean;
|
|
39
|
+
hunkSeparators?: 'simple' | 'metadata' | 'line-info' | 'line-info-basic';
|
|
40
|
+
expandUnchanged?: boolean;
|
|
41
|
+
collapsedContextThreshold?: number;
|
|
42
|
+
lineDiffType?: 'word-alt' | 'word' | 'char' | 'none';
|
|
43
|
+
maxLineDiffLength?: number;
|
|
44
|
+
expansionLineCount?: number;
|
|
45
|
+
parseDiffOptions?: Record<string, unknown>;
|
|
46
|
+
lineHoverHighlight?: 'disabled' | 'both' | 'number' | 'line';
|
|
47
|
+
enableTokenInteractionsOnWhitespace?: boolean;
|
|
48
|
+
enableGutterUtility?: boolean;
|
|
49
|
+
enableLineSelection?: boolean;
|
|
50
|
+
controlledSelection?: boolean;
|
|
51
|
+
onGutterUtilityClick?: (...args: any[]) => unknown;
|
|
52
|
+
onLineClick?: (...args: any[]) => unknown;
|
|
53
|
+
onLineNumberClick?: (...args: any[]) => unknown;
|
|
54
|
+
onLineEnter?: (...args: any[]) => unknown;
|
|
55
|
+
onLineLeave?: (...args: any[]) => unknown;
|
|
56
|
+
onTokenClick?: (...args: any[]) => unknown;
|
|
57
|
+
onTokenEnter?: (...args: any[]) => unknown;
|
|
58
|
+
onTokenLeave?: (...args: any[]) => unknown;
|
|
59
|
+
onLineSelected?: (...args: any[]) => unknown;
|
|
60
|
+
onLineSelectionStart?: (...args: any[]) => unknown;
|
|
61
|
+
onLineSelectionChange?: (...args: any[]) => unknown;
|
|
62
|
+
onLineSelectionEnd?: (...args: any[]) => unknown;
|
|
63
|
+
getLineIndex?: (...args: any[]) => unknown;
|
|
64
|
+
renderAnnotation?: (...args: any[]) => unknown;
|
|
65
|
+
renderGutterUtility?: (...args: any[]) => unknown;
|
|
66
|
+
onPostRender?: (...args: any[]) => unknown;
|
|
67
|
+
mergeConflict?: boolean;
|
|
68
|
+
lineAnnotations?: unknown[];
|
|
69
|
+
onController?: (controller: any) => void;
|
|
70
|
+
workerManager?: unknown;
|
|
71
|
+
}
|
|
72
|
+
export interface CodeBlockNodeProps extends CommonCodeBlockProps {
|
|
73
|
+
node: CodeBlockNode;
|
|
74
|
+
codeBlockOptions?: CodeBlockOptions;
|
|
75
|
+
/** Overrides browser clipboard writes. Copy feedback and events wait for completion. */
|
|
76
|
+
clipboardWriter?: (text: string) => void | Promise<void>;
|
|
77
|
+
showLineNumbers?: boolean;
|
|
78
|
+
isDark?: boolean;
|
|
79
|
+
loading?: boolean;
|
|
80
|
+
stream?: boolean;
|
|
81
|
+
theme?: CodeBlockThemeProp;
|
|
82
|
+
/** @deprecated Use `theme` prop instead. Kept for backward compatibility. */
|
|
83
|
+
darkTheme?: CodeBlockTheme;
|
|
84
|
+
/** @deprecated Use `theme` prop instead. Kept for backward compatibility. */
|
|
85
|
+
lightTheme?: CodeBlockTheme;
|
|
86
|
+
isShowPreview?: boolean;
|
|
87
|
+
enableFontSizeControl?: boolean;
|
|
88
|
+
minWidth?: string | number;
|
|
89
|
+
maxWidth?: string | number;
|
|
90
|
+
themes?: CodeBlockThemes;
|
|
91
|
+
showPreviewButton?: boolean;
|
|
92
|
+
showCollapseButton?: boolean;
|
|
93
|
+
showFontSizeButtons?: boolean;
|
|
94
|
+
showTooltips?: boolean;
|
|
95
|
+
htmlPreviewAllowScripts?: boolean;
|
|
96
|
+
htmlPreviewSandbox?: string;
|
|
97
|
+
customId?: string;
|
|
98
|
+
}
|
|
99
|
+
export interface ImageNodeProps {
|
|
100
|
+
node: {
|
|
101
|
+
type: 'image';
|
|
102
|
+
src: string;
|
|
103
|
+
alt: string;
|
|
104
|
+
title: string | null;
|
|
105
|
+
raw: string;
|
|
106
|
+
loading?: boolean;
|
|
107
|
+
};
|
|
108
|
+
fallbackSrc?: string;
|
|
109
|
+
lazy?: boolean;
|
|
110
|
+
usePlaceholder?: boolean;
|
|
111
|
+
}
|
|
112
|
+
export interface LinkNodeProps {
|
|
113
|
+
node: {
|
|
114
|
+
type: 'link';
|
|
115
|
+
href: string;
|
|
116
|
+
title: string | null;
|
|
117
|
+
text: string;
|
|
118
|
+
attrs?: [string, string][];
|
|
119
|
+
children: {
|
|
120
|
+
type: string;
|
|
121
|
+
raw: string;
|
|
122
|
+
}[];
|
|
123
|
+
raw: string;
|
|
124
|
+
loading?: boolean;
|
|
125
|
+
/** `'linkify'` marks links auto-detected from bare text. */
|
|
126
|
+
markup?: string;
|
|
127
|
+
};
|
|
128
|
+
indexKey: number | string;
|
|
129
|
+
customId?: string;
|
|
130
|
+
showTooltip?: boolean;
|
|
131
|
+
color?: string;
|
|
132
|
+
underlineHeight?: number;
|
|
133
|
+
underlineBottom?: number | string;
|
|
134
|
+
animationDuration?: number;
|
|
135
|
+
animationOpacity?: number;
|
|
136
|
+
animationTiming?: string;
|
|
137
|
+
animationIteration?: string | number;
|
|
138
|
+
}
|
|
139
|
+
export interface ReferenceNodeProps {
|
|
140
|
+
node: {
|
|
141
|
+
type: 'reference';
|
|
142
|
+
id: string | number;
|
|
143
|
+
raw?: string;
|
|
144
|
+
};
|
|
145
|
+
messageId?: string;
|
|
146
|
+
threadId?: string;
|
|
147
|
+
onClick?: (event: MouseEvent, id: string, messageId?: string, threadId?: string) => void;
|
|
148
|
+
onMouseEnter?: (event: MouseEvent, id: string, messageId?: string, threadId?: string) => void;
|
|
149
|
+
onMouseLeave?: (event: MouseEvent, id: string, messageId?: string, threadId?: string) => void;
|
|
150
|
+
}
|
|
151
|
+
export interface PreCodeNodeProps {
|
|
152
|
+
node: CodeBlockNode;
|
|
153
|
+
loading?: boolean;
|
|
154
|
+
showLineNumbers?: boolean;
|
|
155
|
+
diffInline?: boolean;
|
|
156
|
+
diffHideUnchangedRegions?: CodeBlockDiffHideUnchangedRegions;
|
|
157
|
+
/**
|
|
158
|
+
* Optional reserved visual height for async/loading fallbacks.
|
|
159
|
+
* Used by virtual-scroll restore paths to avoid a zero/short pending frame.
|
|
160
|
+
*/
|
|
161
|
+
reservedHeightPx?: number;
|
|
162
|
+
}
|
|
163
|
+
export interface MermaidBlockNodeProps {
|
|
164
|
+
node: CodeBlockNode;
|
|
165
|
+
maxHeight?: string | null;
|
|
166
|
+
estimatedPreviewHeightPx?: number;
|
|
167
|
+
loading?: boolean;
|
|
168
|
+
isDark?: boolean;
|
|
169
|
+
workerTimeoutMs?: number;
|
|
170
|
+
parseTimeoutMs?: number;
|
|
171
|
+
renderTimeoutMs?: number;
|
|
172
|
+
fullRenderTimeoutMs?: number;
|
|
173
|
+
renderDebounceMs?: number;
|
|
174
|
+
contentStableDelayMs?: number;
|
|
175
|
+
previewPollDelayMs?: number;
|
|
176
|
+
previewPollMaxDelayMs?: number;
|
|
177
|
+
previewPollMaxAttempts?: number;
|
|
178
|
+
showHeader?: boolean;
|
|
179
|
+
showModeToggle?: boolean;
|
|
180
|
+
showCopyButton?: boolean;
|
|
181
|
+
showExportButton?: boolean;
|
|
182
|
+
showFullscreenButton?: boolean;
|
|
183
|
+
showCollapseButton?: boolean;
|
|
184
|
+
showZoomControls?: boolean;
|
|
185
|
+
enableWheelZoom?: boolean;
|
|
186
|
+
isStrict?: boolean;
|
|
187
|
+
enableMermaidInteractions?: boolean;
|
|
188
|
+
showTooltips?: boolean;
|
|
189
|
+
fitPreviewHeight?: boolean;
|
|
190
|
+
onRenderError?: (error: unknown, code: string, container: HTMLElement) => boolean | void;
|
|
191
|
+
}
|
|
192
|
+
export interface CodeBlockPreviewPayload {
|
|
193
|
+
node: CodeBlockNode;
|
|
194
|
+
artifactType: 'text/html' | 'image/svg+xml';
|
|
195
|
+
artifactTitle: string;
|
|
196
|
+
id: string;
|
|
197
|
+
}
|
|
198
|
+
export interface MermaidBlockEvent<TPayload = unknown> {
|
|
199
|
+
payload?: TPayload;
|
|
200
|
+
defaultPrevented: boolean;
|
|
201
|
+
preventDefault: () => void;
|
|
202
|
+
svgElement?: SVGElement | null;
|
|
203
|
+
svgString?: string | null;
|
|
204
|
+
}
|
|
205
|
+
export interface D2BlockNodeProps {
|
|
206
|
+
node: CodeBlockNode;
|
|
207
|
+
maxHeight?: string | null;
|
|
208
|
+
estimatedPreviewHeightPx?: number;
|
|
209
|
+
loading?: boolean;
|
|
210
|
+
isDark?: boolean;
|
|
211
|
+
progressiveRender?: boolean;
|
|
212
|
+
progressiveIntervalMs?: number;
|
|
213
|
+
themeId?: number | null;
|
|
214
|
+
darkThemeId?: number | null;
|
|
215
|
+
showHeader?: boolean;
|
|
216
|
+
showModeToggle?: boolean;
|
|
217
|
+
showCopyButton?: boolean;
|
|
218
|
+
showExportButton?: boolean;
|
|
219
|
+
showCollapseButton?: boolean;
|
|
220
|
+
}
|
|
221
|
+
export interface InfographicBlockNodeProps {
|
|
222
|
+
node: CodeBlockNode;
|
|
223
|
+
maxHeight?: string | null;
|
|
224
|
+
estimatedPreviewHeightPx?: number;
|
|
225
|
+
loading?: boolean;
|
|
226
|
+
isDark?: boolean;
|
|
227
|
+
showHeader?: boolean;
|
|
228
|
+
showModeToggle?: boolean;
|
|
229
|
+
showCopyButton?: boolean;
|
|
230
|
+
showCollapseButton?: boolean;
|
|
231
|
+
showExportButton?: boolean;
|
|
232
|
+
showFullscreenButton?: boolean;
|
|
233
|
+
showZoomControls?: boolean;
|
|
234
|
+
}
|
|
235
|
+
export interface MathBlockNodeProps {
|
|
236
|
+
node: {
|
|
237
|
+
type: 'math_block';
|
|
238
|
+
content: string;
|
|
239
|
+
raw: string;
|
|
240
|
+
loading?: boolean;
|
|
241
|
+
};
|
|
242
|
+
indexKey?: number | string;
|
|
243
|
+
cacheScope?: string | number;
|
|
244
|
+
}
|
|
245
|
+
export interface MathInlineNodeProps {
|
|
246
|
+
node: {
|
|
247
|
+
type: 'math_inline';
|
|
248
|
+
content: string;
|
|
249
|
+
raw: string;
|
|
250
|
+
loading?: boolean;
|
|
251
|
+
markup?: string;
|
|
252
|
+
};
|
|
253
|
+
}
|
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
import type { SmoothMarkdownStreamOptions } from 'markstream-core';
|
|
2
|
+
import type { Accessor } from 'solid-js';
|
|
3
|
+
import type { BaseNode, HtmlPolicy, MarkdownIt, ParseOptions } from 'stream-markdown-parser';
|
|
4
|
+
import type { CustomComponentMap, HtmlComponentMap, StreamingComponentMap } from '../customComponents';
|
|
5
|
+
import type { CodeBlockNodeProps, CodeBlockOptions, CodeBlockTheme, CodeBlockThemes, D2BlockNodeProps, InfographicBlockNodeProps, MermaidBlockNodeProps } from './component-props';
|
|
6
|
+
type NodeRendererCodeBlockThemes = CodeBlockNodeProps['themes'];
|
|
7
|
+
export type NodeRendererCodeBlockProps = Partial<Omit<CodeBlockNodeProps, 'node' | 'themes' | 'codeBlockOptions'>> & {
|
|
8
|
+
themes?: NodeRendererCodeBlockThemes;
|
|
9
|
+
codeBlockOptions?: never;
|
|
10
|
+
} & Record<string, unknown>;
|
|
11
|
+
export type NodeRendererMode = 'docs' | 'chat' | 'minimal';
|
|
12
|
+
export type NodeRendererTypewriter = boolean | 'simple' | 'precise';
|
|
13
|
+
export type NodeRendererDomMode = 'full' | 'minimal';
|
|
14
|
+
export type MarkstreamVirtualPhase = 'estimating' | 'streaming' | 'measuring' | 'settling' | 'settled' | 'final';
|
|
15
|
+
export type MarkstreamVirtualConfidence = 'estimate' | 'mixed' | 'measured' | 'final';
|
|
16
|
+
export type MarkstreamVirtualReason = 'content' | 'parse' | 'batch' | 'resize' | 'node-resize' | 'async-node' | 'font' | 'theme' | 'final' | 'restore' | 'manual';
|
|
17
|
+
export type MarkstreamVirtualAnchor = {
|
|
18
|
+
type: 'node';
|
|
19
|
+
nodeIndex: number;
|
|
20
|
+
offsetWithinNodePx: number;
|
|
21
|
+
} | {
|
|
22
|
+
type: 'bottom';
|
|
23
|
+
distanceFromBottomPx: number;
|
|
24
|
+
};
|
|
25
|
+
export interface MarkstreamMeasuredHeightCacheEntry {
|
|
26
|
+
index: number;
|
|
27
|
+
height: number;
|
|
28
|
+
}
|
|
29
|
+
export interface MarkstreamHeightCacheEntry extends MarkstreamMeasuredHeightCacheEntry {
|
|
30
|
+
/**
|
|
31
|
+
* Compatibility metadata.
|
|
32
|
+
*
|
|
33
|
+
* NodeRenderer exports these fields for newly captured caches, and
|
|
34
|
+
* standalone virtualScroll.heightCache imports require signature at runtime.
|
|
35
|
+
*/
|
|
36
|
+
nodeType?: string;
|
|
37
|
+
signature: string;
|
|
38
|
+
}
|
|
39
|
+
export type MarkstreamHeightCache = MarkstreamHeightCacheEntry[];
|
|
40
|
+
export type MarkstreamInternalHeightCache = MarkstreamMeasuredHeightCacheEntry[];
|
|
41
|
+
export interface MarkstreamVirtualMetrics {
|
|
42
|
+
sessionKey: string;
|
|
43
|
+
threadKey?: string;
|
|
44
|
+
phase: MarkstreamVirtualPhase;
|
|
45
|
+
nodeCount: number;
|
|
46
|
+
liveRange: {
|
|
47
|
+
start: number;
|
|
48
|
+
end: number;
|
|
49
|
+
};
|
|
50
|
+
renderedCount: number;
|
|
51
|
+
measuredCount: number;
|
|
52
|
+
estimatedCount: number;
|
|
53
|
+
averageNodeHeight: number;
|
|
54
|
+
topSpacerHeight: number;
|
|
55
|
+
bottomSpacerHeight: number;
|
|
56
|
+
visibleDomHeight: number;
|
|
57
|
+
totalHeight: number;
|
|
58
|
+
width: number;
|
|
59
|
+
final: boolean;
|
|
60
|
+
stable: boolean;
|
|
61
|
+
confidence: MarkstreamVirtualConfidence;
|
|
62
|
+
reason: MarkstreamVirtualReason;
|
|
63
|
+
}
|
|
64
|
+
export interface MarkstreamVirtualState {
|
|
65
|
+
sessionKey: string;
|
|
66
|
+
threadKey?: string;
|
|
67
|
+
/**
|
|
68
|
+
* Present only when this renderer is close enough to the scrollRoot viewport
|
|
69
|
+
* to own a restore anchor. Automatic height/cache state may omit it.
|
|
70
|
+
*/
|
|
71
|
+
anchor?: MarkstreamVirtualAnchor;
|
|
72
|
+
/**
|
|
73
|
+
* true means `anchor` was captured from this renderer's current visible or
|
|
74
|
+
* near-visible viewport area. false/undefined means the state is primarily
|
|
75
|
+
* for metrics and height cache.
|
|
76
|
+
*/
|
|
77
|
+
anchorCaptured?: boolean;
|
|
78
|
+
metrics: MarkstreamVirtualMetrics;
|
|
79
|
+
width: number;
|
|
80
|
+
contentHash?: string;
|
|
81
|
+
measurementKey?: string;
|
|
82
|
+
heightCache?: MarkstreamHeightCache;
|
|
83
|
+
}
|
|
84
|
+
export type MarkstreamScrollRoot = HTMLElement | null | undefined;
|
|
85
|
+
export type MarkstreamScrollRootRef = Accessor<MarkstreamScrollRoot>;
|
|
86
|
+
export type MarkstreamScrollRootLike = MarkstreamScrollRoot | MarkstreamScrollRootRef | {
|
|
87
|
+
$el?: MarkstreamScrollRoot;
|
|
88
|
+
};
|
|
89
|
+
export type MarkstreamScrollRootResolver = () => MarkstreamScrollRootLike;
|
|
90
|
+
export type MarkstreamVirtualScrollHeightCacheOptions = {
|
|
91
|
+
heightCache?: null | undefined;
|
|
92
|
+
heightCacheWidth?: number;
|
|
93
|
+
} | {
|
|
94
|
+
/**
|
|
95
|
+
* Cached measured node heights.
|
|
96
|
+
*
|
|
97
|
+
* When this is supplied outside restoreState, heightCacheWidth is required
|
|
98
|
+
* so the renderer can reject stale layout caches after width changes.
|
|
99
|
+
*/
|
|
100
|
+
heightCache: MarkstreamHeightCache;
|
|
101
|
+
heightCacheWidth: number;
|
|
102
|
+
};
|
|
103
|
+
interface MarkstreamVirtualScrollSharedBaseOptions {
|
|
104
|
+
scrollRoot?: MarkstreamScrollRootLike | MarkstreamScrollRootResolver;
|
|
105
|
+
threadKey?: string;
|
|
106
|
+
restoreState?: MarkstreamVirtualState | null;
|
|
107
|
+
/**
|
|
108
|
+
* Apply `restoreState.anchor` to the shared scroll root.
|
|
109
|
+
*
|
|
110
|
+
* By default `restoreState` imports compatible height cache only, so several
|
|
111
|
+
* MarkdownRender instances can mount with persisted state without fighting
|
|
112
|
+
* over the same outer scroll root.
|
|
113
|
+
*/
|
|
114
|
+
restoreAnchor?: boolean | string | number;
|
|
115
|
+
/**
|
|
116
|
+
* Extra cache invalidation key for layout-affecting host state:
|
|
117
|
+
* theme, font, density, custom component style revision, stream-diffs line height, etc.
|
|
118
|
+
*/
|
|
119
|
+
measurementKey?: string | number;
|
|
120
|
+
settleMode?: 'auto' | 'manual';
|
|
121
|
+
settledToken?: string | number | boolean;
|
|
122
|
+
emitIntervalMs?: number;
|
|
123
|
+
heightDiffThresholdPx?: number;
|
|
124
|
+
/**
|
|
125
|
+
* Maximum number of measured node-height records emitted in heightCache.
|
|
126
|
+
*
|
|
127
|
+
* Default: 5000. Set <= 0 to export all compatible measured heights.
|
|
128
|
+
* Large values improve restore precision but increase event/state payload size.
|
|
129
|
+
*/
|
|
130
|
+
heightCacheLimit?: number;
|
|
131
|
+
}
|
|
132
|
+
export type MarkstreamVirtualScrollSharedOptions = MarkstreamVirtualScrollSharedBaseOptions & MarkstreamVirtualScrollHeightCacheOptions;
|
|
133
|
+
export type MarkstreamVirtualScrollOptions = (MarkstreamVirtualScrollSharedOptions & {
|
|
134
|
+
enabled: true;
|
|
135
|
+
sessionKey: string;
|
|
136
|
+
}) | (MarkstreamVirtualScrollSharedOptions & {
|
|
137
|
+
enabled: boolean;
|
|
138
|
+
sessionKey: string;
|
|
139
|
+
}) | (MarkstreamVirtualScrollSharedOptions & {
|
|
140
|
+
enabled?: false;
|
|
141
|
+
sessionKey?: string;
|
|
142
|
+
});
|
|
143
|
+
export interface MarkstreamCaptureVirtualStateOptions {
|
|
144
|
+
/**
|
|
145
|
+
* Default: false for imperative capture.
|
|
146
|
+
*
|
|
147
|
+
* Event-driven state emission still uses viewport-gated capture internally,
|
|
148
|
+
* but a host virtualizer can opt into viewport-gated imperative capture
|
|
149
|
+
* during thread switch.
|
|
150
|
+
*/
|
|
151
|
+
requireViewport?: boolean;
|
|
152
|
+
/**
|
|
153
|
+
* Default: false.
|
|
154
|
+
*
|
|
155
|
+
* When true, captureVirtualState() may include a best-effort node anchor even
|
|
156
|
+
* if the renderer is not near the viewport. Such anchors are emitted with
|
|
157
|
+
* anchorCaptured=false and are not auto-restored unless explicitly opted in.
|
|
158
|
+
*/
|
|
159
|
+
allowFallbackAnchor?: boolean;
|
|
160
|
+
/**
|
|
161
|
+
* Default: true.
|
|
162
|
+
*/
|
|
163
|
+
includeEmptyState?: boolean;
|
|
164
|
+
}
|
|
165
|
+
export interface MarkstreamRendererHandle {
|
|
166
|
+
getVirtualMetrics: () => MarkstreamVirtualMetrics;
|
|
167
|
+
captureVirtualState: (options?: MarkstreamCaptureVirtualStateOptions) => MarkstreamVirtualState | null;
|
|
168
|
+
restoreVirtualState: (state: MarkstreamVirtualState, options?: {
|
|
169
|
+
/**
|
|
170
|
+
* Default: false.
|
|
171
|
+
*
|
|
172
|
+
* Only works when state.anchor exists. Cache import still works without
|
|
173
|
+
* anchor.
|
|
174
|
+
*/
|
|
175
|
+
restoreAnchor?: boolean;
|
|
176
|
+
restoreToken?: string | number | boolean;
|
|
177
|
+
/**
|
|
178
|
+
* Default: false.
|
|
179
|
+
*
|
|
180
|
+
* Set true only when the caller knows an anchor with
|
|
181
|
+
* anchorCaptured=false still belongs to the active viewport context.
|
|
182
|
+
*/
|
|
183
|
+
allowUncapturedAnchor?: boolean;
|
|
184
|
+
}) => void;
|
|
185
|
+
forceMeasure: (reason?: MarkstreamVirtualReason) => Promise<MarkstreamVirtualMetrics>;
|
|
186
|
+
settle: (options?: {
|
|
187
|
+
frames?: number;
|
|
188
|
+
timeoutMs?: number;
|
|
189
|
+
reason?: MarkstreamVirtualReason;
|
|
190
|
+
/**
|
|
191
|
+
* Force-clear pending delayed height-settling timers before returning.
|
|
192
|
+
* Default: false. Use only when the host knows async layout work is done.
|
|
193
|
+
*/
|
|
194
|
+
flushPendingTimers?: boolean;
|
|
195
|
+
}) => Promise<MarkstreamVirtualMetrics>;
|
|
196
|
+
scrollToNode: (index: number, align?: 'start' | 'center' | 'end' | 'nearest') => void;
|
|
197
|
+
}
|
|
198
|
+
export interface MarkstreamNodeLifecycle {
|
|
199
|
+
reportHeight: (indexKey: string | number, height: number) => void;
|
|
200
|
+
markPending: (indexKey: string | number) => void;
|
|
201
|
+
markSettled: (indexKey: string | number) => void;
|
|
202
|
+
}
|
|
203
|
+
/** @experimental */
|
|
204
|
+
export interface MarkstreamViewportPriorityOptions {
|
|
205
|
+
/** Root margin for MarkdownRender node-shell visibility. Default: '400px'. */
|
|
206
|
+
rootMargin?: string;
|
|
207
|
+
/** Root margin for built-in code block renderers and deferred HTML blocks. Defaults to rootMargin. */
|
|
208
|
+
heavyBlockMargin?: string;
|
|
209
|
+
/** Auto-disable threshold for MarkdownRender node-shell deferral only. Default: 640. */
|
|
210
|
+
maxTargets?: number;
|
|
211
|
+
}
|
|
212
|
+
export interface NodeRendererProps {
|
|
213
|
+
/** Raw Markdown input. Omit this when you pass pre-parsed nodes instead. */
|
|
214
|
+
content?: string;
|
|
215
|
+
/** Pre-parsed Markdown nodes to render without running the internal parser. */
|
|
216
|
+
nodes?: readonly BaseNode[] | null;
|
|
217
|
+
/**
|
|
218
|
+
* Whether the input stream is complete (end-of-stream). When true, the parser
|
|
219
|
+
* will stop emitting streaming "loading" nodes for unfinished constructs.
|
|
220
|
+
*/
|
|
221
|
+
final?: boolean;
|
|
222
|
+
/** Options forwarded to parseMarkdownToStructure when content is provided */
|
|
223
|
+
parseOptions?: ParseOptions;
|
|
224
|
+
customMarkdownIt?: (md: MarkdownIt) => MarkdownIt;
|
|
225
|
+
/** Log parse/render timing and virtualization stats (dev only) */
|
|
226
|
+
debugPerformance?: boolean;
|
|
227
|
+
/**
|
|
228
|
+
* Custom HTML-like tags that participate in streaming mid-state handling
|
|
229
|
+
* and are emitted as custom nodes (e.g. ['thinking']). Forwarded to `getMarkdown()`.
|
|
230
|
+
*/
|
|
231
|
+
customHtmlTags?: readonly string[];
|
|
232
|
+
customComponents?: CustomComponentMap;
|
|
233
|
+
streamingComponents?: StreamingComponentMap;
|
|
234
|
+
htmlComponents?: HtmlComponentMap;
|
|
235
|
+
allowHtml?: boolean;
|
|
236
|
+
/** Preset renderer tuning. Default keeps the existing docs/rich path. */
|
|
237
|
+
mode?: NodeRendererMode;
|
|
238
|
+
/**
|
|
239
|
+
* DOM structure mode. `minimal` is best-effort and falls back to full DOM
|
|
240
|
+
* when rendering needs per-node wrappers.
|
|
241
|
+
*/
|
|
242
|
+
domMode?: NodeRendererDomMode;
|
|
243
|
+
/** HTML rendering policy for html_block/html_inline nodes. Default: safe */
|
|
244
|
+
htmlPolicy?: HtmlPolicy;
|
|
245
|
+
/** Defer built-in heavy nodes until they approach the viewport. Set false to render them immediately. Default: true. */
|
|
246
|
+
viewportPriority?: boolean;
|
|
247
|
+
/** Experimental viewport priority observer tuning; not part of the 1.x compatibility promise. */
|
|
248
|
+
viewportPriorityOptions?: MarkstreamViewportPriorityOptions;
|
|
249
|
+
/**
|
|
250
|
+
* Whether code_block renders should stream updates.
|
|
251
|
+
* When false, code blocks stay in a loading state and render once when final content is ready.
|
|
252
|
+
* Default: true
|
|
253
|
+
*/
|
|
254
|
+
codeBlockStream?: boolean;
|
|
255
|
+
/** Preferred dark stream-diffs theme forwarded to every code block renderer. */
|
|
256
|
+
codeBlockDarkTheme?: CodeBlockTheme;
|
|
257
|
+
/** Preferred light stream-diffs theme forwarded to every code block renderer. */
|
|
258
|
+
codeBlockLightTheme?: CodeBlockTheme;
|
|
259
|
+
/** Force the built-in fenced-code path to PreCodeNode. Custom code block overrides keep priority. */
|
|
260
|
+
renderCodeBlocksAsPre?: boolean;
|
|
261
|
+
/** Minimum width forwarded to CodeBlockNode (px or CSS unit) */
|
|
262
|
+
codeBlockMinWidth?: string | number;
|
|
263
|
+
/** Maximum width forwarded to CodeBlockNode (px or CSS unit) */
|
|
264
|
+
codeBlockMaxWidth?: string | number;
|
|
265
|
+
/** Runtime options forwarded to stream-diffs-backed CodeBlockNode instances. */
|
|
266
|
+
codeBlockOptions?: CodeBlockOptions;
|
|
267
|
+
/** Arbitrary props to forward to every CodeBlockNode */
|
|
268
|
+
codeBlockProps?: NodeRendererCodeBlockProps;
|
|
269
|
+
/** Props forwarded to MermaidBlockNode for mermaid fences */
|
|
270
|
+
mermaidProps?: Partial<Omit<MermaidBlockNodeProps, 'node' | 'loading' | 'isDark'>>;
|
|
271
|
+
/** Props forwarded to D2BlockNode for d2/d2lang fences */
|
|
272
|
+
d2Props?: Partial<Omit<D2BlockNodeProps, 'node' | 'loading' | 'isDark'>>;
|
|
273
|
+
/** Props forwarded to InfographicBlockNode for infographic fences */
|
|
274
|
+
infographicProps?: Partial<Omit<InfographicBlockNodeProps, 'node' | 'loading' | 'isDark'>>;
|
|
275
|
+
/** Global tooltip toggle for link/code-block renderers (default: true) */
|
|
276
|
+
showTooltips?: boolean;
|
|
277
|
+
/**
|
|
278
|
+
* Theme-name tuple ordered as `[dark, light]` for stream-diffs-backed code blocks.
|
|
279
|
+
*/
|
|
280
|
+
themes?: CodeBlockThemes;
|
|
281
|
+
/** Forces dark mode for built-in renderers such as Mermaid, D2, KaTeX, and code blocks. */
|
|
282
|
+
isDark?: boolean;
|
|
283
|
+
/** Scope key used by `setCustomComponents()` and `data-custom-id` style overrides. */
|
|
284
|
+
customId?: string;
|
|
285
|
+
indexKey?: number | string;
|
|
286
|
+
/** Show a blinking typewriter cursor while streamed content grows. `true` uses precise cursor positioning. Applies to `content` mode; ignored when non-empty `nodes` are provided. Default: false */
|
|
287
|
+
typewriter?: NodeRendererTypewriter;
|
|
288
|
+
/**
|
|
289
|
+
* Enable built-in smooth pacing for streaming `content` updates.
|
|
290
|
+
* - `true`: force-enable smooth streaming (content mode only)
|
|
291
|
+
* - `false`: force-disable smooth streaming
|
|
292
|
+
* - `'auto'` (default): enable only when typewriter/incremental mode is active
|
|
293
|
+
* Applies when rendering from `content` (not `nodes`).
|
|
294
|
+
* Default: 'auto'
|
|
295
|
+
*/
|
|
296
|
+
smoothStreaming?: boolean | 'auto';
|
|
297
|
+
/** Options forwarded to the built-in smooth streaming composable. */
|
|
298
|
+
smoothStreamingOptions?: SmoothMarkdownStreamOptions;
|
|
299
|
+
/** Performance tuning knob for the minimum interval in ms between built-in smooth-streaming parse commits. Default: 80. */
|
|
300
|
+
parseCoalesceMs?: number;
|
|
301
|
+
/** Enable/disable non-code-node enter and streamed-text fade animations. Default: true */
|
|
302
|
+
fade?: boolean;
|
|
303
|
+
/** Enable incremental/batched rendering of nodes to avoid large single flush costs. Default: true */
|
|
304
|
+
batchRendering?: boolean;
|
|
305
|
+
/** How many nodes to render immediately before batching kicks in. Default: 40 */
|
|
306
|
+
initialRenderBatchSize?: number;
|
|
307
|
+
/** How many additional nodes to render per batch tick. Default: 80 */
|
|
308
|
+
renderBatchSize?: number;
|
|
309
|
+
/** Extra delay (ms) before each batch after rAF; helps yield to input. Default: 16 */
|
|
310
|
+
renderBatchDelay?: number;
|
|
311
|
+
/** Target budget (ms) for each batch before we shrink subsequent batch sizes. Default: 6 */
|
|
312
|
+
renderBatchBudgetMs?: number;
|
|
313
|
+
/** Timeout (ms) for requestIdleCallback slices. Default: 120 */
|
|
314
|
+
renderBatchIdleTimeoutMs?: number;
|
|
315
|
+
/** Defer rendering nodes until they are near the viewport */
|
|
316
|
+
deferNodesUntilVisible?: boolean;
|
|
317
|
+
/** Maximum number of fully rendered nodes kept in DOM. Default: 220 */
|
|
318
|
+
maxLiveNodes?: number;
|
|
319
|
+
/** Number of nodes to keep before/after focus. Default: 60 */
|
|
320
|
+
liveNodeBuffer?: number;
|
|
321
|
+
/**
|
|
322
|
+
* Controls node-level virtualization inside this Markdown document only.
|
|
323
|
+
*
|
|
324
|
+
* It does not virtualize a chat/timeline list. Use MarkstreamVirtualTimeline
|
|
325
|
+
* or useMarkstreamVirtualAdapter for the outer conversation surface.
|
|
326
|
+
*/
|
|
327
|
+
nodeVirtual?: boolean | 'auto';
|
|
328
|
+
/** Advanced: report logical height and restore state to an outer virtual scroller. */
|
|
329
|
+
virtualScroll?: MarkstreamVirtualScrollOptions;
|
|
330
|
+
/** @internal */
|
|
331
|
+
renderAsFragment?: boolean;
|
|
332
|
+
}
|
|
333
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { SmoothMarkdownStreamOptions } from 'markstream-core';
|
|
2
|
+
export declare function useSmoothMarkdownStream(options?: SmoothMarkdownStreamOptions): {
|
|
3
|
+
snapshot: import("solid-js").Accessor<import("markstream-core").SmoothMarkdownStreamSnapshot>;
|
|
4
|
+
source: () => string;
|
|
5
|
+
visible: () => string;
|
|
6
|
+
done: () => boolean;
|
|
7
|
+
final: () => boolean;
|
|
8
|
+
caughtUp: () => boolean;
|
|
9
|
+
pendingChars: () => number;
|
|
10
|
+
getSnapshot: () => import("markstream-core").SmoothMarkdownStreamSnapshot;
|
|
11
|
+
subscribe: (listener: import("markstream-core").SmoothStreamNotify) => () => void;
|
|
12
|
+
enqueue: (chunk: string) => void;
|
|
13
|
+
finish: (options?: {
|
|
14
|
+
flush?: boolean;
|
|
15
|
+
}) => void;
|
|
16
|
+
flush: () => void;
|
|
17
|
+
reset: (initialMarkdown?: string) => void;
|
|
18
|
+
pause: () => void;
|
|
19
|
+
resume: () => void;
|
|
20
|
+
destroy: () => void;
|
|
21
|
+
dispose: () => void;
|
|
22
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function copyTextToClipboard(source: string): Promise<boolean>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function createD2RenderSalt(prefix?: string): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function findFootnoteElement(source: EventTarget | null | undefined, id: string): Element | null;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { NodeLifecycleContext as MARKSTREAM_NODE_LIFECYCLE_KEY, useMarkstreamNodeLifecycle } from '../components/lifecycle';
|
|
2
|
+
export * from '../icon-themes';
|
|
3
|
+
export { isCodeBlockRuntimeReady, preloadCodeBlockRuntime } from '../optional/streamDiffs';
|
|
4
|
+
export * from './katex-threshold';
|
|
5
|
+
export * from './languageIcon';
|
|
6
|
+
export * from './performance-monitor';
|
|
7
|
+
export * from './safeRaf';
|
|
8
|
+
export * from 'stream-markdown-parser';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recommend when to use Worker based on formula count and complexity.
|
|
3
|
+
*
|
|
4
|
+
* N_threshold ≈ floor(B / (R × (1 - H)))
|
|
5
|
+
* - B: main-thread budget (ms), e.g. 50ms or a stricter 16.7ms
|
|
6
|
+
* - R: avg render time per unique formula (ms)
|
|
7
|
+
* - H: cache hit rate (0~1)
|
|
8
|
+
*/
|
|
9
|
+
export interface ThresholdInput {
|
|
10
|
+
R: number;
|
|
11
|
+
H?: number;
|
|
12
|
+
B?: number;
|
|
13
|
+
}
|
|
14
|
+
export declare function recommendWorkerThreshold({ R, H, B }: ThresholdInput): number;
|
|
15
|
+
export declare function estimateRByFormula(sample: string): 'simple' | 'medium' | 'complex';
|
|
16
|
+
export declare function defaultRByClass(cls: 'simple' | 'medium' | 'complex'): number;
|
|
17
|
+
export declare function recommendNForSamples(formulas: string[], opts?: {
|
|
18
|
+
H?: number;
|
|
19
|
+
B?: number;
|
|
20
|
+
}): number;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type LanguageIconResolver = (lang: string) => string | undefined | null;
|
|
2
|
+
export declare const languageIconsRevision: import("solid-js").Accessor<number>;
|
|
3
|
+
export declare function setLanguageIconResolver(resolver?: LanguageIconResolver | null): void;
|
|
4
|
+
export declare function normalizeLanguageIdentifier(lang?: string | null): string;
|
|
5
|
+
export declare function resolveLanguageId(lang?: string | null): string;
|
|
6
|
+
export declare function preloadExtendedLanguageIcons(): Promise<void>;
|
|
7
|
+
export declare function getLanguageIcon(lang: string): string;
|
|
8
|
+
export declare const languageMap: Record<string, string>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function createMermaidRenderId(prefix?: string): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function normalizeKaTeXRenderInput(content: string): string;
|