@astryxdesign/core 0.6.1-canary.bdea6e2 → 0.6.1-canary.c87f73f
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/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 +2 -1
- package/locales/en.json +16 -0
- package/locales/pseudo.json +12 -0
- package/package.json +8 -6
- package/scripts/agent-doc-state.mjs +1 -1
- 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/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/theme/derivedVarRegistry.test.ts +6 -4
|
@@ -119,6 +119,9 @@ export interface DateRangeInputProps extends Omit<BaseProps, 'onChange' | 'defau
|
|
|
119
119
|
minRangeSpan?: number;
|
|
120
120
|
/**
|
|
121
121
|
* Preset date ranges shown as quick-select options beside the calendar.
|
|
122
|
+
* A preset is disabled when either endpoint violates `min`, `max`, or
|
|
123
|
+
* `dateConstraints`, or when its span violates `minRangeSpan` or
|
|
124
|
+
* `maxRangeSpan`.
|
|
122
125
|
*/
|
|
123
126
|
presets?: ReadonlyArray<DateRangePreset>;
|
|
124
127
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DateRangeInput.d.ts","sourceRoot":"","sources":["../../src/DateRangeInput/DateRangeInput.tsx"],"names":[],"mappings":"AAqCA,OAAO,EAGL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;;OAGG;IACH,cAAc,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;IAEvB;;;;;OAKG;IACH,YAAY,CAAC,EAAE,SAAS,GAAG,aAAa,CAAC;CAC1C;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,cAAc,CAAC,EAC7B,KAAK,EACL,aAAqB,EACrB,WAAW,EACX,UAAkB,EAClB,UAAkB,EAClB,UAAkB,EAClB,eAAe,EACf,KAAK,EACL,QAAQ,EACR,YAAY,EACZ,SAAiB,EACjB,GAAG,EACH,GAAG,EACH,eAAe,EACf,YAAY,EACZ,YAAY,EACZ,OAAO,EACP,QAAe,EACf,WAAW,EAAE,oBAAoB,EACjC,IAAI,EAAE,QAAQ,EACd,MAAM,EACN,aAA0B,EAC1B,YAAY,EACZ,cAAkB,EAClB,YAAY,EACZ,KAAK,EACL,MAAM,EACN,SAAS,EACT,KAAK,EACL,GAAG,EACH,GAAG,IAAI,EACR,EAAE,mBAAmB,+BA+RrB;yBA/Te,cAAc"}
|
|
@@ -24,6 +24,7 @@ import { Field, InputClearButton, inputWrapperStyles, inputStatusBorderStyles, i
|
|
|
24
24
|
import { Icon } from "../Icon/index.js";
|
|
25
25
|
import { Spinner } from "../Spinner/index.js";
|
|
26
26
|
import { Calendar } from "../Calendar/index.js";
|
|
27
|
+
import { useCalendarConstraints } from "../Calendar/hooks/index.js";
|
|
27
28
|
import { usePopover } from "../Popover/index.js";
|
|
28
29
|
import { useTooltip } from "../Tooltip/index.js";
|
|
29
30
|
import { mergeProps } from "../utils/index.js";
|
|
@@ -232,6 +233,13 @@ export function DateRangeInput({
|
|
|
232
233
|
dialogLabel: t('@astryx.dateRangeInput.dialogLabel'),
|
|
233
234
|
closeButtonLabel: t('@astryx.dateInput.closeCalendar')
|
|
234
235
|
});
|
|
236
|
+
const {
|
|
237
|
+
isDateDisabled
|
|
238
|
+
} = useCalendarConstraints({
|
|
239
|
+
min,
|
|
240
|
+
max,
|
|
241
|
+
dateConstraints
|
|
242
|
+
});
|
|
235
243
|
const fireChange = useCallback(newValue => {
|
|
236
244
|
if (isBusy) {
|
|
237
245
|
return;
|
|
@@ -257,10 +265,6 @@ export function DateRangeInput({
|
|
|
257
265
|
fireChange(range);
|
|
258
266
|
popover.hide();
|
|
259
267
|
}, [fireChange, popover]);
|
|
260
|
-
const handlePresetClick = useCallback(preset => {
|
|
261
|
-
fireChange(preset.getRange());
|
|
262
|
-
popover.hide();
|
|
263
|
-
}, [fireChange, popover]);
|
|
264
268
|
const handleClear = useCallback(e => {
|
|
265
269
|
e.stopPropagation();
|
|
266
270
|
fireChange(null);
|
|
@@ -362,13 +366,13 @@ export function DateRangeInput({
|
|
|
362
366
|
children: [presets && presets.length > 0 && /*#__PURE__*/_jsx("div", {
|
|
363
367
|
role: "group",
|
|
364
368
|
"aria-label": t('@astryx.dateRangeInput.presetDateRanges'),
|
|
365
|
-
...{
|
|
369
|
+
...mergeProps(themeProps('date-range-input-presets'), {
|
|
366
370
|
className: "x78zum5 xdt5ytf xzye2dw x1b2ylru xw8tdv1 x18b5jzi xl0t3rv x1d77m7x"
|
|
367
|
-
},
|
|
371
|
+
}),
|
|
368
372
|
children: presets.map(preset => {
|
|
369
373
|
const presetRange = preset.getRange();
|
|
370
374
|
const isActive = isRangeEqual(value, presetRange);
|
|
371
|
-
const isPresetDisabled = !isRangeWithinSpan(presetRange, maxRangeSpan, minRangeSpan);
|
|
375
|
+
const isPresetDisabled = !isRangeWithinSpan(presetRange, maxRangeSpan, minRangeSpan) || isDateDisabled(plainDateFromISO(presetRange.start)) || isDateDisabled(plainDateFromISO(presetRange.end));
|
|
372
376
|
return /*#__PURE__*/_jsx("button", {
|
|
373
377
|
type: "button"
|
|
374
378
|
// These presets are independent action buttons navigated by
|
|
@@ -379,8 +383,11 @@ export function DateRangeInput({
|
|
|
379
383
|
,
|
|
380
384
|
"aria-current": isActive ? 'true' : undefined,
|
|
381
385
|
disabled: isPresetDisabled,
|
|
382
|
-
onClick: () =>
|
|
383
|
-
...
|
|
386
|
+
onClick: () => handleRangeSelect(presetRange),
|
|
387
|
+
...mergeProps(themeProps('date-range-input-preset', {
|
|
388
|
+
selected: isActive ? 'selected' : null,
|
|
389
|
+
disabled: isPresetDisabled ? 'disabled' : null
|
|
390
|
+
}), stylex.props(focusOutlineStyles.focusVisible, styles.presetButton, isActive && styles.presetButtonActive, isPresetDisabled && styles.presetButtonDisabled)),
|
|
384
391
|
children: preset.label
|
|
385
392
|
}, preset.label);
|
|
386
393
|
})
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @file DialogHeader.tsx
|
|
3
|
-
* @input Uses React,
|
|
3
|
+
* @input Uses React, StyleX, LayoutHeader, Button, Icon, Heading, Text, DialogContext, mergeProps, themeProps
|
|
4
4
|
* @output Exports DialogHeader component and DialogHeaderProps
|
|
5
5
|
* @position Dialog header component; used with Dialog and Layout
|
|
6
6
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DialogHeader.d.ts","sourceRoot":"","sources":["../../src/Dialog/DialogHeader.tsx"],"names":[],"mappings":"AAIA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAoB,KAAK,SAAS,EAAC,MAAM,OAAO,CAAC;AAQxD,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"DialogHeader.d.ts","sourceRoot":"","sources":["../../src/Dialog/DialogHeader.tsx"],"names":[],"mappings":"AAIA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAoB,KAAK,SAAS,EAAC,MAAM,OAAO,CAAC;AAQxD,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,cAAc,CAAC;AAyC5C,MAAM,WAAW,iBAAkB,SAAQ,SAAS,CAAC,cAAc,CAAC;IAClE,wCAAwC;IACxC,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;IAChC;;;;;OAKG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;;;OAIG;IACH,YAAY,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,OAAO,CAAC;IAE5C;;OAEG;IACH,YAAY,CAAC,EAAE,SAAS,CAAC;IAEzB;;OAEG;IACH,UAAU,CAAC,EAAE,SAAS,CAAC;IAEvB;;;;OAIG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,YAAY,CAAC,EAC3B,KAAK,EACL,QAAQ,EACR,YAAY,EACZ,YAAY,EACZ,UAAU,EACV,UAAU,EACV,MAAM,EACN,SAAS,EACT,KAAK,EACL,GAAG,EACH,GAAG,IAAI,EACR,EAAE,iBAAiB,+BAmFnB;yBA/Fe,YAAY"}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* @file DialogHeader.tsx
|
|
7
|
-
* @input Uses React,
|
|
7
|
+
* @input Uses React, StyleX, LayoutHeader, Button, Icon, Heading, Text, DialogContext, mergeProps, themeProps
|
|
8
8
|
* @output Exports DialogHeader component and DialogHeaderProps
|
|
9
9
|
* @position Dialog header component; used with Dialog and Layout
|
|
10
10
|
*
|
|
@@ -24,6 +24,8 @@ import { Button } from "../Button/index.js";
|
|
|
24
24
|
import { Icon } from "../Icon/index.js";
|
|
25
25
|
import { Heading } from "../Heading/Heading.js";
|
|
26
26
|
import { Text } from "../Text/Text.js";
|
|
27
|
+
import { mergeProps } from "../utils/index.js";
|
|
28
|
+
import { themeProps } from "../utils/themeProps.js";
|
|
27
29
|
import { useDialogContext } from "./DialogContext.js";
|
|
28
30
|
import { useTranslator } from "../i18n/index.js";
|
|
29
31
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
@@ -92,18 +94,18 @@ export function DialogHeader({
|
|
|
92
94
|
style: style,
|
|
93
95
|
...rest,
|
|
94
96
|
children: /*#__PURE__*/_jsxs("div", {
|
|
95
|
-
...{
|
|
97
|
+
...mergeProps(themeProps('dialog-header'), {
|
|
96
98
|
className: "x78zum5 x1cy8zhl x1qughib xjcht0a"
|
|
97
|
-
},
|
|
99
|
+
}),
|
|
98
100
|
children: [startContent && /*#__PURE__*/_jsx("div", {
|
|
99
101
|
...{
|
|
100
102
|
className: "x78zum5 x6s0dn4 x1txdalj x2lah0s"
|
|
101
103
|
},
|
|
102
104
|
children: startContent
|
|
103
105
|
}), /*#__PURE__*/_jsxs("div", {
|
|
104
|
-
...{
|
|
105
|
-
className: "x98rzlu xeuugli xqixskq"
|
|
106
|
-
},
|
|
106
|
+
...mergeProps(themeProps('dialog-header-title-block'), {
|
|
107
|
+
className: "x78zum5 xdt5ytf xsn7fz1 x98rzlu xeuugli xqixskq"
|
|
108
|
+
}),
|
|
107
109
|
children: [/*#__PURE__*/_jsx(Heading, {
|
|
108
110
|
ref: titleRef,
|
|
109
111
|
id: titleId,
|
|
@@ -132,7 +134,8 @@ export function DialogHeader({
|
|
|
132
134
|
tooltip: t('@astryx.dialog.close'),
|
|
133
135
|
icon: /*#__PURE__*/_jsx(Icon, {
|
|
134
136
|
icon: "close",
|
|
135
|
-
color: "inherit"
|
|
137
|
+
color: "inherit",
|
|
138
|
+
...themeProps('dialog-header-close-icon')
|
|
136
139
|
}),
|
|
137
140
|
onClick: () => {
|
|
138
141
|
onOpenChange?.(false);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileInput.d.ts","sourceRoot":"","sources":["../../src/FileInput/FileInput.tsx"],"names":[],"mappings":"AAsCA,OAAO,EAGL,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACxB,MAAM,UAAU,CAAC;AASlB,YAAY,EACV,WAAW,IAAI,eAAe,EAC9B,eAAe,IAAI,mBAAmB,GACvC,MAAM,UAAU,CAAC;AAElB,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK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ACH,IAAI,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC;IAC5B;;;OAGG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;;;OAIG;IACH,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,EACxB,KAAK,EACL,aAAqB,EACrB,KAAK,EACL,QAAQ,EACR,YAAY,EACZ,MAAM,EACN,UAAkB,EAClB,OAAO,EACP,QAAQ,EACR,UAAkB,EAClB,eAAe,EACf,UAAkB,EAClB,SAAiB,EACjB,MAAM,EAAE,UAAU,EAClB,aAA0B,EAC1B,WAAW,EACX,WAAW,EACX,IAAc,EACd,UAAkB,EAClB,YAAY,EACZ,KAAK,EACL,MAAM,EACN,SAAS,EACT,KAAK,EACL,GAAG,EACH,GAAG,IAAI,EACR,EAAE,cAAc,+
|
|
1
|
+
{"version":3,"file":"FileInput.d.ts","sourceRoot":"","sources":["../../src/FileInput/FileInput.tsx"],"names":[],"mappings":"AAsCA,OAAO,EAGL,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACxB,MAAM,UAAU,CAAC;AASlB,YAAY,EACV,WAAW,IAAI,eAAe,EAC9B,eAAe,IAAI,mBAAmB,GACvC,MAAM,UAAU,CAAC;AAElB,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,gBAAgB,CAAC;AAgO9C,MAAM,WAAW,cAAe,SAAQ,IAAI,CAC1C,SAAS,EACT,UAAU,GAAG,cAAc,GAAG,OAAO,CACtC;IACC,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;IAClC;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB;;OAEG;IACH,KAAK,EAAE,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AAkB,EAClB,OAAO,EACP,QAAQ,EACR,UAAkB,EAClB,eAAe,EACf,UAAkB,EAClB,SAAiB,EACjB,MAAM,EAAE,UAAU,EAClB,aAA0B,EAC1B,WAAW,EACX,WAAW,EACX,IAAc,EACd,UAAkB,EAClB,YAAY,EACZ,KAAK,EACL,MAAM,EACN,SAAS,EACT,KAAK,EACL,GAAG,EACH,GAAG,IAAI,EACR,EAAE,cAAc,+BAkbhB;yBA7ce,SAAS"}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
/**
|
|
6
6
|
* @file FileInput.tsx
|
|
7
7
|
* @input Uses React, useId, Field, Icon, Spinner, VisuallyHidden
|
|
8
|
-
* @output Exports FileInput component,
|
|
8
|
+
* @output Exports FileInput component, public types, and its root/icon theme targets
|
|
9
9
|
* @position Core implementation; consumed by index.ts, tested by FileInput.test.tsx
|
|
10
10
|
*
|
|
11
11
|
* SYNC: When modified, update these files to stay in sync:
|
|
@@ -406,7 +406,10 @@ export function FileInput({
|
|
|
406
406
|
children: [/*#__PURE__*/_jsx(Icon, {
|
|
407
407
|
icon: "arrowUp",
|
|
408
408
|
size: "md",
|
|
409
|
-
color: "secondary"
|
|
409
|
+
color: "secondary",
|
|
410
|
+
...themeProps('file-input-icon', {
|
|
411
|
+
mode
|
|
412
|
+
})
|
|
410
413
|
}), /*#__PURE__*/_jsx("span", {
|
|
411
414
|
...{
|
|
412
415
|
className: "x9ynric xjm74w1 x6pjikd xw6l6zx xv1l7n4 x2b8uid x87ps6o"
|
|
@@ -432,7 +435,10 @@ export function FileInput({
|
|
|
432
435
|
children: [/*#__PURE__*/_jsx(Icon, {
|
|
433
436
|
icon: "arrowUp",
|
|
434
437
|
size: "sm",
|
|
435
|
-
color: "secondary"
|
|
438
|
+
color: "secondary",
|
|
439
|
+
...themeProps('file-input-icon', {
|
|
440
|
+
mode
|
|
441
|
+
})
|
|
436
442
|
}), /*#__PURE__*/_jsx("span", {
|
|
437
443
|
...{
|
|
438
444
|
0: {
|
|
@@ -5,7 +5,7 @@ import type { CitationSource } from '../Citation/Citation';
|
|
|
5
5
|
/**
|
|
6
6
|
* A plugin that transforms text patterns into custom React elements
|
|
7
7
|
* inside Markdown. Applied to parsed text nodes only — code blocks,
|
|
8
|
-
* inline code, and other non-prose contexts are unaffected.
|
|
8
|
+
* inline code, math, and other non-prose contexts are unaffected.
|
|
9
9
|
*
|
|
10
10
|
* Follows Lexical's TextMatchTransformer architecture:
|
|
11
11
|
* - `pattern` for initial regex matching
|
|
@@ -38,6 +38,14 @@ export interface MarkdownComponents {
|
|
|
38
38
|
inlineCode?: React.ComponentType<{
|
|
39
39
|
children: string;
|
|
40
40
|
}>;
|
|
41
|
+
/**
|
|
42
|
+
* Renders opt-in `$…$` and `$$…$$` math. Supplying this renderer enables
|
|
43
|
+
* math parsing; Astryx passes the raw expression and does not execute it.
|
|
44
|
+
*/
|
|
45
|
+
math?: React.ComponentType<{
|
|
46
|
+
value: string;
|
|
47
|
+
display: 'inline' | 'block';
|
|
48
|
+
}>;
|
|
41
49
|
citation?: React.ComponentType<{
|
|
42
50
|
source: CitationSource;
|
|
43
51
|
number: number;
|
|
@@ -125,7 +133,7 @@ export interface MarkdownProps extends BaseProps<HTMLElement> {
|
|
|
125
133
|
components?: Partial<MarkdownComponents>;
|
|
126
134
|
/**
|
|
127
135
|
* Plugins that transform text patterns into custom React elements.
|
|
128
|
-
* Applied to text nodes after parsing — code blocks
|
|
136
|
+
* Applied to text nodes after parsing — code blocks, inline code, and math
|
|
129
137
|
* are unaffected. Patterns are matched in order; first match wins
|
|
130
138
|
* for overlapping ranges.
|
|
131
139
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Markdown.d.ts","sourceRoot":"","sources":["../../src/Markdown/Markdown.tsx"],"names":[],"mappings":"AAYA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAe/B,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,gBAAgB,CAAC;AAgBhD,OAAO,KAA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, 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
|
/**
|