@copilotkit/markdown 2.0.0-rc.19 → 2.0.0-rc.21
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 +24 -7
- package/dist/dom/index.cjs +255 -0
- package/dist/dom/index.cjs.map +1 -0
- package/dist/dom/index.d.cts +93 -0
- package/dist/dom/index.d.cts.map +1 -0
- package/dist/dom/index.d.mts +93 -0
- package/dist/dom/index.d.mts.map +1 -0
- package/dist/dom/index.mjs +254 -0
- package/dist/dom/index.mjs.map +1 -0
- package/dist/index.cjs +522 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +271 -4
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +271 -4
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +512 -12
- package/dist/index.mjs.map +1 -1
- package/dist/react/index.cjs +66 -458
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +13 -22
- package/dist/react/index.d.cts.map +1 -1
- package/dist/react/index.d.mts +13 -22
- package/dist/react/index.d.mts.map +1 -1
- package/dist/react/index.mjs +67 -459
- package/dist/react/index.mjs.map +1 -1
- package/dist/react-native/index.cjs.map +1 -1
- package/dist/react-native/index.d.cts.map +1 -1
- package/dist/react-native/index.d.mts.map +1 -1
- package/dist/react-native/index.mjs.map +1 -1
- package/dist/vue/index.cjs +86 -199
- package/dist/vue/index.cjs.map +1 -1
- package/dist/vue/index.d.cts +46 -16
- package/dist/vue/index.d.cts.map +1 -1
- package/dist/vue/index.d.mts +46 -16
- package/dist/vue/index.d.mts.map +1 -1
- package/dist/vue/index.mjs +88 -201
- package/dist/vue/index.mjs.map +1 -1
- package/package.json +6 -2
package/dist/index.d.cts
CHANGED
|
@@ -16,12 +16,17 @@ type StreamingMarkdownParserOptions = {
|
|
|
16
16
|
segmenter: SegmenterOptions;
|
|
17
17
|
enableTables: boolean;
|
|
18
18
|
enableAutolinks: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Parses `$…$` inline math and `$$…$$` display math into `math` nodes.
|
|
21
|
+
* Off by default: without it, dollar signs stay plain text.
|
|
22
|
+
*/
|
|
23
|
+
enableMath?: boolean;
|
|
19
24
|
};
|
|
20
25
|
/**
|
|
21
26
|
* Supported streaming markdown AST node kinds.
|
|
22
27
|
* @public
|
|
23
28
|
*/
|
|
24
|
-
type StreamingMarkdownNodeType = "document" | "paragraph" | "heading" | "blockquote" | "list" | "list-item" | "code-block" | "table" | "table-row" | "table-cell" | "thematic-break" | "text" | "em" | "strong" | "strikethrough" | "inline-code" | "soft-break" | "hard-break" | "image" | "link" | "autolink" | "citation";
|
|
29
|
+
type StreamingMarkdownNodeType = "document" | "paragraph" | "heading" | "blockquote" | "list" | "list-item" | "code-block" | "table" | "table-row" | "table-cell" | "thematic-break" | "text" | "em" | "strong" | "strikethrough" | "inline-code" | "soft-break" | "hard-break" | "image" | "link" | "autolink" | "citation" | "math";
|
|
25
30
|
/**
|
|
26
31
|
* Parsing mode for block-level processing.
|
|
27
32
|
* @public
|
|
@@ -129,6 +134,11 @@ type StreamingMarkdownListNode = StreamingMarkdownAstNodeBase & {
|
|
|
129
134
|
*/
|
|
130
135
|
type StreamingMarkdownListItemNode = StreamingMarkdownAstNodeBase & {
|
|
131
136
|
type: "list-item";
|
|
137
|
+
/**
|
|
138
|
+
* GFM task-list state: `true` for `[x]`, `false` for `[ ]`, absent for a
|
|
139
|
+
* plain list item.
|
|
140
|
+
*/
|
|
141
|
+
checked?: boolean;
|
|
132
142
|
children: number[];
|
|
133
143
|
};
|
|
134
144
|
/**
|
|
@@ -268,11 +278,21 @@ type StreamingMarkdownCitationNode = StreamingMarkdownAstNodeBase & {
|
|
|
268
278
|
idRef: string;
|
|
269
279
|
number?: number;
|
|
270
280
|
};
|
|
281
|
+
/**
|
|
282
|
+
* AST node representing TeX math (only parsed when `enableMath` is set).
|
|
283
|
+
* `text` is the TeX source without its `$` delimiters.
|
|
284
|
+
* @public
|
|
285
|
+
*/
|
|
286
|
+
type StreamingMarkdownMathNode = StreamingMarkdownAstNodeBase & {
|
|
287
|
+
type: "math";
|
|
288
|
+
text: string;
|
|
289
|
+
display: boolean;
|
|
290
|
+
};
|
|
271
291
|
/**
|
|
272
292
|
* Union of all AST node shapes.
|
|
273
293
|
* @public
|
|
274
294
|
*/
|
|
275
|
-
type StreamingMarkdownAstNode = StreamingMarkdownDocumentNode | StreamingMarkdownParagraphNode | StreamingMarkdownHeadingNode | StreamingMarkdownBlockquoteNode | StreamingMarkdownListNode | StreamingMarkdownListItemNode | StreamingMarkdownCodeBlockNode | StreamingMarkdownTableNode | StreamingMarkdownTableRowNode | StreamingMarkdownTableCellNode | StreamingMarkdownThematicBreakNode | StreamingMarkdownTextNode | StreamingMarkdownEmphasisNode | StreamingMarkdownStrongNode | StreamingMarkdownStrikethroughNode | StreamingMarkdownInlineCodeNode | StreamingMarkdownSoftBreakNode | StreamingMarkdownHardBreakNode | StreamingMarkdownImageNode | StreamingMarkdownLinkNode | StreamingMarkdownAutolinkNode | StreamingMarkdownCitationNode;
|
|
295
|
+
type StreamingMarkdownAstNode = StreamingMarkdownDocumentNode | StreamingMarkdownParagraphNode | StreamingMarkdownHeadingNode | StreamingMarkdownBlockquoteNode | StreamingMarkdownListNode | StreamingMarkdownListItemNode | StreamingMarkdownCodeBlockNode | StreamingMarkdownTableNode | StreamingMarkdownTableRowNode | StreamingMarkdownTableCellNode | StreamingMarkdownThematicBreakNode | StreamingMarkdownTextNode | StreamingMarkdownEmphasisNode | StreamingMarkdownStrongNode | StreamingMarkdownStrikethroughNode | StreamingMarkdownInlineCodeNode | StreamingMarkdownSoftBreakNode | StreamingMarkdownHardBreakNode | StreamingMarkdownImageNode | StreamingMarkdownLinkNode | StreamingMarkdownAutolinkNode | StreamingMarkdownCitationNode | StreamingMarkdownMathNode;
|
|
276
296
|
/**
|
|
277
297
|
* Citation definition captured during parsing.
|
|
278
298
|
* @public
|
|
@@ -352,10 +372,257 @@ declare function finalizeStreamingMarkdown(state: StreamingMarkdownParserState):
|
|
|
352
372
|
*
|
|
353
373
|
* No-op in production and after the first warning. Only the built-in default
|
|
354
374
|
* renderers call this — a custom `markdownRenderer` never triggers it.
|
|
375
|
+
* Pass `{ rendersMath: true }` from a default renderer that typesets math, so
|
|
376
|
+
* only code blocks are flagged.
|
|
355
377
|
*
|
|
356
378
|
* @internal
|
|
357
379
|
*/
|
|
358
|
-
declare function warnUnsupportedRichSyntaxOnce(content: string
|
|
380
|
+
declare function warnUnsupportedRichSyntaxOnce(content: string, {
|
|
381
|
+
rendersMath
|
|
382
|
+
}?: {
|
|
383
|
+
rendersMath?: boolean;
|
|
384
|
+
}): void;
|
|
385
|
+
//#endregion
|
|
386
|
+
//#region src/render/parser-session.d.ts
|
|
387
|
+
/**
|
|
388
|
+
* Parser state plus the inputs that produced it, so the next update can parse
|
|
389
|
+
* only the appended text.
|
|
390
|
+
*
|
|
391
|
+
* @public
|
|
392
|
+
*/
|
|
393
|
+
interface StreamingMarkdownParserSession {
|
|
394
|
+
parserState: StreamingMarkdownParserState;
|
|
395
|
+
text: string;
|
|
396
|
+
optionsKey: string;
|
|
397
|
+
isCompleteInput: boolean;
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* Returns the parser session for `text`, reusing `previous` when it can.
|
|
401
|
+
*
|
|
402
|
+
* - Same inputs: returns `previous` unchanged.
|
|
403
|
+
* - Text grew by a suffix: parses only the suffix, so unchanged AST nodes keep
|
|
404
|
+
* their identity (renderers rely on this to keep DOM and animations stable).
|
|
405
|
+
* - Text was replaced or options changed: parses from scratch.
|
|
406
|
+
* - `isComplete` toggled: finalizes (or re-opens) the current state.
|
|
407
|
+
*
|
|
408
|
+
* @param previous - The session from the last update, or `null` on first use.
|
|
409
|
+
* @param text - Full markdown source, which usually grows over time.
|
|
410
|
+
* @param options - Parser option overrides.
|
|
411
|
+
* @param isCompleteInput - `true` once the source is final.
|
|
412
|
+
* @public
|
|
413
|
+
*/
|
|
414
|
+
declare function updateStreamingMarkdownParserSession(previous: StreamingMarkdownParserSession | null, text: string, options: Partial<StreamingMarkdownParserOptions> | undefined, isCompleteInput: boolean): StreamingMarkdownParserSession;
|
|
415
|
+
//#endregion
|
|
416
|
+
//#region src/render/render-tree.d.ts
|
|
417
|
+
/**
|
|
418
|
+
* Key names for per-node customization (`nodeRenderers`, `nodeClassNames`).
|
|
419
|
+
* camelCase versions of the AST node types, plus `node` as a catch-all.
|
|
420
|
+
*
|
|
421
|
+
* @public
|
|
422
|
+
*/
|
|
423
|
+
type StreamingMarkdownNodeRendererKey = "node" | "document" | "paragraph" | "heading" | "blockquote" | "list" | "listItem" | "codeBlock" | "table" | "tableRow" | "tableCell" | "thematicBreak" | "text" | "em" | "strong" | "strikethrough" | "inlineCode" | "softBreak" | "hardBreak" | "image" | "link" | "autolink" | "citation" | "math";
|
|
424
|
+
/**
|
|
425
|
+
* Metadata available when a citation node is rendered.
|
|
426
|
+
*
|
|
427
|
+
* @public
|
|
428
|
+
*/
|
|
429
|
+
interface StreamingMarkdownCitationRenderData {
|
|
430
|
+
id: string;
|
|
431
|
+
number: number | string;
|
|
432
|
+
definition?: CitationDefinition;
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* Extra class names for the outermost default element of a node type, for
|
|
436
|
+
* example `{ codeBlock: "cpk-markdown-code-block" }`. Ignored for node types
|
|
437
|
+
* that render no element of their own (`document`, `text`, `softBreak`).
|
|
438
|
+
*
|
|
439
|
+
* @public
|
|
440
|
+
*/
|
|
441
|
+
type StreamingMarkdownNodeClassNames = Partial<Record<StreamingMarkdownNodeRendererKey, string>>;
|
|
442
|
+
/**
|
|
443
|
+
* Click behavior a backend attaches to a rendered element.
|
|
444
|
+
*
|
|
445
|
+
* @public
|
|
446
|
+
*/
|
|
447
|
+
type StreamingMarkdownRenderAction = {
|
|
448
|
+
type: "link";
|
|
449
|
+
url: string;
|
|
450
|
+
node: StreamingMarkdownAstNode;
|
|
451
|
+
} | {
|
|
452
|
+
type: "citation";
|
|
453
|
+
citation: StreamingMarkdownCitationRenderData;
|
|
454
|
+
node: StreamingMarkdownAstNode;
|
|
455
|
+
};
|
|
456
|
+
/**
|
|
457
|
+
* A plain element. Attribute values are already sanitized; `true` marks a
|
|
458
|
+
* boolean attribute that is present.
|
|
459
|
+
*
|
|
460
|
+
* @public
|
|
461
|
+
*/
|
|
462
|
+
interface StreamingMarkdownRenderElement {
|
|
463
|
+
kind: "element";
|
|
464
|
+
key: string;
|
|
465
|
+
tag: string;
|
|
466
|
+
attrs: Readonly<Record<string, string | true>>;
|
|
467
|
+
children: StreamingMarkdownRenderChild[];
|
|
468
|
+
action?: StreamingMarkdownRenderAction;
|
|
469
|
+
}
|
|
470
|
+
/**
|
|
471
|
+
* A text run.
|
|
472
|
+
*
|
|
473
|
+
* @public
|
|
474
|
+
*/
|
|
475
|
+
interface StreamingMarkdownRenderText {
|
|
476
|
+
kind: "text";
|
|
477
|
+
key: string;
|
|
478
|
+
text: string;
|
|
479
|
+
}
|
|
480
|
+
/**
|
|
481
|
+
* Where the streaming caret goes. The backend decides what the caret looks like.
|
|
482
|
+
*
|
|
483
|
+
* @public
|
|
484
|
+
*/
|
|
485
|
+
interface StreamingMarkdownRenderCaret {
|
|
486
|
+
kind: "caret";
|
|
487
|
+
key: string;
|
|
488
|
+
}
|
|
489
|
+
/**
|
|
490
|
+
* Placeholder inside a node's default `output` that stands for its `children`.
|
|
491
|
+
*
|
|
492
|
+
* @public
|
|
493
|
+
*/
|
|
494
|
+
interface StreamingMarkdownRenderSlot {
|
|
495
|
+
kind: "slot";
|
|
496
|
+
key: string;
|
|
497
|
+
}
|
|
498
|
+
/**
|
|
499
|
+
* One AST node, ready to render. Backends render `children` once, render
|
|
500
|
+
* `output` with every `slot` replaced by those children, and pass both to a
|
|
501
|
+
* custom node renderer when one is registered for `rendererKey`.
|
|
502
|
+
*
|
|
503
|
+
* @public
|
|
504
|
+
*/
|
|
505
|
+
interface StreamingMarkdownRenderNode {
|
|
506
|
+
kind: "node";
|
|
507
|
+
key: string;
|
|
508
|
+
node: StreamingMarkdownAstNode;
|
|
509
|
+
rendererKey: StreamingMarkdownNodeRendererKey;
|
|
510
|
+
/** Content a custom renderer receives as its children; `null` for leaves. */
|
|
511
|
+
children: StreamingMarkdownRenderChild[] | null;
|
|
512
|
+
/** The default rendering. */
|
|
513
|
+
output: StreamingMarkdownRenderChild[];
|
|
514
|
+
/** `true` when the caret renders somewhere inside this node. */
|
|
515
|
+
containsCaret: boolean;
|
|
516
|
+
citation?: StreamingMarkdownCitationRenderData;
|
|
517
|
+
}
|
|
518
|
+
/**
|
|
519
|
+
* Any entry in a render tree.
|
|
520
|
+
*
|
|
521
|
+
* @public
|
|
522
|
+
*/
|
|
523
|
+
type StreamingMarkdownRenderChild = StreamingMarkdownRenderNode | StreamingMarkdownRenderElement | StreamingMarkdownRenderText | StreamingMarkdownRenderCaret | StreamingMarkdownRenderSlot;
|
|
524
|
+
/**
|
|
525
|
+
* Options for {@link buildStreamingMarkdownRenderTree}.
|
|
526
|
+
*
|
|
527
|
+
* @public
|
|
528
|
+
*/
|
|
529
|
+
interface StreamingMarkdownRenderTreeOptions {
|
|
530
|
+
/** Render a caret inside the deepest open node while streaming. */
|
|
531
|
+
caret: boolean;
|
|
532
|
+
nodeClassNames?: StreamingMarkdownNodeClassNames;
|
|
533
|
+
}
|
|
534
|
+
/**
|
|
535
|
+
* Class on the root element every renderer emits.
|
|
536
|
+
* @public
|
|
537
|
+
*/
|
|
538
|
+
declare const STREAMING_MARKDOWN_ROOT_CLASS = "cpk-streaming-markdown-root";
|
|
539
|
+
/**
|
|
540
|
+
* Node classes CopilotKit's built-in chat markdown renderers (React, Vue,
|
|
541
|
+
* Angular) apply, so all three emit the same themed markup.
|
|
542
|
+
* @public
|
|
543
|
+
*/
|
|
544
|
+
declare const CHAT_MARKDOWN_NODE_CLASS_NAMES: {
|
|
545
|
+
readonly codeBlock: "cpk-markdown-code-block";
|
|
546
|
+
};
|
|
547
|
+
/**
|
|
548
|
+
* Attributes of the default caret element.
|
|
549
|
+
* @public
|
|
550
|
+
*/
|
|
551
|
+
declare const STREAMING_MARKDOWN_CARET_ATTRS: {
|
|
552
|
+
readonly "aria-hidden": "true";
|
|
553
|
+
readonly class: "cpk-streaming-markdown-caret";
|
|
554
|
+
readonly "data-streaming-markdown-caret": "true";
|
|
555
|
+
};
|
|
556
|
+
/**
|
|
557
|
+
* Inline style of the default caret element (camelCase CSS properties).
|
|
558
|
+
* @public
|
|
559
|
+
*/
|
|
560
|
+
declare const STREAMING_MARKDOWN_CARET_STYLE: {
|
|
561
|
+
readonly display: "inline-block";
|
|
562
|
+
readonly width: "0.48em";
|
|
563
|
+
readonly height: "0.48em";
|
|
564
|
+
readonly marginInlineStart: "0.08em";
|
|
565
|
+
readonly verticalAlign: "-0.08em";
|
|
566
|
+
readonly borderRadius: "999px";
|
|
567
|
+
readonly backgroundColor: "currentColor";
|
|
568
|
+
readonly opacity: "0.55";
|
|
569
|
+
};
|
|
570
|
+
/**
|
|
571
|
+
* Stylesheet every renderer injects next to its root: the per-token fade-in
|
|
572
|
+
* for text segments and the citation pill. Read at render time, so it is safe
|
|
573
|
+
* to call during server rendering.
|
|
574
|
+
*
|
|
575
|
+
* @public
|
|
576
|
+
*/
|
|
577
|
+
declare function getStreamingMarkdownStyles(): string;
|
|
578
|
+
/**
|
|
579
|
+
* Returns `href` when its scheme is allowed for links, else `undefined`.
|
|
580
|
+
* @public
|
|
581
|
+
*/
|
|
582
|
+
declare function sanitizeStreamingMarkdownHref(href: string | undefined): string | undefined;
|
|
583
|
+
/**
|
|
584
|
+
* Returns `src` when its scheme is allowed for images, else `undefined`.
|
|
585
|
+
* @public
|
|
586
|
+
*/
|
|
587
|
+
declare function sanitizeStreamingMarkdownImageSrc(src: string | undefined): string | undefined;
|
|
588
|
+
type CitationNode = Extract<StreamingMarkdownAstNode, {
|
|
589
|
+
type: "citation";
|
|
590
|
+
}>;
|
|
591
|
+
/**
|
|
592
|
+
* The deepest open (still streaming) node other than the document, or `null`.
|
|
593
|
+
* This is where the caret goes.
|
|
594
|
+
*
|
|
595
|
+
* @public
|
|
596
|
+
*/
|
|
597
|
+
declare function findStreamingMarkdownOpenNode(state: StreamingMarkdownParserState): StreamingMarkdownParagraphNode | StreamingMarkdownHeadingNode | StreamingMarkdownBlockquoteNode | StreamingMarkdownListNode | StreamingMarkdownListItemNode | StreamingMarkdownCodeBlockNode | StreamingMarkdownTableNode | StreamingMarkdownTableRowNode | StreamingMarkdownTableCellNode | StreamingMarkdownThematicBreakNode | StreamingMarkdownTextNode | StreamingMarkdownEmphasisNode | StreamingMarkdownStrongNode | StreamingMarkdownStrikethroughNode | StreamingMarkdownInlineCodeNode | StreamingMarkdownSoftBreakNode | StreamingMarkdownHardBreakNode | StreamingMarkdownImageNode | StreamingMarkdownLinkNode | StreamingMarkdownAutolinkNode | StreamingMarkdownCitationNode | StreamingMarkdownMathNode | null;
|
|
598
|
+
/**
|
|
599
|
+
* Citation number and definition for a citation node.
|
|
600
|
+
*
|
|
601
|
+
* @public
|
|
602
|
+
*/
|
|
603
|
+
declare function getStreamingMarkdownCitationData(node: CitationNode, citations: CitationState): StreamingMarkdownCitationRenderData;
|
|
604
|
+
/**
|
|
605
|
+
* Turns parser state into a framework-neutral render tree: which elements to
|
|
606
|
+
* create, their sanitized attributes, click actions, text segments for the
|
|
607
|
+
* per-token animation, and where the caret goes. The React, Vue, and DOM
|
|
608
|
+
* renderers all render this tree, so markup and sanitization live here only.
|
|
609
|
+
*
|
|
610
|
+
* @param state - Parser state from the streaming markdown parser.
|
|
611
|
+
* @param options - Whether to place a caret, and optional per-node classes.
|
|
612
|
+
* @returns The root render node (`null` when the state has no root) and the
|
|
613
|
+
* open node the caret targets.
|
|
614
|
+
* @public
|
|
615
|
+
*/
|
|
616
|
+
declare function buildStreamingMarkdownRenderTree(state: StreamingMarkdownParserState, options: StreamingMarkdownRenderTreeOptions): {
|
|
617
|
+
root: StreamingMarkdownRenderNode | null;
|
|
618
|
+
openNode: StreamingMarkdownParagraphNode | StreamingMarkdownHeadingNode | StreamingMarkdownBlockquoteNode | StreamingMarkdownListNode | StreamingMarkdownListItemNode | StreamingMarkdownCodeBlockNode | StreamingMarkdownTableNode | StreamingMarkdownTableRowNode | StreamingMarkdownTableCellNode | StreamingMarkdownThematicBreakNode | StreamingMarkdownTextNode | StreamingMarkdownEmphasisNode | StreamingMarkdownStrongNode | StreamingMarkdownStrikethroughNode | StreamingMarkdownInlineCodeNode | StreamingMarkdownSoftBreakNode | StreamingMarkdownHardBreakNode | StreamingMarkdownImageNode | StreamingMarkdownLinkNode | StreamingMarkdownAutolinkNode | StreamingMarkdownCitationNode | StreamingMarkdownMathNode | null;
|
|
619
|
+
isComplete: boolean;
|
|
620
|
+
};
|
|
621
|
+
/**
|
|
622
|
+
* The render tree produced by {@link buildStreamingMarkdownRenderTree}.
|
|
623
|
+
* @public
|
|
624
|
+
*/
|
|
625
|
+
type StreamingMarkdownRenderTree = ReturnType<typeof buildStreamingMarkdownRenderTree>;
|
|
359
626
|
//#endregion
|
|
360
|
-
export { type CitationDefinition, type CitationState, type ParseMode, type SegmenterOptions, type StreamingMarkdownAstNode, type StreamingMarkdownNodeType, type StreamingMarkdownParserOptions, type StreamingMarkdownParserState, type StreamingMarkdownWarning, type TextSegment, createStreamingMarkdownParserState, finalizeStreamingMarkdown, parseStreamingMarkdownChunk, warnUnsupportedRichSyntaxOnce };
|
|
627
|
+
export { CHAT_MARKDOWN_NODE_CLASS_NAMES, type CitationDefinition, type CitationState, type ParseMode, STREAMING_MARKDOWN_CARET_ATTRS, STREAMING_MARKDOWN_CARET_STYLE, STREAMING_MARKDOWN_ROOT_CLASS, type SegmenterOptions, type StreamingMarkdownAstNode, type StreamingMarkdownCitationRenderData, type StreamingMarkdownNodeClassNames, type StreamingMarkdownNodeRendererKey, type StreamingMarkdownNodeType, type StreamingMarkdownParserOptions, type StreamingMarkdownParserSession, type StreamingMarkdownParserState, type StreamingMarkdownRenderAction, type StreamingMarkdownRenderCaret, type StreamingMarkdownRenderChild, type StreamingMarkdownRenderElement, type StreamingMarkdownRenderNode, type StreamingMarkdownRenderSlot, type StreamingMarkdownRenderText, type StreamingMarkdownRenderTree, type StreamingMarkdownRenderTreeOptions, type StreamingMarkdownWarning, type TextSegment, buildStreamingMarkdownRenderTree, createStreamingMarkdownParserState, finalizeStreamingMarkdown, findStreamingMarkdownOpenNode, getStreamingMarkdownCitationData, getStreamingMarkdownStyles, parseStreamingMarkdownChunk, sanitizeStreamingMarkdownHref, sanitizeStreamingMarkdownImageSrc, updateStreamingMarkdownParserSession, warnUnsupportedRichSyntaxOnce };
|
|
361
628
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/parser/types.ts","../src/parser/state.ts","../src/dev-warning.ts"],"mappings":";KAAK,kBAAA;;;;;KAMO,gBAAA;EAIN,MAAA;EACA,WAAA,GAAc,kBAAA;AAAA;;;;;KAOR,8BAAA;EACV,SAAA,EAAW,gBAAA;EACX,YAAA;EACA,eAAA;AAAA
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/parser/types.ts","../src/parser/state.ts","../src/dev-warning.ts","../src/render/parser-session.ts","../src/render/render-tree.ts"],"mappings":";KAAK,kBAAA;;;;;KAMO,gBAAA;EAIN,MAAA;EACA,WAAA,GAAc,kBAAA;AAAA;;;;;KAOR,8BAAA;EACV,SAAA,EAAW,gBAAA;EACX,YAAA;EACA,eAAA;;;;;EAKA,UAAA;AAAA;;;;AAOF;KAAY,yBAAA;;;;AA6BZ;KAAY,SAAA;;;;AAaZ;KAAY,wBAAA;EACN,IAAA;EAAgC,IAAA;EAAc,EAAA;AAAA;EAC9C,IAAA;EAAqC,EAAA;AAAA;EACrC,IAAA;EAA0B,KAAA;EAAe,EAAA;AAAA;EACzC,IAAA;EAA+B,EAAA;AAAA;EAC/B,IAAA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,YAAA,EACN,SAAA,EAAW,aAAA,GACV,mCAAA;;;;;;;;;;;AJrJH;;iBImgBgB,gCAAA,CACd,KAAA,EAAO,4BAAA,EACP,OAAA,EAAS,kCAAA;;;;;;;AJ5fX;;KIiiBY,2BAAA,GAA8B,UAAA,QACjC,gCAAA"}
|
package/dist/index.d.mts
CHANGED
|
@@ -16,12 +16,17 @@ type StreamingMarkdownParserOptions = {
|
|
|
16
16
|
segmenter: SegmenterOptions;
|
|
17
17
|
enableTables: boolean;
|
|
18
18
|
enableAutolinks: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Parses `$…$` inline math and `$$…$$` display math into `math` nodes.
|
|
21
|
+
* Off by default: without it, dollar signs stay plain text.
|
|
22
|
+
*/
|
|
23
|
+
enableMath?: boolean;
|
|
19
24
|
};
|
|
20
25
|
/**
|
|
21
26
|
* Supported streaming markdown AST node kinds.
|
|
22
27
|
* @public
|
|
23
28
|
*/
|
|
24
|
-
type StreamingMarkdownNodeType = "document" | "paragraph" | "heading" | "blockquote" | "list" | "list-item" | "code-block" | "table" | "table-row" | "table-cell" | "thematic-break" | "text" | "em" | "strong" | "strikethrough" | "inline-code" | "soft-break" | "hard-break" | "image" | "link" | "autolink" | "citation";
|
|
29
|
+
type StreamingMarkdownNodeType = "document" | "paragraph" | "heading" | "blockquote" | "list" | "list-item" | "code-block" | "table" | "table-row" | "table-cell" | "thematic-break" | "text" | "em" | "strong" | "strikethrough" | "inline-code" | "soft-break" | "hard-break" | "image" | "link" | "autolink" | "citation" | "math";
|
|
25
30
|
/**
|
|
26
31
|
* Parsing mode for block-level processing.
|
|
27
32
|
* @public
|
|
@@ -129,6 +134,11 @@ type StreamingMarkdownListNode = StreamingMarkdownAstNodeBase & {
|
|
|
129
134
|
*/
|
|
130
135
|
type StreamingMarkdownListItemNode = StreamingMarkdownAstNodeBase & {
|
|
131
136
|
type: "list-item";
|
|
137
|
+
/**
|
|
138
|
+
* GFM task-list state: `true` for `[x]`, `false` for `[ ]`, absent for a
|
|
139
|
+
* plain list item.
|
|
140
|
+
*/
|
|
141
|
+
checked?: boolean;
|
|
132
142
|
children: number[];
|
|
133
143
|
};
|
|
134
144
|
/**
|
|
@@ -268,11 +278,21 @@ type StreamingMarkdownCitationNode = StreamingMarkdownAstNodeBase & {
|
|
|
268
278
|
idRef: string;
|
|
269
279
|
number?: number;
|
|
270
280
|
};
|
|
281
|
+
/**
|
|
282
|
+
* AST node representing TeX math (only parsed when `enableMath` is set).
|
|
283
|
+
* `text` is the TeX source without its `$` delimiters.
|
|
284
|
+
* @public
|
|
285
|
+
*/
|
|
286
|
+
type StreamingMarkdownMathNode = StreamingMarkdownAstNodeBase & {
|
|
287
|
+
type: "math";
|
|
288
|
+
text: string;
|
|
289
|
+
display: boolean;
|
|
290
|
+
};
|
|
271
291
|
/**
|
|
272
292
|
* Union of all AST node shapes.
|
|
273
293
|
* @public
|
|
274
294
|
*/
|
|
275
|
-
type StreamingMarkdownAstNode = StreamingMarkdownDocumentNode | StreamingMarkdownParagraphNode | StreamingMarkdownHeadingNode | StreamingMarkdownBlockquoteNode | StreamingMarkdownListNode | StreamingMarkdownListItemNode | StreamingMarkdownCodeBlockNode | StreamingMarkdownTableNode | StreamingMarkdownTableRowNode | StreamingMarkdownTableCellNode | StreamingMarkdownThematicBreakNode | StreamingMarkdownTextNode | StreamingMarkdownEmphasisNode | StreamingMarkdownStrongNode | StreamingMarkdownStrikethroughNode | StreamingMarkdownInlineCodeNode | StreamingMarkdownSoftBreakNode | StreamingMarkdownHardBreakNode | StreamingMarkdownImageNode | StreamingMarkdownLinkNode | StreamingMarkdownAutolinkNode | StreamingMarkdownCitationNode;
|
|
295
|
+
type StreamingMarkdownAstNode = StreamingMarkdownDocumentNode | StreamingMarkdownParagraphNode | StreamingMarkdownHeadingNode | StreamingMarkdownBlockquoteNode | StreamingMarkdownListNode | StreamingMarkdownListItemNode | StreamingMarkdownCodeBlockNode | StreamingMarkdownTableNode | StreamingMarkdownTableRowNode | StreamingMarkdownTableCellNode | StreamingMarkdownThematicBreakNode | StreamingMarkdownTextNode | StreamingMarkdownEmphasisNode | StreamingMarkdownStrongNode | StreamingMarkdownStrikethroughNode | StreamingMarkdownInlineCodeNode | StreamingMarkdownSoftBreakNode | StreamingMarkdownHardBreakNode | StreamingMarkdownImageNode | StreamingMarkdownLinkNode | StreamingMarkdownAutolinkNode | StreamingMarkdownCitationNode | StreamingMarkdownMathNode;
|
|
276
296
|
/**
|
|
277
297
|
* Citation definition captured during parsing.
|
|
278
298
|
* @public
|
|
@@ -352,10 +372,257 @@ declare function finalizeStreamingMarkdown(state: StreamingMarkdownParserState):
|
|
|
352
372
|
*
|
|
353
373
|
* No-op in production and after the first warning. Only the built-in default
|
|
354
374
|
* renderers call this — a custom `markdownRenderer` never triggers it.
|
|
375
|
+
* Pass `{ rendersMath: true }` from a default renderer that typesets math, so
|
|
376
|
+
* only code blocks are flagged.
|
|
355
377
|
*
|
|
356
378
|
* @internal
|
|
357
379
|
*/
|
|
358
|
-
declare function warnUnsupportedRichSyntaxOnce(content: string
|
|
380
|
+
declare function warnUnsupportedRichSyntaxOnce(content: string, {
|
|
381
|
+
rendersMath
|
|
382
|
+
}?: {
|
|
383
|
+
rendersMath?: boolean;
|
|
384
|
+
}): void;
|
|
385
|
+
//#endregion
|
|
386
|
+
//#region src/render/parser-session.d.ts
|
|
387
|
+
/**
|
|
388
|
+
* Parser state plus the inputs that produced it, so the next update can parse
|
|
389
|
+
* only the appended text.
|
|
390
|
+
*
|
|
391
|
+
* @public
|
|
392
|
+
*/
|
|
393
|
+
interface StreamingMarkdownParserSession {
|
|
394
|
+
parserState: StreamingMarkdownParserState;
|
|
395
|
+
text: string;
|
|
396
|
+
optionsKey: string;
|
|
397
|
+
isCompleteInput: boolean;
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* Returns the parser session for `text`, reusing `previous` when it can.
|
|
401
|
+
*
|
|
402
|
+
* - Same inputs: returns `previous` unchanged.
|
|
403
|
+
* - Text grew by a suffix: parses only the suffix, so unchanged AST nodes keep
|
|
404
|
+
* their identity (renderers rely on this to keep DOM and animations stable).
|
|
405
|
+
* - Text was replaced or options changed: parses from scratch.
|
|
406
|
+
* - `isComplete` toggled: finalizes (or re-opens) the current state.
|
|
407
|
+
*
|
|
408
|
+
* @param previous - The session from the last update, or `null` on first use.
|
|
409
|
+
* @param text - Full markdown source, which usually grows over time.
|
|
410
|
+
* @param options - Parser option overrides.
|
|
411
|
+
* @param isCompleteInput - `true` once the source is final.
|
|
412
|
+
* @public
|
|
413
|
+
*/
|
|
414
|
+
declare function updateStreamingMarkdownParserSession(previous: StreamingMarkdownParserSession | null, text: string, options: Partial<StreamingMarkdownParserOptions> | undefined, isCompleteInput: boolean): StreamingMarkdownParserSession;
|
|
415
|
+
//#endregion
|
|
416
|
+
//#region src/render/render-tree.d.ts
|
|
417
|
+
/**
|
|
418
|
+
* Key names for per-node customization (`nodeRenderers`, `nodeClassNames`).
|
|
419
|
+
* camelCase versions of the AST node types, plus `node` as a catch-all.
|
|
420
|
+
*
|
|
421
|
+
* @public
|
|
422
|
+
*/
|
|
423
|
+
type StreamingMarkdownNodeRendererKey = "node" | "document" | "paragraph" | "heading" | "blockquote" | "list" | "listItem" | "codeBlock" | "table" | "tableRow" | "tableCell" | "thematicBreak" | "text" | "em" | "strong" | "strikethrough" | "inlineCode" | "softBreak" | "hardBreak" | "image" | "link" | "autolink" | "citation" | "math";
|
|
424
|
+
/**
|
|
425
|
+
* Metadata available when a citation node is rendered.
|
|
426
|
+
*
|
|
427
|
+
* @public
|
|
428
|
+
*/
|
|
429
|
+
interface StreamingMarkdownCitationRenderData {
|
|
430
|
+
id: string;
|
|
431
|
+
number: number | string;
|
|
432
|
+
definition?: CitationDefinition;
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* Extra class names for the outermost default element of a node type, for
|
|
436
|
+
* example `{ codeBlock: "cpk-markdown-code-block" }`. Ignored for node types
|
|
437
|
+
* that render no element of their own (`document`, `text`, `softBreak`).
|
|
438
|
+
*
|
|
439
|
+
* @public
|
|
440
|
+
*/
|
|
441
|
+
type StreamingMarkdownNodeClassNames = Partial<Record<StreamingMarkdownNodeRendererKey, string>>;
|
|
442
|
+
/**
|
|
443
|
+
* Click behavior a backend attaches to a rendered element.
|
|
444
|
+
*
|
|
445
|
+
* @public
|
|
446
|
+
*/
|
|
447
|
+
type StreamingMarkdownRenderAction = {
|
|
448
|
+
type: "link";
|
|
449
|
+
url: string;
|
|
450
|
+
node: StreamingMarkdownAstNode;
|
|
451
|
+
} | {
|
|
452
|
+
type: "citation";
|
|
453
|
+
citation: StreamingMarkdownCitationRenderData;
|
|
454
|
+
node: StreamingMarkdownAstNode;
|
|
455
|
+
};
|
|
456
|
+
/**
|
|
457
|
+
* A plain element. Attribute values are already sanitized; `true` marks a
|
|
458
|
+
* boolean attribute that is present.
|
|
459
|
+
*
|
|
460
|
+
* @public
|
|
461
|
+
*/
|
|
462
|
+
interface StreamingMarkdownRenderElement {
|
|
463
|
+
kind: "element";
|
|
464
|
+
key: string;
|
|
465
|
+
tag: string;
|
|
466
|
+
attrs: Readonly<Record<string, string | true>>;
|
|
467
|
+
children: StreamingMarkdownRenderChild[];
|
|
468
|
+
action?: StreamingMarkdownRenderAction;
|
|
469
|
+
}
|
|
470
|
+
/**
|
|
471
|
+
* A text run.
|
|
472
|
+
*
|
|
473
|
+
* @public
|
|
474
|
+
*/
|
|
475
|
+
interface StreamingMarkdownRenderText {
|
|
476
|
+
kind: "text";
|
|
477
|
+
key: string;
|
|
478
|
+
text: string;
|
|
479
|
+
}
|
|
480
|
+
/**
|
|
481
|
+
* Where the streaming caret goes. The backend decides what the caret looks like.
|
|
482
|
+
*
|
|
483
|
+
* @public
|
|
484
|
+
*/
|
|
485
|
+
interface StreamingMarkdownRenderCaret {
|
|
486
|
+
kind: "caret";
|
|
487
|
+
key: string;
|
|
488
|
+
}
|
|
489
|
+
/**
|
|
490
|
+
* Placeholder inside a node's default `output` that stands for its `children`.
|
|
491
|
+
*
|
|
492
|
+
* @public
|
|
493
|
+
*/
|
|
494
|
+
interface StreamingMarkdownRenderSlot {
|
|
495
|
+
kind: "slot";
|
|
496
|
+
key: string;
|
|
497
|
+
}
|
|
498
|
+
/**
|
|
499
|
+
* One AST node, ready to render. Backends render `children` once, render
|
|
500
|
+
* `output` with every `slot` replaced by those children, and pass both to a
|
|
501
|
+
* custom node renderer when one is registered for `rendererKey`.
|
|
502
|
+
*
|
|
503
|
+
* @public
|
|
504
|
+
*/
|
|
505
|
+
interface StreamingMarkdownRenderNode {
|
|
506
|
+
kind: "node";
|
|
507
|
+
key: string;
|
|
508
|
+
node: StreamingMarkdownAstNode;
|
|
509
|
+
rendererKey: StreamingMarkdownNodeRendererKey;
|
|
510
|
+
/** Content a custom renderer receives as its children; `null` for leaves. */
|
|
511
|
+
children: StreamingMarkdownRenderChild[] | null;
|
|
512
|
+
/** The default rendering. */
|
|
513
|
+
output: StreamingMarkdownRenderChild[];
|
|
514
|
+
/** `true` when the caret renders somewhere inside this node. */
|
|
515
|
+
containsCaret: boolean;
|
|
516
|
+
citation?: StreamingMarkdownCitationRenderData;
|
|
517
|
+
}
|
|
518
|
+
/**
|
|
519
|
+
* Any entry in a render tree.
|
|
520
|
+
*
|
|
521
|
+
* @public
|
|
522
|
+
*/
|
|
523
|
+
type StreamingMarkdownRenderChild = StreamingMarkdownRenderNode | StreamingMarkdownRenderElement | StreamingMarkdownRenderText | StreamingMarkdownRenderCaret | StreamingMarkdownRenderSlot;
|
|
524
|
+
/**
|
|
525
|
+
* Options for {@link buildStreamingMarkdownRenderTree}.
|
|
526
|
+
*
|
|
527
|
+
* @public
|
|
528
|
+
*/
|
|
529
|
+
interface StreamingMarkdownRenderTreeOptions {
|
|
530
|
+
/** Render a caret inside the deepest open node while streaming. */
|
|
531
|
+
caret: boolean;
|
|
532
|
+
nodeClassNames?: StreamingMarkdownNodeClassNames;
|
|
533
|
+
}
|
|
534
|
+
/**
|
|
535
|
+
* Class on the root element every renderer emits.
|
|
536
|
+
* @public
|
|
537
|
+
*/
|
|
538
|
+
declare const STREAMING_MARKDOWN_ROOT_CLASS = "cpk-streaming-markdown-root";
|
|
539
|
+
/**
|
|
540
|
+
* Node classes CopilotKit's built-in chat markdown renderers (React, Vue,
|
|
541
|
+
* Angular) apply, so all three emit the same themed markup.
|
|
542
|
+
* @public
|
|
543
|
+
*/
|
|
544
|
+
declare const CHAT_MARKDOWN_NODE_CLASS_NAMES: {
|
|
545
|
+
readonly codeBlock: "cpk-markdown-code-block";
|
|
546
|
+
};
|
|
547
|
+
/**
|
|
548
|
+
* Attributes of the default caret element.
|
|
549
|
+
* @public
|
|
550
|
+
*/
|
|
551
|
+
declare const STREAMING_MARKDOWN_CARET_ATTRS: {
|
|
552
|
+
readonly "aria-hidden": "true";
|
|
553
|
+
readonly class: "cpk-streaming-markdown-caret";
|
|
554
|
+
readonly "data-streaming-markdown-caret": "true";
|
|
555
|
+
};
|
|
556
|
+
/**
|
|
557
|
+
* Inline style of the default caret element (camelCase CSS properties).
|
|
558
|
+
* @public
|
|
559
|
+
*/
|
|
560
|
+
declare const STREAMING_MARKDOWN_CARET_STYLE: {
|
|
561
|
+
readonly display: "inline-block";
|
|
562
|
+
readonly width: "0.48em";
|
|
563
|
+
readonly height: "0.48em";
|
|
564
|
+
readonly marginInlineStart: "0.08em";
|
|
565
|
+
readonly verticalAlign: "-0.08em";
|
|
566
|
+
readonly borderRadius: "999px";
|
|
567
|
+
readonly backgroundColor: "currentColor";
|
|
568
|
+
readonly opacity: "0.55";
|
|
569
|
+
};
|
|
570
|
+
/**
|
|
571
|
+
* Stylesheet every renderer injects next to its root: the per-token fade-in
|
|
572
|
+
* for text segments and the citation pill. Read at render time, so it is safe
|
|
573
|
+
* to call during server rendering.
|
|
574
|
+
*
|
|
575
|
+
* @public
|
|
576
|
+
*/
|
|
577
|
+
declare function getStreamingMarkdownStyles(): string;
|
|
578
|
+
/**
|
|
579
|
+
* Returns `href` when its scheme is allowed for links, else `undefined`.
|
|
580
|
+
* @public
|
|
581
|
+
*/
|
|
582
|
+
declare function sanitizeStreamingMarkdownHref(href: string | undefined): string | undefined;
|
|
583
|
+
/**
|
|
584
|
+
* Returns `src` when its scheme is allowed for images, else `undefined`.
|
|
585
|
+
* @public
|
|
586
|
+
*/
|
|
587
|
+
declare function sanitizeStreamingMarkdownImageSrc(src: string | undefined): string | undefined;
|
|
588
|
+
type CitationNode = Extract<StreamingMarkdownAstNode, {
|
|
589
|
+
type: "citation";
|
|
590
|
+
}>;
|
|
591
|
+
/**
|
|
592
|
+
* The deepest open (still streaming) node other than the document, or `null`.
|
|
593
|
+
* This is where the caret goes.
|
|
594
|
+
*
|
|
595
|
+
* @public
|
|
596
|
+
*/
|
|
597
|
+
declare function findStreamingMarkdownOpenNode(state: StreamingMarkdownParserState): StreamingMarkdownParagraphNode | StreamingMarkdownHeadingNode | StreamingMarkdownBlockquoteNode | StreamingMarkdownListNode | StreamingMarkdownListItemNode | StreamingMarkdownCodeBlockNode | StreamingMarkdownTableNode | StreamingMarkdownTableRowNode | StreamingMarkdownTableCellNode | StreamingMarkdownThematicBreakNode | StreamingMarkdownTextNode | StreamingMarkdownEmphasisNode | StreamingMarkdownStrongNode | StreamingMarkdownStrikethroughNode | StreamingMarkdownInlineCodeNode | StreamingMarkdownSoftBreakNode | StreamingMarkdownHardBreakNode | StreamingMarkdownImageNode | StreamingMarkdownLinkNode | StreamingMarkdownAutolinkNode | StreamingMarkdownCitationNode | StreamingMarkdownMathNode | null;
|
|
598
|
+
/**
|
|
599
|
+
* Citation number and definition for a citation node.
|
|
600
|
+
*
|
|
601
|
+
* @public
|
|
602
|
+
*/
|
|
603
|
+
declare function getStreamingMarkdownCitationData(node: CitationNode, citations: CitationState): StreamingMarkdownCitationRenderData;
|
|
604
|
+
/**
|
|
605
|
+
* Turns parser state into a framework-neutral render tree: which elements to
|
|
606
|
+
* create, their sanitized attributes, click actions, text segments for the
|
|
607
|
+
* per-token animation, and where the caret goes. The React, Vue, and DOM
|
|
608
|
+
* renderers all render this tree, so markup and sanitization live here only.
|
|
609
|
+
*
|
|
610
|
+
* @param state - Parser state from the streaming markdown parser.
|
|
611
|
+
* @param options - Whether to place a caret, and optional per-node classes.
|
|
612
|
+
* @returns The root render node (`null` when the state has no root) and the
|
|
613
|
+
* open node the caret targets.
|
|
614
|
+
* @public
|
|
615
|
+
*/
|
|
616
|
+
declare function buildStreamingMarkdownRenderTree(state: StreamingMarkdownParserState, options: StreamingMarkdownRenderTreeOptions): {
|
|
617
|
+
root: StreamingMarkdownRenderNode | null;
|
|
618
|
+
openNode: StreamingMarkdownParagraphNode | StreamingMarkdownHeadingNode | StreamingMarkdownBlockquoteNode | StreamingMarkdownListNode | StreamingMarkdownListItemNode | StreamingMarkdownCodeBlockNode | StreamingMarkdownTableNode | StreamingMarkdownTableRowNode | StreamingMarkdownTableCellNode | StreamingMarkdownThematicBreakNode | StreamingMarkdownTextNode | StreamingMarkdownEmphasisNode | StreamingMarkdownStrongNode | StreamingMarkdownStrikethroughNode | StreamingMarkdownInlineCodeNode | StreamingMarkdownSoftBreakNode | StreamingMarkdownHardBreakNode | StreamingMarkdownImageNode | StreamingMarkdownLinkNode | StreamingMarkdownAutolinkNode | StreamingMarkdownCitationNode | StreamingMarkdownMathNode | null;
|
|
619
|
+
isComplete: boolean;
|
|
620
|
+
};
|
|
621
|
+
/**
|
|
622
|
+
* The render tree produced by {@link buildStreamingMarkdownRenderTree}.
|
|
623
|
+
* @public
|
|
624
|
+
*/
|
|
625
|
+
type StreamingMarkdownRenderTree = ReturnType<typeof buildStreamingMarkdownRenderTree>;
|
|
359
626
|
//#endregion
|
|
360
|
-
export { type CitationDefinition, type CitationState, type ParseMode, type SegmenterOptions, type StreamingMarkdownAstNode, type StreamingMarkdownNodeType, type StreamingMarkdownParserOptions, type StreamingMarkdownParserState, type StreamingMarkdownWarning, type TextSegment, createStreamingMarkdownParserState, finalizeStreamingMarkdown, parseStreamingMarkdownChunk, warnUnsupportedRichSyntaxOnce };
|
|
627
|
+
export { CHAT_MARKDOWN_NODE_CLASS_NAMES, type CitationDefinition, type CitationState, type ParseMode, STREAMING_MARKDOWN_CARET_ATTRS, STREAMING_MARKDOWN_CARET_STYLE, STREAMING_MARKDOWN_ROOT_CLASS, type SegmenterOptions, type StreamingMarkdownAstNode, type StreamingMarkdownCitationRenderData, type StreamingMarkdownNodeClassNames, type StreamingMarkdownNodeRendererKey, type StreamingMarkdownNodeType, type StreamingMarkdownParserOptions, type StreamingMarkdownParserSession, type StreamingMarkdownParserState, type StreamingMarkdownRenderAction, type StreamingMarkdownRenderCaret, type StreamingMarkdownRenderChild, type StreamingMarkdownRenderElement, type StreamingMarkdownRenderNode, type StreamingMarkdownRenderSlot, type StreamingMarkdownRenderText, type StreamingMarkdownRenderTree, type StreamingMarkdownRenderTreeOptions, type StreamingMarkdownWarning, type TextSegment, buildStreamingMarkdownRenderTree, createStreamingMarkdownParserState, finalizeStreamingMarkdown, findStreamingMarkdownOpenNode, getStreamingMarkdownCitationData, getStreamingMarkdownStyles, parseStreamingMarkdownChunk, sanitizeStreamingMarkdownHref, sanitizeStreamingMarkdownImageSrc, updateStreamingMarkdownParserSession, warnUnsupportedRichSyntaxOnce };
|
|
361
628
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/parser/types.ts","../src/parser/state.ts","../src/dev-warning.ts"],"mappings":";KAAK,kBAAA;;;;;KAMO,gBAAA;EAIN,MAAA;EACA,WAAA,GAAc,kBAAA;AAAA;;;;;KAOR,8BAAA;EACV,SAAA,EAAW,gBAAA;EACX,YAAA;EACA,eAAA;AAAA
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/parser/types.ts","../src/parser/state.ts","../src/dev-warning.ts","../src/render/parser-session.ts","../src/render/render-tree.ts"],"mappings":";KAAK,kBAAA;;;;;KAMO,g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