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
@@ -905,6 +905,46 @@ function orderSectionProperties(sectPr) {
905
905
  orderChildren(sectPr, SECTPR_ORDER);
906
906
  }
907
907
 
908
+ // src/docx/write-table-margins.ts
909
+ var SIDES = ["top", "left", "bottom", "right"];
910
+ var ORDER = ["top", "start", "left", "bottom", "end", "right"];
911
+ function patchMarginProperties(doc, host, propertiesTag, marginTag, propertiesOrder, next, base) {
912
+ const changed = SIDES.filter((side) => next?.[side] !== base?.[side]);
913
+ if (!changed.length) return;
914
+ for (const side of changed) {
915
+ const value = next?.[side];
916
+ if (value !== void 0 && (!Number.isSafeInteger(value) || value < 0))
917
+ throw new Error("Table cell margins must be nonnegative whole twips.");
918
+ }
919
+ let properties = first2(host, propertiesTag);
920
+ if (!properties) {
921
+ properties = makeW(doc, propertiesTag);
922
+ host.insertBefore(properties, host.firstChild);
923
+ }
924
+ let margins = first2(properties, marginTag);
925
+ if (!margins) {
926
+ margins = makeW(doc, marginTag);
927
+ properties.appendChild(margins);
928
+ }
929
+ for (const side of changed) {
930
+ const logical = side === "left" ? "start" : side === "right" ? "end" : side;
931
+ const edge = first2(margins, logical) ?? first2(margins, side) ?? makeW(doc, side);
932
+ for (const alias of /* @__PURE__ */ new Set([side, logical]))
933
+ for (const old of children2(margins, alias)) margins.removeChild(old);
934
+ const value = next?.[side];
935
+ if (value === void 0) continue;
936
+ edge.setAttributeNS(WORD_NS, "w:w", String(value));
937
+ edge.setAttributeNS(WORD_NS, "w:type", "dxa");
938
+ margins.appendChild(edge);
939
+ }
940
+ if (!Array.from(margins.childNodes).some((node) => node.nodeType === 1) && !margins.attributes.length)
941
+ properties.removeChild(margins);
942
+ else orderChildren(margins, ORDER);
943
+ orderChildren(properties, propertiesOrder);
944
+ if (!Array.from(properties.childNodes).some((node) => node.nodeType === 1) && !properties.attributes.length)
945
+ host.removeChild(properties);
946
+ }
947
+
908
948
  // src/docx/write-table-properties.ts
909
949
  var ROW_ORDER = [
910
950
  "cnfStyle",
@@ -964,26 +1004,15 @@ function patchRowProperties(doc, tr, next, base) {
964
1004
  orderChildren(props, ROW_ORDER);
965
1005
  }
966
1006
  function patchTableMargins(doc, table, node, base) {
967
- if (JSON.stringify(table.cellMargins ?? {}) === JSON.stringify(base?.cellMargins ?? {})) return;
968
- let props = first2(node, "tblPr");
969
- if (!props) {
970
- props = makeW(doc, "tblPr");
971
- node.insertBefore(props, node.firstChild);
972
- }
973
- let margins = first2(props, "tblCellMar");
974
- if (!margins) {
975
- margins = makeW(doc, "tblCellMar");
976
- props.appendChild(margins);
977
- }
978
- const built = buildMargins(doc, table.cellMargins ?? {}, "tblCellMar");
979
- for (const side of ["top", "left", "bottom", "right"]) {
980
- if (table.cellMargins?.[side] === base?.cellMargins?.[side]) continue;
981
- for (const old of children2(margins, side)) margins.removeChild(old);
982
- const replacement = first2(built, side);
983
- if (replacement) margins.appendChild(replacement);
984
- }
985
- orderChildren(margins, ["top", "left", "start", "bottom", "right", "end"]);
986
- orderChildren(props, TABLE_ORDER);
1007
+ patchMarginProperties(
1008
+ doc,
1009
+ node,
1010
+ "tblPr",
1011
+ "tblCellMar",
1012
+ TABLE_ORDER,
1013
+ table.cellMargins,
1014
+ base?.cellMargins
1015
+ );
987
1016
  }
988
1017
  var CELL_ORDER = [
989
1018
  "cnfStyle",
@@ -1007,6 +1036,9 @@ var CELL_ORDER = [
1007
1036
  ];
1008
1037
  var CELL_BORDER_ORDER = ["top", "start", "left", "bottom", "end", "right", "insideH", "insideV"];
1009
1038
  var CELL_SIDES = ["top", "left", "bottom", "right"];
1039
+ function patchCellMargins(doc, tc, next, base) {
1040
+ patchMarginProperties(doc, tc, "tcPr", "tcMar", CELL_ORDER, next, base);
1041
+ }
1010
1042
  function patchCellBorders(doc, tc, next, base) {
1011
1043
  const changed = CELL_SIDES.filter(
1012
1044
  (side) => JSON.stringify(next?.[side]) !== JSON.stringify(base?.[side])
@@ -1034,6 +1066,23 @@ function patchCellBorders(doc, tc, next, base) {
1034
1066
  orderChildren(props, CELL_ORDER);
1035
1067
  if (!Array.from(props.childNodes).some((node) => node.nodeType === 1)) tc.removeChild(props);
1036
1068
  }
1069
+ function patchCellShading(doc, tc, next, base) {
1070
+ if (next.shadingFill === base?.shadingFill && JSON.stringify(next.shadingThemeFill) === JSON.stringify(base?.shadingThemeFill))
1071
+ return;
1072
+ if (next.shadingFill && next.shadingFill !== "auto" && !/^#?[0-9a-f]{6}$/i.test(next.shadingFill))
1073
+ throw new Error("Cell shading must be a six-digit RGB color or auto.");
1074
+ let props = first2(tc, "tcPr");
1075
+ if (!props) {
1076
+ props = makeW(doc, "tcPr");
1077
+ tc.insertBefore(props, tc.firstChild);
1078
+ }
1079
+ for (const old of children2(props, "shd")) props.removeChild(old);
1080
+ const built = buildCellProperties(doc, next);
1081
+ const replacement = built && first2(built, "shd");
1082
+ if (replacement) props.appendChild(replacement);
1083
+ orderChildren(props, CELL_ORDER);
1084
+ if (!Array.from(props.childNodes).some((node) => node.nodeType === 1)) tc.removeChild(props);
1085
+ }
1037
1086
 
1038
1087
  // src/docx/write-table.ts
1039
1088
  function canEditTableStructure(table) {
@@ -1077,15 +1126,7 @@ var TABLE_DESCRIPTOR_KEYS = [
1077
1126
  "style",
1078
1127
  "look"
1079
1128
  ];
1080
- var CELL_DESCRIPTOR_KEYS = [
1081
- "gridSpan",
1082
- "verticalMerge",
1083
- "widthTwips",
1084
- "verticalAlign",
1085
- "shadingFill",
1086
- "shadingThemeFill",
1087
- "margins"
1088
- ];
1129
+ var CELL_DESCRIPTOR_KEYS = ["gridSpan", "verticalMerge", "widthTwips", "verticalAlign"];
1089
1130
  function pick(source, keys) {
1090
1131
  const record = source;
1091
1132
  const result = {};
@@ -1111,7 +1152,7 @@ function assertNoDescriptorEdits(table, base) {
1111
1152
  if (!source) continue;
1112
1153
  if (JSON.stringify(pick(cell, CELL_DESCRIPTOR_KEYS)) !== JSON.stringify(pick(source, CELL_DESCRIPTOR_KEYS)))
1113
1154
  throw new Error(
1114
- "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."
1155
+ "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."
1115
1156
  );
1116
1157
  }
1117
1158
  }
@@ -1180,6 +1221,8 @@ function writeTable(doc, table, node, base, writeParagraph, replaceSlots2) {
1180
1221
  throw new Error("Moving paragraphs between table cells is not supported.");
1181
1222
  const tc = source?.cell ?? makeW(doc, "tc");
1182
1223
  patchCellBorders(doc, tc, cell.borders, source?.model.borders);
1224
+ patchCellShading(doc, tc, cell, source?.model);
1225
+ patchCellMargins(doc, tc, cell.margins, source?.model.margins);
1183
1226
  const oldParagraphs = children2(tc, "p");
1184
1227
  const nextParagraphs = cell.paragraphs.map((paragraph) => {
1185
1228
  const index = source?.paragraphs.findIndex((p) => p.id === paragraph.id) ?? -1;
@@ -1322,7 +1365,7 @@ function parseTintShade(value) {
1322
1365
  }
1323
1366
 
1324
1367
  // src/docx/table-borders.ts
1325
- var SIDES = [
1368
+ var SIDES2 = [
1326
1369
  "top",
1327
1370
  "bottom",
1328
1371
  "left",
@@ -1348,7 +1391,7 @@ function parseTableBorders(bordersElement) {
1348
1391
  if (!bordersElement) return void 0;
1349
1392
  const result = {};
1350
1393
  const alias = { left: "start", right: "end" };
1351
- for (const side of SIDES) {
1394
+ for (const side of SIDES2) {
1352
1395
  const aliasName = alias[side];
1353
1396
  const value = borderSide(
1354
1397
  first2(bordersElement, side) ?? (aliasName ? first2(bordersElement, aliasName) : void 0)
@@ -1385,13 +1428,13 @@ function parseParagraphBorders(pBdr) {
1385
1428
  }
1386
1429
 
1387
1430
  // src/docx/page-borders.ts
1388
- var SIDES2 = ["top", "left", "bottom", "right"];
1431
+ var SIDES3 = ["top", "left", "bottom", "right"];
1389
1432
  var ATTRIBUTES = ["offsetFrom", "display", "zOrder"];
1390
1433
  var setW4 = (element, name, value) => element.setAttributeNS(WORD_NS, `w:${name}`, value);
1391
1434
  function parsePageBorders(element) {
1392
1435
  if (!element) return void 0;
1393
1436
  const result = {};
1394
- for (const side of SIDES2) {
1437
+ for (const side of SIDES3) {
1395
1438
  const source = first2(element, side);
1396
1439
  const value = borderSide(source);
1397
1440
  const art = getW(source, "art");
@@ -1429,7 +1472,7 @@ function patchPageBorders(doc, sectPr, next, base, create) {
1429
1472
  return;
1430
1473
  }
1431
1474
  const element = create(doc, sectPr, "pgBorders");
1432
- for (const side of SIDES2) {
1475
+ for (const side of SIDES3) {
1433
1476
  if (JSON.stringify(next[side]) === JSON.stringify(base?.[side])) continue;
1434
1477
  for (const old of children2(element, side)) element.removeChild(old);
1435
1478
  const value = next[side];
@@ -1754,7 +1797,7 @@ function applySectionEdits(doc, body, blocks, sections, base, references = /* @_
1754
1797
  }
1755
1798
 
1756
1799
  // src/docx/write-paragraph-decoration.ts
1757
- var SIDES3 = ["top", "left", "bottom", "right", "between"];
1800
+ var SIDES4 = ["top", "left", "bottom", "right", "between"];
1758
1801
  function wordColor(color) {
1759
1802
  const hex = /^#?([0-9a-f]{6})$/i.exec(color ?? "")?.[1];
1760
1803
  return hex ? hex.toUpperCase() : "auto";
@@ -1788,7 +1831,7 @@ function updateBorders(doc, props, paragraph, base) {
1788
1831
  const borders = paragraph.borders;
1789
1832
  if (!borders) return;
1790
1833
  const pBdr = makeW(doc, "pBdr");
1791
- for (const side of SIDES3) {
1834
+ for (const side of SIDES4) {
1792
1835
  const value = borders[side];
1793
1836
  if (value) pBdr.appendChild(borderElement(doc, side, value));
1794
1837
  }
@@ -4219,6 +4262,30 @@ function createRun(doc, run, base, old, allocator) {
4219
4262
  if (!run.text) node.appendChild(makeW(doc, "t"));
4220
4263
  return node;
4221
4264
  }
4265
+ var MATH_NAMESPACES = /* @__PURE__ */ new Set([
4266
+ "http://schemas.openxmlformats.org/officeDocument/2006/math",
4267
+ "http://purl.oclc.org/ooxml/officeDocument/math"
4268
+ ]);
4269
+ function isEquationElement(element) {
4270
+ return MATH_NAMESPACES.has(element.namespaceURI ?? "") && (element.localName === "oMath" || element.localName === "oMathPara");
4271
+ }
4272
+ function parseEquation(element) {
4273
+ if (!isEquationElement(element)) return void 0;
4274
+ return {
4275
+ text: "",
4276
+ equation: {
4277
+ omml: new xmldom.XMLSerializer().serializeToString(element),
4278
+ display: element.localName === "oMathPara"
4279
+ }
4280
+ };
4281
+ }
4282
+ function preserveEquation(run, base, old) {
4283
+ if (!old || !isEquationElement(old) || !base?.equation || run.text !== "" || run.equation?.omml !== base.equation.omml || run.equation?.display !== base.equation.display)
4284
+ throw new Error(
4285
+ "Equation editing or insertion is unsupported; imported OMML must remain unchanged."
4286
+ );
4287
+ return old.cloneNode(true);
4288
+ }
4222
4289
 
4223
4290
  // src/docx/breaks.ts
4224
4291
  function hasSpecialBreak(element) {
@@ -4317,10 +4384,11 @@ function collectParagraphRuns(node, parseRun3, parseOther, resolveLink, active =
4317
4384
  if (!isCommentReferenceRun(item)) push(parseRun3(item));
4318
4385
  } else if (named2(item, "hyperlink")) {
4319
4386
  const link = resolveLink?.(item);
4320
- for (const run of children2(item, "r")) {
4321
- const parsed = parseRun3(run);
4322
- if (link) parsed.link = link;
4323
- push(parsed);
4387
+ for (const child3 of Array.from(item.childNodes).filter(isElement)) {
4388
+ for (const parsed of named2(child3, "r") ? [parseRun3(child3)] : parseOther?.(child3) ?? []) {
4389
+ if (link) parsed.link = link;
4390
+ push(parsed);
4391
+ }
4324
4392
  }
4325
4393
  } else if ((!item.namespaceURI || item.namespaceURI === WORD_NS) && Object.hasOwn(REVISION_WRAPPERS, item.localName)) {
4326
4394
  const kind = expectDefined(
@@ -4331,7 +4399,12 @@ function collectParagraphRuns(node, parseRun3, parseOther, resolveLink, active =
4331
4399
  const revision = revisionFrom(item, kind);
4332
4400
  const range = kind === "moveFrom" || kind === "moveTo" ? moves[kind].at(-1) : void 0;
4333
4401
  if (range) revision.move = { name: range.name, rangeId: range.id };
4334
- for (const run of children2(item, "r")) push(parseRun3(run, revision));
4402
+ for (const child3 of Array.from(item.childNodes).filter(isElement)) {
4403
+ for (const parsed of named2(child3, "r") ? [parseRun3(child3, revision)] : parseOther?.(child3) ?? []) {
4404
+ parsed.revision = revision;
4405
+ push(parsed);
4406
+ }
4407
+ }
4335
4408
  } else if (trackMoveRange(item, moves)) {
4336
4409
  continue;
4337
4410
  } else if (named2(item, "commentRangeStart")) {
@@ -4378,7 +4451,9 @@ function runsOf(parent, container, slots) {
4378
4451
  if (child3.nodeType === 3 && child3.textContent?.trim()) return false;
4379
4452
  continue;
4380
4453
  }
4381
- if (named2(child3, "r")) {
4454
+ if (isEquationElement(child3)) {
4455
+ slots.push({ element: child3, ...container && { container } });
4456
+ } else if (named2(child3, "r")) {
4382
4457
  if (isCommentReferenceRun(child3)) continue;
4383
4458
  if (!runIsSafe(child3)) return false;
4384
4459
  slots.push({ element: child3, ...container && { container } });
@@ -4402,7 +4477,9 @@ function collectInlineSlots(paragraph) {
4402
4477
  if (child3.nodeType === 3 && child3.textContent?.trim()) return void 0;
4403
4478
  continue;
4404
4479
  }
4405
- if (named2(child3, "r")) {
4480
+ if (isEquationElement(child3)) {
4481
+ slots.push({ element: child3 });
4482
+ } else if (named2(child3, "r")) {
4406
4483
  if (isCommentReferenceRun(child3)) continue;
4407
4484
  if (!runIsSafe(child3)) return void 0;
4408
4485
  slots.push({ element: child3 });
@@ -4418,7 +4495,7 @@ function collectInlineSlots(paragraph) {
4418
4495
  }
4419
4496
  function replaceableInlineChildren(paragraph) {
4420
4497
  return Array.from(paragraph.childNodes).filter(
4421
- (child3) => isElement(child3) && (named2(child3, "r") || named2(child3, "hyperlink") || named2(child3, "fldSimple") || isRevisionWrapperElement(child3) || isCommentAnchorElement(child3))
4498
+ (child3) => isElement(child3) && (isEquationElement(child3) || named2(child3, "r") || named2(child3, "hyperlink") || named2(child3, "fldSimple") || isRevisionWrapperElement(child3) || isCommentAnchorElement(child3))
4422
4499
  );
4423
4500
  }
4424
4501
  function sameLink(a, b) {
@@ -4443,7 +4520,7 @@ function newHyperlink(doc, link, allocator) {
4443
4520
  }
4444
4521
  function runNodes(doc, run, base, old, opens, closes, allocator) {
4445
4522
  const nodes = opens.flatMap((edge) => rangeStartNodes(doc, edge));
4446
- const node = createRun(doc, run, base, old, allocator);
4523
+ const node = run.equation ? preserveEquation(run, base, old) : createRun(doc, run, base, old, allocator);
4447
4524
  const revision = run.revision;
4448
4525
  if (revision && ["insert", "delete", "moveFrom", "moveTo"].includes(revision.kind)) {
4449
4526
  if (revision.kind === "delete" || revision.kind === "moveFrom") convertToDeleteText(doc, node);
@@ -4455,15 +4532,23 @@ function runNodes(doc, run, base, old, opens, closes, allocator) {
4455
4532
  function buildInlineContent(doc, runs, base, slots, allocator, ranges) {
4456
4533
  const { opens, closes } = rangeEdges(runs, ranges);
4457
4534
  const runAt = (at) => expectDefined(runs[at], `run ${at}`);
4458
- const nodesFor = (index2) => runNodes(
4459
- doc,
4460
- runAt(index2),
4461
- base?.[index2],
4462
- slots[index2]?.element,
4463
- opens.get(index2) ?? [],
4464
- closes.get(index2) ?? [],
4465
- allocator
4466
- );
4535
+ const nodesFor = (index2) => {
4536
+ const run = runAt(index2);
4537
+ const sourceIndex = run.equation ? base?.findIndex(
4538
+ (source2) => source2.equation?.omml === run.equation?.omml && source2.equation?.display === run.equation?.display
4539
+ ) : index2;
4540
+ const source = sourceIndex === void 0 ? void 0 : base?.[sourceIndex];
4541
+ const old = sourceIndex === void 0 ? void 0 : slots[sourceIndex]?.element;
4542
+ return runNodes(
4543
+ doc,
4544
+ run,
4545
+ !run.equation && source?.equation ? void 0 : source,
4546
+ !run.equation && old && isEquationElement(old) ? void 0 : old,
4547
+ opens.get(index2) ?? [],
4548
+ closes.get(index2) ?? [],
4549
+ allocator
4550
+ );
4551
+ };
4467
4552
  const output = [];
4468
4553
  let index = 0;
4469
4554
  while (index < runs.length) {
@@ -6464,14 +6549,14 @@ function parseCell(cell, parseParagraph3, id) {
6464
6549
  const vMerge = first2(props, "vMerge");
6465
6550
  if (vMerge) result.verticalMerge = getW(vMerge, "val") === "restart" ? "restart" : "continue";
6466
6551
  const tcW = first2(props, "tcW");
6467
- if (getW(tcW, "type") !== "nil") {
6552
+ if ((getW(tcW, "type") ?? "dxa") === "dxa") {
6468
6553
  const width = dxa(getW(tcW, "w"));
6469
6554
  if (width !== void 0) result.widthTwips = width;
6470
6555
  }
6471
6556
  const vAlign = enumValue(isStVerticalJc, getW(first2(props, "vAlign"), "val"), "w:tcPr/w:vAlign");
6472
6557
  if (vAlign) result.verticalAlign = vAlign;
6473
6558
  const shd = first2(props, "shd");
6474
- const fill = parseShadingFill(shd);
6559
+ const fill = parseShadingFill(shd) ?? (getW(shd, "fill") === "auto" && !getW(shd, "themeFill") ? "auto" : void 0);
6475
6560
  if (fill) result.shadingFill = fill;
6476
6561
  const themeFill = parseShadingThemeFill(shd);
6477
6562
  if (themeFill) result.shadingThemeFill = themeFill;
@@ -6510,7 +6595,9 @@ function parseMargins(element) {
6510
6595
  ["left", "start"],
6511
6596
  ["right", "end"]
6512
6597
  ]) {
6513
- const value = dxa(getW(first2(element, side) ?? first2(element, logical), "w"));
6598
+ const edge = first2(element, logical) ?? first2(element, side);
6599
+ const type = getW(edge, "type") ?? "dxa";
6600
+ const value = type === "nil" ? parseSignedTwips("0") : type === "dxa" ? parseSignedTwips(getW(edge, "w")) : void 0;
6514
6601
  if (value !== void 0) parsed[side] = value;
6515
6602
  }
6516
6603
  return Object.keys(parsed).length ? parsed : void 0;
@@ -6540,7 +6627,8 @@ function parseTable(node, id, parseParagraph3) {
6540
6627
  }) : [];
6541
6628
  if (grid.length) table.grid = grid;
6542
6629
  const tblPr = first2(node, "tblPr");
6543
- const width = dxa(getW(first2(tblPr, "tblW"), "w"));
6630
+ const tableWidth = first2(tblPr, "tblW");
6631
+ const width = (getW(tableWidth, "type") ?? "dxa") === "dxa" ? dxa(getW(tableWidth, "w")) : void 0;
6544
6632
  if (width !== void 0) table.widthTwips = width;
6545
6633
  const justification = enumValue(isStJcTable, getW(first2(tblPr, "jc"), "val"), "w:tblPr/w:jc");
6546
6634
  if (justification) {
@@ -6714,13 +6802,19 @@ function parseParagraph2(node, id) {
6714
6802
  node,
6715
6803
  (element, revision) => trackField(element, parseRun2(element, revision)),
6716
6804
  (item) => {
6805
+ const equation = parseEquation(item);
6806
+ if (equation) return [equation];
6717
6807
  if (!named2(item, "fldSimple")) return void 0;
6718
6808
  const instr = getW(item, "instr") ?? "";
6719
6809
  const link = parseSimpleHyperlinkField(instr);
6720
- const results = children2(item, "r").map((run) => parseRun2(run));
6810
+ const results = Array.from(item.childNodes).filter(isElement).flatMap((child3) => {
6811
+ const equation2 = parseEquation(child3);
6812
+ return equation2 ? [equation2] : named2(child3, "r") ? [parseRun2(child3)] : [];
6813
+ });
6721
6814
  if (link) return results.map((run) => ({ ...run, link }));
6722
6815
  const field = { instr: instr.trim(), simple: true };
6723
- if (!results.some((run) => run.text)) return [{ text: fieldPlaceholderText(instr), field }];
6816
+ if (!results.some((run) => run.text || run.equation))
6817
+ return [{ text: fieldPlaceholderText(instr), field }];
6724
6818
  return results.map((run) => ({ ...run, field }));
6725
6819
  },
6726
6820
  (hyperlink) => {