documents.js 1.61.0 → 1.63.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 (236) hide show
  1. package/README.md +120 -47
  2. package/dist/{blr-types-CYYC3yYU.d.cts → blr-types-DVgO1DQ9.d.cts} +1 -1
  3. package/dist/{blr-types-CYYC3yYU.d.ts → blr-types-DVgO1DQ9.d.ts} +1 -1
  4. package/dist/convert/capability.cjs +1 -0
  5. package/dist/convert/capability.d.cts +1 -1
  6. package/dist/convert/capability.d.ts +1 -1
  7. package/dist/convert/capability.js +1 -0
  8. package/dist/convert/convert.cjs +92 -38
  9. package/dist/convert/convert.d.cts +11 -4
  10. package/dist/convert/convert.d.ts +11 -4
  11. package/dist/convert/convert.js +93 -39
  12. package/dist/convert/local.cjs +15 -2
  13. package/dist/convert/local.js +15 -2
  14. package/dist/convert/port.d.cts +8 -4
  15. package/dist/convert/port.d.ts +8 -4
  16. package/dist/edit/docx/content.cjs +75 -13
  17. package/dist/edit/docx/content.d.cts +8 -2
  18. package/dist/edit/docx/content.d.ts +8 -2
  19. package/dist/edit/docx/content.js +75 -13
  20. package/dist/edit/docx/paragraph.cjs +14 -0
  21. package/dist/edit/docx/paragraph.d.cts +5 -0
  22. package/dist/edit/docx/paragraph.d.ts +5 -0
  23. package/dist/edit/docx/paragraph.js +14 -0
  24. package/dist/edit/docx/run.cjs +1 -1
  25. package/dist/edit/docx/run.js +1 -1
  26. package/dist/edit/docx/table.cjs +41 -0
  27. package/dist/edit/docx/table.d.cts +7 -1
  28. package/dist/edit/docx/table.d.ts +7 -1
  29. package/dist/edit/docx/table.js +42 -1
  30. package/dist/edit/geometry.cjs +38 -0
  31. package/dist/edit/geometry.d.cts +7 -0
  32. package/dist/edit/geometry.d.ts +7 -0
  33. package/dist/edit/geometry.js +36 -0
  34. package/dist/edit/odg/content.cjs +15 -12
  35. package/dist/edit/odg/content.js +15 -12
  36. package/dist/edit/odg/editor.d.cts +1 -1
  37. package/dist/edit/odg/editor.d.ts +1 -1
  38. package/dist/edit/odg/page.d.cts +3 -3
  39. package/dist/edit/odg/page.d.ts +3 -3
  40. package/dist/edit/odg/vector.cjs +22 -13
  41. package/dist/edit/odg/vector.d.cts +1 -1
  42. package/dist/edit/odg/vector.d.ts +1 -1
  43. package/dist/edit/odg/vector.js +23 -14
  44. package/dist/edit/odp/content.cjs +15 -0
  45. package/dist/edit/odp/content.js +16 -1
  46. package/dist/edit/odp/editor.d.cts +1 -1
  47. package/dist/edit/odp/editor.d.ts +1 -1
  48. package/dist/edit/odp/image.d.cts +1 -1
  49. package/dist/edit/odp/image.d.ts +1 -1
  50. package/dist/edit/odp/shape.cjs +11 -30
  51. package/dist/edit/odp/shape.d.cts +2 -2
  52. package/dist/edit/odp/shape.d.ts +2 -2
  53. package/dist/edit/odp/shape.js +13 -33
  54. package/dist/edit/odp/slide.cjs +11 -0
  55. package/dist/edit/odp/slide.d.cts +14 -4
  56. package/dist/edit/odp/slide.d.ts +14 -4
  57. package/dist/edit/odp/slide.js +12 -1
  58. package/dist/edit/odt/content.cjs +56 -16
  59. package/dist/edit/odt/content.d.cts +4 -2
  60. package/dist/edit/odt/content.d.ts +4 -2
  61. package/dist/edit/odt/content.js +56 -17
  62. package/dist/edit/odt/editor.d.cts +1 -1
  63. package/dist/edit/odt/editor.d.ts +1 -1
  64. package/dist/edit/odt/table.cjs +36 -0
  65. package/dist/edit/odt/table.d.cts +1 -36
  66. package/dist/edit/odt/table.d.ts +1 -36
  67. package/dist/edit/odt/table.js +37 -1
  68. package/dist/edit/pptx/content.cjs +71 -3
  69. package/dist/edit/pptx/content.js +71 -3
  70. package/dist/edit/pptx/editor.d.cts +1 -1
  71. package/dist/edit/pptx/editor.d.ts +1 -1
  72. package/dist/edit/pptx/image.d.cts +1 -1
  73. package/dist/edit/pptx/image.d.ts +1 -1
  74. package/dist/edit/pptx/shape.cjs +23 -1
  75. package/dist/edit/pptx/shape.d.cts +2 -2
  76. package/dist/edit/pptx/shape.d.ts +2 -2
  77. package/dist/edit/pptx/shape.js +23 -3
  78. package/dist/edit/pptx/slide.cjs +10 -1
  79. package/dist/edit/pptx/slide.d.cts +11 -4
  80. package/dist/edit/pptx/slide.d.ts +11 -4
  81. package/dist/edit/pptx/slide.js +10 -1
  82. package/dist/edit/pptx/table.cjs +136 -0
  83. package/dist/edit/pptx/table.d.cts +2 -0
  84. package/dist/edit/pptx/table.d.ts +2 -0
  85. package/dist/edit/pptx/table.js +131 -0
  86. package/dist/firebird/backup.d.cts +1 -1
  87. package/dist/firebird/backup.d.ts +1 -1
  88. package/dist/firebird/blr-types.cjs +2 -2
  89. package/dist/firebird/blr-types.d.cts +1 -1
  90. package/dist/firebird/blr-types.d.ts +1 -1
  91. package/dist/firebird/blr-types.js +2 -2
  92. package/dist/firebird/data.cjs +68 -14
  93. package/dist/firebird/data.d.cts +1 -1
  94. package/dist/firebird/data.d.ts +1 -1
  95. package/dist/firebird/data.js +68 -14
  96. package/dist/firebird/schema.cjs +13 -1
  97. package/dist/firebird/schema.d.cts +1 -1
  98. package/dist/firebird/schema.d.ts +1 -1
  99. package/dist/firebird/schema.js +13 -1
  100. package/dist/fonts/obfuscation.cjs +50 -0
  101. package/dist/fonts/obfuscation.d.cts +9 -0
  102. package/dist/fonts/obfuscation.d.ts +9 -0
  103. package/dist/fonts/obfuscation.js +46 -0
  104. package/dist/fonts/odf.cjs +86 -0
  105. package/dist/fonts/odf.d.cts +9 -0
  106. package/dist/fonts/odf.d.ts +9 -0
  107. package/dist/fonts/odf.js +84 -0
  108. package/dist/fonts/ooxml.cjs +129 -0
  109. package/dist/fonts/ooxml.d.cts +9 -0
  110. package/dist/fonts/ooxml.d.ts +9 -0
  111. package/dist/fonts/ooxml.js +127 -0
  112. package/dist/fonts/registry.cjs +18 -0
  113. package/dist/fonts/registry.d.cts +2 -0
  114. package/dist/fonts/registry.d.ts +2 -0
  115. package/dist/fonts/registry.js +16 -0
  116. package/dist/{geometry-DvwdrIij.d.cts → geometry-DaJr8yQW.d.cts} +2 -2
  117. package/dist/{geometry-DvwdrIij.d.ts → geometry-DaJr8yQW.d.ts} +2 -2
  118. package/dist/hsqldb/binary-script.cjs +154 -0
  119. package/dist/hsqldb/binary-script.d.cts +15 -0
  120. package/dist/hsqldb/binary-script.d.ts +15 -0
  121. package/dist/hsqldb/binary-script.js +151 -0
  122. package/dist/hsqldb/cache.cjs +18 -11
  123. package/dist/hsqldb/cache.d.cts +9 -4
  124. package/dist/hsqldb/cache.d.ts +9 -4
  125. package/dist/hsqldb/cache.js +18 -11
  126. package/dist/hsqldb/rowformat.cjs +60 -16
  127. package/dist/hsqldb/rowformat.d.cts +2 -21
  128. package/dist/hsqldb/rowformat.d.ts +2 -21
  129. package/dist/hsqldb/rowformat.js +60 -17
  130. package/dist/{image-BZDy72Jb.d.cts → image-7snmKIxn.d.cts} +1 -1
  131. package/dist/{image-B-xQWYYS.d.ts → image-Cs8xF753.d.ts} +1 -1
  132. package/dist/{image-CeqwL-Qs.d.ts → image-DHcA9kaK.d.ts} +1 -1
  133. package/dist/{image-DWX6cNOD.d.cts → image-M5SezZVI.d.cts} +1 -1
  134. package/dist/index.cjs +86 -3
  135. package/dist/index.d.cts +33 -21
  136. package/dist/index.d.ts +33 -21
  137. package/dist/index.js +18 -5
  138. package/dist/layout/cell-typing.cjs +209 -0
  139. package/dist/layout/cell-typing.d.cts +22 -0
  140. package/dist/layout/cell-typing.d.ts +22 -0
  141. package/dist/layout/cell-typing.js +208 -0
  142. package/dist/layout/drawing.cjs +193 -17
  143. package/dist/layout/drawing.js +193 -17
  144. package/dist/layout/engine.cjs +46 -29
  145. package/dist/layout/engine.d.cts +0 -2
  146. package/dist/layout/engine.d.ts +0 -2
  147. package/dist/layout/engine.js +47 -30
  148. package/dist/layout/lattice.cjs +139 -0
  149. package/dist/layout/lattice.d.cts +20 -0
  150. package/dist/layout/lattice.d.ts +20 -0
  151. package/dist/layout/lattice.js +135 -0
  152. package/dist/layout/reconstruct.cjs +176 -113
  153. package/dist/layout/reconstruct.d.cts +2 -0
  154. package/dist/layout/reconstruct.d.ts +2 -0
  155. package/dist/layout/reconstruct.js +173 -110
  156. package/dist/layout/shared.cjs +52 -0
  157. package/dist/layout/shared.d.cts +4 -2
  158. package/dist/layout/shared.d.ts +4 -2
  159. package/dist/layout/shared.js +51 -1
  160. package/dist/layout/sheets.cjs +45 -11
  161. package/dist/layout/sheets.js +46 -12
  162. package/dist/layout/slides.cjs +7 -7
  163. package/dist/layout/slides.d.cts +0 -3
  164. package/dist/layout/slides.d.ts +0 -3
  165. package/dist/layout/slides.js +7 -7
  166. package/dist/markdown/write.cjs +19 -6
  167. package/dist/markdown/write.js +19 -6
  168. package/dist/mathml/layout.cjs +2 -2
  169. package/dist/mathml/layout.d.cts +1 -1
  170. package/dist/mathml/layout.d.ts +1 -1
  171. package/dist/mathml/layout.js +2 -2
  172. package/dist/model/embedded-drawing.cjs +32 -0
  173. package/dist/model/embedded-drawing.d.cts +8 -0
  174. package/dist/model/embedded-drawing.d.ts +8 -0
  175. package/dist/model/embedded-drawing.js +30 -0
  176. package/dist/model/formula.cjs +31 -0
  177. package/dist/model/formula.d.cts +6 -6
  178. package/dist/model/formula.d.ts +6 -6
  179. package/dist/model/formula.js +27 -0
  180. package/dist/model/geometry.d.cts +1 -1
  181. package/dist/model/geometry.d.ts +1 -1
  182. package/dist/model/paint-order.cjs +15 -0
  183. package/dist/model/paint-order.d.cts +14 -0
  184. package/dist/model/paint-order.d.ts +14 -0
  185. package/dist/model/paint-order.js +14 -0
  186. package/dist/odb/components.cjs +12 -0
  187. package/dist/odb/components.d.cts +6 -0
  188. package/dist/odb/components.d.ts +6 -0
  189. package/dist/odb/components.js +10 -0
  190. package/dist/odb/read.cjs +11 -7
  191. package/dist/odb/read.d.cts +3 -2
  192. package/dist/odb/read.d.ts +3 -2
  193. package/dist/odb/read.js +11 -7
  194. package/dist/odf/formula/detect.cjs +86 -18
  195. package/dist/odf/formula/detect.d.cts +10 -6
  196. package/dist/odf/formula/detect.d.ts +10 -6
  197. package/dist/odf/formula/detect.js +86 -19
  198. package/dist/odf/formula/read.cjs +4 -16
  199. package/dist/odf/formula/read.d.cts +4 -8
  200. package/dist/odf/formula/read.d.ts +4 -8
  201. package/dist/odf/formula/read.js +5 -17
  202. package/dist/odf/odp/read.cjs +9 -19
  203. package/dist/odf/odp/read.d.cts +2 -7
  204. package/dist/odf/odp/read.d.ts +2 -7
  205. package/dist/odf/odp/read.js +10 -20
  206. package/dist/odf/odt/read.cjs +63 -23
  207. package/dist/odf/odt/read.d.cts +2 -7
  208. package/dist/odf/odt/read.d.ts +2 -7
  209. package/dist/odf/odt/read.js +64 -24
  210. package/dist/omml/write.cjs +258 -0
  211. package/dist/omml/write.d.cts +2 -0
  212. package/dist/omml/write.d.ts +2 -0
  213. package/dist/omml/write.js +256 -0
  214. package/dist/registry-CrSqLIcn.d.ts +19 -0
  215. package/dist/registry-CtPhMD0f.d.cts +19 -0
  216. package/dist/rowformat-Cl2exlEh.d.cts +25 -0
  217. package/dist/rowformat-Cl2exlEh.d.ts +25 -0
  218. package/dist/{schema-Acco3Ezi.d.cts → schema-BeR_KJ0X.d.cts} +3 -1
  219. package/dist/{schema-VkAA6pF5.d.ts → schema-CSKwSb_v.d.ts} +3 -1
  220. package/dist/{shape-BUfjw5eZ.d.cts → shape-BhkP6HB8.d.cts} +6 -2
  221. package/dist/{shape-CTkl6kt8.d.ts → shape-BkVcwPcf.d.ts} +6 -2
  222. package/dist/{shape-BfN3m52m.d.ts → shape-CVXedeL7.d.ts} +3 -2
  223. package/dist/{shape-CN2ycxOo.d.cts → shape-CXZ6fejV.d.cts} +3 -2
  224. package/dist/table-C3CPZ--2.d.cts +35 -0
  225. package/dist/table-DjYcNOFm.d.cts +44 -0
  226. package/dist/table-DqfqMkVq.d.ts +44 -0
  227. package/dist/table-DvS_7UQS.d.ts +35 -0
  228. package/dist/{vector-ClohqsOe.d.cts → vector-Puuqu_IT.d.cts} +4 -0
  229. package/dist/{vector-ClohqsOe.d.ts → vector-Puuqu_IT.d.ts} +4 -0
  230. package/dist/write-DuyfnbL_.d.cts +16 -0
  231. package/dist/write-Zqwx6pka.d.ts +16 -0
  232. package/package.json +4 -4
  233. package/dist/odf/formula/placeholder.cjs +0 -36
  234. package/dist/odf/formula/placeholder.d.cts +0 -14
  235. package/dist/odf/formula/placeholder.d.ts +0 -14
  236. package/dist/odf/formula/placeholder.js +0 -36
@@ -1,43 +1,33 @@
1
- import { detectEmbeddedFormulaFrames } from "../formula/detect.js";
2
- import { buildFormulaPlaceholderBlock } from "../formula/placeholder.js";
1
+ import { buildFormulaBlock } from "../../model/formula.js";
2
+ import { collectSlideFormulaFrames } from "../formula/detect.js";
3
3
  import { CONTENT_FORMAT_VERSION } from "document-schema.js";
4
4
  import { childrenWithTag, findChildElement, readOdp, rootElement } from "odf.js";
5
5
  //#region src/odf/odp/read.ts
6
6
  function readOdpContent(pkg) {
7
7
  const odpDoc = readOdp(pkg);
8
- const formulas = /* @__PURE__ */ new Map();
9
8
  const contentPart = pkg.parts["content.xml"];
10
9
  if (contentPart?.kind === "xml") {
11
10
  const root = rootElement(contentPart.nodes);
12
11
  const body = root === void 0 ? void 0 : findChildElement(root.children, "office:body");
13
12
  const presentation = body === void 0 ? void 0 : findChildElement(body.children, "office:presentation");
14
13
  (presentation === void 0 ? [] : childrenWithTag(presentation, "draw:page")).forEach((pageElement, slideIndex) => {
15
- if (childrenWithTag(pageElement, "draw:g").length > 0) return;
16
14
  const slide = odpDoc.slides[slideIndex];
17
15
  if (slide === void 0) return;
18
- const frameElements = childrenWithTag(pageElement, "draw:frame");
19
- const detected = detectEmbeddedFormulaFrames(frameElements, pkg);
20
- for (const found of detected) {
21
- const shapeIndex = frameElements.indexOf(found.frameElement);
22
- const shape = slide.shapes[shapeIndex];
16
+ for (const found of collectSlideFormulaFrames(pageElement.children, pkg)) {
17
+ const shape = slide.shapes[found.shapeIndex];
23
18
  if (shape === void 0) continue;
24
- const sourcePath = `slides[${slideIndex}].shapes[${shapeIndex}]`;
25
- slide.shapes[shapeIndex] = {
19
+ slide.shapes[found.shapeIndex] = {
26
20
  ...shape,
27
- blocks: [buildFormulaPlaceholderBlock(found.formula, found.frame, sourcePath)]
21
+ blocks: [buildFormulaBlock(found.formula, found.frame, `slides[${slideIndex}].shapes[${found.shapeIndex}]`)]
28
22
  };
29
- formulas.set(sourcePath, found.formula);
30
23
  }
31
24
  });
32
25
  }
33
26
  return {
34
- document: {
35
- kind: "presentation",
36
- formatVersion: CONTENT_FORMAT_VERSION,
37
- metadata: { ...odpDoc.metadata },
38
- slides: odpDoc.slides
39
- },
40
- formulas
27
+ kind: "presentation",
28
+ formatVersion: CONTENT_FORMAT_VERSION,
29
+ metadata: { ...odpDoc.metadata },
30
+ slides: odpDoc.slides
41
31
  };
42
32
  }
43
33
  //#endregion
@@ -1,43 +1,83 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_model_formula = require("../../model/formula.cjs");
2
3
  const require_odf_formula_detect = require("../formula/detect.cjs");
3
- const require_odf_formula_placeholder = require("../formula/placeholder.cjs");
4
4
  let document_schema_js = require("document-schema.js");
5
5
  let odf_js = require("odf.js");
6
6
  //#region src/odf/odt/read.ts
7
7
  function readOdtContent(pkg) {
8
8
  const odtDoc = (0, odf_js.readOdt)(pkg);
9
- const formulas = /* @__PURE__ */ new Map();
10
9
  const contentPart = pkg.parts["content.xml"];
11
10
  if (contentPart?.kind === "xml" && odtDoc.sections.length === 1) {
12
11
  const root = (0, odf_js.rootElement)(contentPart.nodes);
13
12
  const body = root === void 0 ? void 0 : (0, odf_js.findChildElement)(root.children, "office:body");
14
13
  const text = body === void 0 ? void 0 : (0, odf_js.findChildElement)(body.children, "office:text");
15
14
  if (text !== void 0) {
16
- const detected = require_odf_formula_detect.detectEmbeddedFormulaFrames(text.children, pkg);
17
- if (detected.length > 0) {
18
- const section = odtDoc.sections[0];
19
- const blocks = [...section.blocks];
20
- for (const found of detected) {
21
- const sourcePath = `sections[0].blocks[${blocks.length}]`;
22
- blocks.push(require_odf_formula_placeholder.buildFormulaPlaceholderBlock(found.formula, found.frame, sourcePath));
23
- formulas.set(sourcePath, found.formula);
24
- }
25
- odtDoc.sections[0] = {
26
- ...section,
27
- blocks
28
- };
29
- }
15
+ const section = odtDoc.sections[0];
16
+ const placements = collectFormulaPlacements(text.children, pkg);
17
+ if (placements.length > 0) odtDoc.sections[0] = {
18
+ ...section,
19
+ blocks: spliceFormulaBlocks(section.blocks, placements)
20
+ };
30
21
  }
31
22
  }
32
23
  return {
33
- document: {
34
- kind: "wordprocessing",
35
- formatVersion: document_schema_js.CONTENT_FORMAT_VERSION,
36
- metadata: { ...odtDoc.metadata },
37
- sections: odtDoc.sections
38
- },
39
- formulas
24
+ kind: "wordprocessing",
25
+ formatVersion: document_schema_js.CONTENT_FORMAT_VERSION,
26
+ metadata: { ...odtDoc.metadata },
27
+ sections: odtDoc.sections
40
28
  };
41
29
  }
30
+ function pushPlacements(out, index, detected) {
31
+ for (const frame of detected) out.push({
32
+ index,
33
+ detected: frame
34
+ });
35
+ }
36
+ function collectFormulaPlacements(nodes, pkg) {
37
+ const out = [];
38
+ walkForPlacements(nodes, pkg, { blockCount: 0 }, out);
39
+ return out;
40
+ }
41
+ function walkForPlacements(nodes, pkg, state, out) {
42
+ for (const node of nodes) {
43
+ if (node.type !== "element") continue;
44
+ if (node.tag === "text:p" || node.tag === "text:h") {
45
+ state.blockCount += 1;
46
+ pushPlacements(out, state.blockCount, require_odf_formula_detect.collectFormulaFrames(node.children, pkg));
47
+ } else if (node.tag === "text:list") walkListForPlacements(node.children, pkg, state, out);
48
+ else if (node.tag === "table:table") {
49
+ state.blockCount += 1;
50
+ pushPlacements(out, state.blockCount, require_odf_formula_detect.collectFormulaFrames(node.children, pkg));
51
+ } else if (node.tag === "text:section") walkForPlacements(node.children, pkg, state, out);
52
+ else pushPlacements(out, state.blockCount, require_odf_formula_detect.collectFormulaFrames([node], pkg));
53
+ }
54
+ }
55
+ function walkListForPlacements(itemNodes, pkg, state, out) {
56
+ for (const item of itemNodes) {
57
+ if (item.type !== "element" || item.tag !== "text:list-item") continue;
58
+ for (const itemChild of item.children) {
59
+ if (itemChild.type !== "element") continue;
60
+ if (itemChild.tag === "text:p" || itemChild.tag === "text:h") {
61
+ state.blockCount += 1;
62
+ pushPlacements(out, state.blockCount, require_odf_formula_detect.collectFormulaFrames(itemChild.children, pkg));
63
+ } else if (itemChild.tag === "text:list") walkListForPlacements(itemChild.children, pkg, state, out);
64
+ else pushPlacements(out, state.blockCount, require_odf_formula_detect.collectFormulaFrames([itemChild], pkg));
65
+ }
66
+ }
67
+ }
68
+ function spliceFormulaBlocks(blocks, placements) {
69
+ const out = [];
70
+ let next = 0;
71
+ for (let index = 0; index <= blocks.length; index++) {
72
+ while (next < placements.length && placements[next].index === index) {
73
+ const { detected } = placements[next];
74
+ out.push(require_model_formula.buildFormulaBlock(detected.formula, detected.frame, `sections[0].blocks[${out.length}]`));
75
+ next += 1;
76
+ }
77
+ const block = blocks[index];
78
+ if (block !== void 0) out.push(block);
79
+ }
80
+ return out;
81
+ }
42
82
  //#endregion
43
83
  exports.readOdtContent = readOdtContent;
@@ -1,11 +1,6 @@
1
- import { EmbeddedFormula } from "../../model/formula.cjs";
2
1
  import { ContentDocument } from "document-schema.js";
3
2
  import { Package } from "odf.js";
4
3
  //#region src/odf/odt/read.d.ts
5
- interface OdtContentResult {
6
- readonly document: ContentDocument;
7
- readonly formulas: ReadonlyMap<string, EmbeddedFormula>;
8
- }
9
- declare function readOdtContent(pkg: Package): OdtContentResult;
4
+ declare function readOdtContent(pkg: Package): ContentDocument;
10
5
  //#endregion
11
- export { OdtContentResult, readOdtContent };
6
+ export { readOdtContent };
@@ -1,11 +1,6 @@
1
- import { EmbeddedFormula } from "../../model/formula.js";
2
1
  import { ContentDocument } from "document-schema.js";
3
2
  import { Package } from "odf.js";
4
3
  //#region src/odf/odt/read.d.ts
5
- interface OdtContentResult {
6
- readonly document: ContentDocument;
7
- readonly formulas: ReadonlyMap<string, EmbeddedFormula>;
8
- }
9
- declare function readOdtContent(pkg: Package): OdtContentResult;
4
+ declare function readOdtContent(pkg: Package): ContentDocument;
10
5
  //#endregion
11
- export { OdtContentResult, readOdtContent };
6
+ export { readOdtContent };
@@ -1,42 +1,82 @@
1
- import { detectEmbeddedFormulaFrames } from "../formula/detect.js";
2
- import { buildFormulaPlaceholderBlock } from "../formula/placeholder.js";
1
+ import { buildFormulaBlock } from "../../model/formula.js";
2
+ import { collectFormulaFrames } from "../formula/detect.js";
3
3
  import { CONTENT_FORMAT_VERSION } from "document-schema.js";
4
4
  import { findChildElement, readOdt, rootElement } from "odf.js";
5
5
  //#region src/odf/odt/read.ts
6
6
  function readOdtContent(pkg) {
7
7
  const odtDoc = readOdt(pkg);
8
- const formulas = /* @__PURE__ */ new Map();
9
8
  const contentPart = pkg.parts["content.xml"];
10
9
  if (contentPart?.kind === "xml" && odtDoc.sections.length === 1) {
11
10
  const root = rootElement(contentPart.nodes);
12
11
  const body = root === void 0 ? void 0 : findChildElement(root.children, "office:body");
13
12
  const text = body === void 0 ? void 0 : findChildElement(body.children, "office:text");
14
13
  if (text !== void 0) {
15
- const detected = detectEmbeddedFormulaFrames(text.children, pkg);
16
- if (detected.length > 0) {
17
- const section = odtDoc.sections[0];
18
- const blocks = [...section.blocks];
19
- for (const found of detected) {
20
- const sourcePath = `sections[0].blocks[${blocks.length}]`;
21
- blocks.push(buildFormulaPlaceholderBlock(found.formula, found.frame, sourcePath));
22
- formulas.set(sourcePath, found.formula);
23
- }
24
- odtDoc.sections[0] = {
25
- ...section,
26
- blocks
27
- };
28
- }
14
+ const section = odtDoc.sections[0];
15
+ const placements = collectFormulaPlacements(text.children, pkg);
16
+ if (placements.length > 0) odtDoc.sections[0] = {
17
+ ...section,
18
+ blocks: spliceFormulaBlocks(section.blocks, placements)
19
+ };
29
20
  }
30
21
  }
31
22
  return {
32
- document: {
33
- kind: "wordprocessing",
34
- formatVersion: CONTENT_FORMAT_VERSION,
35
- metadata: { ...odtDoc.metadata },
36
- sections: odtDoc.sections
37
- },
38
- formulas
23
+ kind: "wordprocessing",
24
+ formatVersion: CONTENT_FORMAT_VERSION,
25
+ metadata: { ...odtDoc.metadata },
26
+ sections: odtDoc.sections
39
27
  };
40
28
  }
29
+ function pushPlacements(out, index, detected) {
30
+ for (const frame of detected) out.push({
31
+ index,
32
+ detected: frame
33
+ });
34
+ }
35
+ function collectFormulaPlacements(nodes, pkg) {
36
+ const out = [];
37
+ walkForPlacements(nodes, pkg, { blockCount: 0 }, out);
38
+ return out;
39
+ }
40
+ function walkForPlacements(nodes, pkg, state, out) {
41
+ for (const node of nodes) {
42
+ if (node.type !== "element") continue;
43
+ if (node.tag === "text:p" || node.tag === "text:h") {
44
+ state.blockCount += 1;
45
+ pushPlacements(out, state.blockCount, collectFormulaFrames(node.children, pkg));
46
+ } else if (node.tag === "text:list") walkListForPlacements(node.children, pkg, state, out);
47
+ else if (node.tag === "table:table") {
48
+ state.blockCount += 1;
49
+ pushPlacements(out, state.blockCount, collectFormulaFrames(node.children, pkg));
50
+ } else if (node.tag === "text:section") walkForPlacements(node.children, pkg, state, out);
51
+ else pushPlacements(out, state.blockCount, collectFormulaFrames([node], pkg));
52
+ }
53
+ }
54
+ function walkListForPlacements(itemNodes, pkg, state, out) {
55
+ for (const item of itemNodes) {
56
+ if (item.type !== "element" || item.tag !== "text:list-item") continue;
57
+ for (const itemChild of item.children) {
58
+ if (itemChild.type !== "element") continue;
59
+ if (itemChild.tag === "text:p" || itemChild.tag === "text:h") {
60
+ state.blockCount += 1;
61
+ pushPlacements(out, state.blockCount, collectFormulaFrames(itemChild.children, pkg));
62
+ } else if (itemChild.tag === "text:list") walkListForPlacements(itemChild.children, pkg, state, out);
63
+ else pushPlacements(out, state.blockCount, collectFormulaFrames([itemChild], pkg));
64
+ }
65
+ }
66
+ }
67
+ function spliceFormulaBlocks(blocks, placements) {
68
+ const out = [];
69
+ let next = 0;
70
+ for (let index = 0; index <= blocks.length; index++) {
71
+ while (next < placements.length && placements[next].index === index) {
72
+ const { detected } = placements[next];
73
+ out.push(buildFormulaBlock(detected.formula, detected.frame, `sections[0].blocks[${out.length}]`));
74
+ next += 1;
75
+ }
76
+ const block = blocks[index];
77
+ if (block !== void 0) out.push(block);
78
+ }
79
+ return out;
80
+ }
41
81
  //#endregion
42
82
  export { readOdtContent };
@@ -0,0 +1,258 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_xml_fragment = require("../xml/fragment.cjs");
3
+ const require_mathml_length = require("../mathml/length.cjs");
4
+ const require_mathml_nodes = require("../mathml/nodes.cjs");
5
+ const require_mathml_operators = require("../mathml/operators.cjs");
6
+ const require_mathml_variant = require("../mathml/variant.cjs");
7
+ const require_xml_entities = require("../xml/entities.cjs");
8
+ //#region src/omml/write.ts
9
+ const OMML_NS = "http://schemas.openxmlformats.org/officeDocument/2006/math";
10
+ const VARIANT_RUN_PROPERTIES = {
11
+ normal: { sty: "p" },
12
+ bold: { sty: "b" },
13
+ italic: { sty: "i" },
14
+ "bold-italic": { sty: "bi" },
15
+ "double-struck": {
16
+ scr: "double-struck",
17
+ sty: "p"
18
+ },
19
+ script: {
20
+ scr: "script",
21
+ sty: "p"
22
+ },
23
+ "bold-script": {
24
+ scr: "script",
25
+ sty: "b"
26
+ },
27
+ fraktur: {
28
+ scr: "fraktur",
29
+ sty: "p"
30
+ },
31
+ "bold-fraktur": {
32
+ scr: "fraktur",
33
+ sty: "b"
34
+ },
35
+ "sans-serif": {
36
+ scr: "sans-serif",
37
+ sty: "p"
38
+ },
39
+ "bold-sans-serif": {
40
+ scr: "sans-serif",
41
+ sty: "b"
42
+ },
43
+ "sans-serif-italic": {
44
+ scr: "sans-serif",
45
+ sty: "i"
46
+ },
47
+ "sans-serif-bold-italic": {
48
+ scr: "sans-serif",
49
+ sty: "bi"
50
+ },
51
+ monospace: {
52
+ scr: "monospace",
53
+ sty: "p"
54
+ }
55
+ };
56
+ function columnJustification(align) {
57
+ return align === "left" || align === "right" || align === "center" ? align : "center";
58
+ }
59
+ function diagnose(ctx, kind, element) {
60
+ ctx.diagnostics.push({
61
+ kind,
62
+ detail: require_mathml_nodes.elementLocalName(element)
63
+ });
64
+ }
65
+ function mathRun(text, properties) {
66
+ const tAttrs = require_xml_entities.needsSpacePreserve(text) ? { "xml:space": "preserve" } : {};
67
+ const children = [];
68
+ if (properties !== void 0) children.push(properties);
69
+ children.push(require_xml_fragment.el("m:t", tAttrs, [require_xml_fragment.txt(require_xml_entities.encodeXmlText(text))]));
70
+ return require_xml_fragment.el("m:r", {}, children);
71
+ }
72
+ function variantRunProperties(variant) {
73
+ const mapped = VARIANT_RUN_PROPERTIES[variant];
74
+ const children = [];
75
+ if (mapped.scr !== void 0) children.push(require_xml_fragment.el("m:scr", { "m:val": mapped.scr }));
76
+ children.push(require_xml_fragment.el("m:sty", { "m:val": mapped.sty }));
77
+ return require_xml_fragment.el("m:rPr", {}, children);
78
+ }
79
+ function miIntrinsicDefault(content) {
80
+ return [...content].length === 1 ? "italic" : "normal";
81
+ }
82
+ function tokenVariant(element, intrinsicDefault, ctx) {
83
+ const attr = require_mathml_nodes.attrValue(element, "mathvariant");
84
+ if (attr !== void 0 && require_mathml_variant.isMathVariant(attr)) return attr;
85
+ return ctx.inheritedVariant ?? intrinsicDefault;
86
+ }
87
+ function tokenRun(element, rawText, intrinsicDefault, ctx, normalText) {
88
+ if (rawText.length === 0) return [];
89
+ if (normalText && require_mathml_nodes.attrValue(element, "mathvariant") === void 0) return [mathRun(rawText, require_xml_fragment.el("m:rPr", {}, [require_xml_fragment.el("m:nor")]))];
90
+ return [mathRun(rawText, variantRunProperties(tokenVariant(element, intrinsicDefault, ctx)))];
91
+ }
92
+ function argSlot(tag, child, ctx) {
93
+ return require_xml_fragment.el(tag, {}, child === void 0 ? [] : convertElement(child, ctx));
94
+ }
95
+ function argSlotFromChildren(tag, children, ctx) {
96
+ return require_xml_fragment.el(tag, {}, children.flatMap((child) => convertElement(child, ctx)));
97
+ }
98
+ function convertFraction(element, ctx) {
99
+ const children = require_mathml_nodes.elementChildren(element);
100
+ const lineThickness = require_mathml_nodes.attrValue(element, "linethickness");
101
+ const barless = lineThickness !== void 0 && require_mathml_length.parseMathLength(lineThickness, 1) === 0;
102
+ const parts = [];
103
+ if (barless) parts.push(require_xml_fragment.el("m:fPr", {}, [require_xml_fragment.el("m:type", { "m:val": "noBar" })]));
104
+ parts.push(argSlot("m:num", children[0], ctx), argSlot("m:den", children[1], ctx));
105
+ return require_xml_fragment.el("m:f", {}, parts);
106
+ }
107
+ function convertRadical(element, kind, ctx) {
108
+ const children = require_mathml_nodes.elementChildren(element);
109
+ if (kind === "msqrt") return require_xml_fragment.el("m:rad", {}, [
110
+ require_xml_fragment.el("m:radPr", {}, [require_xml_fragment.el("m:degHide", { "m:val": "1" })]),
111
+ require_xml_fragment.el("m:deg"),
112
+ argSlotFromChildren("m:e", children, ctx)
113
+ ]);
114
+ return require_xml_fragment.el("m:rad", {}, [argSlot("m:deg", children[1], ctx), argSlot("m:e", children[0], ctx)]);
115
+ }
116
+ function convertScripts(element, kind, ctx) {
117
+ const children = require_mathml_nodes.elementChildren(element);
118
+ const base = argSlot("m:e", children[0], ctx);
119
+ if (kind === "msub") return require_xml_fragment.el("m:sSub", {}, [base, argSlot("m:sub", children[1], ctx)]);
120
+ if (kind === "msup") return require_xml_fragment.el("m:sSup", {}, [base, argSlot("m:sup", children[1], ctx)]);
121
+ return require_xml_fragment.el("m:sSubSup", {}, [
122
+ base,
123
+ argSlot("m:sub", children[1], ctx),
124
+ argSlot("m:sup", children[2], ctx)
125
+ ]);
126
+ }
127
+ function isMovableLimitsOperator(element) {
128
+ return element !== void 0 && require_mathml_nodes.elementLocalName(element) === "mo" && require_mathml_operators.operatorProperties(require_mathml_nodes.textContent(element).trim()).movablelimits;
129
+ }
130
+ function convertUnderOver(element, kind, ctx) {
131
+ const children = require_mathml_nodes.elementChildren(element);
132
+ if (!ctx.displayStyle && isMovableLimitsOperator(children[0])) return convertScripts(element, kind === "munder" ? "msub" : kind === "mover" ? "msup" : "msubsup", ctx);
133
+ if (kind === "munder") return require_xml_fragment.el("m:limLow", {}, [argSlot("m:e", children[0], ctx), argSlot("m:lim", children[1], ctx)]);
134
+ if (kind === "mover") return require_xml_fragment.el("m:limUpp", {}, [argSlot("m:e", children[0], ctx), argSlot("m:lim", children[1], ctx)]);
135
+ const lower = require_xml_fragment.el("m:limLow", {}, [argSlot("m:e", children[0], ctx), argSlot("m:lim", children[1], ctx)]);
136
+ return require_xml_fragment.el("m:limUpp", {}, [require_xml_fragment.el("m:e", {}, [lower]), argSlot("m:lim", children[2], ctx)]);
137
+ }
138
+ function convertTable(element, ctx) {
139
+ const rows = require_mathml_nodes.elementChildren(element).filter((child) => require_mathml_nodes.elementLocalName(child) === "mtr");
140
+ const columnAligns = (require_mathml_nodes.attrValue(element, "columnalign") ?? "").trim().split(/\s+/).filter((token) => token.length > 0);
141
+ const rowCells = rows.map((row) => require_mathml_nodes.elementChildren(row).filter((child) => require_mathml_nodes.elementLocalName(child) === "mtd"));
142
+ const columnCount = rowCells.reduce((max, cells) => Math.max(max, cells.length), 0);
143
+ const children = [];
144
+ if (columnCount > 0) {
145
+ const columns = [];
146
+ for (let column = 0; column < columnCount; column++) {
147
+ const align = columnJustification(columnAligns[column] ?? columnAligns[columnAligns.length - 1]);
148
+ columns.push(require_xml_fragment.el("m:mc", {}, [require_xml_fragment.el("m:mcPr", {}, [require_xml_fragment.el("m:count", { "m:val": "1" }), require_xml_fragment.el("m:mcJc", { "m:val": align })])]));
149
+ }
150
+ children.push(require_xml_fragment.el("m:mPr", {}, [require_xml_fragment.el("m:mcs", {}, columns)]));
151
+ }
152
+ for (const cells of rowCells) {
153
+ const slots = cells.map((cell) => argSlotFromChildren("m:e", require_mathml_nodes.elementChildren(cell), ctx));
154
+ children.push(require_xml_fragment.el("m:mr", {}, slots.length === 0 ? [require_xml_fragment.el("m:e")] : slots));
155
+ }
156
+ return require_xml_fragment.el("m:m", {}, children);
157
+ }
158
+ function convertSpace(element, ctx) {
159
+ const width = require_mathml_nodes.attrValue(element, "width");
160
+ const widthValue = width === void 0 ? void 0 : require_mathml_length.parseMathLength(width, 1);
161
+ if (widthValue === void 0 || widthValue <= 0) return [];
162
+ diagnose(ctx, "approximated-element", element);
163
+ return [mathRun(" ", require_xml_fragment.el("m:rPr", {}, [require_xml_fragment.el("m:nor")]))];
164
+ }
165
+ function convertSemantics(element, ctx) {
166
+ const content = require_mathml_nodes.elementChildren(element).find((child) => {
167
+ const name = require_mathml_nodes.elementLocalName(child);
168
+ return name !== "annotation" && name !== "annotation-xml";
169
+ });
170
+ return content === void 0 ? [] : convertElement(content, ctx);
171
+ }
172
+ function mstyleContext(element, ctx) {
173
+ let next = ctx;
174
+ const displayAttr = require_mathml_nodes.attrValue(element, "displaystyle");
175
+ if (displayAttr === "true" || displayAttr === "false") next = {
176
+ ...next,
177
+ displayStyle: displayAttr === "true"
178
+ };
179
+ const variantAttr = require_mathml_nodes.attrValue(element, "mathvariant");
180
+ if (variantAttr !== void 0 && require_mathml_variant.isMathVariant(variantAttr)) next = {
181
+ ...next,
182
+ inheritedVariant: variantAttr
183
+ };
184
+ return next;
185
+ }
186
+ function convertElement(node, ctx) {
187
+ const name = require_mathml_nodes.elementLocalName(node);
188
+ switch (name) {
189
+ case "mrow": return convertNodes(node.children, ctx);
190
+ case "mstyle": return convertNodes(node.children, mstyleContext(node, ctx));
191
+ case "semantics": return convertSemantics(node, ctx);
192
+ case "mi": {
193
+ const text = require_mathml_nodes.textContent(node);
194
+ return tokenRun(node, text, miIntrinsicDefault(text), ctx, false);
195
+ }
196
+ case "mn": return tokenRun(node, require_mathml_nodes.textContent(node), "normal", ctx, false);
197
+ case "mo": return tokenRun(node, require_mathml_nodes.textContent(node).trim(), "normal", ctx, false);
198
+ case "mtext": return tokenRun(node, require_mathml_nodes.textContent(node), "normal", ctx, true);
199
+ case "mspace": return convertSpace(node, ctx);
200
+ case "mfrac": return [convertFraction(node, ctx)];
201
+ case "msqrt": return [convertRadical(node, "msqrt", ctx)];
202
+ case "mroot": return [convertRadical(node, "mroot", ctx)];
203
+ case "msub":
204
+ case "msup":
205
+ case "msubsup": return [convertScripts(node, name, ctx)];
206
+ case "munder":
207
+ case "mover":
208
+ case "munderover": return [convertUnderOver(node, name, ctx)];
209
+ case "mtable": return [convertTable(node, ctx)];
210
+ case "mtr":
211
+ case "mtd": return convertNodes(node.children, ctx);
212
+ default:
213
+ diagnose(ctx, "unsupported-element", node);
214
+ return tokenRun(node, require_mathml_nodes.textContent(node), "normal", ctx, true);
215
+ }
216
+ }
217
+ function convertNodes(nodes, ctx) {
218
+ const out = [];
219
+ for (const node of nodes) {
220
+ if (!require_mathml_nodes.isMathMlElement(node)) continue;
221
+ out.push(...convertElement(node, ctx));
222
+ }
223
+ return out;
224
+ }
225
+ function rootContext(diagnostics) {
226
+ return {
227
+ inheritedVariant: void 0,
228
+ displayStyle: true,
229
+ diagnostics
230
+ };
231
+ }
232
+ function buildOfficeMath(mathml) {
233
+ const diagnostics = [];
234
+ const children = convertNodes(mathml, rootContext(diagnostics));
235
+ if (children.length === 0) return {
236
+ element: void 0,
237
+ diagnostics
238
+ };
239
+ return {
240
+ element: require_xml_fragment.el("m:oMath", { "xmlns:m": OMML_NS }, children),
241
+ diagnostics
242
+ };
243
+ }
244
+ function buildOfficeMathParagraph(mathml) {
245
+ const diagnostics = [];
246
+ const children = convertNodes(mathml, rootContext(diagnostics));
247
+ if (children.length === 0) return {
248
+ element: void 0,
249
+ diagnostics
250
+ };
251
+ return {
252
+ element: require_xml_fragment.el("m:oMathPara", { "xmlns:m": OMML_NS }, [require_xml_fragment.el("m:oMath", {}, children)]),
253
+ diagnostics
254
+ };
255
+ }
256
+ //#endregion
257
+ exports.buildOfficeMath = buildOfficeMath;
258
+ exports.buildOfficeMathParagraph = buildOfficeMathParagraph;
@@ -0,0 +1,2 @@
1
+ import { a as buildOfficeMathParagraph, i as buildOfficeMath, n as OmmlDiagnosticKind, r as OmmlWriteResult, t as OmmlDiagnostic } from "../write-DuyfnbL_.cjs";
2
+ export { OmmlDiagnostic, OmmlDiagnosticKind, OmmlWriteResult, buildOfficeMath, buildOfficeMathParagraph };
@@ -0,0 +1,2 @@
1
+ import { a as buildOfficeMathParagraph, i as buildOfficeMath, n as OmmlDiagnosticKind, r as OmmlWriteResult, t as OmmlDiagnostic } from "../write-Zqwx6pka.js";
2
+ export { OmmlDiagnostic, OmmlDiagnosticKind, OmmlWriteResult, buildOfficeMath, buildOfficeMathParagraph };