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