@ai-matrx/content-ir 0.19.1 → 0.19.3

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/source.cjs CHANGED
@@ -747,6 +747,7 @@ var IDENTIFIER = /^[A-Za-z_][A-Za-z0-9_]*$/;
747
747
  var MATH_SUFFIX = /^(?:s|es|th|st|nd|rd)$/i;
748
748
  function isVariableChain(content, after) {
749
749
  if (/^\{[A-Za-z_][\w.]*\}$/.test(content)) return true;
750
+ if (/^\(\(.*\)\)$/.test(content) || /^_[.[]/.test(content)) return true;
750
751
  if (!after) return false;
751
752
  if (after[0] === "{") return IDENTIFIER.test(content);
752
753
  const run = /^[A-Za-z0-9_]+/.exec(after)?.[0];
@@ -1318,6 +1319,16 @@ var Tokenizer = class {
1318
1319
  holdUndecidedTail() {
1319
1320
  const last = this.lineStarts.length - 1;
1320
1321
  if (last < 0) return;
1322
+ if (this.provisionalFrom < this.n) {
1323
+ for (let b = 0; b < this.blocks.length; b++) {
1324
+ const block = this.blocks[b];
1325
+ if (block.end <= this.provisionalFrom) continue;
1326
+ if (block.kind === "prose") block.inlines = block.inlines.filter((inline) => inline.end <= this.provisionalFrom);
1327
+ else if (block.island?.fromParagraph && block.start < this.provisionalFrom) {
1328
+ this.blocks[b] = { kind: "prose", start: block.start, end: block.end, island: null, inlines: [] };
1329
+ }
1330
+ }
1331
+ }
1321
1332
  if (this.isOpenTail(last)) {
1322
1333
  let b = this.blocks.length - 1;
1323
1334
  while (b >= 0 && this.blocks[b].kind === "gap") b--;
@@ -1615,6 +1626,9 @@ var Tokenizer = class {
1615
1626
  }
1616
1627
  if (this.isOpenTail(k)) return this.heldFootnote(p, open[1]);
1617
1628
  if (FOOTNOTE_DEF.test(line.trimStart())) break;
1629
+ if (this.streaming && TREE_GLYPHS.test(line) && this.connectorRunReachesEnd(k)) {
1630
+ return this.heldFootnote(p, open[1]);
1631
+ }
1618
1632
  const block = this.detectBlock(this.lineStarts[k], k, false);
1619
1633
  if (block && this.mayDissolve(block)) return this.heldFootnote(p, open[1]);
1620
1634
  if (block) break;
@@ -1622,8 +1636,22 @@ var Tokenizer = class {
1622
1636
  }
1623
1637
  const end = this.contentEnds[last];
1624
1638
  if (this.paragraphMayGrow(end)) return this.heldFootnote(p, open[1]);
1639
+ if (this.streaming && end > this.provisionalFrom) return this.heldFootnote(p, open[1]);
1625
1640
  return this.island("footnote_def", p, end, true, { id: open[1] });
1626
1641
  }
1642
+ /** Every line from `k` to the end is a connector line or blank (a tree may still form there). */
1643
+ connectorRunReachesEnd(k) {
1644
+ if (this.lastNonConnectorLine === void 0) {
1645
+ let j = this.lineCount - 1;
1646
+ for (; j >= 0; j--) {
1647
+ this.tick(1);
1648
+ if (!this.lineIsBlank(j) && !TREE_GLYPHS.test(this.lineText(j))) break;
1649
+ }
1650
+ this.lastNonConnectorLine = j;
1651
+ }
1652
+ return k > this.lastNonConnectorLine;
1653
+ }
1654
+ lastNonConnectorLine = void 0;
1627
1655
  /** A footnote whose continuation is still arriving: open to the end of the text. */
1628
1656
  heldFootnote(p, id) {
1629
1657
  return this.island("footnote_def", p, this.n, false, { id });
@@ -1888,7 +1916,6 @@ var Tokenizer = class {
1888
1916
  if (isRecognizedJsonHead(this.text.slice(tp, tp + 512))) {
1889
1917
  return this.island("json", p, this.n, false, jsonMeta(this.text.slice(tp)));
1890
1918
  }
1891
- this.provisionalFrom = Math.min(this.provisionalFrom, p);
1892
1919
  return null;
1893
1920
  }
1894
1921
  if (net !== 0) return null;
@@ -2559,6 +2586,76 @@ function mapRange(changes, start, end, unit = "utf16") {
2559
2586
  return { start: newStart, end: newEnd, touched, collapsed: newEnd === newStart && end > start };
2560
2587
  }
2561
2588
 
2589
+ // source/gfm-table.ts
2590
+ function splitRowSegments(line) {
2591
+ const segments = [];
2592
+ let start = 0;
2593
+ for (let i = 0; i < line.length; i += 1) {
2594
+ const ch = line[i];
2595
+ if (ch === "\\") {
2596
+ i += 1;
2597
+ continue;
2598
+ }
2599
+ if (ch === "|") {
2600
+ segments.push(line.slice(start, i));
2601
+ start = i + 1;
2602
+ }
2603
+ }
2604
+ segments.push(line.slice(start));
2605
+ return segments;
2606
+ }
2607
+ function rowCells(line) {
2608
+ const cells = splitRowSegments(line).map((cell) => cell.trim());
2609
+ if (cells.length > 1 && cells[0] === "") cells.shift();
2610
+ if (cells.length > 1 && cells[cells.length - 1] === "") cells.pop();
2611
+ else if (cells.length === 1 && cells[0] === "") cells.pop();
2612
+ return cells;
2613
+ }
2614
+ function unescapeCellPipes(cell) {
2615
+ return cell.replace(/\\\|/g, "|");
2616
+ }
2617
+ var BLOCK_START = /^(?:[-+*](?:\s|$)|\d{1,9}[.)](?:\s|$)|>|#{1,6}(?:\s|$)|```|~~~|(?:-\s*){3,}$|(?:\*\s*){3,}$|(?:_\s*){3,}$)/;
2618
+ var DELIMITER_CELL = /^:?-+:?$/;
2619
+ function isGfmDelimiterRow(line) {
2620
+ const trimmed = line.trim();
2621
+ if (!trimmed.includes("|")) return false;
2622
+ const cells = rowCells(trimmed);
2623
+ return cells.length > 0 && cells.every((cell) => DELIMITER_CELL.test(cell));
2624
+ }
2625
+ function isPipeLedRow(line) {
2626
+ const trimmed = line.trim();
2627
+ return trimmed.startsWith("|") && trimmed.includes("|", 1);
2628
+ }
2629
+ function startsPipelessTable(header, delimiter) {
2630
+ const head = header.trim();
2631
+ if (!head || head.startsWith("|") || BLOCK_START.test(head)) return false;
2632
+ if (splitRowSegments(head).length < 2) return false;
2633
+ if (delimiter === void 0 || !isGfmDelimiterRow(delimiter)) return false;
2634
+ return rowCells(head).length === rowCells(delimiter.trim()).length;
2635
+ }
2636
+ function continuesTable(line) {
2637
+ const trimmed = line.trim();
2638
+ if (!trimmed) return false;
2639
+ if (trimmed.startsWith("|")) return trimmed.includes("|", 1);
2640
+ return splitRowSegments(trimmed).length > 1 && !BLOCK_START.test(trimmed);
2641
+ }
2642
+ function opensTable(lines, index) {
2643
+ const line = lines[index] ?? "";
2644
+ return isPipeLedRow(line) || startsPipelessTable(line, lines[index + 1]);
2645
+ }
2646
+ function tableStartsAt(lines, index) {
2647
+ return opensTable(lines, index) && isGfmDelimiterRow(lines[index + 1] ?? "");
2648
+ }
2649
+ function findTableStart(lines, from = 0) {
2650
+ for (let i = Math.max(0, from); i < lines.length; i += 1) if (opensTable(lines, i)) return i;
2651
+ return -1;
2652
+ }
2653
+ function findTableEnd(lines, start) {
2654
+ let end = Math.min(lines.length, start + 2);
2655
+ while (end < lines.length && continuesTable(lines[end] ?? "")) end += 1;
2656
+ return end;
2657
+ }
2658
+
2562
2659
  exports.AFTER_WINDOW = AFTER_WINDOW;
2563
2660
  exports.BacktickRuns = BacktickRuns;
2564
2661
  exports.CALLOUT_NAMES = CALLOUT_NAMES;
@@ -2575,13 +2672,18 @@ exports.buildCodePointIndex = buildCodePointIndex;
2575
2672
  exports.classifyInnerFenceLine = classifyInnerFenceLine;
2576
2673
  exports.closeFence = closeFence;
2577
2674
  exports.codeSpanText = codeSpanText;
2675
+ exports.continuesTable = continuesTable;
2578
2676
  exports.fenceLineKinds = fenceLineKinds;
2579
2677
  exports.fenceNestsInnerFences = fenceNestsInnerFences;
2580
2678
  exports.fenceOpenerOf = fenceOpenerOf;
2581
2679
  exports.fenceParts = fenceParts;
2582
2680
  exports.findCodeRanges = findCodeRanges;
2681
+ exports.findTableEnd = findTableEnd;
2682
+ exports.findTableStart = findTableStart;
2583
2683
  exports.isEscapedBracketMath = isEscapedBracketMath;
2684
+ exports.isGfmDelimiterRow = isGfmDelimiterRow;
2584
2685
  exports.isMathPlaceholder = isMathPlaceholder;
2686
+ exports.isPipeLedRow = isPipeLedRow;
2585
2687
  exports.isSingleDollarMath = isSingleDollarMath;
2586
2688
  exports.islandEdit = islandEdit;
2587
2689
  exports.joinSource = joinSource;
@@ -2591,17 +2693,23 @@ exports.looksLikeOpenInlineMath = looksLikeOpenInlineMath;
2591
2693
  exports.mapCodeRanges = mapCodeRanges;
2592
2694
  exports.mapPosition = mapPosition;
2593
2695
  exports.mapRange = mapRange;
2696
+ exports.opensTable = opensTable;
2594
2697
  exports.pairDisplayMath = pairDisplayMath;
2595
2698
  exports.parseFenceOpener = parseFenceOpener;
2596
2699
  exports.pendingDisplayMathOpener = pendingDisplayMathOpener;
2597
2700
  exports.readXmlTag = readXmlTag;
2701
+ exports.rowCells = rowCells;
2598
2702
  exports.singleDollarAfter = singleDollarAfter;
2599
2703
  exports.singleDollarMathEnd = singleDollarMathEnd;
2600
2704
  exports.spliceSave = spliceSave;
2705
+ exports.splitRowSegments = splitRowSegments;
2601
2706
  exports.splitsSurrogatePair = splitsSurrogatePair;
2707
+ exports.startsPipelessTable = startsPipelessTable;
2708
+ exports.tableStartsAt = tableStartsAt;
2602
2709
  exports.toCodePointOffset = toCodePointOffset;
2603
2710
  exports.toUtf16Offset = toUtf16Offset;
2604
2711
  exports.tokenizeSource = tokenizeSource;
2605
2712
  exports.trimFenceLine = trimFenceLine;
2713
+ exports.unescapeCellPipes = unescapeCellPipes;
2606
2714
  //# sourceMappingURL=source.cjs.map
2607
2715
  //# sourceMappingURL=source.cjs.map