@superdoc/mcp 1.11.0-next.5 → 1.11.0-next.7

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 +213 -88
  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.5";
31633
+ var SDK_VERSION = "2.24.0-next.7";
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);
236416
+ }
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("");
236367
236426
  }
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 = () => ({
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
  });
@@ -320259,18 +320318,34 @@ function preparePaintedOffsets(paraXml, namespaceBindings = {}, model = parsePar
320259
320318
  toPaintedOffset(offset, affinity = "after") {
320260
320319
  let shift = 0;
320261
320320
  for (const run of objects) {
320262
- if (run.kernelStart > offset || run.kernelStart === offset && affinity === "before")
320321
+ if (offset < run.kernelStart)
320263
320322
  break;
320264
- shift++;
320323
+ if (run.kernelLength > 0) {
320324
+ if (offset === run.kernelStart)
320325
+ return run.paintedStart;
320326
+ if (offset < run.kernelStart + run.kernelLength) {
320327
+ return run.paintedStart + (affinity === "after" ? 1 : 0);
320328
+ }
320329
+ } else if (offset === run.kernelStart && affinity === "before") {
320330
+ return run.paintedStart;
320331
+ }
320332
+ shift += 1 - run.kernelLength;
320265
320333
  }
320266
320334
  return offset + shift;
320267
320335
  },
320268
320336
  toPaintedTrackedOffset(offset, affinity = "after") {
320269
320337
  let shift = 0;
320270
320338
  for (const run of objects) {
320271
- if (run.trackedStart > offset || run.trackedStart === offset && affinity === "before")
320339
+ if (offset < run.trackedStart)
320272
320340
  break;
320273
- shift++;
320341
+ if (run.trackedLength > 0) {
320342
+ if (offset === run.trackedStart)
320343
+ return offset + shift;
320344
+ if (offset < run.trackedStart + run.trackedLength)
320345
+ return run.trackedStart + shift + (affinity === "after" ? 1 : 0);
320346
+ } else if (offset === run.trackedStart && affinity === "before")
320347
+ break;
320348
+ shift += 1 - run.trackedLength;
320274
320349
  }
320275
320350
  return offset + shift;
320276
320351
  },
@@ -320298,7 +320373,7 @@ function preparePaintedOffsets(paraXml, namespaceBindings = {}, model = parsePar
320298
320373
  const last2 = runs.at(-1);
320299
320374
  return last2 ? last2.kernelStart + last2.kernelLength : 0;
320300
320375
  }
320301
- return run.objectOrdinal === null ? run.kernelStart + Math.max(0, offset - run.paintedStart) : run.kernelStart;
320376
+ return run.objectOrdinal === null ? run.kernelStart + Math.max(0, offset - run.paintedStart) : run.kernelStart + (offset > run.paintedStart ? run.kernelLength : 0);
320302
320377
  },
320303
320378
  caretObjectBoundary(offset) {
320304
320379
  const run = objects[lowerBound(objects, offset, "end")];
@@ -320334,31 +320409,32 @@ function paintedToKernelOffset(paraXml, paintedOffset) {
320334
320409
  }
320335
320410
  function paintedRuns(map3) {
320336
320411
  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;
320412
+ const ordinals = new Map(visibleParagraphInlineObjects(map3.pieces).map((piece, ordinal) => [piece, ordinal]));
320413
+ let paintedDelta = 0;
320414
+ for (const piece of paintedPieces(map3.pieces)) {
320415
+ const ordinal = ordinals.get(piece);
320416
+ const isObject2 = ordinal !== undefined;
320342
320417
  const isPaintedObject = isObject2 && (map3.visibleLength === 0 || !isFloatingDrawing(piece));
320343
320418
  const kernelLength = piece.visibleEnd - piece.visibleStart;
320344
320419
  if (!isPaintedObject && kernelLength === 0)
320345
320420
  continue;
320346
320421
  runs.push({
320347
- paintedStart: piece.visibleStart + paintedObjectCount,
320422
+ paintedStart: piece.visibleStart + paintedDelta,
320348
320423
  paintedLength: isPaintedObject ? 1 : kernelLength,
320349
320424
  kernelStart: piece.visibleStart,
320350
320425
  trackedStart: piece.trackedStart,
320426
+ trackedLength: piece.trackedEnd - piece.trackedStart,
320351
320427
  kernelLength,
320352
320428
  objectOrdinal: isPaintedObject ? ordinal : null,
320353
320429
  ...isPaintedObject ? { objectSource: { byteStart: piece.byteStart, byteEnd: piece.byteEnd } } : {}
320354
320430
  });
320355
320431
  if (isPaintedObject)
320356
- paintedObjectCount++;
320432
+ paintedDelta += 1 - kernelLength;
320357
320433
  }
320358
320434
  return runs;
320359
320435
  }
320360
- function isVisibleObject(piece) {
320361
- return piece.kind === "container" && (piece.containerKind === "drawing" || piece.containerKind === "pict" || piece.containerKind === "object") && !piece.containerStack.some((scope) => scope.deleted);
320436
+ function paintedPieces(pieces) {
320437
+ return pieces.flatMap((piece) => piece.kind === "container" && piece.containerKind === "math" ? [piece] : ("children" in piece) && piece.children.length ? paintedPieces(piece.children) : [piece]);
320362
320438
  }
320363
320439
  function isFloatingDrawing(piece) {
320364
320440
  if (piece.kind !== "container")
@@ -320483,7 +320559,7 @@ function prepareSelectionTargetResolution(input) {
320483
320559
  });
320484
320560
  const kernelTextLength = coordinateSpace === "tracked" ? offsetMap.totalChars() : entry.textLength;
320485
320561
  const paraXml = coordinateSpace === "visible" && input.offsetSpace === "selection" ? SELECTION_TARGET_TD.decode(paragraphBytes) : "";
320486
- const objectRuns = (paraXml.match(/<[\w.-]+:(?:drawing|pict|object)\b/g) ?? []).length;
320562
+ const objectRuns = (paraXml.match(/<[\w.-]+:(?:drawing|pict|object|oMath)\b/g) ?? []).length;
320487
320563
  const namespaceBytes = objectRuns > 0 && !input.namespaceBindings ? fullBytes ?? input.readPartBytes(entry.partUri) : fullBytes;
320488
320564
  const painted = objectRuns > 0 ? preparePaintedOffsets(paraXml, namespaceBytes ? partRootNamespaceBindings(namespaceBytes) : input.namespaceBindings ?? {}) : null;
320489
320565
  const originalStart = target.start.offset;
@@ -368014,8 +368090,8 @@ function* serializeSelectionRangeSteps(context, target, includeHtml, options) {
368014
368090
  const map3 = parseParagraphInlineMap(paragraphXml);
368015
368091
  const isStartEndpoint = entry.ordinal === startEntry.ordinal;
368016
368092
  const isEndEndpoint = entry.ordinal === endEntry.ordinal;
368017
- const objectPieces = map3.leaves().filter(isVisibleZeroWidthObjectPiece);
368018
- const paintedLength = map3.visibleLength + objectPieces.length;
368093
+ const objectPieces = visibleParagraphInlineObjects(map3.pieces);
368094
+ const paintedLength = preparePaintedOffsets(paragraphXml, {}, map3).totalLength;
368019
368095
  let from = options?.selectedBlockIds ? 0 : isStartEndpoint ? startPoint.offset : 0;
368020
368096
  let to = options?.selectedBlockIds ? map3.visibleLength : isEndEndpoint ? endPoint.offset : map3.visibleLength;
368021
368097
  let selectedObjectOrdinals = null;
@@ -368058,6 +368134,9 @@ function* serializeSelectionRangeSteps(context, target, includeHtml, options) {
368058
368134
  message: "selection offsets exceed paragraph text."
368059
368135
  };
368060
368136
  }
368137
+ if (objectPieces.some((piece, ordinal) => piece.containerKind === "math" && (selectedObjectOrdinals?.has(ordinal) || options?.wholeParagraphs || piece.visibleStart < to && piece.visibleEnd > from))) {
368138
+ return { ok: false, code: "CAPABILITY_UNAVAILABLE", message: "Equation clipboard serialization is unsupported; use selection.extractOoxml for native source." };
368139
+ }
368061
368140
  const commentRanges = collectCommentRanges(map3.leaves());
368062
368141
  const review = {
368063
368142
  commentRanges,
@@ -372614,7 +372693,7 @@ function resolveCrossCellDeletePlan(deps, index2, target) {
372614
372693
  if (!context?.hasObjectAnchor)
372615
372694
  continue;
372616
372695
  const paragraphXml = TD100.decode(bytes.subarray(entry.byteStart, entry.byteEnd));
372617
- const objects = visibleObjects3(paragraphXml);
372696
+ const objects = visibleObjects(paragraphXml);
372618
372697
  let ordinals;
372619
372698
  if (entry.blockId === head.entry.blockId) {
372620
372699
  if (!head.objectBoundary && objects.some((object4) => object4.visibleStart === head.offset)) {
@@ -372751,7 +372830,7 @@ function resolveSelectedImages(deps, selected) {
372751
372830
  });
372752
372831
  }
372753
372832
  const paragraphXml = TD100.decode(bytes.subarray(entry.byteStart, entry.byteEnd));
372754
- const objects = visibleObjects3(paragraphXml);
372833
+ const objects = visibleObjects(paragraphXml);
372755
372834
  const images = selected.ordinals.map((ordinal) => {
372756
372835
  const object4 = objects[ordinal];
372757
372836
  if (!object4)
@@ -372767,8 +372846,8 @@ function resolveSelectedImages(deps, selected) {
372767
372846
  }
372768
372847
  return images.map((image) => image);
372769
372848
  }
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));
372849
+ function visibleObjects(paragraphXml) {
372850
+ return visibleParagraphInlineObjects(parseParagraphInlineMap(paragraphXml).pieces);
372772
372851
  }
372773
372852
  function clearSegment(deps, segment) {
372774
372853
  const resolved = resolveSegmentDelete(deps, segment);
@@ -374001,6 +374080,12 @@ class V2SelectionMutationAdapter {
374001
374080
  return { success: false, failure: { code: narrowed.error, message: narrowed.message }, resolution };
374002
374081
  if (narrowed.paintedObjectContained)
374003
374082
  return { success: false, failure: { code: "INVALID_CONTEXT", message: "rewrite contains an inline object" }, resolution };
374083
+ if (span.text === "" && this.context.isCollaborativeSession()) {
374084
+ const model = readSDDocumentSessionInternalParagraphInlineModel(this.context.session, narrowed.storyId, narrowed.startBlockId);
374085
+ if (model && visibleParagraphInlineObjects(model.pieces).some((piece) => piece.containerKind === "math" && piece.visibleStart === narrowed.startOffset && piece.visibleEnd === narrowed.endOffset)) {
374086
+ return { success: false, failure: { code: "CAPABILITY_UNAVAILABLE", message: "Equation deletion currently requires a non-collaborative direct mutation." }, resolution };
374087
+ }
374088
+ }
374004
374089
  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
374090
  }
374006
374091
  }
@@ -374444,8 +374529,17 @@ class V2SelectionMutationAdapter {
374444
374529
  if ("error" in resolved) {
374445
374530
  return failureWithoutResolution(resolved.error, resolved.message);
374446
374531
  }
374447
- if (resolved.paintedObjectContained) {
374448
- return failureWithoutResolution("INVALID_CONTEXT", "selection contains an inline object; the text lane cannot rewrite it.");
374532
+ if (resolved.paintedObjectContained || request.text === "" && (this.context.isCollaborativeSession() || options?.changeMode === "tracked")) {
374533
+ const model = request.text === "" ? readSDDocumentSessionInternalParagraphInlineModel(this.context.session, story.storyId, resolved.startBlockId) : null;
374534
+ const objects = model ? visibleParagraphInlineObjects(model.pieces) : [];
374535
+ const selectedObjects = model && resolved.paintedObjectContained ? preparePaintedOffsets(model.paragraphXml, {}, model).containedObjectOrdinals(resolved.paintedStartOffset, resolved.paintedEndOffset) : [];
374536
+ 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));
374537
+ if (completeEquation && (this.context.isCollaborativeSession() || options?.changeMode === "tracked")) {
374538
+ return failureWithoutResolution("CAPABILITY_UNAVAILABLE", "Equation deletion currently requires a non-collaborative direct mutation.");
374539
+ }
374540
+ if (resolved.paintedObjectContained && !completeEquation) {
374541
+ return failureWithoutResolution("INVALID_CONTEXT", "selection contains an inline object; the text lane cannot rewrite it.");
374542
+ }
374449
374543
  }
374450
374544
  const resolveSelectionTargetMs = nowMs6() - resolveSelectionTargetStartedAt;
374451
374545
  const containmentStartedAt = nowMs6();
@@ -386457,11 +386551,13 @@ class V2BlocksAdapter {
386457
386551
  }
386458
386552
  const partBytes = getSDDocumentSessionInternalPartBytes(this.context.session, storyPartUriFromId5(resolved.storyId));
386459
386553
  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;
386554
+ const model = readSDDocumentSessionInternalParagraphInlineModel(this.context.session, resolved.storyId, resolved.entry.blockId);
386555
+ const offsetSpace = options?.offsetSpace === "selection" ? "selection" : "kernel";
386556
+ const offsetLength = offsetSpace === "selection" ? preparePaintedOffsets(paraXml, {}, model ?? undefined).totalLength : resolved.entry.textLength + (model ? visibleParagraphInlineObjects(model.pieces).filter((piece) => piece.containerKind !== "math").length : 0);
386461
386557
  const coordinateSpace = input.coordinateSpace ?? "visible";
386462
386558
  const metadataAnchorBindings = storyPartUriFromId5(resolved.storyId) === "/word/document.xml" ? listMetadataSplitBindings(this.context, paraXml) : [];
386463
386559
  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);
386560
+ const offset = coordinateSpace === "tracked" ? Math.max(0, Math.trunc(Number.isFinite(input.offset) ? input.offset : 0)) : clampStructuralOffset(input.offset, offsetLength);
386465
386561
  const restoreIndex = options?.changeMode === "tracked" && paragraphMarkHasTrackedMarker(paraXml, "del") && resolved.entry.directBodyChildOrdinal != null ? readParagraphIndexForStory(this.context, resolved.storyId) : null;
386466
386562
  const next = restoreIndex ? paragraphIndexEntryAt(restoreIndex, resolved.entry.ordinal + 1) : null;
386467
386563
  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 +386585,7 @@ class V2BlocksAdapter {
386489
386585
  paragraphByteStart: resolved.entry.byteStart,
386490
386586
  offset,
386491
386587
  coordinateSpace,
386588
+ offsetSpace,
386492
386589
  knownMetadataAnchorIds
386493
386590
  });
386494
386591
  if (!restore && !planned.ok)
@@ -386503,6 +386600,7 @@ class V2BlocksAdapter {
386503
386600
  target: { storyId: resolved.storyId, paraId: input.target.nodeId },
386504
386601
  offset,
386505
386602
  coordinateSpace,
386603
+ offsetSpace,
386506
386604
  knownMetadataAnchorIds,
386507
386605
  metadataAnchorBindings,
386508
386606
  changeMode: options?.changeMode ?? "direct"
@@ -386565,7 +386663,8 @@ class V2BlocksAdapter {
386565
386663
  }
386566
386664
  const partBytes = getSDDocumentSessionInternalPartBytes(this.context.session, storyPartUriFromId5(first.storyId));
386567
386665
  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;
386666
+ const model = readSDDocumentSessionInternalParagraphInlineModel(this.context.session, first.storyId, first.entry.blockId);
386667
+ 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
386668
  const begun = this.context.beginMutation({ expectedRevision: options?.expectedRevision });
386570
386669
  if ("failure" in begun)
386571
386670
  return failure4(begun.failure.code, begun.failure.message);
@@ -387745,6 +387844,7 @@ function readTailParaId(provisionalToFinal, createdRefs) {
387745
387844
  var TD106, PARAGRAPH_TYPES, TOP_LEVEL_LIST_ROWS_CACHE, PARAGRAPH_CLASSIFICATIONS, MAX_PARAGRAPH_CLASSIFICATIONS = 8192, BLOCK_NUMBERING_CACHE;
387746
387845
  var init_adapter9 = __esm(() => {
387747
387846
  init_sd_document_session_internal();
387847
+ init_painted_offsets();
387748
387848
  init_adapter3();
387749
387849
  init_mutation_guard();
387750
387850
  init_adapter5();
@@ -389170,10 +389270,14 @@ function normalizeOoxml(content3, allocate) {
389170
389270
  if (!range.tag.isSelfClosing)
389171
389271
  edits.push({ start: range.closeStart, end: range.end, xml: `</${name}>` });
389172
389272
  }
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;
389273
+ const pieces = [];
389274
+ let offset = 0;
389275
+ for (const edit of edits.sort((a, b) => a.start - b.start)) {
389276
+ pieces.push(content3.slice(offset, edit.start), edit.xml);
389277
+ offset = edit.end;
389278
+ }
389279
+ pieces.push(content3.slice(offset));
389280
+ return pieces.join("");
389177
389281
  }
389178
389282
  function paragraph3(id, runs) {
389179
389283
  return `<w:p xmlns:w14="${W147}" w14:paraId="${id}">${runs}</w:p>`;
@@ -422440,6 +422544,23 @@ function executeParagraphContentWrite(context, kind, input, options) {
422440
422544
  const story2 = context.resolveFullStoryLocator(target.story ?? { kind: "story", storyType: "body" });
422441
422545
  if ("error" in story2)
422442
422546
  return failure11("INVALID_TARGET", "The selection story is unavailable.");
422547
+ if (range && options?.offsetSpace === "selection") {
422548
+ const model = readSDDocumentSessionInternalParagraphInlineModel(context.session, story2.storyId, target.nodeId, story2.storyByteRange);
422549
+ if (!model)
422550
+ return failure11("TARGET_NOT_FOUND", "The selection paragraph is unavailable.");
422551
+ const painted = preparePaintedOffsets(model.paragraphXml, {}, model);
422552
+ if (range.start < 0 || range.end < range.start || range.end > painted.totalLength)
422553
+ return failure11("INVALID_TARGET", "Selection offsets exceed the paragraph.");
422554
+ const objects = visibleParagraphInlineObjects(model.pieces);
422555
+ if (range.start !== range.end && painted.containedObjectOrdinals(range.start, range.end).some((ordinal) => objects[ordinal]?.containerKind !== "math"))
422556
+ return failure11("CAPABILITY_UNSUPPORTED", "Native replacement of selected inline objects is unsupported.");
422557
+ const boundary = range.start === range.end ? painted.caretObjectBoundary(range.start) : undefined;
422558
+ range = {
422559
+ start: painted.toKernelOffset(range.start),
422560
+ end: painted.toKernelOffset(range.end),
422561
+ ...boundary ? { collapsedObjectBoundary: boundary } : {}
422562
+ };
422563
+ }
422443
422564
  for (const locator of [
422444
422565
  selection.story,
422445
422566
  selection.start.kind === "text" ? selection.start.story : selection.start.node.story,
@@ -422623,6 +422744,7 @@ var init_paragraph_content = __esm(() => {
422623
422744
  init_stories();
422624
422745
  init_text_range_shifts();
422625
422746
  init_rich_fragment_apply();
422747
+ init_painted_offsets();
422626
422748
  init_applied_change_mode();
422627
422749
  });
422628
422750
 
@@ -455197,7 +455319,8 @@ function mergeNumberingDefinitions(currentXml3, sourceXml) {
455197
455319
  const sourceAbstractNums = extractDefinitions(sourceXml, "w:abstractNum");
455198
455320
  const sourceNums = extractDefinitions(sourceXml, "w:num");
455199
455321
  const idMappings = [];
455200
- const additions = [];
455322
+ const abstractAdditions = [];
455323
+ const numAdditions = [];
455201
455324
  const abstractRemaps = new Map;
455202
455325
  if (usedAbstractIds.size > 0 && !usedAbstractIds.has("0")) {
455203
455326
  usedAbstractIds.add("0");
@@ -455218,7 +455341,7 @@ function mergeNumberingDefinitions(currentXml3, sourceXml) {
455218
455341
  for (const def of sourceAbstractNums) {
455219
455342
  const id = readIdAttr(def, "w:abstractNumId");
455220
455343
  if (id === null) {
455221
- additions.push(def);
455344
+ abstractAdditions.push(def);
455222
455345
  continue;
455223
455346
  }
455224
455347
  let finalId = id;
@@ -455231,7 +455354,7 @@ function mergeNumberingDefinitions(currentXml3, sourceXml) {
455231
455354
  usedAbstractIds.add(id);
455232
455355
  }
455233
455356
  abstractRemaps.set(id, finalId);
455234
- additions.push(nextDef);
455357
+ abstractAdditions.push(nextDef);
455235
455358
  }
455236
455359
  for (const def of sourceNums) {
455237
455360
  const id = readIdAttr(def, "w:numId");
@@ -455251,12 +455374,12 @@ function mergeNumberingDefinitions(currentXml3, sourceXml) {
455251
455374
  if (abstractRef !== null && remappedAbstractRef) {
455252
455375
  nextDef = replaceChildValAttr(nextDef, "w:abstractNumId", remappedAbstractRef);
455253
455376
  }
455254
- additions.push(nextDef);
455377
+ numAdditions.push(nextDef);
455255
455378
  }
455379
+ const additions = [...abstractAdditions, ...numAdditions];
455256
455380
  if (additions.length === 0) {
455257
455381
  return { xml: currentXml3, changed: false, idMappings };
455258
455382
  }
455259
- const additionsXml = additions.join("");
455260
455383
  const reconciled = reconcileAdoptedFragmentNamespaces(currentXml3, sourceXml, additions);
455261
455384
  if ("error" in reconciled)
455262
455385
  return reconciled;
@@ -455265,8 +455388,10 @@ function mergeNumberingDefinitions(currentXml3, sourceXml) {
455265
455388
  if (!rootClose) {
455266
455389
  return { xml: currentXml3, changed: false, idMappings };
455267
455390
  }
455268
- const insertAt = rootClose.index;
455269
- const nextXml = `${rootXml.slice(0, insertAt)}${additionsXml}${rootXml.slice(insertAt)}`;
455391
+ const children3 = extractTopLevelXmlElements(rootXml);
455392
+ const abstractAt = children3.find(({ localName: localName2 }) => localName2 === "num" || localName2 === "numIdMac")?.start ?? rootClose.index;
455393
+ const numAt = children3.find(({ localName: localName2 }) => localName2 === "numIdMac")?.start ?? rootClose.index;
455394
+ const nextXml = `${rootXml.slice(0, abstractAt)}${abstractAdditions.join("")}` + `${rootXml.slice(abstractAt, numAt)}${numAdditions.join("")}${rootXml.slice(numAt)}`;
455270
455395
  return { xml: nextXml, changed: true, idMappings };
455271
455396
  }
455272
455397
  function scanTagEnd(xml, start) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superdoc/mcp",
3
- "version": "1.11.0-next.5",
3
+ "version": "1.11.0-next.7",
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.5",
27
+ "@superdoc/sdk": "2.24.0-next.7",
28
28
  "debug": "^4.4.3",
29
29
  "zod": "^4.3.6"
30
30
  },
31
31
  "devDependencies": {
32
- "superdoc": "2.27.0-next.5",
33
- "@superdoc/docx-engine": "0.26.0-next.5",
32
+ "superdoc": "2.27.0-next.7",
33
+ "@superdoc/docx-engine": "0.26.0-next.7",
34
34
  "@superdoc/document-api": "0.1.0-alpha.0",
35
35
  "@types/bun": "^1.3.8",
36
36
  "@types/node": "22.19.2",