@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
@@ -8,7 +8,7 @@ import {
8
8
  getRevisionActionability,
9
9
  normalizeParsedTextDocument,
10
10
  normalizeParsedTextDocumentAsync
11
- } from "./chunk-327AIUXL.js";
11
+ } from "./chunk-UWDWGQH5.js";
12
12
  import {
13
13
  OLE_RELATIONSHIP_TYPES,
14
14
  buildFieldRegistry,
@@ -59,7 +59,7 @@ import {
59
59
  resolveHighlightColor,
60
60
  setActiveParseTelemetryBus,
61
61
  toCanonicalNumberingInstanceId
62
- } from "./chunk-NQZUGMLW.js";
62
+ } from "./chunk-TMU7JMXX.js";
63
63
  import {
64
64
  createPersistedSourcePackage,
65
65
  decodeBytesBase64,
@@ -117,7 +117,7 @@ import {
117
117
  createCanonicalDocumentId,
118
118
  createCanonicalDocumentSignature,
119
119
  validatePersistedEditorSnapshot
120
- } from "./chunk-4JNUMMM7.js";
120
+ } from "./chunk-PGGPPZ65.js";
121
121
  import {
122
122
  createDetachedAnchor
123
123
  } from "./chunk-M2HUK3KF.js";
@@ -7577,16 +7577,14 @@ function parseHdrFtrXml(xml, rootLocalName, opts = { relationships: [] }) {
7577
7577
  return { blocks: [] };
7578
7578
  }
7579
7579
  const blocks = [];
7580
- for (const child of hdrFtrElement.children) {
7581
- if (child.type !== "element") {
7582
- continue;
7583
- }
7580
+ const rootXmlPath = `/${rootLocalName}[1]`;
7581
+ for (const [child, childXmlPath] of elementChildrenWithXmlPath(hdrFtrElement, rootXmlPath)) {
7584
7582
  const name = localName(child.name);
7585
7583
  if (name === "p") {
7586
7584
  blocks.push(parseParagraphElement(child, xml, opts));
7587
7585
  } else if (name === "tbl") {
7588
7586
  if (isSimpleSecondaryStoryTable(child)) {
7589
- blocks.push(parseSimpleTableElement(child, xml, opts));
7587
+ blocks.push(parseSimpleTableElement(child, xml, opts, childXmlPath));
7590
7588
  } else {
7591
7589
  blocks.push({
7592
7590
  type: "opaque_block",
@@ -7635,7 +7633,7 @@ function parseParagraphElement(pElement, sourceXml, opts) {
7635
7633
  } else if (name === "hyperlink") {
7636
7634
  children.push(parseHyperlinkElement(child, opts));
7637
7635
  } else if (name === "bookmarkStart" || name === "bookmarkEnd") {
7638
- children.push(parseBookmarkElement(child));
7636
+ children.push(parseBookmarkElement(child, opts.sourcePartPath ?? "/word/document.xml"));
7639
7637
  } else if (name === "fldSimple") {
7640
7638
  if (activeComplexField && activeComplexField.instruction.trim().length > 0) {
7641
7639
  children.push(
@@ -7661,7 +7659,7 @@ function parseParagraphElement(pElement, sourceXml, opts) {
7661
7659
  } else if (gname === "hyperlink") {
7662
7660
  children.push(parseHyperlinkElement(grandchild, opts));
7663
7661
  } else if (gname === "bookmarkStart" || gname === "bookmarkEnd") {
7664
- children.push(parseBookmarkElement(grandchild));
7662
+ children.push(parseBookmarkElement(grandchild, opts.sourcePartPath ?? "/word/document.xml"));
7665
7663
  } else if (gname === "fldSimple") {
7666
7664
  pushFieldNode(children, grandchild, "simple", opts.sourcePartPath);
7667
7665
  }
@@ -7790,12 +7788,12 @@ function parseRunElement(rElement, opts) {
7790
7788
  nodes.push(ref);
7791
7789
  }
7792
7790
  } else if (name === "bookmarkStart" || name === "bookmarkEnd") {
7793
- nodes.push(parseBookmarkElement(child));
7791
+ nodes.push(parseBookmarkElement(child, opts.sourcePartPath ?? "/word/document.xml"));
7794
7792
  } else if (name === "instrText") {
7795
7793
  pushFieldNode(nodes, child, "complex", opts.sourcePartPath);
7796
7794
  } else if (name === "drawing") {
7797
7795
  const drawingXml = currentSourceXml.slice(child.start, child.end);
7798
- const drawingResult = parseDrawingInlineNode(drawingXml, opts);
7796
+ const drawingResult = parseDrawingInlineNode(drawingXml, opts, void 0, child);
7799
7797
  if (drawingResult) {
7800
7798
  nodes.push(drawingResult);
7801
7799
  }
@@ -7877,11 +7875,11 @@ function parseRunChildNode(child, marks, opts) {
7877
7875
  return null;
7878
7876
  }
7879
7877
  if (name === "bookmarkStart" || name === "bookmarkEnd") {
7880
- return parseBookmarkElement(child);
7878
+ return parseBookmarkElement(child, opts.sourcePartPath ?? "/word/document.xml");
7881
7879
  }
7882
7880
  if (name === "drawing") {
7883
7881
  const drawingXml = currentSourceXml.slice(child.start, child.end);
7884
- return parseDrawingInlineNode(drawingXml, opts);
7882
+ return parseDrawingInlineNode(drawingXml, opts, void 0, child);
7885
7883
  }
7886
7884
  if (name === "pict") {
7887
7885
  const pictXml = currentSourceXml.slice(child.start, child.end);
@@ -7927,7 +7925,7 @@ function parseHyperlinkElement(element, opts) {
7927
7925
  children
7928
7926
  };
7929
7927
  }
7930
- function parseDrawingInlineNode(rawXml, opts, legacyDrawingXml) {
7928
+ function parseDrawingInlineNode(rawXml, opts, legacyDrawingXml, sourceElement) {
7931
7929
  try {
7932
7930
  const frame = parseDrawingFrame(rawXml, {
7933
7931
  ...opts,
@@ -7942,7 +7940,14 @@ function parseDrawingInlineNode(rawXml, opts, legacyDrawingXml) {
7942
7940
  blockParser: (xml) => parseTxbxBlocksForHeaderFooter(xml, opts, 1)
7943
7941
  });
7944
7942
  if (frame && !(frame.content.type === "shape" && frame.content.isTextBox)) {
7945
- return frame;
7943
+ return sourceElement ? {
7944
+ ...frame,
7945
+ sourceRef: createElementSourceRef(
7946
+ opts.sourcePartPath ?? "/word/document.xml",
7947
+ "drawing",
7948
+ sourceElement
7949
+ )
7950
+ } : frame;
7946
7951
  }
7947
7952
  if (frame?.content.type !== "shape" || !frame.content.isTextBox) {
7948
7953
  return frame;
@@ -7981,14 +7986,13 @@ function parseTxbxBlocksForHeaderFooter(innerXml, opts, depth) {
7981
7986
  currentSourceXml = innerXml;
7982
7987
  try {
7983
7988
  const blocks = [];
7984
- for (const child of txbxContent.children) {
7985
- if (child.type !== "element") continue;
7989
+ for (const [child, childXmlPath] of elementChildrenWithXmlPath(txbxContent, "/txbxContent[1]")) {
7986
7990
  const name = localName(child.name);
7987
7991
  if (name === "p") {
7988
7992
  blocks.push(parseParagraphElement(child, innerXml, opts));
7989
7993
  } else if (name === "tbl") {
7990
7994
  if (isSimpleSecondaryStoryTable(child)) {
7991
- blocks.push(parseSimpleTableElement(child, innerXml, opts));
7995
+ blocks.push(parseSimpleTableElement(child, innerXml, opts, childXmlPath));
7992
7996
  } else {
7993
7997
  blocks.push({
7994
7998
  type: "opaque_block",
@@ -8004,18 +8008,21 @@ function parseTxbxBlocksForHeaderFooter(innerXml, opts, depth) {
8004
8008
  currentSourceXml = previousSourceXml;
8005
8009
  }
8006
8010
  }
8007
- function parseBookmarkElement(element) {
8011
+ function parseBookmarkElement(element, partPath) {
8008
8012
  const bookmarkId = readStringAttr(element, "w:id") ?? "0";
8013
+ const sourceRef = createElementSourceRef(partPath, localName(element.name), element);
8009
8014
  if (localName(element.name) === "bookmarkStart") {
8010
8015
  return {
8011
8016
  type: "bookmark_start",
8012
8017
  bookmarkId,
8013
- name: readStringAttr(element, "w:name") ?? ""
8018
+ name: readStringAttr(element, "w:name") ?? "",
8019
+ sourceRef
8014
8020
  };
8015
8021
  }
8016
8022
  return {
8017
8023
  type: "bookmark_end",
8018
- bookmarkId
8024
+ bookmarkId,
8025
+ sourceRef
8019
8026
  };
8020
8027
  }
8021
8028
  function pushFieldNode(nodes, element, fieldType, sourcePartPath = "/word/document.xml") {
@@ -8058,6 +8065,40 @@ function createFieldSequenceSourceRef(partPath, node) {
8058
8065
  endOffset: node.end
8059
8066
  };
8060
8067
  }
8068
+ function createElementSourceRef(partPath, element, node) {
8069
+ return {
8070
+ sourceId: `part:${partPath}#${element}:${node.start}`,
8071
+ partPath,
8072
+ storyKind: /\/footer\d+\.xml$/i.test(partPath) ? "footer" : "header",
8073
+ element,
8074
+ startOffset: node.start,
8075
+ endOffset: node.end
8076
+ };
8077
+ }
8078
+ function createStableTableSourceRef(partPath, element, xmlPath, extras = {}) {
8079
+ return {
8080
+ sourceId: `part:${partPath}#${xmlPath}`,
8081
+ partPath,
8082
+ storyKind: /\/footer\d+\.xml$/i.test(partPath) ? "footer" : "header",
8083
+ element,
8084
+ xmlPath,
8085
+ ...extras
8086
+ };
8087
+ }
8088
+ function elementChildrenWithXmlPath(parent, parentXmlPath) {
8089
+ const ordinals = /* @__PURE__ */ new Map();
8090
+ const children = [];
8091
+ for (const child of parent.children) {
8092
+ if (child.type !== "element") {
8093
+ continue;
8094
+ }
8095
+ const name = localName(child.name);
8096
+ const ordinal = (ordinals.get(name) ?? 0) + 1;
8097
+ ordinals.set(name, ordinal);
8098
+ children.push([child, `${parentXmlPath}/${name}[${ordinal}]`]);
8099
+ }
8100
+ return children;
8101
+ }
8061
8102
  function readFieldInstruction(element) {
8062
8103
  const instruction = readStringAttr(element, "w:instr") ?? extractTextContent(element);
8063
8104
  return instruction.trim().length > 0 ? instruction : void 0;
@@ -8284,7 +8325,7 @@ function containsRiskyElement(element) {
8284
8325
  }
8285
8326
  return false;
8286
8327
  }
8287
- function parseSimpleTableElement(tblElement, sourceXml, opts) {
8328
+ function parseSimpleTableElement(tblElement, sourceXml, opts, sourceXmlPath) {
8288
8329
  let gridColumns = [];
8289
8330
  const rows = [];
8290
8331
  let propertiesXml;
@@ -8322,11 +8363,12 @@ function parseSimpleTableElement(tblElement, sourceXml, opts) {
8322
8363
  } else if (name === "tblGrid") {
8323
8364
  gridColumns = readGridColumns2(child);
8324
8365
  } else if (name === "tr") {
8325
- rows.push(parseSimpleTableRow(child, sourceXml, opts));
8366
+ rows.push(parseSimpleTableRow(child, sourceXml, opts, `${sourceXmlPath}/tr[${rows.length + 1}]`));
8326
8367
  }
8327
8368
  }
8328
8369
  return {
8329
8370
  type: "table",
8371
+ sourceRef: createStableTableSourceRef(opts.sourcePartPath ?? "/word/document.xml", "tbl", sourceXmlPath),
8330
8372
  ...styleId ? { styleId } : {},
8331
8373
  ...propertiesXml ? { propertiesXml } : {},
8332
8374
  gridColumns,
@@ -8348,7 +8390,7 @@ function parseSimpleTableElement(tblElement, sourceXml, opts) {
8348
8390
  function readGridColumns2(tblGrid) {
8349
8391
  return readGridColumns(tblGrid);
8350
8392
  }
8351
- function parseSimpleTableRow(trElement, sourceXml, opts) {
8393
+ function parseSimpleTableRow(trElement, sourceXml, opts, sourceXmlPath) {
8352
8394
  const cells = [];
8353
8395
  let propertiesXml;
8354
8396
  let height;
@@ -8369,11 +8411,12 @@ function parseSimpleTableRow(trElement, sourceXml, opts) {
8369
8411
  horizontalAlignment = readRowHorizontalAlignment(child);
8370
8412
  cnfStyle = readRowCnfStyle(child);
8371
8413
  } else if (name === "tc") {
8372
- cells.push(parseSimpleTableCell(child, sourceXml, opts));
8414
+ cells.push(parseSimpleTableCell(child, sourceXml, opts, `${sourceXmlPath}/tc[${cells.length + 1}]`));
8373
8415
  }
8374
8416
  }
8375
8417
  return {
8376
8418
  type: "table_row",
8419
+ sourceRef: createStableTableSourceRef(opts.sourcePartPath ?? "/word/document.xml", "tr", sourceXmlPath),
8377
8420
  ...propertiesXml ? { propertiesXml } : {},
8378
8421
  ...height !== void 0 ? { height } : {},
8379
8422
  ...heightRule ? { heightRule } : {},
@@ -8384,7 +8427,7 @@ function parseSimpleTableRow(trElement, sourceXml, opts) {
8384
8427
  cells
8385
8428
  };
8386
8429
  }
8387
- function parseSimpleTableCell(tcElement, sourceXml, opts) {
8430
+ function parseSimpleTableCell(tcElement, sourceXml, opts, sourceXmlPath) {
8388
8431
  const children = [];
8389
8432
  let propertiesXml;
8390
8433
  let gridSpan;
@@ -8426,6 +8469,9 @@ function parseSimpleTableCell(tcElement, sourceXml, opts) {
8426
8469
  }
8427
8470
  return {
8428
8471
  type: "table_cell",
8472
+ sourceRef: createStableTableSourceRef(opts.sourcePartPath ?? "/word/document.xml", "tc", sourceXmlPath, {
8473
+ tableCellPath: sourceXmlPath
8474
+ }),
8429
8475
  ...propertiesXml ? { propertiesXml } : {},
8430
8476
  ...gridSpan ? { gridSpan } : {},
8431
8477
  ...verticalMerge ? { verticalMerge } : {},
@@ -8471,28 +8517,22 @@ function parseFootnotesXml(xml) {
8471
8517
  const footnotes = {};
8472
8518
  const endnotes = {};
8473
8519
  if (footnotesElement) {
8474
- for (const child of footnotesElement.children) {
8475
- if (child.type !== "element") {
8476
- continue;
8477
- }
8520
+ for (const [child, childXmlPath] of elementChildrenWithXmlPath2(footnotesElement, "/footnotes[1]")) {
8478
8521
  if (localName(child.name) !== "footnote") {
8479
8522
  continue;
8480
8523
  }
8481
- const definition = parseNoteElement(child, "footnote");
8524
+ const definition = parseNoteElement(child, "footnote", childXmlPath);
8482
8525
  if (definition) {
8483
8526
  footnotes[definition.noteId] = definition;
8484
8527
  }
8485
8528
  }
8486
8529
  }
8487
8530
  if (endnotesElement) {
8488
- for (const child of endnotesElement.children) {
8489
- if (child.type !== "element") {
8490
- continue;
8491
- }
8531
+ for (const [child, childXmlPath] of elementChildrenWithXmlPath2(endnotesElement, "/endnotes[1]")) {
8492
8532
  if (localName(child.name) !== "endnote") {
8493
8533
  continue;
8494
8534
  }
8495
- const definition = parseNoteElement(child, "endnote");
8535
+ const definition = parseNoteElement(child, "endnote", childXmlPath);
8496
8536
  if (definition) {
8497
8537
  endnotes[definition.noteId] = definition;
8498
8538
  }
@@ -8512,14 +8552,11 @@ function parseEndnotesXml(xml, existing) {
8512
8552
  ...existing?.endnotes ?? {}
8513
8553
  };
8514
8554
  if (endnotesElement) {
8515
- for (const child of endnotesElement.children) {
8516
- if (child.type !== "element") {
8517
- continue;
8518
- }
8555
+ for (const [child, childXmlPath] of elementChildrenWithXmlPath2(endnotesElement, "/endnotes[1]")) {
8519
8556
  if (localName(child.name) !== "endnote") {
8520
8557
  continue;
8521
8558
  }
8522
- const definition = parseNoteElement(child, "endnote");
8559
+ const definition = parseNoteElement(child, "endnote", childXmlPath);
8523
8560
  if (definition) {
8524
8561
  endnotes[definition.noteId] = definition;
8525
8562
  }
@@ -8568,7 +8605,7 @@ function parseFootnoteSeparators(xml) {
8568
8605
  ...continuationSeparatorParagraphXml !== void 0 ? { continuationSeparatorParagraphXml } : {}
8569
8606
  };
8570
8607
  }
8571
- function parseNoteElement(element, kind) {
8608
+ function parseNoteElement(element, kind, sourceXmlPath) {
8572
8609
  const rawId = readStringAttr(element, "w:id") ?? "";
8573
8610
  const rawType = readStringAttr(element, "w:type") ?? "";
8574
8611
  if (!rawId || SPECIAL_NOTE_IDS.has(rawId) || SPECIAL_NOTE_TYPES.has(rawType)) {
@@ -8576,16 +8613,13 @@ function parseNoteElement(element, kind) {
8576
8613
  }
8577
8614
  const noteId = rawId;
8578
8615
  const blocks = [];
8579
- for (const child of element.children) {
8580
- if (child.type !== "element") {
8581
- continue;
8582
- }
8616
+ for (const [child, childXmlPath] of elementChildrenWithXmlPath2(element, sourceXmlPath)) {
8583
8617
  const name = localName(child.name);
8584
8618
  if (name === "p") {
8585
- blocks.push(parseParagraphElement2(child));
8619
+ blocks.push(parseParagraphElement2(child, kind));
8586
8620
  } else if (name === "tbl") {
8587
8621
  if (isSimpleSecondaryStoryTable2(child)) {
8588
- blocks.push(parseSimpleTableElement2(child));
8622
+ blocks.push(parseSimpleTableElement2(child, kind, childXmlPath));
8589
8623
  } else {
8590
8624
  blocks.push({
8591
8625
  type: "opaque_block",
@@ -8605,7 +8639,7 @@ function parseNoteElement(element, kind) {
8605
8639
  }
8606
8640
  return { noteId, kind, blocks };
8607
8641
  }
8608
- function parseParagraphElement2(pElement) {
8642
+ function parseParagraphElement2(pElement, noteKind) {
8609
8643
  let styleId;
8610
8644
  let alignment;
8611
8645
  let spacing;
@@ -8628,15 +8662,15 @@ function parseParagraphElement2(pElement) {
8628
8662
  spacing = readParagraphSpacing2(child);
8629
8663
  indentation = readParagraphIndentation2(child);
8630
8664
  } else if (name === "r") {
8631
- activeComplexField = appendRunNodes2(child, children, activeComplexField);
8665
+ activeComplexField = appendRunNodes2(child, children, activeComplexField, noteKind);
8632
8666
  } else if (name === "hyperlink") {
8633
8667
  if (activeComplexField && activeComplexField.instruction.trim().length > 0) {
8634
8668
  children.push(createFieldNode2(activeComplexField.instruction, "complex", activeComplexField.children));
8635
8669
  activeComplexField = null;
8636
8670
  }
8637
- children.push(parseHyperlinkElement2(child));
8671
+ children.push(parseHyperlinkElement2(child, noteKind));
8638
8672
  } else if (name === "bookmarkStart" || name === "bookmarkEnd") {
8639
- const bookmarkNode = parseBookmarkElement2(child);
8673
+ const bookmarkNode = parseBookmarkElement2(child, noteKind);
8640
8674
  if (activeComplexField?.mode === "result") {
8641
8675
  activeComplexField.children.push(bookmarkNode);
8642
8676
  } else {
@@ -8666,7 +8700,7 @@ function parseParagraphElement2(pElement) {
8666
8700
  children
8667
8701
  };
8668
8702
  }
8669
- function appendRunNodes2(rElement, nodes, activeComplexField) {
8703
+ function appendRunNodes2(rElement, nodes, activeComplexField, noteKind) {
8670
8704
  const marks = parseRunProperties2(rElement);
8671
8705
  for (const child of rElement.children) {
8672
8706
  if (child.type !== "element") {
@@ -8695,7 +8729,7 @@ function appendRunNodes2(rElement, nodes, activeComplexField) {
8695
8729
  }
8696
8730
  continue;
8697
8731
  }
8698
- const inlineNode = parseRunChildNode2(child, marks);
8732
+ const inlineNode = parseRunChildNode2(child, marks, noteKind);
8699
8733
  if (!inlineNode) {
8700
8734
  continue;
8701
8735
  }
@@ -8707,7 +8741,7 @@ function appendRunNodes2(rElement, nodes, activeComplexField) {
8707
8741
  }
8708
8742
  return activeComplexField;
8709
8743
  }
8710
- function parseRunElement2(rElement) {
8744
+ function parseRunElement2(rElement, noteKind) {
8711
8745
  const nodes = [];
8712
8746
  const marks = parseRunProperties2(rElement);
8713
8747
  for (const child of rElement.children) {
@@ -8740,14 +8774,14 @@ function parseRunElement2(rElement) {
8740
8774
  nodes.push({ type: "footnote_ref", noteId, noteKind: "endnote" });
8741
8775
  }
8742
8776
  } else if (name === "bookmarkStart" || name === "bookmarkEnd") {
8743
- nodes.push(parseBookmarkElement2(child));
8777
+ nodes.push(parseBookmarkElement2(child, noteKind));
8744
8778
  } else if (name === "instrText") {
8745
8779
  pushFieldNode2(nodes, child, "complex");
8746
8780
  }
8747
8781
  }
8748
8782
  return nodes;
8749
8783
  }
8750
- function parseRunChildNode2(child, marks) {
8784
+ function parseRunChildNode2(child, marks, noteKind) {
8751
8785
  const name = localName(child.name);
8752
8786
  if (name === "t") {
8753
8787
  const text = extractTextContent2(child);
@@ -8781,16 +8815,16 @@ function parseRunChildNode2(child, marks) {
8781
8815
  return null;
8782
8816
  }
8783
8817
  if (name === "bookmarkStart" || name === "bookmarkEnd") {
8784
- return parseBookmarkElement2(child);
8818
+ return parseBookmarkElement2(child, noteKind);
8785
8819
  }
8786
8820
  return null;
8787
8821
  }
8788
- function parseHyperlinkElement2(element) {
8822
+ function parseHyperlinkElement2(element, noteKind) {
8789
8823
  const href = element.attributes["w:anchor"] ? `#${element.attributes["w:anchor"]}` : element.attributes["r:id"] ?? "relationship:unknown";
8790
8824
  const children = [];
8791
8825
  for (const child of element.children) {
8792
8826
  if (child.type === "element" && localName(child.name) === "r") {
8793
- for (const runChild of parseRunElement2(child)) {
8827
+ for (const runChild of parseRunElement2(child, noteKind)) {
8794
8828
  if (runChild.type === "text" || runChild.type === "hard_break" || runChild.type === "tab") {
8795
8829
  children.push(runChild);
8796
8830
  }
@@ -8803,18 +8837,21 @@ function parseHyperlinkElement2(element) {
8803
8837
  children
8804
8838
  };
8805
8839
  }
8806
- function parseBookmarkElement2(element) {
8840
+ function parseBookmarkElement2(element, noteKind) {
8807
8841
  const bookmarkId = readStringAttr(element, "w:id") ?? "0";
8842
+ const sourceRef = createElementSourceRef2(noteKind, localName(element.name), element);
8808
8843
  if (localName(element.name) === "bookmarkStart") {
8809
8844
  return {
8810
8845
  type: "bookmark_start",
8811
8846
  bookmarkId,
8812
- name: readStringAttr(element, "w:name") ?? ""
8847
+ name: readStringAttr(element, "w:name") ?? "",
8848
+ sourceRef
8813
8849
  };
8814
8850
  }
8815
8851
  return {
8816
8852
  type: "bookmark_end",
8817
- bookmarkId
8853
+ bookmarkId,
8854
+ sourceRef
8818
8855
  };
8819
8856
  }
8820
8857
  function pushFieldNode2(nodes, element, fieldType) {
@@ -8986,7 +9023,7 @@ function containsRiskyElement2(element) {
8986
9023
  }
8987
9024
  return false;
8988
9025
  }
8989
- function parseSimpleTableElement2(tblElement) {
9026
+ function parseSimpleTableElement2(tblElement, noteKind = "footnote", sourceXmlPath = `/${noteKind === "endnote" ? "endnotes" : "footnotes"}[1]/tbl[1]`) {
8990
9027
  let gridColumns = [];
8991
9028
  const rows = [];
8992
9029
  let propertiesXml;
@@ -9024,11 +9061,12 @@ function parseSimpleTableElement2(tblElement) {
9024
9061
  } else if (name === "tblGrid") {
9025
9062
  gridColumns = readGridColumns3(child);
9026
9063
  } else if (name === "tr") {
9027
- rows.push(parseSimpleTableRow2(child));
9064
+ rows.push(parseSimpleTableRow2(child, noteKind, `${sourceXmlPath}/tr[${rows.length + 1}]`));
9028
9065
  }
9029
9066
  }
9030
9067
  return {
9031
9068
  type: "table",
9069
+ sourceRef: createStableTableSourceRef2(noteKind, "tbl", sourceXmlPath),
9032
9070
  ...styleId ? { styleId } : {},
9033
9071
  ...propertiesXml ? { propertiesXml } : {},
9034
9072
  gridColumns,
@@ -9050,7 +9088,7 @@ function parseSimpleTableElement2(tblElement) {
9050
9088
  function readGridColumns3(tblGrid) {
9051
9089
  return readGridColumns(tblGrid);
9052
9090
  }
9053
- function parseSimpleTableRow2(trElement) {
9091
+ function parseSimpleTableRow2(trElement, noteKind, sourceXmlPath) {
9054
9092
  const cells = [];
9055
9093
  let propertiesXml;
9056
9094
  let height;
@@ -9071,11 +9109,12 @@ function parseSimpleTableRow2(trElement) {
9071
9109
  horizontalAlignment = readRowHorizontalAlignment(child);
9072
9110
  cnfStyle = readRowCnfStyle(child);
9073
9111
  } else if (name === "tc") {
9074
- cells.push(parseSimpleTableCell2(child));
9112
+ cells.push(parseSimpleTableCell2(child, noteKind, `${sourceXmlPath}/tc[${cells.length + 1}]`));
9075
9113
  }
9076
9114
  }
9077
9115
  return {
9078
9116
  type: "table_row",
9117
+ sourceRef: createStableTableSourceRef2(noteKind, "tr", sourceXmlPath),
9079
9118
  ...propertiesXml ? { propertiesXml } : {},
9080
9119
  ...height !== void 0 ? { height } : {},
9081
9120
  ...heightRule ? { heightRule } : {},
@@ -9086,7 +9125,7 @@ function parseSimpleTableRow2(trElement) {
9086
9125
  cells
9087
9126
  };
9088
9127
  }
9089
- function parseSimpleTableCell2(tcElement) {
9128
+ function parseSimpleTableCell2(tcElement, noteKind, sourceXmlPath) {
9090
9129
  const children = [];
9091
9130
  let propertiesXml;
9092
9131
  let gridSpan;
@@ -9123,11 +9162,14 @@ function parseSimpleTableCell2(tcElement) {
9123
9162
  margins = readCellMargins(child);
9124
9163
  cnfStyle = readCellCnfStyle(child);
9125
9164
  } else if (name === "p") {
9126
- children.push(parseParagraphElement2(child));
9165
+ children.push(parseParagraphElement2(child, noteKind));
9127
9166
  }
9128
9167
  }
9129
9168
  return {
9130
9169
  type: "table_cell",
9170
+ sourceRef: createStableTableSourceRef2(noteKind, "tc", sourceXmlPath, {
9171
+ tableCellPath: sourceXmlPath
9172
+ }),
9131
9173
  ...propertiesXml ? { propertiesXml } : {},
9132
9174
  ...gridSpan ? { gridSpan } : {},
9133
9175
  ...verticalMerge ? { verticalMerge } : {},
@@ -9143,6 +9185,42 @@ function parseSimpleTableCell2(tcElement) {
9143
9185
  children: children.length > 0 ? children : [{ type: "paragraph", children: [] }]
9144
9186
  };
9145
9187
  }
9188
+ function createStableTableSourceRef2(noteKind, element, xmlPath, extras = {}) {
9189
+ const partPath = noteKind === "endnote" ? "/word/endnotes.xml" : "/word/footnotes.xml";
9190
+ return {
9191
+ sourceId: `part:${partPath}#${xmlPath}`,
9192
+ partPath,
9193
+ storyKind: noteKind,
9194
+ element,
9195
+ xmlPath,
9196
+ ...extras
9197
+ };
9198
+ }
9199
+ function createElementSourceRef2(noteKind, element, node) {
9200
+ const partPath = noteKind === "endnote" ? "/word/endnotes.xml" : "/word/footnotes.xml";
9201
+ return {
9202
+ sourceId: `part:${partPath}#${element}:${node.start}`,
9203
+ partPath,
9204
+ storyKind: noteKind,
9205
+ element,
9206
+ startOffset: node.start,
9207
+ endOffset: node.end
9208
+ };
9209
+ }
9210
+ function elementChildrenWithXmlPath2(parent, parentXmlPath) {
9211
+ const ordinals = /* @__PURE__ */ new Map();
9212
+ const children = [];
9213
+ for (const child of parent.children) {
9214
+ if (child.type !== "element") {
9215
+ continue;
9216
+ }
9217
+ const name = localName(child.name);
9218
+ const ordinal = (ordinals.get(name) ?? 0) + 1;
9219
+ ordinals.set(name, ordinal);
9220
+ children.push([child, `${parentXmlPath}/${name}[${ordinal}]`]);
9221
+ }
9222
+ return children;
9223
+ }
9146
9224
  function serializeElementToXml2(element) {
9147
9225
  const attrs = Object.entries(element.attributes).map(([key, value]) => ` ${key}="${escapeXmlAttribute4(value)}"`).join("");
9148
9226
  const children = element.children.map((child) => {