js.documents 7.2.5 → 7.4.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/dist/codecs/read.cjs +1 -1
- package/dist/codecs/read.js +1 -1
- package/dist/convert/composition.cjs +1 -1
- package/dist/convert/composition.js +1 -1
- package/dist/edit/docx/content.cjs +2 -2
- package/dist/edit/docx/content.js +2 -2
- package/dist/edit/docx/editor.cjs +8 -1
- package/dist/edit/docx/editor.d.cts +3 -0
- package/dist/edit/docx/editor.d.ts +3 -0
- package/dist/edit/docx/editor.js +9 -2
- package/dist/edit/docx/run.cjs +1 -1
- package/dist/edit/docx/run.js +1 -1
- package/dist/edit/odg/editor.cjs +8 -1
- package/dist/edit/odg/editor.d.cts +3 -1
- package/dist/edit/odg/editor.d.ts +3 -1
- package/dist/edit/odg/editor.js +9 -2
- package/dist/edit/odg/scaffold.cjs +5 -4
- package/dist/edit/odg/scaffold.d.cts +2 -1
- package/dist/edit/odg/scaffold.d.ts +2 -1
- package/dist/edit/odg/scaffold.js +5 -5
- package/dist/edit/odp/editor.cjs +8 -1
- package/dist/edit/odp/editor.d.cts +3 -1
- package/dist/edit/odp/editor.d.ts +3 -1
- package/dist/edit/odp/editor.js +9 -2
- package/dist/edit/odp/scaffold.cjs +5 -4
- package/dist/edit/odp/scaffold.d.cts +2 -1
- package/dist/edit/odp/scaffold.d.ts +2 -1
- package/dist/edit/odp/scaffold.js +5 -5
- package/dist/edit/odp/shape.cjs +1 -1
- package/dist/edit/odp/shape.js +1 -1
- package/dist/edit/ods/editor.cjs +8 -1
- package/dist/edit/ods/editor.d.cts +3 -0
- package/dist/edit/ods/editor.d.ts +3 -0
- package/dist/edit/ods/editor.js +9 -2
- package/dist/edit/ods/scaffold.cjs +5 -4
- package/dist/edit/ods/scaffold.d.cts +2 -1
- package/dist/edit/ods/scaffold.d.ts +2 -1
- package/dist/edit/ods/scaffold.js +5 -5
- package/dist/edit/odt/editor.cjs +7 -0
- package/dist/edit/odt/editor.d.cts +3 -1
- package/dist/edit/odt/editor.d.ts +3 -1
- package/dist/edit/odt/editor.js +8 -1
- package/dist/edit/odt/scaffold.cjs +5 -4
- package/dist/edit/odt/scaffold.d.cts +2 -1
- package/dist/edit/odt/scaffold.d.ts +2 -1
- package/dist/edit/odt/scaffold.js +5 -5
- package/dist/edit/pptx/editor.cjs +10 -3
- package/dist/edit/pptx/editor.d.cts +3 -1
- package/dist/edit/pptx/editor.d.ts +3 -1
- package/dist/edit/pptx/editor.js +11 -4
- package/dist/edit/pptx/scaffold.cjs +1 -1
- package/dist/edit/pptx/scaffold.js +1 -1
- package/dist/edit/pptx/shape.cjs +1 -1
- package/dist/edit/pptx/shape.js +1 -1
- package/dist/edit/pptx/slide.cjs +2 -2
- package/dist/edit/pptx/slide.js +2 -2
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -1
- package/dist/metadata/core-patch.cjs +29 -0
- package/dist/metadata/core-patch.d.cts +15 -0
- package/dist/metadata/core-patch.d.ts +15 -0
- package/dist/metadata/core-patch.js +26 -0
- package/dist/metadata/write.cjs +4 -17
- package/dist/metadata/write.d.cts +2 -7
- package/dist/metadata/write.d.ts +2 -7
- package/dist/metadata/write.js +3 -16
- package/dist/odf-package/formula.cjs +1 -1
- package/dist/odf-package/formula.js +1 -1
- package/dist/omml/write.cjs +1 -1
- package/dist/omml/write.js +1 -1
- package/dist/ooxml/docx/embedded-objects.cjs +75 -14
- package/dist/ooxml/docx/embedded-objects.d.cts +2 -2
- package/dist/ooxml/docx/embedded-objects.d.ts +2 -2
- package/dist/ooxml/docx/embedded-objects.js +76 -15
- package/dist/ooxml/docx/read.cjs +1 -1
- package/dist/ooxml/docx/read.js +1 -1
- package/dist/ooxml/legacy-embedded.cjs +29 -0
- package/dist/ooxml/legacy-embedded.d.cts +9 -0
- package/dist/ooxml/legacy-embedded.d.ts +9 -0
- package/dist/ooxml/legacy-embedded.js +28 -0
- package/dist/ooxml/pptx/legacy-embedded.cjs +56 -0
- package/dist/ooxml/pptx/legacy-embedded.d.cts +6 -0
- package/dist/ooxml/pptx/legacy-embedded.d.ts +6 -0
- package/dist/ooxml/pptx/legacy-embedded.js +55 -0
- package/dist/ooxml/pptx/read.cjs +5 -2
- package/dist/ooxml/pptx/read.js +5 -2
- package/dist/opc/core-properties.cjs +2 -2
- package/dist/opc/core-properties.js +2 -2
- package/dist/opc/media.cjs +1 -1
- package/dist/opc/media.js +1 -1
- package/dist/xml/odf-text.cjs +1 -1
- package/dist/xml/odf-text.js +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Package } from "ooxml.js";
|
|
2
|
+
import { LayoutMetadata } from "document-schema.js";
|
|
3
|
+
import { Package as Package$1 } from "odf.js";
|
|
4
|
+
//#region src/metadata/core-patch.d.ts
|
|
5
|
+
interface MetadataOverrides {
|
|
6
|
+
readonly title?: string;
|
|
7
|
+
readonly author?: string;
|
|
8
|
+
readonly subject?: string;
|
|
9
|
+
readonly keywords?: string[];
|
|
10
|
+
}
|
|
11
|
+
declare function mergeMetadata(current: LayoutMetadata, overrides: MetadataOverrides): LayoutMetadata;
|
|
12
|
+
declare function patchOoxmlCorePropertiesOnPackage(pkg: Package, overrides: MetadataOverrides): void;
|
|
13
|
+
declare function patchOdfMetadataOnPackage(pkg: Package$1, overrides: MetadataOverrides, version: string): void;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { MetadataOverrides, mergeMetadata, patchOdfMetadataOnPackage, patchOoxmlCorePropertiesOnPackage };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { addCoreProperties } from "../opc/core-properties.js";
|
|
2
|
+
import { hasCoreProperties, patchCoreProperties } from "ooxml.js";
|
|
3
|
+
import { hasOdfMetadata, patchOdfMetadata, writeOdfMetadata } from "odf.js";
|
|
4
|
+
//#region src/metadata/core-patch.ts
|
|
5
|
+
function mergeMetadata(current, overrides) {
|
|
6
|
+
return {
|
|
7
|
+
...current,
|
|
8
|
+
...overrides.title !== void 0 ? { title: overrides.title } : {},
|
|
9
|
+
...overrides.author !== void 0 ? { author: overrides.author } : {},
|
|
10
|
+
...overrides.subject !== void 0 ? { subject: overrides.subject } : {},
|
|
11
|
+
...overrides.keywords !== void 0 ? { keywords: overrides.keywords } : {}
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
function hasWritableMetadataOverride(overrides) {
|
|
15
|
+
return overrides.title !== void 0 || overrides.author !== void 0 || overrides.subject !== void 0 || overrides.keywords !== void 0 && overrides.keywords.length > 0;
|
|
16
|
+
}
|
|
17
|
+
function patchOoxmlCorePropertiesOnPackage(pkg, overrides) {
|
|
18
|
+
if (hasCoreProperties(pkg)) patchCoreProperties(pkg, overrides);
|
|
19
|
+
else if (hasWritableMetadataOverride(overrides)) addCoreProperties(pkg, mergeMetadata({}, overrides));
|
|
20
|
+
}
|
|
21
|
+
function patchOdfMetadataOnPackage(pkg, overrides, version) {
|
|
22
|
+
if (hasOdfMetadata(pkg)) patchOdfMetadata(pkg, overrides);
|
|
23
|
+
else if (hasWritableMetadataOverride(overrides)) writeOdfMetadata(pkg, mergeMetadata({}, overrides), version);
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
26
|
+
export { mergeMetadata, patchOdfMetadataOnPackage, patchOoxmlCorePropertiesOnPackage };
|
package/dist/metadata/write.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_model_bytes = require("../model/bytes.cjs");
|
|
3
|
-
const
|
|
3
|
+
const require_metadata_core_patch = require("./core-patch.cjs");
|
|
4
4
|
const require_ports_abort = require("../ports/abort.cjs");
|
|
5
5
|
const require_codecs_registry = require("../codecs/registry.cjs");
|
|
6
6
|
let ooxml_js = require("ooxml.js");
|
|
@@ -29,23 +29,10 @@ function buildBytesForRebuildFormat(format, content) {
|
|
|
29
29
|
if (!codec?.write) throw new Error(`RebuildFormat '${format}' has no content.write codec in DOCUMENT_FORMAT_CODECS -- this is an internal invariant violation, not a caller error`);
|
|
30
30
|
return require_model_bytes.requireArrayBufferBytes(codec.write(content));
|
|
31
31
|
}
|
|
32
|
-
function mergeMetadata(current, overrides) {
|
|
33
|
-
return {
|
|
34
|
-
...current,
|
|
35
|
-
...overrides.title !== void 0 ? { title: overrides.title } : {},
|
|
36
|
-
...overrides.author !== void 0 ? { author: overrides.author } : {},
|
|
37
|
-
...overrides.subject !== void 0 ? { subject: overrides.subject } : {},
|
|
38
|
-
...overrides.keywords !== void 0 ? { keywords: overrides.keywords } : {}
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
function hasWritableMetadataOverride(overrides) {
|
|
42
|
-
return overrides.title !== void 0 || overrides.author !== void 0 || overrides.subject !== void 0 || overrides.keywords !== void 0 && overrides.keywords.length > 0;
|
|
43
|
-
}
|
|
44
32
|
function patchDocxMetadata(bytes, overrides, options) {
|
|
45
33
|
require_ports_abort.throwIfAborted(options?.signal);
|
|
46
34
|
const pkg = (0, ooxml_js.decodePackage)(bytes);
|
|
47
|
-
|
|
48
|
-
else if (hasWritableMetadataOverride(overrides)) require_opc_core_properties.addCoreProperties(pkg, mergeMetadata({}, overrides));
|
|
35
|
+
require_metadata_core_patch.patchOoxmlCorePropertiesOnPackage(pkg, overrides);
|
|
49
36
|
return (0, ooxml_js.encodePackage)(pkg);
|
|
50
37
|
}
|
|
51
38
|
function classifyWritePath(source, target) {
|
|
@@ -75,7 +62,7 @@ function setDocumentMetadata(sourceFormat, targetFormat, bytes, overrides, optio
|
|
|
75
62
|
const layout = (0, pdf_codec.readPdf)(bytes, { signal: options?.signal });
|
|
76
63
|
const patched = {
|
|
77
64
|
...layout,
|
|
78
|
-
metadata: mergeMetadata(layout.metadata, overrides)
|
|
65
|
+
metadata: require_metadata_core_patch.mergeMetadata(layout.metadata, overrides)
|
|
79
66
|
};
|
|
80
67
|
return (0, pdf_codec.writePdf)(patched, { signal: options?.signal });
|
|
81
68
|
}
|
|
@@ -86,7 +73,7 @@ function setDocumentMetadata(sourceFormat, targetFormat, bytes, overrides, optio
|
|
|
86
73
|
});
|
|
87
74
|
const nextContent = {
|
|
88
75
|
...content,
|
|
89
|
-
metadata: mergeMetadata(content.metadata, overrides)
|
|
76
|
+
metadata: require_metadata_core_patch.mergeMetadata(content.metadata, overrides)
|
|
90
77
|
};
|
|
91
78
|
return buildBytesForRebuildFormat(writePath.format, nextContent);
|
|
92
79
|
}
|
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
import { DocumentFormat } from "../convert/port.cjs";
|
|
2
|
+
import { MetadataOverrides } from "./core-patch.cjs";
|
|
2
3
|
import { MarkdownImageResolver } from "markdown-codec";
|
|
3
4
|
//#region src/metadata/write.d.ts
|
|
4
|
-
interface MetadataOverrides {
|
|
5
|
-
readonly title?: string;
|
|
6
|
-
readonly author?: string;
|
|
7
|
-
readonly subject?: string;
|
|
8
|
-
readonly keywords?: string[];
|
|
9
|
-
}
|
|
10
5
|
interface PatchDocxMetadataOptions {
|
|
11
6
|
readonly signal?: AbortSignal;
|
|
12
7
|
}
|
|
@@ -17,4 +12,4 @@ interface SetDocumentMetadataOptions {
|
|
|
17
12
|
}
|
|
18
13
|
declare function setDocumentMetadata(sourceFormat: DocumentFormat, targetFormat: DocumentFormat, bytes: Uint8Array<ArrayBuffer>, overrides: MetadataOverrides, options?: SetDocumentMetadataOptions): Uint8Array<ArrayBuffer>;
|
|
19
14
|
//#endregion
|
|
20
|
-
export {
|
|
15
|
+
export { PatchDocxMetadataOptions, SetDocumentMetadataOptions, patchDocxMetadata, setDocumentMetadata };
|
package/dist/metadata/write.d.ts
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
import { DocumentFormat } from "../convert/port.js";
|
|
2
|
+
import { MetadataOverrides } from "./core-patch.js";
|
|
2
3
|
import { MarkdownImageResolver } from "markdown-codec";
|
|
3
4
|
//#region src/metadata/write.d.ts
|
|
4
|
-
interface MetadataOverrides {
|
|
5
|
-
readonly title?: string;
|
|
6
|
-
readonly author?: string;
|
|
7
|
-
readonly subject?: string;
|
|
8
|
-
readonly keywords?: string[];
|
|
9
|
-
}
|
|
10
5
|
interface PatchDocxMetadataOptions {
|
|
11
6
|
readonly signal?: AbortSignal;
|
|
12
7
|
}
|
|
@@ -17,4 +12,4 @@ interface SetDocumentMetadataOptions {
|
|
|
17
12
|
}
|
|
18
13
|
declare function setDocumentMetadata(sourceFormat: DocumentFormat, targetFormat: DocumentFormat, bytes: Uint8Array<ArrayBuffer>, overrides: MetadataOverrides, options?: SetDocumentMetadataOptions): Uint8Array<ArrayBuffer>;
|
|
19
14
|
//#endregion
|
|
20
|
-
export {
|
|
15
|
+
export { PatchDocxMetadataOptions, SetDocumentMetadataOptions, patchDocxMetadata, setDocumentMetadata };
|
package/dist/metadata/write.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { requireArrayBufferBytes } from "../model/bytes.js";
|
|
2
|
-
import {
|
|
2
|
+
import { mergeMetadata, patchOoxmlCorePropertiesOnPackage } from "./core-patch.js";
|
|
3
3
|
import { throwIfAborted } from "../ports/abort.js";
|
|
4
4
|
import { DOCUMENT_FORMAT_CODECS } from "../codecs/registry.js";
|
|
5
|
-
import { decodePackage, encodePackage
|
|
5
|
+
import { decodePackage, encodePackage } from "ooxml.js";
|
|
6
6
|
import { readPdf, writePdf } from "pdf-codec";
|
|
7
7
|
//#region src/metadata/write.ts
|
|
8
8
|
const REBUILD_FORMATS = {
|
|
@@ -28,23 +28,10 @@ function buildBytesForRebuildFormat(format, content) {
|
|
|
28
28
|
if (!codec?.write) throw new Error(`RebuildFormat '${format}' has no content.write codec in DOCUMENT_FORMAT_CODECS -- this is an internal invariant violation, not a caller error`);
|
|
29
29
|
return requireArrayBufferBytes(codec.write(content));
|
|
30
30
|
}
|
|
31
|
-
function mergeMetadata(current, overrides) {
|
|
32
|
-
return {
|
|
33
|
-
...current,
|
|
34
|
-
...overrides.title !== void 0 ? { title: overrides.title } : {},
|
|
35
|
-
...overrides.author !== void 0 ? { author: overrides.author } : {},
|
|
36
|
-
...overrides.subject !== void 0 ? { subject: overrides.subject } : {},
|
|
37
|
-
...overrides.keywords !== void 0 ? { keywords: overrides.keywords } : {}
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
function hasWritableMetadataOverride(overrides) {
|
|
41
|
-
return overrides.title !== void 0 || overrides.author !== void 0 || overrides.subject !== void 0 || overrides.keywords !== void 0 && overrides.keywords.length > 0;
|
|
42
|
-
}
|
|
43
31
|
function patchDocxMetadata(bytes, overrides, options) {
|
|
44
32
|
throwIfAborted(options?.signal);
|
|
45
33
|
const pkg = decodePackage(bytes);
|
|
46
|
-
|
|
47
|
-
else if (hasWritableMetadataOverride(overrides)) addCoreProperties(pkg, mergeMetadata({}, overrides));
|
|
34
|
+
patchOoxmlCorePropertiesOnPackage(pkg, overrides);
|
|
48
35
|
return encodePackage(pkg);
|
|
49
36
|
}
|
|
50
37
|
function classifyWritePath(source, target) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_xml_fragment = require("../xml/fragment.cjs");
|
|
3
2
|
const require_xml_entities = require("../xml/entities.cjs");
|
|
3
|
+
const require_xml_fragment = require("../xml/fragment.cjs");
|
|
4
4
|
const require_odf_package_manifest = require("./manifest.cjs");
|
|
5
5
|
//#region src/odf-package/formula.ts
|
|
6
6
|
const OBJECT_PREFIX = "Object ";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { el, txt } from "../xml/fragment.js";
|
|
2
1
|
import { encodeXmlText } from "../xml/entities.js";
|
|
2
|
+
import { el, txt } from "../xml/fragment.js";
|
|
3
3
|
import { syncOdfManifest } from "./manifest.js";
|
|
4
4
|
//#region src/odf-package/formula.ts
|
|
5
5
|
const OBJECT_PREFIX = "Object ";
|
package/dist/omml/write.cjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_xml_entities = require("../xml/entities.cjs");
|
|
2
3
|
const require_xml_fragment = require("../xml/fragment.cjs");
|
|
3
4
|
const require_mathml_length = require("../mathml/length.cjs");
|
|
4
5
|
const require_mathml_nodes = require("../mathml/nodes.cjs");
|
|
5
6
|
const require_mathml_operators = require("../mathml/operators.cjs");
|
|
6
7
|
const require_mathml_variant = require("../mathml/variant.cjs");
|
|
7
|
-
const require_xml_entities = require("../xml/entities.cjs");
|
|
8
8
|
const require_omml_shared = require("./shared.cjs");
|
|
9
9
|
//#region src/omml/write.ts
|
|
10
10
|
const OMML_NS = "http://schemas.openxmlformats.org/officeDocument/2006/math";
|
package/dist/omml/write.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { encodeXmlText, needsSpacePreserve } from "../xml/entities.js";
|
|
1
2
|
import { el, txt } from "../xml/fragment.js";
|
|
2
3
|
import { parseMathLength } from "../mathml/length.js";
|
|
3
4
|
import { attrValue, elementChildren, elementLocalName, isMathMlElement, textContent } from "../mathml/nodes.js";
|
|
4
5
|
import { operatorProperties } from "../mathml/operators.js";
|
|
5
6
|
import { isMathVariant } from "../mathml/variant.js";
|
|
6
|
-
import { encodeXmlText, needsSpacePreserve } from "../xml/entities.js";
|
|
7
7
|
import { VARIANT_RUN_PROPERTIES, miIntrinsicDefault } from "./shared.js";
|
|
8
8
|
//#region src/omml/write.ts
|
|
9
9
|
const OMML_NS = "http://schemas.openxmlformats.org/officeDocument/2006/math";
|
|
@@ -1,20 +1,71 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_model_units = require("../../model/units.cjs");
|
|
2
3
|
const require_model_embedded_drawing = require("../../model/embedded-drawing.cjs");
|
|
3
4
|
const require_model_formula = require("../../model/formula.cjs");
|
|
4
5
|
const require_omml_read = require("../../omml/read.cjs");
|
|
5
6
|
const require_model_block_splice = require("../../model/block-splice.cjs");
|
|
7
|
+
const require_ooxml_legacy_embedded = require("../legacy-embedded.cjs");
|
|
6
8
|
const require_ooxml_docx_vector = require("./vector.cjs");
|
|
7
9
|
const require_ooxml_docx_formula = require("./formula.cjs");
|
|
8
10
|
let ooxml_js = require("ooxml.js");
|
|
9
11
|
//#region src/ooxml/docx/embedded-objects.ts
|
|
12
|
+
const DOCUMENT_PART_PATH = "word/document.xml";
|
|
10
13
|
function isVectorOnlyRun(run, vectors) {
|
|
11
14
|
const elementChildren = run.children.filter((child) => child.type === "element");
|
|
12
15
|
if (elementChildren.length !== 1) return false;
|
|
13
16
|
if (run.children.some((child) => child.type === "text" && child.value.trim().length > 0)) return false;
|
|
14
17
|
return vectors.some((detected) => detected.drawingElement === elementChildren[0]);
|
|
15
18
|
}
|
|
16
|
-
function
|
|
17
|
-
|
|
19
|
+
function objectFrame(object) {
|
|
20
|
+
const dxaOrig = (0, ooxml_js.attr)(object, "w:dxaOrig");
|
|
21
|
+
const dyaOrig = (0, ooxml_js.attr)(object, "w:dyaOrig");
|
|
22
|
+
if (dxaOrig === void 0 || dyaOrig === void 0) return;
|
|
23
|
+
const widthPt = require_model_units.twipsToPt(Number(dxaOrig));
|
|
24
|
+
const heightPt = require_model_units.twipsToPt(Number(dyaOrig));
|
|
25
|
+
return Number.isFinite(widthPt) && Number.isFinite(heightPt) ? {
|
|
26
|
+
widthPt,
|
|
27
|
+
heightPt
|
|
28
|
+
} : void 0;
|
|
29
|
+
}
|
|
30
|
+
function resolveLegacyOleObject(object, rels, pkg) {
|
|
31
|
+
const oleObject = (0, ooxml_js.elementsWithTag)([object], "o:OLEObject")[0];
|
|
32
|
+
const rId = oleObject === void 0 ? void 0 : (0, ooxml_js.attr)(oleObject, "r:id");
|
|
33
|
+
const rel = rId === void 0 ? void 0 : rels.get(rId);
|
|
34
|
+
const payloadPart = rel === void 0 ? void 0 : pkg.parts[rel.target];
|
|
35
|
+
if (payloadPart?.kind !== "binary") return;
|
|
36
|
+
const frame = objectFrame(object);
|
|
37
|
+
if (frame === void 0) return;
|
|
38
|
+
const payload = require_ooxml_legacy_embedded.decodeLegacyEmbeddedObject((0, ooxml_js.base64ToBytes)(payloadPart.base64));
|
|
39
|
+
return payload === void 0 ? void 0 : {
|
|
40
|
+
kind: "embeddedObject",
|
|
41
|
+
objectKind: payload.objectKind,
|
|
42
|
+
document: payload.document,
|
|
43
|
+
frame: {
|
|
44
|
+
xPt: 0,
|
|
45
|
+
yPt: 0,
|
|
46
|
+
...frame
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function collectParagraphOleObjects(paragraph, rels, pkg) {
|
|
51
|
+
const out = [];
|
|
52
|
+
for (const object of (0, ooxml_js.elementsWithTag)(paragraph.children, "w:object")) {
|
|
53
|
+
const block = resolveLegacyOleObject(object, rels, pkg);
|
|
54
|
+
if (block !== void 0) out.push({
|
|
55
|
+
objectElement: object,
|
|
56
|
+
block
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
return out;
|
|
60
|
+
}
|
|
61
|
+
function isOleObjectOnlyRun(run, oleObjects) {
|
|
62
|
+
const elementChildren = run.children.filter((child) => child.type === "element");
|
|
63
|
+
if (elementChildren.length !== 1) return false;
|
|
64
|
+
if (run.children.some((child) => child.type === "text" && child.value.trim().length > 0)) return false;
|
|
65
|
+
return oleObjects.some((detected) => detected.objectElement === elementChildren[0]);
|
|
66
|
+
}
|
|
67
|
+
function isEmbeddedObjectOnlyParagraph(paragraph, equations, vectors, oleObjects) {
|
|
68
|
+
if (equations.length === 0 && vectors.length === 0 && oleObjects.length === 0) return false;
|
|
18
69
|
for (const child of paragraph.children) {
|
|
19
70
|
if (child.type === "text") {
|
|
20
71
|
if (child.value.trim().length > 0) return false;
|
|
@@ -24,14 +75,16 @@ function isEmbeddedObjectOnlyParagraph(paragraph, equations, vectors) {
|
|
|
24
75
|
if (require_ooxml_docx_formula.PARAGRAPH_NON_CONTENT_TAGS.has(child.tag) || equations.includes(child)) continue;
|
|
25
76
|
if (child.tag === "m:oMathPara" && require_omml_read.collectOfficeMathElements(child.children).every((math) => equations.includes(math))) continue;
|
|
26
77
|
if (child.tag === "w:r" && isVectorOnlyRun(child, vectors)) continue;
|
|
78
|
+
if (child.tag === "w:r" && isOleObjectOnlyRun(child, oleObjects)) continue;
|
|
27
79
|
return false;
|
|
28
80
|
}
|
|
29
81
|
return true;
|
|
30
82
|
}
|
|
31
|
-
function paragraphEmbeddings(block, paragraph, blockIndex, onMathDiagnostic) {
|
|
83
|
+
function paragraphEmbeddings(block, paragraph, blockIndex, rels, pkg, onMathDiagnostic) {
|
|
32
84
|
const equations = require_omml_read.collectOfficeMathElements(paragraph.children);
|
|
33
85
|
const vectors = require_ooxml_docx_vector.collectParagraphVectors(paragraph);
|
|
34
|
-
|
|
86
|
+
const oleObjects = collectParagraphOleObjects(paragraph, rels, pkg);
|
|
87
|
+
if (equations.length === 0 && vectors.length === 0 && oleObjects.length === 0) return {
|
|
35
88
|
placements: [],
|
|
36
89
|
consume: false
|
|
37
90
|
};
|
|
@@ -40,7 +93,7 @@ function paragraphEmbeddings(block, paragraph, blockIndex, onMathDiagnostic) {
|
|
|
40
93
|
...require_omml_read.readOfficeMath(equation)
|
|
41
94
|
}));
|
|
42
95
|
const rendered = converted.filter((result) => result.mathml.length > 0);
|
|
43
|
-
if (rendered.length === 0 && vectors.length === 0) {
|
|
96
|
+
if (rendered.length === 0 && vectors.length === 0 && oleObjects.length === 0) {
|
|
44
97
|
for (const result of converted) for (const diagnostic of result.diagnostics) onMathDiagnostic?.(diagnostic, { sourcePath: block.sourcePath });
|
|
45
98
|
return {
|
|
46
99
|
placements: [],
|
|
@@ -73,12 +126,19 @@ function paragraphEmbeddings(block, paragraph, blockIndex, onMathDiagnostic) {
|
|
|
73
126
|
})
|
|
74
127
|
});
|
|
75
128
|
}
|
|
129
|
+
for (const detected of oleObjects) placements.push({
|
|
130
|
+
index: insertAt,
|
|
131
|
+
build: (sourcePath) => ({
|
|
132
|
+
...detected.block,
|
|
133
|
+
sourcePath
|
|
134
|
+
})
|
|
135
|
+
});
|
|
76
136
|
return {
|
|
77
137
|
placements,
|
|
78
|
-
consume: isEmbeddedObjectOnlyParagraph(paragraph, equations, vectors)
|
|
138
|
+
consume: isEmbeddedObjectOnlyParagraph(paragraph, equations, vectors, oleObjects)
|
|
79
139
|
};
|
|
80
140
|
}
|
|
81
|
-
function spliceContainerBlocks(blocks, containerChildren, pageSize, sourcePathPrefix, onMathDiagnostic) {
|
|
141
|
+
function spliceContainerBlocks(blocks, containerChildren, pageSize, sourcePathPrefix, rels, pkg, onMathDiagnostic) {
|
|
82
142
|
const paragraphElements = [];
|
|
83
143
|
require_ooxml_docx_formula.collectBodyParagraphs(containerChildren, paragraphElements);
|
|
84
144
|
const tableElements = [];
|
|
@@ -92,7 +152,7 @@ function spliceContainerBlocks(blocks, containerChildren, pageSize, sourcePathPr
|
|
|
92
152
|
const paragraph = paragraphElements[paragraphOrdinal];
|
|
93
153
|
paragraphOrdinal += 1;
|
|
94
154
|
if (paragraph === void 0) return block;
|
|
95
|
-
const { placements: paragraphPlacements, consume } = paragraphEmbeddings(block, paragraph, blockIndex, onMathDiagnostic);
|
|
155
|
+
const { placements: paragraphPlacements, consume } = paragraphEmbeddings(block, paragraph, blockIndex, rels, pkg, onMathDiagnostic);
|
|
96
156
|
if (paragraphPlacements.length > 0) placements.push(...paragraphPlacements);
|
|
97
157
|
if (consume) consumedIndices.add(blockIndex);
|
|
98
158
|
return block;
|
|
@@ -101,14 +161,14 @@ function spliceContainerBlocks(blocks, containerChildren, pageSize, sourcePathPr
|
|
|
101
161
|
const tableElement = tableElements[tableOrdinal];
|
|
102
162
|
tableOrdinal += 1;
|
|
103
163
|
if (tableElement === void 0) return block;
|
|
104
|
-
return rebuildTable(block, tableElement, pageSize, `${sourcePathPrefix}[${blockIndex}]`, onMathDiagnostic);
|
|
164
|
+
return rebuildTable(block, tableElement, pageSize, `${sourcePathPrefix}[${blockIndex}]`, rels, pkg, onMathDiagnostic);
|
|
105
165
|
}
|
|
106
166
|
return block;
|
|
107
167
|
});
|
|
108
168
|
if (!(consumedIndices.size > 0 || rebuiltBlocks.some((block, index) => block !== blocks[index])) && placements.length === 0) return [...blocks];
|
|
109
169
|
return require_model_block_splice.spliceBlocks(rebuiltBlocks, placements, consumedIndices, (position) => `${sourcePathPrefix}[${position}]`);
|
|
110
170
|
}
|
|
111
|
-
function rebuildTable(table, tblElement, pageSize, blockPath, onMathDiagnostic) {
|
|
171
|
+
function rebuildTable(table, tblElement, pageSize, blockPath, rels, pkg, onMathDiagnostic) {
|
|
112
172
|
const rowElements = (0, ooxml_js.childrenWithTag)(tblElement, "w:tr");
|
|
113
173
|
const rows = table.rows.map((row, rowIndex) => {
|
|
114
174
|
const rowElement = rowElements[rowIndex];
|
|
@@ -116,7 +176,7 @@ function rebuildTable(table, tblElement, pageSize, blockPath, onMathDiagnostic)
|
|
|
116
176
|
const cells = row.cells.map((cell, cellIndex) => {
|
|
117
177
|
const cellElement = cellElements[cellIndex];
|
|
118
178
|
if (cellElement === void 0) return cell;
|
|
119
|
-
const blocks = spliceContainerBlocks(cell.blocks, cellElement.children, pageSize, `${blockPath}.rows[${rowIndex}].cells[${cellIndex}].blocks`, onMathDiagnostic);
|
|
179
|
+
const blocks = spliceContainerBlocks(cell.blocks, cellElement.children, pageSize, `${blockPath}.rows[${rowIndex}].cells[${cellIndex}].blocks`, rels, pkg, onMathDiagnostic);
|
|
120
180
|
return blocks === cell.blocks ? cell : {
|
|
121
181
|
...cell,
|
|
122
182
|
blocks
|
|
@@ -132,11 +192,12 @@ function rebuildTable(table, tblElement, pageSize, blockPath, onMathDiagnostic)
|
|
|
132
192
|
rows
|
|
133
193
|
} : table;
|
|
134
194
|
}
|
|
135
|
-
function spliceDocxEmbeddedObjects(sections, bodyChildren, onMathDiagnostic) {
|
|
195
|
+
function spliceDocxEmbeddedObjects(sections, bodyChildren, pkg, onMathDiagnostic) {
|
|
136
196
|
const paragraphElements = [];
|
|
137
197
|
require_ooxml_docx_formula.collectBodyParagraphs(bodyChildren, paragraphElements);
|
|
138
198
|
const tableElements = [];
|
|
139
199
|
require_ooxml_docx_formula.collectBodyTables(bodyChildren, tableElements);
|
|
200
|
+
const rels = (0, ooxml_js.resolveRelationships)(pkg, DOCUMENT_PART_PATH);
|
|
140
201
|
let paragraphOrdinal = 0;
|
|
141
202
|
let tableOrdinal = 0;
|
|
142
203
|
const out = [];
|
|
@@ -148,7 +209,7 @@ function spliceDocxEmbeddedObjects(sections, bodyChildren, onMathDiagnostic) {
|
|
|
148
209
|
const paragraph = paragraphElements[paragraphOrdinal];
|
|
149
210
|
paragraphOrdinal += 1;
|
|
150
211
|
if (paragraph === void 0) return block;
|
|
151
|
-
const { placements: paragraphPlacements, consume } = paragraphEmbeddings(block, paragraph, blockIndex, onMathDiagnostic);
|
|
212
|
+
const { placements: paragraphPlacements, consume } = paragraphEmbeddings(block, paragraph, blockIndex, rels, pkg, onMathDiagnostic);
|
|
152
213
|
if (paragraphPlacements.length > 0) placements.push(...paragraphPlacements);
|
|
153
214
|
if (consume) consumedIndices.add(blockIndex);
|
|
154
215
|
return block;
|
|
@@ -157,7 +218,7 @@ function spliceDocxEmbeddedObjects(sections, bodyChildren, onMathDiagnostic) {
|
|
|
157
218
|
const tableElement = tableElements[tableOrdinal];
|
|
158
219
|
tableOrdinal += 1;
|
|
159
220
|
if (tableElement === void 0) return block;
|
|
160
|
-
return rebuildTable(block, tableElement, section.pageSize, `sections[${sectionIndex}].blocks`, onMathDiagnostic);
|
|
221
|
+
return rebuildTable(block, tableElement, section.pageSize, `sections[${sectionIndex}].blocks`, rels, pkg, onMathDiagnostic);
|
|
161
222
|
}
|
|
162
223
|
return block;
|
|
163
224
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { t as OmmlDiagnosticSink } from "../../formula-BpuJ3ae0.cjs";
|
|
2
2
|
import { ContentSection } from "document-schema.js";
|
|
3
|
-
import { XmlNode } from "ooxml.js";
|
|
3
|
+
import { Package, XmlNode } from "ooxml.js";
|
|
4
4
|
//#region src/ooxml/docx/embedded-objects.d.ts
|
|
5
|
-
declare function spliceDocxEmbeddedObjects(sections: readonly ContentSection[], bodyChildren: readonly XmlNode[], onMathDiagnostic?: OmmlDiagnosticSink): ContentSection[];
|
|
5
|
+
declare function spliceDocxEmbeddedObjects(sections: readonly ContentSection[], bodyChildren: readonly XmlNode[], pkg: Package, onMathDiagnostic?: OmmlDiagnosticSink): ContentSection[];
|
|
6
6
|
//#endregion
|
|
7
7
|
export { spliceDocxEmbeddedObjects };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { t as OmmlDiagnosticSink } from "../../formula-Cb-LRoIE.js";
|
|
2
|
-
import { XmlNode } from "ooxml.js";
|
|
2
|
+
import { Package, XmlNode } from "ooxml.js";
|
|
3
3
|
import { ContentSection } from "document-schema.js";
|
|
4
4
|
//#region src/ooxml/docx/embedded-objects.d.ts
|
|
5
|
-
declare function spliceDocxEmbeddedObjects(sections: readonly ContentSection[], bodyChildren: readonly XmlNode[], onMathDiagnostic?: OmmlDiagnosticSink): ContentSection[];
|
|
5
|
+
declare function spliceDocxEmbeddedObjects(sections: readonly ContentSection[], bodyChildren: readonly XmlNode[], pkg: Package, onMathDiagnostic?: OmmlDiagnosticSink): ContentSection[];
|
|
6
6
|
//#endregion
|
|
7
7
|
export { spliceDocxEmbeddedObjects };
|
|
@@ -1,19 +1,70 @@
|
|
|
1
|
+
import { twipsToPt } from "../../model/units.js";
|
|
1
2
|
import { buildDrawingBlock } from "../../model/embedded-drawing.js";
|
|
2
3
|
import { buildFormulaBlock } from "../../model/formula.js";
|
|
3
4
|
import { collectOfficeMathElements, readOfficeMath } from "../../omml/read.js";
|
|
4
5
|
import { spliceBlocks } from "../../model/block-splice.js";
|
|
6
|
+
import { decodeLegacyEmbeddedObject } from "../legacy-embedded.js";
|
|
5
7
|
import { collectParagraphVectors } from "./vector.js";
|
|
6
8
|
import { PARAGRAPH_NON_CONTENT_TAGS, collectBodyParagraphs, collectBodyTables, equationFrame } from "./formula.js";
|
|
7
|
-
import { childrenWithTag } from "ooxml.js";
|
|
9
|
+
import { attr, base64ToBytes, childrenWithTag, elementsWithTag, resolveRelationships } from "ooxml.js";
|
|
8
10
|
//#region src/ooxml/docx/embedded-objects.ts
|
|
11
|
+
const DOCUMENT_PART_PATH = "word/document.xml";
|
|
9
12
|
function isVectorOnlyRun(run, vectors) {
|
|
10
13
|
const elementChildren = run.children.filter((child) => child.type === "element");
|
|
11
14
|
if (elementChildren.length !== 1) return false;
|
|
12
15
|
if (run.children.some((child) => child.type === "text" && child.value.trim().length > 0)) return false;
|
|
13
16
|
return vectors.some((detected) => detected.drawingElement === elementChildren[0]);
|
|
14
17
|
}
|
|
15
|
-
function
|
|
16
|
-
|
|
18
|
+
function objectFrame(object) {
|
|
19
|
+
const dxaOrig = attr(object, "w:dxaOrig");
|
|
20
|
+
const dyaOrig = attr(object, "w:dyaOrig");
|
|
21
|
+
if (dxaOrig === void 0 || dyaOrig === void 0) return;
|
|
22
|
+
const widthPt = twipsToPt(Number(dxaOrig));
|
|
23
|
+
const heightPt = twipsToPt(Number(dyaOrig));
|
|
24
|
+
return Number.isFinite(widthPt) && Number.isFinite(heightPt) ? {
|
|
25
|
+
widthPt,
|
|
26
|
+
heightPt
|
|
27
|
+
} : void 0;
|
|
28
|
+
}
|
|
29
|
+
function resolveLegacyOleObject(object, rels, pkg) {
|
|
30
|
+
const oleObject = elementsWithTag([object], "o:OLEObject")[0];
|
|
31
|
+
const rId = oleObject === void 0 ? void 0 : attr(oleObject, "r:id");
|
|
32
|
+
const rel = rId === void 0 ? void 0 : rels.get(rId);
|
|
33
|
+
const payloadPart = rel === void 0 ? void 0 : pkg.parts[rel.target];
|
|
34
|
+
if (payloadPart?.kind !== "binary") return;
|
|
35
|
+
const frame = objectFrame(object);
|
|
36
|
+
if (frame === void 0) return;
|
|
37
|
+
const payload = decodeLegacyEmbeddedObject(base64ToBytes(payloadPart.base64));
|
|
38
|
+
return payload === void 0 ? void 0 : {
|
|
39
|
+
kind: "embeddedObject",
|
|
40
|
+
objectKind: payload.objectKind,
|
|
41
|
+
document: payload.document,
|
|
42
|
+
frame: {
|
|
43
|
+
xPt: 0,
|
|
44
|
+
yPt: 0,
|
|
45
|
+
...frame
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function collectParagraphOleObjects(paragraph, rels, pkg) {
|
|
50
|
+
const out = [];
|
|
51
|
+
for (const object of elementsWithTag(paragraph.children, "w:object")) {
|
|
52
|
+
const block = resolveLegacyOleObject(object, rels, pkg);
|
|
53
|
+
if (block !== void 0) out.push({
|
|
54
|
+
objectElement: object,
|
|
55
|
+
block
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
return out;
|
|
59
|
+
}
|
|
60
|
+
function isOleObjectOnlyRun(run, oleObjects) {
|
|
61
|
+
const elementChildren = run.children.filter((child) => child.type === "element");
|
|
62
|
+
if (elementChildren.length !== 1) return false;
|
|
63
|
+
if (run.children.some((child) => child.type === "text" && child.value.trim().length > 0)) return false;
|
|
64
|
+
return oleObjects.some((detected) => detected.objectElement === elementChildren[0]);
|
|
65
|
+
}
|
|
66
|
+
function isEmbeddedObjectOnlyParagraph(paragraph, equations, vectors, oleObjects) {
|
|
67
|
+
if (equations.length === 0 && vectors.length === 0 && oleObjects.length === 0) return false;
|
|
17
68
|
for (const child of paragraph.children) {
|
|
18
69
|
if (child.type === "text") {
|
|
19
70
|
if (child.value.trim().length > 0) return false;
|
|
@@ -23,14 +74,16 @@ function isEmbeddedObjectOnlyParagraph(paragraph, equations, vectors) {
|
|
|
23
74
|
if (PARAGRAPH_NON_CONTENT_TAGS.has(child.tag) || equations.includes(child)) continue;
|
|
24
75
|
if (child.tag === "m:oMathPara" && collectOfficeMathElements(child.children).every((math) => equations.includes(math))) continue;
|
|
25
76
|
if (child.tag === "w:r" && isVectorOnlyRun(child, vectors)) continue;
|
|
77
|
+
if (child.tag === "w:r" && isOleObjectOnlyRun(child, oleObjects)) continue;
|
|
26
78
|
return false;
|
|
27
79
|
}
|
|
28
80
|
return true;
|
|
29
81
|
}
|
|
30
|
-
function paragraphEmbeddings(block, paragraph, blockIndex, onMathDiagnostic) {
|
|
82
|
+
function paragraphEmbeddings(block, paragraph, blockIndex, rels, pkg, onMathDiagnostic) {
|
|
31
83
|
const equations = collectOfficeMathElements(paragraph.children);
|
|
32
84
|
const vectors = collectParagraphVectors(paragraph);
|
|
33
|
-
|
|
85
|
+
const oleObjects = collectParagraphOleObjects(paragraph, rels, pkg);
|
|
86
|
+
if (equations.length === 0 && vectors.length === 0 && oleObjects.length === 0) return {
|
|
34
87
|
placements: [],
|
|
35
88
|
consume: false
|
|
36
89
|
};
|
|
@@ -39,7 +92,7 @@ function paragraphEmbeddings(block, paragraph, blockIndex, onMathDiagnostic) {
|
|
|
39
92
|
...readOfficeMath(equation)
|
|
40
93
|
}));
|
|
41
94
|
const rendered = converted.filter((result) => result.mathml.length > 0);
|
|
42
|
-
if (rendered.length === 0 && vectors.length === 0) {
|
|
95
|
+
if (rendered.length === 0 && vectors.length === 0 && oleObjects.length === 0) {
|
|
43
96
|
for (const result of converted) for (const diagnostic of result.diagnostics) onMathDiagnostic?.(diagnostic, { sourcePath: block.sourcePath });
|
|
44
97
|
return {
|
|
45
98
|
placements: [],
|
|
@@ -72,12 +125,19 @@ function paragraphEmbeddings(block, paragraph, blockIndex, onMathDiagnostic) {
|
|
|
72
125
|
})
|
|
73
126
|
});
|
|
74
127
|
}
|
|
128
|
+
for (const detected of oleObjects) placements.push({
|
|
129
|
+
index: insertAt,
|
|
130
|
+
build: (sourcePath) => ({
|
|
131
|
+
...detected.block,
|
|
132
|
+
sourcePath
|
|
133
|
+
})
|
|
134
|
+
});
|
|
75
135
|
return {
|
|
76
136
|
placements,
|
|
77
|
-
consume: isEmbeddedObjectOnlyParagraph(paragraph, equations, vectors)
|
|
137
|
+
consume: isEmbeddedObjectOnlyParagraph(paragraph, equations, vectors, oleObjects)
|
|
78
138
|
};
|
|
79
139
|
}
|
|
80
|
-
function spliceContainerBlocks(blocks, containerChildren, pageSize, sourcePathPrefix, onMathDiagnostic) {
|
|
140
|
+
function spliceContainerBlocks(blocks, containerChildren, pageSize, sourcePathPrefix, rels, pkg, onMathDiagnostic) {
|
|
81
141
|
const paragraphElements = [];
|
|
82
142
|
collectBodyParagraphs(containerChildren, paragraphElements);
|
|
83
143
|
const tableElements = [];
|
|
@@ -91,7 +151,7 @@ function spliceContainerBlocks(blocks, containerChildren, pageSize, sourcePathPr
|
|
|
91
151
|
const paragraph = paragraphElements[paragraphOrdinal];
|
|
92
152
|
paragraphOrdinal += 1;
|
|
93
153
|
if (paragraph === void 0) return block;
|
|
94
|
-
const { placements: paragraphPlacements, consume } = paragraphEmbeddings(block, paragraph, blockIndex, onMathDiagnostic);
|
|
154
|
+
const { placements: paragraphPlacements, consume } = paragraphEmbeddings(block, paragraph, blockIndex, rels, pkg, onMathDiagnostic);
|
|
95
155
|
if (paragraphPlacements.length > 0) placements.push(...paragraphPlacements);
|
|
96
156
|
if (consume) consumedIndices.add(blockIndex);
|
|
97
157
|
return block;
|
|
@@ -100,14 +160,14 @@ function spliceContainerBlocks(blocks, containerChildren, pageSize, sourcePathPr
|
|
|
100
160
|
const tableElement = tableElements[tableOrdinal];
|
|
101
161
|
tableOrdinal += 1;
|
|
102
162
|
if (tableElement === void 0) return block;
|
|
103
|
-
return rebuildTable(block, tableElement, pageSize, `${sourcePathPrefix}[${blockIndex}]`, onMathDiagnostic);
|
|
163
|
+
return rebuildTable(block, tableElement, pageSize, `${sourcePathPrefix}[${blockIndex}]`, rels, pkg, onMathDiagnostic);
|
|
104
164
|
}
|
|
105
165
|
return block;
|
|
106
166
|
});
|
|
107
167
|
if (!(consumedIndices.size > 0 || rebuiltBlocks.some((block, index) => block !== blocks[index])) && placements.length === 0) return [...blocks];
|
|
108
168
|
return spliceBlocks(rebuiltBlocks, placements, consumedIndices, (position) => `${sourcePathPrefix}[${position}]`);
|
|
109
169
|
}
|
|
110
|
-
function rebuildTable(table, tblElement, pageSize, blockPath, onMathDiagnostic) {
|
|
170
|
+
function rebuildTable(table, tblElement, pageSize, blockPath, rels, pkg, onMathDiagnostic) {
|
|
111
171
|
const rowElements = childrenWithTag(tblElement, "w:tr");
|
|
112
172
|
const rows = table.rows.map((row, rowIndex) => {
|
|
113
173
|
const rowElement = rowElements[rowIndex];
|
|
@@ -115,7 +175,7 @@ function rebuildTable(table, tblElement, pageSize, blockPath, onMathDiagnostic)
|
|
|
115
175
|
const cells = row.cells.map((cell, cellIndex) => {
|
|
116
176
|
const cellElement = cellElements[cellIndex];
|
|
117
177
|
if (cellElement === void 0) return cell;
|
|
118
|
-
const blocks = spliceContainerBlocks(cell.blocks, cellElement.children, pageSize, `${blockPath}.rows[${rowIndex}].cells[${cellIndex}].blocks`, onMathDiagnostic);
|
|
178
|
+
const blocks = spliceContainerBlocks(cell.blocks, cellElement.children, pageSize, `${blockPath}.rows[${rowIndex}].cells[${cellIndex}].blocks`, rels, pkg, onMathDiagnostic);
|
|
119
179
|
return blocks === cell.blocks ? cell : {
|
|
120
180
|
...cell,
|
|
121
181
|
blocks
|
|
@@ -131,11 +191,12 @@ function rebuildTable(table, tblElement, pageSize, blockPath, onMathDiagnostic)
|
|
|
131
191
|
rows
|
|
132
192
|
} : table;
|
|
133
193
|
}
|
|
134
|
-
function spliceDocxEmbeddedObjects(sections, bodyChildren, onMathDiagnostic) {
|
|
194
|
+
function spliceDocxEmbeddedObjects(sections, bodyChildren, pkg, onMathDiagnostic) {
|
|
135
195
|
const paragraphElements = [];
|
|
136
196
|
collectBodyParagraphs(bodyChildren, paragraphElements);
|
|
137
197
|
const tableElements = [];
|
|
138
198
|
collectBodyTables(bodyChildren, tableElements);
|
|
199
|
+
const rels = resolveRelationships(pkg, DOCUMENT_PART_PATH);
|
|
139
200
|
let paragraphOrdinal = 0;
|
|
140
201
|
let tableOrdinal = 0;
|
|
141
202
|
const out = [];
|
|
@@ -147,7 +208,7 @@ function spliceDocxEmbeddedObjects(sections, bodyChildren, onMathDiagnostic) {
|
|
|
147
208
|
const paragraph = paragraphElements[paragraphOrdinal];
|
|
148
209
|
paragraphOrdinal += 1;
|
|
149
210
|
if (paragraph === void 0) return block;
|
|
150
|
-
const { placements: paragraphPlacements, consume } = paragraphEmbeddings(block, paragraph, blockIndex, onMathDiagnostic);
|
|
211
|
+
const { placements: paragraphPlacements, consume } = paragraphEmbeddings(block, paragraph, blockIndex, rels, pkg, onMathDiagnostic);
|
|
151
212
|
if (paragraphPlacements.length > 0) placements.push(...paragraphPlacements);
|
|
152
213
|
if (consume) consumedIndices.add(blockIndex);
|
|
153
214
|
return block;
|
|
@@ -156,7 +217,7 @@ function spliceDocxEmbeddedObjects(sections, bodyChildren, onMathDiagnostic) {
|
|
|
156
217
|
const tableElement = tableElements[tableOrdinal];
|
|
157
218
|
tableOrdinal += 1;
|
|
158
219
|
if (tableElement === void 0) return block;
|
|
159
|
-
return rebuildTable(block, tableElement, section.pageSize, `sections[${sectionIndex}].blocks`, onMathDiagnostic);
|
|
220
|
+
return rebuildTable(block, tableElement, section.pageSize, `sections[${sectionIndex}].blocks`, rels, pkg, onMathDiagnostic);
|
|
160
221
|
}
|
|
161
222
|
return block;
|
|
162
223
|
});
|
package/dist/ooxml/docx/read.cjs
CHANGED
|
@@ -10,7 +10,7 @@ function documentBody(pkg) {
|
|
|
10
10
|
function readDocxContent(pkg, options) {
|
|
11
11
|
const docxDoc = (0, ooxml_js.readDocxContent)(pkg);
|
|
12
12
|
const body = documentBody(pkg);
|
|
13
|
-
const sections = body === void 0 ? docxDoc.sections : require_ooxml_docx_embedded_objects.spliceDocxEmbeddedObjects(docxDoc.sections, body.children, options?.onMathDiagnostic);
|
|
13
|
+
const sections = body === void 0 ? docxDoc.sections : require_ooxml_docx_embedded_objects.spliceDocxEmbeddedObjects(docxDoc.sections, body.children, pkg, options?.onMathDiagnostic);
|
|
14
14
|
return {
|
|
15
15
|
kind: "wordprocessing",
|
|
16
16
|
metadata: { ...docxDoc.metadata },
|
package/dist/ooxml/docx/read.js
CHANGED
|
@@ -9,7 +9,7 @@ function documentBody(pkg) {
|
|
|
9
9
|
function readDocxContent(pkg, options) {
|
|
10
10
|
const docxDoc = readDocxContent$1(pkg);
|
|
11
11
|
const body = documentBody(pkg);
|
|
12
|
-
const sections = body === void 0 ? docxDoc.sections : spliceDocxEmbeddedObjects(docxDoc.sections, body.children, options?.onMathDiagnostic);
|
|
12
|
+
const sections = body === void 0 ? docxDoc.sections : spliceDocxEmbeddedObjects(docxDoc.sections, body.children, pkg, options?.onMathDiagnostic);
|
|
13
13
|
return {
|
|
14
14
|
kind: "wordprocessing",
|
|
15
15
|
metadata: { ...docxDoc.metadata },
|