documents.js 1.67.16 → 1.70.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/README.md +3 -3
- package/dist/color-BHhGSqAh.d.ts +2 -0
- package/dist/edit/docx/content.cjs +6 -1
- package/dist/edit/docx/content.d.cts +2 -0
- package/dist/edit/docx/content.d.ts +2 -0
- package/dist/edit/docx/content.js +7 -2
- package/dist/edit/docx/editor.cjs +6 -2
- package/dist/edit/docx/editor.d.cts +6 -2
- package/dist/edit/docx/editor.d.ts +6 -2
- package/dist/edit/docx/editor.js +6 -2
- package/dist/edit/docx/paragraph.d.ts +1 -1
- package/dist/edit/docx/props.d.ts +1 -1
- package/dist/edit/docx/run.d.ts +1 -1
- package/dist/edit/docx/scaffold.cjs +5 -2
- package/dist/edit/docx/scaffold.d.cts +6 -2
- package/dist/edit/docx/scaffold.d.ts +6 -2
- package/dist/edit/docx/scaffold.js +5 -2
- package/dist/edit/drawingml/vector.cjs +145 -0
- package/dist/edit/drawingml/vector.d.cts +3 -2
- package/dist/edit/drawingml/vector.d.ts +3 -2
- package/dist/edit/drawingml/vector.js +147 -3
- package/dist/edit/odg/content.cjs +7 -2
- package/dist/edit/odg/content.d.cts +6 -2
- package/dist/edit/odg/content.d.ts +6 -2
- package/dist/edit/odg/content.js +8 -3
- package/dist/edit/odg/editor.cjs +6 -2
- package/dist/edit/odg/editor.d.cts +6 -2
- package/dist/edit/odg/editor.d.ts +6 -2
- package/dist/edit/odg/editor.js +6 -2
- package/dist/edit/odg/page.d.ts +1 -1
- package/dist/edit/odg/scaffold.cjs +17 -4
- package/dist/edit/odg/scaffold.d.cts +6 -2
- package/dist/edit/odg/scaffold.d.ts +6 -2
- package/dist/edit/odg/scaffold.js +18 -5
- package/dist/edit/odp/content.cjs +7 -2
- package/dist/edit/odp/content.d.cts +6 -2
- package/dist/edit/odp/content.d.ts +6 -2
- package/dist/edit/odp/content.js +8 -3
- package/dist/edit/odp/editor.cjs +6 -2
- package/dist/edit/odp/editor.d.cts +6 -2
- package/dist/edit/odp/editor.d.ts +6 -2
- package/dist/edit/odp/editor.js +6 -2
- package/dist/edit/odp/scaffold.cjs +17 -4
- package/dist/edit/odp/scaffold.d.cts +6 -2
- package/dist/edit/odp/scaffold.d.ts +6 -2
- package/dist/edit/odp/scaffold.js +18 -5
- package/dist/edit/odp/shape.d.ts +1 -1
- package/dist/edit/odp/slide.d.ts +2 -2
- package/dist/edit/ods/content.cjs +7 -2
- package/dist/edit/ods/content.d.cts +6 -2
- package/dist/edit/ods/content.d.ts +6 -2
- package/dist/edit/ods/content.js +8 -3
- package/dist/edit/ods/editor.cjs +6 -2
- package/dist/edit/ods/editor.d.cts +6 -2
- package/dist/edit/ods/editor.d.ts +6 -2
- package/dist/edit/ods/editor.js +6 -2
- package/dist/edit/ods/scaffold.cjs +17 -4
- package/dist/edit/ods/scaffold.d.cts +6 -2
- package/dist/edit/ods/scaffold.d.ts +6 -2
- package/dist/edit/ods/scaffold.js +18 -5
- package/dist/edit/odt/content.cjs +7 -2
- package/dist/edit/odt/content.d.cts +6 -2
- package/dist/edit/odt/content.d.ts +8 -4
- package/dist/edit/odt/content.js +8 -3
- package/dist/edit/odt/editor.cjs +6 -2
- package/dist/edit/odt/editor.d.cts +6 -2
- package/dist/edit/odt/editor.d.ts +9 -5
- package/dist/edit/odt/editor.js +6 -2
- package/dist/edit/odt/list.d.ts +1 -1
- package/dist/edit/odt/paragraph.d.ts +1 -1
- package/dist/edit/odt/run.d.ts +1 -1
- package/dist/edit/odt/scaffold.cjs +17 -4
- package/dist/edit/odt/scaffold.d.cts +6 -2
- package/dist/edit/odt/scaffold.d.ts +6 -2
- package/dist/edit/odt/scaffold.js +18 -5
- package/dist/edit/odt/table.d.ts +1 -1
- package/dist/edit/pptx/content.cjs +7 -2
- package/dist/edit/pptx/content.d.cts +6 -2
- package/dist/edit/pptx/content.d.ts +6 -2
- package/dist/edit/pptx/content.js +8 -3
- package/dist/edit/pptx/editor.cjs +6 -2
- package/dist/edit/pptx/editor.d.cts +6 -2
- package/dist/edit/pptx/editor.d.ts +6 -2
- package/dist/edit/pptx/editor.js +6 -2
- package/dist/edit/pptx/scaffold.cjs +3 -1
- package/dist/edit/pptx/scaffold.d.cts +6 -2
- package/dist/edit/pptx/scaffold.d.ts +6 -2
- package/dist/edit/pptx/scaffold.js +3 -1
- package/dist/edit/pptx/shape.d.ts +1 -1
- package/dist/edit/pptx/slide.d.ts +2 -2
- package/dist/edit/pptx/table.d.ts +1 -1
- package/dist/formula-B_4mdCuK.d.ts +12 -0
- package/dist/formula-DFc2Ofsk.d.cts +12 -0
- package/dist/index.cjs +3 -1
- package/dist/index.d.cts +20 -13
- package/dist/index.d.ts +29 -22
- package/dist/index.js +3 -2
- package/dist/layout/sheets.js +3 -3
- package/dist/{list-nlhN5bat.d.ts → list-BJVehfU8.d.ts} +1 -1
- package/dist/mathml/layout.cjs +42 -3
- package/dist/mathml/layout.js +42 -3
- package/dist/mathml/operators.cjs +12 -0
- package/dist/mathml/operators.js +12 -0
- package/dist/model/block-splice.cjs +18 -0
- package/dist/model/block-splice.d.cts +9 -0
- package/dist/model/block-splice.d.ts +9 -0
- package/dist/model/block-splice.js +17 -0
- package/dist/model/color.d.ts +1 -1
- package/dist/model/metadata.cjs +13 -0
- package/dist/model/metadata.d.cts +6 -0
- package/dist/model/metadata.d.ts +6 -0
- package/dist/model/metadata.js +12 -0
- package/dist/odf/odp/read.cjs +38 -0
- package/dist/odf/odp/read.js +38 -0
- package/dist/odf/odt/read.cjs +100 -35
- package/dist/odf/odt/read.js +100 -35
- package/dist/odf/vector/detect.cjs +52 -0
- package/dist/odf/vector/detect.d.cts +12 -0
- package/dist/odf/vector/detect.d.ts +12 -0
- package/dist/odf/vector/detect.js +49 -0
- package/dist/ooxml/docx/embedded-objects.cjs +92 -0
- package/dist/ooxml/docx/embedded-objects.d.cts +7 -0
- package/dist/ooxml/docx/embedded-objects.d.ts +7 -0
- package/dist/ooxml/docx/embedded-objects.js +91 -0
- package/dist/ooxml/docx/formula.cjs +3 -58
- package/dist/ooxml/docx/formula.d.cts +2 -2
- package/dist/ooxml/docx/formula.d.ts +2 -2
- package/dist/ooxml/docx/formula.js +1 -58
- package/dist/ooxml/docx/read.cjs +2 -2
- package/dist/ooxml/docx/read.d.cts +1 -1
- package/dist/ooxml/docx/read.d.ts +1 -1
- package/dist/ooxml/docx/read.js +2 -2
- package/dist/ooxml/docx/vector.cjs +63 -0
- package/dist/ooxml/docx/vector.d.cts +10 -0
- package/dist/ooxml/docx/vector.d.ts +10 -0
- package/dist/ooxml/docx/vector.js +62 -0
- package/dist/ooxml/pptx/read.cjs +25 -1
- package/dist/ooxml/pptx/read.js +26 -2
- package/dist/ooxml/pptx/vector.cjs +96 -0
- package/dist/ooxml/pptx/vector.d.cts +6 -0
- package/dist/ooxml/pptx/vector.d.ts +6 -0
- package/dist/ooxml/pptx/vector.js +95 -0
- package/dist/opc/core-properties.cjs +65 -0
- package/dist/opc/core-properties.d.cts +6 -0
- package/dist/opc/core-properties.d.ts +6 -0
- package/dist/opc/core-properties.js +64 -0
- package/dist/opc/rels.cjs +11 -4
- package/dist/opc/rels.d.cts +2 -1
- package/dist/opc/rels.d.ts +2 -1
- package/dist/opc/rels.js +11 -5
- package/dist/{paragraph-DndYbWuT.d.ts → paragraph-CjtZP77X.d.ts} +1 -1
- package/dist/{run-BhYv2wJf.d.ts → run-DDe7miD5.d.ts} +1 -1
- package/dist/{run-DtrwZwN6.d.ts → run-wB22_F5w.d.ts} +1 -1
- package/dist/{shape-B-TjU_Ej.d.ts → shape-BjX3wlig.d.ts} +1 -1
- package/dist/{shape-XGp__l-J.d.ts → shape-GV8i37zL.d.ts} +2 -2
- package/dist/{table-DQpKafyl.d.ts → table-Db91eorq.d.ts} +1 -1
- package/dist/{table-BHeUmLzZ.d.ts → table-Vf6nCixr.d.ts} +1 -1
- package/package.json +1 -1
- package/dist/color-C98dn-pT.d.ts +0 -2
- package/dist/formula-CgydMiTt.d.ts +0 -10
- package/dist/formula-CiwPw8nY.d.cts +0 -10
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { buildDrawingBlock } from "../../model/embedded-drawing.js";
|
|
2
|
+
import { buildFormulaBlock } from "../../model/formula.js";
|
|
3
|
+
import { collectOfficeMathElements, readOfficeMath } from "../../omml/read.js";
|
|
4
|
+
import { spliceBlocks } from "../../model/block-splice.js";
|
|
5
|
+
import { collectParagraphVectors } from "./vector.js";
|
|
6
|
+
import { PARAGRAPH_NON_CONTENT_TAGS, collectBodyParagraphs, equationFrame } from "./formula.js";
|
|
7
|
+
//#region src/ooxml/docx/embedded-objects.ts
|
|
8
|
+
function isVectorOnlyRun(run, vectors) {
|
|
9
|
+
const elementChildren = run.children.filter((child) => child.type === "element");
|
|
10
|
+
if (elementChildren.length !== 1) return false;
|
|
11
|
+
if (run.children.some((child) => child.type === "text" && child.value.trim().length > 0)) return false;
|
|
12
|
+
return vectors.some((detected) => detected.drawingElement === elementChildren[0]);
|
|
13
|
+
}
|
|
14
|
+
function isEmbeddedObjectOnlyParagraph(paragraph, equations, vectors) {
|
|
15
|
+
if (equations.length === 0 && vectors.length === 0) return false;
|
|
16
|
+
for (const child of paragraph.children) {
|
|
17
|
+
if (child.type === "text") {
|
|
18
|
+
if (child.value.trim().length > 0) return false;
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
if (child.type !== "element") continue;
|
|
22
|
+
if (PARAGRAPH_NON_CONTENT_TAGS.has(child.tag) || equations.includes(child)) continue;
|
|
23
|
+
if (child.tag === "m:oMathPara" && collectOfficeMathElements(child.children).every((math) => equations.includes(math))) continue;
|
|
24
|
+
if (child.tag === "w:r" && isVectorOnlyRun(child, vectors)) continue;
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
function spliceDocxEmbeddedObjects(sections, bodyChildren, onMathDiagnostic) {
|
|
30
|
+
const paragraphElements = [];
|
|
31
|
+
collectBodyParagraphs(bodyChildren, paragraphElements);
|
|
32
|
+
let paragraphOrdinal = 0;
|
|
33
|
+
const out = [];
|
|
34
|
+
for (const [sectionIndex, section] of sections.entries()) {
|
|
35
|
+
const placements = [];
|
|
36
|
+
const consumedIndices = /* @__PURE__ */ new Set();
|
|
37
|
+
section.blocks.forEach((block, blockIndex) => {
|
|
38
|
+
if (block.kind !== "paragraph") return;
|
|
39
|
+
const paragraph = paragraphElements[paragraphOrdinal];
|
|
40
|
+
paragraphOrdinal += 1;
|
|
41
|
+
if (paragraph === void 0) return;
|
|
42
|
+
const equations = collectOfficeMathElements(paragraph.children);
|
|
43
|
+
const vectors = collectParagraphVectors(paragraph);
|
|
44
|
+
if (equations.length === 0 && vectors.length === 0) return;
|
|
45
|
+
const converted = equations.map((equation) => ({
|
|
46
|
+
equation,
|
|
47
|
+
...readOfficeMath(equation)
|
|
48
|
+
}));
|
|
49
|
+
const rendered = converted.filter((result) => result.mathml.length > 0);
|
|
50
|
+
if (rendered.length === 0 && vectors.length === 0) {
|
|
51
|
+
for (const result of converted) for (const diagnostic of result.diagnostics) onMathDiagnostic?.(diagnostic, { sourcePath: block.sourcePath });
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const insertAt = blockIndex + 1;
|
|
55
|
+
if (isEmbeddedObjectOnlyParagraph(paragraph, equations, vectors)) consumedIndices.add(blockIndex);
|
|
56
|
+
for (const result of rendered) placements.push({
|
|
57
|
+
index: insertAt,
|
|
58
|
+
build: (sourcePath) => {
|
|
59
|
+
for (const diagnostic of result.diagnostics) onMathDiagnostic?.(diagnostic, { sourcePath });
|
|
60
|
+
return buildFormulaBlock({ mathml: result.mathml }, equationFrame(result.equation), sourcePath);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
for (const result of converted) {
|
|
64
|
+
if (result.mathml.length > 0) continue;
|
|
65
|
+
for (const diagnostic of result.diagnostics) onMathDiagnostic?.(diagnostic, { sourcePath: block.sourcePath });
|
|
66
|
+
}
|
|
67
|
+
if (vectors.length > 0) {
|
|
68
|
+
const vectorValues = vectors.map((detected) => detected.vector);
|
|
69
|
+
placements.push({
|
|
70
|
+
index: insertAt,
|
|
71
|
+
build: (sourcePath) => ({
|
|
72
|
+
...buildDrawingBlock(section.pageSize, vectorValues),
|
|
73
|
+
sourcePath
|
|
74
|
+
})
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
if (placements.length === 0 && consumedIndices.size === 0) {
|
|
79
|
+
out.push(section);
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
const blocks = spliceBlocks(section.blocks, placements, consumedIndices, (position) => `sections[${sectionIndex}].blocks[${position}]`);
|
|
83
|
+
out.push({
|
|
84
|
+
...section,
|
|
85
|
+
blocks
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
return out;
|
|
89
|
+
}
|
|
90
|
+
//#endregion
|
|
91
|
+
export { spliceDocxEmbeddedObjects };
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_model_formula = require("../../model/formula.cjs");
|
|
3
|
-
const require_omml_read = require("../../omml/read.cjs");
|
|
4
2
|
let ooxml_js = require("ooxml.js");
|
|
5
3
|
//#region src/ooxml/docx/formula.ts
|
|
6
4
|
function collectBodyParagraphs(nodes, out) {
|
|
@@ -25,19 +23,6 @@ const PARAGRAPH_NON_CONTENT_TAGS = /* @__PURE__ */ new Set([
|
|
|
25
23
|
"w:commentRangeStart",
|
|
26
24
|
"w:commentRangeEnd"
|
|
27
25
|
]);
|
|
28
|
-
function isEquationOnlyParagraph(paragraph, equations) {
|
|
29
|
-
for (const child of paragraph.children) {
|
|
30
|
-
if (child.type === "text") {
|
|
31
|
-
if (child.value.trim().length > 0) return false;
|
|
32
|
-
continue;
|
|
33
|
-
}
|
|
34
|
-
if (child.type !== "element") continue;
|
|
35
|
-
if (PARAGRAPH_NON_CONTENT_TAGS.has(child.tag) || equations.includes(child)) continue;
|
|
36
|
-
if (child.tag === "m:oMathPara" && require_omml_read.collectOfficeMathElements(child.children).every((math) => equations.includes(math))) continue;
|
|
37
|
-
return false;
|
|
38
|
-
}
|
|
39
|
-
return true;
|
|
40
|
-
}
|
|
41
26
|
const FRAME_HEIGHT_PER_SIZE_PT = 2;
|
|
42
27
|
const DEFAULT_MATH_SIZE_PT = 11;
|
|
43
28
|
function mathRunSizePt(equation) {
|
|
@@ -63,47 +48,7 @@ function equationFrame(equation) {
|
|
|
63
48
|
heightPt: (mathRunSizePt(equation) ?? DEFAULT_MATH_SIZE_PT) * FRAME_HEIGHT_PER_SIZE_PT
|
|
64
49
|
};
|
|
65
50
|
}
|
|
66
|
-
function spliceDocxFormulas(sections, bodyChildren, onMathDiagnostic) {
|
|
67
|
-
const paragraphElements = [];
|
|
68
|
-
collectBodyParagraphs(bodyChildren, paragraphElements);
|
|
69
|
-
let paragraphOrdinal = 0;
|
|
70
|
-
const out = [];
|
|
71
|
-
for (const [sectionIndex, section] of sections.entries()) {
|
|
72
|
-
const blocks = [];
|
|
73
|
-
for (const block of section.blocks) {
|
|
74
|
-
if (block.kind !== "paragraph") {
|
|
75
|
-
blocks.push(block);
|
|
76
|
-
continue;
|
|
77
|
-
}
|
|
78
|
-
const paragraph = paragraphElements[paragraphOrdinal];
|
|
79
|
-
paragraphOrdinal += 1;
|
|
80
|
-
const equations = paragraph === void 0 ? [] : require_omml_read.collectOfficeMathElements(paragraph.children);
|
|
81
|
-
if (equations.length === 0 || paragraph === void 0) {
|
|
82
|
-
blocks.push(block);
|
|
83
|
-
continue;
|
|
84
|
-
}
|
|
85
|
-
const converted = equations.map((equation) => ({
|
|
86
|
-
equation,
|
|
87
|
-
...require_omml_read.readOfficeMath(equation)
|
|
88
|
-
}));
|
|
89
|
-
if (converted.filter((result) => result.mathml.length > 0).length === 0) {
|
|
90
|
-
blocks.push(block);
|
|
91
|
-
for (const result of converted) for (const diagnostic of result.diagnostics) onMathDiagnostic?.(diagnostic, { sourcePath: block.sourcePath });
|
|
92
|
-
continue;
|
|
93
|
-
}
|
|
94
|
-
if (!isEquationOnlyParagraph(paragraph, equations)) blocks.push(block);
|
|
95
|
-
for (const result of converted) {
|
|
96
|
-
const sourcePath = `sections[${sectionIndex}].blocks[${blocks.length}]`;
|
|
97
|
-
if (result.mathml.length > 0) blocks.push(require_model_formula.buildFormulaBlock({ mathml: result.mathml }, equationFrame(result.equation), sourcePath));
|
|
98
|
-
for (const diagnostic of result.diagnostics) onMathDiagnostic?.(diagnostic, { sourcePath });
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
out.push({
|
|
102
|
-
...section,
|
|
103
|
-
blocks
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
return out;
|
|
107
|
-
}
|
|
108
51
|
//#endregion
|
|
109
|
-
exports.
|
|
52
|
+
exports.PARAGRAPH_NON_CONTENT_TAGS = PARAGRAPH_NON_CONTENT_TAGS;
|
|
53
|
+
exports.collectBodyParagraphs = collectBodyParagraphs;
|
|
54
|
+
exports.equationFrame = equationFrame;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as
|
|
2
|
-
export { OmmlDiagnosticSink,
|
|
1
|
+
import { i as equationFrame, n as PARAGRAPH_NON_CONTENT_TAGS, r as collectBodyParagraphs, t as OmmlDiagnosticSink } from "../../formula-DFc2Ofsk.cjs";
|
|
2
|
+
export { OmmlDiagnosticSink, PARAGRAPH_NON_CONTENT_TAGS, collectBodyParagraphs, equationFrame };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as
|
|
2
|
-
export { OmmlDiagnosticSink,
|
|
1
|
+
import { i as equationFrame, n as PARAGRAPH_NON_CONTENT_TAGS, r as collectBodyParagraphs, t as OmmlDiagnosticSink } from "../../formula-B_4mdCuK.js";
|
|
2
|
+
export { OmmlDiagnosticSink, PARAGRAPH_NON_CONTENT_TAGS, collectBodyParagraphs, equationFrame };
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { buildFormulaBlock } from "../../model/formula.js";
|
|
2
|
-
import { collectOfficeMathElements, readOfficeMath } from "../../omml/read.js";
|
|
3
1
|
import { childrenWithTag } from "ooxml.js";
|
|
4
2
|
//#region src/ooxml/docx/formula.ts
|
|
5
3
|
function collectBodyParagraphs(nodes, out) {
|
|
@@ -24,19 +22,6 @@ const PARAGRAPH_NON_CONTENT_TAGS = /* @__PURE__ */ new Set([
|
|
|
24
22
|
"w:commentRangeStart",
|
|
25
23
|
"w:commentRangeEnd"
|
|
26
24
|
]);
|
|
27
|
-
function isEquationOnlyParagraph(paragraph, equations) {
|
|
28
|
-
for (const child of paragraph.children) {
|
|
29
|
-
if (child.type === "text") {
|
|
30
|
-
if (child.value.trim().length > 0) return false;
|
|
31
|
-
continue;
|
|
32
|
-
}
|
|
33
|
-
if (child.type !== "element") continue;
|
|
34
|
-
if (PARAGRAPH_NON_CONTENT_TAGS.has(child.tag) || equations.includes(child)) continue;
|
|
35
|
-
if (child.tag === "m:oMathPara" && collectOfficeMathElements(child.children).every((math) => equations.includes(math))) continue;
|
|
36
|
-
return false;
|
|
37
|
-
}
|
|
38
|
-
return true;
|
|
39
|
-
}
|
|
40
25
|
const FRAME_HEIGHT_PER_SIZE_PT = 2;
|
|
41
26
|
const DEFAULT_MATH_SIZE_PT = 11;
|
|
42
27
|
function mathRunSizePt(equation) {
|
|
@@ -62,47 +47,5 @@ function equationFrame(equation) {
|
|
|
62
47
|
heightPt: (mathRunSizePt(equation) ?? DEFAULT_MATH_SIZE_PT) * FRAME_HEIGHT_PER_SIZE_PT
|
|
63
48
|
};
|
|
64
49
|
}
|
|
65
|
-
function spliceDocxFormulas(sections, bodyChildren, onMathDiagnostic) {
|
|
66
|
-
const paragraphElements = [];
|
|
67
|
-
collectBodyParagraphs(bodyChildren, paragraphElements);
|
|
68
|
-
let paragraphOrdinal = 0;
|
|
69
|
-
const out = [];
|
|
70
|
-
for (const [sectionIndex, section] of sections.entries()) {
|
|
71
|
-
const blocks = [];
|
|
72
|
-
for (const block of section.blocks) {
|
|
73
|
-
if (block.kind !== "paragraph") {
|
|
74
|
-
blocks.push(block);
|
|
75
|
-
continue;
|
|
76
|
-
}
|
|
77
|
-
const paragraph = paragraphElements[paragraphOrdinal];
|
|
78
|
-
paragraphOrdinal += 1;
|
|
79
|
-
const equations = paragraph === void 0 ? [] : collectOfficeMathElements(paragraph.children);
|
|
80
|
-
if (equations.length === 0 || paragraph === void 0) {
|
|
81
|
-
blocks.push(block);
|
|
82
|
-
continue;
|
|
83
|
-
}
|
|
84
|
-
const converted = equations.map((equation) => ({
|
|
85
|
-
equation,
|
|
86
|
-
...readOfficeMath(equation)
|
|
87
|
-
}));
|
|
88
|
-
if (converted.filter((result) => result.mathml.length > 0).length === 0) {
|
|
89
|
-
blocks.push(block);
|
|
90
|
-
for (const result of converted) for (const diagnostic of result.diagnostics) onMathDiagnostic?.(diagnostic, { sourcePath: block.sourcePath });
|
|
91
|
-
continue;
|
|
92
|
-
}
|
|
93
|
-
if (!isEquationOnlyParagraph(paragraph, equations)) blocks.push(block);
|
|
94
|
-
for (const result of converted) {
|
|
95
|
-
const sourcePath = `sections[${sectionIndex}].blocks[${blocks.length}]`;
|
|
96
|
-
if (result.mathml.length > 0) blocks.push(buildFormulaBlock({ mathml: result.mathml }, equationFrame(result.equation), sourcePath));
|
|
97
|
-
for (const diagnostic of result.diagnostics) onMathDiagnostic?.(diagnostic, { sourcePath });
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
out.push({
|
|
101
|
-
...section,
|
|
102
|
-
blocks
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
return out;
|
|
106
|
-
}
|
|
107
50
|
//#endregion
|
|
108
|
-
export {
|
|
51
|
+
export { PARAGRAPH_NON_CONTENT_TAGS, collectBodyParagraphs, equationFrame };
|
package/dist/ooxml/docx/read.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const
|
|
2
|
+
const require_ooxml_docx_embedded_objects = require("./embedded-objects.cjs");
|
|
3
3
|
let ooxml_js = require("ooxml.js");
|
|
4
4
|
let document_schema_js = require("document-schema.js");
|
|
5
5
|
//#region src/ooxml/docx/read.ts
|
|
@@ -11,7 +11,7 @@ function documentBody(pkg) {
|
|
|
11
11
|
function readDocxContent(pkg, options) {
|
|
12
12
|
const docxDoc = (0, ooxml_js.readDocx)(pkg);
|
|
13
13
|
const body = documentBody(pkg);
|
|
14
|
-
const sections = body === void 0 ? docxDoc.sections :
|
|
14
|
+
const sections = body === void 0 ? docxDoc.sections : require_ooxml_docx_embedded_objects.spliceDocxEmbeddedObjects(docxDoc.sections, body.children, options?.onMathDiagnostic);
|
|
15
15
|
return {
|
|
16
16
|
kind: "wordprocessing",
|
|
17
17
|
formatVersion: document_schema_js.CONTENT_FORMAT_VERSION,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as OmmlDiagnosticSink } from "../../formula-
|
|
1
|
+
import { t as OmmlDiagnosticSink } from "../../formula-DFc2Ofsk.cjs";
|
|
2
2
|
import { ContentDocument } from "document-schema.js";
|
|
3
3
|
import { Package } from "ooxml.js";
|
|
4
4
|
//#region src/ooxml/docx/read.d.ts
|
package/dist/ooxml/docx/read.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { spliceDocxEmbeddedObjects } from "./embedded-objects.js";
|
|
2
2
|
import { childrenWithTag, readDocx, rootElement } from "ooxml.js";
|
|
3
3
|
import { CONTENT_FORMAT_VERSION } from "document-schema.js";
|
|
4
4
|
//#region src/ooxml/docx/read.ts
|
|
@@ -10,7 +10,7 @@ function documentBody(pkg) {
|
|
|
10
10
|
function readDocxContent(pkg, options) {
|
|
11
11
|
const docxDoc = readDocx(pkg);
|
|
12
12
|
const body = documentBody(pkg);
|
|
13
|
-
const sections = body === void 0 ? docxDoc.sections :
|
|
13
|
+
const sections = body === void 0 ? docxDoc.sections : spliceDocxEmbeddedObjects(docxDoc.sections, body.children, options?.onMathDiagnostic);
|
|
14
14
|
return {
|
|
15
15
|
kind: "wordprocessing",
|
|
16
16
|
formatVersion: CONTENT_FORMAT_VERSION,
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_model_units = require("../../model/units.cjs");
|
|
3
|
+
const require_edit_drawingml_vector = require("../../edit/drawingml/vector.cjs");
|
|
4
|
+
let ooxml_js = require("ooxml.js");
|
|
5
|
+
//#region src/ooxml/docx/vector.ts
|
|
6
|
+
const WORDPROCESSING_SHAPE_URI = "http://schemas.microsoft.com/office/word/2010/wordprocessingShape";
|
|
7
|
+
function parseEmuInt(value) {
|
|
8
|
+
if (value === void 0) return;
|
|
9
|
+
const parsed = Number.parseInt(value, 10);
|
|
10
|
+
return Number.isNaN(parsed) ? void 0 : parsed;
|
|
11
|
+
}
|
|
12
|
+
function anchorFrame(anchor) {
|
|
13
|
+
const positionH = (0, ooxml_js.childrenWithTag)(anchor, "wp:positionH")[0];
|
|
14
|
+
const positionV = (0, ooxml_js.childrenWithTag)(anchor, "wp:positionV")[0];
|
|
15
|
+
const extent = (0, ooxml_js.childrenWithTag)(anchor, "wp:extent")[0];
|
|
16
|
+
if (positionH === void 0 || positionV === void 0 || extent === void 0) return;
|
|
17
|
+
if ((0, ooxml_js.attr)(positionH, "relativeFrom") !== "page" || (0, ooxml_js.attr)(positionV, "relativeFrom") !== "page") return;
|
|
18
|
+
const offsetHEl = (0, ooxml_js.childrenWithTag)(positionH, "wp:posOffset")[0];
|
|
19
|
+
const offsetVEl = (0, ooxml_js.childrenWithTag)(positionV, "wp:posOffset")[0];
|
|
20
|
+
if (offsetHEl === void 0 || offsetVEl === void 0) return;
|
|
21
|
+
const xEmu = parseEmuInt((0, ooxml_js.textContent)(offsetHEl).trim());
|
|
22
|
+
const yEmu = parseEmuInt((0, ooxml_js.textContent)(offsetVEl).trim());
|
|
23
|
+
const cx = parseEmuInt((0, ooxml_js.attr)(extent, "cx"));
|
|
24
|
+
const cy = parseEmuInt((0, ooxml_js.attr)(extent, "cy"));
|
|
25
|
+
if (xEmu === void 0 || yEmu === void 0 || cx === void 0 || cy === void 0) return;
|
|
26
|
+
return {
|
|
27
|
+
xPt: require_model_units.emuToPt(xEmu),
|
|
28
|
+
yPt: require_model_units.emuToPt(yEmu),
|
|
29
|
+
widthPt: require_model_units.emuToPt(cx),
|
|
30
|
+
heightPt: require_model_units.emuToPt(cy)
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
function hasRealText(wsp) {
|
|
34
|
+
for (const txbx of (0, ooxml_js.childrenWithTag)(wsp, "wps:txbx")) for (const txBodyContent of (0, ooxml_js.childrenWithTag)(txbx, "w:txbxContent")) if ((0, ooxml_js.textContent)(txBodyContent).trim().length > 0) return true;
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
function collectParagraphVectors(paragraph) {
|
|
38
|
+
const out = [];
|
|
39
|
+
for (const run of (0, ooxml_js.childrenWithTag)(paragraph, "w:r")) for (const drawing of (0, ooxml_js.childrenWithTag)(run, "w:drawing")) for (const anchor of (0, ooxml_js.childrenWithTag)(drawing, "wp:anchor")) {
|
|
40
|
+
const frame = anchorFrame(anchor);
|
|
41
|
+
if (frame === void 0) continue;
|
|
42
|
+
for (const graphic of (0, ooxml_js.childrenWithTag)(anchor, "a:graphic")) for (const graphicData of (0, ooxml_js.childrenWithTag)(graphic, "a:graphicData")) {
|
|
43
|
+
if ((0, ooxml_js.attr)(graphicData, "uri") !== WORDPROCESSING_SHAPE_URI) continue;
|
|
44
|
+
for (const wsp of (0, ooxml_js.childrenWithTag)(graphicData, "wps:wsp")) {
|
|
45
|
+
if (hasRealText(wsp)) continue;
|
|
46
|
+
const spPr = (0, ooxml_js.childrenWithTag)(wsp, "wps:spPr")[0];
|
|
47
|
+
if (spPr === void 0) continue;
|
|
48
|
+
const vector = require_edit_drawingml_vector.readDrawingMlVector(spPr, frame);
|
|
49
|
+
if (vector === void 0) continue;
|
|
50
|
+
out.push({
|
|
51
|
+
drawingElement: drawing,
|
|
52
|
+
vector: {
|
|
53
|
+
...vector,
|
|
54
|
+
paintOrder: out.length
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return out;
|
|
61
|
+
}
|
|
62
|
+
//#endregion
|
|
63
|
+
exports.collectParagraphVectors = collectParagraphVectors;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ContentVector } from "document-schema.js";
|
|
2
|
+
import { XmlElement } from "ooxml.js";
|
|
3
|
+
//#region src/ooxml/docx/vector.d.ts
|
|
4
|
+
interface DetectedParagraphVector {
|
|
5
|
+
readonly drawingElement: XmlElement;
|
|
6
|
+
readonly vector: ContentVector;
|
|
7
|
+
}
|
|
8
|
+
declare function collectParagraphVectors(paragraph: XmlElement): readonly DetectedParagraphVector[];
|
|
9
|
+
//#endregion
|
|
10
|
+
export { DetectedParagraphVector, collectParagraphVectors };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { XmlElement } from "ooxml.js";
|
|
2
|
+
import { ContentVector } from "document-schema.js";
|
|
3
|
+
//#region src/ooxml/docx/vector.d.ts
|
|
4
|
+
interface DetectedParagraphVector {
|
|
5
|
+
readonly drawingElement: XmlElement;
|
|
6
|
+
readonly vector: ContentVector;
|
|
7
|
+
}
|
|
8
|
+
declare function collectParagraphVectors(paragraph: XmlElement): readonly DetectedParagraphVector[];
|
|
9
|
+
//#endregion
|
|
10
|
+
export { DetectedParagraphVector, collectParagraphVectors };
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { emuToPt } from "../../model/units.js";
|
|
2
|
+
import { readDrawingMlVector } from "../../edit/drawingml/vector.js";
|
|
3
|
+
import { attr, childrenWithTag, textContent } from "ooxml.js";
|
|
4
|
+
//#region src/ooxml/docx/vector.ts
|
|
5
|
+
const WORDPROCESSING_SHAPE_URI = "http://schemas.microsoft.com/office/word/2010/wordprocessingShape";
|
|
6
|
+
function parseEmuInt(value) {
|
|
7
|
+
if (value === void 0) return;
|
|
8
|
+
const parsed = Number.parseInt(value, 10);
|
|
9
|
+
return Number.isNaN(parsed) ? void 0 : parsed;
|
|
10
|
+
}
|
|
11
|
+
function anchorFrame(anchor) {
|
|
12
|
+
const positionH = childrenWithTag(anchor, "wp:positionH")[0];
|
|
13
|
+
const positionV = childrenWithTag(anchor, "wp:positionV")[0];
|
|
14
|
+
const extent = childrenWithTag(anchor, "wp:extent")[0];
|
|
15
|
+
if (positionH === void 0 || positionV === void 0 || extent === void 0) return;
|
|
16
|
+
if (attr(positionH, "relativeFrom") !== "page" || attr(positionV, "relativeFrom") !== "page") return;
|
|
17
|
+
const offsetHEl = childrenWithTag(positionH, "wp:posOffset")[0];
|
|
18
|
+
const offsetVEl = childrenWithTag(positionV, "wp:posOffset")[0];
|
|
19
|
+
if (offsetHEl === void 0 || offsetVEl === void 0) return;
|
|
20
|
+
const xEmu = parseEmuInt(textContent(offsetHEl).trim());
|
|
21
|
+
const yEmu = parseEmuInt(textContent(offsetVEl).trim());
|
|
22
|
+
const cx = parseEmuInt(attr(extent, "cx"));
|
|
23
|
+
const cy = parseEmuInt(attr(extent, "cy"));
|
|
24
|
+
if (xEmu === void 0 || yEmu === void 0 || cx === void 0 || cy === void 0) return;
|
|
25
|
+
return {
|
|
26
|
+
xPt: emuToPt(xEmu),
|
|
27
|
+
yPt: emuToPt(yEmu),
|
|
28
|
+
widthPt: emuToPt(cx),
|
|
29
|
+
heightPt: emuToPt(cy)
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function hasRealText(wsp) {
|
|
33
|
+
for (const txbx of childrenWithTag(wsp, "wps:txbx")) for (const txBodyContent of childrenWithTag(txbx, "w:txbxContent")) if (textContent(txBodyContent).trim().length > 0) return true;
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
function collectParagraphVectors(paragraph) {
|
|
37
|
+
const out = [];
|
|
38
|
+
for (const run of childrenWithTag(paragraph, "w:r")) for (const drawing of childrenWithTag(run, "w:drawing")) for (const anchor of childrenWithTag(drawing, "wp:anchor")) {
|
|
39
|
+
const frame = anchorFrame(anchor);
|
|
40
|
+
if (frame === void 0) continue;
|
|
41
|
+
for (const graphic of childrenWithTag(anchor, "a:graphic")) for (const graphicData of childrenWithTag(graphic, "a:graphicData")) {
|
|
42
|
+
if (attr(graphicData, "uri") !== WORDPROCESSING_SHAPE_URI) continue;
|
|
43
|
+
for (const wsp of childrenWithTag(graphicData, "wps:wsp")) {
|
|
44
|
+
if (hasRealText(wsp)) continue;
|
|
45
|
+
const spPr = childrenWithTag(wsp, "wps:spPr")[0];
|
|
46
|
+
if (spPr === void 0) continue;
|
|
47
|
+
const vector = readDrawingMlVector(spPr, frame);
|
|
48
|
+
if (vector === void 0) continue;
|
|
49
|
+
out.push({
|
|
50
|
+
drawingElement: drawing,
|
|
51
|
+
vector: {
|
|
52
|
+
...vector,
|
|
53
|
+
paintOrder: out.length
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return out;
|
|
60
|
+
}
|
|
61
|
+
//#endregion
|
|
62
|
+
export { collectParagraphVectors };
|
package/dist/ooxml/pptx/read.cjs
CHANGED
|
@@ -1,14 +1,38 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_ooxml_pptx_vector = require("./vector.cjs");
|
|
2
3
|
let ooxml_js = require("ooxml.js");
|
|
3
4
|
let document_schema_js = require("document-schema.js");
|
|
4
5
|
//#region src/ooxml/pptx/read.ts
|
|
6
|
+
const PRESENTATION_PART = "ppt/presentation.xml";
|
|
7
|
+
function slidePathsInOrder(pkg) {
|
|
8
|
+
const presentationRoot = (0, ooxml_js.rootElement)(pkg.parts[PRESENTATION_PART]);
|
|
9
|
+
if (presentationRoot === void 0) return [];
|
|
10
|
+
const sldIdLst = (0, ooxml_js.childrenWithTag)(presentationRoot, "p:sldIdLst")[0];
|
|
11
|
+
if (sldIdLst === void 0) return [];
|
|
12
|
+
const rels = (0, ooxml_js.resolveRelationships)(pkg, PRESENTATION_PART);
|
|
13
|
+
const paths = [];
|
|
14
|
+
for (const sldId of (0, ooxml_js.childrenWithTag)(sldIdLst, "p:sldId")) {
|
|
15
|
+
const rId = (0, ooxml_js.attr)(sldId, "r:id");
|
|
16
|
+
const rel = rId === void 0 ? void 0 : rels.get(rId);
|
|
17
|
+
if (rel !== void 0) paths.push(rel.target);
|
|
18
|
+
}
|
|
19
|
+
return paths;
|
|
20
|
+
}
|
|
5
21
|
function readPptxContent(pkg) {
|
|
6
22
|
const pptxDoc = (0, ooxml_js.readPptx)(pkg);
|
|
23
|
+
const slidePaths = slidePathsInOrder(pkg);
|
|
24
|
+
const slides = pptxDoc.slides.map((slide, slideIndex) => {
|
|
25
|
+
const slidePath = slidePaths[slideIndex];
|
|
26
|
+
const slideRoot = slidePath === void 0 ? void 0 : (0, ooxml_js.rootElement)(pkg.parts[slidePath]);
|
|
27
|
+
const cSld = slideRoot === void 0 ? void 0 : (0, ooxml_js.childrenWithTag)(slideRoot, "p:cSld")[0];
|
|
28
|
+
const spTree = cSld === void 0 ? void 0 : (0, ooxml_js.childrenWithTag)(cSld, "p:spTree")[0];
|
|
29
|
+
return spTree === void 0 ? slide : require_ooxml_pptx_vector.collapseVectorShapeRuns(slide, slideIndex, spTree.children);
|
|
30
|
+
});
|
|
7
31
|
return {
|
|
8
32
|
kind: "presentation",
|
|
9
33
|
formatVersion: document_schema_js.CONTENT_FORMAT_VERSION,
|
|
10
34
|
metadata: { ...pptxDoc.metadata },
|
|
11
|
-
slides
|
|
35
|
+
slides
|
|
12
36
|
};
|
|
13
37
|
}
|
|
14
38
|
//#endregion
|
package/dist/ooxml/pptx/read.js
CHANGED
|
@@ -1,13 +1,37 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { collapseVectorShapeRuns } from "./vector.js";
|
|
2
|
+
import { attr, childrenWithTag, readPptx, resolveRelationships, rootElement } from "ooxml.js";
|
|
2
3
|
import { CONTENT_FORMAT_VERSION } from "document-schema.js";
|
|
3
4
|
//#region src/ooxml/pptx/read.ts
|
|
5
|
+
const PRESENTATION_PART = "ppt/presentation.xml";
|
|
6
|
+
function slidePathsInOrder(pkg) {
|
|
7
|
+
const presentationRoot = rootElement(pkg.parts[PRESENTATION_PART]);
|
|
8
|
+
if (presentationRoot === void 0) return [];
|
|
9
|
+
const sldIdLst = childrenWithTag(presentationRoot, "p:sldIdLst")[0];
|
|
10
|
+
if (sldIdLst === void 0) return [];
|
|
11
|
+
const rels = resolveRelationships(pkg, PRESENTATION_PART);
|
|
12
|
+
const paths = [];
|
|
13
|
+
for (const sldId of childrenWithTag(sldIdLst, "p:sldId")) {
|
|
14
|
+
const rId = attr(sldId, "r:id");
|
|
15
|
+
const rel = rId === void 0 ? void 0 : rels.get(rId);
|
|
16
|
+
if (rel !== void 0) paths.push(rel.target);
|
|
17
|
+
}
|
|
18
|
+
return paths;
|
|
19
|
+
}
|
|
4
20
|
function readPptxContent(pkg) {
|
|
5
21
|
const pptxDoc = readPptx(pkg);
|
|
22
|
+
const slidePaths = slidePathsInOrder(pkg);
|
|
23
|
+
const slides = pptxDoc.slides.map((slide, slideIndex) => {
|
|
24
|
+
const slidePath = slidePaths[slideIndex];
|
|
25
|
+
const slideRoot = slidePath === void 0 ? void 0 : rootElement(pkg.parts[slidePath]);
|
|
26
|
+
const cSld = slideRoot === void 0 ? void 0 : childrenWithTag(slideRoot, "p:cSld")[0];
|
|
27
|
+
const spTree = cSld === void 0 ? void 0 : childrenWithTag(cSld, "p:spTree")[0];
|
|
28
|
+
return spTree === void 0 ? slide : collapseVectorShapeRuns(slide, slideIndex, spTree.children);
|
|
29
|
+
});
|
|
6
30
|
return {
|
|
7
31
|
kind: "presentation",
|
|
8
32
|
formatVersion: CONTENT_FORMAT_VERSION,
|
|
9
33
|
metadata: { ...pptxDoc.metadata },
|
|
10
|
-
slides
|
|
34
|
+
slides
|
|
11
35
|
};
|
|
12
36
|
}
|
|
13
37
|
//#endregion
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_edit_drawingml_vector = require("../../edit/drawingml/vector.cjs");
|
|
3
|
+
const require_model_embedded_drawing = require("../../model/embedded-drawing.cjs");
|
|
4
|
+
let ooxml_js = require("ooxml.js");
|
|
5
|
+
//#region src/ooxml/pptx/vector.ts
|
|
6
|
+
function isBlankParagraphBlocks(blocks) {
|
|
7
|
+
return blocks.length === 0 || blocks.every((block) => block.kind === "paragraph" && block.runs.every((run) => run.text.trim().length === 0));
|
|
8
|
+
}
|
|
9
|
+
function collectVectorOnlyShapes(children, shapes, state, out) {
|
|
10
|
+
for (const node of children) {
|
|
11
|
+
if (node.type !== "element") continue;
|
|
12
|
+
if (node.tag === "p:sp") {
|
|
13
|
+
const shapeIndex = state.shapeIndex;
|
|
14
|
+
state.shapeIndex += 1;
|
|
15
|
+
const shape = shapes[shapeIndex];
|
|
16
|
+
if (shape !== void 0 && isBlankParagraphBlocks(shape.blocks)) {
|
|
17
|
+
const spPr = (0, ooxml_js.childrenWithTag)(node, "p:spPr")[0];
|
|
18
|
+
const vector = spPr === void 0 ? void 0 : require_edit_drawingml_vector.readDrawingMlVector(spPr);
|
|
19
|
+
if (vector !== void 0) out.push({
|
|
20
|
+
shapeIndex,
|
|
21
|
+
vector
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
} else if (node.tag === "p:pic" || node.tag === "p:graphicFrame") state.shapeIndex += 1;
|
|
25
|
+
else if (node.tag === "p:grpSp") collectVectorOnlyShapes(node.children, shapes, state, out);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function collectSlideVectorGroups(spTreeChildren, shapes) {
|
|
29
|
+
const state = { shapeIndex: 0 };
|
|
30
|
+
const found = [];
|
|
31
|
+
collectVectorOnlyShapes(spTreeChildren, shapes, state, found);
|
|
32
|
+
const groups = [];
|
|
33
|
+
for (const item of found) {
|
|
34
|
+
const last = groups[groups.length - 1];
|
|
35
|
+
if (last !== void 0 && last.insertAt + last.length === item.shapeIndex) {
|
|
36
|
+
last.vectors.push(item.vector);
|
|
37
|
+
last.length += 1;
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
groups.push({
|
|
41
|
+
insertAt: item.shapeIndex,
|
|
42
|
+
length: 1,
|
|
43
|
+
vectors: [item.vector]
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
return groups.map((group) => ({
|
|
47
|
+
insertAt: group.insertAt,
|
|
48
|
+
length: group.length,
|
|
49
|
+
vectors: group.vectors.map((vector, index) => ({
|
|
50
|
+
...vector,
|
|
51
|
+
paintOrder: index
|
|
52
|
+
}))
|
|
53
|
+
}));
|
|
54
|
+
}
|
|
55
|
+
function collapseVectorShapeRuns(slide, slideIndex, spTreeChildren) {
|
|
56
|
+
const groups = collectSlideVectorGroups(spTreeChildren, slide.shapes);
|
|
57
|
+
if (groups.length === 0) return slide;
|
|
58
|
+
const shapes = [];
|
|
59
|
+
let index = 0;
|
|
60
|
+
let groupIndex = 0;
|
|
61
|
+
while (index < slide.shapes.length) {
|
|
62
|
+
const group = groups[groupIndex];
|
|
63
|
+
if (group?.insertAt === index && group !== void 0) {
|
|
64
|
+
const sourcePath = `slides[${slideIndex}].shapes[${shapes.length}]`;
|
|
65
|
+
shapes.push({
|
|
66
|
+
frame: {
|
|
67
|
+
xPt: 0,
|
|
68
|
+
yPt: 0,
|
|
69
|
+
widthPt: slide.size.widthPt,
|
|
70
|
+
heightPt: slide.size.heightPt
|
|
71
|
+
},
|
|
72
|
+
insetLeftPt: 0,
|
|
73
|
+
insetTopPt: 0,
|
|
74
|
+
insetRightPt: 0,
|
|
75
|
+
insetBottomPt: 0,
|
|
76
|
+
blocks: [{
|
|
77
|
+
...require_model_embedded_drawing.buildDrawingBlock(slide.size, group.vectors),
|
|
78
|
+
sourcePath
|
|
79
|
+
}],
|
|
80
|
+
sourcePath
|
|
81
|
+
});
|
|
82
|
+
index += group.length;
|
|
83
|
+
groupIndex += 1;
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
const shape = slide.shapes[index];
|
|
87
|
+
if (shape !== void 0) shapes.push(shape);
|
|
88
|
+
index += 1;
|
|
89
|
+
}
|
|
90
|
+
return {
|
|
91
|
+
...slide,
|
|
92
|
+
shapes
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
//#endregion
|
|
96
|
+
exports.collapseVectorShapeRuns = collapseVectorShapeRuns;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ContentSlide } from "document-schema.js";
|
|
2
|
+
import { XmlNode } from "ooxml.js";
|
|
3
|
+
//#region src/ooxml/pptx/vector.d.ts
|
|
4
|
+
declare function collapseVectorShapeRuns(slide: ContentSlide, slideIndex: number, spTreeChildren: readonly XmlNode[]): ContentSlide;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { collapseVectorShapeRuns };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { XmlNode } from "ooxml.js";
|
|
2
|
+
import { ContentSlide } from "document-schema.js";
|
|
3
|
+
//#region src/ooxml/pptx/vector.d.ts
|
|
4
|
+
declare function collapseVectorShapeRuns(slide: ContentSlide, slideIndex: number, spTreeChildren: readonly XmlNode[]): ContentSlide;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { collapseVectorShapeRuns };
|