@ai-matrx/content-ir 0.19.0 → 0.19.1

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.js CHANGED
@@ -586,7 +586,7 @@ function pendingCodeSpanStart(text) {
586
586
  const n = text.length;
587
587
  if (n === 0 || /\n[ \t]*\n[ \t]*$/.test(text)) return -1;
588
588
  const lastLine = text.slice(text.lastIndexOf("\n") + 1);
589
- if (lastLine && /^(?: {0,3}>[ \t]?)*[ \t]*$/.test(lastLine)) return pendingCodeSpanStart(`${text}x`);
589
+ if (lastLine && /^(?: {0,3}>[ \t]?)*[ \t\r]*$/.test(lastLine)) return pendingCodeSpanStart(`${text}x`);
590
590
  const s = scan(text);
591
591
  const para = s.pendingPara;
592
592
  if (s.endsInFence || para === -1) return -1;
@@ -750,7 +750,7 @@ function isVariableChain(content, after) {
750
750
  const run = /^[A-Za-z0-9_]+/.exec(after)?.[0];
751
751
  if (!run) return false;
752
752
  if (after.length === 1) return false;
753
- if (/^[A-Za-z_][A-Za-z0-9_]*[.@-]$/.test(content)) return true;
753
+ if (/^[A-Za-z_][A-Za-z0-9_]*(?:[.@-]|->|::)$/.test(content)) return true;
754
754
  return IDENTIFIER.test(content) && !MATH_SUFFIX.test(run);
755
755
  }
756
756
  var FUNCTION_NAMES = /* @__PURE__ */ new Set([
@@ -1155,7 +1155,7 @@ var Tokenizer = class {
1155
1155
  if (close >= span) this.provisionalFrom = Math.min(this.provisionalFrom, open);
1156
1156
  }
1157
1157
  }
1158
- for (const pad of ["`", "``", "```", "~~~"]) {
1158
+ for (const pad of ["`", "``", "```", "~~~", "$"]) {
1159
1159
  const alt = pairDisplayMath(text + pad);
1160
1160
  for (const [open, close] of this.mathPairs) {
1161
1161
  if (alt.get(open) !== close) this.provisionalFrom = Math.min(this.provisionalFrom, open);
@@ -1187,19 +1187,6 @@ var Tokenizer = class {
1187
1187
  provisionalFrom = Number.POSITIVE_INFINITY;
1188
1188
  /** Streaming: the text ends in a lone CR whose LF has not arrived yet. */
1189
1189
  pendingCR = false;
1190
- /**
1191
- * Streaming: an open last line that begins with `{` is undecided — each new
1192
- * byte can balance or unbalance its braces and flip the whole line between
1193
- * prose and a JSON island — so it is provisional until it ends (G5).
1194
- * (A lone HTML tag on that line is held by {@link holdUndecidedTail}.)
1195
- */
1196
- markOpenJsonTail() {
1197
- const last = this.lineStarts.length - 1;
1198
- if (!this.isOpenTail(last)) return;
1199
- if (this.lineText(last).trim().startsWith("{")) {
1200
- this.provisionalFrom = Math.min(this.provisionalFrom, this.lineStarts[last]);
1201
- }
1202
- }
1203
1190
  /**
1204
1191
  * `text.indexOf(needle, from)` in O(log k): the first query for a needle
1205
1192
  * indexes all of its occurrences once, so repeated searches for a closer
@@ -1234,7 +1221,7 @@ var Tokenizer = class {
1234
1221
  const rest = this.n - pe;
1235
1222
  if (rest === 0) return true;
1236
1223
  const tail = this.text.slice(pe);
1237
- return /^(?:\r\n|\r|\n)[ \t]*$/.test(tail);
1224
+ return /^(?:\r\n|\r|\n)[ \t\r]*$/.test(tail);
1238
1225
  }
1239
1226
  /**
1240
1227
  * Streaming: an open block that may still turn back into prose — a `$$`
@@ -1243,7 +1230,9 @@ var Tokenizer = class {
1243
1230
  * or any opener that is itself still arriving on the open last line.
1244
1231
  */
1245
1232
  mayDissolve(block) {
1246
- if (!this.streaming || block.complete) return false;
1233
+ if (!this.streaming) return false;
1234
+ if (block.start >= this.provisionalFrom) return true;
1235
+ if (block.complete) return false;
1247
1236
  if (block.type === "math_block" || block.type === "json") return true;
1248
1237
  return this.isOpenTail(this.lineOf(block.start));
1249
1238
  }
@@ -1282,7 +1271,6 @@ var Tokenizer = class {
1282
1271
  return this.text.slice(this.lineStarts[li], this.contentEnds[li]);
1283
1272
  }
1284
1273
  run() {
1285
- if (this.streaming) this.markOpenJsonTail();
1286
1274
  let pos = 0;
1287
1275
  while (pos < this.n) {
1288
1276
  const li = this.lineOf(pos);
@@ -1520,7 +1508,7 @@ var Tokenizer = class {
1520
1508
  return { type, start, end, complete, meta };
1521
1509
  }
1522
1510
  frontMatter(li, t) {
1523
- const fence = this.lineText(li);
1511
+ const fence = this.lineText(li).replace(/^\uFEFF/, "");
1524
1512
  if (fence !== "---" && fence !== "+++" || t !== fence) return null;
1525
1513
  const toml = fence === "+++";
1526
1514
  let sawContent = false;
@@ -1531,9 +1519,13 @@ var Tokenizer = class {
1531
1519
  }
1532
1520
  if (!NOT_WHITESPACE.test(line)) continue;
1533
1521
  const shaped = toml ? /^\s*(?:[A-Za-z0-9_."-]+\s*=|\[|#)/.test(line) : /^(?:[A-Za-z0-9_"'-][^:]*:(?:\s|$)|\s+\S|-\s|#)/.test(line);
1534
- if (!shaped) return null;
1522
+ if (!shaped) {
1523
+ if (this.isOpenTail(k)) break;
1524
+ return null;
1525
+ }
1535
1526
  sawContent = true;
1536
1527
  }
1528
+ if (this.streaming) return this.island("front_matter", 0, this.n, false, { format: toml ? "toml" : "yaml" });
1537
1529
  return null;
1538
1530
  }
1539
1531
  /**
@@ -1934,7 +1926,7 @@ var Tokenizer = class {
1934
1926
  const block = this.detectBlock(this.lineStarts[k], k, false);
1935
1927
  if (block) {
1936
1928
  breakLine = k;
1937
- if (this.mayDissolve(block) || this.streaming && block.start >= this.provisionalFrom) {
1929
+ if (this.mayDissolve(block)) {
1938
1930
  this.undecidedBreaks.add(end);
1939
1931
  }
1940
1932
  break;