@superdoc/mcp 1.6.0-next.19 → 1.6.0-next.20

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 +308 -309
  2. package/package.json +4 -4
package/dist/index.js CHANGED
@@ -31600,7 +31600,7 @@ var init_host = __esm(() => {
31600
31600
  });
31601
31601
 
31602
31602
  // ../../packages/sdk/langs/node/src/runtime/sdk-version.generated.ts
31603
- var SDK_VERSION = "2.19.0-next.19";
31603
+ var SDK_VERSION = "2.19.0-next.20";
31604
31604
 
31605
31605
  // ../../packages/sdk/langs/node/src/runtime/embedded-platform.ts
31606
31606
  import { accessSync, chmodSync, constants, existsSync, statSync } from "node:fs";
@@ -194184,13 +194184,13 @@ function renderTrackedPasteTableRows(tableSpec, stamp) {
194184
194184
  return tableSpec.rows.map((row) => {
194185
194185
  const header = row.header ? "<w:tblHeader/>" : "";
194186
194186
  const rowMarker = renderTrackedChangeMarker("ins", stamp.allocateWId(), stamp, false);
194187
- return `<w:tr w:rsidR="${escapeXmlAttribute(stamp.rsid)}"><w:trPr>${header}${rowMarker}</w:trPr>` + row.cells.map((cell) => renderPasteTableCell(cell, (paragraph) => renderTrackedPasteParagraphBlock(paragraph, stamp))).join("") + "</w:tr>";
194187
+ return `<w:tr w:rsidR="${escapeXmlAttribute(stamp.rsid)}"><w:trPr>${header}${rowMarker}</w:trPr>` + row.cells.map((cell) => renderPasteTableCell(cell, (paragraph) => renderTrackedPasteParagraphBlock(paragraph, stamp), (table) => renderTrackedPasteTableBlock(table, stamp))).join("") + "</w:tr>";
194188
194188
  }).join("");
194189
194189
  }
194190
194190
  function renderPasteTableCellBody(cellSpec) {
194191
- return cellSpec.paragraphs.map((paragraph) => renderPasteParagraphBlock(paragraph)).join("");
194191
+ return cellSpec.paragraphs.map((block) => ("rows" in block) ? renderPasteTableBlock(block) : renderPasteParagraphBlock(block)).join("");
194192
194192
  }
194193
- function renderPasteTableCell(cell, renderParagraph = renderPasteParagraphBlock) {
194193
+ function renderPasteTableCell(cell, renderParagraph = renderPasteParagraphBlock, renderTable = renderPasteTableBlock) {
194194
194194
  const gridSpan = Math.max(1, cell.gridSpan ?? 1);
194195
194195
  const shading = cell.shadingColor ? `<w:shd w:val="clear" w:color="auto" w:fill="${escapeXmlAttribute(cell.shadingColor.toUpperCase())}"/>` : "";
194196
194196
  const marginSides = [
@@ -194202,7 +194202,7 @@ function renderPasteTableCell(cell, renderParagraph = renderPasteParagraphBlock)
194202
194202
  const margins = marginSides.flatMap(([side, points]) => points === undefined ? [] : [`<w:${side} w:w="${Math.round(points * 20)}" w:type="dxa"/>`]).join("");
194203
194203
  const tcMar = margins ? `<w:tcMar>${margins}</w:tcMar>` : "";
194204
194204
  const tcPr = `<w:tcPr><w:tcW w:w="0" w:type="auto"/>` + (gridSpan > 1 ? `<w:gridSpan w:val="${gridSpan}"/>` : "") + shading + tcMar + "</w:tcPr>";
194205
- return `<w:tc>${tcPr}${cell.paragraphs.map(renderParagraph).join("")}</w:tc>`;
194205
+ return `<w:tc>${tcPr}${cell.paragraphs.map((block) => ("rows" in block) ? renderTable(block) : renderParagraph(block)).join("")}</w:tc>`;
194206
194206
  }
194207
194207
  function renderPasteRun(run, options = {}) {
194208
194208
  if (run.kind === "sdt")
@@ -225371,6 +225371,56 @@ var init_clone_relationships = __esm(() => {
225371
225371
  init_relationship();
225372
225372
  });
225373
225373
 
225374
+ // ../../../v2/editor-core/dist/document/transactions/paste-blocks.js
225375
+ function* walkPasteBlocks(blocks) {
225376
+ for (const block of blocks) {
225377
+ yield block;
225378
+ if (block.kind === "table") {
225379
+ for (const row of block.rows)
225380
+ for (const cell of row.cells)
225381
+ yield* walkPasteBlocks(cell.blocks);
225382
+ }
225383
+ }
225384
+ }
225385
+ function mapPasteTableParagraphs(block, paragraph, table = (block2) => block2) {
225386
+ return table({
225387
+ ...block,
225388
+ rows: block.rows.map((row) => ({
225389
+ ...row,
225390
+ cells: row.cells.map((cell) => ({
225391
+ ...cell,
225392
+ blocks: cell.blocks.map((child) => child.kind === "table" ? mapPasteTableParagraphs(child, paragraph, table) : paragraph(child))
225393
+ }))
225394
+ }))
225395
+ });
225396
+ }
225397
+ function pasteTableSpec(block, mintNextParaId, bindW14NamespaceInline, runs = (block2) => block2.runs.map(toPasteTextRunSpec)) {
225398
+ return {
225399
+ ...block.styleRef !== undefined ? { styleRef: block.styleRef } : {},
225400
+ ...block.cellSpacingPt !== undefined ? { cellSpacingPt: block.cellSpacingPt } : {},
225401
+ rows: block.rows.map((row) => ({
225402
+ ...row.header !== undefined ? { header: row.header } : {},
225403
+ cells: row.cells.map((cell) => ({
225404
+ ...cell.gridSpan !== undefined ? { gridSpan: cell.gridSpan } : {},
225405
+ ...cell.shadingColor !== undefined ? { shadingColor: cell.shadingColor } : {},
225406
+ ...cell.padding !== undefined ? { padding: cell.padding } : {},
225407
+ paragraphs: cell.blocks.map((child) => child.kind === "table" ? pasteTableSpec(child, mintNextParaId, bindW14NamespaceInline, runs) : {
225408
+ paraId: mintNextParaId(),
225409
+ bindW14NamespaceInline,
225410
+ styleId: child.styleRef ?? null,
225411
+ numbering: child.numbering ?? null,
225412
+ ...child.paragraphProps ? { paragraphProps: child.paragraphProps } : {},
225413
+ ...child.pPrXml ? { pPrXml: child.pPrXml } : {},
225414
+ runs: runs(child)
225415
+ })
225416
+ }))
225417
+ }))
225418
+ };
225419
+ }
225420
+ var init_paste_blocks = __esm(() => {
225421
+ init_paragraph_contribution();
225422
+ });
225423
+
225374
225424
  // ../../../v2/editor-core/dist/document/transactions/compile-paste-notes.js
225375
225425
  function compilePastedNotesMetadata(input) {
225376
225426
  const referenced = collectReferencedNoteIds(input.blocks);
@@ -225493,17 +225543,9 @@ function collectReferencedNoteIds(blocks) {
225493
225543
  ids.add(inline.noteId);
225494
225544
  }
225495
225545
  };
225496
- for (const block of blocks) {
225546
+ for (const block of walkPasteBlocks(blocks))
225497
225547
  if (block.kind === "paragraph")
225498
225548
  visitParagraph(block);
225499
- else if (block.kind === "table") {
225500
- for (const row of block.rows) {
225501
- for (const cell of row.cells)
225502
- for (const paragraph of cell.blocks)
225503
- visitParagraph(paragraph);
225504
- }
225505
- }
225506
- }
225507
225549
  return ids;
225508
225550
  }
225509
225551
  function nextNoteNumericId(xml) {
@@ -225570,6 +225612,7 @@ function buildFreshNotesPartXml(type, fragments) {
225570
225612
  }
225571
225613
  var TE28, TD58, DOCUMENT_PART_URI2 = "/word/document.xml", DOCUMENT_RELS_PART_URI5 = "/word/_rels/document.xml.rels", CONTENT_TYPES_PART_URI6 = "/[Content_Types].xml", FOOTNOTES_PART_URI = "/word/footnotes.xml", ENDNOTES_PART_URI = "/word/endnotes.xml", W14_NS2 = "http://schemas.microsoft.com/office/word/2010/wordml", W_NS3 = "http://schemas.openxmlformats.org/wordprocessingml/2006/main";
225572
225614
  var init_compile_paste_notes = __esm(() => {
225615
+ init_paste_blocks();
225573
225616
  init_paragraph_contribution();
225574
225617
  init_compile_comment_helpers();
225575
225618
  init_package_graph();
@@ -238146,27 +238189,7 @@ function planParagraphSplice(input) {
238146
238189
  const standalone = (block, blockIndex, inheritedPPrXml) => {
238147
238190
  if (block.kind === "table") {
238148
238191
  const before = createdParaIds.length;
238149
- const tableSpec = {
238150
- ...block.styleRef !== undefined ? { styleRef: block.styleRef } : {},
238151
- ...block.cellSpacingPt !== undefined ? { cellSpacingPt: block.cellSpacingPt } : {},
238152
- rows: block.rows.map((row) => ({
238153
- ...row.header !== undefined ? { header: row.header } : {},
238154
- cells: row.cells.map((cell) => ({
238155
- ...cell.gridSpan !== undefined ? { gridSpan: cell.gridSpan } : {},
238156
- ...cell.shadingColor !== undefined ? { shadingColor: cell.shadingColor } : {},
238157
- ...cell.padding !== undefined ? { padding: cell.padding } : {},
238158
- paragraphs: cell.blocks.map((cellBlock) => ({
238159
- paraId: mintId(),
238160
- bindW14NamespaceInline,
238161
- styleId: cellBlock.styleRef ?? null,
238162
- numbering: cellBlock.numbering ?? null,
238163
- ...cellBlock.paragraphProps ? { paragraphProps: cellBlock.paragraphProps } : {},
238164
- ...cellBlock.pPrXml ? { pPrXml: cellBlock.pPrXml } : {},
238165
- runs: (input.inlineSpecs?.get(cellBlock) ?? cellBlock.runs.map(toPasteTextRunSpec)).map((run) => applyPasteNoteIdMap(applyPasteCommentIdMap(run, input.commentIdMap), input.noteIdMap))
238166
- }))
238167
- }))
238168
- }))
238169
- };
238192
+ const tableSpec = pasteTableSpec(block, mintId, bindW14NamespaceInline, (paragraph) => (input.inlineSpecs?.get(paragraph) ?? paragraph.runs.map(toPasteTextRunSpec)).map((run) => applyPasteCommentIdMap(run, input.commentIdMap)));
238170
238193
  const xml = input.trackedStamp ? renderTrackedPasteTableBlock(tableSpec, input.trackedStamp) : renderPasteTableBlock(tableSpec);
238171
238194
  destinationParaIdsByBlock[blockIndex].push(...createdParaIds.slice(before));
238172
238195
  return xml;
@@ -238444,6 +238467,7 @@ var init_compile_paste_splice = __esm(() => {
238444
238467
  init_overlap_edit_compiler();
238445
238468
  init_paragraph_contribution();
238446
238469
  init_paragraph_para_id_attrs();
238470
+ init_paste_blocks();
238447
238471
  });
238448
238472
 
238449
238473
  // ../../../v2/editor-core/dist/document/transactions/compile-paste-lists.js
@@ -238608,7 +238632,7 @@ function renderPasteListNumInstance(group, numId, abstractNumId) {
238608
238632
  return renderFirstListNumInstance(numId, abstractNumId);
238609
238633
  }
238610
238634
  function paragraphBlocks(blocks) {
238611
- return blocks.flatMap((block) => block.kind === "paragraph" ? [block] : block.kind === "table" ? block.rows.flatMap((row) => row.cells.flatMap((cell) => cell.blocks)) : []);
238635
+ return Array.from(walkPasteBlocks(blocks)).filter((block) => block.kind === "paragraph");
238612
238636
  }
238613
238637
  function numberingMatchesIntent(catalog, numbering, intent) {
238614
238638
  if (!numbering || catalog.status !== "available")
@@ -238650,16 +238674,10 @@ function rewriteListBlocks(blocks, catalog, numIdByGroup, groupKeyByBlock) {
238650
238674
  ...rest.pPrXml ? { pPrXml: rewritePastePPrNumbering(rest.pPrXml, numbering) } : {}
238651
238675
  };
238652
238676
  };
238653
- return blocks.map((block) => block.kind === "paragraph" ? rewriteParagraph(block) : block.kind === "table" ? {
238654
- ...block,
238655
- rows: block.rows.map((row) => ({
238656
- ...row,
238657
- cells: row.cells.map((cell) => ({
238658
- ...cell,
238659
- blocks: cell.blocks.map(rewriteParagraph)
238660
- }))
238661
- }))
238662
- } : block);
238677
+ return blocks.map((block) => block.kind === "paragraph" ? rewriteParagraph(block) : block.kind === "table" ? mapPasteTableParagraphs(block, rewriteParagraph, (table) => {
238678
+ const { listItemContinuationLevel: _continuationLevel, ...rest } = table;
238679
+ return rest;
238680
+ }) : block);
238663
238681
  }
238664
238682
  function assignListGroupKeys(blocks, catalog) {
238665
238683
  const keys = new Map;
@@ -238673,6 +238691,13 @@ function assignListGroupKeys(blocks, catalog) {
238673
238691
  ...intent.text !== undefined ? { text: intent.text } : {}
238674
238692
  });
238675
238693
  for (const block of paragraphs) {
238694
+ if (block.kind === "table") {
238695
+ activeIntentRuns.length = block.listItemContinuationLevel === undefined ? 0 : Math.min(activeIntentRuns.length, block.listItemContinuationLevel + 1);
238696
+ for (const row of block.rows)
238697
+ for (const cell of row.cells)
238698
+ assignSequence(cell.blocks);
238699
+ continue;
238700
+ }
238676
238701
  if (!block.listIntent || blockCanReuseNumbering(catalog, block)) {
238677
238702
  if (!block.listIntent && block.listItemContinuationLevel !== undefined) {
238678
238703
  activeIntentRuns.length = Math.min(activeIntentRuns.length, block.listItemContinuationLevel + 1);
@@ -238699,25 +238724,15 @@ function assignListGroupKeys(blocks, catalog) {
238699
238724
  keys.set(block, intentRun.key);
238700
238725
  }
238701
238726
  };
238702
- let topLevelParagraphs = [];
238703
- const flushTopLevel = () => {
238704
- assignSequence(topLevelParagraphs);
238705
- topLevelParagraphs = [];
238706
- };
238727
+ let sequence = [];
238707
238728
  for (const block of blocks) {
238708
- if (block.kind === "paragraph") {
238709
- topLevelParagraphs.push(block);
238710
- continue;
238711
- }
238712
- flushTopLevel();
238713
- if (block.kind !== "table")
238714
- continue;
238715
- for (const row of block.rows) {
238716
- for (const cell of row.cells)
238717
- assignSequence(cell.blocks);
238718
- }
238729
+ if (block.kind === "horizontalRule") {
238730
+ assignSequence(sequence);
238731
+ sequence = [];
238732
+ } else
238733
+ sequence.push(block);
238719
238734
  }
238720
- flushTopLevel();
238735
+ assignSequence(sequence);
238721
238736
  return keys;
238722
238737
  }
238723
238738
  function blockCanReuseNumbering(catalog, block) {
@@ -238770,6 +238785,7 @@ function byteWindowPrecondition6(partUri, bytes) {
238770
238785
  }
238771
238786
  var TE34, TD65, CONTENT_TYPES_PART_URI9 = "/[Content_Types].xml", DOCUMENT_RELS_PART_URI8 = "/word/_rels/document.xml.rels";
238772
238787
  var init_compile_paste_lists = __esm(() => {
238788
+ init_paste_blocks();
238773
238789
  init_sd_document_state();
238774
238790
  init_numbering_catalog();
238775
238791
  init_package_graph();
@@ -240861,7 +240877,7 @@ function validateFragmentRangeIntegrity(input) {
240861
240877
  return "text-range-in-field";
240862
240878
  }
240863
240879
  function fragmentRequiresCommit5Materialization(blocks) {
240864
- for (const block of blocks) {
240880
+ for (const block of walkPasteBlocks(blocks)) {
240865
240881
  if ((block.kind === "paragraph" || block.kind === "heading" || block.kind === "table") && block.blockSdts?.length)
240866
240882
  return true;
240867
240883
  if (block.kind === "heading" || block.kind === "horizontalRule")
@@ -240871,7 +240887,7 @@ function fragmentRequiresCommit5Materialization(blocks) {
240871
240887
  return true;
240872
240888
  for (const row of block.rows) {
240873
240889
  for (const cell of row.cells) {
240874
- if (cell.blocks.some((paragraph) => paragraphHasFutureInline(paragraph)))
240890
+ if (Array.from(walkPasteBlocks(cell.blocks)).some((paragraph) => paragraph.kind === "paragraph" && paragraphHasFutureInline(paragraph)))
240875
240891
  return true;
240876
240892
  }
240877
240893
  }
@@ -240903,7 +240919,7 @@ function collectFragmentSourcePaths(blocks) {
240903
240919
  for (const run of block.runs)
240904
240920
  add(run.sourcePath);
240905
240921
  };
240906
- for (const block of blocks) {
240922
+ const visit = (block) => {
240907
240923
  if (block.kind === "horizontalRule")
240908
240924
  add(block.sourcePath);
240909
240925
  else if (block.kind === "table") {
@@ -240913,12 +240929,14 @@ function collectFragmentSourcePaths(blocks) {
240913
240929
  for (const cell of row.cells) {
240914
240930
  add(cell.sourcePath);
240915
240931
  for (const cellBlock of cell.blocks)
240916
- paragraph(cellBlock);
240932
+ visit(cellBlock);
240917
240933
  }
240918
240934
  }
240919
240935
  } else
240920
240936
  paragraph(block);
240921
- }
240937
+ };
240938
+ for (const block of blocks)
240939
+ visit(block);
240922
240940
  return paths;
240923
240941
  }
240924
240942
  function fragmentSourcePathHandle(path6) {
@@ -240948,7 +240966,7 @@ function buildPasteProvisionalMappings(txId, createdParaIds, blocks, destination
240948
240966
  let createdCursor = 0;
240949
240967
  for (let blockIndex = 0;blockIndex < blocks.length; blockIndex += 1) {
240950
240968
  const block = blocks[blockIndex];
240951
- const inferredCount = block.kind === "table" ? block.rows.reduce((sum, row) => sum + row.cells.reduce((cellSum, cell) => cellSum + cell.blocks.length, 0), 0) : 1;
240969
+ const inferredCount = block.kind === "table" ? collectPasteParagraphs([block]).length : 1;
240952
240970
  const destinationIds = destinationsByBlock?.[blockIndex] ?? createdParaIds.slice(createdCursor, createdCursor + inferredCount);
240953
240971
  if (!destinationsByBlock)
240954
240972
  createdCursor += inferredCount;
@@ -240961,25 +240979,47 @@ function buildPasteProvisionalMappings(txId, createdParaIds, blocks, destination
240961
240979
  continue;
240962
240980
  }
240963
240981
  let paragraphCursor = 0;
240964
- const tableFirstParaId = destinationIds[paragraphCursor];
240965
- map3(block.sourcePath, tableFirstParaId ? `tbl:${tableFirstParaId}` : undefined);
240966
- for (const row of block.rows) {
240967
- const rowFirstParaId = destinationIds[paragraphCursor];
240968
- map3(row.sourcePath, rowFirstParaId ? `tr:${rowFirstParaId}` : undefined);
240969
- for (const cell of row.cells) {
240970
- const cellFirstParaId = destinationIds[paragraphCursor];
240971
- map3(cell.sourcePath, cellFirstParaId ? `tc:${cellFirstParaId}` : undefined);
240972
- for (const paragraph of cell.blocks) {
240973
- mapParagraph(paragraph, destinationIds[paragraphCursor]);
240974
- paragraphCursor += 1;
240982
+ const mapTable = (table) => {
240983
+ const first = destinationIds[paragraphCursor];
240984
+ map3(table.sourcePath, first ? `tbl:${first}` : undefined);
240985
+ for (const row of table.rows) {
240986
+ const rowFirst = destinationIds[paragraphCursor];
240987
+ map3(row.sourcePath, rowFirst ? `tr:${rowFirst}` : undefined);
240988
+ for (const cell of row.cells) {
240989
+ const cellFirst = destinationIds[paragraphCursor];
240990
+ map3(cell.sourcePath, cellFirst ? `tc:${cellFirst}` : undefined);
240991
+ for (const child of cell.blocks) {
240992
+ if (child.kind === "table")
240993
+ mapTable(child);
240994
+ else
240995
+ mapParagraph(child, destinationIds[paragraphCursor++]);
240996
+ }
240975
240997
  }
240976
240998
  }
240977
- }
240999
+ };
241000
+ mapTable(block);
240978
241001
  }
240979
241002
  return mappings;
240980
241003
  }
240981
241004
  function lowerDirectFragmentBlocks(blocks) {
240982
241005
  return blocks.map((block) => {
241006
+ if (block.kind === "table") {
241007
+ const normalizeTable = (table) => ({
241008
+ ...table,
241009
+ rows: table.rows.map((row) => ({
241010
+ ...row,
241011
+ cells: row.cells.map((cell) => {
241012
+ const children = cell.blocks.map((child) => child.kind === "table" ? normalizeTable(child) : child);
241013
+ if (children[0]?.kind === "table")
241014
+ children.unshift({ kind: "paragraph", runs: [] });
241015
+ if (children.at(-1)?.kind === "table")
241016
+ children.push({ kind: "paragraph", runs: [] });
241017
+ return { ...cell, blocks: children };
241018
+ })
241019
+ }))
241020
+ });
241021
+ return normalizeTable(block);
241022
+ }
240983
241023
  if (block.kind !== "heading")
240984
241024
  return block;
240985
241025
  const semanticStyleRole = semanticHeadingRole(block.level);
@@ -241619,7 +241659,7 @@ function renderCompletePasteFragment(input) {
241619
241659
  const before = createdParaIds.length;
241620
241660
  let xml;
241621
241661
  if (block.kind === "table") {
241622
- const spec = pasteTableSpec(block, mintNextParaId, bindW14NamespaceInline, input.inlineSpecs);
241662
+ const spec = pasteTableSpec(block, mintNextParaId, bindW14NamespaceInline, (paragraph) => (input.inlineSpecs.get(paragraph) ?? paragraph.runs.map(toPasteTextRunSpec)).map((run) => applyPasteCommentIdMap(run, input.commentIdMap)));
241623
241663
  xml = input.trackedStamp ? renderTrackedPasteTableBlock(spec, input.trackedStamp) : renderPasteTableBlock(spec);
241624
241664
  } else if (block.kind === "horizontalRule") {
241625
241665
  const spec = {
@@ -242281,7 +242321,7 @@ function tryRunTableRowPasteCommit(input, pasteTarget, pastedBlocks, additionalP
242281
242321
  createdParagraphIds.push(paragraphId2);
242282
242322
  return paragraphId2;
242283
242323
  };
242284
- const tableSpec = pasteTableSpec(pastedBlocks[0], createNextParagraphId, shouldBindW14NamespaceInline, pastedImageExtras.inlineSpecs);
242324
+ const tableSpec = pasteTableSpec(pastedBlocks[0], createNextParagraphId, shouldBindW14NamespaceInline, (paragraph) => pastedImageExtras.inlineSpecs.get(paragraph) ?? paragraph.runs.map(toPasteTextRunSpec));
242285
242325
  const renderedRowsXml = trackedStamp ? renderTrackedPasteTableRows(tableSpec, trackedStamp) : renderPasteTableRows(tableSpec);
242286
242326
  const targetRowNamespaceBindings = trackedStamp ? readWmlInsertionParentNamespaceBindings(storyPartBytes, targetTableLocation.row.rowByteStart, targetTableLocation.row.rowByteEnd, "tr") : null;
242287
242327
  if (trackedStamp && !targetRowNamespaceBindings) {
@@ -242392,7 +242432,7 @@ function runPartialTableCellPasteCommit(args) {
242392
242432
  createdParagraphIds.push(paragraphId2);
242393
242433
  return paragraphId2;
242394
242434
  };
242395
- const renderedSourceCells = pasteTableSpec(pastedTable, createNextParagraphId, shouldBindW14NamespaceInline, inlineSpecs).rows[0].cells;
242435
+ const renderedSourceCells = pasteTableSpec(pastedTable, createNextParagraphId, shouldBindW14NamespaceInline, (paragraph) => inlineSpecs?.get(paragraph) ?? paragraph.runs.map(toPasteTextRunSpec)).rows[0].cells;
242396
242436
  const cellBodyPatches = targetCells.map((targetCell, index) => ({
242397
242437
  kind: "replaceBytes",
242398
242438
  order: index,
@@ -242592,18 +242632,7 @@ function fragmentHasTrackedInsertion(blocks) {
242592
242632
  return collectPasteParagraphs(blocks).some((block) => block.runs.some((run) => run.trackedInsertion === true) || (block.inlines ?? []).some((inline) => inline.kind === "text" && inline.trackedInsertion === true));
242593
242633
  }
242594
242634
  function collectPasteParagraphs(blocks) {
242595
- const paragraphs = [];
242596
- for (const block of blocks) {
242597
- if (block.kind === "paragraph")
242598
- paragraphs.push(block);
242599
- else if (block.kind === "table") {
242600
- for (const row of block.rows) {
242601
- for (const cell of row.cells)
242602
- paragraphs.push(...cell.blocks);
242603
- }
242604
- }
242605
- }
242606
- return paragraphs;
242635
+ return Array.from(walkPasteBlocks(blocks)).filter((block) => block.kind === "paragraph");
242607
242636
  }
242608
242637
  function compilePastedReviewMetadata(input, blocks) {
242609
242638
  const comments = input.op.fragment.comments ?? [];
@@ -242921,26 +242950,13 @@ function collectSemanticStyleRoles(blocks) {
242921
242950
  if (block.semanticStyleRole)
242922
242951
  roles.add(block.semanticStyleRole);
242923
242952
  };
242924
- for (const block of blocks) {
242925
- if (block.kind === "paragraph")
242926
- collectParagraph(block);
242927
- else if (block.kind === "table")
242928
- for (const row of block.rows)
242929
- for (const cell of row.cells)
242930
- for (const paragraph of cell.blocks)
242931
- collectParagraph(paragraph);
242932
- }
242953
+ for (const paragraph of collectPasteParagraphs(blocks))
242954
+ collectParagraph(paragraph);
242933
242955
  return [...roles];
242934
242956
  }
242935
242957
  function pasteBlocksContainHyperlinks(blocks) {
242936
242958
  const paragraphContainsHyperlink = (block) => block.inlines?.some((inline) => inline.kind === "hyperlink") ?? false;
242937
- return blocks.some((block) => {
242938
- if (block.kind === "paragraph")
242939
- return paragraphContainsHyperlink(block);
242940
- if (block.kind !== "table")
242941
- return false;
242942
- return block.rows.some((row) => row.cells.some((cell) => cell.blocks.some(paragraphContainsHyperlink)));
242943
- });
242959
+ return collectPasteParagraphs(blocks).some(paragraphContainsHyperlink);
242944
242960
  }
242945
242961
  function explicitPasteStyleRefsExist(state, blocks) {
242946
242962
  const references = [];
@@ -242948,17 +242964,11 @@ function explicitPasteStyleRefsExist(state, blocks) {
242948
242964
  if (block.styleRef && !block.pPrXml)
242949
242965
  references.push({ styleId: block.styleRef, type: "paragraph" });
242950
242966
  };
242951
- for (const block of blocks) {
242967
+ for (const block of walkPasteBlocks(blocks)) {
242952
242968
  if (block.kind === "paragraph")
242953
242969
  inspectParagraph(block);
242954
- else if (block.kind === "table") {
242955
- if (block.styleRef)
242956
- references.push({ styleId: block.styleRef, type: "table" });
242957
- for (const row of block.rows)
242958
- for (const cell of row.cells)
242959
- for (const paragraph of cell.blocks)
242960
- inspectParagraph(paragraph);
242961
- }
242970
+ else if (block.kind === "table" && block.styleRef)
242971
+ references.push({ styleId: block.styleRef, type: "table" });
242962
242972
  }
242963
242973
  return explicitStyleReferencesExist(state, references);
242964
242974
  }
@@ -242981,16 +242991,7 @@ function resolveSemanticStyleBlocks(blocks, styleIdByRole) {
242981
242991
  return paragraph(block);
242982
242992
  if (block.kind !== "table")
242983
242993
  return block;
242984
- return {
242985
- ...block,
242986
- rows: block.rows.map((row) => ({
242987
- ...row,
242988
- cells: row.cells.map((cell) => ({
242989
- ...cell,
242990
- blocks: cell.blocks.map(paragraph)
242991
- }))
242992
- }))
242993
- };
242994
+ return mapPasteTableParagraphs(block, paragraph);
242994
242995
  });
242995
242996
  }
242996
242997
  function validateImageFragment(fragment3) {
@@ -243022,7 +243023,7 @@ function validateImageFragment(fragment3) {
243022
243023
  if (block.kind === "table") {
243023
243024
  for (const row of block.rows) {
243024
243025
  for (const cell of row.cells) {
243025
- if (cell.blocks.some((paragraph) => paragraph.inlines?.some((inline) => inline.kind === "image"))) {
243026
+ if (Array.from(walkPasteBlocks(cell.blocks)).some((paragraph) => paragraph.kind === "paragraph" && paragraph.inlines?.some((inline) => inline.kind === "image"))) {
243026
243027
  return { ok: false, reason: "paste-structure-unsupported" };
243027
243028
  }
243028
243029
  }
@@ -243062,20 +243063,7 @@ function validateImageFragment(fragment3) {
243062
243063
  return { ok: true, hasImages: references > 0 };
243063
243064
  }
243064
243065
  function prepareImageExtras(state, storyId, partUri, fragment3, blocks, changeMode, relationshipHyperlinks, hyperlinkCharacterStyleId, preparedPackageXml) {
243065
- const inlineParagraphs = [];
243066
- for (const block of blocks) {
243067
- if (block.kind === "paragraph" && (block.inlines || block.blockSdts?.length))
243068
- inlineParagraphs.push(block);
243069
- if (block.kind === "table") {
243070
- for (const row of block.rows) {
243071
- for (const cell of row.cells) {
243072
- for (const paragraph of cell.blocks)
243073
- if (paragraph.inlines)
243074
- inlineParagraphs.push(paragraph);
243075
- }
243076
- }
243077
- }
243078
- }
243066
+ const inlineParagraphs = collectPasteParagraphs(blocks).filter((block) => block.inlines || block.blockSdts?.length);
243079
243067
  const blockControls = blocks.flatMap((block) => block.kind === "paragraph" || block.kind === "table" ? block.blockSdts ?? [] : []);
243080
243068
  if (inlineParagraphs.length === 0 && blockControls.length === 0) {
243081
243069
  return { ok: true, value: { inlineSpecs: new Map, blockSdtIds: new Map, partUris: [], perPart: {}, preconditions: [], patchMaps: {} } };
@@ -243271,130 +243259,138 @@ function prepareImageExtras(state, storyId, partUri, fragment3, blocks, changeMo
243271
243259
  return { ok: true, value: { inlineSpecs, blockSdtIds, partUris: packagePartUris, perPart, preconditions, patchMaps: {} } };
243272
243260
  }
243273
243261
  function validateBlocks(blocks) {
243274
- const budget = { totalChars: 0, hyperlinkRefs: 0, sourcePaths: new Set };
243275
- const closedControls = new Set;
243276
- let activeControls = [];
243277
- for (const block of blocks) {
243278
- const controls = block.kind === "paragraph" || block.kind === "heading" || block.kind === "table" ? block.blockSdts ?? [] : [];
243279
- if (controls.length && ((block.kind === "paragraph" || block.kind === "heading") && !block.complete || controls.length > 16)) {
243280
- return { ok: false, reason: "paste-structure-unsupported" };
243281
- }
243282
- let common = 0;
243283
- while (common < controls.length && common < activeControls.length && controls[common].sourceId === activeControls[common].sourceId && controls[common].controlType === activeControls[common].controlType && controls[common].tag === activeControls[common].tag && controls[common].alias === activeControls[common].alias)
243284
- common += 1;
243285
- for (const wrapper of activeControls.slice(common))
243286
- closedControls.add(wrapper.sourceId);
243287
- for (const wrapper of controls.slice(common)) {
243288
- if (!/^[0-9]{1,10}$/.test(wrapper.sourceId) || closedControls.has(wrapper.sourceId) || controls.filter((candidate2) => candidate2.sourceId === wrapper.sourceId).length !== 1 || wrapper.controlType !== "text" && wrapper.controlType !== "richText" || !isValidOptionalXmlAttributeText(wrapper.tag, 255) || !isValidOptionalXmlAttributeText(wrapper.alias, 255)) {
243262
+ const budget = { totalChars: 0, hyperlinkRefs: 0, sourcePaths: new Set, blocks: 0 };
243263
+ const ancestors = new Set;
243264
+ const validateSequence = (blocks2, depth, inCell) => {
243265
+ if (depth > MAX_PASTE_BLOCK_DEPTH)
243266
+ return { ok: false, reason: "paste-depth-exceeded" };
243267
+ const closedControls = new Set;
243268
+ let activeControls = [];
243269
+ for (const block of blocks2) {
243270
+ if (!block || typeof block !== "object" || ancestors.has(block))
243289
243271
  return { ok: false, reason: "paste-structure-unsupported" };
243290
- }
243291
- }
243292
- activeControls = controls;
243293
- if (!recordSourcePath(block.sourcePath, budget.sourcePaths)) {
243294
- return { ok: false, reason: "paste-structure-unsupported" };
243295
- }
243296
- if (block.kind === "horizontalRule")
243297
- continue;
243298
- if (block.kind === "table") {
243299
- if (block.cellSpacingPt !== undefined && !isSafePaddingPoints(block.cellSpacingPt)) {
243272
+ if (++budget.blocks > MAX_PASTE_BLOCKS)
243273
+ return { ok: false, reason: "paste-payload-too-large" };
243274
+ if (inCell && block.kind !== "paragraph" && block.kind !== "table")
243300
243275
  return { ok: false, reason: "paste-structure-unsupported" };
243301
- }
243302
- if (!Array.isArray(block.rows) || block.rows.length === 0) {
243276
+ const controls = block.kind === "paragraph" || block.kind === "heading" || block.kind === "table" ? block.blockSdts ?? [] : [];
243277
+ if (inCell && controls.length)
243278
+ return { ok: false, reason: "paste-structure-unsupported" };
243279
+ if (controls.length && ((block.kind === "paragraph" || block.kind === "heading") && !block.complete || controls.length > 16)) {
243303
243280
  return { ok: false, reason: "paste-structure-unsupported" };
243304
243281
  }
243305
- for (const [rowIndex, row] of block.rows.entries()) {
243306
- if (row.header !== undefined && typeof row.header !== "boolean") {
243307
- return { ok: false, reason: "paste-structure-unsupported" };
243308
- }
243309
- if (row.header === true && rowIndex !== 0) {
243282
+ let common = 0;
243283
+ while (common < controls.length && common < activeControls.length && controls[common].sourceId === activeControls[common].sourceId && controls[common].controlType === activeControls[common].controlType && controls[common].tag === activeControls[common].tag && controls[common].alias === activeControls[common].alias)
243284
+ common += 1;
243285
+ for (const wrapper of activeControls.slice(common))
243286
+ closedControls.add(wrapper.sourceId);
243287
+ for (const wrapper of controls.slice(common)) {
243288
+ if (!/^[0-9]{1,10}$/.test(wrapper.sourceId) || closedControls.has(wrapper.sourceId) || controls.filter((candidate2) => candidate2.sourceId === wrapper.sourceId).length !== 1 || wrapper.controlType !== "text" && wrapper.controlType !== "richText" || !isValidOptionalXmlAttributeText(wrapper.tag, 255) || !isValidOptionalXmlAttributeText(wrapper.alias, 255)) {
243310
243289
  return { ok: false, reason: "paste-structure-unsupported" };
243311
243290
  }
243312
- if (!recordSourcePath(row.sourcePath, budget.sourcePaths)) {
243291
+ }
243292
+ activeControls = controls;
243293
+ if (!recordSourcePath(block.sourcePath, budget.sourcePaths)) {
243294
+ return { ok: false, reason: "paste-structure-unsupported" };
243295
+ }
243296
+ if (block.kind === "horizontalRule")
243297
+ continue;
243298
+ if (block.kind === "table") {
243299
+ if (!isValidListIntentLevel(block.listItemContinuationLevel))
243313
243300
  return { ok: false, reason: "paste-structure-unsupported" };
243314
- }
243315
- if (!Array.isArray(row.cells) || row.cells.length === 0) {
243301
+ ancestors.add(block);
243302
+ if (block.cellSpacingPt !== undefined && !isSafePaddingPoints(block.cellSpacingPt)) {
243316
243303
  return { ok: false, reason: "paste-structure-unsupported" };
243317
243304
  }
243318
- if (row.cells.length > MAX_WORD_TABLE_COLUMNS) {
243305
+ if (!Array.isArray(block.rows) || block.rows.length === 0) {
243319
243306
  return { ok: false, reason: "paste-structure-unsupported" };
243320
243307
  }
243321
- let rowColumnCount = 0;
243322
- for (const cell of row.cells) {
243323
- if (!recordSourcePath(cell.sourcePath, budget.sourcePaths)) {
243308
+ for (const [rowIndex, row] of block.rows.entries()) {
243309
+ if (!row || typeof row !== "object")
243310
+ return { ok: false, reason: "paste-structure-unsupported" };
243311
+ if (row.header !== undefined && typeof row.header !== "boolean") {
243324
243312
  return { ok: false, reason: "paste-structure-unsupported" };
243325
243313
  }
243326
- if (!Array.isArray(cell.blocks) || cell.blocks.length === 0) {
243314
+ if (row.header === true && rowIndex !== 0) {
243327
243315
  return { ok: false, reason: "paste-structure-unsupported" };
243328
243316
  }
243329
- if (cell.gridSpan !== undefined && (!Number.isSafeInteger(cell.gridSpan) || cell.gridSpan < 1)) {
243317
+ if (!recordSourcePath(row.sourcePath, budget.sourcePaths)) {
243330
243318
  return { ok: false, reason: "paste-structure-unsupported" };
243331
243319
  }
243332
- rowColumnCount += cell.gridSpan ?? 1;
243333
- if (rowColumnCount > MAX_WORD_TABLE_COLUMNS) {
243320
+ if (!Array.isArray(row.cells) || row.cells.length === 0) {
243334
243321
  return { ok: false, reason: "paste-structure-unsupported" };
243335
243322
  }
243336
- if (cell.shadingColor !== undefined && (typeof cell.shadingColor !== "string" || !/^[0-9A-F]{6}$/i.test(cell.shadingColor))) {
243323
+ if (row.cells.length > MAX_WORD_TABLE_COLUMNS) {
243337
243324
  return { ok: false, reason: "paste-structure-unsupported" };
243338
243325
  }
243339
- if (cell.padding !== undefined) {
243340
- if (typeof cell.padding !== "object" || cell.padding === null || Array.isArray(cell.padding)) {
243326
+ let rowColumnCount = 0;
243327
+ for (const cell of row.cells) {
243328
+ if (!cell || typeof cell !== "object")
243341
243329
  return { ok: false, reason: "paste-structure-unsupported" };
243342
- }
243343
- let hasPaddingSide = false;
243344
- for (const side of ["topPt", "rightPt", "bottomPt", "leftPt"]) {
243345
- const value = cell.padding[side];
243346
- if (value === undefined)
243347
- continue;
243348
- if (!isSafePaddingPoints(value))
243349
- return { ok: false, reason: "paste-structure-unsupported" };
243350
- hasPaddingSide = true;
243351
- }
243352
- if (!hasPaddingSide)
243353
- return { ok: false, reason: "paste-structure-unsupported" };
243354
- }
243355
- for (const cellBlock of cell.blocks) {
243356
- if (cellBlock.kind !== "paragraph") {
243330
+ if (!recordSourcePath(cell.sourcePath, budget.sourcePaths)) {
243357
243331
  return { ok: false, reason: "paste-structure-unsupported" };
243358
243332
  }
243359
- if (cellBlock.blockSdts?.length) {
243333
+ if (!Array.isArray(cell.blocks) || cell.blocks.length === 0) {
243360
243334
  return { ok: false, reason: "paste-structure-unsupported" };
243361
243335
  }
243362
- if (!recordSourcePath(cellBlock.sourcePath, budget.sourcePaths)) {
243336
+ if (cell.gridSpan !== undefined && (!Number.isSafeInteger(cell.gridSpan) || cell.gridSpan < 1)) {
243363
243337
  return { ok: false, reason: "paste-structure-unsupported" };
243364
243338
  }
243365
- if (!isValidListItemContinuation(cellBlock)) {
243339
+ rowColumnCount += cell.gridSpan ?? 1;
243340
+ if (rowColumnCount > MAX_WORD_TABLE_COLUMNS) {
243366
243341
  return { ok: false, reason: "paste-structure-unsupported" };
243367
243342
  }
243368
- if (cellBlock.listIntent && (cellBlock.listIntent.kind !== "bullet" && cellBlock.listIntent.kind !== "ordered" || !isValidListIntentLevel(cellBlock.listIntent.level) || !isValidStartsNewList(cellBlock.listIntent.startsNewList) || !isValidListIntentStart(cellBlock.listIntent) || !isValidListIntentLevelShape(cellBlock.listIntent))) {
243343
+ if (cell.shadingColor !== undefined && (typeof cell.shadingColor !== "string" || !/^[0-9A-F]{6}$/i.test(cell.shadingColor))) {
243369
243344
  return { ok: false, reason: "paste-structure-unsupported" };
243370
243345
  }
243371
- const validation2 = validateParagraphBlock(cellBlock, budget);
243346
+ if (cell.padding !== undefined) {
243347
+ if (typeof cell.padding !== "object" || cell.padding === null || Array.isArray(cell.padding)) {
243348
+ return { ok: false, reason: "paste-structure-unsupported" };
243349
+ }
243350
+ let hasPaddingSide = false;
243351
+ for (const side of ["topPt", "rightPt", "bottomPt", "leftPt"]) {
243352
+ const value = cell.padding[side];
243353
+ if (value === undefined)
243354
+ continue;
243355
+ if (!isSafePaddingPoints(value))
243356
+ return { ok: false, reason: "paste-structure-unsupported" };
243357
+ hasPaddingSide = true;
243358
+ }
243359
+ if (!hasPaddingSide)
243360
+ return { ok: false, reason: "paste-structure-unsupported" };
243361
+ }
243362
+ budget.blocks += Number(cell.blocks[0]?.kind === "table") + Number(cell.blocks.at(-1)?.kind === "table");
243363
+ if (budget.blocks > MAX_PASTE_BLOCKS)
243364
+ return { ok: false, reason: "paste-payload-too-large" };
243365
+ const validation2 = validateSequence(cell.blocks, depth + 1, true);
243372
243366
  if (!validation2.ok)
243373
243367
  return validation2;
243374
243368
  }
243375
243369
  }
243370
+ ancestors.delete(block);
243371
+ continue;
243376
243372
  }
243377
- continue;
243378
- }
243379
- if (block.kind !== "paragraph" && block.kind !== "heading") {
243380
- return { ok: false, reason: "paste-structure-unsupported" };
243381
- }
243382
- if (block.kind === "heading" && (!Number.isInteger(block.level) || block.level < 1 || block.level > 9)) {
243383
- return { ok: false, reason: "paste-structure-unsupported" };
243384
- }
243385
- if (!isValidListItemContinuation(block)) {
243386
- return { ok: false, reason: "paste-structure-unsupported" };
243387
- }
243388
- if (block.listIntent) {
243389
- if (block.listIntent.kind !== "bullet" && block.listIntent.kind !== "ordered" || !isValidListIntentLevel(block.listIntent.level) || !isValidStartsNewList(block.listIntent.startsNewList) || !isValidListIntentStart(block.listIntent) || !isValidListIntentLevelShape(block.listIntent)) {
243373
+ if (block.kind !== "paragraph" && block.kind !== "heading") {
243374
+ return { ok: false, reason: "paste-structure-unsupported" };
243375
+ }
243376
+ if (block.kind === "heading" && (!Number.isInteger(block.level) || block.level < 1 || block.level > 9)) {
243390
243377
  return { ok: false, reason: "paste-structure-unsupported" };
243391
243378
  }
243379
+ if (!isValidListItemContinuation(block)) {
243380
+ return { ok: false, reason: "paste-structure-unsupported" };
243381
+ }
243382
+ if (block.listIntent) {
243383
+ if (block.listIntent.kind !== "bullet" && block.listIntent.kind !== "ordered" || !isValidListIntentLevel(block.listIntent.level) || !isValidStartsNewList(block.listIntent.startsNewList) || !isValidListIntentStart(block.listIntent) || !isValidListIntentLevelShape(block.listIntent)) {
243384
+ return { ok: false, reason: "paste-structure-unsupported" };
243385
+ }
243386
+ }
243387
+ const validation = validateParagraphBlock(block, budget);
243388
+ if (!validation.ok)
243389
+ return validation;
243392
243390
  }
243393
- const validation = validateParagraphBlock(block, budget);
243394
- if (!validation.ok)
243395
- return validation;
243396
- }
243397
- return { ok: true };
243391
+ return { ok: true };
243392
+ };
243393
+ return validateSequence(blocks, 0, false);
243398
243394
  }
243399
243395
  function recordSourcePath(path6, seen) {
243400
243396
  if (path6 === undefined)
@@ -243587,29 +243583,6 @@ function visibleCharLength(block) {
243587
243583
  function isMaterializablePasteBlocks(blocks) {
243588
243584
  return blocks.every((block) => block.kind === "paragraph" || block.kind === "horizontalRule" || block.kind === "table");
243589
243585
  }
243590
- function pasteTableSpec(block, mintNextParaId, bindW14NamespaceInline, inlineSpecs) {
243591
- return {
243592
- ...block.styleRef !== undefined ? { styleRef: block.styleRef } : {},
243593
- ...block.cellSpacingPt !== undefined ? { cellSpacingPt: block.cellSpacingPt } : {},
243594
- rows: block.rows.map((row) => ({
243595
- ...row.header !== undefined ? { header: row.header } : {},
243596
- cells: row.cells.map((cell) => ({
243597
- ...cell.gridSpan !== undefined ? { gridSpan: cell.gridSpan } : {},
243598
- ...cell.shadingColor !== undefined ? { shadingColor: cell.shadingColor } : {},
243599
- ...cell.padding !== undefined ? { padding: cell.padding } : {},
243600
- paragraphs: cell.blocks.map((cellBlock) => ({
243601
- paraId: mintNextParaId(),
243602
- bindW14NamespaceInline,
243603
- styleId: cellBlock.styleRef ?? null,
243604
- numbering: cellBlock.numbering ?? null,
243605
- ...cellBlock.paragraphProps ? { paragraphProps: cellBlock.paragraphProps } : {},
243606
- ...cellBlock.pPrXml ? { pPrXml: cellBlock.pPrXml } : {},
243607
- runs: inlineSpecs?.get(cellBlock) ?? cellBlock.runs.map(toPasteTextRunSpec)
243608
- }))
243609
- }))
243610
- }))
243611
- };
243612
- }
243613
243586
  function isSafePaddingPoints(value) {
243614
243587
  return typeof value === "number" && Number.isFinite(value) && value >= 0 && Number.isSafeInteger(value * 20);
243615
243588
  }
@@ -243631,8 +243604,7 @@ function trackedFragmentCarrierBudget(blocks) {
243631
243604
  for (const row of block.rows) {
243632
243605
  count += 1;
243633
243606
  for (const cell of row.cells) {
243634
- for (const cellBlock of cell.blocks)
243635
- count += paragraph(cellBlock);
243607
+ count += trackedFragmentCarrierBudget(cell.blocks);
243636
243608
  }
243637
243609
  }
243638
243610
  }
@@ -244174,7 +244146,7 @@ function collectPerPartRevisions9(state, partUris) {
244174
244146
  function rejected18(txId, reason) {
244175
244147
  return { txId, status: "rejected", rejectedReason: reason };
244176
244148
  }
244177
- var TE36, TD68, MAX_PASTE_BLOCKS = 1000, MAX_PASTE_TOTAL_CHARS = 500000, MAX_ASSET_BYTES, MAX_TOTAL_ASSET_BYTES, MAX_ASSET_COUNT = 16, MAX_IMAGE_REF_COUNT = 64, MAX_WORD_TABLE_COLUMNS = 63, MAX_HYPERLINK_URL_CHARS = 8192, MAX_HYPERLINK_ANCHOR_CHARS = 255, MAX_HYPERLINK_TOOLTIP_CHARS = 260, MAX_HYPERLINK_REF_COUNT = 256, CONTENT_TYPES_PART_URI11 = "/[Content_Types].xml", DOCUMENT_RELS_PART_URI9 = "/word/_rels/document.xml.rels", NUMBERING_PART_URI3 = "/word/numbering.xml", RELS_CONTENT_TYPE3 = "application/vnd.openxmlformats-package.relationships+xml", IMAGE_REL_TYPE2 = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", HYPERLINK_REL_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink", EMU_PER_PX3 = 9525, PASTE_ORDERED_LIST_FORMATS, MAX_PASTE_PPR_XML_CHARS = 8192;
244149
+ var TE36, TD68, MAX_PASTE_BLOCKS = 1000, MAX_PASTE_BLOCK_DEPTH = 32, MAX_PASTE_TOTAL_CHARS = 500000, MAX_ASSET_BYTES, MAX_TOTAL_ASSET_BYTES, MAX_ASSET_COUNT = 16, MAX_IMAGE_REF_COUNT = 64, MAX_WORD_TABLE_COLUMNS = 63, MAX_HYPERLINK_URL_CHARS = 8192, MAX_HYPERLINK_ANCHOR_CHARS = 255, MAX_HYPERLINK_TOOLTIP_CHARS = 260, MAX_HYPERLINK_REF_COUNT = 256, CONTENT_TYPES_PART_URI11 = "/[Content_Types].xml", DOCUMENT_RELS_PART_URI9 = "/word/_rels/document.xml.rels", NUMBERING_PART_URI3 = "/word/numbering.xml", RELS_CONTENT_TYPE3 = "application/vnd.openxmlformats-package.relationships+xml", IMAGE_REL_TYPE2 = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", HYPERLINK_REL_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink", EMU_PER_PX3 = 9525, PASTE_ORDERED_LIST_FORMATS, MAX_PASTE_PPR_XML_CHARS = 8192;
244178
244150
  var init_compile_paste_fragment = __esm(() => {
244179
244151
  init_image_content_types();
244180
244152
  init_sd_document_state();
@@ -244197,6 +244169,7 @@ var init_compile_paste_fragment = __esm(() => {
244197
244169
  init_patch_substrate();
244198
244170
  init_compile_paste_splice();
244199
244171
  init_compile_paste_lists();
244172
+ init_paste_blocks();
244200
244173
  init_paragraph_para_id_attrs();
244201
244174
  init_table_catalog();
244202
244175
  init_comments_catalog();
@@ -317830,20 +317803,6 @@ function usesDefaultWordOrderedLevelShape(descriptor) {
317830
317803
  }
317831
317804
  function convertTable(table, context, inherited, path6) {
317832
317805
  let structurallyRejected = false;
317833
- const nestedTable = findNestedTable(table);
317834
- if (nestedTable) {
317835
- addDiagnostic(context, {
317836
- code: "conversion-unsupported-construct",
317837
- severity: "error",
317838
- message: "Nested tables cannot be represented by this conversion.",
317839
- construct: "table",
317840
- disposition: "rejected",
317841
- lossy: true,
317842
- path: path6,
317843
- range: sourceRangeForNode(nestedTable)
317844
- });
317845
- structurallyRejected = true;
317846
- }
317847
317806
  const rows = collectTableRows(table, path6);
317848
317807
  for (const { row, path: rowPath } of rows) {
317849
317808
  let rowGridColumns = 0;
@@ -318346,21 +318305,6 @@ function collectTableRows(table, tablePath) {
318346
318305
  visit(table, tablePath);
318347
318306
  return rows;
318348
318307
  }
318349
- function findNestedTable(table) {
318350
- const visit = (parent) => {
318351
- for (const child of parent.childNodes) {
318352
- if (!isElement(child))
318353
- continue;
318354
- if (child.tagName === "table")
318355
- return child;
318356
- const nested = visit(child);
318357
- if (nested)
318358
- return nested;
318359
- }
318360
- return null;
318361
- };
318362
- return visit(table);
318363
- }
318364
318308
  function findDescendantElement(element, tagName) {
318365
318309
  const visit = (parent) => {
318366
318310
  for (const child of parent.childNodes) {
@@ -337375,10 +337319,18 @@ function lowerList(node4, path7, startsNewList, images) {
337375
337319
  blocks.push(...lowerList(content3, contentPath, false, images));
337376
337320
  continue;
337377
337321
  }
337378
- if (content3.kind !== "paragraph") {
337322
+ if (content3.kind === "table") {
337323
+ if (!materializedItemParagraph)
337324
+ invalid3(contentPath, "A list-item table must follow its number-bearing paragraph.");
337325
+ blocks.push({ ...lowerTable(content3, contentPath, images), listItemContinuationLevel: item.level });
337326
+ continue;
337327
+ }
337328
+ if (content3.kind !== "paragraph" && content3.kind !== "heading") {
337379
337329
  unsupported4(contentPath, `List item block kind "${content3.kind}" is not materializable.`);
337380
337330
  }
337381
- const block = lowerParagraph(content3.paragraph, contentPath, [...contentPath, "paragraph"], images);
337331
+ const block = lowerTableCellContent(content3, contentPath, images)[0];
337332
+ if (block.kind !== "paragraph")
337333
+ unsupported4(contentPath, "List markers require a paragraph carrier.");
337382
337334
  if (!materializedItemParagraph) {
337383
337335
  const firstAtLevel = !startedLevels.has(item.level);
337384
337336
  const startsLevelSequence = firstAtLevel || item.path?.at(-1) === 0 || previousItemLevel !== undefined && item.level > previousItemLevel;
@@ -337533,18 +337485,23 @@ function lowerTableCellContent(content3, path7, images) {
337533
337485
  semanticStyleRole: `heading-${content3.heading.level}`
337534
337486
  }];
337535
337487
  }
337488
+ if (content3.kind === "table")
337489
+ return [lowerTable(content3, path7, images)];
337536
337490
  if (content3.kind === "list") {
337537
- const blocks = lowerList(content3, path7, true, images);
337538
- return blocks.map((block) => {
337539
- if (block.kind !== "paragraph") {
337540
- unsupported4(path7, "Table-cell lists must lower to paragraph blocks.");
337541
- }
337491
+ return lowerList(content3, path7, true, images).map((block) => {
337492
+ if (block.kind !== "paragraph" && block.kind !== "table")
337493
+ unsupported4(path7, "Table-cell lists require paragraph/table carriers.");
337542
337494
  return block;
337543
337495
  });
337544
337496
  }
337545
337497
  unsupported4(path7, `Table-cell block kind "${content3.kind}" is not materializable.`);
337546
337498
  }
337547
337499
  function emphasizeHeaderCellBlock(block) {
337500
+ if (block.kind === "table")
337501
+ return { ...block, rows: block.rows.map((row) => ({
337502
+ ...row,
337503
+ cells: row.cells.map((cell) => ({ ...cell, blocks: cell.blocks.map(emphasizeHeaderCellBlock) }))
337504
+ })) };
337548
337505
  const inlines = block.inlines?.map((inline) => {
337549
337506
  if (inline.kind === "text") {
337550
337507
  return { ...inline, marks: { ...inline.marks, bold: true } };
@@ -338326,16 +338283,18 @@ function collectParagraphEffects(blocks) {
338326
338283
  return;
338327
338284
  out.push({ sourcePath: paragraph3.sourcePath, text: paragraphText2(paragraph3) });
338328
338285
  };
338329
- for (const block of blocks) {
338330
- if (block.kind === "paragraph" || block.kind === "heading")
338331
- add(block);
338332
- else if (block.kind === "table") {
338333
- for (const row of block.rows)
338334
- for (const cell of row.cells)
338335
- for (const paragraph3 of cell.blocks)
338336
- add(paragraph3);
338286
+ const visit = (blocks2) => {
338287
+ for (const block of blocks2) {
338288
+ if (block.kind === "paragraph" || block.kind === "heading")
338289
+ add(block);
338290
+ else if (block.kind === "table") {
338291
+ for (const row of block.rows)
338292
+ for (const cell of row.cells)
338293
+ visit(cell.blocks);
338294
+ }
338337
338295
  }
338338
- }
338296
+ };
338297
+ visit(blocks);
338339
338298
  return out;
338340
338299
  }
338341
338300
  function paragraphText2(paragraph3) {
@@ -338700,7 +338659,11 @@ function htmlContent(context, content3, kind, allocate) {
338700
338659
  styleRef: block.styleRef,
338701
338660
  rows: block.rows.map((row) => ({
338702
338661
  header: row.header,
338703
- cells: row.cells.map((cell) => ({ ...cell, paragraphs: cell.blocks.map(spec) }))
338662
+ cells: row.cells.map((cell) => ({ ...cell, paragraphs: cell.blocks.map((child) => {
338663
+ if (child.kind !== "paragraph")
338664
+ throw operationError("CAPABILITY_UNAVAILABLE", "Nested replacement tables require the rich fragment operation.");
338665
+ return spec(child);
338666
+ }) }))
338704
338667
  }))
338705
338668
  });
338706
338669
  throw operationError("CAPABILITY_UNAVAILABLE", `Replacement does not support ${block.kind} blocks.`);
@@ -393307,7 +393270,12 @@ function prepareClipboardPlan(fragment4, sourceKind, diagnostics = [], plainFall
393307
393270
  applyPlan: applyPlanFromClipboardFragment(fragment4)
393308
393271
  };
393309
393272
  }
393273
+ function isClipboardRepresentableApplyPlan(plan) {
393274
+ return plan.blocks.every((block) => block.kind !== "table" || block.listItemContinuationLevel === undefined && block.rows.every((row) => row.cells.every((cell) => cell.blocks.every((child) => child.kind === "paragraph"))));
393275
+ }
393310
393276
  function prepareClipboardApplyPlan(applyPlan2, sourceKind, diagnostics = [], plainFallback = false) {
393277
+ if (!isClipboardRepresentableApplyPlan(applyPlan2))
393278
+ throw new Error("Kernel paste plan is outside the clipboard fragment contract.");
393311
393279
  const fragment4 = {
393312
393280
  kind: SUPERDOC_V2_CLIPBOARD_FRAGMENT_KIND,
393313
393281
  version: applyPlan2.version,
@@ -393375,7 +393343,11 @@ function clipboardBlockFromKernel(block) {
393375
393343
  ...row,
393376
393344
  cells: row.cells.map((cell) => ({
393377
393345
  ...cell,
393378
- blocks: cell.blocks.map(clipboardParagraphFromKernel)
393346
+ blocks: cell.blocks.map((child) => {
393347
+ if (child.kind !== "paragraph")
393348
+ throw new Error("Nested tables are outside the clipboard fragment contract.");
393349
+ return clipboardParagraphFromKernel(child);
393350
+ })
393379
393351
  }))
393380
393352
  }))
393381
393353
  };
@@ -394740,7 +394712,11 @@ function rewriteBlockInlines(block, notes) {
394740
394712
  ...row,
394741
394713
  cells: row.cells.map((cell) => ({
394742
394714
  ...cell,
394743
- blocks: cell.blocks.map((paragraph4) => rewriteBodyParagraph(paragraph4, notes))
394715
+ blocks: cell.blocks.map((paragraph4) => {
394716
+ if (paragraph4.kind !== "paragraph")
394717
+ throw new Error("Nested tables are outside the clipboard note contract.");
394718
+ return rewriteBodyParagraph(paragraph4, notes);
394719
+ })
394744
394720
  }))
394745
394721
  }))
394746
394722
  };
@@ -394807,6 +394783,8 @@ function referencedNoteIds(blocks) {
394807
394783
  for (const row of block.rows) {
394808
394784
  for (const cell of row.cells) {
394809
394785
  for (const paragraph4 of cell.blocks) {
394786
+ if (paragraph4.kind !== "paragraph")
394787
+ throw new Error("Nested tables are outside the clipboard note contract.");
394810
394788
  for (const inline of paragraph4.inlines ?? [])
394811
394789
  visit(inline);
394812
394790
  }
@@ -394967,6 +394945,9 @@ function planFromHtml(payload, html, options) {
394967
394945
  const reason = lowered.code === "INVALID_PAYLOAD" ? "paste-structure-unsupported" : "paste-no-faithful-representation";
394968
394946
  return fallbackOrFail(payload, options, reason, lowered.message);
394969
394947
  }
394948
+ if (!isClipboardRepresentableApplyPlan(lowered.plan)) {
394949
+ return fallbackOrFail(payload, options, "paste-no-faithful-representation", "HTML structure is outside the clipboard fragment contract.");
394950
+ }
394970
394951
  const planWithNotes = liftWordNotesInApplyPlan(lowered.plan, rewritten);
394971
394952
  const plain = readStringItem(payload, "text/plain");
394972
394953
  const reconciliation = plain === null ? { kind: "complete" } : reconcileHtmlWithPlainText(planWithNotes, plain);
@@ -436708,10 +436689,13 @@ function composeTableStructuralProjection(input) {
436708
436689
  return null;
436709
436690
  const snapshotBlocks = (input.readStorySnapshot ?? snapshotStoryShard)(shardReadTarget(input.handle)).blocks;
436710
436691
  const liveBlockIds = new Set(snapshotBlocks.map((block) => block.blockId));
436692
+ const bootstrapNamespaces = new XmlEmissionContext(input.bootstrap?.sourceXml ?? "");
436711
436693
  const rawTableReplacements = replacements.map((replacement) => {
436712
436694
  if (!replacement.creationPlacement && !replacement.relocation && !replacement.rowReordered && replacement.splitChildren.length === 0)
436713
436695
  return replacement;
436714
- const liveTableBlockIds = snapshotBlocks.filter((block) => block.structuralRefs.tableNodeId === replacement.tableNodeId).map((block) => block.blockId);
436696
+ const nestedIds = nestedTableParagraphIds(replacement.xml, bootstrapNamespaces.at(replacement.sourceXmlStart));
436697
+ const nestedMembership = nestedIds === null ? null : new Set(nestedIds);
436698
+ const liveTableBlockIds = snapshotBlocks.filter((block) => nestedMembership ? nestedMembership.has(block.blockId) : block.structuralRefs.tableNodeId === replacement.tableNodeId).map((block) => block.blockId);
436715
436699
  if (liveTableBlockIds.length === 0 && !replacement.splitSourceTableNodeId)
436716
436700
  return replacement;
436717
436701
  return {
@@ -437406,8 +437390,8 @@ function assertCurrentTableSpanMatchesBaseXml(input) {
437406
437390
  if (input.start < 0 || input.end < input.start || input.end > input.baseXml.length) {
437407
437391
  throw new Error(`table structural projection span drift in ${input.storyId} for ${input.tableNodeId}: ${input.resolution} coordinates are out of bounds`);
437408
437392
  }
437409
- const tables2 = nativeStoryElements(input.baseXml).filter((range) => range.tag.localName === "tbl" && range.start >= input.start && range.end <= input.end);
437410
- if (tables2.length !== 1 || tables2[0].start !== input.start || tables2[0].end !== input.end) {
437393
+ const tables2 = nativeStoryElements(input.baseXml).filter((range) => range.tag.localName === "tbl" && range.start === input.start && range.end === input.end);
437394
+ if (tables2.length !== 1) {
437411
437395
  throw new Error(`table structural projection span drift in ${input.storyId} for ${input.tableNodeId}: ${input.resolution} coordinates do not resolve to a single current <w:tbl> span`);
437412
437396
  }
437413
437397
  for (const block of input.affectedBlocks) {
@@ -437494,18 +437478,29 @@ function locateBlockDigestInReplacementXml(blockDigest, replacementXml) {
437494
437478
  const paragraph4 = findParagraphSpanByBlockId(replacementXml, blockDigest.blockId);
437495
437479
  return paragraph4 ? { start: paragraph4.start, length: paragraph4.end - paragraph4.start } : null;
437496
437480
  }
437481
+ function nestedTableParagraphIds(tableXml, inherited) {
437482
+ const parsed = collectXmlElementRanges(tableXml, { fragment: true, additionalNamespaces: inherited });
437483
+ if (parsed.errors.length)
437484
+ throw new Error("table structural projection could not parse the native table XML");
437485
+ const native4 = parsed.ranges.filter((range) => range.tag.namespaceUri === "http://schemas.openxmlformats.org/wordprocessingml/2006/main");
437486
+ const tables2 = native4.filter((range) => range.tag.localName === "tbl");
437487
+ if (!tables2.some((outer) => tables2.some((inner) => inner.start > outer.start && inner.end < outer.end)))
437488
+ return null;
437489
+ return [...new Set(native4.filter((range) => range.tag.localName === "p").flatMap((range) => range.tag.attributes.filter((attribute2) => attribute2.localName === "paraId" && attribute2.namespaceUri === "http://schemas.microsoft.com/office/word/2010/wordml").map((attribute2) => attribute2.value)))];
437490
+ }
437497
437491
  function composeLiveTableBlockXml(tableXml, tableNodeId, tableBlockIds, storyBlocks, columnInsertions, rowProperties, cellProperties, gridChangeXml, inherited) {
437492
+ const nestedParagraphIds = nestedTableParagraphIds(tableXml, inherited);
437498
437493
  const liveTableBlocks = storyBlocks.filter((block) => block.structuralRefs.tableNodeId === tableNodeId);
437499
437494
  const liveTableBlockIds = new Set(liveTableBlocks.map((block) => block.blockId));
437500
437495
  const snapshotTableBlockIds = tableBlockIdsFromXml(tableXml);
437501
437496
  const hasConvergedTopologyMismatch = liveTableBlocks.some((block) => !snapshotTableBlockIds.has(block.blockId)) || [...snapshotTableBlockIds].some((blockId) => !liveTableBlockIds.has(blockId));
437502
- if (hasConvergedTopologyMismatch && liveTableBlocks.length > 0 && liveTableBlocks.every((block) => block.structuralRefs.rowNodeId && block.structuralRefs.cellNodeId)) {
437497
+ if (hasConvergedTopologyMismatch && nestedParagraphIds === null && liveTableBlocks.length > 0 && liveTableBlocks.every((block) => block.structuralRefs.rowNodeId && block.structuralRefs.cellNodeId)) {
437503
437498
  return composeLiveTableStructure(tableXml, tableNodeId, liveTableBlocks, columnInsertions, rowProperties, cellProperties, gridChangeXml, inherited);
437504
437499
  }
437505
437500
  const blocksById = new Map(storyBlocks.map((block) => [block.blockId, block]));
437506
437501
  const namespaces = new XmlEmissionContext(tableXml, inherited);
437507
437502
  const replacements = [];
437508
- for (const blockId of tableBlockIds) {
437503
+ for (const blockId of nestedParagraphIds ?? tableBlockIds) {
437509
437504
  const block = blocksById.get(blockId);
437510
437505
  if (!block)
437511
437506
  continue;
@@ -437568,6 +437563,10 @@ function replaceLiveTableStructuralProperties(tableXml, tableBlocks, rowProperti
437568
437563
  return composed;
437569
437564
  }
437570
437565
  function composeCreatedTableBlockXml(tableXml, tableNodeId, storyBlocks, columnInsertions, rowProperties, cellProperties, gridChangeXml, inherited) {
437566
+ const nestedParagraphIds = nestedTableParagraphIds(tableXml, inherited);
437567
+ if (nestedParagraphIds !== null) {
437568
+ return composeLiveTableBlockXml(tableXml, tableNodeId, nestedParagraphIds, storyBlocks, columnInsertions, rowProperties, cellProperties, gridChangeXml, inherited);
437569
+ }
437571
437570
  const tableBlocks = storyBlocks.filter((block) => block.structuralRefs.tableNodeId === tableNodeId);
437572
437571
  if (tableBlocks.length > 0 && tableBlocks.every((block) => block.structuralRefs.rowNodeId && block.structuralRefs.cellNodeId)) {
437573
437572
  return composeLiveTableStructure(tableXml, tableNodeId, tableBlocks, columnInsertions, rowProperties, cellProperties, gridChangeXml, inherited);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superdoc/mcp",
3
- "version": "1.6.0-next.19",
3
+ "version": "1.6.0-next.20",
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.19.0-next.19",
27
+ "@superdoc/sdk": "2.19.0-next.20",
28
28
  "debug": "^4.4.3",
29
29
  "zod": "^4.3.6"
30
30
  },
31
31
  "devDependencies": {
32
- "superdoc": "2.22.0-next.18",
33
- "@superdoc/docx-engine": "0.21.0-next.19",
32
+ "superdoc": "2.22.0-next.19",
33
+ "@superdoc/docx-engine": "0.21.0-next.20",
34
34
  "@superdoc/document-api": "0.1.0-alpha.0",
35
35
  "@types/bun": "^1.3.8",
36
36
  "@types/node": "22.19.2",