@ai-matrx/content-ir 0.19.0 → 0.19.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/source.cjs CHANGED
@@ -588,7 +588,7 @@ function pendingCodeSpanStart(text) {
588
588
  const n = text.length;
589
589
  if (n === 0 || /\n[ \t]*\n[ \t]*$/.test(text)) return -1;
590
590
  const lastLine = text.slice(text.lastIndexOf("\n") + 1);
591
- if (lastLine && /^(?: {0,3}>[ \t]?)*[ \t]*$/.test(lastLine)) return pendingCodeSpanStart(`${text}x`);
591
+ if (lastLine && /^(?: {0,3}>[ \t]?)*[ \t\r]*$/.test(lastLine)) return pendingCodeSpanStart(`${text}x`);
592
592
  const s = scan(text);
593
593
  const para = s.pendingPara;
594
594
  if (s.endsInFence || para === -1) return -1;
@@ -752,7 +752,7 @@ function isVariableChain(content, after) {
752
752
  const run = /^[A-Za-z0-9_]+/.exec(after)?.[0];
753
753
  if (!run) return false;
754
754
  if (after.length === 1) return false;
755
- if (/^[A-Za-z_][A-Za-z0-9_]*[.@-]$/.test(content)) return true;
755
+ if (/^[A-Za-z_][A-Za-z0-9_]*(?:[.@-]|->|::)$/.test(content)) return true;
756
756
  return IDENTIFIER.test(content) && !MATH_SUFFIX.test(run);
757
757
  }
758
758
  var FUNCTION_NAMES = /* @__PURE__ */ new Set([
@@ -1157,7 +1157,7 @@ var Tokenizer = class {
1157
1157
  if (close >= span) this.provisionalFrom = Math.min(this.provisionalFrom, open);
1158
1158
  }
1159
1159
  }
1160
- for (const pad of ["`", "``", "```", "~~~"]) {
1160
+ for (const pad of ["`", "``", "```", "~~~", "$"]) {
1161
1161
  const alt = pairDisplayMath(text + pad);
1162
1162
  for (const [open, close] of this.mathPairs) {
1163
1163
  if (alt.get(open) !== close) this.provisionalFrom = Math.min(this.provisionalFrom, open);
@@ -1189,19 +1189,6 @@ var Tokenizer = class {
1189
1189
  provisionalFrom = Number.POSITIVE_INFINITY;
1190
1190
  /** Streaming: the text ends in a lone CR whose LF has not arrived yet. */
1191
1191
  pendingCR = false;
1192
- /**
1193
- * Streaming: an open last line that begins with `{` is undecided — each new
1194
- * byte can balance or unbalance its braces and flip the whole line between
1195
- * prose and a JSON island — so it is provisional until it ends (G5).
1196
- * (A lone HTML tag on that line is held by {@link holdUndecidedTail}.)
1197
- */
1198
- markOpenJsonTail() {
1199
- const last = this.lineStarts.length - 1;
1200
- if (!this.isOpenTail(last)) return;
1201
- if (this.lineText(last).trim().startsWith("{")) {
1202
- this.provisionalFrom = Math.min(this.provisionalFrom, this.lineStarts[last]);
1203
- }
1204
- }
1205
1192
  /**
1206
1193
  * `text.indexOf(needle, from)` in O(log k): the first query for a needle
1207
1194
  * indexes all of its occurrences once, so repeated searches for a closer
@@ -1236,7 +1223,7 @@ var Tokenizer = class {
1236
1223
  const rest = this.n - pe;
1237
1224
  if (rest === 0) return true;
1238
1225
  const tail = this.text.slice(pe);
1239
- return /^(?:\r\n|\r|\n)[ \t]*$/.test(tail);
1226
+ return /^(?:\r\n|\r|\n)[ \t\r]*$/.test(tail);
1240
1227
  }
1241
1228
  /**
1242
1229
  * Streaming: an open block that may still turn back into prose — a `$$`
@@ -1245,7 +1232,9 @@ var Tokenizer = class {
1245
1232
  * or any opener that is itself still arriving on the open last line.
1246
1233
  */
1247
1234
  mayDissolve(block) {
1248
- if (!this.streaming || block.complete) return false;
1235
+ if (!this.streaming) return false;
1236
+ if (block.start >= this.provisionalFrom) return true;
1237
+ if (block.complete) return false;
1249
1238
  if (block.type === "math_block" || block.type === "json") return true;
1250
1239
  return this.isOpenTail(this.lineOf(block.start));
1251
1240
  }
@@ -1284,7 +1273,6 @@ var Tokenizer = class {
1284
1273
  return this.text.slice(this.lineStarts[li], this.contentEnds[li]);
1285
1274
  }
1286
1275
  run() {
1287
- if (this.streaming) this.markOpenJsonTail();
1288
1276
  let pos = 0;
1289
1277
  while (pos < this.n) {
1290
1278
  const li = this.lineOf(pos);
@@ -1522,7 +1510,7 @@ var Tokenizer = class {
1522
1510
  return { type, start, end, complete, meta };
1523
1511
  }
1524
1512
  frontMatter(li, t) {
1525
- const fence = this.lineText(li);
1513
+ const fence = this.lineText(li).replace(/^\uFEFF/, "");
1526
1514
  if (fence !== "---" && fence !== "+++" || t !== fence) return null;
1527
1515
  const toml = fence === "+++";
1528
1516
  let sawContent = false;
@@ -1533,9 +1521,13 @@ var Tokenizer = class {
1533
1521
  }
1534
1522
  if (!NOT_WHITESPACE.test(line)) continue;
1535
1523
  const shaped = toml ? /^\s*(?:[A-Za-z0-9_."-]+\s*=|\[|#)/.test(line) : /^(?:[A-Za-z0-9_"'-][^:]*:(?:\s|$)|\s+\S|-\s|#)/.test(line);
1536
- if (!shaped) return null;
1524
+ if (!shaped) {
1525
+ if (this.isOpenTail(k)) break;
1526
+ return null;
1527
+ }
1537
1528
  sawContent = true;
1538
1529
  }
1530
+ if (this.streaming) return this.island("front_matter", 0, this.n, false, { format: toml ? "toml" : "yaml" });
1539
1531
  return null;
1540
1532
  }
1541
1533
  /**
@@ -1936,7 +1928,7 @@ var Tokenizer = class {
1936
1928
  const block = this.detectBlock(this.lineStarts[k], k, false);
1937
1929
  if (block) {
1938
1930
  breakLine = k;
1939
- if (this.mayDissolve(block) || this.streaming && block.start >= this.provisionalFrom) {
1931
+ if (this.mayDissolve(block)) {
1940
1932
  this.undecidedBreaks.add(end);
1941
1933
  }
1942
1934
  break;
@@ -2567,6 +2559,76 @@ function mapRange(changes, start, end, unit = "utf16") {
2567
2559
  return { start: newStart, end: newEnd, touched, collapsed: newEnd === newStart && end > start };
2568
2560
  }
2569
2561
 
2562
+ // source/gfm-table.ts
2563
+ function splitRowSegments(line) {
2564
+ const segments = [];
2565
+ let start = 0;
2566
+ for (let i = 0; i < line.length; i += 1) {
2567
+ const ch = line[i];
2568
+ if (ch === "\\") {
2569
+ i += 1;
2570
+ continue;
2571
+ }
2572
+ if (ch === "|") {
2573
+ segments.push(line.slice(start, i));
2574
+ start = i + 1;
2575
+ }
2576
+ }
2577
+ segments.push(line.slice(start));
2578
+ return segments;
2579
+ }
2580
+ function rowCells(line) {
2581
+ const cells = splitRowSegments(line).map((cell) => cell.trim());
2582
+ if (cells.length > 1 && cells[0] === "") cells.shift();
2583
+ if (cells.length > 1 && cells[cells.length - 1] === "") cells.pop();
2584
+ else if (cells.length === 1 && cells[0] === "") cells.pop();
2585
+ return cells;
2586
+ }
2587
+ function unescapeCellPipes(cell) {
2588
+ return cell.replace(/\\\|/g, "|");
2589
+ }
2590
+ var BLOCK_START = /^(?:[-+*](?:\s|$)|\d{1,9}[.)](?:\s|$)|>|#{1,6}(?:\s|$)|```|~~~|(?:-\s*){3,}$|(?:\*\s*){3,}$|(?:_\s*){3,}$)/;
2591
+ var DELIMITER_CELL = /^:?-+:?$/;
2592
+ function isGfmDelimiterRow(line) {
2593
+ const trimmed = line.trim();
2594
+ if (!trimmed.includes("|")) return false;
2595
+ const cells = rowCells(trimmed);
2596
+ return cells.length > 0 && cells.every((cell) => DELIMITER_CELL.test(cell));
2597
+ }
2598
+ function isPipeLedRow(line) {
2599
+ const trimmed = line.trim();
2600
+ return trimmed.startsWith("|") && trimmed.includes("|", 1);
2601
+ }
2602
+ function startsPipelessTable(header, delimiter) {
2603
+ const head = header.trim();
2604
+ if (!head || head.startsWith("|") || BLOCK_START.test(head)) return false;
2605
+ if (splitRowSegments(head).length < 2) return false;
2606
+ if (delimiter === void 0 || !isGfmDelimiterRow(delimiter)) return false;
2607
+ return rowCells(head).length === rowCells(delimiter.trim()).length;
2608
+ }
2609
+ function continuesTable(line) {
2610
+ const trimmed = line.trim();
2611
+ if (!trimmed) return false;
2612
+ if (trimmed.startsWith("|")) return trimmed.includes("|", 1);
2613
+ return splitRowSegments(trimmed).length > 1 && !BLOCK_START.test(trimmed);
2614
+ }
2615
+ function opensTable(lines, index) {
2616
+ const line = lines[index] ?? "";
2617
+ return isPipeLedRow(line) || startsPipelessTable(line, lines[index + 1]);
2618
+ }
2619
+ function tableStartsAt(lines, index) {
2620
+ return opensTable(lines, index) && isGfmDelimiterRow(lines[index + 1] ?? "");
2621
+ }
2622
+ function findTableStart(lines, from = 0) {
2623
+ for (let i = Math.max(0, from); i < lines.length; i += 1) if (opensTable(lines, i)) return i;
2624
+ return -1;
2625
+ }
2626
+ function findTableEnd(lines, start) {
2627
+ let end = Math.min(lines.length, start + 2);
2628
+ while (end < lines.length && continuesTable(lines[end] ?? "")) end += 1;
2629
+ return end;
2630
+ }
2631
+
2570
2632
  exports.AFTER_WINDOW = AFTER_WINDOW;
2571
2633
  exports.BacktickRuns = BacktickRuns;
2572
2634
  exports.CALLOUT_NAMES = CALLOUT_NAMES;
@@ -2583,13 +2645,18 @@ exports.buildCodePointIndex = buildCodePointIndex;
2583
2645
  exports.classifyInnerFenceLine = classifyInnerFenceLine;
2584
2646
  exports.closeFence = closeFence;
2585
2647
  exports.codeSpanText = codeSpanText;
2648
+ exports.continuesTable = continuesTable;
2586
2649
  exports.fenceLineKinds = fenceLineKinds;
2587
2650
  exports.fenceNestsInnerFences = fenceNestsInnerFences;
2588
2651
  exports.fenceOpenerOf = fenceOpenerOf;
2589
2652
  exports.fenceParts = fenceParts;
2590
2653
  exports.findCodeRanges = findCodeRanges;
2654
+ exports.findTableEnd = findTableEnd;
2655
+ exports.findTableStart = findTableStart;
2591
2656
  exports.isEscapedBracketMath = isEscapedBracketMath;
2657
+ exports.isGfmDelimiterRow = isGfmDelimiterRow;
2592
2658
  exports.isMathPlaceholder = isMathPlaceholder;
2659
+ exports.isPipeLedRow = isPipeLedRow;
2593
2660
  exports.isSingleDollarMath = isSingleDollarMath;
2594
2661
  exports.islandEdit = islandEdit;
2595
2662
  exports.joinSource = joinSource;
@@ -2599,17 +2666,23 @@ exports.looksLikeOpenInlineMath = looksLikeOpenInlineMath;
2599
2666
  exports.mapCodeRanges = mapCodeRanges;
2600
2667
  exports.mapPosition = mapPosition;
2601
2668
  exports.mapRange = mapRange;
2669
+ exports.opensTable = opensTable;
2602
2670
  exports.pairDisplayMath = pairDisplayMath;
2603
2671
  exports.parseFenceOpener = parseFenceOpener;
2604
2672
  exports.pendingDisplayMathOpener = pendingDisplayMathOpener;
2605
2673
  exports.readXmlTag = readXmlTag;
2674
+ exports.rowCells = rowCells;
2606
2675
  exports.singleDollarAfter = singleDollarAfter;
2607
2676
  exports.singleDollarMathEnd = singleDollarMathEnd;
2608
2677
  exports.spliceSave = spliceSave;
2678
+ exports.splitRowSegments = splitRowSegments;
2609
2679
  exports.splitsSurrogatePair = splitsSurrogatePair;
2680
+ exports.startsPipelessTable = startsPipelessTable;
2681
+ exports.tableStartsAt = tableStartsAt;
2610
2682
  exports.toCodePointOffset = toCodePointOffset;
2611
2683
  exports.toUtf16Offset = toUtf16Offset;
2612
2684
  exports.tokenizeSource = tokenizeSource;
2613
2685
  exports.trimFenceLine = trimFenceLine;
2686
+ exports.unescapeCellPipes = unescapeCellPipes;
2614
2687
  //# sourceMappingURL=source.cjs.map
2615
2688
  //# sourceMappingURL=source.cjs.map