markstream-react 0.0.45 → 0.0.47

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 (35) hide show
  1. package/dist/Tooltip-DQ6sUeEf.js +205 -0
  2. package/dist/customHtmlTag-BRT4eqd8.js +3 -0
  3. package/dist/index-DOjYeelM.js +86 -0
  4. package/dist/index.css +1 -1
  5. package/dist/index.d.ts +3 -3
  6. package/dist/index.js +1 -1
  7. package/dist/index.px.css +1 -1
  8. package/dist/index.tailwind.css +1 -1
  9. package/dist/markstream-react.css +1 -1
  10. package/dist/next.d.ts +27 -11
  11. package/dist/next.js +1 -1
  12. package/dist/server.d.ts +23 -9
  13. package/dist/server.js +1 -1
  14. package/dist/tailwind.ts +1 -1
  15. package/dist/types/components/HtmlBlockNode/HtmlBlockNode.d.ts +5 -0
  16. package/dist/types/components/HtmlInlineNode/HtmlInlineNode.d.ts +4 -1
  17. package/dist/types/components/InfographicBlockNode/height.d.ts +5 -0
  18. package/dist/types/components/MermaidBlockNode/height.d.ts +6 -0
  19. package/dist/types/customComponents.d.ts +9 -1
  20. package/dist/types/index.d.ts +3 -3
  21. package/dist/types/next.d.ts +12 -3
  22. package/dist/types/server-renderer/html.d.ts +1 -2
  23. package/dist/types/server-renderer/index.d.ts +3 -3
  24. package/dist/types/server.d.ts +3 -2
  25. package/dist/types/types/component-props.d.ts +3 -3
  26. package/dist/types/types.d.ts +8 -5
  27. package/dist/types/utils/customHtmlTag.d.ts +16 -0
  28. package/dist/types/utils/htmlToReact.d.ts +9 -0
  29. package/dist/types/utils/normalizeKaTeXRenderInput.d.ts +1 -0
  30. package/dist/workers/mermaidParser.worker.js +1 -1
  31. package/package.json +3 -3
  32. package/dist/Tooltip-CgreNSxF.js +0 -211
  33. package/dist/index-DzmDCKan.js +0 -89
  34. package/dist/languageIcon-CEJktwcf.js +0 -3
  35. package/dist/types/components/SoftBreakNode/SoftBreakNode.d.ts +0 -5
@@ -0,0 +1,6 @@
1
+ export declare const MERMAID_PREVIEW_MIN_HEIGHT = 360;
2
+ export declare const MERMAID_PREVIEW_MAX_HEIGHT = 500;
3
+ export declare function parsePositiveNumber(value: unknown): number;
4
+ export declare function getMermaidDiagramKind(code: string): string;
5
+ export declare function estimateMermaidPreviewHeight(code: string): number;
6
+ export declare function clampMermaidPreviewHeight(height: number, minHeight?: number, maxHeight?: number | null): number;
@@ -1,5 +1,9 @@
1
1
  import { ComponentType } from 'react';
2
- export type CustomComponentMap = Record<string, ComponentType<any>>;
2
+ export type CustomComponentDisplayMode = 'inline' | 'block';
3
+ export type MarkstreamCustomComponent<P = any> = ComponentType<P> & {
4
+ markstreamDisplay?: CustomComponentDisplayMode;
5
+ };
6
+ export type CustomComponentMap = Record<string, MarkstreamCustomComponent<any>>;
3
7
  export declare function subscribeCustomComponents(listener: () => void): () => void;
4
8
  export declare function getCustomComponentsRevision(): number;
5
9
  export declare function setCustomComponents(id: string, mapping: CustomComponentMap): void;
@@ -7,3 +11,7 @@ export declare function setCustomComponents(mapping: CustomComponentMap): void;
7
11
  export declare function getCustomNodeComponents(customId?: string): CustomComponentMap;
8
12
  export declare function removeCustomComponents(id: string): void;
9
13
  export declare function clearGlobalCustomComponents(): void;
14
+ export declare function getCustomComponentDisplay(component: ComponentType<any> | null | undefined): CustomComponentDisplayMode | undefined;
15
+ export declare function withMarkstreamComponentDisplay<T extends ComponentType<any>>(component: T, display: CustomComponentDisplayMode): T & {
16
+ markstreamDisplay: CustomComponentDisplayMode;
17
+ };
@@ -41,7 +41,6 @@ export { FallbackComponent } from './components/NodeRenderer/FallbackComponent';
41
41
  export { ParagraphNode } from './components/ParagraphNode/ParagraphNode';
42
42
  export { PreCodeNode } from './components/PreCodeNode/PreCodeNode';
43
43
  export { ReferenceNode } from './components/ReferenceNode/ReferenceNode';
44
- export { SoftBreakNode } from './components/SoftBreakNode/SoftBreakNode';
45
44
  export { StrikethroughNode } from './components/StrikethroughNode/StrikethroughNode';
46
45
  export { StrongNode } from './components/StrongNode/StrongNode';
47
46
  export { SubscriptNode } from './components/SubscriptNode/SubscriptNode';
@@ -52,10 +51,11 @@ export { ThematicBreakNode } from './components/ThematicBreakNode/ThematicBreakN
52
51
  export { Tooltip } from './components/Tooltip/Tooltip';
53
52
  export type { TooltipPlacement, TooltipProps } from './components/Tooltip/Tooltip';
54
53
  export { VmrContainerNode } from './components/VmrContainerNode/VmrContainerNode';
55
- export { clearGlobalCustomComponents, getCustomNodeComponents, removeCustomComponents, setCustomComponents, } from './customComponents';
54
+ export { clearGlobalCustomComponents, getCustomComponentDisplay, getCustomNodeComponents, removeCustomComponents, setCustomComponents, withMarkstreamComponentDisplay, } from './customComponents';
55
+ export type { CustomComponentDisplayMode, MarkstreamCustomComponent, } from './customComponents';
56
56
  export * from './i18n/useSafeI18n';
57
57
  export * from './renderers/renderNode';
58
- export type { NodeRendererProps } from './types';
58
+ export type { NodeRendererCodeBlockProps, NodeRendererProps } from './types';
59
59
  export type { CodeBlockDiffAppearance, CodeBlockDiffHideUnchangedRegions, CodeBlockDiffHideUnchangedRegionsOptions, CodeBlockDiffHunkActionContext, CodeBlockDiffHunkActionKind, CodeBlockDiffHunkSide, CodeBlockDiffLineStyle, CodeBlockDiffUnchangedRegionStyle, CodeBlockMonacoLanguage, CodeBlockMonacoOptions, CodeBlockMonacoTheme, CodeBlockMonacoThemeObject, CodeBlockNodeProps, D2BlockNodeProps, ImageNodeProps, InfographicBlockNodeProps, LinkNodeProps, MathBlockNodeProps, MathInlineNodeProps, MermaidBlockEvent, MermaidBlockNodeProps, PreCodeNodeProps, } from './types/component-props';
60
60
  export type { NodeComponentProps } from './types/node-component';
61
61
  export * from './utils/languageIcon';
@@ -109,8 +109,17 @@ export declare const HighlightNode: {
109
109
  export declare const HtmlBlockNode: {
110
110
  (props: import('./types/node-component').NodeComponentProps<{
111
111
  type: "html_block";
112
- content?: string;
113
- }>): React.ReactElement<any, string | React.JSXElementConstructor<any>>;
112
+ content: string;
113
+ raw?: string;
114
+ tag?: string;
115
+ attrs?: [string, string | null][] | null;
116
+ children?: any[];
117
+ loading?: boolean;
118
+ }> & {
119
+ customComponents?: Record<string, React.ComponentType<any>>;
120
+ htmlPolicy?: import('stream-markdown-parser').HtmlPolicy;
121
+ placeholder?: React.ReactNode;
122
+ }): React.ReactElement<any, string | React.JSXElementConstructor<any>>;
114
123
  displayName: string;
115
124
  };
116
125
  export declare const HtmlInlineNode: {
@@ -289,7 +298,7 @@ export type { MarkdownCodeBlockNodeProps } from './components/MarkdownCodeBlockN
289
298
  export type { TooltipPlacement, TooltipProps } from './components/Tooltip/Tooltip';
290
299
  export * from './i18n/useSafeI18n';
291
300
  export * from './renderers/renderNode';
292
- export type { NodeRendererProps } from './types';
301
+ export type { NodeRendererCodeBlockProps, NodeRendererProps } from './types';
293
302
  export * from './types/component-props';
294
303
  export type { NodeComponentProps } from './types/node-component';
295
304
  export * from './utils/languageIcon';
@@ -1,2 +1 @@
1
- import { ComponentType, ReactNode } from 'react';
2
- export declare function parseHtmlToReactNodes(content: string, customComponents: Record<string, ComponentType<any>>): ReactNode[] | null;
1
+ export { parseHtmlToReactNodes } from '../utils/htmlToReact';
@@ -108,9 +108,6 @@ export declare function SuperscriptNode(props: NodeComponentProps<{
108
108
  export declare function HardBreakNode(_props: NodeComponentProps<{
109
109
  type: 'hardbreak';
110
110
  }>): import("react/jsx-runtime").JSX.Element;
111
- export declare function SoftBreakNode(_props: NodeComponentProps<{
112
- type: 'softbreak';
113
- }>): string;
114
111
  export declare function ThematicBreakNode(_props?: NodeComponentProps<{
115
112
  type: 'thematic_break';
116
113
  }>): import("react/jsx-runtime").JSX.Element;
@@ -147,6 +144,9 @@ export declare function ReferenceNode(props: NodeComponentProps<{
147
144
  export declare function HtmlBlockNode(props: NodeComponentProps<{
148
145
  type: 'html_block';
149
146
  content?: string;
147
+ tag?: string;
148
+ attrs?: [string, string | null][] | null;
149
+ children?: ParsedNode[];
150
150
  }>): import("react/jsx-runtime").JSX.Element;
151
151
  export declare function HtmlInlineNode(props: NodeComponentProps<{
152
152
  type: 'html_inline';
@@ -3,7 +3,8 @@ export type { LinkNodeStyleProps } from './components/LinkNode/LinkNode';
3
3
  export type { ListItemNodeProps } from './components/ListItemNode/ListItemNode';
4
4
  export type { MarkdownCodeBlockNodeProps } from './components/MarkdownCodeBlockNode/MarkdownCodeBlockNode';
5
5
  export type { TooltipPlacement, TooltipProps } from './components/Tooltip/Tooltip';
6
- export { clearGlobalCustomComponents, getCustomNodeComponents, removeCustomComponents, setCustomComponents, } from './customComponents';
6
+ export { clearGlobalCustomComponents, getCustomComponentDisplay, getCustomNodeComponents, removeCustomComponents, setCustomComponents, withMarkstreamComponentDisplay, } from './customComponents';
7
+ export type { CustomComponentDisplayMode, MarkstreamCustomComponent } from './customComponents';
7
8
  export { AdmonitionNode } from './server-renderer';
8
9
  export { BlockquoteNode } from './server-renderer';
9
10
  export { CheckboxNode } from './server-renderer';
@@ -49,6 +50,6 @@ export { ThematicBreakNode } from './server-renderer';
49
50
  export { Tooltip } from './server-renderer';
50
51
  export { VmrContainerNode } from './server-renderer';
51
52
  export { renderNode } from './server-renderer';
52
- export type { NodeRendererProps } from './types';
53
+ export type { NodeRendererCodeBlockProps, NodeRendererProps } from './types';
53
54
  export * from './types/component-props';
54
55
  export type { NodeComponentProps } from './types/node-component';
@@ -41,6 +41,7 @@ export interface CodeBlockMonacoOptions {
41
41
  themes?: CodeBlockMonacoTheme[];
42
42
  languages?: CodeBlockMonacoLanguage[];
43
43
  renderSideBySide?: boolean;
44
+ useInlineViewWhenSpaceIsLimited?: boolean;
44
45
  enableSplitViewResizing?: boolean;
45
46
  ignoreTrimWhitespace?: boolean;
46
47
  maxComputationTime?: number;
@@ -95,11 +96,8 @@ export interface ImageNodeProps {
95
96
  loading?: boolean;
96
97
  };
97
98
  fallbackSrc?: string;
98
- showCaption?: boolean;
99
99
  lazy?: boolean;
100
- svgMinHeight?: string;
101
100
  usePlaceholder?: boolean;
102
- inline?: boolean;
103
101
  }
104
102
  export interface LinkNodeProps {
105
103
  node: {
@@ -132,6 +130,7 @@ export interface PreCodeNodeProps {
132
130
  export interface MermaidBlockNodeProps {
133
131
  node: CodeBlockNode;
134
132
  maxHeight?: string | null;
133
+ estimatedPreviewHeightPx?: number;
135
134
  loading?: boolean;
136
135
  isDark?: boolean;
137
136
  workerTimeoutMs?: number;
@@ -197,6 +196,7 @@ export interface MathInlineNodeProps {
197
196
  export interface InfographicBlockNodeProps {
198
197
  node: CodeBlockNode;
199
198
  maxHeight?: string | null;
199
+ estimatedPreviewHeightPx?: number;
200
200
  loading?: boolean;
201
201
  isDark?: boolean;
202
202
  showHeader?: boolean;
@@ -1,6 +1,7 @@
1
1
  import { default as React } from 'react';
2
- import { BaseNode, MarkdownIt, ParsedNode, ParseOptions } from 'stream-markdown-parser';
3
- import { CodeBlockMonacoOptions, CodeBlockMonacoTheme, D2BlockNodeProps, InfographicBlockNodeProps, MermaidBlockNodeProps } from './types/component-props';
2
+ import { BaseNode, HtmlPolicy, MarkdownIt, ParsedNode, ParseOptions } from 'stream-markdown-parser';
3
+ import { CodeBlockMonacoOptions, CodeBlockMonacoTheme, CodeBlockNodeProps, D2BlockNodeProps, InfographicBlockNodeProps, MermaidBlockNodeProps } from './types/component-props';
4
+ export type NodeRendererCodeBlockProps = Partial<Omit<CodeBlockNodeProps, 'node'>> & Record<string, unknown>;
4
5
  export interface NodeRendererProps {
5
6
  content?: string;
6
7
  nodes?: readonly BaseNode[] | null;
@@ -18,6 +19,7 @@ export interface NodeRendererProps {
18
19
  * Forwarded to `getMarkdown()` and merged into parseOptions.
19
20
  */
20
21
  customHtmlTags?: readonly string[];
22
+ htmlPolicy?: HtmlPolicy;
21
23
  viewportPriority?: boolean;
22
24
  codeBlockStream?: boolean;
23
25
  codeBlockDarkTheme?: CodeBlockMonacoTheme;
@@ -26,7 +28,7 @@ export interface NodeRendererProps {
26
28
  renderCodeBlocksAsPre?: boolean;
27
29
  codeBlockMinWidth?: string | number;
28
30
  codeBlockMaxWidth?: string | number;
29
- codeBlockProps?: Record<string, any>;
31
+ codeBlockProps?: NodeRendererCodeBlockProps;
30
32
  mermaidProps?: Partial<Omit<MermaidBlockNodeProps, 'node' | 'loading' | 'isDark'>>;
31
33
  d2Props?: Partial<Omit<D2BlockNodeProps, 'node' | 'loading' | 'isDark'>>;
32
34
  infographicProps?: Partial<Omit<InfographicBlockNodeProps, 'node' | 'loading' | 'isDark'>>;
@@ -59,12 +61,13 @@ export interface RenderContext {
59
61
  textStreamState?: Map<string, string>;
60
62
  streamRenderVersion?: number;
61
63
  customComponents?: Record<string, React.ComponentType<any>>;
62
- codeBlockProps?: Record<string, any>;
64
+ customHtmlTags?: readonly string[];
65
+ htmlPolicy?: HtmlPolicy;
66
+ codeBlockProps?: NodeRendererCodeBlockProps;
63
67
  mermaidProps?: Partial<Omit<MermaidBlockNodeProps, 'node' | 'loading' | 'isDark'>>;
64
68
  d2Props?: Partial<Omit<D2BlockNodeProps, 'node' | 'loading' | 'isDark'>>;
65
69
  infographicProps?: Partial<Omit<InfographicBlockNodeProps, 'node' | 'loading' | 'isDark'>>;
66
70
  showTooltips?: boolean;
67
- inlineImages?: boolean;
68
71
  codeBlockStream?: boolean;
69
72
  renderCodeBlocksAsPre?: boolean;
70
73
  codeBlockThemes?: {
@@ -0,0 +1,16 @@
1
+ import { ParsedNode } from 'stream-markdown-parser';
2
+ import { CustomComponentDisplayMode, CustomComponentMap, MarkstreamCustomComponent } from '../customComponents';
3
+ export interface ResolvedCustomHtmlTag {
4
+ tag: string;
5
+ isWhitelisted: boolean;
6
+ component: MarkstreamCustomComponent<any> | null;
7
+ display: CustomComponentDisplayMode | undefined;
8
+ }
9
+ export declare function resolveCustomHtmlTag(node: Pick<ParsedNode, 'type'> & {
10
+ tag?: string | null;
11
+ content?: unknown;
12
+ }, customComponents: CustomComponentMap, customHtmlTags?: readonly string[]): ResolvedCustomHtmlTag | null;
13
+ export declare function isParagraphBreakingCustomHtmlNode(node: Pick<ParsedNode, 'type'> & {
14
+ tag?: string | null;
15
+ content?: unknown;
16
+ }, customComponents: CustomComponentMap, customHtmlTags?: readonly string[]): boolean;
@@ -0,0 +1,9 @@
1
+ import { ComponentType, ReactNode } from 'react';
2
+ import { HtmlPolicy, sanitizeHtmlAttrs as sanitizeHtmlAttrsBase, tokenizeHtml as tokenizeHtmlBase } from 'stream-markdown-parser';
3
+ export type { HtmlToken } from 'stream-markdown-parser';
4
+ export declare function normalizeDomAttrs(attrs: Record<string, string>): Record<string, any>;
5
+ export declare const tokenizeHtml: typeof tokenizeHtmlBase;
6
+ export declare const sanitizeHtmlAttrs: typeof sanitizeHtmlAttrsBase;
7
+ export declare function isCustomHtmlComponent(tagName: string, customComponents: Record<string, ComponentType<any>>): boolean;
8
+ export declare function hasCustomHtmlComponents(content: string, customComponents: Record<string, ComponentType<any>>): boolean;
9
+ export declare function parseHtmlToReactNodes(content: string, customComponents: Record<string, ComponentType<any>>, htmlPolicy?: HtmlPolicy): ReactNode[] | null;
@@ -0,0 +1 @@
1
+ export declare function normalizeKaTeXRenderInput(content: string): string;
@@ -1 +1 @@
1
- import t from"mermaid";async function a(a,r){var n;const e=function(t,a){const r=`%%{init: {"theme": "${"dark"===a?"dark":"default"}"}}%%\n`;return t.trimStart().startsWith("%%{")?t:r+t}(a,r),i=t;if("function"==typeof i.parse)return await(null==(n=i.parse)?void 0:n.call(i,e)),!0;throw new Error("mermaid.parse not available in worker")}t.initialize({startOnLoad:!1,securityLevel:"loose"}),self.onmessage=async t=>{var r;const n=t.data,e=t=>self.postMessage(t),i=n.id;try{if("canParse"===n.action)return void e({id:i,ok:!0,result:await a(n.payload.code,n.payload.theme)});if("findPrefix"===n.action)return void e({id:i,ok:!0,result:await async function(t,r){const n=t.split("\n"),e=function(t){const a=/^(?:graph|flowchart|flowchart\s+tb|flowchart\s+lr|sequenceDiagram|gantt|classDiagram|stateDiagram(?:-v2)?|erDiagram|journey|pie|quadrantChart|timeline|xychart(?:-beta)?)\b/;for(let r=0;r<t.length;r++){const n=t[r].trim();if(n&&!n.startsWith("%%")&&a.test(n))return r}return-1}(n);if(-1===e)return null;const i=n.slice(0,e+1);await a(i.join("\n"),r);let o=e+1,s=n.length,l=e+1,c=0;for(;o<=s&&c<12;){const t=Math.floor((o+s)/2),d=[...i,...n.slice(e+1,t)].join("\n");c++;try{await a(d,r),l=t,o=t+1}catch{s=t-1}}return[...i,...n.slice(e+1,l)].join("\n")}(n.payload.code,n.payload.theme)});e({id:i,ok:!1,error:"Unknown action"})}catch(o){e({id:i,ok:!1,error:null!=(r=null==o?void 0:o.message)?r:String(o)})}};
1
+ import t from"mermaid";async function a(a,r){var n;const e=function(t,a){const r=`%%{init: {"theme": "${"dark"===a?"dark":"default"}"}}%%\n`;return t.trimStart().startsWith("%%{")?t:r+t}(a,r),i=t;if("function"==typeof i.parse)return await(null==(n=i.parse)?void 0:n.call(i,e)),!0;throw new Error("mermaid.parse not available in worker")}t.initialize({startOnLoad:!1,securityLevel:"strict",flowchart:{htmlLabels:!1}}),self.onmessage=async t=>{var r;const n=t.data,e=t=>self.postMessage(t),i=n.id;try{if("canParse"===n.action)return void e({id:i,ok:!0,result:await a(n.payload.code,n.payload.theme)});if("findPrefix"===n.action)return void e({id:i,ok:!0,result:await async function(t,r){const n=t.split("\n"),e=function(t){const a=/^(?:graph|flowchart|flowchart\s+tb|flowchart\s+lr|sequenceDiagram|gantt|classDiagram|stateDiagram(?:-v2)?|erDiagram|journey|pie|quadrantChart|timeline|xychart(?:-beta)?)\b/;for(let r=0;r<t.length;r++){const n=t[r].trim();if(n&&!n.startsWith("%%")&&a.test(n))return r}return-1}(n);if(-1===e)return null;const i=n.slice(0,e+1);await a(i.join("\n"),r);let o=e+1,s=n.length,l=e+1,c=0;for(;o<=s&&c<12;){const t=Math.floor((o+s)/2),d=[...i,...n.slice(e+1,t)].join("\n");c++;try{await a(d,r),l=t,o=t+1}catch{s=t-1}}return[...i,...n.slice(e+1,l)].join("\n")}(n.payload.code,n.payload.theme)});e({id:i,ok:!1,error:"Unknown action"})}catch(o){e({id:i,ok:!1,error:null!=(r=null==o?void 0:o.message)?r:String(o)})}};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "markstream-react",
3
3
  "type": "module",
4
- "version": "0.0.45",
4
+ "version": "0.0.47",
5
5
  "description": "React Markdown renderer optimized for large documents with progressive Mermaid rendering, streaming diff code blocks, and fast real-time preview. Built on stream-markdown AST for consistent rendering across frameworks. Perfect for documentation sites, AI chat interfaces, and content management systems.",
6
6
  "author": "Simon He",
7
7
  "license": "MIT",
@@ -91,7 +91,7 @@
91
91
  "react": ">=18",
92
92
  "react-dom": ">=18",
93
93
  "stream-markdown": ">=0.0.15",
94
- "stream-monaco": ">=0.0.38"
94
+ "stream-monaco": ">=0.0.40"
95
95
  },
96
96
  "peerDependenciesMeta": {
97
97
  "@antv/infographic": {
@@ -116,7 +116,7 @@
116
116
  "dependencies": {
117
117
  "@floating-ui/dom": "^1.7.6",
118
118
  "clsx": "^2.1.1",
119
- "stream-markdown-parser": "0.0.90"
119
+ "stream-markdown-parser": "0.0.92"
120
120
  },
121
121
  "devDependencies": {
122
122
  "@types/react": "^18.3.28",