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
@@ -2298,6 +2298,46 @@ function orderSectionProperties(sectPr) {
2298
2298
  orderChildren(sectPr, SECTPR_ORDER);
2299
2299
  }
2300
2300
 
2301
+ // src/docx/write-table-margins.ts
2302
+ var SIDES2 = ["top", "left", "bottom", "right"];
2303
+ var ORDER = ["top", "start", "left", "bottom", "end", "right"];
2304
+ function patchMarginProperties(doc, host, propertiesTag, marginTag, propertiesOrder, next, base) {
2305
+ const changed = SIDES2.filter((side) => next?.[side] !== base?.[side]);
2306
+ if (!changed.length) return;
2307
+ for (const side of changed) {
2308
+ const value = next?.[side];
2309
+ if (value !== void 0 && (!Number.isSafeInteger(value) || value < 0))
2310
+ throw new Error("Table cell margins must be nonnegative whole twips.");
2311
+ }
2312
+ let properties = first2(host, propertiesTag);
2313
+ if (!properties) {
2314
+ properties = makeW(doc, propertiesTag);
2315
+ host.insertBefore(properties, host.firstChild);
2316
+ }
2317
+ let margins = first2(properties, marginTag);
2318
+ if (!margins) {
2319
+ margins = makeW(doc, marginTag);
2320
+ properties.appendChild(margins);
2321
+ }
2322
+ for (const side of changed) {
2323
+ const logical = side === "left" ? "start" : side === "right" ? "end" : side;
2324
+ const edge = first2(margins, logical) ?? first2(margins, side) ?? makeW(doc, side);
2325
+ for (const alias of /* @__PURE__ */ new Set([side, logical]))
2326
+ for (const old of children2(margins, alias)) margins.removeChild(old);
2327
+ const value = next?.[side];
2328
+ if (value === void 0) continue;
2329
+ edge.setAttributeNS(WORD_NS, "w:w", String(value));
2330
+ edge.setAttributeNS(WORD_NS, "w:type", "dxa");
2331
+ margins.appendChild(edge);
2332
+ }
2333
+ if (!Array.from(margins.childNodes).some((node) => node.nodeType === 1) && !margins.attributes.length)
2334
+ properties.removeChild(margins);
2335
+ else orderChildren(margins, ORDER);
2336
+ orderChildren(properties, propertiesOrder);
2337
+ if (!Array.from(properties.childNodes).some((node) => node.nodeType === 1) && !properties.attributes.length)
2338
+ host.removeChild(properties);
2339
+ }
2340
+
2301
2341
  // src/docx/write-table-properties.ts
2302
2342
  var ROW_ORDER = [
2303
2343
  "cnfStyle",
@@ -2357,26 +2397,15 @@ function patchRowProperties(doc, tr, next, base) {
2357
2397
  orderChildren(props, ROW_ORDER);
2358
2398
  }
2359
2399
  function patchTableMargins(doc, table, node, base) {
2360
- if (JSON.stringify(table.cellMargins ?? {}) === JSON.stringify(base?.cellMargins ?? {})) return;
2361
- let props = first2(node, "tblPr");
2362
- if (!props) {
2363
- props = makeW(doc, "tblPr");
2364
- node.insertBefore(props, node.firstChild);
2365
- }
2366
- let margins = first2(props, "tblCellMar");
2367
- if (!margins) {
2368
- margins = makeW(doc, "tblCellMar");
2369
- props.appendChild(margins);
2370
- }
2371
- const built = buildMargins(doc, table.cellMargins ?? {}, "tblCellMar");
2372
- for (const side of ["top", "left", "bottom", "right"]) {
2373
- if (table.cellMargins?.[side] === base?.cellMargins?.[side]) continue;
2374
- for (const old of children2(margins, side)) margins.removeChild(old);
2375
- const replacement = first2(built, side);
2376
- if (replacement) margins.appendChild(replacement);
2377
- }
2378
- orderChildren(margins, ["top", "left", "start", "bottom", "right", "end"]);
2379
- orderChildren(props, TABLE_ORDER);
2400
+ patchMarginProperties(
2401
+ doc,
2402
+ node,
2403
+ "tblPr",
2404
+ "tblCellMar",
2405
+ TABLE_ORDER,
2406
+ table.cellMargins,
2407
+ base?.cellMargins
2408
+ );
2380
2409
  }
2381
2410
  var CELL_ORDER = [
2382
2411
  "cnfStyle",
@@ -2400,6 +2429,9 @@ var CELL_ORDER = [
2400
2429
  ];
2401
2430
  var CELL_BORDER_ORDER = ["top", "start", "left", "bottom", "end", "right", "insideH", "insideV"];
2402
2431
  var CELL_SIDES = ["top", "left", "bottom", "right"];
2432
+ function patchCellMargins(doc, tc, next, base) {
2433
+ patchMarginProperties(doc, tc, "tcPr", "tcMar", CELL_ORDER, next, base);
2434
+ }
2403
2435
  function patchCellBorders(doc, tc, next, base) {
2404
2436
  const changed = CELL_SIDES.filter(
2405
2437
  (side) => JSON.stringify(next?.[side]) !== JSON.stringify(base?.[side])
@@ -2427,6 +2459,23 @@ function patchCellBorders(doc, tc, next, base) {
2427
2459
  orderChildren(props, CELL_ORDER);
2428
2460
  if (!Array.from(props.childNodes).some((node) => node.nodeType === 1)) tc.removeChild(props);
2429
2461
  }
2462
+ function patchCellShading(doc, tc, next, base) {
2463
+ if (next.shadingFill === base?.shadingFill && JSON.stringify(next.shadingThemeFill) === JSON.stringify(base?.shadingThemeFill))
2464
+ return;
2465
+ if (next.shadingFill && next.shadingFill !== "auto" && !/^#?[0-9a-f]{6}$/i.test(next.shadingFill))
2466
+ throw new Error("Cell shading must be a six-digit RGB color or auto.");
2467
+ let props = first2(tc, "tcPr");
2468
+ if (!props) {
2469
+ props = makeW(doc, "tcPr");
2470
+ tc.insertBefore(props, tc.firstChild);
2471
+ }
2472
+ for (const old of children2(props, "shd")) props.removeChild(old);
2473
+ const built = buildCellProperties(doc, next);
2474
+ const replacement = built && first2(built, "shd");
2475
+ if (replacement) props.appendChild(replacement);
2476
+ orderChildren(props, CELL_ORDER);
2477
+ if (!Array.from(props.childNodes).some((node) => node.nodeType === 1)) tc.removeChild(props);
2478
+ }
2430
2479
 
2431
2480
  // src/docx/write-table.ts
2432
2481
  function canEditTableStructure(table) {
@@ -2470,15 +2519,7 @@ var TABLE_DESCRIPTOR_KEYS = [
2470
2519
  "style",
2471
2520
  "look"
2472
2521
  ];
2473
- var CELL_DESCRIPTOR_KEYS = [
2474
- "gridSpan",
2475
- "verticalMerge",
2476
- "widthTwips",
2477
- "verticalAlign",
2478
- "shadingFill",
2479
- "shadingThemeFill",
2480
- "margins"
2481
- ];
2522
+ var CELL_DESCRIPTOR_KEYS = ["gridSpan", "verticalMerge", "widthTwips", "verticalAlign"];
2482
2523
  function pick(source, keys) {
2483
2524
  const record = source;
2484
2525
  const result = {};
@@ -2504,7 +2545,7 @@ function assertNoDescriptorEdits(table, base) {
2504
2545
  if (!source) continue;
2505
2546
  if (JSON.stringify(pick(cell, CELL_DESCRIPTOR_KEYS)) !== JSON.stringify(pick(source, CELL_DESCRIPTOR_KEYS)))
2506
2547
  throw new Error(
2507
- "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."
2548
+ "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."
2508
2549
  );
2509
2550
  }
2510
2551
  }
@@ -2573,6 +2614,8 @@ function writeTable(doc, table, node, base, writeParagraph, replaceSlots2) {
2573
2614
  throw new Error("Moving paragraphs between table cells is not supported.");
2574
2615
  const tc = source?.cell ?? makeW(doc, "tc");
2575
2616
  patchCellBorders(doc, tc, cell.borders, source?.model.borders);
2617
+ patchCellShading(doc, tc, cell, source?.model);
2618
+ patchCellMargins(doc, tc, cell.margins, source?.model.margins);
2576
2619
  const oldParagraphs = children2(tc, "p");
2577
2620
  const nextParagraphs = cell.paragraphs.map((paragraph) => {
2578
2621
  const index = source?.paragraphs.findIndex((p) => p.id === paragraph.id) ?? -1;
@@ -2603,13 +2646,13 @@ function writeTable(doc, table, node, base, writeParagraph, replaceSlots2) {
2603
2646
  }
2604
2647
 
2605
2648
  // src/docx/page-borders.ts
2606
- var SIDES2 = ["top", "left", "bottom", "right"];
2649
+ var SIDES3 = ["top", "left", "bottom", "right"];
2607
2650
  var ATTRIBUTES = ["offsetFrom", "display", "zOrder"];
2608
2651
  var setW4 = (element, name, value) => element.setAttributeNS(WORD_NS, `w:${name}`, value);
2609
2652
  function parsePageBorders(element) {
2610
2653
  if (!element) return void 0;
2611
2654
  const result = {};
2612
- for (const side of SIDES2) {
2655
+ for (const side of SIDES3) {
2613
2656
  const source = first2(element, side);
2614
2657
  const value = borderSide(source);
2615
2658
  const art = getW(source, "art");
@@ -2647,7 +2690,7 @@ function patchPageBorders(doc, sectPr, next, base, create) {
2647
2690
  return;
2648
2691
  }
2649
2692
  const element = create(doc, sectPr, "pgBorders");
2650
- for (const side of SIDES2) {
2693
+ for (const side of SIDES3) {
2651
2694
  if (JSON.stringify(next[side]) === JSON.stringify(base?.[side])) continue;
2652
2695
  for (const old of children2(element, side)) element.removeChild(old);
2653
2696
  const value = next[side];
@@ -2972,7 +3015,7 @@ function applySectionEdits(doc, body, blocks, sections, base, references = /* @_
2972
3015
  }
2973
3016
 
2974
3017
  // src/docx/write-paragraph-decoration.ts
2975
- var SIDES3 = ["top", "left", "bottom", "right", "between"];
3018
+ var SIDES4 = ["top", "left", "bottom", "right", "between"];
2976
3019
  function wordColor(color) {
2977
3020
  const hex = /^#?([0-9a-f]{6})$/i.exec(color ?? "")?.[1];
2978
3021
  return hex ? hex.toUpperCase() : "auto";
@@ -3006,7 +3049,7 @@ function updateBorders(doc, props, paragraph, base) {
3006
3049
  const borders = paragraph.borders;
3007
3050
  if (!borders) return;
3008
3051
  const pBdr = makeW(doc, "pBdr");
3009
- for (const side of SIDES3) {
3052
+ for (const side of SIDES4) {
3010
3053
  const value = borders[side];
3011
3054
  if (value) pBdr.appendChild(borderElement(doc, side, value));
3012
3055
  }
@@ -5537,6 +5580,30 @@ function createRun(doc, run, base, old, allocator) {
5537
5580
  if (!run.text) node.appendChild(makeW(doc, "t"));
5538
5581
  return node;
5539
5582
  }
5583
+ var MATH_NAMESPACES = /* @__PURE__ */ new Set([
5584
+ "http://schemas.openxmlformats.org/officeDocument/2006/math",
5585
+ "http://purl.oclc.org/ooxml/officeDocument/math"
5586
+ ]);
5587
+ function isEquationElement(element) {
5588
+ return MATH_NAMESPACES.has(element.namespaceURI ?? "") && (element.localName === "oMath" || element.localName === "oMathPara");
5589
+ }
5590
+ function parseEquation(element) {
5591
+ if (!isEquationElement(element)) return void 0;
5592
+ return {
5593
+ text: "",
5594
+ equation: {
5595
+ omml: new XMLSerializer().serializeToString(element),
5596
+ display: element.localName === "oMathPara"
5597
+ }
5598
+ };
5599
+ }
5600
+ function preserveEquation(run, base, old) {
5601
+ if (!old || !isEquationElement(old) || !base?.equation || run.text !== "" || run.equation?.omml !== base.equation.omml || run.equation?.display !== base.equation.display)
5602
+ throw new Error(
5603
+ "Equation editing or insertion is unsupported; imported OMML must remain unchanged."
5604
+ );
5605
+ return old.cloneNode(true);
5606
+ }
5540
5607
 
5541
5608
  // src/docx/breaks.ts
5542
5609
  function hasSpecialBreak(element) {
@@ -5635,10 +5702,11 @@ function collectParagraphRuns(node, parseRun3, parseOther, resolveLink, active =
5635
5702
  if (!isCommentReferenceRun(item)) push(parseRun3(item));
5636
5703
  } else if (named2(item, "hyperlink")) {
5637
5704
  const link = resolveLink?.(item);
5638
- for (const run of children2(item, "r")) {
5639
- const parsed = parseRun3(run);
5640
- if (link) parsed.link = link;
5641
- push(parsed);
5705
+ for (const child3 of Array.from(item.childNodes).filter(isElement)) {
5706
+ for (const parsed of named2(child3, "r") ? [parseRun3(child3)] : parseOther?.(child3) ?? []) {
5707
+ if (link) parsed.link = link;
5708
+ push(parsed);
5709
+ }
5642
5710
  }
5643
5711
  } else if ((!item.namespaceURI || item.namespaceURI === WORD_NS) && Object.hasOwn(REVISION_WRAPPERS, item.localName)) {
5644
5712
  const kind = expectDefined(
@@ -5649,7 +5717,12 @@ function collectParagraphRuns(node, parseRun3, parseOther, resolveLink, active =
5649
5717
  const revision = revisionFrom(item, kind);
5650
5718
  const range = kind === "moveFrom" || kind === "moveTo" ? moves[kind].at(-1) : void 0;
5651
5719
  if (range) revision.move = { name: range.name, rangeId: range.id };
5652
- for (const run of children2(item, "r")) push(parseRun3(run, revision));
5720
+ for (const child3 of Array.from(item.childNodes).filter(isElement)) {
5721
+ for (const parsed of named2(child3, "r") ? [parseRun3(child3, revision)] : parseOther?.(child3) ?? []) {
5722
+ parsed.revision = revision;
5723
+ push(parsed);
5724
+ }
5725
+ }
5653
5726
  } else if (trackMoveRange(item, moves)) {
5654
5727
  continue;
5655
5728
  } else if (named2(item, "commentRangeStart")) {
@@ -5696,7 +5769,9 @@ function runsOf(parent, container, slots) {
5696
5769
  if (child3.nodeType === 3 && child3.textContent?.trim()) return false;
5697
5770
  continue;
5698
5771
  }
5699
- if (named2(child3, "r")) {
5772
+ if (isEquationElement(child3)) {
5773
+ slots.push({ element: child3, ...container && { container } });
5774
+ } else if (named2(child3, "r")) {
5700
5775
  if (isCommentReferenceRun(child3)) continue;
5701
5776
  if (!runIsSafe(child3)) return false;
5702
5777
  slots.push({ element: child3, ...container && { container } });
@@ -5720,7 +5795,9 @@ function collectInlineSlots(paragraph) {
5720
5795
  if (child3.nodeType === 3 && child3.textContent?.trim()) return void 0;
5721
5796
  continue;
5722
5797
  }
5723
- if (named2(child3, "r")) {
5798
+ if (isEquationElement(child3)) {
5799
+ slots.push({ element: child3 });
5800
+ } else if (named2(child3, "r")) {
5724
5801
  if (isCommentReferenceRun(child3)) continue;
5725
5802
  if (!runIsSafe(child3)) return void 0;
5726
5803
  slots.push({ element: child3 });
@@ -5736,7 +5813,7 @@ function collectInlineSlots(paragraph) {
5736
5813
  }
5737
5814
  function replaceableInlineChildren(paragraph) {
5738
5815
  return Array.from(paragraph.childNodes).filter(
5739
- (child3) => isElement(child3) && (named2(child3, "r") || named2(child3, "hyperlink") || named2(child3, "fldSimple") || isRevisionWrapperElement(child3) || isCommentAnchorElement(child3))
5816
+ (child3) => isElement(child3) && (isEquationElement(child3) || named2(child3, "r") || named2(child3, "hyperlink") || named2(child3, "fldSimple") || isRevisionWrapperElement(child3) || isCommentAnchorElement(child3))
5740
5817
  );
5741
5818
  }
5742
5819
  function sameLink(a, b) {
@@ -5761,7 +5838,7 @@ function newHyperlink(doc, link, allocator) {
5761
5838
  }
5762
5839
  function runNodes(doc, run, base, old, opens, closes, allocator) {
5763
5840
  const nodes = opens.flatMap((edge) => rangeStartNodes(doc, edge));
5764
- const node = createRun(doc, run, base, old, allocator);
5841
+ const node = run.equation ? preserveEquation(run, base, old) : createRun(doc, run, base, old, allocator);
5765
5842
  const revision = run.revision;
5766
5843
  if (revision && ["insert", "delete", "moveFrom", "moveTo"].includes(revision.kind)) {
5767
5844
  if (revision.kind === "delete" || revision.kind === "moveFrom") convertToDeleteText(doc, node);
@@ -5773,15 +5850,23 @@ function runNodes(doc, run, base, old, opens, closes, allocator) {
5773
5850
  function buildInlineContent(doc, runs, base, slots, allocator, ranges) {
5774
5851
  const { opens, closes } = rangeEdges(runs, ranges);
5775
5852
  const runAt = (at) => expectDefined(runs[at], `run ${at}`);
5776
- const nodesFor = (index2) => runNodes(
5777
- doc,
5778
- runAt(index2),
5779
- base?.[index2],
5780
- slots[index2]?.element,
5781
- opens.get(index2) ?? [],
5782
- closes.get(index2) ?? [],
5783
- allocator
5784
- );
5853
+ const nodesFor = (index2) => {
5854
+ const run = runAt(index2);
5855
+ const sourceIndex = run.equation ? base?.findIndex(
5856
+ (source2) => source2.equation?.omml === run.equation?.omml && source2.equation?.display === run.equation?.display
5857
+ ) : index2;
5858
+ const source = sourceIndex === void 0 ? void 0 : base?.[sourceIndex];
5859
+ const old = sourceIndex === void 0 ? void 0 : slots[sourceIndex]?.element;
5860
+ return runNodes(
5861
+ doc,
5862
+ run,
5863
+ !run.equation && source?.equation ? void 0 : source,
5864
+ !run.equation && old && isEquationElement(old) ? void 0 : old,
5865
+ opens.get(index2) ?? [],
5866
+ closes.get(index2) ?? [],
5867
+ allocator
5868
+ );
5869
+ };
5785
5870
  const output = [];
5786
5871
  let index = 0;
5787
5872
  while (index < runs.length) {
@@ -7436,14 +7521,14 @@ function parseCell(cell, parseParagraph3, id) {
7436
7521
  const vMerge = first2(props, "vMerge");
7437
7522
  if (vMerge) result.verticalMerge = getW(vMerge, "val") === "restart" ? "restart" : "continue";
7438
7523
  const tcW = first2(props, "tcW");
7439
- if (getW(tcW, "type") !== "nil") {
7524
+ if ((getW(tcW, "type") ?? "dxa") === "dxa") {
7440
7525
  const width = dxa(getW(tcW, "w"));
7441
7526
  if (width !== void 0) result.widthTwips = width;
7442
7527
  }
7443
7528
  const vAlign = enumValue(isStVerticalJc, getW(first2(props, "vAlign"), "val"), "w:tcPr/w:vAlign");
7444
7529
  if (vAlign) result.verticalAlign = vAlign;
7445
7530
  const shd = first2(props, "shd");
7446
- const fill = parseShadingFill(shd);
7531
+ const fill = parseShadingFill(shd) ?? (getW(shd, "fill") === "auto" && !getW(shd, "themeFill") ? "auto" : void 0);
7447
7532
  if (fill) result.shadingFill = fill;
7448
7533
  const themeFill = parseShadingThemeFill(shd);
7449
7534
  if (themeFill) result.shadingThemeFill = themeFill;
@@ -7482,7 +7567,9 @@ function parseMargins(element) {
7482
7567
  ["left", "start"],
7483
7568
  ["right", "end"]
7484
7569
  ]) {
7485
- const value = dxa(getW(first2(element, side) ?? first2(element, logical), "w"));
7570
+ const edge = first2(element, logical) ?? first2(element, side);
7571
+ const type = getW(edge, "type") ?? "dxa";
7572
+ const value = type === "nil" ? parseSignedTwips("0") : type === "dxa" ? parseSignedTwips(getW(edge, "w")) : void 0;
7486
7573
  if (value !== void 0) parsed[side] = value;
7487
7574
  }
7488
7575
  return Object.keys(parsed).length ? parsed : void 0;
@@ -7512,7 +7599,8 @@ function parseTable(node, id, parseParagraph3) {
7512
7599
  }) : [];
7513
7600
  if (grid.length) table.grid = grid;
7514
7601
  const tblPr = first2(node, "tblPr");
7515
- const width = dxa(getW(first2(tblPr, "tblW"), "w"));
7602
+ const tableWidth = first2(tblPr, "tblW");
7603
+ const width = (getW(tableWidth, "type") ?? "dxa") === "dxa" ? dxa(getW(tableWidth, "w")) : void 0;
7516
7604
  if (width !== void 0) table.widthTwips = width;
7517
7605
  const justification = enumValue(isStJcTable, getW(first2(tblPr, "jc"), "val"), "w:tblPr/w:jc");
7518
7606
  if (justification) {
@@ -7689,13 +7777,19 @@ function parseParagraph2(node, id) {
7689
7777
  node,
7690
7778
  (element, revision) => trackField(element, parseRun2(element, revision)),
7691
7779
  (item) => {
7780
+ const equation = parseEquation(item);
7781
+ if (equation) return [equation];
7692
7782
  if (!named2(item, "fldSimple")) return void 0;
7693
7783
  const instr = getW(item, "instr") ?? "";
7694
7784
  const link = parseSimpleHyperlinkField(instr);
7695
- const results = children2(item, "r").map((run) => parseRun2(run));
7785
+ const results = Array.from(item.childNodes).filter(isElement).flatMap((child3) => {
7786
+ const equation2 = parseEquation(child3);
7787
+ return equation2 ? [equation2] : named2(child3, "r") ? [parseRun2(child3)] : [];
7788
+ });
7696
7789
  if (link) return results.map((run) => ({ ...run, link }));
7697
7790
  const field = { instr: instr.trim(), simple: true };
7698
- if (!results.some((run) => run.text)) return [{ text: fieldPlaceholderText(instr), field }];
7791
+ if (!results.some((run) => run.text || run.equation))
7792
+ return [{ text: fieldPlaceholderText(instr), field }];
7699
7793
  return results.map((run) => ({ ...run, field }));
7700
7794
  },
7701
7795
  (hyperlink) => {
@@ -1 +1 @@
1
- {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../../src/docx/layout/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEX,aAAa,EAKb,MAAM,aAAa,CAAC;AAmBrB,OAAO,KAAK,EAEX,mBAAmB,EAMnB,MAAM,YAAY,CAAC;AAyBpB,oFAAoF;AACpF,wBAAgB,kBAAkB,CACjC,KAAK,EAAE,aAAa,EACpB,IAAI,GAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAe,GACxC,mBAAmB,CA2PrB"}
1
+ {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../../src/docx/layout/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEX,aAAa,EAKb,MAAM,aAAa,CAAC;AAmBrB,OAAO,KAAK,EAEX,mBAAmB,EAMnB,MAAM,YAAY,CAAC;AA2BpB,oFAAoF;AACpF,wBAAgB,kBAAkB,CACjC,KAAK,EAAE,aAAa,EACpB,IAAI,GAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAe,GACxC,mBAAmB,CA8PrB"}
@@ -2149,6 +2149,7 @@ var TABLE_ROW_NOTE = "Table rows with an exact height clip content that does not
2149
2149
  var VERTICAL_MERGE_NOTE = "Vertically merged table cells are drawn as one cell, but their text stays in the first row of the merge.";
2150
2150
  var DROP_CAP_NOTE = "Drop caps are laid out as an enlarged first letter (a raised cap), not as a dropped cap.";
2151
2151
  var TEXT_BOX_NOTE = "Text boxes are shown on the editing surface but are not drawn in Print Layout.";
2152
+ var EQUATION_NOTE = "Equations display on the editing surface; Print Layout shows markers rather than typeset equations.";
2152
2153
  var NEXT_COLUMN_NOTE = 'A "next column" section break is laid out as a continuous section break.';
2153
2154
  var twipsToPx3 = twipsToPixels;
2154
2155
  function sectionBreak(type, note) {
@@ -2184,9 +2185,10 @@ function adaptDocumentModel(model, note = () => {
2184
2185
  const noteLabel = noteLabels(model);
2185
2186
  function adaptRun(run, paragraphStyleId, markLabel) {
2186
2187
  const { formatting, family, color } = effective(run, paragraphStyleId);
2188
+ if (run.equation) reportOnce(EQUATION_NOTE);
2187
2189
  const name = run.field ? fieldName(run.field.instr) : "";
2188
2190
  const noteText = run.noteReference ? noteLabel(run.noteReference.kind, run.noteReference.id) : run.noteMark ? markLabel ?? "" : void 0;
2189
- const text = noteText ?? (run.field && (name === "DATE" || name === "TIME") ? dateFieldResult(name, run.field.instr, now) : run.text);
2191
+ const text = noteText ?? (run.field && (name === "DATE" || name === "TIME") ? dateFieldResult(name, run.field.instr, now) : run.equation ? "[Equation]" : run.text);
2190
2192
  const script = formatting.verticalAlign === "superscript" || noteText !== void 0 && formatting.verticalAlign === void 0 ? "super" : formatting.verticalAlign === "subscript" ? "sub" : void 0;
2191
2193
  const image = run.image;
2192
2194
  if (image?.unsupported === "Text box") reportOnce(TEXT_BOX_NOTE);
@@ -2147,6 +2147,7 @@ var TABLE_ROW_NOTE = "Table rows with an exact height clip content that does not
2147
2147
  var VERTICAL_MERGE_NOTE = "Vertically merged table cells are drawn as one cell, but their text stays in the first row of the merge.";
2148
2148
  var DROP_CAP_NOTE = "Drop caps are laid out as an enlarged first letter (a raised cap), not as a dropped cap.";
2149
2149
  var TEXT_BOX_NOTE = "Text boxes are shown on the editing surface but are not drawn in Print Layout.";
2150
+ var EQUATION_NOTE = "Equations display on the editing surface; Print Layout shows markers rather than typeset equations.";
2150
2151
  var NEXT_COLUMN_NOTE = 'A "next column" section break is laid out as a continuous section break.';
2151
2152
  var twipsToPx3 = twipsToPixels;
2152
2153
  function sectionBreak(type, note) {
@@ -2182,9 +2183,10 @@ function adaptDocumentModel(model, note = () => {
2182
2183
  const noteLabel = noteLabels(model);
2183
2184
  function adaptRun(run, paragraphStyleId, markLabel) {
2184
2185
  const { formatting, family, color } = effective(run, paragraphStyleId);
2186
+ if (run.equation) reportOnce(EQUATION_NOTE);
2185
2187
  const name = run.field ? fieldName(run.field.instr) : "";
2186
2188
  const noteText = run.noteReference ? noteLabel(run.noteReference.kind, run.noteReference.id) : run.noteMark ? markLabel ?? "" : void 0;
2187
- const text = noteText ?? (run.field && (name === "DATE" || name === "TIME") ? dateFieldResult(name, run.field.instr, now) : run.text);
2189
+ const text = noteText ?? (run.field && (name === "DATE" || name === "TIME") ? dateFieldResult(name, run.field.instr, now) : run.equation ? "[Equation]" : run.text);
2188
2190
  const script = formatting.verticalAlign === "superscript" || noteText !== void 0 && formatting.verticalAlign === void 0 ? "super" : formatting.verticalAlign === "subscript" ? "sub" : void 0;
2189
2191
  const image = run.image;
2190
2192
  if (image?.unsupported === "Text box") reportOnce(TEXT_BOX_NOTE);