markstream-octane 0.0.56-beta.1

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 (106) hide show
  1. package/README.md +276 -0
  2. package/dist/client/chunks/languageIconExtended-BZR3DrgI.js +2 -0
  3. package/dist/client/index.js +2 -0
  4. package/dist/client/workers/katexRenderer.worker.js +59 -0
  5. package/dist/client/workers/mermaidParser.worker.js +63 -0
  6. package/dist/index.css +2 -0
  7. package/dist/index.d.ts +845 -0
  8. package/dist/index.px.css +2 -0
  9. package/dist/index.tailwind.css +2009 -0
  10. package/dist/server/index.js +2 -0
  11. package/dist/server.d.ts +661 -0
  12. package/dist/tailwind.cjs +4 -0
  13. package/dist/tailwind.d.ts +2 -0
  14. package/dist/tailwind.js +2 -0
  15. package/dist/types/components/AdmonitionNode/AdmonitionNode.d.ts +12 -0
  16. package/dist/types/components/BlockquoteNode/BlockquoteNode.d.ts +8 -0
  17. package/dist/types/components/CheckboxNode/CheckboxNode.d.ts +7 -0
  18. package/dist/types/components/CodeBlockNode/CodeBlockNode.d.ts +14 -0
  19. package/dist/types/components/CodeBlockNode/HtmlPreviewFrame.d.ts +12 -0
  20. package/dist/types/components/CodeBlockNode/PreCodeNode.d.ts +3 -0
  21. package/dist/types/components/CodeBlockNode/monaco.d.ts +2 -0
  22. package/dist/types/components/CodeBlockNode/monacoThemeRegistry.d.ts +8 -0
  23. package/dist/types/components/CodeBlockNode/monacoThemeScheduler.d.ts +5 -0
  24. package/dist/types/components/D2BlockNode/D2BlockNode.d.ts +3 -0
  25. package/dist/types/components/D2BlockNode/d2.d.ts +18 -0
  26. package/dist/types/components/D2BlockNode/index.d.ts +3 -0
  27. package/dist/types/components/DefinitionListNode/DefinitionListNode.d.ts +8 -0
  28. package/dist/types/components/EmojiNode/EmojiNode.d.ts +8 -0
  29. package/dist/types/components/EmphasisNode/EmphasisNode.d.ts +6 -0
  30. package/dist/types/components/FootnoteAnchorNode/FootnoteAnchorNode.d.ts +7 -0
  31. package/dist/types/components/FootnoteNode/FootnoteNode.d.ts +9 -0
  32. package/dist/types/components/FootnoteReferenceNode/FootnoteReferenceNode.d.ts +7 -0
  33. package/dist/types/components/HardBreakNode/HardBreakNode.d.ts +6 -0
  34. package/dist/types/components/HeadingNode/HeadingNode.d.ts +10 -0
  35. package/dist/types/components/HighlightNode/HighlightNode.d.ts +6 -0
  36. package/dist/types/components/HtmlBlockNode/HtmlBlockNode.d.ts +19 -0
  37. package/dist/types/components/HtmlInlineNode/HtmlInlineNode.d.ts +16 -0
  38. package/dist/types/components/ImageNode/ImageNode.d.ts +9 -0
  39. package/dist/types/components/InfographicBlockNode/InfographicBlockNode.d.ts +16 -0
  40. package/dist/types/components/InfographicBlockNode/height.d.ts +6 -0
  41. package/dist/types/components/InfographicBlockNode/index.d.ts +3 -0
  42. package/dist/types/components/InfographicBlockNode/infographic.d.ts +2 -0
  43. package/dist/types/components/InlineCodeNode/InlineCodeNode.d.ts +7 -0
  44. package/dist/types/components/InsertNode/InsertNode.d.ts +6 -0
  45. package/dist/types/components/LinkNode/LinkNode.d.ts +22 -0
  46. package/dist/types/components/ListItemNode/ListItemNode.d.ts +13 -0
  47. package/dist/types/components/ListNode/ListNode.d.ts +10 -0
  48. package/dist/types/components/MarkdownCodeBlockNode/MarkdownCodeBlockNode.d.ts +34 -0
  49. package/dist/types/components/Math/MathBlockNode.d.ts +3 -0
  50. package/dist/types/components/Math/MathInlineNode.d.ts +3 -0
  51. package/dist/types/components/Math/katex.d.ts +2 -0
  52. package/dist/types/components/MathBlockNode/MathBlockNode.d.ts +3 -0
  53. package/dist/types/components/MathInlineNode/MathInlineNode.d.ts +3 -0
  54. package/dist/types/components/MermaidBlockNode/MermaidBlockNode.d.ts +16 -0
  55. package/dist/types/components/MermaidBlockNode/height.d.ts +7 -0
  56. package/dist/types/components/MermaidBlockNode/index.d.ts +3 -0
  57. package/dist/types/components/MermaidBlockNode/mermaid.d.ts +23 -0
  58. package/dist/types/components/NodeRenderer/FallbackComponent.d.ts +6 -0
  59. package/dist/types/components/NodeRenderer/preloadMonaco.d.ts +2 -0
  60. package/dist/types/components/NodeRenderer.d.ts +5 -0
  61. package/dist/types/components/ParagraphNode/ParagraphNode.d.ts +9 -0
  62. package/dist/types/components/PreCodeNode/PreCodeNode.d.ts +3 -0
  63. package/dist/types/components/ReferenceNode/ReferenceNode.d.ts +15 -0
  64. package/dist/types/components/StrikethroughNode/StrikethroughNode.d.ts +6 -0
  65. package/dist/types/components/StrongNode/StrongNode.d.ts +6 -0
  66. package/dist/types/components/SubscriptNode/SubscriptNode.d.ts +6 -0
  67. package/dist/types/components/SuperscriptNode/SuperscriptNode.d.ts +6 -0
  68. package/dist/types/components/TableNode/TableNode.d.ts +10 -0
  69. package/dist/types/components/TextNode/TextNode.d.ts +8 -0
  70. package/dist/types/components/ThematicBreakNode/ThematicBreakNode.d.ts +3 -0
  71. package/dist/types/components/Tooltip/Tooltip.d.ts +16 -0
  72. package/dist/types/components/VmrContainerNode/VmrContainerNode.d.ts +10 -0
  73. package/dist/types/context/smoothStreaming.d.ts +2 -0
  74. package/dist/types/context/streamState.d.ts +25 -0
  75. package/dist/types/context/viewportPriority.d.ts +18 -0
  76. package/dist/types/customComponents.d.ts +38 -0
  77. package/dist/types/hooks/useSmoothMarkdownStream.d.ts +21 -0
  78. package/dist/types/i18n/useSafeI18n.d.ts +11 -0
  79. package/dist/types/index.d.ts +71 -0
  80. package/dist/types/renderers/codeBlockExtraProps.d.ts +5 -0
  81. package/dist/types/renderers/renderChildren.d.ts +7 -0
  82. package/dist/types/renderers/renderNode.d.ts +5 -0
  83. package/dist/types/server-renderer/html.d.ts +2 -0
  84. package/dist/types/server-renderer/index.d.ts +176 -0
  85. package/dist/types/server-renderer/katex.d.ts +2 -0
  86. package/dist/types/server.d.ts +56 -0
  87. package/dist/types/tailwind-entry.d.ts +3 -0
  88. package/dist/types/tooltip/singletonTooltip.d.ts +8 -0
  89. package/dist/types/types/component-props.d.ts +234 -0
  90. package/dist/types/types/node-component.d.ts +15 -0
  91. package/dist/types/types/octane.d.ts +12 -0
  92. package/dist/types/types.d.ts +127 -0
  93. package/dist/types/utils/customHtmlTag.d.ts +18 -0
  94. package/dist/types/utils/devEnv.d.ts +2 -0
  95. package/dist/types/utils/htmlToOctane.d.ts +23 -0
  96. package/dist/types/utils/languageIcon.d.ts +9 -0
  97. package/dist/types/utils/languageIconExtended.d.ts +2 -0
  98. package/dist/types/utils/normalizeKaTeXRenderInput.d.ts +2 -0
  99. package/dist/types/utils/performanceMonitor.d.ts +79 -0
  100. package/dist/types/utils/safeRaf.d.ts +3 -0
  101. package/dist/types/utils/streamingTextState.d.ts +3 -0
  102. package/dist/types/workers/katexRenderer.worker.d.ts +2 -0
  103. package/dist/types/workers/katexWorkerClient.d.ts +32 -0
  104. package/dist/types/workers/mermaidParser.worker.d.ts +2 -0
  105. package/dist/types/workers/mermaidWorkerClient.d.ts +15 -0
  106. package/package.json +149 -0
package/README.md ADDED
@@ -0,0 +1,276 @@
1
+ # markstream-octane
2
+
3
+ Native Octane streaming Markdown renderer for AI chat, SSE/WebSocket output, incomplete Markdown, Mermaid, KaTeX, Shiki, and Monaco.
4
+
5
+ `markstream-octane` is compiled with the Octane compiler and runs on the Octane client and server runtimes. It does not require a React root or React compatibility layer. The published package contains precompiled JavaScript, declarations, styles, and workers, so consumers do not need to compile TSRX from `node_modules`.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ pnpm add markstream-octane octane
11
+ ```
12
+
13
+ Octane 0.1.x currently declares Vite 8 plus React/React DOM compatibility peers in its own package metadata. `markstream-octane` does not import or execute React, but package managers may still ask consumers to satisfy those upstream Octane peer declarations.
14
+
15
+ Optional renderer features are peer dependencies. Install only the features used by your Markdown:
16
+
17
+ | Feature | Package |
18
+ | --- | --- |
19
+ | Shiki code blocks | `stream-markdown` |
20
+ | Monaco editor code blocks | `stream-monaco` |
21
+ | Mermaid diagrams | `mermaid` |
22
+ | KaTeX math | `katex` |
23
+ | D2 diagrams | `@terrastruct/d2` |
24
+ | Infographic blocks | `@antv/infographic` |
25
+
26
+ ## Compiler setup
27
+
28
+ Octane source components use the `.tsrx` extension. Add the Octane compiler to Vite:
29
+
30
+ ```ts
31
+ // vite.config.ts
32
+ import { octane } from 'octane/compiler/vite'
33
+ import { defineConfig } from 'vite'
34
+
35
+ export default defineConfig({
36
+ plugins: [octane()],
37
+ resolve: {
38
+ extensions: ['.tsrx', '.ts', '.mjs', '.js', '.json'],
39
+ },
40
+ })
41
+ ```
42
+
43
+ Configure TSRX and the Octane JSX runtime:
44
+
45
+ ```json
46
+ {
47
+ "tsrx": {
48
+ "compiler": "octane/compiler"
49
+ },
50
+ "compilerOptions": {
51
+ "jsx": "react-jsx",
52
+ "jsxImportSource": "octane",
53
+ "module": "ESNext",
54
+ "moduleResolution": "Bundler",
55
+ "target": "ESNext"
56
+ }
57
+ }
58
+ ```
59
+
60
+ ## Quick start
61
+
62
+ Import one Markstream stylesheet explicitly; the JavaScript entry does not inject styles:
63
+
64
+ ```tsrx
65
+ // App.tsrx
66
+ import { NodeRenderer } from 'markstream-octane'
67
+ import 'markstream-octane/index.css'
68
+
69
+ export function ChatMessage(props: {
70
+ content: string
71
+ isDone: boolean
72
+ }) {
73
+ return (
74
+ <NodeRenderer
75
+ content={props.content}
76
+ final={props.isDone}
77
+ fade={false}
78
+ />
79
+ )
80
+ }
81
+ ```
82
+
83
+ Mount the app with the native Octane root:
84
+
85
+ ```ts
86
+ // main.ts
87
+ import { createRoot } from 'octane'
88
+ import { ChatMessage } from './App.tsrx'
89
+
90
+ const host = document.getElementById('root')
91
+ if (!host)
92
+ throw new Error('Missing #root')
93
+
94
+ createRoot(host).render(ChatMessage, {
95
+ content: '# Hello from Octane',
96
+ isDone: true,
97
+ })
98
+ ```
99
+
100
+ Use `markstream-octane/index.px.css` when the application changes the root font size but renderer dimensions should remain pixel-based. Import `katex/dist/katex.min.css` as well when math rendering is enabled.
101
+
102
+ ## Streaming
103
+
104
+ Accumulate SSE or WebSocket chunks and pass the growing string through `content`. Set `final` only after the stream ends:
105
+
106
+ ```tsrx
107
+ import { useState } from 'octane'
108
+ import { NodeRenderer } from 'markstream-octane'
109
+
110
+ export function StreamingMessage() {
111
+ const [content, setContent] = useState('')
112
+ const [final, setFinal] = useState(false)
113
+
114
+ const start = () => {
115
+ setContent('')
116
+ setFinal(false)
117
+
118
+ const source = new EventSource('/api/chat/stream')
119
+ source.onmessage = (event) => {
120
+ if (event.data === '[DONE]') {
121
+ source.close()
122
+ setFinal(true)
123
+ return
124
+ }
125
+
126
+ const chunk = JSON.parse(event.data) as { content: string }
127
+ setContent(current => current + chunk.content)
128
+ }
129
+ }
130
+
131
+ return (
132
+ <>
133
+ <button type="button" onClick={start}>Start</button>
134
+ <NodeRenderer
135
+ content={content}
136
+ final={final}
137
+ typewriter
138
+ smoothStreaming="auto"
139
+ />
140
+ </>
141
+ )
142
+ }
143
+ ```
144
+
145
+ If parsing is already owned by a worker or store, pass pre-parsed `nodes` instead of `content`.
146
+
147
+ ## Server rendering
148
+
149
+ Use the explicit server entry together with `octane/server`:
150
+
151
+ ```ts
152
+ import { NodeRenderer } from 'markstream-octane/server'
153
+ import { renderToString } from 'octane/server'
154
+
155
+ const result = renderToString(NodeRenderer, {
156
+ content: '# Server-rendered Markdown',
157
+ final: true,
158
+ })
159
+
160
+ console.log(result.html)
161
+ ```
162
+
163
+ The root export selects the server build through its `node` condition, but `markstream-octane/server` makes the runtime boundary unambiguous in server-only code.
164
+
165
+ ## Custom components
166
+
167
+ Use `streamingComponents` for parser-backed custom tags. These components receive `NodeComponentProps`, including the parsed node, loading state, render context, and child renderer:
168
+
169
+ ```tsrx
170
+ import type { NodeComponentProps } from 'markstream-octane'
171
+ import {
172
+ NodeRenderer,
173
+ defineStreamingComponents,
174
+ } from 'markstream-octane'
175
+
176
+ type DocumentNode = {
177
+ type: 'documentlink'
178
+ content: string
179
+ loading?: boolean
180
+ }
181
+
182
+ function DocumentLink(props: NodeComponentProps<DocumentNode>) {
183
+ return (
184
+ <span aria-busy={props.node.loading || undefined}>
185
+ {props.node.content}
186
+ </span>
187
+ )
188
+ }
189
+
190
+ const components = defineStreamingComponents({
191
+ documentlink: DocumentLink,
192
+ })
193
+
194
+ export function Message(props: { content: string }) {
195
+ return (
196
+ <NodeRenderer
197
+ content={props.content}
198
+ streamingComponents={components}
199
+ />
200
+ )
201
+ }
202
+ ```
203
+
204
+ Keys in `streamingComponents` are normalized and included in the parser's effective `customHtmlTags`, so incomplete tags can render while tokens arrive.
205
+
206
+ Use `htmlComponents` for the dynamic HTML path. These receive HTML-style props and `children`:
207
+
208
+ ```tsrx
209
+ import type { OctaneNode } from 'octane'
210
+ import {
211
+ NodeRenderer,
212
+ defineHtmlComponents,
213
+ } from 'markstream-octane'
214
+
215
+ function Badge(props: { kind?: string, children?: OctaneNode }) {
216
+ return <mark data-kind={props.kind}>{props.children}</mark>
217
+ }
218
+
219
+ const htmlComponents = defineHtmlComponents({ badge: Badge })
220
+
221
+ export function Message(props: { content: string }) {
222
+ return (
223
+ <NodeRenderer
224
+ content={props.content}
225
+ htmlComponents={htmlComponents}
226
+ />
227
+ )
228
+ }
229
+ ```
230
+
231
+ `setCustomComponents` and `customId` remain available for shared application-level registration and built-in node overrides such as `code_block`, `mermaid`, or a language-specific renderer.
232
+
233
+ ## Tailwind
234
+
235
+ Non-Tailwind applications should use the precompiled stylesheet:
236
+
237
+ ```ts
238
+ import 'markstream-octane/index.css'
239
+ ```
240
+
241
+ Tailwind applications can import the Tailwind-ready stylesheet and include the extracted class list:
242
+
243
+ ```ts
244
+ import 'markstream-octane/index.tailwind.css'
245
+ ```
246
+
247
+ ```js
248
+ module.exports = {
249
+ content: [
250
+ './src/**/*.{js,ts,tsrx}',
251
+ require('markstream-octane/tailwind'),
252
+ ],
253
+ }
254
+ ```
255
+
256
+ ## Public entries
257
+
258
+ - `markstream-octane`: precompiled Octane client runtime and public types
259
+ - `markstream-octane/server`: precompiled Octane server renderer
260
+ - `markstream-octane/index.css`: precompiled renderer styles
261
+ - `markstream-octane/index.px.css`: pixel-based renderer styles
262
+ - `markstream-octane/index.tailwind.css`: Tailwind-ready styles
263
+ - `markstream-octane/tailwind`: extracted Tailwind class source
264
+ - worker subpaths for KaTeX and Mermaid
265
+
266
+ ## Development
267
+
268
+ From the repository root:
269
+
270
+ ```bash
271
+ pnpm --filter markstream-octane typecheck
272
+ pnpm --filter markstream-octane test
273
+ pnpm --filter markstream-octane build
274
+ pnpm play:octane
275
+ pnpm test:e2e:octane-playground
276
+ ```
@@ -0,0 +1,2 @@
1
+ // octane-no-slot: compiler-assigned hook slots are already present.
2
+ var n={cpp:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16">\n <path fill="none" stroke="#8caaee" stroke-linecap="round" stroke-linejoin="round" d="m 2.5559121,12.951629 c 2.7459832,2.734744 7.1981158,2.734744 9.9441189,0 l -1.789955,-1.782586 c -1.7574201,1.750224 -4.606788,1.750224 -6.3642295,0 -1.7574416,-1.7502236 -1.7574416,-4.587893 0,-6.338097 1.7574415,-1.750224 4.6068094,-1.750224 6.3642295,0 l 0.894977,-0.8912929 0.894978,-0.891293 c -2.7460031,-2.73472867 -7.198136,-2.73472867 -9.9441191,0 -2.74598585,2.7347089 -2.74598585,7.1685599 2e-7,9.9032689 z" clip-rule="evenodd" />\n <path fill="none" stroke="#8caaee" stroke-linecap="round" stroke-linejoin="round" d="M7.5 6v4M5.513524 7.9999996H9.51304M13.486476 5.9999996v4M11.5 7.9999992h3.999516" />\n</svg>\n',svg:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16">\n <path fill="none" stroke="#ef9f76" stroke-linecap="round" stroke-linejoin="round" d="m4.54 10 6.92-4m-6.92 4a1.5 1.5 0 10-2.6 1.5 1.5 1.5 0 002.6-1.5M8 4v8m0-8a1.5 1.5 0 100-3 1.5 1.5 0 000 3M4.54 6l6.92 4M4.54 6a1.5 1.5 0 10-2.6-1.5A1.5 1.5 0 004.54 6M8 12a1.5 1.5 0 100 3 1.5 1.5 0 000-3m3.46-2a1.5 1.5 0 102.6 1.5 1.5 1.5 0 00-2.6-1.5m0-4a1.5 1.5 0 102.6-1.5 1.5 1.5 0 00-2.6 1.5" />\n</svg>\n',vue:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16">\n <g fill="none" stroke="#a6d189" stroke-linecap="round" stroke-linejoin="round">\n <path d="M1 1.5h5.44L8 4.56 9.56 1.5H15l-6.99 13z" />\n <path d="M12.05 1.73 8 9.28 3.95 1.73" />\n </g>\n</svg>\n'};export{n as EXTENDED_LANGUAGE_ICON_MAP};