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.
Files changed (161) hide show
  1. package/README.md +3 -3
  2. package/dist/color-BHhGSqAh.d.ts +2 -0
  3. package/dist/edit/docx/content.cjs +6 -1
  4. package/dist/edit/docx/content.d.cts +2 -0
  5. package/dist/edit/docx/content.d.ts +2 -0
  6. package/dist/edit/docx/content.js +7 -2
  7. package/dist/edit/docx/editor.cjs +6 -2
  8. package/dist/edit/docx/editor.d.cts +6 -2
  9. package/dist/edit/docx/editor.d.ts +6 -2
  10. package/dist/edit/docx/editor.js +6 -2
  11. package/dist/edit/docx/paragraph.d.ts +1 -1
  12. package/dist/edit/docx/props.d.ts +1 -1
  13. package/dist/edit/docx/run.d.ts +1 -1
  14. package/dist/edit/docx/scaffold.cjs +5 -2
  15. package/dist/edit/docx/scaffold.d.cts +6 -2
  16. package/dist/edit/docx/scaffold.d.ts +6 -2
  17. package/dist/edit/docx/scaffold.js +5 -2
  18. package/dist/edit/drawingml/vector.cjs +145 -0
  19. package/dist/edit/drawingml/vector.d.cts +3 -2
  20. package/dist/edit/drawingml/vector.d.ts +3 -2
  21. package/dist/edit/drawingml/vector.js +147 -3
  22. package/dist/edit/odg/content.cjs +7 -2
  23. package/dist/edit/odg/content.d.cts +6 -2
  24. package/dist/edit/odg/content.d.ts +6 -2
  25. package/dist/edit/odg/content.js +8 -3
  26. package/dist/edit/odg/editor.cjs +6 -2
  27. package/dist/edit/odg/editor.d.cts +6 -2
  28. package/dist/edit/odg/editor.d.ts +6 -2
  29. package/dist/edit/odg/editor.js +6 -2
  30. package/dist/edit/odg/page.d.ts +1 -1
  31. package/dist/edit/odg/scaffold.cjs +17 -4
  32. package/dist/edit/odg/scaffold.d.cts +6 -2
  33. package/dist/edit/odg/scaffold.d.ts +6 -2
  34. package/dist/edit/odg/scaffold.js +18 -5
  35. package/dist/edit/odp/content.cjs +7 -2
  36. package/dist/edit/odp/content.d.cts +6 -2
  37. package/dist/edit/odp/content.d.ts +6 -2
  38. package/dist/edit/odp/content.js +8 -3
  39. package/dist/edit/odp/editor.cjs +6 -2
  40. package/dist/edit/odp/editor.d.cts +6 -2
  41. package/dist/edit/odp/editor.d.ts +6 -2
  42. package/dist/edit/odp/editor.js +6 -2
  43. package/dist/edit/odp/scaffold.cjs +17 -4
  44. package/dist/edit/odp/scaffold.d.cts +6 -2
  45. package/dist/edit/odp/scaffold.d.ts +6 -2
  46. package/dist/edit/odp/scaffold.js +18 -5
  47. package/dist/edit/odp/shape.d.ts +1 -1
  48. package/dist/edit/odp/slide.d.ts +2 -2
  49. package/dist/edit/ods/content.cjs +7 -2
  50. package/dist/edit/ods/content.d.cts +6 -2
  51. package/dist/edit/ods/content.d.ts +6 -2
  52. package/dist/edit/ods/content.js +8 -3
  53. package/dist/edit/ods/editor.cjs +6 -2
  54. package/dist/edit/ods/editor.d.cts +6 -2
  55. package/dist/edit/ods/editor.d.ts +6 -2
  56. package/dist/edit/ods/editor.js +6 -2
  57. package/dist/edit/ods/scaffold.cjs +17 -4
  58. package/dist/edit/ods/scaffold.d.cts +6 -2
  59. package/dist/edit/ods/scaffold.d.ts +6 -2
  60. package/dist/edit/ods/scaffold.js +18 -5
  61. package/dist/edit/odt/content.cjs +7 -2
  62. package/dist/edit/odt/content.d.cts +6 -2
  63. package/dist/edit/odt/content.d.ts +8 -4
  64. package/dist/edit/odt/content.js +8 -3
  65. package/dist/edit/odt/editor.cjs +6 -2
  66. package/dist/edit/odt/editor.d.cts +6 -2
  67. package/dist/edit/odt/editor.d.ts +9 -5
  68. package/dist/edit/odt/editor.js +6 -2
  69. package/dist/edit/odt/list.d.ts +1 -1
  70. package/dist/edit/odt/paragraph.d.ts +1 -1
  71. package/dist/edit/odt/run.d.ts +1 -1
  72. package/dist/edit/odt/scaffold.cjs +17 -4
  73. package/dist/edit/odt/scaffold.d.cts +6 -2
  74. package/dist/edit/odt/scaffold.d.ts +6 -2
  75. package/dist/edit/odt/scaffold.js +18 -5
  76. package/dist/edit/odt/table.d.ts +1 -1
  77. package/dist/edit/pptx/content.cjs +7 -2
  78. package/dist/edit/pptx/content.d.cts +6 -2
  79. package/dist/edit/pptx/content.d.ts +6 -2
  80. package/dist/edit/pptx/content.js +8 -3
  81. package/dist/edit/pptx/editor.cjs +6 -2
  82. package/dist/edit/pptx/editor.d.cts +6 -2
  83. package/dist/edit/pptx/editor.d.ts +6 -2
  84. package/dist/edit/pptx/editor.js +6 -2
  85. package/dist/edit/pptx/scaffold.cjs +3 -1
  86. package/dist/edit/pptx/scaffold.d.cts +6 -2
  87. package/dist/edit/pptx/scaffold.d.ts +6 -2
  88. package/dist/edit/pptx/scaffold.js +3 -1
  89. package/dist/edit/pptx/shape.d.ts +1 -1
  90. package/dist/edit/pptx/slide.d.ts +2 -2
  91. package/dist/edit/pptx/table.d.ts +1 -1
  92. package/dist/formula-B_4mdCuK.d.ts +12 -0
  93. package/dist/formula-DFc2Ofsk.d.cts +12 -0
  94. package/dist/index.cjs +3 -1
  95. package/dist/index.d.cts +20 -13
  96. package/dist/index.d.ts +29 -22
  97. package/dist/index.js +3 -2
  98. package/dist/layout/sheets.js +3 -3
  99. package/dist/{list-nlhN5bat.d.ts → list-BJVehfU8.d.ts} +1 -1
  100. package/dist/mathml/layout.cjs +42 -3
  101. package/dist/mathml/layout.js +42 -3
  102. package/dist/mathml/operators.cjs +12 -0
  103. package/dist/mathml/operators.js +12 -0
  104. package/dist/model/block-splice.cjs +18 -0
  105. package/dist/model/block-splice.d.cts +9 -0
  106. package/dist/model/block-splice.d.ts +9 -0
  107. package/dist/model/block-splice.js +17 -0
  108. package/dist/model/color.d.ts +1 -1
  109. package/dist/model/metadata.cjs +13 -0
  110. package/dist/model/metadata.d.cts +6 -0
  111. package/dist/model/metadata.d.ts +6 -0
  112. package/dist/model/metadata.js +12 -0
  113. package/dist/odf/odp/read.cjs +38 -0
  114. package/dist/odf/odp/read.js +38 -0
  115. package/dist/odf/odt/read.cjs +100 -35
  116. package/dist/odf/odt/read.js +100 -35
  117. package/dist/odf/vector/detect.cjs +52 -0
  118. package/dist/odf/vector/detect.d.cts +12 -0
  119. package/dist/odf/vector/detect.d.ts +12 -0
  120. package/dist/odf/vector/detect.js +49 -0
  121. package/dist/ooxml/docx/embedded-objects.cjs +92 -0
  122. package/dist/ooxml/docx/embedded-objects.d.cts +7 -0
  123. package/dist/ooxml/docx/embedded-objects.d.ts +7 -0
  124. package/dist/ooxml/docx/embedded-objects.js +91 -0
  125. package/dist/ooxml/docx/formula.cjs +3 -58
  126. package/dist/ooxml/docx/formula.d.cts +2 -2
  127. package/dist/ooxml/docx/formula.d.ts +2 -2
  128. package/dist/ooxml/docx/formula.js +1 -58
  129. package/dist/ooxml/docx/read.cjs +2 -2
  130. package/dist/ooxml/docx/read.d.cts +1 -1
  131. package/dist/ooxml/docx/read.d.ts +1 -1
  132. package/dist/ooxml/docx/read.js +2 -2
  133. package/dist/ooxml/docx/vector.cjs +63 -0
  134. package/dist/ooxml/docx/vector.d.cts +10 -0
  135. package/dist/ooxml/docx/vector.d.ts +10 -0
  136. package/dist/ooxml/docx/vector.js +62 -0
  137. package/dist/ooxml/pptx/read.cjs +25 -1
  138. package/dist/ooxml/pptx/read.js +26 -2
  139. package/dist/ooxml/pptx/vector.cjs +96 -0
  140. package/dist/ooxml/pptx/vector.d.cts +6 -0
  141. package/dist/ooxml/pptx/vector.d.ts +6 -0
  142. package/dist/ooxml/pptx/vector.js +95 -0
  143. package/dist/opc/core-properties.cjs +65 -0
  144. package/dist/opc/core-properties.d.cts +6 -0
  145. package/dist/opc/core-properties.d.ts +6 -0
  146. package/dist/opc/core-properties.js +64 -0
  147. package/dist/opc/rels.cjs +11 -4
  148. package/dist/opc/rels.d.cts +2 -1
  149. package/dist/opc/rels.d.ts +2 -1
  150. package/dist/opc/rels.js +11 -5
  151. package/dist/{paragraph-DndYbWuT.d.ts → paragraph-CjtZP77X.d.ts} +1 -1
  152. package/dist/{run-BhYv2wJf.d.ts → run-DDe7miD5.d.ts} +1 -1
  153. package/dist/{run-DtrwZwN6.d.ts → run-wB22_F5w.d.ts} +1 -1
  154. package/dist/{shape-B-TjU_Ej.d.ts → shape-BjX3wlig.d.ts} +1 -1
  155. package/dist/{shape-XGp__l-J.d.ts → shape-GV8i37zL.d.ts} +2 -2
  156. package/dist/{table-DQpKafyl.d.ts → table-Db91eorq.d.ts} +1 -1
  157. package/dist/{table-BHeUmLzZ.d.ts → table-Vf6nCixr.d.ts} +1 -1
  158. package/package.json +1 -1
  159. package/dist/color-C98dn-pT.d.ts +0 -2
  160. package/dist/formula-CgydMiTt.d.ts +0 -10
  161. package/dist/formula-CiwPw8nY.d.cts +0 -10
@@ -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
- if (placements.length > 0) odtDoc.sections[0] = {
18
- ...section,
19
- blocks: spliceFormulaBlocks(section.blocks, placements, consumedBlockIndices)
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 pushPlacements(out, index, detected) {
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 isFormulaOnlyParagraph(paragraph, detected) {
37
- if (detected.length === 0) return false;
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 (!frames.includes(child)) return false;
61
+ if (!recognisedElements.includes(child)) return false;
46
62
  }
47
63
  return true;
48
64
  }
49
- function pushParagraphPlacements(node, pkg, state) {
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 (isFormulaOnlyParagraph(node, detected)) state.consumedBlockIndices.add(state.blockCount - 1);
53
- pushPlacements(state.placements, state.blockCount, detected);
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
- walkForPlacements(nodes, pkg, state);
77
+ walkForFormulaPlacements(nodes, pkg, state);
62
78
  return {
63
79
  placements: state.placements,
64
80
  consumedBlockIndices: state.consumedBlockIndices
65
81
  };
66
82
  }
67
- function walkForPlacements(nodes, pkg, state) {
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") pushParagraphPlacements(node, pkg, state);
71
- else if (node.tag === "text:list") walkListForPlacements(node.children, pkg, state);
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
- pushPlacements(state.placements, state.blockCount, require_odf_formula_detect.collectFormulaFrames(node.children, pkg));
75
- } else if (node.tag === "text:section") walkForPlacements(node.children, pkg, state);
76
- else pushPlacements(state.placements, state.blockCount, require_odf_formula_detect.collectFormulaFrames([node], pkg));
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 walkListForPlacements(itemNodes, pkg, state) {
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") pushParagraphPlacements(itemChild, pkg, state);
85
- else if (itemChild.tag === "text:list") walkListForPlacements(itemChild.children, pkg, state);
86
- else pushPlacements(state.placements, state.blockCount, require_odf_formula_detect.collectFormulaFrames([itemChild], pkg));
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 spliceFormulaBlocks(blocks, placements, consumedBlockIndices) {
91
- const out = [];
92
- let next = 0;
93
- for (let index = 0; index <= blocks.length; index++) {
94
- while (next < placements.length && placements[next].index === index) {
95
- const { detected } = placements[next];
96
- out.push(require_model_formula.buildFormulaBlock(detected.formula, detected.frame, `sections[0].blocks[${out.length}]`));
97
- next += 1;
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;
@@ -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
- if (placements.length > 0) odtDoc.sections[0] = {
17
- ...section,
18
- blocks: spliceFormulaBlocks(section.blocks, placements, consumedBlockIndices)
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 pushPlacements(out, index, detected) {
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 isFormulaOnlyParagraph(paragraph, detected) {
36
- if (detected.length === 0) return false;
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 (!frames.includes(child)) return false;
60
+ if (!recognisedElements.includes(child)) return false;
45
61
  }
46
62
  return true;
47
63
  }
48
- function pushParagraphPlacements(node, pkg, state) {
64
+ function pushFormulaParagraphPlacement(node, pkg, state) {
49
65
  const detected = collectFormulaFrames(node.children, pkg);
50
66
  state.blockCount += 1;
51
- if (isFormulaOnlyParagraph(node, detected)) state.consumedBlockIndices.add(state.blockCount - 1);
52
- pushPlacements(state.placements, state.blockCount, detected);
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
- walkForPlacements(nodes, pkg, state);
76
+ walkForFormulaPlacements(nodes, pkg, state);
61
77
  return {
62
78
  placements: state.placements,
63
79
  consumedBlockIndices: state.consumedBlockIndices
64
80
  };
65
81
  }
66
- function walkForPlacements(nodes, pkg, state) {
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") pushParagraphPlacements(node, pkg, state);
70
- else if (node.tag === "text:list") walkListForPlacements(node.children, pkg, state);
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
- pushPlacements(state.placements, state.blockCount, collectFormulaFrames(node.children, pkg));
74
- } else if (node.tag === "text:section") walkForPlacements(node.children, pkg, state);
75
- else pushPlacements(state.placements, state.blockCount, collectFormulaFrames([node], pkg));
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 walkListForPlacements(itemNodes, pkg, state) {
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") pushParagraphPlacements(itemChild, pkg, state);
84
- else if (itemChild.tag === "text:list") walkListForPlacements(itemChild.children, pkg, state);
85
- else pushPlacements(state.placements, state.blockCount, collectFormulaFrames([itemChild], pkg));
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 spliceFormulaBlocks(blocks, placements, consumedBlockIndices) {
90
- const out = [];
91
- let next = 0;
92
- for (let index = 0; index <= blocks.length; index++) {
93
- while (next < placements.length && placements[next].index === index) {
94
- const { detected } = placements[next];
95
- out.push(buildFormulaBlock(detected.formula, detected.frame, `sections[0].blocks[${out.length}]`));
96
- next += 1;
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 };
@@ -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 };
@@ -0,0 +1,49 @@
1
+ import { readDrawPageContent } from "odf.js";
2
+ //#region src/odf/vector/detect.ts
3
+ const VECTOR_ELEMENT_TAGS = /* @__PURE__ */ new Set([
4
+ "draw:rect",
5
+ "draw:ellipse",
6
+ "draw:circle",
7
+ "draw:line",
8
+ "draw:path",
9
+ "draw:polygon",
10
+ "draw:polyline",
11
+ "draw:custom-shape"
12
+ ]);
13
+ function isVectorElementTag(tag) {
14
+ return VECTOR_ELEMENT_TAGS.has(tag);
15
+ }
16
+ function collectContainerVectors(children, pkg) {
17
+ return readDrawPageContent(children, pkg).vectors;
18
+ }
19
+ function paintOrderOf(item) {
20
+ if (item.paintOrder === void 0) throw new Error("expected odf.js's own readDrawPageContent to stamp every shape/vector with a paintOrder");
21
+ return item.paintOrder;
22
+ }
23
+ function collectSlideVectorGroups(pageChildren, pkg) {
24
+ const { shapes, vectors } = readDrawPageContent(pageChildren, pkg);
25
+ const shapePaintOrders = shapes.map(paintOrderOf);
26
+ const groups = [];
27
+ for (const vector of vectors) {
28
+ const vectorOrder = paintOrderOf(vector);
29
+ const insertBeforeShapeIndex = shapePaintOrders.filter((order) => order < vectorOrder).length;
30
+ const last = groups[groups.length - 1];
31
+ if (last?.insertBeforeShapeIndex === insertBeforeShapeIndex && last !== void 0) {
32
+ last.vectors.push(vector);
33
+ continue;
34
+ }
35
+ groups.push({
36
+ insertBeforeShapeIndex,
37
+ vectors: [vector]
38
+ });
39
+ }
40
+ return groups.map((group) => ({
41
+ insertBeforeShapeIndex: group.insertBeforeShapeIndex,
42
+ vectors: group.vectors.map((vector, index) => ({
43
+ ...vector,
44
+ paintOrder: index
45
+ }))
46
+ }));
47
+ }
48
+ //#endregion
49
+ export { collectContainerVectors, collectSlideVectorGroups, isVectorElementTag };
@@ -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 };