ooxml-core 0.4.0 → 0.6.0

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 (104) hide show
  1. package/NOTICE +2 -0
  2. package/README.md +1 -0
  3. package/dist/digest/algorithm-names.d.ts +20 -0
  4. package/dist/digest/algorithm-names.d.ts.map +1 -0
  5. package/dist/digest/base64.d.ts +8 -0
  6. package/dist/digest/base64.d.ts.map +1 -0
  7. package/dist/digest/digest.d.ts +13 -0
  8. package/dist/digest/digest.d.ts.map +1 -0
  9. package/dist/digest/index.cjs +594 -0
  10. package/dist/digest/index.d.ts +8 -0
  11. package/dist/digest/index.d.ts.map +1 -0
  12. package/dist/digest/index.mjs +581 -0
  13. package/dist/digest/password-hash.d.ts +30 -0
  14. package/dist/digest/password-hash.d.ts.map +1 -0
  15. package/dist/digest/sha1.d.ts +3 -0
  16. package/dist/digest/sha1.d.ts.map +1 -0
  17. package/dist/digest/sha256.d.ts +10 -0
  18. package/dist/digest/sha256.d.ts.map +1 -0
  19. package/dist/digest/sha512.d.ts +5 -0
  20. package/dist/digest/sha512.d.ts.map +1 -0
  21. package/dist/docx/block-parser.d.ts.map +1 -1
  22. package/dist/docx/embedded.cjs +153 -59
  23. package/dist/docx/embedded.mjs +153 -59
  24. package/dist/docx/equation.d.ts +8 -0
  25. package/dist/docx/equation.d.ts.map +1 -0
  26. package/dist/docx/index.cjs +153 -59
  27. package/dist/docx/index.mjs +153 -59
  28. package/dist/docx/layout/adapter.d.ts.map +1 -1
  29. package/dist/docx/layout/index.cjs +3 -1
  30. package/dist/docx/layout/index.mjs +3 -1
  31. package/dist/docx/load/index.cjs +155 -61
  32. package/dist/docx/load/index.mjs +155 -61
  33. package/dist/docx/model-run.d.ts +5 -0
  34. package/dist/docx/model-run.d.ts.map +1 -1
  35. package/dist/docx/parse-revisions.d.ts.map +1 -1
  36. package/dist/docx/parse-table.d.ts.map +1 -1
  37. package/dist/docx/write-inline.d.ts.map +1 -1
  38. package/dist/docx/write-table-margins.d.ts +5 -0
  39. package/dist/docx/write-table-margins.d.ts.map +1 -0
  40. package/dist/docx/write-table-properties.d.ts +6 -2
  41. package/dist/docx/write-table-properties.d.ts.map +1 -1
  42. package/dist/docx/write-table.d.ts.map +1 -1
  43. package/dist/index.cjs +2640 -13
  44. package/dist/index.d.ts +2 -0
  45. package/dist/index.d.ts.map +1 -1
  46. package/dist/index.mjs +2639 -14
  47. package/dist/math/index.cjs +2050 -0
  48. package/dist/math/index.d.ts +15 -0
  49. package/dist/math/index.d.ts.map +1 -0
  50. package/dist/math/index.mjs +1985 -0
  51. package/dist/math/latex-omml-siblings.d.ts +21 -0
  52. package/dist/math/latex-omml-siblings.d.ts.map +1 -0
  53. package/dist/math/latex-omml-symbols.d.ts +42 -0
  54. package/dist/math/latex-omml-symbols.d.ts.map +1 -0
  55. package/dist/math/latex-to-omml-commands.d.ts +9 -0
  56. package/dist/math/latex-to-omml-commands.d.ts.map +1 -0
  57. package/dist/math/latex-to-omml-constructs.d.ts +39 -0
  58. package/dist/math/latex-to-omml-constructs.d.ts.map +1 -0
  59. package/dist/math/latex-to-omml-environments.d.ts +28 -0
  60. package/dist/math/latex-to-omml-environments.d.ts.map +1 -0
  61. package/dist/math/latex-to-omml.d.ts +9 -0
  62. package/dist/math/latex-to-omml.d.ts.map +1 -0
  63. package/dist/math/omml-color.d.ts +11 -0
  64. package/dist/math/omml-color.d.ts.map +1 -0
  65. package/dist/math/omml-dom.d.ts +7 -0
  66. package/dist/math/omml-dom.d.ts.map +1 -0
  67. package/dist/math/omml-mathml-converters.d.ts +39 -0
  68. package/dist/math/omml-mathml-converters.d.ts.map +1 -0
  69. package/dist/math/omml-mathml-helpers.d.ts +23 -0
  70. package/dist/math/omml-mathml-helpers.d.ts.map +1 -0
  71. package/dist/math/omml-node.d.ts +7 -0
  72. package/dist/math/omml-node.d.ts.map +1 -0
  73. package/dist/math/omml-to-latex-helpers.d.ts +41 -0
  74. package/dist/math/omml-to-latex-helpers.d.ts.map +1 -0
  75. package/dist/math/omml-to-latex-layout.d.ts +18 -0
  76. package/dist/math/omml-to-latex-layout.d.ts.map +1 -0
  77. package/dist/math/omml-to-latex.d.ts +6 -0
  78. package/dist/math/omml-to-latex.d.ts.map +1 -0
  79. package/dist/math/omml-to-mathml.d.ts +21 -0
  80. package/dist/math/omml-to-mathml.d.ts.map +1 -0
  81. package/dist/xlsx/edit/history.d.ts +1 -1
  82. package/dist/xlsx/edit/history.d.ts.map +1 -1
  83. package/dist/xlsx/edit/index.d.ts +1 -1
  84. package/dist/xlsx/edit/index.d.ts.map +1 -1
  85. package/dist/xlsx/edit/protection.d.ts +18 -6
  86. package/dist/xlsx/edit/protection.d.ts.map +1 -1
  87. package/dist/xlsx/edit/types.d.ts +2 -2
  88. package/dist/xlsx/index.cjs +671 -28
  89. package/dist/xlsx/index.mjs +670 -29
  90. package/dist/xlsx/load/index.cjs +56 -19
  91. package/dist/xlsx/load/index.mjs +56 -19
  92. package/dist/xlsx/model.d.ts +21 -0
  93. package/dist/xlsx/model.d.ts.map +1 -1
  94. package/dist/xlsx/read/load.d.ts.map +1 -1
  95. package/dist/xlsx/read/password-hash.d.ts +15 -0
  96. package/dist/xlsx/read/password-hash.d.ts.map +1 -0
  97. package/dist/xlsx/read/sheet-props.d.ts.map +1 -1
  98. package/dist/xlsx/read/workbook-part.d.ts +3 -1
  99. package/dist/xlsx/read/workbook-part.d.ts.map +1 -1
  100. package/dist/xlsx/write/password-hash.d.ts +8 -0
  101. package/dist/xlsx/write/password-hash.d.ts.map +1 -0
  102. package/dist/xlsx/write/sheet-props.d.ts.map +1 -1
  103. package/dist/xlsx/write/workbook-part.d.ts.map +1 -1
  104. package/package.json +11 -1
@@ -1659,6 +1659,46 @@ function orderSectionProperties(sectPr) {
1659
1659
  orderChildren(sectPr, SECTPR_ORDER);
1660
1660
  }
1661
1661
 
1662
+ // src/docx/write-table-margins.ts
1663
+ var SIDES2 = ["top", "left", "bottom", "right"];
1664
+ var ORDER = ["top", "start", "left", "bottom", "end", "right"];
1665
+ function patchMarginProperties(doc, host, propertiesTag, marginTag, propertiesOrder, next, base) {
1666
+ const changed = SIDES2.filter((side) => next?.[side] !== base?.[side]);
1667
+ if (!changed.length) return;
1668
+ for (const side of changed) {
1669
+ const value = next?.[side];
1670
+ if (value !== void 0 && (!Number.isSafeInteger(value) || value < 0))
1671
+ throw new Error("Table cell margins must be nonnegative whole twips.");
1672
+ }
1673
+ let properties = first2(host, propertiesTag);
1674
+ if (!properties) {
1675
+ properties = makeW(doc, propertiesTag);
1676
+ host.insertBefore(properties, host.firstChild);
1677
+ }
1678
+ let margins = first2(properties, marginTag);
1679
+ if (!margins) {
1680
+ margins = makeW(doc, marginTag);
1681
+ properties.appendChild(margins);
1682
+ }
1683
+ for (const side of changed) {
1684
+ const logical = side === "left" ? "start" : side === "right" ? "end" : side;
1685
+ const edge = first2(margins, logical) ?? first2(margins, side) ?? makeW(doc, side);
1686
+ for (const alias of /* @__PURE__ */ new Set([side, logical]))
1687
+ for (const old of children2(margins, alias)) margins.removeChild(old);
1688
+ const value = next?.[side];
1689
+ if (value === void 0) continue;
1690
+ edge.setAttributeNS(WORD_NS, "w:w", String(value));
1691
+ edge.setAttributeNS(WORD_NS, "w:type", "dxa");
1692
+ margins.appendChild(edge);
1693
+ }
1694
+ if (!Array.from(margins.childNodes).some((node) => node.nodeType === 1) && !margins.attributes.length)
1695
+ properties.removeChild(margins);
1696
+ else orderChildren(margins, ORDER);
1697
+ orderChildren(properties, propertiesOrder);
1698
+ if (!Array.from(properties.childNodes).some((node) => node.nodeType === 1) && !properties.attributes.length)
1699
+ host.removeChild(properties);
1700
+ }
1701
+
1662
1702
  // src/docx/write-table-properties.ts
1663
1703
  var ROW_ORDER = [
1664
1704
  "cnfStyle",
@@ -1718,26 +1758,15 @@ function patchRowProperties(doc, tr, next, base) {
1718
1758
  orderChildren(props, ROW_ORDER);
1719
1759
  }
1720
1760
  function patchTableMargins(doc, table, node, base) {
1721
- if (JSON.stringify(table.cellMargins ?? {}) === JSON.stringify(base?.cellMargins ?? {})) return;
1722
- let props = first2(node, "tblPr");
1723
- if (!props) {
1724
- props = makeW(doc, "tblPr");
1725
- node.insertBefore(props, node.firstChild);
1726
- }
1727
- let margins = first2(props, "tblCellMar");
1728
- if (!margins) {
1729
- margins = makeW(doc, "tblCellMar");
1730
- props.appendChild(margins);
1731
- }
1732
- const built = buildMargins(doc, table.cellMargins ?? {}, "tblCellMar");
1733
- for (const side of ["top", "left", "bottom", "right"]) {
1734
- if (table.cellMargins?.[side] === base?.cellMargins?.[side]) continue;
1735
- for (const old of children2(margins, side)) margins.removeChild(old);
1736
- const replacement = first2(built, side);
1737
- if (replacement) margins.appendChild(replacement);
1738
- }
1739
- orderChildren(margins, ["top", "left", "start", "bottom", "right", "end"]);
1740
- orderChildren(props, TABLE_ORDER);
1761
+ patchMarginProperties(
1762
+ doc,
1763
+ node,
1764
+ "tblPr",
1765
+ "tblCellMar",
1766
+ TABLE_ORDER,
1767
+ table.cellMargins,
1768
+ base?.cellMargins
1769
+ );
1741
1770
  }
1742
1771
  var CELL_ORDER = [
1743
1772
  "cnfStyle",
@@ -1761,6 +1790,9 @@ var CELL_ORDER = [
1761
1790
  ];
1762
1791
  var CELL_BORDER_ORDER = ["top", "start", "left", "bottom", "end", "right", "insideH", "insideV"];
1763
1792
  var CELL_SIDES = ["top", "left", "bottom", "right"];
1793
+ function patchCellMargins(doc, tc, next, base) {
1794
+ patchMarginProperties(doc, tc, "tcPr", "tcMar", CELL_ORDER, next, base);
1795
+ }
1764
1796
  function patchCellBorders(doc, tc, next, base) {
1765
1797
  const changed = CELL_SIDES.filter(
1766
1798
  (side) => JSON.stringify(next?.[side]) !== JSON.stringify(base?.[side])
@@ -1788,6 +1820,23 @@ function patchCellBorders(doc, tc, next, base) {
1788
1820
  orderChildren(props, CELL_ORDER);
1789
1821
  if (!Array.from(props.childNodes).some((node) => node.nodeType === 1)) tc.removeChild(props);
1790
1822
  }
1823
+ function patchCellShading(doc, tc, next, base) {
1824
+ if (next.shadingFill === base?.shadingFill && JSON.stringify(next.shadingThemeFill) === JSON.stringify(base?.shadingThemeFill))
1825
+ return;
1826
+ if (next.shadingFill && next.shadingFill !== "auto" && !/^#?[0-9a-f]{6}$/i.test(next.shadingFill))
1827
+ throw new Error("Cell shading must be a six-digit RGB color or auto.");
1828
+ let props = first2(tc, "tcPr");
1829
+ if (!props) {
1830
+ props = makeW(doc, "tcPr");
1831
+ tc.insertBefore(props, tc.firstChild);
1832
+ }
1833
+ for (const old of children2(props, "shd")) props.removeChild(old);
1834
+ const built = buildCellProperties(doc, next);
1835
+ const replacement = built && first2(built, "shd");
1836
+ if (replacement) props.appendChild(replacement);
1837
+ orderChildren(props, CELL_ORDER);
1838
+ if (!Array.from(props.childNodes).some((node) => node.nodeType === 1)) tc.removeChild(props);
1839
+ }
1791
1840
 
1792
1841
  // src/docx/write-table.ts
1793
1842
  function canEditTableStructure(table) {
@@ -1831,15 +1880,7 @@ var TABLE_DESCRIPTOR_KEYS = [
1831
1880
  "style",
1832
1881
  "look"
1833
1882
  ];
1834
- var CELL_DESCRIPTOR_KEYS = [
1835
- "gridSpan",
1836
- "verticalMerge",
1837
- "widthTwips",
1838
- "verticalAlign",
1839
- "shadingFill",
1840
- "shadingThemeFill",
1841
- "margins"
1842
- ];
1883
+ var CELL_DESCRIPTOR_KEYS = ["gridSpan", "verticalMerge", "widthTwips", "verticalAlign"];
1843
1884
  function pick(source, keys) {
1844
1885
  const record = source;
1845
1886
  const result = {};
@@ -1865,7 +1906,7 @@ function assertNoDescriptorEdits(table, base) {
1865
1906
  if (!source) continue;
1866
1907
  if (JSON.stringify(pick(cell, CELL_DESCRIPTOR_KEYS)) !== JSON.stringify(pick(source, CELL_DESCRIPTOR_KEYS)))
1867
1908
  throw new Error(
1868
- "Cannot edit table cell width, merge, vertical alignment, shading, or margins on an existing cell; only cell text and borders are supported. The original DOCX package remains unchanged."
1909
+ "Cannot edit table cell width, merge or vertical alignment on an existing cell; only cell text, borders, shading and margins are supported. The original DOCX package remains unchanged."
1869
1910
  );
1870
1911
  }
1871
1912
  }
@@ -1934,6 +1975,8 @@ function writeTable(doc, table, node, base, writeParagraph, replaceSlots2) {
1934
1975
  throw new Error("Moving paragraphs between table cells is not supported.");
1935
1976
  const tc = source?.cell ?? makeW(doc, "tc");
1936
1977
  patchCellBorders(doc, tc, cell.borders, source?.model.borders);
1978
+ patchCellShading(doc, tc, cell, source?.model);
1979
+ patchCellMargins(doc, tc, cell.margins, source?.model.margins);
1937
1980
  const oldParagraphs = children2(tc, "p");
1938
1981
  const nextParagraphs = cell.paragraphs.map((paragraph) => {
1939
1982
  const index = source?.paragraphs.findIndex((p) => p.id === paragraph.id) ?? -1;
@@ -1964,13 +2007,13 @@ function writeTable(doc, table, node, base, writeParagraph, replaceSlots2) {
1964
2007
  }
1965
2008
 
1966
2009
  // src/docx/page-borders.ts
1967
- var SIDES2 = ["top", "left", "bottom", "right"];
2010
+ var SIDES3 = ["top", "left", "bottom", "right"];
1968
2011
  var ATTRIBUTES = ["offsetFrom", "display", "zOrder"];
1969
2012
  var setW4 = (element, name, value) => element.setAttributeNS(WORD_NS, `w:${name}`, value);
1970
2013
  function parsePageBorders(element) {
1971
2014
  if (!element) return void 0;
1972
2015
  const result = {};
1973
- for (const side of SIDES2) {
2016
+ for (const side of SIDES3) {
1974
2017
  const source = first2(element, side);
1975
2018
  const value = borderSide(source);
1976
2019
  const art = getW(source, "art");
@@ -2008,7 +2051,7 @@ function patchPageBorders(doc, sectPr, next, base, create) {
2008
2051
  return;
2009
2052
  }
2010
2053
  const element = create(doc, sectPr, "pgBorders");
2011
- for (const side of SIDES2) {
2054
+ for (const side of SIDES3) {
2012
2055
  if (JSON.stringify(next[side]) === JSON.stringify(base?.[side])) continue;
2013
2056
  for (const old of children2(element, side)) element.removeChild(old);
2014
2057
  const value = next[side];
@@ -2333,7 +2376,7 @@ function applySectionEdits(doc, body, blocks, sections, base, references = /* @_
2333
2376
  }
2334
2377
 
2335
2378
  // src/docx/write-paragraph-decoration.ts
2336
- var SIDES3 = ["top", "left", "bottom", "right", "between"];
2379
+ var SIDES4 = ["top", "left", "bottom", "right", "between"];
2337
2380
  function wordColor(color) {
2338
2381
  const hex = /^#?([0-9a-f]{6})$/i.exec(color ?? "")?.[1];
2339
2382
  return hex ? hex.toUpperCase() : "auto";
@@ -2367,7 +2410,7 @@ function updateBorders(doc, props, paragraph, base) {
2367
2410
  const borders = paragraph.borders;
2368
2411
  if (!borders) return;
2369
2412
  const pBdr = makeW(doc, "pBdr");
2370
- for (const side of SIDES3) {
2413
+ for (const side of SIDES4) {
2371
2414
  const value = borders[side];
2372
2415
  if (value) pBdr.appendChild(borderElement(doc, side, value));
2373
2416
  }
@@ -4654,6 +4697,30 @@ function createRun(doc, run, base, old, allocator) {
4654
4697
  if (!run.text) node.appendChild(makeW(doc, "t"));
4655
4698
  return node;
4656
4699
  }
4700
+ var MATH_NAMESPACES = /* @__PURE__ */ new Set([
4701
+ "http://schemas.openxmlformats.org/officeDocument/2006/math",
4702
+ "http://purl.oclc.org/ooxml/officeDocument/math"
4703
+ ]);
4704
+ function isEquationElement(element) {
4705
+ return MATH_NAMESPACES.has(element.namespaceURI ?? "") && (element.localName === "oMath" || element.localName === "oMathPara");
4706
+ }
4707
+ function parseEquation(element) {
4708
+ if (!isEquationElement(element)) return void 0;
4709
+ return {
4710
+ text: "",
4711
+ equation: {
4712
+ omml: new xmldom.XMLSerializer().serializeToString(element),
4713
+ display: element.localName === "oMathPara"
4714
+ }
4715
+ };
4716
+ }
4717
+ function preserveEquation(run, base, old) {
4718
+ if (!old || !isEquationElement(old) || !base?.equation || run.text !== "" || run.equation?.omml !== base.equation.omml || run.equation?.display !== base.equation.display)
4719
+ throw new Error(
4720
+ "Equation editing or insertion is unsupported; imported OMML must remain unchanged."
4721
+ );
4722
+ return old.cloneNode(true);
4723
+ }
4657
4724
 
4658
4725
  // src/docx/breaks.ts
4659
4726
  function hasSpecialBreak(element) {
@@ -4752,10 +4819,11 @@ function collectParagraphRuns(node, parseRun3, parseOther, resolveLink, active =
4752
4819
  if (!isCommentReferenceRun(item)) push(parseRun3(item));
4753
4820
  } else if (named2(item, "hyperlink")) {
4754
4821
  const link = resolveLink?.(item);
4755
- for (const run of children2(item, "r")) {
4756
- const parsed = parseRun3(run);
4757
- if (link) parsed.link = link;
4758
- push(parsed);
4822
+ for (const child3 of Array.from(item.childNodes).filter(isElement)) {
4823
+ for (const parsed of named2(child3, "r") ? [parseRun3(child3)] : parseOther?.(child3) ?? []) {
4824
+ if (link) parsed.link = link;
4825
+ push(parsed);
4826
+ }
4759
4827
  }
4760
4828
  } else if ((!item.namespaceURI || item.namespaceURI === WORD_NS) && Object.hasOwn(REVISION_WRAPPERS, item.localName)) {
4761
4829
  const kind = expectDefined(
@@ -4766,7 +4834,12 @@ function collectParagraphRuns(node, parseRun3, parseOther, resolveLink, active =
4766
4834
  const revision = revisionFrom(item, kind);
4767
4835
  const range = kind === "moveFrom" || kind === "moveTo" ? moves[kind].at(-1) : void 0;
4768
4836
  if (range) revision.move = { name: range.name, rangeId: range.id };
4769
- for (const run of children2(item, "r")) push(parseRun3(run, revision));
4837
+ for (const child3 of Array.from(item.childNodes).filter(isElement)) {
4838
+ for (const parsed of named2(child3, "r") ? [parseRun3(child3, revision)] : parseOther?.(child3) ?? []) {
4839
+ parsed.revision = revision;
4840
+ push(parsed);
4841
+ }
4842
+ }
4770
4843
  } else if (trackMoveRange(item, moves)) {
4771
4844
  continue;
4772
4845
  } else if (named2(item, "commentRangeStart")) {
@@ -4813,7 +4886,9 @@ function runsOf(parent, container, slots) {
4813
4886
  if (child3.nodeType === 3 && child3.textContent?.trim()) return false;
4814
4887
  continue;
4815
4888
  }
4816
- if (named2(child3, "r")) {
4889
+ if (isEquationElement(child3)) {
4890
+ slots.push({ element: child3, ...container && { container } });
4891
+ } else if (named2(child3, "r")) {
4817
4892
  if (isCommentReferenceRun(child3)) continue;
4818
4893
  if (!runIsSafe(child3)) return false;
4819
4894
  slots.push({ element: child3, ...container && { container } });
@@ -4837,7 +4912,9 @@ function collectInlineSlots(paragraph) {
4837
4912
  if (child3.nodeType === 3 && child3.textContent?.trim()) return void 0;
4838
4913
  continue;
4839
4914
  }
4840
- if (named2(child3, "r")) {
4915
+ if (isEquationElement(child3)) {
4916
+ slots.push({ element: child3 });
4917
+ } else if (named2(child3, "r")) {
4841
4918
  if (isCommentReferenceRun(child3)) continue;
4842
4919
  if (!runIsSafe(child3)) return void 0;
4843
4920
  slots.push({ element: child3 });
@@ -4853,7 +4930,7 @@ function collectInlineSlots(paragraph) {
4853
4930
  }
4854
4931
  function replaceableInlineChildren(paragraph) {
4855
4932
  return Array.from(paragraph.childNodes).filter(
4856
- (child3) => isElement(child3) && (named2(child3, "r") || named2(child3, "hyperlink") || named2(child3, "fldSimple") || isRevisionWrapperElement(child3) || isCommentAnchorElement(child3))
4933
+ (child3) => isElement(child3) && (isEquationElement(child3) || named2(child3, "r") || named2(child3, "hyperlink") || named2(child3, "fldSimple") || isRevisionWrapperElement(child3) || isCommentAnchorElement(child3))
4857
4934
  );
4858
4935
  }
4859
4936
  function sameLink(a, b) {
@@ -4878,7 +4955,7 @@ function newHyperlink(doc, link, allocator) {
4878
4955
  }
4879
4956
  function runNodes(doc, run, base, old, opens, closes, allocator) {
4880
4957
  const nodes = opens.flatMap((edge) => rangeStartNodes(doc, edge));
4881
- const node = createRun(doc, run, base, old, allocator);
4958
+ const node = run.equation ? preserveEquation(run, base, old) : createRun(doc, run, base, old, allocator);
4882
4959
  const revision = run.revision;
4883
4960
  if (revision && ["insert", "delete", "moveFrom", "moveTo"].includes(revision.kind)) {
4884
4961
  if (revision.kind === "delete" || revision.kind === "moveFrom") convertToDeleteText(doc, node);
@@ -4890,15 +4967,23 @@ function runNodes(doc, run, base, old, opens, closes, allocator) {
4890
4967
  function buildInlineContent(doc, runs, base, slots, allocator, ranges) {
4891
4968
  const { opens, closes } = rangeEdges(runs, ranges);
4892
4969
  const runAt = (at) => expectDefined(runs[at], `run ${at}`);
4893
- const nodesFor = (index2) => runNodes(
4894
- doc,
4895
- runAt(index2),
4896
- base?.[index2],
4897
- slots[index2]?.element,
4898
- opens.get(index2) ?? [],
4899
- closes.get(index2) ?? [],
4900
- allocator
4901
- );
4970
+ const nodesFor = (index2) => {
4971
+ const run = runAt(index2);
4972
+ const sourceIndex = run.equation ? base?.findIndex(
4973
+ (source2) => source2.equation?.omml === run.equation?.omml && source2.equation?.display === run.equation?.display
4974
+ ) : index2;
4975
+ const source = sourceIndex === void 0 ? void 0 : base?.[sourceIndex];
4976
+ const old = sourceIndex === void 0 ? void 0 : slots[sourceIndex]?.element;
4977
+ return runNodes(
4978
+ doc,
4979
+ run,
4980
+ !run.equation && source?.equation ? void 0 : source,
4981
+ !run.equation && old && isEquationElement(old) ? void 0 : old,
4982
+ opens.get(index2) ?? [],
4983
+ closes.get(index2) ?? [],
4984
+ allocator
4985
+ );
4986
+ };
4902
4987
  const output = [];
4903
4988
  let index = 0;
4904
4989
  while (index < runs.length) {
@@ -6553,14 +6638,14 @@ function parseCell(cell, parseParagraph3, id) {
6553
6638
  const vMerge = first2(props, "vMerge");
6554
6639
  if (vMerge) result.verticalMerge = getW(vMerge, "val") === "restart" ? "restart" : "continue";
6555
6640
  const tcW = first2(props, "tcW");
6556
- if (getW(tcW, "type") !== "nil") {
6641
+ if ((getW(tcW, "type") ?? "dxa") === "dxa") {
6557
6642
  const width = dxa(getW(tcW, "w"));
6558
6643
  if (width !== void 0) result.widthTwips = width;
6559
6644
  }
6560
6645
  const vAlign = enumValue(isStVerticalJc, getW(first2(props, "vAlign"), "val"), "w:tcPr/w:vAlign");
6561
6646
  if (vAlign) result.verticalAlign = vAlign;
6562
6647
  const shd = first2(props, "shd");
6563
- const fill = parseShadingFill(shd);
6648
+ const fill = parseShadingFill(shd) ?? (getW(shd, "fill") === "auto" && !getW(shd, "themeFill") ? "auto" : void 0);
6564
6649
  if (fill) result.shadingFill = fill;
6565
6650
  const themeFill = parseShadingThemeFill(shd);
6566
6651
  if (themeFill) result.shadingThemeFill = themeFill;
@@ -6599,7 +6684,9 @@ function parseMargins(element) {
6599
6684
  ["left", "start"],
6600
6685
  ["right", "end"]
6601
6686
  ]) {
6602
- const value = dxa(getW(first2(element, side) ?? first2(element, logical), "w"));
6687
+ const edge = first2(element, logical) ?? first2(element, side);
6688
+ const type = getW(edge, "type") ?? "dxa";
6689
+ const value = type === "nil" ? parseSignedTwips("0") : type === "dxa" ? parseSignedTwips(getW(edge, "w")) : void 0;
6603
6690
  if (value !== void 0) parsed[side] = value;
6604
6691
  }
6605
6692
  return Object.keys(parsed).length ? parsed : void 0;
@@ -6629,7 +6716,8 @@ function parseTable(node, id, parseParagraph3) {
6629
6716
  }) : [];
6630
6717
  if (grid.length) table.grid = grid;
6631
6718
  const tblPr = first2(node, "tblPr");
6632
- const width = dxa(getW(first2(tblPr, "tblW"), "w"));
6719
+ const tableWidth = first2(tblPr, "tblW");
6720
+ const width = (getW(tableWidth, "type") ?? "dxa") === "dxa" ? dxa(getW(tableWidth, "w")) : void 0;
6633
6721
  if (width !== void 0) table.widthTwips = width;
6634
6722
  const justification = enumValue(isStJcTable, getW(first2(tblPr, "jc"), "val"), "w:tblPr/w:jc");
6635
6723
  if (justification) {
@@ -6803,13 +6891,19 @@ function parseParagraph2(node, id) {
6803
6891
  node,
6804
6892
  (element, revision) => trackField(element, parseRun2(element, revision)),
6805
6893
  (item) => {
6894
+ const equation = parseEquation(item);
6895
+ if (equation) return [equation];
6806
6896
  if (!named2(item, "fldSimple")) return void 0;
6807
6897
  const instr = getW(item, "instr") ?? "";
6808
6898
  const link = parseSimpleHyperlinkField(instr);
6809
- const results = children2(item, "r").map((run) => parseRun2(run));
6899
+ const results = Array.from(item.childNodes).filter(isElement).flatMap((child3) => {
6900
+ const equation2 = parseEquation(child3);
6901
+ return equation2 ? [equation2] : named2(child3, "r") ? [parseRun2(child3)] : [];
6902
+ });
6810
6903
  if (link) return results.map((run) => ({ ...run, link }));
6811
6904
  const field = { instr: instr.trim(), simple: true };
6812
- if (!results.some((run) => run.text)) return [{ text: fieldPlaceholderText(instr), field }];
6905
+ if (!results.some((run) => run.text || run.equation))
6906
+ return [{ text: fieldPlaceholderText(instr), field }];
6813
6907
  return results.map((run) => ({ ...run, field }));
6814
6908
  },
6815
6909
  (hyperlink) => {