@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.d.cts CHANGED
@@ -390,6 +390,24 @@ type InnerFenceLine =
390
390
  declare const FENCE_WHITESPACE = " \t\n\r\f\v";
391
391
  /** Strip {@link FENCE_WHITESPACE} (and nothing else) from both ends of a line. */
392
392
  declare function trimFenceLine(line: string): string;
393
+ /**
394
+ * The whitespace around a fence OPENER and inside its info string. The
395
+ * renderer finds openers with JavaScript's `String#trim()` and splits the info
396
+ * string on `/\s/`; this set IS that definition, written out so the Python
397
+ * twin can match it exactly — ECMAScript WhiteSpace + LineTerminator. It
398
+ * differs from Python's `str.split()` on U+0085 and U+001C–U+001F (not JS
399
+ * whitespace) and U+FEFF (JS whitespace) — verify-RC-B3 residual R4′.
400
+ */
401
+ declare const FENCE_OPENER_WHITESPACE = "\t\n\v\f\r \u00A0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF";
402
+ /**
403
+ * Parse a backtick fence OPENER line the way the renderer does: trim the line,
404
+ * count the backtick run (3+), trim the rest, and take the first
405
+ * whitespace-separated word as the language. null when the line opens nothing.
406
+ */
407
+ declare function parseFenceOpener(line: string): {
408
+ ticks: number;
409
+ lang: string;
410
+ } | null;
393
411
  declare function classifyInnerFenceLine(trimmed: string, openTicks: number, nests: boolean, nestedDepth: number): InnerFenceLine;
394
412
 
395
413
  /**
@@ -412,4 +430,4 @@ declare function looksLikeDisplayMath(inner: string): boolean;
412
430
  /** Map of `$$` opener offset → closer offset for every pair the renderer shows as math. */
413
431
  declare function pairDisplayMath(text: string): Map<number, number>;
414
432
 
415
- export { type BlockIslandType, CALLOUT_NAMES, type CodePointIndex, type DisturbedIsland, FENCE_WHITESPACE, type InlineIslandType, type InnerFenceLine, type IslandMeta, type IslandType, type MapOptions, type MappedPosition, type MappedRange, NESTING_FENCE_LANGUAGES, type ReadXmlTag, type SourceBlock, type SourceBlockKind, type SourceChange, type SourceEdit, type SourceIsland, type SourceSpan, SourceSpliceError, type SourceSpliceErrorCode, type SpliceIntegrity, type SpliceOptions, type SpliceResult, type TokenizeOptions, XmlContainerTracker, blockAt, blockEdit, blockRangeEdit, buildCodePointIndex, classifyInnerFenceLine, fenceNestsInnerFences, isSingleDollarMath, islandEdit, joinSource, listIslands, looksLikeDisplayMath, mapPosition, mapRange, pairDisplayMath, readXmlTag, singleDollarMathEnd, spliceSave, splitsSurrogatePair, toCodePointOffset, toUtf16Offset, tokenizeSource, trimFenceLine };
433
+ export { type BlockIslandType, CALLOUT_NAMES, type CodePointIndex, type DisturbedIsland, FENCE_OPENER_WHITESPACE, FENCE_WHITESPACE, type InlineIslandType, type InnerFenceLine, type IslandMeta, type IslandType, type MapOptions, type MappedPosition, type MappedRange, NESTING_FENCE_LANGUAGES, type ReadXmlTag, type SourceBlock, type SourceBlockKind, type SourceChange, type SourceEdit, type SourceIsland, type SourceSpan, SourceSpliceError, type SourceSpliceErrorCode, type SpliceIntegrity, type SpliceOptions, type SpliceResult, type TokenizeOptions, XmlContainerTracker, blockAt, blockEdit, blockRangeEdit, buildCodePointIndex, classifyInnerFenceLine, fenceNestsInnerFences, isSingleDollarMath, islandEdit, joinSource, listIslands, looksLikeDisplayMath, mapPosition, mapRange, pairDisplayMath, parseFenceOpener, readXmlTag, singleDollarMathEnd, spliceSave, splitsSurrogatePair, toCodePointOffset, toUtf16Offset, tokenizeSource, trimFenceLine };
package/dist/source.d.ts CHANGED
@@ -390,6 +390,24 @@ type InnerFenceLine =
390
390
  declare const FENCE_WHITESPACE = " \t\n\r\f\v";
391
391
  /** Strip {@link FENCE_WHITESPACE} (and nothing else) from both ends of a line. */
392
392
  declare function trimFenceLine(line: string): string;
393
+ /**
394
+ * The whitespace around a fence OPENER and inside its info string. The
395
+ * renderer finds openers with JavaScript's `String#trim()` and splits the info
396
+ * string on `/\s/`; this set IS that definition, written out so the Python
397
+ * twin can match it exactly — ECMAScript WhiteSpace + LineTerminator. It
398
+ * differs from Python's `str.split()` on U+0085 and U+001C–U+001F (not JS
399
+ * whitespace) and U+FEFF (JS whitespace) — verify-RC-B3 residual R4′.
400
+ */
401
+ declare const FENCE_OPENER_WHITESPACE = "\t\n\v\f\r \u00A0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF";
402
+ /**
403
+ * Parse a backtick fence OPENER line the way the renderer does: trim the line,
404
+ * count the backtick run (3+), trim the rest, and take the first
405
+ * whitespace-separated word as the language. null when the line opens nothing.
406
+ */
407
+ declare function parseFenceOpener(line: string): {
408
+ ticks: number;
409
+ lang: string;
410
+ } | null;
393
411
  declare function classifyInnerFenceLine(trimmed: string, openTicks: number, nests: boolean, nestedDepth: number): InnerFenceLine;
394
412
 
395
413
  /**
@@ -412,4 +430,4 @@ declare function looksLikeDisplayMath(inner: string): boolean;
412
430
  /** Map of `$$` opener offset → closer offset for every pair the renderer shows as math. */
413
431
  declare function pairDisplayMath(text: string): Map<number, number>;
414
432
 
415
- export { type BlockIslandType, CALLOUT_NAMES, type CodePointIndex, type DisturbedIsland, FENCE_WHITESPACE, type InlineIslandType, type InnerFenceLine, type IslandMeta, type IslandType, type MapOptions, type MappedPosition, type MappedRange, NESTING_FENCE_LANGUAGES, type ReadXmlTag, type SourceBlock, type SourceBlockKind, type SourceChange, type SourceEdit, type SourceIsland, type SourceSpan, SourceSpliceError, type SourceSpliceErrorCode, type SpliceIntegrity, type SpliceOptions, type SpliceResult, type TokenizeOptions, XmlContainerTracker, blockAt, blockEdit, blockRangeEdit, buildCodePointIndex, classifyInnerFenceLine, fenceNestsInnerFences, isSingleDollarMath, islandEdit, joinSource, listIslands, looksLikeDisplayMath, mapPosition, mapRange, pairDisplayMath, readXmlTag, singleDollarMathEnd, spliceSave, splitsSurrogatePair, toCodePointOffset, toUtf16Offset, tokenizeSource, trimFenceLine };
433
+ export { type BlockIslandType, CALLOUT_NAMES, type CodePointIndex, type DisturbedIsland, FENCE_OPENER_WHITESPACE, FENCE_WHITESPACE, type InlineIslandType, type InnerFenceLine, type IslandMeta, type IslandType, type MapOptions, type MappedPosition, type MappedRange, NESTING_FENCE_LANGUAGES, type ReadXmlTag, type SourceBlock, type SourceBlockKind, type SourceChange, type SourceEdit, type SourceIsland, type SourceSpan, SourceSpliceError, type SourceSpliceErrorCode, type SpliceIntegrity, type SpliceOptions, type SpliceResult, type TokenizeOptions, XmlContainerTracker, blockAt, blockEdit, blockRangeEdit, buildCodePointIndex, classifyInnerFenceLine, fenceNestsInnerFences, isSingleDollarMath, islandEdit, joinSource, listIslands, looksLikeDisplayMath, mapPosition, mapRange, pairDisplayMath, parseFenceOpener, readXmlTag, singleDollarMathEnd, spliceSave, splitsSurrogatePair, toCodePointOffset, toUtf16Offset, tokenizeSource, trimFenceLine };
package/dist/source.js CHANGED
@@ -220,6 +220,24 @@ function trimFenceLine(line) {
220
220
  while (end > start && isFenceWhitespace(line[end - 1])) end--;
221
221
  return start === 0 && end === line.length ? line : line.slice(start, end);
222
222
  }
223
+ 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";
224
+ function isOpenerWhitespace(ch) {
225
+ return ch !== void 0 && ch !== "" && FENCE_OPENER_WHITESPACE.includes(ch);
226
+ }
227
+ function parseFenceOpener(line) {
228
+ let start = 0;
229
+ let end = line.length;
230
+ while (start < end && isOpenerWhitespace(line[start])) start++;
231
+ while (end > start && isOpenerWhitespace(line[end - 1])) end--;
232
+ let ticks = 0;
233
+ while (start + ticks < end && line[start + ticks] === "`") ticks++;
234
+ if (ticks < 3) return null;
235
+ let infoStart = start + ticks;
236
+ while (infoStart < end && isOpenerWhitespace(line[infoStart])) infoStart++;
237
+ let langEnd = infoStart;
238
+ while (langEnd < end && !isOpenerWhitespace(line[langEnd])) langEnd++;
239
+ return { ticks, lang: line.slice(infoStart, langEnd) };
240
+ }
223
241
  function classifyInnerFenceLine(trimmed, openTicks, nests, nestedDepth) {
224
242
  let ticks = 0;
225
243
  while (ticks < trimmed.length && trimmed[ticks] === "`") ticks++;
@@ -980,8 +998,7 @@ var Tokenizer = class {
980
998
  */
981
999
  backtickFence(p, li, t) {
982
1000
  const openTicks = backtickRunLength(t, 0);
983
- const info = t.slice(openTicks).trim();
984
- const lang = info.split(/\s/)[0] ?? "";
1001
+ const lang = parseFenceOpener(t)?.lang ?? "";
985
1002
  const isJson = lang === "json";
986
1003
  const normalized = normalizeFenceLanguage(lang);
987
1004
  const meta = { fence: "`", ticks: openTicks, lang };
@@ -1111,6 +1128,7 @@ var Tokenizer = class {
1111
1128
  const endLine = this.lineOf(close);
1112
1129
  const endCe = this.contentEnds[endLine];
1113
1130
  if (endLine !== li && !this.isBlank(end, endCe)) return null;
1131
+ if (this.isOpenTail(endLine)) return this.island("math_block", p, this.n, false, { delimiter: "$$" });
1114
1132
  return this.island("math_block", p, end, true, { delimiter: "$$" });
1115
1133
  }
1116
1134
  /** `<artifact …>`, `<decision …>`, … at the start of a line. */
@@ -1440,7 +1458,7 @@ var Tokenizer = class {
1440
1458
  continue;
1441
1459
  }
1442
1460
  const end = singleDollarMathEnd(text, i, pe);
1443
- if (end > 0) {
1461
+ if (end > 0 && !(this.streaming && end === this.n)) {
1444
1462
  inlines.push(this.island("math_inline", i, end, true, { delimiter: "$" }));
1445
1463
  i = end;
1446
1464
  continue;
@@ -1850,11 +1868,17 @@ function spliceSave(original, edits, options = {}) {
1850
1868
  else newIslandsByStart.set(island.start, [island.raw]);
1851
1869
  }
1852
1870
  const disturbed = [];
1871
+ const carried = (island) => sorted.some((edit) => !edit.island && island.start >= edit.start && island.end <= edit.end);
1872
+ const changedInside = [];
1853
1873
  for (const island of islands) {
1854
1874
  if (replacedIslands.has(`${island.start}:${island.end}`)) continue;
1855
1875
  const mappedStart = mapPosition(changes, island.start, { assoc: 1 }).pos;
1856
1876
  const candidates = newIslandsByStart.get(mappedStart);
1857
1877
  if (!candidates || !candidates.includes(island.raw)) {
1878
+ if (carried(island)) {
1879
+ changedInside.push(island);
1880
+ continue;
1881
+ }
1858
1882
  disturbed.push({
1859
1883
  islandType: island.islandType,
1860
1884
  inline: island.inline,
@@ -1864,6 +1888,14 @@ function spliceSave(original, edits, options = {}) {
1864
1888
  });
1865
1889
  }
1866
1890
  }
1891
+ if (changedInside.length > 0) {
1892
+ const first = changedInside[0];
1893
+ const name = first.meta.tag ?? first.meta.name ?? first.meta.lang ?? "";
1894
+ throw new SourceSpliceError(
1895
+ "island_edit",
1896
+ `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()`
1897
+ );
1898
+ }
1867
1899
  const integrity = {
1868
1900
  ok: bytesOutsideEditsIdentical && disturbed.length === 0,
1869
1901
  bytesOutsideEditsIdentical,
@@ -1915,6 +1947,6 @@ function mapRange(changes, start, end, unit = "utf16") {
1915
1947
  return { start: newStart, end: newEnd, touched, collapsed: newEnd === newStart && end > start };
1916
1948
  }
1917
1949
 
1918
- export { CALLOUT_NAMES, FENCE_WHITESPACE, NESTING_FENCE_LANGUAGES, SourceSpliceError, XmlContainerTracker, blockAt, blockEdit, blockRangeEdit, buildCodePointIndex, classifyInnerFenceLine, fenceNestsInnerFences, isSingleDollarMath, islandEdit, joinSource, listIslands, looksLikeDisplayMath, mapPosition, mapRange, pairDisplayMath, readXmlTag, singleDollarMathEnd, spliceSave, splitsSurrogatePair, toCodePointOffset, toUtf16Offset, tokenizeSource, trimFenceLine };
1950
+ export { CALLOUT_NAMES, FENCE_OPENER_WHITESPACE, FENCE_WHITESPACE, NESTING_FENCE_LANGUAGES, SourceSpliceError, XmlContainerTracker, blockAt, blockEdit, blockRangeEdit, buildCodePointIndex, classifyInnerFenceLine, fenceNestsInnerFences, isSingleDollarMath, islandEdit, joinSource, listIslands, looksLikeDisplayMath, mapPosition, mapRange, pairDisplayMath, parseFenceOpener, readXmlTag, singleDollarMathEnd, spliceSave, splitsSurrogatePair, toCodePointOffset, toUtf16Offset, tokenizeSource, trimFenceLine };
1919
1951
  //# sourceMappingURL=source.js.map
1920
1952
  //# sourceMappingURL=source.js.map