@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.dev.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 (TABLE_PART_NAMES.has(tag)) cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start + m.index);
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 (TABLE_PART_NAMES.has(tag)) cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start + mr.index);
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) => TABLE_PART_NAMES.has(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 (TABLE_PART_NAMES.has(tag) && cp.htmlFlowReal) {
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.some((c) => c.type === "html" && TABLE_PART_TAG_RE.test(c.value))) return null;
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])) {
@@ -4009,6 +4027,14 @@ var graphemeEnds = (text, base) => {
4009
4027
  }
4010
4028
  return ends;
4011
4029
  };
4030
+ var RESUME_LOOKBACK = 64;
4031
+ var isMidSurrogatePair = (text, at) => at > 0 && at < text.length && (text.charCodeAt(at - 1) & 64512) === 55296 && (text.charCodeAt(at) & 64512) === 56320;
4032
+ var RI_FIRST = 127462;
4033
+ var RI_LAST = 127487;
4034
+ var isRegionalIndicatorAt = (text, at) => {
4035
+ const cp = text.codePointAt(at);
4036
+ return cp !== void 0 && cp >= RI_FIRST && cp <= RI_LAST;
4037
+ };
4012
4038
  var createSmoothStreamController = (options = {}) => {
4013
4039
  const now = options.now ?? defaultNow;
4014
4040
  const schedule = options.schedule ?? defaultSchedule;
@@ -4017,6 +4043,7 @@ var createSmoothStreamController = (options = {}) => {
4017
4043
  let pending = [];
4018
4044
  let tentativeEnd = 0;
4019
4045
  let finished = false;
4046
+ let seam;
4020
4047
  let drainDeadlineAt;
4021
4048
  let initialized = false;
4022
4049
  let visibleCache = "";
@@ -4100,8 +4127,19 @@ var createSmoothStreamController = (options = {}) => {
4100
4127
  if (!disposed && !cancelFrame && pending.length > 0) cancelFrame = schedule(tick);
4101
4128
  };
4102
4129
  const resegmentTail = () => {
4130
+ if (seam !== void 0 && seam < source.length && pending[pending.length - 1] === seam) {
4131
+ pending.pop();
4132
+ }
4103
4133
  const from = pending.length > 0 ? pending[pending.length - 1] : visibleEnd;
4104
- const ends = graphemeEnds(source.slice(from), from);
4134
+ let anchor = from;
4135
+ if (seam !== void 0 && from <= seam) {
4136
+ anchor = Math.max(0, from - RESUME_LOOKBACK);
4137
+ if (isMidSurrogatePair(source, anchor)) anchor -= 1;
4138
+ while (anchor >= 2 && isRegionalIndicatorAt(source, anchor - 2)) anchor -= 2;
4139
+ } else {
4140
+ seam = void 0;
4141
+ }
4142
+ const ends = graphemeEnds(source.slice(anchor), anchor);
4105
4143
  if (ends.length === 0) {
4106
4144
  tentativeEnd = from;
4107
4145
  return;
@@ -4113,7 +4151,7 @@ var createSmoothStreamController = (options = {}) => {
4113
4151
  if (last >= 55296 && last <= 56319) hold = 2;
4114
4152
  }
4115
4153
  const confirmedEnds = finished ? ends : ends.slice(0, -hold);
4116
- for (const end of confirmedEnds) pending.push(end);
4154
+ for (const end of confirmedEnds) if (end > from) pending.push(end);
4117
4155
  };
4118
4156
  const snap = (next) => {
4119
4157
  disposed = false;
@@ -4127,6 +4165,7 @@ var createSmoothStreamController = (options = {}) => {
4127
4165
  visibleEnd = next.length;
4128
4166
  tentativeEnd = next.length;
4129
4167
  pending = [];
4168
+ seam = next.length;
4130
4169
  credit = 0;
4131
4170
  cancelScheduled();
4132
4171
  if (visibleCache !== next) notify();
@@ -4161,6 +4200,7 @@ var createSmoothStreamController = (options = {}) => {
4161
4200
  if (tentativeEnd > (pending.length > 0 ? pending[pending.length - 1] : visibleEnd)) {
4162
4201
  pending.push(tentativeEnd);
4163
4202
  }
4203
+ seam = source.length;
4164
4204
  ensureScheduled();
4165
4205
  },
4166
4206
  snap,
@@ -4537,21 +4577,7 @@ function convertSingleToDoubleDollar(text) {
4537
4577
  }
4538
4578
  function preprocessLaTeX(str) {
4539
4579
  if (!hasLatexTrigger(str)) return str;
4540
- const segments = splitByProtectedRegions(str);
4541
- const result = segments.map((segment) => {
4542
- if (segment.isCode) return segment.text;
4543
- let text = segment.text;
4544
- text = escapeMhchemCommands(text);
4545
- text = escapeCurrencyDollarSigns(text);
4546
- text = convertLatexDelimiters(text);
4547
- text = escapeLatexPipes(text);
4548
- text = escapeLatexPipesInUnclosed(text);
4549
- text = escapeTextUnderscores(text);
4550
- text = convertSingleToDoubleDollar(text);
4551
- text = truncateUnclosedLatexBlock(text);
4552
- return text;
4553
- });
4554
- return result.join("");
4580
+ return processSlice(str, false).out;
4555
4581
  }
4556
4582
  function hasLatexTrigger(str) {
4557
4583
  return str.includes("$") || str.includes("\\[") || str.includes("\\(");
@@ -4580,7 +4606,7 @@ function hasUnclosedTextCommand(text) {
4580
4606
  }
4581
4607
  var RESIDUAL_OPEN_BRACKET_RE = /(?<!!)\\\[/;
4582
4608
  var LEADING_DOUBLE_DOLLAR_RE = /^\s*\$\$/;
4583
- function processSliceInstrumented(slice, probe = true) {
4609
+ function processSlice(slice, probe = true) {
4584
4610
  const segments = splitByProtectedRegions(slice);
4585
4611
  const parts = [];
4586
4612
  let quiescent = true;
@@ -4704,13 +4730,13 @@ function createIncrementalLatexPreprocessor(options) {
4704
4730
  };
4705
4731
  const cut = findRawSafeCut(active);
4706
4732
  if (cut > 0) {
4707
- const candidate = processSliceInstrumented(active.slice(0, cut));
4733
+ const candidate = processSlice(active.slice(0, cut));
4708
4734
  if (candidate.quiescent) freeze(cut, candidate);
4709
4735
  }
4710
4736
  nextAttemptLen = advanced || !backoff ? 0 : active.length * 2;
4711
4737
  onAttempt?.({ activeLength, frozenBytes });
4712
4738
  }
4713
- const tail = processSliceInstrumented(active, false);
4739
+ const tail = processSlice(active, false);
4714
4740
  const head = tail.truncatedAtSeamStart ? frozenOut.replace(/\s+$/, "") : frozenOut;
4715
4741
  const out = head + tail.out;
4716
4742
  prevSource = source;
@@ -4774,6 +4800,8 @@ export {
4774
4800
  hasLoneSurrogate,
4775
4801
  highlight,
4776
4802
  isFootnoteSection,
4803
+ isWhitespaceText,
4804
+ lastMeaningfulIdx,
4777
4805
  measureStage,
4778
4806
  mergeClassNameAllowlist,
4779
4807
  normalizeForMatch,