js.documents 7.2.5 → 7.3.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/index.cjs +1 -1
- package/dist/index.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/package.json +1 -1
package/dist/codecs/read.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_model_bytes = require("../model/bytes.cjs");
|
|
3
3
|
const require_markdown_read = require("../markdown/read.cjs");
|
|
4
|
+
const require_ppt_read = require("../ppt/read.cjs");
|
|
4
5
|
const require_ooxml_docx_read = require("../ooxml/docx/read.cjs");
|
|
5
6
|
const require_ooxml_pptx_read = require("../ooxml/pptx/read.cjs");
|
|
6
7
|
const require_odf_formula_read = require("../odf/formula/read.cjs");
|
|
@@ -13,7 +14,6 @@ const require_csv_text = require("../csv/text.cjs");
|
|
|
13
14
|
const require_csv_read = require("../csv/read.cjs");
|
|
14
15
|
const require_svg_text = require("../svg/text.cjs");
|
|
15
16
|
const require_svg_read = require("../svg/read.cjs");
|
|
16
|
-
const require_ppt_read = require("../ppt/read.cjs");
|
|
17
17
|
const require_ports_abort = require("../ports/abort.cjs");
|
|
18
18
|
const require_package_codec = require("../package-codec.cjs");
|
|
19
19
|
let ooxml_js = require("ooxml.js");
|
package/dist/codecs/read.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { requireArrayBufferBytes } from "../model/bytes.js";
|
|
2
2
|
import { readMarkdownContent } from "../markdown/read.js";
|
|
3
|
+
import { readPptContent } from "../ppt/read.js";
|
|
3
4
|
import { readDocxContent as readDocxContent$1 } from "../ooxml/docx/read.js";
|
|
4
5
|
import { readPptxContent as readPptxContent$1 } from "../ooxml/pptx/read.js";
|
|
5
6
|
import { readOdfFormulaContent } from "../odf/formula/read.js";
|
|
@@ -12,7 +13,6 @@ import { decodeCsvText } from "../csv/text.js";
|
|
|
12
13
|
import { readCsvContent } from "../csv/read.js";
|
|
13
14
|
import { decodeSvgText } from "../svg/text.js";
|
|
14
15
|
import { readSvgContent } from "../svg/read.js";
|
|
15
|
-
import { readPptContent } from "../ppt/read.js";
|
|
16
16
|
import { throwIfAborted } from "../ports/abort.js";
|
|
17
17
|
import { decodeDocumentPackage } from "../package-codec.js";
|
|
18
18
|
import { readXlsxContent } from "ooxml.js";
|
|
@@ -8,6 +8,7 @@ const require_edit_ods_content = require("../edit/ods/content.cjs");
|
|
|
8
8
|
const require_edit_odg_content = require("../edit/odg/content.cjs");
|
|
9
9
|
const require_markdown_write = require("../markdown/write.cjs");
|
|
10
10
|
const require_markdown_read = require("../markdown/read.cjs");
|
|
11
|
+
const require_ppt_read = require("../ppt/read.cjs");
|
|
11
12
|
const require_ooxml_docx_read = require("../ooxml/docx/read.cjs");
|
|
12
13
|
const require_ooxml_pptx_read = require("../ooxml/pptx/read.cjs");
|
|
13
14
|
const require_odf_odt_read = require("../odf/odt/read.cjs");
|
|
@@ -21,7 +22,6 @@ const require_csv_write = require("../csv/write.cjs");
|
|
|
21
22
|
const require_svg_text = require("../svg/text.cjs");
|
|
22
23
|
const require_svg_read = require("../svg/read.cjs");
|
|
23
24
|
const require_svg_write = require("../svg/write.cjs");
|
|
24
|
-
const require_ppt_read = require("../ppt/read.cjs");
|
|
25
25
|
const require_ppt_write = require("../ppt/write.cjs");
|
|
26
26
|
const require_ports_abort = require("../ports/abort.cjs");
|
|
27
27
|
const require_layout_reconstruct = require("../layout/reconstruct.cjs");
|
|
@@ -7,6 +7,7 @@ import { buildOdsPackage } from "../edit/ods/content.js";
|
|
|
7
7
|
import { buildOdgPackage } from "../edit/odg/content.js";
|
|
8
8
|
import { buildMarkdownText } from "../markdown/write.js";
|
|
9
9
|
import { readMarkdownContent as readMarkdownContent$1 } from "../markdown/read.js";
|
|
10
|
+
import { readPptContent } from "../ppt/read.js";
|
|
10
11
|
import { readDocxContent as readDocxContent$1 } from "../ooxml/docx/read.js";
|
|
11
12
|
import { readPptxContent as readPptxContent$1 } from "../ooxml/pptx/read.js";
|
|
12
13
|
import { readOdtContent as readOdtContent$1 } from "../odf/odt/read.js";
|
|
@@ -20,7 +21,6 @@ import { buildCsvText } from "../csv/write.js";
|
|
|
20
21
|
import { decodeSvgText, encodeSvgText } from "../svg/text.js";
|
|
21
22
|
import { readSvgContent } from "../svg/read.js";
|
|
22
23
|
import { buildSvgText } from "../svg/write.js";
|
|
23
|
-
import { readPptContent } from "../ppt/read.js";
|
|
24
24
|
import { writePptContent } from "../ppt/write.js";
|
|
25
25
|
import { throwIfAborted } from "../ports/abort.js";
|
|
26
26
|
import { reconstructDrawing, reconstructPresentation, reconstructSpreadsheet, reconstructWordprocessing } from "../layout/reconstruct.js";
|
package/dist/index.cjs
CHANGED
|
@@ -57,6 +57,7 @@ const require_fonts_registry = require("./fonts/registry.cjs");
|
|
|
57
57
|
const require_omml_read = require("./omml/read.cjs");
|
|
58
58
|
const require_latex_diagnostics = require("./latex/diagnostics.cjs");
|
|
59
59
|
const require_latex_lint = require("./latex/lint.cjs");
|
|
60
|
+
const require_ppt_read = require("./ppt/read.cjs");
|
|
60
61
|
const require_ooxml_docx_read = require("./ooxml/docx/read.cjs");
|
|
61
62
|
const require_ooxml_docx_extras = require("./ooxml/docx/extras.cjs");
|
|
62
63
|
const require_ooxml_pptx_read = require("./ooxml/pptx/read.cjs");
|
|
@@ -75,7 +76,6 @@ const require_svg_text = require("./svg/text.cjs");
|
|
|
75
76
|
const require_svg_read = require("./svg/read.cjs");
|
|
76
77
|
const require_svg_write = require("./svg/write.cjs");
|
|
77
78
|
const require_svg_diagnostics = require("./svg/diagnostics.cjs");
|
|
78
|
-
const require_ppt_read = require("./ppt/read.cjs");
|
|
79
79
|
const require_ppt_write = require("./ppt/write.cjs");
|
|
80
80
|
const require_markdown_render = require("./markdown/render.cjs");
|
|
81
81
|
const require_layout_engine = require("./layout/engine.cjs");
|
package/dist/index.js
CHANGED
|
@@ -56,6 +56,7 @@ import { createDocumentFontRegistry, extractSourceFonts } from "./fonts/registry
|
|
|
56
56
|
import { collectOfficeMathElements, readOfficeMath } from "./omml/read.js";
|
|
57
57
|
import { LATEX_DIAGNOSTIC_CODES, MATH_LINT_CODES } from "./latex/diagnostics.js";
|
|
58
58
|
import { lintMathCoherence } from "./latex/lint.js";
|
|
59
|
+
import { readPptContent } from "./ppt/read.js";
|
|
59
60
|
import { readDocxContent } from "./ooxml/docx/read.js";
|
|
60
61
|
import { readDocxExtras } from "./ooxml/docx/extras.js";
|
|
61
62
|
import { readPptxContent } from "./ooxml/pptx/read.js";
|
|
@@ -74,7 +75,6 @@ import { SvgInvalidUtf8Error, decodeSvgText, encodeSvgText } from "./svg/text.js
|
|
|
74
75
|
import { SvgMissingRootElementError, readSvgContent } from "./svg/read.js";
|
|
75
76
|
import { SvgMultiPageNotSpecifiedError, SvgPageNotFoundError, SvgUnsupportedDocumentKindError, buildSvgText } from "./svg/write.js";
|
|
76
77
|
import { SVG_DIAGNOSTIC_CODES } from "./svg/diagnostics.js";
|
|
77
|
-
import { readPptContent } from "./ppt/read.js";
|
|
78
78
|
import { writePptContent } from "./ppt/write.js";
|
|
79
79
|
import { MarkdownRenderDiagnosticCodes, renderContentDocumentToMarkdown } from "./markdown/render.js";
|
|
80
80
|
import { convertWordprocessingToLayout } from "./layout/engine.js";
|
|
@@ -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 },
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_ppt_read = require("../ppt/read.cjs");
|
|
3
|
+
let doc_codec = require("doc-codec");
|
|
4
|
+
let xls_codec = require("xls-codec");
|
|
5
|
+
let archive_codec = require("archive-codec");
|
|
6
|
+
//#region src/ooxml/legacy-embedded.ts
|
|
7
|
+
function decodeLegacyEmbeddedObject(bytes) {
|
|
8
|
+
if (!(0, archive_codec.isCompoundFile)(bytes)) return;
|
|
9
|
+
try {
|
|
10
|
+
return {
|
|
11
|
+
objectKind: "wordprocessing",
|
|
12
|
+
document: (0, doc_codec.readDocContent)(bytes)
|
|
13
|
+
};
|
|
14
|
+
} catch {}
|
|
15
|
+
try {
|
|
16
|
+
return {
|
|
17
|
+
objectKind: "spreadsheet",
|
|
18
|
+
document: (0, xls_codec.readXlsContent)(bytes)
|
|
19
|
+
};
|
|
20
|
+
} catch {}
|
|
21
|
+
try {
|
|
22
|
+
return {
|
|
23
|
+
objectKind: "presentation",
|
|
24
|
+
document: require_ppt_read.readPptContent(bytes)
|
|
25
|
+
};
|
|
26
|
+
} catch {}
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
exports.decodeLegacyEmbeddedObject = decodeLegacyEmbeddedObject;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ContentDocument, ContentEmbeddedObjectKind } from "document-schema.js";
|
|
2
|
+
//#region src/ooxml/legacy-embedded.d.ts
|
|
3
|
+
interface LegacyEmbeddedPayload {
|
|
4
|
+
readonly objectKind: Extract<ContentEmbeddedObjectKind, "wordprocessing" | "spreadsheet" | "presentation">;
|
|
5
|
+
readonly document: ContentDocument;
|
|
6
|
+
}
|
|
7
|
+
declare function decodeLegacyEmbeddedObject(bytes: Uint8Array<ArrayBuffer>): LegacyEmbeddedPayload | undefined;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { LegacyEmbeddedPayload, decodeLegacyEmbeddedObject };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ContentDocument, ContentEmbeddedObjectKind } from "document-schema.js";
|
|
2
|
+
//#region src/ooxml/legacy-embedded.d.ts
|
|
3
|
+
interface LegacyEmbeddedPayload {
|
|
4
|
+
readonly objectKind: Extract<ContentEmbeddedObjectKind, "wordprocessing" | "spreadsheet" | "presentation">;
|
|
5
|
+
readonly document: ContentDocument;
|
|
6
|
+
}
|
|
7
|
+
declare function decodeLegacyEmbeddedObject(bytes: Uint8Array<ArrayBuffer>): LegacyEmbeddedPayload | undefined;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { LegacyEmbeddedPayload, decodeLegacyEmbeddedObject };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { readPptContent } from "../ppt/read.js";
|
|
2
|
+
import { readDocContent } from "doc-codec";
|
|
3
|
+
import { readXlsContent } from "xls-codec";
|
|
4
|
+
import { isCompoundFile } from "archive-codec";
|
|
5
|
+
//#region src/ooxml/legacy-embedded.ts
|
|
6
|
+
function decodeLegacyEmbeddedObject(bytes) {
|
|
7
|
+
if (!isCompoundFile(bytes)) return;
|
|
8
|
+
try {
|
|
9
|
+
return {
|
|
10
|
+
objectKind: "wordprocessing",
|
|
11
|
+
document: readDocContent(bytes)
|
|
12
|
+
};
|
|
13
|
+
} catch {}
|
|
14
|
+
try {
|
|
15
|
+
return {
|
|
16
|
+
objectKind: "spreadsheet",
|
|
17
|
+
document: readXlsContent(bytes)
|
|
18
|
+
};
|
|
19
|
+
} catch {}
|
|
20
|
+
try {
|
|
21
|
+
return {
|
|
22
|
+
objectKind: "presentation",
|
|
23
|
+
document: readPptContent(bytes)
|
|
24
|
+
};
|
|
25
|
+
} catch {}
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
export { decodeLegacyEmbeddedObject };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_ooxml_legacy_embedded = require("../legacy-embedded.cjs");
|
|
3
|
+
let ooxml_js = require("ooxml.js");
|
|
4
|
+
//#region src/ooxml/pptx/legacy-embedded.ts
|
|
5
|
+
const OLE_GRAPHIC_URI = "http://schemas.openxmlformats.org/presentationml/2006/ole";
|
|
6
|
+
function collectLegacyOleShapes(children, state, out) {
|
|
7
|
+
for (const node of children) {
|
|
8
|
+
if (node.type !== "element") continue;
|
|
9
|
+
if (node.tag === "p:sp" || node.tag === "p:pic") state.shapeIndex += 1;
|
|
10
|
+
else if (node.tag === "p:graphicFrame") {
|
|
11
|
+
const shapeIndex = state.shapeIndex;
|
|
12
|
+
state.shapeIndex += 1;
|
|
13
|
+
const graphic = (0, ooxml_js.childrenWithTag)(node, "a:graphic")[0];
|
|
14
|
+
const graphicData = graphic === void 0 ? void 0 : (0, ooxml_js.childrenWithTag)(graphic, "a:graphicData")[0];
|
|
15
|
+
if (graphicData !== void 0 && (0, ooxml_js.attr)(graphicData, "uri") === OLE_GRAPHIC_URI) {
|
|
16
|
+
const oleObj = (0, ooxml_js.elementsWithTag)([graphicData], "p:oleObj")[0];
|
|
17
|
+
if (oleObj !== void 0) out.push({
|
|
18
|
+
shapeIndex,
|
|
19
|
+
oleObj
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
} else if (node.tag === "p:grpSp") collectLegacyOleShapes(node.children, state, out);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function spliceSlideLegacyEmbeddedObjects(slide, spTreeChildren, slideRels, pkg) {
|
|
26
|
+
const state = { shapeIndex: 0 };
|
|
27
|
+
const found = [];
|
|
28
|
+
collectLegacyOleShapes(spTreeChildren, state, found);
|
|
29
|
+
if (found.length === 0) return slide;
|
|
30
|
+
const shapes = [...slide.shapes];
|
|
31
|
+
for (const { shapeIndex, oleObj } of found) {
|
|
32
|
+
const shape = shapes[shapeIndex];
|
|
33
|
+
if (shape === void 0) continue;
|
|
34
|
+
const rId = (0, ooxml_js.attr)(oleObj, "r:id");
|
|
35
|
+
const rel = rId === void 0 ? void 0 : slideRels.get(rId);
|
|
36
|
+
const payloadPart = rel === void 0 ? void 0 : pkg.parts[rel.target];
|
|
37
|
+
if (payloadPart?.kind !== "binary") continue;
|
|
38
|
+
const payload = require_ooxml_legacy_embedded.decodeLegacyEmbeddedObject((0, ooxml_js.base64ToBytes)(payloadPart.base64));
|
|
39
|
+
if (payload === void 0) continue;
|
|
40
|
+
shapes[shapeIndex] = {
|
|
41
|
+
...shape,
|
|
42
|
+
blocks: [...shape.blocks, {
|
|
43
|
+
kind: "embeddedObject",
|
|
44
|
+
objectKind: payload.objectKind,
|
|
45
|
+
document: payload.document,
|
|
46
|
+
frame: shape.frame
|
|
47
|
+
}]
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
...slide,
|
|
52
|
+
shapes
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
//#endregion
|
|
56
|
+
exports.spliceSlideLegacyEmbeddedObjects = spliceSlideLegacyEmbeddedObjects;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ContentSlide } from "document-schema.js";
|
|
2
|
+
import { Package, Relationship, XmlNode } from "ooxml.js";
|
|
3
|
+
//#region src/ooxml/pptx/legacy-embedded.d.ts
|
|
4
|
+
declare function spliceSlideLegacyEmbeddedObjects(slide: ContentSlide, spTreeChildren: readonly XmlNode[], slideRels: ReadonlyMap<string, Relationship>, pkg: Package): ContentSlide;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { spliceSlideLegacyEmbeddedObjects };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Package, Relationship, XmlNode } from "ooxml.js";
|
|
2
|
+
import { ContentSlide } from "document-schema.js";
|
|
3
|
+
//#region src/ooxml/pptx/legacy-embedded.d.ts
|
|
4
|
+
declare function spliceSlideLegacyEmbeddedObjects(slide: ContentSlide, spTreeChildren: readonly XmlNode[], slideRels: ReadonlyMap<string, Relationship>, pkg: Package): ContentSlide;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { spliceSlideLegacyEmbeddedObjects };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { decodeLegacyEmbeddedObject } from "../legacy-embedded.js";
|
|
2
|
+
import { attr, base64ToBytes, childrenWithTag, elementsWithTag } from "ooxml.js";
|
|
3
|
+
//#region src/ooxml/pptx/legacy-embedded.ts
|
|
4
|
+
const OLE_GRAPHIC_URI = "http://schemas.openxmlformats.org/presentationml/2006/ole";
|
|
5
|
+
function collectLegacyOleShapes(children, state, out) {
|
|
6
|
+
for (const node of children) {
|
|
7
|
+
if (node.type !== "element") continue;
|
|
8
|
+
if (node.tag === "p:sp" || node.tag === "p:pic") state.shapeIndex += 1;
|
|
9
|
+
else if (node.tag === "p:graphicFrame") {
|
|
10
|
+
const shapeIndex = state.shapeIndex;
|
|
11
|
+
state.shapeIndex += 1;
|
|
12
|
+
const graphic = childrenWithTag(node, "a:graphic")[0];
|
|
13
|
+
const graphicData = graphic === void 0 ? void 0 : childrenWithTag(graphic, "a:graphicData")[0];
|
|
14
|
+
if (graphicData !== void 0 && attr(graphicData, "uri") === OLE_GRAPHIC_URI) {
|
|
15
|
+
const oleObj = elementsWithTag([graphicData], "p:oleObj")[0];
|
|
16
|
+
if (oleObj !== void 0) out.push({
|
|
17
|
+
shapeIndex,
|
|
18
|
+
oleObj
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
} else if (node.tag === "p:grpSp") collectLegacyOleShapes(node.children, state, out);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function spliceSlideLegacyEmbeddedObjects(slide, spTreeChildren, slideRels, pkg) {
|
|
25
|
+
const state = { shapeIndex: 0 };
|
|
26
|
+
const found = [];
|
|
27
|
+
collectLegacyOleShapes(spTreeChildren, state, found);
|
|
28
|
+
if (found.length === 0) return slide;
|
|
29
|
+
const shapes = [...slide.shapes];
|
|
30
|
+
for (const { shapeIndex, oleObj } of found) {
|
|
31
|
+
const shape = shapes[shapeIndex];
|
|
32
|
+
if (shape === void 0) continue;
|
|
33
|
+
const rId = attr(oleObj, "r:id");
|
|
34
|
+
const rel = rId === void 0 ? void 0 : slideRels.get(rId);
|
|
35
|
+
const payloadPart = rel === void 0 ? void 0 : pkg.parts[rel.target];
|
|
36
|
+
if (payloadPart?.kind !== "binary") continue;
|
|
37
|
+
const payload = decodeLegacyEmbeddedObject(base64ToBytes(payloadPart.base64));
|
|
38
|
+
if (payload === void 0) continue;
|
|
39
|
+
shapes[shapeIndex] = {
|
|
40
|
+
...shape,
|
|
41
|
+
blocks: [...shape.blocks, {
|
|
42
|
+
kind: "embeddedObject",
|
|
43
|
+
objectKind: payload.objectKind,
|
|
44
|
+
document: payload.document,
|
|
45
|
+
frame: shape.frame
|
|
46
|
+
}]
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
...slide,
|
|
51
|
+
shapes
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
//#endregion
|
|
55
|
+
export { spliceSlideLegacyEmbeddedObjects };
|
package/dist/ooxml/pptx/read.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_ooxml_pptx_formula = require("./formula.cjs");
|
|
3
3
|
const require_ooxml_pptx_vector = require("./vector.cjs");
|
|
4
|
+
const require_ooxml_pptx_legacy_embedded = require("./legacy-embedded.cjs");
|
|
4
5
|
let ooxml_js = require("ooxml.js");
|
|
5
6
|
//#region src/ooxml/pptx/read.ts
|
|
6
7
|
const PRESENTATION_PART = "ppt/presentation.xml";
|
|
@@ -23,12 +24,14 @@ function readPptxContent(pkg, options) {
|
|
|
23
24
|
const slidePaths = slidePathsInOrder(pkg);
|
|
24
25
|
const slides = pptxDoc.slides.map((slide, slideIndex) => {
|
|
25
26
|
const slidePath = slidePaths[slideIndex];
|
|
26
|
-
|
|
27
|
+
if (slidePath === void 0) return slide;
|
|
28
|
+
const slideRoot = (0, ooxml_js.rootElement)(pkg.parts[slidePath]);
|
|
27
29
|
const cSld = slideRoot === void 0 ? void 0 : (0, ooxml_js.childrenWithTag)(slideRoot, "p:cSld")[0];
|
|
28
30
|
const spTree = cSld === void 0 ? void 0 : (0, ooxml_js.childrenWithTag)(cSld, "p:spTree")[0];
|
|
29
31
|
if (spTree === void 0) return slide;
|
|
30
32
|
const withFormulas = require_ooxml_pptx_formula.spliceSlideFormulas(slide, slideIndex, spTree.children, options?.onMathDiagnostic);
|
|
31
|
-
|
|
33
|
+
const withLegacyEmbeddings = require_ooxml_pptx_legacy_embedded.spliceSlideLegacyEmbeddedObjects(withFormulas, spTree.children, (0, ooxml_js.resolveRelationships)(pkg, slidePath), pkg);
|
|
34
|
+
return require_ooxml_pptx_vector.collapseVectorShapeRuns(withLegacyEmbeddings, slideIndex, spTree.children);
|
|
32
35
|
});
|
|
33
36
|
return {
|
|
34
37
|
kind: "presentation",
|
package/dist/ooxml/pptx/read.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { spliceSlideFormulas } from "./formula.js";
|
|
2
2
|
import { collapseVectorShapeRuns } from "./vector.js";
|
|
3
|
+
import { spliceSlideLegacyEmbeddedObjects } from "./legacy-embedded.js";
|
|
3
4
|
import { attr, childrenWithTag, readPptxContent as readPptxContent$1, resolveRelationships, rootElement } from "ooxml.js";
|
|
4
5
|
//#region src/ooxml/pptx/read.ts
|
|
5
6
|
const PRESENTATION_PART = "ppt/presentation.xml";
|
|
@@ -22,12 +23,14 @@ function readPptxContent(pkg, options) {
|
|
|
22
23
|
const slidePaths = slidePathsInOrder(pkg);
|
|
23
24
|
const slides = pptxDoc.slides.map((slide, slideIndex) => {
|
|
24
25
|
const slidePath = slidePaths[slideIndex];
|
|
25
|
-
|
|
26
|
+
if (slidePath === void 0) return slide;
|
|
27
|
+
const slideRoot = rootElement(pkg.parts[slidePath]);
|
|
26
28
|
const cSld = slideRoot === void 0 ? void 0 : childrenWithTag(slideRoot, "p:cSld")[0];
|
|
27
29
|
const spTree = cSld === void 0 ? void 0 : childrenWithTag(cSld, "p:spTree")[0];
|
|
28
30
|
if (spTree === void 0) return slide;
|
|
29
31
|
const withFormulas = spliceSlideFormulas(slide, slideIndex, spTree.children, options?.onMathDiagnostic);
|
|
30
|
-
|
|
32
|
+
const withLegacyEmbeddings = spliceSlideLegacyEmbeddedObjects(withFormulas, spTree.children, resolveRelationships(pkg, slidePath), pkg);
|
|
33
|
+
return collapseVectorShapeRuns(withLegacyEmbeddings, slideIndex, spTree.children);
|
|
31
34
|
});
|
|
32
35
|
return {
|
|
33
36
|
kind: "presentation",
|
package/package.json
CHANGED