documents.js 1.60.3 → 1.62.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 (216) hide show
  1. package/README.md +84 -44
  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 +29 -27
  9. package/dist/convert/convert.d.cts +9 -3
  10. package/dist/convert/convert.d.ts +9 -3
  11. package/dist/convert/convert.js +29 -27
  12. package/dist/edit/docx/content.cjs +75 -13
  13. package/dist/edit/docx/content.d.cts +8 -2
  14. package/dist/edit/docx/content.d.ts +8 -2
  15. package/dist/edit/docx/content.js +75 -13
  16. package/dist/edit/docx/paragraph.cjs +14 -0
  17. package/dist/edit/docx/paragraph.d.cts +5 -0
  18. package/dist/edit/docx/paragraph.d.ts +5 -0
  19. package/dist/edit/docx/paragraph.js +14 -0
  20. package/dist/edit/docx/run.cjs +1 -1
  21. package/dist/edit/docx/run.js +1 -1
  22. package/dist/edit/docx/table.cjs +41 -0
  23. package/dist/edit/docx/table.d.cts +7 -1
  24. package/dist/edit/docx/table.d.ts +7 -1
  25. package/dist/edit/docx/table.js +42 -1
  26. package/dist/edit/geometry.cjs +38 -0
  27. package/dist/edit/geometry.d.cts +7 -0
  28. package/dist/edit/geometry.d.ts +7 -0
  29. package/dist/edit/geometry.js +36 -0
  30. package/dist/edit/odg/content.cjs +15 -12
  31. package/dist/edit/odg/content.js +15 -12
  32. package/dist/edit/odg/editor.d.cts +1 -1
  33. package/dist/edit/odg/editor.d.ts +1 -1
  34. package/dist/edit/odg/page.d.cts +3 -3
  35. package/dist/edit/odg/page.d.ts +3 -3
  36. package/dist/edit/odg/vector.cjs +22 -13
  37. package/dist/edit/odg/vector.d.cts +1 -1
  38. package/dist/edit/odg/vector.d.ts +1 -1
  39. package/dist/edit/odg/vector.js +23 -14
  40. package/dist/edit/odp/content.cjs +15 -0
  41. package/dist/edit/odp/content.js +16 -1
  42. package/dist/edit/odp/editor.d.cts +1 -1
  43. package/dist/edit/odp/editor.d.ts +1 -1
  44. package/dist/edit/odp/image.d.cts +1 -1
  45. package/dist/edit/odp/image.d.ts +1 -1
  46. package/dist/edit/odp/shape.cjs +11 -30
  47. package/dist/edit/odp/shape.d.cts +2 -2
  48. package/dist/edit/odp/shape.d.ts +2 -2
  49. package/dist/edit/odp/shape.js +13 -33
  50. package/dist/edit/odp/slide.cjs +11 -0
  51. package/dist/edit/odp/slide.d.cts +14 -4
  52. package/dist/edit/odp/slide.d.ts +14 -4
  53. package/dist/edit/odp/slide.js +12 -1
  54. package/dist/edit/odt/content.cjs +56 -16
  55. package/dist/edit/odt/content.d.cts +4 -2
  56. package/dist/edit/odt/content.d.ts +4 -2
  57. package/dist/edit/odt/content.js +56 -17
  58. package/dist/edit/odt/editor.d.cts +1 -1
  59. package/dist/edit/odt/editor.d.ts +1 -1
  60. package/dist/edit/odt/table.cjs +36 -0
  61. package/dist/edit/odt/table.d.cts +1 -36
  62. package/dist/edit/odt/table.d.ts +1 -36
  63. package/dist/edit/odt/table.js +37 -1
  64. package/dist/edit/pptx/content.cjs +71 -3
  65. package/dist/edit/pptx/content.js +71 -3
  66. package/dist/edit/pptx/editor.d.cts +1 -1
  67. package/dist/edit/pptx/editor.d.ts +1 -1
  68. package/dist/edit/pptx/image.d.cts +1 -1
  69. package/dist/edit/pptx/image.d.ts +1 -1
  70. package/dist/edit/pptx/shape.cjs +23 -1
  71. package/dist/edit/pptx/shape.d.cts +2 -2
  72. package/dist/edit/pptx/shape.d.ts +2 -2
  73. package/dist/edit/pptx/shape.js +23 -3
  74. package/dist/edit/pptx/slide.cjs +10 -1
  75. package/dist/edit/pptx/slide.d.cts +11 -4
  76. package/dist/edit/pptx/slide.d.ts +11 -4
  77. package/dist/edit/pptx/slide.js +10 -1
  78. package/dist/edit/pptx/table.cjs +136 -0
  79. package/dist/edit/pptx/table.d.cts +2 -0
  80. package/dist/edit/pptx/table.d.ts +2 -0
  81. package/dist/edit/pptx/table.js +131 -0
  82. package/dist/firebird/backup.d.cts +1 -1
  83. package/dist/firebird/backup.d.ts +1 -1
  84. package/dist/firebird/blr-types.cjs +2 -2
  85. package/dist/firebird/blr-types.d.cts +1 -1
  86. package/dist/firebird/blr-types.d.ts +1 -1
  87. package/dist/firebird/blr-types.js +2 -2
  88. package/dist/firebird/data.cjs +68 -14
  89. package/dist/firebird/data.d.cts +1 -1
  90. package/dist/firebird/data.d.ts +1 -1
  91. package/dist/firebird/data.js +68 -14
  92. package/dist/firebird/schema.cjs +13 -1
  93. package/dist/firebird/schema.d.cts +1 -1
  94. package/dist/firebird/schema.d.ts +1 -1
  95. package/dist/firebird/schema.js +13 -1
  96. package/dist/{geometry-DvwdrIij.d.cts → geometry-DaJr8yQW.d.cts} +2 -2
  97. package/dist/{geometry-DvwdrIij.d.ts → geometry-DaJr8yQW.d.ts} +2 -2
  98. package/dist/hsqldb/binary-script.cjs +154 -0
  99. package/dist/hsqldb/binary-script.d.cts +15 -0
  100. package/dist/hsqldb/binary-script.d.ts +15 -0
  101. package/dist/hsqldb/binary-script.js +151 -0
  102. package/dist/hsqldb/cache.cjs +18 -11
  103. package/dist/hsqldb/cache.d.cts +9 -4
  104. package/dist/hsqldb/cache.d.ts +9 -4
  105. package/dist/hsqldb/cache.js +18 -11
  106. package/dist/hsqldb/rowformat.cjs +60 -16
  107. package/dist/hsqldb/rowformat.d.cts +2 -21
  108. package/dist/hsqldb/rowformat.d.ts +2 -21
  109. package/dist/hsqldb/rowformat.js +60 -17
  110. package/dist/{image-BZDy72Jb.d.cts → image-7snmKIxn.d.cts} +1 -1
  111. package/dist/{image-B-xQWYYS.d.ts → image-Cs8xF753.d.ts} +1 -1
  112. package/dist/{image-CeqwL-Qs.d.ts → image-DHcA9kaK.d.ts} +1 -1
  113. package/dist/{image-DWX6cNOD.d.cts → image-M5SezZVI.d.cts} +1 -1
  114. package/dist/index.cjs +54 -3
  115. package/dist/index.d.cts +28 -20
  116. package/dist/index.d.ts +27 -19
  117. package/dist/index.js +13 -4
  118. package/dist/layout/cell-typing.cjs +209 -0
  119. package/dist/layout/cell-typing.d.cts +22 -0
  120. package/dist/layout/cell-typing.d.ts +22 -0
  121. package/dist/layout/cell-typing.js +208 -0
  122. package/dist/layout/drawing.cjs +193 -17
  123. package/dist/layout/drawing.js +193 -17
  124. package/dist/layout/engine.cjs +46 -29
  125. package/dist/layout/engine.d.cts +0 -2
  126. package/dist/layout/engine.d.ts +0 -2
  127. package/dist/layout/engine.js +47 -30
  128. package/dist/layout/lattice.cjs +139 -0
  129. package/dist/layout/lattice.d.cts +20 -0
  130. package/dist/layout/lattice.d.ts +20 -0
  131. package/dist/layout/lattice.js +135 -0
  132. package/dist/layout/reconstruct.cjs +176 -113
  133. package/dist/layout/reconstruct.d.cts +2 -0
  134. package/dist/layout/reconstruct.d.ts +2 -0
  135. package/dist/layout/reconstruct.js +173 -110
  136. package/dist/layout/shared.cjs +52 -0
  137. package/dist/layout/shared.d.cts +4 -2
  138. package/dist/layout/shared.d.ts +4 -2
  139. package/dist/layout/shared.js +51 -1
  140. package/dist/layout/sheets.cjs +45 -11
  141. package/dist/layout/sheets.js +46 -12
  142. package/dist/layout/slides.cjs +7 -7
  143. package/dist/layout/slides.d.cts +0 -3
  144. package/dist/layout/slides.d.ts +0 -3
  145. package/dist/layout/slides.js +7 -7
  146. package/dist/markdown/write.cjs +19 -6
  147. package/dist/markdown/write.js +19 -6
  148. package/dist/mathml/layout.cjs +43 -9
  149. package/dist/mathml/layout.d.cts +1 -1
  150. package/dist/mathml/layout.d.ts +1 -1
  151. package/dist/mathml/layout.js +43 -9
  152. package/dist/mathml/variant.cjs +48 -5
  153. package/dist/mathml/variant.js +48 -5
  154. package/dist/model/embedded-drawing.cjs +32 -0
  155. package/dist/model/embedded-drawing.d.cts +8 -0
  156. package/dist/model/embedded-drawing.d.ts +8 -0
  157. package/dist/model/embedded-drawing.js +30 -0
  158. package/dist/model/formula.cjs +31 -0
  159. package/dist/model/formula.d.cts +6 -6
  160. package/dist/model/formula.d.ts +6 -6
  161. package/dist/model/formula.js +27 -0
  162. package/dist/model/geometry.d.cts +1 -1
  163. package/dist/model/geometry.d.ts +1 -1
  164. package/dist/model/paint-order.cjs +15 -0
  165. package/dist/model/paint-order.d.cts +14 -0
  166. package/dist/model/paint-order.d.ts +14 -0
  167. package/dist/model/paint-order.js +14 -0
  168. package/dist/odb/components.cjs +12 -0
  169. package/dist/odb/components.d.cts +6 -0
  170. package/dist/odb/components.d.ts +6 -0
  171. package/dist/odb/components.js +10 -0
  172. package/dist/odb/read.cjs +11 -7
  173. package/dist/odb/read.d.cts +3 -2
  174. package/dist/odb/read.d.ts +3 -2
  175. package/dist/odb/read.js +11 -7
  176. package/dist/odf/formula/detect.cjs +86 -18
  177. package/dist/odf/formula/detect.d.cts +10 -6
  178. package/dist/odf/formula/detect.d.ts +10 -6
  179. package/dist/odf/formula/detect.js +86 -19
  180. package/dist/odf/formula/read.cjs +4 -16
  181. package/dist/odf/formula/read.d.cts +4 -8
  182. package/dist/odf/formula/read.d.ts +4 -8
  183. package/dist/odf/formula/read.js +5 -17
  184. package/dist/odf/odp/read.cjs +9 -19
  185. package/dist/odf/odp/read.d.cts +2 -7
  186. package/dist/odf/odp/read.d.ts +2 -7
  187. package/dist/odf/odp/read.js +10 -20
  188. package/dist/odf/odt/read.cjs +63 -23
  189. package/dist/odf/odt/read.d.cts +2 -7
  190. package/dist/odf/odt/read.d.ts +2 -7
  191. package/dist/odf/odt/read.js +64 -24
  192. package/dist/omml/write.cjs +258 -0
  193. package/dist/omml/write.d.cts +2 -0
  194. package/dist/omml/write.d.ts +2 -0
  195. package/dist/omml/write.js +256 -0
  196. package/dist/rowformat-Cl2exlEh.d.cts +25 -0
  197. package/dist/rowformat-Cl2exlEh.d.ts +25 -0
  198. package/dist/{schema-Acco3Ezi.d.cts → schema-BeR_KJ0X.d.cts} +3 -1
  199. package/dist/{schema-VkAA6pF5.d.ts → schema-CSKwSb_v.d.ts} +3 -1
  200. package/dist/{shape-BUfjw5eZ.d.cts → shape-BhkP6HB8.d.cts} +6 -2
  201. package/dist/{shape-CTkl6kt8.d.ts → shape-BkVcwPcf.d.ts} +6 -2
  202. package/dist/{shape-BfN3m52m.d.ts → shape-CVXedeL7.d.ts} +3 -2
  203. package/dist/{shape-CN2ycxOo.d.cts → shape-CXZ6fejV.d.cts} +3 -2
  204. package/dist/table-C3CPZ--2.d.cts +35 -0
  205. package/dist/table-DjYcNOFm.d.cts +44 -0
  206. package/dist/table-DqfqMkVq.d.ts +44 -0
  207. package/dist/table-DvS_7UQS.d.ts +35 -0
  208. package/dist/{vector-ClohqsOe.d.cts → vector-Puuqu_IT.d.cts} +4 -0
  209. package/dist/{vector-ClohqsOe.d.ts → vector-Puuqu_IT.d.ts} +4 -0
  210. package/dist/write-DuyfnbL_.d.cts +16 -0
  211. package/dist/write-Zqwx6pka.d.ts +16 -0
  212. package/package.json +4 -4
  213. package/dist/odf/formula/placeholder.cjs +0 -36
  214. package/dist/odf/formula/placeholder.d.cts +0 -14
  215. package/dist/odf/formula/placeholder.d.ts +0 -14
  216. package/dist/odf/formula/placeholder.js +0 -36
@@ -30,6 +30,6 @@ declare class FirebirdUnsupportedFieldTypeError extends Error {
30
30
  constructor(blrType: number);
31
31
  }
32
32
  declare function decodeBlrType(blrType: number): FirebirdPhysicalType;
33
- declare function describeFieldType(physical: FirebirdPhysicalType, lengthBytes: number, scale: number, characterLength: number | undefined): string;
33
+ declare function describeFieldType(physical: FirebirdPhysicalType, lengthBytes: number, scale: number, characterLength: number | undefined, subType: number): string;
34
34
  //#endregion
35
35
  export { BLR_TIMESTAMP_TZ as C, FirebirdUnsupportedFieldTypeError as D, FirebirdPhysicalType as E, decodeBlrType as O, BLR_TIMESTAMP as S, BLR_VARYING2 as T, BLR_SQL_DATE as _, BLR_DEC128 as a, BLR_TEXT as b, BLR_D_FLOAT as c, BLR_FLOAT as d, BLR_INT128 as f, BLR_SHORT as g, BLR_QUAD as h, BLR_CSTRING2 as i, describeFieldType as k, BLR_EX_TIMESTAMP_TZ as l, BLR_LONG as m, BLR_BOOL as n, BLR_DEC64 as o, BLR_INT64 as p, BLR_CSTRING as r, BLR_DOUBLE as s, BLR_BLOB as t, BLR_EX_TIME_TZ as u, BLR_SQL_TIME as v, BLR_VARYING as w, BLR_TEXT2 as x, BLR_SQL_TIME_TZ as y };
@@ -30,6 +30,6 @@ declare class FirebirdUnsupportedFieldTypeError extends Error {
30
30
  constructor(blrType: number);
31
31
  }
32
32
  declare function decodeBlrType(blrType: number): FirebirdPhysicalType;
33
- declare function describeFieldType(physical: FirebirdPhysicalType, lengthBytes: number, scale: number, characterLength: number | undefined): string;
33
+ declare function describeFieldType(physical: FirebirdPhysicalType, lengthBytes: number, scale: number, characterLength: number | undefined, subType: number): string;
34
34
  //#endregion
35
35
  export { BLR_TIMESTAMP_TZ as C, FirebirdUnsupportedFieldTypeError as D, FirebirdPhysicalType as E, decodeBlrType as O, BLR_TIMESTAMP as S, BLR_VARYING2 as T, BLR_SQL_DATE as _, BLR_DEC128 as a, BLR_TEXT as b, BLR_D_FLOAT as c, BLR_FLOAT as d, BLR_INT128 as f, BLR_SHORT as g, BLR_QUAD as h, BLR_CSTRING2 as i, describeFieldType as k, BLR_EX_TIMESTAMP_TZ as l, BLR_LONG as m, BLR_BOOL as n, BLR_DEC64 as o, BLR_INT64 as p, BLR_CSTRING as r, BLR_DOUBLE as s, BLR_BLOB as t, BLR_EX_TIME_TZ as u, BLR_SQL_TIME as v, BLR_VARYING as w, BLR_TEXT2 as x, BLR_SQL_TIME_TZ as y };
@@ -39,6 +39,7 @@ const FORMAT_CAPABILITIES = {
39
39
  },
40
40
  odf: {
41
41
  format: "odf",
42
+ variant: "formula",
42
43
  hasLayoutPath: false
43
44
  },
44
45
  markdown: {
@@ -1,7 +1,7 @@
1
1
  import { DocumentBridgeOptions, DocumentToPdfOptions, PdfToDocumentOptions } from "./convert.cjs";
2
2
  import { DocumentFormat } from "./port.cjs";
3
3
  //#region src/convert/capability.d.ts
4
- type ContentVariant = 'wordprocessing' | 'presentation' | 'spreadsheet' | 'drawing';
4
+ type ContentVariant = 'wordprocessing' | 'presentation' | 'spreadsheet' | 'drawing' | 'formula';
5
5
  interface FormatCapability {
6
6
  readonly format: DocumentFormat;
7
7
  readonly variant?: ContentVariant;
@@ -1,7 +1,7 @@
1
1
  import { DocumentBridgeOptions, DocumentToPdfOptions, PdfToDocumentOptions } from "./convert.js";
2
2
  import { DocumentFormat } from "./port.js";
3
3
  //#region src/convert/capability.d.ts
4
- type ContentVariant = 'wordprocessing' | 'presentation' | 'spreadsheet' | 'drawing';
4
+ type ContentVariant = 'wordprocessing' | 'presentation' | 'spreadsheet' | 'drawing' | 'formula';
5
5
  interface FormatCapability {
6
6
  readonly format: DocumentFormat;
7
7
  readonly variant?: ContentVariant;
@@ -38,6 +38,7 @@ const FORMAT_CAPABILITIES = {
38
38
  },
39
39
  odf: {
40
40
  format: "odf",
41
+ variant: "formula",
41
42
  hasLayoutPath: false
42
43
  },
43
44
  markdown: {
@@ -52,14 +52,11 @@ function docxToPdf(bytes, options) {
52
52
  function odtToPdf(bytes, options) {
53
53
  const pkg = (0, odf_js.decodePackage)(bytes);
54
54
  const content = require_odf_odt_read.readOdtContent(pkg);
55
- if (content.document.kind !== "wordprocessing") throw new Error("readOdtContent returned a non-wordprocessing ContentDocument");
56
- const { document: layout, formulas } = require_layout_engine.convertWordprocessingToLayout(content.document, {
57
- measurer: (0, pdf_codec.createStandardFontMeasurer)(),
58
- formulas: content.formulas
59
- });
55
+ if (content.kind !== "wordprocessing") throw new Error("readOdtContent returned a non-wordprocessing ContentDocument");
56
+ const { document: layout, formulas } = require_layout_engine.convertWordprocessingToLayout(content, { measurer: (0, pdf_codec.createStandardFontMeasurer)() });
60
57
  options?.onDocument?.({
61
58
  formatVersion: document_schema_js.DOCUMENT_PACKAGE_FORMAT_VERSION,
62
- content: content.document,
59
+ content,
63
60
  layout
64
61
  });
65
62
  return (0, pdf_codec.writePdf)(layout, {
@@ -72,7 +69,7 @@ function pptxToPdf(bytes, options) {
72
69
  const pkg = require_edit_pptx_editor.openPptx(bytes).toPackage();
73
70
  const content = require_ooxml_pptx_read.readPptxContent(pkg);
74
71
  if (content.kind !== "presentation") throw new Error("readPptxContent returned a non-presentation ContentDocument");
75
- const { document: layout } = require_layout_slides.convertPresentationToLayout(content, { measurer: (0, pdf_codec.createStandardFontMeasurer)() });
72
+ const { document: layout, formulas } = require_layout_slides.convertPresentationToLayout(content, { measurer: (0, pdf_codec.createStandardFontMeasurer)() });
76
73
  options?.onDocument?.({
77
74
  formatVersion: document_schema_js.DOCUMENT_PACKAGE_FORMAT_VERSION,
78
75
  content,
@@ -80,20 +77,18 @@ function pptxToPdf(bytes, options) {
80
77
  });
81
78
  return (0, pdf_codec.writePdf)(layout, {
82
79
  signal: options?.signal,
83
- onSubstitution: options?.onSubstitution
80
+ onSubstitution: options?.onSubstitution,
81
+ formulas
84
82
  });
85
83
  }
86
84
  function odpToPdf(bytes, options) {
87
85
  const pkg = (0, odf_js.decodePackage)(bytes);
88
86
  const content = require_odf_odp_read.readOdpContent(pkg);
89
- if (content.document.kind !== "presentation") throw new Error("readOdpContent returned a non-presentation ContentDocument");
90
- const { document: layout, formulas } = require_layout_slides.convertPresentationToLayout(content.document, {
91
- measurer: (0, pdf_codec.createStandardFontMeasurer)(),
92
- formulas: content.formulas
93
- });
87
+ if (content.kind !== "presentation") throw new Error("readOdpContent returned a non-presentation ContentDocument");
88
+ const { document: layout, formulas } = require_layout_slides.convertPresentationToLayout(content, { measurer: (0, pdf_codec.createStandardFontMeasurer)() });
94
89
  options?.onDocument?.({
95
90
  formatVersion: document_schema_js.DOCUMENT_PACKAGE_FORMAT_VERSION,
96
- content: content.document,
91
+ content,
97
92
  layout
98
93
  });
99
94
  return (0, pdf_codec.writePdf)(layout, {
@@ -157,9 +152,10 @@ const STANDALONE_FORMULA_MARGIN_PT = 72;
157
152
  function odfToPdf(bytes, options) {
158
153
  require_ports_abort.throwIfAborted(options?.signal);
159
154
  const pkg = (0, odf_js.decodePackage)(bytes);
160
- const formula = require_odf_formula_read.readOdfFormulaContent(pkg);
155
+ const content = require_odf_formula_read.readOdfFormulaContent(pkg);
156
+ if (content.kind !== "formula") throw new Error("readOdfFormulaContent returned a non-formula ContentDocument");
161
157
  const metrics = (0, pdf_codec.loadMathFont)().metricsAt(STANDALONE_FORMULA_SIZE_PT);
162
- const { box } = require_mathml_layout.layoutFormula(formula.mathml, {
158
+ const { box } = require_mathml_layout.layoutFormula(content.formula.mathml, {
163
159
  metrics,
164
160
  sizePt: STANDALONE_FORMULA_SIZE_PT,
165
161
  color: document_schema_js.COLOR_BLACK
@@ -172,7 +168,7 @@ function odfToPdf(bytes, options) {
172
168
  }, document_schema_js.PAGE_SIZE_A4.heightPt);
173
169
  const layout = {
174
170
  formatVersion: document_schema_js.LAYOUT_FORMAT_VERSION,
175
- metadata: formula.metadata,
171
+ metadata: content.metadata,
176
172
  pages: [{
177
173
  widthPt: document_schema_js.PAGE_SIZE_A4.widthPt,
178
174
  heightPt: document_schema_js.PAGE_SIZE_A4.heightPt,
@@ -180,6 +176,11 @@ function odfToPdf(bytes, options) {
180
176
  }],
181
177
  images: {}
182
178
  };
179
+ options?.onDocument?.({
180
+ formatVersion: document_schema_js.DOCUMENT_PACKAGE_FORMAT_VERSION,
181
+ content,
182
+ layout
183
+ });
183
184
  require_ports_abort.throwIfAborted(options?.signal);
184
185
  return (0, pdf_codec.writePdf)(layout, {
185
186
  signal: options?.signal,
@@ -286,14 +287,14 @@ function pdfToMarkdown(bytes, options) {
286
287
  function odtToDocx(bytes, options) {
287
288
  require_ports_abort.throwIfAborted(options?.signal);
288
289
  const pkg = (0, odf_js.decodePackage)(bytes);
289
- const content = require_odf_odt_read.readOdtContent(pkg).document;
290
+ const content = require_odf_odt_read.readOdtContent(pkg);
290
291
  if (content.kind !== "wordprocessing") throw new Error("readOdtContent returned a non-wordprocessing ContentDocument");
291
292
  require_ports_abort.throwIfAborted(options?.signal);
292
293
  options?.onDocument?.({
293
294
  formatVersion: document_schema_js.DOCUMENT_PACKAGE_FORMAT_VERSION,
294
295
  content
295
296
  });
296
- return (0, ooxml_js.encodePackage)(require_edit_docx_content.buildDocxPackage(content));
297
+ return (0, ooxml_js.encodePackage)(require_edit_docx_content.buildDocxPackage(content, { onMathDiagnostic: options?.onMathDiagnostic }));
297
298
  }
298
299
  function docxToOdt(bytes, options) {
299
300
  require_ports_abort.throwIfAborted(options?.signal);
@@ -310,7 +311,7 @@ function docxToOdt(bytes, options) {
310
311
  function odpToPptx(bytes, options) {
311
312
  require_ports_abort.throwIfAborted(options?.signal);
312
313
  const pkg = (0, odf_js.decodePackage)(bytes);
313
- const content = require_odf_odp_read.readOdpContent(pkg).document;
314
+ const content = require_odf_odp_read.readOdpContent(pkg);
314
315
  if (content.kind !== "presentation") throw new Error("readOdpContent returned a non-presentation ContentDocument");
315
316
  require_ports_abort.throwIfAborted(options?.signal);
316
317
  options?.onDocument?.({
@@ -365,7 +366,7 @@ function markdownToDocx(bytes, options) {
365
366
  formatVersion: document_schema_js.DOCUMENT_PACKAGE_FORMAT_VERSION,
366
367
  content
367
368
  });
368
- return (0, ooxml_js.encodePackage)(require_edit_docx_content.buildDocxPackage(content));
369
+ return (0, ooxml_js.encodePackage)(require_edit_docx_content.buildDocxPackage(content, { onMathDiagnostic: options?.onMathDiagnostic }));
369
370
  }
370
371
  function docxToMarkdown(bytes, options) {
371
372
  require_ports_abort.throwIfAborted(options?.signal);
@@ -395,7 +396,7 @@ function markdownToOdt(bytes, options) {
395
396
  function odtToMarkdown(bytes, options) {
396
397
  require_ports_abort.throwIfAborted(options?.signal);
397
398
  const pkg = (0, odf_js.decodePackage)(bytes);
398
- const content = require_odf_odt_read.readOdtContent(pkg).document;
399
+ const content = require_odf_odt_read.readOdtContent(pkg);
399
400
  if (content.kind !== "wordprocessing") throw new Error("readOdtContent returned a non-wordprocessing ContentDocument");
400
401
  require_ports_abort.throwIfAborted(options?.signal);
401
402
  options?.onDocument?.({
@@ -480,7 +481,7 @@ function odmToPdf(bytes, options) {
480
481
  continue;
481
482
  }
482
483
  const chapterPkg = (0, odf_js.decodePackage)(chapterBytes);
483
- const chapterContent = require_odf_odt_read.readOdtContent(chapterPkg).document;
484
+ const chapterContent = require_odf_odt_read.readOdtContent(chapterPkg);
484
485
  if (chapterContent.kind !== "wordprocessing") throw new Error("readOdtContent returned a non-wordprocessing ContentDocument");
485
486
  chapterSections.push(chapterContent.sections);
486
487
  }
@@ -500,16 +501,17 @@ function odmToPdf(bytes, options) {
500
501
  metadata: (0, odf_js.readOdfMetadata)(pkg),
501
502
  sections: combinedSections
502
503
  };
503
- const { document: layout } = require_layout_engine.convertWordprocessingToLayout(content, { measurer: (0, pdf_codec.createStandardFontMeasurer)() });
504
+ const { document: layout, formulas } = require_layout_engine.convertWordprocessingToLayout(content, { measurer: (0, pdf_codec.createStandardFontMeasurer)() });
504
505
  return (0, pdf_codec.writePdf)(layout, {
505
506
  signal: options?.signal,
506
- onSubstitution: options?.onSubstitution
507
+ onSubstitution: options?.onSubstitution,
508
+ formulas
507
509
  });
508
510
  }
509
511
  function odbToXlsx(bytes, options) {
510
512
  require_ports_abort.throwIfAborted(options?.signal);
511
513
  const pkg = (0, odf_js.decodePackage)(bytes);
512
- const tables = require_odb_read.readOdbTables(pkg);
514
+ const tables = require_odb_read.readOdbTables(pkg, { timeZone: options?.timeZone });
513
515
  require_ports_abort.throwIfAborted(options?.signal);
514
516
  const content = require_odb_spreadsheet.odbTablesToSpreadsheetDocument(tables);
515
517
  return (0, ooxml_js.encodePackage)((0, ooxml_js.buildXlsxPackage)(content));
@@ -517,7 +519,7 @@ function odbToXlsx(bytes, options) {
517
519
  function odbToCsv(bytes, options) {
518
520
  require_ports_abort.throwIfAborted(options?.signal);
519
521
  const pkg = (0, odf_js.decodePackage)(bytes);
520
- const tables = require_odb_read.readOdbTables(pkg);
522
+ const tables = require_odb_read.readOdbTables(pkg, { timeZone: options?.timeZone });
521
523
  require_ports_abort.throwIfAborted(options?.signal);
522
524
  return require_odb_csv.buildOdbTableCsv(tables, options?.table);
523
525
  }
@@ -1,3 +1,5 @@
1
+ import { n as HsqldbDecodeOptions } from "../rowformat-Cl2exlEh.cjs";
2
+ import { t as OmmlDiagnostic } from "../write-DuyfnbL_.cjs";
1
3
  import { ContentSection, DocumentPackage } from "document-schema.js";
2
4
  import { OdmSection, Package } from "odf.js";
3
5
  import { PdfDiagnosticSink, WinAnsiSubstitution } from "pdf-codec";
@@ -32,6 +34,9 @@ declare function pdfToMarkdown(bytes: Uint8Array<ArrayBuffer>, options?: PdfToDo
32
34
  interface DocumentBridgeOptions {
33
35
  readonly signal?: AbortSignal;
34
36
  readonly onDocument?: (pkg: DocumentPackage) => void;
37
+ readonly onMathDiagnostic?: (diagnostic: OmmlDiagnostic, context: {
38
+ readonly sourcePath?: string;
39
+ }) => void;
35
40
  }
36
41
  declare function odtToDocx(bytes: Uint8Array<ArrayBuffer>, options?: DocumentBridgeOptions): Uint8Array<ArrayBuffer>;
37
42
  declare function docxToOdt(bytes: Uint8Array<ArrayBuffer>, options?: DocumentBridgeOptions): Uint8Array<ArrayBuffer>;
@@ -54,10 +59,11 @@ declare class OdmUnresolvedSectionError extends Error {
54
59
  }
55
60
  declare function inlineOdmSectionToContentSection(section: OdmSection, pkg: Package): ContentSection;
56
61
  declare function odmToPdf(bytes: Uint8Array<ArrayBuffer>, options?: OdmToPdfOptions): Uint8Array<ArrayBuffer>;
57
- declare function odbToXlsx(bytes: Uint8Array<ArrayBuffer>, options?: DocumentBridgeOptions): Uint8Array<ArrayBuffer>;
58
- interface OdbToCsvOptions extends DocumentBridgeOptions {
62
+ interface OdbConversionOptions extends DocumentBridgeOptions, HsqldbDecodeOptions {}
63
+ declare function odbToXlsx(bytes: Uint8Array<ArrayBuffer>, options?: OdbConversionOptions): Uint8Array<ArrayBuffer>;
64
+ interface OdbToCsvOptions extends OdbConversionOptions {
59
65
  readonly table?: string;
60
66
  }
61
67
  declare function odbToCsv(bytes: Uint8Array<ArrayBuffer>, options?: OdbToCsvOptions): Uint8Array<ArrayBuffer>;
62
68
  //#endregion
63
- export { DocumentBridgeOptions, DocumentToPdfOptions, OdbToCsvOptions, OdmToPdfOptions, OdmUnresolvedSectionError, PdfToDocumentOptions, docxToMarkdown, docxToOdt, docxToPdf, inlineOdmSectionToContentSection, markdownToDocx, markdownToOdt, markdownToPdf, odbToCsv, odbToXlsx, odfToPdf, odgToPdf, odmToPdf, odpToPdf, odpToPptx, odsToPdf, odsToXlsx, odtToDocx, odtToMarkdown, odtToPdf, pdfToDocx, pdfToMarkdown, pdfToOdg, pdfToOdp, pdfToOds, pdfToOdt, pdfToPptx, pdfToXlsx, pptxToOdp, pptxToPdf, xlsxToOds, xlsxToPdf };
69
+ export { DocumentBridgeOptions, DocumentToPdfOptions, OdbConversionOptions, OdbToCsvOptions, OdmToPdfOptions, OdmUnresolvedSectionError, PdfToDocumentOptions, docxToMarkdown, docxToOdt, docxToPdf, inlineOdmSectionToContentSection, markdownToDocx, markdownToOdt, markdownToPdf, odbToCsv, odbToXlsx, odfToPdf, odgToPdf, odmToPdf, odpToPdf, odpToPptx, odsToPdf, odsToXlsx, odtToDocx, odtToMarkdown, odtToPdf, pdfToDocx, pdfToMarkdown, pdfToOdg, pdfToOdp, pdfToOds, pdfToOdt, pdfToPptx, pdfToXlsx, pptxToOdp, pptxToPdf, xlsxToOds, xlsxToPdf };
@@ -1,3 +1,5 @@
1
+ import { n as HsqldbDecodeOptions } from "../rowformat-Cl2exlEh.js";
2
+ import { t as OmmlDiagnostic } from "../write-Zqwx6pka.js";
1
3
  import { ContentSection, DocumentPackage } from "document-schema.js";
2
4
  import { OdmSection, Package } from "odf.js";
3
5
  import { PdfDiagnosticSink, WinAnsiSubstitution } from "pdf-codec";
@@ -32,6 +34,9 @@ declare function pdfToMarkdown(bytes: Uint8Array<ArrayBuffer>, options?: PdfToDo
32
34
  interface DocumentBridgeOptions {
33
35
  readonly signal?: AbortSignal;
34
36
  readonly onDocument?: (pkg: DocumentPackage) => void;
37
+ readonly onMathDiagnostic?: (diagnostic: OmmlDiagnostic, context: {
38
+ readonly sourcePath?: string;
39
+ }) => void;
35
40
  }
36
41
  declare function odtToDocx(bytes: Uint8Array<ArrayBuffer>, options?: DocumentBridgeOptions): Uint8Array<ArrayBuffer>;
37
42
  declare function docxToOdt(bytes: Uint8Array<ArrayBuffer>, options?: DocumentBridgeOptions): Uint8Array<ArrayBuffer>;
@@ -54,10 +59,11 @@ declare class OdmUnresolvedSectionError extends Error {
54
59
  }
55
60
  declare function inlineOdmSectionToContentSection(section: OdmSection, pkg: Package): ContentSection;
56
61
  declare function odmToPdf(bytes: Uint8Array<ArrayBuffer>, options?: OdmToPdfOptions): Uint8Array<ArrayBuffer>;
57
- declare function odbToXlsx(bytes: Uint8Array<ArrayBuffer>, options?: DocumentBridgeOptions): Uint8Array<ArrayBuffer>;
58
- interface OdbToCsvOptions extends DocumentBridgeOptions {
62
+ interface OdbConversionOptions extends DocumentBridgeOptions, HsqldbDecodeOptions {}
63
+ declare function odbToXlsx(bytes: Uint8Array<ArrayBuffer>, options?: OdbConversionOptions): Uint8Array<ArrayBuffer>;
64
+ interface OdbToCsvOptions extends OdbConversionOptions {
59
65
  readonly table?: string;
60
66
  }
61
67
  declare function odbToCsv(bytes: Uint8Array<ArrayBuffer>, options?: OdbToCsvOptions): Uint8Array<ArrayBuffer>;
62
68
  //#endregion
63
- export { DocumentBridgeOptions, DocumentToPdfOptions, OdbToCsvOptions, OdmToPdfOptions, OdmUnresolvedSectionError, PdfToDocumentOptions, docxToMarkdown, docxToOdt, docxToPdf, inlineOdmSectionToContentSection, markdownToDocx, markdownToOdt, markdownToPdf, odbToCsv, odbToXlsx, odfToPdf, odgToPdf, odmToPdf, odpToPdf, odpToPptx, odsToPdf, odsToXlsx, odtToDocx, odtToMarkdown, odtToPdf, pdfToDocx, pdfToMarkdown, pdfToOdg, pdfToOdp, pdfToOds, pdfToOdt, pdfToPptx, pdfToXlsx, pptxToOdp, pptxToPdf, xlsxToOds, xlsxToPdf };
69
+ export { DocumentBridgeOptions, DocumentToPdfOptions, OdbConversionOptions, OdbToCsvOptions, OdmToPdfOptions, OdmUnresolvedSectionError, PdfToDocumentOptions, docxToMarkdown, docxToOdt, docxToPdf, inlineOdmSectionToContentSection, markdownToDocx, markdownToOdt, markdownToPdf, odbToCsv, odbToXlsx, odfToPdf, odgToPdf, odmToPdf, odpToPdf, odpToPptx, odsToPdf, odsToXlsx, odtToDocx, odtToMarkdown, odtToPdf, pdfToDocx, pdfToMarkdown, pdfToOdg, pdfToOdp, pdfToOds, pdfToOdt, pdfToPptx, pdfToXlsx, pptxToOdp, pptxToPdf, xlsxToOds, xlsxToPdf };
@@ -51,14 +51,11 @@ function docxToPdf(bytes, options) {
51
51
  function odtToPdf(bytes, options) {
52
52
  const pkg = decodePackage$1(bytes);
53
53
  const content = readOdtContent(pkg);
54
- if (content.document.kind !== "wordprocessing") throw new Error("readOdtContent returned a non-wordprocessing ContentDocument");
55
- const { document: layout, formulas } = convertWordprocessingToLayout(content.document, {
56
- measurer: createStandardFontMeasurer(),
57
- formulas: content.formulas
58
- });
54
+ if (content.kind !== "wordprocessing") throw new Error("readOdtContent returned a non-wordprocessing ContentDocument");
55
+ const { document: layout, formulas } = convertWordprocessingToLayout(content, { measurer: createStandardFontMeasurer() });
59
56
  options?.onDocument?.({
60
57
  formatVersion: DOCUMENT_PACKAGE_FORMAT_VERSION,
61
- content: content.document,
58
+ content,
62
59
  layout
63
60
  });
64
61
  return writePdf(layout, {
@@ -71,7 +68,7 @@ function pptxToPdf(bytes, options) {
71
68
  const pkg = openPptx(bytes).toPackage();
72
69
  const content = readPptxContent(pkg);
73
70
  if (content.kind !== "presentation") throw new Error("readPptxContent returned a non-presentation ContentDocument");
74
- const { document: layout } = convertPresentationToLayout(content, { measurer: createStandardFontMeasurer() });
71
+ const { document: layout, formulas } = convertPresentationToLayout(content, { measurer: createStandardFontMeasurer() });
75
72
  options?.onDocument?.({
76
73
  formatVersion: DOCUMENT_PACKAGE_FORMAT_VERSION,
77
74
  content,
@@ -79,20 +76,18 @@ function pptxToPdf(bytes, options) {
79
76
  });
80
77
  return writePdf(layout, {
81
78
  signal: options?.signal,
82
- onSubstitution: options?.onSubstitution
79
+ onSubstitution: options?.onSubstitution,
80
+ formulas
83
81
  });
84
82
  }
85
83
  function odpToPdf(bytes, options) {
86
84
  const pkg = decodePackage$1(bytes);
87
85
  const content = readOdpContent(pkg);
88
- if (content.document.kind !== "presentation") throw new Error("readOdpContent returned a non-presentation ContentDocument");
89
- const { document: layout, formulas } = convertPresentationToLayout(content.document, {
90
- measurer: createStandardFontMeasurer(),
91
- formulas: content.formulas
92
- });
86
+ if (content.kind !== "presentation") throw new Error("readOdpContent returned a non-presentation ContentDocument");
87
+ const { document: layout, formulas } = convertPresentationToLayout(content, { measurer: createStandardFontMeasurer() });
93
88
  options?.onDocument?.({
94
89
  formatVersion: DOCUMENT_PACKAGE_FORMAT_VERSION,
95
- content: content.document,
90
+ content,
96
91
  layout
97
92
  });
98
93
  return writePdf(layout, {
@@ -156,9 +151,10 @@ const STANDALONE_FORMULA_MARGIN_PT = 72;
156
151
  function odfToPdf(bytes, options) {
157
152
  throwIfAborted(options?.signal);
158
153
  const pkg = decodePackage$1(bytes);
159
- const formula = readOdfFormulaContent(pkg);
154
+ const content = readOdfFormulaContent(pkg);
155
+ if (content.kind !== "formula") throw new Error("readOdfFormulaContent returned a non-formula ContentDocument");
160
156
  const metrics = loadMathFont().metricsAt(STANDALONE_FORMULA_SIZE_PT);
161
- const { box } = layoutFormula(formula.mathml, {
157
+ const { box } = layoutFormula(content.formula.mathml, {
162
158
  metrics,
163
159
  sizePt: STANDALONE_FORMULA_SIZE_PT,
164
160
  color: COLOR_BLACK
@@ -171,7 +167,7 @@ function odfToPdf(bytes, options) {
171
167
  }, PAGE_SIZE_A4.heightPt);
172
168
  const layout = {
173
169
  formatVersion: LAYOUT_FORMAT_VERSION,
174
- metadata: formula.metadata,
170
+ metadata: content.metadata,
175
171
  pages: [{
176
172
  widthPt: PAGE_SIZE_A4.widthPt,
177
173
  heightPt: PAGE_SIZE_A4.heightPt,
@@ -179,6 +175,11 @@ function odfToPdf(bytes, options) {
179
175
  }],
180
176
  images: {}
181
177
  };
178
+ options?.onDocument?.({
179
+ formatVersion: DOCUMENT_PACKAGE_FORMAT_VERSION,
180
+ content,
181
+ layout
182
+ });
182
183
  throwIfAborted(options?.signal);
183
184
  return writePdf(layout, {
184
185
  signal: options?.signal,
@@ -285,14 +286,14 @@ function pdfToMarkdown(bytes, options) {
285
286
  function odtToDocx(bytes, options) {
286
287
  throwIfAborted(options?.signal);
287
288
  const pkg = decodePackage$1(bytes);
288
- const content = readOdtContent(pkg).document;
289
+ const content = readOdtContent(pkg);
289
290
  if (content.kind !== "wordprocessing") throw new Error("readOdtContent returned a non-wordprocessing ContentDocument");
290
291
  throwIfAborted(options?.signal);
291
292
  options?.onDocument?.({
292
293
  formatVersion: DOCUMENT_PACKAGE_FORMAT_VERSION,
293
294
  content
294
295
  });
295
- return encodePackage(buildDocxPackage(content));
296
+ return encodePackage(buildDocxPackage(content, { onMathDiagnostic: options?.onMathDiagnostic }));
296
297
  }
297
298
  function docxToOdt(bytes, options) {
298
299
  throwIfAborted(options?.signal);
@@ -309,7 +310,7 @@ function docxToOdt(bytes, options) {
309
310
  function odpToPptx(bytes, options) {
310
311
  throwIfAborted(options?.signal);
311
312
  const pkg = decodePackage$1(bytes);
312
- const content = readOdpContent(pkg).document;
313
+ const content = readOdpContent(pkg);
313
314
  if (content.kind !== "presentation") throw new Error("readOdpContent returned a non-presentation ContentDocument");
314
315
  throwIfAborted(options?.signal);
315
316
  options?.onDocument?.({
@@ -364,7 +365,7 @@ function markdownToDocx(bytes, options) {
364
365
  formatVersion: DOCUMENT_PACKAGE_FORMAT_VERSION,
365
366
  content
366
367
  });
367
- return encodePackage(buildDocxPackage(content));
368
+ return encodePackage(buildDocxPackage(content, { onMathDiagnostic: options?.onMathDiagnostic }));
368
369
  }
369
370
  function docxToMarkdown(bytes, options) {
370
371
  throwIfAborted(options?.signal);
@@ -394,7 +395,7 @@ function markdownToOdt(bytes, options) {
394
395
  function odtToMarkdown(bytes, options) {
395
396
  throwIfAborted(options?.signal);
396
397
  const pkg = decodePackage$1(bytes);
397
- const content = readOdtContent(pkg).document;
398
+ const content = readOdtContent(pkg);
398
399
  if (content.kind !== "wordprocessing") throw new Error("readOdtContent returned a non-wordprocessing ContentDocument");
399
400
  throwIfAborted(options?.signal);
400
401
  options?.onDocument?.({
@@ -479,7 +480,7 @@ function odmToPdf(bytes, options) {
479
480
  continue;
480
481
  }
481
482
  const chapterPkg = decodePackage$1(chapterBytes);
482
- const chapterContent = readOdtContent(chapterPkg).document;
483
+ const chapterContent = readOdtContent(chapterPkg);
483
484
  if (chapterContent.kind !== "wordprocessing") throw new Error("readOdtContent returned a non-wordprocessing ContentDocument");
484
485
  chapterSections.push(chapterContent.sections);
485
486
  }
@@ -499,16 +500,17 @@ function odmToPdf(bytes, options) {
499
500
  metadata: readOdfMetadata(pkg),
500
501
  sections: combinedSections
501
502
  };
502
- const { document: layout } = convertWordprocessingToLayout(content, { measurer: createStandardFontMeasurer() });
503
+ const { document: layout, formulas } = convertWordprocessingToLayout(content, { measurer: createStandardFontMeasurer() });
503
504
  return writePdf(layout, {
504
505
  signal: options?.signal,
505
- onSubstitution: options?.onSubstitution
506
+ onSubstitution: options?.onSubstitution,
507
+ formulas
506
508
  });
507
509
  }
508
510
  function odbToXlsx(bytes, options) {
509
511
  throwIfAborted(options?.signal);
510
512
  const pkg = decodePackage$1(bytes);
511
- const tables = readOdbTables(pkg);
513
+ const tables = readOdbTables(pkg, { timeZone: options?.timeZone });
512
514
  throwIfAborted(options?.signal);
513
515
  const content = odbTablesToSpreadsheetDocument(tables);
514
516
  return encodePackage(buildXlsxPackage(content));
@@ -516,7 +518,7 @@ function odbToXlsx(bytes, options) {
516
518
  function odbToCsv(bytes, options) {
517
519
  throwIfAborted(options?.signal);
518
520
  const pkg = decodePackage$1(bytes);
519
- const tables = readOdbTables(pkg);
521
+ const tables = readOdbTables(pkg, { timeZone: options?.timeZone });
520
522
  throwIfAborted(options?.signal);
521
523
  return buildOdbTableCsv(tables, options?.table);
522
524
  }
@@ -1,17 +1,45 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_model_units = require("../../model/units.cjs");
3
3
  const require_edit_docx_editor = require("./editor.cjs");
4
+ const require_model_formula = require("../../model/formula.cjs");
4
5
  let ooxml_js = require("ooxml.js");
5
6
  //#region src/edit/docx/content.ts
6
- function buildDocxPackage(content) {
7
+ function buildDocxPackage(content, options) {
7
8
  if (content.kind !== "wordprocessing") throw new Error("buildDocxPackage requires a wordprocessing ContentDocument");
8
9
  const editor = require_edit_docx_editor.createDocx();
9
10
  content.sections.forEach((section, sectionIndex) => {
10
11
  if (sectionIndex > 0) editor.body.appendPageBreak();
11
- for (const block of section.blocks) appendBlock(editor.body, block);
12
+ appendBlocks(editor.body, section.blocks, options);
12
13
  });
13
14
  return editor.toPackage();
14
15
  }
16
+ function isMergeableImageParagraph(block) {
17
+ return block.kind === "paragraph" && block.runs.every((run) => run.text === "");
18
+ }
19
+ function appendBlocks(body, blocks, options) {
20
+ let index = 0;
21
+ while (index < blocks.length) {
22
+ const block = blocks[index];
23
+ const next = blocks[index + 1];
24
+ if (block !== void 0 && isMergeableImageParagraph(block) && next?.kind === "image") {
25
+ const paragraph = body.appendParagraph();
26
+ paragraph.styleId = block.styleId;
27
+ paragraph.alignment = block.alignment;
28
+ paragraph.list = block.list;
29
+ paragraph.insertImageAfter({
30
+ format: next.format,
31
+ bytes: (0, ooxml_js.base64ToBytes)(next.base64),
32
+ widthPt: next.widthPt,
33
+ heightPt: next.heightPt,
34
+ altText: next.altText
35
+ });
36
+ index += 2;
37
+ continue;
38
+ }
39
+ if (block !== void 0) appendBlock(body, block, options);
40
+ index += 1;
41
+ }
42
+ }
15
43
  function populateParagraph(paragraph, block) {
16
44
  paragraph.styleId = block.styleId;
17
45
  paragraph.alignment = block.alignment;
@@ -30,32 +58,57 @@ function populateParagraph(paragraph, block) {
30
58
  if (run.color !== void 0) docxRun.color = run.color;
31
59
  }
32
60
  }
61
+ function populateCellBlocks(cell, blocks) {
62
+ const [firstBlock, ...restBlocks] = blocks;
63
+ const firstParagraph = cell.paragraphs()[0];
64
+ if (firstBlock?.kind === "paragraph" && firstParagraph !== void 0) populateParagraph(firstParagraph, firstBlock);
65
+ else if (firstBlock !== void 0) appendCellBlock(cell, firstBlock);
66
+ for (const remaining of restBlocks) appendCellBlock(cell, remaining);
67
+ }
33
68
  function appendTable(body, block) {
34
69
  const columns = block.columnWidthsPt.length;
35
70
  if (block.rows.length === 0 || columns === 0) return;
36
71
  const table = body.appendTable({
37
- rows: block.rows.length,
72
+ rows: 0,
38
73
  columns,
39
74
  columnWidthsTwips: block.columnWidthsPt.map(require_model_units.ptToTwips)
40
75
  });
41
- block.rows.forEach((row, rowIndex) => {
42
- const tableRow = table.rows()[rowIndex];
43
- if (tableRow === void 0) return;
76
+ const verticalMerges = /* @__PURE__ */ new Map();
77
+ block.rows.forEach((row) => {
78
+ const domCells = table.appendRow(row.cells.length).cells();
79
+ let colIndex = 0;
44
80
  row.cells.forEach((cell, cellIndex) => {
45
- const tableCell = tableRow.cells()[cellIndex];
81
+ const tableCell = domCells[cellIndex];
46
82
  if (tableCell === void 0) return;
47
- const [firstBlock, ...restBlocks] = cell.blocks;
48
- const firstParagraph = tableCell.paragraphs()[0];
49
- if (firstBlock?.kind === "paragraph" && firstParagraph !== void 0) populateParagraph(firstParagraph, firstBlock);
50
- else if (firstBlock !== void 0) appendCellBlock(tableCell, firstBlock);
51
- for (const remaining of restBlocks) appendCellBlock(tableCell, remaining);
83
+ const active = verticalMerges.get(colIndex);
84
+ if (active !== void 0 && active.rowsRemaining > 0) {
85
+ if (active.gridSpan > 1) tableCell.colSpan = active.gridSpan;
86
+ tableCell.verticalMerge = "continue";
87
+ verticalMerges.set(colIndex, {
88
+ rowsRemaining: active.rowsRemaining - 1,
89
+ gridSpan: active.gridSpan
90
+ });
91
+ colIndex += active.gridSpan;
92
+ return;
93
+ }
94
+ const span = cell.colSpan ?? 1;
95
+ if (span > 1) tableCell.colSpan = span;
96
+ if (cell.rowSpan !== void 0 && cell.rowSpan > 1) {
97
+ tableCell.verticalMerge = "restart";
98
+ verticalMerges.set(colIndex, {
99
+ rowsRemaining: cell.rowSpan - 1,
100
+ gridSpan: span
101
+ });
102
+ }
103
+ populateCellBlocks(tableCell, cell.blocks);
104
+ colIndex += span;
52
105
  });
53
106
  });
54
107
  }
55
108
  function appendCellBlock(cell, block) {
56
109
  if (block.kind === "paragraph") populateParagraph(cell.appendParagraph(), block);
57
110
  }
58
- function appendBlock(body, block) {
111
+ function appendBlock(body, block, options) {
59
112
  if (block.kind === "paragraph") populateParagraph(body.appendParagraph(), block);
60
113
  else if (block.kind === "image") body.appendParagraph().insertImageAfter({
61
114
  format: block.format,
@@ -66,6 +119,15 @@ function appendBlock(body, block) {
66
119
  });
67
120
  else if (block.kind === "pageBreak") body.appendPageBreak();
68
121
  else if (block.kind === "table") appendTable(body, block);
122
+ else if (block.kind === "embeddedObject") appendEmbeddedObject(body, block, options);
123
+ }
124
+ function appendEmbeddedObject(body, block, options) {
125
+ const formula = require_model_formula.formulaOfBlock(block);
126
+ if (formula === void 0) return;
127
+ const paragraph = body.appendParagraph();
128
+ const { written, diagnostics } = paragraph.appendOfficeMath(formula.mathml);
129
+ for (const diagnostic of diagnostics) options?.onMathDiagnostic?.(diagnostic, { sourcePath: block.sourcePath });
130
+ if (!written) paragraph.appendRun({ text: require_model_formula.formulaPlaceholderText(formula) });
69
131
  }
70
132
  //#endregion
71
133
  exports.buildDocxPackage = buildDocxPackage;
@@ -1,6 +1,12 @@
1
+ import { t as OmmlDiagnostic } from "../../write-DuyfnbL_.cjs";
1
2
  import { ContentDocument } from "document-schema.js";
2
3
  import { Package } from "ooxml.js";
3
4
  //#region src/edit/docx/content.d.ts
4
- declare function buildDocxPackage(content: ContentDocument): Package;
5
+ interface BuildDocxPackageOptions {
6
+ readonly onMathDiagnostic?: (diagnostic: OmmlDiagnostic, context: {
7
+ readonly sourcePath?: string;
8
+ }) => void;
9
+ }
10
+ declare function buildDocxPackage(content: ContentDocument, options?: BuildDocxPackageOptions): Package;
5
11
  //#endregion
6
- export { buildDocxPackage };
12
+ export { BuildDocxPackageOptions, buildDocxPackage };
@@ -1,6 +1,12 @@
1
+ import { t as OmmlDiagnostic } from "../../write-Zqwx6pka.js";
1
2
  import { Package } from "ooxml.js";
2
3
  import { ContentDocument } from "document-schema.js";
3
4
  //#region src/edit/docx/content.d.ts
4
- declare function buildDocxPackage(content: ContentDocument): Package;
5
+ interface BuildDocxPackageOptions {
6
+ readonly onMathDiagnostic?: (diagnostic: OmmlDiagnostic, context: {
7
+ readonly sourcePath?: string;
8
+ }) => void;
9
+ }
10
+ declare function buildDocxPackage(content: ContentDocument, options?: BuildDocxPackageOptions): Package;
5
11
  //#endregion
6
- export { buildDocxPackage };
12
+ export { BuildDocxPackageOptions, buildDocxPackage };