documents.js 1.67.15 → 1.68.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/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/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/page.d.ts +1 -1
- package/dist/edit/odp/shape.d.ts +1 -1
- package/dist/edit/odp/slide.d.ts +2 -2
- package/dist/edit/odt/content.d.ts +2 -2
- package/dist/edit/odt/editor.d.ts +3 -3
- 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/table.d.ts +1 -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.d.ts +9 -9
- package/dist/layout/sheets.js +3 -3
- package/dist/{list-nlhN5bat.d.ts → list-BJVehfU8.d.ts} +1 -1
- 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/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/{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
package/dist/layout/sheets.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { flipY } from "../model/geometry.js";
|
|
2
|
-
import { COLOR_BLACK as COLOR_BLACK$1, rgbHexToColor } from "../model/color.js";
|
|
2
|
+
import { COLOR_BLACK as COLOR_BLACK$1, rgbHexToColor as rgbHexToColor$1 } from "../model/color.js";
|
|
3
3
|
import { DEFAULT_LAYOUT_FONT } from "../model/style.js";
|
|
4
4
|
import { layoutFormula } from "../mathml/layout.js";
|
|
5
5
|
import { alignmentOffsetPt, formulaSizePtFromFrame, justifyLineGapsPt, lineNaturalHeightPt, pushCellBorderLines, sumColumnWidthsPt, toStyledRuns } from "./shared.js";
|
|
@@ -36,9 +36,9 @@ const CELL_TEXT_PADDING_PT = 2;
|
|
|
36
36
|
const HEADER_LABEL_PADDING_PT = 2;
|
|
37
37
|
const MINIMUM_SCALE = .01;
|
|
38
38
|
const NUMERIC_OVERFLOW_TEXT = "###";
|
|
39
|
-
const GRIDLINE_COLOR = rgbHexToColor("#D0D0D0");
|
|
39
|
+
const GRIDLINE_COLOR = rgbHexToColor$1("#D0D0D0");
|
|
40
40
|
const GRIDLINE_WIDTH_PT = .5;
|
|
41
|
-
const HEADER_LABEL_COLOR = rgbHexToColor("#606060");
|
|
41
|
+
const HEADER_LABEL_COLOR = rgbHexToColor$1("#606060");
|
|
42
42
|
function columnLetters(index) {
|
|
43
43
|
let n = index + 1;
|
|
44
44
|
let letters = "";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as ParagraphInit, t as OdtParagraph } from "./paragraph-
|
|
1
|
+
import { n as ParagraphInit, t as OdtParagraph } from "./paragraph-CjtZP77X.js";
|
|
2
2
|
import { Package, XmlElement, XmlNode } from "odf.js";
|
|
3
3
|
//#region src/edit/odt/list.d.ts
|
|
4
4
|
declare class OdtListItem {
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/model/block-splice.ts
|
|
3
|
+
function spliceBlocks(blocks, placements, consumedIndices, sourcePathFor) {
|
|
4
|
+
const out = [];
|
|
5
|
+
let next = 0;
|
|
6
|
+
for (let index = 0; index <= blocks.length; index++) {
|
|
7
|
+
while (next < placements.length && placements[next].index === index) {
|
|
8
|
+
const { build } = placements[next];
|
|
9
|
+
out.push(build(sourcePathFor(out.length)));
|
|
10
|
+
next += 1;
|
|
11
|
+
}
|
|
12
|
+
const block = blocks[index];
|
|
13
|
+
if (block !== void 0 && !consumedIndices.has(index)) out.push(block);
|
|
14
|
+
}
|
|
15
|
+
return out;
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
exports.spliceBlocks = spliceBlocks;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ContentBlock } from "document-schema.js";
|
|
2
|
+
//#region src/model/block-splice.d.ts
|
|
3
|
+
interface BlockPlacement {
|
|
4
|
+
readonly index: number;
|
|
5
|
+
readonly build: (sourcePath: string) => ContentBlock;
|
|
6
|
+
}
|
|
7
|
+
declare function spliceBlocks(blocks: readonly ContentBlock[], placements: readonly BlockPlacement[], consumedIndices: ReadonlySet<number>, sourcePathFor: (position: number) => string): ContentBlock[];
|
|
8
|
+
//#endregion
|
|
9
|
+
export { BlockPlacement, spliceBlocks };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ContentBlock } from "document-schema.js";
|
|
2
|
+
//#region src/model/block-splice.d.ts
|
|
3
|
+
interface BlockPlacement {
|
|
4
|
+
readonly index: number;
|
|
5
|
+
readonly build: (sourcePath: string) => ContentBlock;
|
|
6
|
+
}
|
|
7
|
+
declare function spliceBlocks(blocks: readonly ContentBlock[], placements: readonly BlockPlacement[], consumedIndices: ReadonlySet<number>, sourcePathFor: (position: number) => string): ContentBlock[];
|
|
8
|
+
//#endregion
|
|
9
|
+
export { BlockPlacement, spliceBlocks };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//#region src/model/block-splice.ts
|
|
2
|
+
function spliceBlocks(blocks, placements, consumedIndices, sourcePathFor) {
|
|
3
|
+
const out = [];
|
|
4
|
+
let next = 0;
|
|
5
|
+
for (let index = 0; index <= blocks.length; index++) {
|
|
6
|
+
while (next < placements.length && placements[next].index === index) {
|
|
7
|
+
const { build } = placements[next];
|
|
8
|
+
out.push(build(sourcePathFor(out.length)));
|
|
9
|
+
next += 1;
|
|
10
|
+
}
|
|
11
|
+
const block = blocks[index];
|
|
12
|
+
if (block !== void 0 && !consumedIndices.has(index)) out.push(block);
|
|
13
|
+
}
|
|
14
|
+
return out;
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
export { spliceBlocks };
|
package/dist/model/color.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as rgbHexToColor, i as colorToRgbHex, n as LayoutColor, r as LayoutColorSchema, t as COLOR_BLACK } from "../color-
|
|
1
|
+
import { a as rgbHexToColor, i as colorToRgbHex, n as LayoutColor, r as LayoutColorSchema, t as COLOR_BLACK } from "../color-BHhGSqAh.js";
|
|
2
2
|
export { COLOR_BLACK, type LayoutColor, LayoutColorSchema, colorToRgbHex, rgbHexToColor };
|
package/dist/odf/odp/read.cjs
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_model_embedded_drawing = require("../../model/embedded-drawing.cjs");
|
|
2
3
|
const require_model_formula = require("../../model/formula.cjs");
|
|
3
4
|
const require_odf_formula_detect = require("../formula/detect.cjs");
|
|
5
|
+
const require_odf_vector_detect = require("../vector/detect.cjs");
|
|
4
6
|
let document_schema_js = require("document-schema.js");
|
|
5
7
|
let odf_js = require("odf.js");
|
|
6
8
|
//#region src/odf/odp/read.ts
|
|
@@ -22,6 +24,42 @@ function readOdpContent(pkg) {
|
|
|
22
24
|
blocks: [require_model_formula.buildFormulaBlock(found.formula, found.frame, `slides[${slideIndex}].shapes[${found.shapeIndex}]`)]
|
|
23
25
|
};
|
|
24
26
|
}
|
|
27
|
+
const groups = require_odf_vector_detect.collectSlideVectorGroups(pageElement.children, pkg);
|
|
28
|
+
if (groups.length === 0) return;
|
|
29
|
+
const shapes = [];
|
|
30
|
+
let shapeIndex = 0;
|
|
31
|
+
let groupIndex = 0;
|
|
32
|
+
while (shapeIndex <= slide.shapes.length) {
|
|
33
|
+
while (groupIndex < groups.length && groups[groupIndex].insertBeforeShapeIndex === shapeIndex) {
|
|
34
|
+
const group = groups[groupIndex];
|
|
35
|
+
const sourcePath = `slides[${slideIndex}].shapes[${shapes.length}]`;
|
|
36
|
+
shapes.push({
|
|
37
|
+
frame: {
|
|
38
|
+
xPt: 0,
|
|
39
|
+
yPt: 0,
|
|
40
|
+
widthPt: slide.size.widthPt,
|
|
41
|
+
heightPt: slide.size.heightPt
|
|
42
|
+
},
|
|
43
|
+
insetLeftPt: 0,
|
|
44
|
+
insetTopPt: 0,
|
|
45
|
+
insetRightPt: 0,
|
|
46
|
+
insetBottomPt: 0,
|
|
47
|
+
blocks: [{
|
|
48
|
+
...require_model_embedded_drawing.buildDrawingBlock(slide.size, group.vectors),
|
|
49
|
+
sourcePath
|
|
50
|
+
}],
|
|
51
|
+
sourcePath
|
|
52
|
+
});
|
|
53
|
+
groupIndex += 1;
|
|
54
|
+
}
|
|
55
|
+
const shape = slide.shapes[shapeIndex];
|
|
56
|
+
if (shape !== void 0) shapes.push(shape);
|
|
57
|
+
shapeIndex += 1;
|
|
58
|
+
}
|
|
59
|
+
odpDoc.slides[slideIndex] = {
|
|
60
|
+
...slide,
|
|
61
|
+
shapes
|
|
62
|
+
};
|
|
25
63
|
});
|
|
26
64
|
}
|
|
27
65
|
return {
|
package/dist/odf/odp/read.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { buildDrawingBlock } from "../../model/embedded-drawing.js";
|
|
1
2
|
import { buildFormulaBlock } from "../../model/formula.js";
|
|
2
3
|
import { collectSlideFormulaFrames } from "../formula/detect.js";
|
|
4
|
+
import { collectSlideVectorGroups } from "../vector/detect.js";
|
|
3
5
|
import { CONTENT_FORMAT_VERSION } from "document-schema.js";
|
|
4
6
|
import { childrenWithTag, findChildElement, readOdp, rootElement } from "odf.js";
|
|
5
7
|
//#region src/odf/odp/read.ts
|
|
@@ -21,6 +23,42 @@ function readOdpContent(pkg) {
|
|
|
21
23
|
blocks: [buildFormulaBlock(found.formula, found.frame, `slides[${slideIndex}].shapes[${found.shapeIndex}]`)]
|
|
22
24
|
};
|
|
23
25
|
}
|
|
26
|
+
const groups = collectSlideVectorGroups(pageElement.children, pkg);
|
|
27
|
+
if (groups.length === 0) return;
|
|
28
|
+
const shapes = [];
|
|
29
|
+
let shapeIndex = 0;
|
|
30
|
+
let groupIndex = 0;
|
|
31
|
+
while (shapeIndex <= slide.shapes.length) {
|
|
32
|
+
while (groupIndex < groups.length && groups[groupIndex].insertBeforeShapeIndex === shapeIndex) {
|
|
33
|
+
const group = groups[groupIndex];
|
|
34
|
+
const sourcePath = `slides[${slideIndex}].shapes[${shapes.length}]`;
|
|
35
|
+
shapes.push({
|
|
36
|
+
frame: {
|
|
37
|
+
xPt: 0,
|
|
38
|
+
yPt: 0,
|
|
39
|
+
widthPt: slide.size.widthPt,
|
|
40
|
+
heightPt: slide.size.heightPt
|
|
41
|
+
},
|
|
42
|
+
insetLeftPt: 0,
|
|
43
|
+
insetTopPt: 0,
|
|
44
|
+
insetRightPt: 0,
|
|
45
|
+
insetBottomPt: 0,
|
|
46
|
+
blocks: [{
|
|
47
|
+
...buildDrawingBlock(slide.size, group.vectors),
|
|
48
|
+
sourcePath
|
|
49
|
+
}],
|
|
50
|
+
sourcePath
|
|
51
|
+
});
|
|
52
|
+
groupIndex += 1;
|
|
53
|
+
}
|
|
54
|
+
const shape = slide.shapes[shapeIndex];
|
|
55
|
+
if (shape !== void 0) shapes.push(shape);
|
|
56
|
+
shapeIndex += 1;
|
|
57
|
+
}
|
|
58
|
+
odpDoc.slides[slideIndex] = {
|
|
59
|
+
...slide,
|
|
60
|
+
shapes
|
|
61
|
+
};
|
|
24
62
|
});
|
|
25
63
|
}
|
|
26
64
|
return {
|
package/dist/odf/odt/read.cjs
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_model_embedded_drawing = require("../../model/embedded-drawing.cjs");
|
|
2
3
|
const require_model_formula = require("../../model/formula.cjs");
|
|
4
|
+
const require_model_block_splice = require("../../model/block-splice.cjs");
|
|
3
5
|
const require_odf_formula_detect = require("../formula/detect.cjs");
|
|
6
|
+
const require_odf_vector_detect = require("../vector/detect.cjs");
|
|
4
7
|
let document_schema_js = require("document-schema.js");
|
|
5
8
|
let odf_js = require("odf.js");
|
|
6
9
|
//#region src/odf/odt/read.ts
|
|
@@ -13,11 +16,25 @@ function readOdtContent(pkg) {
|
|
|
13
16
|
const text = body === void 0 ? void 0 : (0, odf_js.findChildElement)(body.children, "office:text");
|
|
14
17
|
if (text !== void 0) {
|
|
15
18
|
const section = odtDoc.sections[0];
|
|
16
|
-
const { placements, consumedBlockIndices } = collectFormulaPlacements(text.children, pkg);
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
const { placements: formulaPlacements, consumedBlockIndices: formulaConsumed } = collectFormulaPlacements(text.children, pkg);
|
|
20
|
+
const { placements: vectorPlacements, consumedBlockIndices: vectorConsumed } = collectVectorPlacements(text.children, pkg);
|
|
21
|
+
if (formulaPlacements.length > 0 || vectorPlacements.length > 0) {
|
|
22
|
+
const combined = [...formulaPlacements.map((placement) => ({
|
|
23
|
+
index: placement.index,
|
|
24
|
+
build: (sourcePath) => require_model_formula.buildFormulaBlock(placement.detected.formula, placement.detected.frame, sourcePath)
|
|
25
|
+
})), ...vectorPlacements.map((placement) => ({
|
|
26
|
+
index: placement.index,
|
|
27
|
+
build: (sourcePath) => ({
|
|
28
|
+
...require_model_embedded_drawing.buildDrawingBlock(section.pageSize, placement.vectors),
|
|
29
|
+
sourcePath
|
|
30
|
+
})
|
|
31
|
+
}))].sort((a, b) => a.index - b.index);
|
|
32
|
+
const consumedBlockIndices = /* @__PURE__ */ new Set([...formulaConsumed, ...vectorConsumed]);
|
|
33
|
+
odtDoc.sections[0] = {
|
|
34
|
+
...section,
|
|
35
|
+
blocks: require_model_block_splice.spliceBlocks(section.blocks, combined, consumedBlockIndices, (position) => `sections[0].blocks[${position}]`)
|
|
36
|
+
};
|
|
37
|
+
}
|
|
21
38
|
}
|
|
22
39
|
}
|
|
23
40
|
return {
|
|
@@ -27,30 +44,29 @@ function readOdtContent(pkg) {
|
|
|
27
44
|
sections: odtDoc.sections
|
|
28
45
|
};
|
|
29
46
|
}
|
|
30
|
-
function
|
|
47
|
+
function pushFormulaPlacements(out, index, detected) {
|
|
31
48
|
for (const frame of detected) out.push({
|
|
32
49
|
index,
|
|
33
50
|
detected: frame
|
|
34
51
|
});
|
|
35
52
|
}
|
|
36
|
-
function
|
|
37
|
-
if (
|
|
38
|
-
const frames = detected.map((entry) => entry.frameElement);
|
|
53
|
+
function isEmbeddedObjectOnlyParagraph(paragraph, recognisedElements) {
|
|
54
|
+
if (recognisedElements.length === 0) return false;
|
|
39
55
|
for (const child of paragraph.children) {
|
|
40
56
|
if (child.type === "text") {
|
|
41
57
|
if (child.value.trim().length > 0) return false;
|
|
42
58
|
continue;
|
|
43
59
|
}
|
|
44
60
|
if (child.type !== "element") continue;
|
|
45
|
-
if (!
|
|
61
|
+
if (!recognisedElements.includes(child)) return false;
|
|
46
62
|
}
|
|
47
63
|
return true;
|
|
48
64
|
}
|
|
49
|
-
function
|
|
65
|
+
function pushFormulaParagraphPlacement(node, pkg, state) {
|
|
50
66
|
const detected = require_odf_formula_detect.collectFormulaFrames(node.children, pkg);
|
|
51
67
|
state.blockCount += 1;
|
|
52
|
-
if (
|
|
53
|
-
|
|
68
|
+
if (isEmbeddedObjectOnlyParagraph(node, detected.map((entry) => entry.frameElement))) state.consumedBlockIndices.add(state.blockCount - 1);
|
|
69
|
+
pushFormulaPlacements(state.placements, state.blockCount, detected);
|
|
54
70
|
}
|
|
55
71
|
function collectFormulaPlacements(nodes, pkg) {
|
|
56
72
|
const state = {
|
|
@@ -58,48 +74,97 @@ function collectFormulaPlacements(nodes, pkg) {
|
|
|
58
74
|
placements: [],
|
|
59
75
|
consumedBlockIndices: /* @__PURE__ */ new Set()
|
|
60
76
|
};
|
|
61
|
-
|
|
77
|
+
walkForFormulaPlacements(nodes, pkg, state);
|
|
62
78
|
return {
|
|
63
79
|
placements: state.placements,
|
|
64
80
|
consumedBlockIndices: state.consumedBlockIndices
|
|
65
81
|
};
|
|
66
82
|
}
|
|
67
|
-
function
|
|
83
|
+
function walkForFormulaPlacements(nodes, pkg, state) {
|
|
68
84
|
for (const node of nodes) {
|
|
69
85
|
if (node.type !== "element") continue;
|
|
70
|
-
if (node.tag === "text:p" || node.tag === "text:h")
|
|
71
|
-
else if (node.tag === "text:list")
|
|
86
|
+
if (node.tag === "text:p" || node.tag === "text:h") pushFormulaParagraphPlacement(node, pkg, state);
|
|
87
|
+
else if (node.tag === "text:list") walkListForFormulaPlacements(node.children, pkg, state);
|
|
72
88
|
else if (node.tag === "table:table") {
|
|
73
89
|
state.blockCount += 1;
|
|
74
|
-
|
|
75
|
-
} else if (node.tag === "text:section")
|
|
76
|
-
else
|
|
90
|
+
pushFormulaPlacements(state.placements, state.blockCount, require_odf_formula_detect.collectFormulaFrames(node.children, pkg));
|
|
91
|
+
} else if (node.tag === "text:section") walkForFormulaPlacements(node.children, pkg, state);
|
|
92
|
+
else pushFormulaPlacements(state.placements, state.blockCount, require_odf_formula_detect.collectFormulaFrames([node], pkg));
|
|
77
93
|
}
|
|
78
94
|
}
|
|
79
|
-
function
|
|
95
|
+
function walkListForFormulaPlacements(itemNodes, pkg, state) {
|
|
80
96
|
for (const item of itemNodes) {
|
|
81
97
|
if (item.type !== "element" || item.tag !== "text:list-item") continue;
|
|
82
98
|
for (const itemChild of item.children) {
|
|
83
99
|
if (itemChild.type !== "element") continue;
|
|
84
|
-
if (itemChild.tag === "text:p" || itemChild.tag === "text:h")
|
|
85
|
-
else if (itemChild.tag === "text:list")
|
|
86
|
-
else
|
|
100
|
+
if (itemChild.tag === "text:p" || itemChild.tag === "text:h") pushFormulaParagraphPlacement(itemChild, pkg, state);
|
|
101
|
+
else if (itemChild.tag === "text:list") walkListForFormulaPlacements(itemChild.children, pkg, state);
|
|
102
|
+
else pushFormulaPlacements(state.placements, state.blockCount, require_odf_formula_detect.collectFormulaFrames([itemChild], pkg));
|
|
87
103
|
}
|
|
88
104
|
}
|
|
89
105
|
}
|
|
90
|
-
function
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
106
|
+
function vectorTaggedChildren(node) {
|
|
107
|
+
return node.children.filter((child) => child.type === "element" && require_odf_vector_detect.isVectorElementTag(child.tag));
|
|
108
|
+
}
|
|
109
|
+
function pushVectorParagraphPlacement(node, pkg, state) {
|
|
110
|
+
const vectors = require_odf_vector_detect.collectContainerVectors(node.children, pkg);
|
|
111
|
+
state.blockCount += 1;
|
|
112
|
+
if (vectors.length > 0 && isEmbeddedObjectOnlyParagraph(node, vectorTaggedChildren(node))) state.consumedBlockIndices.add(state.blockCount - 1);
|
|
113
|
+
if (vectors.length > 0) state.placements.push({
|
|
114
|
+
index: state.blockCount,
|
|
115
|
+
vectors
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
function collectVectorPlacements(nodes, pkg) {
|
|
119
|
+
const state = {
|
|
120
|
+
blockCount: 0,
|
|
121
|
+
placements: [],
|
|
122
|
+
consumedBlockIndices: /* @__PURE__ */ new Set()
|
|
123
|
+
};
|
|
124
|
+
walkForVectorPlacements(nodes, pkg, state);
|
|
125
|
+
return {
|
|
126
|
+
placements: state.placements,
|
|
127
|
+
consumedBlockIndices: state.consumedBlockIndices
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
function walkForVectorPlacements(nodes, pkg, state) {
|
|
131
|
+
for (const node of nodes) {
|
|
132
|
+
if (node.type !== "element") continue;
|
|
133
|
+
if (node.tag === "text:p" || node.tag === "text:h") pushVectorParagraphPlacement(node, pkg, state);
|
|
134
|
+
else if (node.tag === "text:list") walkListForVectorPlacements(node.children, pkg, state);
|
|
135
|
+
else if (node.tag === "table:table") {
|
|
136
|
+
state.blockCount += 1;
|
|
137
|
+
const vectors = require_odf_vector_detect.collectContainerVectors(node.children, pkg);
|
|
138
|
+
if (vectors.length > 0) state.placements.push({
|
|
139
|
+
index: state.blockCount,
|
|
140
|
+
vectors
|
|
141
|
+
});
|
|
142
|
+
} else if (node.tag === "text:section") walkForVectorPlacements(node.children, pkg, state);
|
|
143
|
+
else {
|
|
144
|
+
const vectors = require_odf_vector_detect.collectContainerVectors([node], pkg);
|
|
145
|
+
if (vectors.length > 0) state.placements.push({
|
|
146
|
+
index: state.blockCount,
|
|
147
|
+
vectors
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
function walkListForVectorPlacements(itemNodes, pkg, state) {
|
|
153
|
+
for (const item of itemNodes) {
|
|
154
|
+
if (item.type !== "element" || item.tag !== "text:list-item") continue;
|
|
155
|
+
for (const itemChild of item.children) {
|
|
156
|
+
if (itemChild.type !== "element") continue;
|
|
157
|
+
if (itemChild.tag === "text:p" || itemChild.tag === "text:h") pushVectorParagraphPlacement(itemChild, pkg, state);
|
|
158
|
+
else if (itemChild.tag === "text:list") walkListForVectorPlacements(itemChild.children, pkg, state);
|
|
159
|
+
else {
|
|
160
|
+
const vectors = require_odf_vector_detect.collectContainerVectors([itemChild], pkg);
|
|
161
|
+
if (vectors.length > 0) state.placements.push({
|
|
162
|
+
index: state.blockCount,
|
|
163
|
+
vectors
|
|
164
|
+
});
|
|
165
|
+
}
|
|
98
166
|
}
|
|
99
|
-
const block = blocks[index];
|
|
100
|
-
if (block !== void 0 && !consumedBlockIndices.has(index)) out.push(block);
|
|
101
167
|
}
|
|
102
|
-
return out;
|
|
103
168
|
}
|
|
104
169
|
//#endregion
|
|
105
170
|
exports.readOdtContent = readOdtContent;
|
package/dist/odf/odt/read.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import { buildDrawingBlock } from "../../model/embedded-drawing.js";
|
|
1
2
|
import { buildFormulaBlock } from "../../model/formula.js";
|
|
3
|
+
import { spliceBlocks } from "../../model/block-splice.js";
|
|
2
4
|
import { collectFormulaFrames } from "../formula/detect.js";
|
|
5
|
+
import { collectContainerVectors, isVectorElementTag } from "../vector/detect.js";
|
|
3
6
|
import { CONTENT_FORMAT_VERSION } from "document-schema.js";
|
|
4
7
|
import { findChildElement, readOdt, rootElement } from "odf.js";
|
|
5
8
|
//#region src/odf/odt/read.ts
|
|
@@ -12,11 +15,25 @@ function readOdtContent(pkg) {
|
|
|
12
15
|
const text = body === void 0 ? void 0 : findChildElement(body.children, "office:text");
|
|
13
16
|
if (text !== void 0) {
|
|
14
17
|
const section = odtDoc.sections[0];
|
|
15
|
-
const { placements, consumedBlockIndices } = collectFormulaPlacements(text.children, pkg);
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
const { placements: formulaPlacements, consumedBlockIndices: formulaConsumed } = collectFormulaPlacements(text.children, pkg);
|
|
19
|
+
const { placements: vectorPlacements, consumedBlockIndices: vectorConsumed } = collectVectorPlacements(text.children, pkg);
|
|
20
|
+
if (formulaPlacements.length > 0 || vectorPlacements.length > 0) {
|
|
21
|
+
const combined = [...formulaPlacements.map((placement) => ({
|
|
22
|
+
index: placement.index,
|
|
23
|
+
build: (sourcePath) => buildFormulaBlock(placement.detected.formula, placement.detected.frame, sourcePath)
|
|
24
|
+
})), ...vectorPlacements.map((placement) => ({
|
|
25
|
+
index: placement.index,
|
|
26
|
+
build: (sourcePath) => ({
|
|
27
|
+
...buildDrawingBlock(section.pageSize, placement.vectors),
|
|
28
|
+
sourcePath
|
|
29
|
+
})
|
|
30
|
+
}))].sort((a, b) => a.index - b.index);
|
|
31
|
+
const consumedBlockIndices = /* @__PURE__ */ new Set([...formulaConsumed, ...vectorConsumed]);
|
|
32
|
+
odtDoc.sections[0] = {
|
|
33
|
+
...section,
|
|
34
|
+
blocks: spliceBlocks(section.blocks, combined, consumedBlockIndices, (position) => `sections[0].blocks[${position}]`)
|
|
35
|
+
};
|
|
36
|
+
}
|
|
20
37
|
}
|
|
21
38
|
}
|
|
22
39
|
return {
|
|
@@ -26,30 +43,29 @@ function readOdtContent(pkg) {
|
|
|
26
43
|
sections: odtDoc.sections
|
|
27
44
|
};
|
|
28
45
|
}
|
|
29
|
-
function
|
|
46
|
+
function pushFormulaPlacements(out, index, detected) {
|
|
30
47
|
for (const frame of detected) out.push({
|
|
31
48
|
index,
|
|
32
49
|
detected: frame
|
|
33
50
|
});
|
|
34
51
|
}
|
|
35
|
-
function
|
|
36
|
-
if (
|
|
37
|
-
const frames = detected.map((entry) => entry.frameElement);
|
|
52
|
+
function isEmbeddedObjectOnlyParagraph(paragraph, recognisedElements) {
|
|
53
|
+
if (recognisedElements.length === 0) return false;
|
|
38
54
|
for (const child of paragraph.children) {
|
|
39
55
|
if (child.type === "text") {
|
|
40
56
|
if (child.value.trim().length > 0) return false;
|
|
41
57
|
continue;
|
|
42
58
|
}
|
|
43
59
|
if (child.type !== "element") continue;
|
|
44
|
-
if (!
|
|
60
|
+
if (!recognisedElements.includes(child)) return false;
|
|
45
61
|
}
|
|
46
62
|
return true;
|
|
47
63
|
}
|
|
48
|
-
function
|
|
64
|
+
function pushFormulaParagraphPlacement(node, pkg, state) {
|
|
49
65
|
const detected = collectFormulaFrames(node.children, pkg);
|
|
50
66
|
state.blockCount += 1;
|
|
51
|
-
if (
|
|
52
|
-
|
|
67
|
+
if (isEmbeddedObjectOnlyParagraph(node, detected.map((entry) => entry.frameElement))) state.consumedBlockIndices.add(state.blockCount - 1);
|
|
68
|
+
pushFormulaPlacements(state.placements, state.blockCount, detected);
|
|
53
69
|
}
|
|
54
70
|
function collectFormulaPlacements(nodes, pkg) {
|
|
55
71
|
const state = {
|
|
@@ -57,48 +73,97 @@ function collectFormulaPlacements(nodes, pkg) {
|
|
|
57
73
|
placements: [],
|
|
58
74
|
consumedBlockIndices: /* @__PURE__ */ new Set()
|
|
59
75
|
};
|
|
60
|
-
|
|
76
|
+
walkForFormulaPlacements(nodes, pkg, state);
|
|
61
77
|
return {
|
|
62
78
|
placements: state.placements,
|
|
63
79
|
consumedBlockIndices: state.consumedBlockIndices
|
|
64
80
|
};
|
|
65
81
|
}
|
|
66
|
-
function
|
|
82
|
+
function walkForFormulaPlacements(nodes, pkg, state) {
|
|
67
83
|
for (const node of nodes) {
|
|
68
84
|
if (node.type !== "element") continue;
|
|
69
|
-
if (node.tag === "text:p" || node.tag === "text:h")
|
|
70
|
-
else if (node.tag === "text:list")
|
|
85
|
+
if (node.tag === "text:p" || node.tag === "text:h") pushFormulaParagraphPlacement(node, pkg, state);
|
|
86
|
+
else if (node.tag === "text:list") walkListForFormulaPlacements(node.children, pkg, state);
|
|
71
87
|
else if (node.tag === "table:table") {
|
|
72
88
|
state.blockCount += 1;
|
|
73
|
-
|
|
74
|
-
} else if (node.tag === "text:section")
|
|
75
|
-
else
|
|
89
|
+
pushFormulaPlacements(state.placements, state.blockCount, collectFormulaFrames(node.children, pkg));
|
|
90
|
+
} else if (node.tag === "text:section") walkForFormulaPlacements(node.children, pkg, state);
|
|
91
|
+
else pushFormulaPlacements(state.placements, state.blockCount, collectFormulaFrames([node], pkg));
|
|
76
92
|
}
|
|
77
93
|
}
|
|
78
|
-
function
|
|
94
|
+
function walkListForFormulaPlacements(itemNodes, pkg, state) {
|
|
79
95
|
for (const item of itemNodes) {
|
|
80
96
|
if (item.type !== "element" || item.tag !== "text:list-item") continue;
|
|
81
97
|
for (const itemChild of item.children) {
|
|
82
98
|
if (itemChild.type !== "element") continue;
|
|
83
|
-
if (itemChild.tag === "text:p" || itemChild.tag === "text:h")
|
|
84
|
-
else if (itemChild.tag === "text:list")
|
|
85
|
-
else
|
|
99
|
+
if (itemChild.tag === "text:p" || itemChild.tag === "text:h") pushFormulaParagraphPlacement(itemChild, pkg, state);
|
|
100
|
+
else if (itemChild.tag === "text:list") walkListForFormulaPlacements(itemChild.children, pkg, state);
|
|
101
|
+
else pushFormulaPlacements(state.placements, state.blockCount, collectFormulaFrames([itemChild], pkg));
|
|
86
102
|
}
|
|
87
103
|
}
|
|
88
104
|
}
|
|
89
|
-
function
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
105
|
+
function vectorTaggedChildren(node) {
|
|
106
|
+
return node.children.filter((child) => child.type === "element" && isVectorElementTag(child.tag));
|
|
107
|
+
}
|
|
108
|
+
function pushVectorParagraphPlacement(node, pkg, state) {
|
|
109
|
+
const vectors = collectContainerVectors(node.children, pkg);
|
|
110
|
+
state.blockCount += 1;
|
|
111
|
+
if (vectors.length > 0 && isEmbeddedObjectOnlyParagraph(node, vectorTaggedChildren(node))) state.consumedBlockIndices.add(state.blockCount - 1);
|
|
112
|
+
if (vectors.length > 0) state.placements.push({
|
|
113
|
+
index: state.blockCount,
|
|
114
|
+
vectors
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
function collectVectorPlacements(nodes, pkg) {
|
|
118
|
+
const state = {
|
|
119
|
+
blockCount: 0,
|
|
120
|
+
placements: [],
|
|
121
|
+
consumedBlockIndices: /* @__PURE__ */ new Set()
|
|
122
|
+
};
|
|
123
|
+
walkForVectorPlacements(nodes, pkg, state);
|
|
124
|
+
return {
|
|
125
|
+
placements: state.placements,
|
|
126
|
+
consumedBlockIndices: state.consumedBlockIndices
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
function walkForVectorPlacements(nodes, pkg, state) {
|
|
130
|
+
for (const node of nodes) {
|
|
131
|
+
if (node.type !== "element") continue;
|
|
132
|
+
if (node.tag === "text:p" || node.tag === "text:h") pushVectorParagraphPlacement(node, pkg, state);
|
|
133
|
+
else if (node.tag === "text:list") walkListForVectorPlacements(node.children, pkg, state);
|
|
134
|
+
else if (node.tag === "table:table") {
|
|
135
|
+
state.blockCount += 1;
|
|
136
|
+
const vectors = collectContainerVectors(node.children, pkg);
|
|
137
|
+
if (vectors.length > 0) state.placements.push({
|
|
138
|
+
index: state.blockCount,
|
|
139
|
+
vectors
|
|
140
|
+
});
|
|
141
|
+
} else if (node.tag === "text:section") walkForVectorPlacements(node.children, pkg, state);
|
|
142
|
+
else {
|
|
143
|
+
const vectors = collectContainerVectors([node], pkg);
|
|
144
|
+
if (vectors.length > 0) state.placements.push({
|
|
145
|
+
index: state.blockCount,
|
|
146
|
+
vectors
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
function walkListForVectorPlacements(itemNodes, pkg, state) {
|
|
152
|
+
for (const item of itemNodes) {
|
|
153
|
+
if (item.type !== "element" || item.tag !== "text:list-item") continue;
|
|
154
|
+
for (const itemChild of item.children) {
|
|
155
|
+
if (itemChild.type !== "element") continue;
|
|
156
|
+
if (itemChild.tag === "text:p" || itemChild.tag === "text:h") pushVectorParagraphPlacement(itemChild, pkg, state);
|
|
157
|
+
else if (itemChild.tag === "text:list") walkListForVectorPlacements(itemChild.children, pkg, state);
|
|
158
|
+
else {
|
|
159
|
+
const vectors = collectContainerVectors([itemChild], pkg);
|
|
160
|
+
if (vectors.length > 0) state.placements.push({
|
|
161
|
+
index: state.blockCount,
|
|
162
|
+
vectors
|
|
163
|
+
});
|
|
164
|
+
}
|
|
97
165
|
}
|
|
98
|
-
const block = blocks[index];
|
|
99
|
-
if (block !== void 0 && !consumedBlockIndices.has(index)) out.push(block);
|
|
100
166
|
}
|
|
101
|
-
return out;
|
|
102
167
|
}
|
|
103
168
|
//#endregion
|
|
104
169
|
export { readOdtContent };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let odf_js = require("odf.js");
|
|
3
|
+
//#region src/odf/vector/detect.ts
|
|
4
|
+
const VECTOR_ELEMENT_TAGS = /* @__PURE__ */ new Set([
|
|
5
|
+
"draw:rect",
|
|
6
|
+
"draw:ellipse",
|
|
7
|
+
"draw:circle",
|
|
8
|
+
"draw:line",
|
|
9
|
+
"draw:path",
|
|
10
|
+
"draw:polygon",
|
|
11
|
+
"draw:polyline",
|
|
12
|
+
"draw:custom-shape"
|
|
13
|
+
]);
|
|
14
|
+
function isVectorElementTag(tag) {
|
|
15
|
+
return VECTOR_ELEMENT_TAGS.has(tag);
|
|
16
|
+
}
|
|
17
|
+
function collectContainerVectors(children, pkg) {
|
|
18
|
+
return (0, odf_js.readDrawPageContent)(children, pkg).vectors;
|
|
19
|
+
}
|
|
20
|
+
function paintOrderOf(item) {
|
|
21
|
+
if (item.paintOrder === void 0) throw new Error("expected odf.js's own readDrawPageContent to stamp every shape/vector with a paintOrder");
|
|
22
|
+
return item.paintOrder;
|
|
23
|
+
}
|
|
24
|
+
function collectSlideVectorGroups(pageChildren, pkg) {
|
|
25
|
+
const { shapes, vectors } = (0, odf_js.readDrawPageContent)(pageChildren, pkg);
|
|
26
|
+
const shapePaintOrders = shapes.map(paintOrderOf);
|
|
27
|
+
const groups = [];
|
|
28
|
+
for (const vector of vectors) {
|
|
29
|
+
const vectorOrder = paintOrderOf(vector);
|
|
30
|
+
const insertBeforeShapeIndex = shapePaintOrders.filter((order) => order < vectorOrder).length;
|
|
31
|
+
const last = groups[groups.length - 1];
|
|
32
|
+
if (last?.insertBeforeShapeIndex === insertBeforeShapeIndex && last !== void 0) {
|
|
33
|
+
last.vectors.push(vector);
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
groups.push({
|
|
37
|
+
insertBeforeShapeIndex,
|
|
38
|
+
vectors: [vector]
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
return groups.map((group) => ({
|
|
42
|
+
insertBeforeShapeIndex: group.insertBeforeShapeIndex,
|
|
43
|
+
vectors: group.vectors.map((vector, index) => ({
|
|
44
|
+
...vector,
|
|
45
|
+
paintOrder: index
|
|
46
|
+
}))
|
|
47
|
+
}));
|
|
48
|
+
}
|
|
49
|
+
//#endregion
|
|
50
|
+
exports.collectContainerVectors = collectContainerVectors;
|
|
51
|
+
exports.collectSlideVectorGroups = collectSlideVectorGroups;
|
|
52
|
+
exports.isVectorElementTag = isVectorElementTag;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ContentVector } from "document-schema.js";
|
|
2
|
+
import { Package, XmlNode } from "odf.js";
|
|
3
|
+
//#region src/odf/vector/detect.d.ts
|
|
4
|
+
declare function isVectorElementTag(tag: string): boolean;
|
|
5
|
+
declare function collectContainerVectors(children: readonly XmlNode[], pkg: Package): readonly ContentVector[];
|
|
6
|
+
interface DetectedSlideVectorGroup {
|
|
7
|
+
readonly insertBeforeShapeIndex: number;
|
|
8
|
+
readonly vectors: readonly ContentVector[];
|
|
9
|
+
}
|
|
10
|
+
declare function collectSlideVectorGroups(pageChildren: readonly XmlNode[], pkg: Package): readonly DetectedSlideVectorGroup[];
|
|
11
|
+
//#endregion
|
|
12
|
+
export { DetectedSlideVectorGroup, collectContainerVectors, collectSlideVectorGroups, isVectorElementTag };
|