@ai-matrx/content-ir 0.18.6 → 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.cjs CHANGED
@@ -270,12 +270,6 @@ function fenceOpenerOf(content) {
270
270
  return null;
271
271
  }
272
272
  var FenceReader = class {
273
- constructor(opener, options = {}) {
274
- this.opener = opener;
275
- this.isJson = opener.char === "`" && opener.lang === "json";
276
- this.nesting = opener.char === "`" && (options.nesting ?? fenceNestsInnerFences(opener.lang));
277
- this.tildeCloser = opener.char === "~" ? new RegExp(`^ {0,3}~{${opener.ticks},}[ \\t]*$`) : null;
278
- }
279
273
  opener;
280
274
  state = { inString: false, escaped: false };
281
275
  depth = 0;
@@ -284,6 +278,12 @@ var FenceReader = class {
284
278
  isJson;
285
279
  nesting;
286
280
  tildeCloser;
281
+ constructor(opener, options = {}) {
282
+ this.opener = opener;
283
+ this.isJson = opener.char === "`" && opener.lang === "json";
284
+ this.nesting = opener.char === "`" && (options.nesting ?? fenceNestsInnerFences(opener.lang));
285
+ this.tildeCloser = opener.char === "~" ? new RegExp(`^ {0,3}~{${opener.ticks},}[ \\t]*$`) : null;
286
+ }
287
287
  /** How many nested fences are open right now. */
288
288
  get nestedDepth() {
289
289
  return this.depth;
@@ -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([
@@ -901,9 +901,6 @@ function isEscapedBacktick(line, offset) {
901
901
  return slashes % 2 === 1;
902
902
  }
903
903
  var XmlContainerTracker = class {
904
- constructor(rootTag) {
905
- this.rootTag = rootTag;
906
- }
907
904
  rootTag;
908
905
  depth = 0;
909
906
  inComment = false;
@@ -911,6 +908,9 @@ var XmlContainerTracker = class {
911
908
  inlineTicks = 0;
912
909
  /** The open fence, read by THE one closer (source/code-ranges.ts). */
913
910
  fence = null;
911
+ constructor(rootTag) {
912
+ this.rootTag = rootTag;
913
+ }
914
914
  consumeLine(line, startOffset = 0) {
915
915
  if (this.fence) {
916
916
  if (this.fence.feed(line)) this.fence = null;
@@ -1122,6 +1122,23 @@ function isSplitterTreeLine(line) {
1122
1122
  }
1123
1123
  var MEDIA_REF_PREFIXES = ["[Image URL:", "[Video URL:", "[Audio URL:"];
1124
1124
  var Tokenizer = class {
1125
+ text;
1126
+ streaming;
1127
+ meter;
1128
+ n;
1129
+ lineStarts = [];
1130
+ contentEnds = [];
1131
+ lineEnds = [];
1132
+ blocks = [];
1133
+ blockCache = /* @__PURE__ */ new Map();
1134
+ /** Lazily built: for line i, first line j >= i where brace net from i drops to <= 0. */
1135
+ braceStop = null;
1136
+ braceNet = null;
1137
+ /** Every occurrence offset of each needle searched so far (overlapping, like indexOf). */
1138
+ occurrences = /* @__PURE__ */ new Map();
1139
+ /** `$$` opener → closer for the pairs the core renders as math. */
1140
+ mathPairs;
1141
+ finder = (needle, from) => this.next(needle, from);
1125
1142
  constructor(text, streaming = false, meter = void 0) {
1126
1143
  this.text = text;
1127
1144
  this.streaming = streaming;
@@ -1140,7 +1157,7 @@ var Tokenizer = class {
1140
1157
  if (close >= span) this.provisionalFrom = Math.min(this.provisionalFrom, open);
1141
1158
  }
1142
1159
  }
1143
- for (const pad of ["`", "``", "```", "~~~"]) {
1160
+ for (const pad of ["`", "``", "```", "~~~", "$"]) {
1144
1161
  const alt = pairDisplayMath(text + pad);
1145
1162
  for (const [open, close] of this.mathPairs) {
1146
1163
  if (alt.get(open) !== close) this.provisionalFrom = Math.min(this.provisionalFrom, open);
@@ -1168,40 +1185,10 @@ var Tokenizer = class {
1168
1185
  this.lineEnds.push(text.length);
1169
1186
  }
1170
1187
  }
1171
- text;
1172
- streaming;
1173
- meter;
1174
- n;
1175
- lineStarts = [];
1176
- contentEnds = [];
1177
- lineEnds = [];
1178
- blocks = [];
1179
- blockCache = /* @__PURE__ */ new Map();
1180
- /** Lazily built: for line i, first line j >= i where brace net from i drops to <= 0. */
1181
- braceStop = null;
1182
- braceNet = null;
1183
- /** Every occurrence offset of each needle searched so far (overlapping, like indexOf). */
1184
- occurrences = /* @__PURE__ */ new Map();
1185
- /** `$$` opener → closer for the pairs the core renders as math. */
1186
- mathPairs;
1187
- finder = (needle, from) => this.next(needle, from);
1188
1188
  /** Streaming: where provisional text starts (a pending `$$`), or +∞. */
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);
@@ -1331,12 +1319,6 @@ var Tokenizer = class {
1331
1319
  const last = this.lineStarts.length - 1;
1332
1320
  if (last < 0) return;
1333
1321
  if (this.isOpenTail(last)) {
1334
- const lineStart = this.lineStarts[last];
1335
- for (const block2 of this.blocks) {
1336
- if (block2.kind === "prose" && block2.end > lineStart) {
1337
- block2.inlines = block2.inlines.filter((inline) => inline.end <= lineStart);
1338
- }
1339
- }
1340
1322
  let b = this.blocks.length - 1;
1341
1323
  while (b >= 0 && this.blocks[b].kind === "gap") b--;
1342
1324
  const block = this.blocks[b];
@@ -1528,7 +1510,7 @@ var Tokenizer = class {
1528
1510
  return { type, start, end, complete, meta };
1529
1511
  }
1530
1512
  frontMatter(li, t) {
1531
- const fence = this.lineText(li);
1513
+ const fence = this.lineText(li).replace(/^\uFEFF/, "");
1532
1514
  if (fence !== "---" && fence !== "+++" || t !== fence) return null;
1533
1515
  const toml = fence === "+++";
1534
1516
  let sawContent = false;
@@ -1539,9 +1521,13 @@ var Tokenizer = class {
1539
1521
  }
1540
1522
  if (!NOT_WHITESPACE.test(line)) continue;
1541
1523
  const shaped = toml ? /^\s*(?:[A-Za-z0-9_."-]+\s*=|\[|#)/.test(line) : /^(?:[A-Za-z0-9_"'-][^:]*:(?:\s|$)|\s+\S|-\s|#)/.test(line);
1542
- if (!shaped) return null;
1524
+ if (!shaped) {
1525
+ if (this.isOpenTail(k)) break;
1526
+ return null;
1527
+ }
1543
1528
  sawContent = true;
1544
1529
  }
1530
+ if (this.streaming) return this.island("front_matter", 0, this.n, false, { format: toml ? "toml" : "yaml" });
1545
1531
  return null;
1546
1532
  }
1547
1533
  /**
@@ -1942,7 +1928,9 @@ var Tokenizer = class {
1942
1928
  const block = this.detectBlock(this.lineStarts[k], k, false);
1943
1929
  if (block) {
1944
1930
  breakLine = k;
1945
- if (this.mayDissolve(block)) this.undecidedBreaks.add(end);
1931
+ if (this.mayDissolve(block)) {
1932
+ this.undecidedBreaks.add(end);
1933
+ }
1946
1934
  break;
1947
1935
  }
1948
1936
  end = this.contentEnds[k];
@@ -2287,12 +2275,12 @@ function blockAt(blocks, offset) {
2287
2275
 
2288
2276
  // source/splice.ts
2289
2277
  var SourceSpliceError = class extends Error {
2278
+ code;
2290
2279
  constructor(code, message) {
2291
2280
  super(message);
2292
2281
  this.code = code;
2293
2282
  this.name = "SourceSpliceError";
2294
2283
  }
2295
- code;
2296
2284
  };
2297
2285
  function blockEdit(block, text) {
2298
2286
  return { start: block.start, end: block.end, text };