@superdoc/mcp 1.11.0-next.6 → 1.11.0-next.8

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.
Files changed (2) hide show
  1. package/dist/index.js +275 -82
  2. package/package.json +4 -4
package/dist/index.js CHANGED
@@ -31630,7 +31630,7 @@ var init_host = __esm(() => {
31630
31630
  });
31631
31631
 
31632
31632
  // ../../packages/sdk/langs/node/src/runtime/sdk-version.generated.ts
31633
- var SDK_VERSION = "2.24.0-next.6";
31633
+ var SDK_VERSION = "2.24.0-next.8";
31634
31634
 
31635
31635
  // ../../packages/sdk/langs/node/src/runtime/embedded-platform.ts
31636
31636
  import { accessSync, chmodSync, constants, existsSync, statSync } from "node:fs";
@@ -133512,6 +133512,14 @@ function copyParagraphInlineData(data) {
133512
133512
  });
133513
133513
  return { ...data, pieces: copyArray(data.pieces, copyPiece) };
133514
133514
  }
133515
+ function visibleParagraphInlineObjects(pieces) {
133516
+ return pieces.flatMap((piece) => {
133517
+ if (piece.kind === "container" && (piece.containerKind === "drawing" || piece.containerKind === "pict" || piece.containerKind === "object" || piece.containerKind === "math")) {
133518
+ return piece.containerStack.some((scope) => scope.deleted) ? [] : [piece];
133519
+ }
133520
+ return "children" in piece ? visibleParagraphInlineObjects(piece.children) : [];
133521
+ });
133522
+ }
133515
133523
  function createParagraphInlineMapFromPieces(paragraphXml, pieces, visibleLength, trackedLength) {
133516
133524
  let visibleString = null;
133517
133525
  let trackedString = null;
@@ -195269,6 +195277,10 @@ function validParagraphPlacement(xml, ranges, root) {
195269
195277
  children.set(parent, siblings);
195270
195278
  const name = parent.tag.localName;
195271
195279
  if (isWord(parent)) {
195280
+ if (name === "p" && range.tag.namespaceUri === OFFICE_MATH_NAMESPACE && ["oMath", "oMathPara"].includes(range.tag.localName)) {
195281
+ stack.push(range);
195282
+ continue;
195283
+ }
195272
195284
  let allowed;
195273
195285
  if (name === "p")
195274
195286
  allowed = PARAGRAPH_CHILDREN;
@@ -195301,6 +195313,9 @@ function validParagraphPlacement(xml, ranges, root) {
195301
195313
  return false;
195302
195314
  if (["pPr", "rPr"].includes(range.tag.localName) && siblings.some((r) => r !== range && r.tag.localName === range.tag.localName))
195303
195315
  return false;
195316
+ } else if (parent.tag.namespaceUri === OFFICE_MATH_NAMESPACE) {
195317
+ if (range.tag.namespaceUri !== OFFICE_MATH_NAMESPACE && !(parent.tag.localName === "r" && isWord(range) && range.tag.localName === "rPr"))
195318
+ return false;
195304
195319
  } else if (isWord(range))
195305
195320
  return false;
195306
195321
  }
@@ -195353,18 +195368,20 @@ function validateRetainableParagraphXml(xml, namespaces) {
195353
195368
  const propertyEnd = root.openEnd + pPr.length;
195354
195369
  const runPropertyRanges = parsed.ranges.filter((range) => isWord(range) && range.tag.localName === "rPr");
195355
195370
  const drawingRanges = parsed.ranges.filter((r) => isWord(r) && r.tag.localName === "drawing");
195371
+ const mathRanges = parsed.ranges.filter((range) => range.tag.namespaceUri === OFFICE_MATH_NAMESPACE && ["oMath", "oMathPara"].includes(range.tag.localName));
195356
195372
  for (const range of parsed.ranges) {
195357
195373
  if (range !== root && isWord(range) && range.tag.localName === "p")
195358
195374
  return { ok: false, reason: "paragraph-tracked-wrapper-unsupported" };
195359
195375
  const inProperties = range.start >= root.openEnd && range.end <= propertyEnd;
195360
195376
  const inRunProperties = runPropertyRanges.some((properties2) => range.start >= properties2.start && range.end <= properties2.end);
195361
195377
  const inDrawing = drawingRanges.some((d) => range.start >= d.start && range.end <= d.end);
195378
+ const inMath = mathRanges.some((math) => range.start >= math.start && range.end <= math.end);
195362
195379
  if (range.tag.attributes.some((attribute) => isRelationshipNamespace(attribute.namespaceUri)) && !inDrawing && range.tag.localName !== "hyperlink")
195363
195380
  return { ok: false, reason: "paragraph-relationship-bearing-unsupported" };
195364
195381
  if (inProperties) {
195365
195382
  if (FORBIDDEN_PROPERTIES.has(range.tag.localName) && range.tag.localName !== "ins")
195366
195383
  return { ok: false, reason: "paragraph-tracked-wrapper-unsupported" };
195367
- } else if (!inDrawing && (!isWord(range) || (inRunProperties ? !RUN_PROPERTY_NAMES.has(range.tag.localName) : !INLINE_NAMES.has(range.tag.localName)) || (range.tag.localName === "ins" || range.tag.localName === "del") && range.tag.isSelfClosing)) {
195384
+ } else if (!inDrawing && !inMath && (!isWord(range) || (inRunProperties ? !RUN_PROPERTY_NAMES.has(range.tag.localName) : !INLINE_NAMES.has(range.tag.localName)) || (range.tag.localName === "ins" || range.tag.localName === "del") && range.tag.isSelfClosing)) {
195368
195385
  return { ok: false, reason: "paragraph-tracked-wrapper-unsupported" };
195369
195386
  }
195370
195387
  if (range.tag.localName === "rPrChange")
@@ -195680,7 +195697,7 @@ function readParagraphRelationshipDependencies(state, partUri, ranges, policy =
195680
195697
  }
195681
195698
  return { ok: true, value: dependencies };
195682
195699
  }
195683
- var TD34, TE8, MAX_SNAPSHOTS = 64, MAX_RETAINED_BYTES, MAX_BODY_WRAPPER_BYTES, INLINE_NAMES, FORBIDDEN_PROPERTIES, RUN_PROPERTY_NAMES, PARAGRAPH_MARK_PROPERTY_NAMES, REGISTRIES, PARAGRAPH_CHILDREN, INLINE_CONTAINER_CHILDREN, RUN_CHILDREN, PARAGRAPH_PROPERTIES;
195700
+ var TD34, TE8, MAX_SNAPSHOTS = 64, MAX_RETAINED_BYTES, MAX_BODY_WRAPPER_BYTES, OFFICE_MATH_NAMESPACE = "http://schemas.openxmlformats.org/officeDocument/2006/math", INLINE_NAMES, FORBIDDEN_PROPERTIES, RUN_PROPERTY_NAMES, PARAGRAPH_MARK_PROPERTY_NAMES, REGISTRIES, PARAGRAPH_CHILDREN, INLINE_CONTAINER_CHILDREN, RUN_CHILDREN, PARAGRAPH_PROPERTIES;
195684
195701
  var init_paragraph_snapshots = __esm(() => {
195685
195702
  init_relationship();
195686
195703
  init_xml_sax();
@@ -195978,9 +195995,9 @@ function planDirectInlineEdit(paragraphBytes, startOffset, endOffset, newText, c
195978
195995
  if (collapsedObjectBoundary) {
195979
195996
  if (startOffset !== endOffset || newText.length === 0)
195980
195997
  return { ok: false, reason: "invalid-range" };
195981
- const object4 = visibleObjects(leaves)[collapsedObjectBoundary.objectOrdinal];
195982
- const insertByte = collapsedObjectBoundary.edge === "before" ? object4?.runByteStart : object4?.runByteEnd;
195983
- if (insertByte == null || object4?.runCharStart == null || object4.runCharEnd == null) {
195998
+ const object4 = visibleParagraphInlineObjects(model.pieces)[collapsedObjectBoundary.objectOrdinal];
195999
+ const insertByte = object4?.containerKind === "math" ? collapsedObjectBoundary.edge === "before" ? object4.byteStart : object4.byteEnd : collapsedObjectBoundary.edge === "before" ? object4?.runByteStart : object4?.runByteEnd;
196000
+ if (insertByte == null || object4?.containerKind !== "math" && (object4?.runCharStart == null || object4.runCharEnd == null)) {
195984
196001
  return { ok: false, reason: "paste-target-unsupported" };
195985
196002
  }
195986
196003
  const enclosingSdts = findEnclosingSdtContainers(model.pieces, object4);
@@ -196011,7 +196028,7 @@ function planDirectInlineEdit(paragraphBytes, startOffset, endOffset, newText, c
196011
196028
  if (beside)
196012
196029
  return withOpaqueCarrierSessionSync(beside, usesOpaqueCarrierCoordinates);
196013
196030
  }
196014
- const scope = resolveEditScope(model.pieces, startOffset, endOffset, collapsedInlineAffinity, collapsedOutsideContentControl);
196031
+ const scope = resolveEditScope(model.pieces, startOffset, endOffset, collapsedInlineAffinity, collapsedOutsideContentControl, newText.length === 0);
196015
196032
  if (!scope.ok)
196016
196033
  return { ok: false, reason: scope.reason };
196017
196034
  const pieces = scope.pieces;
@@ -196213,9 +196230,6 @@ function sameFastBatchTextScope(left, right) {
196213
196230
  return false;
196214
196231
  return left.containerStack.every((scope, index) => scope === right.containerStack[index]);
196215
196232
  }
196216
- function visibleObjects(pieces) {
196217
- return pieces.filter((piece) => piece.kind === "container" && (piece.containerKind === "drawing" || piece.containerKind === "pict" || piece.containerKind === "object") && !piece.containerStack.some((scope) => scope.deleted));
196218
- }
196219
196233
  function findEnclosingSdtContainers(pieces, target) {
196220
196234
  const containers = [];
196221
196235
  for (const piece of pieces) {
@@ -196702,13 +196716,27 @@ function validateSelectedSdtProtection(pieces, start, end) {
196702
196716
  }
196703
196717
  return null;
196704
196718
  }
196705
- function resolveEditScope(pieces, start, end, collapsedInlineAffinity, collapsedOutsideContentControl = false) {
196719
+ function resolveEditScope(pieces, start, end, collapsedInlineAffinity, collapsedOutsideContentControl = false, allowWholeMathDelete = false) {
196706
196720
  let current = pieces;
196707
196721
  let descended = false;
196708
196722
  let emptySdt;
196709
196723
  let requiresCollaborationSessionSync = false;
196710
196724
  for (;; ) {
196711
196725
  const container = start === end ? findCaretContainer(current, start, collapsedInlineAffinity, collapsedOutsideContentControl) : current.find((piece) => piece.kind === "container" && containerContainsRange(piece, start, end));
196726
+ if (container?.containerKind === "math" && allowWholeMathDelete && start === container.visibleStart && end === container.visibleEnd) {
196727
+ const removeRun = container.runCharStart != null && container.runCharEnd != null;
196728
+ return {
196729
+ ok: true,
196730
+ pieces: current.filter((piece) => piece !== container),
196731
+ descended,
196732
+ wrapperRemovalOps: [{
196733
+ start: removeRun ? container.runByteStart : container.byteStart,
196734
+ end: removeRun ? container.runByteEnd : container.byteEnd,
196735
+ bytes: EMPTY
196736
+ }],
196737
+ requiresCollaborationSessionSync: true
196738
+ };
196739
+ }
196712
196740
  if (!container) {
196713
196741
  if (start === end) {
196714
196742
  return {
@@ -203891,9 +203919,9 @@ function splitAnchorContent(anchorXml, pieces, envelope, start, end, collapsedOb
203891
203919
  if (collapsedObjectBoundary) {
203892
203920
  if (start !== end)
203893
203921
  return reject2;
203894
- const object4 = visibleObjects2(pieces)[collapsedObjectBoundary.objectOrdinal];
203895
- const cut = collapsedObjectBoundary.edge === "before" ? object4?.runCharStart : object4?.runCharEnd;
203896
- if (cut == null || object4?.runByteStart == null || object4.runByteEnd == null)
203922
+ const object4 = visibleParagraphInlineObjects(pieces)[collapsedObjectBoundary.objectOrdinal];
203923
+ const cut = object4?.containerKind === "math" ? collapsedObjectBoundary.edge === "before" ? object4.charStart : object4.charEnd : collapsedObjectBoundary.edge === "before" ? object4?.runCharStart : object4?.runCharEnd;
203924
+ if (cut == null || object4?.containerKind !== "math" && (object4?.runByteStart == null || object4.runByteEnd == null))
203897
203925
  return reject2;
203898
203926
  return {
203899
203927
  ok: true,
@@ -203935,6 +203963,9 @@ function splitAnchorContent(anchorXml, pieces, envelope, start, end, collapsedOb
203935
203963
  if (piece.kind === "control" && start <= piece.visibleStart && piece.visibleEnd <= end) {
203936
203964
  continue;
203937
203965
  }
203966
+ if (piece.kind === "container" && piece.containerKind === "math" && start === piece.visibleStart && end === piece.visibleEnd && !piece.containerStack.some((scope) => scope.deleted)) {
203967
+ continue;
203968
+ }
203938
203969
  return reject2;
203939
203970
  }
203940
203971
  const headBoundary = splitHeadPiece ? splitHeadPiece.runCharStart : boundaryEnd(lastHeadPiece, envelope);
@@ -203977,9 +204008,6 @@ function trackedOffsetAtVisible(paragraphXml, visibleOffset) {
203977
204008
  }
203978
204009
  return tracked;
203979
204010
  }
203980
- function visibleObjects2(pieces) {
203981
- return pieces.filter((piece) => piece.kind === "container" && (piece.containerKind === "drawing" || piece.containerKind === "pict" || piece.containerKind === "object") && !piece.containerStack.some((scope) => scope.deleted));
203982
- }
203983
204011
  function boundaryEnd(piece, envelope) {
203984
204012
  if (!piece)
203985
204013
  return envelope.innerStart;
@@ -204071,12 +204099,12 @@ function withTrackedRsid(openTag, rsid) {
204071
204099
  }
204072
204100
  return openTag.replace(/>$/, ` w:rsidR="${rsid}">`);
204073
204101
  }
204074
- function planNativeInlineSplice(anchorXml, inlineXml, start, end) {
204075
- const map3 = parseParagraphInlineMap(anchorXml);
204102
+ function planNativeInlineSplice(anchorXml, inlineXml, start, end, collapsedObjectBoundary, namespaceBindings = {}) {
204103
+ const map3 = parseParagraphInlineMap(anchorXml, namespaceBindings);
204076
204104
  const envelope = parseParagraphEnvelope(anchorXml);
204077
204105
  if (!envelope || !Number.isInteger(start) || !Number.isInteger(end) || start < 0 || end < start || end > map3.visibleLength)
204078
204106
  return { ok: false, reason: "invalid-range" };
204079
- const split = splitAnchorContent(anchorXml, map3.pieces, envelope, start, end);
204107
+ const split = splitAnchorContent(anchorXml, map3.pieces, envelope, start, end, collapsedObjectBoundary);
204080
204108
  if (!split.ok)
204081
204109
  return split;
204082
204110
  return { ok: true, xml: envelope.open + envelope.pPr + split.headXml + inlineXml + split.tailXml + envelope.close };
@@ -218602,9 +218630,9 @@ function rewriteRunSpanTrackedReplace(paragraphXml, startOffset, endOffset, stam
218602
218630
  if (!collected.ok)
218603
218631
  return collected;
218604
218632
  if (collapsedObjectBoundary) {
218605
- const object4 = parseParagraphInlineMap(paragraphXml).leaves().filter((piece) => piece.kind === "container" && (piece.containerKind === "drawing" || piece.containerKind === "pict" || piece.containerKind === "object") && !piece.containerStack.some((scope) => scope.deleted))[collapsedObjectBoundary.objectOrdinal];
218606
- const insertChar = collapsedObjectBoundary.edge === "before" ? object4?.runCharStart : object4?.runCharEnd;
218607
- if (insertChar == null || object4?.runByteStart == null || object4.runByteEnd == null) {
218633
+ const object4 = visibleParagraphInlineObjects(parseParagraphInlineMap(paragraphXml).pieces)[collapsedObjectBoundary.objectOrdinal];
218634
+ const insertChar = object4?.containerKind === "math" ? collapsedObjectBoundary.edge === "before" ? object4.charStart : object4.charEnd : collapsedObjectBoundary.edge === "before" ? object4?.runCharStart : object4?.runCharEnd;
218635
+ if (insertChar == null || object4?.containerKind !== "math" && (object4?.runByteStart == null || object4.runByteEnd == null)) {
218608
218636
  return { ok: false, reason: "paste-target-unsupported" };
218609
218637
  }
218610
218638
  const precedingCarrier = [...collected.runs].reverse().find((run) => run.textEnd === startOffset);
@@ -221756,26 +221784,28 @@ function sliceParagraphContentAt(input) {
221756
221784
  }
221757
221785
  function pieceStart(piece, input, rootPieces) {
221758
221786
  const base2 = input.space === "tracked" ? piece.trackedStart : piece.visibleStart;
221759
- return base2 + atomicCaretSlotsBefore(rootPieces, piece.charStart, input);
221787
+ return base2 + atomicCaretDeltaBefore(rootPieces, piece.charStart, input);
221760
221788
  }
221761
221789
  function pieceEnd(piece, input, rootPieces) {
221762
221790
  const base2 = input.space === "tracked" ? piece.trackedEnd : piece.visibleEnd;
221763
- return base2 + atomicCaretSlotsBefore(rootPieces, piece.charEnd, input);
221791
+ return base2 + atomicCaretDeltaBefore(rootPieces, piece.charEnd, input);
221764
221792
  }
221765
221793
  function coordinateLength(pieces, input) {
221766
221794
  const base2 = input.space === "tracked" ? Math.max(0, ...pieces.map((piece) => piece.trackedEnd)) : Math.max(0, ...pieces.map((piece) => piece.visibleEnd));
221767
- return base2 + atomicCaretSlotsBefore(pieces, Number.POSITIVE_INFINITY, input);
221795
+ return base2 + atomicCaretDeltaBefore(pieces, Number.POSITIVE_INFINITY, input);
221768
221796
  }
221769
- function atomicCaretSlotsBefore(pieces, charOffset, input) {
221797
+ function atomicCaretDeltaBefore(pieces, charOffset, input) {
221770
221798
  if (input.atomicObjectsAsCaretSlots !== true)
221771
221799
  return 0;
221772
221800
  let count = 0;
221773
221801
  for (const piece of pieces) {
221774
221802
  if (isCaretSlotAtomic(piece, input) && piece.charEnd <= charOffset) {
221775
- count += 1;
221803
+ const sourceLength = input.space === "tracked" ? piece.trackedEnd - piece.trackedStart : piece.visibleEnd - piece.visibleStart;
221804
+ count += 1 - sourceLength;
221805
+ continue;
221776
221806
  }
221777
221807
  if ((piece.kind === "container" || piece.kind === "tracked") && piece.children.length > 0) {
221778
- count += atomicCaretSlotsBefore(piece.children, charOffset, input);
221808
+ count += atomicCaretDeltaBefore(piece.children, charOffset, input);
221779
221809
  }
221780
221810
  }
221781
221811
  return count;
@@ -221785,7 +221815,9 @@ function isCaretSlotAtomic(piece, input) {
221785
221815
  return false;
221786
221816
  if (piece.policy !== "atomic")
221787
221817
  return false;
221788
- if (piece.containerKind !== "drawing" && piece.containerKind !== "object" && piece.containerKind !== "pict") {
221818
+ if (piece.containerKind === "math" && !input.atomicMathAsCaretSlots)
221819
+ return false;
221820
+ if (piece.containerKind !== "drawing" && piece.containerKind !== "object" && piece.containerKind !== "pict" && piece.containerKind !== "math") {
221789
221821
  return false;
221790
221822
  }
221791
221823
  return input.space === "tracked" || !piece.containerStack.some((scope) => scope.deleted);
@@ -224503,7 +224535,7 @@ function resolveIsolatedImageCarrier(input) {
224503
224535
  if (ancestorPath == null || ancestorPath.some((piece) => piece.kind !== "container" || piece.containerKind !== "hyperlink")) {
224504
224536
  return null;
224505
224537
  }
224506
- const visibleOffset = drawingPiece.visibleStart + atomicCaretSlotsBefore2(inlineMap.pieces, drawingPiece.charStart);
224538
+ const visibleOffset = drawingPiece.visibleStart + atomicCaretSlotsBefore(inlineMap.pieces, drawingPiece.charStart);
224507
224539
  const runRe = /<([\w.-]+):r\b[^>]*>[\s\S]*?<\/\1:r>/g;
224508
224540
  let match;
224509
224541
  while ((match = runRe.exec(input.paragraphXml)) != null) {
@@ -224579,14 +224611,14 @@ function wrapCarrierWithAncestors(carrierXml, ancestors, paragraphXml) {
224579
224611
  }
224580
224612
  return wrapped;
224581
224613
  }
224582
- function atomicCaretSlotsBefore2(pieces, charOffset) {
224614
+ function atomicCaretSlotsBefore(pieces, charOffset) {
224583
224615
  let count = 0;
224584
224616
  for (const piece of pieces) {
224585
224617
  const isVisibleAtomic = piece.kind === "container" && piece.policy === "atomic" && (piece.containerKind === "drawing" || piece.containerKind === "object" || piece.containerKind === "pict") && !piece.containerStack.some((scope) => scope.deleted);
224586
224618
  if (isVisibleAtomic && piece.charEnd <= charOffset)
224587
224619
  count += 1;
224588
224620
  if ((piece.kind === "container" || piece.kind === "tracked") && piece.children.length > 0) {
224589
- count += atomicCaretSlotsBefore2(piece.children, charOffset);
224621
+ count += atomicCaretSlotsBefore(piece.children, charOffset);
224590
224622
  }
224591
224623
  }
224592
224624
  return count;
@@ -229665,6 +229697,7 @@ function prepareParagraphSplit(input) {
229665
229697
  space: input.coordinateSpace,
229666
229698
  allocateWId: input.allocateWId,
229667
229699
  atomicObjectsAsCaretSlots: true,
229700
+ atomicMathAsCaretSlots: input.offsetSpace === "selection",
229668
229701
  onRevisionWrapperClone: input.onRevisionWrapperClone,
229669
229702
  allowMetadataAnchorSplit: true,
229670
229703
  knownMetadataAnchorIds: new Set(input.knownMetadataAnchorIds),
@@ -229841,6 +229874,7 @@ function runParagraphSplitCommit(input) {
229841
229874
  paragraphByteStart: target.entry.byteStart,
229842
229875
  offset: op.offset,
229843
229876
  coordinateSpace: op.coordinateSpace ?? "visible",
229877
+ offsetSpace: op.offsetSpace,
229844
229878
  knownMetadataAnchorIds: op.knownMetadataAnchorIds,
229845
229879
  onMetadataAnchorClone: (id, originalId, cloneId) => metadataClones.push({ id, originalId, cloneId }),
229846
229880
  onRevisionWrapperClone: (clone3) => revisionWrapperClones.push(clone3),
@@ -229880,6 +229914,7 @@ function runParagraphSplitCommit(input) {
229880
229914
  paragraphByteStart: context.byteStart,
229881
229915
  offset: op.offset,
229882
229916
  coordinateSpace: op.coordinateSpace ?? "visible",
229917
+ offsetSpace: op.offsetSpace,
229883
229918
  knownMetadataAnchorIds: op.knownMetadataAnchorIds,
229884
229919
  tailParaId,
229885
229920
  allocateWId: () => {
@@ -235535,9 +235570,16 @@ function readNativeRoots(xml, namespaces) {
235535
235570
  fragment: true,
235536
235571
  additionalNamespaces: { ...namespaces }
235537
235572
  });
235538
- if (parsed.errors.length || parsed.ranges.length > 50000)
235573
+ if (parsed.errors.length)
235539
235574
  return fail4();
235540
- const roots = parsed.ranges.filter((r) => !parsed.ranges.some((p) => p !== r && p.start < r.start && p.end > r.end));
235575
+ const roots = [];
235576
+ let coveredEnd = -1;
235577
+ for (const range of [...parsed.ranges].sort((a, b) => a.start - b.start)) {
235578
+ if (range.start < coveredEnd)
235579
+ continue;
235580
+ roots.push(range);
235581
+ coveredEnd = range.end;
235582
+ }
235541
235583
  let end = 0;
235542
235584
  for (const root of roots) {
235543
235585
  if (xml.slice(end, root.start).trim())
@@ -235581,7 +235623,7 @@ function planNativeOoxmlImport(state, source, txId, basePerPart = {}) {
235581
235623
  "commentRangeStart",
235582
235624
  "commentRangeEnd",
235583
235625
  "fldSimple"
235584
- ].includes(r.tag.localName));
235626
+ ].includes(r.tag.localName) || math(r) && ["oMath", "oMathPara"].includes(r.tag.localName));
235585
235627
  if (!inline && !roots.value.every((r) => word3(r) && ["p", "tbl"].includes(r.tag.localName)))
235586
235628
  return fail4();
235587
235629
  if (inline && !validateRetainableParagraphXml(`<w:p xmlns:w="${NS_W}">${source.xml}</w:p>`, source.namespaces).ok)
@@ -235652,8 +235694,9 @@ function planNativeOoxmlImport(state, source, txId, basePerPart = {}) {
235652
235694
  if (!map3.has(key3)) {
235653
235695
  let value;
235654
235696
  do {
235655
- value = sha256HexSync(TE28.encode(`${txId}:${++sequence}:${key3}`)).slice(0, 8).toUpperCase();
235656
- } while (occupiedHex.has(value));
235697
+ const digest = sha256HexSync(TE28.encode(`${txId}:${++sequence}:${key3}`)).slice(0, 8);
235698
+ value = (map3 === paraIds ? (Number.parseInt(digest, 16) & 2147483647).toString(16).padStart(8, "0") : digest).toUpperCase();
235699
+ } while (occupiedHex.has(value) || map3 === paraIds && value === "00000000");
235657
235700
  occupiedHex.add(value);
235658
235701
  map3.set(key3, value);
235659
235702
  }
@@ -235774,7 +235817,7 @@ function planNativeOoxmlImport(state, source, txId, basePerPart = {}) {
235774
235817
  });
235775
235818
  if (collected.errors.length)
235776
235819
  return null;
235777
- let result = xml2;
235820
+ const edits = [];
235778
235821
  for (const range of [...collected.ranges].sort((a, b) => b.start - a.start)) {
235779
235822
  let open2 = xml2.slice(range.start, range.openEnd);
235780
235823
  for (const a of range.tag.attributes) {
@@ -235831,9 +235874,11 @@ function planNativeOoxmlImport(state, source, txId, basePerPart = {}) {
235831
235874
  if (next !== undefined && next !== a.value)
235832
235875
  open2 = replaceAttribute(open2, a, next);
235833
235876
  }
235834
- result = result.slice(0, range.start) + open2 + result.slice(range.openEnd);
235877
+ if (open2 !== xml2.slice(range.start, range.openEnd)) {
235878
+ edits.push({ start: range.start, end: range.openEnd, xml: open2 });
235879
+ }
235835
235880
  }
235836
- return result;
235881
+ return applyXmlEdits(xml2, edits);
235837
235882
  };
235838
235883
  for (const dep of deps) {
235839
235884
  const owner = sourceToDest.get(dep.sourcePartUri);
@@ -235942,11 +235987,17 @@ function planNativeOoxmlImport(state, source, txId, basePerPart = {}) {
235942
235987
  xml = `<w:p xmlns:w="${NS_W}" xmlns:w14="${W14}" w14:paraId="${mintHex(paraIds, "inline-root")}">${xml}</w:p>`;
235943
235988
  else {
235944
235989
  const all = collectXmlElementRanges(xml, { fragment: true });
235990
+ const edits = [];
235945
235991
  for (const range of [...all.ranges].reverse())
235946
235992
  if (word3(range) && range.tag.localName === "p" && !range.tag.attributes.some((a) => a.namespaceUri === W14 && a.localName === "paraId")) {
235947
235993
  const open2 = xml.slice(range.start, range.openEnd);
235948
- xml = xml.slice(0, range.start) + open2.replace(/\/?\s*>$/, (tail) => `${range.namespaceBindings.w14 === W14 ? "" : ` xmlns:w14="${W14}"`} w14:paraId="${mintHex(paraIds, "paragraph-" + range.start)}"` + tail) + xml.slice(range.openEnd);
235994
+ edits.push({
235995
+ start: range.start,
235996
+ end: range.openEnd,
235997
+ xml: open2.replace(/\/?\s*>$/, (tail) => `${range.namespaceBindings.w14 === W14 ? "" : ` xmlns:w14="${W14}"`} w14:paraId="${mintHex(paraIds, "paragraph-" + range.start)}"` + tail)
235998
+ });
235949
235999
  }
236000
+ xml = applyXmlEdits(xml, edits);
235950
236001
  }
235951
236002
  return {
235952
236003
  ok: true,
@@ -236361,14 +236412,22 @@ function canonicalWordMarkup(xml, namespaces) {
236361
236412
  if (!r.tag.isSelfClosing)
236362
236413
  patches.push({ start: r.closeStart, end: r.end, xml: `</w:${r.tag.localName}>` });
236363
236414
  }
236364
- for (const p of patches.sort((a, b) => b.start - a.start))
236365
- xml = xml.slice(0, p.start) + p.xml + xml.slice(p.end);
236366
- return xml;
236415
+ return applyXmlEdits(xml, patches);
236367
236416
  }
236368
- var TE28, TD57, W14 = "http://schemas.microsoft.com/office/word/2010/wordml", CT_URI = "/[Content_Types].xml", REL_CT = "application/vnd.openxmlformats-package.relationships+xml", fail4 = () => ({
236417
+ function applyXmlEdits(xml, edits) {
236418
+ const pieces = [];
236419
+ let offset = 0;
236420
+ for (const edit of edits.sort((a, b) => a.start - b.start)) {
236421
+ pieces.push(xml.slice(offset, edit.start), edit.xml);
236422
+ offset = edit.end;
236423
+ }
236424
+ pieces.push(xml.slice(offset));
236425
+ return pieces.join("");
236426
+ }
236427
+ var TE28, TD57, W14 = "http://schemas.microsoft.com/office/word/2010/wordml", OFFICE_MATH_NAMESPACE2 = "http://schemas.openxmlformats.org/officeDocument/2006/math", CT_URI = "/[Content_Types].xml", REL_CT = "application/vnd.openxmlformats-package.relationships+xml", fail4 = () => ({
236369
236428
  ok: false,
236370
236429
  reason: "paste-structure-unsupported"
236371
- }), word3 = (r) => r.tag.namespaceUri === NS_W || r.tag.namespaceUri === NS_WSTRICT, attr3 = (r, name) => r.tag.attributes.find((a) => a.localName === name)?.value;
236430
+ }), word3 = (r) => r.tag.namespaceUri === NS_W || r.tag.namespaceUri === NS_WSTRICT, math = (r) => r.tag.namespaceUri === OFFICE_MATH_NAMESPACE2, attr3 = (r, name) => r.tag.attributes.find((a) => a.localName === name)?.value;
236372
236431
  var init_native_ooxml_import = __esm(() => {
236373
236432
  init_xml_sax();
236374
236433
  init_sha256_sync();
@@ -237653,7 +237712,7 @@ function runParagraphContentCommit(input) {
237653
237712
  if (!bound.ok)
237654
237713
  return rejected8(input.txId, bound.reason);
237655
237714
  if (op.action.kind === "ooxml" && op.action.range) {
237656
- const splice = planNativeInlineSplice(current.xml, bound.xml, op.action.range.start, op.action.range.end);
237715
+ const splice = planNativeInlineSplice(current.xml, bound.xml, op.action.range.start, op.action.range.end, op.action.range.collapsedObjectBoundary, current.namespaceBindings);
237657
237716
  if (!splice.ok)
237658
237717
  return rejected8(input.txId, splice.reason);
237659
237718
  nextXml = splice.xml;
@@ -250327,12 +250386,12 @@ function hasSessionSyncStructuralInlineDeletion(xml, fragments, namespaceBinding
250327
250386
  walkXmlElements(xml, {
250328
250387
  additionalNamespaces: xmlFragmentAdditionalNamespaces(xml, namespaceBindings, {
250329
250388
  w: NS_W,
250330
- m: OFFICE_MATH_NAMESPACE
250389
+ m: OFFICE_MATH_NAMESPACE3
250331
250390
  }),
250332
250391
  onOpenTag({ tag, start, end }) {
250333
250392
  if (matched || !isInsideSelectedDeletion(start, end))
250334
250393
  return;
250335
- matched = tag.namespaceUri === NS_W ? tag.localName === "smartTag" || tag.localName === "dir" || tag.localName === "bdo" || tag.localName === "lastRenderedPageBreak" : tag.namespaceUri === OFFICE_MATH_NAMESPACE && tag.localName === "oMath";
250394
+ matched = tag.namespaceUri === NS_W ? tag.localName === "smartTag" || tag.localName === "dir" || tag.localName === "bdo" || tag.localName === "lastRenderedPageBreak" : tag.namespaceUri === OFFICE_MATH_NAMESPACE3 && tag.localName === "oMath";
250336
250395
  }
250337
250396
  });
250338
250397
  return matched;
@@ -250370,7 +250429,7 @@ function hasSessionSyncAdjacentRevisionDecision(xml, fragments, decision, namesp
250370
250429
  }
250371
250430
  return false;
250372
250431
  }
250373
- var OFFICE_MATH_NAMESPACE = "http://schemas.openxmlformats.org/officeDocument/2006/math";
250432
+ var OFFICE_MATH_NAMESPACE3 = "http://schemas.openxmlformats.org/officeDocument/2006/math";
250374
250433
  var init_structural_inline_decision = __esm(() => {
250375
250434
  init_xml_sax();
250376
250435
  });
@@ -283263,6 +283322,68 @@ async function serializeSDDocumentSessionInternalPackageToSinkAsync(session, sin
283263
283322
  }
283264
283323
  return saveSourceBackedStreamingToSink(internal, reader.partUri, sink, options);
283265
283324
  }
283325
+ function readRemoteParagraphBytes(state, storyId) {
283326
+ const index = getStoryParagraphIndexFromState(state, storyId);
283327
+ if (!index)
283328
+ return null;
283329
+ const first = index.entries[0];
283330
+ const head = first ? readPartRangeFromStateSync(state, first.partUri, 0, first.byteStart) : null;
283331
+ if (first && !head)
283332
+ return null;
283333
+ const declarations = head ? new TextDecoder().decode(head).matchAll(/xmlns(?::([A-Za-z_][\w.-]*))?="([^"]*)"/g) : [];
283334
+ const namespaceBindings = createCanonicalXmlNamespaceBindings([...declarations].map((match) => [match[1] ?? "", match[2]]));
283335
+ const paragraphs2 = new Map;
283336
+ for (const entry of index.entries) {
283337
+ const bytes = readPartRangeFromStateSync(state, entry.partUri, entry.byteStart, entry.byteEnd);
283338
+ if (!bytes)
283339
+ return null;
283340
+ const ambiguous = paragraphs2.has(entry.blockId) || index.duplicateParaIds.has(entry.blockId);
283341
+ paragraphs2.set(entry.blockId, ambiguous ? null : bytes);
283342
+ }
283343
+ return { paragraphs: paragraphs2, namespaceBindings };
283344
+ }
283345
+ function sameRemoteParagraphText(before, beforeBindings, after, afterBindings) {
283346
+ try {
283347
+ const decoder7 = new TextDecoder;
283348
+ const previous = parseParagraphInlineMap(decoder7.decode(before), beforeBindings);
283349
+ const next = parseParagraphInlineMap(decoder7.decode(after), afterBindings);
283350
+ return previous.visibleText() === next.visibleText() && previous.trackedText() === next.trackedText();
283351
+ } catch {
283352
+ return false;
283353
+ }
283354
+ }
283355
+ function listParagraphIdsInWholeBlocks(blockWindows) {
283356
+ const decoder7 = new TextDecoder;
283357
+ const blockIds = new Set;
283358
+ for (const blockWindow of blockWindows) {
283359
+ const xml = decoder7.decode(blockWindow).trim();
283360
+ const wholeBlocks = /^<w:(p|tbl|sdt)[\s>/]/.test(xml) && /(<\/w:(p|tbl|sdt)>|\/>)$/.test(xml);
283361
+ if (xml && !wholeBlocks)
283362
+ return null;
283363
+ for (const open2 of xml.matchAll(/<w:p(?=[\s>/])[^>]*>/g)) {
283364
+ const paraId = open2[0].match(/w14:paraId="([^"]+)"/)?.[1];
283365
+ if (!paraId)
283366
+ return null;
283367
+ blockIds.add(paraId);
283368
+ }
283369
+ }
283370
+ return [...blockIds];
283371
+ }
283372
+ function listChangedRemoteParagraphs(before, after) {
283373
+ const sameBytes2 = (left, right) => left.byteLength === right.byteLength && left.every((value, index) => value === right[index]);
283374
+ const changed = new Set;
283375
+ for (const [blockId, previous] of before.paragraphs) {
283376
+ const next = after.paragraphs.get(blockId);
283377
+ if (!previous || !next)
283378
+ changed.add(blockId);
283379
+ else if (!sameBytes2(previous, next) && !sameRemoteParagraphText(previous, before.namespaceBindings, next, after.namespaceBindings))
283380
+ changed.add(blockId);
283381
+ }
283382
+ for (const [blockId, next] of after.paragraphs)
283383
+ if (!next || !before.paragraphs.has(blockId))
283384
+ changed.add(blockId);
283385
+ return [...changed];
283386
+ }
283266
283387
  function applySDDocumentSessionInternalProjection(session, input) {
283267
283388
  const internal = INTERNALS.get(session);
283268
283389
  if (!internal)
@@ -283310,6 +283431,10 @@ function applySDDocumentSessionInternalProjection(session, input) {
283310
283431
  });
283311
283432
  const remoteParagraphInput = !input.packageReplaced && inventoryUnchanged && requestedChangedPartUris.size === 1 && requestedChangedStoryIds.size === 1 && textPart?.bytes === null && textPart.patches?.length === 1 && textStory?.storyKind === "main" && textStory.partUri === textPart.partUri ? { storyId: textStory.storyId, partUri: textPart.partUri, patch: textPart.patches[0] } : null;
283312
283433
  const remoteTextInput = remoteParagraphInput ? captureSDRemoteTextRenderInput(state, remoteParagraphInput.storyId, remoteParagraphInput.partUri, remoteParagraphInput.patch) : null;
283434
+ const mainStoryRemoteChange = !input.packageReplaced && inventoryUnchanged && requestedChangedPartUris.size === 1 && requestedChangedStoryIds.size === 1 && textStory?.storyKind === "main" && textStory.storyId === state.mainStoryId && textPart !== undefined && textStory.partUri === textPart.partUri ? textStory.storyId : null;
283435
+ const wholeStoryRemoteChange = mainStoryRemoteChange && textPart?.bytes ? mainStoryRemoteChange : null;
283436
+ const paragraphsBeforeRemoteChange = wholeStoryRemoteChange ? readRemoteParagraphBytes(state, wholeStoryRemoteChange) : null;
283437
+ const patchedRemoteWindows = mainStoryRemoteChange && !textPart?.bytes && textPart?.patches?.length ? textPart.patches.map((patch) => readPartRangeFromStateSync(state, textPart.partUri, patch.startByte, patch.endByte)) : null;
283313
283438
  const publishRemoteParagraph = inventoryUnchanged ? remoteParagraphCandidate : null;
283314
283439
  const publishRemoteResidentParagraph = inventoryUnchanged && remoteParagraphInput ? captureRemoteResidentParagraphPublication(state, remoteParagraphInput.storyId, remoteParagraphInput.partUri, remoteParagraphInput.patch) : null;
283315
283440
  const coverageHints = new Map;
@@ -283527,6 +283652,10 @@ function applySDDocumentSessionInternalProjection(session, input) {
283527
283652
  const remoteGeneration = (REMOTE_PROJECTION_GENERATIONS.get(session) ?? 0) + 1;
283528
283653
  REMOTE_PROJECTION_GENERATIONS.set(session, remoteGeneration);
283529
283654
  const remoteText = remoteTextInput && changedStoryIds.size === 1 && changedPartUris.size === 1 ? sealSDRemoteTextRenderInput(state, remoteTextInput) : null;
283655
+ const paragraphsAfterRemoteChange = wholeStoryRemoteChange && paragraphsBeforeRemoteChange && changedStoryIds.size === 1 && changedStoryIds.has(wholeStoryRemoteChange) && changedPartUris.size === 1 ? readRemoteParagraphBytes(state, wholeStoryRemoteChange) : null;
283656
+ const remoteChangeIsNarrow = remoteText?.classification != null;
283657
+ const remoteChangedParagraphs = wholeStoryRemoteChange && paragraphsBeforeRemoteChange && paragraphsAfterRemoteChange ? { storyId: wholeStoryRemoteChange, blockIds: listChangedRemoteParagraphs(paragraphsBeforeRemoteChange, paragraphsAfterRemoteChange) } : null;
283658
+ const patchedRemoteParagraphs = !remoteChangedParagraphs && mainStoryRemoteChange && patchedRemoteWindows && !remoteChangeIsNarrow && patchedRemoteWindows.every((blockWindow) => blockWindow !== null) && changedStoryIds.size === 1 && changedStoryIds.has(mainStoryRemoteChange) && changedPartUris.size === 1 ? listParagraphIdsInWholeBlocks([...patchedRemoteWindows, ...textPart.patches.map((patch) => patch.bytes)]) : null;
283530
283659
  return snapshotSDRenderCommitEnvelope({
283531
283660
  documentEpoch: state.documentRef.documentId,
283532
283661
  commitSequence: state.renderCommitSequence,
@@ -283551,7 +283680,8 @@ function applySDDocumentSessionInternalProjection(session, input) {
283551
283680
  ...remoteText ? { localizedBodyText: remoteText.localizedBodyText } : {}
283552
283681
  },
283553
283682
  ...remoteText ? { sourceProjectionEffect: remoteText.sourceProjectionEffect } : {},
283554
- remote: { generation: remoteGeneration }
283683
+ remote: { generation: remoteGeneration },
283684
+ ...remoteChangedParagraphs && !input.packageReplaced ? { remoteChangedParagraphs } : patchedRemoteParagraphs && mainStoryRemoteChange && !input.packageReplaced ? { remoteChangedParagraphs: { storyId: mainStoryRemoteChange, blockIds: patchedRemoteParagraphs } } : {}
283555
283685
  });
283556
283686
  }
283557
283687
  function validateSDDocumentSessionInternalPackageBytes(bytes) {
@@ -320259,18 +320389,34 @@ function preparePaintedOffsets(paraXml, namespaceBindings = {}, model = parsePar
320259
320389
  toPaintedOffset(offset, affinity = "after") {
320260
320390
  let shift = 0;
320261
320391
  for (const run of objects) {
320262
- if (run.kernelStart > offset || run.kernelStart === offset && affinity === "before")
320392
+ if (offset < run.kernelStart)
320263
320393
  break;
320264
- shift++;
320394
+ if (run.kernelLength > 0) {
320395
+ if (offset === run.kernelStart)
320396
+ return run.paintedStart;
320397
+ if (offset < run.kernelStart + run.kernelLength) {
320398
+ return run.paintedStart + (affinity === "after" ? 1 : 0);
320399
+ }
320400
+ } else if (offset === run.kernelStart && affinity === "before") {
320401
+ return run.paintedStart;
320402
+ }
320403
+ shift += 1 - run.kernelLength;
320265
320404
  }
320266
320405
  return offset + shift;
320267
320406
  },
320268
320407
  toPaintedTrackedOffset(offset, affinity = "after") {
320269
320408
  let shift = 0;
320270
320409
  for (const run of objects) {
320271
- if (run.trackedStart > offset || run.trackedStart === offset && affinity === "before")
320410
+ if (offset < run.trackedStart)
320411
+ break;
320412
+ if (run.trackedLength > 0) {
320413
+ if (offset === run.trackedStart)
320414
+ return offset + shift;
320415
+ if (offset < run.trackedStart + run.trackedLength)
320416
+ return run.trackedStart + shift + (affinity === "after" ? 1 : 0);
320417
+ } else if (offset === run.trackedStart && affinity === "before")
320272
320418
  break;
320273
- shift++;
320419
+ shift += 1 - run.trackedLength;
320274
320420
  }
320275
320421
  return offset + shift;
320276
320422
  },
@@ -320298,7 +320444,7 @@ function preparePaintedOffsets(paraXml, namespaceBindings = {}, model = parsePar
320298
320444
  const last2 = runs.at(-1);
320299
320445
  return last2 ? last2.kernelStart + last2.kernelLength : 0;
320300
320446
  }
320301
- return run.objectOrdinal === null ? run.kernelStart + Math.max(0, offset - run.paintedStart) : run.kernelStart;
320447
+ return run.objectOrdinal === null ? run.kernelStart + Math.max(0, offset - run.paintedStart) : run.kernelStart + (offset > run.paintedStart ? run.kernelLength : 0);
320302
320448
  },
320303
320449
  caretObjectBoundary(offset) {
320304
320450
  const run = objects[lowerBound(objects, offset, "end")];
@@ -320334,31 +320480,32 @@ function paintedToKernelOffset(paraXml, paintedOffset) {
320334
320480
  }
320335
320481
  function paintedRuns(map3) {
320336
320482
  const runs = [];
320337
- let objectOrdinal = 0;
320338
- let paintedObjectCount = 0;
320339
- for (const piece of map3.leaves()) {
320340
- const isObject2 = isVisibleObject(piece);
320341
- const ordinal = isObject2 ? objectOrdinal++ : null;
320483
+ const ordinals = new Map(visibleParagraphInlineObjects(map3.pieces).map((piece, ordinal) => [piece, ordinal]));
320484
+ let paintedDelta = 0;
320485
+ for (const piece of paintedPieces(map3.pieces)) {
320486
+ const ordinal = ordinals.get(piece);
320487
+ const isObject2 = ordinal !== undefined;
320342
320488
  const isPaintedObject = isObject2 && (map3.visibleLength === 0 || !isFloatingDrawing(piece));
320343
320489
  const kernelLength = piece.visibleEnd - piece.visibleStart;
320344
320490
  if (!isPaintedObject && kernelLength === 0)
320345
320491
  continue;
320346
320492
  runs.push({
320347
- paintedStart: piece.visibleStart + paintedObjectCount,
320493
+ paintedStart: piece.visibleStart + paintedDelta,
320348
320494
  paintedLength: isPaintedObject ? 1 : kernelLength,
320349
320495
  kernelStart: piece.visibleStart,
320350
320496
  trackedStart: piece.trackedStart,
320497
+ trackedLength: piece.trackedEnd - piece.trackedStart,
320351
320498
  kernelLength,
320352
320499
  objectOrdinal: isPaintedObject ? ordinal : null,
320353
320500
  ...isPaintedObject ? { objectSource: { byteStart: piece.byteStart, byteEnd: piece.byteEnd } } : {}
320354
320501
  });
320355
320502
  if (isPaintedObject)
320356
- paintedObjectCount++;
320503
+ paintedDelta += 1 - kernelLength;
320357
320504
  }
320358
320505
  return runs;
320359
320506
  }
320360
- function isVisibleObject(piece) {
320361
- return piece.kind === "container" && (piece.containerKind === "drawing" || piece.containerKind === "pict" || piece.containerKind === "object") && !piece.containerStack.some((scope) => scope.deleted);
320507
+ function paintedPieces(pieces) {
320508
+ return pieces.flatMap((piece) => piece.kind === "container" && piece.containerKind === "math" ? [piece] : ("children" in piece) && piece.children.length ? paintedPieces(piece.children) : [piece]);
320362
320509
  }
320363
320510
  function isFloatingDrawing(piece) {
320364
320511
  if (piece.kind !== "container")
@@ -320483,7 +320630,7 @@ function prepareSelectionTargetResolution(input) {
320483
320630
  });
320484
320631
  const kernelTextLength = coordinateSpace === "tracked" ? offsetMap.totalChars() : entry.textLength;
320485
320632
  const paraXml = coordinateSpace === "visible" && input.offsetSpace === "selection" ? SELECTION_TARGET_TD.decode(paragraphBytes) : "";
320486
- const objectRuns = (paraXml.match(/<[\w.-]+:(?:drawing|pict|object)\b/g) ?? []).length;
320633
+ const objectRuns = (paraXml.match(/<[\w.-]+:(?:drawing|pict|object|oMath)\b/g) ?? []).length;
320487
320634
  const namespaceBytes = objectRuns > 0 && !input.namespaceBindings ? fullBytes ?? input.readPartBytes(entry.partUri) : fullBytes;
320488
320635
  const painted = objectRuns > 0 ? preparePaintedOffsets(paraXml, namespaceBytes ? partRootNamespaceBindings(namespaceBytes) : input.namespaceBindings ?? {}) : null;
320489
320636
  const originalStart = target.start.offset;
@@ -368014,8 +368161,8 @@ function* serializeSelectionRangeSteps(context, target, includeHtml, options) {
368014
368161
  const map3 = parseParagraphInlineMap(paragraphXml);
368015
368162
  const isStartEndpoint = entry.ordinal === startEntry.ordinal;
368016
368163
  const isEndEndpoint = entry.ordinal === endEntry.ordinal;
368017
- const objectPieces = map3.leaves().filter(isVisibleZeroWidthObjectPiece);
368018
- const paintedLength = map3.visibleLength + objectPieces.length;
368164
+ const objectPieces = visibleParagraphInlineObjects(map3.pieces);
368165
+ const paintedLength = preparePaintedOffsets(paragraphXml, {}, map3).totalLength;
368019
368166
  let from = options?.selectedBlockIds ? 0 : isStartEndpoint ? startPoint.offset : 0;
368020
368167
  let to = options?.selectedBlockIds ? map3.visibleLength : isEndEndpoint ? endPoint.offset : map3.visibleLength;
368021
368168
  let selectedObjectOrdinals = null;
@@ -368058,6 +368205,9 @@ function* serializeSelectionRangeSteps(context, target, includeHtml, options) {
368058
368205
  message: "selection offsets exceed paragraph text."
368059
368206
  };
368060
368207
  }
368208
+ if (objectPieces.some((piece, ordinal) => piece.containerKind === "math" && (selectedObjectOrdinals?.has(ordinal) || options?.wholeParagraphs || piece.visibleStart < to && piece.visibleEnd > from))) {
368209
+ return { ok: false, code: "CAPABILITY_UNAVAILABLE", message: "Equation clipboard serialization is unsupported; use selection.extractOoxml for native source." };
368210
+ }
368061
368211
  const commentRanges = collectCommentRanges(map3.leaves());
368062
368212
  const review = {
368063
368213
  commentRanges,
@@ -372614,7 +372764,7 @@ function resolveCrossCellDeletePlan(deps, index2, target) {
372614
372764
  if (!context?.hasObjectAnchor)
372615
372765
  continue;
372616
372766
  const paragraphXml = TD100.decode(bytes.subarray(entry.byteStart, entry.byteEnd));
372617
- const objects = visibleObjects3(paragraphXml);
372767
+ const objects = visibleObjects(paragraphXml);
372618
372768
  let ordinals;
372619
372769
  if (entry.blockId === head.entry.blockId) {
372620
372770
  if (!head.objectBoundary && objects.some((object4) => object4.visibleStart === head.offset)) {
@@ -372751,7 +372901,7 @@ function resolveSelectedImages(deps, selected) {
372751
372901
  });
372752
372902
  }
372753
372903
  const paragraphXml = TD100.decode(bytes.subarray(entry.byteStart, entry.byteEnd));
372754
- const objects = visibleObjects3(paragraphXml);
372904
+ const objects = visibleObjects(paragraphXml);
372755
372905
  const images = selected.ordinals.map((ordinal) => {
372756
372906
  const object4 = objects[ordinal];
372757
372907
  if (!object4)
@@ -372767,8 +372917,8 @@ function resolveSelectedImages(deps, selected) {
372767
372917
  }
372768
372918
  return images.map((image) => image);
372769
372919
  }
372770
- function visibleObjects3(paragraphXml) {
372771
- return Array.from(parseParagraphInlineMap(paragraphXml).leaves()).filter((piece) => piece.kind === "container" && (piece.containerKind === "drawing" || piece.containerKind === "pict" || piece.containerKind === "object") && !piece.containerStack.some((scope) => scope.deleted));
372920
+ function visibleObjects(paragraphXml) {
372921
+ return visibleParagraphInlineObjects(parseParagraphInlineMap(paragraphXml).pieces);
372772
372922
  }
372773
372923
  function clearSegment(deps, segment) {
372774
372924
  const resolved = resolveSegmentDelete(deps, segment);
@@ -374001,6 +374151,12 @@ class V2SelectionMutationAdapter {
374001
374151
  return { success: false, failure: { code: narrowed.error, message: narrowed.message }, resolution };
374002
374152
  if (narrowed.paintedObjectContained)
374003
374153
  return { success: false, failure: { code: "INVALID_CONTEXT", message: "rewrite contains an inline object" }, resolution };
374154
+ if (span.text === "" && this.context.isCollaborativeSession()) {
374155
+ const model = readSDDocumentSessionInternalParagraphInlineModel(this.context.session, narrowed.storyId, narrowed.startBlockId);
374156
+ if (model && visibleParagraphInlineObjects(model.pieces).some((piece) => piece.containerKind === "math" && piece.visibleStart === narrowed.startOffset && piece.visibleEnd === narrowed.endOffset)) {
374157
+ return { success: false, failure: { code: "CAPABILITY_UNAVAILABLE", message: "Equation deletion currently requires a non-collaborative direct mutation." }, resolution };
374158
+ }
374159
+ }
374004
374160
  planned.push({ on: narrowed, newText: span.text, resolution: { ...resolution, text: resolution.text.slice(span.start, span.end) }, resultKey: String(editIndex), owner: edit.ownerStepId ?? "", rewriteIntent: edit.rewriteIntent === true, structuralRewrite });
374005
374161
  }
374006
374162
  }
@@ -374444,8 +374600,17 @@ class V2SelectionMutationAdapter {
374444
374600
  if ("error" in resolved) {
374445
374601
  return failureWithoutResolution(resolved.error, resolved.message);
374446
374602
  }
374447
- if (resolved.paintedObjectContained) {
374448
- return failureWithoutResolution("INVALID_CONTEXT", "selection contains an inline object; the text lane cannot rewrite it.");
374603
+ if (resolved.paintedObjectContained || request.text === "" && (this.context.isCollaborativeSession() || options?.changeMode === "tracked")) {
374604
+ const model = request.text === "" ? readSDDocumentSessionInternalParagraphInlineModel(this.context.session, story.storyId, resolved.startBlockId) : null;
374605
+ const objects = model ? visibleParagraphInlineObjects(model.pieces) : [];
374606
+ const selectedObjects = model && resolved.paintedObjectContained ? preparePaintedOffsets(model.paragraphXml, {}, model).containedObjectOrdinals(resolved.paintedStartOffset, resolved.paintedEndOffset) : [];
374607
+ const completeEquation = objects.some((piece) => piece.containerKind === "math" && piece.visibleStart === resolved.startOffset && piece.visibleEnd === resolved.endOffset && (!resolved.paintedObjectContained || selectedObjects.length === 1 && objects[selectedObjects[0]] === piece));
374608
+ if (completeEquation && (this.context.isCollaborativeSession() || options?.changeMode === "tracked")) {
374609
+ return failureWithoutResolution("CAPABILITY_UNAVAILABLE", "Equation deletion currently requires a non-collaborative direct mutation.");
374610
+ }
374611
+ if (resolved.paintedObjectContained && !completeEquation) {
374612
+ return failureWithoutResolution("INVALID_CONTEXT", "selection contains an inline object; the text lane cannot rewrite it.");
374613
+ }
374449
374614
  }
374450
374615
  const resolveSelectionTargetMs = nowMs6() - resolveSelectionTargetStartedAt;
374451
374616
  const containmentStartedAt = nowMs6();
@@ -386457,11 +386622,13 @@ class V2BlocksAdapter {
386457
386622
  }
386458
386623
  const partBytes = getSDDocumentSessionInternalPartBytes(this.context.session, storyPartUriFromId5(resolved.storyId));
386459
386624
  const paraXml = partBytes ? TD106.decode(partBytes.subarray(resolved.entry.byteStart, resolved.entry.byteEnd)) : "";
386460
- const objectSlack = (paraXml.match(/<[\w.-]+:(?:drawing|pict|object)\b/g) ?? []).length;
386625
+ const model = readSDDocumentSessionInternalParagraphInlineModel(this.context.session, resolved.storyId, resolved.entry.blockId);
386626
+ const offsetSpace = options?.offsetSpace === "selection" ? "selection" : "kernel";
386627
+ const offsetLength = offsetSpace === "selection" ? preparePaintedOffsets(paraXml, {}, model ?? undefined).totalLength : resolved.entry.textLength + (model ? visibleParagraphInlineObjects(model.pieces).filter((piece) => piece.containerKind !== "math").length : 0);
386461
386628
  const coordinateSpace = input.coordinateSpace ?? "visible";
386462
386629
  const metadataAnchorBindings = storyPartUriFromId5(resolved.storyId) === "/word/document.xml" ? listMetadataSplitBindings(this.context, paraXml) : [];
386463
386630
  const knownMetadataAnchorIds = metadataAnchorBindings.map((binding) => binding.id);
386464
- const offset = coordinateSpace === "tracked" ? Math.max(0, Math.trunc(Number.isFinite(input.offset) ? input.offset : 0)) : clampStructuralOffset(input.offset, resolved.entry.textLength + objectSlack);
386631
+ const offset = coordinateSpace === "tracked" ? Math.max(0, Math.trunc(Number.isFinite(input.offset) ? input.offset : 0)) : clampStructuralOffset(input.offset, offsetLength);
386465
386632
  const restoreIndex = options?.changeMode === "tracked" && paragraphMarkHasTrackedMarker(paraXml, "del") && resolved.entry.directBodyChildOrdinal != null ? readParagraphIndexForStory(this.context, resolved.storyId) : null;
386466
386633
  const next = restoreIndex ? paragraphIndexEntryAt(restoreIndex, resolved.entry.ordinal + 1) : null;
386467
386634
  const restore = next && partBytes && next.partUri === resolved.entry.partUri && next.directBodyChildOrdinal === resolved.entry.directBodyChildOrdinal + 1 && !TD106.decode(partBytes.subarray(resolved.entry.byteEnd, next.byteStart)).trim() ? planTrackedListBoundaryRestore({
@@ -386489,6 +386656,7 @@ class V2BlocksAdapter {
386489
386656
  paragraphByteStart: resolved.entry.byteStart,
386490
386657
  offset,
386491
386658
  coordinateSpace,
386659
+ offsetSpace,
386492
386660
  knownMetadataAnchorIds
386493
386661
  });
386494
386662
  if (!restore && !planned.ok)
@@ -386503,6 +386671,7 @@ class V2BlocksAdapter {
386503
386671
  target: { storyId: resolved.storyId, paraId: input.target.nodeId },
386504
386672
  offset,
386505
386673
  coordinateSpace,
386674
+ offsetSpace,
386506
386675
  knownMetadataAnchorIds,
386507
386676
  metadataAnchorBindings,
386508
386677
  changeMode: options?.changeMode ?? "direct"
@@ -386565,7 +386734,8 @@ class V2BlocksAdapter {
386565
386734
  }
386566
386735
  const partBytes = getSDDocumentSessionInternalPartBytes(this.context.session, storyPartUriFromId5(first.storyId));
386567
386736
  const firstParaXml = partBytes ? TD106.decode(partBytes.subarray(first.entry.byteStart, first.entry.byteEnd)) : "";
386568
- const joinOffset = first.entry.textLength + (firstParaXml.match(/<[\w.-]+:(?:drawing|pict|object)\b/g) ?? []).length;
386737
+ const model = readSDDocumentSessionInternalParagraphInlineModel(this.context.session, first.storyId, first.entry.blockId);
386738
+ const joinOffset = options?.offsetSpace === "selection" ? preparePaintedOffsets(firstParaXml, {}, model ?? undefined).totalLength : first.entry.textLength + (model ? visibleParagraphInlineObjects(model.pieces).filter((piece) => piece.containerKind !== "math").length : 0);
386569
386739
  const begun = this.context.beginMutation({ expectedRevision: options?.expectedRevision });
386570
386740
  if ("failure" in begun)
386571
386741
  return failure4(begun.failure.code, begun.failure.message);
@@ -387745,6 +387915,7 @@ function readTailParaId(provisionalToFinal, createdRefs) {
387745
387915
  var TD106, PARAGRAPH_TYPES, TOP_LEVEL_LIST_ROWS_CACHE, PARAGRAPH_CLASSIFICATIONS, MAX_PARAGRAPH_CLASSIFICATIONS = 8192, BLOCK_NUMBERING_CACHE;
387746
387916
  var init_adapter9 = __esm(() => {
387747
387917
  init_sd_document_session_internal();
387918
+ init_painted_offsets();
387748
387919
  init_adapter3();
387749
387920
  init_mutation_guard();
387750
387921
  init_adapter5();
@@ -389170,10 +389341,14 @@ function normalizeOoxml(content3, allocate) {
389170
389341
  if (!range.tag.isSelfClosing)
389171
389342
  edits.push({ start: range.closeStart, end: range.end, xml: `</${name}>` });
389172
389343
  }
389173
- let xml = content3;
389174
- for (const edit of edits.sort((a, b) => b.start - a.start))
389175
- xml = xml.slice(0, edit.start) + edit.xml + xml.slice(edit.end);
389176
- return xml;
389344
+ const pieces = [];
389345
+ let offset = 0;
389346
+ for (const edit of edits.sort((a, b) => a.start - b.start)) {
389347
+ pieces.push(content3.slice(offset, edit.start), edit.xml);
389348
+ offset = edit.end;
389349
+ }
389350
+ pieces.push(content3.slice(offset));
389351
+ return pieces.join("");
389177
389352
  }
389178
389353
  function paragraph3(id, runs) {
389179
389354
  return `<w:p xmlns:w14="${W147}" w14:paraId="${id}">${runs}</w:p>`;
@@ -422440,6 +422615,23 @@ function executeParagraphContentWrite(context, kind, input, options) {
422440
422615
  const story2 = context.resolveFullStoryLocator(target.story ?? { kind: "story", storyType: "body" });
422441
422616
  if ("error" in story2)
422442
422617
  return failure11("INVALID_TARGET", "The selection story is unavailable.");
422618
+ if (range && options?.offsetSpace === "selection") {
422619
+ const model = readSDDocumentSessionInternalParagraphInlineModel(context.session, story2.storyId, target.nodeId, story2.storyByteRange);
422620
+ if (!model)
422621
+ return failure11("TARGET_NOT_FOUND", "The selection paragraph is unavailable.");
422622
+ const painted = preparePaintedOffsets(model.paragraphXml, {}, model);
422623
+ if (range.start < 0 || range.end < range.start || range.end > painted.totalLength)
422624
+ return failure11("INVALID_TARGET", "Selection offsets exceed the paragraph.");
422625
+ const objects = visibleParagraphInlineObjects(model.pieces);
422626
+ if (range.start !== range.end && painted.containedObjectOrdinals(range.start, range.end).some((ordinal) => objects[ordinal]?.containerKind !== "math"))
422627
+ return failure11("CAPABILITY_UNSUPPORTED", "Native replacement of selected inline objects is unsupported.");
422628
+ const boundary = range.start === range.end ? painted.caretObjectBoundary(range.start) : undefined;
422629
+ range = {
422630
+ start: painted.toKernelOffset(range.start),
422631
+ end: painted.toKernelOffset(range.end),
422632
+ ...boundary ? { collapsedObjectBoundary: boundary } : {}
422633
+ };
422634
+ }
422443
422635
  for (const locator of [
422444
422636
  selection.story,
422445
422637
  selection.start.kind === "text" ? selection.start.story : selection.start.node.story,
@@ -422623,6 +422815,7 @@ var init_paragraph_content = __esm(() => {
422623
422815
  init_stories();
422624
422816
  init_text_range_shifts();
422625
422817
  init_rich_fragment_apply();
422818
+ init_painted_offsets();
422626
422819
  init_applied_change_mode();
422627
422820
  });
422628
422821
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superdoc/mcp",
3
- "version": "1.11.0-next.6",
3
+ "version": "1.11.0-next.8",
4
4
  "description": "Model Context Protocol server for SuperDoc, giving an AI agent tools to read and edit .docx files.",
5
5
  "type": "module",
6
6
  "license": "AGPL-3.0",
@@ -24,13 +24,13 @@
24
24
  ],
25
25
  "dependencies": {
26
26
  "@modelcontextprotocol/sdk": "^1.26.0",
27
- "@superdoc/sdk": "2.24.0-next.6",
27
+ "@superdoc/sdk": "2.24.0-next.8",
28
28
  "debug": "^4.4.3",
29
29
  "zod": "^4.3.6"
30
30
  },
31
31
  "devDependencies": {
32
- "superdoc": "2.27.0-next.6",
33
- "@superdoc/docx-engine": "0.26.0-next.6",
32
+ "superdoc": "2.27.0-next.8",
33
+ "@superdoc/docx-engine": "0.26.0-next.8",
34
34
  "@superdoc/document-api": "0.1.0-alpha.0",
35
35
  "@types/bun": "^1.3.8",
36
36
  "@types/node": "22.19.2",