@ai-matrx/content-ir 0.14.3 → 0.15.0

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
@@ -222,6 +222,24 @@ function trimFenceLine(line) {
222
222
  while (end > start && isFenceWhitespace(line[end - 1])) end--;
223
223
  return start === 0 && end === line.length ? line : line.slice(start, end);
224
224
  }
225
+ var FENCE_OPENER_WHITESPACE = " \n\v\f\r \xA0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF";
226
+ function isOpenerWhitespace(ch) {
227
+ return ch !== void 0 && ch !== "" && FENCE_OPENER_WHITESPACE.includes(ch);
228
+ }
229
+ function parseFenceOpener(line) {
230
+ let start = 0;
231
+ let end = line.length;
232
+ while (start < end && isOpenerWhitespace(line[start])) start++;
233
+ while (end > start && isOpenerWhitespace(line[end - 1])) end--;
234
+ let ticks = 0;
235
+ while (start + ticks < end && line[start + ticks] === "`") ticks++;
236
+ if (ticks < 3) return null;
237
+ let infoStart = start + ticks;
238
+ while (infoStart < end && isOpenerWhitespace(line[infoStart])) infoStart++;
239
+ let langEnd = infoStart;
240
+ while (langEnd < end && !isOpenerWhitespace(line[langEnd])) langEnd++;
241
+ return { ticks, lang: line.slice(infoStart, langEnd) };
242
+ }
225
243
  function classifyInnerFenceLine(trimmed, openTicks, nests, nestedDepth) {
226
244
  let ticks = 0;
227
245
  while (ticks < trimmed.length && trimmed[ticks] === "`") ticks++;
@@ -982,8 +1000,7 @@ var Tokenizer = class {
982
1000
  */
983
1001
  backtickFence(p, li, t) {
984
1002
  const openTicks = backtickRunLength(t, 0);
985
- const info = t.slice(openTicks).trim();
986
- const lang = info.split(/\s/)[0] ?? "";
1003
+ const lang = parseFenceOpener(t)?.lang ?? "";
987
1004
  const isJson = lang === "json";
988
1005
  const normalized = normalizeFenceLanguage(lang);
989
1006
  const meta = { fence: "`", ticks: openTicks, lang };
@@ -1113,6 +1130,7 @@ var Tokenizer = class {
1113
1130
  const endLine = this.lineOf(close);
1114
1131
  const endCe = this.contentEnds[endLine];
1115
1132
  if (endLine !== li && !this.isBlank(end, endCe)) return null;
1133
+ if (this.isOpenTail(endLine)) return this.island("math_block", p, this.n, false, { delimiter: "$$" });
1116
1134
  return this.island("math_block", p, end, true, { delimiter: "$$" });
1117
1135
  }
1118
1136
  /** `<artifact …>`, `<decision …>`, … at the start of a line. */
@@ -1442,7 +1460,7 @@ var Tokenizer = class {
1442
1460
  continue;
1443
1461
  }
1444
1462
  const end = singleDollarMathEnd(text, i, pe);
1445
- if (end > 0) {
1463
+ if (end > 0 && !(this.streaming && end === this.n)) {
1446
1464
  inlines.push(this.island("math_inline", i, end, true, { delimiter: "$" }));
1447
1465
  i = end;
1448
1466
  continue;
@@ -1852,11 +1870,17 @@ function spliceSave(original, edits, options = {}) {
1852
1870
  else newIslandsByStart.set(island.start, [island.raw]);
1853
1871
  }
1854
1872
  const disturbed = [];
1873
+ const carried = (island) => sorted.some((edit) => !edit.island && island.start >= edit.start && island.end <= edit.end);
1874
+ const changedInside = [];
1855
1875
  for (const island of islands) {
1856
1876
  if (replacedIslands.has(`${island.start}:${island.end}`)) continue;
1857
1877
  const mappedStart = mapPosition(changes, island.start, { assoc: 1 }).pos;
1858
1878
  const candidates = newIslandsByStart.get(mappedStart);
1859
1879
  if (!candidates || !candidates.includes(island.raw)) {
1880
+ if (carried(island)) {
1881
+ changedInside.push(island);
1882
+ continue;
1883
+ }
1860
1884
  disturbed.push({
1861
1885
  islandType: island.islandType,
1862
1886
  inline: island.inline,
@@ -1866,6 +1890,14 @@ function spliceSave(original, edits, options = {}) {
1866
1890
  });
1867
1891
  }
1868
1892
  }
1893
+ if (changedInside.length > 0) {
1894
+ const first = changedInside[0];
1895
+ const name = first.meta.tag ?? first.meta.name ?? first.meta.lang ?? "";
1896
+ throw new SourceSpliceError(
1897
+ "island_edit",
1898
+ `the edit changes the protected ${first.islandType}${name ? ` (${String(name)})` : ""} island at [${first.start}, ${first.end}) \u2014 its bytes survive only as ordinary text${changedInside.length > 1 ? ` (and ${changedInside.length - 1} more)` : ""}; islands change only through islandEdit()`
1899
+ );
1900
+ }
1869
1901
  const integrity = {
1870
1902
  ok: bytesOutsideEditsIdentical && disturbed.length === 0,
1871
1903
  bytesOutsideEditsIdentical,
@@ -1918,6 +1950,7 @@ function mapRange(changes, start, end, unit = "utf16") {
1918
1950
  }
1919
1951
 
1920
1952
  exports.CALLOUT_NAMES = CALLOUT_NAMES;
1953
+ exports.FENCE_OPENER_WHITESPACE = FENCE_OPENER_WHITESPACE;
1921
1954
  exports.FENCE_WHITESPACE = FENCE_WHITESPACE;
1922
1955
  exports.NESTING_FENCE_LANGUAGES = NESTING_FENCE_LANGUAGES;
1923
1956
  exports.SourceSpliceError = SourceSpliceError;
@@ -1936,6 +1969,7 @@ exports.looksLikeDisplayMath = looksLikeDisplayMath;
1936
1969
  exports.mapPosition = mapPosition;
1937
1970
  exports.mapRange = mapRange;
1938
1971
  exports.pairDisplayMath = pairDisplayMath;
1972
+ exports.parseFenceOpener = parseFenceOpener;
1939
1973
  exports.readXmlTag = readXmlTag;
1940
1974
  exports.singleDollarMathEnd = singleDollarMathEnd;
1941
1975
  exports.spliceSave = spliceSave;