js.documents 1.63.0 → 1.64.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 (177) hide show
  1. package/README.md +113 -20
  2. package/dist/convert/convert.cjs +3 -3
  3. package/dist/convert/convert.d.cts +5 -2
  4. package/dist/convert/convert.d.ts +4 -1
  5. package/dist/convert/convert.js +3 -3
  6. package/dist/edit/docx/content.d.cts +1 -1
  7. package/dist/edit/docx/content.d.ts +1 -1
  8. package/dist/edit/docx/paragraph.d.cts +3 -3
  9. package/dist/edit/docx/paragraph.d.ts +3 -3
  10. package/dist/edit/ods/address.cjs +42 -24
  11. package/dist/edit/ods/address.d.cts +12 -2
  12. package/dist/edit/ods/address.d.ts +12 -2
  13. package/dist/edit/ods/address.js +39 -25
  14. package/dist/edit/ods/column-row.cjs +68 -6
  15. package/dist/edit/ods/column-row.d.cts +5 -1
  16. package/dist/edit/ods/column-row.d.ts +5 -1
  17. package/dist/edit/ods/column-row.js +68 -10
  18. package/dist/edit/ods/content.cjs +10 -2
  19. package/dist/edit/ods/content.js +10 -2
  20. package/dist/edit/ods/floating.cjs +90 -0
  21. package/dist/edit/ods/floating.d.cts +7 -0
  22. package/dist/edit/ods/floating.d.ts +7 -0
  23. package/dist/edit/ods/floating.js +88 -0
  24. package/dist/edit/ods/print-settings.cjs +158 -2
  25. package/dist/edit/ods/print-settings.js +159 -3
  26. package/dist/edit/ods/sheet.cjs +13 -0
  27. package/dist/edit/ods/sheet.d.cts +5 -1
  28. package/dist/edit/ods/sheet.d.ts +5 -1
  29. package/dist/edit/ods/sheet.js +14 -1
  30. package/dist/edit/odt/content.cjs +8 -4
  31. package/dist/edit/odt/content.js +8 -4
  32. package/dist/edit/odt/editor.cjs +7 -0
  33. package/dist/edit/odt/editor.d.cts +3 -0
  34. package/dist/edit/odt/editor.d.ts +3 -0
  35. package/dist/edit/odt/editor.js +7 -0
  36. package/dist/edit/odt/formula.cjs +19 -0
  37. package/dist/edit/odt/formula.d.cts +8 -0
  38. package/dist/edit/odt/formula.d.ts +8 -0
  39. package/dist/edit/odt/formula.js +17 -0
  40. package/dist/evaluate-BU5N1Jk1.d.ts +11 -0
  41. package/dist/evaluate-BhMXY6DM.d.cts +11 -0
  42. package/dist/firebird/backup.d.cts +1 -1
  43. package/dist/firebird/backup.d.ts +1 -1
  44. package/dist/firebird/data.cjs +30 -16
  45. package/dist/firebird/data.d.cts +3 -2
  46. package/dist/firebird/data.d.ts +3 -2
  47. package/dist/firebird/data.js +30 -17
  48. package/dist/fonts/ooxml.d.cts +1 -1
  49. package/dist/fonts/registry.d.cts +1 -1
  50. package/dist/formula-CgydMiTt.d.ts +10 -0
  51. package/dist/formula-CiwPw8nY.d.cts +10 -0
  52. package/dist/hsqldb/binary-script.d.cts +1 -1
  53. package/dist/hsqldb/binary-script.d.ts +1 -1
  54. package/dist/hsqldb/cache.d.cts +1 -1
  55. package/dist/hsqldb/cache.d.ts +1 -1
  56. package/dist/hsqldb/rowformat.cjs +22 -13
  57. package/dist/hsqldb/rowformat.js +22 -13
  58. package/dist/hsqldb/script.d.cts +1 -18
  59. package/dist/hsqldb/script.d.ts +1 -18
  60. package/dist/index.cjs +56 -0
  61. package/dist/index.d.cts +22 -8
  62. package/dist/index.d.ts +21 -7
  63. package/dist/index.js +15 -2
  64. package/dist/layout/sheets.cjs +30 -24
  65. package/dist/layout/sheets.js +31 -25
  66. package/dist/layout/slides.cjs +6 -4
  67. package/dist/layout/slides.js +7 -5
  68. package/dist/lexer-DGPWx_f2.d.cts +42 -0
  69. package/dist/lexer-DGPWx_f2.d.ts +42 -0
  70. package/dist/mathml/layout.d.cts +1 -1
  71. package/dist/mathml/layout.d.ts +1 -1
  72. package/dist/mathml/variant.d.cts +1 -6
  73. package/dist/mathml/variant.d.ts +1 -6
  74. package/dist/odb/csv.d.cts +1 -1
  75. package/dist/odb/csv.d.ts +1 -1
  76. package/dist/odb/formula/definition.cjs +49 -0
  77. package/dist/odb/formula/definition.d.cts +8 -0
  78. package/dist/odb/formula/definition.d.ts +8 -0
  79. package/dist/odb/formula/definition.js +46 -0
  80. package/dist/odb/formula/errors.cjs +47 -0
  81. package/dist/odb/formula/errors.d.cts +21 -0
  82. package/dist/odb/formula/errors.d.ts +21 -0
  83. package/dist/odb/formula/errors.js +43 -0
  84. package/dist/odb/formula/evaluate.cjs +283 -0
  85. package/dist/odb/formula/evaluate.d.cts +43 -0
  86. package/dist/odb/formula/evaluate.d.ts +43 -0
  87. package/dist/odb/formula/evaluate.js +281 -0
  88. package/dist/odb/formula/parser.cjs +198 -0
  89. package/dist/odb/formula/parser.d.cts +29 -0
  90. package/dist/odb/formula/parser.d.ts +29 -0
  91. package/dist/odb/formula/parser.js +197 -0
  92. package/dist/odb/read.d.cts +1 -1
  93. package/dist/odb/read.d.ts +1 -1
  94. package/dist/odb/report/content.cjs +27 -0
  95. package/dist/odb/report/content.d.cts +14 -0
  96. package/dist/odb/report/content.d.ts +14 -0
  97. package/dist/odb/report/content.js +25 -0
  98. package/dist/odb/report/render.cjs +106 -0
  99. package/dist/odb/report/render.d.cts +7 -0
  100. package/dist/odb/report/render.d.ts +7 -0
  101. package/dist/odb/report/render.js +106 -0
  102. package/dist/odb/report/source.cjs +45 -0
  103. package/dist/odb/report/source.d.cts +14 -0
  104. package/dist/odb/report/source.d.ts +14 -0
  105. package/dist/odb/report/source.js +42 -0
  106. package/dist/odb/spreadsheet.d.cts +1 -1
  107. package/dist/odb/spreadsheet.d.ts +1 -1
  108. package/dist/odb/sql/errors.cjs +38 -0
  109. package/dist/odb/sql/errors.d.cts +17 -0
  110. package/dist/odb/sql/errors.d.ts +17 -0
  111. package/dist/odb/sql/errors.js +35 -0
  112. package/dist/odb/sql/evaluate.cjs +312 -0
  113. package/dist/odb/sql/evaluate.d.cts +2 -0
  114. package/dist/odb/sql/evaluate.d.ts +2 -0
  115. package/dist/odb/sql/evaluate.js +311 -0
  116. package/dist/odb/sql/lexer.cjs +282 -0
  117. package/dist/odb/sql/lexer.d.cts +2 -0
  118. package/dist/odb/sql/lexer.d.ts +2 -0
  119. package/dist/odb/sql/lexer.js +281 -0
  120. package/dist/odb/sql/parser.cjs +479 -0
  121. package/dist/odb/sql/parser.d.cts +2 -0
  122. package/dist/odb/sql/parser.d.ts +2 -0
  123. package/dist/odb/sql/parser.js +478 -0
  124. package/dist/odb/values.cjs +75 -0
  125. package/dist/odb/values.d.cts +2 -0
  126. package/dist/odb/values.d.ts +2 -0
  127. package/dist/odb/values.js +69 -0
  128. package/dist/odf/odt/read.cjs +43 -21
  129. package/dist/odf/odt/read.js +43 -21
  130. package/dist/odf-package/formula.cjs +59 -0
  131. package/dist/odf-package/formula.d.cts +11 -0
  132. package/dist/odf-package/formula.d.ts +11 -0
  133. package/dist/odf-package/formula.js +58 -0
  134. package/dist/odf-package/manifest.cjs +29 -0
  135. package/dist/odf-package/manifest.d.cts +5 -2
  136. package/dist/odf-package/manifest.d.ts +5 -2
  137. package/dist/odf-package/manifest.js +30 -2
  138. package/dist/odf-package/media.cjs +2 -1
  139. package/dist/odf-package/media.js +2 -2
  140. package/dist/omml/read.cjs +265 -0
  141. package/dist/omml/read.d.cts +12 -0
  142. package/dist/omml/read.d.ts +12 -0
  143. package/dist/omml/read.js +263 -0
  144. package/dist/omml/shared.cjs +67 -0
  145. package/dist/omml/shared.d.cts +2 -0
  146. package/dist/omml/shared.d.ts +2 -0
  147. package/dist/omml/shared.js +64 -0
  148. package/dist/omml/write.cjs +3 -51
  149. package/dist/omml/write.d.cts +2 -2
  150. package/dist/omml/write.d.ts +2 -2
  151. package/dist/omml/write.js +1 -49
  152. package/dist/ooxml/docx/extras.cjs +15 -0
  153. package/dist/ooxml/docx/extras.d.cts +12 -0
  154. package/dist/ooxml/docx/extras.d.ts +12 -0
  155. package/dist/ooxml/docx/extras.js +14 -0
  156. package/dist/ooxml/docx/formula.cjs +109 -0
  157. package/dist/ooxml/docx/formula.d.cts +2 -0
  158. package/dist/ooxml/docx/formula.d.ts +2 -0
  159. package/dist/ooxml/docx/formula.js +108 -0
  160. package/dist/ooxml/docx/read.cjs +10 -2
  161. package/dist/ooxml/docx/read.d.cts +6 -2
  162. package/dist/ooxml/docx/read.d.ts +6 -2
  163. package/dist/ooxml/docx/read.js +11 -3
  164. package/dist/parser-B9vC1T6T.d.cts +101 -0
  165. package/dist/parser-DQSgYJzQ.d.ts +101 -0
  166. package/dist/{registry-CtPhMD0f.d.cts → registry-lqJej0Jr.d.cts} +1 -1
  167. package/dist/script-DsGGIzGU.d.cts +19 -0
  168. package/dist/script-DsGGIzGU.d.ts +19 -0
  169. package/dist/shared-DLZ3IQUl.d.cts +15 -0
  170. package/dist/shared-DUOzjwcL.d.ts +15 -0
  171. package/dist/values-BetetbaH.d.cts +23 -0
  172. package/dist/values-BetetbaH.d.ts +23 -0
  173. package/dist/variant-BMrebjMw.d.cts +7 -0
  174. package/dist/variant-BMrebjMw.d.ts +7 -0
  175. package/dist/{write-DuyfnbL_.d.cts → write-BQ6SK8r8.d.cts} +2 -6
  176. package/dist/{write-Zqwx6pka.d.ts → write-THs7ipBq.d.ts} +2 -6
  177. package/package.json +1 -1
@@ -13,10 +13,10 @@ function readOdtContent(pkg) {
13
13
  const text = body === void 0 ? void 0 : (0, odf_js.findChildElement)(body.children, "office:text");
14
14
  if (text !== void 0) {
15
15
  const section = odtDoc.sections[0];
16
- const placements = collectFormulaPlacements(text.children, pkg);
16
+ const { placements, consumedBlockIndices } = collectFormulaPlacements(text.children, pkg);
17
17
  if (placements.length > 0) odtDoc.sections[0] = {
18
18
  ...section,
19
- blocks: spliceFormulaBlocks(section.blocks, placements)
19
+ blocks: spliceFormulaBlocks(section.blocks, placements, consumedBlockIndices)
20
20
  };
21
21
  }
22
22
  }
@@ -33,39 +33,61 @@ function pushPlacements(out, index, detected) {
33
33
  detected: frame
34
34
  });
35
35
  }
36
+ function isFormulaOnlyParagraph(paragraph, detected) {
37
+ if (detected.length === 0) return false;
38
+ const frames = detected.map((entry) => entry.frameElement);
39
+ for (const child of paragraph.children) {
40
+ if (child.type === "text") {
41
+ if (child.value.trim().length > 0) return false;
42
+ continue;
43
+ }
44
+ if (child.type !== "element") continue;
45
+ if (!frames.includes(child)) return false;
46
+ }
47
+ return true;
48
+ }
49
+ function pushParagraphPlacements(node, pkg, state) {
50
+ const detected = require_odf_formula_detect.collectFormulaFrames(node.children, pkg);
51
+ state.blockCount += 1;
52
+ if (isFormulaOnlyParagraph(node, detected)) state.consumedBlockIndices.add(state.blockCount - 1);
53
+ pushPlacements(state.placements, state.blockCount, detected);
54
+ }
36
55
  function collectFormulaPlacements(nodes, pkg) {
37
- const out = [];
38
- walkForPlacements(nodes, pkg, { blockCount: 0 }, out);
39
- return out;
56
+ const state = {
57
+ blockCount: 0,
58
+ placements: [],
59
+ consumedBlockIndices: /* @__PURE__ */ new Set()
60
+ };
61
+ walkForPlacements(nodes, pkg, state);
62
+ return {
63
+ placements: state.placements,
64
+ consumedBlockIndices: state.consumedBlockIndices
65
+ };
40
66
  }
41
- function walkForPlacements(nodes, pkg, state, out) {
67
+ function walkForPlacements(nodes, pkg, state) {
42
68
  for (const node of nodes) {
43
69
  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);
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);
48
72
  else if (node.tag === "table:table") {
49
73
  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));
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));
53
77
  }
54
78
  }
55
- function walkListForPlacements(itemNodes, pkg, state, out) {
79
+ function walkListForPlacements(itemNodes, pkg, state) {
56
80
  for (const item of itemNodes) {
57
81
  if (item.type !== "element" || item.tag !== "text:list-item") continue;
58
82
  for (const itemChild of item.children) {
59
83
  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));
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));
65
87
  }
66
88
  }
67
89
  }
68
- function spliceFormulaBlocks(blocks, placements) {
90
+ function spliceFormulaBlocks(blocks, placements, consumedBlockIndices) {
69
91
  const out = [];
70
92
  let next = 0;
71
93
  for (let index = 0; index <= blocks.length; index++) {
@@ -75,7 +97,7 @@ function spliceFormulaBlocks(blocks, placements) {
75
97
  next += 1;
76
98
  }
77
99
  const block = blocks[index];
78
- if (block !== void 0) out.push(block);
100
+ if (block !== void 0 && !consumedBlockIndices.has(index)) out.push(block);
79
101
  }
80
102
  return out;
81
103
  }
@@ -12,10 +12,10 @@ function readOdtContent(pkg) {
12
12
  const text = body === void 0 ? void 0 : findChildElement(body.children, "office:text");
13
13
  if (text !== void 0) {
14
14
  const section = odtDoc.sections[0];
15
- const placements = collectFormulaPlacements(text.children, pkg);
15
+ const { placements, consumedBlockIndices } = collectFormulaPlacements(text.children, pkg);
16
16
  if (placements.length > 0) odtDoc.sections[0] = {
17
17
  ...section,
18
- blocks: spliceFormulaBlocks(section.blocks, placements)
18
+ blocks: spliceFormulaBlocks(section.blocks, placements, consumedBlockIndices)
19
19
  };
20
20
  }
21
21
  }
@@ -32,39 +32,61 @@ function pushPlacements(out, index, detected) {
32
32
  detected: frame
33
33
  });
34
34
  }
35
+ function isFormulaOnlyParagraph(paragraph, detected) {
36
+ if (detected.length === 0) return false;
37
+ const frames = detected.map((entry) => entry.frameElement);
38
+ for (const child of paragraph.children) {
39
+ if (child.type === "text") {
40
+ if (child.value.trim().length > 0) return false;
41
+ continue;
42
+ }
43
+ if (child.type !== "element") continue;
44
+ if (!frames.includes(child)) return false;
45
+ }
46
+ return true;
47
+ }
48
+ function pushParagraphPlacements(node, pkg, state) {
49
+ const detected = collectFormulaFrames(node.children, pkg);
50
+ state.blockCount += 1;
51
+ if (isFormulaOnlyParagraph(node, detected)) state.consumedBlockIndices.add(state.blockCount - 1);
52
+ pushPlacements(state.placements, state.blockCount, detected);
53
+ }
35
54
  function collectFormulaPlacements(nodes, pkg) {
36
- const out = [];
37
- walkForPlacements(nodes, pkg, { blockCount: 0 }, out);
38
- return out;
55
+ const state = {
56
+ blockCount: 0,
57
+ placements: [],
58
+ consumedBlockIndices: /* @__PURE__ */ new Set()
59
+ };
60
+ walkForPlacements(nodes, pkg, state);
61
+ return {
62
+ placements: state.placements,
63
+ consumedBlockIndices: state.consumedBlockIndices
64
+ };
39
65
  }
40
- function walkForPlacements(nodes, pkg, state, out) {
66
+ function walkForPlacements(nodes, pkg, state) {
41
67
  for (const node of nodes) {
42
68
  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);
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);
47
71
  else if (node.tag === "table:table") {
48
72
  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));
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));
52
76
  }
53
77
  }
54
- function walkListForPlacements(itemNodes, pkg, state, out) {
78
+ function walkListForPlacements(itemNodes, pkg, state) {
55
79
  for (const item of itemNodes) {
56
80
  if (item.type !== "element" || item.tag !== "text:list-item") continue;
57
81
  for (const itemChild of item.children) {
58
82
  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));
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));
64
86
  }
65
87
  }
66
88
  }
67
- function spliceFormulaBlocks(blocks, placements) {
89
+ function spliceFormulaBlocks(blocks, placements, consumedBlockIndices) {
68
90
  const out = [];
69
91
  let next = 0;
70
92
  for (let index = 0; index <= blocks.length; index++) {
@@ -74,7 +96,7 @@ function spliceFormulaBlocks(blocks, placements) {
74
96
  next += 1;
75
97
  }
76
98
  const block = blocks[index];
77
- if (block !== void 0) out.push(block);
99
+ if (block !== void 0 && !consumedBlockIndices.has(index)) out.push(block);
78
100
  }
79
101
  return out;
80
102
  }
@@ -0,0 +1,59 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_xml_fragment = require("../xml/fragment.cjs");
3
+ const require_xml_entities = require("../xml/entities.cjs");
4
+ const require_odf_package_manifest = require("./manifest.cjs");
5
+ //#region src/odf-package/formula.ts
6
+ const OBJECT_PREFIX = "Object ";
7
+ const CONTENT_PART = "content.xml";
8
+ const MATHML_NS = "http://www.w3.org/1998/Math/MathML";
9
+ const OFFICE_NS = "urn:oasis:names:tc:opendocument:xmlns:office:1.0";
10
+ const ODF_VERSION = "1.3";
11
+ const STARMATH_ENCODING = "StarMath 5.0";
12
+ function nextObjectIndex(pkg) {
13
+ const pattern = /^Object (\d+)\//;
14
+ let max = 0;
15
+ for (const path of Object.keys(pkg.parts)) {
16
+ const digits = pattern.exec(path)?.[1];
17
+ if (digits === void 0) continue;
18
+ const index = Number.parseInt(digits, 10);
19
+ if (index > max) max = index;
20
+ }
21
+ return max + 1;
22
+ }
23
+ function buildFormulaContentXml(formula) {
24
+ const mathChildren = [...formula.mathml];
25
+ if (formula.starMath !== void 0) mathChildren.push(require_xml_fragment.el("math:annotation", { encoding: STARMATH_ENCODING }, [require_xml_fragment.txt(require_xml_entities.encodeXmlText(formula.starMath))]));
26
+ return require_xml_fragment.el("office:document-content", {
27
+ "xmlns:office": OFFICE_NS,
28
+ "xmlns:math": MATHML_NS,
29
+ "office:version": ODF_VERSION
30
+ }, [require_xml_fragment.el("office:body", {}, [require_xml_fragment.el("office:math", {}, [require_xml_fragment.el("math:math", {
31
+ xmlns: MATHML_NS,
32
+ "xmlns:math": MATHML_NS
33
+ }, mathChildren)])])]);
34
+ }
35
+ function addFormulaObject(pkg, formula) {
36
+ const objectName = `${OBJECT_PREFIX}${nextObjectIndex(pkg)}`;
37
+ const partPath = `${objectName}/${CONTENT_PART}`;
38
+ pkg.parts[partPath] = {
39
+ kind: "xml",
40
+ nodes: [{
41
+ type: "declaration",
42
+ attributes: [{
43
+ name: "version",
44
+ value: "1.0"
45
+ }, {
46
+ name: "encoding",
47
+ value: "UTF-8"
48
+ }]
49
+ }, buildFormulaContentXml(formula)]
50
+ };
51
+ require_odf_package_manifest.syncOdfManifest(pkg);
52
+ return {
53
+ objectName,
54
+ href: `./${objectName}`,
55
+ partPath
56
+ };
57
+ }
58
+ //#endregion
59
+ exports.addFormulaObject = addFormulaObject;
@@ -0,0 +1,11 @@
1
+ import { ContentFormula } from "document-schema.js";
2
+ import { Package } from "odf.js";
3
+ //#region src/odf-package/formula.d.ts
4
+ interface AddedOdfFormula {
5
+ readonly objectName: string;
6
+ readonly href: string;
7
+ readonly partPath: string;
8
+ }
9
+ declare function addFormulaObject(pkg: Package, formula: ContentFormula): AddedOdfFormula;
10
+ //#endregion
11
+ export { AddedOdfFormula, addFormulaObject };
@@ -0,0 +1,11 @@
1
+ import { ContentFormula } from "document-schema.js";
2
+ import { Package } from "odf.js";
3
+ //#region src/odf-package/formula.d.ts
4
+ interface AddedOdfFormula {
5
+ readonly objectName: string;
6
+ readonly href: string;
7
+ readonly partPath: string;
8
+ }
9
+ declare function addFormulaObject(pkg: Package, formula: ContentFormula): AddedOdfFormula;
10
+ //#endregion
11
+ export { AddedOdfFormula, addFormulaObject };
@@ -0,0 +1,58 @@
1
+ import { el, txt } from "../xml/fragment.js";
2
+ import { encodeXmlText } from "../xml/entities.js";
3
+ import { syncOdfManifest } from "./manifest.js";
4
+ //#region src/odf-package/formula.ts
5
+ const OBJECT_PREFIX = "Object ";
6
+ const CONTENT_PART = "content.xml";
7
+ const MATHML_NS = "http://www.w3.org/1998/Math/MathML";
8
+ const OFFICE_NS = "urn:oasis:names:tc:opendocument:xmlns:office:1.0";
9
+ const ODF_VERSION = "1.3";
10
+ const STARMATH_ENCODING = "StarMath 5.0";
11
+ function nextObjectIndex(pkg) {
12
+ const pattern = /^Object (\d+)\//;
13
+ let max = 0;
14
+ for (const path of Object.keys(pkg.parts)) {
15
+ const digits = pattern.exec(path)?.[1];
16
+ if (digits === void 0) continue;
17
+ const index = Number.parseInt(digits, 10);
18
+ if (index > max) max = index;
19
+ }
20
+ return max + 1;
21
+ }
22
+ function buildFormulaContentXml(formula) {
23
+ const mathChildren = [...formula.mathml];
24
+ if (formula.starMath !== void 0) mathChildren.push(el("math:annotation", { encoding: STARMATH_ENCODING }, [txt(encodeXmlText(formula.starMath))]));
25
+ return el("office:document-content", {
26
+ "xmlns:office": OFFICE_NS,
27
+ "xmlns:math": MATHML_NS,
28
+ "office:version": ODF_VERSION
29
+ }, [el("office:body", {}, [el("office:math", {}, [el("math:math", {
30
+ xmlns: MATHML_NS,
31
+ "xmlns:math": MATHML_NS
32
+ }, mathChildren)])])]);
33
+ }
34
+ function addFormulaObject(pkg, formula) {
35
+ const objectName = `${OBJECT_PREFIX}${nextObjectIndex(pkg)}`;
36
+ const partPath = `${objectName}/${CONTENT_PART}`;
37
+ pkg.parts[partPath] = {
38
+ kind: "xml",
39
+ nodes: [{
40
+ type: "declaration",
41
+ attributes: [{
42
+ name: "version",
43
+ value: "1.0"
44
+ }, {
45
+ name: "encoding",
46
+ value: "UTF-8"
47
+ }]
48
+ }, buildFormulaContentXml(formula)]
49
+ };
50
+ syncOdfManifest(pkg);
51
+ return {
52
+ objectName,
53
+ href: `./${objectName}`,
54
+ partPath
55
+ };
56
+ }
57
+ //#endregion
58
+ export { addFormulaObject };
@@ -1,5 +1,33 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  let odf_js = require("odf.js");
3
+ //#region src/odf-package/manifest.ts
4
+ const CONTENT_PART_SUFFIX = "/content.xml";
5
+ const ROOT_CONTENT_PART = "content.xml";
6
+ const MEDIA_TYPE_BY_BODY_ELEMENT = /* @__PURE__ */ new Map([
7
+ ["office:text", odf_js.ODF_MEDIA_TYPES.odt],
8
+ ["office:spreadsheet", odf_js.ODF_MEDIA_TYPES.ods],
9
+ ["office:presentation", odf_js.ODF_MEDIA_TYPES.odp],
10
+ ["office:drawing", odf_js.ODF_MEDIA_TYPES.odg],
11
+ ["office:math", odf_js.ODF_MEDIA_TYPES.odf]
12
+ ]);
13
+ function subDocumentMediaType(pkg, directory) {
14
+ const part = pkg.parts[`${directory}${ROOT_CONTENT_PART}`];
15
+ const root = part?.kind === "xml" ? (0, odf_js.rootElement)(part.nodes) : void 0;
16
+ const body = root === void 0 ? void 0 : (0, odf_js.findChildElement)(root.children, "office:body");
17
+ if (body === void 0) return;
18
+ for (const child of body.children) if (child.type === "element") return MEDIA_TYPE_BY_BODY_ELEMENT.get(child.tag);
19
+ }
20
+ function syncOdfManifest(pkg) {
21
+ const mediaTypeOverrides = {};
22
+ for (const path of Object.keys(pkg.parts)) {
23
+ if (!path.endsWith(CONTENT_PART_SUFFIX) || path === ROOT_CONTENT_PART) continue;
24
+ const directory = path.slice(0, path.length - 11);
25
+ const mediaType = subDocumentMediaType(pkg, directory);
26
+ if (mediaType !== void 0) mediaTypeOverrides[directory] = mediaType;
27
+ }
28
+ (0, odf_js.syncManifest)(pkg, { mediaTypeOverrides });
29
+ }
30
+ //#endregion
3
31
  Object.defineProperty(exports, "MANIFEST_PART", {
4
32
  enumerable: true,
5
33
  get: function() {
@@ -48,6 +76,7 @@ Object.defineProperty(exports, "syncManifest", {
48
76
  return odf_js.syncManifest;
49
77
  }
50
78
  });
79
+ exports.syncOdfManifest = syncOdfManifest;
51
80
  Object.defineProperty(exports, "validateManifest", {
52
81
  enumerable: true,
53
82
  get: function() {
@@ -1,2 +1,5 @@
1
- import { BuildManifestOptions, MANIFEST_PART, Manifest, ManifestEntry, ManifestEntrySchema, ManifestProblem, ManifestProblemSchema, ManifestSchema, buildManifest, readManifest, setDocumentMediaType, syncManifest, validateManifest, writeManifest } from "odf.js";
2
- export { type BuildManifestOptions, MANIFEST_PART, type Manifest, type ManifestEntry, ManifestEntrySchema, type ManifestProblem, ManifestProblemSchema, ManifestSchema, buildManifest, readManifest, setDocumentMediaType, syncManifest, validateManifest, writeManifest };
1
+ import { BuildManifestOptions, MANIFEST_PART, Manifest, ManifestEntry, ManifestEntrySchema, ManifestProblem, ManifestProblemSchema, ManifestSchema, Package, buildManifest, readManifest, setDocumentMediaType, syncManifest, validateManifest, writeManifest } from "odf.js";
2
+ //#region src/odf-package/manifest.d.ts
3
+ declare function syncOdfManifest(pkg: Package): void;
4
+ //#endregion
5
+ export { type BuildManifestOptions, MANIFEST_PART, type Manifest, type ManifestEntry, ManifestEntrySchema, type ManifestProblem, ManifestProblemSchema, ManifestSchema, buildManifest, readManifest, setDocumentMediaType, syncManifest, syncOdfManifest, validateManifest, writeManifest };
@@ -1,2 +1,5 @@
1
- import { BuildManifestOptions, MANIFEST_PART, Manifest, ManifestEntry, ManifestEntrySchema, ManifestProblem, ManifestProblemSchema, ManifestSchema, buildManifest, readManifest, setDocumentMediaType, syncManifest, validateManifest, writeManifest } from "odf.js";
2
- export { type BuildManifestOptions, MANIFEST_PART, type Manifest, type ManifestEntry, ManifestEntrySchema, type ManifestProblem, ManifestProblemSchema, ManifestSchema, buildManifest, readManifest, setDocumentMediaType, syncManifest, validateManifest, writeManifest };
1
+ import { BuildManifestOptions, MANIFEST_PART, Manifest, ManifestEntry, ManifestEntrySchema, ManifestProblem, ManifestProblemSchema, ManifestSchema, Package, buildManifest, readManifest, setDocumentMediaType, syncManifest, validateManifest, writeManifest } from "odf.js";
2
+ //#region src/odf-package/manifest.d.ts
3
+ declare function syncOdfManifest(pkg: Package): void;
4
+ //#endregion
5
+ export { type BuildManifestOptions, MANIFEST_PART, type Manifest, type ManifestEntry, ManifestEntrySchema, type ManifestProblem, ManifestProblemSchema, ManifestSchema, buildManifest, readManifest, setDocumentMediaType, syncManifest, syncOdfManifest, validateManifest, writeManifest };
@@ -1,2 +1,30 @@
1
- import { MANIFEST_PART, ManifestEntrySchema, ManifestProblemSchema, ManifestSchema, buildManifest, readManifest, setDocumentMediaType, syncManifest, validateManifest, writeManifest } from "odf.js";
2
- export { MANIFEST_PART, ManifestEntrySchema, ManifestProblemSchema, ManifestSchema, buildManifest, readManifest, setDocumentMediaType, syncManifest, validateManifest, writeManifest };
1
+ import { MANIFEST_PART, ManifestEntrySchema, ManifestProblemSchema, ManifestSchema, ODF_MEDIA_TYPES, buildManifest, findChildElement, readManifest, rootElement, setDocumentMediaType, syncManifest, syncManifest as syncManifest$1, validateManifest, writeManifest } from "odf.js";
2
+ //#region src/odf-package/manifest.ts
3
+ const CONTENT_PART_SUFFIX = "/content.xml";
4
+ const ROOT_CONTENT_PART = "content.xml";
5
+ const MEDIA_TYPE_BY_BODY_ELEMENT = /* @__PURE__ */ new Map([
6
+ ["office:text", ODF_MEDIA_TYPES.odt],
7
+ ["office:spreadsheet", ODF_MEDIA_TYPES.ods],
8
+ ["office:presentation", ODF_MEDIA_TYPES.odp],
9
+ ["office:drawing", ODF_MEDIA_TYPES.odg],
10
+ ["office:math", ODF_MEDIA_TYPES.odf]
11
+ ]);
12
+ function subDocumentMediaType(pkg, directory) {
13
+ const part = pkg.parts[`${directory}${ROOT_CONTENT_PART}`];
14
+ const root = part?.kind === "xml" ? rootElement(part.nodes) : void 0;
15
+ const body = root === void 0 ? void 0 : findChildElement(root.children, "office:body");
16
+ if (body === void 0) return;
17
+ for (const child of body.children) if (child.type === "element") return MEDIA_TYPE_BY_BODY_ELEMENT.get(child.tag);
18
+ }
19
+ function syncOdfManifest(pkg) {
20
+ const mediaTypeOverrides = {};
21
+ for (const path of Object.keys(pkg.parts)) {
22
+ if (!path.endsWith(CONTENT_PART_SUFFIX) || path === ROOT_CONTENT_PART) continue;
23
+ const directory = path.slice(0, path.length - 11);
24
+ const mediaType = subDocumentMediaType(pkg, directory);
25
+ if (mediaType !== void 0) mediaTypeOverrides[directory] = mediaType;
26
+ }
27
+ syncManifest$1(pkg, { mediaTypeOverrides });
28
+ }
29
+ //#endregion
30
+ export { MANIFEST_PART, ManifestEntrySchema, ManifestProblemSchema, ManifestSchema, buildManifest, readManifest, setDocumentMediaType, syncManifest, syncOdfManifest, validateManifest, writeManifest };
@@ -1,4 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_odf_package_manifest = require("./manifest.cjs");
2
3
  let odf_js = require("odf.js");
3
4
  //#region src/odf-package/media.ts
4
5
  const PICTURES_DIR = "Pictures";
@@ -27,7 +28,7 @@ function addImageMedia(pkg, imageBytes, format) {
27
28
  kind: "binary",
28
29
  base64: (0, odf_js.bytesToBase64)(imageBytes)
29
30
  };
30
- (0, odf_js.syncManifest)(pkg);
31
+ require_odf_package_manifest.syncOdfManifest(pkg);
31
32
  return { partPath };
32
33
  }
33
34
  //#endregion
@@ -1,4 +1,4 @@
1
- import { syncManifest as syncManifest$1 } from "./manifest.js";
1
+ import { syncOdfManifest } from "./manifest.js";
2
2
  import { bytesToBase64 } from "odf.js";
3
3
  //#region src/odf-package/media.ts
4
4
  const PICTURES_DIR = "Pictures";
@@ -27,7 +27,7 @@ function addImageMedia(pkg, imageBytes, format) {
27
27
  kind: "binary",
28
28
  base64: bytesToBase64(imageBytes)
29
29
  };
30
- syncManifest$1(pkg);
30
+ syncOdfManifest(pkg);
31
31
  return { partPath };
32
32
  }
33
33
  //#endregion