documents.js 1.67.16 → 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.
Files changed (71) hide show
  1. package/dist/color-BHhGSqAh.d.ts +2 -0
  2. package/dist/edit/docx/paragraph.d.ts +1 -1
  3. package/dist/edit/docx/props.d.ts +1 -1
  4. package/dist/edit/docx/run.d.ts +1 -1
  5. package/dist/edit/drawingml/vector.cjs +145 -0
  6. package/dist/edit/drawingml/vector.d.cts +3 -2
  7. package/dist/edit/drawingml/vector.d.ts +3 -2
  8. package/dist/edit/drawingml/vector.js +147 -3
  9. package/dist/edit/odg/page.d.ts +1 -1
  10. package/dist/edit/odp/shape.d.ts +1 -1
  11. package/dist/edit/odp/slide.d.ts +2 -2
  12. package/dist/edit/odt/content.d.ts +2 -2
  13. package/dist/edit/odt/editor.d.ts +3 -3
  14. package/dist/edit/odt/list.d.ts +1 -1
  15. package/dist/edit/odt/paragraph.d.ts +1 -1
  16. package/dist/edit/odt/run.d.ts +1 -1
  17. package/dist/edit/odt/table.d.ts +1 -1
  18. package/dist/edit/pptx/shape.d.ts +1 -1
  19. package/dist/edit/pptx/slide.d.ts +2 -2
  20. package/dist/edit/pptx/table.d.ts +1 -1
  21. package/dist/formula-B_4mdCuK.d.ts +12 -0
  22. package/dist/formula-DFc2Ofsk.d.cts +12 -0
  23. package/dist/index.d.ts +9 -9
  24. package/dist/layout/sheets.js +3 -3
  25. package/dist/{list-nlhN5bat.d.ts → list-BJVehfU8.d.ts} +1 -1
  26. package/dist/model/block-splice.cjs +18 -0
  27. package/dist/model/block-splice.d.cts +9 -0
  28. package/dist/model/block-splice.d.ts +9 -0
  29. package/dist/model/block-splice.js +17 -0
  30. package/dist/model/color.d.ts +1 -1
  31. package/dist/odf/odp/read.cjs +38 -0
  32. package/dist/odf/odp/read.js +38 -0
  33. package/dist/odf/odt/read.cjs +100 -35
  34. package/dist/odf/odt/read.js +100 -35
  35. package/dist/odf/vector/detect.cjs +52 -0
  36. package/dist/odf/vector/detect.d.cts +12 -0
  37. package/dist/odf/vector/detect.d.ts +12 -0
  38. package/dist/odf/vector/detect.js +49 -0
  39. package/dist/ooxml/docx/embedded-objects.cjs +92 -0
  40. package/dist/ooxml/docx/embedded-objects.d.cts +7 -0
  41. package/dist/ooxml/docx/embedded-objects.d.ts +7 -0
  42. package/dist/ooxml/docx/embedded-objects.js +91 -0
  43. package/dist/ooxml/docx/formula.cjs +3 -58
  44. package/dist/ooxml/docx/formula.d.cts +2 -2
  45. package/dist/ooxml/docx/formula.d.ts +2 -2
  46. package/dist/ooxml/docx/formula.js +1 -58
  47. package/dist/ooxml/docx/read.cjs +2 -2
  48. package/dist/ooxml/docx/read.d.cts +1 -1
  49. package/dist/ooxml/docx/read.d.ts +1 -1
  50. package/dist/ooxml/docx/read.js +2 -2
  51. package/dist/ooxml/docx/vector.cjs +63 -0
  52. package/dist/ooxml/docx/vector.d.cts +10 -0
  53. package/dist/ooxml/docx/vector.d.ts +10 -0
  54. package/dist/ooxml/docx/vector.js +62 -0
  55. package/dist/ooxml/pptx/read.cjs +25 -1
  56. package/dist/ooxml/pptx/read.js +26 -2
  57. package/dist/ooxml/pptx/vector.cjs +96 -0
  58. package/dist/ooxml/pptx/vector.d.cts +6 -0
  59. package/dist/ooxml/pptx/vector.d.ts +6 -0
  60. package/dist/ooxml/pptx/vector.js +95 -0
  61. package/dist/{paragraph-DndYbWuT.d.ts → paragraph-CjtZP77X.d.ts} +1 -1
  62. package/dist/{run-BhYv2wJf.d.ts → run-DDe7miD5.d.ts} +1 -1
  63. package/dist/{run-DtrwZwN6.d.ts → run-wB22_F5w.d.ts} +1 -1
  64. package/dist/{shape-B-TjU_Ej.d.ts → shape-BjX3wlig.d.ts} +1 -1
  65. package/dist/{shape-XGp__l-J.d.ts → shape-GV8i37zL.d.ts} +2 -2
  66. package/dist/{table-DQpKafyl.d.ts → table-Db91eorq.d.ts} +1 -1
  67. package/dist/{table-BHeUmLzZ.d.ts → table-Vf6nCixr.d.ts} +1 -1
  68. package/package.json +1 -1
  69. package/dist/color-C98dn-pT.d.ts +0 -2
  70. package/dist/formula-CgydMiTt.d.ts +0 -10
  71. package/dist/formula-CiwPw8nY.d.cts +0 -10
@@ -0,0 +1,92 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_model_embedded_drawing = require("../../model/embedded-drawing.cjs");
3
+ const require_model_formula = require("../../model/formula.cjs");
4
+ const require_omml_read = require("../../omml/read.cjs");
5
+ const require_model_block_splice = require("../../model/block-splice.cjs");
6
+ const require_ooxml_docx_vector = require("./vector.cjs");
7
+ const require_ooxml_docx_formula = require("./formula.cjs");
8
+ //#region src/ooxml/docx/embedded-objects.ts
9
+ function isVectorOnlyRun(run, vectors) {
10
+ const elementChildren = run.children.filter((child) => child.type === "element");
11
+ if (elementChildren.length !== 1) return false;
12
+ if (run.children.some((child) => child.type === "text" && child.value.trim().length > 0)) return false;
13
+ return vectors.some((detected) => detected.drawingElement === elementChildren[0]);
14
+ }
15
+ function isEmbeddedObjectOnlyParagraph(paragraph, equations, vectors) {
16
+ if (equations.length === 0 && vectors.length === 0) return false;
17
+ for (const child of paragraph.children) {
18
+ if (child.type === "text") {
19
+ if (child.value.trim().length > 0) return false;
20
+ continue;
21
+ }
22
+ if (child.type !== "element") continue;
23
+ if (require_ooxml_docx_formula.PARAGRAPH_NON_CONTENT_TAGS.has(child.tag) || equations.includes(child)) continue;
24
+ if (child.tag === "m:oMathPara" && require_omml_read.collectOfficeMathElements(child.children).every((math) => equations.includes(math))) continue;
25
+ if (child.tag === "w:r" && isVectorOnlyRun(child, vectors)) continue;
26
+ return false;
27
+ }
28
+ return true;
29
+ }
30
+ function spliceDocxEmbeddedObjects(sections, bodyChildren, onMathDiagnostic) {
31
+ const paragraphElements = [];
32
+ require_ooxml_docx_formula.collectBodyParagraphs(bodyChildren, paragraphElements);
33
+ let paragraphOrdinal = 0;
34
+ const out = [];
35
+ for (const [sectionIndex, section] of sections.entries()) {
36
+ const placements = [];
37
+ const consumedIndices = /* @__PURE__ */ new Set();
38
+ section.blocks.forEach((block, blockIndex) => {
39
+ if (block.kind !== "paragraph") return;
40
+ const paragraph = paragraphElements[paragraphOrdinal];
41
+ paragraphOrdinal += 1;
42
+ if (paragraph === void 0) return;
43
+ const equations = require_omml_read.collectOfficeMathElements(paragraph.children);
44
+ const vectors = require_ooxml_docx_vector.collectParagraphVectors(paragraph);
45
+ if (equations.length === 0 && vectors.length === 0) return;
46
+ const converted = equations.map((equation) => ({
47
+ equation,
48
+ ...require_omml_read.readOfficeMath(equation)
49
+ }));
50
+ const rendered = converted.filter((result) => result.mathml.length > 0);
51
+ if (rendered.length === 0 && vectors.length === 0) {
52
+ for (const result of converted) for (const diagnostic of result.diagnostics) onMathDiagnostic?.(diagnostic, { sourcePath: block.sourcePath });
53
+ return;
54
+ }
55
+ const insertAt = blockIndex + 1;
56
+ if (isEmbeddedObjectOnlyParagraph(paragraph, equations, vectors)) consumedIndices.add(blockIndex);
57
+ for (const result of rendered) placements.push({
58
+ index: insertAt,
59
+ build: (sourcePath) => {
60
+ for (const diagnostic of result.diagnostics) onMathDiagnostic?.(diagnostic, { sourcePath });
61
+ return require_model_formula.buildFormulaBlock({ mathml: result.mathml }, require_ooxml_docx_formula.equationFrame(result.equation), sourcePath);
62
+ }
63
+ });
64
+ for (const result of converted) {
65
+ if (result.mathml.length > 0) continue;
66
+ for (const diagnostic of result.diagnostics) onMathDiagnostic?.(diagnostic, { sourcePath: block.sourcePath });
67
+ }
68
+ if (vectors.length > 0) {
69
+ const vectorValues = vectors.map((detected) => detected.vector);
70
+ placements.push({
71
+ index: insertAt,
72
+ build: (sourcePath) => ({
73
+ ...require_model_embedded_drawing.buildDrawingBlock(section.pageSize, vectorValues),
74
+ sourcePath
75
+ })
76
+ });
77
+ }
78
+ });
79
+ if (placements.length === 0 && consumedIndices.size === 0) {
80
+ out.push(section);
81
+ continue;
82
+ }
83
+ const blocks = require_model_block_splice.spliceBlocks(section.blocks, placements, consumedIndices, (position) => `sections[${sectionIndex}].blocks[${position}]`);
84
+ out.push({
85
+ ...section,
86
+ blocks
87
+ });
88
+ }
89
+ return out;
90
+ }
91
+ //#endregion
92
+ exports.spliceDocxEmbeddedObjects = spliceDocxEmbeddedObjects;
@@ -0,0 +1,7 @@
1
+ import { t as OmmlDiagnosticSink } from "../../formula-DFc2Ofsk.cjs";
2
+ import { ContentSection } from "document-schema.js";
3
+ import { XmlNode } from "ooxml.js";
4
+ //#region src/ooxml/docx/embedded-objects.d.ts
5
+ declare function spliceDocxEmbeddedObjects(sections: readonly ContentSection[], bodyChildren: readonly XmlNode[], onMathDiagnostic?: OmmlDiagnosticSink): ContentSection[];
6
+ //#endregion
7
+ export { spliceDocxEmbeddedObjects };
@@ -0,0 +1,7 @@
1
+ import { t as OmmlDiagnosticSink } from "../../formula-B_4mdCuK.js";
2
+ import { XmlNode } from "ooxml.js";
3
+ import { ContentSection } from "document-schema.js";
4
+ //#region src/ooxml/docx/embedded-objects.d.ts
5
+ declare function spliceDocxEmbeddedObjects(sections: readonly ContentSection[], bodyChildren: readonly XmlNode[], onMathDiagnostic?: OmmlDiagnosticSink): ContentSection[];
6
+ //#endregion
7
+ export { spliceDocxEmbeddedObjects };
@@ -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.spliceDocxFormulas = spliceDocxFormulas;
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 spliceDocxFormulas, t as OmmlDiagnosticSink } from "../../formula-CiwPw8nY.cjs";
2
- export { OmmlDiagnosticSink, spliceDocxFormulas };
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 spliceDocxFormulas, t as OmmlDiagnosticSink } from "../../formula-CgydMiTt.js";
2
- export { OmmlDiagnosticSink, spliceDocxFormulas };
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 { spliceDocxFormulas };
51
+ export { PARAGRAPH_NON_CONTENT_TAGS, collectBodyParagraphs, equationFrame };
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_ooxml_docx_formula = require("./formula.cjs");
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 : require_ooxml_docx_formula.spliceDocxFormulas(docxDoc.sections, body.children, options?.onMathDiagnostic);
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-CiwPw8nY.cjs";
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
@@ -1,4 +1,4 @@
1
- import { t as OmmlDiagnosticSink } from "../../formula-CgydMiTt.js";
1
+ import { t as OmmlDiagnosticSink } from "../../formula-B_4mdCuK.js";
2
2
  import { Package } from "ooxml.js";
3
3
  import { ContentDocument } from "document-schema.js";
4
4
  //#region src/ooxml/docx/read.d.ts
@@ -1,4 +1,4 @@
1
- import { spliceDocxFormulas } from "./formula.js";
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 : spliceDocxFormulas(docxDoc.sections, body.children, options?.onMathDiagnostic);
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 };
@@ -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: pptxDoc.slides
35
+ slides
12
36
  };
13
37
  }
14
38
  //#endregion
@@ -1,13 +1,37 @@
1
- import { readPptx } from "ooxml.js";
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: pptxDoc.slides
34
+ slides
11
35
  };
12
36
  }
13
37
  //#endregion