documents.js 1.63.0 → 1.65.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 (187) hide show
  1. package/README.md +124 -25
  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 +24 -10
  62. package/dist/index.d.ts +23 -9
  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/compose.cjs +8 -0
  71. package/dist/mathml/compose.js +8 -0
  72. package/dist/mathml/layout-types.d.cts +14 -2
  73. package/dist/mathml/layout-types.d.ts +14 -2
  74. package/dist/mathml/layout.cjs +62 -3
  75. package/dist/mathml/layout.d.cts +1 -1
  76. package/dist/mathml/layout.d.ts +1 -1
  77. package/dist/mathml/layout.js +62 -3
  78. package/dist/mathml/metrics.d.cts +17 -1
  79. package/dist/mathml/metrics.d.ts +17 -1
  80. package/dist/mathml/operators.cjs +1 -1
  81. package/dist/mathml/operators.js +1 -1
  82. package/dist/mathml/variant.d.cts +1 -6
  83. package/dist/mathml/variant.d.ts +1 -6
  84. package/dist/odb/csv.d.cts +1 -1
  85. package/dist/odb/csv.d.ts +1 -1
  86. package/dist/odb/formula/definition.cjs +49 -0
  87. package/dist/odb/formula/definition.d.cts +8 -0
  88. package/dist/odb/formula/definition.d.ts +8 -0
  89. package/dist/odb/formula/definition.js +46 -0
  90. package/dist/odb/formula/errors.cjs +47 -0
  91. package/dist/odb/formula/errors.d.cts +21 -0
  92. package/dist/odb/formula/errors.d.ts +21 -0
  93. package/dist/odb/formula/errors.js +43 -0
  94. package/dist/odb/formula/evaluate.cjs +283 -0
  95. package/dist/odb/formula/evaluate.d.cts +43 -0
  96. package/dist/odb/formula/evaluate.d.ts +43 -0
  97. package/dist/odb/formula/evaluate.js +281 -0
  98. package/dist/odb/formula/parser.cjs +198 -0
  99. package/dist/odb/formula/parser.d.cts +29 -0
  100. package/dist/odb/formula/parser.d.ts +29 -0
  101. package/dist/odb/formula/parser.js +197 -0
  102. package/dist/odb/read.d.cts +1 -1
  103. package/dist/odb/read.d.ts +1 -1
  104. package/dist/odb/report/content.cjs +27 -0
  105. package/dist/odb/report/content.d.cts +14 -0
  106. package/dist/odb/report/content.d.ts +14 -0
  107. package/dist/odb/report/content.js +25 -0
  108. package/dist/odb/report/render.cjs +106 -0
  109. package/dist/odb/report/render.d.cts +7 -0
  110. package/dist/odb/report/render.d.ts +7 -0
  111. package/dist/odb/report/render.js +106 -0
  112. package/dist/odb/report/source.cjs +45 -0
  113. package/dist/odb/report/source.d.cts +14 -0
  114. package/dist/odb/report/source.d.ts +14 -0
  115. package/dist/odb/report/source.js +42 -0
  116. package/dist/odb/spreadsheet.d.cts +1 -1
  117. package/dist/odb/spreadsheet.d.ts +1 -1
  118. package/dist/odb/sql/errors.cjs +38 -0
  119. package/dist/odb/sql/errors.d.cts +17 -0
  120. package/dist/odb/sql/errors.d.ts +17 -0
  121. package/dist/odb/sql/errors.js +35 -0
  122. package/dist/odb/sql/evaluate.cjs +312 -0
  123. package/dist/odb/sql/evaluate.d.cts +2 -0
  124. package/dist/odb/sql/evaluate.d.ts +2 -0
  125. package/dist/odb/sql/evaluate.js +311 -0
  126. package/dist/odb/sql/lexer.cjs +282 -0
  127. package/dist/odb/sql/lexer.d.cts +2 -0
  128. package/dist/odb/sql/lexer.d.ts +2 -0
  129. package/dist/odb/sql/lexer.js +281 -0
  130. package/dist/odb/sql/parser.cjs +479 -0
  131. package/dist/odb/sql/parser.d.cts +2 -0
  132. package/dist/odb/sql/parser.d.ts +2 -0
  133. package/dist/odb/sql/parser.js +478 -0
  134. package/dist/odb/values.cjs +75 -0
  135. package/dist/odb/values.d.cts +2 -0
  136. package/dist/odb/values.d.ts +2 -0
  137. package/dist/odb/values.js +69 -0
  138. package/dist/odf/odt/read.cjs +43 -21
  139. package/dist/odf/odt/read.js +43 -21
  140. package/dist/odf-package/formula.cjs +59 -0
  141. package/dist/odf-package/formula.d.cts +11 -0
  142. package/dist/odf-package/formula.d.ts +11 -0
  143. package/dist/odf-package/formula.js +58 -0
  144. package/dist/odf-package/manifest.cjs +29 -0
  145. package/dist/odf-package/manifest.d.cts +5 -2
  146. package/dist/odf-package/manifest.d.ts +5 -2
  147. package/dist/odf-package/manifest.js +30 -2
  148. package/dist/odf-package/media.cjs +2 -1
  149. package/dist/odf-package/media.js +2 -2
  150. package/dist/omml/read.cjs +265 -0
  151. package/dist/omml/read.d.cts +12 -0
  152. package/dist/omml/read.d.ts +12 -0
  153. package/dist/omml/read.js +263 -0
  154. package/dist/omml/shared.cjs +67 -0
  155. package/dist/omml/shared.d.cts +2 -0
  156. package/dist/omml/shared.d.ts +2 -0
  157. package/dist/omml/shared.js +64 -0
  158. package/dist/omml/write.cjs +3 -51
  159. package/dist/omml/write.d.cts +2 -2
  160. package/dist/omml/write.d.ts +2 -2
  161. package/dist/omml/write.js +1 -49
  162. package/dist/ooxml/docx/extras.cjs +15 -0
  163. package/dist/ooxml/docx/extras.d.cts +12 -0
  164. package/dist/ooxml/docx/extras.d.ts +12 -0
  165. package/dist/ooxml/docx/extras.js +14 -0
  166. package/dist/ooxml/docx/formula.cjs +109 -0
  167. package/dist/ooxml/docx/formula.d.cts +2 -0
  168. package/dist/ooxml/docx/formula.d.ts +2 -0
  169. package/dist/ooxml/docx/formula.js +108 -0
  170. package/dist/ooxml/docx/read.cjs +10 -2
  171. package/dist/ooxml/docx/read.d.cts +6 -2
  172. package/dist/ooxml/docx/read.d.ts +6 -2
  173. package/dist/ooxml/docx/read.js +11 -3
  174. package/dist/parser-B9vC1T6T.d.cts +101 -0
  175. package/dist/parser-DQSgYJzQ.d.ts +101 -0
  176. package/dist/{registry-CtPhMD0f.d.cts → registry-lqJej0Jr.d.cts} +1 -1
  177. package/dist/script-DsGGIzGU.d.cts +19 -0
  178. package/dist/script-DsGGIzGU.d.ts +19 -0
  179. package/dist/shared-DLZ3IQUl.d.cts +15 -0
  180. package/dist/shared-DUOzjwcL.d.ts +15 -0
  181. package/dist/values-BetetbaH.d.cts +23 -0
  182. package/dist/values-BetetbaH.d.ts +23 -0
  183. package/dist/variant-BMrebjMw.d.cts +7 -0
  184. package/dist/variant-BMrebjMw.d.ts +7 -0
  185. package/dist/{write-DuyfnbL_.d.cts → write-BQ6SK8r8.d.cts} +2 -6
  186. package/dist/{write-Zqwx6pka.d.ts → write-THs7ipBq.d.ts} +2 -6
  187. package/package.json +2 -2
@@ -0,0 +1,64 @@
1
+ import { isMathVariant } from "../mathml/variant.js";
2
+ //#region src/omml/shared.ts
3
+ const VARIANT_RUN_PROPERTIES = {
4
+ normal: { sty: "p" },
5
+ bold: { sty: "b" },
6
+ italic: { sty: "i" },
7
+ "bold-italic": { sty: "bi" },
8
+ "double-struck": {
9
+ scr: "double-struck",
10
+ sty: "p"
11
+ },
12
+ script: {
13
+ scr: "script",
14
+ sty: "p"
15
+ },
16
+ "bold-script": {
17
+ scr: "script",
18
+ sty: "b"
19
+ },
20
+ fraktur: {
21
+ scr: "fraktur",
22
+ sty: "p"
23
+ },
24
+ "bold-fraktur": {
25
+ scr: "fraktur",
26
+ sty: "b"
27
+ },
28
+ "sans-serif": {
29
+ scr: "sans-serif",
30
+ sty: "p"
31
+ },
32
+ "bold-sans-serif": {
33
+ scr: "sans-serif",
34
+ sty: "b"
35
+ },
36
+ "sans-serif-italic": {
37
+ scr: "sans-serif",
38
+ sty: "i"
39
+ },
40
+ "sans-serif-bold-italic": {
41
+ scr: "sans-serif",
42
+ sty: "bi"
43
+ },
44
+ monospace: {
45
+ scr: "monospace",
46
+ sty: "p"
47
+ }
48
+ };
49
+ const DEFAULT_SCRIPT = "roman";
50
+ const DEFAULT_STYLE = "i";
51
+ function buildVariantLookup() {
52
+ const lookup = /* @__PURE__ */ new Map();
53
+ for (const [variant, mapped] of Object.entries(VARIANT_RUN_PROPERTIES)) if (isMathVariant(variant)) lookup.set(`${mapped.scr ?? DEFAULT_SCRIPT}|${mapped.sty}`, variant);
54
+ return lookup;
55
+ }
56
+ const VARIANT_BY_RUN_PROPERTIES = buildVariantLookup();
57
+ function variantFromRunProperties(script, style) {
58
+ return VARIANT_BY_RUN_PROPERTIES.get(`${script ?? DEFAULT_SCRIPT}|${style ?? DEFAULT_STYLE}`);
59
+ }
60
+ function miIntrinsicDefault(content) {
61
+ return [...content].length === 1 ? "italic" : "normal";
62
+ }
63
+ //#endregion
64
+ export { VARIANT_RUN_PROPERTIES, miIntrinsicDefault, variantFromRunProperties };
@@ -5,54 +5,9 @@ const require_mathml_nodes = require("../mathml/nodes.cjs");
5
5
  const require_mathml_operators = require("../mathml/operators.cjs");
6
6
  const require_mathml_variant = require("../mathml/variant.cjs");
7
7
  const require_xml_entities = require("../xml/entities.cjs");
8
+ const require_omml_shared = require("./shared.cjs");
8
9
  //#region src/omml/write.ts
9
10
  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
11
  function columnJustification(align) {
57
12
  return align === "left" || align === "right" || align === "center" ? align : "center";
58
13
  }
@@ -70,15 +25,12 @@ function mathRun(text, properties) {
70
25
  return require_xml_fragment.el("m:r", {}, children);
71
26
  }
72
27
  function variantRunProperties(variant) {
73
- const mapped = VARIANT_RUN_PROPERTIES[variant];
28
+ const mapped = require_omml_shared.VARIANT_RUN_PROPERTIES[variant];
74
29
  const children = [];
75
30
  if (mapped.scr !== void 0) children.push(require_xml_fragment.el("m:scr", { "m:val": mapped.scr }));
76
31
  children.push(require_xml_fragment.el("m:sty", { "m:val": mapped.sty }));
77
32
  return require_xml_fragment.el("m:rPr", {}, children);
78
33
  }
79
- function miIntrinsicDefault(content) {
80
- return [...content].length === 1 ? "italic" : "normal";
81
- }
82
34
  function tokenVariant(element, intrinsicDefault, ctx) {
83
35
  const attr = require_mathml_nodes.attrValue(element, "mathvariant");
84
36
  if (attr !== void 0 && require_mathml_variant.isMathVariant(attr)) return attr;
@@ -191,7 +143,7 @@ function convertElement(node, ctx) {
191
143
  case "semantics": return convertSemantics(node, ctx);
192
144
  case "mi": {
193
145
  const text = require_mathml_nodes.textContent(node);
194
- return tokenRun(node, text, miIntrinsicDefault(text), ctx, false);
146
+ return tokenRun(node, text, require_omml_shared.miIntrinsicDefault(text), ctx, false);
195
147
  }
196
148
  case "mn": return tokenRun(node, require_mathml_nodes.textContent(node), "normal", ctx, false);
197
149
  case "mo": return tokenRun(node, require_mathml_nodes.textContent(node).trim(), "normal", ctx, false);
@@ -1,2 +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 };
1
+ import { n as buildOfficeMath, r as buildOfficeMathParagraph, t as OmmlWriteResult } from "../write-BQ6SK8r8.cjs";
2
+ export { OmmlWriteResult, buildOfficeMath, buildOfficeMathParagraph };
@@ -1,2 +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 };
1
+ import { n as buildOfficeMath, r as buildOfficeMathParagraph, t as OmmlWriteResult } from "../write-THs7ipBq.js";
2
+ export { OmmlWriteResult, buildOfficeMath, buildOfficeMathParagraph };
@@ -4,54 +4,9 @@ import { attrValue, elementChildren, elementLocalName, isMathMlElement, textCont
4
4
  import { operatorProperties } from "../mathml/operators.js";
5
5
  import { isMathVariant } from "../mathml/variant.js";
6
6
  import { encodeXmlText, needsSpacePreserve } from "../xml/entities.js";
7
+ import { VARIANT_RUN_PROPERTIES, miIntrinsicDefault } from "./shared.js";
7
8
  //#region src/omml/write.ts
8
9
  const OMML_NS = "http://schemas.openxmlformats.org/officeDocument/2006/math";
9
- const VARIANT_RUN_PROPERTIES = {
10
- normal: { sty: "p" },
11
- bold: { sty: "b" },
12
- italic: { sty: "i" },
13
- "bold-italic": { sty: "bi" },
14
- "double-struck": {
15
- scr: "double-struck",
16
- sty: "p"
17
- },
18
- script: {
19
- scr: "script",
20
- sty: "p"
21
- },
22
- "bold-script": {
23
- scr: "script",
24
- sty: "b"
25
- },
26
- fraktur: {
27
- scr: "fraktur",
28
- sty: "p"
29
- },
30
- "bold-fraktur": {
31
- scr: "fraktur",
32
- sty: "b"
33
- },
34
- "sans-serif": {
35
- scr: "sans-serif",
36
- sty: "p"
37
- },
38
- "bold-sans-serif": {
39
- scr: "sans-serif",
40
- sty: "b"
41
- },
42
- "sans-serif-italic": {
43
- scr: "sans-serif",
44
- sty: "i"
45
- },
46
- "sans-serif-bold-italic": {
47
- scr: "sans-serif",
48
- sty: "bi"
49
- },
50
- monospace: {
51
- scr: "monospace",
52
- sty: "p"
53
- }
54
- };
55
10
  function columnJustification(align) {
56
11
  return align === "left" || align === "right" || align === "center" ? align : "center";
57
12
  }
@@ -75,9 +30,6 @@ function variantRunProperties(variant) {
75
30
  children.push(el("m:sty", { "m:val": mapped.sty }));
76
31
  return el("m:rPr", {}, children);
77
32
  }
78
- function miIntrinsicDefault(content) {
79
- return [...content].length === 1 ? "italic" : "normal";
80
- }
81
33
  function tokenVariant(element, intrinsicDefault, ctx) {
82
34
  const attr = attrValue(element, "mathvariant");
83
35
  if (attr !== void 0 && isMathVariant(attr)) return attr;
@@ -0,0 +1,15 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ let ooxml_js = require("ooxml.js");
3
+ //#region src/ooxml/docx/extras.ts
4
+ function readDocxExtras(pkg) {
5
+ const docxDoc = (0, ooxml_js.readDocx)(pkg);
6
+ return {
7
+ comments: docxDoc.comments,
8
+ footnotes: docxDoc.footnotes,
9
+ headers: docxDoc.headers,
10
+ footers: docxDoc.footers,
11
+ numbering: docxDoc.numbering
12
+ };
13
+ }
14
+ //#endregion
15
+ exports.readDocxExtras = readDocxExtras;
@@ -0,0 +1,12 @@
1
+ import { Comment, Footnote, NumberingDefinitions, Package } from "ooxml.js";
2
+ //#region src/ooxml/docx/extras.d.ts
3
+ interface DocxExtras {
4
+ readonly comments: readonly Comment[];
5
+ readonly footnotes: readonly Footnote[];
6
+ readonly headers: readonly string[];
7
+ readonly footers: readonly string[];
8
+ readonly numbering: NumberingDefinitions;
9
+ }
10
+ declare function readDocxExtras(pkg: Package): DocxExtras;
11
+ //#endregion
12
+ export { DocxExtras, readDocxExtras };
@@ -0,0 +1,12 @@
1
+ import { Comment, Footnote, NumberingDefinitions, Package } from "ooxml.js";
2
+ //#region src/ooxml/docx/extras.d.ts
3
+ interface DocxExtras {
4
+ readonly comments: readonly Comment[];
5
+ readonly footnotes: readonly Footnote[];
6
+ readonly headers: readonly string[];
7
+ readonly footers: readonly string[];
8
+ readonly numbering: NumberingDefinitions;
9
+ }
10
+ declare function readDocxExtras(pkg: Package): DocxExtras;
11
+ //#endregion
12
+ export { DocxExtras, readDocxExtras };
@@ -0,0 +1,14 @@
1
+ import { readDocx } from "ooxml.js";
2
+ //#region src/ooxml/docx/extras.ts
3
+ function readDocxExtras(pkg) {
4
+ const docxDoc = readDocx(pkg);
5
+ return {
6
+ comments: docxDoc.comments,
7
+ footnotes: docxDoc.footnotes,
8
+ headers: docxDoc.headers,
9
+ footers: docxDoc.footers,
10
+ numbering: docxDoc.numbering
11
+ };
12
+ }
13
+ //#endregion
14
+ export { readDocxExtras };
@@ -0,0 +1,109 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_model_formula = require("../../model/formula.cjs");
3
+ const require_omml_read = require("../../omml/read.cjs");
4
+ let ooxml_js = require("ooxml.js");
5
+ //#region src/ooxml/docx/formula.ts
6
+ function collectBodyParagraphs(nodes, out) {
7
+ for (const node of nodes) {
8
+ if (node.type !== "element") continue;
9
+ if (node.tag === "w:p") out.push(node);
10
+ else if (node.tag === "w:sdt") {
11
+ const content = (0, ooxml_js.childrenWithTag)(node, "w:sdtContent")[0];
12
+ if (content !== void 0) collectBodyParagraphs(content.children, out);
13
+ } else if (node.tag === "w:ins") collectBodyParagraphs(node.children, out);
14
+ else if (node.tag === "mc:AlternateContent") {
15
+ const target = (0, ooxml_js.childrenWithTag)(node, "mc:Fallback")[0] ?? (0, ooxml_js.childrenWithTag)(node, "mc:Choice")[0];
16
+ if (target !== void 0) collectBodyParagraphs(target.children, out);
17
+ }
18
+ }
19
+ }
20
+ const PARAGRAPH_NON_CONTENT_TAGS = /* @__PURE__ */ new Set([
21
+ "w:pPr",
22
+ "w:bookmarkStart",
23
+ "w:bookmarkEnd",
24
+ "w:proofErr",
25
+ "w:commentRangeStart",
26
+ "w:commentRangeEnd"
27
+ ]);
28
+ function isEquationOnlyParagraph(paragraph, equations) {
29
+ for (const child of paragraph.children) {
30
+ if (child.type === "text") {
31
+ if (child.value.trim().length > 0) return false;
32
+ continue;
33
+ }
34
+ if (child.type !== "element") continue;
35
+ if (PARAGRAPH_NON_CONTENT_TAGS.has(child.tag) || equations.includes(child)) continue;
36
+ if (child.tag === "m:oMathPara" && require_omml_read.collectOfficeMathElements(child.children).every((math) => equations.includes(math))) continue;
37
+ return false;
38
+ }
39
+ return true;
40
+ }
41
+ const FRAME_HEIGHT_PER_SIZE_PT = 2;
42
+ const DEFAULT_MATH_SIZE_PT = 11;
43
+ function mathRunSizePt(equation) {
44
+ const stack = [equation];
45
+ while (stack.length > 0) {
46
+ const node = stack.pop();
47
+ if (node?.type !== "element") continue;
48
+ if (node.tag === "w:sz") {
49
+ const halfPoints = Number.parseFloat(node.attributes.find((attribute) => attribute.name === "w:val")?.value ?? "");
50
+ if (Number.isFinite(halfPoints) && halfPoints > 0) return halfPoints / 2;
51
+ }
52
+ for (let index = node.children.length - 1; index >= 0; index--) {
53
+ const child = node.children[index];
54
+ if (child !== void 0) stack.push(child);
55
+ }
56
+ }
57
+ }
58
+ function equationFrame(equation) {
59
+ return {
60
+ xPt: 0,
61
+ yPt: 0,
62
+ widthPt: 0,
63
+ heightPt: (mathRunSizePt(equation) ?? DEFAULT_MATH_SIZE_PT) * FRAME_HEIGHT_PER_SIZE_PT
64
+ };
65
+ }
66
+ function spliceDocxFormulas(sections, bodyChildren, onMathDiagnostic) {
67
+ const paragraphElements = [];
68
+ collectBodyParagraphs(bodyChildren, paragraphElements);
69
+ let paragraphOrdinal = 0;
70
+ const out = [];
71
+ for (const [sectionIndex, section] of sections.entries()) {
72
+ const blocks = [];
73
+ for (const block of section.blocks) {
74
+ if (block.kind !== "paragraph") {
75
+ blocks.push(block);
76
+ continue;
77
+ }
78
+ const paragraph = paragraphElements[paragraphOrdinal];
79
+ paragraphOrdinal += 1;
80
+ const equations = paragraph === void 0 ? [] : require_omml_read.collectOfficeMathElements(paragraph.children);
81
+ if (equations.length === 0 || paragraph === void 0) {
82
+ blocks.push(block);
83
+ continue;
84
+ }
85
+ const converted = equations.map((equation) => ({
86
+ equation,
87
+ ...require_omml_read.readOfficeMath(equation)
88
+ }));
89
+ if (converted.filter((result) => result.mathml.length > 0).length === 0) {
90
+ blocks.push(block);
91
+ for (const result of converted) for (const diagnostic of result.diagnostics) onMathDiagnostic?.(diagnostic, { sourcePath: block.sourcePath });
92
+ continue;
93
+ }
94
+ if (!isEquationOnlyParagraph(paragraph, equations)) blocks.push(block);
95
+ for (const result of converted) {
96
+ const sourcePath = `sections[${sectionIndex}].blocks[${blocks.length}]`;
97
+ if (result.mathml.length > 0) blocks.push(require_model_formula.buildFormulaBlock({ mathml: result.mathml }, equationFrame(result.equation), sourcePath));
98
+ for (const diagnostic of result.diagnostics) onMathDiagnostic?.(diagnostic, { sourcePath });
99
+ }
100
+ }
101
+ out.push({
102
+ ...section,
103
+ blocks
104
+ });
105
+ }
106
+ return out;
107
+ }
108
+ //#endregion
109
+ exports.spliceDocxFormulas = spliceDocxFormulas;
@@ -0,0 +1,2 @@
1
+ import { n as spliceDocxFormulas, t as OmmlDiagnosticSink } from "../../formula-CiwPw8nY.cjs";
2
+ export { OmmlDiagnosticSink, spliceDocxFormulas };
@@ -0,0 +1,2 @@
1
+ import { n as spliceDocxFormulas, t as OmmlDiagnosticSink } from "../../formula-CgydMiTt.js";
2
+ export { OmmlDiagnosticSink, spliceDocxFormulas };
@@ -0,0 +1,108 @@
1
+ import { buildFormulaBlock } from "../../model/formula.js";
2
+ import { collectOfficeMathElements, readOfficeMath } from "../../omml/read.js";
3
+ import { childrenWithTag } from "ooxml.js";
4
+ //#region src/ooxml/docx/formula.ts
5
+ function collectBodyParagraphs(nodes, out) {
6
+ for (const node of nodes) {
7
+ if (node.type !== "element") continue;
8
+ if (node.tag === "w:p") out.push(node);
9
+ else if (node.tag === "w:sdt") {
10
+ const content = childrenWithTag(node, "w:sdtContent")[0];
11
+ if (content !== void 0) collectBodyParagraphs(content.children, out);
12
+ } else if (node.tag === "w:ins") collectBodyParagraphs(node.children, out);
13
+ else if (node.tag === "mc:AlternateContent") {
14
+ const target = childrenWithTag(node, "mc:Fallback")[0] ?? childrenWithTag(node, "mc:Choice")[0];
15
+ if (target !== void 0) collectBodyParagraphs(target.children, out);
16
+ }
17
+ }
18
+ }
19
+ const PARAGRAPH_NON_CONTENT_TAGS = /* @__PURE__ */ new Set([
20
+ "w:pPr",
21
+ "w:bookmarkStart",
22
+ "w:bookmarkEnd",
23
+ "w:proofErr",
24
+ "w:commentRangeStart",
25
+ "w:commentRangeEnd"
26
+ ]);
27
+ function isEquationOnlyParagraph(paragraph, equations) {
28
+ for (const child of paragraph.children) {
29
+ if (child.type === "text") {
30
+ if (child.value.trim().length > 0) return false;
31
+ continue;
32
+ }
33
+ if (child.type !== "element") continue;
34
+ if (PARAGRAPH_NON_CONTENT_TAGS.has(child.tag) || equations.includes(child)) continue;
35
+ if (child.tag === "m:oMathPara" && collectOfficeMathElements(child.children).every((math) => equations.includes(math))) continue;
36
+ return false;
37
+ }
38
+ return true;
39
+ }
40
+ const FRAME_HEIGHT_PER_SIZE_PT = 2;
41
+ const DEFAULT_MATH_SIZE_PT = 11;
42
+ function mathRunSizePt(equation) {
43
+ const stack = [equation];
44
+ while (stack.length > 0) {
45
+ const node = stack.pop();
46
+ if (node?.type !== "element") continue;
47
+ if (node.tag === "w:sz") {
48
+ const halfPoints = Number.parseFloat(node.attributes.find((attribute) => attribute.name === "w:val")?.value ?? "");
49
+ if (Number.isFinite(halfPoints) && halfPoints > 0) return halfPoints / 2;
50
+ }
51
+ for (let index = node.children.length - 1; index >= 0; index--) {
52
+ const child = node.children[index];
53
+ if (child !== void 0) stack.push(child);
54
+ }
55
+ }
56
+ }
57
+ function equationFrame(equation) {
58
+ return {
59
+ xPt: 0,
60
+ yPt: 0,
61
+ widthPt: 0,
62
+ heightPt: (mathRunSizePt(equation) ?? DEFAULT_MATH_SIZE_PT) * FRAME_HEIGHT_PER_SIZE_PT
63
+ };
64
+ }
65
+ function spliceDocxFormulas(sections, bodyChildren, onMathDiagnostic) {
66
+ const paragraphElements = [];
67
+ collectBodyParagraphs(bodyChildren, paragraphElements);
68
+ let paragraphOrdinal = 0;
69
+ const out = [];
70
+ for (const [sectionIndex, section] of sections.entries()) {
71
+ const blocks = [];
72
+ for (const block of section.blocks) {
73
+ if (block.kind !== "paragraph") {
74
+ blocks.push(block);
75
+ continue;
76
+ }
77
+ const paragraph = paragraphElements[paragraphOrdinal];
78
+ paragraphOrdinal += 1;
79
+ const equations = paragraph === void 0 ? [] : collectOfficeMathElements(paragraph.children);
80
+ if (equations.length === 0 || paragraph === void 0) {
81
+ blocks.push(block);
82
+ continue;
83
+ }
84
+ const converted = equations.map((equation) => ({
85
+ equation,
86
+ ...readOfficeMath(equation)
87
+ }));
88
+ if (converted.filter((result) => result.mathml.length > 0).length === 0) {
89
+ blocks.push(block);
90
+ for (const result of converted) for (const diagnostic of result.diagnostics) onMathDiagnostic?.(diagnostic, { sourcePath: block.sourcePath });
91
+ continue;
92
+ }
93
+ if (!isEquationOnlyParagraph(paragraph, equations)) blocks.push(block);
94
+ for (const result of converted) {
95
+ const sourcePath = `sections[${sectionIndex}].blocks[${blocks.length}]`;
96
+ if (result.mathml.length > 0) blocks.push(buildFormulaBlock({ mathml: result.mathml }, equationFrame(result.equation), sourcePath));
97
+ for (const diagnostic of result.diagnostics) onMathDiagnostic?.(diagnostic, { sourcePath });
98
+ }
99
+ }
100
+ out.push({
101
+ ...section,
102
+ blocks
103
+ });
104
+ }
105
+ return out;
106
+ }
107
+ //#endregion
108
+ export { spliceDocxFormulas };
@@ -1,14 +1,22 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_ooxml_docx_formula = require("./formula.cjs");
2
3
  let ooxml_js = require("ooxml.js");
3
4
  let document_schema_js = require("document-schema.js");
4
5
  //#region src/ooxml/docx/read.ts
5
- function readDocxContent(pkg) {
6
+ const DOCUMENT_PART_PATH = "word/document.xml";
7
+ function documentBody(pkg) {
8
+ const root = (0, ooxml_js.rootElement)(pkg.parts[DOCUMENT_PART_PATH]);
9
+ return root === void 0 ? void 0 : (0, ooxml_js.childrenWithTag)(root, "w:body")[0];
10
+ }
11
+ function readDocxContent(pkg, options) {
6
12
  const docxDoc = (0, ooxml_js.readDocx)(pkg);
13
+ const body = documentBody(pkg);
14
+ const sections = body === void 0 ? docxDoc.sections : require_ooxml_docx_formula.spliceDocxFormulas(docxDoc.sections, body.children, options?.onMathDiagnostic);
7
15
  return {
8
16
  kind: "wordprocessing",
9
17
  formatVersion: document_schema_js.CONTENT_FORMAT_VERSION,
10
18
  metadata: { ...docxDoc.metadata },
11
- sections: docxDoc.sections
19
+ sections
12
20
  };
13
21
  }
14
22
  //#endregion
@@ -1,6 +1,10 @@
1
+ import { t as OmmlDiagnosticSink } from "../../formula-CiwPw8nY.cjs";
1
2
  import { ContentDocument } from "document-schema.js";
2
3
  import { Package } from "ooxml.js";
3
4
  //#region src/ooxml/docx/read.d.ts
4
- declare function readDocxContent(pkg: Package): ContentDocument;
5
+ interface ReadDocxContentOptions {
6
+ readonly onMathDiagnostic?: OmmlDiagnosticSink;
7
+ }
8
+ declare function readDocxContent(pkg: Package, options?: ReadDocxContentOptions): ContentDocument;
5
9
  //#endregion
6
- export { readDocxContent };
10
+ export { ReadDocxContentOptions, readDocxContent };
@@ -1,6 +1,10 @@
1
+ import { t as OmmlDiagnosticSink } from "../../formula-CgydMiTt.js";
1
2
  import { Package } from "ooxml.js";
2
3
  import { ContentDocument } from "document-schema.js";
3
4
  //#region src/ooxml/docx/read.d.ts
4
- declare function readDocxContent(pkg: Package): ContentDocument;
5
+ interface ReadDocxContentOptions {
6
+ readonly onMathDiagnostic?: OmmlDiagnosticSink;
7
+ }
8
+ declare function readDocxContent(pkg: Package, options?: ReadDocxContentOptions): ContentDocument;
5
9
  //#endregion
6
- export { readDocxContent };
10
+ export { ReadDocxContentOptions, readDocxContent };
@@ -1,13 +1,21 @@
1
- import { readDocx } from "ooxml.js";
1
+ import { spliceDocxFormulas } from "./formula.js";
2
+ import { childrenWithTag, readDocx, rootElement } from "ooxml.js";
2
3
  import { CONTENT_FORMAT_VERSION } from "document-schema.js";
3
4
  //#region src/ooxml/docx/read.ts
4
- function readDocxContent(pkg) {
5
+ const DOCUMENT_PART_PATH = "word/document.xml";
6
+ function documentBody(pkg) {
7
+ const root = rootElement(pkg.parts[DOCUMENT_PART_PATH]);
8
+ return root === void 0 ? void 0 : childrenWithTag(root, "w:body")[0];
9
+ }
10
+ function readDocxContent(pkg, options) {
5
11
  const docxDoc = readDocx(pkg);
12
+ const body = documentBody(pkg);
13
+ const sections = body === void 0 ? docxDoc.sections : spliceDocxFormulas(docxDoc.sections, body.children, options?.onMathDiagnostic);
6
14
  return {
7
15
  kind: "wordprocessing",
8
16
  formatVersion: CONTENT_FORMAT_VERSION,
9
17
  metadata: { ...docxDoc.metadata },
10
- sections: docxDoc.sections
18
+ sections
11
19
  };
12
20
  }
13
21
  //#endregion