@ant-design/x-markdown-mini 0.1.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +216 -0
  3. package/dist/components/Markdown/index.acss +103 -0
  4. package/dist/components/Markdown/index.axml +12 -0
  5. package/dist/components/Markdown/index.js +93 -0
  6. package/dist/components/Markdown/index.json +7 -0
  7. package/dist/components/MiniNodeRenderer/index.acss +11 -0
  8. package/dist/components/MiniNodeRenderer/index.axml +113 -0
  9. package/dist/components/MiniNodeRenderer/index.js +37 -0
  10. package/dist/components/MiniNodeRenderer/index.json +7 -0
  11. package/dist/components/MiniNodeRenderer/index.sjs +63 -0
  12. package/dist/es/Markdown/index.acss +103 -0
  13. package/dist/es/Markdown/index.axml +12 -0
  14. package/dist/es/Markdown/index.js +93 -0
  15. package/dist/es/Markdown/index.json +7 -0
  16. package/dist/es/MiniNodeRenderer/index.acss +11 -0
  17. package/dist/es/MiniNodeRenderer/index.axml +113 -0
  18. package/dist/es/MiniNodeRenderer/index.js +37 -0
  19. package/dist/es/MiniNodeRenderer/index.json +7 -0
  20. package/dist/es/MiniNodeRenderer/index.sjs +63 -0
  21. package/dist/index.d.mts +508 -0
  22. package/dist/index.d.ts +508 -0
  23. package/dist/index.js +3151 -0
  24. package/dist/index.mjs +3111 -0
  25. package/dist/miniprogram_dist/components/Markdown/index.js +85 -0
  26. package/dist/miniprogram_dist/components/Markdown/index.json +10 -0
  27. package/dist/miniprogram_dist/components/Markdown/index.wxml +11 -0
  28. package/dist/miniprogram_dist/components/Markdown/index.wxss +103 -0
  29. package/dist/miniprogram_dist/components/MiniNodeRenderer/index.js +39 -0
  30. package/dist/miniprogram_dist/components/MiniNodeRenderer/index.json +10 -0
  31. package/dist/miniprogram_dist/components/MiniNodeRenderer/index.wxml +112 -0
  32. package/dist/miniprogram_dist/components/MiniNodeRenderer/index.wxs +40 -0
  33. package/dist/miniprogram_dist/components/MiniNodeRenderer/index.wxss +11 -0
  34. package/dist/miniprogram_dist/es/Markdown/index.js +85 -0
  35. package/dist/miniprogram_dist/es/Markdown/index.json +10 -0
  36. package/dist/miniprogram_dist/es/Markdown/index.wxml +11 -0
  37. package/dist/miniprogram_dist/es/Markdown/index.wxss +103 -0
  38. package/dist/miniprogram_dist/es/MiniNodeRenderer/index.js +39 -0
  39. package/dist/miniprogram_dist/es/MiniNodeRenderer/index.json +10 -0
  40. package/dist/miniprogram_dist/es/MiniNodeRenderer/index.wxml +112 -0
  41. package/dist/miniprogram_dist/es/MiniNodeRenderer/index.wxs +40 -0
  42. package/dist/miniprogram_dist/es/MiniNodeRenderer/index.wxss +11 -0
  43. package/dist/miniprogram_dist/index.js +3151 -0
  44. package/dist/miniprogram_dist/plugins/CodeHighlight/index.js +8038 -0
  45. package/dist/miniprogram_dist/plugins/CodeHighlight/style.wxss +105 -0
  46. package/dist/miniprogram_dist/plugins/Latex/index.js +14728 -0
  47. package/dist/miniprogram_dist/plugins/Latex/style.wxss +648 -0
  48. package/dist/miniprogram_dist/shared/flattenInline.js +100 -0
  49. package/dist/plugins/CodeHighlight/index.d.mts +27 -0
  50. package/dist/plugins/CodeHighlight/index.d.ts +27 -0
  51. package/dist/plugins/CodeHighlight/index.js +8038 -0
  52. package/dist/plugins/CodeHighlight/index.mjs +8028 -0
  53. package/dist/plugins/CodeHighlight/style.acss +105 -0
  54. package/dist/plugins/Latex/index.d.mts +12 -0
  55. package/dist/plugins/Latex/index.d.ts +12 -0
  56. package/dist/plugins/Latex/index.js +14728 -0
  57. package/dist/plugins/Latex/index.mjs +14705 -0
  58. package/dist/plugins/Latex/style.acss +648 -0
  59. package/dist/shared/flattenInline.js +100 -0
  60. package/dist/types-CegkonfJ.d.mts +83 -0
  61. package/dist/types-CegkonfJ.d.ts +83 -0
  62. package/package.json +93 -0
@@ -0,0 +1,508 @@
1
+ import { Token, Tokens, MarkedExtension } from 'marked';
2
+ export { MarkedExtension, Token, Tokens } from 'marked';
3
+
4
+ type BuiltinPlatform = 'wechat' | 'alipay';
5
+ type Platform = BuiltinPlatform | (string & {});
6
+ type PlatformInput = Platform | 'auto';
7
+ interface PlatformCapabilities {
8
+ supportsOlStart: boolean;
9
+ requiresHttpsImage: boolean;
10
+ anchorHrefMode: 'href' | 'data-href';
11
+ supportsTable: boolean;
12
+ supportsPre: boolean;
13
+ supportsBlockquote: boolean;
14
+ }
15
+ interface PlatformRenderer {
16
+ name: Platform;
17
+ capabilities: PlatformCapabilities;
18
+ renderTokens(tokens: Token[], ctx: RenderContext): MiniNode[];
19
+ }
20
+
21
+ /**
22
+ * 语义流式渲染配置
23
+ */
24
+ interface SemanticStreamingConfig {
25
+ /** 语义分隔符正则,默认按句/标点切块 */
26
+ delimiters?: RegExp;
27
+ /** 单块最大字符数,超长句强制按长度切 */
28
+ maxChunkSize?: number;
29
+ /**
30
+ * 语义块之间的延迟(ms)。
31
+ * - number: 恒定延迟
32
+ * - number[]: 按已渲染块序号变速(如 [300,200,100,0] 随块加速),超出长度取最后一项
33
+ */
34
+ chunkDelay?: number | number[];
35
+ /**
36
+ * 块内字符延迟(ms),打字机逐字节奏。
37
+ * - number: 恒定延迟
38
+ * - number[]: 按已渲染块序号变速(如 [50,30,20,10,50]),超出长度取最后一项
39
+ */
40
+ charDelay?: number | number[];
41
+ }
42
+ /**
43
+ * 流式渲染配置
44
+ */
45
+ interface StreamingConfig {
46
+ /**
47
+ * 是否还有后续输入。
48
+ * - true: 还有后续输入,保留未完成片段
49
+ * - false: 本轮输入后 flush 剩余内容并结束
50
+ */
51
+ hasNextChunk: boolean;
52
+ /**
53
+ * 语义分块开关 / 配置:
54
+ * - true: 启用默认语义分块
55
+ * - false: 关闭语义分块,直接一次性渲染
56
+ * - object: 启用语义分块并覆盖配置(delimiters / maxChunkSize / chunkDelay / charDelay)
57
+ */
58
+ semantic?: boolean | SemanticStreamingConfig;
59
+ /**
60
+ * 流式块动画开关
61
+ * - true: 启用流式块动画
62
+ * - false: 关闭流式块动画
63
+ */
64
+ enableAnimation?: boolean;
65
+ }
66
+ interface XMarkdownMiniProps {
67
+ /** Markdown 文本(全量或当前累计流式内容) */
68
+ content: string;
69
+ /** 目标平台,可选,默认 auto 自动识别 */
70
+ platform?: PlatformInput;
71
+ /**
72
+ * 流式渲染:
73
+ * - false: 关闭流式,走一次性渲染
74
+ * - true: 开启默认流式优化(等同 { hasNextChunk: true, semantic: true, enableAnimation: true })
75
+ * - object: 自定义流式行为,需显式提供 hasNextChunk
76
+ */
77
+ streaming?: false | true | StreamingConfig;
78
+ /** 文本是否可选择(推荐默认 true,各端适配尽量映射) */
79
+ selectable?: boolean;
80
+ /** GFM 表格、删除线、自动换行(默认 true)。Per-call 可覆盖构造时的默认值 */
81
+ gfm?: boolean;
82
+ /** 软换行 \n 解析为 <br>(默认 false)。Per-call 可覆盖构造时的默认值 */
83
+ breaks?: boolean;
84
+ /**
85
+ * Per-call extensions that override instance-level extensions for this render.
86
+ * Accepts XMarkdownExtension (preferred, with miniRenderer) or MarkedExtension.
87
+ * Tokenizers are registered via `marked.use()`; renderers are resolved through
88
+ * the per-call list (instance-level `components` extension is always preserved).
89
+ */
90
+ extensions?: (XMarkdownExtension | MarkedExtension)[];
91
+ /** 渲染生命周期 */
92
+ onRenderStart?: () => void;
93
+ onRenderProgress?: (payload: {
94
+ markdown: string;
95
+ }) => void;
96
+ onRenderComplete?: () => void;
97
+ /** 流式时每轮解析完成回调,用于 setData(nodes) */
98
+ onPatch?: (nodes: MiniNode[]) => void;
99
+ }
100
+ interface XMarkdownMiniTokenProps {
101
+ /** Markdown 文本(全量或累计流式内容) */
102
+ content: string;
103
+ /** GFM 表格、删除线、自动换行(默认 true)。Per-call 可覆盖构造时的默认值 */
104
+ gfm?: boolean;
105
+ /** 软换行 \n 解析为 <br>(默认 false)。Per-call 可覆盖构造时的默认值 */
106
+ breaks?: boolean;
107
+ /**
108
+ * Per-call extensions that override instance-level extensions for this render.
109
+ * Accepts XMarkdownExtension (preferred, with miniRenderer) or MarkedExtension.
110
+ * Tokenizers are registered via `marked.use()`; renderers are resolved through
111
+ * the per-call list (instance-level `components` extension is always preserved).
112
+ */
113
+ extensions?: (XMarkdownExtension | MarkedExtension)[];
114
+ /**
115
+ * 流式解析:
116
+ * - false: 关闭流式,走一次性 lex
117
+ * - true: 开启默认流式优化(等同 { hasNextChunk: true, semantic: true })
118
+ * - object: 自定义流式行为,需显式提供 hasNextChunk
119
+ */
120
+ streaming?: false | true | StreamingConfig;
121
+ /** 生命周期 */
122
+ onRenderStart?: () => void;
123
+ onRenderProgress?: (payload: {
124
+ markdown: string;
125
+ }) => void;
126
+ onRenderComplete?: () => void;
127
+ /** 流式时每轮 lex 完成回调,用于拿到 marked Token[] */
128
+ onPatch?: (tokens: Token[]) => void;
129
+ }
130
+ /**
131
+ * A tokenizer + renderer extension colocated on a single object — the
132
+ * preferred shape for new XMarkdownMini extensions. Structurally mirrors
133
+ * marked's `TokenizerAndRendererExtension` but adds `miniRenderer` so the
134
+ * renderer can return `MiniNode` directly instead of HTML.
135
+ */
136
+ interface XMarkdownTokenizerExtension {
137
+ /** Token.type produced by this tokenizer. */
138
+ name: string;
139
+ /** Tokenizer level: 'block' or 'inline'. */
140
+ level?: 'block' | 'inline';
141
+ /** Marked start hook: returns the index of the next potential match. */
142
+ start?: (src: string) => number | undefined;
143
+ /** Marked tokenizer hook. */
144
+ tokenizer?: (this: any, src: string, tokens: Token[]) => Tokens.Generic | undefined;
145
+ /** Optional child token names (forwarded to marked). */
146
+ childTokens?: string[];
147
+ /** Preferred: return a MiniNode tree directly for this token. */
148
+ miniRenderer?: (token: Token, ctx: RenderContext) => MiniNode | MiniNode[] | null | undefined;
149
+ /**
150
+ * marked-style HTML renderer. When present without `miniRenderer`, the HTML
151
+ * output is run through `htmlToMiniNodes` and the result is used.
152
+ */
153
+ renderer?: (this: any, token: Token) => string;
154
+ }
155
+ /**
156
+ * Preferred extension shape for `XMarkdownMiniOptions.extensions`. A subset of
157
+ * `MarkedExtension` whose tokenizer entries carry `miniRenderer` / `renderer`
158
+ * alongside the tokenizer. `MarkedExtension`s (e.g. community plugins that
159
+ * only emit HTML) are also accepted in the same array.
160
+ */
161
+ interface XMarkdownExtension {
162
+ /** Tokenizer entries with colocated mini-program renderers. */
163
+ extensions?: XMarkdownTokenizerExtension[];
164
+ /** Marked walkTokens hook (forwarded to marked). */
165
+ walkTokens?: MarkedExtension['walkTokens'];
166
+ /** Marked hooks (forwarded to marked). */
167
+ hooks?: MarkedExtension['hooks'];
168
+ /** Marked tokenizer overrides (forwarded to marked). */
169
+ tokenizer?: MarkedExtension['tokenizer'];
170
+ }
171
+ /** 渲染上下文:transformer 共用的公共配置。 */
172
+ interface RenderContext {
173
+ /** 是否启用块级动画 */
174
+ animation?: boolean;
175
+ /** 文本是否可选择 */
176
+ selectable?: boolean;
177
+ /**
178
+ * 是否对文本节点的 value 做 HTML 实体转义。
179
+ * - true(默认):用于会解码实体的平台节点容器
180
+ * - false:用于自渲染组件(<text>{{value}}</text> 不解码实体)
181
+ */
182
+ escapeText?: boolean;
183
+ /**
184
+ * Colocated tokenizer+renderer extensions registered on the instance.
185
+ */
186
+ extensions?: readonly XMarkdownExtension[];
187
+ /**
188
+ * Recursively render an inline token array to MiniNode[]. Provided by the
189
+ * platform transformer; used by custom extension miniRenderers that emit
190
+ * tokens with children (e.g. <custom-tag>inner</custom-tag>).
191
+ */
192
+ renderInlineTokens?: (tokens: Token[]) => MiniNode[];
193
+ }
194
+ interface MiniNode {
195
+ /** 标签名,小写 */
196
+ name: string;
197
+ /**
198
+ * 自定义组件原始标签名。仅由 `components` 白名单合成的节点携带,等于 `name`,
199
+ * 用于宿主页面在作用域插槽 / dispatcher 里按 `node.tag` 分发(对齐 markdown-x 约定)。
200
+ */
201
+ tag?: string;
202
+ /** 属性,class/style 等小写 */
203
+ attrs?: Record<string, string | number | boolean>;
204
+ /** 子节点 */
205
+ children?: MiniNode[];
206
+ /** 是否开启动画 */
207
+ animate?: boolean;
208
+ }
209
+
210
+ /**
211
+ * Streaming tail preprocessor:
212
+ * - 'remend' (default): auto-completes unfinished markdown tail syntax
213
+ * - false: disables fixup
214
+ * - function: custom tail preprocessor
215
+ */
216
+ type StreamingFixup = 'remend' | false | ((text: string) => string);
217
+
218
+ interface XMarkdownMiniOptions {
219
+ /**
220
+ * Whether to escape text nodes. Defaults to true for native mini-program node output.
221
+ * Custom component paths should pass false because <text>{{value}}</text>
222
+ * does not decode HTML entities.
223
+ */
224
+ escapeText?: boolean;
225
+ /**
226
+ * Streaming tail fixup strategy. Defaults to 'remend'.
227
+ * Only affects streaming paths; one-shot parse/render calls are untouched.
228
+ */
229
+ streamingFixup?: StreamingFixup;
230
+ /** GFM 表格、删除线、自动换行(默认 true) */
231
+ gfm?: boolean;
232
+ /** 软换行 \n 解析为 <br>(默认 false) */
233
+ breaks?: boolean;
234
+ /**
235
+ * Per-instance extensions. Accepts either the colocated
236
+ * `XMarkdownExtension` shape (tokenizer + `miniRenderer` / `renderer` on the
237
+ * same object — preferred) or a plain `MarkedExtension` (for community
238
+ * marked plugins that only emit HTML). All entries are forwarded to
239
+ * `new Marked(...)`; the new fields (`miniRenderer`) are ignored by marked.
240
+ * Can be overridden per render call via `renderNodes({ extensions })` /
241
+ * `renderTokens({ extensions })`.
242
+ */
243
+ extensions?: (XMarkdownExtension | MarkedExtension)[];
244
+ /**
245
+ * Whitelist of literal custom-component tags allowed in Markdown source.
246
+ * For each entry, an internal inline tokenizer is synthesized that matches
247
+ * `<tag attrs>inner</tag>` (or `<tag attrs />`) and emits a MiniNode whose
248
+ * `name` is the tag and whose `children` are the recursively rendered
249
+ * inner inline tokens.
250
+ *
251
+ * Tags NOT in this list fall through to marked's built-in `html` token
252
+ * handling. Self-closing and empty tags omit `children`.
253
+ *
254
+ * @example
255
+ * ```ts
256
+ * new XMarkdownMini({ components: ['ant-button', 'ant-icon'] });
257
+ * // "<ant-button type=\"primary\">OK</ant-button>" → MiniNode tree
258
+ * ```
259
+ *
260
+ * Limitations: this PoC uses non-greedy matching, so nested same-tag
261
+ * occurrences (e.g. `<x><x>…</x></x>`) match against the innermost
262
+ * `</x>` and will not produce a nested structure.
263
+ */
264
+ components?: string[];
265
+ }
266
+ /**
267
+ * Independent renderer instance with isolated streaming state.
268
+ * Use one instance per concurrent streaming markdown source.
269
+ */
270
+ declare class XMarkdownMini {
271
+ private tokenStreamProcessor;
272
+ private nodeStreamProcessor;
273
+ private readonly escapeText;
274
+ private readonly fixup;
275
+ private readonly gfm;
276
+ private readonly breaks;
277
+ private readonly marked;
278
+ private activeTokenStreamDefaults;
279
+ private activeNodeStreamDefaults;
280
+ /** Instance-level user extensions (from constructor options). */
281
+ private readonly extensions;
282
+ /** Components extension synthesized from `opts.components`, kept separate so
283
+ * per-call extensions can override user extensions but keep components. */
284
+ private readonly componentsExtension;
285
+ constructor(opts?: XMarkdownMiniOptions);
286
+ /**
287
+ * Build the full RenderContext.extensions list for a render call.
288
+ * Per-call extensions replace instance-level user extensions; the
289
+ * components extension is always appended so that `<custom-tag>` sugar
290
+ * continues to work regardless of per-call overrides.
291
+ */
292
+ private resolveExtensions;
293
+ /**
294
+ * Register per-call extensions with the Marked instance and return a
295
+ * snapshot of the previous defaults so they can be restored after the call.
296
+ * Returns `null` if nothing to apply (no per-call extensions).
297
+ */
298
+ private applyPerCallExtensions;
299
+ private restoreDefaults;
300
+ private buildMarkedOptions;
301
+ private lex;
302
+ /**
303
+ * Parses markdown into marked's native Token[] without platform rendering.
304
+ */
305
+ parse(content: string): Token[];
306
+ /**
307
+ * Pure JS entry. Returns marked Token[] for callers that render themselves.
308
+ */
309
+ render(content: string): Token[];
310
+ render(props: XMarkdownMiniTokenProps): Token[];
311
+ /**
312
+ * Token streaming entry. AI streaming fixup runs on markdown text before lex.
313
+ */
314
+ renderTokens(props: XMarkdownMiniTokenProps): Token[];
315
+ /**
316
+ * Component/node entry. Tokens are rendered by the selected platform renderer.
317
+ */
318
+ renderNodes(props: XMarkdownMiniProps): MiniNode[];
319
+ /** Resets streaming state, usually during component detach/unmount. */
320
+ reset(): void;
321
+ }
322
+
323
+ declare const alipayRenderer: PlatformRenderer;
324
+
325
+ interface TokensToAlipayOptions extends RenderContext {
326
+ options?: {
327
+ gfm?: boolean;
328
+ breaks?: boolean;
329
+ };
330
+ }
331
+ /**
332
+ * Converts markdown into Alipay mini-program nodes.
333
+ * Kept for compatibility; new code can parse once and call tokensToAlipayNodes().
334
+ */
335
+ declare function tokensToAlipay(content: string, opts?: TokensToAlipayOptions): MiniNode[];
336
+ /** Converts pre-lexed marked Token[] into Alipay mini-program nodes. */
337
+ declare function tokensToAlipayNodes(tokens: Token[], ctx?: RenderContext): MiniNode[];
338
+
339
+ interface TokensToWechatOptions extends RenderContext {
340
+ options?: {
341
+ gfm?: boolean;
342
+ breaks?: boolean;
343
+ };
344
+ }
345
+ /**
346
+ * Converts markdown into WeChat mini-program nodes.
347
+ * Kept for compatibility; new code can parse once and call tokensToWechatNodes().
348
+ */
349
+ declare function tokensToWechat(content: string, opts?: TokensToWechatOptions): MiniNode[];
350
+ /** Converts pre-lexed marked Token[] into WeChat mini-program nodes. */
351
+ declare function tokensToWechatNodes(tokens: Token[], ctx?: RenderContext): MiniNode[];
352
+
353
+ declare const wechatRenderer: PlatformRenderer;
354
+
355
+ declare function resolvePlatform(platform?: PlatformInput): Platform;
356
+ declare function getPlatformRenderer(platform: Platform): PlatformRenderer;
357
+ declare function registerPlatformRenderer(renderer: PlatformRenderer): void;
358
+
359
+ interface StreamingProcessorConfig<T> {
360
+ /**
361
+ * 把一段已经过流式预处理的 markdown 文本转成平台节点的函数。
362
+ *
363
+ * 重要边界:AI 流式处理发生在 lex 之前。StreamingProcessor 只处理字符串层:
364
+ * 增量合并、语义切块、稳定段缓存、tail fixup。调用 transform 时,入参仍是
365
+ * markdown 字符串;调用方(通常是 XMarkdownMini)才在 transform 内部执行
366
+ * marked lexer,并交给平台 renderer。
367
+ */
368
+ transform: (markdown: string) => T[];
369
+ /**
370
+ * 可选的 tail 预处理。流式渲染时,每次 flush 只对 tail(未稳定段)调用一次,
371
+ * 已 commit 的稳定段不会再被处理。典型用法:接 remend 补全未闭合的 markdown
372
+ * 语法(**bold / `code` / [link]( 等),避免 AI 流式输出时闪烁。
373
+ *
374
+ * 注意:fixup 只影响传给 `transform` 的字符串,不会写回 renderedText,因此
375
+ * `getRenderedText()` 与 `onUpdate` 回调中拿到的仍是用户原始内容。
376
+ */
377
+ fixup?: (tail: string) => string;
378
+ onUpdate: (markdown: string) => void;
379
+ onPatch: (nodes: T[]) => void;
380
+ onComplete: () => void;
381
+ semanticEnabled?: boolean;
382
+ delimiters?: RegExp;
383
+ maxChunkSize?: number;
384
+ /** number = 恒定;number[] = 按已渲染块序号变速(随块加速),超出取末项 */
385
+ chunkDelay?: number | number[];
386
+ /** number = 恒定;number[] = 按已渲染块序号变速,超出取末项 */
387
+ charDelay?: number | number[];
388
+ }
389
+ /**
390
+ * 流式处理器:
391
+ * - 增量合并 markdown 文本(前缀匹配则视作追加,否则 reset)
392
+ * - 已稳定(前面已被空行收尾)的块只进入 transform 一次,缓存为 stableNodes
393
+ * - 仅对未稳定的 tail(最后一段)每次重新走 fixup → transform
394
+ * - chunkDelay/charDelay 全为 0 时跳过 setTimeout 链,单次 onPatch 即返回
395
+ * - 否则走语义切块的"打字机"模式:按 delimiters / maxChunkSize 推进 renderedText
396
+ */
397
+ declare class StreamingProcessor<T = unknown> {
398
+ private buffer;
399
+ private renderedText;
400
+ private previousMarkdown;
401
+ private stableNodes;
402
+ private committedLen;
403
+ /** Whether the character at committedLen is inside a fenced code block (used for incremental scanning). */
404
+ private committedInFence;
405
+ private committedFenceChar;
406
+ private pendingChunks;
407
+ private chunkIndex;
408
+ /** 已渲染块的累计序号,用于数组变速延迟(charDelay/chunkDelay 为数组时按此取值)。 */
409
+ private chunkRenderIndex;
410
+ private activeChunk;
411
+ private activeChunkOffset;
412
+ private timer;
413
+ private currentHasNextChunk;
414
+ private readonly config;
415
+ constructor(cfg: StreamingProcessorConfig<T>);
416
+ /** 内容更新:增量则追加到 buffer,否则 reset 后整段替换。 */
417
+ handleContentUpdate(content: string): void;
418
+ reset(): void;
419
+ /**
420
+ * 推进渲染。若 chunk/charDelay 都为 0,立即一次性 flush;否则进入打字机循环。
421
+ */
422
+ runRenderLoop(hasNextChunk: boolean): void;
423
+ /** 当前已输出给 UI 的完整 markdown 字符串 */
424
+ getRenderedText(): string;
425
+ /** 是否还有待处理 chunks(外部可据此判断是否完成) */
426
+ hasPendingChunks(): boolean;
427
+ /** 按 delimiters + maxChunkSize 把 buffer 切成 chunk 序列;hasNext=false 时 flush 末尾。 */
428
+ private splitIntoChunks;
429
+ private scheduleNext;
430
+ private cancelScheduledRender;
431
+ /** 推进 commit 点:从上次 committedLen 开始增量扫描,找 fenced code 之外的最后一段「双换行」位置。 */
432
+ private advanceCommit;
433
+ /** 重新解析 tail 部分,与 stableNodes 合并后 emit。 */
434
+ private flushNodes;
435
+ }
436
+
437
+ /**
438
+ * 自包含行内脚注扩展。
439
+ *
440
+ * 语法:`[^标签:内容]`,例如 `Markdown[^1:一种轻量标记语言]`。
441
+ * - `标签`(可选,到第一个 `:` 为止):marker 显示文本,默认 `注`。
442
+ * - `内容`:popover 文本,**自包含**在节点里,宿主组件本地即可弹层,
443
+ * 不依赖跨组件边界的事件/数据传递(微信尤其需要)。
444
+ *
445
+ * 产出一个 `name: 'footnote'` 的 MiniNode(带 `tag` 以便宿主按 tag 分发),
446
+ * 经 `Markdown` 组件的 slot(支付宝)/ 抽象节点(微信)交给宿主渲染 marker + popover。
447
+ */
448
+ interface FootnoteOptions {
449
+ /** 缺省 marker 文本(无显式标签时),默认 `注`。 */
450
+ defaultLabel?: string;
451
+ }
452
+ declare function Footnote(options?: FootnoteOptions): XMarkdownExtension;
453
+
454
+ /**
455
+ * 把 marked inline Token[] 扁平成一层 InlineRun[],配合小程序 `<text>` 模板使用。
456
+ *
457
+ * 背景:mini-program 的 `<text>` 不能嵌套自定义组件,所以模板无法递归通过 `<text>`
458
+ * 渲染任意深度的 strong/em/del/code 嵌套——必须在 JS 层把嵌套结构拍平为单层
459
+ * 文本片段序列,每个片段携带「class 链」让模板按类拼样式。
460
+ *
461
+ * 与旧 flattenInline 的差别:输入是 marked 原生 Token[],不再经过 MiniNode 中转。
462
+ * 这样组件可以直接消费 XMarkdownMini.parse() 的输出,无需 transformer 层。
463
+ *
464
+ * Link / Image 由模板单独渲染(小程序 `<text>` 之外的 `<image>` / 可点击 `<text>`),
465
+ * 不并入文本 run。Hard break 用独立 `kind:'br'` 占位。
466
+ */
467
+ type InlineRunKind = 'text' | 'br' | 'link' | 'image';
468
+ interface InlineRun {
469
+ kind: InlineRunKind;
470
+ /** 用作文本节点或链接文本;image 的话是 alt */
471
+ value: string;
472
+ /** 空格分隔的样式类链,e.g. "md-strong md-em" */
473
+ classes: string;
474
+ /** link / image 的属性。其他 kind 不带 attrs。 */
475
+ attrs?: {
476
+ href?: string;
477
+ src?: string;
478
+ alt?: string;
479
+ title?: string;
480
+ };
481
+ }
482
+ interface FlattenInlineTokensOptions {
483
+ /**
484
+ * 是否对文本值做 HTML 转义。
485
+ * - true:用于会解码实体的平台节点容器
486
+ * - false:用于自渲染 `<text>{{value}}</text>` 模板(不解码实体)
487
+ */
488
+ escapeText: boolean;
489
+ }
490
+ declare function flattenInlineTokens(tokens: Token[], opts: FlattenInlineTokensOptions): InlineRun[];
491
+
492
+ /**
493
+ * Parses markdown into marked Token[] without platform rendering.
494
+ */
495
+ declare function parse(content: string): Token[];
496
+ /**
497
+ * Pure JS entry. `render(markdown)` returns marked Token[].
498
+ * Component/node rendering belongs to `renderNodes(props)`.
499
+ */
500
+ declare function render(content: string): Token[];
501
+ declare function render(props: XMarkdownMiniTokenProps): Token[];
502
+ /**
503
+ * Node rendering entry for mini-program components.
504
+ * Use `new XMarkdownMini()` for concurrent streaming sources.
505
+ */
506
+ declare function renderNodes(props: XMarkdownMiniProps): MiniNode[];
507
+
508
+ export { type BuiltinPlatform, type FlattenInlineTokensOptions, Footnote, type FootnoteOptions, type InlineRun, type InlineRunKind, type MiniNode, type Platform, type PlatformCapabilities, type PlatformInput, type PlatformRenderer, type RenderContext, type SemanticStreamingConfig, type StreamingConfig, type StreamingFixup, StreamingProcessor, type XMarkdownExtension, XMarkdownMini, type XMarkdownMiniOptions, type XMarkdownMiniProps, type XMarkdownMiniTokenProps, type XMarkdownTokenizerExtension, alipayRenderer, flattenInlineTokens, getPlatformRenderer, parse, registerPlatformRenderer, render, renderNodes, resolvePlatform, tokensToAlipay, tokensToAlipayNodes, tokensToWechat, tokensToWechatNodes, wechatRenderer };