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.
- package/NOTICE +2 -0
- package/README.md +1 -0
- package/dist/digest/algorithm-names.d.ts +20 -0
- package/dist/digest/algorithm-names.d.ts.map +1 -0
- package/dist/digest/base64.d.ts +8 -0
- package/dist/digest/base64.d.ts.map +1 -0
- package/dist/digest/digest.d.ts +13 -0
- package/dist/digest/digest.d.ts.map +1 -0
- package/dist/digest/index.cjs +594 -0
- package/dist/digest/index.d.ts +8 -0
- package/dist/digest/index.d.ts.map +1 -0
- package/dist/digest/index.mjs +581 -0
- package/dist/digest/password-hash.d.ts +30 -0
- package/dist/digest/password-hash.d.ts.map +1 -0
- package/dist/digest/sha1.d.ts +3 -0
- package/dist/digest/sha1.d.ts.map +1 -0
- package/dist/digest/sha256.d.ts +10 -0
- package/dist/digest/sha256.d.ts.map +1 -0
- package/dist/digest/sha512.d.ts +5 -0
- package/dist/digest/sha512.d.ts.map +1 -0
- package/dist/docx/block-parser.d.ts.map +1 -1
- package/dist/docx/embedded.cjs +153 -59
- package/dist/docx/embedded.mjs +153 -59
- package/dist/docx/equation.d.ts +8 -0
- package/dist/docx/equation.d.ts.map +1 -0
- package/dist/docx/index.cjs +153 -59
- package/dist/docx/index.mjs +153 -59
- package/dist/docx/layout/adapter.d.ts.map +1 -1
- package/dist/docx/layout/index.cjs +3 -1
- package/dist/docx/layout/index.mjs +3 -1
- package/dist/docx/load/index.cjs +155 -61
- package/dist/docx/load/index.mjs +155 -61
- package/dist/docx/model-run.d.ts +5 -0
- package/dist/docx/model-run.d.ts.map +1 -1
- package/dist/docx/parse-revisions.d.ts.map +1 -1
- package/dist/docx/parse-table.d.ts.map +1 -1
- package/dist/docx/write-inline.d.ts.map +1 -1
- package/dist/docx/write-table-margins.d.ts +5 -0
- package/dist/docx/write-table-margins.d.ts.map +1 -0
- package/dist/docx/write-table-properties.d.ts +6 -2
- package/dist/docx/write-table-properties.d.ts.map +1 -1
- package/dist/docx/write-table.d.ts.map +1 -1
- package/dist/index.cjs +2640 -13
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +2639 -14
- package/dist/math/index.cjs +2050 -0
- package/dist/math/index.d.ts +15 -0
- package/dist/math/index.d.ts.map +1 -0
- package/dist/math/index.mjs +1985 -0
- package/dist/math/latex-omml-siblings.d.ts +21 -0
- package/dist/math/latex-omml-siblings.d.ts.map +1 -0
- package/dist/math/latex-omml-symbols.d.ts +42 -0
- package/dist/math/latex-omml-symbols.d.ts.map +1 -0
- package/dist/math/latex-to-omml-commands.d.ts +9 -0
- package/dist/math/latex-to-omml-commands.d.ts.map +1 -0
- package/dist/math/latex-to-omml-constructs.d.ts +39 -0
- package/dist/math/latex-to-omml-constructs.d.ts.map +1 -0
- package/dist/math/latex-to-omml-environments.d.ts +28 -0
- package/dist/math/latex-to-omml-environments.d.ts.map +1 -0
- package/dist/math/latex-to-omml.d.ts +9 -0
- package/dist/math/latex-to-omml.d.ts.map +1 -0
- package/dist/math/omml-color.d.ts +11 -0
- package/dist/math/omml-color.d.ts.map +1 -0
- package/dist/math/omml-dom.d.ts +7 -0
- package/dist/math/omml-dom.d.ts.map +1 -0
- package/dist/math/omml-mathml-converters.d.ts +39 -0
- package/dist/math/omml-mathml-converters.d.ts.map +1 -0
- package/dist/math/omml-mathml-helpers.d.ts +23 -0
- package/dist/math/omml-mathml-helpers.d.ts.map +1 -0
- package/dist/math/omml-node.d.ts +7 -0
- package/dist/math/omml-node.d.ts.map +1 -0
- package/dist/math/omml-to-latex-helpers.d.ts +41 -0
- package/dist/math/omml-to-latex-helpers.d.ts.map +1 -0
- package/dist/math/omml-to-latex-layout.d.ts +18 -0
- package/dist/math/omml-to-latex-layout.d.ts.map +1 -0
- package/dist/math/omml-to-latex.d.ts +6 -0
- package/dist/math/omml-to-latex.d.ts.map +1 -0
- package/dist/math/omml-to-mathml.d.ts +21 -0
- package/dist/math/omml-to-mathml.d.ts.map +1 -0
- package/dist/xlsx/edit/history.d.ts +1 -1
- package/dist/xlsx/edit/history.d.ts.map +1 -1
- package/dist/xlsx/edit/index.d.ts +1 -1
- package/dist/xlsx/edit/index.d.ts.map +1 -1
- package/dist/xlsx/edit/protection.d.ts +18 -6
- package/dist/xlsx/edit/protection.d.ts.map +1 -1
- package/dist/xlsx/edit/types.d.ts +2 -2
- package/dist/xlsx/index.cjs +671 -28
- package/dist/xlsx/index.mjs +670 -29
- package/dist/xlsx/load/index.cjs +56 -19
- package/dist/xlsx/load/index.mjs +56 -19
- package/dist/xlsx/model.d.ts +21 -0
- package/dist/xlsx/model.d.ts.map +1 -1
- package/dist/xlsx/read/load.d.ts.map +1 -1
- package/dist/xlsx/read/password-hash.d.ts +15 -0
- package/dist/xlsx/read/password-hash.d.ts.map +1 -0
- package/dist/xlsx/read/sheet-props.d.ts.map +1 -1
- package/dist/xlsx/read/workbook-part.d.ts +3 -1
- package/dist/xlsx/read/workbook-part.d.ts.map +1 -1
- package/dist/xlsx/write/password-hash.d.ts +8 -0
- package/dist/xlsx/write/password-hash.d.ts.map +1 -0
- package/dist/xlsx/write/sheet-props.d.ts.map +1 -1
- package/dist/xlsx/write/workbook-part.d.ts.map +1 -1
- package/package.json +11 -1
package/dist/docx/index.cjs
CHANGED
|
@@ -2304,6 +2304,46 @@ function orderSectionProperties(sectPr) {
|
|
|
2304
2304
|
orderChildren(sectPr, SECTPR_ORDER);
|
|
2305
2305
|
}
|
|
2306
2306
|
|
|
2307
|
+
// src/docx/write-table-margins.ts
|
|
2308
|
+
var SIDES2 = ["top", "left", "bottom", "right"];
|
|
2309
|
+
var ORDER = ["top", "start", "left", "bottom", "end", "right"];
|
|
2310
|
+
function patchMarginProperties(doc, host, propertiesTag, marginTag, propertiesOrder, next, base) {
|
|
2311
|
+
const changed = SIDES2.filter((side) => next?.[side] !== base?.[side]);
|
|
2312
|
+
if (!changed.length) return;
|
|
2313
|
+
for (const side of changed) {
|
|
2314
|
+
const value = next?.[side];
|
|
2315
|
+
if (value !== void 0 && (!Number.isSafeInteger(value) || value < 0))
|
|
2316
|
+
throw new Error("Table cell margins must be nonnegative whole twips.");
|
|
2317
|
+
}
|
|
2318
|
+
let properties = first2(host, propertiesTag);
|
|
2319
|
+
if (!properties) {
|
|
2320
|
+
properties = makeW(doc, propertiesTag);
|
|
2321
|
+
host.insertBefore(properties, host.firstChild);
|
|
2322
|
+
}
|
|
2323
|
+
let margins = first2(properties, marginTag);
|
|
2324
|
+
if (!margins) {
|
|
2325
|
+
margins = makeW(doc, marginTag);
|
|
2326
|
+
properties.appendChild(margins);
|
|
2327
|
+
}
|
|
2328
|
+
for (const side of changed) {
|
|
2329
|
+
const logical = side === "left" ? "start" : side === "right" ? "end" : side;
|
|
2330
|
+
const edge = first2(margins, logical) ?? first2(margins, side) ?? makeW(doc, side);
|
|
2331
|
+
for (const alias of /* @__PURE__ */ new Set([side, logical]))
|
|
2332
|
+
for (const old of children2(margins, alias)) margins.removeChild(old);
|
|
2333
|
+
const value = next?.[side];
|
|
2334
|
+
if (value === void 0) continue;
|
|
2335
|
+
edge.setAttributeNS(WORD_NS, "w:w", String(value));
|
|
2336
|
+
edge.setAttributeNS(WORD_NS, "w:type", "dxa");
|
|
2337
|
+
margins.appendChild(edge);
|
|
2338
|
+
}
|
|
2339
|
+
if (!Array.from(margins.childNodes).some((node) => node.nodeType === 1) && !margins.attributes.length)
|
|
2340
|
+
properties.removeChild(margins);
|
|
2341
|
+
else orderChildren(margins, ORDER);
|
|
2342
|
+
orderChildren(properties, propertiesOrder);
|
|
2343
|
+
if (!Array.from(properties.childNodes).some((node) => node.nodeType === 1) && !properties.attributes.length)
|
|
2344
|
+
host.removeChild(properties);
|
|
2345
|
+
}
|
|
2346
|
+
|
|
2307
2347
|
// src/docx/write-table-properties.ts
|
|
2308
2348
|
var ROW_ORDER = [
|
|
2309
2349
|
"cnfStyle",
|
|
@@ -2363,26 +2403,15 @@ function patchRowProperties(doc, tr, next, base) {
|
|
|
2363
2403
|
orderChildren(props, ROW_ORDER);
|
|
2364
2404
|
}
|
|
2365
2405
|
function patchTableMargins(doc, table, node, base) {
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
props.appendChild(margins);
|
|
2376
|
-
}
|
|
2377
|
-
const built = buildMargins(doc, table.cellMargins ?? {}, "tblCellMar");
|
|
2378
|
-
for (const side of ["top", "left", "bottom", "right"]) {
|
|
2379
|
-
if (table.cellMargins?.[side] === base?.cellMargins?.[side]) continue;
|
|
2380
|
-
for (const old of children2(margins, side)) margins.removeChild(old);
|
|
2381
|
-
const replacement = first2(built, side);
|
|
2382
|
-
if (replacement) margins.appendChild(replacement);
|
|
2383
|
-
}
|
|
2384
|
-
orderChildren(margins, ["top", "left", "start", "bottom", "right", "end"]);
|
|
2385
|
-
orderChildren(props, TABLE_ORDER);
|
|
2406
|
+
patchMarginProperties(
|
|
2407
|
+
doc,
|
|
2408
|
+
node,
|
|
2409
|
+
"tblPr",
|
|
2410
|
+
"tblCellMar",
|
|
2411
|
+
TABLE_ORDER,
|
|
2412
|
+
table.cellMargins,
|
|
2413
|
+
base?.cellMargins
|
|
2414
|
+
);
|
|
2386
2415
|
}
|
|
2387
2416
|
var CELL_ORDER = [
|
|
2388
2417
|
"cnfStyle",
|
|
@@ -2406,6 +2435,9 @@ var CELL_ORDER = [
|
|
|
2406
2435
|
];
|
|
2407
2436
|
var CELL_BORDER_ORDER = ["top", "start", "left", "bottom", "end", "right", "insideH", "insideV"];
|
|
2408
2437
|
var CELL_SIDES = ["top", "left", "bottom", "right"];
|
|
2438
|
+
function patchCellMargins(doc, tc, next, base) {
|
|
2439
|
+
patchMarginProperties(doc, tc, "tcPr", "tcMar", CELL_ORDER, next, base);
|
|
2440
|
+
}
|
|
2409
2441
|
function patchCellBorders(doc, tc, next, base) {
|
|
2410
2442
|
const changed = CELL_SIDES.filter(
|
|
2411
2443
|
(side) => JSON.stringify(next?.[side]) !== JSON.stringify(base?.[side])
|
|
@@ -2433,6 +2465,23 @@ function patchCellBorders(doc, tc, next, base) {
|
|
|
2433
2465
|
orderChildren(props, CELL_ORDER);
|
|
2434
2466
|
if (!Array.from(props.childNodes).some((node) => node.nodeType === 1)) tc.removeChild(props);
|
|
2435
2467
|
}
|
|
2468
|
+
function patchCellShading(doc, tc, next, base) {
|
|
2469
|
+
if (next.shadingFill === base?.shadingFill && JSON.stringify(next.shadingThemeFill) === JSON.stringify(base?.shadingThemeFill))
|
|
2470
|
+
return;
|
|
2471
|
+
if (next.shadingFill && next.shadingFill !== "auto" && !/^#?[0-9a-f]{6}$/i.test(next.shadingFill))
|
|
2472
|
+
throw new Error("Cell shading must be a six-digit RGB color or auto.");
|
|
2473
|
+
let props = first2(tc, "tcPr");
|
|
2474
|
+
if (!props) {
|
|
2475
|
+
props = makeW(doc, "tcPr");
|
|
2476
|
+
tc.insertBefore(props, tc.firstChild);
|
|
2477
|
+
}
|
|
2478
|
+
for (const old of children2(props, "shd")) props.removeChild(old);
|
|
2479
|
+
const built = buildCellProperties(doc, next);
|
|
2480
|
+
const replacement = built && first2(built, "shd");
|
|
2481
|
+
if (replacement) props.appendChild(replacement);
|
|
2482
|
+
orderChildren(props, CELL_ORDER);
|
|
2483
|
+
if (!Array.from(props.childNodes).some((node) => node.nodeType === 1)) tc.removeChild(props);
|
|
2484
|
+
}
|
|
2436
2485
|
|
|
2437
2486
|
// src/docx/write-table.ts
|
|
2438
2487
|
function canEditTableStructure(table) {
|
|
@@ -2476,15 +2525,7 @@ var TABLE_DESCRIPTOR_KEYS = [
|
|
|
2476
2525
|
"style",
|
|
2477
2526
|
"look"
|
|
2478
2527
|
];
|
|
2479
|
-
var CELL_DESCRIPTOR_KEYS = [
|
|
2480
|
-
"gridSpan",
|
|
2481
|
-
"verticalMerge",
|
|
2482
|
-
"widthTwips",
|
|
2483
|
-
"verticalAlign",
|
|
2484
|
-
"shadingFill",
|
|
2485
|
-
"shadingThemeFill",
|
|
2486
|
-
"margins"
|
|
2487
|
-
];
|
|
2528
|
+
var CELL_DESCRIPTOR_KEYS = ["gridSpan", "verticalMerge", "widthTwips", "verticalAlign"];
|
|
2488
2529
|
function pick(source, keys) {
|
|
2489
2530
|
const record = source;
|
|
2490
2531
|
const result = {};
|
|
@@ -2510,7 +2551,7 @@ function assertNoDescriptorEdits(table, base) {
|
|
|
2510
2551
|
if (!source) continue;
|
|
2511
2552
|
if (JSON.stringify(pick(cell, CELL_DESCRIPTOR_KEYS)) !== JSON.stringify(pick(source, CELL_DESCRIPTOR_KEYS)))
|
|
2512
2553
|
throw new Error(
|
|
2513
|
-
"Cannot edit table cell width, merge
|
|
2554
|
+
"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."
|
|
2514
2555
|
);
|
|
2515
2556
|
}
|
|
2516
2557
|
}
|
|
@@ -2579,6 +2620,8 @@ function writeTable(doc, table, node, base, writeParagraph, replaceSlots2) {
|
|
|
2579
2620
|
throw new Error("Moving paragraphs between table cells is not supported.");
|
|
2580
2621
|
const tc = source?.cell ?? makeW(doc, "tc");
|
|
2581
2622
|
patchCellBorders(doc, tc, cell.borders, source?.model.borders);
|
|
2623
|
+
patchCellShading(doc, tc, cell, source?.model);
|
|
2624
|
+
patchCellMargins(doc, tc, cell.margins, source?.model.margins);
|
|
2582
2625
|
const oldParagraphs = children2(tc, "p");
|
|
2583
2626
|
const nextParagraphs = cell.paragraphs.map((paragraph) => {
|
|
2584
2627
|
const index = source?.paragraphs.findIndex((p) => p.id === paragraph.id) ?? -1;
|
|
@@ -2609,13 +2652,13 @@ function writeTable(doc, table, node, base, writeParagraph, replaceSlots2) {
|
|
|
2609
2652
|
}
|
|
2610
2653
|
|
|
2611
2654
|
// src/docx/page-borders.ts
|
|
2612
|
-
var
|
|
2655
|
+
var SIDES3 = ["top", "left", "bottom", "right"];
|
|
2613
2656
|
var ATTRIBUTES = ["offsetFrom", "display", "zOrder"];
|
|
2614
2657
|
var setW4 = (element, name, value) => element.setAttributeNS(WORD_NS, `w:${name}`, value);
|
|
2615
2658
|
function parsePageBorders(element) {
|
|
2616
2659
|
if (!element) return void 0;
|
|
2617
2660
|
const result = {};
|
|
2618
|
-
for (const side of
|
|
2661
|
+
for (const side of SIDES3) {
|
|
2619
2662
|
const source = first2(element, side);
|
|
2620
2663
|
const value = borderSide(source);
|
|
2621
2664
|
const art = getW(source, "art");
|
|
@@ -2653,7 +2696,7 @@ function patchPageBorders(doc, sectPr, next, base, create) {
|
|
|
2653
2696
|
return;
|
|
2654
2697
|
}
|
|
2655
2698
|
const element = create(doc, sectPr, "pgBorders");
|
|
2656
|
-
for (const side of
|
|
2699
|
+
for (const side of SIDES3) {
|
|
2657
2700
|
if (JSON.stringify(next[side]) === JSON.stringify(base?.[side])) continue;
|
|
2658
2701
|
for (const old of children2(element, side)) element.removeChild(old);
|
|
2659
2702
|
const value = next[side];
|
|
@@ -2978,7 +3021,7 @@ function applySectionEdits(doc, body, blocks, sections, base, references = /* @_
|
|
|
2978
3021
|
}
|
|
2979
3022
|
|
|
2980
3023
|
// src/docx/write-paragraph-decoration.ts
|
|
2981
|
-
var
|
|
3024
|
+
var SIDES4 = ["top", "left", "bottom", "right", "between"];
|
|
2982
3025
|
function wordColor(color) {
|
|
2983
3026
|
const hex = /^#?([0-9a-f]{6})$/i.exec(color ?? "")?.[1];
|
|
2984
3027
|
return hex ? hex.toUpperCase() : "auto";
|
|
@@ -3012,7 +3055,7 @@ function updateBorders(doc, props, paragraph, base) {
|
|
|
3012
3055
|
const borders = paragraph.borders;
|
|
3013
3056
|
if (!borders) return;
|
|
3014
3057
|
const pBdr = makeW(doc, "pBdr");
|
|
3015
|
-
for (const side of
|
|
3058
|
+
for (const side of SIDES4) {
|
|
3016
3059
|
const value = borders[side];
|
|
3017
3060
|
if (value) pBdr.appendChild(borderElement(doc, side, value));
|
|
3018
3061
|
}
|
|
@@ -5543,6 +5586,30 @@ function createRun(doc, run, base, old, allocator) {
|
|
|
5543
5586
|
if (!run.text) node.appendChild(makeW(doc, "t"));
|
|
5544
5587
|
return node;
|
|
5545
5588
|
}
|
|
5589
|
+
var MATH_NAMESPACES = /* @__PURE__ */ new Set([
|
|
5590
|
+
"http://schemas.openxmlformats.org/officeDocument/2006/math",
|
|
5591
|
+
"http://purl.oclc.org/ooxml/officeDocument/math"
|
|
5592
|
+
]);
|
|
5593
|
+
function isEquationElement(element) {
|
|
5594
|
+
return MATH_NAMESPACES.has(element.namespaceURI ?? "") && (element.localName === "oMath" || element.localName === "oMathPara");
|
|
5595
|
+
}
|
|
5596
|
+
function parseEquation(element) {
|
|
5597
|
+
if (!isEquationElement(element)) return void 0;
|
|
5598
|
+
return {
|
|
5599
|
+
text: "",
|
|
5600
|
+
equation: {
|
|
5601
|
+
omml: new xmldom.XMLSerializer().serializeToString(element),
|
|
5602
|
+
display: element.localName === "oMathPara"
|
|
5603
|
+
}
|
|
5604
|
+
};
|
|
5605
|
+
}
|
|
5606
|
+
function preserveEquation(run, base, old) {
|
|
5607
|
+
if (!old || !isEquationElement(old) || !base?.equation || run.text !== "" || run.equation?.omml !== base.equation.omml || run.equation?.display !== base.equation.display)
|
|
5608
|
+
throw new Error(
|
|
5609
|
+
"Equation editing or insertion is unsupported; imported OMML must remain unchanged."
|
|
5610
|
+
);
|
|
5611
|
+
return old.cloneNode(true);
|
|
5612
|
+
}
|
|
5546
5613
|
|
|
5547
5614
|
// src/docx/breaks.ts
|
|
5548
5615
|
function hasSpecialBreak(element) {
|
|
@@ -5641,10 +5708,11 @@ function collectParagraphRuns(node, parseRun3, parseOther, resolveLink, active =
|
|
|
5641
5708
|
if (!isCommentReferenceRun(item)) push(parseRun3(item));
|
|
5642
5709
|
} else if (named2(item, "hyperlink")) {
|
|
5643
5710
|
const link = resolveLink?.(item);
|
|
5644
|
-
for (const
|
|
5645
|
-
const parsed
|
|
5646
|
-
|
|
5647
|
-
|
|
5711
|
+
for (const child3 of Array.from(item.childNodes).filter(isElement)) {
|
|
5712
|
+
for (const parsed of named2(child3, "r") ? [parseRun3(child3)] : parseOther?.(child3) ?? []) {
|
|
5713
|
+
if (link) parsed.link = link;
|
|
5714
|
+
push(parsed);
|
|
5715
|
+
}
|
|
5648
5716
|
}
|
|
5649
5717
|
} else if ((!item.namespaceURI || item.namespaceURI === WORD_NS) && Object.hasOwn(REVISION_WRAPPERS, item.localName)) {
|
|
5650
5718
|
const kind = expectDefined(
|
|
@@ -5655,7 +5723,12 @@ function collectParagraphRuns(node, parseRun3, parseOther, resolveLink, active =
|
|
|
5655
5723
|
const revision = revisionFrom(item, kind);
|
|
5656
5724
|
const range = kind === "moveFrom" || kind === "moveTo" ? moves[kind].at(-1) : void 0;
|
|
5657
5725
|
if (range) revision.move = { name: range.name, rangeId: range.id };
|
|
5658
|
-
for (const
|
|
5726
|
+
for (const child3 of Array.from(item.childNodes).filter(isElement)) {
|
|
5727
|
+
for (const parsed of named2(child3, "r") ? [parseRun3(child3, revision)] : parseOther?.(child3) ?? []) {
|
|
5728
|
+
parsed.revision = revision;
|
|
5729
|
+
push(parsed);
|
|
5730
|
+
}
|
|
5731
|
+
}
|
|
5659
5732
|
} else if (trackMoveRange(item, moves)) {
|
|
5660
5733
|
continue;
|
|
5661
5734
|
} else if (named2(item, "commentRangeStart")) {
|
|
@@ -5702,7 +5775,9 @@ function runsOf(parent, container, slots) {
|
|
|
5702
5775
|
if (child3.nodeType === 3 && child3.textContent?.trim()) return false;
|
|
5703
5776
|
continue;
|
|
5704
5777
|
}
|
|
5705
|
-
if (
|
|
5778
|
+
if (isEquationElement(child3)) {
|
|
5779
|
+
slots.push({ element: child3, ...container && { container } });
|
|
5780
|
+
} else if (named2(child3, "r")) {
|
|
5706
5781
|
if (isCommentReferenceRun(child3)) continue;
|
|
5707
5782
|
if (!runIsSafe(child3)) return false;
|
|
5708
5783
|
slots.push({ element: child3, ...container && { container } });
|
|
@@ -5726,7 +5801,9 @@ function collectInlineSlots(paragraph) {
|
|
|
5726
5801
|
if (child3.nodeType === 3 && child3.textContent?.trim()) return void 0;
|
|
5727
5802
|
continue;
|
|
5728
5803
|
}
|
|
5729
|
-
if (
|
|
5804
|
+
if (isEquationElement(child3)) {
|
|
5805
|
+
slots.push({ element: child3 });
|
|
5806
|
+
} else if (named2(child3, "r")) {
|
|
5730
5807
|
if (isCommentReferenceRun(child3)) continue;
|
|
5731
5808
|
if (!runIsSafe(child3)) return void 0;
|
|
5732
5809
|
slots.push({ element: child3 });
|
|
@@ -5742,7 +5819,7 @@ function collectInlineSlots(paragraph) {
|
|
|
5742
5819
|
}
|
|
5743
5820
|
function replaceableInlineChildren(paragraph) {
|
|
5744
5821
|
return Array.from(paragraph.childNodes).filter(
|
|
5745
|
-
(child3) => isElement(child3) && (named2(child3, "r") || named2(child3, "hyperlink") || named2(child3, "fldSimple") || isRevisionWrapperElement(child3) || isCommentAnchorElement(child3))
|
|
5822
|
+
(child3) => isElement(child3) && (isEquationElement(child3) || named2(child3, "r") || named2(child3, "hyperlink") || named2(child3, "fldSimple") || isRevisionWrapperElement(child3) || isCommentAnchorElement(child3))
|
|
5746
5823
|
);
|
|
5747
5824
|
}
|
|
5748
5825
|
function sameLink(a, b) {
|
|
@@ -5767,7 +5844,7 @@ function newHyperlink(doc, link, allocator) {
|
|
|
5767
5844
|
}
|
|
5768
5845
|
function runNodes(doc, run, base, old, opens, closes, allocator) {
|
|
5769
5846
|
const nodes = opens.flatMap((edge) => rangeStartNodes(doc, edge));
|
|
5770
|
-
const node = createRun(doc, run, base, old, allocator);
|
|
5847
|
+
const node = run.equation ? preserveEquation(run, base, old) : createRun(doc, run, base, old, allocator);
|
|
5771
5848
|
const revision = run.revision;
|
|
5772
5849
|
if (revision && ["insert", "delete", "moveFrom", "moveTo"].includes(revision.kind)) {
|
|
5773
5850
|
if (revision.kind === "delete" || revision.kind === "moveFrom") convertToDeleteText(doc, node);
|
|
@@ -5779,15 +5856,23 @@ function runNodes(doc, run, base, old, opens, closes, allocator) {
|
|
|
5779
5856
|
function buildInlineContent(doc, runs, base, slots, allocator, ranges) {
|
|
5780
5857
|
const { opens, closes } = rangeEdges(runs, ranges);
|
|
5781
5858
|
const runAt = (at) => expectDefined(runs[at], `run ${at}`);
|
|
5782
|
-
const nodesFor = (index2) =>
|
|
5783
|
-
|
|
5784
|
-
|
|
5785
|
-
|
|
5786
|
-
|
|
5787
|
-
|
|
5788
|
-
|
|
5789
|
-
|
|
5790
|
-
|
|
5859
|
+
const nodesFor = (index2) => {
|
|
5860
|
+
const run = runAt(index2);
|
|
5861
|
+
const sourceIndex = run.equation ? base?.findIndex(
|
|
5862
|
+
(source2) => source2.equation?.omml === run.equation?.omml && source2.equation?.display === run.equation?.display
|
|
5863
|
+
) : index2;
|
|
5864
|
+
const source = sourceIndex === void 0 ? void 0 : base?.[sourceIndex];
|
|
5865
|
+
const old = sourceIndex === void 0 ? void 0 : slots[sourceIndex]?.element;
|
|
5866
|
+
return runNodes(
|
|
5867
|
+
doc,
|
|
5868
|
+
run,
|
|
5869
|
+
!run.equation && source?.equation ? void 0 : source,
|
|
5870
|
+
!run.equation && old && isEquationElement(old) ? void 0 : old,
|
|
5871
|
+
opens.get(index2) ?? [],
|
|
5872
|
+
closes.get(index2) ?? [],
|
|
5873
|
+
allocator
|
|
5874
|
+
);
|
|
5875
|
+
};
|
|
5791
5876
|
const output = [];
|
|
5792
5877
|
let index = 0;
|
|
5793
5878
|
while (index < runs.length) {
|
|
@@ -7442,14 +7527,14 @@ function parseCell(cell, parseParagraph3, id) {
|
|
|
7442
7527
|
const vMerge = first2(props, "vMerge");
|
|
7443
7528
|
if (vMerge) result.verticalMerge = getW(vMerge, "val") === "restart" ? "restart" : "continue";
|
|
7444
7529
|
const tcW = first2(props, "tcW");
|
|
7445
|
-
if (getW(tcW, "type")
|
|
7530
|
+
if ((getW(tcW, "type") ?? "dxa") === "dxa") {
|
|
7446
7531
|
const width = dxa(getW(tcW, "w"));
|
|
7447
7532
|
if (width !== void 0) result.widthTwips = width;
|
|
7448
7533
|
}
|
|
7449
7534
|
const vAlign = enumValue(isStVerticalJc, getW(first2(props, "vAlign"), "val"), "w:tcPr/w:vAlign");
|
|
7450
7535
|
if (vAlign) result.verticalAlign = vAlign;
|
|
7451
7536
|
const shd = first2(props, "shd");
|
|
7452
|
-
const fill = parseShadingFill(shd);
|
|
7537
|
+
const fill = parseShadingFill(shd) ?? (getW(shd, "fill") === "auto" && !getW(shd, "themeFill") ? "auto" : void 0);
|
|
7453
7538
|
if (fill) result.shadingFill = fill;
|
|
7454
7539
|
const themeFill = parseShadingThemeFill(shd);
|
|
7455
7540
|
if (themeFill) result.shadingThemeFill = themeFill;
|
|
@@ -7488,7 +7573,9 @@ function parseMargins(element) {
|
|
|
7488
7573
|
["left", "start"],
|
|
7489
7574
|
["right", "end"]
|
|
7490
7575
|
]) {
|
|
7491
|
-
const
|
|
7576
|
+
const edge = first2(element, logical) ?? first2(element, side);
|
|
7577
|
+
const type = getW(edge, "type") ?? "dxa";
|
|
7578
|
+
const value = type === "nil" ? parseSignedTwips("0") : type === "dxa" ? parseSignedTwips(getW(edge, "w")) : void 0;
|
|
7492
7579
|
if (value !== void 0) parsed[side] = value;
|
|
7493
7580
|
}
|
|
7494
7581
|
return Object.keys(parsed).length ? parsed : void 0;
|
|
@@ -7518,7 +7605,8 @@ function parseTable(node, id, parseParagraph3) {
|
|
|
7518
7605
|
}) : [];
|
|
7519
7606
|
if (grid.length) table.grid = grid;
|
|
7520
7607
|
const tblPr = first2(node, "tblPr");
|
|
7521
|
-
const
|
|
7608
|
+
const tableWidth = first2(tblPr, "tblW");
|
|
7609
|
+
const width = (getW(tableWidth, "type") ?? "dxa") === "dxa" ? dxa(getW(tableWidth, "w")) : void 0;
|
|
7522
7610
|
if (width !== void 0) table.widthTwips = width;
|
|
7523
7611
|
const justification = enumValue(isStJcTable, getW(first2(tblPr, "jc"), "val"), "w:tblPr/w:jc");
|
|
7524
7612
|
if (justification) {
|
|
@@ -7695,13 +7783,19 @@ function parseParagraph2(node, id) {
|
|
|
7695
7783
|
node,
|
|
7696
7784
|
(element, revision) => trackField(element, parseRun2(element, revision)),
|
|
7697
7785
|
(item) => {
|
|
7786
|
+
const equation = parseEquation(item);
|
|
7787
|
+
if (equation) return [equation];
|
|
7698
7788
|
if (!named2(item, "fldSimple")) return void 0;
|
|
7699
7789
|
const instr = getW(item, "instr") ?? "";
|
|
7700
7790
|
const link = parseSimpleHyperlinkField(instr);
|
|
7701
|
-
const results =
|
|
7791
|
+
const results = Array.from(item.childNodes).filter(isElement).flatMap((child3) => {
|
|
7792
|
+
const equation2 = parseEquation(child3);
|
|
7793
|
+
return equation2 ? [equation2] : named2(child3, "r") ? [parseRun2(child3)] : [];
|
|
7794
|
+
});
|
|
7702
7795
|
if (link) return results.map((run) => ({ ...run, link }));
|
|
7703
7796
|
const field = { instr: instr.trim(), simple: true };
|
|
7704
|
-
if (!results.some((run) => run.text
|
|
7797
|
+
if (!results.some((run) => run.text || run.equation))
|
|
7798
|
+
return [{ text: fieldPlaceholderText(instr), field }];
|
|
7705
7799
|
return results.map((run) => ({ ...run, field }));
|
|
7706
7800
|
},
|
|
7707
7801
|
(hyperlink) => {
|