@beyondwork/docx-react-component 1.0.120 → 1.0.121

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 (116) hide show
  1. package/README.md +1 -0
  2. package/dist/api/public-types.cjs +1713 -55
  3. package/dist/api/public-types.d.cts +2 -2
  4. package/dist/api/public-types.d.ts +2 -2
  5. package/dist/api/public-types.js +6 -6
  6. package/dist/api/v3.cjs +4958 -406
  7. package/dist/api/v3.d.cts +3 -3
  8. package/dist/api/v3.d.ts +3 -3
  9. package/dist/api/v3.js +14 -14
  10. package/dist/{canonical-document-fNawStsc.d.cts → canonical-document-ByIqTd4s.d.cts} +9 -1
  11. package/dist/{canonical-document-fNawStsc.d.ts → canonical-document-ByIqTd4s.d.ts} +9 -1
  12. package/dist/{chunk-5RNMPLXU.js → chunk-37SEJQ3G.js} +4 -4
  13. package/dist/{chunk-FXGQM2JB.js → chunk-3OFSP2IX.js} +11 -5
  14. package/dist/{chunk-U5BSQXF4.js → chunk-3OHVK2D6.js} +70 -12
  15. package/dist/{chunk-AUQDC5BD.js → chunk-3TUQCHYT.js} +101 -2
  16. package/dist/{chunk-SJSMYEMU.js → chunk-B4YHWFE3.js} +3 -3
  17. package/dist/{chunk-XC56YLIS.js → chunk-C2LWJ4CZ.js} +4 -0
  18. package/dist/{chunk-VDIUVT46.js → chunk-CX42VC67.js} +1 -1
  19. package/dist/{chunk-KCHEAX4Z.js → chunk-EMDH4IQN.js} +148 -70
  20. package/dist/{chunk-TMQGWF7R.js → chunk-G3B2OBCZ.js} +352 -17
  21. package/dist/{chunk-VCL5MJMZ.js → chunk-GON2DNTE.js} +149 -28
  22. package/dist/{chunk-WVZX4NYG.js → chunk-GZW2ERUO.js} +601 -47
  23. package/dist/{chunk-WDNEPRFW.js → chunk-ICX54W4U.js} +1 -1
  24. package/dist/{chunk-FIGWJ43K.js → chunk-IT2DK3A7.js} +1883 -90
  25. package/dist/{chunk-2ZWFQ74R.js → chunk-OBCP6VTG.js} +1 -1
  26. package/dist/{chunk-FLNQY74K.js → chunk-OYGMRRR7.js} +1 -1
  27. package/dist/{chunk-MPYYBRVN.js → chunk-PCXTMEGY.js} +782 -124
  28. package/dist/{chunk-4JNUMMM7.js → chunk-PGGPPZ65.js} +17 -2
  29. package/dist/{chunk-KHZNNBTN.js → chunk-QFU7ZOAD.js} +43 -39
  30. package/dist/{chunk-4ZNQFWFM.js → chunk-QIO6V46H.js} +84 -4
  31. package/dist/{chunk-IQ2VJEF6.js → chunk-QNGJRZ2D.js} +1 -1
  32. package/dist/{chunk-BM5NSDII.js → chunk-S4ANOS2M.js} +2 -2
  33. package/dist/{chunk-AQA7OZ2R.js → chunk-TFSXOIAI.js} +959 -43
  34. package/dist/{chunk-NQZUGMLW.js → chunk-TMU7JMXX.js} +184 -32
  35. package/dist/{chunk-KD5K5XIA.js → chunk-UHQOUTAX.js} +568 -88
  36. package/dist/{chunk-327AIUXL.js → chunk-UWDWGQH5.js} +11 -4
  37. package/dist/{chunk-BBB4GSDB.js → chunk-XVFENXLK.js} +2 -2
  38. package/dist/{chunk-MUEN2WOG.js → chunk-ZKSDVHGH.js} +6 -3
  39. package/dist/compare.cjs +17 -2
  40. package/dist/compare.d.cts +1 -1
  41. package/dist/compare.d.ts +1 -1
  42. package/dist/compare.js +3 -3
  43. package/dist/core/commands/formatting-commands.d.cts +2 -2
  44. package/dist/core/commands/formatting-commands.d.ts +2 -2
  45. package/dist/core/commands/image-commands.cjs +814 -45
  46. package/dist/core/commands/image-commands.d.cts +2 -2
  47. package/dist/core/commands/image-commands.d.ts +2 -2
  48. package/dist/core/commands/image-commands.js +8 -8
  49. package/dist/core/commands/section-layout-commands.d.cts +2 -2
  50. package/dist/core/commands/section-layout-commands.d.ts +2 -2
  51. package/dist/core/commands/style-commands.d.cts +2 -2
  52. package/dist/core/commands/style-commands.d.ts +2 -2
  53. package/dist/core/commands/table-structure-commands.cjs +750 -42
  54. package/dist/core/commands/table-structure-commands.d.cts +2 -2
  55. package/dist/core/commands/table-structure-commands.d.ts +2 -2
  56. package/dist/core/commands/table-structure-commands.js +6 -6
  57. package/dist/core/commands/text-commands.cjs +910 -57
  58. package/dist/core/commands/text-commands.d.cts +2 -2
  59. package/dist/core/commands/text-commands.d.ts +2 -2
  60. package/dist/core/commands/text-commands.js +8 -8
  61. package/dist/core/selection/mapping.d.cts +2 -2
  62. package/dist/core/selection/mapping.d.ts +2 -2
  63. package/dist/core/state/editor-state.cjs +17 -2
  64. package/dist/core/state/editor-state.d.cts +2 -2
  65. package/dist/core/state/editor-state.d.ts +2 -2
  66. package/dist/core/state/editor-state.js +2 -2
  67. package/dist/index.cjs +6203 -625
  68. package/dist/index.d.cts +5 -5
  69. package/dist/index.d.ts +5 -5
  70. package/dist/index.js +299 -67
  71. package/dist/io/docx-session.cjs +354 -102
  72. package/dist/io/docx-session.d.cts +4 -4
  73. package/dist/io/docx-session.d.ts +4 -4
  74. package/dist/io/docx-session.js +5 -5
  75. package/dist/legal.cjs +183 -31
  76. package/dist/legal.d.cts +1 -1
  77. package/dist/legal.d.ts +1 -1
  78. package/dist/legal.js +3 -3
  79. package/dist/{loader-CaohrhNl.d.ts → loader-BF8ju_LK.d.ts} +22 -4
  80. package/dist/{loader-BpCyGnZl.d.cts → loader-g54WRvj1.d.cts} +22 -4
  81. package/dist/{public-types-Dpch9JG0.d.cts → public-types-D_y4Ptcj.d.cts} +747 -21
  82. package/dist/{public-types-C948HNVF.d.ts → public-types-Dl1jiWjk.d.ts} +747 -21
  83. package/dist/public-types.cjs +1713 -55
  84. package/dist/public-types.d.cts +2 -2
  85. package/dist/public-types.d.ts +2 -2
  86. package/dist/public-types.js +6 -6
  87. package/dist/runtime/collab.cjs +4 -0
  88. package/dist/runtime/collab.d.cts +3 -3
  89. package/dist/runtime/collab.d.ts +3 -3
  90. package/dist/runtime/collab.js +2 -2
  91. package/dist/runtime/document-runtime.cjs +3699 -507
  92. package/dist/runtime/document-runtime.d.cts +2 -2
  93. package/dist/runtime/document-runtime.d.ts +2 -2
  94. package/dist/runtime/document-runtime.js +18 -18
  95. package/dist/{session-Dqg17V3s.d.ts → session-C1EPAkcI.d.ts} +3 -3
  96. package/dist/{session-BlXE5zxz.d.cts → session-D15QOO0Q.d.cts} +3 -3
  97. package/dist/session.cjs +951 -104
  98. package/dist/session.d.cts +5 -5
  99. package/dist/session.d.ts +5 -5
  100. package/dist/session.js +10 -8
  101. package/dist/tailwind.cjs +1752 -91
  102. package/dist/tailwind.d.cts +2 -2
  103. package/dist/tailwind.d.ts +2 -2
  104. package/dist/tailwind.js +10 -10
  105. package/dist/{types-C9vZVpKy.d.cts → types-BoSRp2Vg.d.cts} +2 -2
  106. package/dist/{types-B1tlF1bq.d.ts → types-DEvRwq9C.d.ts} +2 -2
  107. package/dist/ui-tailwind/editor-surface/search-plugin.d.cts +3 -3
  108. package/dist/ui-tailwind/editor-surface/search-plugin.d.ts +3 -3
  109. package/dist/ui-tailwind/editor-surface/search-plugin.js +7 -7
  110. package/dist/ui-tailwind/theme/editor-theme.css +5 -5
  111. package/dist/ui-tailwind.cjs +1752 -91
  112. package/dist/ui-tailwind.d.cts +8 -8
  113. package/dist/ui-tailwind.d.ts +8 -8
  114. package/dist/ui-tailwind.js +10 -10
  115. package/package.json +17 -5
  116. package/dist/ui-tailwind/theme/tokens.css +0 -382
package/dist/session.cjs CHANGED
@@ -24,7 +24,8 @@ __export(session_exports, {
24
24
  SessionNotOpenError: () => SessionNotOpenError,
25
25
  SessionNotWiredError: () => SessionNotWiredError,
26
26
  isReopenBarrier: () => isReopenBarrier,
27
- loadDocxSessionAsync: () => loadDocxSessionAsync
27
+ loadDocxSessionAsync: () => loadDocxSessionAsync,
28
+ loadDocxSessionSync: () => loadDocxSessionSync
28
29
  });
29
30
  module.exports = __toCommonJS(session_exports);
30
31
 
@@ -9630,6 +9631,9 @@ function validateDocumentNode(value, path, issues, context = "root") {
9630
9631
  }
9631
9632
  return;
9632
9633
  case "table_row":
9634
+ if (record.sourceRef !== void 0) {
9635
+ validateCanonicalSourceRef(record.sourceRef, `${path}.sourceRef`, issues);
9636
+ }
9633
9637
  if (!Array.isArray(record.cells)) {
9634
9638
  issues.push({ path: `${path}.cells`, message: "cells must be an array." });
9635
9639
  } else {
@@ -9639,6 +9643,9 @@ function validateDocumentNode(value, path, issues, context = "root") {
9639
9643
  }
9640
9644
  return;
9641
9645
  case "table_cell":
9646
+ if (record.sourceRef !== void 0) {
9647
+ validateCanonicalSourceRef(record.sourceRef, `${path}.sourceRef`, issues);
9648
+ }
9642
9649
  if (!Array.isArray(record.children)) {
9643
9650
  issues.push({ path: `${path}.children`, message: "children must be an array." });
9644
9651
  } else {
@@ -9669,9 +9676,15 @@ function validateDocumentNode(value, path, issues, context = "root") {
9669
9676
  case "bookmark_start":
9670
9677
  expectString(record.bookmarkId, `${path}.bookmarkId`, issues);
9671
9678
  expectString(record.name, `${path}.name`, issues);
9679
+ if (record.sourceRef !== void 0) {
9680
+ validateCanonicalSourceRef(record.sourceRef, `${path}.sourceRef`, issues);
9681
+ }
9672
9682
  return;
9673
9683
  case "bookmark_end":
9674
9684
  expectString(record.bookmarkId, `${path}.bookmarkId`, issues);
9685
+ if (record.sourceRef !== void 0) {
9686
+ validateCanonicalSourceRef(record.sourceRef, `${path}.sourceRef`, issues);
9687
+ }
9675
9688
  return;
9676
9689
  case "scope_marker_start":
9677
9690
  case "scope_marker_end":
@@ -9772,6 +9785,9 @@ function validateDocumentNode(value, path, issues, context = "root") {
9772
9785
  return;
9773
9786
  }
9774
9787
  case "ole_embed":
9788
+ if (record.sourceRef !== void 0) {
9789
+ validateCanonicalSourceRef(record.sourceRef, `${path}.sourceRef`, issues);
9790
+ }
9775
9791
  expectString(record.id, `${path}.id`, issues);
9776
9792
  expectString(record.relationshipId, `${path}.relationshipId`, issues);
9777
9793
  expectString(record.rawXml, `${path}.rawXml`, issues);
@@ -9900,12 +9916,12 @@ function validateCanonicalSourceRef(value, path, issues) {
9900
9916
  return;
9901
9917
  }
9902
9918
  expectString(record.sourceId, `${path}.sourceId`, issues);
9903
- for (const key of ["partPath", "storyKind", "element"]) {
9919
+ for (const key of ["partPath", "storyKind", "element", "xmlPath", "tableCellPath"]) {
9904
9920
  if (record[key] !== void 0) {
9905
9921
  expectString(record[key], `${path}.${key}`, issues);
9906
9922
  }
9907
9923
  }
9908
- for (const key of ["ordinal", "startOffset", "endOffset"]) {
9924
+ for (const key of ["ordinal", "startOffset", "endOffset", "tableDepth"]) {
9909
9925
  if (record[key] !== void 0 && (!Number.isInteger(record[key]) || record[key] < 0)) {
9910
9926
  issues.push({
9911
9927
  path: `${path}.${key}`,
@@ -14810,6 +14826,7 @@ function resolveContentType(path, contentTypes) {
14810
14826
  // src/io/ooxml/parse-bookmark-references.ts
14811
14827
  var HYPERLINK_ANCHOR_RE = /<(?:\w+:)?hyperlink\b[^>]*\bw:anchor\s*=\s*"([^"]*)"/gi;
14812
14828
  var INSTR_TEXT_RE = /<(?:\w+:)?instrText\b[^>]*>([\s\S]*?)<\/(?:\w+:)?instrText>/gi;
14829
+ var SIMPLE_FIELD_INSTR_RE = /<(?:\w+:)?fldSimple\b[^>]*\bw:instr\s*=\s*"([^"]*)"/gi;
14813
14830
  var TOC_FIELD_RE = /\bTOC\b/;
14814
14831
  var REFLIKE_FIELD_RE = /\b(?:HYPERLINK|REF|PAGEREF|NOTEREF)\s+([A-Za-z0-9_:.\-]+)/g;
14815
14832
  var DATA_BINDING_RE = /<(?:\w+:)?dataBinding\b/i;
@@ -14828,12 +14845,14 @@ function scanBookmarkReferences(documentXml, callerAllowlist = []) {
14828
14845
  }
14829
14846
  INSTR_TEXT_RE.lastIndex = 0;
14830
14847
  while ((m = INSTR_TEXT_RE.exec(documentXml)) !== null) {
14831
- const instrText = m[1] ?? "";
14832
- if (TOC_FIELD_RE.test(instrText)) retainAllToc = true;
14833
- REFLIKE_FIELD_RE.lastIndex = 0;
14834
- let r;
14835
- while ((r = REFLIKE_FIELD_RE.exec(instrText)) !== null) {
14836
- if (r[1]) retained.add(r[1]);
14848
+ if (scanInstructionForRetainedBookmarks(m[1] ?? "", retained)) {
14849
+ retainAllToc = true;
14850
+ }
14851
+ }
14852
+ SIMPLE_FIELD_INSTR_RE.lastIndex = 0;
14853
+ while ((m = SIMPLE_FIELD_INSTR_RE.exec(documentXml)) !== null) {
14854
+ if (scanInstructionForRetainedBookmarks(m[1] ?? "", retained)) {
14855
+ retainAllToc = true;
14837
14856
  }
14838
14857
  }
14839
14858
  retainRevisionBoundedBookmarks(documentXml, retained);
@@ -14843,6 +14862,15 @@ function scanBookmarkReferences(documentXml, callerAllowlist = []) {
14843
14862
  retainAll
14844
14863
  };
14845
14864
  }
14865
+ function scanInstructionForRetainedBookmarks(instruction, retained) {
14866
+ const hasTocField = TOC_FIELD_RE.test(instruction);
14867
+ REFLIKE_FIELD_RE.lastIndex = 0;
14868
+ let r;
14869
+ while ((r = REFLIKE_FIELD_RE.exec(instruction)) !== null) {
14870
+ if (r[1]) retained.add(r[1]);
14871
+ }
14872
+ return hasTocField;
14873
+ }
14846
14874
  function retainRevisionBoundedBookmarks(documentXml, retained) {
14847
14875
  const starts = /* @__PURE__ */ new Map();
14848
14876
  BOOKMARK_START_RE.lastIndex = 0;
@@ -18345,7 +18373,7 @@ var SAFE_TABLE_FIELD_FAMILIES = /* @__PURE__ */ new Set([
18345
18373
  "FORMULA"
18346
18374
  ]);
18347
18375
  var RISKY_TABLE_MARKUP_RE = /<w:(ins|del|moveFrom|moveTo|rPrChange|pPrChange|tblPrChange|trPrChange|tcPrChange|sectPrChange|cellIns|cellDel|cellMerge|smartTag)\b/;
18348
- var SIMPLE_FIELD_INSTR_RE = /\bw:instr="([^"]*)"/g;
18376
+ var SIMPLE_FIELD_INSTR_RE2 = /\bw:instr="([^"]*)"/g;
18349
18377
  var COMPLEX_FIELD_TOKEN_RE = /<(?:\w+:)?fldChar\b[^>]*?(?:\w+:)?fldCharType="(begin|separate|end)"[^>]*?(?:\/>|>[\s\S]*?<\/(?:\w+:)?fldChar>)|<(?:\w+:)?instrText\b[^>]*>([\s\S]*?)<\/(?:\w+:)?instrText>/gu;
18350
18378
  function decodeXmlEntities5(text) {
18351
18379
  return text.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, '"').replace(/&apos;/g, "'").replace(/&amp;/g, "&");
@@ -18386,7 +18414,7 @@ function isSafeTableFieldInstruction(instruction) {
18386
18414
  }
18387
18415
  function tableRequiresOpaquePreservation(rawXml) {
18388
18416
  if (RISKY_TABLE_MARKUP_RE.test(rawXml)) return true;
18389
- const simpleInstructions = [...rawXml.matchAll(SIMPLE_FIELD_INSTR_RE)].map(
18417
+ const simpleInstructions = [...rawXml.matchAll(SIMPLE_FIELD_INSTR_RE2)].map(
18390
18418
  (match) => match[1] ?? ""
18391
18419
  );
18392
18420
  const complexInstructions = extractComplexFieldInstructionsFromRaw(rawXml);
@@ -19069,7 +19097,11 @@ function parseMainDocumentXmlInner(xml, relationships, mediaParts, sourcePartPat
19069
19097
  const documentElement2 = findChildElement4(root, "document");
19070
19098
  const bodyElement = findChildElement4(documentElement2, "body");
19071
19099
  const relationshipMap = new Map(relationships.map((relationship) => [relationship.id, relationship]));
19072
- const allBlocks = bodyElement.children.filter((node) => node.type === "element").map((node) => parseBodyChild(node, xml, relationshipMap, relationships, mediaParts, sourcePartPath)).filter((block) => !(block.type === "opaque_block" && block.rawXml === ""));
19100
+ const allBlocks = mapElementChildrenWithXmlPath(
19101
+ bodyElement,
19102
+ "/document[1]/body[1]",
19103
+ (node, xmlPath) => parseBodyChild(node, xml, relationshipMap, relationships, mediaParts, sourcePartPath, 0, xmlPath)
19104
+ ).filter((block) => !(block.type === "opaque_block" && block.rawXml === ""));
19073
19105
  let finalSectionProperties;
19074
19106
  const blocks = [];
19075
19107
  for (let i = 0; i < allBlocks.length; i++) {
@@ -19159,22 +19191,25 @@ function parseBlockStreamFromXml(xml, ctx) {
19159
19191
  const priorDepth = activeTxbxBlockStreamDepth;
19160
19192
  activeTxbxBlockStreamDepth = depth;
19161
19193
  try {
19162
- return wrapper.children.filter((n) => n.type === "element").map(
19163
- (n) => parseBodyChild(
19194
+ return mapElementChildrenWithXmlPath(
19195
+ wrapper,
19196
+ `/${localName(wrapper.name)}[1]`,
19197
+ (n, xmlPath) => parseBodyChild(
19164
19198
  n,
19165
19199
  xml,
19166
19200
  relationshipMap,
19167
19201
  ctx.relationships,
19168
19202
  ctx.mediaParts,
19169
19203
  ctx.sourcePartPath,
19170
- depth
19204
+ depth,
19205
+ xmlPath
19171
19206
  )
19172
19207
  );
19173
19208
  } finally {
19174
19209
  activeTxbxBlockStreamDepth = priorDepth;
19175
19210
  }
19176
19211
  }
19177
- function parseBodyChild(node, sourceXml, relationshipMap, relationships, mediaParts, sourcePartPath, _depth = 0) {
19212
+ function parseBodyChild(node, sourceXml, relationshipMap, relationships, mediaParts, sourcePartPath, _depth = 0, sourceXmlPath = `/${localName(node.name)}[1]`) {
19178
19213
  const nodeType = localName(node.name);
19179
19214
  if (nodeType === "tbl") {
19180
19215
  const rawTableXml = sourceXml.slice(node.start, node.end);
@@ -19185,7 +19220,15 @@ function parseBodyChild(node, sourceXml, relationshipMap, relationships, mediaPa
19185
19220
  };
19186
19221
  }
19187
19222
  try {
19188
- return parseTableElement(node, sourceXml, relationshipMap, relationships, mediaParts, sourcePartPath);
19223
+ return parseTableElement(
19224
+ node,
19225
+ sourceXml,
19226
+ relationshipMap,
19227
+ relationships,
19228
+ mediaParts,
19229
+ sourcePartPath,
19230
+ sourceXmlPath
19231
+ );
19189
19232
  } catch {
19190
19233
  return {
19191
19234
  type: "opaque_block",
@@ -19194,10 +19237,26 @@ function parseBodyChild(node, sourceXml, relationshipMap, relationships, mediaPa
19194
19237
  }
19195
19238
  }
19196
19239
  if (nodeType === "sdt") {
19197
- return parseSdtElement(node, sourceXml, relationshipMap, relationships, mediaParts, sourcePartPath);
19240
+ return parseSdtElement(
19241
+ node,
19242
+ sourceXml,
19243
+ relationshipMap,
19244
+ relationships,
19245
+ mediaParts,
19246
+ sourcePartPath,
19247
+ sourceXmlPath
19248
+ );
19198
19249
  }
19199
19250
  if (nodeType === "customXml") {
19200
- return parseCustomXmlElement(node, sourceXml, relationshipMap, relationships, mediaParts, sourcePartPath);
19251
+ return parseCustomXmlElement(
19252
+ node,
19253
+ sourceXml,
19254
+ relationshipMap,
19255
+ relationships,
19256
+ mediaParts,
19257
+ sourcePartPath,
19258
+ sourceXmlPath
19259
+ );
19201
19260
  }
19202
19261
  if (nodeType === "altChunk") {
19203
19262
  return parseAltChunkElement(node, sourceXml);
@@ -19343,6 +19402,7 @@ function parseBodyChild(node, sourceXml, relationshipMap, relationships, mediaPa
19343
19402
  type: "bookmark_start",
19344
19403
  bookmarkId: bkId,
19345
19404
  name: bkName,
19405
+ sourceRef: createElementSourceRef(sourcePartPath, "bookmarkStart", child),
19346
19406
  rawXml: sourceXml.slice(child.start, child.end)
19347
19407
  };
19348
19408
  flushActiveComplexField(children, () => {
@@ -19370,6 +19430,7 @@ function parseBodyChild(node, sourceXml, relationshipMap, relationships, mediaPa
19370
19430
  const bookmarkNode = {
19371
19431
  type: "bookmark_end",
19372
19432
  bookmarkId: bkEndId,
19433
+ sourceRef: createElementSourceRef(sourcePartPath, "bookmarkEnd", child),
19373
19434
  rawXml: sourceXml.slice(child.start, child.end)
19374
19435
  };
19375
19436
  flushActiveComplexField(children, () => {
@@ -19577,7 +19638,7 @@ function flushActiveComplexField(children, reset, activeComplexField) {
19577
19638
  });
19578
19639
  reset();
19579
19640
  }
19580
- function parseTableElement(node, sourceXml, relationshipMap, relationships, mediaParts, sourcePartPath) {
19641
+ function parseTableElement(node, sourceXml, relationshipMap, relationships, mediaParts, sourcePartPath, sourceXmlPath) {
19581
19642
  let styleId;
19582
19643
  let tblLook;
19583
19644
  let propertiesXml;
@@ -19621,13 +19682,24 @@ function parseTableElement(node, sourceXml, relationshipMap, relationships, medi
19621
19682
  break;
19622
19683
  }
19623
19684
  case "tr": {
19624
- rows.push(parseTableRowElement(child, sourceXml, relationshipMap, relationships, mediaParts, sourcePartPath));
19685
+ rows.push(
19686
+ parseTableRowElement(
19687
+ child,
19688
+ sourceXml,
19689
+ relationshipMap,
19690
+ relationships,
19691
+ mediaParts,
19692
+ sourcePartPath,
19693
+ `${sourceXmlPath}/tr[${rows.length + 1}]`
19694
+ )
19695
+ );
19625
19696
  break;
19626
19697
  }
19627
19698
  }
19628
19699
  }
19629
19700
  return {
19630
19701
  type: "table",
19702
+ sourceRef: createStableTableSourceRef(sourcePartPath, "tbl", sourceXmlPath),
19631
19703
  ...styleId ? { styleId } : {},
19632
19704
  ...tblLook ? { tblLook } : {},
19633
19705
  ...propertiesXml ? { propertiesXml } : {},
@@ -19648,7 +19720,7 @@ function parseTableElement(node, sourceXml, relationshipMap, relationships, medi
19648
19720
  rawXml: sourceXml.slice(node.start, node.end)
19649
19721
  };
19650
19722
  }
19651
- function parseTableRowElement(node, sourceXml, relationshipMap, relationships, mediaParts, sourcePartPath) {
19723
+ function parseTableRowElement(node, sourceXml, relationshipMap, relationships, mediaParts, sourcePartPath, sourceXmlPath) {
19652
19724
  let propertiesXml;
19653
19725
  let unknownPropertyChildren;
19654
19726
  let gridBefore;
@@ -19680,12 +19752,23 @@ function parseTableRowElement(node, sourceXml, relationshipMap, relationships, m
19680
19752
  cnfStyle = readRowCnfStyle2(child);
19681
19753
  break;
19682
19754
  case "tc":
19683
- cells.push(parseTableCellElement(child, sourceXml, relationshipMap, relationships, mediaParts, sourcePartPath));
19755
+ cells.push(
19756
+ parseTableCellElement(
19757
+ child,
19758
+ sourceXml,
19759
+ relationshipMap,
19760
+ relationships,
19761
+ mediaParts,
19762
+ sourcePartPath,
19763
+ `${sourceXmlPath}/tc[${cells.length + 1}]`
19764
+ )
19765
+ );
19684
19766
  break;
19685
19767
  }
19686
19768
  }
19687
19769
  return {
19688
19770
  type: "table_row",
19771
+ sourceRef: createStableTableSourceRef(sourcePartPath, "tr", sourceXmlPath),
19689
19772
  ...propertiesXml ? { propertiesXml } : {},
19690
19773
  ...unknownPropertyChildren ? { unknownPropertyChildren } : {},
19691
19774
  ...gridBefore !== void 0 ? { gridBefore } : {},
@@ -19702,7 +19785,7 @@ function parseTableRowElement(node, sourceXml, relationshipMap, relationships, m
19702
19785
  rawXml: sourceXml.slice(node.start, node.end)
19703
19786
  };
19704
19787
  }
19705
- function parseTableCellElement(node, sourceXml, relationshipMap, relationships, mediaParts, sourcePartPath) {
19788
+ function parseTableCellElement(node, sourceXml, relationshipMap, relationships, mediaParts, sourcePartPath, sourceXmlPath) {
19706
19789
  let propertiesXml;
19707
19790
  let unknownPropertyChildren;
19708
19791
  let gridSpan;
@@ -19737,13 +19820,27 @@ function parseTableCellElement(node, sourceXml, relationshipMap, relationships,
19737
19820
  break;
19738
19821
  }
19739
19822
  default: {
19740
- children.push(parseBodyChild(child, sourceXml, relationshipMap, relationships, mediaParts, sourcePartPath));
19823
+ children.push(
19824
+ parseBodyChild(
19825
+ child,
19826
+ sourceXml,
19827
+ relationshipMap,
19828
+ relationships,
19829
+ mediaParts,
19830
+ sourcePartPath,
19831
+ 0,
19832
+ `${sourceXmlPath}/${localName(child.name)}[${countPriorElementSiblingsByName(node, child) + 1}]`
19833
+ )
19834
+ );
19741
19835
  break;
19742
19836
  }
19743
19837
  }
19744
19838
  }
19745
19839
  return {
19746
19840
  type: "table_cell",
19841
+ sourceRef: createStableTableSourceRef(sourcePartPath, "tc", sourceXmlPath, {
19842
+ tableCellPath: sourceXmlPath
19843
+ }),
19747
19844
  ...propertiesXml ? { propertiesXml } : {},
19748
19845
  ...unknownPropertyChildren ? { unknownPropertyChildren } : {},
19749
19846
  ...gridSpan ? { gridSpan } : {},
@@ -19761,7 +19858,7 @@ function parseTableCellElement(node, sourceXml, relationshipMap, relationships,
19761
19858
  rawXml: sourceXml.slice(node.start, node.end)
19762
19859
  };
19763
19860
  }
19764
- function parseSdtElement(node, sourceXml, relationshipMap, relationships, mediaParts, sourcePartPath) {
19861
+ function parseSdtElement(node, sourceXml, relationshipMap, relationships, mediaParts, sourcePartPath, sourceXmlPath) {
19765
19862
  const propertiesNode = node.children.find(
19766
19863
  (child) => child.type === "element" && localName(child.name) === "sdtPr"
19767
19864
  );
@@ -19774,7 +19871,20 @@ function parseSdtElement(node, sourceXml, relationshipMap, relationships, mediaP
19774
19871
  rawXml: sourceXml.slice(node.start, node.end)
19775
19872
  };
19776
19873
  }
19777
- const children = contentNode.children.filter((child) => child.type === "element").map((child) => parseBodyChild(child, sourceXml, relationshipMap, relationships, mediaParts, sourcePartPath));
19874
+ const children = mapElementChildrenWithXmlPath(
19875
+ contentNode,
19876
+ `${sourceXmlPath}/sdtContent[1]`,
19877
+ (child, childXmlPath) => parseBodyChild(
19878
+ child,
19879
+ sourceXml,
19880
+ relationshipMap,
19881
+ relationships,
19882
+ mediaParts,
19883
+ sourcePartPath,
19884
+ 0,
19885
+ childXmlPath
19886
+ )
19887
+ );
19778
19888
  return {
19779
19889
  type: "sdt",
19780
19890
  sourceRef: createElementSourceRef(sourcePartPath, "sdt", node),
@@ -19783,7 +19893,7 @@ function parseSdtElement(node, sourceXml, relationshipMap, relationships, mediaP
19783
19893
  rawXml: sourceXml.slice(node.start, node.end)
19784
19894
  };
19785
19895
  }
19786
- function parseCustomXmlElement(node, sourceXml, relationshipMap, relationships, mediaParts, sourcePartPath) {
19896
+ function parseCustomXmlElement(node, sourceXml, relationshipMap, relationships, mediaParts, sourcePartPath, sourceXmlPath) {
19787
19897
  const uri = readOptionalAttribute2(node, "uri");
19788
19898
  const element = readOptionalAttribute2(node, "element");
19789
19899
  if (!uri && !element) {
@@ -19792,9 +19902,20 @@ function parseCustomXmlElement(node, sourceXml, relationshipMap, relationships,
19792
19902
  rawXml: sourceXml.slice(node.start, node.end)
19793
19903
  };
19794
19904
  }
19795
- const children = node.children.filter(
19796
- (child) => child.type === "element" && localName(child.name) !== "customXmlPr"
19797
- ).map((child) => parseBodyChild(child, sourceXml, relationshipMap, relationships, mediaParts, sourcePartPath));
19905
+ const children = mapElementChildrenWithXmlPath(
19906
+ node,
19907
+ sourceXmlPath,
19908
+ (child, childXmlPath) => localName(child.name) === "customXmlPr" ? void 0 : parseBodyChild(
19909
+ child,
19910
+ sourceXml,
19911
+ relationshipMap,
19912
+ relationships,
19913
+ mediaParts,
19914
+ sourcePartPath,
19915
+ 0,
19916
+ childXmlPath
19917
+ )
19918
+ ).filter((child) => child !== void 0);
19798
19919
  return {
19799
19920
  type: "custom_xml",
19800
19921
  ...uri ? { uri } : {},
@@ -20326,6 +20447,43 @@ function createElementSourceRef(partPath, element, node) {
20326
20447
  endOffset: node.end
20327
20448
  };
20328
20449
  }
20450
+ function createStableTableSourceRef(partPath, element, xmlPath, extras = {}) {
20451
+ return {
20452
+ sourceId: `part:${partPath}#${xmlPath}`,
20453
+ partPath,
20454
+ storyKind: storyKindFromPartPath(partPath),
20455
+ element,
20456
+ xmlPath,
20457
+ ...extras
20458
+ };
20459
+ }
20460
+ function mapElementChildrenWithXmlPath(parent, parentXmlPath, mapChild) {
20461
+ const ordinals = /* @__PURE__ */ new Map();
20462
+ const mapped = [];
20463
+ for (const child of parent.children) {
20464
+ if (child.type !== "element") {
20465
+ continue;
20466
+ }
20467
+ const name = localName(child.name);
20468
+ const ordinal = (ordinals.get(name) ?? 0) + 1;
20469
+ ordinals.set(name, ordinal);
20470
+ mapped.push(mapChild(child, `${parentXmlPath}/${name}[${ordinal}]`));
20471
+ }
20472
+ return mapped;
20473
+ }
20474
+ function countPriorElementSiblingsByName(parent, target) {
20475
+ const name = localName(target.name);
20476
+ let count = 0;
20477
+ for (const child of parent.children) {
20478
+ if (child === target) {
20479
+ return count;
20480
+ }
20481
+ if (child.type === "element" && localName(child.name) === name) {
20482
+ count += 1;
20483
+ }
20484
+ }
20485
+ return count;
20486
+ }
20329
20487
  function createFieldSequenceSourceRef(partPath, node) {
20330
20488
  activeFieldSequenceOrdinal += 1;
20331
20489
  return {
@@ -20427,7 +20585,10 @@ function parseRun(node, sourceXml, relationships, mediaParts, sourcePartPath) {
20427
20585
  })
20428
20586
  });
20429
20587
  if (frame) {
20430
- result.push(frame);
20588
+ result.push({
20589
+ ...frame,
20590
+ sourceRef: createElementSourceRef(sourcePartPath, "drawing", child)
20591
+ });
20431
20592
  break;
20432
20593
  }
20433
20594
  } catch {
@@ -20476,6 +20637,7 @@ function parseRun(node, sourceXml, relationships, mediaParts, sourcePartPath) {
20476
20637
  ...parsedMedia.map((media) => ({
20477
20638
  type: "image",
20478
20639
  mediaId: media.mediaId,
20640
+ sourceRef: createElementSourceRef(sourcePartPath, "drawing", child),
20479
20641
  relationshipId: media.relationshipId,
20480
20642
  packagePartName: media.packagePartName,
20481
20643
  contentType: media.contentType,
@@ -20506,7 +20668,10 @@ function parseRun(node, sourceXml, relationships, mediaParts, sourcePartPath) {
20506
20668
  })
20507
20669
  });
20508
20670
  if (frame) {
20509
- result.push(frame);
20671
+ result.push({
20672
+ ...frame,
20673
+ sourceRef: createElementSourceRef(sourcePartPath, "AlternateContent", child)
20674
+ });
20510
20675
  break;
20511
20676
  }
20512
20677
  } catch {
@@ -20543,7 +20708,10 @@ function parseRun(node, sourceXml, relationships, mediaParts, sourcePartPath) {
20543
20708
  try {
20544
20709
  const oleNode = parseObject(child, objectXml, relationships);
20545
20710
  if (oleNode) {
20546
- result.push(oleNode);
20711
+ result.push({
20712
+ ...oleNode,
20713
+ sourceRef: createElementSourceRef(sourcePartPath, "object", child)
20714
+ });
20547
20715
  break;
20548
20716
  }
20549
20717
  } catch {
@@ -21608,6 +21776,45 @@ function disposeIdleHandles(store) {
21608
21776
  }
21609
21777
 
21610
21778
  // src/io/normalize/normalize-text.ts
21779
+ function normalizeParsedTextDocument(document2, packagePartName = "/word/document.xml") {
21780
+ const state = {
21781
+ nextFragmentIndex: 1,
21782
+ nextWarningIndex: 1,
21783
+ nextDiagnosticIndex: 1,
21784
+ cursor: 0,
21785
+ media: {
21786
+ items: {}
21787
+ },
21788
+ preservation: {
21789
+ opaqueFragments: {},
21790
+ packageParts: {}
21791
+ },
21792
+ diagnostics: {
21793
+ warnings: [],
21794
+ errors: []
21795
+ }
21796
+ };
21797
+ const children = [];
21798
+ let previousParagraph = false;
21799
+ for (const block of document2.blocks) {
21800
+ const normalizedBlocks = normalizeBlocks(block, state, packagePartName);
21801
+ for (const normalizedBlock of normalizedBlocks) {
21802
+ if (previousParagraph && normalizedBlock.type === "paragraph") {
21803
+ state.cursor += 1;
21804
+ }
21805
+ children.push(normalizedBlock);
21806
+ previousParagraph = normalizedBlock.type === "paragraph";
21807
+ }
21808
+ }
21809
+ const content = { type: "doc", children };
21810
+ return {
21811
+ content,
21812
+ media: state.media,
21813
+ preservation: state.preservation,
21814
+ diagnostics: state.diagnostics,
21815
+ ...document2.finalSectionProperties !== void 0 ? { finalSectionProperties: document2.finalSectionProperties } : {}
21816
+ };
21817
+ }
21611
21818
  var NORMALIZE_YIELD_STRIDE = 256;
21612
21819
  async function normalizeParsedTextDocumentAsync(document2, packagePartName = "/word/document.xml", scheduler) {
21613
21820
  const state = {
@@ -21717,6 +21924,7 @@ function normalizeTable(table, state, packagePartName) {
21717
21924
  state.cursor += 1;
21718
21925
  return {
21719
21926
  type: "table",
21927
+ ...table.sourceRef ? { sourceRef: table.sourceRef } : {},
21720
21928
  ...table.styleId ? { styleId: table.styleId } : {},
21721
21929
  ...table.propertiesXml ? { propertiesXml: table.propertiesXml } : {},
21722
21930
  ...table.unknownPropertyChildren ? { unknownPropertyChildren: table.unknownPropertyChildren } : {},
@@ -21740,6 +21948,7 @@ function normalizeTableRow(row, state, packagePartName) {
21740
21948
  const cells = row.cells.map((cell) => normalizeTableCell(cell, state, packagePartName));
21741
21949
  return {
21742
21950
  type: "table_row",
21951
+ ...row.sourceRef ? { sourceRef: row.sourceRef } : {},
21743
21952
  ...row.propertiesXml ? { propertiesXml: row.propertiesXml } : {},
21744
21953
  ...row.unknownPropertyChildren ? { unknownPropertyChildren: row.unknownPropertyChildren } : {},
21745
21954
  ...row.gridBefore !== void 0 ? { gridBefore: row.gridBefore } : {},
@@ -21765,6 +21974,7 @@ function normalizeTableCell(cell, state, packagePartName) {
21765
21974
  }
21766
21975
  return {
21767
21976
  type: "table_cell",
21977
+ ...cell.sourceRef ? { sourceRef: cell.sourceRef } : {},
21768
21978
  ...cell.propertiesXml ? { propertiesXml: cell.propertiesXml } : {},
21769
21979
  ...cell.unknownPropertyChildren ? { unknownPropertyChildren: cell.unknownPropertyChildren } : {},
21770
21980
  ...cell.gridSpan ? { gridSpan: cell.gridSpan } : {},
@@ -21933,6 +22143,7 @@ function normalizeInlineChildren(nodes, state, packagePartName) {
21933
22143
  case "ole_embed":
21934
22144
  normalized.push({
21935
22145
  type: "ole_embed",
22146
+ ...node.sourceRef ? { sourceRef: node.sourceRef } : {},
21936
22147
  id: node.id,
21937
22148
  ...node.progId ? { progId: node.progId } : {},
21938
22149
  embedType: node.embedType,
@@ -21946,13 +22157,15 @@ function normalizeInlineChildren(nodes, state, packagePartName) {
21946
22157
  normalized.push({
21947
22158
  type: "bookmark_start",
21948
22159
  bookmarkId: node.bookmarkId,
21949
- name: node.name
22160
+ name: node.name,
22161
+ ...node.sourceRef ? { sourceRef: node.sourceRef } : {}
21950
22162
  });
21951
22163
  break;
21952
22164
  case "bookmark_end":
21953
22165
  normalized.push({
21954
22166
  type: "bookmark_end",
21955
- bookmarkId: node.bookmarkId
22167
+ bookmarkId: node.bookmarkId,
22168
+ ...node.sourceRef ? { sourceRef: node.sourceRef } : {}
21956
22169
  });
21957
22170
  break;
21958
22171
  case "scope_marker_start":
@@ -22025,6 +22238,7 @@ function normalizeImageNode(node, state) {
22025
22238
  return {
22026
22239
  type: "image",
22027
22240
  mediaId: node.mediaId,
22241
+ ...node.sourceRef ? { sourceRef: node.sourceRef } : {},
22028
22242
  ...node.altText ? { altText: node.altText } : {},
22029
22243
  ...node.placementXml ? { placementXml: node.placementXml } : {},
22030
22244
  ...node.display ? { display: node.display } : {},
@@ -24567,16 +24781,14 @@ function parseHdrFtrXml(xml, rootLocalName, opts = { relationships: [] }) {
24567
24781
  return { blocks: [] };
24568
24782
  }
24569
24783
  const blocks = [];
24570
- for (const child of hdrFtrElement.children) {
24571
- if (child.type !== "element") {
24572
- continue;
24573
- }
24784
+ const rootXmlPath = `/${rootLocalName}[1]`;
24785
+ for (const [child, childXmlPath] of elementChildrenWithXmlPath(hdrFtrElement, rootXmlPath)) {
24574
24786
  const name = localName(child.name);
24575
24787
  if (name === "p") {
24576
24788
  blocks.push(parseParagraphElement(child, xml, opts));
24577
24789
  } else if (name === "tbl") {
24578
24790
  if (isSimpleSecondaryStoryTable(child)) {
24579
- blocks.push(parseSimpleTableElement(child, xml, opts));
24791
+ blocks.push(parseSimpleTableElement(child, xml, opts, childXmlPath));
24580
24792
  } else {
24581
24793
  blocks.push({
24582
24794
  type: "opaque_block",
@@ -24625,7 +24837,7 @@ function parseParagraphElement(pElement, sourceXml, opts) {
24625
24837
  } else if (name === "hyperlink") {
24626
24838
  children.push(parseHyperlinkElement(child, opts));
24627
24839
  } else if (name === "bookmarkStart" || name === "bookmarkEnd") {
24628
- children.push(parseBookmarkElement(child));
24840
+ children.push(parseBookmarkElement(child, opts.sourcePartPath ?? "/word/document.xml"));
24629
24841
  } else if (name === "fldSimple") {
24630
24842
  if (activeComplexField && activeComplexField.instruction.trim().length > 0) {
24631
24843
  children.push(
@@ -24651,7 +24863,7 @@ function parseParagraphElement(pElement, sourceXml, opts) {
24651
24863
  } else if (gname === "hyperlink") {
24652
24864
  children.push(parseHyperlinkElement(grandchild, opts));
24653
24865
  } else if (gname === "bookmarkStart" || gname === "bookmarkEnd") {
24654
- children.push(parseBookmarkElement(grandchild));
24866
+ children.push(parseBookmarkElement(grandchild, opts.sourcePartPath ?? "/word/document.xml"));
24655
24867
  } else if (gname === "fldSimple") {
24656
24868
  pushFieldNode(children, grandchild, "simple", opts.sourcePartPath);
24657
24869
  }
@@ -24780,12 +24992,12 @@ function parseRunElement(rElement, opts) {
24780
24992
  nodes.push(ref);
24781
24993
  }
24782
24994
  } else if (name === "bookmarkStart" || name === "bookmarkEnd") {
24783
- nodes.push(parseBookmarkElement(child));
24995
+ nodes.push(parseBookmarkElement(child, opts.sourcePartPath ?? "/word/document.xml"));
24784
24996
  } else if (name === "instrText") {
24785
24997
  pushFieldNode(nodes, child, "complex", opts.sourcePartPath);
24786
24998
  } else if (name === "drawing") {
24787
24999
  const drawingXml = currentSourceXml.slice(child.start, child.end);
24788
- const drawingResult = parseDrawingInlineNode(drawingXml, opts);
25000
+ const drawingResult = parseDrawingInlineNode(drawingXml, opts, void 0, child);
24789
25001
  if (drawingResult) {
24790
25002
  nodes.push(drawingResult);
24791
25003
  }
@@ -24867,11 +25079,11 @@ function parseRunChildNode(child, marks, opts) {
24867
25079
  return null;
24868
25080
  }
24869
25081
  if (name === "bookmarkStart" || name === "bookmarkEnd") {
24870
- return parseBookmarkElement(child);
25082
+ return parseBookmarkElement(child, opts.sourcePartPath ?? "/word/document.xml");
24871
25083
  }
24872
25084
  if (name === "drawing") {
24873
25085
  const drawingXml = currentSourceXml.slice(child.start, child.end);
24874
- return parseDrawingInlineNode(drawingXml, opts);
25086
+ return parseDrawingInlineNode(drawingXml, opts, void 0, child);
24875
25087
  }
24876
25088
  if (name === "pict") {
24877
25089
  const pictXml = currentSourceXml.slice(child.start, child.end);
@@ -24917,7 +25129,7 @@ function parseHyperlinkElement(element, opts) {
24917
25129
  children
24918
25130
  };
24919
25131
  }
24920
- function parseDrawingInlineNode(rawXml, opts, legacyDrawingXml) {
25132
+ function parseDrawingInlineNode(rawXml, opts, legacyDrawingXml, sourceElement) {
24921
25133
  try {
24922
25134
  const frame = parseDrawingFrame(rawXml, {
24923
25135
  ...opts,
@@ -24932,7 +25144,14 @@ function parseDrawingInlineNode(rawXml, opts, legacyDrawingXml) {
24932
25144
  blockParser: (xml) => parseTxbxBlocksForHeaderFooter(xml, opts, 1)
24933
25145
  });
24934
25146
  if (frame && !(frame.content.type === "shape" && frame.content.isTextBox)) {
24935
- return frame;
25147
+ return sourceElement ? {
25148
+ ...frame,
25149
+ sourceRef: createElementSourceRef2(
25150
+ opts.sourcePartPath ?? "/word/document.xml",
25151
+ "drawing",
25152
+ sourceElement
25153
+ )
25154
+ } : frame;
24936
25155
  }
24937
25156
  if (frame?.content.type !== "shape" || !frame.content.isTextBox) {
24938
25157
  return frame;
@@ -24971,14 +25190,13 @@ function parseTxbxBlocksForHeaderFooter(innerXml, opts, depth) {
24971
25190
  currentSourceXml = innerXml;
24972
25191
  try {
24973
25192
  const blocks = [];
24974
- for (const child of txbxContent.children) {
24975
- if (child.type !== "element") continue;
25193
+ for (const [child, childXmlPath] of elementChildrenWithXmlPath(txbxContent, "/txbxContent[1]")) {
24976
25194
  const name = localName(child.name);
24977
25195
  if (name === "p") {
24978
25196
  blocks.push(parseParagraphElement(child, innerXml, opts));
24979
25197
  } else if (name === "tbl") {
24980
25198
  if (isSimpleSecondaryStoryTable(child)) {
24981
- blocks.push(parseSimpleTableElement(child, innerXml, opts));
25199
+ blocks.push(parseSimpleTableElement(child, innerXml, opts, childXmlPath));
24982
25200
  } else {
24983
25201
  blocks.push({
24984
25202
  type: "opaque_block",
@@ -24994,18 +25212,21 @@ function parseTxbxBlocksForHeaderFooter(innerXml, opts, depth) {
24994
25212
  currentSourceXml = previousSourceXml;
24995
25213
  }
24996
25214
  }
24997
- function parseBookmarkElement(element) {
25215
+ function parseBookmarkElement(element, partPath) {
24998
25216
  const bookmarkId = readStringAttr(element, "w:id") ?? "0";
25217
+ const sourceRef = createElementSourceRef2(partPath, localName(element.name), element);
24999
25218
  if (localName(element.name) === "bookmarkStart") {
25000
25219
  return {
25001
25220
  type: "bookmark_start",
25002
25221
  bookmarkId,
25003
- name: readStringAttr(element, "w:name") ?? ""
25222
+ name: readStringAttr(element, "w:name") ?? "",
25223
+ sourceRef
25004
25224
  };
25005
25225
  }
25006
25226
  return {
25007
25227
  type: "bookmark_end",
25008
- bookmarkId
25228
+ bookmarkId,
25229
+ sourceRef
25009
25230
  };
25010
25231
  }
25011
25232
  function pushFieldNode(nodes, element, fieldType, sourcePartPath = "/word/document.xml") {
@@ -25048,6 +25269,40 @@ function createFieldSequenceSourceRef2(partPath, node) {
25048
25269
  endOffset: node.end
25049
25270
  };
25050
25271
  }
25272
+ function createElementSourceRef2(partPath, element, node) {
25273
+ return {
25274
+ sourceId: `part:${partPath}#${element}:${node.start}`,
25275
+ partPath,
25276
+ storyKind: /\/footer\d+\.xml$/i.test(partPath) ? "footer" : "header",
25277
+ element,
25278
+ startOffset: node.start,
25279
+ endOffset: node.end
25280
+ };
25281
+ }
25282
+ function createStableTableSourceRef2(partPath, element, xmlPath, extras = {}) {
25283
+ return {
25284
+ sourceId: `part:${partPath}#${xmlPath}`,
25285
+ partPath,
25286
+ storyKind: /\/footer\d+\.xml$/i.test(partPath) ? "footer" : "header",
25287
+ element,
25288
+ xmlPath,
25289
+ ...extras
25290
+ };
25291
+ }
25292
+ function elementChildrenWithXmlPath(parent, parentXmlPath) {
25293
+ const ordinals = /* @__PURE__ */ new Map();
25294
+ const children = [];
25295
+ for (const child of parent.children) {
25296
+ if (child.type !== "element") {
25297
+ continue;
25298
+ }
25299
+ const name = localName(child.name);
25300
+ const ordinal = (ordinals.get(name) ?? 0) + 1;
25301
+ ordinals.set(name, ordinal);
25302
+ children.push([child, `${parentXmlPath}/${name}[${ordinal}]`]);
25303
+ }
25304
+ return children;
25305
+ }
25051
25306
  function readFieldInstruction(element) {
25052
25307
  const instruction = readStringAttr(element, "w:instr") ?? extractTextContent(element);
25053
25308
  return instruction.trim().length > 0 ? instruction : void 0;
@@ -25274,7 +25529,7 @@ function containsRiskyElement(element) {
25274
25529
  }
25275
25530
  return false;
25276
25531
  }
25277
- function parseSimpleTableElement(tblElement, sourceXml, opts) {
25532
+ function parseSimpleTableElement(tblElement, sourceXml, opts, sourceXmlPath) {
25278
25533
  let gridColumns = [];
25279
25534
  const rows = [];
25280
25535
  let propertiesXml;
@@ -25312,11 +25567,12 @@ function parseSimpleTableElement(tblElement, sourceXml, opts) {
25312
25567
  } else if (name === "tblGrid") {
25313
25568
  gridColumns = readGridColumns2(child);
25314
25569
  } else if (name === "tr") {
25315
- rows.push(parseSimpleTableRow(child, sourceXml, opts));
25570
+ rows.push(parseSimpleTableRow(child, sourceXml, opts, `${sourceXmlPath}/tr[${rows.length + 1}]`));
25316
25571
  }
25317
25572
  }
25318
25573
  return {
25319
25574
  type: "table",
25575
+ sourceRef: createStableTableSourceRef2(opts.sourcePartPath ?? "/word/document.xml", "tbl", sourceXmlPath),
25320
25576
  ...styleId ? { styleId } : {},
25321
25577
  ...propertiesXml ? { propertiesXml } : {},
25322
25578
  gridColumns,
@@ -25338,7 +25594,7 @@ function parseSimpleTableElement(tblElement, sourceXml, opts) {
25338
25594
  function readGridColumns2(tblGrid) {
25339
25595
  return readGridColumns(tblGrid);
25340
25596
  }
25341
- function parseSimpleTableRow(trElement, sourceXml, opts) {
25597
+ function parseSimpleTableRow(trElement, sourceXml, opts, sourceXmlPath) {
25342
25598
  const cells = [];
25343
25599
  let propertiesXml;
25344
25600
  let height;
@@ -25359,11 +25615,12 @@ function parseSimpleTableRow(trElement, sourceXml, opts) {
25359
25615
  horizontalAlignment = readRowHorizontalAlignment(child);
25360
25616
  cnfStyle = readRowCnfStyle(child);
25361
25617
  } else if (name === "tc") {
25362
- cells.push(parseSimpleTableCell(child, sourceXml, opts));
25618
+ cells.push(parseSimpleTableCell(child, sourceXml, opts, `${sourceXmlPath}/tc[${cells.length + 1}]`));
25363
25619
  }
25364
25620
  }
25365
25621
  return {
25366
25622
  type: "table_row",
25623
+ sourceRef: createStableTableSourceRef2(opts.sourcePartPath ?? "/word/document.xml", "tr", sourceXmlPath),
25367
25624
  ...propertiesXml ? { propertiesXml } : {},
25368
25625
  ...height !== void 0 ? { height } : {},
25369
25626
  ...heightRule ? { heightRule } : {},
@@ -25374,7 +25631,7 @@ function parseSimpleTableRow(trElement, sourceXml, opts) {
25374
25631
  cells
25375
25632
  };
25376
25633
  }
25377
- function parseSimpleTableCell(tcElement, sourceXml, opts) {
25634
+ function parseSimpleTableCell(tcElement, sourceXml, opts, sourceXmlPath) {
25378
25635
  const children = [];
25379
25636
  let propertiesXml;
25380
25637
  let gridSpan;
@@ -25416,6 +25673,9 @@ function parseSimpleTableCell(tcElement, sourceXml, opts) {
25416
25673
  }
25417
25674
  return {
25418
25675
  type: "table_cell",
25676
+ sourceRef: createStableTableSourceRef2(opts.sourcePartPath ?? "/word/document.xml", "tc", sourceXmlPath, {
25677
+ tableCellPath: sourceXmlPath
25678
+ }),
25419
25679
  ...propertiesXml ? { propertiesXml } : {},
25420
25680
  ...gridSpan ? { gridSpan } : {},
25421
25681
  ...verticalMerge ? { verticalMerge } : {},
@@ -25461,28 +25721,22 @@ function parseFootnotesXml(xml) {
25461
25721
  const footnotes = {};
25462
25722
  const endnotes = {};
25463
25723
  if (footnotesElement) {
25464
- for (const child of footnotesElement.children) {
25465
- if (child.type !== "element") {
25466
- continue;
25467
- }
25724
+ for (const [child, childXmlPath] of elementChildrenWithXmlPath2(footnotesElement, "/footnotes[1]")) {
25468
25725
  if (localName(child.name) !== "footnote") {
25469
25726
  continue;
25470
25727
  }
25471
- const definition = parseNoteElement(child, "footnote");
25728
+ const definition = parseNoteElement(child, "footnote", childXmlPath);
25472
25729
  if (definition) {
25473
25730
  footnotes[definition.noteId] = definition;
25474
25731
  }
25475
25732
  }
25476
25733
  }
25477
25734
  if (endnotesElement) {
25478
- for (const child of endnotesElement.children) {
25479
- if (child.type !== "element") {
25480
- continue;
25481
- }
25735
+ for (const [child, childXmlPath] of elementChildrenWithXmlPath2(endnotesElement, "/endnotes[1]")) {
25482
25736
  if (localName(child.name) !== "endnote") {
25483
25737
  continue;
25484
25738
  }
25485
- const definition = parseNoteElement(child, "endnote");
25739
+ const definition = parseNoteElement(child, "endnote", childXmlPath);
25486
25740
  if (definition) {
25487
25741
  endnotes[definition.noteId] = definition;
25488
25742
  }
@@ -25502,14 +25756,11 @@ function parseEndnotesXml(xml, existing) {
25502
25756
  ...existing?.endnotes ?? {}
25503
25757
  };
25504
25758
  if (endnotesElement) {
25505
- for (const child of endnotesElement.children) {
25506
- if (child.type !== "element") {
25507
- continue;
25508
- }
25759
+ for (const [child, childXmlPath] of elementChildrenWithXmlPath2(endnotesElement, "/endnotes[1]")) {
25509
25760
  if (localName(child.name) !== "endnote") {
25510
25761
  continue;
25511
25762
  }
25512
- const definition = parseNoteElement(child, "endnote");
25763
+ const definition = parseNoteElement(child, "endnote", childXmlPath);
25513
25764
  if (definition) {
25514
25765
  endnotes[definition.noteId] = definition;
25515
25766
  }
@@ -25558,7 +25809,7 @@ function parseFootnoteSeparators(xml) {
25558
25809
  ...continuationSeparatorParagraphXml !== void 0 ? { continuationSeparatorParagraphXml } : {}
25559
25810
  };
25560
25811
  }
25561
- function parseNoteElement(element, kind) {
25812
+ function parseNoteElement(element, kind, sourceXmlPath) {
25562
25813
  const rawId = readStringAttr(element, "w:id") ?? "";
25563
25814
  const rawType = readStringAttr(element, "w:type") ?? "";
25564
25815
  if (!rawId || SPECIAL_NOTE_IDS.has(rawId) || SPECIAL_NOTE_TYPES.has(rawType)) {
@@ -25566,16 +25817,13 @@ function parseNoteElement(element, kind) {
25566
25817
  }
25567
25818
  const noteId = rawId;
25568
25819
  const blocks = [];
25569
- for (const child of element.children) {
25570
- if (child.type !== "element") {
25571
- continue;
25572
- }
25820
+ for (const [child, childXmlPath] of elementChildrenWithXmlPath2(element, sourceXmlPath)) {
25573
25821
  const name = localName(child.name);
25574
25822
  if (name === "p") {
25575
- blocks.push(parseParagraphElement2(child));
25823
+ blocks.push(parseParagraphElement2(child, kind));
25576
25824
  } else if (name === "tbl") {
25577
25825
  if (isSimpleSecondaryStoryTable2(child)) {
25578
- blocks.push(parseSimpleTableElement2(child));
25826
+ blocks.push(parseSimpleTableElement2(child, kind, childXmlPath));
25579
25827
  } else {
25580
25828
  blocks.push({
25581
25829
  type: "opaque_block",
@@ -25595,7 +25843,7 @@ function parseNoteElement(element, kind) {
25595
25843
  }
25596
25844
  return { noteId, kind, blocks };
25597
25845
  }
25598
- function parseParagraphElement2(pElement) {
25846
+ function parseParagraphElement2(pElement, noteKind) {
25599
25847
  let styleId;
25600
25848
  let alignment;
25601
25849
  let spacing;
@@ -25618,15 +25866,15 @@ function parseParagraphElement2(pElement) {
25618
25866
  spacing = readParagraphSpacing4(child);
25619
25867
  indentation = readParagraphIndentation4(child);
25620
25868
  } else if (name === "r") {
25621
- activeComplexField = appendRunNodes2(child, children, activeComplexField);
25869
+ activeComplexField = appendRunNodes2(child, children, activeComplexField, noteKind);
25622
25870
  } else if (name === "hyperlink") {
25623
25871
  if (activeComplexField && activeComplexField.instruction.trim().length > 0) {
25624
25872
  children.push(createFieldNode2(activeComplexField.instruction, "complex", activeComplexField.children));
25625
25873
  activeComplexField = null;
25626
25874
  }
25627
- children.push(parseHyperlinkElement2(child));
25875
+ children.push(parseHyperlinkElement2(child, noteKind));
25628
25876
  } else if (name === "bookmarkStart" || name === "bookmarkEnd") {
25629
- const bookmarkNode = parseBookmarkElement2(child);
25877
+ const bookmarkNode = parseBookmarkElement2(child, noteKind);
25630
25878
  if (activeComplexField?.mode === "result") {
25631
25879
  activeComplexField.children.push(bookmarkNode);
25632
25880
  } else {
@@ -25656,7 +25904,7 @@ function parseParagraphElement2(pElement) {
25656
25904
  children
25657
25905
  };
25658
25906
  }
25659
- function appendRunNodes2(rElement, nodes, activeComplexField) {
25907
+ function appendRunNodes2(rElement, nodes, activeComplexField, noteKind) {
25660
25908
  const marks = parseRunProperties2(rElement);
25661
25909
  for (const child of rElement.children) {
25662
25910
  if (child.type !== "element") {
@@ -25685,7 +25933,7 @@ function appendRunNodes2(rElement, nodes, activeComplexField) {
25685
25933
  }
25686
25934
  continue;
25687
25935
  }
25688
- const inlineNode = parseRunChildNode2(child, marks);
25936
+ const inlineNode = parseRunChildNode2(child, marks, noteKind);
25689
25937
  if (!inlineNode) {
25690
25938
  continue;
25691
25939
  }
@@ -25697,7 +25945,7 @@ function appendRunNodes2(rElement, nodes, activeComplexField) {
25697
25945
  }
25698
25946
  return activeComplexField;
25699
25947
  }
25700
- function parseRunElement2(rElement) {
25948
+ function parseRunElement2(rElement, noteKind) {
25701
25949
  const nodes = [];
25702
25950
  const marks = parseRunProperties2(rElement);
25703
25951
  for (const child of rElement.children) {
@@ -25730,14 +25978,14 @@ function parseRunElement2(rElement) {
25730
25978
  nodes.push({ type: "footnote_ref", noteId, noteKind: "endnote" });
25731
25979
  }
25732
25980
  } else if (name === "bookmarkStart" || name === "bookmarkEnd") {
25733
- nodes.push(parseBookmarkElement2(child));
25981
+ nodes.push(parseBookmarkElement2(child, noteKind));
25734
25982
  } else if (name === "instrText") {
25735
25983
  pushFieldNode2(nodes, child, "complex");
25736
25984
  }
25737
25985
  }
25738
25986
  return nodes;
25739
25987
  }
25740
- function parseRunChildNode2(child, marks) {
25988
+ function parseRunChildNode2(child, marks, noteKind) {
25741
25989
  const name = localName(child.name);
25742
25990
  if (name === "t") {
25743
25991
  const text = extractTextContent2(child);
@@ -25771,16 +26019,16 @@ function parseRunChildNode2(child, marks) {
25771
26019
  return null;
25772
26020
  }
25773
26021
  if (name === "bookmarkStart" || name === "bookmarkEnd") {
25774
- return parseBookmarkElement2(child);
26022
+ return parseBookmarkElement2(child, noteKind);
25775
26023
  }
25776
26024
  return null;
25777
26025
  }
25778
- function parseHyperlinkElement2(element) {
26026
+ function parseHyperlinkElement2(element, noteKind) {
25779
26027
  const href = element.attributes["w:anchor"] ? `#${element.attributes["w:anchor"]}` : element.attributes["r:id"] ?? "relationship:unknown";
25780
26028
  const children = [];
25781
26029
  for (const child of element.children) {
25782
26030
  if (child.type === "element" && localName(child.name) === "r") {
25783
- for (const runChild of parseRunElement2(child)) {
26031
+ for (const runChild of parseRunElement2(child, noteKind)) {
25784
26032
  if (runChild.type === "text" || runChild.type === "hard_break" || runChild.type === "tab") {
25785
26033
  children.push(runChild);
25786
26034
  }
@@ -25793,18 +26041,21 @@ function parseHyperlinkElement2(element) {
25793
26041
  children
25794
26042
  };
25795
26043
  }
25796
- function parseBookmarkElement2(element) {
26044
+ function parseBookmarkElement2(element, noteKind) {
25797
26045
  const bookmarkId = readStringAttr(element, "w:id") ?? "0";
26046
+ const sourceRef = createElementSourceRef3(noteKind, localName(element.name), element);
25798
26047
  if (localName(element.name) === "bookmarkStart") {
25799
26048
  return {
25800
26049
  type: "bookmark_start",
25801
26050
  bookmarkId,
25802
- name: readStringAttr(element, "w:name") ?? ""
26051
+ name: readStringAttr(element, "w:name") ?? "",
26052
+ sourceRef
25803
26053
  };
25804
26054
  }
25805
26055
  return {
25806
26056
  type: "bookmark_end",
25807
- bookmarkId
26057
+ bookmarkId,
26058
+ sourceRef
25808
26059
  };
25809
26060
  }
25810
26061
  function pushFieldNode2(nodes, element, fieldType) {
@@ -25976,7 +26227,7 @@ function containsRiskyElement2(element) {
25976
26227
  }
25977
26228
  return false;
25978
26229
  }
25979
- function parseSimpleTableElement2(tblElement) {
26230
+ function parseSimpleTableElement2(tblElement, noteKind = "footnote", sourceXmlPath = `/${noteKind === "endnote" ? "endnotes" : "footnotes"}[1]/tbl[1]`) {
25980
26231
  let gridColumns = [];
25981
26232
  const rows = [];
25982
26233
  let propertiesXml;
@@ -26014,11 +26265,12 @@ function parseSimpleTableElement2(tblElement) {
26014
26265
  } else if (name === "tblGrid") {
26015
26266
  gridColumns = readGridColumns3(child);
26016
26267
  } else if (name === "tr") {
26017
- rows.push(parseSimpleTableRow2(child));
26268
+ rows.push(parseSimpleTableRow2(child, noteKind, `${sourceXmlPath}/tr[${rows.length + 1}]`));
26018
26269
  }
26019
26270
  }
26020
26271
  return {
26021
26272
  type: "table",
26273
+ sourceRef: createStableTableSourceRef3(noteKind, "tbl", sourceXmlPath),
26022
26274
  ...styleId ? { styleId } : {},
26023
26275
  ...propertiesXml ? { propertiesXml } : {},
26024
26276
  gridColumns,
@@ -26040,7 +26292,7 @@ function parseSimpleTableElement2(tblElement) {
26040
26292
  function readGridColumns3(tblGrid) {
26041
26293
  return readGridColumns(tblGrid);
26042
26294
  }
26043
- function parseSimpleTableRow2(trElement) {
26295
+ function parseSimpleTableRow2(trElement, noteKind, sourceXmlPath) {
26044
26296
  const cells = [];
26045
26297
  let propertiesXml;
26046
26298
  let height;
@@ -26061,11 +26313,12 @@ function parseSimpleTableRow2(trElement) {
26061
26313
  horizontalAlignment = readRowHorizontalAlignment(child);
26062
26314
  cnfStyle = readRowCnfStyle(child);
26063
26315
  } else if (name === "tc") {
26064
- cells.push(parseSimpleTableCell2(child));
26316
+ cells.push(parseSimpleTableCell2(child, noteKind, `${sourceXmlPath}/tc[${cells.length + 1}]`));
26065
26317
  }
26066
26318
  }
26067
26319
  return {
26068
26320
  type: "table_row",
26321
+ sourceRef: createStableTableSourceRef3(noteKind, "tr", sourceXmlPath),
26069
26322
  ...propertiesXml ? { propertiesXml } : {},
26070
26323
  ...height !== void 0 ? { height } : {},
26071
26324
  ...heightRule ? { heightRule } : {},
@@ -26076,7 +26329,7 @@ function parseSimpleTableRow2(trElement) {
26076
26329
  cells
26077
26330
  };
26078
26331
  }
26079
- function parseSimpleTableCell2(tcElement) {
26332
+ function parseSimpleTableCell2(tcElement, noteKind, sourceXmlPath) {
26080
26333
  const children = [];
26081
26334
  let propertiesXml;
26082
26335
  let gridSpan;
@@ -26113,11 +26366,14 @@ function parseSimpleTableCell2(tcElement) {
26113
26366
  margins = readCellMargins(child);
26114
26367
  cnfStyle = readCellCnfStyle(child);
26115
26368
  } else if (name === "p") {
26116
- children.push(parseParagraphElement2(child));
26369
+ children.push(parseParagraphElement2(child, noteKind));
26117
26370
  }
26118
26371
  }
26119
26372
  return {
26120
26373
  type: "table_cell",
26374
+ sourceRef: createStableTableSourceRef3(noteKind, "tc", sourceXmlPath, {
26375
+ tableCellPath: sourceXmlPath
26376
+ }),
26121
26377
  ...propertiesXml ? { propertiesXml } : {},
26122
26378
  ...gridSpan ? { gridSpan } : {},
26123
26379
  ...verticalMerge ? { verticalMerge } : {},
@@ -26133,6 +26389,42 @@ function parseSimpleTableCell2(tcElement) {
26133
26389
  children: children.length > 0 ? children : [{ type: "paragraph", children: [] }]
26134
26390
  };
26135
26391
  }
26392
+ function createStableTableSourceRef3(noteKind, element, xmlPath, extras = {}) {
26393
+ const partPath = noteKind === "endnote" ? "/word/endnotes.xml" : "/word/footnotes.xml";
26394
+ return {
26395
+ sourceId: `part:${partPath}#${xmlPath}`,
26396
+ partPath,
26397
+ storyKind: noteKind,
26398
+ element,
26399
+ xmlPath,
26400
+ ...extras
26401
+ };
26402
+ }
26403
+ function createElementSourceRef3(noteKind, element, node) {
26404
+ const partPath = noteKind === "endnote" ? "/word/endnotes.xml" : "/word/footnotes.xml";
26405
+ return {
26406
+ sourceId: `part:${partPath}#${element}:${node.start}`,
26407
+ partPath,
26408
+ storyKind: noteKind,
26409
+ element,
26410
+ startOffset: node.start,
26411
+ endOffset: node.end
26412
+ };
26413
+ }
26414
+ function elementChildrenWithXmlPath2(parent, parentXmlPath) {
26415
+ const ordinals = /* @__PURE__ */ new Map();
26416
+ const children = [];
26417
+ for (const child of parent.children) {
26418
+ if (child.type !== "element") {
26419
+ continue;
26420
+ }
26421
+ const name = localName(child.name);
26422
+ const ordinal = (ordinals.get(name) ?? 0) + 1;
26423
+ ordinals.set(name, ordinal);
26424
+ children.push([child, `${parentXmlPath}/${name}[${ordinal}]`]);
26425
+ }
26426
+ return children;
26427
+ }
26136
26428
  function serializeElementToXml2(element) {
26137
26429
  const attrs = Object.entries(element.attributes).map(([key, value]) => ` ${key}="${escapeXmlAttribute5(value)}"`).join("");
26138
26430
  const children = element.children.map((child) => {
@@ -28335,6 +28627,560 @@ async function loadDocxSessionAsync(options) {
28335
28627
  );
28336
28628
  }
28337
28629
  }
28630
+ function loadDocxSessionSync(options) {
28631
+ const editorBuild = typeof options.editorBuild === "string" && options.editorBuild.length > 0 ? options.editorBuild : "dev";
28632
+ const sourceBytes = toUint8Array2(options.bytes);
28633
+ const stages = createStageEmitter(options.onLoadStage);
28634
+ let sourcePackage;
28635
+ try {
28636
+ sourcePackage = readOpcPackage(sourceBytes);
28637
+ } catch (error) {
28638
+ return createDiagnosticsSession(
28639
+ options,
28640
+ createPackageImportDiagnostics({
28641
+ issue: classifyCorruptPackageError(error)
28642
+ })
28643
+ );
28644
+ }
28645
+ const packageMetadata = parseDocumentMetadataFromOpcParts(sourcePackage.parts);
28646
+ stages.emit("opc");
28647
+ const embeddedWorkflowPayload = parseWorkflowPayloadEnvelopeFromPackage(sourcePackage);
28648
+ const embeddedWorkflowMetadata = embeddedWorkflowPayload?.workflowMetadata;
28649
+ const embeddedWorkflowOverlay = embeddedWorkflowPayload?.workflowOverlay;
28650
+ const mainDocumentPath = resolveMainDocumentPartPath(sourcePackage);
28651
+ const brokenRelationshipIssues = collectBrokenInternalRelationshipIssues(
28652
+ sourcePackage,
28653
+ mainDocumentPath
28654
+ );
28655
+ if (brokenRelationshipIssues.length > 0) {
28656
+ return createDiagnosticsSession(
28657
+ options,
28658
+ createPackageImportDiagnostics({
28659
+ issue: {
28660
+ ...brokenRelationshipIssues[0],
28661
+ message: summarizeBrokenRelationshipIssues(brokenRelationshipIssues),
28662
+ details: {
28663
+ issueCount: brokenRelationshipIssues.length,
28664
+ targets: brokenRelationshipIssues.map((issue) => issue.targetPartPath).filter(Boolean)
28665
+ }
28666
+ }
28667
+ })
28668
+ );
28669
+ }
28670
+ if (!mainDocumentPath) {
28671
+ return createDiagnosticsSession(
28672
+ options,
28673
+ createPackageImportDiagnostics({
28674
+ issue: createMissingPartIssue(MAIN_DOCUMENT_PATH)
28675
+ })
28676
+ );
28677
+ }
28678
+ const documentPart = sourcePackage.parts.get(mainDocumentPath);
28679
+ if (!documentPart) {
28680
+ return createDiagnosticsSession(
28681
+ options,
28682
+ createPackageImportDiagnostics({
28683
+ issue: createMissingPartIssue(mainDocumentPath)
28684
+ })
28685
+ );
28686
+ }
28687
+ if (documentPart.contentType !== MAIN_DOCUMENT_CONTENT_TYPE) {
28688
+ return createDiagnosticsSession(
28689
+ options,
28690
+ createValidationImportDiagnostics({
28691
+ message: `DOCX main document part ${mainDocumentPath} must use content type ${MAIN_DOCUMENT_CONTENT_TYPE}.`
28692
+ })
28693
+ );
28694
+ }
28695
+ try {
28696
+ const sourceDocumentXml = decodeUtf82(documentPart.bytes);
28697
+ const importedRevisions = parseRevisionsFromDocumentXml(sourceDocumentXml);
28698
+ const numberingPartPath = resolveDocumentRelatedPartPath(
28699
+ sourcePackage,
28700
+ mainDocumentPath,
28701
+ documentPart.relationships,
28702
+ NUMBERING_RELATIONSHIP_TYPE,
28703
+ NUMBERING_PART_PATH
28704
+ );
28705
+ const parsedNumbering = numberingPartPath ? parseNumberingXml(
28706
+ decodeUtf82(sourcePackage.parts.get(numberingPartPath)?.bytes ?? new Uint8Array()),
28707
+ {
28708
+ relationships: sourcePackage.parts.get(numberingPartPath)?.relationships,
28709
+ partPath: numberingPartPath
28710
+ }
28711
+ ) : createEmptyNumberingCatalog();
28712
+ const mediaParts = collectInlineMediaParts(sourcePackage);
28713
+ const chartPartLookup = createChartPartLookup(
28714
+ sourcePackage,
28715
+ mainDocumentPath,
28716
+ documentPart.relationships
28717
+ );
28718
+ if (options.telemetryBus) {
28719
+ setActiveParseTelemetryBus(options.telemetryBus);
28720
+ }
28721
+ let parsedDocument;
28722
+ try {
28723
+ parsedDocument = parseMainDocumentXml(
28724
+ sourceDocumentXml,
28725
+ documentPart.relationships,
28726
+ mediaParts,
28727
+ mainDocumentPath,
28728
+ chartPartLookup,
28729
+ {
28730
+ stripCosmeticMarkers: options.stripCosmeticMarkers !== false,
28731
+ ...options.retainedBookmarkNames !== void 0 ? { retainedBookmarkNames: options.retainedBookmarkNames } : {}
28732
+ }
28733
+ );
28734
+ } finally {
28735
+ if (options.telemetryBus) setActiveParseTelemetryBus(void 0);
28736
+ }
28737
+ const protectionRanges = extractProtectionRanges(parsedDocument.blocks);
28738
+ const normalizedDocument = normalizeParsedTextDocument(
28739
+ parsedDocument,
28740
+ mainDocumentPath
28741
+ );
28742
+ stages.emit("body");
28743
+ const commentsPartPath = resolveCommentsPartPath(
28744
+ sourcePackage,
28745
+ mainDocumentPath,
28746
+ documentPart.relationships
28747
+ );
28748
+ const commentsExtendedPartPath = resolveDocumentRelatedPartPath(
28749
+ sourcePackage,
28750
+ mainDocumentPath,
28751
+ documentPart.relationships,
28752
+ COMMENTS_EXTENDED_RELATIONSHIP_TYPE,
28753
+ COMMENTS_EXTENDED_PART_PATH
28754
+ );
28755
+ const commentsIdsPartPath = resolveDocumentRelatedPartPath(
28756
+ sourcePackage,
28757
+ mainDocumentPath,
28758
+ documentPart.relationships,
28759
+ COMMENTS_IDS_RELATIONSHIP_TYPE,
28760
+ COMMENTS_IDS_PART_PATH
28761
+ );
28762
+ const peoplePartPath = resolveDocumentRelatedPartPath(
28763
+ sourcePackage,
28764
+ mainDocumentPath,
28765
+ documentPart.relationships,
28766
+ PEOPLE_RELATIONSHIP_TYPE,
28767
+ PEOPLE_PART_PATH
28768
+ );
28769
+ const parsedComments = commentsPartPath ? parseCommentsFromOoxml(
28770
+ sourceDocumentXml,
28771
+ {
28772
+ commentsXml: decodeUtf82(sourcePackage.parts.get(commentsPartPath)?.bytes ?? new Uint8Array()),
28773
+ commentsExtendedXml: decodeUtf82(
28774
+ sourcePackage.parts.get(commentsExtendedPartPath ?? "")?.bytes ?? new Uint8Array()
28775
+ ),
28776
+ commentsIdsXml: decodeUtf82(
28777
+ sourcePackage.parts.get(commentsIdsPartPath ?? "")?.bytes ?? new Uint8Array()
28778
+ ),
28779
+ peopleXml: decodeUtf82(
28780
+ sourcePackage.parts.get(peoplePartPath ?? "")?.bytes ?? new Uint8Array()
28781
+ )
28782
+ }
28783
+ ) : {
28784
+ threads: [],
28785
+ diagnostics: [],
28786
+ definitions: [],
28787
+ sourceRootTag: void 0,
28788
+ sourceExtendedRootTag: void 0,
28789
+ sourceIdsRootTag: void 0,
28790
+ sourcePeopleRootTag: void 0,
28791
+ peopleAuthors: []
28792
+ };
28793
+ const normalizedRevisions = normalizeImportedRevisionRecords(
28794
+ importedRevisions,
28795
+ normalizedDocument.content,
28796
+ normalizedDocument.preservation.opaqueFragments
28797
+ );
28798
+ const normalizedComments = normalizeImportedCommentThreads(
28799
+ parsedComments,
28800
+ normalizedDocument.preservation.opaqueFragments,
28801
+ normalizedRevisions.revisions
28802
+ );
28803
+ stages.emit("styles-numbering-comments");
28804
+ const importedStoryRevisions = [];
28805
+ const importedStoryRevisionDiagnostics = [];
28806
+ const subPartOpaqueState = createSubPartOpaqueImportState(
28807
+ normalizedDocument.preservation.opaqueFragments,
28808
+ normalizedDocument.diagnostics.warnings
28809
+ );
28810
+ const headerFooterRefs = parseHeaderFooterReferences(sourceDocumentXml);
28811
+ const parsedHeaders = [];
28812
+ const parsedFooters = [];
28813
+ const sourceHeaderPaths = [];
28814
+ const sourceFooterPaths = [];
28815
+ const seenSubPartKeys = /* @__PURE__ */ new Set();
28816
+ for (const ref of headerFooterRefs) {
28817
+ const dedupeKey = `${ref.kind}:${ref.variant}:${ref.relationshipId}`;
28818
+ if (seenSubPartKeys.has(dedupeKey)) {
28819
+ continue;
28820
+ }
28821
+ seenSubPartKeys.add(dedupeKey);
28822
+ const relationship = documentPart.relationships.find(
28823
+ (r) => r.id === ref.relationshipId && r.targetMode === "internal"
28824
+ );
28825
+ if (!relationship) {
28826
+ continue;
28827
+ }
28828
+ const partPath = resolveRelationshipTarget(mainDocumentPath, relationship);
28829
+ const part = sourcePackage.parts.get(partPath);
28830
+ const partBytes = part?.bytes;
28831
+ if (!partBytes) {
28832
+ continue;
28833
+ }
28834
+ const xml = decodeUtf82(partBytes);
28835
+ const subPartRelationships = part?.relationships ?? [];
28836
+ const subPartChartPartLookup = createChartPartLookup(
28837
+ sourcePackage,
28838
+ partPath,
28839
+ subPartRelationships
28840
+ );
28841
+ if (ref.kind === "header") {
28842
+ const parsedHeaderRevisions = parseRevisionsFromStoryXml(xml);
28843
+ const parsed = parseHeaderXml(xml, {
28844
+ relationships: subPartRelationships,
28845
+ mediaParts,
28846
+ sourcePartPath: partPath,
28847
+ chartPartLookup: subPartChartPartLookup
28848
+ });
28849
+ parsedHeaders.push({
28850
+ variant: ref.variant,
28851
+ partPath,
28852
+ relationshipId: ref.relationshipId,
28853
+ ...ref.sectionIndex !== void 0 ? { sectionIndex: ref.sectionIndex } : {},
28854
+ blocks: normalizeSubPartOpaqueBlocks(
28855
+ parsed.blocks,
28856
+ normalizedDocument.preservation.opaqueFragments,
28857
+ normalizedDocument.diagnostics.warnings,
28858
+ partPath,
28859
+ subPartOpaqueState
28860
+ )
28861
+ });
28862
+ importedStoryRevisions.push(
28863
+ ...parsedHeaderRevisions.revisions.map((revision) => ({
28864
+ ...revision,
28865
+ metadata: {
28866
+ ...revision.metadata,
28867
+ storyTarget: {
28868
+ kind: "header",
28869
+ relationshipId: ref.relationshipId,
28870
+ variant: ref.variant,
28871
+ ...ref.sectionIndex !== void 0 ? { sectionIndex: ref.sectionIndex } : {}
28872
+ }
28873
+ }
28874
+ }))
28875
+ );
28876
+ importedStoryRevisionDiagnostics.push(...parsedHeaderRevisions.diagnostics);
28877
+ sourceHeaderPaths.push({ partPath, relationshipId: ref.relationshipId });
28878
+ } else {
28879
+ const parsedFooterRevisions = parseRevisionsFromStoryXml(xml);
28880
+ const parsed = parseFooterXml(xml, {
28881
+ relationships: subPartRelationships,
28882
+ mediaParts,
28883
+ sourcePartPath: partPath,
28884
+ chartPartLookup: subPartChartPartLookup
28885
+ });
28886
+ parsedFooters.push({
28887
+ variant: ref.variant,
28888
+ partPath,
28889
+ relationshipId: ref.relationshipId,
28890
+ ...ref.sectionIndex !== void 0 ? { sectionIndex: ref.sectionIndex } : {},
28891
+ blocks: normalizeSubPartOpaqueBlocks(
28892
+ parsed.blocks,
28893
+ normalizedDocument.preservation.opaqueFragments,
28894
+ normalizedDocument.diagnostics.warnings,
28895
+ partPath,
28896
+ subPartOpaqueState
28897
+ )
28898
+ });
28899
+ importedStoryRevisions.push(
28900
+ ...parsedFooterRevisions.revisions.map((revision) => ({
28901
+ ...revision,
28902
+ metadata: {
28903
+ ...revision.metadata,
28904
+ storyTarget: {
28905
+ kind: "footer",
28906
+ relationshipId: ref.relationshipId,
28907
+ variant: ref.variant,
28908
+ ...ref.sectionIndex !== void 0 ? { sectionIndex: ref.sectionIndex } : {}
28909
+ }
28910
+ }
28911
+ }))
28912
+ );
28913
+ importedStoryRevisionDiagnostics.push(...parsedFooterRevisions.diagnostics);
28914
+ sourceFooterPaths.push({ partPath, relationshipId: ref.relationshipId });
28915
+ }
28916
+ }
28917
+ const footnotesPartPath = resolveDocumentRelatedPartPath(
28918
+ sourcePackage,
28919
+ mainDocumentPath,
28920
+ documentPart.relationships,
28921
+ FOOTNOTES_RELATIONSHIP_TYPE,
28922
+ FOOTNOTES_PART_PATH
28923
+ );
28924
+ const footnotesRelationshipId = documentPart.relationships.find(
28925
+ (r) => r.type === FOOTNOTES_RELATIONSHIP_TYPE && r.targetMode === "internal"
28926
+ )?.id;
28927
+ const endnotesPartPath = resolveDocumentRelatedPartPath(
28928
+ sourcePackage,
28929
+ mainDocumentPath,
28930
+ documentPart.relationships,
28931
+ ENDNOTES_RELATIONSHIP_TYPE,
28932
+ ENDNOTES_PART_PATH
28933
+ );
28934
+ const endnotesRelationshipId = documentPart.relationships.find(
28935
+ (r) => r.type === ENDNOTES_RELATIONSHIP_TYPE && r.targetMode === "internal"
28936
+ )?.id;
28937
+ let footnoteCollection;
28938
+ if (footnotesPartPath) {
28939
+ footnoteCollection = parseFootnotesXml(
28940
+ decodeUtf82(sourcePackage.parts.get(footnotesPartPath)?.bytes ?? new Uint8Array())
28941
+ );
28942
+ normalizeFootnoteCollectionOpaqueBlocks(
28943
+ footnoteCollection,
28944
+ "footnote",
28945
+ normalizedDocument.preservation.opaqueFragments,
28946
+ normalizedDocument.diagnostics.warnings,
28947
+ footnotesPartPath,
28948
+ subPartOpaqueState
28949
+ );
28950
+ }
28951
+ if (endnotesPartPath) {
28952
+ footnoteCollection = parseEndnotesXml(
28953
+ decodeUtf82(sourcePackage.parts.get(endnotesPartPath)?.bytes ?? new Uint8Array()),
28954
+ footnoteCollection
28955
+ );
28956
+ normalizeFootnoteCollectionOpaqueBlocks(
28957
+ footnoteCollection,
28958
+ "endnote",
28959
+ normalizedDocument.preservation.opaqueFragments,
28960
+ normalizedDocument.diagnostics.warnings,
28961
+ endnotesPartPath,
28962
+ subPartOpaqueState
28963
+ );
28964
+ }
28965
+ const themeRelationship = documentPart.relationships.find(
28966
+ (r) => r.type === "http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme" && r.targetMode === "internal"
28967
+ );
28968
+ const themePartPath = themeRelationship ? resolveRelationshipTarget(mainDocumentPath, themeRelationship) : void 0;
28969
+ const parsedTheme = themePartPath && sourcePackage.parts.has(themePartPath) ? parseThemeXml(
28970
+ decodeUtf82(sourcePackage.parts.get(themePartPath)?.bytes ?? new Uint8Array())
28971
+ ) : void 0;
28972
+ const resolvedTheme = parsedTheme ? resolveTheme(parsedTheme) : void 0;
28973
+ const settingsPartPath = resolveDocumentRelatedPartPath(
28974
+ sourcePackage,
28975
+ mainDocumentPath,
28976
+ documentPart.relationships,
28977
+ SETTINGS_RELATIONSHIP_TYPE,
28978
+ SETTINGS_PART_PATH
28979
+ );
28980
+ const parsedSettings = settingsPartPath && sourcePackage.parts.has(settingsPartPath) ? parseSettingsXml(
28981
+ decodeUtf82(sourcePackage.parts.get(settingsPartPath)?.bytes ?? new Uint8Array())
28982
+ ) : void 0;
28983
+ const canonicalTheme = parsedTheme !== void 0 ? materializeCanonicalTheme(
28984
+ parsedTheme,
28985
+ parsedSettings?.clrSchemeMapping ?? {}
28986
+ ) : void 0;
28987
+ const settingsXmlForProtection = settingsPartPath && sourcePackage.parts.has(settingsPartPath) ? decodeUtf82(sourcePackage.parts.get(settingsPartPath)?.bytes ?? new Uint8Array()) : "";
28988
+ const documentProtection = extractDocumentProtection(settingsXmlForProtection);
28989
+ const importedProtectionSnapshot = buildProtectionSnapshot(documentProtection, protectionRanges);
28990
+ const stylesPartPath = resolveDocumentRelatedPartPath(
28991
+ sourcePackage,
28992
+ mainDocumentPath,
28993
+ documentPart.relationships,
28994
+ STYLES_RELATIONSHIP_TYPE,
28995
+ STYLES_PART_PATH
28996
+ );
28997
+ const parsedStyles = stylesPartPath && sourcePackage.parts.has(stylesPartPath) ? parseStylesXml(
28998
+ decodeUtf82(sourcePackage.parts.get(stylesPartPath)?.bytes ?? new Uint8Array())
28999
+ ) : parseStylesXml("");
29000
+ const fontTablePartPath = resolveDocumentRelatedPartPath(
29001
+ sourcePackage,
29002
+ mainDocumentPath,
29003
+ documentPart.relationships,
29004
+ FONT_TABLE_RELATIONSHIP_TYPE,
29005
+ FONT_TABLE_PART_PATH
29006
+ );
29007
+ const parsedFontTable = fontTablePartPath && sourcePackage.parts.has(fontTablePartPath) ? parseFontTable(
29008
+ decodeUtf82(sourcePackage.parts.get(fontTablePartPath)?.bytes ?? new Uint8Array())
29009
+ ) : void 0;
29010
+ const mergedMedia = mergeSecondaryStoryMediaCatalog(normalizedDocument.media, {
29011
+ headers: parsedHeaders,
29012
+ footers: parsedFooters,
29013
+ footnoteCollection,
29014
+ mediaParts
29015
+ });
29016
+ const subParts = parsedHeaders.length > 0 || parsedFooters.length > 0 || footnoteCollection !== void 0 || parsedTheme !== void 0 || normalizedDocument.finalSectionProperties !== void 0 || resolvedTheme !== void 0 || canonicalTheme !== void 0 || parsedSettings !== void 0 ? {
29017
+ headers: parsedHeaders,
29018
+ footers: parsedFooters,
29019
+ ...footnoteCollection !== void 0 ? { footnoteCollection } : {},
29020
+ ...parsedTheme !== void 0 ? { theme: parsedTheme } : {},
29021
+ ...normalizedDocument.finalSectionProperties !== void 0 ? { finalSectionProperties: normalizedDocument.finalSectionProperties } : {},
29022
+ ...resolvedTheme !== void 0 ? { resolvedTheme } : {},
29023
+ ...canonicalTheme !== void 0 ? { canonicalTheme } : {},
29024
+ ...parsedSettings !== void 0 ? { settings: parsedSettings } : {}
29025
+ } : void 0;
29026
+ const timestamp = (/* @__PURE__ */ new Date()).toISOString();
29027
+ const canonicalTimestamp = deriveCanonicalImportTimestamp(packageMetadata);
29028
+ const translatedWorkflowState = translateClmCommentsToWorkflow({
29029
+ comments: normalizedComments.threads,
29030
+ workflowOverlay: embeddedWorkflowOverlay,
29031
+ workflowMetadata: embeddedWorkflowMetadata,
29032
+ timestamp
29033
+ });
29034
+ const rehydratedOffloadSync = hydrateOffloadEntriesFromPayload(
29035
+ embeddedWorkflowPayload?.editorState
29036
+ );
29037
+ const embeddedDocumentManifestsSync = collectEmbeddedDocuments(
29038
+ sourcePackage,
29039
+ mainDocumentPath
29040
+ ).manifests;
29041
+ const document2 = createImportedCanonicalDocument({
29042
+ documentId: options.documentId,
29043
+ timestamp: canonicalTimestamp,
29044
+ numbering: parsedNumbering,
29045
+ media: mergedMedia,
29046
+ content: normalizedDocument.content,
29047
+ subParts,
29048
+ parsedStyles,
29049
+ fontTable: parsedFontTable,
29050
+ metadata: packageMetadata,
29051
+ preservation: buildImportPreservation(normalizedDocument.preservation, sourcePackage, [
29052
+ mainDocumentPath,
29053
+ numberingPartPath,
29054
+ commentsPartPath,
29055
+ commentsExtendedPartPath,
29056
+ commentsIdsPartPath,
29057
+ peoplePartPath,
29058
+ ...rehydratedOffloadSync.ownedPartPaths
29059
+ ]),
29060
+ diagnostics: {
29061
+ warnings: [
29062
+ ...createBrokenRelationshipWarnings(sourcePackage, mainDocumentPath),
29063
+ ...normalizedDocument.diagnostics.warnings,
29064
+ ...mapRevisionDiagnosticsToWarnings(normalizedRevisions.diagnostics),
29065
+ ...mapStoryRevisionDiagnosticsToWarnings(importedStoryRevisionDiagnostics),
29066
+ ...mapCommentDiagnosticsToWarnings(normalizedComments.diagnostics)
29067
+ ],
29068
+ errors: []
29069
+ },
29070
+ review: {
29071
+ comments: toRuntimeCommentRecords(translatedWorkflowState.comments),
29072
+ revisions: toRuntimeRevisionRecords([
29073
+ ...normalizedRevisions.revisions,
29074
+ ...importedStoryRevisions
29075
+ ])
29076
+ }
29077
+ });
29078
+ const compatibility = buildCompatibilityReport({
29079
+ document: document2,
29080
+ generatedAt: timestamp
29081
+ });
29082
+ const snapshot = createImportedSnapshot({
29083
+ documentId: options.documentId,
29084
+ editorBuild,
29085
+ timestamp,
29086
+ document: document2,
29087
+ compatibility,
29088
+ protectionSnapshot: importedProtectionSnapshot,
29089
+ sourcePackage: createPersistedSourcePackage(sourceBytes, options.sourceLabel),
29090
+ workflowOverlay: translatedWorkflowState.workflowOverlay,
29091
+ workflowMetadata: translatedWorkflowState.workflowMetadata,
29092
+ visibilityPolicies: embeddedWorkflowPayload?.visibilityPolicies,
29093
+ markupModePolicy: embeddedWorkflowPayload?.markupModePolicy ?? void 0
29094
+ });
29095
+ const snapshotIssues = validatePersistedEditorSnapshot(snapshot);
29096
+ if (snapshotIssues.length > 0) {
29097
+ const firstIssue = snapshotIssues[0];
29098
+ return createDiagnosticsSession(
29099
+ options,
29100
+ createValidationImportDiagnostics({
29101
+ message: `DOCX import produced an invalid editor state during validation${firstIssue ? ` (${firstIssue.path}: ${firstIssue.message})` : "."}`,
29102
+ source: "import",
29103
+ details: {
29104
+ issueCount: snapshotIssues.length,
29105
+ firstIssuePath: firstIssue?.path
29106
+ }
29107
+ })
29108
+ );
29109
+ }
29110
+ const initialSessionState = editorSessionStateFromPersistedSnapshot(snapshot);
29111
+ const importedState = {
29112
+ sourceBytes: new Uint8Array(sourceBytes),
29113
+ sourcePackage,
29114
+ sourceDocumentXml,
29115
+ sourceDocumentPartPath: mainDocumentPath,
29116
+ sourceDocumentRelationships: documentPart.relationships,
29117
+ sourceDocumentAttributes: extractDocumentRootAttributes(sourceDocumentXml),
29118
+ sourceNumberingPartPath: numberingPartPath,
29119
+ sourceNumberingRelationshipId: documentPart.relationships.find(
29120
+ (relationship) => relationship.type === NUMBERING_RELATIONSHIP_TYPE && relationship.targetMode === "internal"
29121
+ )?.id,
29122
+ sourceSettingsPartPath: settingsPartPath,
29123
+ sourceSettingsXml: settingsXmlForProtection.length > 0 ? settingsXmlForProtection : void 0,
29124
+ sourceCommentsPartPath: commentsPartPath,
29125
+ sourceCommentsRelationshipId: documentPart.relationships.find(
29126
+ (relationship) => relationship.type === COMMENTS_RELATIONSHIP_TYPE && relationship.targetMode === "internal"
29127
+ )?.id,
29128
+ sourceCommentsRootTag: normalizedComments.sourceRootTag,
29129
+ sourceCommentsExtendedPartPath: commentsExtendedPartPath,
29130
+ sourceCommentsExtendedRelationshipId: documentPart.relationships.find(
29131
+ (relationship) => relationship.type === COMMENTS_EXTENDED_RELATIONSHIP_TYPE && relationship.targetMode === "internal"
29132
+ )?.id,
29133
+ sourceCommentsExtendedRootTag: normalizedComments.sourceExtendedRootTag,
29134
+ sourceCommentsIdsPartPath: commentsIdsPartPath,
29135
+ sourceCommentsIdsRelationshipId: documentPart.relationships.find(
29136
+ (relationship) => relationship.type === COMMENTS_IDS_RELATIONSHIP_TYPE && relationship.targetMode === "internal"
29137
+ )?.id,
29138
+ sourceCommentsIdsRootTag: normalizedComments.sourceIdsRootTag,
29139
+ sourcePeoplePartPath: peoplePartPath,
29140
+ sourcePeopleRelationshipId: documentPart.relationships.find(
29141
+ (relationship) => relationship.type === PEOPLE_RELATIONSHIP_TYPE && relationship.targetMode === "internal"
29142
+ )?.id,
29143
+ sourcePeopleRootTag: normalizedComments.sourcePeopleRootTag,
29144
+ sourcePeopleAuthors: normalizedComments.peopleAuthors,
29145
+ protectionSnapshot: buildProtectionSnapshot(documentProtection, protectionRanges),
29146
+ preservedCommentDefinitions: normalizedComments.preservedDefinitions,
29147
+ blockingCommentDiagnostics: normalizedComments.diagnostics.filter(
29148
+ (diagnostic) => BLOCKING_COMMENT_DIAGNOSTIC_CODES.has(diagnostic.code)
29149
+ ),
29150
+ initialCanonicalSignature: serializeCanonicalDocumentForExport(document2),
29151
+ initialNumberingSignature: serializeNumberingCatalogForExport(
29152
+ document2.numbering
29153
+ ),
29154
+ sourceSubPartPaths: {
29155
+ headers: sourceHeaderPaths,
29156
+ footers: sourceFooterPaths,
29157
+ footnotesPartPath,
29158
+ footnotesRelationshipId,
29159
+ endnotesPartPath,
29160
+ endnotesRelationshipId,
29161
+ themePartPath,
29162
+ themeRelationshipId: themeRelationship?.id
29163
+ },
29164
+ embeddingOffloadEntries: rehydratedOffloadSync.entries,
29165
+ ...options.hostAdapter !== void 0 ? { hostAdapter: options.hostAdapter } : {}
29166
+ };
29167
+ stages.emit("skeleton-ready");
29168
+ return {
29169
+ initialSessionState,
29170
+ initialSnapshot: snapshot,
29171
+ readOnly: false,
29172
+ protectionSnapshot: importedProtectionSnapshot,
29173
+ exportDocx: async (nextSessionState, exportOptions) => runStatefulExport(importedState, nextSessionState, exportOptions),
29174
+ embeddedDocumentManifests: embeddedDocumentManifestsSync,
29175
+ ...embeddedWorkflowPayload?.editorState ? { initialEditorStatePayload: embeddedWorkflowPayload.editorState } : {}
29176
+ };
29177
+ } catch (error) {
29178
+ return createDiagnosticsSession(
29179
+ options,
29180
+ createImportDiagnosticsFromError(error)
29181
+ );
29182
+ }
29183
+ }
28338
29184
  function deriveCanonicalImportTimestamp(metadata) {
28339
29185
  return firstNonEmptyString(metadata.createdUtc, metadata.modifiedUtc) ?? CANONICAL_IMPORT_TIMESTAMP;
28340
29186
  }
@@ -28627,5 +29473,6 @@ function isReopenBarrier(result) {
28627
29473
  SessionNotOpenError,
28628
29474
  SessionNotWiredError,
28629
29475
  isReopenBarrier,
28630
- loadDocxSessionAsync
29476
+ loadDocxSessionAsync,
29477
+ loadDocxSessionSync
28631
29478
  });