@ai-react-markdown/engine 2.5.0 → 2.5.2
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/index.cjs +65 -35
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +23 -1
- package/dist/index.d.ts +23 -1
- package/dist/index.dev.cjs +65 -35
- package/dist/index.dev.cjs.map +1 -1
- package/dist/index.dev.js +63 -35
- package/dist/index.dev.js.map +1 -1
- package/dist/index.js +63 -35
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -660,6 +660,7 @@ function processConfirmedLine(cp, ln, text) {
|
|
|
660
660
|
cp.openTotal += 1;
|
|
661
661
|
}
|
|
662
662
|
};
|
|
663
|
+
const strayTablePart = (tag) => TABLE_PART_NAMES.has(tag) && (cp.tagBalance.get("table") ?? 0) === 0;
|
|
663
664
|
const commentOpenAtLineStart = cp.commentOpen;
|
|
664
665
|
const rawOpenAtLineStart = cp.commentOpen || cp.piOpen || cp.declOpen || cp.cdataOpen || cp.bogusOpen;
|
|
665
666
|
if (cp.inFence) {
|
|
@@ -988,7 +989,7 @@ ${cont(scanText)}` };
|
|
|
988
989
|
if (cp.commentOpen) continue;
|
|
989
990
|
const closing = m[1] === "/";
|
|
990
991
|
const tag = m[2].toLowerCase();
|
|
991
|
-
if (
|
|
992
|
+
if (strayTablePart(tag)) cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start + m.index);
|
|
992
993
|
let attrs = m[3] ?? "";
|
|
993
994
|
if (cp.htmlFlowReal && (cp.rawTextOpen === null || closing && tag === cp.rawTextOpen)) {
|
|
994
995
|
const attrStart = m.index + 1 + (closing ? 1 : 0) + m[2].length;
|
|
@@ -1032,7 +1033,7 @@ ${cont(scanText)}` };
|
|
|
1032
1033
|
if (startMasked || wholeVisible || inRaw(mr.index) || cp.commentOpen) continue;
|
|
1033
1034
|
const closing = mr[1] === "/";
|
|
1034
1035
|
const tag = mr[2].toLowerCase();
|
|
1035
|
-
if (
|
|
1036
|
+
if (strayTablePart(tag)) cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start + mr.index);
|
|
1036
1037
|
if (closing && mr[3] !== void 0 && !/^\s*$/.test(mr[3])) continue;
|
|
1037
1038
|
const selfClosing = mr[3] !== void 0 && /\/\s*$/.test(mr[3]);
|
|
1038
1039
|
if (VOID_TAGS.has(tag) || selfClosing && honoursSelfClosing(tag)) continue;
|
|
@@ -1040,7 +1041,7 @@ ${cont(scanText)}` };
|
|
|
1040
1041
|
}
|
|
1041
1042
|
}
|
|
1042
1043
|
if (cp.pendingTruncatedTags.length > 0 && ln.text.includes(">")) {
|
|
1043
|
-
if (cp.pendingTruncatedTags.some((t) =>
|
|
1044
|
+
if (cp.pendingTruncatedTags.some((t) => strayTablePart(t))) {
|
|
1044
1045
|
cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start);
|
|
1045
1046
|
}
|
|
1046
1047
|
cp.pendingTruncatedTags = [];
|
|
@@ -1057,7 +1058,7 @@ ${cont(scanText)}` };
|
|
|
1057
1058
|
if (m2) {
|
|
1058
1059
|
const closing = m2[1] === "/";
|
|
1059
1060
|
const tag = m2[2].toLowerCase();
|
|
1060
|
-
if (
|
|
1061
|
+
if (strayTablePart(tag) && cp.htmlFlowReal) {
|
|
1061
1062
|
cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start + lastLt);
|
|
1062
1063
|
}
|
|
1063
1064
|
if (cp.htmlFlowReal) {
|
|
@@ -1107,6 +1108,15 @@ function isFootnoteSection(node) {
|
|
|
1107
1108
|
const props = node.properties;
|
|
1108
1109
|
return props?.dataFootnotes !== void 0;
|
|
1109
1110
|
}
|
|
1111
|
+
function isWhitespaceText(c) {
|
|
1112
|
+
return c.type === "text" && /^\s*$/.test(c.value);
|
|
1113
|
+
}
|
|
1114
|
+
function lastMeaningfulIdx(children) {
|
|
1115
|
+
for (let i = children.length - 1; i >= 0; i--) {
|
|
1116
|
+
if (!isWhitespaceText(children[i])) return i;
|
|
1117
|
+
}
|
|
1118
|
+
return -1;
|
|
1119
|
+
}
|
|
1110
1120
|
|
|
1111
1121
|
// src/components/incrementalParse/attributeHastChildren.ts
|
|
1112
1122
|
function attributeHastChildren(mdast, hast, stopAt = Infinity) {
|
|
@@ -1282,6 +1292,24 @@ function rebaseDualWalk(node, segments, maxEnd, offsetDelta, lineDelta) {
|
|
|
1282
1292
|
}
|
|
1283
1293
|
}
|
|
1284
1294
|
var TABLE_PART_TAG_RE = /<(?:td|th|tr|tbody|thead|tfoot|caption|col|colgroup)\b/i;
|
|
1295
|
+
var TABLE_TOKEN_RE = /<(\/?)(table|td|th|tr|tbody|thead|tfoot|caption|col|colgroup)\b/gi;
|
|
1296
|
+
function hasStrayTablePart(values) {
|
|
1297
|
+
let depth = 0;
|
|
1298
|
+
for (const value of values) {
|
|
1299
|
+
TABLE_TOKEN_RE.lastIndex = 0;
|
|
1300
|
+
let m;
|
|
1301
|
+
while ((m = TABLE_TOKEN_RE.exec(value)) !== null) {
|
|
1302
|
+
const closing = m[1] === "/";
|
|
1303
|
+
const tag = m[2].toLowerCase();
|
|
1304
|
+
if (tag === "table") {
|
|
1305
|
+
depth = closing ? Math.max(0, depth - 1) : depth + 1;
|
|
1306
|
+
continue;
|
|
1307
|
+
}
|
|
1308
|
+
if (depth === 0) return true;
|
|
1309
|
+
}
|
|
1310
|
+
}
|
|
1311
|
+
return false;
|
|
1312
|
+
}
|
|
1285
1313
|
var STRAY_SYNTHESIZED_END_TAG_RE = /<\/(?:br|p)\b/i;
|
|
1286
1314
|
function spliceTrees(input) {
|
|
1287
1315
|
const { prevMdast, prevHast, tailMdast, tailHast, content, boundary, injectionPrefix, injectedSegments } = input;
|
|
@@ -1339,7 +1367,7 @@ function spliceTrees(input) {
|
|
|
1339
1367
|
return !(start !== void 0 && start < injectedLen);
|
|
1340
1368
|
});
|
|
1341
1369
|
const tailWrapVisible = tailMdastChildren.some((child) => !isWrapInvisible(child));
|
|
1342
|
-
if (prefixMdast.
|
|
1370
|
+
if (hasStrayTablePart(prefixMdast.flatMap((c) => c.type === "html" ? [c.value] : []))) return null;
|
|
1343
1371
|
for (const child of tailMdastChildren) {
|
|
1344
1372
|
if (isWrapInvisible(child)) continue;
|
|
1345
1373
|
if (child.type !== "html") break;
|
|
@@ -1871,16 +1899,6 @@ function isBackrefAnchor(c) {
|
|
|
1871
1899
|
if (el.tagName !== "a") return false;
|
|
1872
1900
|
return Boolean(el.properties && "dataFootnoteBackref" in el.properties);
|
|
1873
1901
|
}
|
|
1874
|
-
function isWhitespaceText(c) {
|
|
1875
|
-
if (c.type !== "text") return false;
|
|
1876
|
-
return /^\s*$/.test(c.value);
|
|
1877
|
-
}
|
|
1878
|
-
function lastMeaningfulIdx(children) {
|
|
1879
|
-
for (let i = children.length - 1; i >= 0; i--) {
|
|
1880
|
-
if (!isWhitespaceText(children[i])) return i;
|
|
1881
|
-
}
|
|
1882
|
-
return -1;
|
|
1883
|
-
}
|
|
1884
1902
|
function dropTrailingBackrefs(children) {
|
|
1885
1903
|
let trailingWsStart = children.length;
|
|
1886
1904
|
while (trailingWsStart > 0 && isWhitespaceText(children[trailingWsStart - 1])) {
|
|
@@ -3997,6 +4015,14 @@ var graphemeEnds = (text, base) => {
|
|
|
3997
4015
|
}
|
|
3998
4016
|
return ends;
|
|
3999
4017
|
};
|
|
4018
|
+
var RESUME_LOOKBACK = 64;
|
|
4019
|
+
var isMidSurrogatePair = (text, at) => at > 0 && at < text.length && (text.charCodeAt(at - 1) & 64512) === 55296 && (text.charCodeAt(at) & 64512) === 56320;
|
|
4020
|
+
var RI_FIRST = 127462;
|
|
4021
|
+
var RI_LAST = 127487;
|
|
4022
|
+
var isRegionalIndicatorAt = (text, at) => {
|
|
4023
|
+
const cp = text.codePointAt(at);
|
|
4024
|
+
return cp !== void 0 && cp >= RI_FIRST && cp <= RI_LAST;
|
|
4025
|
+
};
|
|
4000
4026
|
var createSmoothStreamController = (options = {}) => {
|
|
4001
4027
|
const now = options.now ?? defaultNow;
|
|
4002
4028
|
const schedule = options.schedule ?? defaultSchedule;
|
|
@@ -4005,6 +4031,7 @@ var createSmoothStreamController = (options = {}) => {
|
|
|
4005
4031
|
let pending = [];
|
|
4006
4032
|
let tentativeEnd = 0;
|
|
4007
4033
|
let finished = false;
|
|
4034
|
+
let seam;
|
|
4008
4035
|
let drainDeadlineAt;
|
|
4009
4036
|
let initialized = false;
|
|
4010
4037
|
let visibleCache = "";
|
|
@@ -4088,8 +4115,19 @@ var createSmoothStreamController = (options = {}) => {
|
|
|
4088
4115
|
if (!disposed && !cancelFrame && pending.length > 0) cancelFrame = schedule(tick);
|
|
4089
4116
|
};
|
|
4090
4117
|
const resegmentTail = () => {
|
|
4118
|
+
if (seam !== void 0 && seam < source.length && pending[pending.length - 1] === seam) {
|
|
4119
|
+
pending.pop();
|
|
4120
|
+
}
|
|
4091
4121
|
const from = pending.length > 0 ? pending[pending.length - 1] : visibleEnd;
|
|
4092
|
-
|
|
4122
|
+
let anchor = from;
|
|
4123
|
+
if (seam !== void 0 && from <= seam) {
|
|
4124
|
+
anchor = Math.max(0, from - RESUME_LOOKBACK);
|
|
4125
|
+
if (isMidSurrogatePair(source, anchor)) anchor -= 1;
|
|
4126
|
+
while (anchor >= 2 && isRegionalIndicatorAt(source, anchor - 2)) anchor -= 2;
|
|
4127
|
+
} else {
|
|
4128
|
+
seam = void 0;
|
|
4129
|
+
}
|
|
4130
|
+
const ends = graphemeEnds(source.slice(anchor), anchor);
|
|
4093
4131
|
if (ends.length === 0) {
|
|
4094
4132
|
tentativeEnd = from;
|
|
4095
4133
|
return;
|
|
@@ -4101,7 +4139,7 @@ var createSmoothStreamController = (options = {}) => {
|
|
|
4101
4139
|
if (last >= 55296 && last <= 56319) hold = 2;
|
|
4102
4140
|
}
|
|
4103
4141
|
const confirmedEnds = finished ? ends : ends.slice(0, -hold);
|
|
4104
|
-
for (const end of confirmedEnds) pending.push(end);
|
|
4142
|
+
for (const end of confirmedEnds) if (end > from) pending.push(end);
|
|
4105
4143
|
};
|
|
4106
4144
|
const snap = (next) => {
|
|
4107
4145
|
disposed = false;
|
|
@@ -4115,6 +4153,7 @@ var createSmoothStreamController = (options = {}) => {
|
|
|
4115
4153
|
visibleEnd = next.length;
|
|
4116
4154
|
tentativeEnd = next.length;
|
|
4117
4155
|
pending = [];
|
|
4156
|
+
seam = next.length;
|
|
4118
4157
|
credit = 0;
|
|
4119
4158
|
cancelScheduled();
|
|
4120
4159
|
if (visibleCache !== next) notify();
|
|
@@ -4149,6 +4188,7 @@ var createSmoothStreamController = (options = {}) => {
|
|
|
4149
4188
|
if (tentativeEnd > (pending.length > 0 ? pending[pending.length - 1] : visibleEnd)) {
|
|
4150
4189
|
pending.push(tentativeEnd);
|
|
4151
4190
|
}
|
|
4191
|
+
seam = source.length;
|
|
4152
4192
|
ensureScheduled();
|
|
4153
4193
|
},
|
|
4154
4194
|
snap,
|
|
@@ -4525,21 +4565,7 @@ function convertSingleToDoubleDollar(text) {
|
|
|
4525
4565
|
}
|
|
4526
4566
|
function preprocessLaTeX(str) {
|
|
4527
4567
|
if (!hasLatexTrigger(str)) return str;
|
|
4528
|
-
|
|
4529
|
-
const result = segments.map((segment) => {
|
|
4530
|
-
if (segment.isCode) return segment.text;
|
|
4531
|
-
let text = segment.text;
|
|
4532
|
-
text = escapeMhchemCommands(text);
|
|
4533
|
-
text = escapeCurrencyDollarSigns(text);
|
|
4534
|
-
text = convertLatexDelimiters(text);
|
|
4535
|
-
text = escapeLatexPipes(text);
|
|
4536
|
-
text = escapeLatexPipesInUnclosed(text);
|
|
4537
|
-
text = escapeTextUnderscores(text);
|
|
4538
|
-
text = convertSingleToDoubleDollar(text);
|
|
4539
|
-
text = truncateUnclosedLatexBlock(text);
|
|
4540
|
-
return text;
|
|
4541
|
-
});
|
|
4542
|
-
return result.join("");
|
|
4568
|
+
return processSlice(str, false).out;
|
|
4543
4569
|
}
|
|
4544
4570
|
function hasLatexTrigger(str) {
|
|
4545
4571
|
return str.includes("$") || str.includes("\\[") || str.includes("\\(");
|
|
@@ -4568,7 +4594,7 @@ function hasUnclosedTextCommand(text) {
|
|
|
4568
4594
|
}
|
|
4569
4595
|
var RESIDUAL_OPEN_BRACKET_RE = /(?<!!)\\\[/;
|
|
4570
4596
|
var LEADING_DOUBLE_DOLLAR_RE = /^\s*\$\$/;
|
|
4571
|
-
function
|
|
4597
|
+
function processSlice(slice, probe = true) {
|
|
4572
4598
|
const segments = splitByProtectedRegions(slice);
|
|
4573
4599
|
const parts = [];
|
|
4574
4600
|
let quiescent = true;
|
|
@@ -4692,13 +4718,13 @@ function createIncrementalLatexPreprocessor(options) {
|
|
|
4692
4718
|
};
|
|
4693
4719
|
const cut = findRawSafeCut(active);
|
|
4694
4720
|
if (cut > 0) {
|
|
4695
|
-
const candidate =
|
|
4721
|
+
const candidate = processSlice(active.slice(0, cut));
|
|
4696
4722
|
if (candidate.quiescent) freeze(cut, candidate);
|
|
4697
4723
|
}
|
|
4698
4724
|
nextAttemptLen = advanced || !backoff ? 0 : active.length * 2;
|
|
4699
4725
|
onAttempt?.({ activeLength, frozenBytes });
|
|
4700
4726
|
}
|
|
4701
|
-
const tail =
|
|
4727
|
+
const tail = processSlice(active, false);
|
|
4702
4728
|
const head = tail.truncatedAtSeamStart ? frozenOut.replace(/\s+$/, "") : frozenOut;
|
|
4703
4729
|
const out = head + tail.out;
|
|
4704
4730
|
prevSource = source;
|
|
@@ -4762,6 +4788,8 @@ export {
|
|
|
4762
4788
|
hasLoneSurrogate,
|
|
4763
4789
|
highlight,
|
|
4764
4790
|
isFootnoteSection,
|
|
4791
|
+
isWhitespaceText,
|
|
4792
|
+
lastMeaningfulIdx,
|
|
4765
4793
|
measureStage,
|
|
4766
4794
|
mergeClassNameAllowlist,
|
|
4767
4795
|
normalizeForMatch,
|