@astryxdesign/core 0.6.1 → 0.6.2-canary.605fa9a
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/CHANGELOG.md +33 -0
- package/dist/BottomSheet/BottomSheet.d.ts +1 -1
- package/dist/BottomSheet/BottomSheet.d.ts.map +1 -1
- package/dist/BottomSheet/BottomSheet.js +3 -1
- package/dist/BottomSheet/BottomSheetPanel.d.ts +7 -5
- package/dist/BottomSheet/BottomSheetPanel.d.ts.map +1 -1
- package/dist/BottomSheet/BottomSheetPanel.js +56 -19
- package/dist/DateRangeInput/DateRangeInput.d.ts +3 -0
- package/dist/DateRangeInput/DateRangeInput.d.ts.map +1 -1
- package/dist/DateRangeInput/DateRangeInput.js +16 -9
- package/dist/Dialog/DialogHeader.d.ts +1 -1
- package/dist/Dialog/DialogHeader.d.ts.map +1 -1
- package/dist/Dialog/DialogHeader.js +10 -7
- package/dist/FileInput/FileInput.d.ts.map +1 -1
- package/dist/FileInput/FileInput.js +9 -3
- package/dist/Markdown/Markdown.d.ts +10 -2
- package/dist/Markdown/Markdown.d.ts.map +1 -1
- package/dist/Markdown/Markdown.js +58 -14
- package/dist/Markdown/index.d.ts +1 -1
- package/dist/Markdown/index.d.ts.map +1 -1
- package/dist/Markdown/parser.d.ts +126 -12
- package/dist/Markdown/parser.d.ts.map +1 -1
- package/dist/Markdown/parser.js +369 -34
- package/dist/Markdown/utils.d.ts +1 -1
- package/dist/Markdown/utils.d.ts.map +1 -1
- package/dist/Slider/Slider.d.ts.map +1 -1
- package/dist/Slider/Slider.js +5 -2
- package/dist/Spinner/Spinner.d.ts +1 -1
- package/dist/Spinner/Spinner.d.ts.map +1 -1
- package/dist/Spinner/Spinner.js +23 -15
- package/dist/astryx.css +5 -2
- package/dist/hooks/scrollKeyboardDelegation.d.ts +3 -0
- package/dist/hooks/scrollKeyboardDelegation.d.ts.map +1 -0
- package/dist/hooks/scrollKeyboardDelegation.js +146 -0
- package/dist/hooks/useScrollableArea.d.ts +6 -2
- package/dist/hooks/useScrollableArea.d.ts.map +1 -1
- package/dist/hooks/useScrollableArea.js +17 -5
- package/locales/en.json +16 -0
- package/locales/pseudo.json +12 -0
- package/package.json +7 -5
- package/scripts/agent-doc-state.mjs +1 -1
- package/src/BottomSheet/BottomSheet.doc.mjs +8 -1
- package/src/BottomSheet/BottomSheet.spec.md +46 -20
- package/src/BottomSheet/BottomSheet.test.tsx +6 -3
- package/src/BottomSheet/BottomSheet.tsx +3 -1
- package/src/BottomSheet/BottomSheetKeyboard.test.tsx +195 -0
- package/src/BottomSheet/BottomSheetPanel.test.tsx +11 -1
- package/src/BottomSheet/BottomSheetPanel.tsx +49 -16
- package/src/BottomSheet/__tests__/BottomSheetKeyboard.a11y.browser.spec.ts +344 -0
- package/src/DateRangeInput/DateRangeInput.doc.mjs +35 -7
- package/src/DateRangeInput/DateRangeInput.spec.md +203 -0
- package/src/DateRangeInput/DateRangeInput.test.tsx +100 -4
- package/src/DateRangeInput/DateRangeInput.tsx +29 -20
- package/src/Dialog/Dialog.doc.mjs +3 -0
- package/src/Dialog/Dialog.spec.md +1 -1
- package/src/Dialog/DialogHeader.doc.mjs +38 -0
- package/src/Dialog/DialogHeader.test.tsx +49 -0
- package/src/Dialog/DialogHeader.tsx +23 -4
- package/src/Dialog/modules/DialogHeader.spec.md +152 -0
- package/src/FileInput/FileInput.doc.mjs +2 -0
- package/src/FileInput/FileInput.spec.md +199 -0
- package/src/FileInput/FileInput.test.tsx +14 -0
- package/src/FileInput/FileInput.tsx +13 -3
- package/src/Markdown/Markdown.doc.mjs +167 -42
- package/src/Markdown/Markdown.public.test.ts +157 -0
- package/src/Markdown/Markdown.spec.md +149 -70
- package/src/Markdown/Markdown.test.tsx +107 -3
- package/src/Markdown/Markdown.tsx +116 -35
- package/src/Markdown/incremental.test.ts +175 -7
- package/src/Markdown/index.ts +6 -0
- package/src/Markdown/parser.perf.test.ts +3 -1
- package/src/Markdown/parser.test.ts +122 -0
- package/src/Markdown/parser.ts +609 -81
- package/src/Markdown/utils.ts +6 -0
- package/src/ScrollableArea/modules/useScrollableArea.spec.md +50 -22
- package/src/Slider/Slider.doc.mjs +16 -0
- package/src/Slider/Slider.spec.md +61 -47
- package/src/Slider/Slider.test.tsx +18 -0
- package/src/Slider/Slider.tsx +12 -6
- package/src/Spinner/Spinner.doc.mjs +6 -3
- package/src/Spinner/Spinner.test.tsx +37 -0
- package/src/Spinner/Spinner.tsx +31 -14
- package/src/hooks/scrollKeyboardDelegation.test.ts +155 -0
- package/src/hooks/scrollKeyboardDelegation.ts +233 -0
- package/src/hooks/useScrollableArea.doc.mjs +15 -3
- package/src/hooks/useScrollableArea.test.tsx +59 -1
- package/src/hooks/useScrollableArea.ts +34 -10
- package/src/theme/derivedVarRegistry.test.ts +6 -4
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* @file Markdown.tsx
|
|
7
|
-
* @input Markdown string, parser AST types
|
|
8
|
-
* @output Exports Markdown component and
|
|
7
|
+
* @input Markdown string, parser AST types, optional custom renderers
|
|
8
|
+
* @output Exports Markdown component, MarkdownProps, and renderer contracts
|
|
9
9
|
* @position Core implementation; renders markdown as Astryx components
|
|
10
10
|
*/
|
|
11
11
|
import { useMemo, useRef } from 'react';
|
|
@@ -42,7 +42,7 @@ import { useTranslator } from "../i18n/index.js";
|
|
|
42
42
|
/**
|
|
43
43
|
* A plugin that transforms text patterns into custom React elements
|
|
44
44
|
* inside Markdown. Applied to parsed text nodes only — code blocks,
|
|
45
|
-
* inline code, and other non-prose contexts are unaffected.
|
|
45
|
+
* inline code, math, and other non-prose contexts are unaffected.
|
|
46
46
|
*
|
|
47
47
|
* Follows Lexical's TextMatchTransformer architecture:
|
|
48
48
|
* - `pattern` for initial regex matching
|
|
@@ -336,6 +336,9 @@ function countInlineTextLength(nodes) {
|
|
|
336
336
|
case 'code':
|
|
337
337
|
len += node.content.length;
|
|
338
338
|
break;
|
|
339
|
+
case 'math':
|
|
340
|
+
len += node.value.length;
|
|
341
|
+
break;
|
|
339
342
|
case 'image':
|
|
340
343
|
len += node.alt.length;
|
|
341
344
|
break;
|
|
@@ -370,6 +373,9 @@ function countBlockTextLength(nodes) {
|
|
|
370
373
|
case 'codeblock':
|
|
371
374
|
len += node.content.length;
|
|
372
375
|
break;
|
|
376
|
+
case 'math':
|
|
377
|
+
len += node.value.length;
|
|
378
|
+
break;
|
|
373
379
|
case 'blockquote':
|
|
374
380
|
len += countBlockTextLength(node.children);
|
|
375
381
|
break;
|
|
@@ -625,6 +631,18 @@ function renderInline(node, index, onLinkClick, cursor, citationCtx, linkCompone
|
|
|
625
631
|
}, index);
|
|
626
632
|
return codeEl;
|
|
627
633
|
}
|
|
634
|
+
case 'math':
|
|
635
|
+
{
|
|
636
|
+
const MathComp = components?.math;
|
|
637
|
+
if (MathComp == null) {
|
|
638
|
+
return wrapTextWithFade(`$${node.value}$`, cursor, index);
|
|
639
|
+
}
|
|
640
|
+
cursor.offset += node.value.length;
|
|
641
|
+
return /*#__PURE__*/_jsx(MathComp, {
|
|
642
|
+
value: node.value,
|
|
643
|
+
display: "inline"
|
|
644
|
+
}, index);
|
|
645
|
+
}
|
|
628
646
|
case 'link':
|
|
629
647
|
{
|
|
630
648
|
const safeHref = sanitizeUrl(node.href);
|
|
@@ -732,6 +750,7 @@ function getElementSpacing(node, density) {
|
|
|
732
750
|
case 'paragraph':
|
|
733
751
|
return compact ? styles.spacingParagraphCompact : styles.spacingParagraphDefault;
|
|
734
752
|
case 'codeblock':
|
|
753
|
+
case 'math':
|
|
735
754
|
return compact ? styles.spacingCodeblockCompact : styles.spacingCodeblockDefault;
|
|
736
755
|
case 'blockquote':
|
|
737
756
|
return compact ? styles.spacingBlockquoteCompact : styles.spacingBlockquoteDefault;
|
|
@@ -851,6 +870,21 @@ function renderBlock(node, index, blockCount, density, headingLevelStart, onLink
|
|
|
851
870
|
})
|
|
852
871
|
}, index);
|
|
853
872
|
}
|
|
873
|
+
case 'math':
|
|
874
|
+
{
|
|
875
|
+
cursor.offset += node.value.length;
|
|
876
|
+
const MathComp = components?.math;
|
|
877
|
+
if (MathComp == null) {
|
|
878
|
+
return /*#__PURE__*/_jsx("div", {
|
|
879
|
+
role: "paragraph",
|
|
880
|
+
children: `$$${node.value}$$`
|
|
881
|
+
}, index);
|
|
882
|
+
}
|
|
883
|
+
return /*#__PURE__*/_jsx(MathComp, {
|
|
884
|
+
value: node.value,
|
|
885
|
+
display: "block"
|
|
886
|
+
}, index);
|
|
887
|
+
}
|
|
854
888
|
case 'blockquote':
|
|
855
889
|
{
|
|
856
890
|
const BlockquoteComp = components?.blockquote;
|
|
@@ -1071,21 +1105,29 @@ export function Markdown({
|
|
|
1071
1105
|
const LinkComponent = useLinkComponent();
|
|
1072
1106
|
// Derive the set of source IDs for the parser (stable across renders when sources don't change)
|
|
1073
1107
|
const sourceIds = useMemo(() => sources ? new Set(Object.keys(sources)) : undefined, [sources]);
|
|
1074
|
-
const
|
|
1108
|
+
const hasMathRenderer = components?.math != null;
|
|
1109
|
+
const legacyParseOptions = useMemo(() => ({
|
|
1075
1110
|
sourceIds,
|
|
1076
1111
|
autolink
|
|
1077
1112
|
}), [sourceIds, autolink]);
|
|
1113
|
+
const mathParseOptions = useMemo(() => ({
|
|
1114
|
+
sourceIds,
|
|
1115
|
+
autolink,
|
|
1116
|
+
math: true
|
|
1117
|
+
}), [sourceIds, autolink]);
|
|
1078
1118
|
|
|
1079
1119
|
// Smooth bursty streamed chunks into a steady character-by-character reveal.
|
|
1080
1120
|
// When not streaming, the hook returns children unchanged (no-op).
|
|
1081
1121
|
const smoothedText = useStreamingText(children, isStreaming);
|
|
1082
1122
|
const incrementalStateRef = useRef(createIncrementalState());
|
|
1083
|
-
// Reset incremental cache when
|
|
1084
|
-
// settled blocks were parsed with the previous setting.
|
|
1123
|
+
// Reset incremental cache when parser-affecting component options toggle —
|
|
1124
|
+
// cached settled blocks were parsed with the previous setting.
|
|
1085
1125
|
const prevAutolinkRef = useRef(autolink);
|
|
1086
|
-
|
|
1126
|
+
const prevMathRef = useRef(hasMathRenderer);
|
|
1127
|
+
if (prevAutolinkRef.current !== autolink || prevMathRef.current !== hasMathRenderer) {
|
|
1087
1128
|
incrementalStateRef.current = createIncrementalState();
|
|
1088
1129
|
prevAutolinkRef.current = autolink;
|
|
1130
|
+
prevMathRef.current = hasMathRenderer;
|
|
1089
1131
|
}
|
|
1090
1132
|
const blocks = useMemo(() => {
|
|
1091
1133
|
if (display === 'inline') {
|
|
@@ -1096,11 +1138,12 @@ export function Markdown({
|
|
|
1096
1138
|
incrementalStateRef.current = createIncrementalState();
|
|
1097
1139
|
return [];
|
|
1098
1140
|
}
|
|
1099
|
-
const
|
|
1100
|
-
|
|
1141
|
+
const options = hasMathRenderer ? mathParseOptions : legacyParseOptions;
|
|
1142
|
+
const input = trimStreamingArtifacts(smoothedText, options);
|
|
1143
|
+
return hasMathRenderer ? parseMarkdownIncremental(input, incrementalStateRef.current, mathParseOptions) : parseMarkdownIncremental(input, incrementalStateRef.current, legacyParseOptions);
|
|
1101
1144
|
}
|
|
1102
|
-
return parseMarkdown(children,
|
|
1103
|
-
}, [display, smoothedText, children, isStreaming,
|
|
1145
|
+
return hasMathRenderer ? parseMarkdown(children, mathParseOptions) : parseMarkdown(children, legacyParseOptions);
|
|
1146
|
+
}, [display, smoothedText, children, isStreaming, hasMathRenderer, mathParseOptions, legacyParseOptions]);
|
|
1104
1147
|
|
|
1105
1148
|
// Assign each top-level heading the slug that parseOutlineFromMarkdown
|
|
1106
1149
|
// would derive for it, so Outline hash links built from the same source
|
|
@@ -1126,9 +1169,10 @@ export function Markdown({
|
|
|
1126
1169
|
if (display !== 'inline') {
|
|
1127
1170
|
return [];
|
|
1128
1171
|
}
|
|
1129
|
-
const
|
|
1130
|
-
|
|
1131
|
-
|
|
1172
|
+
const options = hasMathRenderer ? mathParseOptions : legacyParseOptions;
|
|
1173
|
+
const input = isStreaming ? trimStreamingArtifacts(smoothedText, options) : children;
|
|
1174
|
+
return hasMathRenderer ? parseInline(input, mathParseOptions) : parseInline(input, legacyParseOptions);
|
|
1175
|
+
}, [display, smoothedText, children, isStreaming, hasMathRenderer, mathParseOptions, legacyParseOptions]);
|
|
1132
1176
|
|
|
1133
1177
|
// Track recent boundaries for stacked fade-in animation.
|
|
1134
1178
|
// The number of spans needed = ceil(animationDuration / tickInterval).
|
package/dist/Markdown/index.d.ts
CHANGED
|
@@ -6,5 +6,5 @@
|
|
|
6
6
|
export { Markdown } from './Markdown';
|
|
7
7
|
export type { MarkdownProps, MarkdownSource, MarkdownComponents, MarkdownInlinePlugin, } from './Markdown';
|
|
8
8
|
export { parseMarkdown, parseMarkdownIncremental, createIncrementalState, parseInline, } from './parser';
|
|
9
|
-
export type { BlockNode, InlineNode, SourceRange, ListItemNode, TableCellNode, TableAlignment, IncrementalState as IncrementalParseState, } from './parser';
|
|
9
|
+
export type { BlockNode, BlockNodeWithMath, MathBlockNode, InlineNode, InlineNodeWithMath, MathInlineNode, SourceRange, ListItemNode, TableCellNode, TableAlignment, ParseOptions, MathParseOptions, IncrementalState as IncrementalParseState, } from './parser';
|
|
10
10
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/Markdown/index.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AAEH,OAAO,EAAC,QAAQ,EAAC,MAAM,YAAY,CAAC;AACpC,YAAY,EACV,aAAa,EACb,cAAc,EACd,kBAAkB,EAClB,oBAAoB,GACrB,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,aAAa,EACb,wBAAwB,EACxB,sBAAsB,EACtB,WAAW,GACZ,MAAM,UAAU,CAAC;AAClB,YAAY,EACV,SAAS,EACT,UAAU,EACV,WAAW,EACX,YAAY,EACZ,aAAa,EACb,cAAc,EACd,gBAAgB,IAAI,qBAAqB,GAC1C,MAAM,UAAU,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/Markdown/index.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AAEH,OAAO,EAAC,QAAQ,EAAC,MAAM,YAAY,CAAC;AACpC,YAAY,EACV,aAAa,EACb,cAAc,EACd,kBAAkB,EAClB,oBAAoB,GACrB,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,aAAa,EACb,wBAAwB,EACxB,sBAAsB,EACtB,WAAW,GACZ,MAAM,UAAU,CAAC;AAClB,YAAY,EACV,SAAS,EACT,iBAAiB,EACjB,aAAa,EACb,UAAU,EACV,kBAAkB,EAClB,cAAc,EACd,WAAW,EACX,YAAY,EACZ,aAAa,EACb,cAAc,EACd,YAAY,EACZ,gBAAgB,EAChB,gBAAgB,IAAI,qBAAqB,GAC1C,MAAM,UAAU,CAAC"}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @file parser.ts
|
|
3
3
|
* @input Markdown string
|
|
4
|
-
* @output Array of MarkdownNode AST nodes; heading slug
|
|
4
|
+
* @output Array of MarkdownNode AST nodes, including opt-in math; heading slug
|
|
5
|
+
* helpers
|
|
5
6
|
* (inlineText, slugify, uniqueSlug) shared by Markdown rendering and
|
|
6
7
|
* Outline's parseOutlineFromMarkdown
|
|
7
8
|
* @position Core parser; consumed by Markdown.tsx and Outline
|
|
8
9
|
*/
|
|
10
|
+
/** Nodes returned by default and legacy parser calls. */
|
|
9
11
|
export type InlineNode = {
|
|
10
12
|
type: 'text';
|
|
11
13
|
content: string;
|
|
@@ -35,14 +37,49 @@ export type InlineNode = {
|
|
|
35
37
|
} | {
|
|
36
38
|
type: 'break';
|
|
37
39
|
};
|
|
38
|
-
|
|
40
|
+
/** The additional inline node returned only when parsing with `math: true`. */
|
|
41
|
+
export type MathInlineNode = {
|
|
42
|
+
type: 'math';
|
|
43
|
+
value: string;
|
|
44
|
+
};
|
|
45
|
+
/** Nodes returned by an explicitly math-enabled inline parse. */
|
|
46
|
+
export type InlineNodeWithMath = {
|
|
47
|
+
type: 'text';
|
|
48
|
+
content: string;
|
|
49
|
+
} | {
|
|
50
|
+
type: 'bold';
|
|
51
|
+
children: InlineNodeWithMath[];
|
|
52
|
+
} | {
|
|
53
|
+
type: 'italic';
|
|
54
|
+
children: InlineNodeWithMath[];
|
|
55
|
+
} | {
|
|
56
|
+
type: 'strikethrough';
|
|
57
|
+
children: InlineNodeWithMath[];
|
|
58
|
+
} | {
|
|
59
|
+
type: 'code';
|
|
60
|
+
content: string;
|
|
61
|
+
} | MathInlineNode | {
|
|
62
|
+
type: 'link';
|
|
63
|
+
href: string;
|
|
64
|
+
children: InlineNodeWithMath[];
|
|
65
|
+
} | {
|
|
66
|
+
type: 'image';
|
|
67
|
+
src: string;
|
|
68
|
+
alt: string;
|
|
69
|
+
} | {
|
|
70
|
+
type: 'citation';
|
|
71
|
+
sourceId: string;
|
|
72
|
+
} | {
|
|
73
|
+
type: 'break';
|
|
74
|
+
};
|
|
75
|
+
type BlockMetadata = {
|
|
39
76
|
/**
|
|
40
77
|
* Where this block came from in the source, when parsed with the
|
|
41
78
|
* `sourceRanges` option. Top-level blocks only.
|
|
42
79
|
*/
|
|
43
80
|
range?: SourceRange;
|
|
44
81
|
};
|
|
45
|
-
type
|
|
82
|
+
type LegacyBlockNodeKind = {
|
|
46
83
|
type: 'heading';
|
|
47
84
|
level: 1 | 2 | 3 | 4 | 5 | 6;
|
|
48
85
|
children: InlineNode[];
|
|
@@ -76,6 +113,49 @@ type BlockNodeKind = {
|
|
|
76
113
|
src: string;
|
|
77
114
|
alt: string;
|
|
78
115
|
};
|
|
116
|
+
/** Blocks returned by default and legacy parser calls. */
|
|
117
|
+
export type BlockNode = LegacyBlockNodeKind & BlockMetadata;
|
|
118
|
+
/** The additional block returned only when parsing with `math: true`. */
|
|
119
|
+
export type MathBlockNode = {
|
|
120
|
+
type: 'math';
|
|
121
|
+
value: string;
|
|
122
|
+
} & BlockMetadata;
|
|
123
|
+
type MathEnabledBlockNodeKind = {
|
|
124
|
+
type: 'heading';
|
|
125
|
+
level: 1 | 2 | 3 | 4 | 5 | 6;
|
|
126
|
+
children: InlineNodeWithMath[];
|
|
127
|
+
} | {
|
|
128
|
+
type: 'paragraph';
|
|
129
|
+
children: InlineNodeWithMath[];
|
|
130
|
+
} | {
|
|
131
|
+
type: 'codeblock';
|
|
132
|
+
language: string;
|
|
133
|
+
content: string;
|
|
134
|
+
} | MathBlockNode | {
|
|
135
|
+
type: 'blockquote';
|
|
136
|
+
children: BlockNodeWithMath[];
|
|
137
|
+
} | {
|
|
138
|
+
type: 'list';
|
|
139
|
+
ordered: boolean;
|
|
140
|
+
start?: number;
|
|
141
|
+
/** Ordered-list marker delimiter ('.' or ')'). Undefined for bullets. */
|
|
142
|
+
delimiter?: '.' | ')';
|
|
143
|
+
loose?: boolean;
|
|
144
|
+
items: ListItemNodeWithMath[];
|
|
145
|
+
} | {
|
|
146
|
+
type: 'table';
|
|
147
|
+
headers: TableCellNodeWithMath[];
|
|
148
|
+
alignments: TableAlignment[];
|
|
149
|
+
rows: TableCellNodeWithMath[][];
|
|
150
|
+
} | {
|
|
151
|
+
type: 'hr';
|
|
152
|
+
} | {
|
|
153
|
+
type: 'image';
|
|
154
|
+
src: string;
|
|
155
|
+
alt: string;
|
|
156
|
+
};
|
|
157
|
+
/** Blocks returned by an explicitly math-enabled block parse. */
|
|
158
|
+
export type BlockNodeWithMath = MathEnabledBlockNodeKind & BlockMetadata;
|
|
79
159
|
/**
|
|
80
160
|
* Where a block sits in the source string handed to `parseMarkdown`:
|
|
81
161
|
* `source.slice(start, end)` is the block, and `end` excludes the block's
|
|
@@ -93,9 +173,16 @@ export type ListItemNode = {
|
|
|
93
173
|
checked?: boolean;
|
|
94
174
|
children: BlockNode[];
|
|
95
175
|
};
|
|
176
|
+
type ListItemNodeWithMath = {
|
|
177
|
+
checked?: boolean;
|
|
178
|
+
children: BlockNodeWithMath[];
|
|
179
|
+
};
|
|
96
180
|
export type TableCellNode = {
|
|
97
181
|
children: InlineNode[];
|
|
98
182
|
};
|
|
183
|
+
type TableCellNodeWithMath = {
|
|
184
|
+
children: InlineNodeWithMath[];
|
|
185
|
+
};
|
|
99
186
|
export type TableAlignment = 'left' | 'center' | 'right' | null;
|
|
100
187
|
/**
|
|
101
188
|
* Options for the markdown parser entry points.
|
|
@@ -104,7 +191,7 @@ export type TableAlignment = 'left' | 'center' | 'right' | null;
|
|
|
104
191
|
* `parseMarkdownIncremental` functions also accept the legacy
|
|
105
192
|
* `ReadonlySet<string>` shape as the second argument.
|
|
106
193
|
*/
|
|
107
|
-
|
|
194
|
+
type CommonParseOptions = {
|
|
108
195
|
/** Set of citation source ids — `[id]` / `【id】` markers in this set
|
|
109
196
|
* become citation nodes instead of plain text / links. */
|
|
110
197
|
sourceIds?: ReadonlySet<string>;
|
|
@@ -131,14 +218,32 @@ export type ParseOptions = {
|
|
|
131
218
|
*/
|
|
132
219
|
sourceRanges?: boolean;
|
|
133
220
|
};
|
|
221
|
+
/** Options for default and legacy parser results. */
|
|
222
|
+
export type ParseOptions = CommonParseOptions & {
|
|
223
|
+
math?: false | undefined;
|
|
224
|
+
};
|
|
225
|
+
/**
|
|
226
|
+
* Options that explicitly parse `$…$` and `$$…$$` into math-enabled result
|
|
227
|
+
* unions. Keeping this separate prevents a legacy `ParseOptions` annotation
|
|
228
|
+
* from silently widening an exhaustive node switch.
|
|
229
|
+
*/
|
|
230
|
+
export type MathParseOptions = CommonParseOptions & {
|
|
231
|
+
math: true;
|
|
232
|
+
};
|
|
134
233
|
export declare function parseInline(text: string, sourceIds?: ReadonlySet<string>): InlineNode[];
|
|
234
|
+
export declare function parseInline(text: string, options: MathParseOptions): InlineNodeWithMath[];
|
|
135
235
|
export declare function parseInline(text: string, options: ParseOptions): InlineNode[];
|
|
136
236
|
export declare function parseMarkdown(input: string, sourceIds?: ReadonlySet<string>): BlockNode[];
|
|
237
|
+
export declare function parseMarkdown(input: string, options: MathParseOptions): BlockNodeWithMath[];
|
|
137
238
|
export declare function parseMarkdown(input: string, options: ParseOptions): BlockNode[];
|
|
138
|
-
|
|
239
|
+
type IncrementalBlockNode<MathEnabled extends boolean> = MathEnabled extends true ? BlockNodeWithMath : BlockNode;
|
|
240
|
+
declare const incrementalStateMode: unique symbol;
|
|
241
|
+
export interface IncrementalState<MathEnabled extends boolean = false> {
|
|
242
|
+
/** @internal Nominally couples a factory-created cache to its node union. */
|
|
243
|
+
readonly [incrementalStateMode]: MathEnabled;
|
|
139
244
|
prevInput: string;
|
|
140
245
|
settledText: string;
|
|
141
|
-
settledBlocks:
|
|
246
|
+
settledBlocks: IncrementalBlockNode<MathEnabled>[];
|
|
142
247
|
settledUpTo: number;
|
|
143
248
|
/**
|
|
144
249
|
* The `autolink` option the cached `settledBlocks` were parsed with.
|
|
@@ -147,6 +252,8 @@ export interface IncrementalState {
|
|
|
147
252
|
* with newly-arriving content.
|
|
148
253
|
*/
|
|
149
254
|
autolink?: 'gfm';
|
|
255
|
+
/** Whether the cached settled blocks were parsed with math enabled. */
|
|
256
|
+
math?: MathEnabled;
|
|
150
257
|
/**
|
|
151
258
|
* The `sourceRanges` option the cached `settledBlocks` were parsed with.
|
|
152
259
|
* Flipping it invalidates them the same way `autolink` does: they either
|
|
@@ -171,17 +278,23 @@ type IncrementalWork = {
|
|
|
171
278
|
/** Block nodes parsed anew this call (settled delta + unsettled tail). */
|
|
172
279
|
readonly renderedBlocks: number;
|
|
173
280
|
};
|
|
174
|
-
|
|
281
|
+
/**
|
|
282
|
+
* Create an incremental parser cache. Use the `<true>` type argument with
|
|
283
|
+
* `MathParseOptions` so the cache and returned nodes share the math contract.
|
|
284
|
+
*/
|
|
285
|
+
export declare function createIncrementalState<MathEnabled extends boolean = false>(): IncrementalState<MathEnabled>;
|
|
175
286
|
/**
|
|
176
287
|
* Deterministic work counters for the most recent incremental parse.
|
|
177
288
|
* @internal Exported from this module for performance regression tests only.
|
|
178
289
|
*/
|
|
179
|
-
export declare function getIncrementalParseWork(state: IncrementalState): IncrementalWork;
|
|
290
|
+
export declare function getIncrementalParseWork(state: IncrementalState<boolean>): IncrementalWork;
|
|
180
291
|
/**
|
|
181
292
|
* Strip trailing incomplete inline syntax that appears during streaming.
|
|
182
293
|
* Only affects the tail of the last line — safe to apply to the full string.
|
|
183
294
|
*/
|
|
184
|
-
export declare function trimStreamingArtifacts(input: string
|
|
295
|
+
export declare function trimStreamingArtifacts(input: string, options?: {
|
|
296
|
+
math?: boolean;
|
|
297
|
+
}): string;
|
|
185
298
|
/**
|
|
186
299
|
* Parse one cumulative snapshot of a streaming Markdown document.
|
|
187
300
|
*
|
|
@@ -193,10 +306,11 @@ export declare function trimStreamingArtifacts(input: string): string;
|
|
|
193
306
|
* starts with the settled prefix (a replacement rather than an append),
|
|
194
307
|
* the cache is discarded and the whole document is re-parsed.
|
|
195
308
|
*/
|
|
196
|
-
export declare function parseMarkdownIncremental(input: string, state: IncrementalState
|
|
197
|
-
export declare function parseMarkdownIncremental(input: string, state: IncrementalState
|
|
309
|
+
export declare function parseMarkdownIncremental(input: string, state: IncrementalState<false>, sourceIds?: ReadonlySet<string>): BlockNode[];
|
|
310
|
+
export declare function parseMarkdownIncremental(input: string, state: IncrementalState<true>, options: MathParseOptions): BlockNodeWithMath[];
|
|
311
|
+
export declare function parseMarkdownIncremental(input: string, state: IncrementalState<false>, options: ParseOptions): BlockNode[];
|
|
198
312
|
/** Flatten inline nodes into their plain text content. */
|
|
199
|
-
export declare function inlineText(nodes:
|
|
313
|
+
export declare function inlineText(nodes: ReadonlyArray<InlineNodeWithMath>): string;
|
|
200
314
|
/** Turn heading text into a URL-safe slug (lowercase, hyphen-separated). */
|
|
201
315
|
export declare function slugify(value: string): string;
|
|
202
316
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../src/Markdown/parser.ts"],"names":[],"mappings":"AAEA
|
|
1
|
+
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources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