@stream-mdx/core 0.0.2 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/dist/index.cjs +358 -27
- package/dist/index.d.cts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.mjs +356 -27
- package/dist/inline-parser.cjs +100 -18
- package/dist/inline-parser.d.cts +10 -0
- package/dist/inline-parser.d.ts +10 -0
- package/dist/inline-parser.mjs +100 -18
- package/dist/mixed-content.cjs +130 -9
- package/dist/mixed-content.d.cts +16 -2
- package/dist/mixed-content.d.ts +16 -2
- package/dist/mixed-content.mjs +130 -9
- package/dist/streaming/inline-streaming.cjs +153 -0
- package/dist/streaming/inline-streaming.d.cts +28 -0
- package/dist/streaming/inline-streaming.d.ts +28 -0
- package/dist/streaming/inline-streaming.mjs +127 -0
- package/dist/types.d.cts +24 -1
- package/dist/types.d.ts +24 -1
- package/dist/worker-html-sanitizer.cjs +16 -2
- package/dist/worker-html-sanitizer.mjs +16 -2
- package/package.json +7 -2
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/streaming/inline-streaming.ts
|
|
21
|
+
var inline_streaming_exports = {};
|
|
22
|
+
__export(inline_streaming_exports, {
|
|
23
|
+
normalizeFormatAnticipation: () => normalizeFormatAnticipation,
|
|
24
|
+
prepareInlineStreamingContent: () => prepareInlineStreamingContent
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(inline_streaming_exports);
|
|
27
|
+
var DEFAULT_FORMAT_ANTICIPATION = {
|
|
28
|
+
inline: false,
|
|
29
|
+
mathInline: false,
|
|
30
|
+
mathBlock: false,
|
|
31
|
+
html: false,
|
|
32
|
+
mdx: false,
|
|
33
|
+
regex: false
|
|
34
|
+
};
|
|
35
|
+
function normalizeFormatAnticipation(input) {
|
|
36
|
+
if (input === true) {
|
|
37
|
+
return { ...DEFAULT_FORMAT_ANTICIPATION, inline: true };
|
|
38
|
+
}
|
|
39
|
+
if (!input) {
|
|
40
|
+
return { ...DEFAULT_FORMAT_ANTICIPATION };
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
inline: input.inline ?? false,
|
|
44
|
+
mathInline: input.mathInline ?? false,
|
|
45
|
+
mathBlock: input.mathBlock ?? false,
|
|
46
|
+
html: input.html ?? false,
|
|
47
|
+
mdx: input.mdx ?? false,
|
|
48
|
+
regex: input.regex ?? false
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function prepareInlineStreamingContent(content, options) {
|
|
52
|
+
const enableMath = options?.math !== false;
|
|
53
|
+
const anticipation = normalizeFormatAnticipation(options?.formatAnticipation);
|
|
54
|
+
const enableInlineAnticipation = anticipation.inline;
|
|
55
|
+
const enableMathInlineAnticipation = anticipation.mathInline;
|
|
56
|
+
const enableMathBlockAnticipation = anticipation.mathBlock;
|
|
57
|
+
const stack = [];
|
|
58
|
+
const toggleToken = (token) => {
|
|
59
|
+
const last = stack[stack.length - 1];
|
|
60
|
+
if (last === token) {
|
|
61
|
+
stack.pop();
|
|
62
|
+
} else {
|
|
63
|
+
stack.push(token);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
let mathDisplayOpen = false;
|
|
67
|
+
let mathDisplayCrossedNewline = false;
|
|
68
|
+
for (let i = 0; i < content.length; i++) {
|
|
69
|
+
const code = content.charCodeAt(i);
|
|
70
|
+
if (code === 10 || code === 13) {
|
|
71
|
+
if (mathDisplayOpen) {
|
|
72
|
+
mathDisplayCrossedNewline = true;
|
|
73
|
+
}
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
if (code === 96) {
|
|
77
|
+
toggleToken("code");
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
if (code === 126 && i + 1 < content.length && content.charCodeAt(i + 1) === 126) {
|
|
81
|
+
toggleToken("strike");
|
|
82
|
+
i += 1;
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
if (code === 42) {
|
|
86
|
+
if (i + 1 < content.length && content.charCodeAt(i + 1) === 42) {
|
|
87
|
+
toggleToken("strong");
|
|
88
|
+
i += 1;
|
|
89
|
+
} else {
|
|
90
|
+
toggleToken("em");
|
|
91
|
+
}
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
if (enableMath && code === 36) {
|
|
95
|
+
if (i + 1 < content.length && content.charCodeAt(i + 1) === 36) {
|
|
96
|
+
toggleToken("math-display");
|
|
97
|
+
if (mathDisplayOpen) {
|
|
98
|
+
mathDisplayOpen = false;
|
|
99
|
+
mathDisplayCrossedNewline = false;
|
|
100
|
+
} else {
|
|
101
|
+
mathDisplayOpen = true;
|
|
102
|
+
mathDisplayCrossedNewline = false;
|
|
103
|
+
}
|
|
104
|
+
i += 1;
|
|
105
|
+
} else {
|
|
106
|
+
toggleToken("math-inline");
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
const hasIncompleteFormatting = stack.some((token) => token === "code" || token === "strike" || token === "strong" || token === "em");
|
|
111
|
+
const hasIncompleteMathInline = stack.includes("math-inline");
|
|
112
|
+
const hasIncompleteMathDisplay = stack.includes("math-display");
|
|
113
|
+
const hasIncompleteMath = hasIncompleteMathInline || hasIncompleteMathDisplay;
|
|
114
|
+
if (enableMath && hasIncompleteMath) {
|
|
115
|
+
if (hasIncompleteMathInline && !enableMathInlineAnticipation) {
|
|
116
|
+
return { kind: "raw", status: "raw", reason: "incomplete-math" };
|
|
117
|
+
}
|
|
118
|
+
if (hasIncompleteMathDisplay && (!enableMathBlockAnticipation || mathDisplayCrossedNewline)) {
|
|
119
|
+
return { kind: "raw", status: "raw", reason: "incomplete-math" };
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
if (hasIncompleteFormatting && !enableInlineAnticipation) {
|
|
123
|
+
return { kind: "raw", status: "raw", reason: "incomplete-formatting" };
|
|
124
|
+
}
|
|
125
|
+
if (!hasIncompleteFormatting && !hasIncompleteMath) {
|
|
126
|
+
return { kind: "parse", status: "complete", content, appended: "" };
|
|
127
|
+
}
|
|
128
|
+
const appendForToken = (token) => {
|
|
129
|
+
switch (token) {
|
|
130
|
+
case "code":
|
|
131
|
+
return "`";
|
|
132
|
+
case "strike":
|
|
133
|
+
return "~~";
|
|
134
|
+
case "strong":
|
|
135
|
+
return "**";
|
|
136
|
+
case "em":
|
|
137
|
+
return "*";
|
|
138
|
+
case "math-inline":
|
|
139
|
+
return "$";
|
|
140
|
+
case "math-display":
|
|
141
|
+
return "$$";
|
|
142
|
+
default:
|
|
143
|
+
return "";
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
const appended = stack.slice().reverse().map((token) => appendForToken(token)).join("");
|
|
147
|
+
return { kind: "parse", status: "anticipated", content: content + appended, appended };
|
|
148
|
+
}
|
|
149
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
150
|
+
0 && (module.exports = {
|
|
151
|
+
normalizeFormatAnticipation,
|
|
152
|
+
prepareInlineStreamingContent
|
|
153
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { FormatAnticipationConfig } from '../types.cjs';
|
|
2
|
+
|
|
3
|
+
type InlineStreamingInlineStatus = "complete" | "anticipated" | "raw";
|
|
4
|
+
type NormalizedFormatAnticipation = {
|
|
5
|
+
inline: boolean;
|
|
6
|
+
mathInline: boolean;
|
|
7
|
+
mathBlock: boolean;
|
|
8
|
+
html: boolean;
|
|
9
|
+
mdx: boolean;
|
|
10
|
+
regex: boolean;
|
|
11
|
+
};
|
|
12
|
+
declare function normalizeFormatAnticipation(input?: FormatAnticipationConfig): NormalizedFormatAnticipation;
|
|
13
|
+
type InlineStreamingPrepareResult = {
|
|
14
|
+
kind: "raw";
|
|
15
|
+
status: "raw";
|
|
16
|
+
reason: "incomplete-math" | "incomplete-formatting";
|
|
17
|
+
} | {
|
|
18
|
+
kind: "parse";
|
|
19
|
+
status: Exclude<InlineStreamingInlineStatus, "raw">;
|
|
20
|
+
content: string;
|
|
21
|
+
appended: string;
|
|
22
|
+
};
|
|
23
|
+
declare function prepareInlineStreamingContent(content: string, options?: {
|
|
24
|
+
formatAnticipation?: FormatAnticipationConfig;
|
|
25
|
+
math?: boolean;
|
|
26
|
+
}): InlineStreamingPrepareResult;
|
|
27
|
+
|
|
28
|
+
export { type InlineStreamingInlineStatus, type InlineStreamingPrepareResult, type NormalizedFormatAnticipation, normalizeFormatAnticipation, prepareInlineStreamingContent };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { FormatAnticipationConfig } from '../types.js';
|
|
2
|
+
|
|
3
|
+
type InlineStreamingInlineStatus = "complete" | "anticipated" | "raw";
|
|
4
|
+
type NormalizedFormatAnticipation = {
|
|
5
|
+
inline: boolean;
|
|
6
|
+
mathInline: boolean;
|
|
7
|
+
mathBlock: boolean;
|
|
8
|
+
html: boolean;
|
|
9
|
+
mdx: boolean;
|
|
10
|
+
regex: boolean;
|
|
11
|
+
};
|
|
12
|
+
declare function normalizeFormatAnticipation(input?: FormatAnticipationConfig): NormalizedFormatAnticipation;
|
|
13
|
+
type InlineStreamingPrepareResult = {
|
|
14
|
+
kind: "raw";
|
|
15
|
+
status: "raw";
|
|
16
|
+
reason: "incomplete-math" | "incomplete-formatting";
|
|
17
|
+
} | {
|
|
18
|
+
kind: "parse";
|
|
19
|
+
status: Exclude<InlineStreamingInlineStatus, "raw">;
|
|
20
|
+
content: string;
|
|
21
|
+
appended: string;
|
|
22
|
+
};
|
|
23
|
+
declare function prepareInlineStreamingContent(content: string, options?: {
|
|
24
|
+
formatAnticipation?: FormatAnticipationConfig;
|
|
25
|
+
math?: boolean;
|
|
26
|
+
}): InlineStreamingPrepareResult;
|
|
27
|
+
|
|
28
|
+
export { type InlineStreamingInlineStatus, type InlineStreamingPrepareResult, type NormalizedFormatAnticipation, normalizeFormatAnticipation, prepareInlineStreamingContent };
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
// src/streaming/inline-streaming.ts
|
|
2
|
+
var DEFAULT_FORMAT_ANTICIPATION = {
|
|
3
|
+
inline: false,
|
|
4
|
+
mathInline: false,
|
|
5
|
+
mathBlock: false,
|
|
6
|
+
html: false,
|
|
7
|
+
mdx: false,
|
|
8
|
+
regex: false
|
|
9
|
+
};
|
|
10
|
+
function normalizeFormatAnticipation(input) {
|
|
11
|
+
if (input === true) {
|
|
12
|
+
return { ...DEFAULT_FORMAT_ANTICIPATION, inline: true };
|
|
13
|
+
}
|
|
14
|
+
if (!input) {
|
|
15
|
+
return { ...DEFAULT_FORMAT_ANTICIPATION };
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
inline: input.inline ?? false,
|
|
19
|
+
mathInline: input.mathInline ?? false,
|
|
20
|
+
mathBlock: input.mathBlock ?? false,
|
|
21
|
+
html: input.html ?? false,
|
|
22
|
+
mdx: input.mdx ?? false,
|
|
23
|
+
regex: input.regex ?? false
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function prepareInlineStreamingContent(content, options) {
|
|
27
|
+
const enableMath = options?.math !== false;
|
|
28
|
+
const anticipation = normalizeFormatAnticipation(options?.formatAnticipation);
|
|
29
|
+
const enableInlineAnticipation = anticipation.inline;
|
|
30
|
+
const enableMathInlineAnticipation = anticipation.mathInline;
|
|
31
|
+
const enableMathBlockAnticipation = anticipation.mathBlock;
|
|
32
|
+
const stack = [];
|
|
33
|
+
const toggleToken = (token) => {
|
|
34
|
+
const last = stack[stack.length - 1];
|
|
35
|
+
if (last === token) {
|
|
36
|
+
stack.pop();
|
|
37
|
+
} else {
|
|
38
|
+
stack.push(token);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
let mathDisplayOpen = false;
|
|
42
|
+
let mathDisplayCrossedNewline = false;
|
|
43
|
+
for (let i = 0; i < content.length; i++) {
|
|
44
|
+
const code = content.charCodeAt(i);
|
|
45
|
+
if (code === 10 || code === 13) {
|
|
46
|
+
if (mathDisplayOpen) {
|
|
47
|
+
mathDisplayCrossedNewline = true;
|
|
48
|
+
}
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
if (code === 96) {
|
|
52
|
+
toggleToken("code");
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
if (code === 126 && i + 1 < content.length && content.charCodeAt(i + 1) === 126) {
|
|
56
|
+
toggleToken("strike");
|
|
57
|
+
i += 1;
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
if (code === 42) {
|
|
61
|
+
if (i + 1 < content.length && content.charCodeAt(i + 1) === 42) {
|
|
62
|
+
toggleToken("strong");
|
|
63
|
+
i += 1;
|
|
64
|
+
} else {
|
|
65
|
+
toggleToken("em");
|
|
66
|
+
}
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
if (enableMath && code === 36) {
|
|
70
|
+
if (i + 1 < content.length && content.charCodeAt(i + 1) === 36) {
|
|
71
|
+
toggleToken("math-display");
|
|
72
|
+
if (mathDisplayOpen) {
|
|
73
|
+
mathDisplayOpen = false;
|
|
74
|
+
mathDisplayCrossedNewline = false;
|
|
75
|
+
} else {
|
|
76
|
+
mathDisplayOpen = true;
|
|
77
|
+
mathDisplayCrossedNewline = false;
|
|
78
|
+
}
|
|
79
|
+
i += 1;
|
|
80
|
+
} else {
|
|
81
|
+
toggleToken("math-inline");
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
const hasIncompleteFormatting = stack.some((token) => token === "code" || token === "strike" || token === "strong" || token === "em");
|
|
86
|
+
const hasIncompleteMathInline = stack.includes("math-inline");
|
|
87
|
+
const hasIncompleteMathDisplay = stack.includes("math-display");
|
|
88
|
+
const hasIncompleteMath = hasIncompleteMathInline || hasIncompleteMathDisplay;
|
|
89
|
+
if (enableMath && hasIncompleteMath) {
|
|
90
|
+
if (hasIncompleteMathInline && !enableMathInlineAnticipation) {
|
|
91
|
+
return { kind: "raw", status: "raw", reason: "incomplete-math" };
|
|
92
|
+
}
|
|
93
|
+
if (hasIncompleteMathDisplay && (!enableMathBlockAnticipation || mathDisplayCrossedNewline)) {
|
|
94
|
+
return { kind: "raw", status: "raw", reason: "incomplete-math" };
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (hasIncompleteFormatting && !enableInlineAnticipation) {
|
|
98
|
+
return { kind: "raw", status: "raw", reason: "incomplete-formatting" };
|
|
99
|
+
}
|
|
100
|
+
if (!hasIncompleteFormatting && !hasIncompleteMath) {
|
|
101
|
+
return { kind: "parse", status: "complete", content, appended: "" };
|
|
102
|
+
}
|
|
103
|
+
const appendForToken = (token) => {
|
|
104
|
+
switch (token) {
|
|
105
|
+
case "code":
|
|
106
|
+
return "`";
|
|
107
|
+
case "strike":
|
|
108
|
+
return "~~";
|
|
109
|
+
case "strong":
|
|
110
|
+
return "**";
|
|
111
|
+
case "em":
|
|
112
|
+
return "*";
|
|
113
|
+
case "math-inline":
|
|
114
|
+
return "$";
|
|
115
|
+
case "math-display":
|
|
116
|
+
return "$$";
|
|
117
|
+
default:
|
|
118
|
+
return "";
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
const appended = stack.slice().reverse().map((token) => appendForToken(token)).join("");
|
|
122
|
+
return { kind: "parse", status: "anticipated", content: content + appended, appended };
|
|
123
|
+
}
|
|
124
|
+
export {
|
|
125
|
+
normalizeFormatAnticipation,
|
|
126
|
+
prepareInlineStreamingContent
|
|
127
|
+
};
|
package/dist/types.d.cts
CHANGED
|
@@ -39,6 +39,14 @@ interface MixedContentSegment {
|
|
|
39
39
|
status?: "pending" | "compiled" | "error";
|
|
40
40
|
error?: string;
|
|
41
41
|
}
|
|
42
|
+
type FormatAnticipationConfig = boolean | {
|
|
43
|
+
inline?: boolean;
|
|
44
|
+
mathInline?: boolean;
|
|
45
|
+
mathBlock?: boolean;
|
|
46
|
+
html?: boolean;
|
|
47
|
+
mdx?: boolean;
|
|
48
|
+
regex?: boolean;
|
|
49
|
+
};
|
|
42
50
|
interface InlineHtmlDescriptor {
|
|
43
51
|
tagName: string;
|
|
44
52
|
attributes: Record<string, string>;
|
|
@@ -114,6 +122,10 @@ type WorkerIn = {
|
|
|
114
122
|
mdx?: boolean;
|
|
115
123
|
tables?: boolean;
|
|
116
124
|
callouts?: boolean;
|
|
125
|
+
math?: boolean;
|
|
126
|
+
formatAnticipation?: FormatAnticipationConfig;
|
|
127
|
+
liveCodeHighlighting?: boolean;
|
|
128
|
+
mdxComponentNames?: string[];
|
|
117
129
|
};
|
|
118
130
|
mdx?: {
|
|
119
131
|
compileMode?: "server" | "worker";
|
|
@@ -179,6 +191,17 @@ interface RegexInlinePlugin extends InlinePlugin {
|
|
|
179
191
|
* the regex is skipped for that node.
|
|
180
192
|
*/
|
|
181
193
|
fastCheck?: (text: string) => boolean;
|
|
194
|
+
/**
|
|
195
|
+
* Optional streaming anticipation config. Only used when formatAnticipation.regex is enabled.
|
|
196
|
+
*/
|
|
197
|
+
anticipation?: RegexAnticipationPattern;
|
|
198
|
+
}
|
|
199
|
+
interface RegexAnticipationPattern {
|
|
200
|
+
start: RegExp;
|
|
201
|
+
end: RegExp;
|
|
202
|
+
full?: RegExp;
|
|
203
|
+
append: string | ((match: RegExpExecArray, content: string) => string);
|
|
204
|
+
maxScanChars?: number;
|
|
182
205
|
}
|
|
183
206
|
interface ASTInlinePlugin extends InlinePlugin {
|
|
184
207
|
visit: (node: InlineNode, ctx: {
|
|
@@ -311,4 +334,4 @@ interface CoalescingMetrics {
|
|
|
311
334
|
insertChildCoalesced: number;
|
|
312
335
|
}
|
|
313
336
|
|
|
314
|
-
export { type ASTInlinePlugin, type Block, type CoalescingMetrics, type CompiledMdxModule, type InlineHtmlDescriptor, type InlineNode, type InlinePlugin, LANGUAGE_ALIASES, type MixedContentSegment, type NodePath, type NodeSnapshot, PATCH_ROOT_ID, type Patch, type PatchMetrics, type PerformanceMetrics, type ProtectedRange, type ProtectedRangeKind, type RegexInlinePlugin, type SetPropsBatchEntry, type WorkerErrorPayload, type WorkerIn, type WorkerOut, type WorkerPhase };
|
|
337
|
+
export { type ASTInlinePlugin, type Block, type CoalescingMetrics, type CompiledMdxModule, type FormatAnticipationConfig, type InlineHtmlDescriptor, type InlineNode, type InlinePlugin, LANGUAGE_ALIASES, type MixedContentSegment, type NodePath, type NodeSnapshot, PATCH_ROOT_ID, type Patch, type PatchMetrics, type PerformanceMetrics, type ProtectedRange, type ProtectedRangeKind, type RegexAnticipationPattern, type RegexInlinePlugin, type SetPropsBatchEntry, type WorkerErrorPayload, type WorkerIn, type WorkerOut, type WorkerPhase };
|
package/dist/types.d.ts
CHANGED
|
@@ -39,6 +39,14 @@ interface MixedContentSegment {
|
|
|
39
39
|
status?: "pending" | "compiled" | "error";
|
|
40
40
|
error?: string;
|
|
41
41
|
}
|
|
42
|
+
type FormatAnticipationConfig = boolean | {
|
|
43
|
+
inline?: boolean;
|
|
44
|
+
mathInline?: boolean;
|
|
45
|
+
mathBlock?: boolean;
|
|
46
|
+
html?: boolean;
|
|
47
|
+
mdx?: boolean;
|
|
48
|
+
regex?: boolean;
|
|
49
|
+
};
|
|
42
50
|
interface InlineHtmlDescriptor {
|
|
43
51
|
tagName: string;
|
|
44
52
|
attributes: Record<string, string>;
|
|
@@ -114,6 +122,10 @@ type WorkerIn = {
|
|
|
114
122
|
mdx?: boolean;
|
|
115
123
|
tables?: boolean;
|
|
116
124
|
callouts?: boolean;
|
|
125
|
+
math?: boolean;
|
|
126
|
+
formatAnticipation?: FormatAnticipationConfig;
|
|
127
|
+
liveCodeHighlighting?: boolean;
|
|
128
|
+
mdxComponentNames?: string[];
|
|
117
129
|
};
|
|
118
130
|
mdx?: {
|
|
119
131
|
compileMode?: "server" | "worker";
|
|
@@ -179,6 +191,17 @@ interface RegexInlinePlugin extends InlinePlugin {
|
|
|
179
191
|
* the regex is skipped for that node.
|
|
180
192
|
*/
|
|
181
193
|
fastCheck?: (text: string) => boolean;
|
|
194
|
+
/**
|
|
195
|
+
* Optional streaming anticipation config. Only used when formatAnticipation.regex is enabled.
|
|
196
|
+
*/
|
|
197
|
+
anticipation?: RegexAnticipationPattern;
|
|
198
|
+
}
|
|
199
|
+
interface RegexAnticipationPattern {
|
|
200
|
+
start: RegExp;
|
|
201
|
+
end: RegExp;
|
|
202
|
+
full?: RegExp;
|
|
203
|
+
append: string | ((match: RegExpExecArray, content: string) => string);
|
|
204
|
+
maxScanChars?: number;
|
|
182
205
|
}
|
|
183
206
|
interface ASTInlinePlugin extends InlinePlugin {
|
|
184
207
|
visit: (node: InlineNode, ctx: {
|
|
@@ -311,4 +334,4 @@ interface CoalescingMetrics {
|
|
|
311
334
|
insertChildCoalesced: number;
|
|
312
335
|
}
|
|
313
336
|
|
|
314
|
-
export { type ASTInlinePlugin, type Block, type CoalescingMetrics, type CompiledMdxModule, type InlineHtmlDescriptor, type InlineNode, type InlinePlugin, LANGUAGE_ALIASES, type MixedContentSegment, type NodePath, type NodeSnapshot, PATCH_ROOT_ID, type Patch, type PatchMetrics, type PerformanceMetrics, type ProtectedRange, type ProtectedRangeKind, type RegexInlinePlugin, type SetPropsBatchEntry, type WorkerErrorPayload, type WorkerIn, type WorkerOut, type WorkerPhase };
|
|
337
|
+
export { type ASTInlinePlugin, type Block, type CoalescingMetrics, type CompiledMdxModule, type FormatAnticipationConfig, type InlineHtmlDescriptor, type InlineNode, type InlinePlugin, LANGUAGE_ALIASES, type MixedContentSegment, type NodePath, type NodeSnapshot, PATCH_ROOT_ID, type Patch, type PatchMetrics, type PerformanceMetrics, type ProtectedRange, type ProtectedRangeKind, type RegexAnticipationPattern, type RegexInlinePlugin, type SetPropsBatchEntry, type WorkerErrorPayload, type WorkerIn, type WorkerOut, type WorkerPhase };
|
|
@@ -37,9 +37,23 @@ var rehypeParse = __toESM(require("rehype-parse"), 1);
|
|
|
37
37
|
var rehypeSanitize = __toESM(require("rehype-sanitize"), 1);
|
|
38
38
|
var rehypeStringify = __toESM(require("rehype-stringify"), 1);
|
|
39
39
|
var import_unified = require("unified");
|
|
40
|
-
var
|
|
40
|
+
var rehypeSanitizeModule = rehypeSanitize;
|
|
41
|
+
var defaultSchema = rehypeSanitizeModule.defaultSchema;
|
|
42
|
+
var resolvePlugin = (mod) => {
|
|
43
|
+
if (typeof mod === "function") return mod;
|
|
44
|
+
if (mod && typeof mod.default === "function") {
|
|
45
|
+
return mod.default;
|
|
46
|
+
}
|
|
47
|
+
if (mod && typeof mod.default?.default === "function") {
|
|
48
|
+
return mod.default?.default;
|
|
49
|
+
}
|
|
50
|
+
return mod;
|
|
51
|
+
};
|
|
52
|
+
var rehypeParsePlugin = resolvePlugin(rehypeParse);
|
|
53
|
+
var rehypeSanitizePlugin = resolvePlugin(rehypeSanitizeModule);
|
|
54
|
+
var rehypeStringifyPlugin = resolvePlugin(rehypeStringify);
|
|
41
55
|
var SANITIZED_SCHEMA = createSchema();
|
|
42
|
-
var sanitizeProcessor = (0, import_unified.unified)().use(
|
|
56
|
+
var sanitizeProcessor = (0, import_unified.unified)().use(rehypeParsePlugin, { fragment: true }).use(rehypeSanitizePlugin, SANITIZED_SCHEMA).use(rehypeStringifyPlugin).freeze();
|
|
43
57
|
function sanitizeHtmlInWorker(html) {
|
|
44
58
|
if (!html) return "";
|
|
45
59
|
try {
|
|
@@ -3,9 +3,23 @@ import * as rehypeParse from "rehype-parse";
|
|
|
3
3
|
import * as rehypeSanitize from "rehype-sanitize";
|
|
4
4
|
import * as rehypeStringify from "rehype-stringify";
|
|
5
5
|
import { unified } from "unified";
|
|
6
|
-
var
|
|
6
|
+
var rehypeSanitizeModule = rehypeSanitize;
|
|
7
|
+
var defaultSchema = rehypeSanitizeModule.defaultSchema;
|
|
8
|
+
var resolvePlugin = (mod) => {
|
|
9
|
+
if (typeof mod === "function") return mod;
|
|
10
|
+
if (mod && typeof mod.default === "function") {
|
|
11
|
+
return mod.default;
|
|
12
|
+
}
|
|
13
|
+
if (mod && typeof mod.default?.default === "function") {
|
|
14
|
+
return mod.default?.default;
|
|
15
|
+
}
|
|
16
|
+
return mod;
|
|
17
|
+
};
|
|
18
|
+
var rehypeParsePlugin = resolvePlugin(rehypeParse);
|
|
19
|
+
var rehypeSanitizePlugin = resolvePlugin(rehypeSanitizeModule);
|
|
20
|
+
var rehypeStringifyPlugin = resolvePlugin(rehypeStringify);
|
|
7
21
|
var SANITIZED_SCHEMA = createSchema();
|
|
8
|
-
var sanitizeProcessor = unified().use(
|
|
22
|
+
var sanitizeProcessor = unified().use(rehypeParsePlugin, { fragment: true }).use(rehypeSanitizePlugin, SANITIZED_SCHEMA).use(rehypeStringifyPlugin).freeze();
|
|
9
23
|
function sanitizeHtmlInWorker(html) {
|
|
10
24
|
if (!html) return "";
|
|
11
25
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stream-mdx/core",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "Core types, snapshot utilities, and perf helpers for the Streaming Markdown V2 stack",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -75,6 +75,11 @@
|
|
|
75
75
|
"types": "./dist/streaming/custom-matcher.d.ts",
|
|
76
76
|
"import": "./dist/streaming/custom-matcher.mjs",
|
|
77
77
|
"require": "./dist/streaming/custom-matcher.cjs"
|
|
78
|
+
},
|
|
79
|
+
"./streaming/inline-streaming": {
|
|
80
|
+
"types": "./dist/streaming/inline-streaming.d.ts",
|
|
81
|
+
"import": "./dist/streaming/inline-streaming.mjs",
|
|
82
|
+
"require": "./dist/streaming/inline-streaming.cjs"
|
|
78
83
|
}
|
|
79
84
|
},
|
|
80
85
|
"files": [
|
|
@@ -85,7 +90,7 @@
|
|
|
85
90
|
"sideEffects": false,
|
|
86
91
|
"scripts": {
|
|
87
92
|
"build": "tsup",
|
|
88
|
-
"test": "tsx
|
|
93
|
+
"test": "tsx ../../scripts/run-tests.ts __tests__",
|
|
89
94
|
"clean": "rm -rf dist",
|
|
90
95
|
"prepack": "npm run build"
|
|
91
96
|
},
|